Skip to content

Commit

Permalink
net: aquantia: Cleanup pci functions module
Browse files Browse the repository at this point in the history
Driver contained a dead code of maintaining multiple pci port instances.
That will never be used since for each pci function a separate NIC
instance is created.
Simplify this, making pci module only responsible for pci resource
management.
NIC initialization is also simplified accordingly.

Signed-off-by: Igor Russkikh <igor.russkikh@aquantia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Igor Russkikh authored and David S. Miller committed Jan 21, 2018
1 parent 8fcb98f commit 23ee07a
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 385 deletions.
1 change: 0 additions & 1 deletion drivers/net/ethernet/aquantia/atlantic/aq_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct aq_hw_caps_s {
u32 vecs;
u32 mtu;
u32 mac_regs_count;
u8 ports;
u8 msix_irqs;
u8 tcs;
u8 rxd_alignment;
Expand Down
14 changes: 3 additions & 11 deletions drivers/net/ethernet/aquantia/atlantic/aq_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,9 @@ struct net_device *aq_ndev_alloc(void)

static int aq_ndev_open(struct net_device *ndev)
{
struct aq_nic_s *aq_nic = NULL;
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);
if (err < 0)
goto err_exit;
Expand All @@ -73,7 +68,6 @@ static int aq_ndev_close(struct net_device *ndev)
if (err < 0)
goto err_exit;
aq_nic_deinit(aq_nic);
aq_nic_free_hot_resources(aq_nic);

err_exit:
return err;
Expand Down Expand Up @@ -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);
if (err < 0)
goto err_exit;
return;

if (netdev_mc_count(ndev)) {
err = aq_nic_set_multicast_list(aq_nic, ndev);
if (err < 0)
goto err_exit;
return;
}

err_exit:;
}

static const struct net_device_ops aq_ndev_ops = {
Expand Down
157 changes: 29 additions & 128 deletions drivers/net/ethernet/aquantia/atlantic/aq_nic.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "aq_vec.h"
#include "aq_hw.h"
#include "aq_pci_func.h"
#include "aq_main.h"

#include <linux/moduleparam.h>
#include <linux/netdevice.h>
Expand Down Expand Up @@ -61,17 +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);
}

/* Fills aq_nic_cfg with valid defaults */
static void aq_nic_cfg_init_defaults(struct aq_nic_s *self)
/* Checks hw_caps and 'corrects' aq_nic_cfg in runtime */
void aq_nic_cfg_start(struct aq_nic_s *self)
{
struct aq_nic_cfg_s *cfg = &self->aq_nic_cfg;

cfg->vecs = AQ_CFG_VECS_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->itr = aq_itr;
Expand All @@ -92,19 +87,13 @@ static void aq_nic_cfg_init_defaults(struct aq_nic_s *self)
cfg->vlan_id = 0U;

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 */
cfg->rxds = min(cfg->rxds, cfg->aq_hw_caps->rxds);
cfg->txds = min(cfg->txds, cfg->aq_hw_caps->txds);
cfg->rxds = min(cfg->aq_hw_caps->rxds, AQ_CFG_RXDS_DEF);
cfg->txds = min(cfg->aq_hw_caps->txds, AQ_CFG_TXDS_DEF);

/*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 should be power of 2 for RSS */
if (cfg->vecs >= 8U)
Expand All @@ -118,7 +107,7 @@ int aq_nic_cfg_start(struct aq_nic_s *self)

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) ||
(cfg->aq_hw_caps->vecs == 1U) ||
Expand All @@ -129,7 +118,6 @@ int aq_nic_cfg_start(struct aq_nic_s *self)

cfg->link_speed_msk &= cfg->aq_hw_caps->link_speed_msk;
cfg->hw_features = cfg->aq_hw_caps->hw_features;
return 0;
}

static int aq_nic_update_link_status(struct aq_nic_s *self)
Expand Down Expand Up @@ -203,50 +191,6 @@ static void aq_nic_polling_timer_cb(struct timer_list *t)
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,
const struct aq_hw_caps_s *aq_hw_caps)
{
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->aq_nic_cfg.aq_hw_caps = aq_hw_caps;
self->aq_hw->aq_nic_cfg = &self->aq_nic_cfg;
self->port = (u8)port;

self->aq_hw = self->aq_hw_ops->create(aq_pci_func, self->port);
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 err = 0;
Expand All @@ -255,9 +199,10 @@ int aq_nic_ndev_register(struct aq_nic_s *self)
err = -EINVAL;
goto err_exit;
}

err = self->aq_hw_ops->hw_get_mac_permanent(self->aq_hw,
self->ndev->dev_addr);
if (err < 0)
if (err)
goto err_exit;

#if defined(AQ_CFG_MAC_ADDR_PERMANENT)
Expand All @@ -268,19 +213,29 @@ int aq_nic_ndev_register(struct aq_nic_s *self)
}
#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_tx_disable(self->ndev);

err = register_netdev(self->ndev);
if (err < 0)
if (err)
goto err_exit;

err_exit:
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;
struct aq_nic_cfg_s *aq_nic_cfg = &self->aq_nic_cfg;
Expand All @@ -291,60 +246,6 @@ int aq_nic_ndev_init(struct aq_nic_s *self)
self->ndev->mtu = aq_nic_cfg->mtu - 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,
Expand All @@ -370,14 +271,16 @@ int aq_nic_init(struct aq_nic_s *self)
goto err_exit;

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)
goto err_exit;

for (i = 0U, aq_vec = self->aq_vec[0];
self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i])
aq_vec_init(aq_vec, self->aq_hw_ops, self->aq_hw);

netif_carrier_off(self->ndev);

err_exit:
return err;
}
Expand Down Expand Up @@ -424,9 +327,9 @@ int aq_nic_start(struct aq_nic_s *self)
} else {
for (i = 0U, aq_vec = self->aq_vec[0];
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,
aq_vec_get_affinity_mask(aq_vec));
aq_vec_get_affinity_mask(aq_vec));
if (err < 0)
goto err_exit;
}
Expand Down Expand Up @@ -617,8 +520,7 @@ int aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb)

if (likely(frags)) {
err = self->aq_hw_ops->hw_ring_tx_xmit(self->aq_hw,
ring,
frags);
ring, frags);
if (err >= 0) {
++ring->stats.tx.packets;
ring->stats.tx.bytes += skb->len;
Expand Down Expand Up @@ -674,7 +576,7 @@ int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev)
self->packet_filter |= IFF_ALLMULTI;
self->aq_nic_cfg.mc_list_count = 0;
return self->aq_hw_ops->hw_packet_filter_set(self->aq_hw,
self->packet_filter);
self->packet_filter);
} else {
return self->aq_hw_ops->hw_multicast_list_set(self->aq_hw,
self->mc_list.ar,
Expand Down Expand Up @@ -757,7 +659,6 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data)
i++;

data += i;
count = 0U;

for (i = 0U, aq_vec = self->aq_vec[0];
aq_vec && self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) {
Expand Down Expand Up @@ -937,7 +838,7 @@ int aq_nic_stop(struct aq_nic_s *self)
if (self->aq_nic_cfg.is_polling)
del_timer_sync(&self->polling_timer);
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];
self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i])
Expand Down Expand Up @@ -968,7 +869,7 @@ void aq_nic_deinit(struct aq_nic_s *self)
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;

Expand Down
13 changes: 3 additions & 10 deletions drivers/net/ethernet/aquantia/atlantic/aq_nic.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "aq_hw.h"

struct aq_ring_s;
struct aq_pci_func_s;
struct aq_hw_ops;
struct aq_fw_s;
struct aq_vec_s;
Expand Down Expand Up @@ -64,7 +63,6 @@ struct aq_nic_s {
struct aq_ring_s *aq_ring_tx[AQ_CFG_VECS_MAX * AQ_CFG_TCS_MAX];
struct aq_hw_s *aq_hw;
struct net_device *ndev;
struct aq_pci_func_s *aq_pci_func;
unsigned int aq_vecs;
unsigned int packet_filter;
unsigned int power_state;
Expand All @@ -88,19 +86,13 @@ static inline struct device *aq_nic_get_dev(struct aq_nic_s *self)
return self->ndev->dev.parent;
}

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,
const struct aq_hw_caps_s *aq_hw_caps);
int aq_nic_ndev_init(struct aq_nic_s *self);
void aq_nic_ndev_init(struct aq_nic_s *self);
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,
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);
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);
void aq_nic_ndev_free(struct aq_nic_s *self);
int aq_nic_start(struct aq_nic_s *self);
Expand All @@ -111,6 +103,7 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data);
int aq_nic_stop(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_vectors(struct aq_nic_s *self);
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_packet_filter(struct aq_nic_s *self, unsigned int flags);
Expand Down
Loading

0 comments on commit 23ee07a

Please sign in to comment.