Skip to content

Commit 23ee07a

Browse files
caildavem330
authored andcommitted
net: aquantia: Cleanup pci functions module
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8fcb98f commit 23ee07a

File tree

7 files changed

+156
-385
lines changed

7 files changed

+156
-385
lines changed

drivers/net/ethernet/aquantia/atlantic/aq_hw.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ struct aq_hw_caps_s {
3131
u32 vecs;
3232
u32 mtu;
3333
u32 mac_regs_count;
34-
u8 ports;
3534
u8 msix_irqs;
3635
u8 tcs;
3736
u8 rxd_alignment;

drivers/net/ethernet/aquantia/atlantic/aq_main.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,9 @@ struct net_device *aq_ndev_alloc(void)
4343

4444
static int aq_ndev_open(struct net_device *ndev)
4545
{
46-
struct aq_nic_s *aq_nic = NULL;
4746
int err = 0;
47+
struct aq_nic_s *aq_nic = netdev_priv(ndev);
4848

49-
aq_nic = aq_nic_alloc_hot(ndev);
50-
if (!aq_nic) {
51-
err = -ENOMEM;
52-
goto err_exit;
53-
}
5449
err = aq_nic_init(aq_nic);
5550
if (err < 0)
5651
goto err_exit;
@@ -73,7 +68,6 @@ static int aq_ndev_close(struct net_device *ndev)
7368
if (err < 0)
7469
goto err_exit;
7570
aq_nic_deinit(aq_nic);
76-
aq_nic_free_hot_resources(aq_nic);
7771

7872
err_exit:
7973
return err;
@@ -145,15 +139,13 @@ static void aq_ndev_set_multicast_settings(struct net_device *ndev)
145139

146140
err = aq_nic_set_packet_filter(aq_nic, ndev->flags);
147141
if (err < 0)
148-
goto err_exit;
142+
return;
149143

150144
if (netdev_mc_count(ndev)) {
151145
err = aq_nic_set_multicast_list(aq_nic, ndev);
152146
if (err < 0)
153-
goto err_exit;
147+
return;
154148
}
155-
156-
err_exit:;
157149
}
158150

159151
static const struct net_device_ops aq_ndev_ops = {

drivers/net/ethernet/aquantia/atlantic/aq_nic.c

Lines changed: 29 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "aq_vec.h"
1515
#include "aq_hw.h"
1616
#include "aq_pci_func.h"
17-
#include "aq_main.h"
1817

1918
#include <linux/moduleparam.h>
2019
#include <linux/netdevice.h>
@@ -61,17 +60,13 @@ static void aq_nic_rss_init(struct aq_nic_s *self, unsigned int num_rss_queues)
6160
rss_params->indirection_table[i] = i & (num_rss_queues - 1);
6261
}
6362

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

69-
cfg->vecs = AQ_CFG_VECS_DEF;
7068
cfg->tcs = AQ_CFG_TCS_DEF;
7169

72-
cfg->rxds = AQ_CFG_RXDS_DEF;
73-
cfg->txds = AQ_CFG_TXDS_DEF;
74-
7570
cfg->is_polling = AQ_CFG_IS_POLLING_DEF;
7671

7772
cfg->itr = aq_itr;
@@ -92,19 +87,13 @@ static void aq_nic_cfg_init_defaults(struct aq_nic_s *self)
9287
cfg->vlan_id = 0U;
9388

9489
aq_nic_rss_init(self, cfg->num_rss_queues);
95-
}
96-
97-
/* Checks hw_caps and 'corrects' aq_nic_cfg in runtime */
98-
int aq_nic_cfg_start(struct aq_nic_s *self)
99-
{
100-
struct aq_nic_cfg_s *cfg = &self->aq_nic_cfg;
10190

10291
/*descriptors */
103-
cfg->rxds = min(cfg->rxds, cfg->aq_hw_caps->rxds);
104-
cfg->txds = min(cfg->txds, cfg->aq_hw_caps->txds);
92+
cfg->rxds = min(cfg->aq_hw_caps->rxds, AQ_CFG_RXDS_DEF);
93+
cfg->txds = min(cfg->aq_hw_caps->txds, AQ_CFG_TXDS_DEF);
10594

10695
/*rss rings */
107-
cfg->vecs = min(cfg->vecs, cfg->aq_hw_caps->vecs);
96+
cfg->vecs = min(cfg->aq_hw_caps->vecs, AQ_CFG_VECS_DEF);
10897
cfg->vecs = min(cfg->vecs, num_online_cpus());
10998
/* cfg->vecs should be power of 2 for RSS */
11099
if (cfg->vecs >= 8U)
@@ -118,7 +107,7 @@ int aq_nic_cfg_start(struct aq_nic_s *self)
118107

119108
cfg->num_rss_queues = min(cfg->vecs, AQ_CFG_NUM_RSS_QUEUES_DEF);
120109

121-
cfg->irq_type = aq_pci_func_get_irq_type(self->aq_pci_func);
110+
cfg->irq_type = aq_pci_func_get_irq_type(self);
122111

123112
if ((cfg->irq_type == AQ_HW_IRQ_LEGACY) ||
124113
(cfg->aq_hw_caps->vecs == 1U) ||
@@ -129,7 +118,6 @@ int aq_nic_cfg_start(struct aq_nic_s *self)
129118

130119
cfg->link_speed_msk &= cfg->aq_hw_caps->link_speed_msk;
131120
cfg->hw_features = cfg->aq_hw_caps->hw_features;
132-
return 0;
133121
}
134122

135123
static int aq_nic_update_link_status(struct aq_nic_s *self)
@@ -203,50 +191,6 @@ static void aq_nic_polling_timer_cb(struct timer_list *t)
203191
AQ_CFG_POLLING_TIMER_INTERVAL);
204192
}
205193

206-
struct aq_nic_s *aq_nic_alloc_cold(struct pci_dev *pdev,
207-
struct aq_pci_func_s *aq_pci_func,
208-
unsigned int port,
209-
const struct aq_hw_ops *aq_hw_ops,
210-
const struct aq_hw_caps_s *aq_hw_caps)
211-
{
212-
struct net_device *ndev = NULL;
213-
struct aq_nic_s *self = NULL;
214-
int err = 0;
215-
216-
ndev = aq_ndev_alloc();
217-
if (!ndev) {
218-
err = -ENOMEM;
219-
goto err_exit;
220-
}
221-
222-
self = netdev_priv(ndev);
223-
224-
SET_NETDEV_DEV(ndev, &pdev->dev);
225-
226-
ndev->if_port = port;
227-
self->ndev = ndev;
228-
229-
self->aq_pci_func = aq_pci_func;
230-
231-
self->aq_hw_ops = aq_hw_ops;
232-
self->aq_nic_cfg.aq_hw_caps = aq_hw_caps;
233-
self->aq_hw->aq_nic_cfg = &self->aq_nic_cfg;
234-
self->port = (u8)port;
235-
236-
self->aq_hw = self->aq_hw_ops->create(aq_pci_func, self->port);
237-
if (err < 0)
238-
goto err_exit;
239-
240-
aq_nic_cfg_init_defaults(self);
241-
242-
err_exit:
243-
if (err < 0) {
244-
aq_nic_free_hot_resources(self);
245-
self = NULL;
246-
}
247-
return self;
248-
}
249-
250194
int aq_nic_ndev_register(struct aq_nic_s *self)
251195
{
252196
int err = 0;
@@ -255,9 +199,10 @@ int aq_nic_ndev_register(struct aq_nic_s *self)
255199
err = -EINVAL;
256200
goto err_exit;
257201
}
202+
258203
err = self->aq_hw_ops->hw_get_mac_permanent(self->aq_hw,
259204
self->ndev->dev_addr);
260-
if (err < 0)
205+
if (err)
261206
goto err_exit;
262207

263208
#if defined(AQ_CFG_MAC_ADDR_PERMANENT)
@@ -268,19 +213,29 @@ int aq_nic_ndev_register(struct aq_nic_s *self)
268213
}
269214
#endif
270215

216+
for (self->aq_vecs = 0; self->aq_vecs < aq_nic_get_cfg(self)->vecs;
217+
self->aq_vecs++) {
218+
self->aq_vec[self->aq_vecs] =
219+
aq_vec_alloc(self, self->aq_vecs, aq_nic_get_cfg(self));
220+
if (!self->aq_vec[self->aq_vecs]) {
221+
err = -ENOMEM;
222+
goto err_exit;
223+
}
224+
}
225+
271226
netif_carrier_off(self->ndev);
272227

273228
netif_tx_disable(self->ndev);
274229

275230
err = register_netdev(self->ndev);
276-
if (err < 0)
231+
if (err)
277232
goto err_exit;
278233

279234
err_exit:
280235
return err;
281236
}
282237

283-
int aq_nic_ndev_init(struct aq_nic_s *self)
238+
void aq_nic_ndev_init(struct aq_nic_s *self)
284239
{
285240
const struct aq_hw_caps_s *aq_hw_caps = self->aq_nic_cfg.aq_hw_caps;
286241
struct aq_nic_cfg_s *aq_nic_cfg = &self->aq_nic_cfg;
@@ -291,60 +246,6 @@ int aq_nic_ndev_init(struct aq_nic_s *self)
291246
self->ndev->mtu = aq_nic_cfg->mtu - ETH_HLEN;
292247
self->ndev->max_mtu = aq_hw_caps->mtu - ETH_FCS_LEN - ETH_HLEN;
293248

294-
return 0;
295-
}
296-
297-
void aq_nic_ndev_free(struct aq_nic_s *self)
298-
{
299-
if (!self->ndev)
300-
goto err_exit;
301-
302-
if (self->ndev->reg_state == NETREG_REGISTERED)
303-
unregister_netdev(self->ndev);
304-
305-
if (self->aq_hw)
306-
self->aq_hw_ops->destroy(self->aq_hw);
307-
308-
free_netdev(self->ndev);
309-
310-
err_exit:;
311-
}
312-
313-
struct aq_nic_s *aq_nic_alloc_hot(struct net_device *ndev)
314-
{
315-
struct aq_nic_s *self = NULL;
316-
int err = 0;
317-
318-
if (!ndev) {
319-
err = -EINVAL;
320-
goto err_exit;
321-
}
322-
self = netdev_priv(ndev);
323-
324-
if (!self) {
325-
err = -EINVAL;
326-
goto err_exit;
327-
}
328-
if (netif_running(ndev))
329-
netif_tx_disable(ndev);
330-
netif_carrier_off(self->ndev);
331-
332-
for (self->aq_vecs = 0; self->aq_vecs < self->aq_nic_cfg.vecs;
333-
self->aq_vecs++) {
334-
self->aq_vec[self->aq_vecs] =
335-
aq_vec_alloc(self, self->aq_vecs, &self->aq_nic_cfg);
336-
if (!self->aq_vec[self->aq_vecs]) {
337-
err = -ENOMEM;
338-
goto err_exit;
339-
}
340-
}
341-
342-
err_exit:
343-
if (err < 0) {
344-
aq_nic_free_hot_resources(self);
345-
self = NULL;
346-
}
347-
return self;
348249
}
349250

350251
void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx,
@@ -370,14 +271,16 @@ int aq_nic_init(struct aq_nic_s *self)
370271
goto err_exit;
371272

372273
err = self->aq_hw_ops->hw_init(self->aq_hw,
373-
aq_nic_get_ndev(self)->dev_addr);
274+
aq_nic_get_ndev(self)->dev_addr);
374275
if (err < 0)
375276
goto err_exit;
376277

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

282+
netif_carrier_off(self->ndev);
283+
381284
err_exit:
382285
return err;
383286
}
@@ -424,9 +327,9 @@ int aq_nic_start(struct aq_nic_s *self)
424327
} else {
425328
for (i = 0U, aq_vec = self->aq_vec[0];
426329
self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) {
427-
err = aq_pci_func_alloc_irq(self->aq_pci_func, i,
330+
err = aq_pci_func_alloc_irq(self, i,
428331
self->ndev->name, aq_vec,
429-
aq_vec_get_affinity_mask(aq_vec));
332+
aq_vec_get_affinity_mask(aq_vec));
430333
if (err < 0)
431334
goto err_exit;
432335
}
@@ -617,8 +520,7 @@ int aq_nic_xmit(struct aq_nic_s *self, struct sk_buff *skb)
617520

618521
if (likely(frags)) {
619522
err = self->aq_hw_ops->hw_ring_tx_xmit(self->aq_hw,
620-
ring,
621-
frags);
523+
ring, frags);
622524
if (err >= 0) {
623525
++ring->stats.tx.packets;
624526
ring->stats.tx.bytes += skb->len;
@@ -674,7 +576,7 @@ int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev)
674576
self->packet_filter |= IFF_ALLMULTI;
675577
self->aq_nic_cfg.mc_list_count = 0;
676578
return self->aq_hw_ops->hw_packet_filter_set(self->aq_hw,
677-
self->packet_filter);
579+
self->packet_filter);
678580
} else {
679581
return self->aq_hw_ops->hw_multicast_list_set(self->aq_hw,
680582
self->mc_list.ar,
@@ -757,7 +659,6 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data)
757659
i++;
758660

759661
data += i;
760-
count = 0U;
761662

762663
for (i = 0U, aq_vec = self->aq_vec[0];
763664
aq_vec && self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) {
@@ -937,7 +838,7 @@ int aq_nic_stop(struct aq_nic_s *self)
937838
if (self->aq_nic_cfg.is_polling)
938839
del_timer_sync(&self->polling_timer);
939840
else
940-
aq_pci_func_free_irqs(self->aq_pci_func);
841+
aq_pci_func_free_irqs(self);
941842

942843
for (i = 0U, aq_vec = self->aq_vec[0];
943844
self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i])
@@ -968,7 +869,7 @@ void aq_nic_deinit(struct aq_nic_s *self)
968869
err_exit:;
969870
}
970871

971-
void aq_nic_free_hot_resources(struct aq_nic_s *self)
872+
void aq_nic_free_vectors(struct aq_nic_s *self)
972873
{
973874
unsigned int i = 0U;
974875

drivers/net/ethernet/aquantia/atlantic/aq_nic.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "aq_hw.h"
1818

1919
struct aq_ring_s;
20-
struct aq_pci_func_s;
2120
struct aq_hw_ops;
2221
struct aq_fw_s;
2322
struct aq_vec_s;
@@ -64,7 +63,6 @@ struct aq_nic_s {
6463
struct aq_ring_s *aq_ring_tx[AQ_CFG_VECS_MAX * AQ_CFG_TCS_MAX];
6564
struct aq_hw_s *aq_hw;
6665
struct net_device *ndev;
67-
struct aq_pci_func_s *aq_pci_func;
6866
unsigned int aq_vecs;
6967
unsigned int packet_filter;
7068
unsigned int power_state;
@@ -88,19 +86,13 @@ static inline struct device *aq_nic_get_dev(struct aq_nic_s *self)
8886
return self->ndev->dev.parent;
8987
}
9088

91-
struct aq_nic_s *aq_nic_alloc_cold(struct pci_dev *pdev,
92-
struct aq_pci_func_s *aq_pci_func,
93-
unsigned int port,
94-
const struct aq_hw_ops *aq_hw_ops,
95-
const struct aq_hw_caps_s *aq_hw_caps);
96-
int aq_nic_ndev_init(struct aq_nic_s *self);
89+
void aq_nic_ndev_init(struct aq_nic_s *self);
9790
struct aq_nic_s *aq_nic_alloc_hot(struct net_device *ndev);
9891
void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx,
9992
struct aq_ring_s *ring);
100-
struct device *aq_nic_get_dev(struct aq_nic_s *self);
10193
struct net_device *aq_nic_get_ndev(struct aq_nic_s *self);
10294
int aq_nic_init(struct aq_nic_s *self);
103-
int aq_nic_cfg_start(struct aq_nic_s *self);
95+
void aq_nic_cfg_start(struct aq_nic_s *self);
10496
int aq_nic_ndev_register(struct aq_nic_s *self);
10597
void aq_nic_ndev_free(struct aq_nic_s *self);
10698
int aq_nic_start(struct aq_nic_s *self);
@@ -111,6 +103,7 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data);
111103
int aq_nic_stop(struct aq_nic_s *self);
112104
void aq_nic_deinit(struct aq_nic_s *self);
113105
void aq_nic_free_hot_resources(struct aq_nic_s *self);
106+
void aq_nic_free_vectors(struct aq_nic_s *self);
114107
int aq_nic_set_mtu(struct aq_nic_s *self, int new_mtu);
115108
int aq_nic_set_mac(struct aq_nic_s *self, struct net_device *ndev);
116109
int aq_nic_set_packet_filter(struct aq_nic_s *self, unsigned int flags);

0 commit comments

Comments
 (0)