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.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 = CXGB4_DCBX_FW_SUPPORT;
130 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
131 /* expected transition */
135 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
136 dcb->state = CXGB4_DCB_STATE_FW_ALLSYNCED;
141 goto bad_state_input;
146 case CXGB4_DCB_STATE_FW_INCOMPLETE: {
147 switch (transition_to) {
148 case CXGB4_DCB_INPUT_FW_ENABLED: {
149 /* we're alreaady in firmware DCB mode */
153 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
154 /* we're already incomplete */
158 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
159 dcb->state = CXGB4_DCB_STATE_FW_ALLSYNCED;
161 linkwatch_fire_event(dev);
166 goto bad_state_input;
171 case CXGB4_DCB_STATE_FW_ALLSYNCED: {
172 switch (transition_to) {
173 case CXGB4_DCB_INPUT_FW_ENABLED: {
174 /* we're alreaady in firmware DCB mode */
178 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
179 /* We were successfully running with firmware DCB but
180 * now it's telling us that it's in an "incomplete
181 * state. We need to reset back to a ground state
184 cxgb4_dcb_cleanup_apps(dev);
185 cxgb4_dcb_state_init(dev);
186 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE;
187 dcb->supported = CXGB4_DCBX_FW_SUPPORT;
188 linkwatch_fire_event(dev);
192 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
193 /* we're already all sync'ed
194 * this is only applicable for IEEE or
195 * when another VI already completed negotiaton
198 linkwatch_fire_event(dev);
203 goto bad_state_input;
208 case CXGB4_DCB_STATE_HOST: {
209 switch (transition_to) {
210 case CXGB4_DCB_INPUT_FW_DISABLED: {
211 /* we're alreaady in Host DCB mode */
216 goto bad_state_input;
222 goto bad_state_transition;
227 dev_err(adap->pdev_dev, "cxgb4_dcb_state_fsm: illegal input symbol %d\n",
231 bad_state_transition:
232 dev_err(adap->pdev_dev, "cxgb4_dcb_state_fsm: bad state transition, state = %d, input = %d\n",
233 current_state, transition_to);
236 /* Handle a DCB/DCBX update message from the firmware.
238 void cxgb4_dcb_handle_fw_update(struct adapter *adap,
239 const struct fw_port_cmd *pcmd)
241 const union fw_port_dcb *fwdcb = &pcmd->u.dcb;
242 int port = FW_PORT_CMD_PORTID_GET(be32_to_cpu(pcmd->op_to_portid));
243 struct net_device *dev = adap->port[port];
244 struct port_info *pi = netdev_priv(dev);
245 struct port_dcb_info *dcb = &pi->dcb;
246 int dcb_type = pcmd->u.dcb.pgid.type;
247 int dcb_running_version;
249 /* Handle Firmware DCB Control messages separately since they drive
252 if (dcb_type == FW_PORT_DCB_TYPE_CONTROL) {
253 enum cxgb4_dcb_state_input input =
254 ((pcmd->u.dcb.control.all_syncd_pkd &
255 FW_PORT_CMD_ALL_SYNCD)
256 ? CXGB4_DCB_STATE_FW_ALLSYNCED
257 : CXGB4_DCB_STATE_FW_INCOMPLETE);
259 if (dcb->dcb_version != FW_PORT_DCB_VER_UNKNOWN) {
260 dcb_running_version = FW_PORT_CMD_DCB_VERSION_GET(
262 pcmd->u.dcb.control.dcb_version_to_app_state));
263 if (dcb_running_version == FW_PORT_DCB_VER_CEE1D01 ||
264 dcb_running_version == FW_PORT_DCB_VER_IEEE) {
265 dcb->dcb_version = dcb_running_version;
266 dev_warn(adap->pdev_dev, "Interface %s is running %s\n",
268 dcb_ver_array[dcb->dcb_version]);
270 dev_warn(adap->pdev_dev,
271 "Something screwed up, requested firmware for %s, but firmware returned %s instead\n",
272 dcb_ver_array[dcb->dcb_version],
273 dcb_ver_array[dcb_running_version]);
274 dcb->dcb_version = FW_PORT_DCB_VER_UNKNOWN;
278 cxgb4_dcb_state_fsm(dev, input);
282 /* It's weird, and almost certainly an error, to get Firmware DCB
283 * messages when we either haven't been told whether we're going to be
284 * doing Host or Firmware DCB; and even worse when we've been told
285 * that we're doing Host DCB!
287 if (dcb->state == CXGB4_DCB_STATE_START ||
288 dcb->state == CXGB4_DCB_STATE_HOST) {
289 dev_err(adap->pdev_dev, "Receiving Firmware DCB messages in State %d\n",
294 /* Now handle the general Firmware DCB update messages ...
297 case FW_PORT_DCB_TYPE_PGID:
298 dcb->pgid = be32_to_cpu(fwdcb->pgid.pgid);
299 dcb->msgs |= CXGB4_DCB_FW_PGID;
302 case FW_PORT_DCB_TYPE_PGRATE:
303 dcb->pg_num_tcs_supported = fwdcb->pgrate.num_tcs_supported;
304 memcpy(dcb->pgrate, &fwdcb->pgrate.pgrate,
305 sizeof(dcb->pgrate));
306 memcpy(dcb->tsa, &fwdcb->pgrate.tsa,
308 dcb->msgs |= CXGB4_DCB_FW_PGRATE;
309 if (dcb->msgs & CXGB4_DCB_FW_PGID)
310 IEEE_FAUX_SYNC(dev, dcb);
313 case FW_PORT_DCB_TYPE_PRIORATE:
314 memcpy(dcb->priorate, &fwdcb->priorate.strict_priorate,
315 sizeof(dcb->priorate));
316 dcb->msgs |= CXGB4_DCB_FW_PRIORATE;
319 case FW_PORT_DCB_TYPE_PFC:
320 dcb->pfcen = fwdcb->pfc.pfcen;
321 dcb->pfc_num_tcs_supported = fwdcb->pfc.max_pfc_tcs;
322 dcb->msgs |= CXGB4_DCB_FW_PFC;
323 IEEE_FAUX_SYNC(dev, dcb);
326 case FW_PORT_DCB_TYPE_APP_ID: {
327 const struct fw_port_app_priority *fwap = &fwdcb->app_priority;
329 struct app_priority *ap = &dcb->app_priority[idx];
331 struct dcb_app app = {
332 .protocol = be16_to_cpu(fwap->protocolid),
336 /* Convert from firmware format to relevant format
337 * when using app selector
339 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE) {
340 app.selector = (fwap->sel_field + 1);
341 app.priority = ffs(fwap->user_prio_map) - 1;
342 err = dcb_ieee_setapp(dev, &app);
343 IEEE_FAUX_SYNC(dev, dcb);
346 app.selector = !!(fwap->sel_field);
347 app.priority = fwap->user_prio_map;
348 err = dcb_setapp(dev, &app);
352 dev_err(adap->pdev_dev,
353 "Failed DCB Set Application Priority: sel=%d, prot=%d, prio=%d, err=%d\n",
354 app.selector, app.protocol, app.priority, -err);
356 ap->user_prio_map = fwap->user_prio_map;
357 ap->sel_field = fwap->sel_field;
358 ap->protocolid = be16_to_cpu(fwap->protocolid);
359 dcb->msgs |= CXGB4_DCB_FW_APP_ID;
364 dev_err(adap->pdev_dev, "Unknown DCB update type received %x\n",
370 /* Data Center Bridging netlink operations.
374 /* Get current DCB enabled/disabled state.
376 static u8 cxgb4_getstate(struct net_device *dev)
378 struct port_info *pi = netdev2pinfo(dev);
380 return pi->dcb.enabled;
383 /* Set DCB enabled/disabled.
385 static u8 cxgb4_setstate(struct net_device *dev, u8 enabled)
387 struct port_info *pi = netdev2pinfo(dev);
389 /* If DCBx is host-managed, dcb is enabled by outside lldp agents */
390 if (pi->dcb.state == CXGB4_DCB_STATE_HOST) {
391 pi->dcb.enabled = enabled;
395 /* Firmware doesn't provide any mechanism to control the DCB state.
397 if (enabled != (pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED))
403 static void cxgb4_getpgtccfg(struct net_device *dev, int tc,
404 u8 *prio_type, u8 *pgid, u8 *bw_per,
405 u8 *up_tc_map, int local)
407 struct fw_port_cmd pcmd;
408 struct port_info *pi = netdev2pinfo(dev);
409 struct adapter *adap = pi->adapter;
412 *prio_type = *pgid = *bw_per = *up_tc_map = 0;
415 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
417 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
419 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
420 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
421 if (err != FW_PORT_DCB_CFG_SUCCESS) {
422 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
425 *pgid = (be32_to_cpu(pcmd.u.dcb.pgid.pgid) >> (tc * 4)) & 0xf;
427 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
428 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
429 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
430 if (err != FW_PORT_DCB_CFG_SUCCESS) {
431 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
436 *bw_per = pcmd.u.dcb.pgrate.pgrate[*pgid];
437 *up_tc_map = (1 << tc);
439 /* prio_type is link strict */
443 static void cxgb4_getpgtccfg_tx(struct net_device *dev, int tc,
444 u8 *prio_type, u8 *pgid, u8 *bw_per,
447 return cxgb4_getpgtccfg(dev, tc, prio_type, pgid, bw_per, up_tc_map, 1);
451 static void cxgb4_getpgtccfg_rx(struct net_device *dev, int tc,
452 u8 *prio_type, u8 *pgid, u8 *bw_per,
455 return cxgb4_getpgtccfg(dev, tc, prio_type, pgid, bw_per, up_tc_map, 0);
458 static void cxgb4_setpgtccfg_tx(struct net_device *dev, int tc,
459 u8 prio_type, u8 pgid, u8 bw_per,
462 struct fw_port_cmd pcmd;
463 struct port_info *pi = netdev2pinfo(dev);
464 struct adapter *adap = pi->adapter;
468 if (pgid == DCB_ATTR_VALUE_UNDEFINED)
470 if (bw_per == DCB_ATTR_VALUE_UNDEFINED)
473 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
474 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
476 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
477 if (err != FW_PORT_DCB_CFG_SUCCESS) {
478 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
482 _pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
483 _pgid &= ~(0xF << (tc * 4));
484 _pgid |= pgid << (tc * 4);
485 pcmd.u.dcb.pgid.pgid = cpu_to_be32(_pgid);
487 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
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 write PGID failed with %d\n",
496 memset(&pcmd, 0, sizeof(struct fw_port_cmd));
498 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
499 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
501 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
502 if (err != FW_PORT_DCB_CFG_SUCCESS) {
503 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
508 pcmd.u.dcb.pgrate.pgrate[pgid] = bw_per;
510 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
511 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
512 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
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 write PGRATE failed with %d\n",
520 static void cxgb4_getpgbwgcfg(struct net_device *dev, int pgid, u8 *bw_per,
523 struct fw_port_cmd pcmd;
524 struct port_info *pi = netdev2pinfo(dev);
525 struct adapter *adap = pi->adapter;
529 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
531 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
533 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
534 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
535 if (err != FW_PORT_DCB_CFG_SUCCESS) {
536 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
541 *bw_per = pcmd.u.dcb.pgrate.pgrate[pgid];
544 static void cxgb4_getpgbwgcfg_tx(struct net_device *dev, int pgid, u8 *bw_per)
546 return cxgb4_getpgbwgcfg(dev, pgid, bw_per, 1);
549 static void cxgb4_getpgbwgcfg_rx(struct net_device *dev, int pgid, u8 *bw_per)
551 return cxgb4_getpgbwgcfg(dev, pgid, bw_per, 0);
554 static void cxgb4_setpgbwgcfg_tx(struct net_device *dev, int pgid,
557 struct fw_port_cmd pcmd;
558 struct port_info *pi = netdev2pinfo(dev);
559 struct adapter *adap = pi->adapter;
562 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
563 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
565 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
566 if (err != FW_PORT_DCB_CFG_SUCCESS) {
567 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
572 pcmd.u.dcb.pgrate.pgrate[pgid] = bw_per;
574 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
575 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
576 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
578 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
580 if (err != FW_PORT_DCB_CFG_SUCCESS)
581 dev_err(adap->pdev_dev, "DCB write PGRATE failed with %d\n",
585 /* Return whether the specified Traffic Class Priority has Priority Pause
588 static void cxgb4_getpfccfg(struct net_device *dev, int priority, u8 *pfccfg)
590 struct port_info *pi = netdev2pinfo(dev);
591 struct port_dcb_info *dcb = &pi->dcb;
593 if (dcb->state != CXGB4_DCB_STATE_FW_ALLSYNCED ||
594 priority >= CXGB4_MAX_PRIORITY)
597 *pfccfg = (pi->dcb.pfcen >> priority) & 1;
600 /* Enable/disable Priority Pause Frames for the specified Traffic Class
603 static void cxgb4_setpfccfg(struct net_device *dev, int priority, u8 pfccfg)
605 struct fw_port_cmd pcmd;
606 struct port_info *pi = netdev2pinfo(dev);
607 struct adapter *adap = pi->adapter;
610 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED ||
611 priority >= CXGB4_MAX_PRIORITY)
614 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
615 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
616 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
618 pcmd.u.dcb.pfc.type = FW_PORT_DCB_TYPE_PFC;
619 pcmd.u.dcb.pfc.pfcen = pi->dcb.pfcen;
622 pcmd.u.dcb.pfc.pfcen |= (1 << priority);
624 pcmd.u.dcb.pfc.pfcen &= (~(1 << priority));
626 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
627 if (err != FW_PORT_DCB_CFG_SUCCESS) {
628 dev_err(adap->pdev_dev, "DCB PFC write failed with %d\n", -err);
632 pi->dcb.pfcen = pcmd.u.dcb.pfc.pfcen;
635 static u8 cxgb4_setall(struct net_device *dev)
640 /* Return DCB capabilities.
642 static u8 cxgb4_getcap(struct net_device *dev, int cap_id, u8 *caps)
644 struct port_info *pi = netdev2pinfo(dev);
647 case DCB_CAP_ATTR_PG:
648 case DCB_CAP_ATTR_PFC:
652 case DCB_CAP_ATTR_PG_TCS:
653 /* 8 priorities for PG represented by bitmap */
657 case DCB_CAP_ATTR_PFC_TCS:
658 /* 8 priorities for PFC represented by bitmap */
662 case DCB_CAP_ATTR_GSP:
666 case DCB_CAP_ATTR_UP2TC:
667 case DCB_CAP_ATTR_BCN:
671 case DCB_CAP_ATTR_DCBX:
672 *caps = pi->dcb.supported;
682 /* Return the number of Traffic Classes for the indicated Traffic Class ID.
684 static int cxgb4_getnumtcs(struct net_device *dev, int tcs_id, u8 *num)
686 struct port_info *pi = netdev2pinfo(dev);
689 case DCB_NUMTCS_ATTR_PG:
690 if (pi->dcb.msgs & CXGB4_DCB_FW_PGRATE)
691 *num = pi->dcb.pg_num_tcs_supported;
696 case DCB_NUMTCS_ATTR_PFC:
707 /* Set the number of Traffic Classes supported for the indicated Traffic Class
710 static int cxgb4_setnumtcs(struct net_device *dev, int tcs_id, u8 num)
712 /* Setting the number of Traffic Classes isn't supported.
717 /* Return whether Priority Flow Control is enabled. */
718 static u8 cxgb4_getpfcstate(struct net_device *dev)
720 struct port_info *pi = netdev2pinfo(dev);
722 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
725 return pi->dcb.pfcen != 0;
728 /* Enable/disable Priority Flow Control. */
729 static void cxgb4_setpfcstate(struct net_device *dev, u8 state)
731 /* We can't enable/disable Priority Flow Control but we also can't
732 * return an error ...
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,
742 struct port_info *pi = netdev2pinfo(dev);
743 struct adapter *adap = pi->adapter;
746 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
749 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
750 struct fw_port_cmd pcmd;
754 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
756 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
758 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
759 pcmd.u.dcb.app_priority.idx = i;
761 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
762 if (err != FW_PORT_DCB_CFG_SUCCESS) {
763 dev_err(adap->pdev_dev, "DCB APP read failed with %d\n",
767 if (be16_to_cpu(pcmd.u.dcb.app_priority.protocolid) == app_id)
768 if (pcmd.u.dcb.app_priority.sel_field == app_idtype)
769 return pcmd.u.dcb.app_priority.user_prio_map;
771 /* exhausted app list */
772 if (!pcmd.u.dcb.app_priority.protocolid)
779 /* Return the Application User Priority Map associated with the specified
782 static int cxgb4_getapp(struct net_device *dev, u8 app_idtype, u16 app_id)
784 return __cxgb4_getapp(dev, app_idtype, app_id, 0);
787 /* Write a new Application User Priority Map for the specified Application ID
789 static int __cxgb4_setapp(struct net_device *dev, u8 app_idtype, u16 app_id,
792 struct fw_port_cmd pcmd;
793 struct port_info *pi = netdev2pinfo(dev);
794 struct adapter *adap = pi->adapter;
798 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
801 /* DCB info gets thrown away on link up */
802 if (!netif_carrier_ok(dev))
805 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
806 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
807 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
808 pcmd.u.dcb.app_priority.idx = i;
809 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
811 if (err != FW_PORT_DCB_CFG_SUCCESS) {
812 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
816 if (be16_to_cpu(pcmd.u.dcb.app_priority.protocolid) == app_id) {
817 /* overwrite existing app table */
818 pcmd.u.dcb.app_priority.protocolid = 0;
821 /* find first empty slot */
822 if (!pcmd.u.dcb.app_priority.protocolid)
826 if (i == CXGB4_MAX_DCBX_APP_SUPPORTED) {
827 /* no empty slots available */
828 dev_err(adap->pdev_dev, "DCB app table full\n");
832 /* write out new app table entry */
833 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
834 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
835 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY);
837 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
838 pcmd.u.dcb.app_priority.protocolid = cpu_to_be16(app_id);
839 pcmd.u.dcb.app_priority.sel_field = app_idtype;
840 pcmd.u.dcb.app_priority.user_prio_map = app_prio;
841 pcmd.u.dcb.app_priority.idx = i;
843 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
844 if (err != FW_PORT_DCB_CFG_SUCCESS) {
845 dev_err(adap->pdev_dev, "DCB app table write failed with %d\n",
853 /* Priority for CEE inside dcb_app is bitmask, with 0 being an invalid value */
854 static int cxgb4_setapp(struct net_device *dev, u8 app_idtype, u16 app_id,
858 struct dcb_app app = {
859 .selector = app_idtype,
861 .priority = app_prio,
864 if (app_idtype != DCB_APP_IDTYPE_ETHTYPE &&
865 app_idtype != DCB_APP_IDTYPE_PORTNUM)
868 /* Convert app_idtype to a format that firmware understands */
869 ret = __cxgb4_setapp(dev, app_idtype == DCB_APP_IDTYPE_ETHTYPE ?
870 app_idtype : 3, app_id, app_prio);
874 return dcb_setapp(dev, &app);
877 /* Return whether IEEE Data Center Bridging has been negotiated.
880 cxgb4_ieee_negotiation_complete(struct net_device *dev,
881 enum cxgb4_dcb_fw_msgs dcb_subtype)
883 struct port_info *pi = netdev2pinfo(dev);
884 struct port_dcb_info *dcb = &pi->dcb;
886 if (dcb_subtype && !(dcb->msgs & dcb_subtype))
889 return (dcb->state == CXGB4_DCB_STATE_FW_ALLSYNCED &&
890 (dcb->supported & DCB_CAP_DCBX_VER_IEEE));
893 /* Fill in the Application User Priority Map associated with the
894 * specified Application.
895 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
897 static int cxgb4_ieee_getapp(struct net_device *dev, struct dcb_app *app)
901 if (!cxgb4_ieee_negotiation_complete(dev, CXGB4_DCB_FW_APP_ID))
903 if (!(app->selector && app->protocol))
906 /* Try querying firmware first, use firmware format */
907 prio = __cxgb4_getapp(dev, app->selector - 1, app->protocol, 0);
910 prio = dcb_ieee_getapp_mask(dev, app);
912 app->priority = ffs(prio) - 1;
916 /* Write a new Application User Priority Map for the specified Application ID.
917 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
919 static int cxgb4_ieee_setapp(struct net_device *dev, struct dcb_app *app)
923 if (!cxgb4_ieee_negotiation_complete(dev, CXGB4_DCB_FW_APP_ID))
925 if (!(app->selector && app->protocol))
928 if (!(app->selector > IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
929 app->selector < IEEE_8021QAZ_APP_SEL_ANY))
932 /* change selector to a format that firmware understands */
933 ret = __cxgb4_setapp(dev, app->selector - 1, app->protocol,
934 (1 << app->priority));
938 return dcb_ieee_setapp(dev, app);
941 /* Return our DCBX parameters.
943 static u8 cxgb4_getdcbx(struct net_device *dev)
945 struct port_info *pi = netdev2pinfo(dev);
947 /* This is already set by cxgb4_set_dcb_caps, so just return it */
948 return pi->dcb.supported;
951 /* Set our DCBX parameters.
953 static u8 cxgb4_setdcbx(struct net_device *dev, u8 dcb_request)
955 struct port_info *pi = netdev2pinfo(dev);
957 /* Filter out requests which exceed our capabilities.
959 if ((dcb_request & (CXGB4_DCBX_FW_SUPPORT | CXGB4_DCBX_HOST_SUPPORT))
963 /* Can't enable DCB if we haven't successfully negotiated it.
965 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
968 /* There's currently no mechanism to allow for the firmware DCBX
969 * negotiation to be changed from the Host Driver. If the caller
970 * requests exactly the same parameters that we already have then
971 * we'll allow them to be successfully "set" ...
973 if (dcb_request != pi->dcb.supported)
976 pi->dcb.supported = dcb_request;
980 static int cxgb4_getpeer_app(struct net_device *dev,
981 struct dcb_peer_app_info *info, u16 *app_count)
983 struct fw_port_cmd pcmd;
984 struct port_info *pi = netdev2pinfo(dev);
985 struct adapter *adap = pi->adapter;
988 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
995 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
996 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
997 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
998 pcmd.u.dcb.app_priority.idx = *app_count;
999 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1001 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1002 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
1007 /* find first empty slot */
1008 if (!pcmd.u.dcb.app_priority.protocolid)
1015 static int cxgb4_getpeerapp_tbl(struct net_device *dev, struct dcb_app *table)
1017 struct fw_port_cmd pcmd;
1018 struct port_info *pi = netdev2pinfo(dev);
1019 struct adapter *adap = pi->adapter;
1022 if (pi->dcb.state != CXGB4_DCB_STATE_FW_ALLSYNCED)
1025 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
1026 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1027 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
1028 pcmd.u.dcb.app_priority.idx = i;
1029 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1031 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1032 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
1037 /* find first empty slot */
1038 if (!pcmd.u.dcb.app_priority.protocolid)
1041 table[i].selector = pcmd.u.dcb.app_priority.sel_field;
1043 be16_to_cpu(pcmd.u.dcb.app_priority.protocolid);
1045 ffs(pcmd.u.dcb.app_priority.user_prio_map) - 1;
1050 /* Return Priority Group information.
1052 static int cxgb4_cee_peer_getpg(struct net_device *dev, struct cee_pg *pg)
1054 struct fw_port_cmd pcmd;
1055 struct port_info *pi = netdev2pinfo(dev);
1056 struct adapter *adap = pi->adapter;
1060 /* We're always "willing" -- the Switch Fabric always dictates the
1061 * DCBX parameters to us.
1065 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1066 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
1067 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1068 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1069 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
1072 pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
1074 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1075 pg->prio_pg[i] = (pgid >> (i * 4)) & 0xF;
1077 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1078 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
1079 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1080 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1081 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
1086 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1087 pg->pg_bw[i] = pcmd.u.dcb.pgrate.pgrate[i];
1092 /* Return Priority Flow Control information.
1094 static int cxgb4_cee_peer_getpfc(struct net_device *dev, struct cee_pfc *pfc)
1096 struct port_info *pi = netdev2pinfo(dev);
1098 cxgb4_getnumtcs(dev, DCB_NUMTCS_ATTR_PFC, &(pfc->tcs_supported));
1099 pfc->pfc_en = pi->dcb.pfcen;
1104 const struct dcbnl_rtnl_ops cxgb4_dcb_ops = {
1105 .ieee_getapp = cxgb4_ieee_getapp,
1106 .ieee_setapp = cxgb4_ieee_setapp,
1109 .getstate = cxgb4_getstate,
1110 .setstate = cxgb4_setstate,
1111 .getpgtccfgtx = cxgb4_getpgtccfg_tx,
1112 .getpgbwgcfgtx = cxgb4_getpgbwgcfg_tx,
1113 .getpgtccfgrx = cxgb4_getpgtccfg_rx,
1114 .getpgbwgcfgrx = cxgb4_getpgbwgcfg_rx,
1115 .setpgtccfgtx = cxgb4_setpgtccfg_tx,
1116 .setpgbwgcfgtx = cxgb4_setpgbwgcfg_tx,
1117 .setpfccfg = cxgb4_setpfccfg,
1118 .getpfccfg = cxgb4_getpfccfg,
1119 .setall = cxgb4_setall,
1120 .getcap = cxgb4_getcap,
1121 .getnumtcs = cxgb4_getnumtcs,
1122 .setnumtcs = cxgb4_setnumtcs,
1123 .getpfcstate = cxgb4_getpfcstate,
1124 .setpfcstate = cxgb4_setpfcstate,
1125 .getapp = cxgb4_getapp,
1126 .setapp = cxgb4_setapp,
1128 /* DCBX configuration */
1129 .getdcbx = cxgb4_getdcbx,
1130 .setdcbx = cxgb4_setdcbx,
1133 .peer_getappinfo = cxgb4_getpeer_app,
1134 .peer_getapptable = cxgb4_getpeerapp_tbl,
1137 .cee_peer_getpg = cxgb4_cee_peer_getpg,
1138 .cee_peer_getpfc = cxgb4_cee_peer_getpfc,