diff options
author | Igor Russkikh <igor.russkikh@aquantia.com> | 2018-01-15 08:41:18 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-01-16 14:40:00 -0500 |
commit | 5b97b0d10eddeeec258b807f009a2cb2764653c7 (patch) | |
tree | 5d03c0038f540027814a55ef332bd97445e238a4 | |
parent | 4cbc9f92f9a134fb4c8ab190a1ed5f9014bb99a5 (diff) |
net: aquantia: Simplify dependencies between pci modules
Eliminate useless passing of net_device_ops and ethtools_ops through
deep chain of calls.
Move all pci related code into aq_pci_func module.
Signed-off-by: Igor Russkikh <igor.russkikh@aquantia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/ethernet/aquantia/atlantic/aq_main.c | 97 | ||||
-rw-r--r-- | drivers/net/ethernet/aquantia/atlantic/aq_main.h | 2 | ||||
-rw-r--r-- | drivers/net/ethernet/aquantia/atlantic/aq_nic.c | 15 | ||||
-rw-r--r-- | drivers/net/ethernet/aquantia/atlantic/aq_nic.h | 4 | ||||
-rw-r--r-- | drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c | 97 | ||||
-rw-r--r-- | drivers/net/ethernet/aquantia/atlantic/aq_pci_func.h | 4 |
6 files changed, 113 insertions, 106 deletions
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_main.c b/drivers/net/ethernet/aquantia/atlantic/aq_main.c index 1b0399c37584..c2c1eb57ab6c 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_main.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_main.c | |||
@@ -11,39 +11,35 @@ | |||
11 | 11 | ||
12 | #include "aq_main.h" | 12 | #include "aq_main.h" |
13 | #include "aq_nic.h" | 13 | #include "aq_nic.h" |
14 | #include "aq_nic_internal.h" | ||
14 | #include "aq_pci_func.h" | 15 | #include "aq_pci_func.h" |
15 | #include "aq_ethtool.h" | 16 | #include "aq_ethtool.h" |
16 | #include "hw_atl/hw_atl_a0.h" | ||
17 | #include "hw_atl/hw_atl_b0.h" | ||
18 | 17 | ||
19 | #include <linux/netdevice.h> | 18 | #include <linux/netdevice.h> |
20 | #include <linux/module.h> | 19 | #include <linux/module.h> |
21 | 20 | ||
22 | static const struct pci_device_id aq_pci_tbl[] = { | ||
23 | { PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_0001), }, | ||
24 | { PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D100), }, | ||
25 | { PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D107), }, | ||
26 | { PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D108), }, | ||
27 | { PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D109), }, | ||
28 | {} | ||
29 | }; | ||
30 | |||
31 | MODULE_DEVICE_TABLE(pci, aq_pci_tbl); | ||
32 | |||
33 | MODULE_LICENSE("GPL v2"); | 21 | MODULE_LICENSE("GPL v2"); |
34 | MODULE_VERSION(AQ_CFG_DRV_VERSION); | 22 | MODULE_VERSION(AQ_CFG_DRV_VERSION); |
35 | MODULE_AUTHOR(AQ_CFG_DRV_AUTHOR); | 23 | MODULE_AUTHOR(AQ_CFG_DRV_AUTHOR); |
36 | MODULE_DESCRIPTION(AQ_CFG_DRV_DESC); | 24 | MODULE_DESCRIPTION(AQ_CFG_DRV_DESC); |
37 | 25 | ||
38 | static const struct aq_hw_ops *aq_pci_probe_get_hw_ops_by_id(struct pci_dev *pdev) | 26 | static const struct net_device_ops aq_ndev_ops; |
27 | |||
28 | struct net_device *aq_ndev_alloc(void) | ||
39 | { | 29 | { |
40 | const struct aq_hw_ops *ops = NULL; | 30 | struct net_device *ndev = NULL; |
31 | struct aq_nic_s *aq_nic = NULL; | ||
41 | 32 | ||
42 | ops = hw_atl_a0_get_ops_by_id(pdev); | 33 | ndev = alloc_etherdev_mq(sizeof(struct aq_nic_s), AQ_CFG_VECS_MAX); |
43 | if (!ops) | 34 | if (!ndev) |
44 | ops = hw_atl_b0_get_ops_by_id(pdev); | 35 | return NULL; |
45 | 36 | ||
46 | return ops; | 37 | aq_nic = netdev_priv(ndev); |
38 | aq_nic->ndev = ndev; | ||
39 | ndev->netdev_ops = &aq_ndev_ops; | ||
40 | ndev->ethtool_ops = &aq_ethtool_ops; | ||
41 | |||
42 | return ndev; | ||
47 | } | 43 | } |
48 | 44 | ||
49 | static int aq_ndev_open(struct net_device *ndev) | 45 | static int aq_ndev_open(struct net_device *ndev) |
@@ -170,66 +166,3 @@ static const struct net_device_ops aq_ndev_ops = { | |||
170 | .ndo_set_mac_address = aq_ndev_set_mac_address, | 166 | .ndo_set_mac_address = aq_ndev_set_mac_address, |
171 | .ndo_set_features = aq_ndev_set_features | 167 | .ndo_set_features = aq_ndev_set_features |
172 | }; | 168 | }; |
173 | |||
174 | static int aq_pci_probe(struct pci_dev *pdev, | ||
175 | const struct pci_device_id *pci_id) | ||
176 | { | ||
177 | const struct aq_hw_ops *aq_hw_ops = NULL; | ||
178 | struct aq_pci_func_s *aq_pci_func = NULL; | ||
179 | int err = 0; | ||
180 | |||
181 | err = pci_enable_device(pdev); | ||
182 | if (err < 0) | ||
183 | goto err_exit; | ||
184 | aq_hw_ops = aq_pci_probe_get_hw_ops_by_id(pdev); | ||
185 | aq_pci_func = aq_pci_func_alloc(aq_hw_ops, pdev, | ||
186 | &aq_ndev_ops, &aq_ethtool_ops); | ||
187 | if (!aq_pci_func) { | ||
188 | err = -ENOMEM; | ||
189 | goto err_exit; | ||
190 | } | ||
191 | err = aq_pci_func_init(aq_pci_func); | ||
192 | if (err < 0) | ||
193 | goto err_exit; | ||
194 | |||
195 | err_exit: | ||
196 | if (err < 0) { | ||
197 | if (aq_pci_func) | ||
198 | aq_pci_func_free(aq_pci_func); | ||
199 | } | ||
200 | return err; | ||
201 | } | ||
202 | |||
203 | static void aq_pci_remove(struct pci_dev *pdev) | ||
204 | { | ||
205 | struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev); | ||
206 | |||
207 | aq_pci_func_deinit(aq_pci_func); | ||
208 | aq_pci_func_free(aq_pci_func); | ||
209 | } | ||
210 | |||
211 | static int aq_pci_suspend(struct pci_dev *pdev, pm_message_t pm_msg) | ||
212 | { | ||
213 | struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev); | ||
214 | |||
215 | return aq_pci_func_change_pm_state(aq_pci_func, &pm_msg); | ||
216 | } | ||
217 | |||
218 | static int aq_pci_resume(struct pci_dev *pdev) | ||
219 | { | ||
220 | struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev); | ||
221 | pm_message_t pm_msg = PMSG_RESTORE; | ||
222 | |||
223 | return aq_pci_func_change_pm_state(aq_pci_func, &pm_msg); | ||
224 | } | ||
225 | |||
226 | static struct pci_driver aq_pci_ops = { | ||
227 | .name = AQ_CFG_DRV_NAME, | ||
228 | .id_table = aq_pci_tbl, | ||
229 | .probe = aq_pci_probe, | ||
230 | .remove = aq_pci_remove, | ||
231 | .suspend = aq_pci_suspend, | ||
232 | .resume = aq_pci_resume, | ||
233 | }; | ||
234 | |||
235 | module_pci_driver(aq_pci_ops); | ||
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_main.h b/drivers/net/ethernet/aquantia/atlantic/aq_main.h index 9748e7e575e0..ce92152eb43e 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_main.h +++ b/drivers/net/ethernet/aquantia/atlantic/aq_main.h | |||
@@ -14,4 +14,6 @@ | |||
14 | 14 | ||
15 | #include "aq_common.h" | 15 | #include "aq_common.h" |
16 | 16 | ||
17 | struct net_device *aq_ndev_alloc(void); | ||
18 | |||
17 | #endif /* AQ_MAIN_H */ | 19 | #endif /* AQ_MAIN_H */ |
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c index f210e6237679..00b0ad92540a 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include "aq_hw.h" | 15 | #include "aq_hw.h" |
16 | #include "aq_pci_func.h" | 16 | #include "aq_pci_func.h" |
17 | #include "aq_nic_internal.h" | 17 | #include "aq_nic_internal.h" |
18 | #include "aq_main.h" | ||
18 | 19 | ||
19 | #include <linux/moduleparam.h> | 20 | #include <linux/moduleparam.h> |
20 | #include <linux/netdevice.h> | 21 | #include <linux/netdevice.h> |
@@ -205,14 +206,7 @@ static void aq_nic_polling_timer_cb(struct timer_list *t) | |||
205 | AQ_CFG_POLLING_TIMER_INTERVAL); | 206 | AQ_CFG_POLLING_TIMER_INTERVAL); |
206 | } | 207 | } |
207 | 208 | ||
208 | static struct net_device *aq_nic_ndev_alloc(void) | 209 | struct aq_nic_s *aq_nic_alloc_cold(struct pci_dev *pdev, |
209 | { | ||
210 | return alloc_etherdev_mq(sizeof(struct aq_nic_s), AQ_CFG_VECS_MAX); | ||
211 | } | ||
212 | |||
213 | struct aq_nic_s *aq_nic_alloc_cold(const struct net_device_ops *ndev_ops, | ||
214 | const struct ethtool_ops *et_ops, | ||
215 | struct pci_dev *pdev, | ||
216 | struct aq_pci_func_s *aq_pci_func, | 210 | struct aq_pci_func_s *aq_pci_func, |
217 | unsigned int port, | 211 | unsigned int port, |
218 | const struct aq_hw_ops *aq_hw_ops) | 212 | const struct aq_hw_ops *aq_hw_ops) |
@@ -221,7 +215,7 @@ struct aq_nic_s *aq_nic_alloc_cold(const struct net_device_ops *ndev_ops, | |||
221 | struct aq_nic_s *self = NULL; | 215 | struct aq_nic_s *self = NULL; |
222 | int err = 0; | 216 | int err = 0; |
223 | 217 | ||
224 | ndev = aq_nic_ndev_alloc(); | 218 | ndev = aq_ndev_alloc(); |
225 | if (!ndev) { | 219 | if (!ndev) { |
226 | err = -ENOMEM; | 220 | err = -ENOMEM; |
227 | goto err_exit; | 221 | goto err_exit; |
@@ -229,9 +223,6 @@ struct aq_nic_s *aq_nic_alloc_cold(const struct net_device_ops *ndev_ops, | |||
229 | 223 | ||
230 | self = netdev_priv(ndev); | 224 | self = netdev_priv(ndev); |
231 | 225 | ||
232 | ndev->netdev_ops = ndev_ops; | ||
233 | ndev->ethtool_ops = et_ops; | ||
234 | |||
235 | SET_NETDEV_DEV(ndev, &pdev->dev); | 226 | SET_NETDEV_DEV(ndev, &pdev->dev); |
236 | 227 | ||
237 | ndev->if_port = port; | 228 | ndev->if_port = port; |
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.h b/drivers/net/ethernet/aquantia/atlantic/aq_nic.h index 715b53c689ef..cd00faf885c6 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.h +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.h | |||
@@ -70,9 +70,7 @@ struct aq_nic_cfg_s { | |||
70 | #define AQ_NIC_TCVEC2RING(_NIC_, _TC_, _VEC_) \ | 70 | #define AQ_NIC_TCVEC2RING(_NIC_, _TC_, _VEC_) \ |
71 | ((_TC_) * AQ_CFG_TCS_MAX + (_VEC_)) | 71 | ((_TC_) * AQ_CFG_TCS_MAX + (_VEC_)) |
72 | 72 | ||
73 | struct aq_nic_s *aq_nic_alloc_cold(const struct net_device_ops *ndev_ops, | 73 | struct aq_nic_s *aq_nic_alloc_cold(struct pci_dev *pdev, |
74 | const struct ethtool_ops *et_ops, | ||
75 | struct pci_dev *pdev, | ||
76 | struct aq_pci_func_s *aq_pci_func, | 74 | struct aq_pci_func_s *aq_pci_func, |
77 | unsigned int port, | 75 | unsigned int port, |
78 | const struct aq_hw_ops *aq_hw_ops); | 76 | const struct aq_hw_ops *aq_hw_ops); |
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c b/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c index bc85809288ee..78ef7d2deffe 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c | |||
@@ -9,11 +9,15 @@ | |||
9 | 9 | ||
10 | /* File aq_pci_func.c: Definition of PCI functions. */ | 10 | /* File aq_pci_func.c: Definition of PCI functions. */ |
11 | 11 | ||
12 | #include <linux/interrupt.h> | ||
13 | #include <linux/module.h> | ||
14 | |||
12 | #include "aq_pci_func.h" | 15 | #include "aq_pci_func.h" |
13 | #include "aq_nic.h" | 16 | #include "aq_nic.h" |
14 | #include "aq_vec.h" | 17 | #include "aq_vec.h" |
15 | #include "aq_hw.h" | 18 | #include "aq_hw.h" |
16 | #include <linux/interrupt.h> | 19 | #include "hw_atl/hw_atl_a0.h" |
20 | #include "hw_atl/hw_atl_b0.h" | ||
17 | 21 | ||
18 | struct aq_pci_func_s { | 22 | struct aq_pci_func_s { |
19 | struct pci_dev *pdev; | 23 | struct pci_dev *pdev; |
@@ -29,10 +33,30 @@ struct aq_pci_func_s { | |||
29 | struct aq_hw_caps_s aq_hw_caps; | 33 | struct aq_hw_caps_s aq_hw_caps; |
30 | }; | 34 | }; |
31 | 35 | ||
36 | static const struct pci_device_id aq_pci_tbl[] = { | ||
37 | { PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_0001), }, | ||
38 | { PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D100), }, | ||
39 | { PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D107), }, | ||
40 | { PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D108), }, | ||
41 | { PCI_VDEVICE(AQUANTIA, HW_ATL_DEVICE_ID_D109), }, | ||
42 | {} | ||
43 | }; | ||
44 | |||
45 | MODULE_DEVICE_TABLE(pci, aq_pci_tbl); | ||
46 | |||
47 | static const struct aq_hw_ops *aq_pci_probe_get_hw_ops_by_id(struct pci_dev *pdev) | ||
48 | { | ||
49 | const struct aq_hw_ops *ops = NULL; | ||
50 | |||
51 | ops = hw_atl_a0_get_ops_by_id(pdev); | ||
52 | if (!ops) | ||
53 | ops = hw_atl_b0_get_ops_by_id(pdev); | ||
54 | |||
55 | return ops; | ||
56 | } | ||
57 | |||
32 | struct aq_pci_func_s *aq_pci_func_alloc(const struct aq_hw_ops *aq_hw_ops, | 58 | struct aq_pci_func_s *aq_pci_func_alloc(const struct aq_hw_ops *aq_hw_ops, |
33 | struct pci_dev *pdev, | 59 | struct pci_dev *pdev) |
34 | const struct net_device_ops *ndev_ops, | ||
35 | const struct ethtool_ops *eth_ops) | ||
36 | { | 60 | { |
37 | struct aq_pci_func_s *self = NULL; | 61 | struct aq_pci_func_s *self = NULL; |
38 | int err = 0; | 62 | int err = 0; |
@@ -59,8 +83,7 @@ struct aq_pci_func_s *aq_pci_func_alloc(const struct aq_hw_ops *aq_hw_ops, | |||
59 | self->ports = self->aq_hw_caps.ports; | 83 | self->ports = self->aq_hw_caps.ports; |
60 | 84 | ||
61 | for (port = 0; port < self->ports; ++port) { | 85 | for (port = 0; port < self->ports; ++port) { |
62 | struct aq_nic_s *aq_nic = aq_nic_alloc_cold(ndev_ops, eth_ops, | 86 | struct aq_nic_s *aq_nic = aq_nic_alloc_cold(pdev, self, |
63 | pdev, self, | ||
64 | port, aq_hw_ops); | 87 | port, aq_hw_ops); |
65 | 88 | ||
66 | if (!aq_nic) { | 89 | if (!aq_nic) { |
@@ -297,3 +320,65 @@ int aq_pci_func_change_pm_state(struct aq_pci_func_s *self, | |||
297 | err_exit: | 320 | err_exit: |
298 | return err; | 321 | return err; |
299 | } | 322 | } |
323 | |||
324 | static int aq_pci_probe(struct pci_dev *pdev, | ||
325 | const struct pci_device_id *pci_id) | ||
326 | { | ||
327 | const struct aq_hw_ops *aq_hw_ops = NULL; | ||
328 | struct aq_pci_func_s *aq_pci_func = NULL; | ||
329 | int err = 0; | ||
330 | |||
331 | err = pci_enable_device(pdev); | ||
332 | if (err < 0) | ||
333 | goto err_exit; | ||
334 | aq_hw_ops = aq_pci_probe_get_hw_ops_by_id(pdev); | ||
335 | aq_pci_func = aq_pci_func_alloc(aq_hw_ops, pdev); | ||
336 | if (!aq_pci_func) { | ||
337 | err = -ENOMEM; | ||
338 | goto err_exit; | ||
339 | } | ||
340 | err = aq_pci_func_init(aq_pci_func); | ||
341 | if (err < 0) | ||
342 | goto err_exit; | ||
343 | |||
344 | err_exit: | ||
345 | if (err < 0) { | ||
346 | if (aq_pci_func) | ||
347 | aq_pci_func_free(aq_pci_func); | ||
348 | } | ||
349 | return err; | ||
350 | } | ||
351 | |||
352 | static void aq_pci_remove(struct pci_dev *pdev) | ||
353 | { | ||
354 | struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev); | ||
355 | |||
356 | aq_pci_func_deinit(aq_pci_func); | ||
357 | aq_pci_func_free(aq_pci_func); | ||
358 | } | ||
359 | |||
360 | static int aq_pci_suspend(struct pci_dev *pdev, pm_message_t pm_msg) | ||
361 | { | ||
362 | struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev); | ||
363 | |||
364 | return aq_pci_func_change_pm_state(aq_pci_func, &pm_msg); | ||
365 | } | ||
366 | |||
367 | static int aq_pci_resume(struct pci_dev *pdev) | ||
368 | { | ||
369 | struct aq_pci_func_s *aq_pci_func = pci_get_drvdata(pdev); | ||
370 | pm_message_t pm_msg = PMSG_RESTORE; | ||
371 | |||
372 | return aq_pci_func_change_pm_state(aq_pci_func, &pm_msg); | ||
373 | } | ||
374 | |||
375 | static struct pci_driver aq_pci_ops = { | ||
376 | .name = AQ_CFG_DRV_NAME, | ||
377 | .id_table = aq_pci_tbl, | ||
378 | .probe = aq_pci_probe, | ||
379 | .remove = aq_pci_remove, | ||
380 | .suspend = aq_pci_suspend, | ||
381 | .resume = aq_pci_resume, | ||
382 | }; | ||
383 | |||
384 | module_pci_driver(aq_pci_ops); | ||
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.h b/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.h index 84465220b36b..5f100ea1b0d6 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.h +++ b/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.h | |||
@@ -16,9 +16,7 @@ | |||
16 | #include "aq_nic.h" | 16 | #include "aq_nic.h" |
17 | 17 | ||
18 | struct aq_pci_func_s *aq_pci_func_alloc(const struct aq_hw_ops *hw_ops, | 18 | struct aq_pci_func_s *aq_pci_func_alloc(const struct aq_hw_ops *hw_ops, |
19 | struct pci_dev *pdev, | 19 | struct pci_dev *pdev); |
20 | const struct net_device_ops *ndev_ops, | ||
21 | const struct ethtool_ops *eth_ops); | ||
22 | int aq_pci_func_init(struct aq_pci_func_s *self); | 20 | int aq_pci_func_init(struct aq_pci_func_s *self); |
23 | int aq_pci_func_alloc_irq(struct aq_pci_func_s *self, unsigned int i, | 21 | int aq_pci_func_alloc_irq(struct aq_pci_func_s *self, unsigned int i, |
24 | char *name, void *aq_vec, | 22 | char *name, void *aq_vec, |