2 * Copyright (C) 2013-2014 Chelsio Communications. All rights reserved.
4 * Written by Anish Bhatt (anish@chelsio.com)
5 * Casey Leedom (leedom@chelsio.com)
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * The full GNU General Public License is included in this distribution in
17 * the file called "COPYING".
23 /* DCBx version control
25 char *dcb_ver_array[] = {
34 /* Initialize a port's Data Center Bridging state. Typically used after a
37 void cxgb4_dcb_state_init(struct net_device *dev)
39 struct port_info *pi = netdev2pinfo(dev);
40 struct port_dcb_info *dcb = &pi->dcb;
41 int version_temp = dcb->dcb_version;
43 memset(dcb, 0, sizeof(struct port_dcb_info));
44 dcb->state = CXGB4_DCB_STATE_START;
46 dcb->dcb_version = version_temp;
48 netdev_dbg(dev, "%s: Initializing DCB state for port[%d]\n",
49 __func__, pi->port_id);
52 void cxgb4_dcb_version_init(struct net_device *dev)
54 struct port_info *pi = netdev2pinfo(dev);
55 struct port_dcb_info *dcb = &pi->dcb;
57 /* Any writes here are only done on kernels that exlicitly need
58 * a specific version, say < 2.6.38 which only support CEE
60 dcb->dcb_version = FW_PORT_DCB_VER_AUTO;
63 static void cxgb4_dcb_cleanup_apps(struct net_device *dev)
65 struct port_info *pi = netdev2pinfo(dev);
66 struct adapter *adap = pi->adapter;
67 struct port_dcb_info *dcb = &pi->dcb;
71 /* zero priority implies remove */
74 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
75 /* Check if app list is exhausted */
76 if (!dcb->app_priority[i].protocolid)
79 app.protocol = dcb->app_priority[i].protocolid;
81 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE) {
82 app.selector = dcb->app_priority[i].sel_field + 1;
83 err = dcb_ieee_setapp(dev, &app);
85 app.selector = !!(dcb->app_priority[i].sel_field);
86 err = dcb_setapp(dev, &app);
90 dev_err(adap->pdev_dev,
91 "Failed DCB Clear %s Application Priority: sel=%d, prot=%d, , err=%d\n",
92 dcb_ver_array[dcb->dcb_version], app.selector,
99 /* Finite State machine for Data Center Bridging.
101 void cxgb4_dcb_state_fsm(struct net_device *dev,
102 enum cxgb4_dcb_state_input transition_to)
104 struct port_info *pi = netdev2pinfo(dev);
105 struct port_dcb_info *dcb = &pi->dcb;
106 struct adapter *adap = pi->adapter;
107 enum cxgb4_dcb_state current_state = dcb->state;
109 netdev_dbg(dev, "%s: State change from %d to %d for %s\n",
110 __func__, dcb->state, transition_to, dev->name);
112 switch (current_state) {
113 case CXGB4_DCB_STATE_START: {
114 switch (transition_to) {
115 case CXGB4_DCB_INPUT_FW_DISABLED: {
116 /* we're going to use Host DCB */
117 dcb->state = CXGB4_DCB_STATE_HOST;
118 dcb->supported = CXGB4_DCBX_HOST_SUPPORT;
122 case CXGB4_DCB_INPUT_FW_ENABLED: {
123 /* we're going to use Firmware DCB */
124 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE;
125 dcb->supported = CXGB4_DCBX_FW_SUPPORT;
129 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
130 /* expected transition */
134 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
135 dcb->state = CXGB4_DCB_STATE_FW_ALLSYNCED;
140 goto bad_state_input;
145 case CXGB4_DCB_STATE_FW_INCOMPLETE: {
146 switch (transition_to) {
147 case CXGB4_DCB_INPUT_FW_ENABLED: {
148 /* we're alreaady in firmware DCB mode */
152 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
153 /* we're already incomplete */
157 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
158 dcb->state = CXGB4_DCB_STATE_FW_ALLSYNCED;
160 linkwatch_fire_event(dev);
165 goto bad_state_input;
170 case CXGB4_DCB_STATE_FW_ALLSYNCED: {
171 switch (transition_to) {
172 case CXGB4_DCB_INPUT_FW_ENABLED: {
173 /* we're alreaady in firmware DCB mode */
177 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
178 /* We were successfully running with firmware DCB but
179 * now it's telling us that it's in an "incomplete
180 * state. We need to reset back to a ground state
183 cxgb4_dcb_cleanup_apps(dev);
184 cxgb4_dcb_state_init(dev);
185 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE;
186 dcb->supported = CXGB4_DCBX_FW_SUPPORT;
187 linkwatch_fire_event(dev);
191 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
192 /* we're already all sync'ed
193 * this is only applicable for IEEE or
194 * when another VI already completed negotiaton
197 linkwatch_fire_event(dev);
202 goto bad_state_input;
207 case CXGB4_DCB_STATE_HOST: {
208 switch (transition_to) {
209 case CXGB4_DCB_INPUT_FW_DISABLED: {
210 /* we're alreaady in Host DCB mode */
215 goto bad_state_input;
221 goto bad_state_transition;
226 dev_err(adap->pdev_dev, "cxgb4_dcb_state_fsm: illegal input symbol %d\n",
230 bad_state_transition:
231 dev_err(adap->pdev_dev, "cxgb4_dcb_state_fsm: bad state transition, state = %d, input = %d\n",
232 current_state, transition_to);
235 /* Handle a DCB/DCBX update message from the firmware.
237 void cxgb4_dcb_handle_fw_update(struct adapter *adap,
238 const struct fw_port_cmd *pcmd)
240 const union fw_port_dcb *fwdcb = &pcmd->u.dcb;
241 int port = FW_PORT_CMD_PORTID_GET(be32_to_cpu(pcmd->op_to_portid));
242 struct net_device *dev = adap->port[port];
243 struct port_info *pi = netdev_priv(dev);
244 struct port_dcb_info *dcb = &pi->dcb;
245 int dcb_type = pcmd->u.dcb.pgid.type;
246 int dcb_running_version;
248 /* Handle Firmware DCB Control messages separately since they drive
251 if (dcb_type == FW_PORT_DCB_TYPE_CONTROL) {
252 enum cxgb4_dcb_state_input input =
253 ((pcmd->u.dcb.control.all_syncd_pkd &
254 FW_PORT_CMD_ALL_SYNCD)
255 ? CXGB4_DCB_STATE_FW_ALLSYNCED
256 : CXGB4_DCB_STATE_FW_INCOMPLETE);
258 if (dcb->dcb_version != FW_PORT_DCB_VER_UNKNOWN) {
259 dcb_running_version = FW_PORT_CMD_DCB_VERSION_GET(
261 pcmd->u.dcb.control.dcb_version_to_app_state));
262 if (dcb_running_version == FW_PORT_DCB_VER_CEE1D01 ||
263 dcb_running_version == FW_PORT_DCB_VER_IEEE) {
264 dcb->dcb_version = dcb_running_version;
265 dev_warn(adap->pdev_dev, "Interface %s is running %s\n",
267 dcb_ver_array[dcb->dcb_version]);
269 dev_warn(adap->pdev_dev,
270 "Something screwed up, requested firmware for %s, but firmware returned %s instead\n",
271 dcb_ver_array[dcb->dcb_version],
272 dcb_ver_array[dcb_running_version]);
273 dcb->dcb_version = FW_PORT_DCB_VER_UNKNOWN;
277 cxgb4_dcb_state_fsm(dev, input);
281 /* It's weird, and almost certainly an error, to get Firmware DCB
282 * messages when we either haven't been told whether we're going to be
283 * doing Host or Firmware DCB; and even worse when we've been told
284 * that we're doing Host DCB!
286 if (dcb->state == CXGB4_DCB_STATE_START ||
287 dcb->state == CXGB4_DCB_STATE_HOST) {
288 dev_err(adap->pdev_dev, "Receiving Firmware DCB messages in State %d\n",
293 /* Now handle the general Firmware DCB update messages ...
296 case FW_PORT_DCB_TYPE_PGID:
297 dcb->pgid = be32_to_cpu(fwdcb->pgid.pgid);
298 dcb->msgs |= CXGB4_DCB_FW_PGID;
301 case FW_PORT_DCB_TYPE_PGRATE:
302 dcb->pg_num_tcs_supported = fwdcb->pgrate.num_tcs_supported;
303 memcpy(dcb->pgrate, &fwdcb->pgrate.pgrate,
304 sizeof(dcb->pgrate));
305 memcpy(dcb->tsa, &fwdcb->pgrate.tsa,
307 dcb->msgs |= CXGB4_DCB_FW_PGRATE;
308 if (dcb->msgs & CXGB4_DCB_FW_PGID)
309 IEEE_FAUX_SYNC(dev, dcb);
312 case FW_PORT_DCB_TYPE_PRIORATE:
313 memcpy(dcb->priorate, &fwdcb->priorate.strict_priorate,
314 sizeof(dcb->priorate));
315 dcb->msgs |= CXGB4_DCB_FW_PRIORATE;
318 case FW_PORT_DCB_TYPE_PFC:
319 dcb->pfcen = fwdcb->pfc.pfcen;
320 dcb->pfc_num_tcs_supported = fwdcb->pfc.max_pfc_tcs;
321 dcb->msgs |= CXGB4_DCB_FW_PFC;
322 IEEE_FAUX_SYNC(dev, dcb);
325 case FW_PORT_DCB_TYPE_APP_ID: {
326 const struct fw_port_app_priority *fwap = &fwdcb->app_priority;
328 struct app_priority *ap = &dcb->app_priority[idx];
330 struct dcb_app app = {
331 .protocol = be16_to_cpu(fwap->protocolid),
335 /* Convert from firmware format to relevant format
336 * when using app selector
338 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE) {
339 app.selector = (fwap->sel_field + 1);
340 app.priority = ffs(fwap->user_prio_map) - 1;
341 err = dcb_ieee_setapp(dev, &app);
342 IEEE_FAUX_SYNC(dev, dcb);
345 app.selector = !!(fwap->sel_field);
346 app.priority = fwap->user_prio_map;
347 err = dcb_setapp(dev, &app);
351 dev_err(adap->pdev_dev,
352 "Failed DCB Set Application Priority: sel=%d, prot=%d, prio=%d, err=%d\n",
353 app.selector, app.protocol, app.priority, -err);
355 ap->user_prio_map = fwap->user_prio_map;
356 ap->sel_field = fwap->sel_field;
357 ap->protocolid = be16_to_cpu(fwap->protocolid);
358 dcb->msgs |= CXGB4_DCB_FW_APP_ID;
363 dev_err(adap->pdev_dev, "Unknown DCB update type received %x\n",
369 /* Data Center Bridging netlink operations.
373 /* Get current DCB enabled/disabled state.
375 static u8 cxgb4_getstate(struct net_device *dev)
377 struct port_info *pi = netdev2pinfo(dev);
379 return pi->dcb.enabled;
382 /* Set DCB enabled/disabled.
384 static u8 cxgb4_setstate(struct net_device *dev, u8 enabled)
386 struct port_info *pi = netdev2pinfo(dev);
388 /* If DCBx is host-managed, dcb is enabled by outside lldp agents */
389 if (pi->dcb.state == CXGB4_DCB_STATE_HOST) {
390 pi->dcb.enabled = enabled;
394 /* Firmware doesn't provide any mechanism to control the DCB state.
396 if (enabled != (pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED))
402 static void cxgb4_getpgtccfg(struct net_device *dev, int tc,
403 u8 *prio_type, u8 *pgid, u8 *bw_per,
404 u8 *up_tc_map, int local)
406 struct fw_port_cmd pcmd;
407 struct port_info *pi = netdev2pinfo(dev);
408 struct adapter *adap = pi->adapter;
411 *prio_type = *pgid = *bw_per = *up_tc_map = 0;
414 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
416 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
418 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
419 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
420 if (err != FW_PORT_DCB_CFG_SUCCESS) {
421 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
424 *pgid = (be32_to_cpu(pcmd.u.dcb.pgid.pgid) >> (tc * 4)) & 0xf;
426 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
427 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
428 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
429 if (err != FW_PORT_DCB_CFG_SUCCESS) {
430 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
435 *bw_per = pcmd.u.dcb.pgrate.pgrate[*pgid];
436 *up_tc_map = (1 << tc);
438 /* prio_type is link strict */
442 static void cxgb4_getpgtccfg_tx(struct net_device *dev, int tc,
443 u8 *prio_type, u8 *pgid, u8 *bw_per,
446 return cxgb4_getpgtccfg(dev, tc, prio_type, pgid, bw_per, up_tc_map, 1);
450 static void cxgb4_getpgtccfg_rx(struct net_device *dev, int tc,
451 u8 *prio_type, u8 *pgid, u8 *bw_per,
454 return cxgb4_getpgtccfg(dev, tc, prio_type, pgid, bw_per, up_tc_map, 0);
457 static void cxgb4_setpgtccfg_tx(struct net_device *dev, int tc,
458 u8 prio_type, u8 pgid, u8 bw_per,
461 struct fw_port_cmd pcmd;
462 struct port_info *pi = netdev2pinfo(dev);
463 struct adapter *adap = pi->adapter;
467 if (pgid == DCB_ATTR_VALUE_UNDEFINED)
469 if (bw_per == DCB_ATTR_VALUE_UNDEFINED)
472 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
473 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
475 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
476 if (err != FW_PORT_DCB_CFG_SUCCESS) {
477 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
481 _pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
482 _pgid &= ~(0xF << (tc * 4));
483 _pgid |= pgid << (tc * 4);
484 pcmd.u.dcb.pgid.pgid = cpu_to_be32(_pgid);
486 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
488 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
489 if (err != FW_PORT_DCB_CFG_SUCCESS) {
490 dev_err(adap->pdev_dev, "DCB write PGID failed with %d\n",
495 memset(&pcmd, 0, sizeof(struct fw_port_cmd));
497 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
498 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
500 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
501 if (err != FW_PORT_DCB_CFG_SUCCESS) {
502 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
507 pcmd.u.dcb.pgrate.pgrate[pgid] = bw_per;
509 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
510 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
511 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
513 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
514 if (err != FW_PORT_DCB_CFG_SUCCESS)
515 dev_err(adap->pdev_dev, "DCB write PGRATE failed with %d\n",
519 static void cxgb4_getpgbwgcfg(struct net_device *dev, int pgid, u8 *bw_per,
522 struct fw_port_cmd pcmd;
523 struct port_info *pi = netdev2pinfo(dev);
524 struct adapter *adap = pi->adapter;
528 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
530 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
532 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
533 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
534 if (err != FW_PORT_DCB_CFG_SUCCESS) {
535 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
540 *bw_per = pcmd.u.dcb.pgrate.pgrate[pgid];
543 static void cxgb4_getpgbwgcfg_tx(struct net_device *dev, int pgid, u8 *bw_per)
545 return cxgb4_getpgbwgcfg(dev, pgid, bw_per, 1);
548 static void cxgb4_getpgbwgcfg_rx(struct net_device *dev, int pgid, u8 *bw_per)
550 return cxgb4_getpgbwgcfg(dev, pgid, bw_per, 0);
553 static void cxgb4_setpgbwgcfg_tx(struct net_device *dev, int pgid,
556 struct fw_port_cmd pcmd;
557 struct port_info *pi = netdev2pinfo(dev);
558 struct adapter *adap = pi->adapter;
561 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
562 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
564 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
565 if (err != FW_PORT_DCB_CFG_SUCCESS) {
566 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
571 pcmd.u.dcb.pgrate.pgrate[pgid] = bw_per;
573 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
574 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
575 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
577 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
579 if (err != FW_PORT_DCB_CFG_SUCCESS)
580 dev_err(adap->pdev_dev, "DCB write PGRATE failed with %d\n",
584 /* Return whether the specified Traffic Class Priority has Priority Pause
587 static void cxgb4_getpfccfg(struct net_device *dev, int priority, u8 *pfccfg)
589 struct port_info *pi = netdev2pinfo(dev);
590 struct port_dcb_info *dcb = &pi->dcb;
592 if (dcb->state != CXGB4_DCB_STATE_FW_ALLSYNCED ||
593 priority >= CXGB4_MAX_PRIORITY)
596 *pfccfg = (pi->dcb.pfcen >> priority) & 1;
599 /* Enable/disable Priority Pause Frames for the specified Traffic Class
602 static void cxgb4_setpfccfg(struct net_device *dev, int priority, u8 pfccfg)
604 struct fw_port_cmd pcmd;
605 struct port_info *pi = netdev2pinfo(dev);
606 struct adapter *adap = pi->adapter;
609 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED ||
610 priority >= CXGB4_MAX_PRIORITY)
613 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
614 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
615 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
617 pcmd.u.dcb.pfc.type = FW_PORT_DCB_TYPE_PFC;
618 pcmd.u.dcb.pfc.pfcen = pi->dcb.pfcen;
621 pcmd.u.dcb.pfc.pfcen |= (1 << priority);
623 pcmd.u.dcb.pfc.pfcen &= (~(1 << priority));
625 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
626 if (err != FW_PORT_DCB_CFG_SUCCESS) {
627 dev_err(adap->pdev_dev, "DCB PFC write failed with %d\n", -err);
631 pi->dcb.pfcen = pcmd.u.dcb.pfc.pfcen;
634 static u8 cxgb4_setall(struct net_device *dev)
639 /* Return DCB capabilities.
641 static u8 cxgb4_getcap(struct net_device *dev, int cap_id, u8 *caps)
643 struct port_info *pi = netdev2pinfo(dev);
646 case DCB_CAP_ATTR_PG:
647 case DCB_CAP_ATTR_PFC:
651 case DCB_CAP_ATTR_PG_TCS:
652 /* 8 priorities for PG represented by bitmap */
656 case DCB_CAP_ATTR_PFC_TCS:
657 /* 8 priorities for PFC represented by bitmap */
661 case DCB_CAP_ATTR_GSP:
665 case DCB_CAP_ATTR_UP2TC:
666 case DCB_CAP_ATTR_BCN:
670 case DCB_CAP_ATTR_DCBX:
671 *caps = pi->dcb.supported;
681 /* Return the number of Traffic Classes for the indicated Traffic Class ID.
683 static int cxgb4_getnumtcs(struct net_device *dev, int tcs_id, u8 *num)
685 struct port_info *pi = netdev2pinfo(dev);
688 case DCB_NUMTCS_ATTR_PG:
689 if (pi->dcb.msgs & CXGB4_DCB_FW_PGRATE)
690 *num = pi->dcb.pg_num_tcs_supported;
695 case DCB_NUMTCS_ATTR_PFC:
706 /* Set the number of Traffic Classes supported for the indicated Traffic Class
709 static int cxgb4_setnumtcs(struct net_device *dev, int tcs_id, u8 num)
711 /* Setting the number of Traffic Classes isn't supported.
716 /* Return whether Priority Flow Control is enabled. */
717 static u8 cxgb4_getpfcstate(struct net_device *dev)
719 struct port_info *pi = netdev2pinfo(dev);
721 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
724 return pi->dcb.pfcen != 0;
727 /* Enable/disable Priority Flow Control. */
728 static void cxgb4_setpfcstate(struct net_device *dev, u8 state)
730 /* We can't enable/disable Priority Flow Control but we also can't
731 * return an error ...
735 /* Return the Application User Priority Map associated with the specified
738 static int __cxgb4_getapp(struct net_device *dev, u8 app_idtype, u16 app_id,
741 struct port_info *pi = netdev2pinfo(dev);
742 struct adapter *adap = pi->adapter;
745 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
748 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
749 struct fw_port_cmd pcmd;
753 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
755 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
757 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
758 pcmd.u.dcb.app_priority.idx = i;
760 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
761 if (err != FW_PORT_DCB_CFG_SUCCESS) {
762 dev_err(adap->pdev_dev, "DCB APP read failed with %d\n",
766 if (be16_to_cpu(pcmd.u.dcb.app_priority.protocolid) == app_id)
767 if (pcmd.u.dcb.app_priority.sel_field == app_idtype)
768 return pcmd.u.dcb.app_priority.user_prio_map;
770 /* exhausted app list */
771 if (!pcmd.u.dcb.app_priority.protocolid)
778 /* Return the Application User Priority Map associated with the specified
781 static int cxgb4_getapp(struct net_device *dev, u8 app_idtype, u16 app_id)
783 return __cxgb4_getapp(dev, app_idtype, app_id, 0);
786 /* Write a new Application User Priority Map for the specified Application ID
788 static int __cxgb4_setapp(struct net_device *dev, u8 app_idtype, u16 app_id,
791 struct fw_port_cmd pcmd;
792 struct port_info *pi = netdev2pinfo(dev);
793 struct adapter *adap = pi->adapter;
797 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
800 /* DCB info gets thrown away on link up */
801 if (!netif_carrier_ok(dev))
804 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
805 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
806 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
807 pcmd.u.dcb.app_priority.idx = i;
808 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
810 if (err != FW_PORT_DCB_CFG_SUCCESS) {
811 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
815 if (be16_to_cpu(pcmd.u.dcb.app_priority.protocolid) == app_id) {
816 /* overwrite existing app table */
817 pcmd.u.dcb.app_priority.protocolid = 0;
820 /* find first empty slot */
821 if (!pcmd.u.dcb.app_priority.protocolid)
825 if (i == CXGB4_MAX_DCBX_APP_SUPPORTED) {
826 /* no empty slots available */
827 dev_err(adap->pdev_dev, "DCB app table full\n");
831 /* write out new app table entry */
832 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
833 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
834 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
836 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
837 pcmd.u.dcb.app_priority.protocolid = cpu_to_be16(app_id);
838 pcmd.u.dcb.app_priority.sel_field = app_idtype;
839 pcmd.u.dcb.app_priority.user_prio_map = app_prio;
840 pcmd.u.dcb.app_priority.idx = i;
842 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
843 if (err != FW_PORT_DCB_CFG_SUCCESS) {
844 dev_err(adap->pdev_dev, "DCB app table write failed with %d\n",
852 /* Priority for CEE inside dcb_app is bitmask, with 0 being an invalid value */
853 static int cxgb4_setapp(struct net_device *dev, u8 app_idtype, u16 app_id,
857 struct dcb_app app = {
858 .selector = app_idtype,
860 .priority = app_prio,
863 if (app_idtype != DCB_APP_IDTYPE_ETHTYPE &&
864 app_idtype != DCB_APP_IDTYPE_PORTNUM)
867 /* Convert app_idtype to a format that firmware understands */
868 ret = __cxgb4_setapp(dev, app_idtype == DCB_APP_IDTYPE_ETHTYPE ?
869 app_idtype : 3, app_id, app_prio);
873 return dcb_setapp(dev, &app);
876 /* Return whether IEEE Data Center Bridging has been negotiated.
879 cxgb4_ieee_negotiation_complete(struct net_device *dev,
880 enum cxgb4_dcb_fw_msgs dcb_subtype)
882 struct port_info *pi = netdev2pinfo(dev);
883 struct port_dcb_info *dcb = &pi->dcb;
885 if (dcb_subtype && !(dcb->msgs & dcb_subtype))
888 return (dcb->state == CXGB4_DCB_STATE_FW_ALLSYNCED &&
889 (dcb->supported & DCB_CAP_DCBX_VER_IEEE));
892 /* Fill in the Application User Priority Map associated with the
893 * specified Application.
894 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
896 static int cxgb4_ieee_getapp(struct net_device *dev, struct dcb_app *app)
900 if (!cxgb4_ieee_negotiation_complete(dev, CXGB4_DCB_FW_APP_ID))
902 if (!(app->selector && app->protocol))
905 /* Try querying firmware first, use firmware format */
906 prio = __cxgb4_getapp(dev, app->selector - 1, app->protocol, 0);
909 prio = dcb_ieee_getapp_mask(dev, app);
911 app->priority = ffs(prio) - 1;
915 /* Write a new Application User Priority Map for the specified Application ID.
916 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
918 static int cxgb4_ieee_setapp(struct net_device *dev, struct dcb_app *app)
922 if (!cxgb4_ieee_negotiation_complete(dev, CXGB4_DCB_FW_APP_ID))
924 if (!(app->selector && app->protocol))
927 if (!(app->selector > IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
928 app->selector < IEEE_8021QAZ_APP_SEL_ANY))
931 /* change selector to a format that firmware understands */
932 ret = __cxgb4_setapp(dev, app->selector - 1, app->protocol,
933 (1 << app->priority));
937 return dcb_ieee_setapp(dev, app);
940 /* Return our DCBX parameters.
942 static u8 cxgb4_getdcbx(struct net_device *dev)
944 struct port_info *pi = netdev2pinfo(dev);
946 /* This is already set by cxgb4_set_dcb_caps, so just return it */
947 return pi->dcb.supported;
950 /* Set our DCBX parameters.
952 static u8 cxgb4_setdcbx(struct net_device *dev, u8 dcb_request)
954 struct port_info *pi = netdev2pinfo(dev);
956 /* Filter out requests which exceed our capabilities.
958 if ((dcb_request & (CXGB4_DCBX_FW_SUPPORT | CXGB4_DCBX_HOST_SUPPORT))
962 /* Can't enable DCB if we haven't successfully negotiated it.
964 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
967 /* There's currently no mechanism to allow for the firmware DCBX
968 * negotiation to be changed from the Host Driver. If the caller
969 * requests exactly the same parameters that we already have then
970 * we'll allow them to be successfully "set" ...
972 if (dcb_request != pi->dcb.supported)
975 pi->dcb.supported = dcb_request;
979 static int cxgb4_getpeer_app(struct net_device *dev,
980 struct dcb_peer_app_info *info, u16 *app_count)
982 struct fw_port_cmd pcmd;
983 struct port_info *pi = netdev2pinfo(dev);
984 struct adapter *adap = pi->adapter;
987 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
994 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
995 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
996 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
997 pcmd.u.dcb.app_priority.idx = *app_count;
998 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1000 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1001 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
1006 /* find first empty slot */
1007 if (!pcmd.u.dcb.app_priority.protocolid)
1014 static int cxgb4_getpeerapp_tbl(struct net_device *dev, struct dcb_app *table)
1016 struct fw_port_cmd pcmd;
1017 struct port_info *pi = netdev2pinfo(dev);
1018 struct adapter *adap = pi->adapter;
1021 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
1024 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
1025 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1026 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
1027 pcmd.u.dcb.app_priority.idx = i;
1028 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1030 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1031 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
1036 /* find first empty slot */
1037 if (!pcmd.u.dcb.app_priority.protocolid)
1040 table[i].selector = pcmd.u.dcb.app_priority.sel_field;
1042 be16_to_cpu(pcmd.u.dcb.app_priority.protocolid);
1044 ffs(pcmd.u.dcb.app_priority.user_prio_map) - 1;
1049 /* Return Priority Group information.
1051 static int cxgb4_cee_peer_getpg(struct net_device *dev, struct cee_pg *pg)
1053 struct fw_port_cmd pcmd;
1054 struct port_info *pi = netdev2pinfo(dev);
1055 struct adapter *adap = pi->adapter;
1059 /* We're always "willing" -- the Switch Fabric always dictates the
1060 * DCBX parameters to us.
1064 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1065 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
1066 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1067 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1068 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
1071 pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
1073 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1074 pg->prio_pg[i] = (pgid >> (i * 4)) & 0xF;
1076 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1077 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
1078 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1079 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1080 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
1085 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1086 pg->pg_bw[i] = pcmd.u.dcb.pgrate.pgrate[i];
1091 /* Return Priority Flow Control information.
1093 static int cxgb4_cee_peer_getpfc(struct net_device *dev, struct cee_pfc *pfc)
1095 struct port_info *pi = netdev2pinfo(dev);
1097 cxgb4_getnumtcs(dev, DCB_NUMTCS_ATTR_PFC, &(pfc->tcs_supported));
1098 pfc->pfc_en = pi->dcb.pfcen;
1103 const struct dcbnl_rtnl_ops cxgb4_dcb_ops = {
1104 .ieee_getapp = cxgb4_ieee_getapp,
1105 .ieee_setapp = cxgb4_ieee_setapp,
1108 .getstate = cxgb4_getstate,
1109 .setstate = cxgb4_setstate,
1110 .getpgtccfgtx = cxgb4_getpgtccfg_tx,
1111 .getpgbwgcfgtx = cxgb4_getpgbwgcfg_tx,
1112 .getpgtccfgrx = cxgb4_getpgtccfg_rx,
1113 .getpgbwgcfgrx = cxgb4_getpgbwgcfg_rx,
1114 .setpgtccfgtx = cxgb4_setpgtccfg_tx,
1115 .setpgbwgcfgtx = cxgb4_setpgbwgcfg_tx,
1116 .setpfccfg = cxgb4_setpfccfg,
1117 .getpfccfg = cxgb4_getpfccfg,
1118 .setall = cxgb4_setall,
1119 .getcap = cxgb4_getcap,
1120 .getnumtcs = cxgb4_getnumtcs,
1121 .setnumtcs = cxgb4_setnumtcs,
1122 .getpfcstate = cxgb4_getpfcstate,
1123 .setpfcstate = cxgb4_setpfcstate,
1124 .getapp = cxgb4_getapp,
1125 .setapp = cxgb4_setapp,
1127 /* DCBX configuration */
1128 .getdcbx = cxgb4_getdcbx,
1129 .setdcbx = cxgb4_setdcbx,
1132 .peer_getappinfo = cxgb4_getpeer_app,
1133 .peer_getapptable = cxgb4_getpeerapp_tbl,
1136 .cee_peer_getpg = cxgb4_cee_peer_getpg,
1137 .cee_peer_getpfc = cxgb4_cee_peer_getpfc,