1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2017 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
27 #include "i40e_adminq.h"
28 #include "i40e_prototype.h"
32 * i40e_get_dcbx_status
33 * @hw: pointer to the hw struct
34 * @status: Embedded DCBX Engine Status
36 * Get the DCBX status from the Firmware
38 i40e_status i40e_get_dcbx_status(struct i40e_hw *hw, u16 *status)
43 return I40E_ERR_PARAM;
45 reg = rd32(hw, I40E_PRTDCB_GENS);
46 *status = (u16)((reg & I40E_PRTDCB_GENS_DCBX_STATUS_MASK) >>
47 I40E_PRTDCB_GENS_DCBX_STATUS_SHIFT);
53 * i40e_parse_ieee_etscfg_tlv
54 * @tlv: IEEE 802.1Qaz ETS CFG TLV
55 * @dcbcfg: Local store to update ETS CFG data
57 * Parses IEEE 802.1Qaz ETS CFG TLV
59 static void i40e_parse_ieee_etscfg_tlv(struct i40e_lldp_org_tlv *tlv,
60 struct i40e_dcbx_config *dcbcfg)
62 struct i40e_dcb_ets_config *etscfg;
63 u8 *buf = tlv->tlvinfo;
68 /* First Octet post subtype
69 * --------------------------
70 * |will-|CBS | Re- | Max |
71 * |ing | |served| TCs |
72 * --------------------------
73 * |1bit | 1bit|3 bits|3bits|
75 etscfg = &dcbcfg->etscfg;
76 etscfg->willing = (u8)((buf[offset] & I40E_IEEE_ETS_WILLING_MASK) >>
77 I40E_IEEE_ETS_WILLING_SHIFT);
78 etscfg->cbs = (u8)((buf[offset] & I40E_IEEE_ETS_CBS_MASK) >>
79 I40E_IEEE_ETS_CBS_SHIFT);
80 etscfg->maxtcs = (u8)((buf[offset] & I40E_IEEE_ETS_MAXTC_MASK) >>
81 I40E_IEEE_ETS_MAXTC_SHIFT);
83 /* Move offset to Priority Assignment Table */
86 /* Priority Assignment Table (4 octets)
87 * Octets:| 1 | 2 | 3 | 4 |
88 * -----------------------------------------
89 * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
90 * -----------------------------------------
91 * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
92 * -----------------------------------------
94 for (i = 0; i < 4; i++) {
95 priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_1_MASK) >>
96 I40E_IEEE_ETS_PRIO_1_SHIFT);
97 etscfg->prioritytable[i * 2] = priority;
98 priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_0_MASK) >>
99 I40E_IEEE_ETS_PRIO_0_SHIFT);
100 etscfg->prioritytable[i * 2 + 1] = priority;
104 /* TC Bandwidth Table (8 octets)
105 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
106 * ---------------------------------
107 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
108 * ---------------------------------
110 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
111 etscfg->tcbwtable[i] = buf[offset++];
113 /* TSA Assignment Table (8 octets)
114 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
115 * ---------------------------------
116 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
117 * ---------------------------------
119 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
120 etscfg->tsatable[i] = buf[offset++];
124 * i40e_parse_ieee_etsrec_tlv
125 * @tlv: IEEE 802.1Qaz ETS REC TLV
126 * @dcbcfg: Local store to update ETS REC data
128 * Parses IEEE 802.1Qaz ETS REC TLV
130 static void i40e_parse_ieee_etsrec_tlv(struct i40e_lldp_org_tlv *tlv,
131 struct i40e_dcbx_config *dcbcfg)
133 u8 *buf = tlv->tlvinfo;
138 /* Move offset to priority table */
141 /* Priority Assignment Table (4 octets)
142 * Octets:| 1 | 2 | 3 | 4 |
143 * -----------------------------------------
144 * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
145 * -----------------------------------------
146 * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
147 * -----------------------------------------
149 for (i = 0; i < 4; i++) {
150 priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_1_MASK) >>
151 I40E_IEEE_ETS_PRIO_1_SHIFT);
152 dcbcfg->etsrec.prioritytable[i*2] = priority;
153 priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_0_MASK) >>
154 I40E_IEEE_ETS_PRIO_0_SHIFT);
155 dcbcfg->etsrec.prioritytable[i*2 + 1] = priority;
159 /* TC Bandwidth Table (8 octets)
160 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
161 * ---------------------------------
162 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
163 * ---------------------------------
165 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
166 dcbcfg->etsrec.tcbwtable[i] = buf[offset++];
168 /* TSA Assignment Table (8 octets)
169 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
170 * ---------------------------------
171 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
172 * ---------------------------------
174 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
175 dcbcfg->etsrec.tsatable[i] = buf[offset++];
179 * i40e_parse_ieee_pfccfg_tlv
180 * @tlv: IEEE 802.1Qaz PFC CFG TLV
181 * @dcbcfg: Local store to update PFC CFG data
183 * Parses IEEE 802.1Qaz PFC CFG TLV
185 static void i40e_parse_ieee_pfccfg_tlv(struct i40e_lldp_org_tlv *tlv,
186 struct i40e_dcbx_config *dcbcfg)
188 u8 *buf = tlv->tlvinfo;
190 /* ----------------------------------------
191 * |will-|MBC | Re- | PFC | PFC Enable |
192 * |ing | |served| cap | |
193 * -----------------------------------------
194 * |1bit | 1bit|2 bits|4bits| 1 octet |
196 dcbcfg->pfc.willing = (u8)((buf[0] & I40E_IEEE_PFC_WILLING_MASK) >>
197 I40E_IEEE_PFC_WILLING_SHIFT);
198 dcbcfg->pfc.mbc = (u8)((buf[0] & I40E_IEEE_PFC_MBC_MASK) >>
199 I40E_IEEE_PFC_MBC_SHIFT);
200 dcbcfg->pfc.pfccap = (u8)((buf[0] & I40E_IEEE_PFC_CAP_MASK) >>
201 I40E_IEEE_PFC_CAP_SHIFT);
202 dcbcfg->pfc.pfcenable = buf[1];
206 * i40e_parse_ieee_app_tlv
207 * @tlv: IEEE 802.1Qaz APP TLV
208 * @dcbcfg: Local store to update APP PRIO data
210 * Parses IEEE 802.1Qaz APP PRIO TLV
212 static void i40e_parse_ieee_app_tlv(struct i40e_lldp_org_tlv *tlv,
213 struct i40e_dcbx_config *dcbcfg)
221 typelength = ntohs(tlv->typelength);
222 length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
223 I40E_LLDP_TLV_LEN_SHIFT);
226 /* The App priority table starts 5 octets after TLV header */
227 length -= (sizeof(tlv->ouisubtype) + 1);
229 /* Move offset to App Priority Table */
232 /* Application Priority Table (3 octets)
233 * Octets:| 1 | 2 | 3 |
234 * -----------------------------------------
235 * |Priority|Rsrvd| Sel | Protocol ID |
236 * -----------------------------------------
237 * Bits:|23 21|20 19|18 16|15 0|
238 * -----------------------------------------
240 while (offset < length) {
241 dcbcfg->app[i].priority = (u8)((buf[offset] &
242 I40E_IEEE_APP_PRIO_MASK) >>
243 I40E_IEEE_APP_PRIO_SHIFT);
244 dcbcfg->app[i].selector = (u8)((buf[offset] &
245 I40E_IEEE_APP_SEL_MASK) >>
246 I40E_IEEE_APP_SEL_SHIFT);
247 dcbcfg->app[i].protocolid = (buf[offset + 1] << 0x8) |
249 /* Move to next app */
252 if (i >= I40E_DCBX_MAX_APPS)
260 * i40e_parse_ieee_etsrec_tlv
261 * @tlv: IEEE 802.1Qaz TLV
262 * @dcbcfg: Local store to update ETS REC data
264 * Get the TLV subtype and send it to parsing function
265 * based on the subtype value
267 static void i40e_parse_ieee_tlv(struct i40e_lldp_org_tlv *tlv,
268 struct i40e_dcbx_config *dcbcfg)
273 ouisubtype = ntohl(tlv->ouisubtype);
274 subtype = (u8)((ouisubtype & I40E_LLDP_TLV_SUBTYPE_MASK) >>
275 I40E_LLDP_TLV_SUBTYPE_SHIFT);
277 case I40E_IEEE_SUBTYPE_ETS_CFG:
278 i40e_parse_ieee_etscfg_tlv(tlv, dcbcfg);
280 case I40E_IEEE_SUBTYPE_ETS_REC:
281 i40e_parse_ieee_etsrec_tlv(tlv, dcbcfg);
283 case I40E_IEEE_SUBTYPE_PFC_CFG:
284 i40e_parse_ieee_pfccfg_tlv(tlv, dcbcfg);
286 case I40E_IEEE_SUBTYPE_APP_PRI:
287 i40e_parse_ieee_app_tlv(tlv, dcbcfg);
295 * i40e_parse_cee_pgcfg_tlv
296 * @tlv: CEE DCBX PG CFG TLV
297 * @dcbcfg: Local store to update ETS CFG data
299 * Parses CEE DCBX PG CFG TLV
301 static void i40e_parse_cee_pgcfg_tlv(struct i40e_cee_feat_tlv *tlv,
302 struct i40e_dcbx_config *dcbcfg)
304 struct i40e_dcb_ets_config *etscfg;
305 u8 *buf = tlv->tlvinfo;
310 etscfg = &dcbcfg->etscfg;
312 if (tlv->en_will_err & I40E_CEE_FEAT_TLV_WILLING_MASK)
316 /* Priority Group Table (4 octets)
317 * Octets:| 1 | 2 | 3 | 4 |
318 * -----------------------------------------
319 * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
320 * -----------------------------------------
321 * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
322 * -----------------------------------------
324 for (i = 0; i < 4; i++) {
325 priority = (u8)((buf[offset] & I40E_CEE_PGID_PRIO_1_MASK) >>
326 I40E_CEE_PGID_PRIO_1_SHIFT);
327 etscfg->prioritytable[i * 2] = priority;
328 priority = (u8)((buf[offset] & I40E_CEE_PGID_PRIO_0_MASK) >>
329 I40E_CEE_PGID_PRIO_0_SHIFT);
330 etscfg->prioritytable[i * 2 + 1] = priority;
334 /* PG Percentage Table (8 octets)
335 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
336 * ---------------------------------
337 * |pg0|pg1|pg2|pg3|pg4|pg5|pg6|pg7|
338 * ---------------------------------
340 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
341 etscfg->tcbwtable[i] = buf[offset++];
343 /* Number of TCs supported (1 octet) */
344 etscfg->maxtcs = buf[offset];
348 * i40e_parse_cee_pfccfg_tlv
349 * @tlv: CEE DCBX PFC CFG TLV
350 * @dcbcfg: Local store to update PFC CFG data
352 * Parses CEE DCBX PFC CFG TLV
354 static void i40e_parse_cee_pfccfg_tlv(struct i40e_cee_feat_tlv *tlv,
355 struct i40e_dcbx_config *dcbcfg)
357 u8 *buf = tlv->tlvinfo;
359 if (tlv->en_will_err & I40E_CEE_FEAT_TLV_WILLING_MASK)
360 dcbcfg->pfc.willing = 1;
362 /* ------------------------
363 * | PFC Enable | PFC TCs |
364 * ------------------------
365 * | 1 octet | 1 octet |
367 dcbcfg->pfc.pfcenable = buf[0];
368 dcbcfg->pfc.pfccap = buf[1];
372 * i40e_parse_cee_app_tlv
373 * @tlv: CEE DCBX APP TLV
374 * @dcbcfg: Local store to update APP PRIO data
376 * Parses CEE DCBX APP PRIO TLV
378 static void i40e_parse_cee_app_tlv(struct i40e_cee_feat_tlv *tlv,
379 struct i40e_dcbx_config *dcbcfg)
381 u16 length, typelength, offset = 0;
382 struct i40e_cee_app_prio *app;
385 typelength = ntohs(tlv->hdr.typelen);
386 length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
387 I40E_LLDP_TLV_LEN_SHIFT);
389 dcbcfg->numapps = length / sizeof(*app);
391 if (!dcbcfg->numapps)
393 if (dcbcfg->numapps > I40E_DCBX_MAX_APPS)
394 dcbcfg->numapps = I40E_DCBX_MAX_APPS;
396 for (i = 0; i < dcbcfg->numapps; i++) {
399 app = (struct i40e_cee_app_prio *)(tlv->tlvinfo + offset);
400 for (up = 0; up < I40E_MAX_USER_PRIORITY; up++) {
401 if (app->prio_map & BIT(up))
404 dcbcfg->app[i].priority = up;
406 /* Get Selector from lower 2 bits, and convert to IEEE */
407 selector = (app->upper_oui_sel & I40E_CEE_APP_SELECTOR_MASK);
409 case I40E_CEE_APP_SEL_ETHTYPE:
410 dcbcfg->app[i].selector = I40E_APP_SEL_ETHTYPE;
412 case I40E_CEE_APP_SEL_TCPIP:
413 dcbcfg->app[i].selector = I40E_APP_SEL_TCPIP;
416 /* Keep selector as it is for unknown types */
417 dcbcfg->app[i].selector = selector;
420 dcbcfg->app[i].protocolid = ntohs(app->protocol);
421 /* Move to next app */
422 offset += sizeof(*app);
429 * @dcbcfg: Local store to update DCBX config data
431 * Get the TLV subtype and send it to parsing function
432 * based on the subtype value
434 static void i40e_parse_cee_tlv(struct i40e_lldp_org_tlv *tlv,
435 struct i40e_dcbx_config *dcbcfg)
437 u16 len, tlvlen, sublen, typelength;
438 struct i40e_cee_feat_tlv *sub_tlv;
439 u8 subtype, feat_tlv_count = 0;
442 ouisubtype = ntohl(tlv->ouisubtype);
443 subtype = (u8)((ouisubtype & I40E_LLDP_TLV_SUBTYPE_MASK) >>
444 I40E_LLDP_TLV_SUBTYPE_SHIFT);
445 /* Return if not CEE DCBX */
446 if (subtype != I40E_CEE_DCBX_TYPE)
449 typelength = ntohs(tlv->typelength);
450 tlvlen = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
451 I40E_LLDP_TLV_LEN_SHIFT);
452 len = sizeof(tlv->typelength) + sizeof(ouisubtype) +
453 sizeof(struct i40e_cee_ctrl_tlv);
454 /* Return if no CEE DCBX Feature TLVs */
458 sub_tlv = (struct i40e_cee_feat_tlv *)((char *)tlv + len);
459 while (feat_tlv_count < I40E_CEE_MAX_FEAT_TYPE) {
460 typelength = ntohs(sub_tlv->hdr.typelen);
461 sublen = (u16)((typelength &
462 I40E_LLDP_TLV_LEN_MASK) >>
463 I40E_LLDP_TLV_LEN_SHIFT);
464 subtype = (u8)((typelength & I40E_LLDP_TLV_TYPE_MASK) >>
465 I40E_LLDP_TLV_TYPE_SHIFT);
467 case I40E_CEE_SUBTYPE_PG_CFG:
468 i40e_parse_cee_pgcfg_tlv(sub_tlv, dcbcfg);
470 case I40E_CEE_SUBTYPE_PFC_CFG:
471 i40e_parse_cee_pfccfg_tlv(sub_tlv, dcbcfg);
473 case I40E_CEE_SUBTYPE_APP_PRI:
474 i40e_parse_cee_app_tlv(sub_tlv, dcbcfg);
477 return; /* Invalid Sub-type return */
480 /* Move to next sub TLV */
481 sub_tlv = (struct i40e_cee_feat_tlv *)((char *)sub_tlv +
482 sizeof(sub_tlv->hdr.typelen) +
489 * @tlv: Organization specific TLV
490 * @dcbcfg: Local store to update ETS REC data
492 * Currently only IEEE 802.1Qaz TLV is supported, all others
495 static void i40e_parse_org_tlv(struct i40e_lldp_org_tlv *tlv,
496 struct i40e_dcbx_config *dcbcfg)
501 ouisubtype = ntohl(tlv->ouisubtype);
502 oui = (u32)((ouisubtype & I40E_LLDP_TLV_OUI_MASK) >>
503 I40E_LLDP_TLV_OUI_SHIFT);
505 case I40E_IEEE_8021QAZ_OUI:
506 i40e_parse_ieee_tlv(tlv, dcbcfg);
508 case I40E_CEE_DCBX_OUI:
509 i40e_parse_cee_tlv(tlv, dcbcfg);
517 * i40e_lldp_to_dcb_config
518 * @lldpmib: LLDPDU to be parsed
519 * @dcbcfg: store for LLDPDU data
521 * Parse DCB configuration from the LLDPDU
523 i40e_status i40e_lldp_to_dcb_config(u8 *lldpmib,
524 struct i40e_dcbx_config *dcbcfg)
527 struct i40e_lldp_org_tlv *tlv;
533 if (!lldpmib || !dcbcfg)
534 return I40E_ERR_PARAM;
536 /* set to the start of LLDPDU */
538 tlv = (struct i40e_lldp_org_tlv *)lldpmib;
540 typelength = ntohs(tlv->typelength);
541 type = (u16)((typelength & I40E_LLDP_TLV_TYPE_MASK) >>
542 I40E_LLDP_TLV_TYPE_SHIFT);
543 length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
544 I40E_LLDP_TLV_LEN_SHIFT);
545 offset += sizeof(typelength) + length;
547 /* END TLV or beyond LLDPDU size */
548 if ((type == I40E_TLV_TYPE_END) || (offset > I40E_LLDPDU_SIZE))
552 case I40E_TLV_TYPE_ORG:
553 i40e_parse_org_tlv(tlv, dcbcfg);
559 /* Move to next TLV */
560 tlv = (struct i40e_lldp_org_tlv *)((char *)tlv +
561 sizeof(tlv->typelength) +
569 * i40e_aq_get_dcb_config
570 * @hw: pointer to the hw struct
571 * @mib_type: mib type for the query
572 * @bridgetype: bridge type for the query (remote)
573 * @dcbcfg: store for LLDPDU data
575 * Query DCB configuration from the Firmware
577 i40e_status i40e_aq_get_dcb_config(struct i40e_hw *hw, u8 mib_type,
579 struct i40e_dcbx_config *dcbcfg)
582 struct i40e_virt_mem mem;
585 /* Allocate the LLDPDU */
586 ret = i40e_allocate_virt_mem(hw, &mem, I40E_LLDPDU_SIZE);
590 lldpmib = (u8 *)mem.va;
591 ret = i40e_aq_get_lldp_mib(hw, bridgetype, mib_type,
592 (void *)lldpmib, I40E_LLDPDU_SIZE,
597 /* Parse LLDP MIB to get dcb configuration */
598 ret = i40e_lldp_to_dcb_config(lldpmib, dcbcfg);
601 i40e_free_virt_mem(hw, &mem);
606 * i40e_cee_to_dcb_v1_config
607 * @cee_cfg: pointer to CEE v1 response configuration struct
608 * @dcbcfg: DCB configuration struct
610 * Convert CEE v1 configuration from firmware to DCB configuration
612 static void i40e_cee_to_dcb_v1_config(
613 struct i40e_aqc_get_cee_dcb_cfg_v1_resp *cee_cfg,
614 struct i40e_dcbx_config *dcbcfg)
616 u16 status, tlv_status = le16_to_cpu(cee_cfg->tlv_status);
617 u16 app_prio = le16_to_cpu(cee_cfg->oper_app_prio);
620 /* CEE PG data to ETS config */
621 dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
623 /* Note that the FW creates the oper_prio_tc nibbles reversed
624 * from those in the CEE Priority Group sub-TLV.
626 for (i = 0; i < 4; i++) {
627 tc = (u8)((cee_cfg->oper_prio_tc[i] &
628 I40E_CEE_PGID_PRIO_0_MASK) >>
629 I40E_CEE_PGID_PRIO_0_SHIFT);
630 dcbcfg->etscfg.prioritytable[i * 2] = tc;
631 tc = (u8)((cee_cfg->oper_prio_tc[i] &
632 I40E_CEE_PGID_PRIO_1_MASK) >>
633 I40E_CEE_PGID_PRIO_1_SHIFT);
634 dcbcfg->etscfg.prioritytable[i*2 + 1] = tc;
637 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
638 dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
640 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
641 if (dcbcfg->etscfg.prioritytable[i] == I40E_CEE_PGID_STRICT) {
642 /* Map it to next empty TC */
643 dcbcfg->etscfg.prioritytable[i] =
644 cee_cfg->oper_num_tc - 1;
645 dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_STRICT;
647 dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
651 /* CEE PFC data to ETS config */
652 dcbcfg->pfc.pfcenable = cee_cfg->oper_pfc_en;
653 dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
655 status = (tlv_status & I40E_AQC_CEE_APP_STATUS_MASK) >>
656 I40E_AQC_CEE_APP_STATUS_SHIFT;
657 err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
658 /* Add APPs if Error is False */
660 /* CEE operating configuration supports FCoE/iSCSI/FIP only */
661 dcbcfg->numapps = I40E_CEE_OPER_MAX_APPS;
664 dcbcfg->app[0].priority =
665 (app_prio & I40E_AQC_CEE_APP_FCOE_MASK) >>
666 I40E_AQC_CEE_APP_FCOE_SHIFT;
667 dcbcfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
668 dcbcfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
671 dcbcfg->app[1].priority =
672 (app_prio & I40E_AQC_CEE_APP_ISCSI_MASK) >>
673 I40E_AQC_CEE_APP_ISCSI_SHIFT;
674 dcbcfg->app[1].selector = I40E_APP_SEL_TCPIP;
675 dcbcfg->app[1].protocolid = I40E_APP_PROTOID_ISCSI;
678 dcbcfg->app[2].priority =
679 (app_prio & I40E_AQC_CEE_APP_FIP_MASK) >>
680 I40E_AQC_CEE_APP_FIP_SHIFT;
681 dcbcfg->app[2].selector = I40E_APP_SEL_ETHTYPE;
682 dcbcfg->app[2].protocolid = I40E_APP_PROTOID_FIP;
687 * i40e_cee_to_dcb_config
688 * @cee_cfg: pointer to CEE configuration struct
689 * @dcbcfg: DCB configuration struct
691 * Convert CEE configuration from firmware to DCB configuration
693 static void i40e_cee_to_dcb_config(
694 struct i40e_aqc_get_cee_dcb_cfg_resp *cee_cfg,
695 struct i40e_dcbx_config *dcbcfg)
697 u32 status, tlv_status = le32_to_cpu(cee_cfg->tlv_status);
698 u16 app_prio = le16_to_cpu(cee_cfg->oper_app_prio);
699 u8 i, tc, err, sync, oper;
701 /* CEE PG data to ETS config */
702 dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
704 /* Note that the FW creates the oper_prio_tc nibbles reversed
705 * from those in the CEE Priority Group sub-TLV.
707 for (i = 0; i < 4; i++) {
708 tc = (u8)((cee_cfg->oper_prio_tc[i] &
709 I40E_CEE_PGID_PRIO_0_MASK) >>
710 I40E_CEE_PGID_PRIO_0_SHIFT);
711 dcbcfg->etscfg.prioritytable[i * 2] = tc;
712 tc = (u8)((cee_cfg->oper_prio_tc[i] &
713 I40E_CEE_PGID_PRIO_1_MASK) >>
714 I40E_CEE_PGID_PRIO_1_SHIFT);
715 dcbcfg->etscfg.prioritytable[i * 2 + 1] = tc;
718 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
719 dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
721 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
722 if (dcbcfg->etscfg.prioritytable[i] == I40E_CEE_PGID_STRICT) {
723 /* Map it to next empty TC */
724 dcbcfg->etscfg.prioritytable[i] =
725 cee_cfg->oper_num_tc - 1;
726 dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_STRICT;
728 dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
732 /* CEE PFC data to ETS config */
733 dcbcfg->pfc.pfcenable = cee_cfg->oper_pfc_en;
734 dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
737 status = (tlv_status & I40E_AQC_CEE_FCOE_STATUS_MASK) >>
738 I40E_AQC_CEE_FCOE_STATUS_SHIFT;
739 err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
740 sync = (status & I40E_TLV_STATUS_SYNC) ? 1 : 0;
741 oper = (status & I40E_TLV_STATUS_OPER) ? 1 : 0;
742 /* Add FCoE APP if Error is False and Oper/Sync is True */
743 if (!err && sync && oper) {
745 dcbcfg->app[i].priority =
746 (app_prio & I40E_AQC_CEE_APP_FCOE_MASK) >>
747 I40E_AQC_CEE_APP_FCOE_SHIFT;
748 dcbcfg->app[i].selector = I40E_APP_SEL_ETHTYPE;
749 dcbcfg->app[i].protocolid = I40E_APP_PROTOID_FCOE;
753 status = (tlv_status & I40E_AQC_CEE_ISCSI_STATUS_MASK) >>
754 I40E_AQC_CEE_ISCSI_STATUS_SHIFT;
755 err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
756 sync = (status & I40E_TLV_STATUS_SYNC) ? 1 : 0;
757 oper = (status & I40E_TLV_STATUS_OPER) ? 1 : 0;
758 /* Add iSCSI APP if Error is False and Oper/Sync is True */
759 if (!err && sync && oper) {
761 dcbcfg->app[i].priority =
762 (app_prio & I40E_AQC_CEE_APP_ISCSI_MASK) >>
763 I40E_AQC_CEE_APP_ISCSI_SHIFT;
764 dcbcfg->app[i].selector = I40E_APP_SEL_TCPIP;
765 dcbcfg->app[i].protocolid = I40E_APP_PROTOID_ISCSI;
769 status = (tlv_status & I40E_AQC_CEE_FIP_STATUS_MASK) >>
770 I40E_AQC_CEE_FIP_STATUS_SHIFT;
771 err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
772 sync = (status & I40E_TLV_STATUS_SYNC) ? 1 : 0;
773 oper = (status & I40E_TLV_STATUS_OPER) ? 1 : 0;
774 /* Add FIP APP if Error is False and Oper/Sync is True */
775 if (!err && sync && oper) {
777 dcbcfg->app[i].priority =
778 (app_prio & I40E_AQC_CEE_APP_FIP_MASK) >>
779 I40E_AQC_CEE_APP_FIP_SHIFT;
780 dcbcfg->app[i].selector = I40E_APP_SEL_ETHTYPE;
781 dcbcfg->app[i].protocolid = I40E_APP_PROTOID_FIP;
788 * i40e_get_ieee_dcb_config
789 * @hw: pointer to the hw struct
791 * Get IEEE mode DCB configuration from the Firmware
793 static i40e_status i40e_get_ieee_dcb_config(struct i40e_hw *hw)
798 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
799 /* Get Local DCB Config */
800 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
801 &hw->local_dcbx_config);
805 /* Get Remote DCB Config */
806 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
807 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
808 &hw->remote_dcbx_config);
809 /* Don't treat ENOENT as an error for Remote MIBs */
810 if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
818 * i40e_get_dcb_config
819 * @hw: pointer to the hw struct
821 * Get DCB configuration from the Firmware
823 i40e_status i40e_get_dcb_config(struct i40e_hw *hw)
826 struct i40e_aqc_get_cee_dcb_cfg_resp cee_cfg;
827 struct i40e_aqc_get_cee_dcb_cfg_v1_resp cee_v1_cfg;
829 /* If Firmware version < v4.33 on X710/XL710, IEEE only */
830 if ((hw->mac.type == I40E_MAC_XL710) &&
831 (((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver < 33)) ||
832 (hw->aq.fw_maj_ver < 4)))
833 return i40e_get_ieee_dcb_config(hw);
835 /* If Firmware version == v4.33 on X710/XL710, use old CEE struct */
836 if ((hw->mac.type == I40E_MAC_XL710) &&
837 ((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver == 33))) {
838 ret = i40e_aq_get_cee_dcb_config(hw, &cee_v1_cfg,
839 sizeof(cee_v1_cfg), NULL);
842 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_CEE;
843 hw->local_dcbx_config.tlv_status =
844 le16_to_cpu(cee_v1_cfg.tlv_status);
845 i40e_cee_to_dcb_v1_config(&cee_v1_cfg,
846 &hw->local_dcbx_config);
849 ret = i40e_aq_get_cee_dcb_config(hw, &cee_cfg,
850 sizeof(cee_cfg), NULL);
853 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_CEE;
854 hw->local_dcbx_config.tlv_status =
855 le32_to_cpu(cee_cfg.tlv_status);
856 i40e_cee_to_dcb_config(&cee_cfg,
857 &hw->local_dcbx_config);
861 /* CEE mode not enabled try querying IEEE data */
862 if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
863 return i40e_get_ieee_dcb_config(hw);
868 /* Get CEE DCB Desired Config */
869 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
870 &hw->desired_dcbx_config);
874 /* Get Remote DCB Config */
875 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
876 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
877 &hw->remote_dcbx_config);
878 /* Don't treat ENOENT as an error for Remote MIBs */
879 if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
888 * @hw: pointer to the hw struct
890 * Update DCB configuration from the Firmware
892 i40e_status i40e_init_dcb(struct i40e_hw *hw)
895 struct i40e_lldp_variables lldp_cfg;
898 if (!hw->func_caps.dcb)
901 /* Read LLDP NVM area */
902 ret = i40e_read_lldp_cfg(hw, &lldp_cfg);
906 /* Get the LLDP AdminStatus for the current port */
907 adminstatus = lldp_cfg.adminstatus >> (hw->port * 4);
910 /* LLDP agent disabled */
912 hw->dcbx_status = I40E_DCBX_STATUS_DISABLED;
916 /* Get DCBX status */
917 ret = i40e_get_dcbx_status(hw, &hw->dcbx_status);
921 /* Check the DCBX Status */
922 switch (hw->dcbx_status) {
923 case I40E_DCBX_STATUS_DONE:
924 case I40E_DCBX_STATUS_IN_PROGRESS:
925 /* Get current DCBX configuration */
926 ret = i40e_get_dcb_config(hw);
930 case I40E_DCBX_STATUS_DISABLED:
932 case I40E_DCBX_STATUS_NOT_STARTED:
933 case I40E_DCBX_STATUS_MULTIPLE_PEERS:
938 /* Configure the LLDP MIB change event */
939 ret = i40e_aq_cfg_lldp_mib_change_event(hw, true, NULL);
947 * i40e_read_lldp_cfg - read LLDP Configuration data from NVM
948 * @hw: pointer to the HW structure
949 * @lldp_cfg: pointer to hold lldp configuration variables
951 * Reads the LLDP configuration data from NVM
953 i40e_status i40e_read_lldp_cfg(struct i40e_hw *hw,
954 struct i40e_lldp_variables *lldp_cfg)
957 u32 offset = (2 * I40E_NVM_LLDP_CFG_PTR);
960 return I40E_ERR_PARAM;
962 ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
966 ret = i40e_aq_read_nvm(hw, I40E_SR_EMP_MODULE_PTR, offset,
967 sizeof(struct i40e_lldp_variables),
970 i40e_release_nvm(hw);