1
2
3
4#include "ice_common.h"
5#include "ice_sched.h"
6#include "ice_dcb.h"
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21static enum ice_status
22ice_aq_get_lldp_mib(struct ice_hw *hw, u8 bridge_type, u8 mib_type, void *buf,
23 u16 buf_size, u16 *local_len, u16 *remote_len,
24 struct ice_sq_cd *cd)
25{
26 struct ice_aqc_lldp_get_mib *cmd;
27 struct ice_aq_desc desc;
28 enum ice_status status;
29
30 cmd = &desc.params.lldp_get_mib;
31
32 if (buf_size == 0 || !buf)
33 return ICE_ERR_PARAM;
34
35 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_get_mib);
36
37 cmd->type = mib_type & ICE_AQ_LLDP_MIB_TYPE_M;
38 cmd->type |= (bridge_type << ICE_AQ_LLDP_BRID_TYPE_S) &
39 ICE_AQ_LLDP_BRID_TYPE_M;
40
41 desc.datalen = cpu_to_le16(buf_size);
42
43 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
44 if (!status) {
45 if (local_len)
46 *local_len = le16_to_cpu(cmd->local_len);
47 if (remote_len)
48 *remote_len = le16_to_cpu(cmd->remote_len);
49 }
50
51 return status;
52}
53
54
55
56
57
58
59
60
61
62
63static enum ice_status
64ice_aq_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_update,
65 struct ice_sq_cd *cd)
66{
67 struct ice_aqc_lldp_set_mib_change *cmd;
68 struct ice_aq_desc desc;
69
70 cmd = &desc.params.lldp_set_event;
71
72 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_set_mib_change);
73
74 if (!ena_update)
75 cmd->command |= ICE_AQ_LLDP_MIB_UPDATE_DIS;
76
77 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
78}
79
80
81
82
83
84
85
86
87
88
89
90
91enum ice_status
92ice_aq_stop_lldp(struct ice_hw *hw, bool shutdown_lldp_agent, bool persist,
93 struct ice_sq_cd *cd)
94{
95 struct ice_aqc_lldp_stop *cmd;
96 struct ice_aq_desc desc;
97
98 cmd = &desc.params.lldp_stop;
99
100 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_stop);
101
102 if (shutdown_lldp_agent)
103 cmd->command |= ICE_AQ_LLDP_AGENT_SHUTDOWN;
104
105 if (persist)
106 cmd->command |= ICE_AQ_LLDP_AGENT_PERSIST_DIS;
107
108 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
109}
110
111
112
113
114
115
116
117
118
119enum ice_status
120ice_aq_start_lldp(struct ice_hw *hw, bool persist, struct ice_sq_cd *cd)
121{
122 struct ice_aqc_lldp_start *cmd;
123 struct ice_aq_desc desc;
124
125 cmd = &desc.params.lldp_start;
126
127 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_start);
128
129 cmd->command = ICE_AQ_LLDP_AGENT_START;
130
131 if (persist)
132 cmd->command |= ICE_AQ_LLDP_AGENT_PERSIST_ENA;
133
134 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
135}
136
137
138
139
140
141
142
143static u8 ice_get_dcbx_status(struct ice_hw *hw)
144{
145 u32 reg;
146
147 reg = rd32(hw, PRTDCB_GENS);
148 return (u8)((reg & PRTDCB_GENS_DCBX_STATUS_M) >>
149 PRTDCB_GENS_DCBX_STATUS_S);
150}
151
152
153
154
155
156
157
158
159static void
160ice_parse_ieee_ets_common_tlv(u8 *buf, struct ice_dcb_ets_cfg *ets_cfg)
161{
162 u8 offset = 0;
163 int i;
164
165
166
167
168
169
170
171
172
173 for (i = 0; i < 4; i++) {
174 ets_cfg->prio_table[i * 2] =
175 ((buf[offset] & ICE_IEEE_ETS_PRIO_1_M) >>
176 ICE_IEEE_ETS_PRIO_1_S);
177 ets_cfg->prio_table[i * 2 + 1] =
178 ((buf[offset] & ICE_IEEE_ETS_PRIO_0_M) >>
179 ICE_IEEE_ETS_PRIO_0_S);
180 offset++;
181 }
182
183
184
185
186
187
188
189
190
191
192
193
194
195 ice_for_each_traffic_class(i) {
196 ets_cfg->tcbwtable[i] = buf[offset];
197 ets_cfg->tsatable[i] = buf[ICE_MAX_TRAFFIC_CLASS + offset++];
198 }
199}
200
201
202
203
204
205
206
207
208static void
209ice_parse_ieee_etscfg_tlv(struct ice_lldp_org_tlv *tlv,
210 struct ice_dcbx_cfg *dcbcfg)
211{
212 struct ice_dcb_ets_cfg *etscfg;
213 u8 *buf = tlv->tlvinfo;
214
215
216
217
218
219
220
221
222 etscfg = &dcbcfg->etscfg;
223 etscfg->willing = ((buf[0] & ICE_IEEE_ETS_WILLING_M) >>
224 ICE_IEEE_ETS_WILLING_S);
225 etscfg->cbs = ((buf[0] & ICE_IEEE_ETS_CBS_M) >> ICE_IEEE_ETS_CBS_S);
226 etscfg->maxtcs = ((buf[0] & ICE_IEEE_ETS_MAXTC_M) >>
227 ICE_IEEE_ETS_MAXTC_S);
228
229
230 ice_parse_ieee_ets_common_tlv(&buf[1], etscfg);
231}
232
233
234
235
236
237
238
239
240static void
241ice_parse_ieee_etsrec_tlv(struct ice_lldp_org_tlv *tlv,
242 struct ice_dcbx_cfg *dcbcfg)
243{
244 u8 *buf = tlv->tlvinfo;
245
246
247 ice_parse_ieee_ets_common_tlv(&buf[1], &dcbcfg->etsrec);
248}
249
250
251
252
253
254
255
256
257static void
258ice_parse_ieee_pfccfg_tlv(struct ice_lldp_org_tlv *tlv,
259 struct ice_dcbx_cfg *dcbcfg)
260{
261 u8 *buf = tlv->tlvinfo;
262
263
264
265
266
267
268
269 dcbcfg->pfc.willing = ((buf[0] & ICE_IEEE_PFC_WILLING_M) >>
270 ICE_IEEE_PFC_WILLING_S);
271 dcbcfg->pfc.mbc = ((buf[0] & ICE_IEEE_PFC_MBC_M) >> ICE_IEEE_PFC_MBC_S);
272 dcbcfg->pfc.pfccap = ((buf[0] & ICE_IEEE_PFC_CAP_M) >>
273 ICE_IEEE_PFC_CAP_S);
274 dcbcfg->pfc.pfcena = buf[1];
275}
276
277
278
279
280
281
282
283
284static void
285ice_parse_ieee_app_tlv(struct ice_lldp_org_tlv *tlv,
286 struct ice_dcbx_cfg *dcbcfg)
287{
288 u16 offset = 0;
289 u16 typelen;
290 int i = 0;
291 u16 len;
292 u8 *buf;
293
294 typelen = ntohs(tlv->typelen);
295 len = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
296 buf = tlv->tlvinfo;
297
298
299
300
301 len -= (sizeof(tlv->ouisubtype) + 1);
302
303
304 offset++;
305
306
307
308
309
310
311
312
313
314 while (offset < len) {
315 dcbcfg->app[i].priority = ((buf[offset] &
316 ICE_IEEE_APP_PRIO_M) >>
317 ICE_IEEE_APP_PRIO_S);
318 dcbcfg->app[i].selector = ((buf[offset] &
319 ICE_IEEE_APP_SEL_M) >>
320 ICE_IEEE_APP_SEL_S);
321 dcbcfg->app[i].prot_id = (buf[offset + 1] << 0x8) |
322 buf[offset + 2];
323
324 offset += 3;
325 i++;
326 if (i >= ICE_DCBX_MAX_APPS)
327 break;
328 }
329
330 dcbcfg->numapps = i;
331}
332
333
334
335
336
337
338
339
340
341static void
342ice_parse_ieee_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
343{
344 u32 ouisubtype;
345 u8 subtype;
346
347 ouisubtype = ntohl(tlv->ouisubtype);
348 subtype = (u8)((ouisubtype & ICE_LLDP_TLV_SUBTYPE_M) >>
349 ICE_LLDP_TLV_SUBTYPE_S);
350 switch (subtype) {
351 case ICE_IEEE_SUBTYPE_ETS_CFG:
352 ice_parse_ieee_etscfg_tlv(tlv, dcbcfg);
353 break;
354 case ICE_IEEE_SUBTYPE_ETS_REC:
355 ice_parse_ieee_etsrec_tlv(tlv, dcbcfg);
356 break;
357 case ICE_IEEE_SUBTYPE_PFC_CFG:
358 ice_parse_ieee_pfccfg_tlv(tlv, dcbcfg);
359 break;
360 case ICE_IEEE_SUBTYPE_APP_PRI:
361 ice_parse_ieee_app_tlv(tlv, dcbcfg);
362 break;
363 default:
364 break;
365 }
366}
367
368
369
370
371
372
373
374
375static void
376ice_parse_cee_pgcfg_tlv(struct ice_cee_feat_tlv *tlv,
377 struct ice_dcbx_cfg *dcbcfg)
378{
379 struct ice_dcb_ets_cfg *etscfg;
380 u8 *buf = tlv->tlvinfo;
381 u16 offset = 0;
382 int i;
383
384 etscfg = &dcbcfg->etscfg;
385
386 if (tlv->en_will_err & ICE_CEE_FEAT_TLV_WILLING_M)
387 etscfg->willing = 1;
388
389 etscfg->cbs = 0;
390
391
392
393
394
395
396
397
398 for (i = 0; i < 4; i++) {
399 etscfg->prio_table[i * 2] =
400 ((buf[offset] & ICE_CEE_PGID_PRIO_1_M) >>
401 ICE_CEE_PGID_PRIO_1_S);
402 etscfg->prio_table[i * 2 + 1] =
403 ((buf[offset] & ICE_CEE_PGID_PRIO_0_M) >>
404 ICE_CEE_PGID_PRIO_0_S);
405 offset++;
406 }
407
408
409
410
411
412
413
414 ice_for_each_traffic_class(i) {
415 etscfg->tcbwtable[i] = buf[offset++];
416
417 if (etscfg->prio_table[i] == ICE_CEE_PGID_STRICT)
418 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_STRICT;
419 else
420 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_ETS;
421 }
422
423
424 etscfg->maxtcs = buf[offset];
425}
426
427
428
429
430
431
432
433
434static void
435ice_parse_cee_pfccfg_tlv(struct ice_cee_feat_tlv *tlv,
436 struct ice_dcbx_cfg *dcbcfg)
437{
438 u8 *buf = tlv->tlvinfo;
439
440 if (tlv->en_will_err & ICE_CEE_FEAT_TLV_WILLING_M)
441 dcbcfg->pfc.willing = 1;
442
443
444
445
446
447
448 dcbcfg->pfc.pfcena = buf[0];
449 dcbcfg->pfc.pfccap = buf[1];
450}
451
452
453
454
455
456
457
458
459static void
460ice_parse_cee_app_tlv(struct ice_cee_feat_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
461{
462 u16 len, typelen, offset = 0;
463 struct ice_cee_app_prio *app;
464 u8 i;
465
466 typelen = ntohs(tlv->hdr.typelen);
467 len = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
468
469 dcbcfg->numapps = len / sizeof(*app);
470 if (!dcbcfg->numapps)
471 return;
472 if (dcbcfg->numapps > ICE_DCBX_MAX_APPS)
473 dcbcfg->numapps = ICE_DCBX_MAX_APPS;
474
475 for (i = 0; i < dcbcfg->numapps; i++) {
476 u8 up, selector;
477
478 app = (struct ice_cee_app_prio *)(tlv->tlvinfo + offset);
479 for (up = 0; up < ICE_MAX_USER_PRIORITY; up++)
480 if (app->prio_map & BIT(up))
481 break;
482
483 dcbcfg->app[i].priority = up;
484
485
486 selector = (app->upper_oui_sel & ICE_CEE_APP_SELECTOR_M);
487 switch (selector) {
488 case ICE_CEE_APP_SEL_ETHTYPE:
489 dcbcfg->app[i].selector = ICE_APP_SEL_ETHTYPE;
490 break;
491 case ICE_CEE_APP_SEL_TCPIP:
492 dcbcfg->app[i].selector = ICE_APP_SEL_TCPIP;
493 break;
494 default:
495
496 dcbcfg->app[i].selector = selector;
497 }
498
499 dcbcfg->app[i].prot_id = ntohs(app->protocol);
500
501 offset += sizeof(*app);
502 }
503}
504
505
506
507
508
509
510
511
512
513static void
514ice_parse_cee_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
515{
516 struct ice_cee_feat_tlv *sub_tlv;
517 u8 subtype, feat_tlv_count = 0;
518 u16 len, tlvlen, typelen;
519 u32 ouisubtype;
520
521 ouisubtype = ntohl(tlv->ouisubtype);
522 subtype = (u8)((ouisubtype & ICE_LLDP_TLV_SUBTYPE_M) >>
523 ICE_LLDP_TLV_SUBTYPE_S);
524
525 if (subtype != ICE_CEE_DCBX_TYPE)
526 return;
527
528 typelen = ntohs(tlv->typelen);
529 tlvlen = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
530 len = sizeof(tlv->typelen) + sizeof(ouisubtype) +
531 sizeof(struct ice_cee_ctrl_tlv);
532
533 if (tlvlen <= len)
534 return;
535
536 sub_tlv = (struct ice_cee_feat_tlv *)((char *)tlv + len);
537 while (feat_tlv_count < ICE_CEE_MAX_FEAT_TYPE) {
538 u16 sublen;
539
540 typelen = ntohs(sub_tlv->hdr.typelen);
541 sublen = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
542 subtype = (u8)((typelen & ICE_LLDP_TLV_TYPE_M) >>
543 ICE_LLDP_TLV_TYPE_S);
544 switch (subtype) {
545 case ICE_CEE_SUBTYPE_PG_CFG:
546 ice_parse_cee_pgcfg_tlv(sub_tlv, dcbcfg);
547 break;
548 case ICE_CEE_SUBTYPE_PFC_CFG:
549 ice_parse_cee_pfccfg_tlv(sub_tlv, dcbcfg);
550 break;
551 case ICE_CEE_SUBTYPE_APP_PRI:
552 ice_parse_cee_app_tlv(sub_tlv, dcbcfg);
553 break;
554 default:
555 return;
556 }
557 feat_tlv_count++;
558
559 sub_tlv = (struct ice_cee_feat_tlv *)
560 ((char *)sub_tlv + sizeof(sub_tlv->hdr.typelen) +
561 sublen);
562 }
563}
564
565
566
567
568
569
570
571
572
573static void
574ice_parse_org_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
575{
576 u32 ouisubtype;
577 u32 oui;
578
579 ouisubtype = ntohl(tlv->ouisubtype);
580 oui = ((ouisubtype & ICE_LLDP_TLV_OUI_M) >> ICE_LLDP_TLV_OUI_S);
581 switch (oui) {
582 case ICE_IEEE_8021QAZ_OUI:
583 ice_parse_ieee_tlv(tlv, dcbcfg);
584 break;
585 case ICE_CEE_DCBX_OUI:
586 ice_parse_cee_tlv(tlv, dcbcfg);
587 break;
588 default:
589 break;
590 }
591}
592
593
594
595
596
597
598
599
600static enum ice_status
601ice_lldp_to_dcb_cfg(u8 *lldpmib, struct ice_dcbx_cfg *dcbcfg)
602{
603 struct ice_lldp_org_tlv *tlv;
604 enum ice_status ret = 0;
605 u16 offset = 0;
606 u16 typelen;
607 u16 type;
608 u16 len;
609
610 if (!lldpmib || !dcbcfg)
611 return ICE_ERR_PARAM;
612
613
614 lldpmib += ETH_HLEN;
615 tlv = (struct ice_lldp_org_tlv *)lldpmib;
616 while (1) {
617 typelen = ntohs(tlv->typelen);
618 type = ((typelen & ICE_LLDP_TLV_TYPE_M) >> ICE_LLDP_TLV_TYPE_S);
619 len = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
620 offset += sizeof(typelen) + len;
621
622
623 if (type == ICE_TLV_TYPE_END || offset > ICE_LLDPDU_SIZE)
624 break;
625
626 switch (type) {
627 case ICE_TLV_TYPE_ORG:
628 ice_parse_org_tlv(tlv, dcbcfg);
629 break;
630 default:
631 break;
632 }
633
634
635 tlv = (struct ice_lldp_org_tlv *)
636 ((char *)tlv + sizeof(tlv->typelen) + len);
637 }
638
639 return ret;
640}
641
642
643
644
645
646
647
648
649
650
651enum ice_status
652ice_aq_get_dcb_cfg(struct ice_hw *hw, u8 mib_type, u8 bridgetype,
653 struct ice_dcbx_cfg *dcbcfg)
654{
655 enum ice_status ret;
656 u8 *lldpmib;
657
658
659 lldpmib = devm_kzalloc(ice_hw_to_dev(hw), ICE_LLDPDU_SIZE, GFP_KERNEL);
660 if (!lldpmib)
661 return ICE_ERR_NO_MEMORY;
662
663 ret = ice_aq_get_lldp_mib(hw, bridgetype, mib_type, (void *)lldpmib,
664 ICE_LLDPDU_SIZE, NULL, NULL, NULL);
665
666 if (!ret)
667
668 ret = ice_lldp_to_dcb_cfg(lldpmib, dcbcfg);
669
670 devm_kfree(ice_hw_to_dev(hw), lldpmib);
671
672 return ret;
673}
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689enum ice_status
690ice_aq_start_stop_dcbx(struct ice_hw *hw, bool start_dcbx_agent,
691 bool *dcbx_agent_status, struct ice_sq_cd *cd)
692{
693 struct ice_aqc_lldp_stop_start_specific_agent *cmd;
694 enum ice_status status;
695 struct ice_aq_desc desc;
696 u16 opcode;
697
698 cmd = &desc.params.lldp_agent_ctrl;
699
700 opcode = ice_aqc_opc_lldp_stop_start_specific_agent;
701
702 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
703
704 if (start_dcbx_agent)
705 cmd->command = ICE_AQC_START_STOP_AGENT_START_DCBX;
706
707 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
708
709 *dcbx_agent_status = false;
710
711 if (!status &&
712 cmd->command == ICE_AQC_START_STOP_AGENT_START_DCBX)
713 *dcbx_agent_status = true;
714
715 return status;
716}
717
718
719
720
721
722
723
724
725
726static enum ice_status
727ice_aq_get_cee_dcb_cfg(struct ice_hw *hw,
728 struct ice_aqc_get_cee_dcb_cfg_resp *buff,
729 struct ice_sq_cd *cd)
730{
731 struct ice_aq_desc desc;
732
733 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_cee_dcb_cfg);
734
735 return ice_aq_send_cmd(hw, &desc, (void *)buff, sizeof(*buff), cd);
736}
737
738
739
740
741
742
743
744
745static void
746ice_cee_to_dcb_cfg(struct ice_aqc_get_cee_dcb_cfg_resp *cee_cfg,
747 struct ice_port_info *pi)
748{
749 u32 status, tlv_status = le32_to_cpu(cee_cfg->tlv_status);
750 u32 ice_aqc_cee_status_mask, ice_aqc_cee_status_shift, j;
751 u8 i, err, sync, oper, app_index, ice_app_sel_type;
752 u16 app_prio = le16_to_cpu(cee_cfg->oper_app_prio);
753 u16 ice_aqc_cee_app_mask, ice_aqc_cee_app_shift;
754 struct ice_dcbx_cfg *cmp_dcbcfg, *dcbcfg;
755 u16 ice_app_prot_id_type;
756
757 dcbcfg = &pi->qos_cfg.local_dcbx_cfg;
758 dcbcfg->dcbx_mode = ICE_DCBX_MODE_CEE;
759 dcbcfg->tlv_status = tlv_status;
760
761
762 dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
763
764
765
766
767 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS / 2; i++) {
768 dcbcfg->etscfg.prio_table[i * 2] =
769 ((cee_cfg->oper_prio_tc[i] & ICE_CEE_PGID_PRIO_0_M) >>
770 ICE_CEE_PGID_PRIO_0_S);
771 dcbcfg->etscfg.prio_table[i * 2 + 1] =
772 ((cee_cfg->oper_prio_tc[i] & ICE_CEE_PGID_PRIO_1_M) >>
773 ICE_CEE_PGID_PRIO_1_S);
774 }
775
776 ice_for_each_traffic_class(i) {
777 dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
778
779 if (dcbcfg->etscfg.prio_table[i] == ICE_CEE_PGID_STRICT) {
780
781 dcbcfg->etscfg.prio_table[i] = cee_cfg->oper_num_tc - 1;
782 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_STRICT;
783 } else {
784 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_ETS;
785 }
786 }
787
788
789 dcbcfg->pfc.pfcena = cee_cfg->oper_pfc_en;
790 dcbcfg->pfc.pfccap = ICE_MAX_TRAFFIC_CLASS;
791
792
793 if (dcbcfg->app_mode == ICE_DCBX_APPS_NON_WILLING)
794 cmp_dcbcfg = &pi->qos_cfg.desired_dcbx_cfg;
795 else
796 cmp_dcbcfg = &pi->qos_cfg.remote_dcbx_cfg;
797
798 app_index = 0;
799 for (i = 0; i < 3; i++) {
800 if (i == 0) {
801
802 ice_aqc_cee_status_mask = ICE_AQC_CEE_FCOE_STATUS_M;
803 ice_aqc_cee_status_shift = ICE_AQC_CEE_FCOE_STATUS_S;
804 ice_aqc_cee_app_mask = ICE_AQC_CEE_APP_FCOE_M;
805 ice_aqc_cee_app_shift = ICE_AQC_CEE_APP_FCOE_S;
806 ice_app_sel_type = ICE_APP_SEL_ETHTYPE;
807 ice_app_prot_id_type = ETH_P_FCOE;
808 } else if (i == 1) {
809
810 ice_aqc_cee_status_mask = ICE_AQC_CEE_ISCSI_STATUS_M;
811 ice_aqc_cee_status_shift = ICE_AQC_CEE_ISCSI_STATUS_S;
812 ice_aqc_cee_app_mask = ICE_AQC_CEE_APP_ISCSI_M;
813 ice_aqc_cee_app_shift = ICE_AQC_CEE_APP_ISCSI_S;
814 ice_app_sel_type = ICE_APP_SEL_TCPIP;
815 ice_app_prot_id_type = ISCSI_LISTEN_PORT;
816
817 for (j = 0; j < cmp_dcbcfg->numapps; j++) {
818 u16 prot_id = cmp_dcbcfg->app[j].prot_id;
819 u8 sel = cmp_dcbcfg->app[j].selector;
820
821 if (sel == ICE_APP_SEL_TCPIP &&
822 (prot_id == ISCSI_LISTEN_PORT ||
823 prot_id == ICE_APP_PROT_ID_ISCSI_860)) {
824 ice_app_prot_id_type = prot_id;
825 break;
826 }
827 }
828 } else {
829
830 ice_aqc_cee_status_mask = ICE_AQC_CEE_FIP_STATUS_M;
831 ice_aqc_cee_status_shift = ICE_AQC_CEE_FIP_STATUS_S;
832 ice_aqc_cee_app_mask = ICE_AQC_CEE_APP_FIP_M;
833 ice_aqc_cee_app_shift = ICE_AQC_CEE_APP_FIP_S;
834 ice_app_sel_type = ICE_APP_SEL_ETHTYPE;
835 ice_app_prot_id_type = ETH_P_FIP;
836 }
837
838 status = (tlv_status & ice_aqc_cee_status_mask) >>
839 ice_aqc_cee_status_shift;
840 err = (status & ICE_TLV_STATUS_ERR) ? 1 : 0;
841 sync = (status & ICE_TLV_STATUS_SYNC) ? 1 : 0;
842 oper = (status & ICE_TLV_STATUS_OPER) ? 1 : 0;
843
844
845
846 if (!err && sync && oper) {
847 dcbcfg->app[app_index].priority =
848 (app_prio & ice_aqc_cee_app_mask) >>
849 ice_aqc_cee_app_shift;
850 dcbcfg->app[app_index].selector = ice_app_sel_type;
851 dcbcfg->app[app_index].prot_id = ice_app_prot_id_type;
852 app_index++;
853 }
854 }
855
856 dcbcfg->numapps = app_index;
857}
858
859
860
861
862
863
864
865
866static enum ice_status
867ice_get_ieee_or_cee_dcb_cfg(struct ice_port_info *pi, u8 dcbx_mode)
868{
869 struct ice_dcbx_cfg *dcbx_cfg = NULL;
870 enum ice_status ret;
871
872 if (!pi)
873 return ICE_ERR_PARAM;
874
875 if (dcbx_mode == ICE_DCBX_MODE_IEEE)
876 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
877 else if (dcbx_mode == ICE_DCBX_MODE_CEE)
878 dcbx_cfg = &pi->qos_cfg.desired_dcbx_cfg;
879
880
881
882
883 ret = ice_aq_get_dcb_cfg(pi->hw, ICE_AQ_LLDP_MIB_LOCAL,
884 ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID, dcbx_cfg);
885 if (ret)
886 goto out;
887
888
889 dcbx_cfg = &pi->qos_cfg.remote_dcbx_cfg;
890 ret = ice_aq_get_dcb_cfg(pi->hw, ICE_AQ_LLDP_MIB_REMOTE,
891 ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID, dcbx_cfg);
892
893 if (pi->hw->adminq.sq_last_status == ICE_AQ_RC_ENOENT)
894 ret = 0;
895
896out:
897 return ret;
898}
899
900
901
902
903
904
905
906enum ice_status ice_get_dcb_cfg(struct ice_port_info *pi)
907{
908 struct ice_aqc_get_cee_dcb_cfg_resp cee_cfg;
909 struct ice_dcbx_cfg *dcbx_cfg;
910 enum ice_status ret;
911
912 if (!pi)
913 return ICE_ERR_PARAM;
914
915 ret = ice_aq_get_cee_dcb_cfg(pi->hw, &cee_cfg, NULL);
916 if (!ret) {
917
918 ret = ice_get_ieee_or_cee_dcb_cfg(pi, ICE_DCBX_MODE_CEE);
919 ice_cee_to_dcb_cfg(&cee_cfg, pi);
920 } else if (pi->hw->adminq.sq_last_status == ICE_AQ_RC_ENOENT) {
921
922 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
923 dcbx_cfg->dcbx_mode = ICE_DCBX_MODE_IEEE;
924 ret = ice_get_ieee_or_cee_dcb_cfg(pi, ICE_DCBX_MODE_IEEE);
925 }
926
927 return ret;
928}
929
930
931
932
933
934
935
936
937enum ice_status ice_init_dcb(struct ice_hw *hw, bool enable_mib_change)
938{
939 struct ice_qos_cfg *qos_cfg = &hw->port_info->qos_cfg;
940 enum ice_status ret = 0;
941
942 if (!hw->func_caps.common_cap.dcb)
943 return ICE_ERR_NOT_SUPPORTED;
944
945 qos_cfg->is_sw_lldp = true;
946
947
948 qos_cfg->dcbx_status = ice_get_dcbx_status(hw);
949
950 if (qos_cfg->dcbx_status == ICE_DCBX_STATUS_DONE ||
951 qos_cfg->dcbx_status == ICE_DCBX_STATUS_IN_PROGRESS ||
952 qos_cfg->dcbx_status == ICE_DCBX_STATUS_NOT_STARTED) {
953
954 ret = ice_get_dcb_cfg(hw->port_info);
955 if (ret)
956 return ret;
957 qos_cfg->is_sw_lldp = false;
958 } else if (qos_cfg->dcbx_status == ICE_DCBX_STATUS_DIS) {
959 return ICE_ERR_NOT_READY;
960 }
961
962
963 if (enable_mib_change) {
964 ret = ice_aq_cfg_lldp_mib_change(hw, true, NULL);
965 if (ret)
966 qos_cfg->is_sw_lldp = true;
967 }
968
969 return ret;
970}
971
972
973
974
975
976
977
978
979enum ice_status ice_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_mib)
980{
981 struct ice_qos_cfg *qos_cfg = &hw->port_info->qos_cfg;
982 enum ice_status ret;
983
984 if (!hw->func_caps.common_cap.dcb)
985 return ICE_ERR_NOT_SUPPORTED;
986
987
988 qos_cfg->dcbx_status = ice_get_dcbx_status(hw);
989
990 if (qos_cfg->dcbx_status == ICE_DCBX_STATUS_DIS)
991 return ICE_ERR_NOT_READY;
992
993 ret = ice_aq_cfg_lldp_mib_change(hw, ena_mib, NULL);
994 if (!ret)
995 qos_cfg->is_sw_lldp = !ena_mib;
996
997 return ret;
998}
999
1000
1001
1002
1003
1004
1005
1006
1007static void
1008ice_add_ieee_ets_common_tlv(u8 *buf, struct ice_dcb_ets_cfg *ets_cfg)
1009{
1010 u8 priority0, priority1;
1011 u8 offset = 0;
1012 int i;
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS / 2; i++) {
1023 priority0 = ets_cfg->prio_table[i * 2] & 0xF;
1024 priority1 = ets_cfg->prio_table[i * 2 + 1] & 0xF;
1025 buf[offset] = (priority0 << ICE_IEEE_ETS_PRIO_1_S) | priority1;
1026 offset++;
1027 }
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041 ice_for_each_traffic_class(i) {
1042 buf[offset] = ets_cfg->tcbwtable[i];
1043 buf[ICE_MAX_TRAFFIC_CLASS + offset] = ets_cfg->tsatable[i];
1044 offset++;
1045 }
1046}
1047
1048
1049
1050
1051
1052
1053
1054
1055static void
1056ice_add_ieee_ets_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
1057{
1058 struct ice_dcb_ets_cfg *etscfg;
1059 u8 *buf = tlv->tlvinfo;
1060 u8 maxtcwilling = 0;
1061 u32 ouisubtype;
1062 u16 typelen;
1063
1064 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
1065 ICE_IEEE_ETS_TLV_LEN);
1066 tlv->typelen = htons(typelen);
1067
1068 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1069 ICE_IEEE_SUBTYPE_ETS_CFG);
1070 tlv->ouisubtype = htonl(ouisubtype);
1071
1072
1073
1074
1075
1076
1077
1078
1079 etscfg = &dcbcfg->etscfg;
1080 if (etscfg->willing)
1081 maxtcwilling = BIT(ICE_IEEE_ETS_WILLING_S);
1082 maxtcwilling |= etscfg->maxtcs & ICE_IEEE_ETS_MAXTC_M;
1083 buf[0] = maxtcwilling;
1084
1085
1086 ice_add_ieee_ets_common_tlv(&buf[1], etscfg);
1087}
1088
1089
1090
1091
1092
1093
1094
1095
1096static void
1097ice_add_ieee_etsrec_tlv(struct ice_lldp_org_tlv *tlv,
1098 struct ice_dcbx_cfg *dcbcfg)
1099{
1100 struct ice_dcb_ets_cfg *etsrec;
1101 u8 *buf = tlv->tlvinfo;
1102 u32 ouisubtype;
1103 u16 typelen;
1104
1105 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
1106 ICE_IEEE_ETS_TLV_LEN);
1107 tlv->typelen = htons(typelen);
1108
1109 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1110 ICE_IEEE_SUBTYPE_ETS_REC);
1111 tlv->ouisubtype = htonl(ouisubtype);
1112
1113 etsrec = &dcbcfg->etsrec;
1114
1115
1116
1117 ice_add_ieee_ets_common_tlv(&buf[1], etsrec);
1118}
1119
1120
1121
1122
1123
1124
1125
1126
1127static void
1128ice_add_ieee_pfc_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
1129{
1130 u8 *buf = tlv->tlvinfo;
1131 u32 ouisubtype;
1132 u16 typelen;
1133
1134 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
1135 ICE_IEEE_PFC_TLV_LEN);
1136 tlv->typelen = htons(typelen);
1137
1138 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1139 ICE_IEEE_SUBTYPE_PFC_CFG);
1140 tlv->ouisubtype = htonl(ouisubtype);
1141
1142
1143
1144
1145
1146
1147
1148 if (dcbcfg->pfc.willing)
1149 buf[0] = BIT(ICE_IEEE_PFC_WILLING_S);
1150
1151 if (dcbcfg->pfc.mbc)
1152 buf[0] |= BIT(ICE_IEEE_PFC_MBC_S);
1153
1154 buf[0] |= dcbcfg->pfc.pfccap & 0xF;
1155 buf[1] = dcbcfg->pfc.pfcena;
1156}
1157
1158
1159
1160
1161
1162
1163
1164
1165static void
1166ice_add_ieee_app_pri_tlv(struct ice_lldp_org_tlv *tlv,
1167 struct ice_dcbx_cfg *dcbcfg)
1168{
1169 u16 typelen, len, offset = 0;
1170 u8 priority, selector, i = 0;
1171 u8 *buf = tlv->tlvinfo;
1172 u32 ouisubtype;
1173
1174
1175 if (dcbcfg->numapps == 0)
1176 return;
1177 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1178 ICE_IEEE_SUBTYPE_APP_PRI);
1179 tlv->ouisubtype = htonl(ouisubtype);
1180
1181
1182 offset++;
1183
1184
1185
1186
1187
1188
1189
1190
1191 while (i < dcbcfg->numapps) {
1192 priority = dcbcfg->app[i].priority & 0x7;
1193 selector = dcbcfg->app[i].selector & 0x7;
1194 buf[offset] = (priority << ICE_IEEE_APP_PRIO_S) | selector;
1195 buf[offset + 1] = (dcbcfg->app[i].prot_id >> 0x8) & 0xFF;
1196 buf[offset + 2] = dcbcfg->app[i].prot_id & 0xFF;
1197
1198 offset += 3;
1199 i++;
1200 if (i >= ICE_DCBX_MAX_APPS)
1201 break;
1202 }
1203
1204 len = sizeof(tlv->ouisubtype) + 1 + (i * 3);
1205 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) | (len & 0x1FF));
1206 tlv->typelen = htons(typelen);
1207}
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217static void
1218ice_add_dcb_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg,
1219 u16 tlvid)
1220{
1221 switch (tlvid) {
1222 case ICE_IEEE_TLV_ID_ETS_CFG:
1223 ice_add_ieee_ets_tlv(tlv, dcbcfg);
1224 break;
1225 case ICE_IEEE_TLV_ID_ETS_REC:
1226 ice_add_ieee_etsrec_tlv(tlv, dcbcfg);
1227 break;
1228 case ICE_IEEE_TLV_ID_PFC_CFG:
1229 ice_add_ieee_pfc_tlv(tlv, dcbcfg);
1230 break;
1231 case ICE_IEEE_TLV_ID_APP_PRI:
1232 ice_add_ieee_app_pri_tlv(tlv, dcbcfg);
1233 break;
1234 default:
1235 break;
1236 }
1237}
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247static void
1248ice_dcb_cfg_to_lldp(u8 *lldpmib, u16 *miblen, struct ice_dcbx_cfg *dcbcfg)
1249{
1250 u16 len, offset = 0, tlvid = ICE_TLV_ID_START;
1251 struct ice_lldp_org_tlv *tlv;
1252 u16 typelen;
1253
1254 tlv = (struct ice_lldp_org_tlv *)lldpmib;
1255 while (1) {
1256 ice_add_dcb_tlv(tlv, dcbcfg, tlvid++);
1257 typelen = ntohs(tlv->typelen);
1258 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
1259 if (len)
1260 offset += len + 2;
1261
1262 if (tlvid >= ICE_TLV_ID_END_OF_LLDPPDU ||
1263 offset > ICE_LLDPDU_SIZE)
1264 break;
1265
1266 if (len)
1267 tlv = (struct ice_lldp_org_tlv *)
1268 ((char *)tlv + sizeof(tlv->typelen) + len);
1269 }
1270 *miblen = offset;
1271}
1272
1273
1274
1275
1276
1277
1278
1279enum ice_status ice_set_dcb_cfg(struct ice_port_info *pi)
1280{
1281 u8 mib_type, *lldpmib = NULL;
1282 struct ice_dcbx_cfg *dcbcfg;
1283 enum ice_status ret;
1284 struct ice_hw *hw;
1285 u16 miblen;
1286
1287 if (!pi)
1288 return ICE_ERR_PARAM;
1289
1290 hw = pi->hw;
1291
1292
1293 dcbcfg = &pi->qos_cfg.local_dcbx_cfg;
1294
1295 lldpmib = devm_kzalloc(ice_hw_to_dev(hw), ICE_LLDPDU_SIZE, GFP_KERNEL);
1296 if (!lldpmib)
1297 return ICE_ERR_NO_MEMORY;
1298
1299 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB;
1300 if (dcbcfg->app_mode == ICE_DCBX_APPS_NON_WILLING)
1301 mib_type |= SET_LOCAL_MIB_TYPE_CEE_NON_WILLING;
1302
1303 ice_dcb_cfg_to_lldp(lldpmib, &miblen, dcbcfg);
1304 ret = ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, miblen,
1305 NULL);
1306
1307 devm_kfree(ice_hw_to_dev(hw), lldpmib);
1308
1309 return ret;
1310}
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321static enum ice_status
1322ice_aq_query_port_ets(struct ice_port_info *pi,
1323 struct ice_aqc_port_ets_elem *buf, u16 buf_size,
1324 struct ice_sq_cd *cd)
1325{
1326 struct ice_aqc_query_port_ets *cmd;
1327 struct ice_aq_desc desc;
1328 enum ice_status status;
1329
1330 if (!pi)
1331 return ICE_ERR_PARAM;
1332 cmd = &desc.params.port_ets;
1333 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_port_ets);
1334 cmd->port_teid = pi->root->info.node_teid;
1335
1336 status = ice_aq_send_cmd(pi->hw, &desc, buf, buf_size, cd);
1337 return status;
1338}
1339
1340
1341
1342
1343
1344
1345
1346
1347static enum ice_status
1348ice_update_port_tc_tree_cfg(struct ice_port_info *pi,
1349 struct ice_aqc_port_ets_elem *buf)
1350{
1351 struct ice_sched_node *node, *tc_node;
1352 struct ice_aqc_txsched_elem_data elem;
1353 enum ice_status status = 0;
1354 u32 teid1, teid2;
1355 u8 i, j;
1356
1357 if (!pi)
1358 return ICE_ERR_PARAM;
1359
1360 for (i = 0; i < pi->root->num_children; i++) {
1361 teid1 = le32_to_cpu(pi->root->children[i]->info.node_teid);
1362 ice_for_each_traffic_class(j) {
1363 teid2 = le32_to_cpu(buf->tc_node_teid[j]);
1364 if (teid1 == teid2)
1365 break;
1366 }
1367 if (j < ICE_MAX_TRAFFIC_CLASS)
1368 continue;
1369
1370 pi->root->children[i]->in_use = false;
1371 }
1372
1373 ice_for_each_traffic_class(j) {
1374 teid2 = le32_to_cpu(buf->tc_node_teid[j]);
1375 if (teid2 == ICE_INVAL_TEID)
1376 continue;
1377
1378 for (i = 0; i < pi->root->num_children; i++) {
1379 tc_node = pi->root->children[i];
1380 if (!tc_node)
1381 continue;
1382 teid1 = le32_to_cpu(tc_node->info.node_teid);
1383 if (teid1 == teid2) {
1384 tc_node->tc_num = j;
1385 tc_node->in_use = true;
1386 break;
1387 }
1388 }
1389 if (i < pi->root->num_children)
1390 continue;
1391
1392 status = ice_sched_query_elem(pi->hw, teid2, &elem);
1393 if (!status)
1394 status = ice_sched_add_node(pi, 1, &elem);
1395 if (status)
1396 break;
1397
1398 node = ice_sched_find_node_by_teid(pi->root, teid2);
1399 if (node)
1400 node->tc_num = j;
1401 }
1402 return status;
1403}
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415enum ice_status
1416ice_query_port_ets(struct ice_port_info *pi,
1417 struct ice_aqc_port_ets_elem *buf, u16 buf_size,
1418 struct ice_sq_cd *cd)
1419{
1420 enum ice_status status;
1421
1422 mutex_lock(&pi->sched_lock);
1423 status = ice_aq_query_port_ets(pi, buf, buf_size, cd);
1424 if (!status)
1425 status = ice_update_port_tc_tree_cfg(pi, buf);
1426 mutex_unlock(&pi->sched_lock);
1427 return status;
1428}
1429