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