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 static const char * const 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.priority = dcb->app_priority[i].user_prio_map;
83 app.selector = dcb->app_priority[i].sel_field + 1;
84 err = dcb_ieee_delapp(dev, &app);
86 app.selector = !!(dcb->app_priority[i].sel_field);
87 err = dcb_setapp(dev, &app);
91 dev_err(adap->pdev_dev,
92 "Failed DCB Clear %s Application Priority: sel=%d, prot=%d, , err=%d\n",
93 dcb_ver_array[dcb->dcb_version], app.selector,
100 /* Finite State machine for Data Center Bridging.
102 void cxgb4_dcb_state_fsm(struct net_device *dev,
103 enum cxgb4_dcb_state_input transition_to)
105 struct port_info *pi = netdev2pinfo(dev);
106 struct port_dcb_info *dcb = &pi->dcb;
107 struct adapter *adap = pi->adapter;
108 enum cxgb4_dcb_state current_state = dcb->state;
110 netdev_dbg(dev, "%s: State change from %d to %d for %s\n",
111 __func__, dcb->state, transition_to, dev->name);
113 switch (current_state) {
114 case CXGB4_DCB_STATE_START: {
115 switch (transition_to) {
116 case CXGB4_DCB_INPUT_FW_DISABLED: {
117 /* we're going to use Host DCB */
118 dcb->state = CXGB4_DCB_STATE_HOST;
119 dcb->supported = CXGB4_DCBX_HOST_SUPPORT;
123 case CXGB4_DCB_INPUT_FW_ENABLED: {
124 /* we're going to use Firmware DCB */
125 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE;
126 dcb->supported = DCB_CAP_DCBX_LLD_MANAGED;
127 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE)
128 dcb->supported |= DCB_CAP_DCBX_VER_IEEE;
130 dcb->supported |= DCB_CAP_DCBX_VER_CEE;
134 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
135 /* expected transition */
139 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
140 dcb->state = CXGB4_DCB_STATE_FW_ALLSYNCED;
145 goto bad_state_input;
150 case CXGB4_DCB_STATE_FW_INCOMPLETE: {
151 switch (transition_to) {
152 case CXGB4_DCB_INPUT_FW_ENABLED: {
153 /* we're alreaady in firmware DCB mode */
157 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
158 /* we're already incomplete */
162 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
163 dcb->state = CXGB4_DCB_STATE_FW_ALLSYNCED;
165 linkwatch_fire_event(dev);
170 goto bad_state_input;
175 case CXGB4_DCB_STATE_FW_ALLSYNCED: {
176 switch (transition_to) {
177 case CXGB4_DCB_INPUT_FW_ENABLED: {
178 /* we're alreaady in firmware DCB mode */
182 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
183 /* We were successfully running with firmware DCB but
184 * now it's telling us that it's in an "incomplete
185 * state. We need to reset back to a ground state
188 cxgb4_dcb_cleanup_apps(dev);
189 cxgb4_dcb_state_init(dev);
190 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE;
191 dcb->supported = CXGB4_DCBX_FW_SUPPORT;
192 linkwatch_fire_event(dev);
196 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
197 /* we're already all sync'ed
198 * this is only applicable for IEEE or
199 * when another VI already completed negotiaton
202 linkwatch_fire_event(dev);
207 goto bad_state_input;
212 case CXGB4_DCB_STATE_HOST: {
213 switch (transition_to) {
214 case CXGB4_DCB_INPUT_FW_DISABLED: {
215 /* we're alreaady in Host DCB mode */
220 goto bad_state_input;
226 goto bad_state_transition;
231 dev_err(adap->pdev_dev, "cxgb4_dcb_state_fsm: illegal input symbol %d\n",
235 bad_state_transition:
236 dev_err(adap->pdev_dev, "cxgb4_dcb_state_fsm: bad state transition, state = %d, input = %d\n",
237 current_state, transition_to);
240 /* Handle a DCB/DCBX update message from the firmware.
242 void cxgb4_dcb_handle_fw_update(struct adapter *adap,
243 const struct fw_port_cmd *pcmd)
245 const union fw_port_dcb *fwdcb = &pcmd->u.dcb;
246 int port = FW_PORT_CMD_PORTID_G(be32_to_cpu(pcmd->op_to_portid));
247 struct net_device *dev = adap->port[port];
248 struct port_info *pi = netdev_priv(dev);
249 struct port_dcb_info *dcb = &pi->dcb;
250 int dcb_type = pcmd->u.dcb.pgid.type;
251 int dcb_running_version;
253 /* Handle Firmware DCB Control messages separately since they drive
256 if (dcb_type == FW_PORT_DCB_TYPE_CONTROL) {
257 enum cxgb4_dcb_state_input input =
258 ((pcmd->u.dcb.control.all_syncd_pkd &
259 FW_PORT_CMD_ALL_SYNCD_F)
260 ? CXGB4_DCB_STATE_FW_ALLSYNCED
261 : CXGB4_DCB_STATE_FW_INCOMPLETE);
263 if (dcb->dcb_version != FW_PORT_DCB_VER_UNKNOWN) {
264 dcb_running_version = FW_PORT_CMD_DCB_VERSION_G(
266 pcmd->u.dcb.control.dcb_version_to_app_state));
267 if (dcb_running_version == FW_PORT_DCB_VER_CEE1D01 ||
268 dcb_running_version == FW_PORT_DCB_VER_IEEE) {
269 dcb->dcb_version = dcb_running_version;
270 dev_warn(adap->pdev_dev, "Interface %s is running %s\n",
272 dcb_ver_array[dcb->dcb_version]);
274 dev_warn(adap->pdev_dev,
275 "Something screwed up, requested firmware for %s, but firmware returned %s instead\n",
276 dcb_ver_array[dcb->dcb_version],
277 dcb_ver_array[dcb_running_version]);
278 dcb->dcb_version = FW_PORT_DCB_VER_UNKNOWN;
282 cxgb4_dcb_state_fsm(dev, input);
286 /* It's weird, and almost certainly an error, to get Firmware DCB
287 * messages when we either haven't been told whether we're going to be
288 * doing Host or Firmware DCB; and even worse when we've been told
289 * that we're doing Host DCB!
291 if (dcb->state == CXGB4_DCB_STATE_START ||
292 dcb->state == CXGB4_DCB_STATE_HOST) {
293 dev_err(adap->pdev_dev, "Receiving Firmware DCB messages in State %d\n",
298 /* Now handle the general Firmware DCB update messages ...
301 case FW_PORT_DCB_TYPE_PGID:
302 dcb->pgid = be32_to_cpu(fwdcb->pgid.pgid);
303 dcb->msgs |= CXGB4_DCB_FW_PGID;
306 case FW_PORT_DCB_TYPE_PGRATE:
307 dcb->pg_num_tcs_supported = fwdcb->pgrate.num_tcs_supported;
308 memcpy(dcb->pgrate, &fwdcb->pgrate.pgrate,
309 sizeof(dcb->pgrate));
310 memcpy(dcb->tsa, &fwdcb->pgrate.tsa,
312 dcb->msgs |= CXGB4_DCB_FW_PGRATE;
313 if (dcb->msgs & CXGB4_DCB_FW_PGID)
314 IEEE_FAUX_SYNC(dev, dcb);
317 case FW_PORT_DCB_TYPE_PRIORATE:
318 memcpy(dcb->priorate, &fwdcb->priorate.strict_priorate,
319 sizeof(dcb->priorate));
320 dcb->msgs |= CXGB4_DCB_FW_PRIORATE;
323 case FW_PORT_DCB_TYPE_PFC:
324 dcb->pfcen = fwdcb->pfc.pfcen;
325 dcb->pfc_num_tcs_supported = fwdcb->pfc.max_pfc_tcs;
326 dcb->msgs |= CXGB4_DCB_FW_PFC;
327 IEEE_FAUX_SYNC(dev, dcb);
330 case FW_PORT_DCB_TYPE_APP_ID: {
331 const struct fw_port_app_priority *fwap = &fwdcb->app_priority;
333 struct app_priority *ap = &dcb->app_priority[idx];
335 struct dcb_app app = {
336 .protocol = be16_to_cpu(fwap->protocolid),
340 /* Convert from firmware format to relevant format
341 * when using app selector
343 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE) {
344 app.selector = (fwap->sel_field + 1);
345 app.priority = ffs(fwap->user_prio_map) - 1;
346 err = dcb_ieee_setapp(dev, &app);
347 IEEE_FAUX_SYNC(dev, dcb);
350 app.selector = !!(fwap->sel_field);
351 app.priority = fwap->user_prio_map;
352 err = dcb_setapp(dev, &app);
356 dev_err(adap->pdev_dev,
357 "Failed DCB Set Application Priority: sel=%d, prot=%d, prio=%d, err=%d\n",
358 app.selector, app.protocol, app.priority, -err);
360 ap->user_prio_map = fwap->user_prio_map;
361 ap->sel_field = fwap->sel_field;
362 ap->protocolid = be16_to_cpu(fwap->protocolid);
363 dcb->msgs |= CXGB4_DCB_FW_APP_ID;
368 dev_err(adap->pdev_dev, "Unknown DCB update type received %x\n",
374 /* Data Center Bridging netlink operations.
378 /* Get current DCB enabled/disabled state.
380 static u8 cxgb4_getstate(struct net_device *dev)
382 struct port_info *pi = netdev2pinfo(dev);
384 return pi->dcb.enabled;
387 /* Set DCB enabled/disabled.
389 static u8 cxgb4_setstate(struct net_device *dev, u8 enabled)
391 struct port_info *pi = netdev2pinfo(dev);
393 /* If DCBx is host-managed, dcb is enabled by outside lldp agents */
394 if (pi->dcb.state == CXGB4_DCB_STATE_HOST) {
395 pi->dcb.enabled = enabled;
399 /* Firmware doesn't provide any mechanism to control the DCB state.
401 if (enabled != (pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED))
407 static void cxgb4_getpgtccfg(struct net_device *dev, int tc,
408 u8 *prio_type, u8 *pgid, u8 *bw_per,
409 u8 *up_tc_map, int local)
411 struct fw_port_cmd pcmd;
412 struct port_info *pi = netdev2pinfo(dev);
413 struct adapter *adap = pi->adapter;
416 *prio_type = *pgid = *bw_per = *up_tc_map = 0;
419 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
421 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
423 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
424 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
425 if (err != FW_PORT_DCB_CFG_SUCCESS) {
426 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
429 *pgid = (be32_to_cpu(pcmd.u.dcb.pgid.pgid) >> (tc * 4)) & 0xf;
432 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
434 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
435 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
436 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
437 if (err != FW_PORT_DCB_CFG_SUCCESS) {
438 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
443 *bw_per = pcmd.u.dcb.pgrate.pgrate[*pgid];
444 *up_tc_map = (1 << tc);
446 /* prio_type is link strict */
451 static void cxgb4_getpgtccfg_tx(struct net_device *dev, int tc,
452 u8 *prio_type, u8 *pgid, u8 *bw_per,
455 /* tc 0 is written at MSB position */
456 return cxgb4_getpgtccfg(dev, (7 - tc), prio_type, pgid, bw_per,
461 static void cxgb4_getpgtccfg_rx(struct net_device *dev, int tc,
462 u8 *prio_type, u8 *pgid, u8 *bw_per,
465 /* tc 0 is written at MSB position */
466 return cxgb4_getpgtccfg(dev, (7 - tc), prio_type, pgid, bw_per,
470 static void cxgb4_setpgtccfg_tx(struct net_device *dev, int tc,
471 u8 prio_type, u8 pgid, u8 bw_per,
474 struct fw_port_cmd pcmd;
475 struct port_info *pi = netdev2pinfo(dev);
476 struct adapter *adap = pi->adapter;
481 if (pgid == DCB_ATTR_VALUE_UNDEFINED)
483 if (bw_per == DCB_ATTR_VALUE_UNDEFINED)
486 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
487 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
489 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
490 if (err != FW_PORT_DCB_CFG_SUCCESS) {
491 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
495 _pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
496 _pgid &= ~(0xF << (fw_tc * 4));
497 _pgid |= pgid << (fw_tc * 4);
498 pcmd.u.dcb.pgid.pgid = cpu_to_be32(_pgid);
500 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
502 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
503 if (err != FW_PORT_DCB_CFG_SUCCESS) {
504 dev_err(adap->pdev_dev, "DCB write PGID failed with %d\n",
509 memset(&pcmd, 0, sizeof(struct fw_port_cmd));
511 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
512 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
514 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
515 if (err != FW_PORT_DCB_CFG_SUCCESS) {
516 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
521 pcmd.u.dcb.pgrate.pgrate[pgid] = bw_per;
523 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
524 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
525 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY_F);
527 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
528 if (err != FW_PORT_DCB_CFG_SUCCESS)
529 dev_err(adap->pdev_dev, "DCB write PGRATE failed with %d\n",
533 static void cxgb4_getpgbwgcfg(struct net_device *dev, int pgid, u8 *bw_per,
536 struct fw_port_cmd pcmd;
537 struct port_info *pi = netdev2pinfo(dev);
538 struct adapter *adap = pi->adapter;
542 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
544 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
546 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
547 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
548 if (err != FW_PORT_DCB_CFG_SUCCESS) {
549 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
554 *bw_per = pcmd.u.dcb.pgrate.pgrate[pgid];
557 static void cxgb4_getpgbwgcfg_tx(struct net_device *dev, int pgid, u8 *bw_per)
559 return cxgb4_getpgbwgcfg(dev, pgid, bw_per, 1);
562 static void cxgb4_getpgbwgcfg_rx(struct net_device *dev, int pgid, u8 *bw_per)
564 return cxgb4_getpgbwgcfg(dev, pgid, bw_per, 0);
567 static void cxgb4_setpgbwgcfg_tx(struct net_device *dev, int pgid,
570 struct fw_port_cmd pcmd;
571 struct port_info *pi = netdev2pinfo(dev);
572 struct adapter *adap = pi->adapter;
575 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
576 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
578 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 read PGRATE failed with %d\n",
585 pcmd.u.dcb.pgrate.pgrate[pgid] = bw_per;
587 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
588 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
589 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY_F);
591 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
593 if (err != FW_PORT_DCB_CFG_SUCCESS)
594 dev_err(adap->pdev_dev, "DCB write PGRATE failed with %d\n",
598 /* Return whether the specified Traffic Class Priority has Priority Pause
601 static void cxgb4_getpfccfg(struct net_device *dev, int priority, u8 *pfccfg)
603 struct port_info *pi = netdev2pinfo(dev);
604 struct port_dcb_info *dcb = &pi->dcb;
606 if (dcb->state != CXGB4_DCB_STATE_FW_ALLSYNCED ||
607 priority >= CXGB4_MAX_PRIORITY)
610 *pfccfg = (pi->dcb.pfcen >> (7 - priority)) & 1;
613 /* Enable/disable Priority Pause Frames for the specified Traffic Class
616 static void cxgb4_setpfccfg(struct net_device *dev, int priority, u8 pfccfg)
618 struct fw_port_cmd pcmd;
619 struct port_info *pi = netdev2pinfo(dev);
620 struct adapter *adap = pi->adapter;
623 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED ||
624 priority >= CXGB4_MAX_PRIORITY)
627 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
628 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
629 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY_F);
631 pcmd.u.dcb.pfc.type = FW_PORT_DCB_TYPE_PFC;
632 pcmd.u.dcb.pfc.pfcen = pi->dcb.pfcen;
635 pcmd.u.dcb.pfc.pfcen |= (1 << (7 - priority));
637 pcmd.u.dcb.pfc.pfcen &= (~(1 << (7 - priority)));
639 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
640 if (err != FW_PORT_DCB_CFG_SUCCESS) {
641 dev_err(adap->pdev_dev, "DCB PFC write failed with %d\n", -err);
645 pi->dcb.pfcen = pcmd.u.dcb.pfc.pfcen;
648 static u8 cxgb4_setall(struct net_device *dev)
653 /* Return DCB capabilities.
655 static u8 cxgb4_getcap(struct net_device *dev, int cap_id, u8 *caps)
657 struct port_info *pi = netdev2pinfo(dev);
660 case DCB_CAP_ATTR_PG:
661 case DCB_CAP_ATTR_PFC:
665 case DCB_CAP_ATTR_PG_TCS:
666 /* 8 priorities for PG represented by bitmap */
670 case DCB_CAP_ATTR_PFC_TCS:
671 /* 8 priorities for PFC represented by bitmap */
675 case DCB_CAP_ATTR_GSP:
679 case DCB_CAP_ATTR_UP2TC:
680 case DCB_CAP_ATTR_BCN:
684 case DCB_CAP_ATTR_DCBX:
685 *caps = pi->dcb.supported;
695 /* Return the number of Traffic Classes for the indicated Traffic Class ID.
697 static int cxgb4_getnumtcs(struct net_device *dev, int tcs_id, u8 *num)
699 struct port_info *pi = netdev2pinfo(dev);
702 case DCB_NUMTCS_ATTR_PG:
703 if (pi->dcb.msgs & CXGB4_DCB_FW_PGRATE)
704 *num = pi->dcb.pg_num_tcs_supported;
709 case DCB_NUMTCS_ATTR_PFC:
720 /* Set the number of Traffic Classes supported for the indicated Traffic Class
723 static int cxgb4_setnumtcs(struct net_device *dev, int tcs_id, u8 num)
725 /* Setting the number of Traffic Classes isn't supported.
730 /* Return whether Priority Flow Control is enabled. */
731 static u8 cxgb4_getpfcstate(struct net_device *dev)
733 struct port_info *pi = netdev2pinfo(dev);
735 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
738 return pi->dcb.pfcen != 0;
741 /* Enable/disable Priority Flow Control. */
742 static void cxgb4_setpfcstate(struct net_device *dev, u8 state)
744 /* We can't enable/disable Priority Flow Control but we also can't
745 * return an error ...
749 /* Return the Application User Priority Map associated with the specified
752 static int __cxgb4_getapp(struct net_device *dev, u8 app_idtype, u16 app_id,
755 struct port_info *pi = netdev2pinfo(dev);
756 struct adapter *adap = pi->adapter;
759 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
762 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
763 struct fw_port_cmd pcmd;
767 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
769 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
771 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
772 pcmd.u.dcb.app_priority.idx = i;
774 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
775 if (err != FW_PORT_DCB_CFG_SUCCESS) {
776 dev_err(adap->pdev_dev, "DCB APP read failed with %d\n",
780 if (be16_to_cpu(pcmd.u.dcb.app_priority.protocolid) == app_id)
781 if (pcmd.u.dcb.app_priority.sel_field == app_idtype)
782 return pcmd.u.dcb.app_priority.user_prio_map;
784 /* exhausted app list */
785 if (!pcmd.u.dcb.app_priority.protocolid)
792 /* Return the Application User Priority Map associated with the specified
795 static int cxgb4_getapp(struct net_device *dev, u8 app_idtype, u16 app_id)
797 return __cxgb4_getapp(dev, app_idtype, app_id, 0);
800 /* Write a new Application User Priority Map for the specified Application ID
802 static int __cxgb4_setapp(struct net_device *dev, u8 app_idtype, u16 app_id,
805 struct fw_port_cmd pcmd;
806 struct port_info *pi = netdev2pinfo(dev);
807 struct adapter *adap = pi->adapter;
811 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
814 /* DCB info gets thrown away on link up */
815 if (!netif_carrier_ok(dev))
818 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
819 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
820 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
821 pcmd.u.dcb.app_priority.idx = i;
822 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
824 if (err != FW_PORT_DCB_CFG_SUCCESS) {
825 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
829 if (be16_to_cpu(pcmd.u.dcb.app_priority.protocolid) == app_id) {
830 /* overwrite existing app table */
831 pcmd.u.dcb.app_priority.protocolid = 0;
834 /* find first empty slot */
835 if (!pcmd.u.dcb.app_priority.protocolid)
839 if (i == CXGB4_MAX_DCBX_APP_SUPPORTED) {
840 /* no empty slots available */
841 dev_err(adap->pdev_dev, "DCB app table full\n");
845 /* write out new app table entry */
846 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
847 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
848 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY_F);
850 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
851 pcmd.u.dcb.app_priority.protocolid = cpu_to_be16(app_id);
852 pcmd.u.dcb.app_priority.sel_field = app_idtype;
853 pcmd.u.dcb.app_priority.user_prio_map = app_prio;
854 pcmd.u.dcb.app_priority.idx = i;
856 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
857 if (err != FW_PORT_DCB_CFG_SUCCESS) {
858 dev_err(adap->pdev_dev, "DCB app table write failed with %d\n",
866 /* Priority for CEE inside dcb_app is bitmask, with 0 being an invalid value */
867 static int cxgb4_setapp(struct net_device *dev, u8 app_idtype, u16 app_id,
871 struct dcb_app app = {
872 .selector = app_idtype,
874 .priority = app_prio,
877 if (app_idtype != DCB_APP_IDTYPE_ETHTYPE &&
878 app_idtype != DCB_APP_IDTYPE_PORTNUM)
881 /* Convert app_idtype to a format that firmware understands */
882 ret = __cxgb4_setapp(dev, app_idtype == DCB_APP_IDTYPE_ETHTYPE ?
883 app_idtype : 3, app_id, app_prio);
887 return dcb_setapp(dev, &app);
890 /* Return whether IEEE Data Center Bridging has been negotiated.
893 cxgb4_ieee_negotiation_complete(struct net_device *dev,
894 enum cxgb4_dcb_fw_msgs dcb_subtype)
896 struct port_info *pi = netdev2pinfo(dev);
897 struct port_dcb_info *dcb = &pi->dcb;
899 if (dcb_subtype && !(dcb->msgs & dcb_subtype))
902 return (dcb->state == CXGB4_DCB_STATE_FW_ALLSYNCED &&
903 (dcb->supported & DCB_CAP_DCBX_VER_IEEE));
906 static int cxgb4_ieee_read_ets(struct net_device *dev, struct ieee_ets *ets,
909 struct port_info *pi = netdev2pinfo(dev);
910 struct port_dcb_info *dcb = &pi->dcb;
911 struct adapter *adap = pi->adapter;
913 struct fw_port_cmd pcmd;
916 if (!(dcb->msgs & (CXGB4_DCB_FW_PGID | CXGB4_DCB_FW_PGRATE)))
919 ets->ets_cap = dcb->pg_num_tcs_supported;
923 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
925 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
928 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
929 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
930 if (err != FW_PORT_DCB_CFG_SUCCESS) {
931 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
935 tc_info = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
938 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
940 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
942 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
943 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
944 if (err != FW_PORT_DCB_CFG_SUCCESS) {
945 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
950 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
951 bwg = (tc_info >> ((7 - i) * 4)) & 0xF;
952 ets->prio_tc[i] = bwg;
953 ets->tc_tx_bw[i] = pcmd.u.dcb.pgrate.pgrate[i];
954 ets->tc_rx_bw[i] = ets->tc_tx_bw[i];
955 ets->tc_tsa[i] = pcmd.u.dcb.pgrate.tsa[i];
961 static int cxgb4_ieee_get_ets(struct net_device *dev, struct ieee_ets *ets)
963 return cxgb4_ieee_read_ets(dev, ets, 1);
966 /* We reuse this for peer PFC as well, as we can't have it enabled one way */
967 static int cxgb4_ieee_get_pfc(struct net_device *dev, struct ieee_pfc *pfc)
969 struct port_info *pi = netdev2pinfo(dev);
970 struct port_dcb_info *dcb = &pi->dcb;
972 memset(pfc, 0, sizeof(struct ieee_pfc));
974 if (!(dcb->msgs & CXGB4_DCB_FW_PFC))
977 pfc->pfc_cap = dcb->pfc_num_tcs_supported;
978 pfc->pfc_en = bitswap_1(dcb->pfcen);
983 static int cxgb4_ieee_peer_ets(struct net_device *dev, struct ieee_ets *ets)
985 return cxgb4_ieee_read_ets(dev, ets, 0);
988 /* Fill in the Application User Priority Map associated with the
989 * specified Application.
990 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
992 static int cxgb4_ieee_getapp(struct net_device *dev, struct dcb_app *app)
996 if (!cxgb4_ieee_negotiation_complete(dev, CXGB4_DCB_FW_APP_ID))
998 if (!(app->selector && app->protocol))
1001 /* Try querying firmware first, use firmware format */
1002 prio = __cxgb4_getapp(dev, app->selector - 1, app->protocol, 0);
1005 prio = dcb_ieee_getapp_mask(dev, app);
1007 app->priority = ffs(prio) - 1;
1011 /* Write a new Application User Priority Map for the specified Application ID.
1012 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
1014 static int cxgb4_ieee_setapp(struct net_device *dev, struct dcb_app *app)
1018 if (!cxgb4_ieee_negotiation_complete(dev, CXGB4_DCB_FW_APP_ID))
1020 if (!(app->selector && app->protocol))
1023 if (!(app->selector > IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
1024 app->selector < IEEE_8021QAZ_APP_SEL_ANY))
1027 /* change selector to a format that firmware understands */
1028 ret = __cxgb4_setapp(dev, app->selector - 1, app->protocol,
1029 (1 << app->priority));
1033 return dcb_ieee_setapp(dev, app);
1036 /* Return our DCBX parameters.
1038 static u8 cxgb4_getdcbx(struct net_device *dev)
1040 struct port_info *pi = netdev2pinfo(dev);
1042 /* This is already set by cxgb4_set_dcb_caps, so just return it */
1043 return pi->dcb.supported;
1046 /* Set our DCBX parameters.
1048 static u8 cxgb4_setdcbx(struct net_device *dev, u8 dcb_request)
1050 struct port_info *pi = netdev2pinfo(dev);
1052 /* Filter out requests which exceed our capabilities.
1054 if ((dcb_request & (CXGB4_DCBX_FW_SUPPORT | CXGB4_DCBX_HOST_SUPPORT))
1058 /* Can't enable DCB if we haven't successfully negotiated it.
1060 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
1063 /* There's currently no mechanism to allow for the firmware DCBX
1064 * negotiation to be changed from the Host Driver. If the caller
1065 * requests exactly the same parameters that we already have then
1066 * we'll allow them to be successfully "set" ...
1068 if (dcb_request != pi->dcb.supported)
1071 pi->dcb.supported = dcb_request;
1075 static int cxgb4_getpeer_app(struct net_device *dev,
1076 struct dcb_peer_app_info *info, u16 *app_count)
1078 struct fw_port_cmd pcmd;
1079 struct port_info *pi = netdev2pinfo(dev);
1080 struct adapter *adap = pi->adapter;
1083 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
1090 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
1091 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1092 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
1093 pcmd.u.dcb.app_priority.idx = *app_count;
1094 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1096 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1097 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
1102 /* find first empty slot */
1103 if (!pcmd.u.dcb.app_priority.protocolid)
1110 static int cxgb4_getpeerapp_tbl(struct net_device *dev, struct dcb_app *table)
1112 struct fw_port_cmd pcmd;
1113 struct port_info *pi = netdev2pinfo(dev);
1114 struct adapter *adap = pi->adapter;
1117 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
1120 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
1121 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1122 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
1123 pcmd.u.dcb.app_priority.idx = i;
1124 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1126 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1127 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
1132 /* find first empty slot */
1133 if (!pcmd.u.dcb.app_priority.protocolid)
1136 table[i].selector = pcmd.u.dcb.app_priority.sel_field;
1138 be16_to_cpu(pcmd.u.dcb.app_priority.protocolid);
1140 ffs(pcmd.u.dcb.app_priority.user_prio_map) - 1;
1145 /* Return Priority Group information.
1147 static int cxgb4_cee_peer_getpg(struct net_device *dev, struct cee_pg *pg)
1149 struct fw_port_cmd pcmd;
1150 struct port_info *pi = netdev2pinfo(dev);
1151 struct adapter *adap = pi->adapter;
1155 /* We're always "willing" -- the Switch Fabric always dictates the
1156 * DCBX parameters to us.
1160 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1161 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
1162 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1163 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1164 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
1167 pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
1169 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1170 pg->prio_pg[7 - i] = (pgid >> (i * 4)) & 0xF;
1172 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1173 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
1174 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1175 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1176 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
1181 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1182 pg->pg_bw[i] = pcmd.u.dcb.pgrate.pgrate[i];
1187 /* Return Priority Flow Control information.
1189 static int cxgb4_cee_peer_getpfc(struct net_device *dev, struct cee_pfc *pfc)
1191 struct port_info *pi = netdev2pinfo(dev);
1193 cxgb4_getnumtcs(dev, DCB_NUMTCS_ATTR_PFC, &(pfc->tcs_supported));
1195 /* Firmware sends this to us in a formwat that is a bit flipped version
1196 * of spec, correct it before we send it to host. This is taken care of
1197 * by bit shifting in other uses of pfcen
1199 pfc->pfc_en = bitswap_1(pi->dcb.pfcen);
1204 const struct dcbnl_rtnl_ops cxgb4_dcb_ops = {
1205 .ieee_getets = cxgb4_ieee_get_ets,
1206 .ieee_getpfc = cxgb4_ieee_get_pfc,
1207 .ieee_getapp = cxgb4_ieee_getapp,
1208 .ieee_setapp = cxgb4_ieee_setapp,
1209 .ieee_peer_getets = cxgb4_ieee_peer_ets,
1210 .ieee_peer_getpfc = cxgb4_ieee_get_pfc,
1213 .getstate = cxgb4_getstate,
1214 .setstate = cxgb4_setstate,
1215 .getpgtccfgtx = cxgb4_getpgtccfg_tx,
1216 .getpgbwgcfgtx = cxgb4_getpgbwgcfg_tx,
1217 .getpgtccfgrx = cxgb4_getpgtccfg_rx,
1218 .getpgbwgcfgrx = cxgb4_getpgbwgcfg_rx,
1219 .setpgtccfgtx = cxgb4_setpgtccfg_tx,
1220 .setpgbwgcfgtx = cxgb4_setpgbwgcfg_tx,
1221 .setpfccfg = cxgb4_setpfccfg,
1222 .getpfccfg = cxgb4_getpfccfg,
1223 .setall = cxgb4_setall,
1224 .getcap = cxgb4_getcap,
1225 .getnumtcs = cxgb4_getnumtcs,
1226 .setnumtcs = cxgb4_setnumtcs,
1227 .getpfcstate = cxgb4_getpfcstate,
1228 .setpfcstate = cxgb4_setpfcstate,
1229 .getapp = cxgb4_getapp,
1230 .setapp = cxgb4_setapp,
1232 /* DCBX configuration */
1233 .getdcbx = cxgb4_getdcbx,
1234 .setdcbx = cxgb4_setdcbx,
1237 .peer_getappinfo = cxgb4_getpeer_app,
1238 .peer_getapptable = cxgb4_getpeerapp_tbl,
1241 .cee_peer_getpg = cxgb4_cee_peer_getpg,
1242 .cee_peer_getpfc = cxgb4_cee_peer_getpfc,