From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 03FA5A0C41 for ; Fri, 3 Dec 2021 23:56:12 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6379A42748; Fri, 3 Dec 2021 23:56:07 +0100 (CET) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2104.outbound.protection.outlook.com [40.107.21.104]) by mails.dpdk.org (Postfix) with ESMTP id 1876640041; Fri, 3 Dec 2021 23:56:00 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L+l5lHL5Fx9NYpUky/9cdLqXM5SGwW19RWlNiQRigSOIJwfdmjaKxietDTSB4NTzr55TlpZ5k9DjTkSPoWUUkxFHpT4Qdt1YqbNKwQIJL9TkaoypHPZMkd0C7bwqQZZcsowh9Zn/ZSAS0vqE5Zjah1NMVKwB/lgwXB0ZYXF9qAQ0yPnC5JNrUt4TcCPBcvO1ynvg3p2Is2Bebb3s7N8cQFUQTsYkVAxmwTF8/BftmjH6WkA0wekAmh5pjYQ0msoHN+lte+L5duu0OZvuQ0oR1WcOceFe8zTzndEuRPZJ90D1uB1BMbWl3Ryg7JMVvf4JAiUBpAHkXWJp61wFIkRhvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vq/60XPKnfJkiH0fCeGH8KVqdWS5GHyNdO1UPIck2ng=; b=LYHCjNh4ugxgQPDi2alkwqvJ7PjkaA2bhnxN73643aCgOA+DAECyormjPLMfzhlHXas8KGFfrObditq/3F2sXie9w5dhhQE0Fclv68yg6P7Qs4ucJ8jsV+VDA++W2O+8sLh8NbljfNmkIGKNJdKFVLsDCEBGKyf/FJW3hG9MPKAzCkEYh761bXAlW+LaMEPdEIDNyEAjgTL86NFs/B0fP2KONaHAKXdj8tlyYt9ifeRlI93teoS5vTJeTtj9MlFfcjpaff8szdDnwtmMzPrP+czuMEO94gr+ofzmhwct22yHrbAP7icTHVSjs8TmqdIOpx09A2Be08uxTr7GBRsRzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silicom-usa.com; dmarc=pass action=none header.from=silicom-usa.com; dkim=pass header.d=silicom-usa.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=SILICOMLTD.onmicrosoft.com; s=selector2-SILICOMLTD-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vq/60XPKnfJkiH0fCeGH8KVqdWS5GHyNdO1UPIck2ng=; b=jZu7CDwlMyKz1bGBbA0AkeU1a0cICYb4y0gs11cB0SGWPPAmvUg/wLxcJBIwsL1Y8IR6gcMnp352UEb6n6ESyRau4hTHoqzHR4d1SuxU30Tk+XPmckOjpjzBnuc174hIs8pP+FzitTkEkB9FaC2AOS2DkNXcSJZAXLe3hCyYLwM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=silicom-usa.com; Received: from AM0PR04MB4083.eurprd04.prod.outlook.com (2603:10a6:208:64::29) by AM0PR04MB6404.eurprd04.prod.outlook.com (2603:10a6:208:178::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Fri, 3 Dec 2021 22:55:58 +0000 Received: from AM0PR04MB4083.eurprd04.prod.outlook.com ([fe80::f4db:d40d:a746:7bfc]) by AM0PR04MB4083.eurprd04.prod.outlook.com ([fe80::f4db:d40d:a746:7bfc%7]) with mapi id 15.20.4755.019; Fri, 3 Dec 2021 22:55:58 +0000 From: Stephen Douthit To: dev@dpdk.org Cc: wenw@silicom-usa.com, Stephen Douthit , stable@dpdk.org, Haiyue Wang Subject: [PATCH 5/7] net/ixgbe: Fix SFP detection and linking on hotplug Date: Fri, 3 Dec 2021 17:55:14 -0500 Message-Id: <20211203225516.571368-6-stephend@silicom-usa.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211203225516.571368-1-stephend@silicom-usa.com> References: <20211203225516.571368-1-stephend@silicom-usa.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BL1PR13CA0431.namprd13.prod.outlook.com (2603:10b6:208:2c3::16) To AM0PR04MB4083.eurprd04.prod.outlook.com (2603:10a6:208:64::29) MIME-Version: 1.0 Received: from lappy.adi.eng (173.14.114.227) by BL1PR13CA0431.namprd13.prod.outlook.com (2603:10b6:208:2c3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.10 via Frontend Transport; Fri, 3 Dec 2021 22:55:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 79911d8e-fe6f-4608-8886-08d9b6b01248 X-MS-TrafficTypeDiagnostic: AM0PR04MB6404: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: POwXU2UnMJEichqFHTGSp7gYkNx3fvK8YGJ9Hjm819j6NVY7wmBhfkDpYi1rM2+tpJZOlcDjnzjLoWCHBydpTXr6BzkuC5gREEWn5Jbg1ntrfmVTp+SyUWUZh2j5pzqRJm0EH9QecwQEi1FjEMre4B9Euxq5iJQ7PPQhmptSCb82yG5o2AA/qUQqkp77lrOUcKgKqIfgXUI21x3OYsr7JX5frwJ9YFbuygvOsnLGQx1YQ3zvbzGQgmUzQ3BW1GB0guMcfLctsrPRg+wdAIPYGqgwvD/J5KAYpMUJiCksnsW82crfPLJxdEN3h5QmGd83q1Gp4LaUeZvlCjoiPhEDbN6g6RpzUP7NpmHZzeKElQkzjo7NnNwCrEfGXFwZobPPqO5WAGy/Kr/pOQrv1hbukk1/grvfH8V59LH4umX0JuP678pA1+r2dfbm8oXKlb9RIhLw6Jfm7Y5CwMxLmfkJ3L8VQORZ5dijBt1AhQ7WblabbPvgc8w/AJ5jAsV/y5CWtzJRgp12I8Psi9jiYR+hyMuUzNv8q1Fw/2rwVw2iBL6QI9/OrhuT1DnhGrxyRH44DYi3lfNeERhxFme2LEp7DhSFUHwkQ39tarva2KnTRpBhId1qiCgBN4s428fU9FmCVss7qFwacJydhXfRwlheiD522SrW4jqjKZ14XJM53pRxcjfVeyqYup3iaChfh8BmE7mqDggqMaSM99ag4KRxXg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB4083.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(8936002)(2906002)(30864003)(508600001)(6916009)(8676002)(6486002)(26005)(956004)(83380400001)(316002)(1076003)(36756003)(5660300002)(86362001)(186003)(4326008)(66946007)(2616005)(38100700002)(38350700002)(6506007)(66556008)(52116002)(66476007)(6666004)(6512007)(54906003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?tSQpp81a8SWBBxuwnZOYdIwr2soLlyGfCXuuSU1OeB1AZEz8E6MMHHBX/Ehp?= =?us-ascii?Q?qVil4alkQGQQkWbw431Az/OCpErK+QKsB4Nj2cs6kcR1oDF2DIOCnFWZdZxR?= =?us-ascii?Q?IZyLHN3xJqhsNeqPrTpjd7KYyu6xH+eoHuzIsRtc9f1UCV4ZcngK2Tukm1oG?= =?us-ascii?Q?QLflaLk50UzrjGm1L8voVcqUknl2FFu4G9BebGEHfgZy7LiruDzETsaABPvT?= =?us-ascii?Q?IaauV33yi0+hyvCn0I4y2M5wWfi1Pr+xS7uK9lupLLE5YYdeKzdl8KEI02xa?= =?us-ascii?Q?cfyYmpXzpcJB99Rz46LdEhBGveeswBYPoDypxZ02Zq+LbVet7wMg4rL0Z5c/?= =?us-ascii?Q?hH6jSTPvkm1Qrh12MbPkCl9/ANUf+NMHXmjz0uKa+lanNMUW/7gv9Pk6L2JQ?= =?us-ascii?Q?lXvAjePDK20aycwjgcauQfMtHrfxGRs/ncZ1pLtSMl0ZqxAtiVAdTgn1soXg?= =?us-ascii?Q?EZcH+1dhW7KGEoQx/C1NLcAw/RaChzKZSb1xeJNiF6S4GIVnddyZuniLPQna?= =?us-ascii?Q?U92UT8DdU3yVkPgAtbrg8xZjUT1f/PDKDi6oVpaiSWJ9xGJ9aQmJnksW3SWB?= =?us-ascii?Q?cAyEepuBW4FYh+ScnkUTGF064z9fQAr2bSYVjmtb0kZJ7+wa0YvPC8KdiY/b?= =?us-ascii?Q?XT5SCq+ImllGsrvaZ1h5bstmMdX56ADibPu5jvm00LOX25XGKDQK622OG2+1?= =?us-ascii?Q?9FYH80v+Xjt3FQKJbg7t33kbIvLEX+vzyFIRnq3FI+vkfHyJwiYcwXm74rHl?= =?us-ascii?Q?Knn32OMRBpbLUwGefAYvk5dAvScAWrM72rH5ZY6dwJCT4jU7H1f+ApQ76wKw?= =?us-ascii?Q?m6f+fOhrMjGexsbsfyCEwkOmrzDGJWSjEnEbyscwHJnFIRFA+z4V1Vr4krbJ?= =?us-ascii?Q?w3ZgYILwGarxsRMALfAhMqQoz+UxYiTWZ9FQLByADbWmFr8SJq2pVNZwLyMO?= =?us-ascii?Q?iXRoYxeavt7VNpGt4Sxw6GVGecrqUBEqCUj8OjGzjlokuasOiKNq0jYu95IB?= =?us-ascii?Q?8+fGfSx0oQABwbJa4mp/iaui1MmYDz7WvYC/owKELYDawhwwAoYqgcrqrN2f?= =?us-ascii?Q?nYVvu4dZKVy1Q52Ey7kSFSwVmDbG4lfXXpVuEyHAa038qTMYByjR6/VBmOB2?= =?us-ascii?Q?bzKAAUcrxQaAYdNQK1fON7KCx6Y1hAqeMKAO5rw9srcV1udXL52vsazDXH01?= =?us-ascii?Q?o1SGNuFgw+XJpIn22sxykJRqx5DjAxV0vsB2nyOxJuHOWlp/RArGFYnlvbpl?= =?us-ascii?Q?ckbh7uG3rCUCouKtjWGqgkUut/A0BElPVvfg+SRPQ85qcbQsUszOlaOFpoqU?= =?us-ascii?Q?2XKsSuQbRHQp13IYmSaQKKYmYauJKHFfJjhWfKeoa0JADKM6qs8RYsV1wBFN?= =?us-ascii?Q?DRx+DVmyVz0zehDLG4NLqaZZ5CuCaUgmbfGkaRoP9/DKvYnfsqYBk8/JwAx/?= =?us-ascii?Q?kId3KM4dDesCBj1Zn3/8GTzyHzikDN6uU+E84FzAfFKAJ5SgU2mhZrUP8n43?= =?us-ascii?Q?9XTmuVLpV6iMIlhviNO6v3ntkVBKmsWfTNOmr0CctQbYpgMe1RBaE2M8mU3z?= =?us-ascii?Q?7szFnOujz3Ayrrxp06gsqZ3LKG70OuANkVaV4vHsNPBOk8iKUuOLy9Js/j8W?= =?us-ascii?Q?S75fYjAuMlOLiDV4VH/eDyUyl07jVMqY1yiSfHQIn6yVdoZWPpkB+ThryAfJ?= =?us-ascii?Q?a1zQs0eJrTXhkBOQPqNIRWTFEKo=3D?= X-OriginatorOrg: silicom-usa.com X-MS-Exchange-CrossTenant-Network-Message-Id: 79911d8e-fe6f-4608-8886-08d9b6b01248 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB4083.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2021 22:55:58.8357 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: c9e326d8-ce47-4930-8612-cc99d3c87ad1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zzPPzU2plWBnZQ7YFjXm1GL9MIy0XhceyQYKAGSOHjlkUajCo5SB9dj+8M92hi7t0d0Xh46iD89IIrPRrqemfTELsdujhXY2E+dYt/v5KkM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6404 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Currently the ixgbe driver does not ID any SFP except for the first one plugged in. This can lead to no-link, or incorrect speed conditions. For example: * If link is initially established with a 1G SFP, and later a 1G/10G multispeed part is later installed, then the MAC link setup functions are never called to change from 1000BASE-X to 10GBASE-R mode, and the link stays running at the slower rate. * If link is initially established with a 1G SFP, and later a 10G only module is later installed, no link is established, since we are still trasnsmitting in 1000BASE-X mode to a 10GBASE-R only partner. Refactor the SFP ID/setup, and link setup code, to more closely match the flow of the mainline kernel driver which does not have these issues. In that driver a service task runs periodically to handle these operations based on bit flags that have been set (usually via interrupt or userspace request), and then get cleared once the requested subtask has been completed. Fixes: af75078fece ("first public release") Cc: stable@dpdk.org Signed-off-by: Stephen Douthit --- drivers/net/ixgbe/base/ixgbe_type.h | 2 + drivers/net/ixgbe/ixgbe_ethdev.c | 391 ++++++++++++++++++---------- drivers/net/ixgbe/ixgbe_ethdev.h | 18 +- 3 files changed, 266 insertions(+), 145 deletions(-) diff --git a/drivers/net/ixgbe/base/ixgbe_type.h b/drivers/net/ixgbe/base/ixgbe_type.h index b7eec45635..c23257aa4c 100644 --- a/drivers/net/ixgbe/base/ixgbe_type.h +++ b/drivers/net/ixgbe/base/ixgbe_type.h @@ -45,6 +45,8 @@ #include "ixgbe_osdep.h" +#define BIT(a) (1UL << (a)) + /* Override this by setting IOMEM in your ixgbe_osdep.h header */ /* Vendor ID */ diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index 34b7cb2d4e..974b3427d1 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -229,9 +229,6 @@ static int ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev); static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev); static void ixgbe_dev_interrupt_handler(void *param); static void ixgbe_dev_interrupt_delayed_handler(void *param); -static void *ixgbe_dev_setup_link_thread_handler(void *param); -static int ixgbe_dev_wait_setup_link_complete(struct rte_eth_dev *dev, - uint32_t timeout_ms); static int ixgbe_add_rar(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr, @@ -1032,6 +1029,205 @@ ixgbe_swfw_lock_reset(struct ixgbe_hw *hw) ixgbe_release_swfw_semaphore(hw, mask); } +static s32 +ixgbe_sfp_id_and_setup(struct rte_eth_dev *dev) +{ + struct ixgbe_hw *hw = + IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); + enum ixgbe_sfp_cage_status sfp_cage_status; + s32 err; + + /* Can't ID or setup SFP if it's not plugged in */ + sfp_cage_status = ixgbe_check_sfp_cage(hw); + if (sfp_cage_status == IXGBE_SFP_CAGE_EMPTY || + sfp_cage_status == IXGBE_SFP_CAGE_NOCAGE) + return IXGBE_ERR_SFP_NOT_PRESENT; + + /* Something's in the cage, ID it */ + hw->phy.ops.identify_sfp(hw); + + /* Unknown module type, give up */ + if (hw->phy.sfp_type == ixgbe_sfp_type_unknown) { + PMD_DRV_LOG(ERR, "unknown SFP type, giving up"); + return IXGBE_ERR_SFP_NOT_SUPPORTED; + } + + /* This should be a redundant check, since we looked at the + * PRSNT# signal from the cage above, but just in case this is + * an SFP that's slow to respond to I2C pokes correctly, try it + * again later + */ + if (hw->phy.sfp_type == ixgbe_sfp_type_not_present) { + PMD_DRV_LOG(ERR, "IDed SFP as absent but cage PRSNT# active!?"); + return IXGBE_ERR_SFP_NOT_PRESENT; + } + + /* SFP is present and identified, try to set it up */ + err = hw->mac.ops.setup_sfp(hw); + if (err) + PMD_DRV_LOG(ERR, "setup_sfp() failed %d", err); + + return err; +} + +/** + * SFP polling task to identify and setup SFPs. + * + * If we see an SFP present, try to ID it and set it up. If that works then let + * ixgbe_dev_link_update() do the remainder of the non-SFP link setup. + * + * If that fails, schedule ourself to try again. + * + * @param handle + * Pointer to interrupt handle. + * @param param + * The address of parameter (struct rte_eth_dev *) registered before. + * + * @return + * void + */ +static void +ixgbe_sfp_service(struct rte_eth_dev *dev) +{ + struct ixgbe_hw *hw = + IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct ixgbe_interrupt *intr = + IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private); + enum ixgbe_sfp_cage_status sfp_cage_status; + s32 err; + + /* No setup requested? Nothing to do */ + if (!(intr->flags & IXGBE_FLAG_NEED_SFP_SETUP)) + return; + + sfp_cage_status = ixgbe_check_sfp_cage(hw); + if (sfp_cage_status == IXGBE_SFP_CAGE_EMPTY || + sfp_cage_status == IXGBE_SFP_CAGE_NOCAGE) + return; + + err = ixgbe_sfp_id_and_setup(dev); + if (err) { + PMD_DRV_LOG(DEBUG, "failed to ID & setup SFP %d", err); + return; + } + + /* Setup is done, clear the flag, but make sure link config runs for new SFP */ + intr->flags &= ~IXGBE_FLAG_NEED_SFP_SETUP; + intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; + + /* + * Since this is a new SFP, clear the old advertised speed mask so we don't + * end up using an old slower rate + */ + hw->phy.autoneg_advertised = 0; +} + +static void +ixgbe_link_service(struct rte_eth_dev *dev) +{ + struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct ixgbe_interrupt *intr = + IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private); + bool link_up, autoneg = false; + u32 speed; + s32 err; + + /* Skip if we still need to setup an SFP, or if no link config requested + */ + if ((intr->flags & IXGBE_FLAG_NEED_SFP_SETUP) || + !(intr->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) + return; + + speed = hw->phy.autoneg_advertised; + if (!speed) + ixgbe_get_link_capabilities(hw, &speed, &autoneg); + + err = ixgbe_setup_link(hw, speed, true); + if (err) { + PMD_DRV_LOG(ERR, "ixgbe_setup_link failed %d", err); + return; + } + + /* Update internal link status, waiting for link */ + err = ixgbe_check_link(hw, &speed, &link_up, 1); + if (!err && link_up) + intr->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; + + if (!ixgbe_dev_link_update(dev, 0)) { + ixgbe_dev_link_status_print(dev); + rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL); + } +} + +/* + * Is time b after time a? + */ +static bool +ts_time_after(const struct timespec *a, const struct timespec *b) +{ + if (b->tv_sec > a->tv_sec || + (b->tv_sec == a->tv_sec && b->tv_nsec > a->tv_nsec)) + return true; + + return false; +} + +/* + * Service task thread to handle periodic tasks + */ +static void * +ixgbe_dev_service_thread_handler(void *param) +{ +#define SERVICE_THREAD_US_SLEEP (100 * 1000) + + struct rte_eth_dev *dev = (struct rte_eth_dev *)param; + struct ixgbe_hw *hw = + IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct timespec ts, end_ts; + uint32_t speed; + s32 err; + bool link_up; + + while (1) { + ixgbe_sfp_service(dev); + ixgbe_link_service(dev); + + /* Run the service thread handler more frequently when link is + * down to reduce link up latency (every 200ms vs 1s) + * + * Use a number of smaller sleeps to decrease exit latency when + * ixgbe_dev_stop() wants this thread to join + */ + err = ixgbe_check_link(hw, &speed, &link_up, 0); + clock_gettime(CLOCK_REALTIME, &end_ts); + if (err == IXGBE_SUCCESS && link_up) { + end_ts.tv_sec += 1; + } else { + end_ts.tv_nsec += 200000000; + if (end_ts.tv_nsec > 1000000000) { + end_ts.tv_nsec -= 1000000000; + end_ts.tv_sec++; + } + } + + while (1) { + /* Don't assume that rte_delay_us_sleep() provides a + * cancellation point in all execution environments, + * explicitly check for thread cancellation + */ + pthread_testcancel(); + rte_delay_us_sleep(SERVICE_THREAD_US_SLEEP); + + clock_gettime(CLOCK_REALTIME, &ts); + if (ts_time_after(&end_ts, &ts)) + break; + } + } + + /* Never return */ + return NULL; +} + /* * This function is based on code in ixgbe_attach() in base/ixgbe.c. * It returns 0 on success. @@ -1039,7 +1235,6 @@ ixgbe_swfw_lock_reset(struct ixgbe_hw *hw) static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused) { - struct ixgbe_adapter *ad = eth_dev->data->dev_private; struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); struct rte_intr_handle *intr_handle = pci_dev->intr_handle; struct ixgbe_hw *hw = @@ -1094,7 +1289,6 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused) return 0; } - rte_atomic32_clear(&ad->link_thread_running); rte_eth_copy_pci_info(eth_dev, pci_dev); eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; @@ -1537,7 +1731,6 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev) { int diag; uint32_t tc, tcs; - struct ixgbe_adapter *ad = eth_dev->data->dev_private; struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); struct rte_intr_handle *intr_handle = pci_dev->intr_handle; struct ixgbe_hw *hw = @@ -1580,7 +1773,6 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev) return 0; } - rte_atomic32_clear(&ad->link_thread_running); ixgbevf_parse_devargs(eth_dev->data->dev_private, pci_dev->device.devargs); @@ -2382,6 +2574,8 @@ ixgbe_dev_configure(struct rte_eth_dev *dev) struct ixgbe_interrupt *intr = IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private); struct ixgbe_adapter *adapter = dev->data->dev_private; + struct ixgbe_hw *hw = + IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); int ret; PMD_INIT_FUNC_TRACE(); @@ -2400,6 +2594,10 @@ ixgbe_dev_configure(struct rte_eth_dev *dev) /* set flag to update link status after init */ intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; + /* set flag to setup SFP after init */ + if (ixgbe_is_sfp(hw)) + intr->flags |= IXGBE_FLAG_NEED_SFP_SETUP; + /* * Initialize to TRUE. If any of Rx queues doesn't meet the bulk * allocation or vector Rx preconditions we will reset it. @@ -2419,13 +2617,24 @@ ixgbe_dev_phy_intr_setup(struct rte_eth_dev *dev) IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private); uint32_t gpie; - /* only set up it on X550EM_X */ + /* only set up it on X550EM_X (external PHY interrupt) + * or on x550em_a_* for SFP_PRSNT# de-assertion (SFP removal event) + */ if (hw->mac.type == ixgbe_mac_X550EM_x) { gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); gpie |= IXGBE_SDP0_GPIEN_X550EM_x; IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); if (hw->phy.type == ixgbe_phy_x550em_ext_t) intr->mask |= IXGBE_EICR_GPI_SDP0_X550EM_x; + } else if (hw->mac.type == ixgbe_mac_X550EM_a) { + gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); + gpie |= IXGBE_SDP0_GPIEN_X550EM_a; + IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); + intr->mask |= IXGBE_EICR_GPI_SDP0_X550EM_a; + } else { + PMD_DRV_LOG(DEBUG, + "No PHY/SFP interrupt for MAC %d, PHY %d\n", + hw->mac.type, hw->phy.type); } } @@ -2548,8 +2757,11 @@ ixgbe_flow_ctrl_enable(struct rte_eth_dev *dev, struct ixgbe_hw *hw) static int ixgbe_dev_start(struct rte_eth_dev *dev) { + struct ixgbe_adapter *ad = dev->data->dev_private; struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct ixgbe_interrupt *intr = + IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private); struct ixgbe_vf_info *vfinfo = *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private); struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); @@ -2570,9 +2782,6 @@ ixgbe_dev_start(struct rte_eth_dev *dev) PMD_INIT_FUNC_TRACE(); - /* Stop the link setup handler before resetting the HW. */ - ixgbe_dev_wait_setup_link_complete(dev, 0); - /* disable uio/vfio intr/eventfd mapping */ rte_intr_disable(intr_handle); @@ -2688,12 +2897,6 @@ ixgbe_dev_start(struct rte_eth_dev *dev) } } - if (ixgbe_is_sfp(hw) && hw->phy.multispeed_fiber) { - err = hw->mac.ops.setup_sfp(hw); - if (err) - goto error; - } - if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) { /* Turn on the copper */ ixgbe_set_phy_power(hw, true); @@ -2805,6 +3008,20 @@ ixgbe_dev_start(struct rte_eth_dev *dev) ixgbe_l2_tunnel_conf(dev); ixgbe_filter_restore(dev); + /* Spawn service thread */ + if (ixgbe_is_sfp(hw)) { + intr->flags |= IXGBE_FLAG_NEED_SFP_SETUP; + err = rte_ctrl_thread_create(&ad->service_thread_tid, + "ixgbe-service-thread", + NULL, + ixgbe_dev_service_thread_handler, + dev); + if (err) { + PMD_DRV_LOG(ERR, "service_thread err"); + goto error; + } + } + if (tm_conf->root && !tm_conf->committed) PMD_DRV_LOG(WARNING, "please call hierarchy_commit() " @@ -2815,12 +3032,6 @@ ixgbe_dev_start(struct rte_eth_dev *dev) if (err) goto error; - /* - * Update link status right before return, because it may - * start link configuration process in a separate thread. - */ - ixgbe_dev_link_update(dev, 0); - /* setup the macsec setting register */ if (macsec_setting->offload_en) ixgbe_dev_macsec_register_enable(dev, macsec_setting); @@ -2850,13 +3061,21 @@ ixgbe_dev_stop(struct rte_eth_dev *dev) int vf; struct ixgbe_tm_conf *tm_conf = IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private); + void *res; + s32 err; if (hw->adapter_stopped) return 0; PMD_INIT_FUNC_TRACE(); - ixgbe_dev_wait_setup_link_complete(dev, 0); + /* Cancel the service thread, and wait for it to join */ + err = pthread_cancel(adapter->service_thread_tid); + if (err) + PMD_DRV_LOG(ERR, "failed to cancel service thread %d", err); + err = pthread_join(adapter->service_thread_tid, &res); + if (err) + PMD_DRV_LOG(ERR, "failed to join service thread %d", err); /* disable interrupts */ ixgbe_disable_intr(hw); @@ -2935,7 +3154,6 @@ ixgbe_dev_set_link_up(struct rte_eth_dev *dev) } else { /* Turn on the laser */ ixgbe_enable_tx_laser(hw); - ixgbe_dev_link_update(dev, 0); } return 0; @@ -2966,7 +3184,6 @@ ixgbe_dev_set_link_down(struct rte_eth_dev *dev) } else { /* Turn off the laser */ ixgbe_disable_tx_laser(hw); - ixgbe_dev_link_update(dev, 0); } return 0; @@ -4118,57 +4335,6 @@ ixgbevf_check_link(struct ixgbe_hw *hw, ixgbe_link_speed *speed, return ret_val; } -/* - * If @timeout_ms was 0, it means that it will not return until link complete. - * It returns 1 on complete, return 0 on timeout. - */ -static int -ixgbe_dev_wait_setup_link_complete(struct rte_eth_dev *dev, uint32_t timeout_ms) -{ -#define WARNING_TIMEOUT 9000 /* 9s in total */ - struct ixgbe_adapter *ad = dev->data->dev_private; - uint32_t timeout = timeout_ms ? timeout_ms : WARNING_TIMEOUT; - - while (rte_atomic32_read(&ad->link_thread_running)) { - msec_delay(1); - timeout--; - - if (timeout_ms) { - if (!timeout) - return 0; - } else if (!timeout) { - /* It will not return until link complete */ - timeout = WARNING_TIMEOUT; - PMD_DRV_LOG(ERR, "IXGBE link thread not complete too long time!"); - } - } - - return 1; -} - -static void * -ixgbe_dev_setup_link_thread_handler(void *param) -{ - struct rte_eth_dev *dev = (struct rte_eth_dev *)param; - struct ixgbe_adapter *ad = dev->data->dev_private; - struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); - struct ixgbe_interrupt *intr = - IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private); - u32 speed; - bool autoneg = false; - - pthread_detach(pthread_self()); - speed = hw->phy.autoneg_advertised; - if (!speed) - ixgbe_get_link_capabilities(hw, &speed, &autoneg); - - ixgbe_setup_link(hw, speed, true); - - intr->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; - rte_atomic32_clear(&ad->link_thread_running); - return NULL; -} - /* * In freebsd environment, nic_uio drivers do not support interrupts, * rte_intr_callback_register() will fail to register interrupts. @@ -4208,11 +4374,8 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev, int wait_to_complete, int vf) { struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); - struct ixgbe_adapter *ad = dev->data->dev_private; struct rte_eth_link link; ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN; - struct ixgbe_interrupt *intr = - IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private); bool link_up; int diag; int wait = 1; @@ -4226,9 +4389,6 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev, hw->mac.get_link_status = true; - if (intr->flags & IXGBE_FLAG_NEED_LINK_CONFIG) - return rte_eth_linkstatus_set(dev, &link); - /* check if it needs to wait to complete, if lsc interrupt is enabled */ if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0) wait = 0; @@ -4243,38 +4403,12 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev, else diag = ixgbe_check_link(hw, &link_speed, &link_up, wait); - if (diag != 0) { + if (diag != 0 || !link_up) { link.link_speed = RTE_ETH_SPEED_NUM_100M; link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX; return rte_eth_linkstatus_set(dev, &link); } - if (link_up == 0) { - if (ixgbe_get_media_type(hw) == ixgbe_media_type_fiber) { - ixgbe_dev_wait_setup_link_complete(dev, 0); - if (rte_atomic32_test_and_set(&ad->link_thread_running)) { - /* To avoid race condition between threads, set - * the IXGBE_FLAG_NEED_LINK_CONFIG flag only - * when there is no link thread running. - */ - intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; - if (rte_ctrl_thread_create(&ad->link_thread_tid, - "ixgbe-link-handler", - NULL, - ixgbe_dev_setup_link_thread_handler, - dev) < 0) { - PMD_DRV_LOG(ERR, - "Create link thread failed!"); - rte_atomic32_clear(&ad->link_thread_running); - } - } else { - PMD_DRV_LOG(ERR, - "Other link thread is running now!"); - } - } - return rte_eth_linkstatus_set(dev, &link); - } - link.link_status = RTE_ETH_LINK_UP; link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX; @@ -4480,8 +4614,6 @@ ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev) eicr = IXGBE_READ_REG(hw, IXGBE_EICR); PMD_DRV_LOG(DEBUG, "eicr %x", eicr); - intr->flags = 0; - /* set flag for async link update */ if (eicr & IXGBE_EICR_LSC) intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; @@ -4497,6 +4629,11 @@ ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev) (eicr & IXGBE_EICR_GPI_SDP0_X550EM_x)) intr->flags |= IXGBE_FLAG_PHY_INTERRUPT; + /* Check for loss of SFP */ + if (hw->mac.type == ixgbe_mac_X550EM_a && + (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a)) + intr->flags |= IXGBE_FLAG_NEED_SFP_SETUP; + return 0; } @@ -4548,11 +4685,13 @@ ixgbe_dev_link_status_print(struct rte_eth_dev *dev) static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev) { + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); + struct rte_intr_handle *intr_handle = pci_dev->intr_handle; struct ixgbe_interrupt *intr = IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private); - int64_t timeout; struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); + int64_t timeout; PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags); @@ -4587,16 +4726,14 @@ ixgbe_dev_interrupt_action(struct rte_eth_dev *dev) if (rte_eal_alarm_set(timeout * 1000, ixgbe_dev_interrupt_delayed_handler, (void *)dev) < 0) PMD_DRV_LOG(ERR, "Error setting alarm"); - else { - /* remember original mask */ - intr->mask_original = intr->mask; + else /* only disable lsc interrupt */ intr->mask &= ~IXGBE_EIMS_LSC; - } } PMD_DRV_LOG(DEBUG, "enable intr immediately"); ixgbe_enable_intr(dev); + rte_intr_ack(intr_handle); return 0; } @@ -4619,8 +4756,6 @@ static void ixgbe_dev_interrupt_delayed_handler(void *param) { struct rte_eth_dev *dev = (struct rte_eth_dev *)param; - struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); - struct rte_intr_handle *intr_handle = pci_dev->intr_handle; struct ixgbe_interrupt *intr = IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private); struct ixgbe_hw *hw = @@ -4650,13 +4785,10 @@ ixgbe_dev_interrupt_delayed_handler(void *param) intr->flags &= ~IXGBE_FLAG_MACSEC; } - /* restore original mask */ - intr->mask = intr->mask_original; - intr->mask_original = 0; + if (dev->data->dev_conf.intr_conf.lsc != 0) + intr->mask |= IXGBE_EICR_LSC; - PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr); ixgbe_enable_intr(dev); - rte_intr_ack(intr_handle); } /** @@ -5298,9 +5430,6 @@ ixgbevf_dev_start(struct rte_eth_dev *dev) PMD_INIT_FUNC_TRACE(); - /* Stop the link setup handler before resetting the HW. */ - ixgbe_dev_wait_setup_link_complete(dev, 0); - err = hw->mac.ops.reset_hw(hw); /** @@ -5380,12 +5509,6 @@ ixgbevf_dev_start(struct rte_eth_dev *dev) /* Re-enable interrupt for VF */ ixgbevf_intr_enable(dev); - /* - * Update link status right before return, because it may - * start link configuration process in a separate thread. - */ - ixgbevf_dev_link_update(dev, 0); - hw->adapter_stopped = false; return 0; @@ -5404,8 +5527,6 @@ ixgbevf_dev_stop(struct rte_eth_dev *dev) PMD_INIT_FUNC_TRACE(); - ixgbe_dev_wait_setup_link_complete(dev, 0); - ixgbevf_intr_disable(dev); dev->data->dev_started = 0; diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h index 83e8b5e56a..14658a2a82 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.h +++ b/drivers/net/ixgbe/ixgbe_ethdev.h @@ -24,11 +24,12 @@ #include /* need update link, bit flag */ -#define IXGBE_FLAG_NEED_LINK_UPDATE (uint32_t)(1 << 0) -#define IXGBE_FLAG_MAILBOX (uint32_t)(1 << 1) -#define IXGBE_FLAG_PHY_INTERRUPT (uint32_t)(1 << 2) -#define IXGBE_FLAG_MACSEC (uint32_t)(1 << 3) -#define IXGBE_FLAG_NEED_LINK_CONFIG (uint32_t)(1 << 4) +#define IXGBE_FLAG_NEED_LINK_UPDATE BIT(0) +#define IXGBE_FLAG_MAILBOX BIT(1) +#define IXGBE_FLAG_PHY_INTERRUPT BIT(2) +#define IXGBE_FLAG_MACSEC BIT(3) +#define IXGBE_FLAG_NEED_LINK_CONFIG BIT(4) +#define IXGBE_FLAG_NEED_SFP_SETUP BIT(5) /* * Defines that were not part of ixgbe_type.h as they are not used by the @@ -41,7 +42,7 @@ #define IXGBE_RXDADV_ERR_CKSUM_MSK 3 #define IXGBE_ADVTXD_MACLEN_SHIFT 9 /* Bit shift for l2_len */ #define IXGBE_NB_STAT_MAPPING_REGS 32 -#define IXGBE_EXTENDED_VLAN (uint32_t)(1 << 26) /* EXTENDED VLAN ENABLE */ +#define IXGBE_EXTENDED_VLAN BIT(26) /* EXTENDED VLAN ENABLE */ #define IXGBE_VFTA_SIZE 128 #define IXGBE_HKEY_MAX_INDEX 10 #define IXGBE_MAX_RX_QUEUE_NUM 128 @@ -223,8 +224,6 @@ struct ixgbe_rte_flow_rss_conf { struct ixgbe_interrupt { uint32_t flags; uint32_t mask; - /*to save original mask during delayed handler */ - uint32_t mask_original; }; struct ixgbe_stat_mapping_registers { @@ -506,8 +505,7 @@ struct ixgbe_adapter { */ uint8_t pflink_fullchk; uint8_t mac_ctrl_frame_fwd; - rte_atomic32_t link_thread_running; - pthread_t link_thread_tid; + pthread_t service_thread_tid; }; struct ixgbe_vf_representor { -- 2.31.1