From patchwork Wed Dec 14 06:41:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawen Wu X-Patchwork-Id: 13072803 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9073BC4167B for ; Wed, 14 Dec 2022 06:43:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237366AbiLNGn4 (ORCPT ); Wed, 14 Dec 2022 01:43:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237364AbiLNGny (ORCPT ); Wed, 14 Dec 2022 01:43:54 -0500 X-Greylist: delayed 86754 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 13 Dec 2022 22:43:52 PST Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ABB610B65 for ; Tue, 13 Dec 2022 22:43:51 -0800 (PST) X-QQ-mid: bizesmtp70t1671000226tp28165l Received: from wxdbg.localdomain.com ( [183.129.236.74]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 14 Dec 2022 14:43:45 +0800 (CST) X-QQ-SSF: 01400000000000H0X000B00A0000000 X-QQ-FEAT: Fc2LLDWeHZ+cS+suY5PRNWaUW9nTRDFqBJJ0J2lZ97pJvqQZLD5lfcAKJx+Mu prODVFfsp7+NppUTz7hnu6svo2ISx0iCwF2kRIJjnFvaNulA2oAhujrkRvCzyE79s54xR9y qW+WC7NiI5xA+e9w04GENRWaxQS2SQgkFqo7BJKlaL0A3esD66W5FlLqutaXdyWh9It7dET D+ifM83IqyI3R455w956T+49i+A6LZVmzbr6cR7xO9JMk+JEtB1Qd1LwWR/DQdhtuz6hUNG M/tkfs0VEwkivwQWpOHBUyn0zjSrisUMFx0Fk8bDppQmw9TM+9QEH5+Crt4maPHqVYg5ZaU JZnV97GS2/6cpfUGYlGGjj14y4WebuXJfUpgXZyXfYHbMVAipN9wd7FaXLw0C3XqFUOJClv X-QQ-GoodBg: 2 From: Jiawen Wu To: netdev@vger.kernel.org, mengyuanlou@net-swift.com Cc: Jiawen Wu Subject: [PATCH net v2 1/5] net: txgbe: Remove structure txgbe_hw Date: Wed, 14 Dec 2022 14:41:29 +0800 Message-Id: <20221214064133.2424570-2-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20221214064133.2424570-1-jiawenwu@trustnetic.com> References: <20221214064133.2424570-1-jiawenwu@trustnetic.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybglogicsvr:qybglogicsvr5 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Remove useless structure txgbe_hw to make the codes clear. Signed-off-by: Jiawen Wu --- drivers/net/ethernet/wangxun/txgbe/txgbe.h | 20 ---------- drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c | 35 +++++++---------- drivers/net/ethernet/wangxun/txgbe/txgbe_hw.h | 6 +-- .../net/ethernet/wangxun/txgbe/txgbe_main.c | 38 ++++++++----------- .../net/ethernet/wangxun/txgbe/txgbe_type.h | 16 +++++++- 5 files changed, 48 insertions(+), 67 deletions(-) diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe.h b/drivers/net/ethernet/wangxun/txgbe/txgbe.h index 19e61377bd00..629c139926c5 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe.h +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe.h @@ -14,30 +14,10 @@ #define TXGBE_SP_RAR_ENTRIES 128 #define TXGBE_SP_MC_TBL_SIZE 128 -struct txgbe_mac_addr { - u8 addr[ETH_ALEN]; - u16 state; /* bitmask */ - u64 pools; -}; - #define TXGBE_MAC_STATE_DEFAULT 0x1 #define TXGBE_MAC_STATE_MODIFIED 0x2 #define TXGBE_MAC_STATE_IN_USE 0x4 -/* board specific private data structure */ -struct txgbe_adapter { - u8 __iomem *io_addr; /* Mainly for iounmap use */ - /* OS defined structs */ - struct net_device *netdev; - struct pci_dev *pdev; - - /* structs defined in txgbe_type.h */ - struct txgbe_hw hw; - u16 msg_enable; - struct txgbe_mac_addr *mac_table; - char eeprom_id[32]; -}; - extern char txgbe_driver_name[]; #endif /* _TXGBE_H_ */ diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c index 167f7ff73192..9b8826a29981 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c @@ -16,14 +16,13 @@ /** * txgbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds - * @hw: pointer to hardware structure + * @wxhw: pointer to hardware structure * * Inits the thermal sensor thresholds according to the NVM map * and save off the threshold and location values into mac.thermal_sensor_data **/ -static void txgbe_init_thermal_sensor_thresh(struct txgbe_hw *hw) +static void txgbe_init_thermal_sensor_thresh(struct wx_hw *wxhw) { - struct wx_hw *wxhw = &hw->wxhw; struct wx_thermal_sensor_data *data = &wxhw->mac.sensor; memset(data, 0, sizeof(struct wx_thermal_sensor_data)); @@ -46,16 +45,15 @@ static void txgbe_init_thermal_sensor_thresh(struct txgbe_hw *hw) /** * txgbe_read_pba_string - Reads part number string from EEPROM - * @hw: pointer to hardware structure + * @wxhw: pointer to hardware structure * @pba_num: stores the part number string from the EEPROM * @pba_num_size: part number string buffer length * * Reads the part number string from the EEPROM. **/ -int txgbe_read_pba_string(struct txgbe_hw *hw, u8 *pba_num, u32 pba_num_size) +int txgbe_read_pba_string(struct wx_hw *wxhw, u8 *pba_num, u32 pba_num_size) { u16 pba_ptr, offset, length, data; - struct wx_hw *wxhw = &hw->wxhw; int ret_val; if (!pba_num) { @@ -155,14 +153,13 @@ int txgbe_read_pba_string(struct txgbe_hw *hw, u8 *pba_num, u32 pba_num_size) /** * txgbe_calc_eeprom_checksum - Calculates and returns the checksum - * @hw: pointer to hardware structure + * @wxhw: pointer to hardware structure * @checksum: pointer to cheksum * * Returns a negative error code on error **/ -static int txgbe_calc_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum) +static int txgbe_calc_eeprom_checksum(struct wx_hw *wxhw, u16 *checksum) { - struct wx_hw *wxhw = &hw->wxhw; u16 *eeprom_ptrs = NULL; u32 buffer_size = 0; u16 *buffer = NULL; @@ -210,15 +207,14 @@ static int txgbe_calc_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum) /** * txgbe_validate_eeprom_checksum - Validate EEPROM checksum - * @hw: pointer to hardware structure + * @wxhw: pointer to hardware structure * @checksum_val: calculated checksum * * Performs checksum calculation and validates the EEPROM checksum. If the * caller does not need checksum_val, the value can be NULL. **/ -int txgbe_validate_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum_val) +int txgbe_validate_eeprom_checksum(struct wx_hw *wxhw, u16 *checksum_val) { - struct wx_hw *wxhw = &hw->wxhw; u16 read_checksum = 0; u16 checksum; int status; @@ -234,7 +230,7 @@ int txgbe_validate_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum_val) } checksum = 0; - status = txgbe_calc_eeprom_checksum(hw, &checksum); + status = txgbe_calc_eeprom_checksum(wxhw, &checksum); if (status != 0) return status; @@ -258,25 +254,22 @@ int txgbe_validate_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum_val) return status; } -static void txgbe_reset_misc(struct txgbe_hw *hw) +static void txgbe_reset_misc(struct wx_hw *wxhw) { - struct wx_hw *wxhw = &hw->wxhw; - wx_reset_misc(wxhw); - txgbe_init_thermal_sensor_thresh(hw); + txgbe_init_thermal_sensor_thresh(wxhw); } /** * txgbe_reset_hw - Perform hardware reset - * @hw: pointer to hardware structure + * @wxhw: pointer to hardware structure * * Resets the hardware by resetting the transmit and receive units, masks * and clears all interrupts, perform a PHY reset, and perform a link (MAC) * reset. **/ -int txgbe_reset_hw(struct txgbe_hw *hw) +int txgbe_reset_hw(struct wx_hw *wxhw) { - struct wx_hw *wxhw = &hw->wxhw; int status; /* Call adapter stop to disable tx/rx and clear interrupts */ @@ -294,7 +287,7 @@ int txgbe_reset_hw(struct txgbe_hw *hw) if (status != 0) return status; - txgbe_reset_misc(hw); + txgbe_reset_misc(wxhw); /* Store the permanent mac address */ wx_get_mac_addr(wxhw, wxhw->mac.perm_addr); diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.h b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.h index 6a751a69177b..b4f34ab91a38 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.h +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.h @@ -4,8 +4,8 @@ #ifndef _TXGBE_HW_H_ #define _TXGBE_HW_H_ -int txgbe_read_pba_string(struct txgbe_hw *hw, u8 *pba_num, u32 pba_num_size); -int txgbe_validate_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum_val); -int txgbe_reset_hw(struct txgbe_hw *hw); +int txgbe_read_pba_string(struct wx_hw *wxhw, u8 *pba_num, u32 pba_num_size); +int txgbe_validate_eeprom_checksum(struct wx_hw *wxhw, u16 *checksum_val); +int txgbe_reset_hw(struct wx_hw *wxhw); #endif /* _TXGBE_HW_H_ */ diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c index 36780e7f05b7..980523e29f01 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c @@ -75,8 +75,7 @@ static int txgbe_enumerate_functions(struct txgbe_adapter *adapter) static void txgbe_sync_mac_table(struct txgbe_adapter *adapter) { - struct txgbe_hw *hw = &adapter->hw; - struct wx_hw *wxhw = &hw->wxhw; + struct wx_hw *wxhw = &adapter->wxhw; int i; for (i = 0; i < wxhw->mac.num_rar_entries; i++) { @@ -98,7 +97,7 @@ static void txgbe_sync_mac_table(struct txgbe_adapter *adapter) static void txgbe_mac_set_default_filter(struct txgbe_adapter *adapter, u8 *addr) { - struct wx_hw *wxhw = &adapter->hw.wxhw; + struct wx_hw *wxhw = &adapter->wxhw; memcpy(&adapter->mac_table[0].addr, addr, ETH_ALEN); adapter->mac_table[0].pools = 1ULL; @@ -111,7 +110,7 @@ static void txgbe_mac_set_default_filter(struct txgbe_adapter *adapter, static void txgbe_flush_sw_mac_table(struct txgbe_adapter *adapter) { - struct wx_hw *wxhw = &adapter->hw.wxhw; + struct wx_hw *wxhw = &adapter->wxhw; u32 i; for (i = 0; i < wxhw->mac.num_rar_entries; i++) { @@ -125,7 +124,7 @@ static void txgbe_flush_sw_mac_table(struct txgbe_adapter *adapter) static int txgbe_del_mac_filter(struct txgbe_adapter *adapter, u8 *addr, u16 pool) { - struct wx_hw *wxhw = &adapter->hw.wxhw; + struct wx_hw *wxhw = &adapter->wxhw; u32 i; if (is_zero_ether_addr(addr)) @@ -160,8 +159,7 @@ static int txgbe_del_mac_filter(struct txgbe_adapter *adapter, u8 *addr, u16 poo static void txgbe_up_complete(struct txgbe_adapter *adapter) { - struct txgbe_hw *hw = &adapter->hw; - struct wx_hw *wxhw = &hw->wxhw; + struct wx_hw *wxhw = &adapter->wxhw; wx_control_hw(wxhw, true); } @@ -169,11 +167,11 @@ static void txgbe_up_complete(struct txgbe_adapter *adapter) static void txgbe_reset(struct txgbe_adapter *adapter) { struct net_device *netdev = adapter->netdev; - struct txgbe_hw *hw = &adapter->hw; + struct wx_hw *wxhw = &adapter->wxhw; u8 old_addr[ETH_ALEN]; int err; - err = txgbe_reset_hw(hw); + err = txgbe_reset_hw(wxhw); if (err != 0) dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); @@ -186,7 +184,7 @@ static void txgbe_reset(struct txgbe_adapter *adapter) static void txgbe_disable_device(struct txgbe_adapter *adapter) { struct net_device *netdev = adapter->netdev; - struct wx_hw *wxhw = &adapter->hw.wxhw; + struct wx_hw *wxhw = &adapter->wxhw; wx_disable_pcie_master(wxhw); /* disable receives */ @@ -225,8 +223,7 @@ static void txgbe_down(struct txgbe_adapter *adapter) static int txgbe_sw_init(struct txgbe_adapter *adapter) { struct pci_dev *pdev = adapter->pdev; - struct txgbe_hw *hw = &adapter->hw; - struct wx_hw *wxhw = &hw->wxhw; + struct wx_hw *wxhw = &adapter->wxhw; int err; wxhw->hw_addr = adapter->io_addr; @@ -313,7 +310,7 @@ static int txgbe_close(struct net_device *netdev) struct txgbe_adapter *adapter = netdev_priv(netdev); txgbe_down(adapter); - wx_control_hw(&adapter->hw.wxhw, false); + wx_control_hw(&adapter->wxhw, false); return 0; } @@ -322,8 +319,7 @@ static void txgbe_dev_shutdown(struct pci_dev *pdev, bool *enable_wake) { struct txgbe_adapter *adapter = pci_get_drvdata(pdev); struct net_device *netdev = adapter->netdev; - struct txgbe_hw *hw = &adapter->hw; - struct wx_hw *wxhw = &hw->wxhw; + struct wx_hw *wxhw = &adapter->wxhw; netif_device_detach(netdev); @@ -365,7 +361,7 @@ static netdev_tx_t txgbe_xmit_frame(struct sk_buff *skb, static int txgbe_set_mac(struct net_device *netdev, void *p) { struct txgbe_adapter *adapter = netdev_priv(netdev); - struct wx_hw *wxhw = &adapter->hw.wxhw; + struct wx_hw *wxhw = &adapter->wxhw; struct sockaddr *addr = p; int retval; @@ -405,7 +401,6 @@ static int txgbe_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent) { struct txgbe_adapter *adapter = NULL; - struct txgbe_hw *hw = NULL; struct wx_hw *wxhw = NULL; struct net_device *netdev; int err, expected_gts; @@ -453,8 +448,7 @@ static int txgbe_probe(struct pci_dev *pdev, adapter = netdev_priv(netdev); adapter->netdev = netdev; adapter->pdev = pdev; - hw = &adapter->hw; - wxhw = &hw->wxhw; + wxhw = &adapter->wxhw; adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; adapter->io_addr = devm_ioremap(&pdev->dev, @@ -486,7 +480,7 @@ static int txgbe_probe(struct pci_dev *pdev, goto err_free_mac_table; } - err = txgbe_reset_hw(hw); + err = txgbe_reset_hw(wxhw); if (err) { dev_err(&pdev->dev, "HW Init failed: %d\n", err); goto err_free_mac_table; @@ -495,7 +489,7 @@ static int txgbe_probe(struct pci_dev *pdev, netdev->features |= NETIF_F_HIGHDMA; /* make sure the EEPROM is good */ - err = txgbe_validate_eeprom_checksum(hw, NULL); + err = txgbe_validate_eeprom_checksum(wxhw, NULL); if (err != 0) { dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); wr32(wxhw, WX_MIS_RST, WX_MIS_RST_SW_RST); @@ -565,7 +559,7 @@ static int txgbe_probe(struct pci_dev *pdev, dev_warn(&pdev->dev, "Failed to enumerate PF devices.\n"); /* First try to read PBA as a string */ - err = txgbe_read_pba_string(hw, part_str, TXGBE_PBANUM_LENGTH); + err = txgbe_read_pba_string(wxhw, part_str, TXGBE_PBANUM_LENGTH); if (err) strncpy(part_str, "Unknown", TXGBE_PBANUM_LENGTH); diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h index 740a1c447e20..0cc333a11cab 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h @@ -67,8 +67,22 @@ #define TXGBE_PBANUM1_PTR 0x06 #define TXGBE_PBANUM_PTR_GUARD 0xFAFA -struct txgbe_hw { +struct txgbe_mac_addr { + u8 addr[ETH_ALEN]; + u16 state; /* bitmask */ + u64 pools; +}; + +/* board specific private data structure */ +struct txgbe_adapter { + u8 __iomem *io_addr; + /* OS defined structs */ + struct net_device *netdev; + struct pci_dev *pdev; struct wx_hw wxhw; + u16 msg_enable; + struct txgbe_mac_addr *mac_table; + char eeprom_id[32]; }; #endif /* _TXGBE_TYPE_H_ */ From patchwork Wed Dec 14 06:41:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawen Wu X-Patchwork-Id: 13072805 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D70DFC4332F for ; Wed, 14 Dec 2022 06:44:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237364AbiLNGoG (ORCPT ); Wed, 14 Dec 2022 01:44:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbiLNGn6 (ORCPT ); Wed, 14 Dec 2022 01:43:58 -0500 X-Greylist: delayed 86690 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 13 Dec 2022 22:43:55 PST Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B308910B63 for ; Tue, 13 Dec 2022 22:43:55 -0800 (PST) X-QQ-mid: bizesmtp70t1671000229tq522o7x Received: from wxdbg.localdomain.com ( [183.129.236.74]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 14 Dec 2022 14:43:48 +0800 (CST) X-QQ-SSF: 01400000000000H0X000B00A0000000 X-QQ-FEAT: pmyeiOl6PGls08DyVwSQmE1OieplW4y7i1nTLgcrp2dwy+6MyyzvCORKaefFN dw8K3BGyfPPjhrkTB3Bb4utq8K6vTka4dxudLWn6u9dknkmzrUCyS5PoUFwo1D8u8BD0xPv MU1RMaYe6ZrDnJ/3VEFwmDuhnGSy24pD53itXT+3+ZJD3LnbX6vxslu+hjQHFji/3qKp1uP kbDlno/Tl2Puyq5jCl4K5N5u/lkuJZadADWCZIuy09zoBOwhuGanSNtUV0wdk1xjbZCezUd iZXVm0zeED7T1PVynOEax00YGvZBaegsNOeanOjwLN5sK4Di27b7WIq4b176cZHkw+A/jvI c2dvQEvY3nNWNkes7x0pUNEUFv9CmFXSfYCS9+ZnRqdpMRPr0nj769QkEyydmasTuO9F1sm X-QQ-GoodBg: 2 From: Jiawen Wu To: netdev@vger.kernel.org, mengyuanlou@net-swift.com Cc: Jiawen Wu Subject: [PATCH net v2 2/5] net: ngbe: Remove structure ngbe_hw Date: Wed, 14 Dec 2022 14:41:30 +0800 Message-Id: <20221214064133.2424570-3-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20221214064133.2424570-1-jiawenwu@trustnetic.com> References: <20221214064133.2424570-1-jiawenwu@trustnetic.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybglogicsvr:qybglogicsvr5 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Remove useless structure ngbe_hw to make the codes clear. Signed-off-by: Jiawen Wu --- drivers/net/ethernet/wangxun/ngbe/ngbe.h | 46 ------------- drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c | 20 +++--- drivers/net/ethernet/wangxun/ngbe/ngbe_hw.h | 4 +- drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 66 +++++++++---------- drivers/net/ethernet/wangxun/ngbe/ngbe_type.h | 43 +++++++++++- 5 files changed, 84 insertions(+), 95 deletions(-) diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe.h b/drivers/net/ethernet/wangxun/ngbe/ngbe.h index af147ca8605c..ed832ab3e5ed 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe.h +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe.h @@ -4,8 +4,6 @@ #ifndef _NGBE_H_ #define _NGBE_H_ -#include "ngbe_type.h" - #define NGBE_MAX_FDIR_INDICES 7 #define NGBE_MAX_RX_QUEUES (NGBE_MAX_FDIR_INDICES + 1) @@ -30,50 +28,6 @@ #define NGBE_MAC_STATE_MODIFIED 0x2 #define NGBE_MAC_STATE_IN_USE 0x4 -struct ngbe_mac_addr { - u8 addr[ETH_ALEN]; - u16 state; /* bitmask */ - u64 pools; -}; - -/* board specific private data structure */ -struct ngbe_adapter { - u8 __iomem *io_addr; /* Mainly for iounmap use */ - /* OS defined structs */ - struct net_device *netdev; - struct pci_dev *pdev; - - /* structs defined in ngbe_hw.h */ - struct ngbe_hw hw; - struct ngbe_mac_addr *mac_table; - u16 msg_enable; - - /* Tx fast path data */ - int num_tx_queues; - u16 tx_itr_setting; - u16 tx_work_limit; - - /* Rx fast path data */ - int num_rx_queues; - u16 rx_itr_setting; - u16 rx_work_limit; - - int num_q_vectors; /* current number of q_vectors for device */ - int max_q_vectors; /* upper limit of q_vectors for device */ - - u32 tx_ring_count; - u32 rx_ring_count; - -#define NGBE_MAX_RETA_ENTRIES 128 - u8 rss_indir_tbl[NGBE_MAX_RETA_ENTRIES]; - -#define NGBE_RSS_KEY_SIZE 40 /* size of RSS Hash Key in bytes */ - u32 *rss_key; - u32 wol; - - u16 bd_number; -}; - extern char ngbe_driver_name[]; #endif /* _NGBE_H_ */ diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c index 0e3923b3737e..d54e22ce7c31 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c @@ -11,10 +11,10 @@ #include "ngbe_hw.h" #include "ngbe.h" -int ngbe_eeprom_chksum_hostif(struct ngbe_hw *hw) +int ngbe_eeprom_chksum_hostif(struct ngbe_adapter *adapter) { struct wx_hic_read_shadow_ram buffer; - struct wx_hw *wxhw = &hw->wxhw; + struct wx_hw *wxhw = &adapter->wxhw; int status; int tmp; @@ -38,14 +38,14 @@ int ngbe_eeprom_chksum_hostif(struct ngbe_hw *hw) return -EIO; } -static int ngbe_reset_misc(struct ngbe_hw *hw) +static int ngbe_reset_misc(struct ngbe_adapter *adapter) { - struct wx_hw *wxhw = &hw->wxhw; + struct wx_hw *wxhw = &adapter->wxhw; wx_reset_misc(wxhw); - if (hw->mac_type == ngbe_mac_type_rgmii) + if (adapter->mac_type == ngbe_mac_type_rgmii) wr32(wxhw, NGBE_MDIO_CLAUSE_SELECT, 0xF); - if (hw->gpio_ctrl) { + if (adapter->gpio_ctrl) { /* gpio0 is used to power on/off control*/ wr32(wxhw, NGBE_GPIO_DDR, 0x1); wr32(wxhw, NGBE_GPIO_DR, NGBE_GPIO_DR_0); @@ -55,15 +55,15 @@ static int ngbe_reset_misc(struct ngbe_hw *hw) /** * ngbe_reset_hw - Perform hardware reset - * @hw: pointer to hardware structure + * @adapter: pointer to hardware structure * * Resets the hardware by resetting the transmit and receive units, masks * and clears all interrupts, perform a PHY reset, and perform a link (MAC) * reset. **/ -int ngbe_reset_hw(struct ngbe_hw *hw) +int ngbe_reset_hw(struct ngbe_adapter *adapter) { - struct wx_hw *wxhw = &hw->wxhw; + struct wx_hw *wxhw = &adapter->wxhw; int status = 0; u32 reset = 0; @@ -73,7 +73,7 @@ int ngbe_reset_hw(struct ngbe_hw *hw) return status; reset = WX_MIS_RST_LAN_RST(wxhw->bus.func); wr32(wxhw, WX_MIS_RST, reset | rd32(wxhw, WX_MIS_RST)); - ngbe_reset_misc(hw); + ngbe_reset_misc(adapter); /* Store the permanent mac address */ wx_get_mac_addr(wxhw, wxhw->mac.perm_addr); diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.h b/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.h index 42476a3fe57c..0683aefab0d9 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.h +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.h @@ -7,6 +7,6 @@ #ifndef _NGBE_HW_H_ #define _NGBE_HW_H_ -int ngbe_eeprom_chksum_hostif(struct ngbe_hw *hw); -int ngbe_reset_hw(struct ngbe_hw *hw); +int ngbe_eeprom_chksum_hostif(struct ngbe_adapter *adapter); +int ngbe_reset_hw(struct ngbe_adapter *adapter); #endif /* _NGBE_HW_H_ */ diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c index f0b24366da18..5d679c39f451 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c @@ -41,25 +41,23 @@ static const struct pci_device_id ngbe_pci_tbl[] = { static void ngbe_mac_set_default_filter(struct ngbe_adapter *adapter, u8 *addr) { - struct ngbe_hw *hw = &adapter->hw; - memcpy(&adapter->mac_table[0].addr, addr, ETH_ALEN); adapter->mac_table[0].pools = 1ULL; adapter->mac_table[0].state = (NGBE_MAC_STATE_DEFAULT | NGBE_MAC_STATE_IN_USE); - wx_set_rar(&hw->wxhw, 0, adapter->mac_table[0].addr, + wx_set_rar(&adapter->wxhw, 0, adapter->mac_table[0].addr, adapter->mac_table[0].pools, WX_PSR_MAC_SWC_AD_H_AV); } /** * ngbe_init_type_code - Initialize the shared code - * @hw: pointer to hardware structure + * @adapter: pointer to hardware structure **/ -static void ngbe_init_type_code(struct ngbe_hw *hw) +static void ngbe_init_type_code(struct ngbe_adapter *adapter) { + struct wx_hw *wxhw = &adapter->wxhw; int wol_mask = 0, ncsi_mask = 0; - struct wx_hw *wxhw = &hw->wxhw; u16 type_mask = 0; wxhw->mac.type = wx_mac_em; @@ -70,39 +68,39 @@ static void ngbe_init_type_code(struct ngbe_hw *hw) switch (type_mask) { case NGBE_SUBID_M88E1512_SFP: case NGBE_SUBID_LY_M88E1512_SFP: - hw->phy.type = ngbe_phy_m88e1512_sfi; + adapter->phy.type = ngbe_phy_m88e1512_sfi; break; case NGBE_SUBID_M88E1512_RJ45: - hw->phy.type = ngbe_phy_m88e1512; + adapter->phy.type = ngbe_phy_m88e1512; break; case NGBE_SUBID_M88E1512_MIX: - hw->phy.type = ngbe_phy_m88e1512_unknown; + adapter->phy.type = ngbe_phy_m88e1512_unknown; break; case NGBE_SUBID_YT8521S_SFP: case NGBE_SUBID_YT8521S_SFP_GPIO: case NGBE_SUBID_LY_YT8521S_SFP: - hw->phy.type = ngbe_phy_yt8521s_sfi; + adapter->phy.type = ngbe_phy_yt8521s_sfi; break; case NGBE_SUBID_INTERNAL_YT8521S_SFP: case NGBE_SUBID_INTERNAL_YT8521S_SFP_GPIO: - hw->phy.type = ngbe_phy_internal_yt8521s_sfi; + adapter->phy.type = ngbe_phy_internal_yt8521s_sfi; break; case NGBE_SUBID_RGMII_FPGA: case NGBE_SUBID_OCP_CARD: fallthrough; default: - hw->phy.type = ngbe_phy_internal; + adapter->phy.type = ngbe_phy_internal; break; } - if (hw->phy.type == ngbe_phy_internal || - hw->phy.type == ngbe_phy_internal_yt8521s_sfi) - hw->mac_type = ngbe_mac_type_mdi; + if (adapter->phy.type == ngbe_phy_internal || + adapter->phy.type == ngbe_phy_internal_yt8521s_sfi) + adapter->mac_type = ngbe_mac_type_mdi; else - hw->mac_type = ngbe_mac_type_rgmii; + adapter->mac_type = ngbe_mac_type_rgmii; - hw->wol_enabled = (wol_mask == NGBE_WOL_SUP) ? 1 : 0; - hw->ncsi_enabled = (ncsi_mask == NGBE_NCSI_MASK || + adapter->wol_enabled = (wol_mask == NGBE_WOL_SUP) ? 1 : 0; + adapter->ncsi_enabled = (ncsi_mask == NGBE_NCSI_MASK || type_mask == NGBE_SUBID_OCP_CARD) ? 1 : 0; switch (type_mask) { @@ -110,10 +108,10 @@ static void ngbe_init_type_code(struct ngbe_hw *hw) case NGBE_SUBID_LY_M88E1512_SFP: case NGBE_SUBID_YT8521S_SFP_GPIO: case NGBE_SUBID_INTERNAL_YT8521S_SFP_GPIO: - hw->gpio_ctrl = 1; + adapter->gpio_ctrl = 1; break; default: - hw->gpio_ctrl = 0; + adapter->gpio_ctrl = 0; break; } } @@ -147,8 +145,7 @@ static inline int ngbe_init_rss_key(struct ngbe_adapter *adapter) static int ngbe_sw_init(struct ngbe_adapter *adapter) { struct pci_dev *pdev = adapter->pdev; - struct ngbe_hw *hw = &adapter->hw; - struct wx_hw *wxhw = &hw->wxhw; + struct wx_hw *wxhw = &adapter->wxhw; u16 msix_count = 0; int err = 0; @@ -164,7 +161,7 @@ static int ngbe_sw_init(struct ngbe_adapter *adapter) } /* mac type, phy type , oem type */ - ngbe_init_type_code(hw); + ngbe_init_type_code(adapter); wxhw->mac.max_rx_queues = NGBE_MAX_RX_QUEUES; wxhw->mac.max_tx_queues = NGBE_MAX_TX_QUEUES; @@ -221,8 +218,7 @@ static void ngbe_down(struct ngbe_adapter *adapter) static int ngbe_open(struct net_device *netdev) { struct ngbe_adapter *adapter = netdev_priv(netdev); - struct ngbe_hw *hw = &adapter->hw; - struct wx_hw *wxhw = &hw->wxhw; + struct wx_hw *wxhw = &adapter->wxhw; wx_control_hw(wxhw, true); @@ -245,7 +241,7 @@ static int ngbe_close(struct net_device *netdev) struct ngbe_adapter *adapter = netdev_priv(netdev); ngbe_down(adapter); - wx_control_hw(&adapter->hw.wxhw, false); + wx_control_hw(&adapter->wxhw, false); return 0; } @@ -266,7 +262,7 @@ static netdev_tx_t ngbe_xmit_frame(struct sk_buff *skb, static int ngbe_set_mac(struct net_device *netdev, void *p) { struct ngbe_adapter *adapter = netdev_priv(netdev); - struct wx_hw *wxhw = &adapter->hw.wxhw; + struct wx_hw *wxhw = &adapter->wxhw; struct sockaddr *addr = p; if (!is_valid_ether_addr(addr->sa_data)) @@ -291,7 +287,7 @@ static void ngbe_dev_shutdown(struct pci_dev *pdev, bool *enable_wake) if (netif_running(netdev)) ngbe_down(adapter); rtnl_unlock(); - wx_control_hw(&adapter->hw.wxhw, false); + wx_control_hw(&adapter->wxhw, false); pci_disable_device(pdev); } @@ -334,7 +330,6 @@ static int ngbe_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent) { struct ngbe_adapter *adapter = NULL; - struct ngbe_hw *hw = NULL; struct wx_hw *wxhw = NULL; struct net_device *netdev; u32 e2rom_cksum_cap = 0; @@ -381,8 +376,7 @@ static int ngbe_probe(struct pci_dev *pdev, adapter = netdev_priv(netdev); adapter->netdev = netdev; adapter->pdev = pdev; - hw = &adapter->hw; - wxhw = &hw->wxhw; + wxhw = &adapter->wxhw; adapter->msg_enable = BIT(3) - 1; adapter->io_addr = devm_ioremap(&pdev->dev, @@ -417,7 +411,7 @@ static int ngbe_probe(struct pci_dev *pdev, goto err_free_mac_table; } - err = ngbe_reset_hw(hw); + err = ngbe_reset_hw(adapter); if (err) { dev_err(&pdev->dev, "HW Init failed: %d\n", err); goto err_free_mac_table; @@ -434,7 +428,7 @@ static int ngbe_probe(struct pci_dev *pdev, wx_init_eeprom_params(wxhw); if (wxhw->bus.func == 0 || e2rom_cksum_cap == 0) { /* make sure the EEPROM is ready */ - err = ngbe_eeprom_chksum_hostif(hw); + err = ngbe_eeprom_chksum_hostif(adapter); if (err) { dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); err = -EIO; @@ -443,10 +437,10 @@ static int ngbe_probe(struct pci_dev *pdev, } adapter->wol = 0; - if (hw->wol_enabled) + if (adapter->wol_enabled) adapter->wol = NGBE_PSR_WKUP_CTL_MAG; - hw->wol_enabled = !!(adapter->wol); + adapter->wol_enabled = !!(adapter->wol); wr32(wxhw, NGBE_PSR_WKUP_CTL, adapter->wol); device_set_wakeup_enable(&pdev->dev, adapter->wol); @@ -479,7 +473,7 @@ static int ngbe_probe(struct pci_dev *pdev, netif_info(adapter, probe, netdev, "PHY: %s, PBA No: Wang Xun GbE Family Controller\n", - hw->phy.type == ngbe_phy_internal ? "Internal" : "External"); + adapter->phy.type == ngbe_phy_internal ? "Internal" : "External"); netif_info(adapter, probe, netdev, "%pM\n", netdev->dev_addr); return 0; diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h b/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h index 39f6c03f1a54..5a64ce6ded8f 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h @@ -127,7 +127,19 @@ struct ngbe_phy_info { }; -struct ngbe_hw { +struct ngbe_mac_addr { + u8 addr[ETH_ALEN]; + u16 state; /* bitmask */ + u64 pools; +}; + +/* board specific private data structure */ +struct ngbe_adapter { + u8 __iomem *io_addr; /* Mainly for iounmap use */ + /* OS defined structs */ + struct net_device *netdev; + struct pci_dev *pdev; + struct wx_hw wxhw; struct ngbe_phy_info phy; enum ngbe_mac_type mac_type; @@ -135,5 +147,34 @@ struct ngbe_hw { bool wol_enabled; bool ncsi_enabled; bool gpio_ctrl; + + struct ngbe_mac_addr *mac_table; + u16 msg_enable; + + /* Tx fast path data */ + int num_tx_queues; + u16 tx_itr_setting; + u16 tx_work_limit; + + /* Rx fast path data */ + int num_rx_queues; + u16 rx_itr_setting; + u16 rx_work_limit; + + int num_q_vectors; /* current number of q_vectors for device */ + int max_q_vectors; /* upper limit of q_vectors for device */ + + u32 tx_ring_count; + u32 rx_ring_count; + +#define NGBE_MAX_RETA_ENTRIES 128 + u8 rss_indir_tbl[NGBE_MAX_RETA_ENTRIES]; + +#define NGBE_RSS_KEY_SIZE 40 /* size of RSS Hash Key in bytes */ + u32 *rss_key; + u32 wol; + + u16 bd_number; }; + #endif /* _NGBE_TYPE_H_ */ From patchwork Wed Dec 14 06:41:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawen Wu X-Patchwork-Id: 13072804 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3EE5C001B2 for ; Wed, 14 Dec 2022 06:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237370AbiLNGoH (ORCPT ); Wed, 14 Dec 2022 01:44:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbiLNGn7 (ORCPT ); Wed, 14 Dec 2022 01:43:59 -0500 Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 463EF27DD3 for ; Tue, 13 Dec 2022 22:43:57 -0800 (PST) X-QQ-mid: bizesmtp70t1671000232ty124v04 Received: from wxdbg.localdomain.com ( [183.129.236.74]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 14 Dec 2022 14:43:51 +0800 (CST) X-QQ-SSF: 01400000000000H0X000B00A0000000 X-QQ-FEAT: +oIWmpEafD/jwVa2LfE5LfBKAOivAP5R0T1rJ1v4j9QdqAg5L6LJ2Z1xNCFHx hp6TyLFBF3gYUvrUCP+bWoAlP7KlMFP9uCXFWTnoOOxczcY2Eyki2tffbaAlxzlN9t4FPss SVjldg14bmVlBGyRhqPgqvdEB9VPxvquGyaPqjJKvHgo2nPwAU1VKkWzMOcjBgmIyRN7Jw7 +G6u1MkIC1ReMiRbIS6Il+MLxAYfVfQJ6ox7hCD1IJwnp7NiS68kKshvSvKsp+gIB8qbpkR eG7RKP4ekfA5aeui4/CGhCNHjAPhSDFv/aNFubcsMuY2ExNrx3NLH0fwmQehQdeHC/SEchG i1R2uCO9Qov5jeyCdluHg+ETd5loLCeTemhgD/Wo3W7PO+mrOn270HeOTqOsMuoAl/Gxm8o spR8z0nZat8= X-QQ-GoodBg: 2 From: Jiawen Wu To: netdev@vger.kernel.org, mengyuanlou@net-swift.com Cc: Jiawen Wu Subject: [PATCH net v2 3/5] net: txgbe: Move defines into unified file Date: Wed, 14 Dec 2022 14:41:31 +0800 Message-Id: <20221214064133.2424570-4-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20221214064133.2424570-1-jiawenwu@trustnetic.com> References: <20221214064133.2424570-1-jiawenwu@trustnetic.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybglogicsvr:qybglogicsvr5 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Remove txgbe.h, move defines into txgbe_type.h file. Signed-off-by: Jiawen Wu --- drivers/net/ethernet/wangxun/txgbe/txgbe.h | 23 ------------------- drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c | 1 - .../net/ethernet/wangxun/txgbe/txgbe_main.c | 1 - .../net/ethernet/wangxun/txgbe/txgbe_type.h | 16 +++++++++++++ 4 files changed, 16 insertions(+), 25 deletions(-) delete mode 100644 drivers/net/ethernet/wangxun/txgbe/txgbe.h diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe.h b/drivers/net/ethernet/wangxun/txgbe/txgbe.h deleted file mode 100644 index 629c139926c5..000000000000 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe.h +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright (c) 2015 - 2022 Beijing WangXun Technology Co., Ltd. */ - -#ifndef _TXGBE_H_ -#define _TXGBE_H_ - -#define TXGBE_MAX_FDIR_INDICES 63 - -#define TXGBE_MAX_RX_QUEUES (TXGBE_MAX_FDIR_INDICES + 1) -#define TXGBE_MAX_TX_QUEUES (TXGBE_MAX_FDIR_INDICES + 1) - -#define TXGBE_SP_MAX_TX_QUEUES 128 -#define TXGBE_SP_MAX_RX_QUEUES 128 -#define TXGBE_SP_RAR_ENTRIES 128 -#define TXGBE_SP_MC_TBL_SIZE 128 - -#define TXGBE_MAC_STATE_DEFAULT 0x1 -#define TXGBE_MAC_STATE_MODIFIED 0x2 -#define TXGBE_MAC_STATE_IN_USE 0x4 - -extern char txgbe_driver_name[]; - -#endif /* _TXGBE_H_ */ diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c index 9b8826a29981..02656b5971fd 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c @@ -12,7 +12,6 @@ #include "../libwx/wx_hw.h" #include "txgbe_type.h" #include "txgbe_hw.h" -#include "txgbe.h" /** * txgbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c index 980523e29f01..dcdf4e364979 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c @@ -14,7 +14,6 @@ #include "../libwx/wx_hw.h" #include "txgbe_type.h" #include "txgbe_hw.h" -#include "txgbe.h" char txgbe_driver_name[] = "txgbe"; diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h index 0cc333a11cab..c4d22ceeddad 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h @@ -67,6 +67,20 @@ #define TXGBE_PBANUM1_PTR 0x06 #define TXGBE_PBANUM_PTR_GUARD 0xFAFA +#define TXGBE_MAX_FDIR_INDICES 63 + +#define TXGBE_MAX_RX_QUEUES (TXGBE_MAX_FDIR_INDICES + 1) +#define TXGBE_MAX_TX_QUEUES (TXGBE_MAX_FDIR_INDICES + 1) + +#define TXGBE_SP_MAX_TX_QUEUES 128 +#define TXGBE_SP_MAX_RX_QUEUES 128 +#define TXGBE_SP_RAR_ENTRIES 128 +#define TXGBE_SP_MC_TBL_SIZE 128 + +#define TXGBE_MAC_STATE_DEFAULT 0x1 +#define TXGBE_MAC_STATE_MODIFIED 0x2 +#define TXGBE_MAC_STATE_IN_USE 0x4 + struct txgbe_mac_addr { u8 addr[ETH_ALEN]; u16 state; /* bitmask */ @@ -85,4 +99,6 @@ struct txgbe_adapter { char eeprom_id[32]; }; +extern char txgbe_driver_name[]; + #endif /* _TXGBE_TYPE_H_ */ From patchwork Wed Dec 14 06:41:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawen Wu X-Patchwork-Id: 13072806 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25AB9C4167B for ; Wed, 14 Dec 2022 06:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237386AbiLNGoI (ORCPT ); Wed, 14 Dec 2022 01:44:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237368AbiLNGoD (ORCPT ); Wed, 14 Dec 2022 01:44:03 -0500 Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E11827CFF for ; Tue, 13 Dec 2022 22:43:59 -0800 (PST) X-QQ-mid: bizesmtp70t1671000234tqcnsoke Received: from wxdbg.localdomain.com ( [183.129.236.74]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 14 Dec 2022 14:43:54 +0800 (CST) X-QQ-SSF: 01400000000000H0X000B00A0000000 X-QQ-FEAT: fs34Pe/+C2Ty/Q+th0MGoWLYoI0CPwusYSfDyIuAWS8DrvsAdyS58cSFh2Li1 F1CnSKz1MlIDUdN57BUUyfE+ym/JHVdlrSoxOz8aPlsfWv+oUpfB6p8va+cM1nXks8u8/7Q 43I2I4ifU99NhA8EgyORGKXc9WeNFGklpwKr0mzEIfrVfYL+xepoSJnyGgkr9rH/yAgKWmw jFZQjBytETTOQFnASoWb4cZ5xkj8+AwkffaA1ZawSr5zttZCeBcO1QQueqmIEh2sWml//bs tsu5UhiPH6LVHr2qINUCIdmgLhCwHgG9sktMZKCq96DkJmDjJpinfhd91QQeQC+IMcEGON7 S5ON1XGugC5xk8koeoGpeZX0+syjzvVYj/Ae2zO6UjK9jrEywj/lvvq0+TZsKivWr0Wp52E s8Uzz+KIa78= X-QQ-GoodBg: 2 From: Jiawen Wu To: netdev@vger.kernel.org, mengyuanlou@net-swift.com Cc: Jiawen Wu Subject: [PATCH net v2 4/5] net: ngbe: Move defines into unified file Date: Wed, 14 Dec 2022 14:41:32 +0800 Message-Id: <20221214064133.2424570-5-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20221214064133.2424570-1-jiawenwu@trustnetic.com> References: <20221214064133.2424570-1-jiawenwu@trustnetic.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybglogicsvr:qybglogicsvr5 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Remove ngbe.h, move defines into ngbe_type.h file. Signed-off-by: Jiawen Wu --- drivers/net/ethernet/wangxun/ngbe/ngbe.h | 33 ------------------- drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c | 1 - drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 2 +- drivers/net/ethernet/wangxun/ngbe/ngbe_type.h | 26 +++++++++++++++ 4 files changed, 27 insertions(+), 35 deletions(-) delete mode 100644 drivers/net/ethernet/wangxun/ngbe/ngbe.h diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe.h b/drivers/net/ethernet/wangxun/ngbe/ngbe.h deleted file mode 100644 index ed832ab3e5ed..000000000000 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright (c) 2019 - 2022 Beijing WangXun Technology Co., Ltd. */ - -#ifndef _NGBE_H_ -#define _NGBE_H_ - -#define NGBE_MAX_FDIR_INDICES 7 - -#define NGBE_MAX_RX_QUEUES (NGBE_MAX_FDIR_INDICES + 1) -#define NGBE_MAX_TX_QUEUES (NGBE_MAX_FDIR_INDICES + 1) - -#define NGBE_ETH_LENGTH_OF_ADDRESS 6 -#define NGBE_MAX_MSIX_VECTORS 0x09 -#define NGBE_RAR_ENTRIES 32 - -/* TX/RX descriptor defines */ -#define NGBE_DEFAULT_TXD 512 /* default ring size */ -#define NGBE_DEFAULT_TX_WORK 256 -#define NGBE_MAX_TXD 8192 -#define NGBE_MIN_TXD 128 - -#define NGBE_DEFAULT_RXD 512 /* default ring size */ -#define NGBE_DEFAULT_RX_WORK 256 -#define NGBE_MAX_RXD 8192 -#define NGBE_MIN_RXD 128 - -#define NGBE_MAC_STATE_DEFAULT 0x1 -#define NGBE_MAC_STATE_MODIFIED 0x2 -#define NGBE_MAC_STATE_IN_USE 0x4 - -extern char ngbe_driver_name[]; - -#endif /* _NGBE_H_ */ diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c index d54e22ce7c31..6e06a46fe9fa 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c @@ -9,7 +9,6 @@ #include "../libwx/wx_hw.h" #include "ngbe_type.h" #include "ngbe_hw.h" -#include "ngbe.h" int ngbe_eeprom_chksum_hostif(struct ngbe_adapter *adapter) { diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c index 5d679c39f451..f7cb482c8053 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c @@ -14,7 +14,7 @@ #include "../libwx/wx_hw.h" #include "ngbe_type.h" #include "ngbe_hw.h" -#include "ngbe.h" + char ngbe_driver_name[] = "ngbe"; /* ngbe_pci_tbl - PCI Device ID Table diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h b/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h index 5a64ce6ded8f..83e73cac2953 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h @@ -90,6 +90,30 @@ #define NGBE_FW_CMD_ST_PASS 0x80658383 #define NGBE_FW_CMD_ST_FAIL 0x70657376 +#define NGBE_MAX_FDIR_INDICES 7 + +#define NGBE_MAX_RX_QUEUES (NGBE_MAX_FDIR_INDICES + 1) +#define NGBE_MAX_TX_QUEUES (NGBE_MAX_FDIR_INDICES + 1) + +#define NGBE_ETH_LENGTH_OF_ADDRESS 6 +#define NGBE_MAX_MSIX_VECTORS 0x09 +#define NGBE_RAR_ENTRIES 32 + +/* TX/RX descriptor defines */ +#define NGBE_DEFAULT_TXD 512 /* default ring size */ +#define NGBE_DEFAULT_TX_WORK 256 +#define NGBE_MAX_TXD 8192 +#define NGBE_MIN_TXD 128 + +#define NGBE_DEFAULT_RXD 512 /* default ring size */ +#define NGBE_DEFAULT_RX_WORK 256 +#define NGBE_MAX_RXD 8192 +#define NGBE_MIN_RXD 128 + +#define NGBE_MAC_STATE_DEFAULT 0x1 +#define NGBE_MAC_STATE_MODIFIED 0x2 +#define NGBE_MAC_STATE_IN_USE 0x4 + enum ngbe_phy_type { ngbe_phy_unknown = 0, ngbe_phy_none, @@ -177,4 +201,6 @@ struct ngbe_adapter { u16 bd_number; }; +extern char ngbe_driver_name[]; + #endif /* _NGBE_TYPE_H_ */ From patchwork Wed Dec 14 06:41:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawen Wu X-Patchwork-Id: 13072807 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EBA0C4332F for ; Wed, 14 Dec 2022 06:45:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237405AbiLNGpg (ORCPT ); Wed, 14 Dec 2022 01:45:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237419AbiLNGpY (ORCPT ); Wed, 14 Dec 2022 01:45:24 -0500 Received: from smtpbgau2.qq.com (smtpbgau2.qq.com [54.206.34.216]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53CB7286CA for ; Tue, 13 Dec 2022 22:45:11 -0800 (PST) X-QQ-mid: bizesmtp70t1671000237t6lfb6vm Received: from wxdbg.localdomain.com ( [183.129.236.74]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 14 Dec 2022 14:43:56 +0800 (CST) X-QQ-SSF: 01400000000000H0X000B00A0000000 X-QQ-FEAT: +oIWmpEafD9saI4D9OFnjElal540QRfsrmpgcBd4mZ2JrsRavYthVEvnNUUSD z84Gmxt75/NYAh+MF6JC8OrpsuMyiGOrCB9LgEiwoHDNRd4vFYpGrLjpeLGtIp9aJ4j07XK uuAXKBkdAvHiEbeQPhR8vU4XVSJ3G+7T455sPNVFxYic0KhfxaYdMSAX+DTZyNKckC/JTyH swrzCNau5okxmk+cNpvExvkfFW4tbwen6vFNj/BXB163W9KQXq4IUDerUBImmRgp4Ap80au R4sVVhyXrvSpbjBckGu9xn9C0jSexQ3GrxjKHCaVffDZZQIL6ePse65QQ1CWxvAIJxfTF2E Ep/U/c2lVZpNCUH0Ju7AYnxOWmR7I2d/cmV8n0eYayQm9Ei5gJ2N8G5cdug6U3RaOgdzUYz lq1ZZyhO0G8= X-QQ-GoodBg: 2 From: Jiawen Wu To: netdev@vger.kernel.org, mengyuanlou@net-swift.com Cc: Jiawen Wu Subject: [PATCH net v2 5/5] net: wangxun: Move MAC address handling to libwx Date: Wed, 14 Dec 2022 14:41:33 +0800 Message-Id: <20221214064133.2424570-6-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20221214064133.2424570-1-jiawenwu@trustnetic.com> References: <20221214064133.2424570-1-jiawenwu@trustnetic.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybglogicsvr:qybglogicsvr5 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org For setting MAC address, both txgbe and ngbe drivers have the same handling flow with different parameters. Move the same codes to libwx. Signed-off-by: Jiawen Wu --- drivers/net/ethernet/wangxun/libwx/wx_hw.c | 116 +++++++++++++- drivers/net/ethernet/wangxun/libwx/wx_hw.h | 5 +- drivers/net/ethernet/wangxun/libwx/wx_type.h | 12 ++ drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 61 ++------ drivers/net/ethernet/wangxun/ngbe/ngbe_type.h | 11 -- .../net/ethernet/wangxun/txgbe/txgbe_main.c | 145 ++---------------- .../net/ethernet/wangxun/txgbe/txgbe_type.h | 12 +- 7 files changed, 150 insertions(+), 212 deletions(-) diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c index c57dc3238b3f..e04a394ddbe2 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c +++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c @@ -2,6 +2,7 @@ /* Copyright (c) 2015 - 2022 Beijing WangXun Technology Co., Ltd. */ #include +#include #include #include #include @@ -536,8 +537,8 @@ EXPORT_SYMBOL(wx_get_mac_addr); * * Puts an ethernet address into a receive address register. **/ -int wx_set_rar(struct wx_hw *wxhw, u32 index, u8 *addr, u64 pools, - u32 enable_addr) +static int wx_set_rar(struct wx_hw *wxhw, u32 index, u8 *addr, u64 pools, + u32 enable_addr) { u32 rar_entries = wxhw->mac.num_rar_entries; u32 rar_low, rar_high; @@ -581,7 +582,6 @@ int wx_set_rar(struct wx_hw *wxhw, u32 index, u8 *addr, u64 pools, return 0; } -EXPORT_SYMBOL(wx_set_rar); /** * wx_clear_rar - Remove Rx address register @@ -590,7 +590,7 @@ EXPORT_SYMBOL(wx_set_rar); * * Clears an ethernet address from a receive address register. **/ -int wx_clear_rar(struct wx_hw *wxhw, u32 index) +static int wx_clear_rar(struct wx_hw *wxhw, u32 index) { u32 rar_entries = wxhw->mac.num_rar_entries; @@ -618,7 +618,6 @@ int wx_clear_rar(struct wx_hw *wxhw, u32 index) return 0; } -EXPORT_SYMBOL(wx_clear_rar); /** * wx_clear_vmdq - Disassociate a VMDq pool index from a rx address @@ -722,6 +721,105 @@ void wx_init_rx_addrs(struct wx_hw *wxhw) } EXPORT_SYMBOL(wx_init_rx_addrs); +static void wx_sync_mac_table(struct wx_hw *wxhw) +{ + int i; + + for (i = 0; i < wxhw->mac.num_rar_entries; i++) { + if (wxhw->mac_table[i].state & WX_MAC_STATE_MODIFIED) { + if (wxhw->mac_table[i].state & WX_MAC_STATE_IN_USE) { + wx_set_rar(wxhw, i, + wxhw->mac_table[i].addr, + wxhw->mac_table[i].pools, + WX_PSR_MAC_SWC_AD_H_AV); + } else { + wx_clear_rar(wxhw, i); + } + wxhw->mac_table[i].state &= ~(WX_MAC_STATE_MODIFIED); + } + } +} + +/* this function destroys the first RAR entry */ +void wx_mac_set_default_filter(struct wx_hw *wxhw, u8 *addr) +{ + memcpy(&wxhw->mac_table[0].addr, addr, ETH_ALEN); + wxhw->mac_table[0].pools = 1ULL; + wxhw->mac_table[0].state = (WX_MAC_STATE_DEFAULT | WX_MAC_STATE_IN_USE); + wx_set_rar(wxhw, 0, wxhw->mac_table[0].addr, + wxhw->mac_table[0].pools, + WX_PSR_MAC_SWC_AD_H_AV); +} +EXPORT_SYMBOL(wx_mac_set_default_filter); + +void wx_flush_sw_mac_table(struct wx_hw *wxhw) +{ + u32 i; + + for (i = 0; i < wxhw->mac.num_rar_entries; i++) { + if (!(wxhw->mac_table[i].state & WX_MAC_STATE_IN_USE)) + continue; + + wxhw->mac_table[i].state |= WX_MAC_STATE_MODIFIED; + wxhw->mac_table[i].state &= ~WX_MAC_STATE_IN_USE; + memset(wxhw->mac_table[i].addr, 0, ETH_ALEN); + wxhw->mac_table[i].pools = 0; + } + wx_sync_mac_table(wxhw); +} +EXPORT_SYMBOL(wx_flush_sw_mac_table); + +static int wx_del_mac_filter(struct wx_hw *wxhw, u8 *addr, u16 pool) +{ + u32 i; + + if (is_zero_ether_addr(addr)) + return -EINVAL; + + /* search table for addr, if found, set to 0 and sync */ + for (i = 0; i < wxhw->mac.num_rar_entries; i++) { + if (!ether_addr_equal(addr, wxhw->mac_table[i].addr)) + continue; + + wxhw->mac_table[i].state |= WX_MAC_STATE_MODIFIED; + wxhw->mac_table[i].pools &= ~(1ULL << pool); + if (!wxhw->mac_table[i].pools) { + wxhw->mac_table[i].state &= ~WX_MAC_STATE_IN_USE; + memset(wxhw->mac_table[i].addr, 0, ETH_ALEN); + } + wx_sync_mac_table(wxhw); + return 0; + } + return -ENOMEM; +} + +/** + * wx_set_mac - Change the Ethernet Address of the NIC + * @netdev: network interface device structure + * @p: pointer to an address structure + * + * Returns 0 on success, negative on failure + **/ +int wx_set_mac(struct net_device *netdev, void *p) +{ + struct wx_hw *wxhw = container_of(&netdev, struct wx_hw, netdev); + struct sockaddr *addr = p; + int retval; + + retval = eth_prepare_mac_addr_change(netdev, addr); + if (retval) + return retval; + + wx_del_mac_filter(wxhw, wxhw->mac.addr, 0); + eth_hw_addr_set(netdev, addr->sa_data); + memcpy(wxhw->mac.addr, addr->sa_data, netdev->addr_len); + + wx_mac_set_default_filter(wxhw, wxhw->mac.addr); + + return 0; +} +EXPORT_SYMBOL(wx_set_mac); + void wx_disable_rx(struct wx_hw *wxhw) { u32 pfdtxgswc; @@ -929,6 +1027,14 @@ int wx_sw_init(struct wx_hw *wxhw) return err; } + wxhw->mac_table = kcalloc(wxhw->mac.num_rar_entries, + sizeof(struct wx_mac_addr), + GFP_KERNEL); + if (!wxhw->mac_table) { + wx_err(wxhw, "mac_table allocation failed\n"); + return -ENOMEM; + } + return 0; } EXPORT_SYMBOL(wx_sw_init); diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.h b/drivers/net/ethernet/wangxun/libwx/wx_hw.h index a0652f5e9939..5ac4ff78fd72 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_hw.h +++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.h @@ -15,9 +15,10 @@ int wx_read_ee_hostif_buffer(struct wx_hw *wxhw, int wx_reset_hostif(struct wx_hw *wxhw); void wx_init_eeprom_params(struct wx_hw *wxhw); void wx_get_mac_addr(struct wx_hw *wxhw, u8 *mac_addr); -int wx_set_rar(struct wx_hw *wxhw, u32 index, u8 *addr, u64 pools, u32 enable_addr); -int wx_clear_rar(struct wx_hw *wxhw, u32 index); void wx_init_rx_addrs(struct wx_hw *wxhw); +void wx_mac_set_default_filter(struct wx_hw *wxhw, u8 *addr); +void wx_flush_sw_mac_table(struct wx_hw *wxhw); +int wx_set_mac(struct net_device *netdev, void *p); void wx_disable_rx(struct wx_hw *wxhw); int wx_disable_pcie_master(struct wx_hw *wxhw); int wx_stop_adapter(struct wx_hw *wxhw); diff --git a/drivers/net/ethernet/wangxun/libwx/wx_type.h b/drivers/net/ethernet/wangxun/libwx/wx_type.h index 1cbeef8230bf..af7fd112aee4 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_type.h +++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h @@ -185,6 +185,10 @@ #define WX_SW_REGION_PTR 0x1C +#define WX_MAC_STATE_DEFAULT 0x1 +#define WX_MAC_STATE_MODIFIED 0x2 +#define WX_MAC_STATE_IN_USE 0x4 + /* Host Interface Command Structures */ struct wx_hic_hdr { u8 cmd; @@ -284,6 +288,12 @@ struct wx_addr_filter_info { bool user_set_promisc; }; +struct wx_mac_addr { + u8 addr[ETH_ALEN]; + u16 state; /* bitmask */ + u64 pools; +}; + enum wx_reset_type { WX_LAN_RESET = 0, WX_SW_RESET, @@ -293,10 +303,12 @@ enum wx_reset_type { struct wx_hw { u8 __iomem *hw_addr; struct pci_dev *pdev; + struct net_device *netdev; struct wx_bus_info bus; struct wx_mac_info mac; struct wx_eeprom_info eeprom; struct wx_addr_filter_info addr_ctrl; + struct wx_mac_addr *mac_table; u16 device_id; u16 vendor_id; u16 subsystem_device_id; diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c index f7cb482c8053..2af076489b5e 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c @@ -39,17 +39,6 @@ static const struct pci_device_id ngbe_pci_tbl[] = { { .device = 0 } }; -static void ngbe_mac_set_default_filter(struct ngbe_adapter *adapter, u8 *addr) -{ - memcpy(&adapter->mac_table[0].addr, addr, ETH_ALEN); - adapter->mac_table[0].pools = 1ULL; - adapter->mac_table[0].state = (NGBE_MAC_STATE_DEFAULT | - NGBE_MAC_STATE_IN_USE); - wx_set_rar(&adapter->wxhw, 0, adapter->mac_table[0].addr, - adapter->mac_table[0].pools, - WX_PSR_MAC_SWC_AD_H_AV); -} - /** * ngbe_init_type_code - Initialize the shared code * @adapter: pointer to hardware structure @@ -152,6 +141,10 @@ static int ngbe_sw_init(struct ngbe_adapter *adapter) wxhw->hw_addr = adapter->io_addr; wxhw->pdev = pdev; + wxhw->mac.num_rar_entries = NGBE_RAR_ENTRIES; + wxhw->mac.max_rx_queues = NGBE_MAX_RX_QUEUES; + wxhw->mac.max_tx_queues = NGBE_MAX_TX_QUEUES; + /* PCI config space info */ err = wx_sw_init(wxhw); if (err < 0) { @@ -163,25 +156,13 @@ static int ngbe_sw_init(struct ngbe_adapter *adapter) /* mac type, phy type , oem type */ ngbe_init_type_code(adapter); - wxhw->mac.max_rx_queues = NGBE_MAX_RX_QUEUES; - wxhw->mac.max_tx_queues = NGBE_MAX_TX_QUEUES; - wxhw->mac.num_rar_entries = NGBE_RAR_ENTRIES; /* Set common capability flags and settings */ adapter->max_q_vectors = NGBE_MAX_MSIX_VECTORS; - err = wx_get_pcie_msix_counts(wxhw, &msix_count, NGBE_MAX_MSIX_VECTORS); if (err) dev_err(&pdev->dev, "Do not support MSI-X\n"); wxhw->mac.max_msix_vectors = msix_count; - adapter->mac_table = kcalloc(wxhw->mac.num_rar_entries, - sizeof(struct ngbe_mac_addr), - GFP_KERNEL); - if (!adapter->mac_table) { - dev_err(&pdev->dev, "mac_table allocation failed: %d\n", err); - return -ENOMEM; - } - if (ngbe_init_rss_key(adapter)) return -ENOMEM; @@ -252,30 +233,6 @@ static netdev_tx_t ngbe_xmit_frame(struct sk_buff *skb, return NETDEV_TX_OK; } -/** - * ngbe_set_mac - Change the Ethernet Address of the NIC - * @netdev: network interface device structure - * @p: pointer to an address structure - * - * Returns 0 on success, negative on failure - **/ -static int ngbe_set_mac(struct net_device *netdev, void *p) -{ - struct ngbe_adapter *adapter = netdev_priv(netdev); - struct wx_hw *wxhw = &adapter->wxhw; - struct sockaddr *addr = p; - - if (!is_valid_ether_addr(addr->sa_data)) - return -EADDRNOTAVAIL; - - eth_hw_addr_set(netdev, addr->sa_data); - memcpy(wxhw->mac.addr, addr->sa_data, netdev->addr_len); - - ngbe_mac_set_default_filter(adapter, wxhw->mac.addr); - - return 0; -} - static void ngbe_dev_shutdown(struct pci_dev *pdev, bool *enable_wake) { struct ngbe_adapter *adapter = pci_get_drvdata(pdev); @@ -312,7 +269,7 @@ static const struct net_device_ops ngbe_netdev_ops = { .ndo_stop = ngbe_close, .ndo_start_xmit = ngbe_xmit_frame, .ndo_validate_addr = eth_validate_addr, - .ndo_set_mac_address = ngbe_set_mac, + .ndo_set_mac_address = wx_set_mac, }; /** @@ -377,6 +334,7 @@ static int ngbe_probe(struct pci_dev *pdev, adapter->netdev = netdev; adapter->pdev = pdev; wxhw = &adapter->wxhw; + wxhw->netdev = netdev; adapter->msg_enable = BIT(3) - 1; adapter->io_addr = devm_ioremap(&pdev->dev, @@ -463,7 +421,7 @@ static int ngbe_probe(struct pci_dev *pdev, } eth_hw_addr_set(netdev, wxhw->mac.perm_addr); - ngbe_mac_set_default_filter(adapter, wxhw->mac.perm_addr); + wx_mac_set_default_filter(wxhw, wxhw->mac.perm_addr); err = register_netdev(netdev); if (err) @@ -481,7 +439,7 @@ static int ngbe_probe(struct pci_dev *pdev, err_register: wx_control_hw(wxhw, false); err_free_mac_table: - kfree(adapter->mac_table); + kfree(wxhw->mac_table); err_pci_release_regions: pci_disable_pcie_error_reporting(pdev); pci_release_selected_regions(pdev, @@ -503,6 +461,7 @@ static int ngbe_probe(struct pci_dev *pdev, static void ngbe_remove(struct pci_dev *pdev) { struct ngbe_adapter *adapter = pci_get_drvdata(pdev); + struct wx_hw *wxhw = &adapter->wxhw; struct net_device *netdev; netdev = adapter->netdev; @@ -510,7 +469,7 @@ static void ngbe_remove(struct pci_dev *pdev) pci_release_selected_regions(pdev, pci_select_bars(pdev, IORESOURCE_MEM)); - kfree(adapter->mac_table); + kfree(wxhw->mac_table); pci_disable_pcie_error_reporting(pdev); pci_disable_device(pdev); diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h b/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h index 83e73cac2953..4b6c5006c0c6 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_type.h @@ -110,10 +110,6 @@ #define NGBE_MAX_RXD 8192 #define NGBE_MIN_RXD 128 -#define NGBE_MAC_STATE_DEFAULT 0x1 -#define NGBE_MAC_STATE_MODIFIED 0x2 -#define NGBE_MAC_STATE_IN_USE 0x4 - enum ngbe_phy_type { ngbe_phy_unknown = 0, ngbe_phy_none, @@ -151,12 +147,6 @@ struct ngbe_phy_info { }; -struct ngbe_mac_addr { - u8 addr[ETH_ALEN]; - u16 state; /* bitmask */ - u64 pools; -}; - /* board specific private data structure */ struct ngbe_adapter { u8 __iomem *io_addr; /* Mainly for iounmap use */ @@ -172,7 +162,6 @@ struct ngbe_adapter { bool ncsi_enabled; bool gpio_ctrl; - struct ngbe_mac_addr *mac_table; u16 msg_enable; /* Tx fast path data */ diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c index dcdf4e364979..e559c34b42cd 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c @@ -72,90 +72,6 @@ static int txgbe_enumerate_functions(struct txgbe_adapter *adapter) return physfns; } -static void txgbe_sync_mac_table(struct txgbe_adapter *adapter) -{ - struct wx_hw *wxhw = &adapter->wxhw; - int i; - - for (i = 0; i < wxhw->mac.num_rar_entries; i++) { - if (adapter->mac_table[i].state & TXGBE_MAC_STATE_MODIFIED) { - if (adapter->mac_table[i].state & TXGBE_MAC_STATE_IN_USE) { - wx_set_rar(wxhw, i, - adapter->mac_table[i].addr, - adapter->mac_table[i].pools, - WX_PSR_MAC_SWC_AD_H_AV); - } else { - wx_clear_rar(wxhw, i); - } - adapter->mac_table[i].state &= ~(TXGBE_MAC_STATE_MODIFIED); - } - } -} - -/* this function destroys the first RAR entry */ -static void txgbe_mac_set_default_filter(struct txgbe_adapter *adapter, - u8 *addr) -{ - struct wx_hw *wxhw = &adapter->wxhw; - - memcpy(&adapter->mac_table[0].addr, addr, ETH_ALEN); - adapter->mac_table[0].pools = 1ULL; - adapter->mac_table[0].state = (TXGBE_MAC_STATE_DEFAULT | - TXGBE_MAC_STATE_IN_USE); - wx_set_rar(wxhw, 0, adapter->mac_table[0].addr, - adapter->mac_table[0].pools, - WX_PSR_MAC_SWC_AD_H_AV); -} - -static void txgbe_flush_sw_mac_table(struct txgbe_adapter *adapter) -{ - struct wx_hw *wxhw = &adapter->wxhw; - u32 i; - - for (i = 0; i < wxhw->mac.num_rar_entries; i++) { - adapter->mac_table[i].state |= TXGBE_MAC_STATE_MODIFIED; - adapter->mac_table[i].state &= ~TXGBE_MAC_STATE_IN_USE; - memset(adapter->mac_table[i].addr, 0, ETH_ALEN); - adapter->mac_table[i].pools = 0; - } - txgbe_sync_mac_table(adapter); -} - -static int txgbe_del_mac_filter(struct txgbe_adapter *adapter, u8 *addr, u16 pool) -{ - struct wx_hw *wxhw = &adapter->wxhw; - u32 i; - - if (is_zero_ether_addr(addr)) - return -EINVAL; - - /* search table for addr, if found, set to 0 and sync */ - for (i = 0; i < wxhw->mac.num_rar_entries; i++) { - if (ether_addr_equal(addr, adapter->mac_table[i].addr)) { - if (adapter->mac_table[i].pools & (1ULL << pool)) { - adapter->mac_table[i].state |= TXGBE_MAC_STATE_MODIFIED; - adapter->mac_table[i].state &= ~TXGBE_MAC_STATE_IN_USE; - adapter->mac_table[i].pools &= ~(1ULL << pool); - txgbe_sync_mac_table(adapter); - } - return 0; - } - - if (adapter->mac_table[i].pools != (1 << pool)) - continue; - if (!ether_addr_equal(addr, adapter->mac_table[i].addr)) - continue; - - adapter->mac_table[i].state |= TXGBE_MAC_STATE_MODIFIED; - adapter->mac_table[i].state &= ~TXGBE_MAC_STATE_IN_USE; - memset(adapter->mac_table[i].addr, 0, ETH_ALEN); - adapter->mac_table[i].pools = 0; - txgbe_sync_mac_table(adapter); - return 0; - } - return -ENOMEM; -} - static void txgbe_up_complete(struct txgbe_adapter *adapter) { struct wx_hw *wxhw = &adapter->wxhw; @@ -175,9 +91,9 @@ static void txgbe_reset(struct txgbe_adapter *adapter) dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); /* do not flush user set addresses */ - memcpy(old_addr, &adapter->mac_table[0].addr, netdev->addr_len); - txgbe_flush_sw_mac_table(adapter); - txgbe_mac_set_default_filter(adapter, old_addr); + memcpy(old_addr, &wxhw->mac_table[0].addr, netdev->addr_len); + wx_flush_sw_mac_table(wxhw); + wx_mac_set_default_filter(wxhw, old_addr); } static void txgbe_disable_device(struct txgbe_adapter *adapter) @@ -228,6 +144,11 @@ static int txgbe_sw_init(struct txgbe_adapter *adapter) wxhw->hw_addr = adapter->io_addr; wxhw->pdev = pdev; + wxhw->mac.num_rar_entries = TXGBE_SP_RAR_ENTRIES; + wxhw->mac.max_tx_queues = TXGBE_SP_MAX_TX_QUEUES; + wxhw->mac.max_rx_queues = TXGBE_SP_MAX_RX_QUEUES; + wxhw->mac.mcft_size = TXGBE_SP_MC_TBL_SIZE; + /* PCI config space info */ err = wx_sw_init(wxhw); if (err < 0) { @@ -246,20 +167,6 @@ static int txgbe_sw_init(struct txgbe_adapter *adapter) break; } - wxhw->mac.num_rar_entries = TXGBE_SP_RAR_ENTRIES; - wxhw->mac.max_tx_queues = TXGBE_SP_MAX_TX_QUEUES; - wxhw->mac.max_rx_queues = TXGBE_SP_MAX_RX_QUEUES; - wxhw->mac.mcft_size = TXGBE_SP_MC_TBL_SIZE; - - adapter->mac_table = kcalloc(wxhw->mac.num_rar_entries, - sizeof(struct txgbe_mac_addr), - GFP_KERNEL); - if (!adapter->mac_table) { - netif_err(adapter, probe, adapter->netdev, - "mac_table allocation failed\n"); - return -ENOMEM; - } - return 0; } @@ -350,39 +257,12 @@ static netdev_tx_t txgbe_xmit_frame(struct sk_buff *skb, return NETDEV_TX_OK; } -/** - * txgbe_set_mac - Change the Ethernet Address of the NIC - * @netdev: network interface device structure - * @p: pointer to an address structure - * - * Returns 0 on success, negative on failure - **/ -static int txgbe_set_mac(struct net_device *netdev, void *p) -{ - struct txgbe_adapter *adapter = netdev_priv(netdev); - struct wx_hw *wxhw = &adapter->wxhw; - struct sockaddr *addr = p; - int retval; - - retval = eth_prepare_mac_addr_change(netdev, addr); - if (retval) - return retval; - - txgbe_del_mac_filter(adapter, wxhw->mac.addr, 0); - eth_hw_addr_set(netdev, addr->sa_data); - memcpy(wxhw->mac.addr, addr->sa_data, netdev->addr_len); - - txgbe_mac_set_default_filter(adapter, wxhw->mac.addr); - - return 0; -} - static const struct net_device_ops txgbe_netdev_ops = { .ndo_open = txgbe_open, .ndo_stop = txgbe_close, .ndo_start_xmit = txgbe_xmit_frame, .ndo_validate_addr = eth_validate_addr, - .ndo_set_mac_address = txgbe_set_mac, + .ndo_set_mac_address = wx_set_mac, }; /** @@ -448,6 +328,7 @@ static int txgbe_probe(struct pci_dev *pdev, adapter->netdev = netdev; adapter->pdev = pdev; wxhw = &adapter->wxhw; + wxhw->netdev = netdev; adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; adapter->io_addr = devm_ioremap(&pdev->dev, @@ -497,7 +378,7 @@ static int txgbe_probe(struct pci_dev *pdev, } eth_hw_addr_set(netdev, wxhw->mac.perm_addr); - txgbe_mac_set_default_filter(adapter, wxhw->mac.perm_addr); + wx_mac_set_default_filter(wxhw, wxhw->mac.perm_addr); /* Save off EEPROM version number and Option Rom version which * together make a unique identify for the eeprom @@ -569,7 +450,7 @@ static int txgbe_probe(struct pci_dev *pdev, err_release_hw: wx_control_hw(wxhw, false); err_free_mac_table: - kfree(adapter->mac_table); + kfree(wxhw->mac_table); err_pci_release_regions: pci_disable_pcie_error_reporting(pdev); pci_release_selected_regions(pdev, @@ -599,7 +480,7 @@ static void txgbe_remove(struct pci_dev *pdev) pci_release_selected_regions(pdev, pci_select_bars(pdev, IORESOURCE_MEM)); - kfree(adapter->mac_table); + kfree(adapter->wxhw.mac_table); pci_disable_pcie_error_reporting(pdev); diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h index c4d22ceeddad..ec8238ef234d 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h @@ -77,16 +77,6 @@ #define TXGBE_SP_RAR_ENTRIES 128 #define TXGBE_SP_MC_TBL_SIZE 128 -#define TXGBE_MAC_STATE_DEFAULT 0x1 -#define TXGBE_MAC_STATE_MODIFIED 0x2 -#define TXGBE_MAC_STATE_IN_USE 0x4 - -struct txgbe_mac_addr { - u8 addr[ETH_ALEN]; - u16 state; /* bitmask */ - u64 pools; -}; - /* board specific private data structure */ struct txgbe_adapter { u8 __iomem *io_addr; @@ -95,7 +85,7 @@ struct txgbe_adapter { struct pci_dev *pdev; struct wx_hw wxhw; u16 msg_enable; - struct txgbe_mac_addr *mac_table; + char eeprom_id[32]; };