1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2020, 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_aq_set_lldp_mib - Set the LLDP MIB
270 * @hw: pointer to the HW struct
271 * @mib_type: Local, Remote or both Local and Remote MIBs
272 * @buf: pointer to the caller-supplied buffer to store the MIB block
273 * @buf_size: size of the buffer (in bytes)
274 * @cd: pointer to command details structure or NULL
276 * Set the LLDP MIB. (0x0A08)
279 ice_aq_set_lldp_mib(struct ice_hw *hw, u8 mib_type, void *buf, u16 buf_size,
280 struct ice_sq_cd *cd)
282 struct ice_aqc_lldp_set_local_mib *cmd;
283 struct ice_aq_desc desc;
285 cmd = &desc.params.lldp_set_mib;
287 if (buf_size == 0 || !buf)
288 return ICE_ERR_PARAM;
290 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_set_local_mib);
292 desc.flags |= CPU_TO_LE16((u16)ICE_AQ_FLAG_RD);
293 desc.datalen = CPU_TO_LE16(buf_size);
295 cmd->type = mib_type;
296 cmd->length = CPU_TO_LE16(buf_size);
298 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
302 * ice_get_dcbx_status
303 * @hw: pointer to the HW struct
305 * Get the DCBX status from the Firmware
307 u8 ice_get_dcbx_status(struct ice_hw *hw)
311 reg = rd32(hw, PRTDCB_GENS);
312 return (u8)((reg & PRTDCB_GENS_DCBX_STATUS_M) >>
313 PRTDCB_GENS_DCBX_STATUS_S);
317 * ice_parse_ieee_ets_common_tlv
318 * @buf: Data buffer to be parsed for ETS CFG/REC data
319 * @ets_cfg: Container to store parsed data
321 * Parses the common data of IEEE 802.1Qaz ETS CFG/REC TLV
324 ice_parse_ieee_ets_common_tlv(u8 *buf, struct ice_dcb_ets_cfg *ets_cfg)
329 /* Priority Assignment Table (4 octets)
330 * Octets:| 1 | 2 | 3 | 4 |
331 * -----------------------------------------
332 * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
333 * -----------------------------------------
334 * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
335 * -----------------------------------------
337 for (i = 0; i < 4; i++) {
338 ets_cfg->prio_table[i * 2] =
339 ((buf[offset] & ICE_IEEE_ETS_PRIO_1_M) >>
340 ICE_IEEE_ETS_PRIO_1_S);
341 ets_cfg->prio_table[i * 2 + 1] =
342 ((buf[offset] & ICE_IEEE_ETS_PRIO_0_M) >>
343 ICE_IEEE_ETS_PRIO_0_S);
347 /* TC Bandwidth Table (8 octets)
348 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
349 * ---------------------------------
350 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
351 * ---------------------------------
353 * TSA Assignment Table (8 octets)
354 * Octets:| 9 | 10| 11| 12| 13| 14| 15| 16|
355 * ---------------------------------
356 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
357 * ---------------------------------
359 ice_for_each_traffic_class(i) {
360 ets_cfg->tcbwtable[i] = buf[offset];
361 ets_cfg->tsatable[i] = buf[ICE_MAX_TRAFFIC_CLASS + offset++];
366 * ice_parse_ieee_etscfg_tlv
367 * @tlv: IEEE 802.1Qaz ETS CFG TLV
368 * @dcbcfg: Local store to update ETS CFG data
370 * Parses IEEE 802.1Qaz ETS CFG TLV
373 ice_parse_ieee_etscfg_tlv(struct ice_lldp_org_tlv *tlv,
374 struct ice_dcbx_cfg *dcbcfg)
376 struct ice_dcb_ets_cfg *etscfg;
377 u8 *buf = tlv->tlvinfo;
379 /* First Octet post subtype
380 * --------------------------
381 * |will-|CBS | Re- | Max |
382 * |ing | |served| TCs |
383 * --------------------------
384 * |1bit | 1bit|3 bits|3bits|
386 etscfg = &dcbcfg->etscfg;
387 etscfg->willing = ((buf[0] & ICE_IEEE_ETS_WILLING_M) >>
388 ICE_IEEE_ETS_WILLING_S);
389 etscfg->cbs = ((buf[0] & ICE_IEEE_ETS_CBS_M) >> ICE_IEEE_ETS_CBS_S);
390 etscfg->maxtcs = ((buf[0] & ICE_IEEE_ETS_MAXTC_M) >>
391 ICE_IEEE_ETS_MAXTC_S);
393 /* Begin parsing at Priority Assignment Table (offset 1 in buf) */
394 ice_parse_ieee_ets_common_tlv(&buf[1], etscfg);
398 * ice_parse_ieee_etsrec_tlv
399 * @tlv: IEEE 802.1Qaz ETS REC TLV
400 * @dcbcfg: Local store to update ETS REC data
402 * Parses IEEE 802.1Qaz ETS REC TLV
405 ice_parse_ieee_etsrec_tlv(struct ice_lldp_org_tlv *tlv,
406 struct ice_dcbx_cfg *dcbcfg)
408 u8 *buf = tlv->tlvinfo;
410 /* Begin parsing at Priority Assignment Table (offset 1 in buf) */
411 ice_parse_ieee_ets_common_tlv(&buf[1], &dcbcfg->etsrec);
415 * ice_parse_ieee_pfccfg_tlv
416 * @tlv: IEEE 802.1Qaz PFC CFG TLV
417 * @dcbcfg: Local store to update PFC CFG data
419 * Parses IEEE 802.1Qaz PFC CFG TLV
422 ice_parse_ieee_pfccfg_tlv(struct ice_lldp_org_tlv *tlv,
423 struct ice_dcbx_cfg *dcbcfg)
425 u8 *buf = tlv->tlvinfo;
427 /* ----------------------------------------
428 * |will-|MBC | Re- | PFC | PFC Enable |
429 * |ing | |served| cap | |
430 * -----------------------------------------
431 * |1bit | 1bit|2 bits|4bits| 1 octet |
433 dcbcfg->pfc.willing = ((buf[0] & ICE_IEEE_PFC_WILLING_M) >>
434 ICE_IEEE_PFC_WILLING_S);
435 dcbcfg->pfc.mbc = ((buf[0] & ICE_IEEE_PFC_MBC_M) >> ICE_IEEE_PFC_MBC_S);
436 dcbcfg->pfc.pfccap = ((buf[0] & ICE_IEEE_PFC_CAP_M) >>
438 dcbcfg->pfc.pfcena = buf[1];
442 * ice_parse_ieee_app_tlv
443 * @tlv: IEEE 802.1Qaz APP TLV
444 * @dcbcfg: Local store to update APP PRIO data
446 * Parses IEEE 802.1Qaz APP PRIO TLV
449 ice_parse_ieee_app_tlv(struct ice_lldp_org_tlv *tlv,
450 struct ice_dcbx_cfg *dcbcfg)
458 typelen = NTOHS(tlv->typelen);
459 len = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
462 /* Removing sizeof(ouisubtype) and reserved byte from len.
463 * Remaining len div 3 is number of APP TLVs.
465 len -= (sizeof(tlv->ouisubtype) + 1);
467 /* Move offset to App Priority Table */
470 /* Application Priority Table (3 octets)
471 * Octets:| 1 | 2 | 3 |
472 * -----------------------------------------
473 * |Priority|Rsrvd| Sel | Protocol ID |
474 * -----------------------------------------
475 * Bits:|23 21|20 19|18 16|15 0|
476 * -----------------------------------------
478 while (offset < len) {
479 dcbcfg->app[i].priority = ((buf[offset] &
480 ICE_IEEE_APP_PRIO_M) >>
481 ICE_IEEE_APP_PRIO_S);
482 dcbcfg->app[i].selector = ((buf[offset] &
483 ICE_IEEE_APP_SEL_M) >>
485 dcbcfg->app[i].prot_id = (buf[offset + 1] << 0x8) |
487 /* Move to next app */
490 if (i >= ICE_DCBX_MAX_APPS)
499 * @tlv: IEEE 802.1Qaz TLV
500 * @dcbcfg: Local store to update ETS REC data
502 * Get the TLV subtype and send it to parsing function
503 * based on the subtype value
506 ice_parse_ieee_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
511 ouisubtype = NTOHL(tlv->ouisubtype);
512 subtype = (u8)((ouisubtype & ICE_LLDP_TLV_SUBTYPE_M) >>
513 ICE_LLDP_TLV_SUBTYPE_S);
515 case ICE_IEEE_SUBTYPE_ETS_CFG:
516 ice_parse_ieee_etscfg_tlv(tlv, dcbcfg);
518 case ICE_IEEE_SUBTYPE_ETS_REC:
519 ice_parse_ieee_etsrec_tlv(tlv, dcbcfg);
521 case ICE_IEEE_SUBTYPE_PFC_CFG:
522 ice_parse_ieee_pfccfg_tlv(tlv, dcbcfg);
524 case ICE_IEEE_SUBTYPE_APP_PRI:
525 ice_parse_ieee_app_tlv(tlv, dcbcfg);
533 * ice_parse_cee_pgcfg_tlv
534 * @tlv: CEE DCBX PG CFG TLV
535 * @dcbcfg: Local store to update ETS CFG data
537 * Parses CEE DCBX PG CFG TLV
540 ice_parse_cee_pgcfg_tlv(struct ice_cee_feat_tlv *tlv,
541 struct ice_dcbx_cfg *dcbcfg)
543 struct ice_dcb_ets_cfg *etscfg;
544 u8 *buf = tlv->tlvinfo;
548 etscfg = &dcbcfg->etscfg;
550 if (tlv->en_will_err & ICE_CEE_FEAT_TLV_WILLING_M)
554 /* Priority Group Table (4 octets)
555 * Octets:| 1 | 2 | 3 | 4 |
556 * -----------------------------------------
557 * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
558 * -----------------------------------------
559 * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
560 * -----------------------------------------
562 for (i = 0; i < 4; i++) {
563 etscfg->prio_table[i * 2] =
564 ((buf[offset] & ICE_CEE_PGID_PRIO_1_M) >>
565 ICE_CEE_PGID_PRIO_1_S);
566 etscfg->prio_table[i * 2 + 1] =
567 ((buf[offset] & ICE_CEE_PGID_PRIO_0_M) >>
568 ICE_CEE_PGID_PRIO_0_S);
572 /* PG Percentage Table (8 octets)
573 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
574 * ---------------------------------
575 * |pg0|pg1|pg2|pg3|pg4|pg5|pg6|pg7|
576 * ---------------------------------
578 ice_for_each_traffic_class(i) {
579 etscfg->tcbwtable[i] = buf[offset++];
581 if (etscfg->prio_table[i] == ICE_CEE_PGID_STRICT)
582 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_STRICT;
584 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_ETS;
587 /* Number of TCs supported (1 octet) */
588 etscfg->maxtcs = buf[offset];
592 * ice_parse_cee_pfccfg_tlv
593 * @tlv: CEE DCBX PFC CFG TLV
594 * @dcbcfg: Local store to update PFC CFG data
596 * Parses CEE DCBX PFC CFG TLV
599 ice_parse_cee_pfccfg_tlv(struct ice_cee_feat_tlv *tlv,
600 struct ice_dcbx_cfg *dcbcfg)
602 u8 *buf = tlv->tlvinfo;
604 if (tlv->en_will_err & ICE_CEE_FEAT_TLV_WILLING_M)
605 dcbcfg->pfc.willing = 1;
607 /* ------------------------
608 * | PFC Enable | PFC TCs |
609 * ------------------------
610 * | 1 octet | 1 octet |
612 dcbcfg->pfc.pfcena = buf[0];
613 dcbcfg->pfc.pfccap = buf[1];
617 * ice_parse_cee_app_tlv
618 * @tlv: CEE DCBX APP TLV
619 * @dcbcfg: Local store to update APP PRIO data
621 * Parses CEE DCBX APP PRIO TLV
624 ice_parse_cee_app_tlv(struct ice_cee_feat_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
626 u16 len, typelen, offset = 0;
627 struct ice_cee_app_prio *app;
630 typelen = NTOHS(tlv->hdr.typelen);
631 len = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
633 dcbcfg->numapps = len / sizeof(*app);
634 if (!dcbcfg->numapps)
636 if (dcbcfg->numapps > ICE_DCBX_MAX_APPS)
637 dcbcfg->numapps = ICE_DCBX_MAX_APPS;
639 for (i = 0; i < dcbcfg->numapps; i++) {
642 app = (struct ice_cee_app_prio *)(tlv->tlvinfo + offset);
643 for (up = 0; up < ICE_MAX_USER_PRIORITY; up++)
644 if (app->prio_map & BIT(up))
647 dcbcfg->app[i].priority = up;
649 /* Get Selector from lower 2 bits, and convert to IEEE */
650 selector = (app->upper_oui_sel & ICE_CEE_APP_SELECTOR_M);
652 case ICE_CEE_APP_SEL_ETHTYPE:
653 dcbcfg->app[i].selector = ICE_APP_SEL_ETHTYPE;
655 case ICE_CEE_APP_SEL_TCPIP:
656 dcbcfg->app[i].selector = ICE_APP_SEL_TCPIP;
659 /* Keep selector as it is for unknown types */
660 dcbcfg->app[i].selector = selector;
663 dcbcfg->app[i].prot_id = NTOHS(app->protocol);
664 /* Move to next app */
665 offset += sizeof(*app);
672 * @dcbcfg: Local store to update DCBX config data
674 * Get the TLV subtype and send it to parsing function
675 * based on the subtype value
678 ice_parse_cee_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
680 struct ice_cee_feat_tlv *sub_tlv;
681 u8 subtype, feat_tlv_count = 0;
682 u16 len, tlvlen, typelen;
685 ouisubtype = NTOHL(tlv->ouisubtype);
686 subtype = (u8)((ouisubtype & ICE_LLDP_TLV_SUBTYPE_M) >>
687 ICE_LLDP_TLV_SUBTYPE_S);
688 /* Return if not CEE DCBX */
689 if (subtype != ICE_CEE_DCBX_TYPE)
692 typelen = NTOHS(tlv->typelen);
693 tlvlen = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
694 len = sizeof(tlv->typelen) + sizeof(ouisubtype) +
695 sizeof(struct ice_cee_ctrl_tlv);
696 /* Return if no CEE DCBX Feature TLVs */
700 sub_tlv = (struct ice_cee_feat_tlv *)((char *)tlv + len);
701 while (feat_tlv_count < ICE_CEE_MAX_FEAT_TYPE) {
704 typelen = NTOHS(sub_tlv->hdr.typelen);
705 sublen = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
706 subtype = (u8)((typelen & ICE_LLDP_TLV_TYPE_M) >>
707 ICE_LLDP_TLV_TYPE_S);
709 case ICE_CEE_SUBTYPE_PG_CFG:
710 ice_parse_cee_pgcfg_tlv(sub_tlv, dcbcfg);
712 case ICE_CEE_SUBTYPE_PFC_CFG:
713 ice_parse_cee_pfccfg_tlv(sub_tlv, dcbcfg);
715 case ICE_CEE_SUBTYPE_APP_PRI:
716 ice_parse_cee_app_tlv(sub_tlv, dcbcfg);
719 return; /* Invalid Sub-type return */
722 /* Move to next sub TLV */
723 sub_tlv = (struct ice_cee_feat_tlv *)
724 ((char *)sub_tlv + sizeof(sub_tlv->hdr.typelen) +
731 * @tlv: Organization specific TLV
732 * @dcbcfg: Local store to update ETS REC data
734 * Currently only IEEE 802.1Qaz TLV is supported, all others
738 ice_parse_org_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
743 ouisubtype = NTOHL(tlv->ouisubtype);
744 oui = ((ouisubtype & ICE_LLDP_TLV_OUI_M) >> ICE_LLDP_TLV_OUI_S);
746 case ICE_IEEE_8021QAZ_OUI:
747 ice_parse_ieee_tlv(tlv, dcbcfg);
749 case ICE_CEE_DCBX_OUI:
750 ice_parse_cee_tlv(tlv, dcbcfg);
758 * ice_lldp_to_dcb_cfg
759 * @lldpmib: LLDPDU to be parsed
760 * @dcbcfg: store for LLDPDU data
762 * Parse DCB configuration from the LLDPDU
765 ice_lldp_to_dcb_cfg(u8 *lldpmib, struct ice_dcbx_cfg *dcbcfg)
767 struct ice_lldp_org_tlv *tlv;
768 enum ice_status ret = ICE_SUCCESS;
774 if (!lldpmib || !dcbcfg)
775 return ICE_ERR_PARAM;
777 /* set to the start of LLDPDU */
778 lldpmib += ETH_HEADER_LEN;
779 tlv = (struct ice_lldp_org_tlv *)lldpmib;
781 typelen = NTOHS(tlv->typelen);
782 type = ((typelen & ICE_LLDP_TLV_TYPE_M) >> ICE_LLDP_TLV_TYPE_S);
783 len = ((typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S);
784 offset += sizeof(typelen) + len;
786 /* END TLV or beyond LLDPDU size */
787 if (type == ICE_TLV_TYPE_END || offset > ICE_LLDPDU_SIZE)
791 case ICE_TLV_TYPE_ORG:
792 ice_parse_org_tlv(tlv, dcbcfg);
798 /* Move to next TLV */
799 tlv = (struct ice_lldp_org_tlv *)
800 ((char *)tlv + sizeof(tlv->typelen) + len);
808 * @hw: pointer to the HW struct
809 * @mib_type: MIB type for the query
810 * @bridgetype: bridge type for the query (remote)
811 * @dcbcfg: store for LLDPDU data
813 * Query DCB configuration from the firmware
816 ice_aq_get_dcb_cfg(struct ice_hw *hw, u8 mib_type, u8 bridgetype,
817 struct ice_dcbx_cfg *dcbcfg)
822 /* Allocate the LLDPDU */
823 lldpmib = (u8 *)ice_malloc(hw, ICE_LLDPDU_SIZE);
825 return ICE_ERR_NO_MEMORY;
827 ret = ice_aq_get_lldp_mib(hw, bridgetype, mib_type, (void *)lldpmib,
828 ICE_LLDPDU_SIZE, NULL, NULL, NULL);
830 if (ret == ICE_SUCCESS)
831 /* Parse LLDP MIB to get DCB configuration */
832 ret = ice_lldp_to_dcb_cfg(lldpmib, dcbcfg);
834 ice_free(hw, lldpmib);
840 * ice_aq_dcb_ignore_pfc - Ignore PFC for given TCs
841 * @hw: pointer to the HW struct
842 * @tcmap: TC map for request/release any ignore PFC condition
843 * @request: request (true) or release (false) ignore PFC condition
844 * @tcmap_ret: return TCs for which PFC is currently ignored
845 * @cd: pointer to command details structure or NULL
847 * This sends out request/release to ignore PFC condition for a TC.
848 * It will return the TCs for which PFC is currently ignored. (0x0301)
851 ice_aq_dcb_ignore_pfc(struct ice_hw *hw, u8 tcmap, bool request, u8 *tcmap_ret,
852 struct ice_sq_cd *cd)
854 struct ice_aqc_pfc_ignore *cmd;
855 struct ice_aq_desc desc;
856 enum ice_status status;
858 cmd = &desc.params.pfc_ignore;
860 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_pfc_ignore);
863 cmd->cmd_flags = ICE_AQC_PFC_IGNORE_SET;
865 cmd->tc_bitmap = tcmap;
867 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
869 if (!status && tcmap_ret)
870 *tcmap_ret = cmd->tc_bitmap;
876 * ice_aq_start_stop_dcbx - Start/Stop DCBX service in FW
877 * @hw: pointer to the HW struct
878 * @start_dcbx_agent: True if DCBX Agent needs to be started
879 * False if DCBX Agent needs to be stopped
880 * @dcbx_agent_status: FW indicates back the DCBX agent status
881 * True if DCBX Agent is active
882 * False if DCBX Agent is stopped
883 * @cd: pointer to command details structure or NULL
885 * Start/Stop the embedded dcbx Agent. In case that this wrapper function
886 * returns ICE_SUCCESS, caller will need to check if FW returns back the same
887 * value as stated in dcbx_agent_status, and react accordingly. (0x0A09)
890 ice_aq_start_stop_dcbx(struct ice_hw *hw, bool start_dcbx_agent,
891 bool *dcbx_agent_status, struct ice_sq_cd *cd)
893 struct ice_aqc_lldp_stop_start_specific_agent *cmd;
894 enum ice_status status;
895 struct ice_aq_desc desc;
898 cmd = &desc.params.lldp_agent_ctrl;
900 opcode = ice_aqc_opc_lldp_stop_start_specific_agent;
902 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
904 if (start_dcbx_agent)
905 cmd->command = ICE_AQC_START_STOP_AGENT_START_DCBX;
907 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
909 *dcbx_agent_status = false;
911 if (status == ICE_SUCCESS &&
912 cmd->command == ICE_AQC_START_STOP_AGENT_START_DCBX)
913 *dcbx_agent_status = true;
919 * ice_aq_get_cee_dcb_cfg
920 * @hw: pointer to the HW struct
921 * @buff: response buffer that stores CEE operational configuration
922 * @cd: pointer to command details structure or NULL
924 * Get CEE DCBX mode operational configuration from firmware (0x0A07)
927 ice_aq_get_cee_dcb_cfg(struct ice_hw *hw,
928 struct ice_aqc_get_cee_dcb_cfg_resp *buff,
929 struct ice_sq_cd *cd)
931 struct ice_aq_desc desc;
933 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_cee_dcb_cfg);
935 return ice_aq_send_cmd(hw, &desc, (void *)buff, sizeof(*buff), cd);
939 * ice_aq_query_pfc_mode - Query PFC mode
940 * @hw: pointer to the HW struct
941 * @pfcmode_ret: Return PFC mode
942 * @cd: pointer to command details structure or NULL
944 * This will return an indication if DSCP-based PFC or VLAN-based PFC
945 * is enabled. (0x0302)
948 ice_aq_query_pfc_mode(struct ice_hw *hw, u8 *pfcmode_ret, struct ice_sq_cd *cd)
950 struct ice_aqc_set_query_pfc_mode *cmd;
951 struct ice_aq_desc desc;
952 enum ice_status status;
954 cmd = &desc.params.set_query_pfc_mode;
956 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_pfc_mode);
958 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
961 *pfcmode_ret = cmd->pfc_mode;
967 * ice_aq_set_pfc_mode - Set PFC mode
968 * @hw: pointer to the HW struct
969 * @pfcmode_set: set-value of PFC mode
970 * @pfcmode_ret: return value of PFC mode, written by FW
971 * @cd: pointer to command details structure or NULL
973 * This AQ call configures the PFC mdoe to DSCP-based PFC mode or VLAN
974 * -based PFC (0x0303)
977 ice_aq_set_pfc_mode(struct ice_hw *hw, u8 pfcmode_set, u8 *pfcmode_ret,
978 struct ice_sq_cd *cd)
980 struct ice_aqc_set_query_pfc_mode *cmd;
981 struct ice_aq_desc desc;
982 enum ice_status status;
984 if (pfcmode_set > ICE_AQC_PFC_DSCP_BASED_PFC)
985 return ICE_ERR_PARAM;
987 cmd = &desc.params.set_query_pfc_mode;
989 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_pfc_mode);
991 cmd->pfc_mode = pfcmode_set;
993 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
996 *pfcmode_ret = cmd->pfc_mode;
1002 * ice_aq_set_dcb_parameters - Set DCB parameters
1003 * @hw: pointer to the HW struct
1004 * @dcb_enable: True if DCB configuration needs to be applied
1005 * @cd: pointer to command details structure or NULL
1007 * This AQ command will tell FW if it will apply or not apply the default DCB
1008 * configuration when link up (0x0306).
1011 ice_aq_set_dcb_parameters(struct ice_hw *hw, bool dcb_enable,
1012 struct ice_sq_cd *cd)
1014 struct ice_aqc_set_dcb_params *cmd;
1015 struct ice_aq_desc desc;
1017 cmd = &desc.params.set_dcb_params;
1019 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_dcb_params);
1021 cmd->valid_flags = ICE_AQC_LINK_UP_DCB_CFG_VALID;
1023 cmd->cmd_flags = ICE_AQC_LINK_UP_DCB_CFG;
1025 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1029 * ice_cee_to_dcb_cfg
1030 * @cee_cfg: pointer to CEE configuration struct
1031 * @dcbcfg: DCB configuration struct
1033 * Convert CEE configuration from firmware to DCB configuration
1036 ice_cee_to_dcb_cfg(struct ice_aqc_get_cee_dcb_cfg_resp *cee_cfg,
1037 struct ice_dcbx_cfg *dcbcfg)
1039 u32 status, tlv_status = LE32_TO_CPU(cee_cfg->tlv_status);
1040 u32 ice_aqc_cee_status_mask, ice_aqc_cee_status_shift;
1041 u16 app_prio = LE16_TO_CPU(cee_cfg->oper_app_prio);
1042 u8 i, err, sync, oper, app_index, ice_app_sel_type;
1043 u16 ice_aqc_cee_app_mask, ice_aqc_cee_app_shift;
1044 u16 ice_app_prot_id_type;
1046 /* CEE PG data to ETS config */
1047 dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
1049 /* Note that the FW creates the oper_prio_tc nibbles reversed
1050 * from those in the CEE Priority Group sub-TLV.
1052 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS / 2; i++) {
1053 dcbcfg->etscfg.prio_table[i * 2] =
1054 ((cee_cfg->oper_prio_tc[i] & ICE_CEE_PGID_PRIO_0_M) >>
1055 ICE_CEE_PGID_PRIO_0_S);
1056 dcbcfg->etscfg.prio_table[i * 2 + 1] =
1057 ((cee_cfg->oper_prio_tc[i] & ICE_CEE_PGID_PRIO_1_M) >>
1058 ICE_CEE_PGID_PRIO_1_S);
1061 ice_for_each_traffic_class(i) {
1062 dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
1064 if (dcbcfg->etscfg.prio_table[i] == ICE_CEE_PGID_STRICT) {
1065 /* Map it to next empty TC */
1066 dcbcfg->etscfg.prio_table[i] = cee_cfg->oper_num_tc - 1;
1067 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_STRICT;
1069 dcbcfg->etscfg.tsatable[i] = ICE_IEEE_TSA_ETS;
1073 /* CEE PFC data to ETS config */
1074 dcbcfg->pfc.pfcena = cee_cfg->oper_pfc_en;
1075 dcbcfg->pfc.pfccap = ICE_MAX_TRAFFIC_CLASS;
1078 for (i = 0; i < 3; i++) {
1081 ice_aqc_cee_status_mask = ICE_AQC_CEE_FCOE_STATUS_M;
1082 ice_aqc_cee_status_shift = ICE_AQC_CEE_FCOE_STATUS_S;
1083 ice_aqc_cee_app_mask = ICE_AQC_CEE_APP_FCOE_M;
1084 ice_aqc_cee_app_shift = ICE_AQC_CEE_APP_FCOE_S;
1085 ice_app_sel_type = ICE_APP_SEL_ETHTYPE;
1086 ice_app_prot_id_type = ICE_APP_PROT_ID_FCOE;
1087 } else if (i == 1) {
1089 ice_aqc_cee_status_mask = ICE_AQC_CEE_ISCSI_STATUS_M;
1090 ice_aqc_cee_status_shift = ICE_AQC_CEE_ISCSI_STATUS_S;
1091 ice_aqc_cee_app_mask = ICE_AQC_CEE_APP_ISCSI_M;
1092 ice_aqc_cee_app_shift = ICE_AQC_CEE_APP_ISCSI_S;
1093 ice_app_sel_type = ICE_APP_SEL_TCPIP;
1094 ice_app_prot_id_type = ICE_APP_PROT_ID_ISCSI;
1097 ice_aqc_cee_status_mask = ICE_AQC_CEE_FIP_STATUS_M;
1098 ice_aqc_cee_status_shift = ICE_AQC_CEE_FIP_STATUS_S;
1099 ice_aqc_cee_app_mask = ICE_AQC_CEE_APP_FIP_M;
1100 ice_aqc_cee_app_shift = ICE_AQC_CEE_APP_FIP_S;
1101 ice_app_sel_type = ICE_APP_SEL_ETHTYPE;
1102 ice_app_prot_id_type = ICE_APP_PROT_ID_FIP;
1105 status = (tlv_status & ice_aqc_cee_status_mask) >>
1106 ice_aqc_cee_status_shift;
1107 err = (status & ICE_TLV_STATUS_ERR) ? 1 : 0;
1108 sync = (status & ICE_TLV_STATUS_SYNC) ? 1 : 0;
1109 oper = (status & ICE_TLV_STATUS_OPER) ? 1 : 0;
1110 /* Add FCoE/iSCSI/FIP APP if Error is False and
1113 if (!err && sync && oper) {
1114 dcbcfg->app[app_index].priority =
1115 (app_prio & ice_aqc_cee_app_mask) >>
1116 ice_aqc_cee_app_shift;
1117 dcbcfg->app[app_index].selector = ice_app_sel_type;
1118 dcbcfg->app[app_index].prot_id = ice_app_prot_id_type;
1123 dcbcfg->numapps = app_index;
1127 * ice_get_ieee_dcb_cfg
1128 * @pi: port information structure
1129 * @dcbx_mode: mode of DCBX (IEEE or CEE)
1131 * Get IEEE or CEE mode DCB configuration from the Firmware
1133 STATIC enum ice_status
1134 ice_get_ieee_or_cee_dcb_cfg(struct ice_port_info *pi, u8 dcbx_mode)
1136 struct ice_dcbx_cfg *dcbx_cfg = NULL;
1137 enum ice_status ret;
1140 return ICE_ERR_PARAM;
1142 if (dcbx_mode == ICE_DCBX_MODE_IEEE)
1143 dcbx_cfg = &pi->local_dcbx_cfg;
1144 else if (dcbx_mode == ICE_DCBX_MODE_CEE)
1145 dcbx_cfg = &pi->desired_dcbx_cfg;
1147 /* Get Local DCB Config in case of ICE_DCBX_MODE_IEEE
1148 * or get CEE DCB Desired Config in case of ICE_DCBX_MODE_CEE
1150 ret = ice_aq_get_dcb_cfg(pi->hw, ICE_AQ_LLDP_MIB_LOCAL,
1151 ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID, dcbx_cfg);
1155 /* Get Remote DCB Config */
1156 dcbx_cfg = &pi->remote_dcbx_cfg;
1157 ret = ice_aq_get_dcb_cfg(pi->hw, ICE_AQ_LLDP_MIB_REMOTE,
1158 ICE_AQ_LLDP_BRID_TYPE_NEAREST_BRID, dcbx_cfg);
1159 /* Don't treat ENOENT as an error for Remote MIBs */
1160 if (pi->hw->adminq.sq_last_status == ICE_AQ_RC_ENOENT)
1169 * @pi: port information structure
1171 * Get DCB configuration from the Firmware
1173 enum ice_status ice_get_dcb_cfg(struct ice_port_info *pi)
1175 struct ice_aqc_get_cee_dcb_cfg_resp cee_cfg;
1176 struct ice_dcbx_cfg *dcbx_cfg;
1177 enum ice_status ret;
1180 return ICE_ERR_PARAM;
1182 ret = ice_aq_get_cee_dcb_cfg(pi->hw, &cee_cfg, NULL);
1183 if (ret == ICE_SUCCESS) {
1185 dcbx_cfg = &pi->local_dcbx_cfg;
1186 dcbx_cfg->dcbx_mode = ICE_DCBX_MODE_CEE;
1187 dcbx_cfg->tlv_status = LE32_TO_CPU(cee_cfg.tlv_status);
1188 ice_cee_to_dcb_cfg(&cee_cfg, dcbx_cfg);
1189 ret = ice_get_ieee_or_cee_dcb_cfg(pi, ICE_DCBX_MODE_CEE);
1190 } else if (pi->hw->adminq.sq_last_status == ICE_AQ_RC_ENOENT) {
1191 /* CEE mode not enabled try querying IEEE data */
1192 dcbx_cfg = &pi->local_dcbx_cfg;
1193 dcbx_cfg->dcbx_mode = ICE_DCBX_MODE_IEEE;
1194 ret = ice_get_ieee_or_cee_dcb_cfg(pi, ICE_DCBX_MODE_IEEE);
1202 * @hw: pointer to the HW struct
1203 * @enable_mib_change: enable MIB change event
1205 * Update DCB configuration from the Firmware
1207 enum ice_status ice_init_dcb(struct ice_hw *hw, bool enable_mib_change)
1209 struct ice_port_info *pi = hw->port_info;
1210 enum ice_status ret = ICE_SUCCESS;
1212 if (!hw->func_caps.common_cap.dcb)
1213 return ICE_ERR_NOT_SUPPORTED;
1215 pi->is_sw_lldp = true;
1217 /* Get DCBX status */
1218 pi->dcbx_status = ice_get_dcbx_status(hw);
1220 if (pi->dcbx_status == ICE_DCBX_STATUS_DONE ||
1221 pi->dcbx_status == ICE_DCBX_STATUS_IN_PROGRESS ||
1222 pi->dcbx_status == ICE_DCBX_STATUS_NOT_STARTED) {
1223 /* Get current DCBX configuration */
1224 ret = ice_get_dcb_cfg(pi);
1227 pi->is_sw_lldp = false;
1228 } else if (pi->dcbx_status == ICE_DCBX_STATUS_DIS) {
1229 return ICE_ERR_NOT_READY;
1232 /* Configure the LLDP MIB change event */
1233 if (enable_mib_change) {
1234 ret = ice_aq_cfg_lldp_mib_change(hw, true, NULL);
1236 pi->is_sw_lldp = true;
1243 * ice_cfg_lldp_mib_change
1244 * @hw: pointer to the HW struct
1245 * @ena_mib: enable/disable MIB change event
1247 * Configure (disable/enable) MIB
1249 enum ice_status ice_cfg_lldp_mib_change(struct ice_hw *hw, bool ena_mib)
1251 struct ice_port_info *pi = hw->port_info;
1252 enum ice_status ret;
1254 if (!hw->func_caps.common_cap.dcb)
1255 return ICE_ERR_NOT_SUPPORTED;
1257 /* Get DCBX status */
1258 pi->dcbx_status = ice_get_dcbx_status(hw);
1260 if (pi->dcbx_status == ICE_DCBX_STATUS_DIS)
1261 return ICE_ERR_NOT_READY;
1263 ret = ice_aq_cfg_lldp_mib_change(hw, ena_mib, NULL);
1265 pi->is_sw_lldp = !ena_mib;
1271 * ice_add_ieee_ets_common_tlv
1272 * @buf: Data buffer to be populated with ice_dcb_ets_cfg data
1273 * @ets_cfg: Container for ice_dcb_ets_cfg data
1275 * Populate the TLV buffer with ice_dcb_ets_cfg data
1278 ice_add_ieee_ets_common_tlv(u8 *buf, struct ice_dcb_ets_cfg *ets_cfg)
1280 u8 priority0, priority1;
1284 /* Priority Assignment Table (4 octets)
1285 * Octets:| 1 | 2 | 3 | 4 |
1286 * -----------------------------------------
1287 * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
1288 * -----------------------------------------
1289 * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
1290 * -----------------------------------------
1292 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS / 2; i++) {
1293 priority0 = ets_cfg->prio_table[i * 2] & 0xF;
1294 priority1 = ets_cfg->prio_table[i * 2 + 1] & 0xF;
1295 buf[offset] = (priority0 << ICE_IEEE_ETS_PRIO_1_S) | priority1;
1299 /* TC Bandwidth Table (8 octets)
1300 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
1301 * ---------------------------------
1302 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
1303 * ---------------------------------
1305 * TSA Assignment Table (8 octets)
1306 * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
1307 * ---------------------------------
1308 * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
1309 * ---------------------------------
1311 ice_for_each_traffic_class(i) {
1312 buf[offset] = ets_cfg->tcbwtable[i];
1313 buf[ICE_MAX_TRAFFIC_CLASS + offset] = ets_cfg->tsatable[i];
1319 * ice_add_ieee_ets_tlv - Prepare ETS TLV in IEEE format
1320 * @tlv: Fill the ETS config data in IEEE format
1321 * @dcbcfg: Local store which holds the DCB Config
1323 * Prepare IEEE 802.1Qaz ETS CFG TLV
1326 ice_add_ieee_ets_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
1328 struct ice_dcb_ets_cfg *etscfg;
1329 u8 *buf = tlv->tlvinfo;
1330 u8 maxtcwilling = 0;
1334 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
1335 ICE_IEEE_ETS_TLV_LEN);
1336 tlv->typelen = HTONS(typelen);
1338 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1339 ICE_IEEE_SUBTYPE_ETS_CFG);
1340 tlv->ouisubtype = HTONL(ouisubtype);
1342 /* First Octet post subtype
1343 * --------------------------
1344 * |will-|CBS | Re- | Max |
1345 * |ing | |served| TCs |
1346 * --------------------------
1347 * |1bit | 1bit|3 bits|3bits|
1349 etscfg = &dcbcfg->etscfg;
1350 if (etscfg->willing)
1351 maxtcwilling = BIT(ICE_IEEE_ETS_WILLING_S);
1352 maxtcwilling |= etscfg->maxtcs & ICE_IEEE_ETS_MAXTC_M;
1353 buf[0] = maxtcwilling;
1355 /* Begin adding at Priority Assignment Table (offset 1 in buf) */
1356 ice_add_ieee_ets_common_tlv(&buf[1], etscfg);
1360 * ice_add_ieee_etsrec_tlv - Prepare ETS Recommended TLV in IEEE format
1361 * @tlv: Fill ETS Recommended TLV in IEEE format
1362 * @dcbcfg: Local store which holds the DCB Config
1364 * Prepare IEEE 802.1Qaz ETS REC TLV
1367 ice_add_ieee_etsrec_tlv(struct ice_lldp_org_tlv *tlv,
1368 struct ice_dcbx_cfg *dcbcfg)
1370 struct ice_dcb_ets_cfg *etsrec;
1371 u8 *buf = tlv->tlvinfo;
1375 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
1376 ICE_IEEE_ETS_TLV_LEN);
1377 tlv->typelen = HTONS(typelen);
1379 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1380 ICE_IEEE_SUBTYPE_ETS_REC);
1381 tlv->ouisubtype = HTONL(ouisubtype);
1383 etsrec = &dcbcfg->etsrec;
1385 /* First Octet is reserved */
1386 /* Begin adding at Priority Assignment Table (offset 1 in buf) */
1387 ice_add_ieee_ets_common_tlv(&buf[1], etsrec);
1391 * ice_add_ieee_pfc_tlv - Prepare PFC TLV in IEEE format
1392 * @tlv: Fill PFC TLV in IEEE format
1393 * @dcbcfg: Local store which holds the PFC CFG data
1395 * Prepare IEEE 802.1Qaz PFC CFG TLV
1398 ice_add_ieee_pfc_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg)
1400 u8 *buf = tlv->tlvinfo;
1404 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
1405 ICE_IEEE_PFC_TLV_LEN);
1406 tlv->typelen = HTONS(typelen);
1408 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1409 ICE_IEEE_SUBTYPE_PFC_CFG);
1410 tlv->ouisubtype = HTONL(ouisubtype);
1412 /* ----------------------------------------
1413 * |will-|MBC | Re- | PFC | PFC Enable |
1414 * |ing | |served| cap | |
1415 * -----------------------------------------
1416 * |1bit | 1bit|2 bits|4bits| 1 octet |
1418 if (dcbcfg->pfc.willing)
1419 buf[0] = BIT(ICE_IEEE_PFC_WILLING_S);
1421 if (dcbcfg->pfc.mbc)
1422 buf[0] |= BIT(ICE_IEEE_PFC_MBC_S);
1424 buf[0] |= dcbcfg->pfc.pfccap & 0xF;
1425 buf[1] = dcbcfg->pfc.pfcena;
1429 * ice_add_ieee_app_pri_tlv - Prepare APP TLV in IEEE format
1430 * @tlv: Fill APP TLV in IEEE format
1431 * @dcbcfg: Local store which holds the APP CFG data
1433 * Prepare IEEE 802.1Qaz APP CFG TLV
1436 ice_add_ieee_app_pri_tlv(struct ice_lldp_org_tlv *tlv,
1437 struct ice_dcbx_cfg *dcbcfg)
1439 u16 typelen, len, offset = 0;
1440 u8 priority, selector, i = 0;
1441 u8 *buf = tlv->tlvinfo;
1444 /* No APP TLVs then just return */
1445 if (dcbcfg->numapps == 0)
1447 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1448 ICE_IEEE_SUBTYPE_APP_PRI);
1449 tlv->ouisubtype = HTONL(ouisubtype);
1451 /* Move offset to App Priority Table */
1453 /* Application Priority Table (3 octets)
1454 * Octets:| 1 | 2 | 3 |
1455 * -----------------------------------------
1456 * |Priority|Rsrvd| Sel | Protocol ID |
1457 * -----------------------------------------
1458 * Bits:|23 21|20 19|18 16|15 0|
1459 * -----------------------------------------
1461 while (i < dcbcfg->numapps) {
1462 priority = dcbcfg->app[i].priority & 0x7;
1463 selector = dcbcfg->app[i].selector & 0x7;
1464 buf[offset] = (priority << ICE_IEEE_APP_PRIO_S) | selector;
1465 buf[offset + 1] = (dcbcfg->app[i].prot_id >> 0x8) & 0xFF;
1466 buf[offset + 2] = dcbcfg->app[i].prot_id & 0xFF;
1467 /* Move to next app */
1470 if (i >= ICE_DCBX_MAX_APPS)
1473 /* len includes size of ouisubtype + 1 reserved + 3*numapps */
1474 len = sizeof(tlv->ouisubtype) + 1 + (i * 3);
1475 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) | (len & 0x1FF));
1476 tlv->typelen = HTONS(typelen);
1480 * ice_add_dcb_tlv - Add all IEEE TLVs
1481 * @tlv: Fill TLV data in IEEE format
1482 * @dcbcfg: Local store which holds the DCB Config
1483 * @tlvid: Type of IEEE TLV
1485 * Add tlv information
1488 ice_add_dcb_tlv(struct ice_lldp_org_tlv *tlv, struct ice_dcbx_cfg *dcbcfg,
1492 case ICE_IEEE_TLV_ID_ETS_CFG:
1493 ice_add_ieee_ets_tlv(tlv, dcbcfg);
1495 case ICE_IEEE_TLV_ID_ETS_REC:
1496 ice_add_ieee_etsrec_tlv(tlv, dcbcfg);
1498 case ICE_IEEE_TLV_ID_PFC_CFG:
1499 ice_add_ieee_pfc_tlv(tlv, dcbcfg);
1501 case ICE_IEEE_TLV_ID_APP_PRI:
1502 ice_add_ieee_app_pri_tlv(tlv, dcbcfg);
1510 * ice_dcb_cfg_to_lldp - Convert DCB configuration to MIB format
1511 * @lldpmib: pointer to the HW struct
1512 * @miblen: length of LLDP MIB
1513 * @dcbcfg: Local store which holds the DCB Config
1515 * Convert the DCB configuration to MIB format
1517 void ice_dcb_cfg_to_lldp(u8 *lldpmib, u16 *miblen, struct ice_dcbx_cfg *dcbcfg)
1519 u16 len, offset = 0, tlvid = ICE_TLV_ID_START;
1520 struct ice_lldp_org_tlv *tlv;
1523 tlv = (struct ice_lldp_org_tlv *)lldpmib;
1525 ice_add_dcb_tlv(tlv, dcbcfg, tlvid++);
1526 typelen = NTOHS(tlv->typelen);
1527 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
1530 /* END TLV or beyond LLDPDU size */
1531 if (tlvid >= ICE_TLV_ID_END_OF_LLDPPDU ||
1532 offset > ICE_LLDPDU_SIZE)
1534 /* Move to next TLV */
1536 tlv = (struct ice_lldp_org_tlv *)
1537 ((char *)tlv + sizeof(tlv->typelen) + len);
1543 * ice_set_dcb_cfg - Set the local LLDP MIB to FW
1544 * @pi: port information structure
1546 * Set DCB configuration to the Firmware
1548 enum ice_status ice_set_dcb_cfg(struct ice_port_info *pi)
1550 u8 mib_type, *lldpmib = NULL;
1551 struct ice_dcbx_cfg *dcbcfg;
1552 enum ice_status ret;
1557 return ICE_ERR_PARAM;
1561 /* update the HW local config */
1562 dcbcfg = &pi->local_dcbx_cfg;
1563 /* Allocate the LLDPDU */
1564 lldpmib = (u8 *)ice_malloc(hw, ICE_LLDPDU_SIZE);
1566 return ICE_ERR_NO_MEMORY;
1568 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB;
1569 if (dcbcfg->app_mode == ICE_DCBX_APPS_NON_WILLING)
1570 mib_type |= SET_LOCAL_MIB_TYPE_CEE_NON_WILLING;
1572 ice_dcb_cfg_to_lldp(lldpmib, &miblen, dcbcfg);
1573 ret = ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, miblen,
1576 ice_free(hw, lldpmib);
1582 * ice_aq_query_port_ets - query port ETS configuration
1583 * @pi: port information structure
1584 * @buf: pointer to buffer
1585 * @buf_size: buffer size in bytes
1586 * @cd: pointer to command details structure or NULL
1588 * query current port ETS configuration
1591 ice_aq_query_port_ets(struct ice_port_info *pi,
1592 struct ice_aqc_port_ets_elem *buf, u16 buf_size,
1593 struct ice_sq_cd *cd)
1595 struct ice_aqc_query_port_ets *cmd;
1596 struct ice_aq_desc desc;
1597 enum ice_status status;
1600 return ICE_ERR_PARAM;
1601 cmd = &desc.params.port_ets;
1602 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_port_ets);
1603 cmd->port_teid = pi->root->info.node_teid;
1605 status = ice_aq_send_cmd(pi->hw, &desc, buf, buf_size, cd);
1610 * ice_update_port_tc_tree_cfg - update TC tree configuration
1611 * @pi: port information structure
1612 * @buf: pointer to buffer
1614 * update the SW DB with the new TC changes
1617 ice_update_port_tc_tree_cfg(struct ice_port_info *pi,
1618 struct ice_aqc_port_ets_elem *buf)
1620 struct ice_sched_node *node, *tc_node;
1621 struct ice_aqc_get_elem elem;
1622 enum ice_status status = ICE_SUCCESS;
1627 return ICE_ERR_PARAM;
1628 /* suspend the missing TC nodes */
1629 for (i = 0; i < pi->root->num_children; i++) {
1630 teid1 = LE32_TO_CPU(pi->root->children[i]->info.node_teid);
1631 ice_for_each_traffic_class(j) {
1632 teid2 = LE32_TO_CPU(buf->tc_node_teid[j]);
1636 if (j < ICE_MAX_TRAFFIC_CLASS)
1639 pi->root->children[i]->in_use = false;
1641 /* add the new TC nodes */
1642 ice_for_each_traffic_class(j) {
1643 teid2 = LE32_TO_CPU(buf->tc_node_teid[j]);
1644 if (teid2 == ICE_INVAL_TEID)
1646 /* Is it already present in the tree ? */
1647 for (i = 0; i < pi->root->num_children; i++) {
1648 tc_node = pi->root->children[i];
1651 teid1 = LE32_TO_CPU(tc_node->info.node_teid);
1652 if (teid1 == teid2) {
1653 tc_node->tc_num = j;
1654 tc_node->in_use = true;
1658 if (i < pi->root->num_children)
1661 status = ice_sched_query_elem(pi->hw, teid2, &elem);
1663 status = ice_sched_add_node(pi, 1, &elem.generic[0]);
1666 /* update the TC number */
1667 node = ice_sched_find_node_by_teid(pi->root, teid2);
1675 * ice_query_port_ets - query port ETS configuration
1676 * @pi: port information structure
1677 * @buf: pointer to buffer
1678 * @buf_size: buffer size in bytes
1679 * @cd: pointer to command details structure or NULL
1681 * query current port ETS configuration and update the
1682 * SW DB with the TC changes
1685 ice_query_port_ets(struct ice_port_info *pi,
1686 struct ice_aqc_port_ets_elem *buf, u16 buf_size,
1687 struct ice_sq_cd *cd)
1689 enum ice_status status;
1691 ice_acquire_lock(&pi->sched_lock);
1692 status = ice_aq_query_port_ets(pi, buf, buf_size, cd);
1694 status = ice_update_port_tc_tree_cfg(pi, buf);
1695 ice_release_lock(&pi->sched_lock);