From mboxrd@z Thu Jan 1 00:00:00 1970 From: Igor Russkikh Subject: [PATCH v4 07/22] net/atlantic: rte device start, stop, initial configuration Date: Tue, 9 Oct 2018 09:31:40 +0000 Message-ID: <380a05f203152fafdd9efcc922a7841c416bbdc8.1539075891.git.igor.russkikh@aquantia.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Cc: Pavel Belous , Igor Russkikh , "ferruh.yigit@intel.com" , Pavel Belous To: "dev@dpdk.org" Return-path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0070.outbound.protection.outlook.com [104.47.32.70]) by dpdk.org (Postfix) with ESMTP id 9AC0E1B20E for ; Tue, 9 Oct 2018 11:31:42 +0200 (CEST) In-Reply-To: Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Pavel Belous Start, stop and reset are all done via hw_atl layer. Link interrupt configuration is also done here. Signed-off-by: Igor Russkikh Signed-off-by: Pavel Belous Signed-off-by: Pavel Belous --- drivers/net/atlantic/atl_ethdev.c | 158 ++++++++++++++++++++++++++++++++++= ++-- drivers/net/atlantic/atl_ethdev.h | 9 +++ drivers/net/atlantic/atl_types.h | 4 + 3 files changed, 164 insertions(+), 7 deletions(-) diff --git a/drivers/net/atlantic/atl_ethdev.c b/drivers/net/atlantic/atl_e= thdev.c index 2e0331d987c3..a28e10af9781 100644 --- a/drivers/net/atlantic/atl_ethdev.c +++ b/drivers/net/atlantic/atl_ethdev.c @@ -6,6 +6,11 @@ =20 #include "atl_ethdev.h" #include "atl_common.h" +#include "atl_hw_regs.h" +#include "atl_logs.h" +#include "hw_atl/hw_atl_llh.h" +#include "hw_atl/hw_atl_b0.h" +#include "hw_atl/hw_atl_b0_internal.h" =20 static int eth_atl_dev_init(struct rte_eth_dev *eth_dev); static int eth_atl_dev_uninit(struct rte_eth_dev *eth_dev); @@ -16,6 +21,13 @@ static void atl_dev_stop(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); =20 +static int atl_fw_version_get(struct rte_eth_dev *dev, char *fw_version, + size_t fw_size); + +static void atl_dev_info_get(struct rte_eth_dev *dev, + struct rte_eth_dev_info *dev_info); + + 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); @@ -69,26 +81,99 @@ static const struct eth_dev_ops atl_eth_dev_ops =3D { .dev_stop =3D atl_dev_stop, .dev_close =3D atl_dev_close, .dev_reset =3D atl_dev_reset, - .dev_infos_get =3D atl_dev_info_get, + + .fw_version_get =3D atl_fw_version_get, + .dev_infos_get =3D atl_dev_info_get, }; =20 +static inline int32_t +atl_reset_hw(struct aq_hw_s *hw) +{ + return hw_atl_b0_hw_reset(hw); +} + +static void +atl_print_adapter_info(struct aq_hw_s *hw __rte_unused) +{ + PMD_INIT_LOG(DEBUG, "FW version: %u.%u.%u", + hw->fw_ver_actual >> 24, + (hw->fw_ver_actual >> 16) & 0xFF, + hw->fw_ver_actual & 0xFFFF); + PMD_INIT_LOG(DEBUG, "Driver version: %s", ATL_PMD_DRIVER_VERSION); +} + 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 aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private); + int err =3D 0; + + PMD_INIT_FUNC_TRACE(); + eth_dev->dev_ops =3D &atl_eth_dev_ops; =20 + /* For secondary processes, the primary process has done all the work */ + if (rte_eal_process_type() !=3D RTE_PROC_PRIMARY) + return 0; + + rte_eth_copy_pci_info(eth_dev, pci_dev); + + /* Vendor and Device ID need to be set before init of shared code */ + hw->device_id =3D pci_dev->id.device_id; + hw->vendor_id =3D pci_dev->id.vendor_id; + hw->mmio =3D (void *)pci_dev->mem_resource[0].addr; + + /* Hardware configuration - hardcode */ + adapter->hw_cfg.is_lro =3D false; + adapter->hw_cfg.wol =3D false; + + hw->aq_nic_cfg =3D &adapter->hw_cfg; + /* 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) + if (eth_dev->data->mac_addrs =3D=3D NULL) { + PMD_INIT_LOG(ERR, "MAC Malloc failed"); return -ENOMEM; + } =20 - return 0; + err =3D hw_atl_utils_initfw(hw, &hw->aq_fw_ops); + if (err) + return err; + + /* Copy the permanent MAC address */ + if (hw->aq_fw_ops->get_mac_permanent(hw, + (u8 *)ð_dev->data->mac_addrs[0]) !=3D 0) + return -EINVAL; + + return err; } =20 static int eth_atl_dev_uninit(struct rte_eth_dev *eth_dev) { + struct aq_hw_s *hw; + + PMD_INIT_FUNC_TRACE(); + + if (rte_eal_process_type() !=3D RTE_PROC_PRIMARY) + return -EPERM; + + hw =3D ATL_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private); + + if (hw->adapter_stopped =3D=3D 0) + atl_dev_close(eth_dev); + + eth_dev->dev_ops =3D NULL; + rte_free(eth_dev->data->mac_addrs); + eth_dev->data->mac_addrs =3D NULL; + +#ifdef RTE_LIBRTE_SECURITY + rte_free(eth_dev->security_ctx); +#endif =20 return 0; } @@ -118,25 +203,62 @@ atl_dev_configure(struct rte_eth_dev *dev __rte_unuse= d) * It returns 0 on success. */ static int -atl_dev_start(struct rte_eth_dev *dev __rte_unused) +atl_dev_start(struct rte_eth_dev *dev) { - return 0; + struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + int status; + int err; + + PMD_INIT_FUNC_TRACE(); + + /* stop adapter */ + hw->adapter_stopped =3D 0; + + /* reinitialize adapter + * this calls reset and start + */ + status =3D atl_reset_hw(hw); + if (status !=3D 0) + return -1; + + err =3D hw_atl_b0_hw_init(hw, (uint8_t *)dev->data->mac_addrs); + + hw_atl_b0_hw_start(hw); + + atl_print_adapter_info(hw); + + return err; } =20 /* * Stop device: disable rx and tx functions to allow for reconfiguring. */ static void -atl_dev_stop(struct rte_eth_dev *dev __rte_unused) +atl_dev_stop(struct rte_eth_dev *dev) { + struct aq_hw_s *hw =3D + ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + + /* reset the NIC */ + atl_reset_hw(hw); + hw->adapter_stopped =3D 0; + } =20 /* * Reset and stop device. */ static void -atl_dev_close(struct rte_eth_dev *dev __rte_unused) +atl_dev_close(struct rte_eth_dev *dev) { + struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + + PMD_INIT_FUNC_TRACE(); + + atl_reset_hw(hw); + + atl_dev_stop(dev); + hw->adapter_stopped =3D 1; } =20 static int @@ -153,6 +275,28 @@ atl_dev_reset(struct rte_eth_dev *dev) return ret; } =20 +static int +atl_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_si= ze) +{ + struct aq_hw_s *hw =3D ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + uint32_t fw_ver =3D 0; + unsigned int ret =3D 0; + + ret =3D hw_atl_utils_get_fw_version(hw, &fw_ver); + if (ret) + return 0; + + ret =3D snprintf(fw_version, fw_size, "%u.%u.%u", fw_ver >> 24, + (fw_ver >> 16) & 0xFFU, fw_ver & 0xFFFFU); + + ret +=3D 1; /* add string null-terminator */ + + if (fw_size < ret) + return ret; + + return 0; +} + static void atl_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_inf= o) { diff --git a/drivers/net/atlantic/atl_ethdev.h b/drivers/net/atlantic/atl_e= thdev.h index 622806837379..c0cc5475a091 100644 --- a/drivers/net/atlantic/atl_ethdev.h +++ b/drivers/net/atlantic/atl_ethdev.h @@ -6,10 +6,19 @@ #define _ATLANTIC_ETHDEV_H_ #include #include "rte_ethdev.h" + +#include "atl_types.h" +#include "hw_atl/hw_atl_utils.h" + +#define ATL_DEV_PRIVATE_TO_HW(adapter) \ + (&((struct atl_adapter *)adapter)->hw) + /* * Structure to store private data for each driver instance (for each port= ). */ struct atl_adapter { + struct aq_hw_s hw; + struct aq_hw_cfg_s hw_cfg; }; =20 #endif /* _ATLANTIC_ETHDEV_H_ */ diff --git a/drivers/net/atlantic/atl_types.h b/drivers/net/atlantic/atl_ty= pes.h index c9ebbf4e91d8..37ad43a110f0 100644 --- a/drivers/net/atlantic/atl_types.h +++ b/drivers/net/atlantic/atl_types.h @@ -76,6 +76,10 @@ struct aq_hw_cfg_s { }; =20 struct aq_hw_s { + u16 device_id; + u16 vendor_id; + bool adapter_stopped; + u8 rbl_enabled:1; struct aq_hw_cfg_s *aq_nic_cfg; const struct aq_fw_ops *aq_fw_ops; --=20 2.7.4