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 /* Finite State machine for Data Center Bridging.
65 void cxgb4_dcb_state_fsm(struct net_device *dev,
66 enum cxgb4_dcb_state_input transition_to)
68 struct port_info *pi = netdev2pinfo(dev);
69 struct port_dcb_info *dcb = &pi->dcb;
70 struct adapter *adap = pi->adapter;
71 enum cxgb4_dcb_state current_state = dcb->state;
73 netdev_dbg(dev, "%s: State change from %d to %d for %s\n",
74 __func__, dcb->state, transition_to, dev->name);
76 switch (current_state) {
77 case CXGB4_DCB_STATE_START: {
78 switch (transition_to) {
79 case CXGB4_DCB_INPUT_FW_DISABLED: {
80 /* we're going to use Host DCB */
81 dcb->state = CXGB4_DCB_STATE_HOST;
82 dcb->supported = CXGB4_DCBX_HOST_SUPPORT;
87 case CXGB4_DCB_INPUT_FW_ENABLED: {
88 /* we're going to use Firmware DCB */
89 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE;
90 dcb->supported = CXGB4_DCBX_FW_SUPPORT;
94 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
95 /* expected transition */
99 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
100 dcb->state = CXGB4_DCB_STATE_FW_ALLSYNCED;
105 goto bad_state_input;
110 case CXGB4_DCB_STATE_FW_INCOMPLETE: {
111 switch (transition_to) {
112 case CXGB4_DCB_INPUT_FW_ENABLED: {
113 /* we're alreaady in firmware DCB mode */
117 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
118 /* we're already incomplete */
122 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
123 dcb->state = CXGB4_DCB_STATE_FW_ALLSYNCED;
125 linkwatch_fire_event(dev);
130 goto bad_state_input;
135 case CXGB4_DCB_STATE_FW_ALLSYNCED: {
136 switch (transition_to) {
137 case CXGB4_DCB_INPUT_FW_ENABLED: {
138 /* we're alreaady in firmware DCB mode */
142 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
143 /* We were successfully running with firmware DCB but
144 * now it's telling us that it's in an "incomplete
145 * state. We need to reset back to a ground state
148 cxgb4_dcb_state_init(dev);
149 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE;
150 dcb->supported = CXGB4_DCBX_FW_SUPPORT;
151 linkwatch_fire_event(dev);
155 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
156 /* we're already all sync'ed
157 * this is only applicable for IEEE or
158 * when another VI already completed negotiaton
161 linkwatch_fire_event(dev);
166 goto bad_state_input;
171 case CXGB4_DCB_STATE_HOST: {
172 switch (transition_to) {
173 case CXGB4_DCB_INPUT_FW_DISABLED: {
174 /* we're alreaady in Host DCB mode */
179 goto bad_state_input;
185 goto bad_state_transition;
190 dev_err(adap->pdev_dev, "cxgb4_dcb_state_fsm: illegal input symbol %d\n",
194 bad_state_transition:
195 dev_err(adap->pdev_dev, "cxgb4_dcb_state_fsm: bad state transition, state = %d, input = %d\n",
196 current_state, transition_to);
199 /* Handle a DCB/DCBX update message from the firmware.
201 void cxgb4_dcb_handle_fw_update(struct adapter *adap,
202 const struct fw_port_cmd *pcmd)
204 const union fw_port_dcb *fwdcb = &pcmd->u.dcb;
205 int port = FW_PORT_CMD_PORTID_GET(be32_to_cpu(pcmd->op_to_portid));
206 struct net_device *dev = adap->port[port];
207 struct port_info *pi = netdev_priv(dev);
208 struct port_dcb_info *dcb = &pi->dcb;
209 int dcb_type = pcmd->u.dcb.pgid.type;
210 int dcb_running_version;
212 /* Handle Firmware DCB Control messages separately since they drive
215 if (dcb_type == FW_PORT_DCB_TYPE_CONTROL) {
216 enum cxgb4_dcb_state_input input =
217 ((pcmd->u.dcb.control.all_syncd_pkd &
218 FW_PORT_CMD_ALL_SYNCD)
219 ? CXGB4_DCB_STATE_FW_ALLSYNCED
220 : CXGB4_DCB_STATE_FW_INCOMPLETE);
222 if (dcb->dcb_version != FW_PORT_DCB_VER_UNKNOWN) {
223 dcb_running_version = FW_PORT_CMD_DCB_VERSION_GET(
225 pcmd->u.dcb.control.dcb_version_to_app_state));
226 if (dcb_running_version == FW_PORT_DCB_VER_CEE1D01 ||
227 dcb_running_version == FW_PORT_DCB_VER_IEEE) {
228 dcb->dcb_version = dcb_running_version;
229 dev_warn(adap->pdev_dev, "Interface %s is running %s\n",
231 dcb_ver_array[dcb->dcb_version]);
233 dev_warn(adap->pdev_dev,
234 "Something screwed up, requested firmware for %s, but firmware returned %s instead\n",
235 dcb_ver_array[dcb->dcb_version],
236 dcb_ver_array[dcb_running_version]);
237 dcb->dcb_version = FW_PORT_DCB_VER_UNKNOWN;
241 cxgb4_dcb_state_fsm(dev, input);
245 /* It's weird, and almost certainly an error, to get Firmware DCB
246 * messages when we either haven't been told whether we're going to be
247 * doing Host or Firmware DCB; and even worse when we've been told
248 * that we're doing Host DCB!
250 if (dcb->state == CXGB4_DCB_STATE_START ||
251 dcb->state == CXGB4_DCB_STATE_HOST) {
252 dev_err(adap->pdev_dev, "Receiving Firmware DCB messages in State %d\n",
257 /* Now handle the general Firmware DCB update messages ...
260 case FW_PORT_DCB_TYPE_PGID:
261 dcb->pgid = be32_to_cpu(fwdcb->pgid.pgid);
262 dcb->msgs |= CXGB4_DCB_FW_PGID;
265 case FW_PORT_DCB_TYPE_PGRATE:
266 dcb->pg_num_tcs_supported = fwdcb->pgrate.num_tcs_supported;
267 memcpy(dcb->pgrate, &fwdcb->pgrate.pgrate,
268 sizeof(dcb->pgrate));
269 memcpy(dcb->tsa, &fwdcb->pgrate.tsa,
271 dcb->msgs |= CXGB4_DCB_FW_PGRATE;
272 if (dcb->msgs & CXGB4_DCB_FW_PGID)
273 IEEE_FAUX_SYNC(dev, dcb);
276 case FW_PORT_DCB_TYPE_PRIORATE:
277 memcpy(dcb->priorate, &fwdcb->priorate.strict_priorate,
278 sizeof(dcb->priorate));
279 dcb->msgs |= CXGB4_DCB_FW_PRIORATE;
282 case FW_PORT_DCB_TYPE_PFC:
283 dcb->pfcen = fwdcb->pfc.pfcen;
284 dcb->pfc_num_tcs_supported = fwdcb->pfc.max_pfc_tcs;
285 dcb->msgs |= CXGB4_DCB_FW_PFC;
286 IEEE_FAUX_SYNC(dev, dcb);
289 case FW_PORT_DCB_TYPE_APP_ID: {
290 const struct fw_port_app_priority *fwap = &fwdcb->app_priority;
292 struct app_priority *ap = &dcb->app_priority[idx];
294 struct dcb_app app = {
295 .protocol = be16_to_cpu(fwap->protocolid),
299 /* Convert from firmware format to relevant format
300 * when using app selector
302 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE) {
303 app.selector = (fwap->sel_field + 1);
304 app.priority = ffs(fwap->user_prio_map) - 1;
305 err = dcb_ieee_setapp(dev, &app);
306 IEEE_FAUX_SYNC(dev, dcb);
309 app.selector = !!(fwap->sel_field);
310 app.priority = fwap->user_prio_map;
311 err = dcb_setapp(dev, &app);
315 dev_err(adap->pdev_dev,
316 "Failed DCB Set Application Priority: sel=%d, prot=%d, prio=%d, err=%d\n",
317 app.selector, app.protocol, app.priority, -err);
319 ap->user_prio_map = fwap->user_prio_map;
320 ap->sel_field = fwap->sel_field;
321 ap->protocolid = be16_to_cpu(fwap->protocolid);
322 dcb->msgs |= CXGB4_DCB_FW_APP_ID;
327 dev_err(adap->pdev_dev, "Unknown DCB update type received %x\n",
333 /* Data Center Bridging netlink operations.
337 /* Get current DCB enabled/disabled state.
339 static u8 cxgb4_getstate(struct net_device *dev)
341 struct port_info *pi = netdev2pinfo(dev);
343 return pi->dcb.enabled;
346 /* Set DCB enabled/disabled.
348 static u8 cxgb4_setstate(struct net_device *dev, u8 enabled)
350 struct port_info *pi = netdev2pinfo(dev);
352 /* Firmware doesn't provide any mechanism to control the DCB state.
354 if (enabled != (pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED))
360 static void cxgb4_getpgtccfg(struct net_device *dev, int tc,
361 u8 *prio_type, u8 *pgid, u8 *bw_per,
362 u8 *up_tc_map, int local)
364 struct fw_port_cmd pcmd;
365 struct port_info *pi = netdev2pinfo(dev);
366 struct adapter *adap = pi->adapter;
369 *prio_type = *pgid = *bw_per = *up_tc_map = 0;
372 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
374 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
376 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
377 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
378 if (err != FW_PORT_DCB_CFG_SUCCESS) {
379 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
382 *pgid = (be32_to_cpu(pcmd.u.dcb.pgid.pgid) >> (tc * 4)) & 0xf;
384 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
385 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
386 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
387 if (err != FW_PORT_DCB_CFG_SUCCESS) {
388 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
393 *bw_per = pcmd.u.dcb.pgrate.pgrate[*pgid];
394 *up_tc_map = (1 << tc);
396 /* prio_type is link strict */
400 static void cxgb4_getpgtccfg_tx(struct net_device *dev, int tc,
401 u8 *prio_type, u8 *pgid, u8 *bw_per,
404 return cxgb4_getpgtccfg(dev, tc, prio_type, pgid, bw_per, up_tc_map, 1);
408 static void cxgb4_getpgtccfg_rx(struct net_device *dev, int tc,
409 u8 *prio_type, u8 *pgid, u8 *bw_per,
412 return cxgb4_getpgtccfg(dev, tc, prio_type, pgid, bw_per, up_tc_map, 0);
415 static void cxgb4_setpgtccfg_tx(struct net_device *dev, int tc,
416 u8 prio_type, u8 pgid, u8 bw_per,
419 struct fw_port_cmd pcmd;
420 struct port_info *pi = netdev2pinfo(dev);
421 struct adapter *adap = pi->adapter;
425 if (pgid == DCB_ATTR_VALUE_UNDEFINED)
427 if (bw_per == DCB_ATTR_VALUE_UNDEFINED)
430 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
431 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
433 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
434 if (err != FW_PORT_DCB_CFG_SUCCESS) {
435 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
439 _pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
440 _pgid &= ~(0xF << (tc * 4));
441 _pgid |= pgid << (tc * 4);
442 pcmd.u.dcb.pgid.pgid = cpu_to_be32(_pgid);
444 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
446 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
447 if (err != FW_PORT_DCB_CFG_SUCCESS) {
448 dev_err(adap->pdev_dev, "DCB write PGID failed with %d\n",
453 memset(&pcmd, 0, sizeof(struct fw_port_cmd));
455 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
456 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
458 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
459 if (err != FW_PORT_DCB_CFG_SUCCESS) {
460 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
465 pcmd.u.dcb.pgrate.pgrate[pgid] = bw_per;
467 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
468 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
469 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
471 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
472 if (err != FW_PORT_DCB_CFG_SUCCESS)
473 dev_err(adap->pdev_dev, "DCB write PGRATE failed with %d\n",
477 static void cxgb4_getpgbwgcfg(struct net_device *dev, int pgid, u8 *bw_per,
480 struct fw_port_cmd pcmd;
481 struct port_info *pi = netdev2pinfo(dev);
482 struct adapter *adap = pi->adapter;
486 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
488 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
490 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
491 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
492 if (err != FW_PORT_DCB_CFG_SUCCESS) {
493 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
498 *bw_per = pcmd.u.dcb.pgrate.pgrate[pgid];
501 static void cxgb4_getpgbwgcfg_tx(struct net_device *dev, int pgid, u8 *bw_per)
503 return cxgb4_getpgbwgcfg(dev, pgid, bw_per, 1);
506 static void cxgb4_getpgbwgcfg_rx(struct net_device *dev, int pgid, u8 *bw_per)
508 return cxgb4_getpgbwgcfg(dev, pgid, bw_per, 0);
511 static void cxgb4_setpgbwgcfg_tx(struct net_device *dev, int pgid,
514 struct fw_port_cmd pcmd;
515 struct port_info *pi = netdev2pinfo(dev);
516 struct adapter *adap = pi->adapter;
519 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
520 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
522 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
523 if (err != FW_PORT_DCB_CFG_SUCCESS) {
524 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
529 pcmd.u.dcb.pgrate.pgrate[pgid] = bw_per;
531 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
532 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
533 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
535 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
537 if (err != FW_PORT_DCB_CFG_SUCCESS)
538 dev_err(adap->pdev_dev, "DCB write PGRATE failed with %d\n",
542 /* Return whether the specified Traffic Class Priority has Priority Pause
545 static void cxgb4_getpfccfg(struct net_device *dev, int priority, u8 *pfccfg)
547 struct port_info *pi = netdev2pinfo(dev);
548 struct port_dcb_info *dcb = &pi->dcb;
550 if (dcb->state != CXGB4_DCB_STATE_FW_ALLSYNCED ||
551 priority >= CXGB4_MAX_PRIORITY)
554 *pfccfg = (pi->dcb.pfcen >> priority) & 1;
557 /* Enable/disable Priority Pause Frames for the specified Traffic Class
560 static void cxgb4_setpfccfg(struct net_device *dev, int priority, u8 pfccfg)
562 struct fw_port_cmd pcmd;
563 struct port_info *pi = netdev2pinfo(dev);
564 struct adapter *adap = pi->adapter;
567 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED ||
568 priority >= CXGB4_MAX_PRIORITY)
571 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
572 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
573 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
575 pcmd.u.dcb.pfc.type = FW_PORT_DCB_TYPE_PFC;
576 pcmd.u.dcb.pfc.pfcen = pi->dcb.pfcen;
579 pcmd.u.dcb.pfc.pfcen |= (1 << priority);
581 pcmd.u.dcb.pfc.pfcen &= (~(1 << priority));
583 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
584 if (err != FW_PORT_DCB_CFG_SUCCESS) {
585 dev_err(adap->pdev_dev, "DCB PFC write failed with %d\n", -err);
589 pi->dcb.pfcen = pcmd.u.dcb.pfc.pfcen;
592 static u8 cxgb4_setall(struct net_device *dev)
597 /* Return DCB capabilities.
599 static u8 cxgb4_getcap(struct net_device *dev, int cap_id, u8 *caps)
601 struct port_info *pi = netdev2pinfo(dev);
604 case DCB_CAP_ATTR_PG:
605 case DCB_CAP_ATTR_PFC:
609 case DCB_CAP_ATTR_PG_TCS:
610 /* 8 priorities for PG represented by bitmap */
614 case DCB_CAP_ATTR_PFC_TCS:
615 /* 8 priorities for PFC represented by bitmap */
619 case DCB_CAP_ATTR_GSP:
623 case DCB_CAP_ATTR_UP2TC:
624 case DCB_CAP_ATTR_BCN:
628 case DCB_CAP_ATTR_DCBX:
629 *caps = pi->dcb.supported;
639 /* Return the number of Traffic Classes for the indicated Traffic Class ID.
641 static int cxgb4_getnumtcs(struct net_device *dev, int tcs_id, u8 *num)
643 struct port_info *pi = netdev2pinfo(dev);
646 case DCB_NUMTCS_ATTR_PG:
647 if (pi->dcb.msgs & CXGB4_DCB_FW_PGRATE)
648 *num = pi->dcb.pg_num_tcs_supported;
653 case DCB_NUMTCS_ATTR_PFC:
664 /* Set the number of Traffic Classes supported for the indicated Traffic Class
667 static int cxgb4_setnumtcs(struct net_device *dev, int tcs_id, u8 num)
669 /* Setting the number of Traffic Classes isn't supported.
674 /* Return whether Priority Flow Control is enabled. */
675 static u8 cxgb4_getpfcstate(struct net_device *dev)
677 struct port_info *pi = netdev2pinfo(dev);
679 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
682 return pi->dcb.pfcen != 0;
685 /* Enable/disable Priority Flow Control. */
686 static void cxgb4_setpfcstate(struct net_device *dev, u8 state)
688 /* We can't enable/disable Priority Flow Control but we also can't
689 * return an error ...
693 /* Return the Application User Priority Map associated with the specified
696 static int __cxgb4_getapp(struct net_device *dev, u8 app_idtype, u16 app_id,
699 struct port_info *pi = netdev2pinfo(dev);
700 struct adapter *adap = pi->adapter;
703 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
706 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
707 struct fw_port_cmd pcmd;
711 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
713 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
715 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
716 pcmd.u.dcb.app_priority.idx = i;
718 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
719 if (err != FW_PORT_DCB_CFG_SUCCESS) {
720 dev_err(adap->pdev_dev, "DCB APP read failed with %d\n",
724 if (be16_to_cpu(pcmd.u.dcb.app_priority.protocolid) == app_id)
725 if (pcmd.u.dcb.app_priority.sel_field == app_idtype)
726 return pcmd.u.dcb.app_priority.user_prio_map;
728 /* exhausted app list */
729 if (!pcmd.u.dcb.app_priority.protocolid)
736 /* Return the Application User Priority Map associated with the specified
739 static int cxgb4_getapp(struct net_device *dev, u8 app_idtype, u16 app_id)
741 return __cxgb4_getapp(dev, app_idtype, app_id, 0);
744 /* Write a new Application User Priority Map for the specified Application ID
746 static int __cxgb4_setapp(struct net_device *dev, u8 app_idtype, u16 app_id,
749 struct fw_port_cmd pcmd;
750 struct port_info *pi = netdev2pinfo(dev);
751 struct adapter *adap = pi->adapter;
755 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
758 /* DCB info gets thrown away on link up */
759 if (!netif_carrier_ok(dev))
762 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
763 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
764 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
765 pcmd.u.dcb.app_priority.idx = i;
766 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
768 if (err != FW_PORT_DCB_CFG_SUCCESS) {
769 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
773 if (be16_to_cpu(pcmd.u.dcb.app_priority.protocolid) == app_id) {
774 /* overwrite existing app table */
775 pcmd.u.dcb.app_priority.protocolid = 0;
778 /* find first empty slot */
779 if (!pcmd.u.dcb.app_priority.protocolid)
783 if (i == CXGB4_MAX_DCBX_APP_SUPPORTED) {
784 /* no empty slots available */
785 dev_err(adap->pdev_dev, "DCB app table full\n");
789 /* write out new app table entry */
790 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
791 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
792 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
794 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
795 pcmd.u.dcb.app_priority.protocolid = cpu_to_be16(app_id);
796 pcmd.u.dcb.app_priority.sel_field = app_idtype;
797 pcmd.u.dcb.app_priority.user_prio_map = app_prio;
798 pcmd.u.dcb.app_priority.idx = i;
800 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
801 if (err != FW_PORT_DCB_CFG_SUCCESS) {
802 dev_err(adap->pdev_dev, "DCB app table write failed with %d\n",
810 /* Priority for CEE inside dcb_app is bitmask, with 0 being an invalid value */
811 static int cxgb4_setapp(struct net_device *dev, u8 app_idtype, u16 app_id,
815 struct dcb_app app = {
816 .selector = app_idtype,
818 .priority = app_prio,
821 if (app_idtype != DCB_APP_IDTYPE_ETHTYPE &&
822 app_idtype != DCB_APP_IDTYPE_PORTNUM)
825 /* Convert app_idtype to a format that firmware understands */
826 ret = __cxgb4_setapp(dev, app_idtype == DCB_APP_IDTYPE_ETHTYPE ?
827 app_idtype : 3, app_id, app_prio);
831 return dcb_setapp(dev, &app);
834 /* Return whether IEEE Data Center Bridging has been negotiated.
836 static inline int cxgb4_ieee_negotiation_complete(struct net_device *dev)
838 struct port_info *pi = netdev2pinfo(dev);
839 struct port_dcb_info *dcb = &pi->dcb;
841 return (dcb->state == CXGB4_DCB_STATE_FW_ALLSYNCED &&
842 (dcb->supported & DCB_CAP_DCBX_VER_IEEE));
845 /* Fill in the Application User Priority Map associated with the
846 * specified Application.
847 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
849 static int cxgb4_ieee_getapp(struct net_device *dev, struct dcb_app *app)
853 if (!cxgb4_ieee_negotiation_complete(dev))
855 if (!(app->selector && app->protocol))
858 /* Try querying firmware first, use firmware format */
859 prio = __cxgb4_getapp(dev, app->selector - 1, app->protocol, 0);
862 prio = dcb_ieee_getapp_mask(dev, app);
864 app->priority = ffs(prio) - 1;
868 /* Write a new Application User Priority Map for the specified Application ID.
869 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
871 static int cxgb4_ieee_setapp(struct net_device *dev, struct dcb_app *app)
875 if (!cxgb4_ieee_negotiation_complete(dev))
877 if (!(app->selector && app->protocol))
880 if (!(app->selector > IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
881 app->selector < IEEE_8021QAZ_APP_SEL_ANY))
884 /* change selector to a format that firmware understands */
885 ret = __cxgb4_setapp(dev, app->selector - 1, app->protocol,
886 (1 << app->priority));
890 return dcb_ieee_setapp(dev, app);
893 /* Return our DCBX parameters.
895 static u8 cxgb4_getdcbx(struct net_device *dev)
897 struct port_info *pi = netdev2pinfo(dev);
899 /* This is already set by cxgb4_set_dcb_caps, so just return it */
900 return pi->dcb.supported;
903 /* Set our DCBX parameters.
905 static u8 cxgb4_setdcbx(struct net_device *dev, u8 dcb_request)
907 struct port_info *pi = netdev2pinfo(dev);
909 /* Filter out requests which exceed our capabilities.
911 if ((dcb_request & (CXGB4_DCBX_FW_SUPPORT | CXGB4_DCBX_HOST_SUPPORT))
915 /* Can't enable DCB if we haven't successfully negotiated it.
917 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
920 /* There's currently no mechanism to allow for the firmware DCBX
921 * negotiation to be changed from the Host Driver. If the caller
922 * requests exactly the same parameters that we already have then
923 * we'll allow them to be successfully "set" ...
925 if (dcb_request != pi->dcb.supported)
928 pi->dcb.supported = dcb_request;
932 static int cxgb4_getpeer_app(struct net_device *dev,
933 struct dcb_peer_app_info *info, u16 *app_count)
935 struct fw_port_cmd pcmd;
936 struct port_info *pi = netdev2pinfo(dev);
937 struct adapter *adap = pi->adapter;
940 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
947 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
948 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
949 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
950 pcmd.u.dcb.app_priority.idx = *app_count;
951 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
953 if (err != FW_PORT_DCB_CFG_SUCCESS) {
954 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
959 /* find first empty slot */
960 if (!pcmd.u.dcb.app_priority.protocolid)
967 static int cxgb4_getpeerapp_tbl(struct net_device *dev, struct dcb_app *table)
969 struct fw_port_cmd pcmd;
970 struct port_info *pi = netdev2pinfo(dev);
971 struct adapter *adap = pi->adapter;
974 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
977 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
978 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
979 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
980 pcmd.u.dcb.app_priority.idx = i;
981 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
983 if (err != FW_PORT_DCB_CFG_SUCCESS) {
984 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
989 /* find first empty slot */
990 if (!pcmd.u.dcb.app_priority.protocolid)
993 table[i].selector = pcmd.u.dcb.app_priority.sel_field;
995 be16_to_cpu(pcmd.u.dcb.app_priority.protocolid);
997 ffs(pcmd.u.dcb.app_priority.user_prio_map) - 1;
1002 /* Return Priority Group information.
1004 static int cxgb4_cee_peer_getpg(struct net_device *dev, struct cee_pg *pg)
1006 struct fw_port_cmd pcmd;
1007 struct port_info *pi = netdev2pinfo(dev);
1008 struct adapter *adap = pi->adapter;
1012 /* We're always "willing" -- the Switch Fabric always dictates the
1013 * DCBX parameters to us.
1017 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1018 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
1019 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1020 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1021 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
1024 pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
1026 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1027 pg->prio_pg[i] = (pgid >> (i * 4)) & 0xF;
1029 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1030 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
1031 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1032 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1033 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
1038 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1039 pg->pg_bw[i] = pcmd.u.dcb.pgrate.pgrate[i];
1044 /* Return Priority Flow Control information.
1046 static int cxgb4_cee_peer_getpfc(struct net_device *dev, struct cee_pfc *pfc)
1048 struct port_info *pi = netdev2pinfo(dev);
1050 cxgb4_getnumtcs(dev, DCB_NUMTCS_ATTR_PFC, &(pfc->tcs_supported));
1051 pfc->pfc_en = pi->dcb.pfcen;
1056 const struct dcbnl_rtnl_ops cxgb4_dcb_ops = {
1057 .ieee_getapp = cxgb4_ieee_getapp,
1058 .ieee_setapp = cxgb4_ieee_setapp,
1061 .getstate = cxgb4_getstate,
1062 .setstate = cxgb4_setstate,
1063 .getpgtccfgtx = cxgb4_getpgtccfg_tx,
1064 .getpgbwgcfgtx = cxgb4_getpgbwgcfg_tx,
1065 .getpgtccfgrx = cxgb4_getpgtccfg_rx,
1066 .getpgbwgcfgrx = cxgb4_getpgbwgcfg_rx,
1067 .setpgtccfgtx = cxgb4_setpgtccfg_tx,
1068 .setpgbwgcfgtx = cxgb4_setpgbwgcfg_tx,
1069 .setpfccfg = cxgb4_setpfccfg,
1070 .getpfccfg = cxgb4_getpfccfg,
1071 .setall = cxgb4_setall,
1072 .getcap = cxgb4_getcap,
1073 .getnumtcs = cxgb4_getnumtcs,
1074 .setnumtcs = cxgb4_setnumtcs,
1075 .getpfcstate = cxgb4_getpfcstate,
1076 .setpfcstate = cxgb4_setpfcstate,
1077 .getapp = cxgb4_getapp,
1078 .setapp = cxgb4_setapp,
1080 /* DCBX configuration */
1081 .getdcbx = cxgb4_getdcbx,
1082 .setdcbx = cxgb4_setdcbx,
1085 .peer_getappinfo = cxgb4_getpeer_app,
1086 .peer_getapptable = cxgb4_getpeerapp_tbl,
1089 .cee_peer_getpg = cxgb4_cee_peer_getpg,
1090 .cee_peer_getpfc = cxgb4_cee_peer_getpfc,