1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2021, Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Intel Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 #include "ice_common.h"
34 #include "ice_sched.h"
39 * @hw: pointer to the HW struct
40 * @bridge_type: type of bridge requested
41 * @mib_type: Local, Remote or both Local and Remote MIBs
42 * @buf: pointer to the caller-supplied buffer to store the MIB block
43 * @buf_size: size of the buffer (in bytes)
44 * @local_len: length of the returned Local LLDP MIB
45 * @remote_len: length of the returned Remote LLDP MIB
46 * @cd: pointer to command details structure or NULL
48 * Requests the complete LLDP MIB (entire packet). (0x0A00)
51 ice_aq_get_lldp_mib(struct ice_hw *hw, u8 bridge_type, u8 mib_type, void *buf,
52 u16 buf_size, u16 *local_len, u16 *remote_len,
55 struct ice_aqc_lldp_get_mib *cmd;
56 struct ice_aq_desc desc;
57 enum ice_status status;
59 cmd = &desc.params.lldp_get_mib;
61 if (buf_size == 0 || !buf)
64 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_get_mib);
66 cmd->type = mib_type & ICE_AQ_LLDP_MIB_TYPE_M;
67 cmd->type |= (bridge_type << ICE_AQ_LLDP_BRID_TYPE_S) &
68 ICE_AQ_LLDP_BRID_TYPE_M;
70 desc.datalen = CPU_TO_LE16(buf_size);
72 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
75 *local_len = LE16_TO_CPU(cmd->local_len);
77 *remote_len = LE16_TO_CPU(cmd->remote_len);
84 * ice_aq_cfg_lldp_mib_change
85 * @hw: pointer to the HW struct
86 * @ena_update: Enable or Disable event posting
87 * @cd: pointer to command details structure or NULL
89 * Enable or Disable posting of an event on ARQ when LLDP MIB
90 * associated with the interface changes (0x0A01)
93 ice_aq_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_update,
96 struct ice_aqc_lldp_set_mib_change *cmd;
97 struct ice_aq_desc desc;
99 cmd = &desc.params.lldp_set_event;
101 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_set_mib_change);
104 cmd->command |= ICE_AQ_LLDP_MIB_UPDATE_DIS;
106 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
110 * ice_aq_add_delete_lldp_tlv
111 * @hw: pointer to the HW struct
112 * @bridge_type: type of bridge
113 * @add_lldp_tlv: add (true) or delete (false) TLV
114 * @buf: buffer with TLV to add or delete
115 * @buf_size: length of the buffer
116 * @tlv_len: length of the TLV to be added/deleted
117 * @mib_len: length of the LLDP MIB returned in response
118 * @cd: pointer to command details structure or NULL
121 * Add the specified TLV to LLDP Local MIB for the given bridge type,
122 * it is responsibility of the caller to make sure that the TLV is not
123 * already present in the LLDPDU.
124 * In return firmware will write the complete LLDP MIB with the newly
125 * added TLV in the response buffer. (0x0A02)
128 * Delete the specified TLV from LLDP Local MIB for the given bridge type.
129 * The firmware places the entire LLDP MIB in the response buffer. (0x0A04)
132 ice_aq_add_delete_lldp_tlv(struct ice_hw *hw, u8 bridge_type, bool add_lldp_tlv,
133 void *buf, u16 buf_size, u16 tlv_len, u16 *mib_len,
134 struct ice_sq_cd *cd)
136 struct ice_aqc_lldp_add_delete_tlv *cmd;
137 struct ice_aq_desc desc;
138 enum ice_status status;
141 return ICE_ERR_PARAM;
143 cmd = &desc.params.lldp_add_delete_tlv;
146 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_add_tlv);
148 ice_fill_dflt_direct_cmd_desc(&desc,
149 ice_aqc_opc_lldp_delete_tlv);
151 desc.flags |= CPU_TO_LE16((u16)(ICE_AQ_FLAG_RD));
153 cmd->type = ((bridge_type << ICE_AQ_LLDP_BRID_TYPE_S) &
154 ICE_AQ_LLDP_BRID_TYPE_M);
155 cmd->len = CPU_TO_LE16(tlv_len);
157 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
158 if (!status && mib_len)
159 *mib_len = LE16_TO_CPU(desc.datalen);
165 * ice_aq_update_lldp_tlv
166 * @hw: pointer to the HW struct
167 * @bridge_type: type of bridge
168 * @buf: buffer with TLV to update
169 * @buf_size: size of the buffer holding original and updated TLVs
170 * @old_len: Length of the Original TLV
171 * @new_len: Length of the Updated TLV
172 * @offset: offset of the updated TLV in the buff
173 * @mib_len: length of the returned LLDP MIB
174 * @cd: pointer to command details structure or NULL
176 * Update the specified TLV to the LLDP Local MIB for the given bridge type.
177 * Firmware will place the complete LLDP MIB in response buffer with the
178 * updated TLV. (0x0A03)
181 ice_aq_update_lldp_tlv(struct ice_hw *hw, u8 bridge_type, void *buf,
182 u16 buf_size, u16 old_len, u16 new_len, u16 offset,
183 u16 *mib_len, struct ice_sq_cd *cd)
185 struct ice_aqc_lldp_update_tlv *cmd;
186 struct ice_aq_desc desc;
187 enum ice_status status;
189 cmd = &desc.params.lldp_update_tlv;
191 if (offset == 0 || old_len == 0 || new_len == 0)
192 return ICE_ERR_PARAM;
194 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_update_tlv);
196 desc.flags |= CPU_TO_LE16((u16)(ICE_AQ_FLAG_RD));
198 cmd->type = ((bridge_type << ICE_AQ_LLDP_BRID_TYPE_S) &
199 ICE_AQ_LLDP_BRID_TYPE_M);
200 cmd->old_len = CPU_TO_LE16(old_len);
201 cmd->new_offset = CPU_TO_LE16(offset);
202 cmd->new_len = CPU_TO_LE16(new_len);
204 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
205 if (!status && mib_len)
206 *mib_len = LE16_TO_CPU(desc.datalen);
213 * @hw: pointer to the HW struct
214 * @shutdown_lldp_agent: True if LLDP Agent needs to be Shutdown
215 * False if LLDP Agent needs to be Stopped
216 * @persist: True if Stop/Shutdown of LLDP Agent needs to be persistent across
218 * @cd: pointer to command details structure or NULL
220 * Stop or Shutdown the embedded LLDP Agent (0x0A05)
223 ice_aq_stop_lldp(struct ice_hw *hw, bool shutdown_lldp_agent, bool persist,
224 struct ice_sq_cd *cd)
226 struct ice_aqc_lldp_stop *cmd;
227 struct ice_aq_desc desc;
229 cmd = &desc.params.lldp_stop;
231 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_stop);
233 if (shutdown_lldp_agent)
234 cmd->command |= ICE_AQ_LLDP_AGENT_SHUTDOWN;
237 cmd->command |= ICE_AQ_LLDP_AGENT_PERSIST_DIS;
239 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
244 * @hw: pointer to the HW struct
245 * @persist: True if Start of LLDP Agent needs to be persistent across reboots
246 * @cd: pointer to command details structure or NULL
248 * Start the embedded LLDP Agent on all ports. (0x0A06)
251 ice_aq_start_lldp(struct ice_hw *hw, bool persist, struct ice_sq_cd *cd)
253 struct ice_aqc_lldp_start *cmd;
254 struct ice_aq_desc desc;
256 cmd = &desc.params.lldp_start;
258 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_start);
260 cmd->command = ICE_AQ_LLDP_AGENT_START;
263 cmd->command |= ICE_AQ_LLDP_AGENT_PERSIST_ENA;
265 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
269 * ice_get_dcbx_status
270 * @hw: pointer to the HW struct
272 * Get the DCBX status from the Firmware
274 u8 ice_get_dcbx_status(struct ice_hw *hw)
278 reg = rd32(hw, PRTDCB_GENS);
279 return (u8)((reg & PRTDCB_GENS_DCBX_STATUS_M) >>
280 PRTDCB_GENS_DCBX_STATUS_S);
284 * ice_parse_ieee_ets_common_tlv
285 * @buf: Data buffer to be parsed for ETS CFG/REC data
286 * @ets_cfg: Container to store parsed data
288 * Parses the common data of IEEE 802.1Qaz ETS CFG/REC TLV
291 ice_parse_ieee_ets_common_tlv(u8 *buf, struct ice_dcb_ets_cfg *ets_cfg)
296 /* Priority Assignment Table (4 octets)
297 * Octets:| 1 | 2 | 3 | 4 |
298 * -----------------------------------------
299 * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
300 * -----------------------------------------
301 * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
302 * -----------------------------------------
304 for (i = 0; i < 4; i++) {
305 ets_cfg->prio_table[i * 2] =
306 ((buf[offset] & ICE_IEEE_ETS_PRIO_1_M) >>
307 ICE_IEEE_ETS_PRIO_1_S);
308 ets_cfg->prio_table[i * 2 + 1] =
309 ((buf[offset] & ICE_IEEE_ETS_PRIO_0_M) >>
310 ICE_IEEE_ETS_PRIO_0_S);
314 /* TC Bandwidth Table (8 octets)
315 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
316 * ---------------------------------
317 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
318 * ---------------------------------
320 * TSA Assignment Table (8 octets)
321 * Octets:| 9 | 10| 11| 12| 13| 14| 15| 16|
322 * ---------------------------------
323 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
324 * ---------------------------------
326 ice_for_each_traffic_class(i) {
327 ets_cfg->tcbwtable[i] = buf[offset];
328 ets_cfg->tsatable[i] = buf[ICE_MAX_TRAFFIC_CLASS + offset++];
333 * ice_parse_ieee_etscfg_tlv
334 * @tlv: IEEE 802.1Qaz ETS CFG TLV
335 * @dcbcfg: Local store to update ETS CFG data
337 * Parses IEEE 802.1Qaz ETS CFG TLV
340 ice_parse_ieee_etscfg_tlv(struct ice_lldp_org_tlv *tlv,
341 struct ice_dcbx_cfg *dcbcfg)
343 struct ice_dcb_ets_cfg *etscfg;
344 u8 *buf = tlv->tlvinfo;
346 /* First Octet post subtype
347 * --------------------------
348 * |will-|CBS | Re- | Max |
349 * |ing | |served| TCs |
350 * --------------------------
351 * |1bit | 1bit|3 bits|3bits|
353 etscfg = &dcbcfg->etscfg;
354 etscfg->willing = ((buf[0] & ICE_IEEE_ETS_WILLING_M) >>
355 ICE_IEEE_ETS_WILLING_S);
356 etscfg->cbs = ((buf[0] & ICE_IEEE_ETS_CBS_M) >> ICE_IEEE_ETS_CBS_S);
357 etscfg->maxtcs = ((buf[0] & ICE_IEEE_ETS_MAXTC_M) >>
358 ICE_IEEE_ETS_MAXTC_S);
360 /* Begin parsing at Priority Assignment Table (offset 1 in buf) */
361 ice_parse_ieee_ets_common_tlv(&buf[1], etscfg);
365 * ice_parse_ieee_etsrec_tlv
366 * @tlv: IEEE 802.1Qaz ETS REC TLV
367 * @dcbcfg: Local store to update ETS REC data
369 * Parses IEEE 802.1Qaz ETS REC TLV
372 ice_parse_ieee_etsrec_tlv(struct ice_lldp_org_tlv *tlv,
373 struct ice_dcbx_cfg *dcbcfg)
375 u8 *buf = tlv->tlvinfo;
377 /* Begin parsing at Priority Assignment Table (offset 1 in buf) */
378 ice_parse_ieee_ets_common_tlv(&buf[1], &dcbcfg->etsrec);
382 * ice_parse_ieee_pfccfg_tlv
383 * @tlv: IEEE 802.1Qaz PFC CFG TLV
384 * @dcbcfg: Local store to update PFC CFG data
386 * Parses IEEE 802.1Qaz PFC CFG TLV
389 ice_parse_ieee_pfccfg_tlv(struct ice_lldp_org_tlv *tlv,
390 struct ice_dcbx_cfg *dcbcfg)
392 u8 *buf = tlv->tlvinfo;
394 /* ----------------------------------------
395 * |will-|MBC | Re- | PFC | PFC Enable |
396 * |ing | |served| cap | |
397 * -----------------------------------------
398 * |1bit | 1bit|2 bits|4bits| 1 octet |
400 dcbcfg->pfc.willing = ((buf[0] & ICE_IEEE_PFC_WILLING_M) >>
401 ICE_IEEE_PFC_WILLING_S);
402 dcbcfg->pfc.mbc = ((buf[0] & ICE_IEEE_PFC_MBC_M) >> ICE_IEEE_PFC_MBC_S);
403 dcbcfg->pfc.pfccap = ((buf[0] & ICE_IEEE_PFC_CAP_M) >>
405 dcbcfg->pfc.pfcena = buf[1];
409 * ice_parse_ieee_app_tlv
410 * @tlv: IEEE 802.1Qaz APP TLV
411 * @dcbcfg: Local store to update APP PRIO data
413 * Parses IEEE 802.1Qaz APP PRIO TLV
416 ice_parse_ieee_app_tlv(struct ice_lldp_org_tlv *tlv,
417 struct ice_dcbx_cfg *dcbcfg)
425 typelen = NTOHS(tlv->typelen);
426 len = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
429 /* Removing sizeof(ouisubtype) and reserved byte from len.
430 * Remaining len div 3 is number of APP TLVs.
432 len -= (sizeof(tlv->ouisubtype) + 1);
434 /* Move offset to App Priority Table */
437 /* Application Priority Table (3 octets)
438 * Octets:| 1 | 2 | 3 |
439 * -----------------------------------------
440 * |Priority|Rsrvd| Sel | Protocol ID |
441 * -----------------------------------------
442 * Bits:|23 21|20 19|18 16|15 0|
443 * -----------------------------------------
445 while (offset < len) {
446 dcbcfg->app[i].priority = ((buf[offset] &
447 ICE_IEEE_APP_PRIO_M) >>
448 ICE_IEEE_APP_PRIO_S);
449 dcbcfg->app[i].selector = ((buf[offset] &
450 ICE_IEEE_APP_SEL_M) >>
452 dcbcfg->app[i].prot_id = (buf[offset + 1] << 0x8) |
454 /* Move to next app */
457 if (i >= ICE_DCBX_MAX_APPS)
466 * @tlv: IEEE 802.1Qaz TLV
467 * @dcbcfg: Local store to update ETS REC data
469 * Get the TLV subtype and send it to parsing function
470 * based on the subtype value
473 ice_parse_ieee_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
478 ouisubtype = NTOHL(tlv->ouisubtype);
479 subtype = (u8)((ouisubtype & ICE_LLDP_TLV_SUBTYPE_M) >>
480 ICE_LLDP_TLV_SUBTYPE_S);
482 case ICE_IEEE_SUBTYPE_ETS_CFG:
483 ice_parse_ieee_etscfg_tlv(tlv, dcbcfg);
485 case ICE_IEEE_SUBTYPE_ETS_REC:
486 ice_parse_ieee_etsrec_tlv(tlv, dcbcfg);
488 case ICE_IEEE_SUBTYPE_PFC_CFG:
489 ice_parse_ieee_pfccfg_tlv(tlv, dcbcfg);
491 case ICE_IEEE_SUBTYPE_APP_PRI:
492 ice_parse_ieee_app_tlv(tlv, dcbcfg);
500 * ice_parse_cee_pgcfg_tlv
501 * @tlv: CEE DCBX PG CFG TLV
502 * @dcbcfg: Local store to update ETS CFG data
504 * Parses CEE DCBX PG CFG TLV
507 ice_parse_cee_pgcfg_tlv(struct ice_cee_feat_tlv *tlv,
508 struct ice_dcbx_cfg *dcbcfg)
510 struct ice_dcb_ets_cfg *etscfg;
511 u8 *buf = tlv->tlvinfo;
515 etscfg = &dcbcfg->etscfg;
517 if (tlv->en_will_err & ICE_CEE_FEAT_TLV_WILLING_M)
521 /* Priority Group Table (4 octets)
522 * Octets:| 1 | 2 | 3 | 4 |
523 * -----------------------------------------
524 * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
525 * -----------------------------------------
526 * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
527 * -----------------------------------------
529 for (i = 0; i < 4; i++) {
530 etscfg->prio_table[i * 2] =
531 ((buf[offset] & ICE_CEE_PGID_PRIO_1_M) >>
532 ICE_CEE_PGID_PRIO_1_S);
533 etscfg->prio_table[i * 2 + 1] =
534 ((buf[offset] & ICE_CEE_PGID_PRIO_0_M) >>
535 ICE_CEE_PGID_PRIO_0_S);
539 /* PG Percentage Table (8 octets)
540 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
541 * ---------------------------------
542 * |pg0|pg1|pg2|pg3|pg4|pg5|pg6|pg7|
543 * ---------------------------------
545 ice_for_each_traffic_class(i) {
546 etscfg->tcbwtable[i] = buf[offset++];
548 if (etscfg->prio_table[i] == ICE_CEE_PGID_STRICT)
549 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_STRICT;
551 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_ETS;
554 /* Number of TCs supported (1 octet) */
555 etscfg->maxtcs = buf[offset];
559 * ice_parse_cee_pfccfg_tlv
560 * @tlv: CEE DCBX PFC CFG TLV
561 * @dcbcfg: Local store to update PFC CFG data
563 * Parses CEE DCBX PFC CFG TLV
566 ice_parse_cee_pfccfg_tlv(struct ice_cee_feat_tlv *tlv,
567 struct ice_dcbx_cfg *dcbcfg)
569 u8 *buf = tlv->tlvinfo;
571 if (tlv->en_will_err & ICE_CEE_FEAT_TLV_WILLING_M)
572 dcbcfg->pfc.willing = 1;
574 /* ------------------------
575 * | PFC Enable | PFC TCs |
576 * ------------------------
577 * | 1 octet | 1 octet |
579 dcbcfg->pfc.pfcena = buf[0];
580 dcbcfg->pfc.pfccap = buf[1];
584 * ice_parse_cee_app_tlv
585 * @tlv: CEE DCBX APP TLV
586 * @dcbcfg: Local store to update APP PRIO data
588 * Parses CEE DCBX APP PRIO TLV
591 ice_parse_cee_app_tlv(struct ice_cee_feat_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
593 u16 len, typelen, offset = 0;
594 struct ice_cee_app_prio *app;
597 typelen = NTOHS(tlv->hdr.typelen);
598 len = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
600 dcbcfg->numapps = len / sizeof(*app);
601 if (!dcbcfg->numapps)
603 if (dcbcfg->numapps > ICE_DCBX_MAX_APPS)
604 dcbcfg->numapps = ICE_DCBX_MAX_APPS;
606 for (i = 0; i < dcbcfg->numapps; i++) {
609 app = (struct ice_cee_app_prio *)(tlv->tlvinfo + offset);
610 for (up = 0; up < ICE_MAX_USER_PRIORITY; up++)
611 if (app->prio_map & BIT(up))
614 dcbcfg->app[i].priority = up;
616 /* Get Selector from lower 2 bits, and convert to IEEE */
617 selector = (app->upper_oui_sel & ICE_CEE_APP_SELECTOR_M);
619 case ICE_CEE_APP_SEL_ETHTYPE:
620 dcbcfg->app[i].selector = ICE_APP_SEL_ETHTYPE;
622 case ICE_CEE_APP_SEL_TCPIP:
623 dcbcfg->app[i].selector = ICE_APP_SEL_TCPIP;
626 /* Keep selector as it is for unknown types */
627 dcbcfg->app[i].selector = selector;
630 dcbcfg->app[i].prot_id = NTOHS(app->protocol);
631 /* Move to next app */
632 offset += sizeof(*app);
639 * @dcbcfg: Local store to update DCBX config data
641 * Get the TLV subtype and send it to parsing function
642 * based on the subtype value
645 ice_parse_cee_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
647 struct ice_cee_feat_tlv *sub_tlv;
648 u8 subtype, feat_tlv_count = 0;
649 u16 len, tlvlen, typelen;
652 ouisubtype = NTOHL(tlv->ouisubtype);
653 subtype = (u8)((ouisubtype & ICE_LLDP_TLV_SUBTYPE_M) >>
654 ICE_LLDP_TLV_SUBTYPE_S);
655 /* Return if not CEE DCBX */
656 if (subtype != ICE_CEE_DCBX_TYPE)
659 typelen = NTOHS(tlv->typelen);
660 tlvlen = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
661 len = sizeof(tlv->typelen) + sizeof(ouisubtype) +
662 sizeof(struct ice_cee_ctrl_tlv);
663 /* Return if no CEE DCBX Feature TLVs */
667 sub_tlv = (struct ice_cee_feat_tlv *)((char *)tlv + len);
668 while (feat_tlv_count < ICE_CEE_MAX_FEAT_TYPE) {
671 typelen = NTOHS(sub_tlv->hdr.typelen);
672 sublen = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
673 subtype = (u8)((typelen & ICE_LLDP_TLV_TYPE_M) >>
674 ICE_LLDP_TLV_TYPE_S);
676 case ICE_CEE_SUBTYPE_PG_CFG:
677 ice_parse_cee_pgcfg_tlv(sub_tlv, dcbcfg);
679 case ICE_CEE_SUBTYPE_PFC_CFG:
680 ice_parse_cee_pfccfg_tlv(sub_tlv, dcbcfg);
682 case ICE_CEE_SUBTYPE_APP_PRI:
683 ice_parse_cee_app_tlv(sub_tlv, dcbcfg);
686 return; /* Invalid Sub-type return */
689 /* Move to next sub TLV */
690 sub_tlv = (struct ice_cee_feat_tlv *)
691 ((char *)sub_tlv + sizeof(sub_tlv->hdr.typelen) +
698 * @tlv: Organization specific TLV
699 * @dcbcfg: Local store to update ETS REC data
701 * Currently only IEEE 802.1Qaz TLV is supported, all others
705 ice_parse_org_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
710 ouisubtype = NTOHL(tlv->ouisubtype);
711 oui = ((ouisubtype & ICE_LLDP_TLV_OUI_M) >> ICE_LLDP_TLV_OUI_S);
713 case ICE_IEEE_8021QAZ_OUI:
714 ice_parse_ieee_tlv(tlv, dcbcfg);
716 case ICE_CEE_DCBX_OUI:
717 ice_parse_cee_tlv(tlv, dcbcfg);
725 * ice_lldp_to_dcb_cfg
726 * @lldpmib: LLDPDU to be parsed
727 * @dcbcfg: store for LLDPDU data
729 * Parse DCB configuration from the LLDPDU
731 enum ice_status ice_lldp_to_dcb_cfg(u8 *lldpmib, struct ice_dcbx_cfg *dcbcfg)
733 struct ice_lldp_org_tlv *tlv;
734 enum ice_status ret = ICE_SUCCESS;
740 if (!lldpmib || !dcbcfg)
741 return ICE_ERR_PARAM;
743 /* set to the start of LLDPDU */
744 lldpmib += ETH_HEADER_LEN;
745 tlv = (struct ice_lldp_org_tlv *)lldpmib;
747 typelen = NTOHS(tlv->typelen);
748 type = ((typelen & ICE_LLDP_TLV_TYPE_M) >> ICE_LLDP_TLV_TYPE_S);
749 len = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
750 offset += sizeof(typelen) + len;
752 /* END TLV or beyond LLDPDU size */
753 if (type == ICE_TLV_TYPE_END || offset > ICE_LLDPDU_SIZE)
757 case ICE_TLV_TYPE_ORG:
758 ice_parse_org_tlv(tlv, dcbcfg);
764 /* Move to next TLV */
765 tlv = (struct ice_lldp_org_tlv *)
766 ((char *)tlv + sizeof(tlv->typelen) + len);
774 * @hw: pointer to the HW struct
775 * @mib_type: MIB type for the query
776 * @bridgetype: bridge type for the query (remote)
777 * @dcbcfg: store for LLDPDU data
779 * Query DCB configuration from the firmware
782 ice_aq_get_dcb_cfg(struct ice_hw *hw, u8 mib_type, u8 bridgetype,
783 struct ice_dcbx_cfg *dcbcfg)
788 /* Allocate the LLDPDU */
789 lldpmib = (u8 *)ice_malloc(hw, ICE_LLDPDU_SIZE);
791 return ICE_ERR_NO_MEMORY;
793 ret = ice_aq_get_lldp_mib(hw, bridgetype, mib_type, (void *)lldpmib,
794 ICE_LLDPDU_SIZE, NULL, NULL, NULL);
796 if (ret == ICE_SUCCESS)
797 /* Parse LLDP MIB to get DCB configuration */
798 ret = ice_lldp_to_dcb_cfg(lldpmib, dcbcfg);
800 ice_free(hw, lldpmib);
806 * ice_aq_dcb_ignore_pfc - Ignore PFC for given TCs
807 * @hw: pointer to the HW struct
808 * @tcmap: TC map for request/release any ignore PFC condition
809 * @request: request (true) or release (false) ignore PFC condition
810 * @tcmap_ret: return TCs for which PFC is currently ignored
811 * @cd: pointer to command details structure or NULL
813 * This sends out request/release to ignore PFC condition for a TC.
814 * It will return the TCs for which PFC is currently ignored. (0x0301)
817 ice_aq_dcb_ignore_pfc(struct ice_hw *hw, u8 tcmap, bool request, u8 *tcmap_ret,
818 struct ice_sq_cd *cd)
820 struct ice_aqc_pfc_ignore *cmd;
821 struct ice_aq_desc desc;
822 enum ice_status status;
824 cmd = &desc.params.pfc_ignore;
826 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_pfc_ignore);
829 cmd->cmd_flags = ICE_AQC_PFC_IGNORE_SET;
831 cmd->tc_bitmap = tcmap;
833 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
835 if (!status && tcmap_ret)
836 *tcmap_ret = cmd->tc_bitmap;
842 * ice_aq_start_stop_dcbx - Start/Stop DCBX service in FW
843 * @hw: pointer to the HW struct
844 * @start_dcbx_agent: True if DCBX Agent needs to be started
845 * False if DCBX Agent needs to be stopped
846 * @dcbx_agent_status: FW indicates back the DCBX agent status
847 * True if DCBX Agent is active
848 * False if DCBX Agent is stopped
849 * @cd: pointer to command details structure or NULL
851 * Start/Stop the embedded dcbx Agent. In case that this wrapper function
852 * returns ICE_SUCCESS, caller will need to check if FW returns back the same
853 * value as stated in dcbx_agent_status, and react accordingly. (0x0A09)
856 ice_aq_start_stop_dcbx(struct ice_hw *hw, bool start_dcbx_agent,
857 bool *dcbx_agent_status, struct ice_sq_cd *cd)
859 struct ice_aqc_lldp_stop_start_specific_agent *cmd;
860 enum ice_status status;
861 struct ice_aq_desc desc;
864 cmd = &desc.params.lldp_agent_ctrl;
866 opcode = ice_aqc_opc_lldp_stop_start_specific_agent;
868 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
870 if (start_dcbx_agent)
871 cmd->command = ICE_AQC_START_STOP_AGENT_START_DCBX;
873 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
875 *dcbx_agent_status = false;
877 if (status == ICE_SUCCESS &&
878 cmd->command == ICE_AQC_START_STOP_AGENT_START_DCBX)
879 *dcbx_agent_status = true;
885 * ice_aq_get_cee_dcb_cfg
886 * @hw: pointer to the HW struct
887 * @buff: response buffer that stores CEE operational configuration
888 * @cd: pointer to command details structure or NULL
890 * Get CEE DCBX mode operational configuration from firmware (0x0A07)
893 ice_aq_get_cee_dcb_cfg(struct ice_hw *hw,
894 struct ice_aqc_get_cee_dcb_cfg_resp *buff,
895 struct ice_sq_cd *cd)
897 struct ice_aq_desc desc;
899 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_cee_dcb_cfg);
901 return ice_aq_send_cmd(hw, &desc, (void *)buff, sizeof(*buff), cd);
905 * ice_aq_query_pfc_mode - Query PFC mode
906 * @hw: pointer to the HW struct
907 * @pfcmode_ret: Return PFC mode
908 * @cd: pointer to command details structure or NULL
910 * This will return an indication if DSCP-based PFC or VLAN-based PFC
911 * is enabled. (0x0302)
914 ice_aq_query_pfc_mode(struct ice_hw *hw, u8 *pfcmode_ret, struct ice_sq_cd *cd)
916 struct ice_aqc_set_query_pfc_mode *cmd;
917 struct ice_aq_desc desc;
918 enum ice_status status;
920 cmd = &desc.params.set_query_pfc_mode;
922 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_pfc_mode);
924 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
927 *pfcmode_ret = cmd->pfc_mode;
933 * ice_aq_set_pfc_mode - Set PFC mode
934 * @hw: pointer to the HW struct
935 * @pfcmode_set: set-value of PFC mode
936 * @pfcmode_ret: return value of PFC mode, written by FW
937 * @cd: pointer to command details structure or NULL
939 * This AQ call configures the PFC mdoe to DSCP-based PFC mode or VLAN
940 * -based PFC (0x0303)
943 ice_aq_set_pfc_mode(struct ice_hw *hw, u8 pfcmode_set, u8 *pfcmode_ret,
944 struct ice_sq_cd *cd)
946 struct ice_aqc_set_query_pfc_mode *cmd;
947 struct ice_aq_desc desc;
948 enum ice_status status;
950 if (pfcmode_set > ICE_AQC_PFC_DSCP_BASED_PFC)
951 return ICE_ERR_PARAM;
953 cmd = &desc.params.set_query_pfc_mode;
955 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_pfc_mode);
957 cmd->pfc_mode = pfcmode_set;
959 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
962 *pfcmode_ret = cmd->pfc_mode;
968 * ice_aq_set_dcb_parameters - Set DCB parameters
969 * @hw: pointer to the HW struct
970 * @dcb_enable: True if DCB configuration needs to be applied
971 * @cd: pointer to command details structure or NULL
973 * This AQ command will tell FW if it will apply or not apply the default DCB
974 * configuration when link up (0x0306).
977 ice_aq_set_dcb_parameters(struct ice_hw *hw, bool dcb_enable,
978 struct ice_sq_cd *cd)
980 struct ice_aqc_set_dcb_params *cmd;
981 struct ice_aq_desc desc;
983 cmd = &desc.params.set_dcb_params;
985 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_dcb_params);
987 cmd->valid_flags = ICE_AQC_LINK_UP_DCB_CFG_VALID;
989 cmd->cmd_flags = ICE_AQC_LINK_UP_DCB_CFG;
991 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
996 * @cee_cfg: pointer to CEE configuration struct
997 * @pi: port information structure
999 * Convert CEE configuration from firmware to DCB configuration
1002 ice_cee_to_dcb_cfg(struct ice_aqc_get_cee_dcb_cfg_resp *cee_cfg,
1003 struct ice_port_info *pi)
1005 u32 status, tlv_status = LE32_TO_CPU(cee_cfg->tlv_status);
1006 u32 ice_aqc_cee_status_mask, ice_aqc_cee_status_shift;
1007 u8 i, j, err, sync, oper, app_index, ice_app_sel_type;
1008 u16 app_prio = LE16_TO_CPU(cee_cfg->oper_app_prio);
1009 u16 ice_aqc_cee_app_mask, ice_aqc_cee_app_shift;
1010 struct ice_dcbx_cfg *cmp_dcbcfg, *dcbcfg;
1011 u16 ice_app_prot_id_type;
1013 dcbcfg = &pi->qos_cfg.local_dcbx_cfg;
1014 dcbcfg->dcbx_mode = ICE_DCBX_MODE_CEE;
1015 dcbcfg->tlv_status = tlv_status;
1018 dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
1020 /* Note that the FW creates the oper_prio_tc nibbles reversed
1021 * from those in the CEE Priority Group sub-TLV.
1023 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS / 2; i++) {
1024 dcbcfg->etscfg.prio_table[i * 2] =
1025 ((cee_cfg->oper_prio_tc[i] & ICE_CEE_PGID_PRIO_0_M) >>
1026 ICE_CEE_PGID_PRIO_0_S);
1027 dcbcfg->etscfg.prio_table[i * 2 + 1] =
1028 ((cee_cfg->oper_prio_tc[i] & ICE_CEE_PGID_PRIO_1_M) >>
1029 ICE_CEE_PGID_PRIO_1_S);
1032 ice_for_each_traffic_class(i) {
1033 dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
1035 if (dcbcfg->etscfg.prio_table[i] == ICE_CEE_PGID_STRICT) {
1036 /* Map it to next empty TC */
1037 dcbcfg->etscfg.prio_table[i] = cee_cfg->oper_num_tc - 1;
1038 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_STRICT;
1040 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_ETS;
1045 dcbcfg->pfc.pfcena = cee_cfg->oper_pfc_en;
1046 dcbcfg->pfc.pfccap = ICE_MAX_TRAFFIC_CLASS;
1048 /* CEE APP TLV data */
1049 if (dcbcfg->app_mode == ICE_DCBX_APPS_NON_WILLING)
1050 cmp_dcbcfg = &pi->qos_cfg.desired_dcbx_cfg;
1052 cmp_dcbcfg = &pi->qos_cfg.remote_dcbx_cfg;
1055 for (i = 0; i < 3; i++) {
1058 ice_aqc_cee_status_mask = ICE_AQC_CEE_FCOE_STATUS_M;
1059 ice_aqc_cee_status_shift = ICE_AQC_CEE_FCOE_STATUS_S;
1060 ice_aqc_cee_app_mask = ICE_AQC_CEE_APP_FCOE_M;
1061 ice_aqc_cee_app_shift = ICE_AQC_CEE_APP_FCOE_S;
1062 ice_app_sel_type = ICE_APP_SEL_ETHTYPE;
1063 ice_app_prot_id_type = ICE_APP_PROT_ID_FCOE;
1064 } else if (i == 1) {
1066 ice_aqc_cee_status_mask = ICE_AQC_CEE_ISCSI_STATUS_M;
1067 ice_aqc_cee_status_shift = ICE_AQC_CEE_ISCSI_STATUS_S;
1068 ice_aqc_cee_app_mask = ICE_AQC_CEE_APP_ISCSI_M;
1069 ice_aqc_cee_app_shift = ICE_AQC_CEE_APP_ISCSI_S;
1070 ice_app_sel_type = ICE_APP_SEL_TCPIP;
1071 ice_app_prot_id_type = ICE_APP_PROT_ID_ISCSI;
1073 for (j = 0; j < cmp_dcbcfg->numapps; j++) {
1074 u16 prot_id = cmp_dcbcfg->app[j].prot_id;
1075 u8 sel = cmp_dcbcfg->app[j].selector;
1077 if (sel == ICE_APP_SEL_TCPIP &&
1078 (prot_id == ICE_APP_PROT_ID_ISCSI ||
1079 prot_id == ICE_APP_PROT_ID_ISCSI_860)) {
1080 ice_app_prot_id_type = prot_id;
1086 ice_aqc_cee_status_mask = ICE_AQC_CEE_FIP_STATUS_M;
1087 ice_aqc_cee_status_shift = ICE_AQC_CEE_FIP_STATUS_S;
1088 ice_aqc_cee_app_mask = ICE_AQC_CEE_APP_FIP_M;
1089 ice_aqc_cee_app_shift = ICE_AQC_CEE_APP_FIP_S;
1090 ice_app_sel_type = ICE_APP_SEL_ETHTYPE;
1091 ice_app_prot_id_type = ICE_APP_PROT_ID_FIP;
1094 status = (tlv_status & ice_aqc_cee_status_mask) >>
1095 ice_aqc_cee_status_shift;
1096 err = (status & ICE_TLV_STATUS_ERR) ? 1 : 0;
1097 sync = (status & ICE_TLV_STATUS_SYNC) ? 1 : 0;
1098 oper = (status & ICE_TLV_STATUS_OPER) ? 1 : 0;
1099 /* Add FCoE/iSCSI/FIP APP if Error is False and
1102 if (!err && sync && oper) {
1103 dcbcfg->app[app_index].priority =
1104 (app_prio & ice_aqc_cee_app_mask) >>
1105 ice_aqc_cee_app_shift;
1106 dcbcfg->app[app_index].selector = ice_app_sel_type;
1107 dcbcfg->app[app_index].prot_id = ice_app_prot_id_type;
1112 dcbcfg->numapps = app_index;
1116 * ice_get_ieee_dcb_cfg
1117 * @pi: port information structure
1118 * @dcbx_mode: mode of DCBX (IEEE or CEE)
1120 * Get IEEE or CEE mode DCB configuration from the Firmware
1122 STATIC enum ice_status
1123 ice_get_ieee_or_cee_dcb_cfg(struct ice_port_info *pi, u8 dcbx_mode)
1125 struct ice_dcbx_cfg *dcbx_cfg = NULL;
1126 enum ice_status ret;
1129 return ICE_ERR_PARAM;
1131 if (dcbx_mode == ICE_DCBX_MODE_IEEE)
1132 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
1133 else if (dcbx_mode == ICE_DCBX_MODE_CEE)
1134 dcbx_cfg = &pi->qos_cfg.desired_dcbx_cfg;
1136 /* Get Local DCB Config in case of ICE_DCBX_MODE_IEEE
1137 * or get CEE DCB Desired Config in case of ICE_DCBX_MODE_CEE
1139 ret = ice_aq_get_dcb_cfg(pi->hw, ICE_AQ_LLDP_MIB_LOCAL,
1140 ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID, dcbx_cfg);
1144 /* Get Remote DCB Config */
1145 dcbx_cfg = &pi->qos_cfg.remote_dcbx_cfg;
1146 ret = ice_aq_get_dcb_cfg(pi->hw, ICE_AQ_LLDP_MIB_REMOTE,
1147 ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID, dcbx_cfg);
1148 /* Don't treat ENOENT as an error for Remote MIBs */
1149 if (pi->hw->adminq.sq_last_status == ICE_AQ_RC_ENOENT)
1158 * @pi: port information structure
1160 * Get DCB configuration from the Firmware
1162 enum ice_status ice_get_dcb_cfg(struct ice_port_info *pi)
1164 struct ice_aqc_get_cee_dcb_cfg_resp cee_cfg;
1165 struct ice_dcbx_cfg *dcbx_cfg;
1166 enum ice_status ret;
1169 return ICE_ERR_PARAM;
1171 ret = ice_aq_get_cee_dcb_cfg(pi->hw, &cee_cfg, NULL);
1172 if (ret == ICE_SUCCESS) {
1174 ret = ice_get_ieee_or_cee_dcb_cfg(pi, ICE_DCBX_MODE_CEE);
1175 ice_cee_to_dcb_cfg(&cee_cfg, pi);
1176 } else if (pi->hw->adminq.sq_last_status == ICE_AQ_RC_ENOENT) {
1177 /* CEE mode not enabled try querying IEEE data */
1178 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
1179 dcbx_cfg->dcbx_mode = ICE_DCBX_MODE_IEEE;
1180 ret = ice_get_ieee_or_cee_dcb_cfg(pi, ICE_DCBX_MODE_IEEE);
1188 * @hw: pointer to the HW struct
1189 * @enable_mib_change: enable MIB change event
1191 * Update DCB configuration from the Firmware
1193 enum ice_status ice_init_dcb(struct ice_hw *hw, bool enable_mib_change)
1195 struct ice_qos_cfg *qos_cfg = &hw->port_info->qos_cfg;
1196 enum ice_status ret = ICE_SUCCESS;
1198 if (!hw->func_caps.common_cap.dcb)
1199 return ICE_ERR_NOT_SUPPORTED;
1201 qos_cfg->is_sw_lldp = true;
1203 /* Get DCBX status */
1204 qos_cfg->dcbx_status = ice_get_dcbx_status(hw);
1206 if (qos_cfg->dcbx_status == ICE_DCBX_STATUS_DONE ||
1207 qos_cfg->dcbx_status == ICE_DCBX_STATUS_IN_PROGRESS ||
1208 qos_cfg->dcbx_status == ICE_DCBX_STATUS_NOT_STARTED) {
1209 /* Get current DCBX configuration */
1210 ret = ice_get_dcb_cfg(hw->port_info);
1213 qos_cfg->is_sw_lldp = false;
1214 } else if (qos_cfg->dcbx_status == ICE_DCBX_STATUS_DIS) {
1215 return ICE_ERR_NOT_READY;
1218 /* Configure the LLDP MIB change event */
1219 if (enable_mib_change) {
1220 ret = ice_aq_cfg_lldp_mib_change(hw, true, NULL);
1222 qos_cfg->is_sw_lldp = true;
1229 * ice_cfg_lldp_mib_change
1230 * @hw: pointer to the HW struct
1231 * @ena_mib: enable/disable MIB change event
1233 * Configure (disable/enable) MIB
1235 enum ice_status ice_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_mib)
1237 struct ice_qos_cfg *qos_cfg = &hw->port_info->qos_cfg;
1238 enum ice_status ret;
1240 if (!hw->func_caps.common_cap.dcb)
1241 return ICE_ERR_NOT_SUPPORTED;
1243 /* Get DCBX status */
1244 qos_cfg->dcbx_status = ice_get_dcbx_status(hw);
1246 if (qos_cfg->dcbx_status == ICE_DCBX_STATUS_DIS)
1247 return ICE_ERR_NOT_READY;
1249 ret = ice_aq_cfg_lldp_mib_change(hw, ena_mib, NULL);
1251 qos_cfg->is_sw_lldp = !ena_mib;
1257 * ice_add_ieee_ets_common_tlv
1258 * @buf: Data buffer to be populated with ice_dcb_ets_cfg data
1259 * @ets_cfg: Container for ice_dcb_ets_cfg data
1261 * Populate the TLV buffer with ice_dcb_ets_cfg data
1264 ice_add_ieee_ets_common_tlv(u8 *buf, struct ice_dcb_ets_cfg *ets_cfg)
1266 u8 priority0, priority1;
1270 /* Priority Assignment Table (4 octets)
1271 * Octets:| 1 | 2 | 3 | 4 |
1272 * -----------------------------------------
1273 * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
1274 * -----------------------------------------
1275 * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
1276 * -----------------------------------------
1278 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS / 2; i++) {
1279 priority0 = ets_cfg->prio_table[i * 2] & 0xF;
1280 priority1 = ets_cfg->prio_table[i * 2 + 1] & 0xF;
1281 buf[offset] = (priority0 << ICE_IEEE_ETS_PRIO_1_S) | priority1;
1285 /* TC Bandwidth Table (8 octets)
1286 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
1287 * ---------------------------------
1288 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
1289 * ---------------------------------
1291 * TSA Assignment Table (8 octets)
1292 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
1293 * ---------------------------------
1294 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
1295 * ---------------------------------
1297 ice_for_each_traffic_class(i) {
1298 buf[offset] = ets_cfg->tcbwtable[i];
1299 buf[ICE_MAX_TRAFFIC_CLASS + offset] = ets_cfg->tsatable[i];
1305 * ice_add_ieee_ets_tlv - Prepare ETS TLV in IEEE format
1306 * @tlv: Fill the ETS config data in IEEE format
1307 * @dcbcfg: Local store which holds the DCB Config
1309 * Prepare IEEE 802.1Qaz ETS CFG TLV
1312 ice_add_ieee_ets_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
1314 struct ice_dcb_ets_cfg *etscfg;
1315 u8 *buf = tlv->tlvinfo;
1316 u8 maxtcwilling = 0;
1320 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
1321 ICE_IEEE_ETS_TLV_LEN);
1322 tlv->typelen = HTONS(typelen);
1324 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1325 ICE_IEEE_SUBTYPE_ETS_CFG);
1326 tlv->ouisubtype = HTONL(ouisubtype);
1328 /* First Octet post subtype
1329 * --------------------------
1330 * |will-|CBS | Re- | Max |
1331 * |ing | |served| TCs |
1332 * --------------------------
1333 * |1bit | 1bit|3 bits|3bits|
1335 etscfg = &dcbcfg->etscfg;
1336 if (etscfg->willing)
1337 maxtcwilling = BIT(ICE_IEEE_ETS_WILLING_S);
1338 maxtcwilling |= etscfg->maxtcs & ICE_IEEE_ETS_MAXTC_M;
1339 buf[0] = maxtcwilling;
1341 /* Begin adding at Priority Assignment Table (offset 1 in buf) */
1342 ice_add_ieee_ets_common_tlv(&buf[1], etscfg);
1346 * ice_add_ieee_etsrec_tlv - Prepare ETS Recommended TLV in IEEE format
1347 * @tlv: Fill ETS Recommended TLV in IEEE format
1348 * @dcbcfg: Local store which holds the DCB Config
1350 * Prepare IEEE 802.1Qaz ETS REC TLV
1353 ice_add_ieee_etsrec_tlv(struct ice_lldp_org_tlv *tlv,
1354 struct ice_dcbx_cfg *dcbcfg)
1356 struct ice_dcb_ets_cfg *etsrec;
1357 u8 *buf = tlv->tlvinfo;
1361 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
1362 ICE_IEEE_ETS_TLV_LEN);
1363 tlv->typelen = HTONS(typelen);
1365 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1366 ICE_IEEE_SUBTYPE_ETS_REC);
1367 tlv->ouisubtype = HTONL(ouisubtype);
1369 etsrec = &dcbcfg->etsrec;
1371 /* First Octet is reserved */
1372 /* Begin adding at Priority Assignment Table (offset 1 in buf) */
1373 ice_add_ieee_ets_common_tlv(&buf[1], etsrec);
1377 * ice_add_ieee_pfc_tlv - Prepare PFC TLV in IEEE format
1378 * @tlv: Fill PFC TLV in IEEE format
1379 * @dcbcfg: Local store which holds the PFC CFG data
1381 * Prepare IEEE 802.1Qaz PFC CFG TLV
1384 ice_add_ieee_pfc_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
1386 u8 *buf = tlv->tlvinfo;
1390 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
1391 ICE_IEEE_PFC_TLV_LEN);
1392 tlv->typelen = HTONS(typelen);
1394 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1395 ICE_IEEE_SUBTYPE_PFC_CFG);
1396 tlv->ouisubtype = HTONL(ouisubtype);
1398 /* ----------------------------------------
1399 * |will-|MBC | Re- | PFC | PFC Enable |
1400 * |ing | |served| cap | |
1401 * -----------------------------------------
1402 * |1bit | 1bit|2 bits|4bits| 1 octet |
1404 if (dcbcfg->pfc.willing)
1405 buf[0] = BIT(ICE_IEEE_PFC_WILLING_S);
1407 if (dcbcfg->pfc.mbc)
1408 buf[0] |= BIT(ICE_IEEE_PFC_MBC_S);
1410 buf[0] |= dcbcfg->pfc.pfccap & 0xF;
1411 buf[1] = dcbcfg->pfc.pfcena;
1415 * ice_add_ieee_app_pri_tlv - Prepare APP TLV in IEEE format
1416 * @tlv: Fill APP TLV in IEEE format
1417 * @dcbcfg: Local store which holds the APP CFG data
1419 * Prepare IEEE 802.1Qaz APP CFG TLV
1422 ice_add_ieee_app_pri_tlv(struct ice_lldp_org_tlv *tlv,
1423 struct ice_dcbx_cfg *dcbcfg)
1425 u16 typelen, len, offset = 0;
1426 u8 priority, selector, i = 0;
1427 u8 *buf = tlv->tlvinfo;
1430 /* No APP TLVs then just return */
1431 if (dcbcfg->numapps == 0)
1433 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1434 ICE_IEEE_SUBTYPE_APP_PRI);
1435 tlv->ouisubtype = HTONL(ouisubtype);
1437 /* Move offset to App Priority Table */
1439 /* Application Priority Table (3 octets)
1440 * Octets:| 1 | 2 | 3 |
1441 * -----------------------------------------
1442 * |Priority|Rsrvd| Sel | Protocol ID |
1443 * -----------------------------------------
1444 * Bits:|23 21|20 19|18 16|15 0|
1445 * -----------------------------------------
1447 while (i < dcbcfg->numapps) {
1448 priority = dcbcfg->app[i].priority & 0x7;
1449 selector = dcbcfg->app[i].selector & 0x7;
1450 buf[offset] = (priority << ICE_IEEE_APP_PRIO_S) | selector;
1451 buf[offset + 1] = (dcbcfg->app[i].prot_id >> 0x8) & 0xFF;
1452 buf[offset + 2] = dcbcfg->app[i].prot_id & 0xFF;
1453 /* Move to next app */
1456 if (i >= ICE_DCBX_MAX_APPS)
1459 /* len includes size of ouisubtype + 1 reserved + 3*numapps */
1460 len = sizeof(tlv->ouisubtype) + 1 + (i * 3);
1461 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) | (len & 0x1FF));
1462 tlv->typelen = HTONS(typelen);
1466 * ice_add_dcb_tlv - Add all IEEE TLVs
1467 * @tlv: Fill TLV data in IEEE format
1468 * @dcbcfg: Local store which holds the DCB Config
1469 * @tlvid: Type of IEEE TLV
1471 * Add tlv information
1474 ice_add_dcb_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg,
1478 case ICE_IEEE_TLV_ID_ETS_CFG:
1479 ice_add_ieee_ets_tlv(tlv, dcbcfg);
1481 case ICE_IEEE_TLV_ID_ETS_REC:
1482 ice_add_ieee_etsrec_tlv(tlv, dcbcfg);
1484 case ICE_IEEE_TLV_ID_PFC_CFG:
1485 ice_add_ieee_pfc_tlv(tlv, dcbcfg);
1487 case ICE_IEEE_TLV_ID_APP_PRI:
1488 ice_add_ieee_app_pri_tlv(tlv, dcbcfg);
1496 * ice_dcb_cfg_to_lldp - Convert DCB configuration to MIB format
1497 * @lldpmib: pointer to the HW struct
1498 * @miblen: length of LLDP MIB
1499 * @dcbcfg: Local store which holds the DCB Config
1501 * Convert the DCB configuration to MIB format
1503 void ice_dcb_cfg_to_lldp(u8 *lldpmib, u16 *miblen, struct ice_dcbx_cfg *dcbcfg)
1505 u16 len, offset = 0, tlvid = ICE_TLV_ID_START;
1506 struct ice_lldp_org_tlv *tlv;
1509 tlv = (struct ice_lldp_org_tlv *)lldpmib;
1511 ice_add_dcb_tlv(tlv, dcbcfg, tlvid++);
1512 typelen = NTOHS(tlv->typelen);
1513 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
1516 /* END TLV or beyond LLDPDU size */
1517 if (tlvid >= ICE_TLV_ID_END_OF_LLDPPDU ||
1518 offset > ICE_LLDPDU_SIZE)
1520 /* Move to next TLV */
1522 tlv = (struct ice_lldp_org_tlv *)
1523 ((char *)tlv + sizeof(tlv->typelen) + len);
1529 * ice_set_dcb_cfg - Set the local LLDP MIB to FW
1530 * @pi: port information structure
1532 * Set DCB configuration to the Firmware
1534 enum ice_status ice_set_dcb_cfg(struct ice_port_info *pi)
1536 u8 mib_type, *lldpmib = NULL;
1537 struct ice_dcbx_cfg *dcbcfg;
1538 enum ice_status ret;
1543 return ICE_ERR_PARAM;
1547 /* update the HW local config */
1548 dcbcfg = &pi->qos_cfg.local_dcbx_cfg;
1549 /* Allocate the LLDPDU */
1550 lldpmib = (u8 *)ice_malloc(hw, ICE_LLDPDU_SIZE);
1552 return ICE_ERR_NO_MEMORY;
1554 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB;
1555 if (dcbcfg->app_mode == ICE_DCBX_APPS_NON_WILLING)
1556 mib_type |= SET_LOCAL_MIB_TYPE_CEE_NON_WILLING;
1558 ice_dcb_cfg_to_lldp(lldpmib, &miblen, dcbcfg);
1559 ret = ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, miblen,
1562 ice_free(hw, lldpmib);
1568 * ice_aq_query_port_ets - query port ETS configuration
1569 * @pi: port information structure
1570 * @buf: pointer to buffer
1571 * @buf_size: buffer size in bytes
1572 * @cd: pointer to command details structure or NULL
1574 * query current port ETS configuration
1577 ice_aq_query_port_ets(struct ice_port_info *pi,
1578 struct ice_aqc_port_ets_elem *buf, u16 buf_size,
1579 struct ice_sq_cd *cd)
1581 struct ice_aqc_query_port_ets *cmd;
1582 struct ice_aq_desc desc;
1583 enum ice_status status;
1586 return ICE_ERR_PARAM;
1587 cmd = &desc.params.port_ets;
1588 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_port_ets);
1589 cmd->port_teid = pi->root->info.node_teid;
1591 status = ice_aq_send_cmd(pi->hw, &desc, buf, buf_size, cd);
1596 * ice_update_port_tc_tree_cfg - update TC tree configuration
1597 * @pi: port information structure
1598 * @buf: pointer to buffer
1600 * update the SW DB with the new TC changes
1603 ice_update_port_tc_tree_cfg(struct ice_port_info *pi,
1604 struct ice_aqc_port_ets_elem *buf)
1606 struct ice_sched_node *node, *tc_node;
1607 struct ice_aqc_txsched_elem_data elem;
1608 enum ice_status status = ICE_SUCCESS;
1613 return ICE_ERR_PARAM;
1614 /* suspend the missing TC nodes */
1615 for (i = 0; i < pi->root->num_children; i++) {
1616 teid1 = LE32_TO_CPU(pi->root->children[i]->info.node_teid);
1617 ice_for_each_traffic_class(j) {
1618 teid2 = LE32_TO_CPU(buf->tc_node_teid[j]);
1622 if (j < ICE_MAX_TRAFFIC_CLASS)
1625 pi->root->children[i]->in_use = false;
1627 /* add the new TC nodes */
1628 ice_for_each_traffic_class(j) {
1629 teid2 = LE32_TO_CPU(buf->tc_node_teid[j]);
1630 if (teid2 == ICE_INVAL_TEID)
1632 /* Is it already present in the tree ? */
1633 for (i = 0; i < pi->root->num_children; i++) {
1634 tc_node = pi->root->children[i];
1637 teid1 = LE32_TO_CPU(tc_node->info.node_teid);
1638 if (teid1 == teid2) {
1639 tc_node->tc_num = j;
1640 tc_node->in_use = true;
1644 if (i < pi->root->num_children)
1647 status = ice_sched_query_elem(pi->hw, teid2, &elem);
1649 status = ice_sched_add_node(pi, 1, &elem);
1652 /* update the TC number */
1653 node = ice_sched_find_node_by_teid(pi->root, teid2);
1661 * ice_query_port_ets - query port ETS configuration
1662 * @pi: port information structure
1663 * @buf: pointer to buffer
1664 * @buf_size: buffer size in bytes
1665 * @cd: pointer to command details structure or NULL
1667 * query current port ETS configuration and update the
1668 * SW DB with the TC changes
1671 ice_query_port_ets(struct ice_port_info *pi,
1672 struct ice_aqc_port_ets_elem *buf, u16 buf_size,
1673 struct ice_sq_cd *cd)
1675 enum ice_status status;
1677 ice_acquire_lock(&pi->sched_lock);
1678 status = ice_aq_query_port_ets(pi, buf, buf_size, cd);
1680 status = ice_update_port_tc_tree_cfg(pi, buf);
1681 ice_release_lock(&pi->sched_lock);