hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c
....@@ -1,10 +1,8 @@
1
-/*
2
- * aQuantia Corporation Network Driver
3
- * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
1
+// SPDX-License-Identifier: GPL-2.0-only
2
+/* Atlantic Network Driver
43 *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
4
+ * Copyright (C) 2014-2019 aQuantia Corporation
5
+ * Copyright (C) 2019-2020 Marvell International Ltd.
86 */
97
108 /* File aq_pci_func.c: Definition of PCI functions. */
....@@ -19,6 +17,10 @@
1917 #include "aq_pci_func.h"
2018 #include "hw_atl/hw_atl_a0.h"
2119 #include "hw_atl/hw_atl_b0.h"
20
+#include "hw_atl2/hw_atl2.h"
21
+#include "aq_filters.h"
22
+#include "aq_drvinfo.h"
23
+#include "aq_macsec.h"
2224
2325 static const struct pci_device_id aq_pci_tbl[] = {
2426 { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_0001), },
....@@ -41,8 +43,14 @@
4143 { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC111S), },
4244 { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC112S), },
4345
44
- { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC111E), },
45
- { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC112E), },
46
+ { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC113DEV), },
47
+ { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC113CS), },
48
+ { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC114CS), },
49
+ { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC113), },
50
+ { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC113C), },
51
+ { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC115C), },
52
+ { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC113CA), },
53
+ { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC116C), },
4654
4755 {}
4856 };
....@@ -74,8 +82,15 @@
7482 { AQ_DEVICE_ID_AQC111S, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc111s, },
7583 { AQ_DEVICE_ID_AQC112S, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc112s, },
7684
77
- { AQ_DEVICE_ID_AQC111E, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc111e, },
78
- { AQ_DEVICE_ID_AQC112E, AQ_HWREV_ANY, &hw_atl_ops_b1, &hw_atl_b0_caps_aqc112e, },
85
+ { AQ_DEVICE_ID_AQC113DEV, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, },
86
+ { AQ_DEVICE_ID_AQC113, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, },
87
+ { AQ_DEVICE_ID_AQC113CS, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, },
88
+ { AQ_DEVICE_ID_AQC114CS, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, },
89
+ { AQ_DEVICE_ID_AQC113C, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, },
90
+ { AQ_DEVICE_ID_AQC115C, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc115c, },
91
+ { AQ_DEVICE_ID_AQC113CA, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, },
92
+ { AQ_DEVICE_ID_AQC116C, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc116c, },
93
+
7994 };
8095
8196 MODULE_DEVICE_TABLE(pci, aq_pci_tbl);
....@@ -84,7 +99,7 @@
8499 const struct aq_hw_ops **ops,
85100 const struct aq_hw_caps_s **caps)
86101 {
87
- int i = 0;
102
+ int i;
88103
89104 if (pdev->vendor != PCI_VENDOR_ID_AQUANTIA)
90105 return -EINVAL;
....@@ -105,15 +120,13 @@
105120 return 0;
106121 }
107122
108
-int aq_pci_func_init(struct pci_dev *pdev)
123
+static int aq_pci_func_init(struct pci_dev *pdev)
109124 {
110
- int err = 0;
125
+ int err;
111126
112127 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
113
- if (!err) {
128
+ if (!err)
114129 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
115
-
116
- }
117130 if (err) {
118131 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
119132 if (!err)
....@@ -138,41 +151,50 @@
138151 }
139152
140153 int aq_pci_func_alloc_irq(struct aq_nic_s *self, unsigned int i,
141
- char *name, void *aq_vec, cpumask_t *affinity_mask)
154
+ char *name, irq_handler_t irq_handler,
155
+ void *irq_arg, cpumask_t *affinity_mask)
142156 {
143157 struct pci_dev *pdev = self->pdev;
144
- int err = 0;
158
+ int err;
145159
146160 if (pdev->msix_enabled || pdev->msi_enabled)
147
- err = request_irq(pci_irq_vector(pdev, i), aq_vec_isr, 0,
148
- name, aq_vec);
161
+ err = request_irq(pci_irq_vector(pdev, i), irq_handler, 0,
162
+ name, irq_arg);
149163 else
150164 err = request_irq(pci_irq_vector(pdev, i), aq_vec_isr_legacy,
151
- IRQF_SHARED, name, aq_vec);
165
+ IRQF_SHARED, name, irq_arg);
152166
153167 if (err >= 0) {
154168 self->msix_entry_mask |= (1 << i);
155
- self->aq_vec[i] = aq_vec;
156169
157
- if (pdev->msix_enabled)
170
+ if (pdev->msix_enabled && affinity_mask)
158171 irq_set_affinity_hint(pci_irq_vector(pdev, i),
159172 affinity_mask);
160173 }
174
+
161175 return err;
162176 }
163177
164178 void aq_pci_func_free_irqs(struct aq_nic_s *self)
165179 {
166180 struct pci_dev *pdev = self->pdev;
167
- unsigned int i = 0U;
181
+ unsigned int i;
182
+ void *irq_data;
168183
169184 for (i = 32U; i--;) {
170185 if (!((1U << i) & self->msix_entry_mask))
171186 continue;
187
+ if (self->aq_nic_cfg.link_irq_vec &&
188
+ i == self->aq_nic_cfg.link_irq_vec)
189
+ irq_data = self;
190
+ else if (i < AQ_CFG_VECS_MAX)
191
+ irq_data = self->aq_vec[i];
192
+ else
193
+ continue;
172194
173195 if (pdev->msix_enabled)
174196 irq_set_affinity_hint(pci_irq_vector(pdev, i), NULL);
175
- free_irq(pci_irq_vector(pdev, i), self->aq_vec[i]);
197
+ free_irq(pci_irq_vector(pdev, i), irq_data);
176198 self->msix_entry_mask &= ~(1U << i);
177199 }
178200 }
....@@ -182,7 +204,8 @@
182204 if (self->pdev->msix_enabled)
183205 return AQ_HW_IRQ_MSIX;
184206 if (self->pdev->msi_enabled)
185
- return AQ_HW_IRQ_MSIX;
207
+ return AQ_HW_IRQ_MSI;
208
+
186209 return AQ_HW_IRQ_LEGACY;
187210 }
188211
....@@ -194,12 +217,12 @@
194217 static int aq_pci_probe(struct pci_dev *pdev,
195218 const struct pci_device_id *pci_id)
196219 {
197
- struct aq_nic_s *self = NULL;
198
- int err = 0;
199220 struct net_device *ndev;
200221 resource_size_t mmio_pa;
201
- u32 bar;
222
+ struct aq_nic_s *self;
202223 u32 numvecs;
224
+ u32 bar;
225
+ int err;
203226
204227 err = pci_enable_device(pdev);
205228 if (err)
....@@ -220,6 +243,8 @@
220243 SET_NETDEV_DEV(ndev, &pdev->dev);
221244 pci_set_drvdata(pdev, self);
222245
246
+ mutex_init(&self->fwreq_mutex);
247
+
223248 err = aq_pci_probe_get_hw_by_id(pdev, &self->aq_hw_ops,
224249 &aq_nic_get_cfg(self)->aq_hw_caps);
225250 if (err)
....@@ -231,6 +256,15 @@
231256 goto err_ioremap;
232257 }
233258 self->aq_hw->aq_nic_cfg = aq_nic_get_cfg(self);
259
+ if (self->aq_hw->aq_nic_cfg->aq_hw_caps->priv_data_len) {
260
+ int len = self->aq_hw->aq_nic_cfg->aq_hw_caps->priv_data_len;
261
+
262
+ self->aq_hw->priv = kzalloc(len, GFP_KERNEL);
263
+ if (!self->aq_hw->priv) {
264
+ err = -ENOMEM;
265
+ goto err_free_aq_hw;
266
+ }
267
+ }
234268
235269 for (bar = 0; bar < 4; ++bar) {
236270 if (IORESOURCE_MEM & pci_resource_flags(pdev, bar)) {
....@@ -239,19 +273,19 @@
239273 mmio_pa = pci_resource_start(pdev, bar);
240274 if (mmio_pa == 0U) {
241275 err = -EIO;
242
- goto err_free_aq_hw;
276
+ goto err_free_aq_hw_priv;
243277 }
244278
245279 reg_sz = pci_resource_len(pdev, bar);
246280 if ((reg_sz <= 24 /*ATL_REGS_SIZE*/)) {
247281 err = -EIO;
248
- goto err_free_aq_hw;
282
+ goto err_free_aq_hw_priv;
249283 }
250284
251
- self->aq_hw->mmio = ioremap_nocache(mmio_pa, reg_sz);
285
+ self->aq_hw->mmio = ioremap(mmio_pa, reg_sz);
252286 if (!self->aq_hw->mmio) {
253287 err = -EIO;
254
- goto err_free_aq_hw;
288
+ goto err_free_aq_hw_priv;
255289 }
256290 break;
257291 }
....@@ -259,12 +293,16 @@
259293
260294 if (bar == 4) {
261295 err = -EIO;
262
- goto err_free_aq_hw;
296
+ goto err_free_aq_hw_priv;
263297 }
264298
265299 numvecs = min((u8)AQ_CFG_VECS_DEF,
266300 aq_nic_get_cfg(self)->aq_hw_caps->msix_irqs);
267301 numvecs = min(numvecs, num_online_cpus());
302
+ /* Request IRQ vector for PTP */
303
+ numvecs += 1;
304
+
305
+ numvecs += AQ_HW_SERVICE_IRQS;
268306 /*enable interrupts */
269307 #if !AQ_CFG_FORCE_LEGACY_INT
270308 err = pci_alloc_irq_vectors(self->pdev, 1, numvecs,
....@@ -286,6 +324,8 @@
286324 if (err < 0)
287325 goto err_register;
288326
327
+ aq_drvinfo_init(ndev);
328
+
289329 return 0;
290330
291331 err_register:
....@@ -293,6 +333,8 @@
293333 aq_pci_free_irq_vectors(self);
294334 err_hwinit:
295335 iounmap(self->aq_hw->mmio);
336
+err_free_aq_hw_priv:
337
+ kfree(self->aq_hw->priv);
296338 err_free_aq_hw:
297339 kfree(self->aq_hw);
298340 err_ioremap:
....@@ -301,6 +343,7 @@
301343 pci_release_regions(pdev);
302344 err_pci_func:
303345 pci_disable_device(pdev);
346
+
304347 return err;
305348 }
306349
....@@ -309,11 +352,17 @@
309352 struct aq_nic_s *self = pci_get_drvdata(pdev);
310353
311354 if (self->ndev) {
355
+ aq_clear_rxnfc_all_rules(self);
312356 if (self->ndev->reg_state == NETREG_REGISTERED)
313357 unregister_netdev(self->ndev);
358
+
359
+#if IS_ENABLED(CONFIG_MACSEC)
360
+ aq_macsec_free(self);
361
+#endif
314362 aq_nic_free_vectors(self);
315363 aq_pci_free_irq_vectors(self);
316364 iounmap(self->aq_hw->mmio);
365
+ kfree(self->aq_hw->priv);
317366 kfree(self->aq_hw);
318367 pci_release_regions(pdev);
319368 free_netdev(self->ndev);
....@@ -336,29 +385,109 @@
336385 }
337386 }
338387
339
-static int aq_pci_suspend(struct pci_dev *pdev, pm_message_t pm_msg)
388
+static int aq_suspend_common(struct device *dev)
340389 {
341
- struct aq_nic_s *self = pci_get_drvdata(pdev);
390
+ struct aq_nic_s *nic = pci_get_drvdata(to_pci_dev(dev));
342391
343
- return aq_nic_change_pm_state(self, &pm_msg);
392
+ rtnl_lock();
393
+
394
+ nic->power_state = AQ_HW_POWER_STATE_D3;
395
+ netif_device_detach(nic->ndev);
396
+ netif_tx_stop_all_queues(nic->ndev);
397
+
398
+ if (netif_running(nic->ndev))
399
+ aq_nic_stop(nic);
400
+
401
+ aq_nic_deinit(nic, !nic->aq_hw->aq_nic_cfg->wol);
402
+ aq_nic_set_power(nic);
403
+
404
+ rtnl_unlock();
405
+
406
+ return 0;
344407 }
345408
346
-static int aq_pci_resume(struct pci_dev *pdev)
409
+static int atl_resume_common(struct device *dev)
347410 {
348
- struct aq_nic_s *self = pci_get_drvdata(pdev);
349
- pm_message_t pm_msg = PMSG_RESTORE;
411
+ struct pci_dev *pdev = to_pci_dev(dev);
412
+ struct aq_nic_s *nic;
413
+ int ret = 0;
350414
351
- return aq_nic_change_pm_state(self, &pm_msg);
415
+ nic = pci_get_drvdata(pdev);
416
+
417
+ rtnl_lock();
418
+
419
+ pci_set_power_state(pdev, PCI_D0);
420
+ pci_restore_state(pdev);
421
+
422
+ if (netif_running(nic->ndev)) {
423
+ ret = aq_nic_init(nic);
424
+ if (ret)
425
+ goto err_exit;
426
+
427
+ ret = aq_nic_start(nic);
428
+ if (ret)
429
+ goto err_exit;
430
+ }
431
+
432
+ netif_device_attach(nic->ndev);
433
+ netif_tx_start_all_queues(nic->ndev);
434
+
435
+err_exit:
436
+ if (ret < 0)
437
+ aq_nic_deinit(nic, true);
438
+
439
+ rtnl_unlock();
440
+
441
+ return ret;
352442 }
443
+
444
+static int aq_pm_freeze(struct device *dev)
445
+{
446
+ return aq_suspend_common(dev);
447
+}
448
+
449
+static int aq_pm_suspend_poweroff(struct device *dev)
450
+{
451
+ return aq_suspend_common(dev);
452
+}
453
+
454
+static int aq_pm_thaw(struct device *dev)
455
+{
456
+ return atl_resume_common(dev);
457
+}
458
+
459
+static int aq_pm_resume_restore(struct device *dev)
460
+{
461
+ return atl_resume_common(dev);
462
+}
463
+
464
+static const struct dev_pm_ops aq_pm_ops = {
465
+ .suspend = aq_pm_suspend_poweroff,
466
+ .poweroff = aq_pm_suspend_poweroff,
467
+ .freeze = aq_pm_freeze,
468
+ .resume = aq_pm_resume_restore,
469
+ .restore = aq_pm_resume_restore,
470
+ .thaw = aq_pm_thaw,
471
+};
353472
354473 static struct pci_driver aq_pci_ops = {
355474 .name = AQ_CFG_DRV_NAME,
356475 .id_table = aq_pci_tbl,
357476 .probe = aq_pci_probe,
358477 .remove = aq_pci_remove,
359
- .suspend = aq_pci_suspend,
360
- .resume = aq_pci_resume,
361478 .shutdown = aq_pci_shutdown,
479
+#ifdef CONFIG_PM
480
+ .driver.pm = &aq_pm_ops,
481
+#endif
362482 };
363483
364
-module_pci_driver(aq_pci_ops);
484
+int aq_pci_func_register_driver(void)
485
+{
486
+ return pci_register_driver(&aq_pci_ops);
487
+}
488
+
489
+void aq_pci_func_unregister_driver(void)
490
+{
491
+ pci_unregister_driver(&aq_pci_ops);
492
+}
493
+