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