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