Commit 65b342f1 authored by David S. Miller's avatar David S. Miller

Merge branch 'Aquantia-atlantic-driver-new-devices-support'

Igor Russkikh says:

====================
Aquantia atlantic driver new devices support

This patchset introduces a support for new Aquantia hardware:
AQC11x family with updated hardware (B1) and firmware (2.x and 3.x branches).

For that, a number of improvements in overall driver model were done:
 - Firmware specific ops tables. Firmware 2.x and 3.x series support
   functions are now in separate fw2x module.
 - PCI module cleanup and simplification done.
 - Verified and tested hardware reset process.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents f9b6ae29 6de97c04
...@@ -39,4 +39,5 @@ atlantic-objs := aq_main.o \ ...@@ -39,4 +39,5 @@ atlantic-objs := aq_main.o \
hw_atl/hw_atl_a0.o \ hw_atl/hw_atl_a0.o \
hw_atl/hw_atl_b0.o \ hw_atl/hw_atl_b0.o \
hw_atl/hw_atl_utils.o \ hw_atl/hw_atl_utils.o \
hw_atl/hw_atl_utils_fw2x.o \
hw_atl/hw_atl_llh.o hw_atl/hw_atl_llh.o
...@@ -65,7 +65,13 @@ ...@@ -65,7 +65,13 @@
/*#define AQ_CFG_MAC_ADDR_PERMANENT {0x30, 0x0E, 0xE3, 0x12, 0x34, 0x56}*/ /*#define AQ_CFG_MAC_ADDR_PERMANENT {0x30, 0x0E, 0xE3, 0x12, 0x34, 0x56}*/
#define AQ_CFG_FC_MODE 3U #define AQ_NIC_FC_OFF 0U
#define AQ_NIC_FC_TX 1U
#define AQ_NIC_FC_RX 2U
#define AQ_NIC_FC_FULL 3U
#define AQ_NIC_FC_AUTO 4U
#define AQ_CFG_FC_MODE AQ_NIC_FC_FULL
#define AQ_CFG_SPEED_MSK 0xFFFFU /* 0xFFFFU==auto_neg */ #define AQ_CFG_SPEED_MSK 0xFFFFU /* 0xFFFFU==auto_neg */
......
...@@ -19,4 +19,42 @@ ...@@ -19,4 +19,42 @@
#include "aq_cfg.h" #include "aq_cfg.h"
#include "aq_utils.h" #include "aq_utils.h"
#define PCI_VENDOR_ID_AQUANTIA 0x1D6A
#define AQ_DEVICE_ID_0001 0x0001
#define AQ_DEVICE_ID_D100 0xD100
#define AQ_DEVICE_ID_D107 0xD107
#define AQ_DEVICE_ID_D108 0xD108
#define AQ_DEVICE_ID_D109 0xD109
#define AQ_DEVICE_ID_AQC100 0x00B1
#define AQ_DEVICE_ID_AQC107 0x07B1
#define AQ_DEVICE_ID_AQC108 0x08B1
#define AQ_DEVICE_ID_AQC109 0x09B1
#define AQ_DEVICE_ID_AQC111 0x11B1
#define AQ_DEVICE_ID_AQC112 0x12B1
#define AQ_DEVICE_ID_AQC100S 0x80B1
#define AQ_DEVICE_ID_AQC107S 0x87B1
#define AQ_DEVICE_ID_AQC108S 0x88B1
#define AQ_DEVICE_ID_AQC109S 0x89B1
#define AQ_DEVICE_ID_AQC111S 0x91B1
#define AQ_DEVICE_ID_AQC112S 0x92B1
#define AQ_DEVICE_ID_AQC111E 0x51B1
#define AQ_DEVICE_ID_AQC112E 0x52B1
#define HW_ATL_NIC_NAME "aQuantia AQtion 10Gbit Network Adapter"
#define AQ_HWREV_ANY 0
#define AQ_HWREV_1 1
#define AQ_HWREV_2 2
#define AQ_NIC_RATE_10G BIT(0)
#define AQ_NIC_RATE_5G BIT(1)
#define AQ_NIC_RATE_5GSR BIT(2)
#define AQ_NIC_RATE_2GS BIT(3)
#define AQ_NIC_RATE_1G BIT(4)
#define AQ_NIC_RATE_100M BIT(5)
#endif /* AQ_COMMON_H */ #endif /* AQ_COMMON_H */
...@@ -23,6 +23,7 @@ struct aq_hw_caps_s { ...@@ -23,6 +23,7 @@ struct aq_hw_caps_s {
u64 hw_features; u64 hw_features;
u64 link_speed_msk; u64 link_speed_msk;
unsigned int hw_priv_flags; unsigned int hw_priv_flags;
u32 media_type;
u32 rxds; u32 rxds;
u32 txds; u32 txds;
u32 txhwb_alignment; u32 txhwb_alignment;
...@@ -30,7 +31,7 @@ struct aq_hw_caps_s { ...@@ -30,7 +31,7 @@ struct aq_hw_caps_s {
u32 vecs; u32 vecs;
u32 mtu; u32 mtu;
u32 mac_regs_count; u32 mac_regs_count;
u8 ports; u32 hw_alive_check_addr;
u8 msix_irqs; u8 msix_irqs;
u8 tcs; u8 tcs;
u8 rxd_alignment; u8 rxd_alignment;
...@@ -41,7 +42,6 @@ struct aq_hw_caps_s { ...@@ -41,7 +42,6 @@ struct aq_hw_caps_s {
u8 rx_rings; u8 rx_rings;
bool flow_control; bool flow_control;
bool is_64_dma; bool is_64_dma;
u32 fw_ver_expected;
}; };
struct aq_hw_link_status_s { struct aq_hw_link_status_s {
...@@ -95,12 +95,15 @@ struct aq_stats_s { ...@@ -95,12 +95,15 @@ struct aq_stats_s {
#define AQ_NIC_FLAGS_IS_NOT_TX_READY (AQ_NIC_FLAGS_IS_NOT_READY | \ #define AQ_NIC_FLAGS_IS_NOT_TX_READY (AQ_NIC_FLAGS_IS_NOT_READY | \
AQ_NIC_LINK_DOWN) AQ_NIC_LINK_DOWN)
#define AQ_HW_MEDIA_TYPE_TP 1U
#define AQ_HW_MEDIA_TYPE_FIBRE 2U
struct aq_hw_s { struct aq_hw_s {
atomic_t flags; atomic_t flags;
u8 rbl_enabled:1;
struct aq_nic_cfg_s *aq_nic_cfg; struct aq_nic_cfg_s *aq_nic_cfg;
struct aq_pci_func_s *aq_pci_func; const struct aq_fw_ops *aq_fw_ops;
void __iomem *mmio; void __iomem *mmio;
unsigned int not_ff_addr;
struct aq_hw_link_status_s aq_link_status; struct aq_hw_link_status_s aq_link_status;
struct hw_aq_atl_utils_mbox mbox; struct hw_aq_atl_utils_mbox mbox;
struct hw_atl_stats_s last_stats; struct hw_atl_stats_s last_stats;
...@@ -119,19 +122,9 @@ struct aq_hw_s { ...@@ -119,19 +122,9 @@ struct aq_hw_s {
struct aq_ring_s; struct aq_ring_s;
struct aq_ring_param_s; struct aq_ring_param_s;
struct aq_nic_cfg_s;
struct sk_buff; struct sk_buff;
struct aq_hw_ops { struct aq_hw_ops {
struct aq_hw_s *(*create)(struct aq_pci_func_s *aq_pci_func,
unsigned int port);
void (*destroy)(struct aq_hw_s *self);
int (*get_hw_caps)(struct aq_hw_s *self,
struct aq_hw_caps_s *aq_hw_caps,
unsigned short device,
unsigned short subsystem_device);
int (*hw_ring_tx_xmit)(struct aq_hw_s *self, struct aq_ring_s *aq_ring, int (*hw_ring_tx_xmit)(struct aq_hw_s *self, struct aq_ring_s *aq_ring,
unsigned int frags); unsigned int frags);
...@@ -145,15 +138,8 @@ struct aq_hw_ops { ...@@ -145,15 +138,8 @@ struct aq_hw_ops {
int (*hw_ring_tx_head_update)(struct aq_hw_s *self, int (*hw_ring_tx_head_update)(struct aq_hw_s *self,
struct aq_ring_s *aq_ring); struct aq_ring_s *aq_ring);
int (*hw_get_mac_permanent)(struct aq_hw_s *self,
u8 *mac);
int (*hw_set_mac_address)(struct aq_hw_s *self, u8 *mac_addr); int (*hw_set_mac_address)(struct aq_hw_s *self, u8 *mac_addr);
int (*hw_get_link_status)(struct aq_hw_s *self);
int (*hw_set_link_speed)(struct aq_hw_s *self, u32 speed);
int (*hw_reset)(struct aq_hw_s *self); int (*hw_reset)(struct aq_hw_s *self);
int (*hw_init)(struct aq_hw_s *self, u8 *mac_addr); int (*hw_init)(struct aq_hw_s *self, u8 *mac_addr);
...@@ -207,8 +193,6 @@ struct aq_hw_ops { ...@@ -207,8 +193,6 @@ struct aq_hw_ops {
const struct aq_hw_caps_s *aq_hw_caps, const struct aq_hw_caps_s *aq_hw_caps,
u32 *regs_buff); u32 *regs_buff);
int (*hw_update_stats)(struct aq_hw_s *self);
struct aq_stats_s *(*hw_get_hw_stats)(struct aq_hw_s *self); struct aq_stats_s *(*hw_get_hw_stats)(struct aq_hw_s *self);
int (*hw_get_fw_version)(struct aq_hw_s *self, u32 *fw_version); int (*hw_get_fw_version)(struct aq_hw_s *self, u32 *fw_version);
...@@ -218,4 +202,20 @@ struct aq_hw_ops { ...@@ -218,4 +202,20 @@ struct aq_hw_ops {
int (*hw_set_power)(struct aq_hw_s *self, unsigned int power_state); int (*hw_set_power)(struct aq_hw_s *self, unsigned int power_state);
}; };
struct aq_fw_ops {
int (*init)(struct aq_hw_s *self);
int (*reset)(struct aq_hw_s *self);
int (*get_mac_permanent)(struct aq_hw_s *self, u8 *mac);
int (*set_link_speed)(struct aq_hw_s *self, u32 speed);
int (*set_state)(struct aq_hw_s *self, enum hal_atl_utils_fw_state_e state);
int (*update_link_status)(struct aq_hw_s *self);
int (*update_stats)(struct aq_hw_s *self);
};
#endif /* AQ_HW_H */ #endif /* AQ_HW_H */
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "aq_hw_utils.h" #include "aq_hw_utils.h"
#include "aq_hw.h" #include "aq_hw.h"
#include "aq_nic.h"
void aq_hw_write_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk, void aq_hw_write_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk,
u32 shift, u32 val) u32 shift, u32 val)
...@@ -39,7 +40,9 @@ u32 aq_hw_read_reg(struct aq_hw_s *hw, u32 reg) ...@@ -39,7 +40,9 @@ u32 aq_hw_read_reg(struct aq_hw_s *hw, u32 reg)
{ {
u32 value = readl(hw->mmio + reg); u32 value = readl(hw->mmio + reg);
if ((~0U) == value && (~0U) == readl(hw->mmio + hw->not_ff_addr)) if ((~0U) == value &&
(~0U) == readl(hw->mmio +
hw->aq_nic_cfg->aq_hw_caps->hw_alive_check_addr))
aq_utils_obj_set(&hw->flags, AQ_HW_FLAG_ERR_UNPLUG); aq_utils_obj_set(&hw->flags, AQ_HW_FLAG_ERR_UNPLUG);
return value; return value;
......
...@@ -35,6 +35,9 @@ do { \ ...@@ -35,6 +35,9 @@ do { \
} \ } \
} while (0) } while (0)
#define aq_pr_err(...) pr_err(AQ_CFG_DRV_NAME ": " __VA_ARGS__)
#define aq_pr_trace(...) pr_info(AQ_CFG_DRV_NAME ": " __VA_ARGS__)
struct aq_hw_s; struct aq_hw_s;
void aq_hw_write_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk, void aq_hw_write_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk,
......
...@@ -43,14 +43,9 @@ struct net_device *aq_ndev_alloc(void) ...@@ -43,14 +43,9 @@ struct net_device *aq_ndev_alloc(void)
static int aq_ndev_open(struct net_device *ndev) static int aq_ndev_open(struct net_device *ndev)
{ {
struct aq_nic_s *aq_nic = NULL;
int err = 0; int err = 0;
struct aq_nic_s *aq_nic = netdev_priv(ndev);
aq_nic = aq_nic_alloc_hot(ndev);
if (!aq_nic) {
err = -ENOMEM;
goto err_exit;
}
err = aq_nic_init(aq_nic); err = aq_nic_init(aq_nic);
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
...@@ -73,7 +68,6 @@ static int aq_ndev_close(struct net_device *ndev) ...@@ -73,7 +68,6 @@ static int aq_ndev_close(struct net_device *ndev)
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
aq_nic_deinit(aq_nic); aq_nic_deinit(aq_nic);
aq_nic_free_hot_resources(aq_nic);
err_exit: err_exit:
return err; return err;
...@@ -145,15 +139,13 @@ static void aq_ndev_set_multicast_settings(struct net_device *ndev) ...@@ -145,15 +139,13 @@ static void aq_ndev_set_multicast_settings(struct net_device *ndev)
err = aq_nic_set_packet_filter(aq_nic, ndev->flags); err = aq_nic_set_packet_filter(aq_nic, ndev->flags);
if (err < 0) if (err < 0)
goto err_exit; return;
if (netdev_mc_count(ndev)) { if (netdev_mc_count(ndev)) {
err = aq_nic_set_multicast_list(aq_nic, ndev); err = aq_nic_set_multicast_list(aq_nic, ndev);
if (err < 0) if (err < 0)
goto err_exit; return;
} }
err_exit:;
} }
static const struct net_device_ops aq_ndev_ops = { static const struct net_device_ops aq_ndev_ops = {
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "aq_vec.h" #include "aq_vec.h"
#include "aq_hw.h" #include "aq_hw.h"
#include "aq_pci_func.h" #include "aq_pci_func.h"
#include "aq_main.h"
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
...@@ -61,19 +60,13 @@ static void aq_nic_rss_init(struct aq_nic_s *self, unsigned int num_rss_queues) ...@@ -61,19 +60,13 @@ static void aq_nic_rss_init(struct aq_nic_s *self, unsigned int num_rss_queues)
rss_params->indirection_table[i] = i & (num_rss_queues - 1); rss_params->indirection_table[i] = i & (num_rss_queues - 1);
} }
/* Fills aq_nic_cfg with valid defaults */ /* Checks hw_caps and 'corrects' aq_nic_cfg in runtime */
static void aq_nic_cfg_init_defaults(struct aq_nic_s *self) void aq_nic_cfg_start(struct aq_nic_s *self)
{ {
struct aq_nic_cfg_s *cfg = &self->aq_nic_cfg; struct aq_nic_cfg_s *cfg = &self->aq_nic_cfg;
cfg->aq_hw_caps = &self->aq_hw_caps;
cfg->vecs = AQ_CFG_VECS_DEF;
cfg->tcs = AQ_CFG_TCS_DEF; cfg->tcs = AQ_CFG_TCS_DEF;
cfg->rxds = AQ_CFG_RXDS_DEF;
cfg->txds = AQ_CFG_TXDS_DEF;
cfg->is_polling = AQ_CFG_IS_POLLING_DEF; cfg->is_polling = AQ_CFG_IS_POLLING_DEF;
cfg->itr = aq_itr; cfg->itr = aq_itr;
...@@ -94,19 +87,13 @@ static void aq_nic_cfg_init_defaults(struct aq_nic_s *self) ...@@ -94,19 +87,13 @@ static void aq_nic_cfg_init_defaults(struct aq_nic_s *self)
cfg->vlan_id = 0U; cfg->vlan_id = 0U;
aq_nic_rss_init(self, cfg->num_rss_queues); aq_nic_rss_init(self, cfg->num_rss_queues);
}
/* Checks hw_caps and 'corrects' aq_nic_cfg in runtime */
int aq_nic_cfg_start(struct aq_nic_s *self)
{
struct aq_nic_cfg_s *cfg = &self->aq_nic_cfg;
/*descriptors */ /*descriptors */
cfg->rxds = min(cfg->rxds, cfg->aq_hw_caps->rxds); cfg->rxds = min(cfg->aq_hw_caps->rxds, AQ_CFG_RXDS_DEF);
cfg->txds = min(cfg->txds, cfg->aq_hw_caps->txds); cfg->txds = min(cfg->aq_hw_caps->txds, AQ_CFG_TXDS_DEF);
/*rss rings */ /*rss rings */
cfg->vecs = min(cfg->vecs, cfg->aq_hw_caps->vecs); cfg->vecs = min(cfg->aq_hw_caps->vecs, AQ_CFG_VECS_DEF);
cfg->vecs = min(cfg->vecs, num_online_cpus()); cfg->vecs = min(cfg->vecs, num_online_cpus());
/* cfg->vecs should be power of 2 for RSS */ /* cfg->vecs should be power of 2 for RSS */
if (cfg->vecs >= 8U) if (cfg->vecs >= 8U)
...@@ -120,23 +107,22 @@ int aq_nic_cfg_start(struct aq_nic_s *self) ...@@ -120,23 +107,22 @@ int aq_nic_cfg_start(struct aq_nic_s *self)
cfg->num_rss_queues = min(cfg->vecs, AQ_CFG_NUM_RSS_QUEUES_DEF); cfg->num_rss_queues = min(cfg->vecs, AQ_CFG_NUM_RSS_QUEUES_DEF);
cfg->irq_type = aq_pci_func_get_irq_type(self->aq_pci_func); cfg->irq_type = aq_pci_func_get_irq_type(self);
if ((cfg->irq_type == AQ_HW_IRQ_LEGACY) || if ((cfg->irq_type == AQ_HW_IRQ_LEGACY) ||
(self->aq_hw_caps.vecs == 1U) || (cfg->aq_hw_caps->vecs == 1U) ||
(cfg->vecs == 1U)) { (cfg->vecs == 1U)) {
cfg->is_rss = 0U; cfg->is_rss = 0U;
cfg->vecs = 1U; cfg->vecs = 1U;
} }
cfg->link_speed_msk &= self->aq_hw_caps.link_speed_msk; cfg->link_speed_msk &= cfg->aq_hw_caps->link_speed_msk;
cfg->hw_features = self->aq_hw_caps.hw_features; cfg->hw_features = cfg->aq_hw_caps->hw_features;
return 0;
} }
static int aq_nic_update_link_status(struct aq_nic_s *self) static int aq_nic_update_link_status(struct aq_nic_s *self)
{ {
int err = self->aq_hw_ops.hw_get_link_status(self->aq_hw); int err = self->aq_fw_ops->update_link_status(self->aq_hw);
if (err) if (err)
return err; return err;
...@@ -178,8 +164,8 @@ static void aq_nic_service_timer_cb(struct timer_list *t) ...@@ -178,8 +164,8 @@ static void aq_nic_service_timer_cb(struct timer_list *t)
if (err) if (err)
goto err_exit; goto err_exit;
if (self->aq_hw_ops.hw_update_stats) if (self->aq_fw_ops->update_stats)
self->aq_hw_ops.hw_update_stats(self->aq_hw); self->aq_fw_ops->update_stats(self->aq_hw);
aq_nic_update_ndev_stats(self); aq_nic_update_ndev_stats(self);
...@@ -205,51 +191,6 @@ static void aq_nic_polling_timer_cb(struct timer_list *t) ...@@ -205,51 +191,6 @@ static void aq_nic_polling_timer_cb(struct timer_list *t)
AQ_CFG_POLLING_TIMER_INTERVAL); AQ_CFG_POLLING_TIMER_INTERVAL);
} }
struct aq_nic_s *aq_nic_alloc_cold(struct pci_dev *pdev,
struct aq_pci_func_s *aq_pci_func,
unsigned int port,
const struct aq_hw_ops *aq_hw_ops)
{
struct net_device *ndev = NULL;
struct aq_nic_s *self = NULL;
int err = 0;
ndev = aq_ndev_alloc();
if (!ndev) {
err = -ENOMEM;
goto err_exit;
}
self = netdev_priv(ndev);
SET_NETDEV_DEV(ndev, &pdev->dev);
ndev->if_port = port;
self->ndev = ndev;
self->aq_pci_func = aq_pci_func;
self->aq_hw_ops = *aq_hw_ops;
self->port = (u8)port;
self->aq_hw = self->aq_hw_ops.create(aq_pci_func, self->port);
self->aq_hw->aq_nic_cfg = &self->aq_nic_cfg;
err = self->aq_hw_ops.get_hw_caps(self->aq_hw, &self->aq_hw_caps,
pdev->device, pdev->subsystem_device);
if (err < 0)
goto err_exit;
aq_nic_cfg_init_defaults(self);
err_exit:
if (err < 0) {
aq_nic_free_hot_resources(self);
self = NULL;
}
return self;
}
int aq_nic_ndev_register(struct aq_nic_s *self) int aq_nic_ndev_register(struct aq_nic_s *self)
{ {
int err = 0; int err = 0;
...@@ -258,9 +199,14 @@ int aq_nic_ndev_register(struct aq_nic_s *self) ...@@ -258,9 +199,14 @@ int aq_nic_ndev_register(struct aq_nic_s *self)
err = -EINVAL; err = -EINVAL;
goto err_exit; goto err_exit;
} }
err = self->aq_hw_ops.hw_get_mac_permanent(self->aq_hw,
err = hw_atl_utils_initfw(self->aq_hw, &self->aq_fw_ops);
if (err)
goto err_exit;
err = self->aq_fw_ops->get_mac_permanent(self->aq_hw,
self->ndev->dev_addr); self->ndev->dev_addr);
if (err < 0) if (err)
goto err_exit; goto err_exit;
#if defined(AQ_CFG_MAC_ADDR_PERMANENT) #if defined(AQ_CFG_MAC_ADDR_PERMANENT)
...@@ -271,19 +217,29 @@ int aq_nic_ndev_register(struct aq_nic_s *self) ...@@ -271,19 +217,29 @@ int aq_nic_ndev_register(struct aq_nic_s *self)
} }
#endif #endif
for (self->aq_vecs = 0; self->aq_vecs < aq_nic_get_cfg(self)->vecs;
self->aq_vecs++) {
self->aq_vec[self->aq_vecs] =
aq_vec_alloc(self, self->aq_vecs, aq_nic_get_cfg(self));
if (!self->aq_vec[self->aq_vecs]) {
err = -ENOMEM;
goto err_exit;
}
}
netif_carrier_off(self->ndev); netif_carrier_off(self->ndev);
netif_tx_disable(self->ndev); netif_tx_disable(self->ndev);
err = register_netdev(self->ndev); err = register_netdev(self->ndev);
if (err < 0) if (err)
goto err_exit; goto err_exit;
err_exit: err_exit:
return err; return err;
} }
int aq_nic_ndev_init(struct aq_nic_s *self) void aq_nic_ndev_init(struct aq_nic_s *self)
{ {
const struct aq_hw_caps_s *aq_hw_caps = self->aq_nic_cfg.aq_hw_caps; const struct aq_hw_caps_s *aq_hw_caps = self->aq_nic_cfg.aq_hw_caps;
struct aq_nic_cfg_s *aq_nic_cfg = &self->aq_nic_cfg; struct aq_nic_cfg_s *aq_nic_cfg = &self->aq_nic_cfg;
...@@ -292,62 +248,8 @@ int aq_nic_ndev_init(struct aq_nic_s *self) ...@@ -292,62 +248,8 @@ int aq_nic_ndev_init(struct aq_nic_s *self)
self->ndev->features = aq_hw_caps->hw_features; self->ndev->features = aq_hw_caps->hw_features;
self->ndev->priv_flags = aq_hw_caps->hw_priv_flags; self->ndev->priv_flags = aq_hw_caps->hw_priv_flags;
self->ndev->mtu = aq_nic_cfg->mtu - ETH_HLEN; self->ndev->mtu = aq_nic_cfg->mtu - ETH_HLEN;
self->ndev->max_mtu = self->aq_hw_caps.mtu - ETH_FCS_LEN - ETH_HLEN; self->ndev->max_mtu = aq_hw_caps->mtu - ETH_FCS_LEN - ETH_HLEN;
return 0;
}
void aq_nic_ndev_free(struct aq_nic_s *self)
{
if (!self->ndev)
goto err_exit;
if (self->ndev->reg_state == NETREG_REGISTERED)
unregister_netdev(self->ndev);
if (self->aq_hw)
self->aq_hw_ops.destroy(self->aq_hw);
free_netdev(self->ndev);
err_exit:;
}
struct aq_nic_s *aq_nic_alloc_hot(struct net_device *ndev)
{
struct aq_nic_s *self = NULL;
int err = 0;
if (!ndev) {
err = -EINVAL;
goto err_exit;
}
self = netdev_priv(ndev);
if (!self) {
err = -EINVAL;
goto err_exit;
}
if (netif_running(ndev))
netif_tx_disable(ndev);
netif_carrier_off(self->ndev);
for (self->aq_vecs = 0; self->aq_vecs < self->aq_nic_cfg.vecs;
self->aq_vecs++) {
self->aq_vec[self->aq_vecs] =
aq_vec_alloc(self, self->aq_vecs, &self->aq_nic_cfg);
if (!self->aq_vec[self->aq_vecs]) {
err = -ENOMEM;
goto err_exit;
}
}
err_exit:
if (err < 0) {
aq_nic_free_hot_resources(self);
self = NULL;
}
return self;
} }
void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx, void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx,
...@@ -368,18 +270,20 @@ int aq_nic_init(struct aq_nic_s *self) ...@@ -368,18 +270,20 @@ int aq_nic_init(struct aq_nic_s *self)
unsigned int i = 0U; unsigned int i = 0U;
self->power_state = AQ_HW_POWER_STATE_D0; self->power_state = AQ_HW_POWER_STATE_D0;
err = self->aq_hw_ops.hw_reset(self->aq_hw); err = self->aq_hw_ops->hw_reset(self->aq_hw);
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
err = self->aq_hw_ops.hw_init(self->aq_hw, err = self->aq_hw_ops->hw_init(self->aq_hw,
aq_nic_get_ndev(self)->dev_addr); aq_nic_get_ndev(self)->dev_addr);
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
for (i = 0U, aq_vec = self->aq_vec[0]; for (i = 0U, aq_vec = self->aq_vec[0];
self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i])
aq_vec_init(aq_vec, &self->aq_hw_ops, self->aq_hw); aq_vec_init(aq_vec, self->aq_hw_ops, self->aq_hw);
netif_carrier_off(self->ndev);
err_exit: err_exit:
return err; return err;
...@@ -391,13 +295,13 @@ int aq_nic_start(struct aq_nic_s *self) ...@@ -391,13 +295,13 @@ int aq_nic_start(struct aq_nic_s *self)
int err = 0; int err = 0;
unsigned int i = 0U; unsigned int i = 0U;
err = self->aq_hw_ops.hw_multicast_list_set(self->aq_hw, err = self->aq_hw_ops->hw_multicast_list_set(self->aq_hw,
self->mc_list.ar, self->mc_list.ar,
self->mc_list.count); self->mc_list.count);
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
err = self->aq_hw_ops.hw_packet_filter_set(self->aq_hw, err = self->aq_hw_ops->hw_packet_filter_set(self->aq_hw,
self->packet_filter); self->packet_filter);
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
...@@ -409,7 +313,7 @@ int aq_nic_start(struct aq_nic_s *self) ...@@ -409,7 +313,7 @@ int aq_nic_start(struct aq_nic_s *self)
goto err_exit; goto err_exit;
} }
err = self->aq_hw_ops.hw_start(self->aq_hw); err = self->aq_hw_ops->hw_start(self->aq_hw);
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
...@@ -427,14 +331,14 @@ int aq_nic_start(struct aq_nic_s *self) ...@@ -427,14 +331,14 @@ int aq_nic_start(struct aq_nic_s *self)
} else { } else {
for (i = 0U, aq_vec = self->aq_vec[0]; for (i = 0U, aq_vec = self->aq_vec[0];
self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) { self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) {
err = aq_pci_func_alloc_irq(self->aq_pci_func, i, err = aq_pci_func_alloc_irq(self, i,
self->ndev->name, aq_vec, self->ndev->name, aq_vec,
aq_vec_get_affinity_mask(aq_vec)); aq_vec_get_affinity_mask(aq_vec));
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
} }
err = self->aq_hw_ops.hw_irq_enable(self->aq_hw, err = self->aq_hw_ops->hw_irq_enable(self->aq_hw,
AQ_CFG_IRQ_MASK); AQ_CFG_IRQ_MASK);
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
...@@ -619,9 +523,8 @@ int aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb) ...@@ -619,9 +523,8 @@ int aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb)
frags = aq_nic_map_skb(self, skb, ring); frags = aq_nic_map_skb(self, skb, ring);
if (likely(frags)) { if (likely(frags)) {
err = self->aq_hw_ops.hw_ring_tx_xmit(self->aq_hw, err = self->aq_hw_ops->hw_ring_tx_xmit(self->aq_hw,
ring, ring, frags);
frags);
if (err >= 0) { if (err >= 0) {
++ring->stats.tx.packets; ++ring->stats.tx.packets;
ring->stats.tx.bytes += skb->len; ring->stats.tx.bytes += skb->len;
...@@ -636,14 +539,14 @@ int aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb) ...@@ -636,14 +539,14 @@ int aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb)
int aq_nic_update_interrupt_moderation_settings(struct aq_nic_s *self) int aq_nic_update_interrupt_moderation_settings(struct aq_nic_s *self)
{ {
return self->aq_hw_ops.hw_interrupt_moderation_set(self->aq_hw); return self->aq_hw_ops->hw_interrupt_moderation_set(self->aq_hw);
} }
int aq_nic_set_packet_filter(struct aq_nic_s *self, unsigned int flags) int aq_nic_set_packet_filter(struct aq_nic_s *self, unsigned int flags)
{ {
int err = 0; int err = 0;
err = self->aq_hw_ops.hw_packet_filter_set(self->aq_hw, flags); err = self->aq_hw_ops->hw_packet_filter_set(self->aq_hw, flags);
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
...@@ -675,11 +578,11 @@ int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev) ...@@ -675,11 +578,11 @@ int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev)
* multicast mask * multicast mask
*/ */
self->packet_filter |= IFF_ALLMULTI; self->packet_filter |= IFF_ALLMULTI;
self->aq_hw->aq_nic_cfg->mc_list_count = 0; self->aq_nic_cfg.mc_list_count = 0;
return self->aq_hw_ops.hw_packet_filter_set(self->aq_hw, return self->aq_hw_ops->hw_packet_filter_set(self->aq_hw,
self->packet_filter); self->packet_filter);
} else { } else {
return self->aq_hw_ops.hw_multicast_list_set(self->aq_hw, return self->aq_hw_ops->hw_multicast_list_set(self->aq_hw,
self->mc_list.ar, self->mc_list.ar,
self->mc_list.count); self->mc_list.count);
} }
...@@ -694,7 +597,7 @@ int aq_nic_set_mtu(struct aq_nic_s *self, int new_mtu) ...@@ -694,7 +597,7 @@ int aq_nic_set_mtu(struct aq_nic_s *self, int new_mtu)
int aq_nic_set_mac(struct aq_nic_s *self, struct net_device *ndev) int aq_nic_set_mac(struct aq_nic_s *self, struct net_device *ndev)
{ {
return self->aq_hw_ops.hw_set_mac_address(self->aq_hw, ndev->dev_addr); return self->aq_hw_ops->hw_set_mac_address(self->aq_hw, ndev->dev_addr);
} }
unsigned int aq_nic_get_link_speed(struct aq_nic_s *self) unsigned int aq_nic_get_link_speed(struct aq_nic_s *self)
...@@ -709,8 +612,9 @@ int aq_nic_get_regs(struct aq_nic_s *self, struct ethtool_regs *regs, void *p) ...@@ -709,8 +612,9 @@ int aq_nic_get_regs(struct aq_nic_s *self, struct ethtool_regs *regs, void *p)
regs->version = 1; regs->version = 1;
err = self->aq_hw_ops.hw_get_regs(self->aq_hw, err = self->aq_hw_ops->hw_get_regs(self->aq_hw,
&self->aq_hw_caps, regs_buff); self->aq_nic_cfg.aq_hw_caps,
regs_buff);
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
...@@ -720,7 +624,7 @@ int aq_nic_get_regs(struct aq_nic_s *self, struct ethtool_regs *regs, void *p) ...@@ -720,7 +624,7 @@ int aq_nic_get_regs(struct aq_nic_s *self, struct ethtool_regs *regs, void *p)
int aq_nic_get_regs_count(struct aq_nic_s *self) int aq_nic_get_regs_count(struct aq_nic_s *self)
{ {
return self->aq_hw_caps.mac_regs_count; return self->aq_nic_cfg.aq_hw_caps->mac_regs_count;
} }
void aq_nic_get_stats(struct aq_nic_s *self, u64 *data) void aq_nic_get_stats(struct aq_nic_s *self, u64 *data)
...@@ -728,7 +632,7 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data) ...@@ -728,7 +632,7 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data)
unsigned int i = 0U; unsigned int i = 0U;
unsigned int count = 0U; unsigned int count = 0U;
struct aq_vec_s *aq_vec = NULL; struct aq_vec_s *aq_vec = NULL;
struct aq_stats_s *stats = self->aq_hw_ops.hw_get_hw_stats(self->aq_hw); struct aq_stats_s *stats = self->aq_hw_ops->hw_get_hw_stats(self->aq_hw);
if (!stats) if (!stats)
goto err_exit; goto err_exit;
...@@ -759,7 +663,6 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data) ...@@ -759,7 +663,6 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data)
i++; i++;
data += i; data += i;
count = 0U;
for (i = 0U, aq_vec = self->aq_vec[0]; for (i = 0U, aq_vec = self->aq_vec[0];
aq_vec && self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) { aq_vec && self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) {
...@@ -773,7 +676,7 @@ err_exit:; ...@@ -773,7 +676,7 @@ err_exit:;
static void aq_nic_update_ndev_stats(struct aq_nic_s *self) static void aq_nic_update_ndev_stats(struct aq_nic_s *self)
{ {
struct net_device *ndev = self->ndev; struct net_device *ndev = self->ndev;
struct aq_stats_s *stats = self->aq_hw_ops.hw_get_hw_stats(self->aq_hw); struct aq_stats_s *stats = self->aq_hw_ops->hw_get_hw_stats(self->aq_hw);
ndev->stats.rx_packets = stats->uprc + stats->mprc + stats->bprc; ndev->stats.rx_packets = stats->uprc + stats->mprc + stats->bprc;
ndev->stats.rx_bytes = stats->ubrc + stats->mbrc + stats->bbrc; ndev->stats.rx_bytes = stats->ubrc + stats->mbrc + stats->bbrc;
...@@ -787,6 +690,9 @@ static void aq_nic_update_ndev_stats(struct aq_nic_s *self) ...@@ -787,6 +690,9 @@ static void aq_nic_update_ndev_stats(struct aq_nic_s *self)
void aq_nic_get_link_ksettings(struct aq_nic_s *self, void aq_nic_get_link_ksettings(struct aq_nic_s *self,
struct ethtool_link_ksettings *cmd) struct ethtool_link_ksettings *cmd)
{ {
if (self->aq_nic_cfg.aq_hw_caps->media_type == AQ_HW_MEDIA_TYPE_FIBRE)
cmd->base.port = PORT_FIBRE;
else
cmd->base.port = PORT_TP; cmd->base.port = PORT_TP;
/* This driver supports only 10G capable adapters, so DUPLEX_FULL */ /* This driver supports only 10G capable adapters, so DUPLEX_FULL */
cmd->base.duplex = DUPLEX_FULL; cmd->base.duplex = DUPLEX_FULL;
...@@ -794,31 +700,35 @@ void aq_nic_get_link_ksettings(struct aq_nic_s *self, ...@@ -794,31 +700,35 @@ void aq_nic_get_link_ksettings(struct aq_nic_s *self,
ethtool_link_ksettings_zero_link_mode(cmd, supported); ethtool_link_ksettings_zero_link_mode(cmd, supported);
if (self->aq_hw_caps.link_speed_msk & AQ_NIC_RATE_10G) if (self->aq_nic_cfg.aq_hw_caps->link_speed_msk & AQ_NIC_RATE_10G)
ethtool_link_ksettings_add_link_mode(cmd, supported, ethtool_link_ksettings_add_link_mode(cmd, supported,
10000baseT_Full); 10000baseT_Full);
if (self->aq_hw_caps.link_speed_msk & AQ_NIC_RATE_5G) if (self->aq_nic_cfg.aq_hw_caps->link_speed_msk & AQ_NIC_RATE_5G)
ethtool_link_ksettings_add_link_mode(cmd, supported, ethtool_link_ksettings_add_link_mode(cmd, supported,
5000baseT_Full); 5000baseT_Full);
if (self->aq_hw_caps.link_speed_msk & AQ_NIC_RATE_2GS) if (self->aq_nic_cfg.aq_hw_caps->link_speed_msk & AQ_NIC_RATE_2GS)
ethtool_link_ksettings_add_link_mode(cmd, supported, ethtool_link_ksettings_add_link_mode(cmd, supported,
2500baseT_Full); 2500baseT_Full);
if (self->aq_hw_caps.link_speed_msk & AQ_NIC_RATE_1G) if (self->aq_nic_cfg.aq_hw_caps->link_speed_msk & AQ_NIC_RATE_1G)
ethtool_link_ksettings_add_link_mode(cmd, supported, ethtool_link_ksettings_add_link_mode(cmd, supported,
1000baseT_Full); 1000baseT_Full);
if (self->aq_hw_caps.link_speed_msk & AQ_NIC_RATE_100M) if (self->aq_nic_cfg.aq_hw_caps->link_speed_msk & AQ_NIC_RATE_100M)
ethtool_link_ksettings_add_link_mode(cmd, supported, ethtool_link_ksettings_add_link_mode(cmd, supported,
100baseT_Full); 100baseT_Full);
if (self->aq_hw_caps.flow_control) if (self->aq_nic_cfg.aq_hw_caps->flow_control)
ethtool_link_ksettings_add_link_mode(cmd, supported, ethtool_link_ksettings_add_link_mode(cmd, supported,
Pause); Pause);
ethtool_link_ksettings_add_link_mode(cmd, supported, Autoneg); ethtool_link_ksettings_add_link_mode(cmd, supported, Autoneg);
if (self->aq_nic_cfg.aq_hw_caps->media_type == AQ_HW_MEDIA_TYPE_FIBRE)
ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
else
ethtool_link_ksettings_add_link_mode(cmd, supported, TP); ethtool_link_ksettings_add_link_mode(cmd, supported, TP);
ethtool_link_ksettings_zero_link_mode(cmd, advertising); ethtool_link_ksettings_zero_link_mode(cmd, advertising);
...@@ -850,6 +760,9 @@ void aq_nic_get_link_ksettings(struct aq_nic_s *self, ...@@ -850,6 +760,9 @@ void aq_nic_get_link_ksettings(struct aq_nic_s *self,
ethtool_link_ksettings_add_link_mode(cmd, advertising, ethtool_link_ksettings_add_link_mode(cmd, advertising,
Pause); Pause);
if (self->aq_nic_cfg.aq_hw_caps->media_type == AQ_HW_MEDIA_TYPE_FIBRE)
ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
else
ethtool_link_ksettings_add_link_mode(cmd, advertising, TP); ethtool_link_ksettings_add_link_mode(cmd, advertising, TP);
} }
...@@ -861,7 +774,7 @@ int aq_nic_set_link_ksettings(struct aq_nic_s *self, ...@@ -861,7 +774,7 @@ int aq_nic_set_link_ksettings(struct aq_nic_s *self,
int err = 0; int err = 0;
if (cmd->base.autoneg == AUTONEG_ENABLE) { if (cmd->base.autoneg == AUTONEG_ENABLE) {
rate = self->aq_hw_caps.link_speed_msk; rate = self->aq_nic_cfg.aq_hw_caps->link_speed_msk;
self->aq_nic_cfg.is_autoneg = true; self->aq_nic_cfg.is_autoneg = true;
} else { } else {
speed = cmd->base.speed; speed = cmd->base.speed;
...@@ -892,7 +805,7 @@ int aq_nic_set_link_ksettings(struct aq_nic_s *self, ...@@ -892,7 +805,7 @@ int aq_nic_set_link_ksettings(struct aq_nic_s *self,
goto err_exit; goto err_exit;
break; break;
} }
if (!(self->aq_hw_caps.link_speed_msk & rate)) { if (!(self->aq_nic_cfg.aq_hw_caps->link_speed_msk & rate)) {
err = -1; err = -1;
goto err_exit; goto err_exit;
} }
...@@ -900,7 +813,7 @@ int aq_nic_set_link_ksettings(struct aq_nic_s *self, ...@@ -900,7 +813,7 @@ int aq_nic_set_link_ksettings(struct aq_nic_s *self,
self->aq_nic_cfg.is_autoneg = false; self->aq_nic_cfg.is_autoneg = false;
} }
err = self->aq_hw_ops.hw_set_link_speed(self->aq_hw, rate); err = self->aq_fw_ops->set_link_speed(self->aq_hw, rate);
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
...@@ -919,7 +832,7 @@ u32 aq_nic_get_fw_version(struct aq_nic_s *self) ...@@ -919,7 +832,7 @@ u32 aq_nic_get_fw_version(struct aq_nic_s *self)
{ {
u32 fw_version = 0U; u32 fw_version = 0U;
self->aq_hw_ops.hw_get_fw_version(self->aq_hw, &fw_version); self->aq_hw_ops->hw_get_fw_version(self->aq_hw, &fw_version);
return fw_version; return fw_version;
} }
...@@ -934,18 +847,18 @@ int aq_nic_stop(struct aq_nic_s *self) ...@@ -934,18 +847,18 @@ int aq_nic_stop(struct aq_nic_s *self)
del_timer_sync(&self->service_timer); del_timer_sync(&self->service_timer);
self->aq_hw_ops.hw_irq_disable(self->aq_hw, AQ_CFG_IRQ_MASK); self->aq_hw_ops->hw_irq_disable(self->aq_hw, AQ_CFG_IRQ_MASK);
if (self->aq_nic_cfg.is_polling) if (self->aq_nic_cfg.is_polling)
del_timer_sync(&self->polling_timer); del_timer_sync(&self->polling_timer);
else else
aq_pci_func_free_irqs(self->aq_pci_func); aq_pci_func_free_irqs(self);
for (i = 0U, aq_vec = self->aq_vec[0]; for (i = 0U, aq_vec = self->aq_vec[0];
self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i])
aq_vec_stop(aq_vec); aq_vec_stop(aq_vec);
return self->aq_hw_ops.hw_stop(self->aq_hw); return self->aq_hw_ops->hw_stop(self->aq_hw);
} }
void aq_nic_deinit(struct aq_nic_s *self) void aq_nic_deinit(struct aq_nic_s *self)
...@@ -961,16 +874,16 @@ void aq_nic_deinit(struct aq_nic_s *self) ...@@ -961,16 +874,16 @@ void aq_nic_deinit(struct aq_nic_s *self)
aq_vec_deinit(aq_vec); aq_vec_deinit(aq_vec);
if (self->power_state == AQ_HW_POWER_STATE_D0) { if (self->power_state == AQ_HW_POWER_STATE_D0) {
(void)self->aq_hw_ops.hw_deinit(self->aq_hw); (void)self->aq_hw_ops->hw_deinit(self->aq_hw);
} else { } else {
(void)self->aq_hw_ops.hw_set_power(self->aq_hw, (void)self->aq_hw_ops->hw_set_power(self->aq_hw,
self->power_state); self->power_state);
} }
err_exit:; err_exit:;
} }
void aq_nic_free_hot_resources(struct aq_nic_s *self) void aq_nic_free_vectors(struct aq_nic_s *self)
{ {
unsigned int i = 0U; unsigned int i = 0U;
......
...@@ -17,24 +17,10 @@ ...@@ -17,24 +17,10 @@
#include "aq_hw.h" #include "aq_hw.h"
struct aq_ring_s; struct aq_ring_s;
struct aq_pci_func_s;
struct aq_hw_ops; struct aq_hw_ops;
struct aq_fw_s; struct aq_fw_s;
struct aq_vec_s; struct aq_vec_s;
#define AQ_NIC_FC_OFF 0U
#define AQ_NIC_FC_TX 1U
#define AQ_NIC_FC_RX 2U
#define AQ_NIC_FC_FULL 3U
#define AQ_NIC_FC_AUTO 4U
#define AQ_NIC_RATE_10G BIT(0)
#define AQ_NIC_RATE_5G BIT(1)
#define AQ_NIC_RATE_5GSR BIT(2)
#define AQ_NIC_RATE_2GS BIT(3)
#define AQ_NIC_RATE_1G BIT(4)
#define AQ_NIC_RATE_100M BIT(5)
struct aq_nic_cfg_s { struct aq_nic_cfg_s {
const struct aq_hw_caps_s *aq_hw_caps; const struct aq_hw_caps_s *aq_hw_caps;
u64 hw_features; u64 hw_features;
...@@ -77,13 +63,12 @@ struct aq_nic_s { ...@@ -77,13 +63,12 @@ struct aq_nic_s {
struct aq_ring_s *aq_ring_tx[AQ_CFG_VECS_MAX * AQ_CFG_TCS_MAX]; struct aq_ring_s *aq_ring_tx[AQ_CFG_VECS_MAX * AQ_CFG_TCS_MAX];
struct aq_hw_s *aq_hw; struct aq_hw_s *aq_hw;
struct net_device *ndev; struct net_device *ndev;
struct aq_pci_func_s *aq_pci_func;
unsigned int aq_vecs; unsigned int aq_vecs;
unsigned int packet_filter; unsigned int packet_filter;
unsigned int power_state; unsigned int power_state;
u8 port; u8 port;
struct aq_hw_ops aq_hw_ops; const struct aq_hw_ops *aq_hw_ops;
struct aq_hw_caps_s aq_hw_caps; const struct aq_fw_ops *aq_fw_ops;
struct aq_nic_cfg_s aq_nic_cfg; struct aq_nic_cfg_s aq_nic_cfg;
struct timer_list service_timer; struct timer_list service_timer;
struct timer_list polling_timer; struct timer_list polling_timer;
...@@ -102,18 +87,13 @@ static inline struct device *aq_nic_get_dev(struct aq_nic_s *self) ...@@ -102,18 +87,13 @@ static inline struct device *aq_nic_get_dev(struct aq_nic_s *self)
return self->ndev->dev.parent; return self->ndev->dev.parent;
} }
struct aq_nic_s *aq_nic_alloc_cold(struct pci_dev *pdev, void aq_nic_ndev_init(struct aq_nic_s *self);
struct aq_pci_func_s *aq_pci_func,
unsigned int port,
const struct aq_hw_ops *aq_hw_ops);
int aq_nic_ndev_init(struct aq_nic_s *self);
struct aq_nic_s *aq_nic_alloc_hot(struct net_device *ndev); struct aq_nic_s *aq_nic_alloc_hot(struct net_device *ndev);
void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx, void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx,
struct aq_ring_s *ring); struct aq_ring_s *ring);
struct device *aq_nic_get_dev(struct aq_nic_s *self);
struct net_device *aq_nic_get_ndev(struct aq_nic_s *self); struct net_device *aq_nic_get_ndev(struct aq_nic_s *self);
int aq_nic_init(struct aq_nic_s *self); int aq_nic_init(struct aq_nic_s *self);
int aq_nic_cfg_start(struct aq_nic_s *self); void aq_nic_cfg_start(struct aq_nic_s *self);
int aq_nic_ndev_register(struct aq_nic_s *self); int aq_nic_ndev_register(struct aq_nic_s *self);
void aq_nic_ndev_free(struct aq_nic_s *self); void aq_nic_ndev_free(struct aq_nic_s *self);
int aq_nic_start(struct aq_nic_s *self); int aq_nic_start(struct aq_nic_s *self);
...@@ -124,6 +104,7 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data); ...@@ -124,6 +104,7 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data);
int aq_nic_stop(struct aq_nic_s *self); int aq_nic_stop(struct aq_nic_s *self);
void aq_nic_deinit(struct aq_nic_s *self); void aq_nic_deinit(struct aq_nic_s *self);
void aq_nic_free_hot_resources(struct aq_nic_s *self); void aq_nic_free_hot_resources(struct aq_nic_s *self);
void aq_nic_free_vectors(struct aq_nic_s *self);
int aq_nic_set_mtu(struct aq_nic_s *self, int new_mtu); int aq_nic_set_mtu(struct aq_nic_s *self, int new_mtu);
int aq_nic_set_mac(struct aq_nic_s *self, struct net_device *ndev); int aq_nic_set_mac(struct aq_nic_s *self, struct net_device *ndev);
int aq_nic_set_packet_filter(struct aq_nic_s *self, unsigned int flags); int aq_nic_set_packet_filter(struct aq_nic_s *self, unsigned int flags);
......
...@@ -12,201 +12,132 @@ ...@@ -12,201 +12,132 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/module.h> #include <linux/module.h>
#include "aq_pci_func.h" #include "aq_main.h"
#include "aq_nic.h" #include "aq_nic.h"
#include "aq_vec.h" #include "aq_vec.h"
#include "aq_hw.h" #include "aq_hw.h"
#include "aq_pci_func.h"
#include "hw_atl/hw_atl_a0.h" #include "hw_atl/hw_atl_a0.h"
#include "hw_atl/hw_atl_b0.h" #include "hw_atl/hw_atl_b0.h"
struct aq_pci_func_s {
struct pci_dev *pdev;
struct aq_nic_s *port[AQ_CFG_PCI_FUNC_PORTS];
void __iomem *mmio;
void *aq_vec[AQ_CFG_PCI_FUNC_MSIX_IRQS];
resource_size_t mmio_pa;
unsigned int msix_entry_mask;
unsigned int ports;
bool is_pci_enabled;
bool is_regions;
bool is_pci_using_dac;
struct aq_hw_caps_s aq_hw_caps;
};
static const struct pci_device_id aq_pci_tbl[] = { static const struct pci_device_id aq_pci_tbl[] = {
{ PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_0001), }, { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_0001), },
{ PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D100), }, { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_D100), },
{ PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D107), }, { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_D107), },
{ PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D108), }, { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_D108), },
{ PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D109), }, { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_D109), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC100), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC107), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC108), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC109), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC111), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC112), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC100S), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC107S), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC108S), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC109S), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC111S), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC112S), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC111E), },
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC112E), },
{} {}
}; };
MODULE_DEVICE_TABLE(pci, aq_pci_tbl); const struct aq_board_revision_s hw_atl_boards[] = {
{ AQ_DEVICE_ID_0001, AQ_HWREV_1, &hw_atl_ops_a0, &hw_atl_a0_caps_aqc107, },
static const struct aq_hw_ops *aq_pci_probe_get_hw_ops_by_id(struct pci_dev *pdev) { AQ_DEVICE_ID_D100, AQ_HWREV_1, &hw_atl_ops_a0, &hw_atl_a0_caps_aqc100, },
{ { AQ_DEVICE_ID_D107, AQ_HWREV_1, &hw_atl_ops_a0, &hw_atl_a0_caps_aqc107, },
const struct aq_hw_ops *ops = NULL; { AQ_DEVICE_ID_D108, AQ_HWREV_1, &hw_atl_ops_a0, &hw_atl_a0_caps_aqc108, },
{ AQ_DEVICE_ID_D109, AQ_HWREV_1, &hw_atl_ops_a0, &hw_atl_a0_caps_aqc109, },
ops = hw_atl_a0_get_ops_by_id(pdev);
if (!ops) { AQ_DEVICE_ID_0001, AQ_HWREV_2, &hw_atl_ops_b0, &hw_atl_b0_caps_aqc107, },
ops = hw_atl_b0_get_ops_by_id(pdev); { AQ_DEVICE_ID_D100, AQ_HWREV_2, &hw_atl_ops_b0, &hw_atl_b0_caps_aqc100, },
{ AQ_DEVICE_ID_D107, AQ_HWREV_2, &hw_atl_ops_b0, &hw_atl_b0_caps_aqc107, },
{ AQ_DEVICE_ID_D108, AQ_HWREV_2, &hw_atl_ops_b0, &hw_atl_b0_caps_aqc108, },
{ AQ_DEVICE_ID_D109, AQ_HWREV_2, &hw_atl_ops_b0, &hw_atl_b0_caps_aqc109, },
{ AQ_DEVICE_ID_AQC100, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc107, },
{ AQ_DEVICE_ID_AQC107, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc107, },
{ AQ_DEVICE_ID_AQC108, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc108, },
{ AQ_DEVICE_ID_AQC109, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc109, },
{ AQ_DEVICE_ID_AQC111, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc111, },
{ AQ_DEVICE_ID_AQC112, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc112, },
{ AQ_DEVICE_ID_AQC100S, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc100s, },
{ AQ_DEVICE_ID_AQC107S, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc107s, },
{ AQ_DEVICE_ID_AQC108S, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc108s, },
{ AQ_DEVICE_ID_AQC109S, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc109s, },
{ AQ_DEVICE_ID_AQC111S, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc111s, },
{ AQ_DEVICE_ID_AQC112S, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc112s, },
{ AQ_DEVICE_ID_AQC111E, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc111e, },
{ AQ_DEVICE_ID_AQC112E, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc112e, },
};
return ops; MODULE_DEVICE_TABLE(pci, aq_pci_tbl);
}
struct aq_pci_func_s *aq_pci_func_alloc(const struct aq_hw_ops *aq_hw_ops, static int aq_pci_probe_get_hw_by_id(struct pci_dev *pdev,
struct pci_dev *pdev) const struct aq_hw_ops **ops,
const struct aq_hw_caps_s **caps)
{ {
struct aq_pci_func_s *self = NULL; int i = 0;
int err = 0;
unsigned int port = 0U;
if (!aq_hw_ops) {
err = -EFAULT;
goto err_exit;
}
self = kzalloc(sizeof(*self), GFP_KERNEL);
if (!self) {
err = -ENOMEM;
goto err_exit;
}
pci_set_drvdata(pdev, self); if (pdev->vendor != PCI_VENDOR_ID_AQUANTIA)
self->pdev = pdev; return -EINVAL;
err = aq_hw_ops->get_hw_caps(NULL, &self->aq_hw_caps, pdev->device, for (i = 0; i < ARRAY_SIZE(hw_atl_boards); i++) {
pdev->subsystem_device); if (hw_atl_boards[i].devid == pdev->device &&
if (err < 0) (hw_atl_boards[i].revision == AQ_HWREV_ANY ||
goto err_exit; hw_atl_boards[i].revision == pdev->revision)) {
*ops = hw_atl_boards[i].ops;
self->ports = self->aq_hw_caps.ports; *caps = hw_atl_boards[i].caps;
break;
for (port = 0; port < self->ports; ++port) {
struct aq_nic_s *aq_nic = aq_nic_alloc_cold(pdev, self,
port, aq_hw_ops);
if (!aq_nic) {
err = -ENOMEM;
goto err_exit;
} }
self->port[port] = aq_nic;
} }
err_exit: if (i == ARRAY_SIZE(hw_atl_boards))
if (err < 0) { return -EINVAL;
if (self)
aq_pci_func_free(self);
self = NULL;
}
(void)err; return 0;
return self;
} }
int aq_pci_func_init(struct aq_pci_func_s *self) int aq_pci_func_init(struct pci_dev *pdev)
{ {
int err = 0; int err = 0;
unsigned int bar = 0U;
unsigned int port = 0U;
unsigned int numvecs = 0U;
err = pci_enable_device(self->pdev); err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
if (err < 0)
goto err_exit;
self->is_pci_enabled = true;
err = pci_set_dma_mask(self->pdev, DMA_BIT_MASK(64));
if (!err) { if (!err) {
err = pci_set_consistent_dma_mask(self->pdev, DMA_BIT_MASK(64)); err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
self->is_pci_using_dac = 1;
} }
if (err) { if (err) {
err = pci_set_dma_mask(self->pdev, DMA_BIT_MASK(32)); err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
if (!err) if (!err)
err = pci_set_consistent_dma_mask(self->pdev, err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32)); DMA_BIT_MASK(32));
self->is_pci_using_dac = 0;
} }
if (err != 0) { if (err != 0) {
err = -ENOSR; err = -ENOSR;
goto err_exit; goto err_exit;
} }
err = pci_request_regions(self->pdev, AQ_CFG_DRV_NAME "_mmio"); err = pci_request_regions(pdev, AQ_CFG_DRV_NAME "_mmio");
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
self->is_regions = true; pci_set_master(pdev);
pci_set_master(self->pdev); return 0;
for (bar = 0; bar < 4; ++bar) {
if (IORESOURCE_MEM & pci_resource_flags(self->pdev, bar)) {
resource_size_t reg_sz;
self->mmio_pa = pci_resource_start(self->pdev, bar);
if (self->mmio_pa == 0U) {
err = -EIO;
goto err_exit;
}
reg_sz = pci_resource_len(self->pdev, bar);
if ((reg_sz <= 24 /*ATL_REGS_SIZE*/)) {
err = -EIO;
goto err_exit;
}
self->mmio = ioremap_nocache(self->mmio_pa, reg_sz);
if (!self->mmio) {
err = -EIO;
goto err_exit;
}
break;
}
}
numvecs = min((u8)AQ_CFG_VECS_DEF, self->aq_hw_caps.msix_irqs);
numvecs = min(numvecs, num_online_cpus());
/* enable interrupts */
#if !AQ_CFG_FORCE_LEGACY_INT
err = pci_alloc_irq_vectors(self->pdev, numvecs, numvecs, PCI_IRQ_MSIX);
if (err < 0) {
err = pci_alloc_irq_vectors(self->pdev, 1, 1,
PCI_IRQ_MSI | PCI_IRQ_LEGACY);
if (err < 0)
goto err_exit;
}
#endif /* AQ_CFG_FORCE_LEGACY_INT */
/* net device init */
for (port = 0; port < self->ports; ++port) {
if (!self->port[port])
continue;
err = aq_nic_cfg_start(self->port[port]);
if (err < 0)
goto err_exit;
err = aq_nic_ndev_init(self->port[port]);
if (err < 0)
goto err_exit;
err = aq_nic_ndev_register(self->port[port]);
if (err < 0)
goto err_exit;
}
err_exit: err_exit:
if (err < 0)
aq_pci_func_deinit(self);
return err; return err;
} }
int aq_pci_func_alloc_irq(struct aq_pci_func_s *self, unsigned int i, int aq_pci_func_alloc_irq(struct aq_nic_s *self, unsigned int i,
char *name, void *aq_vec, cpumask_t *affinity_mask) char *name, void *aq_vec, cpumask_t *affinity_mask)
{ {
struct pci_dev *pdev = self->pdev; struct pci_dev *pdev = self->pdev;
...@@ -227,11 +158,10 @@ int aq_pci_func_alloc_irq(struct aq_pci_func_s *self, unsigned int i, ...@@ -227,11 +158,10 @@ int aq_pci_func_alloc_irq(struct aq_pci_func_s *self, unsigned int i,
irq_set_affinity_hint(pci_irq_vector(pdev, i), irq_set_affinity_hint(pci_irq_vector(pdev, i),
affinity_mask); affinity_mask);
} }
return err; return err;
} }
void aq_pci_func_free_irqs(struct aq_pci_func_s *self) void aq_pci_func_free_irqs(struct aq_nic_s *self)
{ {
struct pci_dev *pdev = self->pdev; struct pci_dev *pdev = self->pdev;
unsigned int i = 0U; unsigned int i = 0U;
...@@ -247,12 +177,7 @@ void aq_pci_func_free_irqs(struct aq_pci_func_s *self) ...@@ -247,12 +177,7 @@ void aq_pci_func_free_irqs(struct aq_pci_func_s *self)
} }
} }
void __iomem *aq_pci_func_get_mmio(struct aq_pci_func_s *self) unsigned int aq_pci_func_get_irq_type(struct aq_nic_s *self)
{
return self->mmio;
}
unsigned int aq_pci_func_get_irq_type(struct aq_pci_func_s *self)
{ {
if (self->pdev->msix_enabled) if (self->pdev->msix_enabled)
return AQ_HW_IRQ_MSIX; return AQ_HW_IRQ_MSIX;
...@@ -261,115 +186,148 @@ unsigned int aq_pci_func_get_irq_type(struct aq_pci_func_s *self) ...@@ -261,115 +186,148 @@ unsigned int aq_pci_func_get_irq_type(struct aq_pci_func_s *self)
return AQ_HW_IRQ_LEGACY; return AQ_HW_IRQ_LEGACY;
} }
void aq_pci_func_deinit(struct aq_pci_func_s *self) static void aq_pci_free_irq_vectors(struct aq_nic_s *self)
{ {
if (!self)
goto err_exit;
aq_pci_func_free_irqs(self);
pci_free_irq_vectors(self->pdev); pci_free_irq_vectors(self->pdev);
if (self->is_regions)
pci_release_regions(self->pdev);
if (self->is_pci_enabled)
pci_disable_device(self->pdev);
err_exit:;
} }
void aq_pci_func_free(struct aq_pci_func_s *self) static int aq_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *pci_id)
{ {
unsigned int port = 0U; struct aq_nic_s *self = NULL;
int err = 0;
struct net_device *ndev;
resource_size_t mmio_pa;
u32 bar;
u32 numvecs;
if (!self) err = pci_enable_device(pdev);
goto err_exit; if (err)
return err;
for (port = 0; port < self->ports; ++port) { err = aq_pci_func_init(pdev);
if (!self->port[port]) if (err)
continue; goto err_pci_func;
aq_nic_ndev_free(self->port[port]); ndev = aq_ndev_alloc();
} if (!ndev)
goto err_ndev;
if (self->mmio) self = netdev_priv(ndev);
iounmap(self->mmio); self->pdev = pdev;
SET_NETDEV_DEV(ndev, &pdev->dev);
pci_set_drvdata(pdev, self);
kfree(self); err = aq_pci_probe_get_hw_by_id(pdev, &self->aq_hw_ops,
&aq_nic_get_cfg(self)->aq_hw_caps);
if (err)
goto err_ioremap;
err_exit:; self->aq_hw = kzalloc(sizeof(*self->aq_hw), GFP_KERNEL);
} self->aq_hw->aq_nic_cfg = aq_nic_get_cfg(self);
int aq_pci_func_change_pm_state(struct aq_pci_func_s *self, for (bar = 0; bar < 4; ++bar) {
pm_message_t *pm_msg) if (IORESOURCE_MEM & pci_resource_flags(pdev, bar)) {
{ resource_size_t reg_sz;
int err = 0;
unsigned int port = 0U;
if (!self) { mmio_pa = pci_resource_start(pdev, bar);
err = -EFAULT; if (mmio_pa == 0U) {
goto err_exit; err = -EIO;
goto err_ioremap;
} }
for (port = 0; port < self->ports; ++port) {
if (!self->port[port])
continue;
(void)aq_nic_change_pm_state(self->port[port], pm_msg); reg_sz = pci_resource_len(pdev, bar);
if ((reg_sz <= 24 /*ATL_REGS_SIZE*/)) {
err = -EIO;
goto err_ioremap;
} }
err_exit: self->aq_hw->mmio = ioremap_nocache(mmio_pa, reg_sz);
return err; if (!self->aq_hw->mmio) {
} err = -EIO;
goto err_ioremap;
static int aq_pci_probe(struct pci_dev *pdev, }
const struct pci_device_id *pci_id) break;
{ }
const struct aq_hw_ops *aq_hw_ops = NULL; }
struct aq_pci_func_s *aq_pci_func = NULL;
int err = 0;
err = pci_enable_device(pdev); if (bar == 4) {
if (err < 0) err = -EIO;
goto err_exit; goto err_ioremap;
aq_hw_ops = aq_pci_probe_get_hw_ops_by_id(pdev);
aq_pci_func = aq_pci_func_alloc(aq_hw_ops, pdev);
if (!aq_pci_func) {
err = -ENOMEM;
goto err_exit;
} }
err = aq_pci_func_init(aq_pci_func);
if (err < 0)
goto err_exit;
err_exit: numvecs = min((u8)AQ_CFG_VECS_DEF,
aq_nic_get_cfg(self)->aq_hw_caps->msix_irqs);
numvecs = min(numvecs, num_online_cpus());
/*enable interrupts */
#if !AQ_CFG_FORCE_LEGACY_INT
err = pci_alloc_irq_vectors(self->pdev, numvecs, numvecs,
PCI_IRQ_MSIX);
if (err < 0) { if (err < 0) {
if (aq_pci_func) err = pci_alloc_irq_vectors(self->pdev, 1, 1,
aq_pci_func_free(aq_pci_func); PCI_IRQ_MSI | PCI_IRQ_LEGACY);
if (err < 0)
goto err_hwinit;
} }
#endif
/* net device init */
aq_nic_cfg_start(self);
aq_nic_ndev_init(self);
err = aq_nic_ndev_register(self);
if (err < 0)
goto err_register;
return 0;
err_register:
aq_nic_free_vectors(self);
aq_pci_free_irq_vectors(self);
err_hwinit:
iounmap(self->aq_hw->mmio);
err_ioremap:
free_netdev(ndev);
err_pci_func:
pci_release_regions(pdev);
err_ndev:
pci_disable_device(pdev);
return err; return err;
} }
static void aq_pci_remove(struct pci_dev *pdev) static void aq_pci_remove(struct pci_dev *pdev)
{ {
struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev); struct aq_nic_s *self = pci_get_drvdata(pdev);
if (self->ndev) {
if (self->ndev->reg_state == NETREG_REGISTERED)
unregister_netdev(self->ndev);
aq_nic_free_vectors(self);
aq_pci_free_irq_vectors(self);
iounmap(self->aq_hw->mmio);
kfree(self->aq_hw);
pci_release_regions(pdev);
free_netdev(self->ndev);
}
aq_pci_func_deinit(aq_pci_func); pci_disable_device(pdev);
aq_pci_func_free(aq_pci_func);
} }
static int aq_pci_suspend(struct pci_dev *pdev, pm_message_t pm_msg) static int aq_pci_suspend(struct pci_dev *pdev, pm_message_t pm_msg)
{ {
struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev); struct aq_nic_s *self = pci_get_drvdata(pdev);
return aq_pci_func_change_pm_state(aq_pci_func, &pm_msg); return aq_nic_change_pm_state(self, &pm_msg);
} }
static int aq_pci_resume(struct pci_dev *pdev) static int aq_pci_resume(struct pci_dev *pdev)
{ {
struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev); struct aq_nic_s *self = pci_get_drvdata(pdev);
pm_message_t pm_msg = PMSG_RESTORE; pm_message_t pm_msg = PMSG_RESTORE;
return aq_pci_func_change_pm_state(aq_pci_func, &pm_msg); return aq_nic_change_pm_state(self, &pm_msg);
} }
static struct pci_driver aq_pci_ops = { static struct pci_driver aq_pci_ops = {
......
...@@ -15,19 +15,18 @@ ...@@ -15,19 +15,18 @@
#include "aq_common.h" #include "aq_common.h"
#include "aq_nic.h" #include "aq_nic.h"
struct aq_pci_func_s *aq_pci_func_alloc(const struct aq_hw_ops *hw_ops, struct aq_board_revision_s {
struct pci_dev *pdev); unsigned short devid;
int aq_pci_func_init(struct aq_pci_func_s *self); unsigned short revision;
int aq_pci_func_alloc_irq(struct aq_pci_func_s *self, unsigned int i, const struct aq_hw_ops *ops;
const struct aq_hw_caps_s *caps;
};
int aq_pci_func_init(struct pci_dev *pdev);
int aq_pci_func_alloc_irq(struct aq_nic_s *self, unsigned int i,
char *name, void *aq_vec, char *name, void *aq_vec,
cpumask_t *affinity_mask); cpumask_t *affinity_mask);
void aq_pci_func_free_irqs(struct aq_pci_func_s *self); void aq_pci_func_free_irqs(struct aq_nic_s *self);
int aq_pci_func_start(struct aq_pci_func_s *self); unsigned int aq_pci_func_get_irq_type(struct aq_nic_s *self);
void __iomem *aq_pci_func_get_mmio(struct aq_pci_func_s *self);
unsigned int aq_pci_func_get_irq_type(struct aq_pci_func_s *self);
void aq_pci_func_deinit(struct aq_pci_func_s *self);
void aq_pci_func_free(struct aq_pci_func_s *self);
int aq_pci_func_change_pm_state(struct aq_pci_func_s *self,
pm_message_t *pm_msg);
#endif /* AQ_PCI_FUNC_H */ #endif /* AQ_PCI_FUNC_H */
...@@ -18,45 +18,67 @@ ...@@ -18,45 +18,67 @@
#include "hw_atl_llh.h" #include "hw_atl_llh.h"
#include "hw_atl_a0_internal.h" #include "hw_atl_a0_internal.h"
static int hw_atl_a0_get_hw_caps(struct aq_hw_s *self, #define DEFAULT_A0_BOARD_BASIC_CAPABILITIES \
struct aq_hw_caps_s *aq_hw_caps, .is_64_dma = true, \
unsigned short device, .msix_irqs = 4U, \
unsigned short subsystem_device) .irq_mask = ~0U, \
{ .vecs = HW_ATL_A0_RSS_MAX, \
memcpy(aq_hw_caps, &hw_atl_a0_hw_caps_, sizeof(*aq_hw_caps)); .tcs = HW_ATL_A0_TC_MAX, \
.rxd_alignment = 1U, \
if (device == HW_ATL_DEVICE_ID_D108 && subsystem_device == 0x0001) .rxd_size = HW_ATL_A0_RXD_SIZE, \
aq_hw_caps->link_speed_msk &= ~HW_ATL_A0_RATE_10G; .rxds = 248U, \
.txd_alignment = 1U, \
if (device == HW_ATL_DEVICE_ID_D109 && subsystem_device == 0x0001) { .txd_size = HW_ATL_A0_TXD_SIZE, \
aq_hw_caps->link_speed_msk &= ~HW_ATL_A0_RATE_10G; .txds = 8U * 1024U, \
aq_hw_caps->link_speed_msk &= ~HW_ATL_A0_RATE_5G; .txhwb_alignment = 4096U, \
} .tx_rings = HW_ATL_A0_TX_RINGS, \
.rx_rings = HW_ATL_A0_RX_RINGS, \
return 0; .hw_features = NETIF_F_HW_CSUM | \
} NETIF_F_RXHASH | \
NETIF_F_RXCSUM | \
static struct aq_hw_s *hw_atl_a0_create(struct aq_pci_func_s *aq_pci_func, NETIF_F_SG | \
unsigned int port) NETIF_F_TSO, \
{ .hw_priv_flags = IFF_UNICAST_FLT, \
struct aq_hw_s *self = NULL; .flow_control = true, \
.mtu = HW_ATL_A0_MTU_JUMBO, \
self = kzalloc(sizeof(*self), GFP_KERNEL); .mac_regs_count = 88, \
if (!self) .hw_alive_check_addr = 0x10U
goto err_exit;
const struct aq_hw_caps_s hw_atl_a0_caps_aqc100 = {
self->aq_pci_func = aq_pci_func; DEFAULT_A0_BOARD_BASIC_CAPABILITIES,
.media_type = AQ_HW_MEDIA_TYPE_FIBRE,
.link_speed_msk = HW_ATL_A0_RATE_5G |
HW_ATL_A0_RATE_2G5 |
HW_ATL_A0_RATE_1G |
HW_ATL_A0_RATE_100M,
};
self->not_ff_addr = 0x10U; const struct aq_hw_caps_s hw_atl_a0_caps_aqc107 = {
DEFAULT_A0_BOARD_BASIC_CAPABILITIES,
.media_type = AQ_HW_MEDIA_TYPE_TP,
.link_speed_msk = HW_ATL_A0_RATE_10G |
HW_ATL_A0_RATE_5G |
HW_ATL_A0_RATE_2G5 |
HW_ATL_A0_RATE_1G |
HW_ATL_A0_RATE_100M,
};
err_exit: const struct aq_hw_caps_s hw_atl_a0_caps_aqc108 = {
return self; DEFAULT_A0_BOARD_BASIC_CAPABILITIES,
} .media_type = AQ_HW_MEDIA_TYPE_TP,
.link_speed_msk = HW_ATL_A0_RATE_5G |
HW_ATL_A0_RATE_2G5 |
HW_ATL_A0_RATE_1G |
HW_ATL_A0_RATE_100M,
};
static void hw_atl_a0_destroy(struct aq_hw_s *self) const struct aq_hw_caps_s hw_atl_a0_caps_aqc109 = {
{ DEFAULT_A0_BOARD_BASIC_CAPABILITIES,
kfree(self); .media_type = AQ_HW_MEDIA_TYPE_TP,
} .link_speed_msk = HW_ATL_A0_RATE_2G5 |
HW_ATL_A0_RATE_1G |
HW_ATL_A0_RATE_100M,
};
static int hw_atl_a0_hw_reset(struct aq_hw_s *self) static int hw_atl_a0_hw_reset(struct aq_hw_s *self)
{ {
...@@ -83,7 +105,7 @@ static int hw_atl_a0_hw_reset(struct aq_hw_s *self) ...@@ -83,7 +105,7 @@ static int hw_atl_a0_hw_reset(struct aq_hw_s *self)
if (err < 0) if (err < 0)
goto err_exit; goto err_exit;
hw_atl_utils_mpi_set(self, MPI_RESET, 0x0U); self->aq_fw_ops->set_state(self, MPI_RESET);
err = aq_hw_err_from_flags(self); err = aq_hw_err_from_flags(self);
...@@ -332,7 +354,8 @@ static int hw_atl_a0_hw_init(struct aq_hw_s *self, u8 *mac_addr) ...@@ -332,7 +354,8 @@ static int hw_atl_a0_hw_init(struct aq_hw_s *self, u8 *mac_addr)
hw_atl_a0_hw_mac_addr_set(self, mac_addr); hw_atl_a0_hw_mac_addr_set(self, mac_addr);
hw_atl_utils_mpi_set(self, MPI_INIT, aq_nic_cfg->link_speed_msk); self->aq_fw_ops->set_link_speed(self, aq_nic_cfg->link_speed_msk);
self->aq_fw_ops->set_state(self, MPI_INIT);
hw_atl_reg_tx_dma_debug_ctl_set(self, 0x800000b8U); hw_atl_reg_tx_dma_debug_ctl_set(self, 0x800000b8U);
hw_atl_reg_tx_dma_debug_ctl_set(self, 0x000000b8U); hw_atl_reg_tx_dma_debug_ctl_set(self, 0x000000b8U);
...@@ -343,7 +366,7 @@ static int hw_atl_a0_hw_init(struct aq_hw_s *self, u8 *mac_addr) ...@@ -343,7 +366,7 @@ static int hw_atl_a0_hw_init(struct aq_hw_s *self, u8 *mac_addr)
/* Reset link status and read out initial hardware counters */ /* Reset link status and read out initial hardware counters */
self->aq_link_status.mbps = 0; self->aq_link_status.mbps = 0;
hw_atl_utils_update_stats(self); self->aq_fw_ops->update_stats(self);
err = aq_hw_err_from_flags(self); err = aq_hw_err_from_flags(self);
if (err < 0) if (err < 0)
...@@ -849,27 +872,8 @@ static int hw_atl_a0_hw_ring_rx_stop(struct aq_hw_s *self, ...@@ -849,27 +872,8 @@ static int hw_atl_a0_hw_ring_rx_stop(struct aq_hw_s *self,
return aq_hw_err_from_flags(self); return aq_hw_err_from_flags(self);
} }
static int hw_atl_a0_hw_set_speed(struct aq_hw_s *self, u32 speed) const struct aq_hw_ops hw_atl_ops_a0 = {
{
int err = 0;
err = hw_atl_utils_mpi_set_speed(self, speed, MPI_INIT);
if (err < 0)
goto err_exit;
err_exit:
return err;
}
static const struct aq_hw_ops hw_atl_ops_ = {
.create = hw_atl_a0_create,
.destroy = hw_atl_a0_destroy,
.get_hw_caps = hw_atl_a0_get_hw_caps,
.hw_get_mac_permanent = hw_atl_utils_get_mac_permanent,
.hw_set_mac_address = hw_atl_a0_hw_mac_addr_set, .hw_set_mac_address = hw_atl_a0_hw_mac_addr_set,
.hw_get_link_status = hw_atl_utils_mpi_get_link_status,
.hw_set_link_speed = hw_atl_a0_hw_set_speed,
.hw_init = hw_atl_a0_hw_init, .hw_init = hw_atl_a0_hw_init,
.hw_deinit = hw_atl_utils_hw_deinit, .hw_deinit = hw_atl_utils_hw_deinit,
.hw_set_power = hw_atl_utils_hw_set_power, .hw_set_power = hw_atl_utils_hw_set_power,
...@@ -899,21 +903,6 @@ static const struct aq_hw_ops hw_atl_ops_ = { ...@@ -899,21 +903,6 @@ static const struct aq_hw_ops hw_atl_ops_ = {
.hw_rss_set = hw_atl_a0_hw_rss_set, .hw_rss_set = hw_atl_a0_hw_rss_set,
.hw_rss_hash_set = hw_atl_a0_hw_rss_hash_set, .hw_rss_hash_set = hw_atl_a0_hw_rss_hash_set,
.hw_get_regs = hw_atl_utils_hw_get_regs, .hw_get_regs = hw_atl_utils_hw_get_regs,
.hw_update_stats = hw_atl_utils_update_stats,
.hw_get_hw_stats = hw_atl_utils_get_hw_stats, .hw_get_hw_stats = hw_atl_utils_get_hw_stats,
.hw_get_fw_version = hw_atl_utils_get_fw_version, .hw_get_fw_version = hw_atl_utils_get_fw_version,
}; };
const struct aq_hw_ops *hw_atl_a0_get_ops_by_id(struct pci_dev *pdev)
{
bool is_vid_ok = (pdev->vendor == PCI_VENDOR_ID_AQUANTIA);
bool is_did_ok = ((pdev->device == HW_ATL_DEVICE_ID_0001) ||
(pdev->device == HW_ATL_DEVICE_ID_D100) ||
(pdev->device == HW_ATL_DEVICE_ID_D107) ||
(pdev->device == HW_ATL_DEVICE_ID_D108) ||
(pdev->device == HW_ATL_DEVICE_ID_D109));
bool is_rev_ok = (pdev->revision == 1U);
return (is_vid_ok && is_did_ok && is_rev_ok) ? &hw_atl_ops_ : NULL;
}
...@@ -16,19 +16,11 @@ ...@@ -16,19 +16,11 @@
#include "../aq_common.h" #include "../aq_common.h"
#ifndef PCI_VENDOR_ID_AQUANTIA extern const struct aq_hw_caps_s hw_atl_a0_caps_aqc100;
extern const struct aq_hw_caps_s hw_atl_a0_caps_aqc107;
extern const struct aq_hw_caps_s hw_atl_a0_caps_aqc108;
extern const struct aq_hw_caps_s hw_atl_a0_caps_aqc109;
#define PCI_VENDOR_ID_AQUANTIA 0x1D6A extern const struct aq_hw_ops hw_atl_ops_a0;
#define HW_ATL_DEVICE_ID_0001 0x0001
#define HW_ATL_DEVICE_ID_D100 0xD100
#define HW_ATL_DEVICE_ID_D107 0xD107
#define HW_ATL_DEVICE_ID_D108 0xD108
#define HW_ATL_DEVICE_ID_D109 0xD109
#define HW_ATL_NIC_NAME "aQuantia AQtion 5Gbit Network Adapter"
#endif
const struct aq_hw_ops *hw_atl_a0_get_ops_by_id(struct pci_dev *pdev);
#endif /* HW_ATL_A0_H */ #endif /* HW_ATL_A0_H */
...@@ -88,38 +88,4 @@ ...@@ -88,38 +88,4 @@
#define HW_ATL_A0_FW_VER_EXPECTED 0x01050006U #define HW_ATL_A0_FW_VER_EXPECTED 0x01050006U
/* HW layer capabilities */
static struct aq_hw_caps_s hw_atl_a0_hw_caps_ = {
.ports = 1U,
.is_64_dma = true,
.msix_irqs = 4U,
.irq_mask = ~0U,
.vecs = HW_ATL_A0_RSS_MAX,
.tcs = HW_ATL_A0_TC_MAX,
.rxd_alignment = 1U,
.rxd_size = HW_ATL_A0_RXD_SIZE,
.rxds = 248U,
.txd_alignment = 1U,
.txd_size = HW_ATL_A0_TXD_SIZE,
.txds = 8U * 1024U,
.txhwb_alignment = 4096U,
.tx_rings = HW_ATL_A0_TX_RINGS,
.rx_rings = HW_ATL_A0_RX_RINGS,
.hw_features = NETIF_F_HW_CSUM |
NETIF_F_RXCSUM |
NETIF_F_RXHASH |
NETIF_F_SG |
NETIF_F_TSO,
.hw_priv_flags = IFF_UNICAST_FLT,
.link_speed_msk = (HW_ATL_A0_RATE_10G |
HW_ATL_A0_RATE_5G |
HW_ATL_A0_RATE_2G5 |
HW_ATL_A0_RATE_1G |
HW_ATL_A0_RATE_100M),
.flow_control = true,
.mtu = HW_ATL_A0_MTU_JUMBO,
.mac_regs_count = 88,
.fw_ver_expected = HW_ATL_A0_FW_VER_EXPECTED,
};
#endif /* HW_ATL_A0_INTERNAL_H */ #endif /* HW_ATL_A0_INTERNAL_H */
...@@ -19,76 +19,82 @@ ...@@ -19,76 +19,82 @@
#include "hw_atl_b0_internal.h" #include "hw_atl_b0_internal.h"
#include "hw_atl_llh_internal.h" #include "hw_atl_llh_internal.h"
static int hw_atl_b0_get_hw_caps(struct aq_hw_s *self, #define DEFAULT_B0_BOARD_BASIC_CAPABILITIES \
struct aq_hw_caps_s *aq_hw_caps, .is_64_dma = true, \
unsigned short device, .msix_irqs = 4U, \
unsigned short subsystem_device) .irq_mask = ~0U, \
{ .vecs = HW_ATL_B0_RSS_MAX, \
memcpy(aq_hw_caps, &hw_atl_b0_hw_caps_, sizeof(*aq_hw_caps)); .tcs = HW_ATL_B0_TC_MAX, \
.rxd_alignment = 1U, \
if (device == HW_ATL_DEVICE_ID_D108 && subsystem_device == 0x0001) .rxd_size = HW_ATL_B0_RXD_SIZE, \
aq_hw_caps->link_speed_msk &= ~HW_ATL_B0_RATE_10G; .rxds = 4U * 1024U, \
.txd_alignment = 1U, \
if (device == HW_ATL_DEVICE_ID_D109 && subsystem_device == 0x0001) { .txd_size = HW_ATL_B0_TXD_SIZE, \
aq_hw_caps->link_speed_msk &= ~HW_ATL_B0_RATE_10G; .txds = 8U * 1024U, \
aq_hw_caps->link_speed_msk &= ~HW_ATL_B0_RATE_5G; .txhwb_alignment = 4096U, \
} .tx_rings = HW_ATL_B0_TX_RINGS, \
.rx_rings = HW_ATL_B0_RX_RINGS, \
return 0; .hw_features = NETIF_F_HW_CSUM | \
} NETIF_F_RXCSUM | \
NETIF_F_RXHASH | \
static struct aq_hw_s *hw_atl_b0_create(struct aq_pci_func_s *aq_pci_func, NETIF_F_SG | \
unsigned int port) NETIF_F_TSO | \
{ NETIF_F_LRO, \
struct aq_hw_s *self = NULL; .hw_priv_flags = IFF_UNICAST_FLT, \
.flow_control = true, \
self = kzalloc(sizeof(*self), GFP_KERNEL); .mtu = HW_ATL_B0_MTU_JUMBO, \
if (!self) .mac_regs_count = 88, \
goto err_exit; .hw_alive_check_addr = 0x10U
self->aq_pci_func = aq_pci_func; const struct aq_hw_caps_s hw_atl_b0_caps_aqc100 = {
DEFAULT_B0_BOARD_BASIC_CAPABILITIES,
.media_type = AQ_HW_MEDIA_TYPE_FIBRE,
.link_speed_msk = HW_ATL_B0_RATE_10G |
HW_ATL_B0_RATE_5G |
HW_ATL_B0_RATE_2G5 |
HW_ATL_B0_RATE_1G |
HW_ATL_B0_RATE_100M,
};
self->not_ff_addr = 0x10U; const struct aq_hw_caps_s hw_atl_b0_caps_aqc107 = {
DEFAULT_B0_BOARD_BASIC_CAPABILITIES,
.media_type = AQ_HW_MEDIA_TYPE_TP,
.link_speed_msk = HW_ATL_B0_RATE_10G |
HW_ATL_B0_RATE_5G |
HW_ATL_B0_RATE_2G5 |
HW_ATL_B0_RATE_1G |
HW_ATL_B0_RATE_100M,
};
err_exit: const struct aq_hw_caps_s hw_atl_b0_caps_aqc108 = {
return self; DEFAULT_B0_BOARD_BASIC_CAPABILITIES,
} .media_type = AQ_HW_MEDIA_TYPE_TP,
.link_speed_msk = HW_ATL_B0_RATE_5G |
HW_ATL_B0_RATE_2G5 |
HW_ATL_B0_RATE_1G |
HW_ATL_B0_RATE_100M,
};
static void hw_atl_b0_destroy(struct aq_hw_s *self) const struct aq_hw_caps_s hw_atl_b0_caps_aqc109 = {
{ DEFAULT_B0_BOARD_BASIC_CAPABILITIES,
kfree(self); .media_type = AQ_HW_MEDIA_TYPE_TP,
} .link_speed_msk = HW_ATL_B0_RATE_2G5 |
HW_ATL_B0_RATE_1G |
HW_ATL_B0_RATE_100M,
};
static int hw_atl_b0_hw_reset(struct aq_hw_s *self) static int hw_atl_b0_hw_reset(struct aq_hw_s *self)
{ {
int err = 0; int err = 0;
hw_atl_glb_glb_reg_res_dis_set(self, 1U); err = hw_atl_utils_soft_reset(self);
hw_atl_pci_pci_reg_res_dis_set(self, 0U); if (err)
hw_atl_rx_rx_reg_res_dis_set(self, 0U); return err;
hw_atl_tx_tx_reg_res_dis_set(self, 0U);
HW_ATL_FLUSH();
hw_atl_glb_soft_res_set(self, 1);
/* check 10 times by 1ms */
AQ_HW_WAIT_FOR(hw_atl_glb_soft_res_get(self) == 0, 1000U, 10U);
if (err < 0)
goto err_exit;
hw_atl_itr_irq_reg_res_dis_set(self, 0U);
hw_atl_itr_res_irq_set(self, 1U);
/* check 10 times by 1ms */
AQ_HW_WAIT_FOR(hw_atl_itr_res_irq_get(self) == 0, 1000U, 10U);
if (err < 0)
goto err_exit;
hw_atl_utils_mpi_set(self, MPI_RESET, 0x0U); self->aq_fw_ops->set_state(self, MPI_RESET);
err = aq_hw_err_from_flags(self); err = aq_hw_err_from_flags(self);
err_exit:
return err; return err;
} }
...@@ -379,7 +385,8 @@ static int hw_atl_b0_hw_init(struct aq_hw_s *self, u8 *mac_addr) ...@@ -379,7 +385,8 @@ static int hw_atl_b0_hw_init(struct aq_hw_s *self, u8 *mac_addr)
hw_atl_b0_hw_mac_addr_set(self, mac_addr); hw_atl_b0_hw_mac_addr_set(self, mac_addr);
hw_atl_utils_mpi_set(self, MPI_INIT, aq_nic_cfg->link_speed_msk); self->aq_fw_ops->set_link_speed(self, aq_nic_cfg->link_speed_msk);
self->aq_fw_ops->set_state(self, MPI_INIT);
hw_atl_b0_hw_qos_set(self); hw_atl_b0_hw_qos_set(self);
hw_atl_b0_hw_rss_set(self, &aq_nic_cfg->aq_rss); hw_atl_b0_hw_rss_set(self, &aq_nic_cfg->aq_rss);
...@@ -398,7 +405,7 @@ static int hw_atl_b0_hw_init(struct aq_hw_s *self, u8 *mac_addr) ...@@ -398,7 +405,7 @@ static int hw_atl_b0_hw_init(struct aq_hw_s *self, u8 *mac_addr)
/* Reset link status and read out initial hardware counters */ /* Reset link status and read out initial hardware counters */
self->aq_link_status.mbps = 0; self->aq_link_status.mbps = 0;
hw_atl_utils_update_stats(self); self->aq_fw_ops->update_stats(self);
err = aq_hw_err_from_flags(self); err = aq_hw_err_from_flags(self);
if (err < 0) if (err < 0)
...@@ -923,27 +930,8 @@ static int hw_atl_b0_hw_ring_rx_stop(struct aq_hw_s *self, ...@@ -923,27 +930,8 @@ static int hw_atl_b0_hw_ring_rx_stop(struct aq_hw_s *self,
return aq_hw_err_from_flags(self); return aq_hw_err_from_flags(self);
} }
static int hw_atl_b0_hw_set_speed(struct aq_hw_s *self, u32 speed) const struct aq_hw_ops hw_atl_ops_b0 = {
{
int err = 0;
err = hw_atl_utils_mpi_set_speed(self, speed, MPI_INIT);
if (err < 0)
goto err_exit;
err_exit:
return err;
}
static const struct aq_hw_ops hw_atl_ops_ = {
.create = hw_atl_b0_create,
.destroy = hw_atl_b0_destroy,
.get_hw_caps = hw_atl_b0_get_hw_caps,
.hw_get_mac_permanent = hw_atl_utils_get_mac_permanent,
.hw_set_mac_address = hw_atl_b0_hw_mac_addr_set, .hw_set_mac_address = hw_atl_b0_hw_mac_addr_set,
.hw_get_link_status = hw_atl_utils_mpi_get_link_status,
.hw_set_link_speed = hw_atl_b0_hw_set_speed,
.hw_init = hw_atl_b0_hw_init, .hw_init = hw_atl_b0_hw_init,
.hw_deinit = hw_atl_utils_hw_deinit, .hw_deinit = hw_atl_utils_hw_deinit,
.hw_set_power = hw_atl_utils_hw_set_power, .hw_set_power = hw_atl_utils_hw_set_power,
...@@ -973,21 +961,6 @@ static const struct aq_hw_ops hw_atl_ops_ = { ...@@ -973,21 +961,6 @@ static const struct aq_hw_ops hw_atl_ops_ = {
.hw_rss_set = hw_atl_b0_hw_rss_set, .hw_rss_set = hw_atl_b0_hw_rss_set,
.hw_rss_hash_set = hw_atl_b0_hw_rss_hash_set, .hw_rss_hash_set = hw_atl_b0_hw_rss_hash_set,
.hw_get_regs = hw_atl_utils_hw_get_regs, .hw_get_regs = hw_atl_utils_hw_get_regs,
.hw_update_stats = hw_atl_utils_update_stats,
.hw_get_hw_stats = hw_atl_utils_get_hw_stats, .hw_get_hw_stats = hw_atl_utils_get_hw_stats,
.hw_get_fw_version = hw_atl_utils_get_fw_version, .hw_get_fw_version = hw_atl_utils_get_fw_version,
}; };
const struct aq_hw_ops *hw_atl_b0_get_ops_by_id(struct pci_dev *pdev)
{
bool is_vid_ok = (pdev->vendor == PCI_VENDOR_ID_AQUANTIA);
bool is_did_ok = ((pdev->device == HW_ATL_DEVICE_ID_0001) ||
(pdev->device == HW_ATL_DEVICE_ID_D100) ||
(pdev->device == HW_ATL_DEVICE_ID_D107) ||
(pdev->device == HW_ATL_DEVICE_ID_D108) ||
(pdev->device == HW_ATL_DEVICE_ID_D109));
bool is_rev_ok = (pdev->revision == 2U);
return (is_vid_ok && is_did_ok && is_rev_ok) ? &hw_atl_ops_ : NULL;
}
...@@ -16,19 +16,27 @@ ...@@ -16,19 +16,27 @@
#include "../aq_common.h" #include "../aq_common.h"
#ifndef PCI_VENDOR_ID_AQUANTIA extern const struct aq_hw_caps_s hw_atl_b0_caps_aqc100;
extern const struct aq_hw_caps_s hw_atl_b0_caps_aqc107;
extern const struct aq_hw_caps_s hw_atl_b0_caps_aqc108;
extern const struct aq_hw_caps_s hw_atl_b0_caps_aqc109;
#define PCI_VENDOR_ID_AQUANTIA 0x1D6A #define hw_atl_b0_caps_aqc111 hw_atl_b0_caps_aqc108
#define HW_ATL_DEVICE_ID_0001 0x0001 #define hw_atl_b0_caps_aqc112 hw_atl_b0_caps_aqc109
#define HW_ATL_DEVICE_ID_D100 0xD100
#define HW_ATL_DEVICE_ID_D107 0xD107
#define HW_ATL_DEVICE_ID_D108 0xD108
#define HW_ATL_DEVICE_ID_D109 0xD109
#define HW_ATL_NIC_NAME "aQuantia AQtion 5Gbit Network Adapter" #define hw_atl_b0_caps_aqc100s hw_atl_b0_caps_aqc100
#define hw_atl_b0_caps_aqc107s hw_atl_b0_caps_aqc107
#define hw_atl_b0_caps_aqc108s hw_atl_b0_caps_aqc108
#define hw_atl_b0_caps_aqc109s hw_atl_b0_caps_aqc109
#endif #define hw_atl_b0_caps_aqc111s hw_atl_b0_caps_aqc108
#define hw_atl_b0_caps_aqc112s hw_atl_b0_caps_aqc109
const struct aq_hw_ops *hw_atl_b0_get_ops_by_id(struct pci_dev *pdev); #define hw_atl_b0_caps_aqc111e hw_atl_b0_caps_aqc108
#define hw_atl_b0_caps_aqc112e hw_atl_b0_caps_aqc109
extern const struct aq_hw_ops hw_atl_ops_b0;
#define hw_atl_ops_b1 hw_atl_ops_b0
#endif /* HW_ATL_B0_H */ #endif /* HW_ATL_B0_H */
...@@ -143,38 +143,5 @@ ...@@ -143,38 +143,5 @@
#define HW_ATL_INTR_MODER_MIN 0xFF #define HW_ATL_INTR_MODER_MIN 0xFF
/* HW layer capabilities */ /* HW layer capabilities */
static struct aq_hw_caps_s hw_atl_b0_hw_caps_ = {
.ports = 1U,
.is_64_dma = true,
.msix_irqs = 4U,
.irq_mask = ~0U,
.vecs = HW_ATL_B0_RSS_MAX,
.tcs = HW_ATL_B0_TC_MAX,
.rxd_alignment = 1U,
.rxd_size = HW_ATL_B0_RXD_SIZE,
.rxds = 8U * 1024U,
.txd_alignment = 1U,
.txd_size = HW_ATL_B0_TXD_SIZE,
.txds = 8U * 1024U,
.txhwb_alignment = 4096U,
.tx_rings = HW_ATL_B0_TX_RINGS,
.rx_rings = HW_ATL_B0_RX_RINGS,
.hw_features = NETIF_F_HW_CSUM |
NETIF_F_RXCSUM |
NETIF_F_RXHASH |
NETIF_F_SG |
NETIF_F_TSO |
NETIF_F_LRO,
.hw_priv_flags = IFF_UNICAST_FLT,
.link_speed_msk = (HW_ATL_B0_RATE_10G |
HW_ATL_B0_RATE_5G |
HW_ATL_B0_RATE_2G5 |
HW_ATL_B0_RATE_1G |
HW_ATL_B0_RATE_100M),
.flow_control = true,
.mtu = HW_ATL_B0_MTU_JUMBO,
.mac_regs_count = 88,
.fw_ver_expected = HW_ATL_B0_FW_VER_EXPECTED,
};
#endif /* HW_ATL_B0_INTERNAL_H */ #endif /* HW_ATL_B0_INTERNAL_H */
...@@ -13,24 +13,229 @@ ...@@ -13,24 +13,229 @@
#include "../aq_nic.h" #include "../aq_nic.h"
#include "../aq_hw_utils.h" #include "../aq_hw_utils.h"
#include "../aq_pci_func.h"
#include "hw_atl_utils.h" #include "hw_atl_utils.h"
#include "hw_atl_llh.h" #include "hw_atl_llh.h"
#include "hw_atl_llh_internal.h"
#include <linux/random.h> #include <linux/random.h>
#define HW_ATL_UCP_0X370_REG 0x0370U #define HW_ATL_UCP_0X370_REG 0x0370U
#define HW_ATL_FW_SM_RAM 0x2U #define HW_ATL_FW_SM_RAM 0x2U
#define HW_ATL_MPI_FW_VERSION 0x18
#define HW_ATL_MPI_CONTROL_ADR 0x0368U #define HW_ATL_MPI_CONTROL_ADR 0x0368U
#define HW_ATL_MPI_STATE_ADR 0x036CU #define HW_ATL_MPI_STATE_ADR 0x036CU
#define HW_ATL_MPI_STATE_MSK 0x00FFU #define HW_ATL_MPI_STATE_MSK 0x00FFU
#define HW_ATL_MPI_STATE_SHIFT 0U #define HW_ATL_MPI_STATE_SHIFT 0U
#define HW_ATL_MPI_SPEED_MSK 0xFFFFU #define HW_ATL_MPI_SPEED_MSK 0xFFFF0000U
#define HW_ATL_MPI_SPEED_SHIFT 16U #define HW_ATL_MPI_SPEED_SHIFT 16U
static int hw_atl_utils_fw_downld_dwords(struct aq_hw_s *self, u32 a, #define HW_ATL_MPI_DAISY_CHAIN_STATUS 0x704
#define HW_ATL_MPI_BOOT_EXIT_CODE 0x388
#define HW_ATL_MAC_PHY_CONTROL 0x4000
#define HW_ATL_MAC_PHY_MPI_RESET_BIT 0x1D
#define HW_ATL_FW_VER_1X 0x01050006U
#define HW_ATL_FW_VER_2X 0x02000000U
#define HW_ATL_FW_VER_3X 0x03000000U
#define FORCE_FLASHLESS 0
static int hw_atl_utils_ver_match(u32 ver_expected, u32 ver_actual);
int hw_atl_utils_initfw(struct aq_hw_s *self, const struct aq_fw_ops **fw_ops)
{
int err = 0;
err = hw_atl_utils_soft_reset(self);
if (err)
return err;
hw_atl_utils_hw_chip_features_init(self,
&self->chip_features);
hw_atl_utils_get_fw_version(self, &self->fw_ver_actual);
if (hw_atl_utils_ver_match(HW_ATL_FW_VER_1X,
self->fw_ver_actual) == 0) {
*fw_ops = &aq_fw_1x_ops;
} else if (hw_atl_utils_ver_match(HW_ATL_FW_VER_2X,
self->fw_ver_actual) == 0) {
*fw_ops = &aq_fw_2x_ops;
} else if (hw_atl_utils_ver_match(HW_ATL_FW_VER_3X,
self->fw_ver_actual) == 0) {
*fw_ops = &aq_fw_2x_ops;
} else {
aq_pr_err("Bad FW version detected: %x\n",
self->fw_ver_actual);
return -EOPNOTSUPP;
}
self->aq_fw_ops = *fw_ops;
err = self->aq_fw_ops->init(self);
return err;
}
static int hw_atl_utils_soft_reset_flb(struct aq_hw_s *self)
{
int k = 0;
u32 gsr;
aq_hw_write_reg(self, 0x404, 0x40e1);
AQ_HW_SLEEP(50);
/* Cleanup SPI */
aq_hw_write_reg(self, 0x534, 0xA0);
aq_hw_write_reg(self, 0x100, 0x9F);
aq_hw_write_reg(self, 0x100, 0x809F);
gsr = aq_hw_read_reg(self, HW_ATL_GLB_SOFT_RES_ADR);
aq_hw_write_reg(self, HW_ATL_GLB_SOFT_RES_ADR, (gsr & 0xBFFF) | 0x8000);
/* Kickstart MAC */
aq_hw_write_reg(self, 0x404, 0x80e0);
aq_hw_write_reg(self, 0x32a8, 0x0);
aq_hw_write_reg(self, 0x520, 0x1);
AQ_HW_SLEEP(10);
aq_hw_write_reg(self, 0x404, 0x180e0);
for (k = 0; k < 1000; k++) {
u32 flb_status = aq_hw_read_reg(self,
HW_ATL_MPI_DAISY_CHAIN_STATUS);
flb_status = flb_status & 0x10;
if (flb_status)
break;
AQ_HW_SLEEP(10);
}
if (k == 1000) {
aq_pr_err("MAC kickstart failed\n");
return -EIO;
}
/* FW reset */
aq_hw_write_reg(self, 0x404, 0x80e0);
AQ_HW_SLEEP(50);
aq_hw_write_reg(self, 0x3a0, 0x1);
/* Kickstart PHY - skipped */
/* Global software reset*/
hw_atl_rx_rx_reg_res_dis_set(self, 0U);
hw_atl_tx_tx_reg_res_dis_set(self, 0U);
aq_hw_write_reg_bit(self, HW_ATL_MAC_PHY_CONTROL,
BIT(HW_ATL_MAC_PHY_MPI_RESET_BIT),
HW_ATL_MAC_PHY_MPI_RESET_BIT, 0x0);
gsr = aq_hw_read_reg(self, HW_ATL_GLB_SOFT_RES_ADR);
aq_hw_write_reg(self, HW_ATL_GLB_SOFT_RES_ADR, (gsr & 0xBFFF) | 0x8000);
for (k = 0; k < 1000; k++) {
u32 fw_state = aq_hw_read_reg(self, HW_ATL_MPI_FW_VERSION);
if (fw_state)
break;
AQ_HW_SLEEP(10);
}
if (k == 1000) {
aq_pr_err("FW kickstart failed\n");
return -EIO;
}
return 0;
}
static int hw_atl_utils_soft_reset_rbl(struct aq_hw_s *self)
{
u32 gsr, rbl_status;
int k;
aq_hw_write_reg(self, 0x404, 0x40e1);
aq_hw_write_reg(self, 0x3a0, 0x1);
aq_hw_write_reg(self, 0x32a8, 0x0);
/* Alter RBL status */
aq_hw_write_reg(self, 0x388, 0xDEAD);
/* Global software reset*/
hw_atl_rx_rx_reg_res_dis_set(self, 0U);
hw_atl_tx_tx_reg_res_dis_set(self, 0U);
aq_hw_write_reg_bit(self, HW_ATL_MAC_PHY_CONTROL,
BIT(HW_ATL_MAC_PHY_MPI_RESET_BIT),
HW_ATL_MAC_PHY_MPI_RESET_BIT, 0x0);
gsr = aq_hw_read_reg(self, HW_ATL_GLB_SOFT_RES_ADR);
aq_hw_write_reg(self, HW_ATL_GLB_SOFT_RES_ADR,
(gsr & 0xFFFFBFFF) | 0x8000);
if (FORCE_FLASHLESS)
aq_hw_write_reg(self, 0x534, 0x0);
aq_hw_write_reg(self, 0x404, 0x40e0);
/* Wait for RBL boot */
for (k = 0; k < 1000; k++) {
rbl_status = aq_hw_read_reg(self, 0x388) & 0xFFFF;
if (rbl_status && rbl_status != 0xDEAD)
break;
AQ_HW_SLEEP(10);
}
if (!rbl_status || rbl_status == 0xDEAD) {
aq_pr_err("RBL Restart failed");
return -EIO;
}
/* Restore NVR */
if (FORCE_FLASHLESS)
aq_hw_write_reg(self, 0x534, 0xA0);
if (rbl_status == 0xF1A7) {
aq_pr_err("No FW detected. Dynamic FW load not implemented\n");
return -ENOTSUPP;
}
for (k = 0; k < 1000; k++) {
u32 fw_state = aq_hw_read_reg(self, HW_ATL_MPI_FW_VERSION);
if (fw_state)
break;
AQ_HW_SLEEP(10);
}
if (k == 1000) {
aq_pr_err("FW kickstart failed\n");
return -EIO;
}
return 0;
}
int hw_atl_utils_soft_reset(struct aq_hw_s *self)
{
int k;
u32 boot_exit_code = 0;
for (k = 0; k < 1000; ++k) {
u32 flb_status = aq_hw_read_reg(self,
HW_ATL_MPI_DAISY_CHAIN_STATUS);
boot_exit_code = aq_hw_read_reg(self,
HW_ATL_MPI_BOOT_EXIT_CODE);
if (flb_status != 0x06000000 || boot_exit_code != 0)
break;
}
if (k == 1000) {
aq_pr_err("Neither RBL nor FLB firmware started\n");
return -EOPNOTSUPP;
}
self->rbl_enabled = (boot_exit_code != 0);
if (self->rbl_enabled)
return hw_atl_utils_soft_reset_rbl(self);
else
return hw_atl_utils_soft_reset_flb(self);
}
int hw_atl_utils_fw_downld_dwords(struct aq_hw_s *self, u32 a,
u32 *p, u32 cnt) u32 *p, u32 cnt)
{ {
int err = 0; int err = 0;
...@@ -137,14 +342,6 @@ static int hw_atl_utils_init_ucp(struct aq_hw_s *self, ...@@ -137,14 +342,6 @@ static int hw_atl_utils_init_ucp(struct aq_hw_s *self,
AQ_HW_WAIT_FOR(0U != (self->mbox_addr = AQ_HW_WAIT_FOR(0U != (self->mbox_addr =
aq_hw_read_reg(self, 0x360U)), 1000U, 10U); aq_hw_read_reg(self, 0x360U)), 1000U, 10U);
err = hw_atl_utils_ver_match(aq_hw_caps->fw_ver_expected,
aq_hw_read_reg(self, 0x18U));
if (err < 0)
pr_err("%s: Bad FW version detected: expected=%x, actual=%x\n",
AQ_CFG_DRV_NAME,
aq_hw_caps->fw_ver_expected,
aq_hw_read_reg(self, 0x18U));
return err; return err;
} }
...@@ -286,19 +483,19 @@ void hw_atl_utils_mpi_read_stats(struct aq_hw_s *self, ...@@ -286,19 +483,19 @@ void hw_atl_utils_mpi_read_stats(struct aq_hw_s *self,
err_exit:; err_exit:;
} }
int hw_atl_utils_mpi_set_speed(struct aq_hw_s *self, u32 speed, int hw_atl_utils_mpi_set_speed(struct aq_hw_s *self, u32 speed)
enum hal_atl_utils_fw_state_e state)
{ {
u32 ucp_0x368 = 0; u32 val = aq_hw_read_reg(self, HW_ATL_MPI_CONTROL_ADR);
ucp_0x368 = (speed << HW_ATL_MPI_SPEED_SHIFT) | state; val = (val & HW_ATL_MPI_STATE_MSK) | (speed << HW_ATL_MPI_SPEED_SHIFT);
aq_hw_write_reg(self, HW_ATL_MPI_CONTROL_ADR, ucp_0x368); aq_hw_write_reg(self, HW_ATL_MPI_CONTROL_ADR, val);
return 0; return 0;
} }
void hw_atl_utils_mpi_set(struct aq_hw_s *self, void hw_atl_utils_mpi_set(struct aq_hw_s *self,
enum hal_atl_utils_fw_state_e state, u32 speed) enum hal_atl_utils_fw_state_e state,
u32 speed)
{ {
int err = 0; int err = 0;
u32 transaction_id = 0; u32 transaction_id = 0;
...@@ -317,11 +514,22 @@ void hw_atl_utils_mpi_set(struct aq_hw_s *self, ...@@ -317,11 +514,22 @@ void hw_atl_utils_mpi_set(struct aq_hw_s *self,
goto err_exit; goto err_exit;
} }
err = hw_atl_utils_mpi_set_speed(self, speed, state); aq_hw_write_reg(self, HW_ATL_MPI_CONTROL_ADR,
(speed << HW_ATL_MPI_SPEED_SHIFT) | state);
err_exit:; err_exit:;
} }
static int hw_atl_utils_mpi_set_state(struct aq_hw_s *self,
enum hal_atl_utils_fw_state_e state)
{
u32 val = aq_hw_read_reg(self, HW_ATL_MPI_CONTROL_ADR);
val = state | (val & HW_ATL_MPI_SPEED_MSK);
aq_hw_write_reg(self, HW_ATL_MPI_CONTROL_ADR, val);
return 0;
}
int hw_atl_utils_mpi_get_link_status(struct aq_hw_s *self) int hw_atl_utils_mpi_get_link_status(struct aq_hw_s *self)
{ {
u32 cp0x036C = aq_hw_read_reg(self, HW_ATL_MPI_STATE_ADR); u32 cp0x036C = aq_hw_read_reg(self, HW_ATL_MPI_STATE_ADR);
...@@ -369,15 +577,6 @@ int hw_atl_utils_get_mac_permanent(struct aq_hw_s *self, ...@@ -369,15 +577,6 @@ int hw_atl_utils_get_mac_permanent(struct aq_hw_s *self,
u32 l = 0U; u32 l = 0U;
u32 mac_addr[2]; u32 mac_addr[2];
self->mmio = aq_pci_func_get_mmio(self->aq_pci_func);
hw_atl_utils_hw_chip_features_init(self,
&self->chip_features);
err = hw_atl_utils_mpi_create(self);
if (err < 0)
goto err_exit;
if (!aq_hw_read_reg(self, HW_ATL_UCP_0X370_REG)) { if (!aq_hw_read_reg(self, HW_ATL_UCP_0X370_REG)) {
unsigned int rnd = 0; unsigned int rnd = 0;
unsigned int ucp_0x370 = 0; unsigned int ucp_0x370 = 0;
...@@ -423,7 +622,6 @@ int hw_atl_utils_get_mac_permanent(struct aq_hw_s *self, ...@@ -423,7 +622,6 @@ int hw_atl_utils_get_mac_permanent(struct aq_hw_s *self,
mac[0] = (u8)(0xFFU & h); mac[0] = (u8)(0xFFU & h);
} }
err_exit:
return err; return err;
} }
...@@ -580,3 +778,13 @@ int hw_atl_utils_get_fw_version(struct aq_hw_s *self, u32 *fw_version) ...@@ -580,3 +778,13 @@ int hw_atl_utils_get_fw_version(struct aq_hw_s *self, u32 *fw_version)
*fw_version = aq_hw_read_reg(self, 0x18U); *fw_version = aq_hw_read_reg(self, 0x18U);
return 0; return 0;
} }
const struct aq_fw_ops aq_fw_1x_ops = {
.init = hw_atl_utils_mpi_create,
.reset = NULL,
.get_mac_permanent = hw_atl_utils_get_mac_permanent,
.set_link_speed = hw_atl_utils_mpi_set_speed,
.set_state = hw_atl_utils_mpi_set_state,
.update_link_status = hw_atl_utils_mpi_get_link_status,
.update_stats = hw_atl_utils_update_stats,
};
...@@ -180,10 +180,73 @@ enum hal_atl_utils_fw_state_e { ...@@ -180,10 +180,73 @@ enum hal_atl_utils_fw_state_e {
#define HAL_ATLANTIC_RATE_100M BIT(5) #define HAL_ATLANTIC_RATE_100M BIT(5)
#define HAL_ATLANTIC_RATE_INVALID BIT(6) #define HAL_ATLANTIC_RATE_INVALID BIT(6)
enum hw_atl_fw2x_rate {
FW2X_RATE_100M = 0x20,
FW2X_RATE_1G = 0x100,
FW2X_RATE_2G5 = 0x200,
FW2X_RATE_5G = 0x400,
FW2X_RATE_10G = 0x800,
};
enum hw_atl_fw2x_caps_lo {
CAPS_LO_10BASET_HD = 0x00,
CAPS_LO_10BASET_FD,
CAPS_LO_100BASETX_HD,
CAPS_LO_100BASET4_HD,
CAPS_LO_100BASET2_HD,
CAPS_LO_100BASETX_FD,
CAPS_LO_100BASET2_FD,
CAPS_LO_1000BASET_HD,
CAPS_LO_1000BASET_FD,
CAPS_LO_2P5GBASET_FD,
CAPS_LO_5GBASET_FD,
CAPS_LO_10GBASET_FD,
};
enum hw_atl_fw2x_caps_hi {
CAPS_HI_RESERVED1 = 0x00,
CAPS_HI_10BASET_EEE,
CAPS_HI_RESERVED2,
CAPS_HI_PAUSE,
CAPS_HI_ASYMMETRIC_PAUSE,
CAPS_HI_100BASETX_EEE,
CAPS_HI_RESERVED3,
CAPS_HI_RESERVED4,
CAPS_HI_1000BASET_FD_EEE,
CAPS_HI_2P5GBASET_FD_EEE,
CAPS_HI_5GBASET_FD_EEE,
CAPS_HI_10GBASET_FD_EEE,
CAPS_HI_RESERVED5,
CAPS_HI_RESERVED6,
CAPS_HI_RESERVED7,
CAPS_HI_RESERVED8,
CAPS_HI_RESERVED9,
CAPS_HI_CABLE_DIAG,
CAPS_HI_TEMPERATURE,
CAPS_HI_DOWNSHIFT,
CAPS_HI_PTP_AVB_EN,
CAPS_HI_MEDIA_DETECT,
CAPS_HI_LINK_DROP,
CAPS_HI_SLEEP_PROXY,
CAPS_HI_WOL,
CAPS_HI_MAC_STOP,
CAPS_HI_EXT_LOOPBACK,
CAPS_HI_INT_LOOPBACK,
CAPS_HI_EFUSE_AGENT,
CAPS_HI_WOL_TIMER,
CAPS_HI_STATISTICS,
CAPS_HI_TRANSACTION_ID,
};
struct aq_hw_s; struct aq_hw_s;
struct aq_fw_ops;
struct aq_hw_caps_s; struct aq_hw_caps_s;
struct aq_hw_link_status_s; struct aq_hw_link_status_s;
int hw_atl_utils_initfw(struct aq_hw_s *self, const struct aq_fw_ops **fw_ops);
int hw_atl_utils_soft_reset(struct aq_hw_s *self);
void hw_atl_utils_hw_chip_features_init(struct aq_hw_s *self, u32 *p); void hw_atl_utils_hw_chip_features_init(struct aq_hw_s *self, u32 *p);
int hw_atl_utils_mpi_read_mbox(struct aq_hw_s *self, int hw_atl_utils_mpi_read_mbox(struct aq_hw_s *self,
...@@ -196,9 +259,6 @@ void hw_atl_utils_mpi_set(struct aq_hw_s *self, ...@@ -196,9 +259,6 @@ void hw_atl_utils_mpi_set(struct aq_hw_s *self,
enum hal_atl_utils_fw_state_e state, enum hal_atl_utils_fw_state_e state,
u32 speed); u32 speed);
int hw_atl_utils_mpi_set_speed(struct aq_hw_s *self, u32 speed,
enum hal_atl_utils_fw_state_e state);
int hw_atl_utils_mpi_get_link_status(struct aq_hw_s *self); int hw_atl_utils_mpi_get_link_status(struct aq_hw_s *self);
int hw_atl_utils_get_mac_permanent(struct aq_hw_s *self, int hw_atl_utils_get_mac_permanent(struct aq_hw_s *self,
...@@ -220,5 +280,10 @@ int hw_atl_utils_get_fw_version(struct aq_hw_s *self, u32 *fw_version); ...@@ -220,5 +280,10 @@ int hw_atl_utils_get_fw_version(struct aq_hw_s *self, u32 *fw_version);
int hw_atl_utils_update_stats(struct aq_hw_s *self); int hw_atl_utils_update_stats(struct aq_hw_s *self);
struct aq_stats_s *hw_atl_utils_get_hw_stats(struct aq_hw_s *self); struct aq_stats_s *hw_atl_utils_get_hw_stats(struct aq_hw_s *self);
int hw_atl_utils_fw_downld_dwords(struct aq_hw_s *self, u32 a,
u32 *p, u32 cnt);
extern const struct aq_fw_ops aq_fw_1x_ops;
extern const struct aq_fw_ops aq_fw_2x_ops;
#endif /* HW_ATL_UTILS_H */ #endif /* HW_ATL_UTILS_H */
/*
* aQuantia Corporation Network Driver
* Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*/
/* File hw_atl_utils_fw2x.c: Definition of firmware 2.x functions for
* Atlantic hardware abstraction layer.
*/
#include "../aq_hw.h"
#include "../aq_hw_utils.h"
#include "../aq_pci_func.h"
#include "../aq_ring.h"
#include "../aq_vec.h"
#include "hw_atl_utils.h"
#include "hw_atl_llh.h"
#define HW_ATL_FW2X_MPI_EFUSE_ADDR 0x364
#define HW_ATL_FW2X_MPI_MBOX_ADDR 0x360
#define HW_ATL_FW2X_MPI_CONTROL_ADDR 0x368
#define HW_ATL_FW2X_MPI_CONTROL2_ADDR 0x36C
#define HW_ATL_FW2X_MPI_STATE_ADDR 0x370
#define HW_ATL_FW2X_MPI_STATE2_ADDR 0x374
static int aq_fw2x_init(struct aq_hw_s *self)
{
int err = 0;
/* check 10 times by 1ms */
AQ_HW_WAIT_FOR(0U != (self->mbox_addr =
aq_hw_read_reg(self, HW_ATL_FW2X_MPI_MBOX_ADDR)),
1000U, 10U);
return err;
}
static enum hw_atl_fw2x_rate link_speed_mask_2fw2x_ratemask(u32 speed)
{
enum hw_atl_fw2x_rate rate = 0;
if (speed & AQ_NIC_RATE_10G)
rate |= FW2X_RATE_10G;
if (speed & AQ_NIC_RATE_5G)
rate |= FW2X_RATE_5G;
if (speed & AQ_NIC_RATE_5GSR)
rate |= FW2X_RATE_5G;
if (speed & AQ_NIC_RATE_2GS)
rate |= FW2X_RATE_2G5;
if (speed & AQ_NIC_RATE_1G)
rate |= FW2X_RATE_1G;
if (speed & AQ_NIC_RATE_100M)
rate |= FW2X_RATE_100M;
return rate;
}
static int aq_fw2x_set_link_speed(struct aq_hw_s *self, u32 speed)
{
u32 val = link_speed_mask_2fw2x_ratemask(speed);
aq_hw_write_reg(self, HW_ATL_FW2X_MPI_CONTROL_ADDR, val);
return 0;
}
static int aq_fw2x_set_state(struct aq_hw_s *self,
enum hal_atl_utils_fw_state_e state)
{
/* No explicit state in 2x fw */
return 0;
}
static int aq_fw2x_update_link_status(struct aq_hw_s *self)
{
u32 mpi_state = aq_hw_read_reg(self, HW_ATL_FW2X_MPI_STATE_ADDR);
u32 speed = mpi_state & (FW2X_RATE_100M | FW2X_RATE_1G |
FW2X_RATE_2G5 | FW2X_RATE_5G | FW2X_RATE_10G);
struct aq_hw_link_status_s *link_status = &self->aq_link_status;
if (speed) {
if (speed & FW2X_RATE_10G)
link_status->mbps = 10000;
else if (speed & FW2X_RATE_5G)
link_status->mbps = 5000;
else if (speed & FW2X_RATE_2G5)
link_status->mbps = 2500;
else if (speed & FW2X_RATE_1G)
link_status->mbps = 1000;
else if (speed & FW2X_RATE_100M)
link_status->mbps = 100;
else
link_status->mbps = 10000;
} else {
link_status->mbps = 0;
}
return 0;
}
int aq_fw2x_get_mac_permanent(struct aq_hw_s *self, u8 *mac)
{
int err = 0;
u32 h = 0U;
u32 l = 0U;
u32 mac_addr[2] = { 0 };
u32 efuse_addr = aq_hw_read_reg(self, HW_ATL_FW2X_MPI_EFUSE_ADDR);
if (efuse_addr != 0) {
err = hw_atl_utils_fw_downld_dwords(self,
efuse_addr + (40U * 4U),
mac_addr,
ARRAY_SIZE(mac_addr));
if (err)
return err;
mac_addr[0] = __swab32(mac_addr[0]);
mac_addr[1] = __swab32(mac_addr[1]);
}
ether_addr_copy(mac, (u8 *)mac_addr);
if ((mac[0] & 0x01U) || ((mac[0] | mac[1] | mac[2]) == 0x00U)) {
unsigned int rnd = 0;
get_random_bytes(&rnd, sizeof(unsigned int));
l = 0xE3000000U
| (0xFFFFU & rnd)
| (0x00 << 16);
h = 0x8001300EU;
mac[5] = (u8)(0xFFU & l);
l >>= 8;
mac[4] = (u8)(0xFFU & l);
l >>= 8;
mac[3] = (u8)(0xFFU & l);
l >>= 8;
mac[2] = (u8)(0xFFU & l);
mac[1] = (u8)(0xFFU & h);
h >>= 8;
mac[0] = (u8)(0xFFU & h);
}
return err;
}
static int aq_fw2x_update_stats(struct aq_hw_s *self)
{
int err = 0;
u32 mpi_opts = aq_hw_read_reg(self, HW_ATL_FW2X_MPI_CONTROL2_ADDR);
u32 orig_stats_val = mpi_opts & BIT(CAPS_HI_STATISTICS);
/* Toggle statistics bit for FW to update */
mpi_opts = mpi_opts ^ BIT(CAPS_HI_STATISTICS);
aq_hw_write_reg(self, HW_ATL_FW2X_MPI_CONTROL2_ADDR, mpi_opts);
/* Wait FW to report back */
AQ_HW_WAIT_FOR(orig_stats_val !=
(aq_hw_read_reg(self, HW_ATL_FW2X_MPI_STATE2_ADDR) &
BIT(CAPS_HI_STATISTICS)),
1U, 10000U);
if (err)
return err;
return hw_atl_utils_update_stats(self);
}
const struct aq_fw_ops aq_fw_2x_ops = {
.init = aq_fw2x_init,
.reset = NULL,
.get_mac_permanent = aq_fw2x_get_mac_permanent,
.set_link_speed = aq_fw2x_set_link_speed,
.set_state = aq_fw2x_set_state,
.update_link_status = aq_fw2x_update_link_status,
.update_stats = aq_fw2x_update_stats,
};
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
#ifndef VER_H #ifndef VER_H
#define VER_H #define VER_H
#define NIC_MAJOR_DRIVER_VERSION 1 #define NIC_MAJOR_DRIVER_VERSION 2
#define NIC_MINOR_DRIVER_VERSION 6 #define NIC_MINOR_DRIVER_VERSION 0
#define NIC_BUILD_DRIVER_VERSION 13 #define NIC_BUILD_DRIVER_VERSION 2
#define NIC_REVISION_DRIVER_VERSION 0 #define NIC_REVISION_DRIVER_VERSION 0
#define AQ_CFG_DRV_VERSION_SUFFIX "-kern" #define AQ_CFG_DRV_VERSION_SUFFIX "-kern"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment