Skip to content

Commit

Permalink
Merge branch 'net-wangxun-adjust-code-structure'
Browse files Browse the repository at this point in the history
Jiawen Wu says:

====================
net: wangxun: Adjust code structure

Remove useless structs 'txgbe_hw' and 'ngbe_hw' make the codes clear.
And move the same codes which sets MAC address between txgbe and ngbe
to libwx. Further more, rename struct 'wx_hw' to 'wx' and move total
adapter members to wx.
====================

Link: https://lore.kernel.org/r/20230106033853.2806007-1-jiawenwu@trustnetic.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Jan 7, 2023
2 parents 7abd92a + 803df55 commit f23395b
Show file tree
Hide file tree
Showing 13 changed files with 704 additions and 921 deletions.
504 changes: 305 additions & 199 deletions drivers/net/ethernet/wangxun/libwx/wx_hw.c

Large diffs are not rendered by default.

37 changes: 19 additions & 18 deletions drivers/net/ethernet/wangxun/libwx/wx_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
#ifndef _WX_HW_H_
#define _WX_HW_H_

int wx_check_flash_load(struct wx_hw *hw, u32 check_bit);
void wx_control_hw(struct wx_hw *wxhw, bool drv);
int wx_mng_present(struct wx_hw *wxhw);
int wx_host_interface_command(struct wx_hw *wxhw, u32 *buffer,
int wx_check_flash_load(struct wx *wx, u32 check_bit);
void wx_control_hw(struct wx *wx, bool drv);
int wx_mng_present(struct wx *wx);
int wx_host_interface_command(struct wx *wx, u32 *buffer,
u32 length, u32 timeout, bool return_data);
int wx_read_ee_hostif(struct wx_hw *wxhw, u16 offset, u16 *data);
int wx_read_ee_hostif_buffer(struct wx_hw *wxhw,
int wx_read_ee_hostif(struct wx *wx, u16 offset, u16 *data);
int wx_read_ee_hostif_buffer(struct wx *wx,
u16 offset, u16 words, u16 *data);
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_disable_rx(struct wx_hw *wxhw);
int wx_disable_pcie_master(struct wx_hw *wxhw);
int wx_stop_adapter(struct wx_hw *wxhw);
void wx_reset_misc(struct wx_hw *wxhw);
int wx_get_pcie_msix_counts(struct wx_hw *wxhw, u16 *msix_count, u16 max_msix_count);
int wx_sw_init(struct wx_hw *wxhw);
int wx_reset_hostif(struct wx *wx);
void wx_init_eeprom_params(struct wx *wx);
void wx_get_mac_addr(struct wx *wx, u8 *mac_addr);
void wx_init_rx_addrs(struct wx *wx);
void wx_mac_set_default_filter(struct wx *wx, u8 *addr);
void wx_flush_sw_mac_table(struct wx *wx);
int wx_set_mac(struct net_device *netdev, void *p);
void wx_disable_rx(struct wx *wx);
int wx_disable_pcie_master(struct wx *wx);
int wx_stop_adapter(struct wx *wx);
void wx_reset_misc(struct wx *wx);
int wx_get_pcie_msix_counts(struct wx *wx, u16 *msix_count, u16 max_msix_count);
int wx_sw_init(struct wx *wx);

#endif /* _WX_HW_H_ */
72 changes: 62 additions & 10 deletions drivers/net/ethernet/wangxun/libwx/wx_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@

#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

#define WX_CFG_PORT_ST 0x14404

/* Host Interface Command Structures */
struct wx_hic_hdr {
u8 cmd;
Expand Down Expand Up @@ -249,6 +255,12 @@ enum wx_mac_type {
wx_mac_em
};

enum em_mac_type {
em_mac_type_unknown = 0,
em_mac_type_mdi,
em_mac_type_rgmii
};

struct wx_mac_info {
enum wx_mac_type type;
bool set_lben;
Expand Down Expand Up @@ -284,28 +296,68 @@ 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,
WX_GLOBAL_RESET
};

struct wx_hw {
struct wx {
u8 __iomem *hw_addr;
struct pci_dev *pdev;
struct net_device *netdev;
struct wx_bus_info bus;
struct wx_mac_info mac;
enum em_mac_type mac_type;
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;
u16 subsystem_vendor_id;
u8 revision_id;
u16 oem_ssid;
u16 oem_svid;
u16 msg_enable;
bool adapter_stopped;
char eeprom_id[32];
enum wx_reset_type reset_type;

bool wol_enabled;
bool ncsi_enabled;
bool gpio_ctrl;

/* 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 WX_MAX_RETA_ENTRIES 128
u8 rss_indir_tbl[WX_MAX_RETA_ENTRIES];

#define WX_RSS_KEY_SIZE 40 /* size of RSS Hash Key in bytes */
u32 *rss_key;
u32 wol;

u16 bd_number;
};

#define WX_INTR_ALL (~0ULL)
Expand All @@ -319,34 +371,34 @@ struct wx_hw {
wr32((a), (reg) + ((off) << 2), (val))

static inline u32
rd32m(struct wx_hw *wxhw, u32 reg, u32 mask)
rd32m(struct wx *wx, u32 reg, u32 mask)
{
u32 val;

val = rd32(wxhw, reg);
val = rd32(wx, reg);
return val & mask;
}

static inline void
wr32m(struct wx_hw *wxhw, u32 reg, u32 mask, u32 field)
wr32m(struct wx *wx, u32 reg, u32 mask, u32 field)
{
u32 val;

val = rd32(wxhw, reg);
val = rd32(wx, reg);
val = ((val & ~mask) | (field & mask));

wr32(wxhw, reg, val);
wr32(wx, reg, val);
}

/* On some domestic CPU platforms, sometimes IO is not synchronized with
* flushing memory, here use readl() to flush PCI read and write.
*/
#define WX_WRITE_FLUSH(H) rd32(H, WX_MIS_PWR)

#define wx_err(wxhw, fmt, arg...) \
dev_err(&(wxhw)->pdev->dev, fmt, ##arg)
#define wx_err(wx, fmt, arg...) \
dev_err(&(wx)->pdev->dev, fmt, ##arg)

#define wx_dbg(wxhw, fmt, arg...) \
dev_dbg(&(wxhw)->pdev->dev, fmt, ##arg)
#define wx_dbg(wx, fmt, arg...) \
dev_dbg(&(wx)->pdev->dev, fmt, ##arg)

#endif /* _WX_TYPE_H_ */
79 changes: 0 additions & 79 deletions drivers/net/ethernet/wangxun/ngbe/ngbe.h

This file was deleted.

47 changes: 21 additions & 26 deletions drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
#include "../libwx/wx_hw.h"
#include "ngbe_type.h"
#include "ngbe_hw.h"
#include "ngbe.h"

int ngbe_eeprom_chksum_hostif(struct ngbe_hw *hw)
int ngbe_eeprom_chksum_hostif(struct wx *wx)
{
struct wx_hic_read_shadow_ram buffer;
struct wx_hw *wxhw = &hw->wxhw;
int status;
int tmp;

Expand All @@ -27,61 +25,58 @@ int ngbe_eeprom_chksum_hostif(struct ngbe_hw *hw)
/* one word */
buffer.length = 0;

status = wx_host_interface_command(wxhw, (u32 *)&buffer, sizeof(buffer),
status = wx_host_interface_command(wx, (u32 *)&buffer, sizeof(buffer),
WX_HI_COMMAND_TIMEOUT, false);

if (status < 0)
return status;
tmp = rd32a(wxhw, WX_MNG_MBOX, 1);
tmp = rd32a(wx, WX_MNG_MBOX, 1);
if (tmp == NGBE_FW_CMD_ST_PASS)
return 0;
return -EIO;
}

static int ngbe_reset_misc(struct ngbe_hw *hw)
static int ngbe_reset_misc(struct wx *wx)
{
struct wx_hw *wxhw = &hw->wxhw;

wx_reset_misc(wxhw);
if (hw->mac_type == ngbe_mac_type_rgmii)
wr32(wxhw, NGBE_MDIO_CLAUSE_SELECT, 0xF);
if (hw->gpio_ctrl) {
wx_reset_misc(wx);
if (wx->mac_type == em_mac_type_rgmii)
wr32(wx, NGBE_MDIO_CLAUSE_SELECT, 0xF);
if (wx->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);
wr32(wx, NGBE_GPIO_DDR, 0x1);
wr32(wx, NGBE_GPIO_DR, NGBE_GPIO_DR_0);
}
return 0;
}

/**
* ngbe_reset_hw - Perform hardware reset
* @hw: pointer to hardware structure
* @wx: 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 wx *wx)
{
struct wx_hw *wxhw = &hw->wxhw;
int status = 0;
u32 reset = 0;

/* Call adapter stop to disable tx/rx and clear interrupts */
status = wx_stop_adapter(wxhw);
/* Call wx stop to disable tx/rx and clear interrupts */
status = wx_stop_adapter(wx);
if (status != 0)
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);
reset = WX_MIS_RST_LAN_RST(wx->bus.func);
wr32(wx, WX_MIS_RST, reset | rd32(wx, WX_MIS_RST));
ngbe_reset_misc(wx);

/* Store the permanent mac address */
wx_get_mac_addr(wxhw, wxhw->mac.perm_addr);
wx_get_mac_addr(wx, wx->mac.perm_addr);

/* reset num_rar_entries to 128 */
wxhw->mac.num_rar_entries = NGBE_RAR_ENTRIES;
wx_init_rx_addrs(wxhw);
pci_set_master(wxhw->pdev);
wx->mac.num_rar_entries = NGBE_RAR_ENTRIES;
wx_init_rx_addrs(wx);
pci_set_master(wx->pdev);

return 0;
}
4 changes: 2 additions & 2 deletions drivers/net/ethernet/wangxun/ngbe/ngbe_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 wx *wx);
int ngbe_reset_hw(struct wx *wx);
#endif /* _NGBE_HW_H_ */
Loading

0 comments on commit f23395b

Please sign in to comment.