1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "i40evf.h"
28#include "i40e_prototype.h"
29static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter);
30static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter);
31static int i40evf_close(struct net_device *netdev);
32
33char i40evf_driver_name[] = "i40evf";
34static const char i40evf_driver_string[] =
35 "Intel(R) XL710/X710 Virtual Function Network Driver";
36
37#define DRV_VERSION "1.2.25"
38const char i40evf_driver_version[] = DRV_VERSION;
39static const char i40evf_copyright[] =
40 "Copyright (c) 2013 - 2014 Intel Corporation.";
41
42
43
44
45
46
47
48
49
50static const struct pci_device_id i40evf_pci_tbl[] = {
51 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
52
53 {0, }
54};
55
56MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
57
58MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
59MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
60MODULE_LICENSE("GPL");
61MODULE_VERSION(DRV_VERSION);
62
63
64
65
66
67
68
69
70i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
71 struct i40e_dma_mem *mem,
72 u64 size, u32 alignment)
73{
74 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
75
76 if (!mem)
77 return I40E_ERR_PARAM;
78
79 mem->size = ALIGN(size, alignment);
80 mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
81 (dma_addr_t *)&mem->pa, GFP_KERNEL);
82 if (mem->va)
83 return 0;
84 else
85 return I40E_ERR_NO_MEMORY;
86}
87
88
89
90
91
92
93i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
94{
95 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
96
97 if (!mem || !mem->va)
98 return I40E_ERR_PARAM;
99 dma_free_coherent(&adapter->pdev->dev, mem->size,
100 mem->va, (dma_addr_t)mem->pa);
101 return 0;
102}
103
104
105
106
107
108
109
110i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
111 struct i40e_virt_mem *mem, u32 size)
112{
113 if (!mem)
114 return I40E_ERR_PARAM;
115
116 mem->size = size;
117 mem->va = kzalloc(size, GFP_KERNEL);
118
119 if (mem->va)
120 return 0;
121 else
122 return I40E_ERR_NO_MEMORY;
123}
124
125
126
127
128
129
130i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
131 struct i40e_virt_mem *mem)
132{
133 if (!mem)
134 return I40E_ERR_PARAM;
135
136
137 kfree(mem->va);
138
139 return 0;
140}
141
142
143
144
145
146
147
148void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
149{
150 char buf[512];
151 va_list argptr;
152
153 if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
154 return;
155
156 va_start(argptr, fmt_str);
157 vsnprintf(buf, sizeof(buf), fmt_str, argptr);
158 va_end(argptr);
159
160
161 pr_info("%s", buf);
162}
163
164
165
166
167
168static void i40evf_tx_timeout(struct net_device *netdev)
169{
170 struct i40evf_adapter *adapter = netdev_priv(netdev);
171
172 adapter->tx_timeout_count++;
173 if (!(adapter->flags & (I40EVF_FLAG_RESET_PENDING |
174 I40EVF_FLAG_RESET_NEEDED))) {
175 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
176 schedule_work(&adapter->reset_task);
177 }
178}
179
180
181
182
183
184static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
185{
186 struct i40e_hw *hw = &adapter->hw;
187
188 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
189
190
191 rd32(hw, I40E_VFGEN_RSTAT);
192
193 synchronize_irq(adapter->msix_entries[0].vector);
194}
195
196
197
198
199
200static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
201{
202 struct i40e_hw *hw = &adapter->hw;
203
204 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
205 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
206 wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA_ADMINQ_MASK);
207
208
209 rd32(hw, I40E_VFGEN_RSTAT);
210}
211
212
213
214
215
216static void i40evf_irq_disable(struct i40evf_adapter *adapter)
217{
218 int i;
219 struct i40e_hw *hw = &adapter->hw;
220
221 if (!adapter->msix_entries)
222 return;
223
224 for (i = 1; i < adapter->num_msix_vectors; i++) {
225 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
226 synchronize_irq(adapter->msix_entries[i].vector);
227 }
228
229 rd32(hw, I40E_VFGEN_RSTAT);
230}
231
232
233
234
235
236
237void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
238{
239 struct i40e_hw *hw = &adapter->hw;
240 int i;
241
242 for (i = 1; i < adapter->num_msix_vectors; i++) {
243 if (mask & (1 << (i - 1))) {
244 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
245 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
246 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
247 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
248 }
249 }
250}
251
252
253
254
255
256
257static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask)
258{
259 struct i40e_hw *hw = &adapter->hw;
260 int i;
261 uint32_t dyn_ctl;
262
263 if (mask & 1) {
264 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01);
265 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
266 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
267 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
268 wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl);
269 }
270 for (i = 1; i < adapter->num_msix_vectors; i++) {
271 if (mask & (1 << i)) {
272 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
273 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
274 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
275 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
276 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
277 }
278 }
279}
280
281
282
283
284
285void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
286{
287 struct i40e_hw *hw = &adapter->hw;
288
289 i40evf_misc_irq_enable(adapter);
290 i40evf_irq_enable_queues(adapter, ~0);
291
292 if (flush)
293 rd32(hw, I40E_VFGEN_RSTAT);
294}
295
296
297
298
299
300
301static irqreturn_t i40evf_msix_aq(int irq, void *data)
302{
303 struct net_device *netdev = data;
304 struct i40evf_adapter *adapter = netdev_priv(netdev);
305 struct i40e_hw *hw = &adapter->hw;
306 u32 val;
307 u32 ena_mask;
308
309
310 val = rd32(hw, I40E_VFINT_ICR01);
311 ena_mask = rd32(hw, I40E_VFINT_ICR0_ENA1);
312
313
314 val = rd32(hw, I40E_VFINT_DYN_CTL01);
315 val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK;
316 wr32(hw, I40E_VFINT_DYN_CTL01, val);
317
318
319 schedule_work(&adapter->adminq_task);
320
321 return IRQ_HANDLED;
322}
323
324
325
326
327
328
329static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
330{
331 struct i40e_q_vector *q_vector = data;
332
333 if (!q_vector->tx.ring && !q_vector->rx.ring)
334 return IRQ_HANDLED;
335
336 napi_schedule(&q_vector->napi);
337
338 return IRQ_HANDLED;
339}
340
341
342
343
344
345
346
347static void
348i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
349{
350 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
351 struct i40e_ring *rx_ring = adapter->rx_rings[r_idx];
352
353 rx_ring->q_vector = q_vector;
354 rx_ring->next = q_vector->rx.ring;
355 rx_ring->vsi = &adapter->vsi;
356 q_vector->rx.ring = rx_ring;
357 q_vector->rx.count++;
358 q_vector->rx.latency_range = I40E_LOW_LATENCY;
359}
360
361
362
363
364
365
366
367static void
368i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
369{
370 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
371 struct i40e_ring *tx_ring = adapter->tx_rings[t_idx];
372
373 tx_ring->q_vector = q_vector;
374 tx_ring->next = q_vector->tx.ring;
375 tx_ring->vsi = &adapter->vsi;
376 q_vector->tx.ring = tx_ring;
377 q_vector->tx.count++;
378 q_vector->tx.latency_range = I40E_LOW_LATENCY;
379 q_vector->num_ringpairs++;
380 q_vector->ring_mask |= (1 << t_idx);
381}
382
383
384
385
386
387
388
389
390
391
392
393static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
394{
395 int q_vectors;
396 int v_start = 0;
397 int rxr_idx = 0, txr_idx = 0;
398 int rxr_remaining = adapter->num_active_queues;
399 int txr_remaining = adapter->num_active_queues;
400 int i, j;
401 int rqpv, tqpv;
402 int err = 0;
403
404 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
405
406
407
408
409 if (q_vectors == (rxr_remaining * 2)) {
410 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
411 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
412
413 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
414 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
415 goto out;
416 }
417
418
419
420
421
422
423 for (i = v_start; i < q_vectors; i++) {
424 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
425 for (j = 0; j < rqpv; j++) {
426 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
427 rxr_idx++;
428 rxr_remaining--;
429 }
430 }
431 for (i = v_start; i < q_vectors; i++) {
432 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
433 for (j = 0; j < tqpv; j++) {
434 i40evf_map_vector_to_txq(adapter, i, txr_idx);
435 txr_idx++;
436 txr_remaining--;
437 }
438 }
439
440out:
441 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
442
443 return err;
444}
445
446
447
448
449
450
451
452
453static int
454i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
455{
456 int vector, err, q_vectors;
457 int rx_int_idx = 0, tx_int_idx = 0;
458
459 i40evf_irq_disable(adapter);
460
461 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
462
463 for (vector = 0; vector < q_vectors; vector++) {
464 struct i40e_q_vector *q_vector = adapter->q_vector[vector];
465
466 if (q_vector->tx.ring && q_vector->rx.ring) {
467 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
468 "i40evf-%s-%s-%d", basename,
469 "TxRx", rx_int_idx++);
470 tx_int_idx++;
471 } else if (q_vector->rx.ring) {
472 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
473 "i40evf-%s-%s-%d", basename,
474 "rx", rx_int_idx++);
475 } else if (q_vector->tx.ring) {
476 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
477 "i40evf-%s-%s-%d", basename,
478 "tx", tx_int_idx++);
479 } else {
480
481 continue;
482 }
483 err = request_irq(
484 adapter->msix_entries[vector + NONQ_VECS].vector,
485 i40evf_msix_clean_rings,
486 0,
487 q_vector->name,
488 q_vector);
489 if (err) {
490 dev_info(&adapter->pdev->dev,
491 "%s: request_irq failed, error: %d\n",
492 __func__, err);
493 goto free_queue_irqs;
494 }
495
496 irq_set_affinity_hint(
497 adapter->msix_entries[vector + NONQ_VECS].vector,
498 q_vector->affinity_mask);
499 }
500
501 return 0;
502
503free_queue_irqs:
504 while (vector) {
505 vector--;
506 irq_set_affinity_hint(
507 adapter->msix_entries[vector + NONQ_VECS].vector,
508 NULL);
509 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
510 adapter->q_vector[vector]);
511 }
512 return err;
513}
514
515
516
517
518
519
520
521
522
523static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
524{
525 struct net_device *netdev = adapter->netdev;
526 int err;
527
528 snprintf(adapter->misc_vector_name,
529 sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx",
530 dev_name(&adapter->pdev->dev));
531 err = request_irq(adapter->msix_entries[0].vector,
532 &i40evf_msix_aq, 0,
533 adapter->misc_vector_name, netdev);
534 if (err) {
535 dev_err(&adapter->pdev->dev,
536 "request_irq for %s failed: %d\n",
537 adapter->misc_vector_name, err);
538 free_irq(adapter->msix_entries[0].vector, netdev);
539 }
540 return err;
541}
542
543
544
545
546
547
548
549static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
550{
551 int i;
552 int q_vectors;
553
554 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
555
556 for (i = 0; i < q_vectors; i++) {
557 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
558 NULL);
559 free_irq(adapter->msix_entries[i+1].vector,
560 adapter->q_vector[i]);
561 }
562}
563
564
565
566
567
568
569
570static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
571{
572 struct net_device *netdev = adapter->netdev;
573
574 free_irq(adapter->msix_entries[0].vector, netdev);
575}
576
577
578
579
580
581
582
583static void i40evf_configure_tx(struct i40evf_adapter *adapter)
584{
585 struct i40e_hw *hw = &adapter->hw;
586 int i;
587
588 for (i = 0; i < adapter->num_active_queues; i++)
589 adapter->tx_rings[i]->tail = hw->hw_addr + I40E_QTX_TAIL1(i);
590}
591
592
593
594
595
596
597
598static void i40evf_configure_rx(struct i40evf_adapter *adapter)
599{
600 struct i40e_hw *hw = &adapter->hw;
601 struct net_device *netdev = adapter->netdev;
602 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
603 int i;
604 int rx_buf_len;
605
606
607 adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
608 adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
609
610
611 if (netdev->mtu > ETH_DATA_LEN) {
612 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
613 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
614 else
615 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
616 } else {
617 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
618 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
619 else
620 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
621 }
622
623
624 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
625 rx_buf_len = I40E_RX_HDR_SIZE;
626 } else {
627 if (netdev->mtu <= ETH_DATA_LEN)
628 rx_buf_len = I40EVF_RXBUFFER_2048;
629 else
630 rx_buf_len = ALIGN(max_frame, 1024);
631 }
632
633 for (i = 0; i < adapter->num_active_queues; i++) {
634 adapter->rx_rings[i]->tail = hw->hw_addr + I40E_QRX_TAIL1(i);
635 adapter->rx_rings[i]->rx_buf_len = rx_buf_len;
636 }
637}
638
639
640
641
642
643
644
645
646static struct
647i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
648{
649 struct i40evf_vlan_filter *f;
650
651 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
652 if (vlan == f->vlan)
653 return f;
654 }
655 return NULL;
656}
657
658
659
660
661
662
663
664
665static struct
666i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
667{
668 struct i40evf_vlan_filter *f = NULL;
669 int count = 50;
670
671 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
672 &adapter->crit_section)) {
673 udelay(1);
674 if (--count == 0)
675 goto out;
676 }
677
678 f = i40evf_find_vlan(adapter, vlan);
679 if (!f) {
680 f = kzalloc(sizeof(*f), GFP_ATOMIC);
681 if (!f)
682 goto clearout;
683
684 f->vlan = vlan;
685
686 INIT_LIST_HEAD(&f->list);
687 list_add(&f->list, &adapter->vlan_filter_list);
688 f->add = true;
689 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
690 }
691
692clearout:
693 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
694out:
695 return f;
696}
697
698
699
700
701
702
703static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
704{
705 struct i40evf_vlan_filter *f;
706 int count = 50;
707
708 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
709 &adapter->crit_section)) {
710 udelay(1);
711 if (--count == 0)
712 return;
713 }
714
715 f = i40evf_find_vlan(adapter, vlan);
716 if (f) {
717 f->remove = true;
718 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
719 }
720 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
721}
722
723
724
725
726
727
728static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
729 __always_unused __be16 proto, u16 vid)
730{
731 struct i40evf_adapter *adapter = netdev_priv(netdev);
732
733 if (i40evf_add_vlan(adapter, vid) == NULL)
734 return -ENOMEM;
735 return 0;
736}
737
738
739
740
741
742
743static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
744 __always_unused __be16 proto, u16 vid)
745{
746 struct i40evf_adapter *adapter = netdev_priv(netdev);
747
748 i40evf_del_vlan(adapter, vid);
749 return 0;
750}
751
752
753
754
755
756
757
758
759static struct
760i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
761 u8 *macaddr)
762{
763 struct i40evf_mac_filter *f;
764
765 if (!macaddr)
766 return NULL;
767
768 list_for_each_entry(f, &adapter->mac_filter_list, list) {
769 if (ether_addr_equal(macaddr, f->macaddr))
770 return f;
771 }
772 return NULL;
773}
774
775
776
777
778
779
780
781
782static struct
783i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
784 u8 *macaddr)
785{
786 struct i40evf_mac_filter *f;
787 int count = 50;
788
789 if (!macaddr)
790 return NULL;
791
792 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
793 &adapter->crit_section)) {
794 udelay(1);
795 if (--count == 0)
796 return NULL;
797 }
798
799 f = i40evf_find_filter(adapter, macaddr);
800 if (!f) {
801 f = kzalloc(sizeof(*f), GFP_ATOMIC);
802 if (!f) {
803 clear_bit(__I40EVF_IN_CRITICAL_TASK,
804 &adapter->crit_section);
805 return NULL;
806 }
807
808 ether_addr_copy(f->macaddr, macaddr);
809
810 list_add(&f->list, &adapter->mac_filter_list);
811 f->add = true;
812 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
813 }
814
815 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
816 return f;
817}
818
819
820
821
822
823
824
825
826static int i40evf_set_mac(struct net_device *netdev, void *p)
827{
828 struct i40evf_adapter *adapter = netdev_priv(netdev);
829 struct i40e_hw *hw = &adapter->hw;
830 struct i40evf_mac_filter *f;
831 struct sockaddr *addr = p;
832
833 if (!is_valid_ether_addr(addr->sa_data))
834 return -EADDRNOTAVAIL;
835
836 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
837 return 0;
838
839 f = i40evf_add_filter(adapter, addr->sa_data);
840 if (f) {
841 ether_addr_copy(hw->mac.addr, addr->sa_data);
842 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
843 }
844
845 return (f == NULL) ? -ENOMEM : 0;
846}
847
848
849
850
851
852static void i40evf_set_rx_mode(struct net_device *netdev)
853{
854 struct i40evf_adapter *adapter = netdev_priv(netdev);
855 struct i40evf_mac_filter *f, *ftmp;
856 struct netdev_hw_addr *uca;
857 struct netdev_hw_addr *mca;
858 int count = 50;
859
860
861 netdev_for_each_uc_addr(uca, netdev) {
862 i40evf_add_filter(adapter, uca->addr);
863 }
864 netdev_for_each_mc_addr(mca, netdev) {
865 i40evf_add_filter(adapter, mca->addr);
866 }
867
868 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
869 &adapter->crit_section)) {
870 udelay(1);
871 if (--count == 0) {
872 dev_err(&adapter->pdev->dev,
873 "Failed to get lock in %s\n", __func__);
874 return;
875 }
876 }
877
878 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
879 bool found = false;
880
881 if (is_multicast_ether_addr(f->macaddr)) {
882 netdev_for_each_mc_addr(mca, netdev) {
883 if (ether_addr_equal(mca->addr, f->macaddr)) {
884 found = true;
885 break;
886 }
887 }
888 } else {
889 netdev_for_each_uc_addr(uca, netdev) {
890 if (ether_addr_equal(uca->addr, f->macaddr)) {
891 found = true;
892 break;
893 }
894 }
895 }
896 if (found) {
897 f->remove = true;
898 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
899 }
900 }
901 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
902}
903
904
905
906
907
908static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
909{
910 int q_idx;
911 struct i40e_q_vector *q_vector;
912 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
913
914 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
915 struct napi_struct *napi;
916
917 q_vector = adapter->q_vector[q_idx];
918 napi = &q_vector->napi;
919 napi_enable(napi);
920 }
921}
922
923
924
925
926
927static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
928{
929 int q_idx;
930 struct i40e_q_vector *q_vector;
931 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
932
933 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
934 q_vector = adapter->q_vector[q_idx];
935 napi_disable(&q_vector->napi);
936 }
937}
938
939
940
941
942
943static void i40evf_configure(struct i40evf_adapter *adapter)
944{
945 struct net_device *netdev = adapter->netdev;
946 int i;
947
948 i40evf_set_rx_mode(netdev);
949
950 i40evf_configure_tx(adapter);
951 i40evf_configure_rx(adapter);
952 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
953
954 for (i = 0; i < adapter->num_active_queues; i++) {
955 struct i40e_ring *ring = adapter->rx_rings[i];
956
957 i40evf_alloc_rx_buffers_1buf(ring, ring->count);
958 ring->next_to_use = ring->count - 1;
959 writel(ring->next_to_use, ring->tail);
960 }
961}
962
963
964
965
966
967static int i40evf_up_complete(struct i40evf_adapter *adapter)
968{
969 adapter->state = __I40EVF_RUNNING;
970 clear_bit(__I40E_DOWN, &adapter->vsi.state);
971
972 i40evf_napi_enable_all(adapter);
973
974 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
975 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
976 return 0;
977}
978
979
980
981
982
983void i40evf_down(struct i40evf_adapter *adapter)
984{
985 struct net_device *netdev = adapter->netdev;
986 struct i40evf_mac_filter *f;
987
988 if (adapter->state == __I40EVF_DOWN)
989 return;
990
991 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
992 &adapter->crit_section))
993 usleep_range(500, 1000);
994
995 netif_carrier_off(netdev);
996 netif_tx_disable(netdev);
997 i40evf_napi_disable_all(adapter);
998 i40evf_irq_disable(adapter);
999
1000
1001 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1002 f->remove = true;
1003 }
1004
1005 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1006 f->remove = true;
1007 }
1008 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
1009 adapter->state != __I40EVF_RESETTING) {
1010
1011 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1012
1013
1014
1015
1016 adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
1017 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
1018 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
1019 }
1020
1021 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1022}
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033static int
1034i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1035{
1036 int err, vector_threshold;
1037
1038
1039
1040
1041
1042
1043 vector_threshold = MIN_MSIX_COUNT;
1044
1045
1046
1047
1048
1049
1050 err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1051 vector_threshold, vectors);
1052 if (err < 0) {
1053 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
1054 kfree(adapter->msix_entries);
1055 adapter->msix_entries = NULL;
1056 return err;
1057 }
1058
1059
1060
1061
1062
1063 adapter->num_msix_vectors = err;
1064 return 0;
1065}
1066
1067
1068
1069
1070
1071
1072
1073static void i40evf_free_queues(struct i40evf_adapter *adapter)
1074{
1075 int i;
1076
1077 if (!adapter->vsi_res)
1078 return;
1079 for (i = 0; i < adapter->num_active_queues; i++) {
1080 if (adapter->tx_rings[i])
1081 kfree_rcu(adapter->tx_rings[i], rcu);
1082 adapter->tx_rings[i] = NULL;
1083 adapter->rx_rings[i] = NULL;
1084 }
1085}
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1096{
1097 int i;
1098
1099 for (i = 0; i < adapter->num_active_queues; i++) {
1100 struct i40e_ring *tx_ring;
1101 struct i40e_ring *rx_ring;
1102
1103 tx_ring = kzalloc(sizeof(*tx_ring) * 2, GFP_KERNEL);
1104 if (!tx_ring)
1105 goto err_out;
1106
1107 tx_ring->queue_index = i;
1108 tx_ring->netdev = adapter->netdev;
1109 tx_ring->dev = &adapter->pdev->dev;
1110 tx_ring->count = adapter->tx_desc_count;
1111 adapter->tx_rings[i] = tx_ring;
1112
1113 rx_ring = &tx_ring[1];
1114 rx_ring->queue_index = i;
1115 rx_ring->netdev = adapter->netdev;
1116 rx_ring->dev = &adapter->pdev->dev;
1117 rx_ring->count = adapter->rx_desc_count;
1118 adapter->rx_rings[i] = rx_ring;
1119 }
1120
1121 return 0;
1122
1123err_out:
1124 i40evf_free_queues(adapter);
1125 return -ENOMEM;
1126}
1127
1128
1129
1130
1131
1132
1133
1134
1135static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1136{
1137 int vector, v_budget;
1138 int pairs = 0;
1139 int err = 0;
1140
1141 if (!adapter->vsi_res) {
1142 err = -EIO;
1143 goto out;
1144 }
1145 pairs = adapter->num_active_queues;
1146
1147
1148
1149
1150
1151
1152 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1153 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
1154
1155 adapter->msix_entries = kcalloc(v_budget,
1156 sizeof(struct msix_entry), GFP_KERNEL);
1157 if (!adapter->msix_entries) {
1158 err = -ENOMEM;
1159 goto out;
1160 }
1161
1162 for (vector = 0; vector < v_budget; vector++)
1163 adapter->msix_entries[vector].entry = vector;
1164
1165 i40evf_acquire_msix_vectors(adapter, v_budget);
1166
1167out:
1168 adapter->netdev->real_num_tx_queues = pairs;
1169 return err;
1170}
1171
1172
1173
1174
1175
1176
1177
1178
1179static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1180{
1181 int q_idx, num_q_vectors;
1182 struct i40e_q_vector *q_vector;
1183
1184 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1185
1186 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1187 q_vector = kzalloc(sizeof(*q_vector), GFP_KERNEL);
1188 if (!q_vector)
1189 goto err_out;
1190 q_vector->adapter = adapter;
1191 q_vector->vsi = &adapter->vsi;
1192 q_vector->v_idx = q_idx;
1193 netif_napi_add(adapter->netdev, &q_vector->napi,
1194 i40evf_napi_poll, NAPI_POLL_WEIGHT);
1195 adapter->q_vector[q_idx] = q_vector;
1196 }
1197
1198 return 0;
1199
1200err_out:
1201 while (q_idx) {
1202 q_idx--;
1203 q_vector = adapter->q_vector[q_idx];
1204 netif_napi_del(&q_vector->napi);
1205 kfree(q_vector);
1206 adapter->q_vector[q_idx] = NULL;
1207 }
1208 return -ENOMEM;
1209}
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1220{
1221 int q_idx, num_q_vectors;
1222 int napi_vectors;
1223
1224 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1225 napi_vectors = adapter->num_active_queues;
1226
1227 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1228 struct i40e_q_vector *q_vector = adapter->q_vector[q_idx];
1229
1230 adapter->q_vector[q_idx] = NULL;
1231 if (q_idx < napi_vectors)
1232 netif_napi_del(&q_vector->napi);
1233 kfree(q_vector);
1234 }
1235}
1236
1237
1238
1239
1240
1241
1242void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1243{
1244 pci_disable_msix(adapter->pdev);
1245 kfree(adapter->msix_entries);
1246 adapter->msix_entries = NULL;
1247}
1248
1249
1250
1251
1252
1253
1254int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1255{
1256 int err;
1257
1258 err = i40evf_set_interrupt_capability(adapter);
1259 if (err) {
1260 dev_err(&adapter->pdev->dev,
1261 "Unable to setup interrupt capabilities\n");
1262 goto err_set_interrupt;
1263 }
1264
1265 err = i40evf_alloc_q_vectors(adapter);
1266 if (err) {
1267 dev_err(&adapter->pdev->dev,
1268 "Unable to allocate memory for queue vectors\n");
1269 goto err_alloc_q_vectors;
1270 }
1271
1272 err = i40evf_alloc_queues(adapter);
1273 if (err) {
1274 dev_err(&adapter->pdev->dev,
1275 "Unable to allocate memory for queues\n");
1276 goto err_alloc_queues;
1277 }
1278
1279 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
1280 (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
1281 adapter->num_active_queues);
1282
1283 return 0;
1284err_alloc_queues:
1285 i40evf_free_q_vectors(adapter);
1286err_alloc_q_vectors:
1287 i40evf_reset_interrupt_capability(adapter);
1288err_set_interrupt:
1289 return err;
1290}
1291
1292
1293
1294
1295
1296static void i40evf_watchdog_timer(unsigned long data)
1297{
1298 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
1299
1300 schedule_work(&adapter->watchdog_task);
1301
1302}
1303
1304
1305
1306
1307
1308static void i40evf_watchdog_task(struct work_struct *work)
1309{
1310 struct i40evf_adapter *adapter = container_of(work,
1311 struct i40evf_adapter,
1312 watchdog_task);
1313 struct i40e_hw *hw = &adapter->hw;
1314 uint32_t rstat_val;
1315
1316 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
1317 goto restart_watchdog;
1318
1319 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1320 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1321 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1322 if ((rstat_val == I40E_VFR_VFACTIVE) ||
1323 (rstat_val == I40E_VFR_COMPLETED)) {
1324
1325 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1326 adapter->state = __I40EVF_STARTUP;
1327 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1328 schedule_delayed_work(&adapter->init_task, 10);
1329 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1330 &adapter->crit_section);
1331
1332
1333
1334
1335
1336 return;
1337 }
1338 adapter->aq_required = 0;
1339 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1340 goto watchdog_done;
1341 }
1342
1343 if ((adapter->state < __I40EVF_DOWN) ||
1344 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
1345 goto watchdog_done;
1346
1347
1348 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1349 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1350 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) &&
1351 (rstat_val != I40E_VFR_VFACTIVE) &&
1352 (rstat_val != I40E_VFR_COMPLETED)) {
1353 adapter->state = __I40EVF_RESETTING;
1354 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1355 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
1356 schedule_work(&adapter->reset_task);
1357 adapter->aq_required = 0;
1358 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1359 goto watchdog_done;
1360 }
1361
1362
1363
1364
1365 if (adapter->current_op) {
1366 if (!i40evf_asq_done(hw)) {
1367 dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
1368 i40evf_send_api_ver(adapter);
1369 }
1370 goto watchdog_done;
1371 }
1372
1373 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1374 i40evf_disable_queues(adapter);
1375 goto watchdog_done;
1376 }
1377
1378 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1379 i40evf_map_queues(adapter);
1380 goto watchdog_done;
1381 }
1382
1383 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1384 i40evf_add_ether_addrs(adapter);
1385 goto watchdog_done;
1386 }
1387
1388 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1389 i40evf_add_vlans(adapter);
1390 goto watchdog_done;
1391 }
1392
1393 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1394 i40evf_del_ether_addrs(adapter);
1395 goto watchdog_done;
1396 }
1397
1398 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1399 i40evf_del_vlans(adapter);
1400 goto watchdog_done;
1401 }
1402
1403 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1404 i40evf_configure_queues(adapter);
1405 goto watchdog_done;
1406 }
1407
1408 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1409 i40evf_enable_queues(adapter);
1410 goto watchdog_done;
1411 }
1412
1413 if (adapter->state == __I40EVF_RUNNING)
1414 i40evf_request_stats(adapter);
1415watchdog_done:
1416 if (adapter->state == __I40EVF_RUNNING) {
1417 i40evf_irq_enable_queues(adapter, ~0);
1418 i40evf_fire_sw_int(adapter, 0xFF);
1419 } else {
1420 i40evf_fire_sw_int(adapter, 0x1);
1421 }
1422
1423 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1424restart_watchdog:
1425 if (adapter->state == __I40EVF_REMOVE)
1426 return;
1427 if (adapter->aq_required)
1428 mod_timer(&adapter->watchdog_timer,
1429 jiffies + msecs_to_jiffies(20));
1430 else
1431 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
1432 schedule_work(&adapter->adminq_task);
1433}
1434
1435
1436
1437
1438
1439static void i40evf_configure_rss(struct i40evf_adapter *adapter)
1440{
1441 u32 rss_key[I40E_VFQF_HKEY_MAX_INDEX + 1];
1442 struct i40e_hw *hw = &adapter->hw;
1443 u32 cqueue = 0;
1444 u32 lut = 0;
1445 int i, j;
1446 u64 hena;
1447
1448
1449 netdev_rss_key_fill(rss_key, sizeof(rss_key));
1450
1451
1452 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1453 wr32(hw, I40E_VFQF_HKEY(i), rss_key[i]);
1454
1455
1456 hena = I40E_DEFAULT_RSS_HENA;
1457 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1458 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1459
1460
1461 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) {
1462 lut = 0;
1463 for (j = 0; j < 4; j++) {
1464 if (cqueue == adapter->num_active_queues)
1465 cqueue = 0;
1466 lut |= ((cqueue) << (8 * j));
1467 cqueue++;
1468 }
1469 wr32(hw, I40E_VFQF_HLUT(i), lut);
1470 }
1471 i40e_flush(hw);
1472}
1473
1474#define I40EVF_RESET_WAIT_MS 10
1475#define I40EVF_RESET_WAIT_COUNT 500
1476
1477
1478
1479
1480
1481
1482
1483
1484static void i40evf_reset_task(struct work_struct *work)
1485{
1486 struct i40evf_adapter *adapter = container_of(work,
1487 struct i40evf_adapter,
1488 reset_task);
1489 struct net_device *netdev = adapter->netdev;
1490 struct i40e_hw *hw = &adapter->hw;
1491 struct i40evf_mac_filter *f;
1492 uint32_t rstat_val;
1493 int i = 0, err;
1494
1495 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1496 &adapter->crit_section))
1497 usleep_range(500, 1000);
1498
1499 i40evf_misc_irq_disable(adapter);
1500 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
1501 adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED;
1502
1503
1504
1505 i40evf_shutdown_adminq(hw);
1506 i40evf_init_adminq(hw);
1507 i40evf_request_reset(adapter);
1508 }
1509 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1510
1511
1512 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1513 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1514 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1515 if ((rstat_val != I40E_VFR_VFACTIVE) &&
1516 (rstat_val != I40E_VFR_COMPLETED))
1517 break;
1518 usleep_range(500, 1000);
1519 }
1520 if (i == I40EVF_RESET_WAIT_COUNT) {
1521 dev_info(&adapter->pdev->dev, "Never saw reset\n");
1522 goto continue_reset;
1523 }
1524
1525
1526 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1527 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1528 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1529 if (rstat_val == I40E_VFR_VFACTIVE)
1530 break;
1531 msleep(I40EVF_RESET_WAIT_MS);
1532 }
1533
1534 msleep(I40EVF_RESET_WAIT_MS);
1535 if (i == I40EVF_RESET_WAIT_COUNT) {
1536 struct i40evf_mac_filter *f, *ftmp;
1537 struct i40evf_vlan_filter *fv, *fvtmp;
1538
1539
1540 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
1541 rstat_val);
1542 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1543
1544 if (netif_running(adapter->netdev)) {
1545 set_bit(__I40E_DOWN, &adapter->vsi.state);
1546 netif_carrier_off(netdev);
1547 netif_tx_disable(netdev);
1548 i40evf_napi_disable_all(adapter);
1549 i40evf_irq_disable(adapter);
1550 i40evf_free_traffic_irqs(adapter);
1551 i40evf_free_all_tx_resources(adapter);
1552 i40evf_free_all_rx_resources(adapter);
1553 }
1554
1555
1556 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
1557 list) {
1558 list_del(&f->list);
1559 kfree(f);
1560 }
1561
1562 list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
1563 list) {
1564 list_del(&fv->list);
1565 kfree(fv);
1566 }
1567
1568 i40evf_free_misc_irq(adapter);
1569 i40evf_reset_interrupt_capability(adapter);
1570 i40evf_free_queues(adapter);
1571 i40evf_free_q_vectors(adapter);
1572 kfree(adapter->vf_res);
1573 i40evf_shutdown_adminq(hw);
1574 adapter->netdev->flags &= ~IFF_UP;
1575 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1576 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1577 dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
1578 return;
1579 }
1580
1581continue_reset:
1582 if (netif_running(adapter->netdev)) {
1583 netif_carrier_off(netdev);
1584 netif_tx_stop_all_queues(netdev);
1585 i40evf_napi_disable_all(adapter);
1586 }
1587 i40evf_irq_disable(adapter);
1588
1589 adapter->state = __I40EVF_RESETTING;
1590 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1591
1592
1593
1594
1595 i40evf_free_all_rx_resources(adapter);
1596 i40evf_free_all_tx_resources(adapter);
1597
1598
1599 if (i40evf_shutdown_adminq(hw))
1600 dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
1601 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1602 err = i40evf_init_adminq(hw);
1603 if (err)
1604 dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
1605 err);
1606
1607 i40evf_map_queues(adapter);
1608
1609
1610 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1611 f->add = true;
1612 }
1613
1614 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1615 f->add = true;
1616 }
1617 adapter->aq_required = I40EVF_FLAG_AQ_ADD_MAC_FILTER;
1618 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
1619 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1620 i40evf_misc_irq_enable(adapter);
1621
1622 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1623
1624 if (netif_running(adapter->netdev)) {
1625
1626 err = i40evf_setup_all_tx_resources(adapter);
1627 if (err)
1628 goto reset_err;
1629
1630
1631 err = i40evf_setup_all_rx_resources(adapter);
1632 if (err)
1633 goto reset_err;
1634
1635 i40evf_configure(adapter);
1636
1637 err = i40evf_up_complete(adapter);
1638 if (err)
1639 goto reset_err;
1640
1641 i40evf_irq_enable(adapter, true);
1642 } else {
1643 adapter->state = __I40EVF_DOWN;
1644 }
1645
1646 return;
1647reset_err:
1648 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
1649 i40evf_close(adapter->netdev);
1650}
1651
1652
1653
1654
1655
1656static void i40evf_adminq_task(struct work_struct *work)
1657{
1658 struct i40evf_adapter *adapter =
1659 container_of(work, struct i40evf_adapter, adminq_task);
1660 struct i40e_hw *hw = &adapter->hw;
1661 struct i40e_arq_event_info event;
1662 struct i40e_virtchnl_msg *v_msg;
1663 i40e_status ret;
1664 u32 val, oldval;
1665 u16 pending;
1666
1667 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
1668 goto out;
1669
1670 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
1671 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1672 if (!event.msg_buf)
1673 goto out;
1674
1675 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1676 do {
1677 ret = i40evf_clean_arq_element(hw, &event, &pending);
1678 if (ret || !v_msg->v_opcode)
1679 break;
1680
1681 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1682 v_msg->v_retval, event.msg_buf,
1683 event.msg_len);
1684 if (pending != 0)
1685 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
1686 } while (pending);
1687
1688 if ((adapter->flags &
1689 (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
1690 adapter->state == __I40EVF_RESETTING)
1691 goto freedom;
1692
1693
1694 val = rd32(hw, hw->aq.arq.len);
1695 oldval = val;
1696 if (val & I40E_VF_ARQLEN_ARQVFE_MASK) {
1697 dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
1698 val &= ~I40E_VF_ARQLEN_ARQVFE_MASK;
1699 }
1700 if (val & I40E_VF_ARQLEN_ARQOVFL_MASK) {
1701 dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
1702 val &= ~I40E_VF_ARQLEN_ARQOVFL_MASK;
1703 }
1704 if (val & I40E_VF_ARQLEN_ARQCRIT_MASK) {
1705 dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
1706 val &= ~I40E_VF_ARQLEN_ARQCRIT_MASK;
1707 }
1708 if (oldval != val)
1709 wr32(hw, hw->aq.arq.len, val);
1710
1711 val = rd32(hw, hw->aq.asq.len);
1712 oldval = val;
1713 if (val & I40E_VF_ATQLEN_ATQVFE_MASK) {
1714 dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
1715 val &= ~I40E_VF_ATQLEN_ATQVFE_MASK;
1716 }
1717 if (val & I40E_VF_ATQLEN_ATQOVFL_MASK) {
1718 dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
1719 val &= ~I40E_VF_ATQLEN_ATQOVFL_MASK;
1720 }
1721 if (val & I40E_VF_ATQLEN_ATQCRIT_MASK) {
1722 dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
1723 val &= ~I40E_VF_ATQLEN_ATQCRIT_MASK;
1724 }
1725 if (oldval != val)
1726 wr32(hw, hw->aq.asq.len, val);
1727
1728freedom:
1729 kfree(event.msg_buf);
1730out:
1731
1732 i40evf_misc_irq_enable(adapter);
1733}
1734
1735
1736
1737
1738
1739
1740
1741void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
1742{
1743 int i;
1744
1745 for (i = 0; i < adapter->num_active_queues; i++)
1746 if (adapter->tx_rings[i]->desc)
1747 i40evf_free_tx_resources(adapter->tx_rings[i]);
1748}
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
1761{
1762 int i, err = 0;
1763
1764 for (i = 0; i < adapter->num_active_queues; i++) {
1765 adapter->tx_rings[i]->count = adapter->tx_desc_count;
1766 err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]);
1767 if (!err)
1768 continue;
1769 dev_err(&adapter->pdev->dev,
1770 "%s: Allocation for Tx Queue %u failed\n",
1771 __func__, i);
1772 break;
1773 }
1774
1775 return err;
1776}
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
1789{
1790 int i, err = 0;
1791
1792 for (i = 0; i < adapter->num_active_queues; i++) {
1793 adapter->rx_rings[i]->count = adapter->rx_desc_count;
1794 err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]);
1795 if (!err)
1796 continue;
1797 dev_err(&adapter->pdev->dev,
1798 "%s: Allocation for Rx Queue %u failed\n",
1799 __func__, i);
1800 break;
1801 }
1802 return err;
1803}
1804
1805
1806
1807
1808
1809
1810
1811void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
1812{
1813 int i;
1814
1815 for (i = 0; i < adapter->num_active_queues; i++)
1816 if (adapter->rx_rings[i]->desc)
1817 i40evf_free_rx_resources(adapter->rx_rings[i]);
1818}
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832static int i40evf_open(struct net_device *netdev)
1833{
1834 struct i40evf_adapter *adapter = netdev_priv(netdev);
1835 int err;
1836
1837 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1838 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
1839 return -EIO;
1840 }
1841 if (adapter->state != __I40EVF_DOWN || adapter->aq_required)
1842 return -EBUSY;
1843
1844
1845 err = i40evf_setup_all_tx_resources(adapter);
1846 if (err)
1847 goto err_setup_tx;
1848
1849
1850 err = i40evf_setup_all_rx_resources(adapter);
1851 if (err)
1852 goto err_setup_rx;
1853
1854
1855 err = i40evf_request_traffic_irqs(adapter, netdev->name);
1856 if (err)
1857 goto err_req_irq;
1858
1859 i40evf_configure(adapter);
1860
1861 err = i40evf_up_complete(adapter);
1862 if (err)
1863 goto err_req_irq;
1864
1865 i40evf_irq_enable(adapter, true);
1866
1867 return 0;
1868
1869err_req_irq:
1870 i40evf_down(adapter);
1871 i40evf_free_traffic_irqs(adapter);
1872err_setup_rx:
1873 i40evf_free_all_rx_resources(adapter);
1874err_setup_tx:
1875 i40evf_free_all_tx_resources(adapter);
1876
1877 return err;
1878}
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891static int i40evf_close(struct net_device *netdev)
1892{
1893 struct i40evf_adapter *adapter = netdev_priv(netdev);
1894
1895 if (adapter->state <= __I40EVF_DOWN)
1896 return 0;
1897
1898
1899 set_bit(__I40E_DOWN, &adapter->vsi.state);
1900
1901 i40evf_down(adapter);
1902 adapter->state = __I40EVF_DOWN;
1903 i40evf_free_traffic_irqs(adapter);
1904
1905 return 0;
1906}
1907
1908
1909
1910
1911
1912
1913
1914
1915static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
1916{
1917 struct i40evf_adapter *adapter = netdev_priv(netdev);
1918
1919
1920 return &adapter->net_stats;
1921}
1922
1923
1924
1925
1926
1927
1928
1929
1930static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
1931{
1932 struct i40evf_adapter *adapter = netdev_priv(netdev);
1933 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
1934
1935 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
1936 return -EINVAL;
1937
1938 netdev->mtu = new_mtu;
1939 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
1940 schedule_work(&adapter->reset_task);
1941
1942 return 0;
1943}
1944
1945static const struct net_device_ops i40evf_netdev_ops = {
1946 .ndo_open = i40evf_open,
1947 .ndo_stop = i40evf_close,
1948 .ndo_start_xmit = i40evf_xmit_frame,
1949 .ndo_get_stats = i40evf_get_stats,
1950 .ndo_set_rx_mode = i40evf_set_rx_mode,
1951 .ndo_validate_addr = eth_validate_addr,
1952 .ndo_set_mac_address = i40evf_set_mac,
1953 .ndo_change_mtu = i40evf_change_mtu,
1954 .ndo_tx_timeout = i40evf_tx_timeout,
1955 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
1956 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
1957};
1958
1959
1960
1961
1962
1963
1964
1965static int i40evf_check_reset_complete(struct i40e_hw *hw)
1966{
1967 u32 rstat;
1968 int i;
1969
1970 for (i = 0; i < 100; i++) {
1971 rstat = rd32(hw, I40E_VFGEN_RSTAT) &
1972 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1973 if ((rstat == I40E_VFR_VFACTIVE) ||
1974 (rstat == I40E_VFR_COMPLETED))
1975 return 0;
1976 usleep_range(10, 20);
1977 }
1978 return -EBUSY;
1979}
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993static void i40evf_init_task(struct work_struct *work)
1994{
1995 struct i40evf_adapter *adapter = container_of(work,
1996 struct i40evf_adapter,
1997 init_task.work);
1998 struct net_device *netdev = adapter->netdev;
1999 struct i40evf_mac_filter *f;
2000 struct i40e_hw *hw = &adapter->hw;
2001 struct pci_dev *pdev = adapter->pdev;
2002 int i, err, bufsz;
2003
2004 switch (adapter->state) {
2005 case __I40EVF_STARTUP:
2006
2007 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
2008 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
2009 err = i40e_set_mac_type(hw);
2010 if (err) {
2011 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
2012 err);
2013 goto err;
2014 }
2015 err = i40evf_check_reset_complete(hw);
2016 if (err) {
2017 dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
2018 err);
2019 goto err;
2020 }
2021 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
2022 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
2023 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2024 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2025
2026 err = i40evf_init_adminq(hw);
2027 if (err) {
2028 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
2029 err);
2030 goto err;
2031 }
2032 err = i40evf_send_api_ver(adapter);
2033 if (err) {
2034 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
2035 i40evf_shutdown_adminq(hw);
2036 goto err;
2037 }
2038 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2039 goto restart;
2040 case __I40EVF_INIT_VERSION_CHECK:
2041 if (!i40evf_asq_done(hw)) {
2042 dev_err(&pdev->dev, "Admin queue command never completed\n");
2043 i40evf_shutdown_adminq(hw);
2044 adapter->state = __I40EVF_STARTUP;
2045 goto err;
2046 }
2047
2048
2049 err = i40evf_verify_api_ver(adapter);
2050 if (err) {
2051 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
2052 err = i40evf_send_api_ver(adapter);
2053 goto err;
2054 }
2055 err = i40evf_send_vf_config_msg(adapter);
2056 if (err) {
2057 dev_err(&pdev->dev, "Unable to send config request (%d)\n",
2058 err);
2059 goto err;
2060 }
2061 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2062 goto restart;
2063 case __I40EVF_INIT_GET_RESOURCES:
2064
2065 if (!adapter->vf_res) {
2066 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2067 (I40E_MAX_VF_VSI *
2068 sizeof(struct i40e_virtchnl_vsi_resource));
2069 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
2070 if (!adapter->vf_res)
2071 goto err;
2072 }
2073 err = i40evf_get_vf_config(adapter);
2074 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
2075 err = i40evf_send_vf_config_msg(adapter);
2076 goto err;
2077 }
2078 if (err) {
2079 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2080 err);
2081 goto err_alloc;
2082 }
2083 adapter->state = __I40EVF_INIT_SW;
2084 break;
2085 default:
2086 goto err_alloc;
2087 }
2088
2089 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2090 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2091 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2092 }
2093 if (!adapter->vsi_res) {
2094 dev_err(&pdev->dev, "No LAN VSI found\n");
2095 goto err_alloc;
2096 }
2097
2098 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2099
2100 netdev->netdev_ops = &i40evf_netdev_ops;
2101 i40evf_set_ethtool_ops(netdev);
2102 netdev->watchdog_timeo = 5 * HZ;
2103 netdev->features |= NETIF_F_HIGHDMA |
2104 NETIF_F_SG |
2105 NETIF_F_IP_CSUM |
2106 NETIF_F_SCTP_CSUM |
2107 NETIF_F_IPV6_CSUM |
2108 NETIF_F_TSO |
2109 NETIF_F_TSO6 |
2110 NETIF_F_RXCSUM |
2111 NETIF_F_GRO;
2112
2113 if (adapter->vf_res->vf_offload_flags
2114 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
2115 netdev->vlan_features = netdev->features;
2116 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2117 NETIF_F_HW_VLAN_CTAG_RX |
2118 NETIF_F_HW_VLAN_CTAG_FILTER;
2119 }
2120
2121
2122 netdev->hw_features |= netdev->features;
2123 netdev->hw_features &= ~NETIF_F_RXCSUM;
2124
2125 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
2126 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
2127 adapter->hw.mac.addr);
2128 random_ether_addr(adapter->hw.mac.addr);
2129 }
2130 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
2131 ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
2132
2133 f = kzalloc(sizeof(*f), GFP_ATOMIC);
2134 if (!f)
2135 goto err_sw_init;
2136
2137 ether_addr_copy(f->macaddr, adapter->hw.mac.addr);
2138 f->add = true;
2139 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
2140
2141 list_add(&f->list, &adapter->mac_filter_list);
2142
2143 init_timer(&adapter->watchdog_timer);
2144 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2145 adapter->watchdog_timer.data = (unsigned long)adapter;
2146 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2147
2148 adapter->num_active_queues = min_t(int,
2149 adapter->vsi_res->num_queue_pairs,
2150 (int)(num_online_cpus()));
2151 adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2152 adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
2153 err = i40evf_init_interrupt_scheme(adapter);
2154 if (err)
2155 goto err_sw_init;
2156 i40evf_map_rings_to_vectors(adapter);
2157 i40evf_configure_rss(adapter);
2158 err = i40evf_request_misc_irq(adapter);
2159 if (err)
2160 goto err_sw_init;
2161
2162 netif_carrier_off(netdev);
2163
2164 adapter->vsi.id = adapter->vsi_res->vsi_id;
2165 adapter->vsi.seid = adapter->vsi_res->vsi_id;
2166 adapter->vsi.back = adapter;
2167 adapter->vsi.base_vector = 1;
2168 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
2169 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2170 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2171 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2172 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
2173 adapter->vsi.netdev = adapter->netdev;
2174
2175 if (!adapter->netdev_registered) {
2176 err = register_netdev(netdev);
2177 if (err)
2178 goto err_register;
2179 }
2180
2181 adapter->netdev_registered = true;
2182
2183 netif_tx_stop_all_queues(netdev);
2184
2185 dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
2186 if (netdev->features & NETIF_F_GRO)
2187 dev_info(&pdev->dev, "GRO is enabled\n");
2188
2189 dev_info(&pdev->dev, "%s\n", i40evf_driver_string);
2190 adapter->state = __I40EVF_DOWN;
2191 set_bit(__I40E_DOWN, &adapter->vsi.state);
2192 i40evf_misc_irq_enable(adapter);
2193 return;
2194restart:
2195 schedule_delayed_work(&adapter->init_task,
2196 msecs_to_jiffies(50));
2197 return;
2198
2199err_register:
2200 i40evf_free_misc_irq(adapter);
2201err_sw_init:
2202 i40evf_reset_interrupt_capability(adapter);
2203err_alloc:
2204 kfree(adapter->vf_res);
2205 adapter->vf_res = NULL;
2206err:
2207
2208 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
2209 dev_err(&pdev->dev, "Failed to communicate with PF; giving up\n");
2210 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
2211 return;
2212 }
2213 schedule_delayed_work(&adapter->init_task, HZ * 3);
2214}
2215
2216
2217
2218
2219
2220static void i40evf_shutdown(struct pci_dev *pdev)
2221{
2222 struct net_device *netdev = pci_get_drvdata(pdev);
2223 struct i40evf_adapter *adapter = netdev_priv(netdev);
2224
2225 netif_device_detach(netdev);
2226
2227 if (netif_running(netdev))
2228 i40evf_close(netdev);
2229
2230
2231 adapter->state = __I40EVF_REMOVE;
2232 adapter->aq_required = 0;
2233
2234#ifdef CONFIG_PM
2235 pci_save_state(pdev);
2236
2237#endif
2238 pci_disable_device(pdev);
2239}
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2253{
2254 struct net_device *netdev;
2255 struct i40evf_adapter *adapter = NULL;
2256 struct i40e_hw *hw = NULL;
2257 int err;
2258
2259 err = pci_enable_device(pdev);
2260 if (err)
2261 return err;
2262
2263 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
2264 if (err) {
2265 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2266 if (err) {
2267 dev_err(&pdev->dev,
2268 "DMA configuration failed: 0x%x\n", err);
2269 goto err_dma;
2270 }
2271 }
2272
2273 err = pci_request_regions(pdev, i40evf_driver_name);
2274 if (err) {
2275 dev_err(&pdev->dev,
2276 "pci_request_regions failed 0x%x\n", err);
2277 goto err_pci_reg;
2278 }
2279
2280 pci_enable_pcie_error_reporting(pdev);
2281
2282 pci_set_master(pdev);
2283
2284 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter),
2285 MAX_TX_QUEUES);
2286 if (!netdev) {
2287 err = -ENOMEM;
2288 goto err_alloc_etherdev;
2289 }
2290
2291 SET_NETDEV_DEV(netdev, &pdev->dev);
2292
2293 pci_set_drvdata(pdev, netdev);
2294 adapter = netdev_priv(netdev);
2295
2296 adapter->netdev = netdev;
2297 adapter->pdev = pdev;
2298
2299 hw = &adapter->hw;
2300 hw->back = adapter;
2301
2302 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
2303 adapter->state = __I40EVF_STARTUP;
2304
2305
2306 pci_save_state(pdev);
2307
2308 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2309 pci_resource_len(pdev, 0));
2310 if (!hw->hw_addr) {
2311 err = -EIO;
2312 goto err_ioremap;
2313 }
2314 hw->vendor_id = pdev->vendor;
2315 hw->device_id = pdev->device;
2316 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2317 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2318 hw->subsystem_device_id = pdev->subsystem_device;
2319 hw->bus.device = PCI_SLOT(pdev->devfn);
2320 hw->bus.func = PCI_FUNC(pdev->devfn);
2321
2322 INIT_LIST_HEAD(&adapter->mac_filter_list);
2323 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2324
2325 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2326 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2327 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2328 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
2329 schedule_delayed_work(&adapter->init_task, 10);
2330
2331 return 0;
2332
2333err_ioremap:
2334 free_netdev(netdev);
2335err_alloc_etherdev:
2336 pci_release_regions(pdev);
2337err_pci_reg:
2338err_dma:
2339 pci_disable_device(pdev);
2340 return err;
2341}
2342
2343#ifdef CONFIG_PM
2344
2345
2346
2347
2348
2349
2350
2351static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2352{
2353 struct net_device *netdev = pci_get_drvdata(pdev);
2354 struct i40evf_adapter *adapter = netdev_priv(netdev);
2355 int retval = 0;
2356
2357 netif_device_detach(netdev);
2358
2359 if (netif_running(netdev)) {
2360 rtnl_lock();
2361 i40evf_down(adapter);
2362 rtnl_unlock();
2363 }
2364 i40evf_free_misc_irq(adapter);
2365 i40evf_reset_interrupt_capability(adapter);
2366
2367 retval = pci_save_state(pdev);
2368 if (retval)
2369 return retval;
2370
2371 pci_disable_device(pdev);
2372
2373 return 0;
2374}
2375
2376
2377
2378
2379
2380
2381
2382static int i40evf_resume(struct pci_dev *pdev)
2383{
2384 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2385 struct net_device *netdev = adapter->netdev;
2386 u32 err;
2387
2388 pci_set_power_state(pdev, PCI_D0);
2389 pci_restore_state(pdev);
2390
2391
2392
2393 pci_save_state(pdev);
2394
2395 err = pci_enable_device_mem(pdev);
2396 if (err) {
2397 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2398 return err;
2399 }
2400 pci_set_master(pdev);
2401
2402 rtnl_lock();
2403 err = i40evf_set_interrupt_capability(adapter);
2404 if (err) {
2405 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2406 return err;
2407 }
2408 err = i40evf_request_misc_irq(adapter);
2409 rtnl_unlock();
2410 if (err) {
2411 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2412 return err;
2413 }
2414
2415 schedule_work(&adapter->reset_task);
2416
2417 netif_device_attach(netdev);
2418
2419 return err;
2420}
2421
2422#endif
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432static void i40evf_remove(struct pci_dev *pdev)
2433{
2434 struct net_device *netdev = pci_get_drvdata(pdev);
2435 struct i40evf_adapter *adapter = netdev_priv(netdev);
2436 struct i40evf_mac_filter *f, *ftmp;
2437 struct i40e_hw *hw = &adapter->hw;
2438
2439 cancel_delayed_work_sync(&adapter->init_task);
2440 cancel_work_sync(&adapter->reset_task);
2441
2442 if (adapter->netdev_registered) {
2443 unregister_netdev(netdev);
2444 adapter->netdev_registered = false;
2445 }
2446
2447
2448 adapter->state = __I40EVF_REMOVE;
2449 adapter->aq_required = 0;
2450 i40evf_request_reset(adapter);
2451 msleep(20);
2452
2453 if (!i40evf_asq_done(hw)) {
2454 i40evf_request_reset(adapter);
2455 msleep(20);
2456 }
2457
2458 if (adapter->msix_entries) {
2459 i40evf_misc_irq_disable(adapter);
2460 i40evf_free_misc_irq(adapter);
2461 i40evf_reset_interrupt_capability(adapter);
2462 i40evf_free_q_vectors(adapter);
2463 }
2464
2465 if (adapter->watchdog_timer.function)
2466 del_timer_sync(&adapter->watchdog_timer);
2467
2468 flush_scheduled_work();
2469
2470 if (hw->aq.asq.count)
2471 i40evf_shutdown_adminq(hw);
2472
2473 iounmap(hw->hw_addr);
2474 pci_release_regions(pdev);
2475
2476 i40evf_free_all_tx_resources(adapter);
2477 i40evf_free_all_rx_resources(adapter);
2478 i40evf_free_queues(adapter);
2479 kfree(adapter->vf_res);
2480
2481
2482
2483 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
2484 list_del(&f->list);
2485 kfree(f);
2486 }
2487 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
2488 list_del(&f->list);
2489 kfree(f);
2490 }
2491
2492 free_netdev(netdev);
2493
2494 pci_disable_pcie_error_reporting(pdev);
2495
2496 pci_disable_device(pdev);
2497}
2498
2499static struct pci_driver i40evf_driver = {
2500 .name = i40evf_driver_name,
2501 .id_table = i40evf_pci_tbl,
2502 .probe = i40evf_probe,
2503 .remove = i40evf_remove,
2504#ifdef CONFIG_PM
2505 .suspend = i40evf_suspend,
2506 .resume = i40evf_resume,
2507#endif
2508 .shutdown = i40evf_shutdown,
2509};
2510
2511
2512
2513
2514
2515
2516
2517static int __init i40evf_init_module(void)
2518{
2519 int ret;
2520
2521 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
2522 i40evf_driver_version);
2523
2524 pr_info("%s\n", i40evf_copyright);
2525
2526 ret = pci_register_driver(&i40evf_driver);
2527 return ret;
2528}
2529
2530module_init(i40evf_init_module);
2531
2532
2533
2534
2535
2536
2537
2538static void __exit i40evf_exit_module(void)
2539{
2540 pci_unregister_driver(&i40evf_driver);
2541}
2542
2543module_exit(i40evf_exit_module);
2544
2545
2546