1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "fm10k_pf.h"
22#include "fm10k_vf.h"
23
24
25
26
27
28
29
30
31static s32 fm10k_reset_hw_pf(struct fm10k_hw *hw)
32{
33 s32 err;
34 u32 reg;
35 u16 i;
36
37
38 fm10k_write_reg(hw, FM10K_EIMR, FM10K_EIMR_DISABLE(ALL));
39
40
41 fm10k_write_reg(hw, FM10K_ITR2(0), 0);
42 fm10k_write_reg(hw, FM10K_INT_CTRL, 0);
43
44
45
46
47 for (i = 0; i < FM10K_TQMAP_TABLE_SIZE; i++) {
48 fm10k_write_reg(hw, FM10K_TQMAP(i), 0);
49 fm10k_write_reg(hw, FM10K_RQMAP(i), 0);
50 }
51
52
53 err = fm10k_disable_queues_generic(hw, FM10K_MAX_QUEUES);
54 if (err == FM10K_ERR_REQUESTS_PENDING) {
55 hw->mac.reset_while_pending++;
56 goto force_reset;
57 } else if (err) {
58 return err;
59 }
60
61
62 reg = fm10k_read_reg(hw, FM10K_DMA_CTRL);
63 if (reg & (FM10K_DMA_CTRL_TX_ACTIVE | FM10K_DMA_CTRL_RX_ACTIVE))
64 return FM10K_ERR_DMA_PENDING;
65
66force_reset:
67
68 reg = FM10K_DMA_CTRL_DATAPATH_RESET;
69 fm10k_write_reg(hw, FM10K_DMA_CTRL, reg);
70
71
72 fm10k_write_flush(hw);
73 udelay(FM10K_RESET_TIMEOUT);
74
75
76 reg = FM10K_MBX_GLOBAL_REQ_INTERRUPT | FM10K_MBX_GLOBAL_ACK_INTERRUPT;
77 fm10k_write_reg(hw, FM10K_GMBX, reg);
78
79
80 reg = fm10k_read_reg(hw, FM10K_IP);
81 if (!(reg & FM10K_IP_NOTINRESET))
82 return FM10K_ERR_RESET_FAILED;
83
84 return 0;
85}
86
87
88
89
90
91
92
93static bool fm10k_is_ari_hierarchy_pf(struct fm10k_hw *hw)
94{
95 u16 sriov_ctrl = fm10k_read_pci_cfg_word(hw, FM10K_PCIE_SRIOV_CTRL);
96
97 return !!(sriov_ctrl & FM10K_PCIE_SRIOV_CTRL_VFARI);
98}
99
100
101
102
103
104
105static s32 fm10k_init_hw_pf(struct fm10k_hw *hw)
106{
107 u32 dma_ctrl, txqctl;
108 u16 i;
109
110
111 fm10k_write_reg(hw, FM10K_DGLORTDEC(fm10k_dglort_default), 0);
112 fm10k_write_reg(hw, FM10K_DGLORTMAP(fm10k_dglort_default),
113 FM10K_DGLORTMAP_ANY);
114
115
116 for (i = 1; i < FM10K_DGLORT_COUNT; i++)
117 fm10k_write_reg(hw, FM10K_DGLORTMAP(i), FM10K_DGLORTMAP_NONE);
118
119
120 fm10k_write_reg(hw, FM10K_ITR2(0), 0);
121
122
123 fm10k_write_reg(hw, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF), 0);
124
125
126 for (i = 1; i < FM10K_ITR_REG_COUNT_PF; i++)
127 fm10k_write_reg(hw, FM10K_ITR2(i), i - 1);
128
129
130 fm10k_write_reg(hw, FM10K_INT_CTRL, FM10K_INT_CTRL_ENABLEMODERATOR);
131
132
133 txqctl = FM10K_TXQCTL_PF | FM10K_TXQCTL_UNLIMITED_BW |
134 (hw->mac.default_vid << FM10K_TXQCTL_VID_SHIFT);
135
136 for (i = 0; i < FM10K_MAX_QUEUES; i++) {
137
138 fm10k_write_reg(hw, FM10K_TQDLOC(i),
139 (i * FM10K_TQDLOC_BASE_32_DESC) |
140 FM10K_TQDLOC_SIZE_32_DESC);
141 fm10k_write_reg(hw, FM10K_TXQCTL(i), txqctl);
142
143
144 fm10k_write_reg(hw, FM10K_TPH_TXCTRL(i),
145 FM10K_TPH_TXCTRL_DESC_TPHEN |
146 FM10K_TPH_TXCTRL_DESC_RROEN |
147 FM10K_TPH_TXCTRL_DESC_WROEN |
148 FM10K_TPH_TXCTRL_DATA_RROEN);
149 fm10k_write_reg(hw, FM10K_TPH_RXCTRL(i),
150 FM10K_TPH_RXCTRL_DESC_TPHEN |
151 FM10K_TPH_RXCTRL_DESC_RROEN |
152 FM10K_TPH_RXCTRL_DATA_WROEN |
153 FM10K_TPH_RXCTRL_HDR_WROEN);
154 }
155
156
157
158
159 switch (hw->bus.speed) {
160 case fm10k_bus_speed_2500:
161 dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN1;
162 hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN1;
163 break;
164 case fm10k_bus_speed_5000:
165 dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN2;
166 hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN2;
167 break;
168 case fm10k_bus_speed_8000:
169 dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN3;
170 hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN3;
171 break;
172 default:
173 dma_ctrl = 0;
174
175 hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN3;
176 break;
177 }
178
179
180 fm10k_write_reg(hw, FM10K_DTXTCPFLGL, FM10K_TSO_FLAGS_LOW);
181 fm10k_write_reg(hw, FM10K_DTXTCPFLGH, FM10K_TSO_FLAGS_HI);
182
183
184
185
186
187
188 dma_ctrl |= FM10K_DMA_CTRL_TX_ENABLE | FM10K_DMA_CTRL_RX_ENABLE |
189 FM10K_DMA_CTRL_RX_DESC_SIZE | FM10K_DMA_CTRL_MINMSS_64 |
190 FM10K_DMA_CTRL_32_DESC;
191
192 fm10k_write_reg(hw, FM10K_DMA_CTRL, dma_ctrl);
193
194
195 hw->mac.max_queues = FM10K_MAX_QUEUES_PF;
196
197
198 hw->iov.total_vfs = fm10k_is_ari_hierarchy_pf(hw) ? 64 : 7;
199
200 return 0;
201}
202
203
204
205
206
207
208
209
210
211
212
213
214
215static s32 fm10k_update_vlan_pf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
216{
217 u32 vlan_table, reg, mask, bit, len;
218
219
220 if (vsi > FM10K_VLAN_TABLE_VSI_MAX)
221 return FM10K_ERR_PARAM;
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236 len = vid >> 16;
237 vid = (vid << 17) >> 17;
238
239
240 if (len >= FM10K_VLAN_TABLE_VID_MAX || vid >= FM10K_VLAN_TABLE_VID_MAX)
241 return FM10K_ERR_PARAM;
242
243
244 for (reg = FM10K_VLAN_TABLE(vsi, vid / 32), bit = vid % 32;
245 len < FM10K_VLAN_TABLE_VID_MAX;
246 len -= 32 - bit, reg++, bit = 0) {
247
248 vlan_table = fm10k_read_reg(hw, reg);
249
250
251 mask = (~(u32)0 >> ((len < 31) ? 31 - len : 0)) << bit;
252
253
254 mask &= set ? ~vlan_table : vlan_table;
255 if (mask)
256 fm10k_write_reg(hw, reg, vlan_table ^ mask);
257 }
258
259 return 0;
260}
261
262
263
264
265
266
267
268static s32 fm10k_read_mac_addr_pf(struct fm10k_hw *hw)
269{
270 u8 perm_addr[ETH_ALEN];
271 u32 serial_num;
272
273 serial_num = fm10k_read_reg(hw, FM10K_SM_AREA(1));
274
275
276 if ((~serial_num) << 24)
277 return FM10K_ERR_INVALID_MAC_ADDR;
278
279 perm_addr[0] = (u8)(serial_num >> 24);
280 perm_addr[1] = (u8)(serial_num >> 16);
281 perm_addr[2] = (u8)(serial_num >> 8);
282
283 serial_num = fm10k_read_reg(hw, FM10K_SM_AREA(0));
284
285
286 if ((~serial_num) >> 24)
287 return FM10K_ERR_INVALID_MAC_ADDR;
288
289 perm_addr[3] = (u8)(serial_num >> 16);
290 perm_addr[4] = (u8)(serial_num >> 8);
291 perm_addr[5] = (u8)(serial_num);
292
293 ether_addr_copy(hw->mac.perm_addr, perm_addr);
294 ether_addr_copy(hw->mac.addr, perm_addr);
295
296 return 0;
297}
298
299
300
301
302
303
304
305
306bool fm10k_glort_valid_pf(struct fm10k_hw *hw, u16 glort)
307{
308 glort &= hw->mac.dglort_map >> FM10K_DGLORTMAP_MASK_SHIFT;
309
310 return glort == (hw->mac.dglort_map & FM10K_DGLORTMAP_NONE);
311}
312
313
314
315
316
317
318
319
320
321
322
323
324
325static s32 fm10k_update_xc_addr_pf(struct fm10k_hw *hw, u16 glort,
326 const u8 *mac, u16 vid, bool add, u8 flags)
327{
328 struct fm10k_mbx_info *mbx = &hw->mbx;
329 struct fm10k_mac_update mac_update;
330 u32 msg[5];
331
332
333 vid &= ~FM10K_VLAN_CLEAR;
334
335
336 if (!fm10k_glort_valid_pf(hw, glort) || vid >= FM10K_VLAN_TABLE_VID_MAX)
337 return FM10K_ERR_PARAM;
338
339
340 mac_update.mac_lower = cpu_to_le32(((u32)mac[2] << 24) |
341 ((u32)mac[3] << 16) |
342 ((u32)mac[4] << 8) |
343 ((u32)mac[5]));
344 mac_update.mac_upper = cpu_to_le16(((u16)mac[0] << 8) |
345 ((u16)mac[1]));
346 mac_update.vlan = cpu_to_le16(vid);
347 mac_update.glort = cpu_to_le16(glort);
348 mac_update.action = add ? 0 : 1;
349 mac_update.flags = flags;
350
351
352 fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_UPDATE_MAC_FWD_RULE);
353 fm10k_tlv_attr_put_le_struct(msg, FM10K_PF_ATTR_ID_MAC_UPDATE,
354 &mac_update, sizeof(mac_update));
355
356
357 return mbx->ops.enqueue_tx(hw, mbx, msg);
358}
359
360
361
362
363
364
365
366
367
368
369
370
371
372static s32 fm10k_update_uc_addr_pf(struct fm10k_hw *hw, u16 glort,
373 const u8 *mac, u16 vid, bool add, u8 flags)
374{
375
376 if (!is_valid_ether_addr(mac))
377 return FM10K_ERR_PARAM;
378
379 return fm10k_update_xc_addr_pf(hw, glort, mac, vid, add, flags);
380}
381
382
383
384
385
386
387
388
389
390
391
392
393static s32 fm10k_update_mc_addr_pf(struct fm10k_hw *hw, u16 glort,
394 const u8 *mac, u16 vid, bool add)
395{
396
397 if (!is_multicast_ether_addr(mac))
398 return FM10K_ERR_PARAM;
399
400 return fm10k_update_xc_addr_pf(hw, glort, mac, vid, add, 0);
401}
402
403
404
405
406
407
408
409
410
411
412
413static s32 fm10k_update_xcast_mode_pf(struct fm10k_hw *hw, u16 glort, u8 mode)
414{
415 struct fm10k_mbx_info *mbx = &hw->mbx;
416 u32 msg[3], xcast_mode;
417
418 if (mode > FM10K_XCAST_MODE_NONE)
419 return FM10K_ERR_PARAM;
420
421
422 if (!fm10k_glort_valid_pf(hw, glort))
423 return FM10K_ERR_PARAM;
424
425
426
427
428
429 xcast_mode = ((u32)mode << 16) | glort;
430
431
432 fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_XCAST_MODES);
433 fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_XCAST_MODE, xcast_mode);
434
435
436 return mbx->ops.enqueue_tx(hw, mbx, msg);
437}
438
439
440
441
442
443
444
445
446
447static void fm10k_update_int_moderator_pf(struct fm10k_hw *hw)
448{
449 u32 i;
450
451
452 fm10k_write_reg(hw, FM10K_INT_CTRL, 0);
453
454
455 for (i = FM10K_ITR_REG_COUNT_PF - 1; i; i--) {
456 if (!fm10k_read_reg(hw, FM10K_MSIX_VECTOR_MASK(i)))
457 break;
458 }
459
460
461 fm10k_write_reg(hw, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF), i);
462
463
464 if (!hw->iov.num_vfs)
465 fm10k_write_reg(hw, FM10K_ITR2(0), i);
466
467
468 fm10k_write_reg(hw, FM10K_INT_CTRL, FM10K_INT_CTRL_ENABLEMODERATOR);
469}
470
471
472
473
474
475
476
477
478
479
480static s32 fm10k_update_lport_state_pf(struct fm10k_hw *hw, u16 glort,
481 u16 count, bool enable)
482{
483 struct fm10k_mbx_info *mbx = &hw->mbx;
484 u32 msg[3], lport_msg;
485
486
487 if (!count)
488 return 0;
489
490
491 if (!fm10k_glort_valid_pf(hw, glort))
492 return FM10K_ERR_PARAM;
493
494
495 if (!enable)
496 fm10k_update_xcast_mode_pf(hw, glort, FM10K_XCAST_MODE_NONE);
497
498
499 lport_msg = ((u32)count << 16) | glort;
500
501
502 fm10k_tlv_msg_init(msg, enable ? FM10K_PF_MSG_ID_LPORT_CREATE :
503 FM10K_PF_MSG_ID_LPORT_DELETE);
504 fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_PORT, lport_msg);
505
506
507 return mbx->ops.enqueue_tx(hw, mbx, msg);
508}
509
510
511
512
513
514
515
516
517
518
519static s32 fm10k_configure_dglort_map_pf(struct fm10k_hw *hw,
520 struct fm10k_dglort_cfg *dglort)
521{
522 u16 glort, queue_count, vsi_count, pc_count;
523 u16 vsi, queue, pc, q_idx;
524 u32 txqctl, dglortdec, dglortmap;
525
526
527 if (!dglort)
528 return FM10K_ERR_PARAM;
529
530
531 if ((dglort->idx > 7) || (dglort->rss_l > 7) || (dglort->pc_l > 3) ||
532 (dglort->vsi_l > 6) || (dglort->vsi_b > 64) ||
533 (dglort->queue_l > 8) || (dglort->queue_b >= 256))
534 return FM10K_ERR_PARAM;
535
536
537 queue_count = BIT(dglort->rss_l + dglort->pc_l);
538 vsi_count = BIT(dglort->vsi_l + dglort->queue_l);
539 glort = dglort->glort;
540 q_idx = dglort->queue_b;
541
542
543 for (vsi = 0; vsi < vsi_count; vsi++, glort++) {
544 for (queue = 0; queue < queue_count; queue++, q_idx++) {
545 if (q_idx >= FM10K_MAX_QUEUES)
546 break;
547
548 fm10k_write_reg(hw, FM10K_TX_SGLORT(q_idx), glort);
549 fm10k_write_reg(hw, FM10K_RX_SGLORT(q_idx), glort);
550 }
551 }
552
553
554 queue_count = BIT(dglort->queue_l + dglort->rss_l + dglort->vsi_l);
555 pc_count = BIT(dglort->pc_l);
556
557
558 for (pc = 0; pc < pc_count; pc++) {
559 q_idx = pc + dglort->queue_b;
560 for (queue = 0; queue < queue_count; queue++) {
561 if (q_idx >= FM10K_MAX_QUEUES)
562 break;
563
564 txqctl = fm10k_read_reg(hw, FM10K_TXQCTL(q_idx));
565 txqctl &= ~FM10K_TXQCTL_PC_MASK;
566 txqctl |= pc << FM10K_TXQCTL_PC_SHIFT;
567 fm10k_write_reg(hw, FM10K_TXQCTL(q_idx), txqctl);
568
569 q_idx += pc_count;
570 }
571 }
572
573
574 dglortdec = ((u32)(dglort->rss_l) << FM10K_DGLORTDEC_RSSLENGTH_SHIFT) |
575 ((u32)(dglort->queue_b) << FM10K_DGLORTDEC_QBASE_SHIFT) |
576 ((u32)(dglort->pc_l) << FM10K_DGLORTDEC_PCLENGTH_SHIFT) |
577 ((u32)(dglort->vsi_b) << FM10K_DGLORTDEC_VSIBASE_SHIFT) |
578 ((u32)(dglort->vsi_l) << FM10K_DGLORTDEC_VSILENGTH_SHIFT) |
579 ((u32)(dglort->queue_l));
580 if (dglort->inner_rss)
581 dglortdec |= FM10K_DGLORTDEC_INNERRSS_ENABLE;
582
583
584 dglortmap = (dglort->idx == fm10k_dglort_default) ?
585 FM10K_DGLORTMAP_ANY : FM10K_DGLORTMAP_ZERO;
586 dglortmap <<= dglort->vsi_l + dglort->queue_l + dglort->shared_l;
587 dglortmap |= dglort->glort;
588
589
590 fm10k_write_reg(hw, FM10K_DGLORTDEC(dglort->idx), dglortdec);
591 fm10k_write_reg(hw, FM10K_DGLORTMAP(dglort->idx), dglortmap);
592
593 return 0;
594}
595
596u16 fm10k_queues_per_pool(struct fm10k_hw *hw)
597{
598 u16 num_pools = hw->iov.num_pools;
599
600 return (num_pools > 32) ? 2 : (num_pools > 16) ? 4 : (num_pools > 8) ?
601 8 : FM10K_MAX_QUEUES_POOL;
602}
603
604u16 fm10k_vf_queue_index(struct fm10k_hw *hw, u16 vf_idx)
605{
606 u16 num_vfs = hw->iov.num_vfs;
607 u16 vf_q_idx = FM10K_MAX_QUEUES;
608
609 vf_q_idx -= fm10k_queues_per_pool(hw) * (num_vfs - vf_idx);
610
611 return vf_q_idx;
612}
613
614static u16 fm10k_vectors_per_pool(struct fm10k_hw *hw)
615{
616 u16 num_pools = hw->iov.num_pools;
617
618 return (num_pools > 32) ? 8 : (num_pools > 16) ? 16 :
619 FM10K_MAX_VECTORS_POOL;
620}
621
622static u16 fm10k_vf_vector_index(struct fm10k_hw *hw, u16 vf_idx)
623{
624 u16 vf_v_idx = FM10K_MAX_VECTORS_PF;
625
626 vf_v_idx += fm10k_vectors_per_pool(hw) * vf_idx;
627
628 return vf_v_idx;
629}
630
631
632
633
634
635
636
637
638
639
640static s32 fm10k_iov_assign_resources_pf(struct fm10k_hw *hw, u16 num_vfs,
641 u16 num_pools)
642{
643 u16 qmap_stride, qpp, vpp, vf_q_idx, vf_q_idx0, qmap_idx;
644 u32 vid = hw->mac.default_vid << FM10K_TXQCTL_VID_SHIFT;
645 int i, j;
646
647
648 if (num_pools > 64)
649 return FM10K_ERR_PARAM;
650
651
652 if ((num_vfs > num_pools) || (num_vfs > hw->iov.total_vfs))
653 return FM10K_ERR_PARAM;
654
655
656 hw->iov.num_vfs = num_vfs;
657 hw->iov.num_pools = num_pools;
658
659
660 qmap_stride = (num_vfs > 8) ? 32 : 256;
661 qpp = fm10k_queues_per_pool(hw);
662 vpp = fm10k_vectors_per_pool(hw);
663
664
665 vf_q_idx = fm10k_vf_queue_index(hw, 0);
666 qmap_idx = 0;
667
668
669 for (i = 0; i < num_vfs; i++) {
670 fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(i), 0);
671 fm10k_write_reg(hw, FM10K_TC_RATE(i), 0);
672 fm10k_write_reg(hw, FM10K_TC_CREDIT(i),
673 FM10K_TC_CREDIT_CREDIT_MASK);
674 }
675
676
677 for (i = FM10K_VFMBMEM_LEN * num_vfs; i--;)
678 fm10k_write_reg(hw, FM10K_MBMEM(i), 0);
679
680
681 fm10k_write_reg(hw, FM10K_PFVFLREC(0), ~0);
682 fm10k_write_reg(hw, FM10K_PFVFLREC(1), ~0);
683
684
685 for (i = FM10K_MAX_QUEUES_PF; i < vf_q_idx; i++) {
686 fm10k_write_reg(hw, FM10K_TXDCTL(i), 0);
687 fm10k_write_reg(hw, FM10K_TXQCTL(i), FM10K_TXQCTL_PF |
688 FM10K_TXQCTL_UNLIMITED_BW | vid);
689 fm10k_write_reg(hw, FM10K_RXQCTL(i), FM10K_RXQCTL_PF);
690 }
691
692
693
694
695 for (i = FM10K_ITR_REG_COUNT_PF + 1; i < FM10K_ITR_REG_COUNT; i++) {
696 if (!(i & (vpp - 1)))
697 fm10k_write_reg(hw, FM10K_ITR2(i), i - vpp);
698 else
699 fm10k_write_reg(hw, FM10K_ITR2(i), i - 1);
700 }
701
702
703 fm10k_write_reg(hw, FM10K_ITR2(0),
704 fm10k_vf_vector_index(hw, num_vfs - 1));
705
706
707 for (i = 0; i < num_vfs; i++) {
708
709 vf_q_idx0 = vf_q_idx;
710
711 for (j = 0; j < qpp; j++, qmap_idx++, vf_q_idx++) {
712
713 fm10k_write_reg(hw, FM10K_TXDCTL(vf_q_idx), 0);
714 fm10k_write_reg(hw, FM10K_TXQCTL(vf_q_idx),
715 (i << FM10K_TXQCTL_TC_SHIFT) | i |
716 FM10K_TXQCTL_VF | vid);
717 fm10k_write_reg(hw, FM10K_RXDCTL(vf_q_idx),
718 FM10K_RXDCTL_WRITE_BACK_MIN_DELAY |
719 FM10K_RXDCTL_DROP_ON_EMPTY);
720 fm10k_write_reg(hw, FM10K_RXQCTL(vf_q_idx),
721 (i << FM10K_RXQCTL_VF_SHIFT) |
722 FM10K_RXQCTL_VF);
723
724
725 fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx);
726 fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), vf_q_idx);
727 }
728
729
730 for (; j < qmap_stride; j++, qmap_idx++) {
731 fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx0);
732 fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), vf_q_idx0);
733 }
734 }
735
736
737 while (qmap_idx < FM10K_TQMAP_TABLE_SIZE) {
738 fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), 0);
739 fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), 0);
740 qmap_idx++;
741 }
742
743 return 0;
744}
745
746
747
748
749
750
751
752
753
754
755static s32 fm10k_iov_configure_tc_pf(struct fm10k_hw *hw, u16 vf_idx, int rate)
756{
757
758 u32 interval = FM10K_TC_RATE_INTERVAL_4US_GEN3;
759 u32 tc_rate = FM10K_TC_RATE_QUANTA_MASK;
760
761
762 if (vf_idx >= hw->iov.num_vfs)
763 return FM10K_ERR_PARAM;
764
765
766 switch (hw->bus.speed) {
767 case fm10k_bus_speed_2500:
768 interval = FM10K_TC_RATE_INTERVAL_4US_GEN1;
769 break;
770 case fm10k_bus_speed_5000:
771 interval = FM10K_TC_RATE_INTERVAL_4US_GEN2;
772 break;
773 default:
774 break;
775 }
776
777 if (rate) {
778 if (rate > FM10K_VF_TC_MAX || rate < FM10K_VF_TC_MIN)
779 return FM10K_ERR_PARAM;
780
781
782
783
784
785
786
787
788 tc_rate = (rate * 128) / 125;
789
790
791
792
793 if (rate < 4000)
794 interval <<= 1;
795 else
796 tc_rate >>= 1;
797 }
798
799
800 fm10k_write_reg(hw, FM10K_TC_RATE(vf_idx), tc_rate | interval);
801 fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(vf_idx), FM10K_TC_MAXCREDIT_64K);
802 fm10k_write_reg(hw, FM10K_TC_CREDIT(vf_idx), FM10K_TC_MAXCREDIT_64K);
803
804 return 0;
805}
806
807
808
809
810
811
812
813
814
815static s32 fm10k_iov_assign_int_moderator_pf(struct fm10k_hw *hw, u16 vf_idx)
816{
817 u16 vf_v_idx, vf_v_limit, i;
818
819
820 if (vf_idx >= hw->iov.num_vfs)
821 return FM10K_ERR_PARAM;
822
823
824 vf_v_idx = fm10k_vf_vector_index(hw, vf_idx);
825 vf_v_limit = vf_v_idx + fm10k_vectors_per_pool(hw);
826
827
828 for (i = vf_v_limit - 1; i > vf_v_idx; i--) {
829 if (!fm10k_read_reg(hw, FM10K_MSIX_VECTOR_MASK(i)))
830 break;
831 }
832
833
834 if (vf_idx == (hw->iov.num_vfs - 1))
835 fm10k_write_reg(hw, FM10K_ITR2(0), i);
836 else
837 fm10k_write_reg(hw, FM10K_ITR2(vf_v_limit), i);
838
839 return 0;
840}
841
842
843
844
845
846
847
848
849static s32 fm10k_iov_assign_default_mac_vlan_pf(struct fm10k_hw *hw,
850 struct fm10k_vf_info *vf_info)
851{
852 u16 qmap_stride, queues_per_pool, vf_q_idx, timeout, qmap_idx, i;
853 u32 msg[4], txdctl, txqctl, tdbal = 0, tdbah = 0;
854 s32 err = 0;
855 u16 vf_idx, vf_vid;
856
857
858 if (!vf_info || vf_info->vf_idx >= hw->iov.num_vfs)
859 return FM10K_ERR_PARAM;
860
861
862 qmap_stride = (hw->iov.num_vfs > 8) ? 32 : 256;
863 queues_per_pool = fm10k_queues_per_pool(hw);
864
865
866 vf_idx = vf_info->vf_idx;
867 vf_q_idx = fm10k_vf_queue_index(hw, vf_idx);
868 qmap_idx = qmap_stride * vf_idx;
869
870
871
872
873
874
875 if (vf_info->pf_vid)
876 vf_vid = vf_info->pf_vid | FM10K_VLAN_OVERRIDE;
877 else
878 vf_vid = vf_info->sw_vid;
879
880
881 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
882 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_DEFAULT_MAC,
883 vf_info->mac, vf_vid);
884
885
886
887
888
889 txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) &
890 FM10K_TXQCTL_VID_MASK;
891 txqctl |= (vf_idx << FM10K_TXQCTL_TC_SHIFT) |
892 FM10K_TXQCTL_VF | vf_idx;
893
894 for (i = 0; i < queues_per_pool; i++)
895 fm10k_write_reg(hw, FM10K_TXQCTL(vf_q_idx + i), txqctl);
896
897
898 if (vf_info->mbx.ops.enqueue_tx) {
899 err = vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
900 if (err != FM10K_MBX_ERR_NO_MBX)
901 return err;
902 err = 0;
903 }
904
905
906
907
908
909
910
911
912 fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), 0);
913 fm10k_write_reg(hw, FM10K_TXDCTL(vf_q_idx), 0);
914
915
916 txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(vf_q_idx));
917 for (timeout = 0; txdctl & FM10K_TXDCTL_ENABLE; timeout++) {
918
919 if (timeout == 10) {
920 err = FM10K_ERR_DMA_PENDING;
921 goto err_out;
922 }
923
924 usleep_range(100, 200);
925 txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(vf_q_idx));
926 }
927
928
929 if (is_valid_ether_addr(vf_info->mac)) {
930 tdbal = (((u32)vf_info->mac[3]) << 24) |
931 (((u32)vf_info->mac[4]) << 16) |
932 (((u32)vf_info->mac[5]) << 8);
933
934 tdbah = (((u32)0xFF) << 24) |
935 (((u32)vf_info->mac[0]) << 16) |
936 (((u32)vf_info->mac[1]) << 8) |
937 ((u32)vf_info->mac[2]);
938 }
939
940
941 fm10k_write_reg(hw, FM10K_TDBAL(vf_q_idx), tdbal);
942 fm10k_write_reg(hw, FM10K_TDBAH(vf_q_idx), tdbah);
943
944
945
946
947
948 fm10k_write_reg(hw, FM10K_TDLEN(vf_q_idx), hw->mac.itr_scale <<
949 FM10K_TDLEN_ITR_SCALE_SHIFT);
950
951err_out:
952
953 fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx);
954 return err;
955}
956
957
958
959
960
961
962
963
964static s32 fm10k_iov_reset_resources_pf(struct fm10k_hw *hw,
965 struct fm10k_vf_info *vf_info)
966{
967 u16 qmap_stride, queues_per_pool, vf_q_idx, qmap_idx;
968 u32 tdbal = 0, tdbah = 0, txqctl, rxqctl;
969 u16 vf_v_idx, vf_v_limit, vf_vid;
970 u8 vf_idx = vf_info->vf_idx;
971 int i;
972
973
974 if (vf_idx >= hw->iov.num_vfs)
975 return FM10K_ERR_PARAM;
976
977
978 fm10k_write_reg(hw, FM10K_PFVFLREC(vf_idx / 32), BIT(vf_idx % 32));
979
980
981 vf_info->mbx.timeout = 0;
982 if (vf_info->mbx.ops.disconnect)
983 vf_info->mbx.ops.disconnect(hw, &vf_info->mbx);
984
985
986 vf_v_idx = fm10k_vf_vector_index(hw, vf_idx);
987 vf_v_limit = vf_v_idx + fm10k_vectors_per_pool(hw);
988
989
990 qmap_stride = (hw->iov.num_vfs > 8) ? 32 : 256;
991 queues_per_pool = fm10k_queues_per_pool(hw);
992 qmap_idx = qmap_stride * vf_idx;
993
994
995 for (i = qmap_idx; i < (qmap_idx + qmap_stride); i++) {
996 fm10k_write_reg(hw, FM10K_TQMAP(i), 0);
997 fm10k_write_reg(hw, FM10K_RQMAP(i), 0);
998 }
999
1000
1001 vf_q_idx = fm10k_vf_queue_index(hw, vf_idx);
1002
1003
1004 if (vf_info->pf_vid)
1005 vf_vid = vf_info->pf_vid;
1006 else
1007 vf_vid = vf_info->sw_vid;
1008
1009
1010 txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) |
1011 (vf_idx << FM10K_TXQCTL_TC_SHIFT) |
1012 FM10K_TXQCTL_VF | vf_idx;
1013 rxqctl = (vf_idx << FM10K_RXQCTL_VF_SHIFT) | FM10K_RXQCTL_VF;
1014
1015
1016 for (i = vf_q_idx; i < (queues_per_pool + vf_q_idx); i++) {
1017 fm10k_write_reg(hw, FM10K_TXDCTL(i), 0);
1018 fm10k_write_reg(hw, FM10K_TXQCTL(i), txqctl);
1019 fm10k_write_reg(hw, FM10K_RXDCTL(i),
1020 FM10K_RXDCTL_WRITE_BACK_MIN_DELAY |
1021 FM10K_RXDCTL_DROP_ON_EMPTY);
1022 fm10k_write_reg(hw, FM10K_RXQCTL(i), rxqctl);
1023 }
1024
1025
1026 fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(vf_idx), 0);
1027 fm10k_write_reg(hw, FM10K_TC_RATE(vf_idx), 0);
1028 fm10k_write_reg(hw, FM10K_TC_CREDIT(vf_idx),
1029 FM10K_TC_CREDIT_CREDIT_MASK);
1030
1031
1032 if (!vf_idx)
1033 hw->mac.ops.update_int_moderator(hw);
1034 else
1035 hw->iov.ops.assign_int_moderator(hw, vf_idx - 1);
1036
1037
1038 if (vf_idx == (hw->iov.num_vfs - 1))
1039 fm10k_write_reg(hw, FM10K_ITR2(0), vf_v_idx);
1040 else
1041 fm10k_write_reg(hw, FM10K_ITR2(vf_v_limit), vf_v_idx);
1042
1043
1044 for (vf_v_idx++; vf_v_idx < vf_v_limit; vf_v_idx++)
1045 fm10k_write_reg(hw, FM10K_ITR2(vf_v_idx), vf_v_idx - 1);
1046
1047
1048 for (i = FM10K_VFMBMEM_LEN; i--;)
1049 fm10k_write_reg(hw, FM10K_MBMEM_VF(vf_idx, i), 0);
1050 for (i = FM10K_VLAN_TABLE_SIZE; i--;)
1051 fm10k_write_reg(hw, FM10K_VLAN_TABLE(vf_info->vsi, i), 0);
1052 for (i = FM10K_RETA_SIZE; i--;)
1053 fm10k_write_reg(hw, FM10K_RETA(vf_info->vsi, i), 0);
1054 for (i = FM10K_RSSRK_SIZE; i--;)
1055 fm10k_write_reg(hw, FM10K_RSSRK(vf_info->vsi, i), 0);
1056 fm10k_write_reg(hw, FM10K_MRQC(vf_info->vsi), 0);
1057
1058
1059 if (is_valid_ether_addr(vf_info->mac)) {
1060 tdbal = (((u32)vf_info->mac[3]) << 24) |
1061 (((u32)vf_info->mac[4]) << 16) |
1062 (((u32)vf_info->mac[5]) << 8);
1063 tdbah = (((u32)0xFF) << 24) |
1064 (((u32)vf_info->mac[0]) << 16) |
1065 (((u32)vf_info->mac[1]) << 8) |
1066 ((u32)vf_info->mac[2]);
1067 }
1068
1069
1070 for (i = queues_per_pool; i--;) {
1071 fm10k_write_reg(hw, FM10K_TDBAL(vf_q_idx + i), tdbal);
1072 fm10k_write_reg(hw, FM10K_TDBAH(vf_q_idx + i), tdbah);
1073
1074
1075
1076 fm10k_write_reg(hw, FM10K_TDLEN(vf_q_idx + i),
1077 hw->mac.itr_scale <<
1078 FM10K_TDLEN_ITR_SCALE_SHIFT);
1079 fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx + i), vf_q_idx + i);
1080 fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx + i), vf_q_idx + i);
1081 }
1082
1083
1084 for (i = queues_per_pool; i < qmap_stride; i++) {
1085 fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx + i), vf_q_idx);
1086 fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx + i), vf_q_idx);
1087 }
1088
1089 return 0;
1090}
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102static s32 fm10k_iov_set_lport_pf(struct fm10k_hw *hw,
1103 struct fm10k_vf_info *vf_info,
1104 u16 lport_idx, u8 flags)
1105{
1106 u16 glort = (hw->mac.dglort_map + lport_idx) & FM10K_DGLORTMAP_NONE;
1107
1108
1109 if (!fm10k_glort_valid_pf(hw, glort))
1110 return FM10K_ERR_PARAM;
1111
1112 vf_info->vf_flags = flags | FM10K_VF_FLAG_NONE_CAPABLE;
1113 vf_info->glort = glort;
1114
1115 return 0;
1116}
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126static void fm10k_iov_reset_lport_pf(struct fm10k_hw *hw,
1127 struct fm10k_vf_info *vf_info)
1128{
1129 u32 msg[1];
1130
1131
1132 if (FM10K_VF_FLAG_ENABLED(vf_info)) {
1133
1134 fm10k_update_lport_state_pf(hw, vf_info->glort, 1, false);
1135
1136
1137 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
1138 vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
1139 }
1140
1141
1142 vf_info->vf_flags = 0;
1143 vf_info->glort = 0;
1144}
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154static void fm10k_iov_update_stats_pf(struct fm10k_hw *hw,
1155 struct fm10k_hw_stats_q *q,
1156 u16 vf_idx)
1157{
1158 u32 idx, qpp;
1159
1160
1161 qpp = fm10k_queues_per_pool(hw);
1162 idx = fm10k_vf_queue_index(hw, vf_idx);
1163 fm10k_update_hw_stats_q(hw, q, idx, qpp);
1164}
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176s32 fm10k_iov_msg_msix_pf(struct fm10k_hw *hw, u32 **results,
1177 struct fm10k_mbx_info *mbx)
1178{
1179 struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1180 u8 vf_idx = vf_info->vf_idx;
1181
1182 return hw->iov.ops.assign_int_moderator(hw, vf_idx);
1183}
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193static s32 fm10k_iov_select_vid(struct fm10k_vf_info *vf_info, u16 vid)
1194{
1195 if (!vid)
1196 return vf_info->pf_vid ? vf_info->pf_vid : vf_info->sw_vid;
1197 else if (vf_info->pf_vid && vid != vf_info->pf_vid)
1198 return FM10K_ERR_PARAM;
1199 else
1200 return vid;
1201}
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
1214 struct fm10k_mbx_info *mbx)
1215{
1216 struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1217 u8 mac[ETH_ALEN];
1218 u32 *result;
1219 int err = 0;
1220 bool set;
1221 u16 vlan;
1222 u32 vid;
1223
1224
1225 if (!FM10K_VF_FLAG_ENABLED(vf_info))
1226 err = FM10K_ERR_PARAM;
1227
1228 if (!err && !!results[FM10K_MAC_VLAN_MSG_VLAN]) {
1229 result = results[FM10K_MAC_VLAN_MSG_VLAN];
1230
1231
1232 err = fm10k_tlv_attr_get_u32(result, &vid);
1233 if (err)
1234 return err;
1235
1236 set = !(vid & FM10K_VLAN_CLEAR);
1237 vid &= ~FM10K_VLAN_CLEAR;
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249 if (vid >> 16) {
1250
1251
1252
1253 if (vf_info->pf_vid)
1254 return FM10K_ERR_PARAM;
1255 } else {
1256 err = fm10k_iov_select_vid(vf_info, (u16)vid);
1257 if (err < 0)
1258 return err;
1259
1260 vid = err;
1261 }
1262
1263
1264 err = hw->mac.ops.update_vlan(hw, vid, vf_info->vsi, set);
1265 }
1266
1267 if (!err && !!results[FM10K_MAC_VLAN_MSG_MAC]) {
1268 result = results[FM10K_MAC_VLAN_MSG_MAC];
1269
1270
1271 err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan);
1272 if (err)
1273 return err;
1274
1275
1276 if (is_valid_ether_addr(vf_info->mac) &&
1277 !ether_addr_equal(mac, vf_info->mac))
1278 return FM10K_ERR_PARAM;
1279
1280 set = !(vlan & FM10K_VLAN_CLEAR);
1281 vlan &= ~FM10K_VLAN_CLEAR;
1282
1283 err = fm10k_iov_select_vid(vf_info, vlan);
1284 if (err < 0)
1285 return err;
1286
1287 vlan = (u16)err;
1288
1289
1290 err = hw->mac.ops.update_uc_addr(hw, vf_info->glort,
1291 mac, vlan, set, 0);
1292 }
1293
1294 if (!err && !!results[FM10K_MAC_VLAN_MSG_MULTICAST]) {
1295 result = results[FM10K_MAC_VLAN_MSG_MULTICAST];
1296
1297
1298 err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan);
1299 if (err)
1300 return err;
1301
1302
1303 if (!(vf_info->vf_flags & FM10K_VF_FLAG_MULTI_ENABLED))
1304 return FM10K_ERR_PARAM;
1305
1306 set = !(vlan & FM10K_VLAN_CLEAR);
1307 vlan &= ~FM10K_VLAN_CLEAR;
1308
1309 err = fm10k_iov_select_vid(vf_info, vlan);
1310 if (err < 0)
1311 return err;
1312
1313 vlan = (u16)err;
1314
1315
1316 err = hw->mac.ops.update_mc_addr(hw, vf_info->glort,
1317 mac, vlan, set);
1318 }
1319
1320 return err;
1321}
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331static u8 fm10k_iov_supported_xcast_mode_pf(struct fm10k_vf_info *vf_info,
1332 u8 mode)
1333{
1334 u8 vf_flags = vf_info->vf_flags;
1335
1336
1337 switch (mode) {
1338 case FM10K_XCAST_MODE_PROMISC:
1339 if (vf_flags & FM10K_VF_FLAG_PROMISC_CAPABLE)
1340 return FM10K_XCAST_MODE_PROMISC;
1341
1342 case FM10K_XCAST_MODE_ALLMULTI:
1343 if (vf_flags & FM10K_VF_FLAG_ALLMULTI_CAPABLE)
1344 return FM10K_XCAST_MODE_ALLMULTI;
1345
1346 case FM10K_XCAST_MODE_MULTI:
1347 if (vf_flags & FM10K_VF_FLAG_MULTI_CAPABLE)
1348 return FM10K_XCAST_MODE_MULTI;
1349
1350 case FM10K_XCAST_MODE_NONE:
1351 if (vf_flags & FM10K_VF_FLAG_NONE_CAPABLE)
1352 return FM10K_XCAST_MODE_NONE;
1353
1354 default:
1355 break;
1356 }
1357
1358
1359 return FM10K_XCAST_MODE_DISABLE;
1360}
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372s32 fm10k_iov_msg_lport_state_pf(struct fm10k_hw *hw, u32 **results,
1373 struct fm10k_mbx_info *mbx)
1374{
1375 struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1376 u32 *result;
1377 s32 err = 0;
1378 u32 msg[2];
1379 u8 mode = 0;
1380
1381
1382 if (!(vf_info->vf_flags & FM10K_VF_FLAG_NONE_CAPABLE))
1383 return FM10K_ERR_PARAM;
1384
1385 if (!!results[FM10K_LPORT_STATE_MSG_XCAST_MODE]) {
1386 result = results[FM10K_LPORT_STATE_MSG_XCAST_MODE];
1387
1388
1389 err = fm10k_tlv_attr_get_u8(result, &mode);
1390 if (err)
1391 return FM10K_ERR_PARAM;
1392
1393
1394 mode = fm10k_iov_supported_xcast_mode_pf(vf_info, mode);
1395
1396
1397 if (!(FM10K_VF_FLAG_ENABLED(vf_info) & BIT(mode)))
1398 fm10k_update_xcast_mode_pf(hw, vf_info->glort, mode);
1399
1400
1401 mode = FM10K_VF_FLAG_SET_MODE(mode);
1402 } else if (!results[FM10K_LPORT_STATE_MSG_DISABLE]) {
1403
1404 if (FM10K_VF_FLAG_ENABLED(vf_info))
1405 err = fm10k_update_lport_state_pf(hw, vf_info->glort,
1406 1, false);
1407
1408
1409
1410
1411
1412
1413 if (!err)
1414 vf_info->vf_flags = FM10K_VF_FLAG_CAPABLE(vf_info);
1415
1416
1417 hw->iov.ops.configure_tc(hw, vf_info->vf_idx, vf_info->rate);
1418
1419
1420 mode = FM10K_VF_FLAG_SET_MODE_NONE;
1421
1422
1423 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
1424 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_READY);
1425 mbx->ops.enqueue_tx(hw, mbx, msg);
1426 }
1427
1428
1429 if (!err && (!FM10K_VF_FLAG_ENABLED(vf_info) != !mode))
1430 err = fm10k_update_lport_state_pf(hw, vf_info->glort, 1,
1431 !!mode);
1432
1433
1434 mode |= FM10K_VF_FLAG_CAPABLE(vf_info);
1435 if (!err)
1436 vf_info->vf_flags = mode;
1437
1438 return err;
1439}
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449static void fm10k_update_hw_stats_pf(struct fm10k_hw *hw,
1450 struct fm10k_hw_stats *stats)
1451{
1452 u32 timeout, ur, ca, um, xec, vlan_drop, loopback_drop, nodesc_drop;
1453 u32 id, id_prev;
1454
1455
1456 id = fm10k_read_reg(hw, FM10K_TXQCTL(0));
1457
1458
1459 do {
1460 timeout = fm10k_read_hw_stats_32b(hw, FM10K_STATS_TIMEOUT,
1461 &stats->timeout);
1462 ur = fm10k_read_hw_stats_32b(hw, FM10K_STATS_UR, &stats->ur);
1463 ca = fm10k_read_hw_stats_32b(hw, FM10K_STATS_CA, &stats->ca);
1464 um = fm10k_read_hw_stats_32b(hw, FM10K_STATS_UM, &stats->um);
1465 xec = fm10k_read_hw_stats_32b(hw, FM10K_STATS_XEC, &stats->xec);
1466 vlan_drop = fm10k_read_hw_stats_32b(hw, FM10K_STATS_VLAN_DROP,
1467 &stats->vlan_drop);
1468 loopback_drop =
1469 fm10k_read_hw_stats_32b(hw,
1470 FM10K_STATS_LOOPBACK_DROP,
1471 &stats->loopback_drop);
1472 nodesc_drop = fm10k_read_hw_stats_32b(hw,
1473 FM10K_STATS_NODESC_DROP,
1474 &stats->nodesc_drop);
1475
1476
1477 id_prev = id;
1478 id = fm10k_read_reg(hw, FM10K_TXQCTL(0));
1479 } while ((id ^ id_prev) & FM10K_TXQCTL_ID_MASK);
1480
1481
1482 id &= FM10K_TXQCTL_ID_MASK;
1483 id |= FM10K_STAT_VALID;
1484
1485
1486 if (stats->stats_idx == id) {
1487 stats->timeout.count += timeout;
1488 stats->ur.count += ur;
1489 stats->ca.count += ca;
1490 stats->um.count += um;
1491 stats->xec.count += xec;
1492 stats->vlan_drop.count += vlan_drop;
1493 stats->loopback_drop.count += loopback_drop;
1494 stats->nodesc_drop.count += nodesc_drop;
1495 }
1496
1497
1498 fm10k_update_hw_base_32b(&stats->timeout, timeout);
1499 fm10k_update_hw_base_32b(&stats->ur, ur);
1500 fm10k_update_hw_base_32b(&stats->ca, ca);
1501 fm10k_update_hw_base_32b(&stats->um, um);
1502 fm10k_update_hw_base_32b(&stats->xec, xec);
1503 fm10k_update_hw_base_32b(&stats->vlan_drop, vlan_drop);
1504 fm10k_update_hw_base_32b(&stats->loopback_drop, loopback_drop);
1505 fm10k_update_hw_base_32b(&stats->nodesc_drop, nodesc_drop);
1506 stats->stats_idx = id;
1507
1508
1509 fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
1510}
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520static void fm10k_rebind_hw_stats_pf(struct fm10k_hw *hw,
1521 struct fm10k_hw_stats *stats)
1522{
1523
1524 fm10k_unbind_hw_stats_32b(&stats->timeout);
1525 fm10k_unbind_hw_stats_32b(&stats->ur);
1526 fm10k_unbind_hw_stats_32b(&stats->ca);
1527 fm10k_unbind_hw_stats_32b(&stats->um);
1528 fm10k_unbind_hw_stats_32b(&stats->xec);
1529 fm10k_unbind_hw_stats_32b(&stats->vlan_drop);
1530 fm10k_unbind_hw_stats_32b(&stats->loopback_drop);
1531 fm10k_unbind_hw_stats_32b(&stats->nodesc_drop);
1532
1533
1534 fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
1535
1536
1537 fm10k_update_hw_stats_pf(hw, stats);
1538}
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548static void fm10k_set_dma_mask_pf(struct fm10k_hw *hw, u64 dma_mask)
1549{
1550
1551 u32 phyaddr = (u32)(dma_mask >> 32);
1552
1553 fm10k_write_reg(hw, FM10K_PHYADDR, phyaddr);
1554}
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567static s32 fm10k_get_fault_pf(struct fm10k_hw *hw, int type,
1568 struct fm10k_fault *fault)
1569{
1570 u32 func;
1571
1572
1573 switch (type) {
1574 case FM10K_PCA_FAULT:
1575 case FM10K_THI_FAULT:
1576 case FM10K_FUM_FAULT:
1577 break;
1578 default:
1579 return FM10K_ERR_PARAM;
1580 }
1581
1582
1583 func = fm10k_read_reg(hw, type + FM10K_FAULT_FUNC);
1584 if (!(func & FM10K_FAULT_FUNC_VALID))
1585 return FM10K_ERR_PARAM;
1586
1587
1588 fault->address = fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_HI);
1589 fault->address <<= 32;
1590 fault->address = fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_LO);
1591 fault->specinfo = fm10k_read_reg(hw, type + FM10K_FAULT_SPECINFO);
1592
1593
1594 fm10k_write_reg(hw, type + FM10K_FAULT_FUNC, FM10K_FAULT_FUNC_VALID);
1595
1596
1597 if (func & FM10K_FAULT_FUNC_PF)
1598 fault->func = 0;
1599 else
1600 fault->func = 1 + ((func & FM10K_FAULT_FUNC_VF_MASK) >>
1601 FM10K_FAULT_FUNC_VF_SHIFT);
1602
1603
1604 fault->type = func & FM10K_FAULT_FUNC_TYPE_MASK;
1605
1606 return 0;
1607}
1608
1609
1610
1611
1612
1613
1614static s32 fm10k_request_lport_map_pf(struct fm10k_hw *hw)
1615{
1616 struct fm10k_mbx_info *mbx = &hw->mbx;
1617 u32 msg[1];
1618
1619
1620 fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_LPORT_MAP);
1621
1622
1623 return mbx->ops.enqueue_tx(hw, mbx, msg);
1624}
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635static s32 fm10k_get_host_state_pf(struct fm10k_hw *hw, bool *switch_ready)
1636{
1637 u32 dma_ctrl2;
1638
1639
1640 dma_ctrl2 = fm10k_read_reg(hw, FM10K_DMA_CTRL2);
1641 if (!(dma_ctrl2 & FM10K_DMA_CTRL2_SWITCH_READY))
1642 return 0;
1643
1644
1645 return fm10k_get_host_state_generic(hw, switch_ready);
1646}
1647
1648
1649const struct fm10k_tlv_attr fm10k_lport_map_msg_attr[] = {
1650 FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_ERR,
1651 sizeof(struct fm10k_swapi_error)),
1652 FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_LPORT_MAP),
1653 FM10K_TLV_ATTR_LAST
1654};
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665s32 fm10k_msg_lport_map_pf(struct fm10k_hw *hw, u32 **results,
1666 struct fm10k_mbx_info *mbx)
1667{
1668 u16 glort, mask;
1669 u32 dglort_map;
1670 s32 err;
1671
1672 err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_LPORT_MAP],
1673 &dglort_map);
1674 if (err)
1675 return err;
1676
1677
1678 glort = FM10K_MSG_HDR_FIELD_GET(dglort_map, LPORT_MAP_GLORT);
1679 mask = FM10K_MSG_HDR_FIELD_GET(dglort_map, LPORT_MAP_MASK);
1680
1681
1682 if (!mask || (glort & ~mask))
1683 return FM10K_ERR_PARAM;
1684
1685
1686 if (((~(mask - 1) & mask) + mask) & FM10K_DGLORTMAP_NONE)
1687 return FM10K_ERR_PARAM;
1688
1689
1690 hw->mac.dglort_map = dglort_map;
1691
1692 return 0;
1693}
1694
1695const struct fm10k_tlv_attr fm10k_update_pvid_msg_attr[] = {
1696 FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_UPDATE_PVID),
1697 FM10K_TLV_ATTR_LAST
1698};
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708static s32 fm10k_msg_update_pvid_pf(struct fm10k_hw *hw, u32 **results,
1709 struct fm10k_mbx_info *mbx)
1710{
1711 u16 glort, pvid;
1712 u32 pvid_update;
1713 s32 err;
1714
1715 err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_UPDATE_PVID],
1716 &pvid_update);
1717 if (err)
1718 return err;
1719
1720
1721 glort = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_GLORT);
1722 pvid = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_PVID);
1723
1724
1725 if (!fm10k_glort_valid_pf(hw, glort))
1726 return FM10K_ERR_PARAM;
1727
1728
1729 if (pvid >= FM10K_VLAN_TABLE_VID_MAX)
1730 return FM10K_ERR_PARAM;
1731
1732
1733 hw->mac.default_vid = pvid;
1734
1735 return 0;
1736}
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746static void fm10k_record_global_table_data(struct fm10k_global_table_data *from,
1747 struct fm10k_swapi_table_info *to)
1748{
1749
1750 to->used = le32_to_cpu(from->used);
1751 to->avail = le32_to_cpu(from->avail);
1752}
1753
1754const struct fm10k_tlv_attr fm10k_err_msg_attr[] = {
1755 FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_ERR,
1756 sizeof(struct fm10k_swapi_error)),
1757 FM10K_TLV_ATTR_LAST
1758};
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769s32 fm10k_msg_err_pf(struct fm10k_hw *hw, u32 **results,
1770 struct fm10k_mbx_info *mbx)
1771{
1772 struct fm10k_swapi_error err_msg;
1773 s32 err;
1774
1775
1776 err = fm10k_tlv_attr_get_le_struct(results[FM10K_PF_ATTR_ID_ERR],
1777 &err_msg, sizeof(err_msg));
1778 if (err)
1779 return err;
1780
1781
1782 fm10k_record_global_table_data(&err_msg.mac, &hw->swapi.mac);
1783 fm10k_record_global_table_data(&err_msg.nexthop, &hw->swapi.nexthop);
1784 fm10k_record_global_table_data(&err_msg.ffu, &hw->swapi.ffu);
1785
1786
1787 hw->swapi.status = le32_to_cpu(err_msg.status);
1788
1789 return 0;
1790}
1791
1792static const struct fm10k_msg_data fm10k_msg_data_pf[] = {
1793 FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES, fm10k_msg_err_pf),
1794 FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE, fm10k_msg_err_pf),
1795 FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_msg_lport_map_pf),
1796 FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, fm10k_msg_err_pf),
1797 FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, fm10k_msg_err_pf),
1798 FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_msg_update_pvid_pf),
1799 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
1800};
1801
1802static const struct fm10k_mac_ops mac_ops_pf = {
1803 .get_bus_info = fm10k_get_bus_info_generic,
1804 .reset_hw = fm10k_reset_hw_pf,
1805 .init_hw = fm10k_init_hw_pf,
1806 .start_hw = fm10k_start_hw_generic,
1807 .stop_hw = fm10k_stop_hw_generic,
1808 .update_vlan = fm10k_update_vlan_pf,
1809 .read_mac_addr = fm10k_read_mac_addr_pf,
1810 .update_uc_addr = fm10k_update_uc_addr_pf,
1811 .update_mc_addr = fm10k_update_mc_addr_pf,
1812 .update_xcast_mode = fm10k_update_xcast_mode_pf,
1813 .update_int_moderator = fm10k_update_int_moderator_pf,
1814 .update_lport_state = fm10k_update_lport_state_pf,
1815 .update_hw_stats = fm10k_update_hw_stats_pf,
1816 .rebind_hw_stats = fm10k_rebind_hw_stats_pf,
1817 .configure_dglort_map = fm10k_configure_dglort_map_pf,
1818 .set_dma_mask = fm10k_set_dma_mask_pf,
1819 .get_fault = fm10k_get_fault_pf,
1820 .get_host_state = fm10k_get_host_state_pf,
1821 .request_lport_map = fm10k_request_lport_map_pf,
1822};
1823
1824static const struct fm10k_iov_ops iov_ops_pf = {
1825 .assign_resources = fm10k_iov_assign_resources_pf,
1826 .configure_tc = fm10k_iov_configure_tc_pf,
1827 .assign_int_moderator = fm10k_iov_assign_int_moderator_pf,
1828 .assign_default_mac_vlan = fm10k_iov_assign_default_mac_vlan_pf,
1829 .reset_resources = fm10k_iov_reset_resources_pf,
1830 .set_lport = fm10k_iov_set_lport_pf,
1831 .reset_lport = fm10k_iov_reset_lport_pf,
1832 .update_stats = fm10k_iov_update_stats_pf,
1833};
1834
1835static s32 fm10k_get_invariants_pf(struct fm10k_hw *hw)
1836{
1837 fm10k_get_invariants_generic(hw);
1838
1839 return fm10k_sm_mbx_init(hw, &hw->mbx, fm10k_msg_data_pf);
1840}
1841
1842const struct fm10k_info fm10k_pf_info = {
1843 .mac = fm10k_mac_pf,
1844 .get_invariants = fm10k_get_invariants_pf,
1845 .mac_ops = &mac_ops_pf,
1846 .iov_ops = &iov_ops_pf,
1847};
1848