From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0071.outbound.protection.outlook.com [104.47.38.71]) by dpdk.org (Postfix) with ESMTP id 7EFD61B5B5 for ; Fri, 12 Oct 2018 13:09:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=AQUANTIA1COM.onmicrosoft.com; s=selector1-aquantia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sXeHeyy0ayM6WBTGJ/pl+CAibh/ES1nx2/rPm0MSFy8=; b=ANhM2EYzuz7bEcUb3KVQPKgjunL/sIAzU6LX6ZFfD5YHk4IbbSK+qNP8bb6c46g7DnqRLsW878MYMWumlRyrV/Of21B3AHX6mpd4HfHxs/f9KgebPZ9SQt1UKTV+Teuk9Vz62bvs0EUE+kK9+PxjaWPhTVZGOOE68ATcVjUJ0EA= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1627.namprd07.prod.outlook.com (10.162.110.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.22; Fri, 12 Oct 2018 11:09:29 +0000 Received: from BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::346d:e756:e70e:17]) by BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::346d:e756:e70e:17%3]) with mapi id 15.20.1228.020; Fri, 12 Oct 2018 11:09:29 +0000 From: Igor Russkikh To: "dev@dpdk.org" CC: Pavel Belous , Igor Russkikh , "ferruh.yigit@intel.com" Thread-Topic: [PATCH v6 11/22] net/atlantic: add link status and interrupt management Thread-Index: AQHUYhwL9rJK6GGYpUGzyMw+lRdSWA== Date: Fri, 12 Oct 2018 11:09:29 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM5PR0701CA0008.eurprd07.prod.outlook.com (2603:10a6:203:51::18) To BY1PR0701MB1660.namprd07.prod.outlook.com (2a01:111:e400:522a::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Igor.Russkikh@aquantia.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [95.79.108.179] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BY1PR0701MB1627; 6:WQ3YMRPLerYYLB2W/xz1of/tLV3NlyWYNHQZSWoh9gR7pRMa3TVmtiOCIHZ5PQ6t7nHM1F0SC8VpvflROeAXQCPzsVMRw44cpB47GlpFmARCyXWj48nt6fu9C/+bVjL35PPl1oDlql8/NwrAG9jmAq+D8dxLDl4Jd4k0eWNX/H4jp45dutZw0lP+vZirKbsXNbAXdAx8DWvs8jF7115YMaa9Ng2I6p6BdhU2e/TfpApHyflFS/P79QsYyv38HmLCa69PZgisUba/+gsL+jkKvQrmWEswr6+1sy3zJejkLGQ6/UEBB0T+g8x81zx5yT5CkFiWF1aYGGyRPKKAqbOIcw8ws11BDJECB1LS5UuCCnDtEY2bbTPa/BqwGY3kL1QRHGRbzVFe8qxtnPXZ7h7NsMvF+twlYZe5GySSrsZedobVF26yYli78jsblAcFlyAY5Rlyndty3/M6QNOSiMD+U8aC06gjckqVjX0YURA0yFE=; 5:EYfrf+k3cgN8o7Cuz8h4hT9/QB7d9+tATWBs+oEH0IabkbGxh+Nebvbq5ywqs7zxpbhGlKu6HkW6CDzrmh4CVd9uoFHultOVbRI/cjKbhz6Yfokw14Y/vDi6q3SmfVey6ETSiM+OgeKGO1/B/o+Pakkz9J6Us7wgkVvhxOE5oSE=; 7:fnlj1fUZdDwt0k1+KLueKCythh5r52dAbro+y5x8PUyxSRdZTUIse5KFvm4mzoqx3zoK9juAh2CAo2+OzcKl2szPctFU4k3wTwfohijKxKgKdj/X8WOzaldeGFAUwwii4wY54OtHKyZ8/a53TDzdFN/It81BbTBIYxiU+1v6rs0q5WgFoHowaq04tVGpbCnAzhIx8GPz2aWOT4NcxUMl3hcyc/FUUWSlhxoD4n7DdJo/AxkCx12htIPx0CIeKIfh x-ms-office365-filtering-correlation-id: 32c227a4-1ac4-4ea8-0e54-08d630332dc2 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:BY1PR0701MB1627; x-ms-traffictypediagnostic: BY1PR0701MB1627: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(269456686620040); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3231355)(944501410)(52105095)(3002001)(93006095)(93001095)(10201501046)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051)(76991067); SRVR:BY1PR0701MB1627; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0701MB1627; x-forefront-prvs: 0823A5777B x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(366004)(376002)(136003)(39850400004)(396003)(189003)(199004)(186003)(6116002)(486006)(5640700003)(446003)(6436002)(6512007)(53936002)(71200400001)(71190400001)(14454004)(72206003)(316002)(2351001)(44832011)(3846002)(7736002)(305945005)(2906002)(4326008)(6486002)(97736004)(26005)(2501003)(102836004)(53946003)(5250100002)(11346002)(86362001)(575784001)(25786009)(4744004)(476003)(2616005)(106356001)(54906003)(105586002)(256004)(14444005)(5660300001)(66066001)(81166006)(81156014)(1730700003)(8676002)(478600001)(36756003)(68736007)(6916009)(8936002)(99286004)(386003)(6506007)(118296001)(2900100001)(52116002)(76176011)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR0701MB1627; H:BY1PR0701MB1660.namprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: aquantia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 2QBahycHmwinDul4rkK9tHOQ7nQesDhFgsAadcxLvOopOeFPUpuzUft85dTeYxiH9DcjcUSJqgs5MVQSJPEpFhio+ECpgmlGdWyOXJt8j5FDsV6j/c+ZZfkYg02kabjMk49x7+Gj6hayHOfazB0bFE9EUF/UByCzuXDkOW5luZlt32QyGlmuOGaHHxWIumYjlf7EOe0P+90n1mHaFUYLoiqEPooFlgy9E2nRqtGQKeQjPzpUflMdZU29wOnRMvVL13HSiLTf27hIchzfg4agUysN3n1G2R0T0HjwgBr0RJeypQvgJL5PJXcXU0LlnNLcJ9NhlyRqKLG0we7EGSG9Sv7T9whN1jgTEvkpnZ5dDf0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32c227a4-1ac4-4ea8-0e54-08d630332dc2 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2018 11:09:29.5927 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1627 Subject: [dpdk-dev] [PATCH v6 11/22] net/atlantic: add link status and interrupt management X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Oct 2018 11:09:32 -0000 From: Pavel Belous Implement link interrupt, link info, link polling. Signed-off-by: Igor Russkikh Signed-off-by: Pavel Belous --- doc/guides/nics/features/atlantic.ini | 3 + drivers/net/atlantic/atl_ethdev.c | 411 ++++++++++++++++++++++++++++++= +++- drivers/net/atlantic/atl_ethdev.h | 16 ++ drivers/net/atlantic/atl_rxtx.c | 36 +++ drivers/net/atlantic/atl_types.h | 2 + 5 files changed, 466 insertions(+), 2 deletions(-) diff --git a/doc/guides/nics/features/atlantic.ini b/doc/guides/nics/featur= es/atlantic.ini index 374cf9fb1061..f5650ae8f5f7 100644 --- a/doc/guides/nics/features/atlantic.ini +++ b/doc/guides/nics/features/atlantic.ini @@ -4,6 +4,9 @@ ; Refer to default.ini for the full list of available PMD features. ; [Features] +Speed capabilities =3D Y +Link status =3D Y +Link status event =3D Y Queue start/stop =3D Y Jumbo frame =3D Y CRC offload =3D Y diff --git a/drivers/net/atlantic/atl_ethdev.c b/drivers/net/atlantic/atl_e= thdev.c index 156f1be99cdf..b4f2326b4b9a 100644 --- a/drivers/net/atlantic/atl_ethdev.c +++ b/drivers/net/atlantic/atl_ethdev.c @@ -18,8 +18,11 @@ static int eth_atl_dev_uninit(struct rte_eth_dev *eth_de= v); static int atl_dev_configure(struct rte_eth_dev *dev); static int atl_dev_start(struct rte_eth_dev *dev); static void atl_dev_stop(struct rte_eth_dev *dev); +static int atl_dev_set_link_up(struct rte_eth_dev *dev); +static int atl_dev_set_link_down(struct rte_eth_dev *dev); static void atl_dev_close(struct rte_eth_dev *dev); static int atl_dev_reset(struct rte_eth_dev *dev); +static int atl_dev_link_update(struct rte_eth_dev *dev, int wait); =20 static int atl_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size); @@ -29,6 +32,16 @@ static void atl_dev_info_get(struct rte_eth_dev *dev, =20 static const uint32_t *atl_dev_supported_ptypes_get(struct rte_eth_dev *de= v); =20 +static void atl_dev_link_status_print(struct rte_eth_dev *dev); + +/* Interrupts */ +static int atl_dev_rxq_interrupt_setup(struct rte_eth_dev *dev); +static int atl_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on= ); +static int atl_dev_interrupt_get_status(struct rte_eth_dev *dev); +static int atl_dev_interrupt_action(struct rte_eth_dev *dev, + struct rte_intr_handle *handle); +static void atl_dev_interrupt_handler(void *param); + static int eth_atl_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, struct rte_pci_device *pci_dev); static int eth_atl_pci_remove(struct rte_pci_device *pci_dev); @@ -70,7 +83,7 @@ static const struct rte_pci_id pci_id_atl_map[] =3D { =20 static struct rte_pci_driver rte_atl_pmd =3D { .id_table =3D pci_id_atl_map, - .drv_flags =3D RTE_PCI_DRV_NEED_MAPPING | + .drv_flags =3D RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC | RTE_PCI_DRV_IOVA_AS_VA, .probe =3D eth_atl_pci_probe, .remove =3D eth_atl_pci_remove, @@ -107,9 +120,14 @@ static const struct eth_dev_ops atl_eth_dev_ops =3D { .dev_configure =3D atl_dev_configure, .dev_start =3D atl_dev_start, .dev_stop =3D atl_dev_stop, + .dev_set_link_up =3D atl_dev_set_link_up, + .dev_set_link_down =3D atl_dev_set_link_down, .dev_close =3D atl_dev_close, .dev_reset =3D atl_dev_reset, =20 + /* Link */ + .link_update =3D atl_dev_link_update, + .fw_version_get =3D atl_fw_version_get, .dev_infos_get =3D atl_dev_info_get, .dev_supported_ptypes_get =3D atl_dev_supported_ptypes_get, @@ -124,6 +142,9 @@ static const struct eth_dev_ops atl_eth_dev_ops =3D { .tx_queue_stop =3D atl_tx_queue_stop, .tx_queue_setup =3D atl_tx_queue_setup, .tx_queue_release =3D atl_tx_queue_release, + + .rx_queue_intr_enable =3D atl_dev_rx_queue_intr_enable, + .rx_queue_intr_disable =3D atl_dev_rx_queue_intr_disable, }; =20 static inline int32_t @@ -132,12 +153,28 @@ atl_reset_hw(struct aq_hw_s *hw) return hw_atl_b0_hw_reset(hw); } =20 +static inline void +atl_enable_intr(struct rte_eth_dev *dev) +{ + struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + + hw_atl_itr_irq_msk_setlsw_set(hw, 0xffffffff); +} + +static void +atl_disable_intr(struct aq_hw_s *hw) +{ + PMD_INIT_FUNC_TRACE(); + hw_atl_itr_irq_msk_clearlsw_set(hw, 0xffffffff); +} + static int eth_atl_dev_init(struct rte_eth_dev *eth_dev) { struct atl_adapter *adapter =3D (struct atl_adapter *)eth_dev->data->dev_private; struct rte_pci_device *pci_dev =3D RTE_ETH_DEV_TO_PCI(eth_dev); + struct rte_intr_handle *intr_handle =3D &pci_dev->intr_handle; struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private); int err =3D 0; =20 @@ -160,9 +197,17 @@ eth_atl_dev_init(struct rte_eth_dev *eth_dev) /* Hardware configuration - hardcode */ adapter->hw_cfg.is_lro =3D false; adapter->hw_cfg.wol =3D false; + adapter->hw_cfg.link_speed_msk =3D AQ_NIC_RATE_10G | + AQ_NIC_RATE_5G | + AQ_NIC_RATE_2G5 | + AQ_NIC_RATE_1G | + AQ_NIC_RATE_100M; =20 hw->aq_nic_cfg =3D &adapter->hw_cfg; =20 + /* disable interrupt */ + atl_disable_intr(hw); + /* Allocate memory for storing MAC addresses */ eth_dev->data->mac_addrs =3D rte_zmalloc("atlantic", ETHER_ADDR_LEN, 0); if (eth_dev->data->mac_addrs =3D=3D NULL) { @@ -179,12 +224,23 @@ eth_atl_dev_init(struct rte_eth_dev *eth_dev) eth_dev->data->mac_addrs->addr_bytes) !=3D 0) return -EINVAL; =20 + rte_intr_callback_register(intr_handle, + atl_dev_interrupt_handler, eth_dev); + + /* enable uio/vfio intr/eventfd mapping */ + rte_intr_enable(intr_handle); + + /* enable support intr */ + atl_enable_intr(eth_dev); + return err; } =20 static int eth_atl_dev_uninit(struct rte_eth_dev *eth_dev) { + struct rte_pci_device *pci_dev =3D RTE_ETH_DEV_TO_PCI(eth_dev); + struct rte_intr_handle *intr_handle =3D &pci_dev->intr_handle; struct aq_hw_s *hw; =20 PMD_INIT_FUNC_TRACE(); @@ -201,6 +257,11 @@ eth_atl_dev_uninit(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst =3D NULL; eth_dev->tx_pkt_burst =3D NULL; =20 + /* disable uio intr before callback unregister */ + rte_intr_disable(intr_handle); + rte_intr_callback_unregister(intr_handle, + atl_dev_interrupt_handler, eth_dev); + rte_free(eth_dev->data->mac_addrs); eth_dev->data->mac_addrs =3D NULL; =20 @@ -222,8 +283,16 @@ eth_atl_pci_remove(struct rte_pci_device *pci_dev) } =20 static int -atl_dev_configure(struct rte_eth_dev *dev __rte_unused) +atl_dev_configure(struct rte_eth_dev *dev) { + struct atl_interrupt *intr =3D + ATL_DEV_PRIVATE_TO_INTR(dev->data->dev_private); + + PMD_INIT_FUNC_TRACE(); + + /* set flag to update link status after init */ + intr->flags |=3D ATL_FLAG_NEED_LINK_UPDATE; + return 0; } =20 @@ -235,6 +304,11 @@ static int atl_dev_start(struct rte_eth_dev *dev) { struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct rte_pci_device *pci_dev =3D RTE_ETH_DEV_TO_PCI(dev); + struct rte_intr_handle *intr_handle =3D &pci_dev->intr_handle; + uint32_t intr_vector =3D 0; + uint32_t *link_speeds; + uint32_t speed =3D 0; int status; int err; =20 @@ -243,6 +317,16 @@ atl_dev_start(struct rte_eth_dev *dev) /* set adapter started */ hw->adapter_stopped =3D 0; =20 + if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED) { + PMD_INIT_LOG(ERR, + "Invalid link_speeds for port %u, fix speed not supported", + dev->data->port_id); + return -EINVAL; + } + + /* disable uio/vfio intr/eventfd mapping */ + rte_intr_disable(intr_handle); + /* reinitialize adapter * this calls reset and start */ @@ -253,6 +337,32 @@ atl_dev_start(struct rte_eth_dev *dev) err =3D hw_atl_b0_hw_init(hw, dev->data->mac_addrs->addr_bytes); =20 hw_atl_b0_hw_start(hw); + /* check and configure queue intr-vector mapping */ + if ((rte_intr_cap_multiple(intr_handle) || + !RTE_ETH_DEV_SRIOV(dev).active) && + dev->data->dev_conf.intr_conf.rxq !=3D 0) { + intr_vector =3D dev->data->nb_rx_queues; + if (intr_vector > ATL_MAX_INTR_QUEUE_NUM) { + PMD_INIT_LOG(ERR, "At most %d intr queues supported", + ATL_MAX_INTR_QUEUE_NUM); + return -ENOTSUP; + } + if (rte_intr_efd_enable(intr_handle, intr_vector)) { + PMD_INIT_LOG(ERR, "rte_intr_efd_enable failed"); + return -1; + } + } + + if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) { + intr_handle->intr_vec =3D rte_zmalloc("intr_vec", + dev->data->nb_rx_queues * sizeof(int), 0); + if (intr_handle->intr_vec =3D=3D NULL) { + PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues" + " intr_vec", dev->data->nb_rx_queues); + return -ENOMEM; + } + } + /* initialize transmission unit */ atl_tx_init(dev); =20 @@ -275,6 +385,61 @@ atl_dev_start(struct rte_eth_dev *dev) goto error; } =20 + err =3D hw->aq_fw_ops->update_link_status(hw); + + if (err) + goto error; + + dev->data->dev_link.link_status =3D hw->aq_link_status.mbps !=3D 0; + + link_speeds =3D &dev->data->dev_conf.link_speeds; + + speed =3D 0x0; + + if (*link_speeds =3D=3D ETH_LINK_SPEED_AUTONEG) { + speed =3D hw->aq_nic_cfg->link_speed_msk; + } else { + if (*link_speeds & ETH_LINK_SPEED_10G) + speed |=3D AQ_NIC_RATE_10G; + if (*link_speeds & ETH_LINK_SPEED_5G) + speed |=3D AQ_NIC_RATE_5G; + if (*link_speeds & ETH_LINK_SPEED_1G) + speed |=3D AQ_NIC_RATE_1G; + if (*link_speeds & ETH_LINK_SPEED_2_5G) + speed |=3D AQ_NIC_RATE_2G5; + if (*link_speeds & ETH_LINK_SPEED_100M) + speed |=3D AQ_NIC_RATE_100M; + } + + err =3D hw->aq_fw_ops->set_link_speed(hw, speed); + if (err) + goto error; + + if (rte_intr_allow_others(intr_handle)) { + /* check if lsc interrupt is enabled */ + if (dev->data->dev_conf.intr_conf.lsc !=3D 0) + atl_dev_lsc_interrupt_setup(dev, true); + else + atl_dev_lsc_interrupt_setup(dev, false); + } else { + rte_intr_callback_unregister(intr_handle, + atl_dev_interrupt_handler, dev); + if (dev->data->dev_conf.intr_conf.lsc !=3D 0) + PMD_INIT_LOG(INFO, "lsc won't enable because of" + " no intr multiplex"); + } + + /* check if rxq interrupt is enabled */ + if (dev->data->dev_conf.intr_conf.rxq !=3D 0 && + rte_intr_dp_is_en(intr_handle)) + atl_dev_rxq_interrupt_setup(dev); + + /* enable uio/vfio intr/eventfd mapping */ + rte_intr_enable(intr_handle); + + /* resume enabled intr since hw reset */ + atl_enable_intr(dev); + return 0; =20 error: @@ -288,8 +453,16 @@ atl_dev_start(struct rte_eth_dev *dev) static void atl_dev_stop(struct rte_eth_dev *dev) { + struct rte_eth_link link; struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct rte_pci_device *pci_dev =3D RTE_ETH_DEV_TO_PCI(dev); + struct rte_intr_handle *intr_handle =3D &pci_dev->intr_handle; + + PMD_INIT_FUNC_TRACE(); + + /* disable interrupts */ + atl_disable_intr(hw); =20 /* reset the NIC */ atl_reset_hw(hw); @@ -300,6 +473,46 @@ atl_dev_stop(struct rte_eth_dev *dev) /* Clear stored conf */ dev->data->scattered_rx =3D 0; dev->data->lro =3D 0; + + /* Clear recorded link status */ + memset(&link, 0, sizeof(link)); + rte_eth_linkstatus_set(dev, &link); + + if (!rte_intr_allow_others(intr_handle)) + /* resume to the default handler */ + rte_intr_callback_register(intr_handle, + atl_dev_interrupt_handler, + (void *)dev); + + /* Clean datapath event and queue/vec mapping */ + rte_intr_efd_disable(intr_handle); + if (intr_handle->intr_vec !=3D NULL) { + rte_free(intr_handle->intr_vec); + intr_handle->intr_vec =3D NULL; + } +} + +/* + * Set device link up: enable tx. + */ +static int +atl_dev_set_link_up(struct rte_eth_dev *dev) +{ + struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + + return hw->aq_fw_ops->set_link_speed(hw, + hw->aq_nic_cfg->link_speed_msk); +} + +/* + * Set device link down: disable tx. + */ +static int +atl_dev_set_link_down(struct rte_eth_dev *dev) +{ + struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + + return hw->aq_fw_ops->set_link_speed(hw, 0); } =20 /* @@ -383,6 +596,11 @@ atl_dev_info_get(struct rte_eth_dev *dev, struct rte_e= th_dev_info *dev_info) =20 dev_info->rx_desc_lim =3D rx_desc_lim; dev_info->tx_desc_lim =3D tx_desc_lim; + + dev_info->speed_capa =3D ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G; + dev_info->speed_capa |=3D ETH_LINK_SPEED_100M; + dev_info->speed_capa |=3D ETH_LINK_SPEED_2_5G; + dev_info->speed_capa |=3D ETH_LINK_SPEED_5G; } =20 static const uint32_t * @@ -407,6 +625,195 @@ atl_dev_supported_ptypes_get(struct rte_eth_dev *dev) return NULL; } =20 +/* return 0 means link status changed, -1 means not changed */ +static int +atl_dev_link_update(struct rte_eth_dev *dev, int wait __rte_unused) +{ + struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct atl_interrupt *intr =3D + ATL_DEV_PRIVATE_TO_INTR(dev->data->dev_private); + struct rte_eth_link link, old; + int err =3D 0; + + link.link_status =3D ETH_LINK_DOWN; + link.link_speed =3D 0; + link.link_duplex =3D ETH_LINK_FULL_DUPLEX; + link.link_autoneg =3D hw->is_autoneg ? ETH_LINK_AUTONEG : ETH_LINK_FIXED; + memset(&old, 0, sizeof(old)); + + /* load old link status */ + rte_eth_linkstatus_get(dev, &old); + + /* read current link status */ + err =3D hw->aq_fw_ops->update_link_status(hw); + + if (err) + return 0; + + if (hw->aq_link_status.mbps =3D=3D 0) { + /* write default (down) link status */ + rte_eth_linkstatus_set(dev, &link); + if (link.link_status =3D=3D old.link_status) + return -1; + return 0; + } + + intr->flags &=3D ~ATL_FLAG_NEED_LINK_CONFIG; + + link.link_status =3D ETH_LINK_UP; + link.link_duplex =3D ETH_LINK_FULL_DUPLEX; + link.link_speed =3D hw->aq_link_status.mbps; + + rte_eth_linkstatus_set(dev, &link); + + if (link.link_status =3D=3D old.link_status) + return -1; + + return 0; +} + + +/** + * It clears the interrupt causes and enables the interrupt. + * It will be called once only during nic initialized. + * + * @param dev + * Pointer to struct rte_eth_dev. + * @param on + * Enable or Disable. + * + * @return + * - On success, zero. + * - On failure, a negative value. + */ + +static int +atl_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on __rte_unus= ed) +{ + atl_dev_link_status_print(dev); + return 0; +} + +static int +atl_dev_rxq_interrupt_setup(struct rte_eth_dev *dev __rte_unused) +{ + return 0; +} + + +static int +atl_dev_interrupt_get_status(struct rte_eth_dev *dev) +{ + struct atl_interrupt *intr =3D + ATL_DEV_PRIVATE_TO_INTR(dev->data->dev_private); + struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + u64 cause =3D 0; + + hw_atl_b0_hw_irq_read(hw, &cause); + + atl_disable_intr(hw); + intr->flags =3D cause & BIT(ATL_IRQ_CAUSE_LINK) ? + ATL_FLAG_NEED_LINK_UPDATE : 0; + + return 0; +} + +/** + * It gets and then prints the link status. + * + * @param dev + * Pointer to struct rte_eth_dev. + * + * @return + * - On success, zero. + * - On failure, a negative value. + */ +static void +atl_dev_link_status_print(struct rte_eth_dev *dev) +{ + struct rte_eth_link link; + + memset(&link, 0, sizeof(link)); + rte_eth_linkstatus_get(dev, &link); + if (link.link_status) { + PMD_DRV_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s", + (int)(dev->data->port_id), + (unsigned int)link.link_speed, + link.link_duplex =3D=3D ETH_LINK_FULL_DUPLEX ? + "full-duplex" : "half-duplex"); + } else { + PMD_DRV_LOG(INFO, " Port %d: Link Down", + (int)(dev->data->port_id)); + } + + +#ifdef DEBUG +{ + struct rte_pci_device *pci_dev =3D RTE_ETH_DEV_TO_PCI(dev); + + PMD_DRV_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT, + pci_dev->addr.domain, + pci_dev->addr.bus, + pci_dev->addr.devid, + pci_dev->addr.function); +} +#endif + + PMD_DRV_LOG(INFO, "Link speed:%d", link.link_speed); +} + +/* + * It executes link_update after knowing an interrupt occurred. + * + * @param dev + * Pointer to struct rte_eth_dev. + * + * @return + * - On success, zero. + * - On failure, a negative value. + */ +static int +atl_dev_interrupt_action(struct rte_eth_dev *dev, + struct rte_intr_handle *intr_handle) +{ + struct atl_interrupt *intr =3D + ATL_DEV_PRIVATE_TO_INTR(dev->data->dev_private); + + if (intr->flags & ATL_FLAG_NEED_LINK_UPDATE) { + atl_dev_link_update(dev, 0); + intr->flags &=3D ~ATL_FLAG_NEED_LINK_UPDATE; + atl_dev_link_status_print(dev); + _rte_eth_dev_callback_process(dev, + RTE_ETH_EVENT_INTR_LSC, NULL); + } + + atl_enable_intr(dev); + rte_intr_enable(intr_handle); + + return 0; +} + +/** + * Interrupt handler triggered by NIC for handling + * specific interrupt. + * + * @param handle + * Pointer to interrupt handle. + * @param param + * The address of parameter (struct rte_eth_dev *) regsitered before. + * + * @return + * void + */ +static void +atl_dev_interrupt_handler(void *param) +{ + struct rte_eth_dev *dev =3D (struct rte_eth_dev *)param; + + atl_dev_interrupt_get_status(dev); + atl_dev_interrupt_action(dev, dev->intr_handle); +} + RTE_PMD_REGISTER_PCI(net_atlantic, rte_atl_pmd); RTE_PMD_REGISTER_PCI_TABLE(net_atlantic, pci_id_atl_map); RTE_PMD_REGISTER_KMOD_DEP(net_atlantic, "* igb_uio | uio_pci_generic"); diff --git a/drivers/net/atlantic/atl_ethdev.h b/drivers/net/atlantic/atl_e= thdev.h index 92bb302ffe55..55a7e0d6188c 100644 --- a/drivers/net/atlantic/atl_ethdev.h +++ b/drivers/net/atlantic/atl_ethdev.h @@ -16,6 +16,16 @@ #define ATL_DEV_TO_ADAPTER(dev) \ ((struct atl_adapter *)(dev)->data->dev_private) =20 +#define ATL_DEV_PRIVATE_TO_INTR(adapter) \ + (&((struct atl_adapter *)adapter)->intr) + +#define ATL_FLAG_NEED_LINK_UPDATE (uint32_t)(1 << 0) +#define ATL_FLAG_NEED_LINK_CONFIG (uint32_t)(4 << 0) + +struct atl_interrupt { + uint32_t flags; + uint32_t mask; +}; =20 /* * Structure to store private data for each driver instance (for each port= ). @@ -23,6 +33,7 @@ struct atl_adapter { struct aq_hw_s hw; struct aq_hw_cfg_s hw_cfg; + struct atl_interrupt intr; }; =20 /* @@ -40,6 +51,11 @@ int atl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t= tx_queue_id, uint16_t nb_tx_desc, unsigned int socket_id, const struct rte_eth_txconf *tx_conf); =20 +int atl_dev_rx_queue_intr_enable(struct rte_eth_dev *eth_dev, + uint16_t queue_id); +int atl_dev_rx_queue_intr_disable(struct rte_eth_dev *eth_dev, + uint16_t queue_id); + int atl_rx_init(struct rte_eth_dev *dev); int atl_tx_init(struct rte_eth_dev *dev); =20 diff --git a/drivers/net/atlantic/atl_rxtx.c b/drivers/net/atlantic/atl_rxt= x.c index 1d4c8099325d..36141564f5c1 100644 --- a/drivers/net/atlantic/atl_rxtx.c +++ b/drivers/net/atlantic/atl_rxtx.c @@ -651,6 +651,42 @@ atl_stop_queues(struct rte_eth_dev *dev) return 0; } =20 +static int +atl_rx_enable_intr(struct rte_eth_dev *dev, uint16_t queue_id, bool enable= ) +{ + struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct atl_rx_queue *rxq; + + PMD_INIT_FUNC_TRACE(); + + if (queue_id >=3D dev->data->nb_rx_queues) { + PMD_DRV_LOG(ERR, "Invalid RX queue id=3D%d", queue_id); + return -EINVAL; + } + + rxq =3D dev->data->rx_queues[queue_id]; + + if (rxq =3D=3D NULL) + return 0; + + /* Mapping interrupt vector */ + hw_atl_itr_irq_map_en_rx_set(hw, enable, queue_id); + + return 0; +} + +int +atl_dev_rx_queue_intr_enable(struct rte_eth_dev *eth_dev, uint16_t queue_i= d) +{ + return atl_rx_enable_intr(eth_dev, queue_id, true); +} + +int +atl_dev_rx_queue_intr_disable(struct rte_eth_dev *eth_dev, uint16_t queue_= id) +{ + return atl_rx_enable_intr(eth_dev, queue_id, false); +} + uint16_t atl_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) diff --git a/drivers/net/atlantic/atl_types.h b/drivers/net/atlantic/atl_ty= pes.h index 37ad43a110f0..e636464955e3 100644 --- a/drivers/net/atlantic/atl_types.h +++ b/drivers/net/atlantic/atl_types.h @@ -86,11 +86,13 @@ struct aq_hw_s { void *mmio; =20 struct aq_hw_link_status_s aq_link_status; + bool is_autoneg; =20 struct hw_aq_atl_utils_mbox mbox; struct hw_atl_stats_s last_stats; struct aq_stats_s curr_stats; =20 + u64 speed; unsigned int chip_features; u32 fw_ver_actual; u32 mbox_addr; --=20 2.7.4