From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C1780A04DC; Mon, 19 Oct 2020 10:54:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 63883C838; Mon, 19 Oct 2020 10:52:51 +0200 (CEST) Received: from smtpbgeu1.qq.com (smtpbgeu1.qq.com [52.59.177.22]) by dpdk.org (Postfix) with ESMTP id 32009C7EC for ; Mon, 19 Oct 2020 10:52:38 +0200 (CEST) X-QQ-mid: bizesmtp6t1603097553thkry74mc Received: from localhost.localdomain.com (unknown [183.129.236.74]) by esmtp6.qq.com (ESMTP) with id ; Mon, 19 Oct 2020 16:52:33 +0800 (CST) X-QQ-SSF: 01400000002000C0C000B00A0000000 X-QQ-FEAT: da60yr+1N77Ioi8XKwt8UAg5t/q1UbmqFafysHS0bxGYY1L5tB6h1RvoSodqn KWrRS5tgpK99mOFqHRo6xgtg6tXflc2fn/NhzJcnSGDdZek4Jsc5ROE3TgcBkWk/P6I337y lQX0bxaZUL5FMJ/xkjesrLlfiT05q+yKf/GosiHsoASQvHACX24X/aBs2WnvLriggcmvby+ bit+YQ1TgYpdsCsqi+8Sd5wkW96xCivig3Op2EW8uIKGB742IgCgskJkGm5+8J8zWG0RJo3 WIvQJg0/N4vxQ8+Z9dbI1oRs9KsgdEDnUH1PYPthjhLTfZfNUiKpwAm0hxsHOWyTZFRamci mqoWP98nwe+axLqLs30SqsziMP+qg== X-QQ-GoodBg: 2 From: Jiawen Wu To: dev@dpdk.org Cc: Jiawen Wu Date: Mon, 19 Oct 2020 16:53:22 +0800 Message-Id: <20201019085415.82207-6-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201019085415.82207-1-jiawenwu@trustnetic.com> References: <20201019085415.82207-1-jiawenwu@trustnetic.com> X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybgforeign:qybgforeign6 X-QQ-Bgrelay: 1 Subject: [dpdk-dev] [PATCH v4 05/58] net/txgbe: add MAC type and bus lan id 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add base driver shared code. Signed-off-by: Jiawen Wu --- drivers/net/txgbe/base/meson.build | 4 +- drivers/net/txgbe/base/txgbe.h | 1 + drivers/net/txgbe/base/txgbe_hw.c | 134 +++++++++++++++++++++++++ drivers/net/txgbe/base/txgbe_hw.h | 16 +++ drivers/net/txgbe/base/txgbe_type.h | 146 ++++++++++++++++++++++++++++ drivers/net/txgbe/txgbe_ethdev.c | 32 ++++++ 6 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 drivers/net/txgbe/base/txgbe_hw.c create mode 100644 drivers/net/txgbe/base/txgbe_hw.h diff --git a/drivers/net/txgbe/base/meson.build b/drivers/net/txgbe/base/meson.build index a0f65b819..54d6e399d 100644 --- a/drivers/net/txgbe/base/meson.build +++ b/drivers/net/txgbe/base/meson.build @@ -1,7 +1,9 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2015-2020 -sources = [] +sources = [ + 'txgbe_hw.c', +] error_cflags = [] diff --git a/drivers/net/txgbe/base/txgbe.h b/drivers/net/txgbe/base/txgbe.h index 9aee9738a..7783bd694 100644 --- a/drivers/net/txgbe/base/txgbe.h +++ b/drivers/net/txgbe/base/txgbe.h @@ -6,5 +6,6 @@ #define _TXGBE_H_ #include "txgbe_type.h" +#include "txgbe_hw.h" #endif /* _TXGBE_H_ */ diff --git a/drivers/net/txgbe/base/txgbe_hw.c b/drivers/net/txgbe/base/txgbe_hw.c new file mode 100644 index 000000000..1ffd8b1fd --- /dev/null +++ b/drivers/net/txgbe/base/txgbe_hw.c @@ -0,0 +1,134 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2015-2020 + */ + +#include "txgbe_type.h" +#include "txgbe_hw.h" + +#define TXGBE_RAPTOR_RAR_ENTRIES 128 + +/** + * txgbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices + * @hw: pointer to the HW structure + * + * Determines the LAN function id by reading memory-mapped registers and swaps + * the port value if requested, and set MAC instance for devices. + **/ +void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw) +{ + struct txgbe_bus_info *bus = &hw->bus; + u32 reg; + + DEBUGFUNC("txgbe_set_lan_id_multi_port_pcie"); + + reg = rd32(hw, TXGBE_PORTSTAT); + bus->lan_id = TXGBE_PORTSTAT_ID(reg); + + /* check for single port */ + reg = rd32(hw, TXGBE_PWR); + if (TXGBE_PWR_LANID(reg) == TXGBE_PWR_LANID_SWAP) + bus->func = 0; + else + bus->func = bus->lan_id; +} + +s32 txgbe_init_shared_code(struct txgbe_hw *hw) +{ + s32 status; + + DEBUGFUNC("txgbe_init_shared_code"); + + /* + * Set the mac type + */ + txgbe_set_mac_type(hw); + + switch (hw->mac.type) { + case txgbe_mac_raptor: + status = txgbe_init_ops_pf(hw); + break; + default: + status = TXGBE_ERR_DEVICE_NOT_SUPPORTED; + break; + } + hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME; + + hw->bus.set_lan_id(hw); + + return status; +} + +/** + * txgbe_set_mac_type - Sets MAC type + * @hw: pointer to the HW structure + * + * This function sets the mac type of the adapter based on the + * vendor ID and device ID stored in the hw structure. + **/ +s32 txgbe_set_mac_type(struct txgbe_hw *hw) +{ + s32 err = 0; + + DEBUGFUNC("txgbe_set_mac_type"); + + if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) { + DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id); + return TXGBE_ERR_DEVICE_NOT_SUPPORTED; + } + + switch (hw->device_id) { + case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4: + hw->phy.media_type = txgbe_media_type_backplane; + hw->mac.type = txgbe_mac_raptor; + break; + case TXGBE_DEV_ID_RAPTOR_XAUI: + case TXGBE_DEV_ID_RAPTOR_SGMII: + hw->phy.media_type = txgbe_media_type_copper; + hw->mac.type = txgbe_mac_raptor; + break; + case TXGBE_DEV_ID_RAPTOR_SFP: + case TXGBE_DEV_ID_WX1820_SFP: + hw->phy.media_type = txgbe_media_type_fiber; + hw->mac.type = txgbe_mac_raptor; + break; + case TXGBE_DEV_ID_RAPTOR_QSFP: + hw->phy.media_type = txgbe_media_type_fiber_qsfp; + hw->mac.type = txgbe_mac_raptor; + break; + case TXGBE_DEV_ID_RAPTOR_VF: + case TXGBE_DEV_ID_RAPTOR_VF_HV: + hw->phy.media_type = txgbe_media_type_virtual; + hw->mac.type = txgbe_mac_raptor_vf; + break; + default: + err = TXGBE_ERR_DEVICE_NOT_SUPPORTED; + DEBUGOUT("Unsupported device id: %x", hw->device_id); + break; + } + + DEBUGOUT("found mac: %d media: %d, returns: %d\n", + hw->mac.type, hw->phy.media_type, err); + return err; +} + +/** + * txgbe_init_ops_pf - Inits func ptrs and MAC type + * @hw: pointer to hardware structure + * + * Initialize the function pointers and assign the MAC type. + * Does not touch the hardware. + **/ +s32 txgbe_init_ops_pf(struct txgbe_hw *hw) +{ + struct txgbe_bus_info *bus = &hw->bus; + struct txgbe_mac_info *mac = &hw->mac; + + DEBUGFUNC("txgbe_init_ops_pf"); + + /* BUS */ + bus->set_lan_id = txgbe_set_lan_id_multi_port; + + mac->num_rar_entries = TXGBE_RAPTOR_RAR_ENTRIES; + + return 0; +} diff --git a/drivers/net/txgbe/base/txgbe_hw.h b/drivers/net/txgbe/base/txgbe_hw.h new file mode 100644 index 000000000..f9cf2a8f0 --- /dev/null +++ b/drivers/net/txgbe/base/txgbe_hw.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2015-2020 + */ + +#ifndef _TXGBE_HW_H_ +#define _TXGBE_HW_H_ + +#include "txgbe_type.h" + +void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw); + +s32 txgbe_init_shared_code(struct txgbe_hw *hw); +s32 txgbe_set_mac_type(struct txgbe_hw *hw); +s32 txgbe_init_ops_pf(struct txgbe_hw *hw); + +#endif /* _TXGBE_HW_H_ */ diff --git a/drivers/net/txgbe/base/txgbe_type.h b/drivers/net/txgbe/base/txgbe_type.h index f310e154f..e34a57bc7 100644 --- a/drivers/net/txgbe/base/txgbe_type.h +++ b/drivers/net/txgbe/base/txgbe_type.h @@ -5,21 +5,166 @@ #ifndef _TXGBE_TYPE_H_ #define _TXGBE_TYPE_H_ +#define TXGBE_LINK_UP_TIME 90 /* 9.0 Seconds */ + #define TXGBE_ALIGN 128 /* as intel did */ +#include "txgbe_status.h" #include "txgbe_osdep.h" #include "txgbe_devids.h" +enum txgbe_mac_type { + txgbe_mac_unknown = 0, + txgbe_mac_raptor, + txgbe_mac_raptor_vf, + txgbe_num_macs +}; + +enum txgbe_phy_type { + txgbe_phy_unknown = 0, + txgbe_phy_none, + txgbe_phy_tn, + txgbe_phy_aq, + txgbe_phy_ext_1g_t, + txgbe_phy_cu_mtd, + txgbe_phy_cu_unknown, + txgbe_phy_qt, + txgbe_phy_xaui, + txgbe_phy_nl, + txgbe_phy_sfp_tyco_passive, + txgbe_phy_sfp_unknown_passive, + txgbe_phy_sfp_unknown_active, + txgbe_phy_sfp_avago, + txgbe_phy_sfp_ftl, + txgbe_phy_sfp_ftl_active, + txgbe_phy_sfp_unknown, + txgbe_phy_sfp_intel, + txgbe_phy_qsfp_unknown_passive, + txgbe_phy_qsfp_unknown_active, + txgbe_phy_qsfp_intel, + txgbe_phy_qsfp_unknown, + txgbe_phy_sfp_unsupported, /* Enforce bit set with unsupported module */ + txgbe_phy_sgmii, + txgbe_phy_fw, + txgbe_phy_generic +}; + +/* + * SFP+ module type IDs: + * + * ID Module Type + * ============= + * 0 SFP_DA_CU + * 1 SFP_SR + * 2 SFP_LR + * 3 SFP_DA_CU_CORE0 - chip-specific + * 4 SFP_DA_CU_CORE1 - chip-specific + * 5 SFP_SR/LR_CORE0 - chip-specific + * 6 SFP_SR/LR_CORE1 - chip-specific + */ +enum txgbe_sfp_type { + txgbe_sfp_type_unknown = 0, + txgbe_sfp_type_da_cu, + txgbe_sfp_type_sr, + txgbe_sfp_type_lr, + txgbe_sfp_type_da_cu_core0, + txgbe_sfp_type_da_cu_core1, + txgbe_sfp_type_srlr_core0, + txgbe_sfp_type_srlr_core1, + txgbe_sfp_type_da_act_lmt_core0, + txgbe_sfp_type_da_act_lmt_core1, + txgbe_sfp_type_1g_cu_core0, + txgbe_sfp_type_1g_cu_core1, + txgbe_sfp_type_1g_sx_core0, + txgbe_sfp_type_1g_sx_core1, + txgbe_sfp_type_1g_lx_core0, + txgbe_sfp_type_1g_lx_core1, + txgbe_sfp_type_not_present = 0xFFFE, + txgbe_sfp_type_not_known = 0xFFFF +}; + +enum txgbe_media_type { + txgbe_media_type_unknown = 0, + txgbe_media_type_fiber, + txgbe_media_type_fiber_qsfp, + txgbe_media_type_copper, + txgbe_media_type_backplane, + txgbe_media_type_cx4, + txgbe_media_type_virtual +}; + +/* PCI bus types */ +enum txgbe_bus_type { + txgbe_bus_type_unknown = 0, + txgbe_bus_type_pci, + txgbe_bus_type_pcix, + txgbe_bus_type_pci_express, + txgbe_bus_type_internal, + txgbe_bus_type_reserved +}; + +/* PCI bus speeds */ +enum txgbe_bus_speed { + txgbe_bus_speed_unknown = 0, + txgbe_bus_speed_33 = 33, + txgbe_bus_speed_66 = 66, + txgbe_bus_speed_100 = 100, + txgbe_bus_speed_120 = 120, + txgbe_bus_speed_133 = 133, + txgbe_bus_speed_2500 = 2500, + txgbe_bus_speed_5000 = 5000, + txgbe_bus_speed_8000 = 8000, + txgbe_bus_speed_reserved +}; + +/* PCI bus widths */ +enum txgbe_bus_width { + txgbe_bus_width_unknown = 0, + txgbe_bus_width_pcie_x1 = 1, + txgbe_bus_width_pcie_x2 = 2, + txgbe_bus_width_pcie_x4 = 4, + txgbe_bus_width_pcie_x8 = 8, + txgbe_bus_width_32 = 32, + txgbe_bus_width_64 = 64, + txgbe_bus_width_reserved +}; + +struct txgbe_hw; + +/* Bus parameters */ +struct txgbe_bus_info { + s32 (*get_bus_info)(struct txgbe_hw *hw); + void (*set_lan_id)(struct txgbe_hw *hw); + + enum txgbe_bus_speed speed; + enum txgbe_bus_width width; + enum txgbe_bus_type type; + + u16 func; + u8 lan_id; + u16 instance_id; +}; + struct txgbe_mac_info { + enum txgbe_mac_type type; u8 perm_addr[ETH_ADDR_LEN]; u32 num_rar_entries; + u32 max_link_up_time; +}; + +struct txgbe_phy_info { + enum txgbe_phy_type type; + enum txgbe_sfp_type sfp_type; + u32 media_type; }; struct txgbe_hw { void IOMEM *hw_addr; void *back; struct txgbe_mac_info mac; + struct txgbe_phy_info phy; + struct txgbe_bus_info bus; u16 device_id; u16 vendor_id; u16 subsystem_device_id; @@ -31,4 +176,5 @@ struct txgbe_hw { void IOMEM *isb_mem; }; +#include "txgbe_regs.h" #endif /* _TXGBE_TYPE_H_ */ diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c index 963f02fb5..8cc0d79fe 100644 --- a/drivers/net/txgbe/txgbe_ethdev.c +++ b/drivers/net/txgbe/txgbe_ethdev.c @@ -28,6 +28,22 @@ static const struct rte_pci_id pci_id_txgbe_map[] = { static const struct eth_dev_ops txgbe_eth_dev_ops; +static inline int +txgbe_is_sfp(struct txgbe_hw *hw) +{ + switch (hw->phy.type) { + case txgbe_phy_sfp_avago: + case txgbe_phy_sfp_ftl: + case txgbe_phy_sfp_intel: + case txgbe_phy_sfp_unknown: + case txgbe_phy_sfp_tyco_passive: + case txgbe_phy_sfp_unknown_passive: + return 1; + default: + return 0; + } +} + static int eth_txgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused) { @@ -35,6 +51,7 @@ eth_txgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused) struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev); struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; const struct rte_memzone *mz; + int err; PMD_INIT_FUNC_TRACE(); @@ -57,6 +74,13 @@ eth_txgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused) hw->isb_dma = TMZ_PADDR(mz); hw->isb_mem = TMZ_VADDR(mz); + /* Initialize the shared code (base driver) */ + err = txgbe_init_shared_code(hw); + if (err != 0) { + PMD_INIT_LOG(ERR, "Shared code init failed: %d", err); + return -EIO; + } + /* Allocate memory for storing MAC addresses */ eth_dev->data->mac_addrs = rte_zmalloc("txgbe", RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries, 0); @@ -82,6 +106,14 @@ eth_txgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused) return -ENOMEM; } + if (txgbe_is_sfp(hw) && hw->phy.sfp_type != txgbe_sfp_type_not_present) + PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d, SFP+: %d", + (int)hw->mac.type, (int)hw->phy.type, + (int)hw->phy.sfp_type); + else + PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d", + (int)hw->mac.type, (int)hw->phy.type); + PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x", eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id); -- 2.18.4