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 const char * const dcb_ver_array[] = {
34 static inline bool cxgb4_dcb_state_synced(enum cxgb4_dcb_state state)
36 if (state == CXGB4_DCB_STATE_FW_ALLSYNCED ||
37 state == CXGB4_DCB_STATE_HOST)
43 /* Initialize a port's Data Center Bridging state.
45 void cxgb4_dcb_state_init(struct net_device *dev)
47 struct port_info *pi = netdev2pinfo(dev);
48 struct port_dcb_info *dcb = &pi->dcb;
49 int version_temp = dcb->dcb_version;
51 memset(dcb, 0, sizeof(struct port_dcb_info));
52 dcb->state = CXGB4_DCB_STATE_START;
54 dcb->dcb_version = version_temp;
56 netdev_dbg(dev, "%s: Initializing DCB state for port[%d]\n",
57 __func__, pi->port_id);
60 void cxgb4_dcb_version_init(struct net_device *dev)
62 struct port_info *pi = netdev2pinfo(dev);
63 struct port_dcb_info *dcb = &pi->dcb;
65 /* Any writes here are only done on kernels that exlicitly need
66 * a specific version, say < 2.6.38 which only support CEE
68 dcb->dcb_version = FW_PORT_DCB_VER_AUTO;
71 static void cxgb4_dcb_cleanup_apps(struct net_device *dev)
73 struct port_info *pi = netdev2pinfo(dev);
74 struct adapter *adap = pi->adapter;
75 struct port_dcb_info *dcb = &pi->dcb;
79 /* zero priority implies remove */
82 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
83 /* Check if app list is exhausted */
84 if (!dcb->app_priority[i].protocolid)
87 app.protocol = dcb->app_priority[i].protocolid;
89 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE) {
90 app.priority = dcb->app_priority[i].user_prio_map;
91 app.selector = dcb->app_priority[i].sel_field + 1;
92 err = dcb_ieee_delapp(dev, &app);
94 app.selector = !!(dcb->app_priority[i].sel_field);
95 err = dcb_setapp(dev, &app);
99 dev_err(adap->pdev_dev,
100 "Failed DCB Clear %s Application Priority: sel=%d, prot=%d, , err=%d\n",
101 dcb_ver_array[dcb->dcb_version], app.selector,
108 /* Reset a port's Data Center Bridging state. Typically used after a
111 void cxgb4_dcb_reset(struct net_device *dev)
113 cxgb4_dcb_cleanup_apps(dev);
114 cxgb4_dcb_state_init(dev);
117 /* Finite State machine for Data Center Bridging.
119 void cxgb4_dcb_state_fsm(struct net_device *dev,
120 enum cxgb4_dcb_state_input transition_to)
122 struct port_info *pi = netdev2pinfo(dev);
123 struct port_dcb_info *dcb = &pi->dcb;
124 struct adapter *adap = pi->adapter;
125 enum cxgb4_dcb_state current_state = dcb->state;
127 netdev_dbg(dev, "%s: State change from %d to %d for %s\n",
128 __func__, dcb->state, transition_to, dev->name);
130 switch (current_state) {
131 case CXGB4_DCB_STATE_START: {
132 switch (transition_to) {
133 case CXGB4_DCB_INPUT_FW_DISABLED: {
134 /* we're going to use Host DCB */
135 dcb->state = CXGB4_DCB_STATE_HOST;
136 dcb->supported = CXGB4_DCBX_HOST_SUPPORT;
140 case CXGB4_DCB_INPUT_FW_ENABLED: {
141 /* we're going to use Firmware DCB */
142 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE;
143 dcb->supported = DCB_CAP_DCBX_LLD_MANAGED;
144 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE)
145 dcb->supported |= DCB_CAP_DCBX_VER_IEEE;
147 dcb->supported |= DCB_CAP_DCBX_VER_CEE;
151 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
152 /* expected transition */
156 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
157 dcb->state = CXGB4_DCB_STATE_FW_ALLSYNCED;
162 goto bad_state_input;
167 case CXGB4_DCB_STATE_FW_INCOMPLETE: {
168 switch (transition_to) {
169 case CXGB4_DCB_INPUT_FW_ENABLED: {
170 /* we're alreaady in firmware DCB mode */
174 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
175 /* we're already incomplete */
179 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
180 dcb->state = CXGB4_DCB_STATE_FW_ALLSYNCED;
182 linkwatch_fire_event(dev);
187 goto bad_state_input;
192 case CXGB4_DCB_STATE_FW_ALLSYNCED: {
193 switch (transition_to) {
194 case CXGB4_DCB_INPUT_FW_ENABLED: {
195 /* we're alreaady in firmware DCB mode */
199 case CXGB4_DCB_INPUT_FW_INCOMPLETE: {
200 /* We were successfully running with firmware DCB but
201 * now it's telling us that it's in an "incomplete
202 * state. We need to reset back to a ground state
205 cxgb4_dcb_reset(dev);
206 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE;
207 dcb->supported = CXGB4_DCBX_FW_SUPPORT;
208 linkwatch_fire_event(dev);
212 case CXGB4_DCB_INPUT_FW_ALLSYNCED: {
213 /* we're already all sync'ed
214 * this is only applicable for IEEE or
215 * when another VI already completed negotiaton
218 linkwatch_fire_event(dev);
223 goto bad_state_input;
228 case CXGB4_DCB_STATE_HOST: {
229 switch (transition_to) {
230 case CXGB4_DCB_INPUT_FW_DISABLED: {
231 /* we're alreaady in Host DCB mode */
236 goto bad_state_input;
242 goto bad_state_transition;
247 dev_err(adap->pdev_dev, "cxgb4_dcb_state_fsm: illegal input symbol %d\n",
251 bad_state_transition:
252 dev_err(adap->pdev_dev, "cxgb4_dcb_state_fsm: bad state transition, state = %d, input = %d\n",
253 current_state, transition_to);
256 /* Handle a DCB/DCBX update message from the firmware.
258 void cxgb4_dcb_handle_fw_update(struct adapter *adap,
259 const struct fw_port_cmd *pcmd)
261 const union fw_port_dcb *fwdcb = &pcmd->u.dcb;
262 int port = FW_PORT_CMD_PORTID_G(be32_to_cpu(pcmd->op_to_portid));
263 struct net_device *dev = adap->port[adap->chan_map[port]];
264 struct port_info *pi = netdev_priv(dev);
265 struct port_dcb_info *dcb = &pi->dcb;
266 int dcb_type = pcmd->u.dcb.pgid.type;
267 int dcb_running_version;
269 /* Handle Firmware DCB Control messages separately since they drive
272 if (dcb_type == FW_PORT_DCB_TYPE_CONTROL) {
273 enum cxgb4_dcb_state_input input =
274 ((pcmd->u.dcb.control.all_syncd_pkd &
275 FW_PORT_CMD_ALL_SYNCD_F)
276 ? CXGB4_DCB_INPUT_FW_ALLSYNCED
277 : CXGB4_DCB_INPUT_FW_INCOMPLETE);
279 if (dcb->dcb_version != FW_PORT_DCB_VER_UNKNOWN) {
280 dcb_running_version = FW_PORT_CMD_DCB_VERSION_G(
282 pcmd->u.dcb.control.dcb_version_to_app_state));
283 if (dcb_running_version == FW_PORT_DCB_VER_CEE1D01 ||
284 dcb_running_version == FW_PORT_DCB_VER_IEEE) {
285 dcb->dcb_version = dcb_running_version;
286 dev_warn(adap->pdev_dev, "Interface %s is running %s\n",
288 dcb_ver_array[dcb->dcb_version]);
290 dev_warn(adap->pdev_dev,
291 "Something screwed up, requested firmware for %s, but firmware returned %s instead\n",
292 dcb_ver_array[dcb->dcb_version],
293 dcb_ver_array[dcb_running_version]);
294 dcb->dcb_version = FW_PORT_DCB_VER_UNKNOWN;
298 cxgb4_dcb_state_fsm(dev, input);
302 /* It's weird, and almost certainly an error, to get Firmware DCB
303 * messages when we either haven't been told whether we're going to be
304 * doing Host or Firmware DCB; and even worse when we've been told
305 * that we're doing Host DCB!
307 if (dcb->state == CXGB4_DCB_STATE_START ||
308 dcb->state == CXGB4_DCB_STATE_HOST) {
309 dev_err(adap->pdev_dev, "Receiving Firmware DCB messages in State %d\n",
314 /* Now handle the general Firmware DCB update messages ...
317 case FW_PORT_DCB_TYPE_PGID:
318 dcb->pgid = be32_to_cpu(fwdcb->pgid.pgid);
319 dcb->msgs |= CXGB4_DCB_FW_PGID;
322 case FW_PORT_DCB_TYPE_PGRATE:
323 dcb->pg_num_tcs_supported = fwdcb->pgrate.num_tcs_supported;
324 memcpy(dcb->pgrate, &fwdcb->pgrate.pgrate,
325 sizeof(dcb->pgrate));
326 memcpy(dcb->tsa, &fwdcb->pgrate.tsa,
328 dcb->msgs |= CXGB4_DCB_FW_PGRATE;
329 if (dcb->msgs & CXGB4_DCB_FW_PGID)
330 IEEE_FAUX_SYNC(dev, dcb);
333 case FW_PORT_DCB_TYPE_PRIORATE:
334 memcpy(dcb->priorate, &fwdcb->priorate.strict_priorate,
335 sizeof(dcb->priorate));
336 dcb->msgs |= CXGB4_DCB_FW_PRIORATE;
339 case FW_PORT_DCB_TYPE_PFC:
340 dcb->pfcen = fwdcb->pfc.pfcen;
341 dcb->pfc_num_tcs_supported = fwdcb->pfc.max_pfc_tcs;
342 dcb->msgs |= CXGB4_DCB_FW_PFC;
343 IEEE_FAUX_SYNC(dev, dcb);
346 case FW_PORT_DCB_TYPE_APP_ID: {
347 const struct fw_port_app_priority *fwap = &fwdcb->app_priority;
349 struct app_priority *ap = &dcb->app_priority[idx];
351 struct dcb_app app = {
352 .protocol = be16_to_cpu(fwap->protocolid),
356 /* Convert from firmware format to relevant format
357 * when using app selector
359 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE) {
360 app.selector = (fwap->sel_field + 1);
361 app.priority = ffs(fwap->user_prio_map) - 1;
362 err = dcb_ieee_setapp(dev, &app);
363 IEEE_FAUX_SYNC(dev, dcb);
366 app.selector = !!(fwap->sel_field);
367 app.priority = fwap->user_prio_map;
368 err = dcb_setapp(dev, &app);
372 dev_err(adap->pdev_dev,
373 "Failed DCB Set Application Priority: sel=%d, prot=%d, prio=%d, err=%d\n",
374 app.selector, app.protocol, app.priority, -err);
376 ap->user_prio_map = fwap->user_prio_map;
377 ap->sel_field = fwap->sel_field;
378 ap->protocolid = be16_to_cpu(fwap->protocolid);
379 dcb->msgs |= CXGB4_DCB_FW_APP_ID;
384 dev_err(adap->pdev_dev, "Unknown DCB update type received %x\n",
390 /* Data Center Bridging netlink operations.
394 /* Get current DCB enabled/disabled state.
396 static u8 cxgb4_getstate(struct net_device *dev)
398 struct port_info *pi = netdev2pinfo(dev);
400 return pi->dcb.enabled;
403 /* Set DCB enabled/disabled.
405 static u8 cxgb4_setstate(struct net_device *dev, u8 enabled)
407 struct port_info *pi = netdev2pinfo(dev);
409 /* If DCBx is host-managed, dcb is enabled by outside lldp agents */
410 if (pi->dcb.state == CXGB4_DCB_STATE_HOST) {
411 pi->dcb.enabled = enabled;
415 /* Firmware doesn't provide any mechanism to control the DCB state.
417 if (enabled != (pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED))
423 static void cxgb4_getpgtccfg(struct net_device *dev, int tc,
424 u8 *prio_type, u8 *pgid, u8 *bw_per,
425 u8 *up_tc_map, int local)
427 struct fw_port_cmd pcmd;
428 struct port_info *pi = netdev2pinfo(dev);
429 struct adapter *adap = pi->adapter;
432 *prio_type = *pgid = *bw_per = *up_tc_map = 0;
435 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
437 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
439 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
440 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
441 if (err != FW_PORT_DCB_CFG_SUCCESS) {
442 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
445 *pgid = (be32_to_cpu(pcmd.u.dcb.pgid.pgid) >> (tc * 4)) & 0xf;
448 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
450 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
451 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
452 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
453 if (err != FW_PORT_DCB_CFG_SUCCESS) {
454 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
459 *bw_per = pcmd.u.dcb.pgrate.pgrate[*pgid];
460 *up_tc_map = (1 << tc);
462 /* prio_type is link strict */
467 static void cxgb4_getpgtccfg_tx(struct net_device *dev, int tc,
468 u8 *prio_type, u8 *pgid, u8 *bw_per,
471 /* tc 0 is written at MSB position */
472 return cxgb4_getpgtccfg(dev, (7 - tc), prio_type, pgid, bw_per,
477 static void cxgb4_getpgtccfg_rx(struct net_device *dev, int tc,
478 u8 *prio_type, u8 *pgid, u8 *bw_per,
481 /* tc 0 is written at MSB position */
482 return cxgb4_getpgtccfg(dev, (7 - tc), prio_type, pgid, bw_per,
486 static void cxgb4_setpgtccfg_tx(struct net_device *dev, int tc,
487 u8 prio_type, u8 pgid, u8 bw_per,
490 struct fw_port_cmd pcmd;
491 struct port_info *pi = netdev2pinfo(dev);
492 struct adapter *adap = pi->adapter;
497 if (pgid == DCB_ATTR_VALUE_UNDEFINED)
499 if (bw_per == DCB_ATTR_VALUE_UNDEFINED)
502 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
503 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
505 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
506 if (err != FW_PORT_DCB_CFG_SUCCESS) {
507 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
511 _pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
512 _pgid &= ~(0xF << (fw_tc * 4));
513 _pgid |= pgid << (fw_tc * 4);
514 pcmd.u.dcb.pgid.pgid = cpu_to_be32(_pgid);
516 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
518 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
519 if (err != FW_PORT_DCB_CFG_SUCCESS) {
520 dev_err(adap->pdev_dev, "DCB write PGID failed with %d\n",
525 memset(&pcmd, 0, sizeof(struct fw_port_cmd));
527 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
528 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
530 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
531 if (err != FW_PORT_DCB_CFG_SUCCESS) {
532 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
537 pcmd.u.dcb.pgrate.pgrate[pgid] = bw_per;
539 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
540 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
541 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY_F);
543 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
544 if (err != FW_PORT_DCB_CFG_SUCCESS)
545 dev_err(adap->pdev_dev, "DCB write PGRATE failed with %d\n",
549 static void cxgb4_getpgbwgcfg(struct net_device *dev, int pgid, u8 *bw_per,
552 struct fw_port_cmd pcmd;
553 struct port_info *pi = netdev2pinfo(dev);
554 struct adapter *adap = pi->adapter;
558 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
560 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
562 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
563 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
564 if (err != FW_PORT_DCB_CFG_SUCCESS) {
565 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
570 *bw_per = pcmd.u.dcb.pgrate.pgrate[pgid];
573 static void cxgb4_getpgbwgcfg_tx(struct net_device *dev, int pgid, u8 *bw_per)
575 return cxgb4_getpgbwgcfg(dev, pgid, bw_per, 1);
578 static void cxgb4_getpgbwgcfg_rx(struct net_device *dev, int pgid, u8 *bw_per)
580 return cxgb4_getpgbwgcfg(dev, pgid, bw_per, 0);
583 static void cxgb4_setpgbwgcfg_tx(struct net_device *dev, int pgid,
586 struct fw_port_cmd pcmd;
587 struct port_info *pi = netdev2pinfo(dev);
588 struct adapter *adap = pi->adapter;
591 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
592 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
594 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
595 if (err != FW_PORT_DCB_CFG_SUCCESS) {
596 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
601 pcmd.u.dcb.pgrate.pgrate[pgid] = bw_per;
603 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
604 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
605 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY_F);
607 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
609 if (err != FW_PORT_DCB_CFG_SUCCESS)
610 dev_err(adap->pdev_dev, "DCB write PGRATE failed with %d\n",
614 /* Return whether the specified Traffic Class Priority has Priority Pause
617 static void cxgb4_getpfccfg(struct net_device *dev, int priority, u8 *pfccfg)
619 struct port_info *pi = netdev2pinfo(dev);
620 struct port_dcb_info *dcb = &pi->dcb;
622 if (!cxgb4_dcb_state_synced(dcb->state) ||
623 priority >= CXGB4_MAX_PRIORITY)
626 *pfccfg = (pi->dcb.pfcen >> (7 - priority)) & 1;
629 /* Enable/disable Priority Pause Frames for the specified Traffic Class
632 static void cxgb4_setpfccfg(struct net_device *dev, int priority, u8 pfccfg)
634 struct fw_port_cmd pcmd;
635 struct port_info *pi = netdev2pinfo(dev);
636 struct adapter *adap = pi->adapter;
639 if (!cxgb4_dcb_state_synced(pi->dcb.state) ||
640 priority >= CXGB4_MAX_PRIORITY)
643 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
644 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
645 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY_F);
647 pcmd.u.dcb.pfc.type = FW_PORT_DCB_TYPE_PFC;
648 pcmd.u.dcb.pfc.pfcen = pi->dcb.pfcen;
651 pcmd.u.dcb.pfc.pfcen |= (1 << (7 - priority));
653 pcmd.u.dcb.pfc.pfcen &= (~(1 << (7 - priority)));
655 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
656 if (err != FW_PORT_DCB_CFG_SUCCESS) {
657 dev_err(adap->pdev_dev, "DCB PFC write failed with %d\n", -err);
661 pi->dcb.pfcen = pcmd.u.dcb.pfc.pfcen;
664 static u8 cxgb4_setall(struct net_device *dev)
669 /* Return DCB capabilities.
671 static u8 cxgb4_getcap(struct net_device *dev, int cap_id, u8 *caps)
673 struct port_info *pi = netdev2pinfo(dev);
676 case DCB_CAP_ATTR_PG:
677 case DCB_CAP_ATTR_PFC:
681 case DCB_CAP_ATTR_PG_TCS:
682 /* 8 priorities for PG represented by bitmap */
686 case DCB_CAP_ATTR_PFC_TCS:
687 /* 8 priorities for PFC represented by bitmap */
691 case DCB_CAP_ATTR_GSP:
695 case DCB_CAP_ATTR_UP2TC:
696 case DCB_CAP_ATTR_BCN:
700 case DCB_CAP_ATTR_DCBX:
701 *caps = pi->dcb.supported;
711 /* Return the number of Traffic Classes for the indicated Traffic Class ID.
713 static int cxgb4_getnumtcs(struct net_device *dev, int tcs_id, u8 *num)
715 struct port_info *pi = netdev2pinfo(dev);
718 case DCB_NUMTCS_ATTR_PG:
719 if (pi->dcb.msgs & CXGB4_DCB_FW_PGRATE)
720 *num = pi->dcb.pg_num_tcs_supported;
725 case DCB_NUMTCS_ATTR_PFC:
736 /* Set the number of Traffic Classes supported for the indicated Traffic Class
739 static int cxgb4_setnumtcs(struct net_device *dev, int tcs_id, u8 num)
741 /* Setting the number of Traffic Classes isn't supported.
746 /* Return whether Priority Flow Control is enabled. */
747 static u8 cxgb4_getpfcstate(struct net_device *dev)
749 struct port_info *pi = netdev2pinfo(dev);
751 if (!cxgb4_dcb_state_synced(pi->dcb.state))
754 return pi->dcb.pfcen != 0;
757 /* Enable/disable Priority Flow Control. */
758 static void cxgb4_setpfcstate(struct net_device *dev, u8 state)
760 /* We can't enable/disable Priority Flow Control but we also can't
761 * return an error ...
765 /* Return the Application User Priority Map associated with the specified
768 static int __cxgb4_getapp(struct net_device *dev, u8 app_idtype, u16 app_id,
771 struct port_info *pi = netdev2pinfo(dev);
772 struct adapter *adap = pi->adapter;
775 if (!cxgb4_dcb_state_synced(pi->dcb.state))
778 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
779 struct fw_port_cmd pcmd;
783 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
785 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
787 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
788 pcmd.u.dcb.app_priority.idx = i;
790 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
791 if (err != FW_PORT_DCB_CFG_SUCCESS) {
792 dev_err(adap->pdev_dev, "DCB APP read failed with %d\n",
796 if (be16_to_cpu(pcmd.u.dcb.app_priority.protocolid) == app_id)
797 if (pcmd.u.dcb.app_priority.sel_field == app_idtype)
798 return pcmd.u.dcb.app_priority.user_prio_map;
800 /* exhausted app list */
801 if (!pcmd.u.dcb.app_priority.protocolid)
808 /* Return the Application User Priority Map associated with the specified
811 static int cxgb4_getapp(struct net_device *dev, u8 app_idtype, u16 app_id)
813 /* Convert app_idtype to firmware format before querying */
814 return __cxgb4_getapp(dev, app_idtype == DCB_APP_IDTYPE_ETHTYPE ?
815 app_idtype : 3, app_id, 0);
818 /* Write a new Application User Priority Map for the specified Application ID
820 static int __cxgb4_setapp(struct net_device *dev, u8 app_idtype, u16 app_id,
823 struct fw_port_cmd pcmd;
824 struct port_info *pi = netdev2pinfo(dev);
825 struct adapter *adap = pi->adapter;
829 if (!cxgb4_dcb_state_synced(pi->dcb.state))
832 /* DCB info gets thrown away on link up */
833 if (!netif_carrier_ok(dev))
836 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
837 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
838 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
839 pcmd.u.dcb.app_priority.idx = i;
840 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
842 if (err != FW_PORT_DCB_CFG_SUCCESS) {
843 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
847 if (be16_to_cpu(pcmd.u.dcb.app_priority.protocolid) == app_id) {
848 /* overwrite existing app table */
849 pcmd.u.dcb.app_priority.protocolid = 0;
852 /* find first empty slot */
853 if (!pcmd.u.dcb.app_priority.protocolid)
857 if (i == CXGB4_MAX_DCBX_APP_SUPPORTED) {
858 /* no empty slots available */
859 dev_err(adap->pdev_dev, "DCB app table full\n");
863 /* write out new app table entry */
864 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
865 if (pi->dcb.state == CXGB4_DCB_STATE_HOST)
866 pcmd.op_to_portid |= cpu_to_be32(FW_PORT_CMD_APPLY_F);
868 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
869 pcmd.u.dcb.app_priority.protocolid = cpu_to_be16(app_id);
870 pcmd.u.dcb.app_priority.sel_field = app_idtype;
871 pcmd.u.dcb.app_priority.user_prio_map = app_prio;
872 pcmd.u.dcb.app_priority.idx = i;
874 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
875 if (err != FW_PORT_DCB_CFG_SUCCESS) {
876 dev_err(adap->pdev_dev, "DCB app table write failed with %d\n",
884 /* Priority for CEE inside dcb_app is bitmask, with 0 being an invalid value */
885 static int cxgb4_setapp(struct net_device *dev, u8 app_idtype, u16 app_id,
889 struct dcb_app app = {
890 .selector = app_idtype,
892 .priority = app_prio,
895 if (app_idtype != DCB_APP_IDTYPE_ETHTYPE &&
896 app_idtype != DCB_APP_IDTYPE_PORTNUM)
899 /* Convert app_idtype to a format that firmware understands */
900 ret = __cxgb4_setapp(dev, app_idtype == DCB_APP_IDTYPE_ETHTYPE ?
901 app_idtype : 3, app_id, app_prio);
905 return dcb_setapp(dev, &app);
908 /* Return whether IEEE Data Center Bridging has been negotiated.
911 cxgb4_ieee_negotiation_complete(struct net_device *dev,
912 enum cxgb4_dcb_fw_msgs dcb_subtype)
914 struct port_info *pi = netdev2pinfo(dev);
915 struct port_dcb_info *dcb = &pi->dcb;
917 if (dcb->state == CXGB4_DCB_STATE_FW_ALLSYNCED)
918 if (dcb_subtype && !(dcb->msgs & dcb_subtype))
921 return (cxgb4_dcb_state_synced(dcb->state) &&
922 (dcb->supported & DCB_CAP_DCBX_VER_IEEE));
925 static int cxgb4_ieee_read_ets(struct net_device *dev, struct ieee_ets *ets,
928 struct port_info *pi = netdev2pinfo(dev);
929 struct port_dcb_info *dcb = &pi->dcb;
930 struct adapter *adap = pi->adapter;
932 struct fw_port_cmd pcmd;
935 if (!(dcb->msgs & (CXGB4_DCB_FW_PGID | CXGB4_DCB_FW_PGRATE)))
938 ets->ets_cap = dcb->pg_num_tcs_supported;
942 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
944 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
947 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
948 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
949 if (err != FW_PORT_DCB_CFG_SUCCESS) {
950 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
954 tc_info = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
957 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd, pi->port_id);
959 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
961 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
962 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
963 if (err != FW_PORT_DCB_CFG_SUCCESS) {
964 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
969 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
970 bwg = (tc_info >> ((7 - i) * 4)) & 0xF;
971 ets->prio_tc[i] = bwg;
972 ets->tc_tx_bw[i] = pcmd.u.dcb.pgrate.pgrate[i];
973 ets->tc_rx_bw[i] = ets->tc_tx_bw[i];
974 ets->tc_tsa[i] = pcmd.u.dcb.pgrate.tsa[i];
980 static int cxgb4_ieee_get_ets(struct net_device *dev, struct ieee_ets *ets)
982 return cxgb4_ieee_read_ets(dev, ets, 1);
985 /* We reuse this for peer PFC as well, as we can't have it enabled one way */
986 static int cxgb4_ieee_get_pfc(struct net_device *dev, struct ieee_pfc *pfc)
988 struct port_info *pi = netdev2pinfo(dev);
989 struct port_dcb_info *dcb = &pi->dcb;
991 memset(pfc, 0, sizeof(struct ieee_pfc));
993 if (!(dcb->msgs & CXGB4_DCB_FW_PFC))
996 pfc->pfc_cap = dcb->pfc_num_tcs_supported;
997 pfc->pfc_en = bitswap_1(dcb->pfcen);
1002 static int cxgb4_ieee_peer_ets(struct net_device *dev, struct ieee_ets *ets)
1004 return cxgb4_ieee_read_ets(dev, ets, 0);
1007 /* Fill in the Application User Priority Map associated with the
1008 * specified Application.
1009 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
1011 static int cxgb4_ieee_getapp(struct net_device *dev, struct dcb_app *app)
1015 if (!cxgb4_ieee_negotiation_complete(dev, CXGB4_DCB_FW_APP_ID))
1017 if (!(app->selector && app->protocol))
1020 /* Try querying firmware first, use firmware format */
1021 prio = __cxgb4_getapp(dev, app->selector - 1, app->protocol, 0);
1024 prio = dcb_ieee_getapp_mask(dev, app);
1026 app->priority = ffs(prio) - 1;
1030 /* Write a new Application User Priority Map for the specified Application ID.
1031 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
1033 static int cxgb4_ieee_setapp(struct net_device *dev, struct dcb_app *app)
1037 if (!cxgb4_ieee_negotiation_complete(dev, CXGB4_DCB_FW_APP_ID))
1039 if (!(app->selector && app->protocol))
1042 if (!(app->selector > IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
1043 app->selector < IEEE_8021QAZ_APP_SEL_ANY))
1046 /* change selector to a format that firmware understands */
1047 ret = __cxgb4_setapp(dev, app->selector - 1, app->protocol,
1048 (1 << app->priority));
1052 return dcb_ieee_setapp(dev, app);
1055 /* Return our DCBX parameters.
1057 static u8 cxgb4_getdcbx(struct net_device *dev)
1059 struct port_info *pi = netdev2pinfo(dev);
1061 /* This is already set by cxgb4_set_dcb_caps, so just return it */
1062 return pi->dcb.supported;
1065 /* Set our DCBX parameters.
1067 static u8 cxgb4_setdcbx(struct net_device *dev, u8 dcb_request)
1069 struct port_info *pi = netdev2pinfo(dev);
1071 /* Filter out requests which exceed our capabilities.
1073 if ((dcb_request & (CXGB4_DCBX_FW_SUPPORT | CXGB4_DCBX_HOST_SUPPORT))
1077 /* Can't enable DCB if we haven't successfully negotiated it.
1079 if (!cxgb4_dcb_state_synced(pi->dcb.state))
1082 /* There's currently no mechanism to allow for the firmware DCBX
1083 * negotiation to be changed from the Host Driver. If the caller
1084 * requests exactly the same parameters that we already have then
1085 * we'll allow them to be successfully "set" ...
1087 if (dcb_request != pi->dcb.supported)
1090 pi->dcb.supported = dcb_request;
1094 static int cxgb4_getpeer_app(struct net_device *dev,
1095 struct dcb_peer_app_info *info, u16 *app_count)
1097 struct fw_port_cmd pcmd;
1098 struct port_info *pi = netdev2pinfo(dev);
1099 struct adapter *adap = pi->adapter;
1102 if (!cxgb4_dcb_state_synced(pi->dcb.state))
1109 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
1110 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1111 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
1112 pcmd.u.dcb.app_priority.idx = *app_count;
1113 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1115 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1116 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
1121 /* find first empty slot */
1122 if (!pcmd.u.dcb.app_priority.protocolid)
1129 static int cxgb4_getpeerapp_tbl(struct net_device *dev, struct dcb_app *table)
1131 struct fw_port_cmd pcmd;
1132 struct port_info *pi = netdev2pinfo(dev);
1133 struct adapter *adap = pi->adapter;
1136 if (!cxgb4_dcb_state_synced(pi->dcb.state))
1139 for (i = 0; i < CXGB4_MAX_DCBX_APP_SUPPORTED; i++) {
1140 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1141 pcmd.u.dcb.app_priority.type = FW_PORT_DCB_TYPE_APP_ID;
1142 pcmd.u.dcb.app_priority.idx = i;
1143 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1145 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1146 dev_err(adap->pdev_dev, "DCB app table read failed with %d\n",
1151 /* find first empty slot */
1152 if (!pcmd.u.dcb.app_priority.protocolid)
1155 table[i].selector = (pcmd.u.dcb.app_priority.sel_field + 1);
1157 be16_to_cpu(pcmd.u.dcb.app_priority.protocolid);
1159 ffs(pcmd.u.dcb.app_priority.user_prio_map) - 1;
1164 /* Return Priority Group information.
1166 static int cxgb4_cee_peer_getpg(struct net_device *dev, struct cee_pg *pg)
1168 struct fw_port_cmd pcmd;
1169 struct port_info *pi = netdev2pinfo(dev);
1170 struct adapter *adap = pi->adapter;
1174 /* We're always "willing" -- the Switch Fabric always dictates the
1175 * DCBX parameters to us.
1179 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1180 pcmd.u.dcb.pgid.type = FW_PORT_DCB_TYPE_PGID;
1181 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1182 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1183 dev_err(adap->pdev_dev, "DCB read PGID failed with %d\n", -err);
1186 pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
1188 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1189 pg->prio_pg[7 - i] = (pgid >> (i * 4)) & 0xF;
1191 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1192 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
1193 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
1194 if (err != FW_PORT_DCB_CFG_SUCCESS) {
1195 dev_err(adap->pdev_dev, "DCB read PGRATE failed with %d\n",
1200 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1201 pg->pg_bw[i] = pcmd.u.dcb.pgrate.pgrate[i];
1203 pg->tcs_supported = pcmd.u.dcb.pgrate.num_tcs_supported;
1208 /* Return Priority Flow Control information.
1210 static int cxgb4_cee_peer_getpfc(struct net_device *dev, struct cee_pfc *pfc)
1212 struct port_info *pi = netdev2pinfo(dev);
1214 cxgb4_getnumtcs(dev, DCB_NUMTCS_ATTR_PFC, &(pfc->tcs_supported));
1216 /* Firmware sends this to us in a formwat that is a bit flipped version
1217 * of spec, correct it before we send it to host. This is taken care of
1218 * by bit shifting in other uses of pfcen
1220 pfc->pfc_en = bitswap_1(pi->dcb.pfcen);
1222 pfc->tcs_supported = pi->dcb.pfc_num_tcs_supported;
1227 const struct dcbnl_rtnl_ops cxgb4_dcb_ops = {
1228 .ieee_getets = cxgb4_ieee_get_ets,
1229 .ieee_getpfc = cxgb4_ieee_get_pfc,
1230 .ieee_getapp = cxgb4_ieee_getapp,
1231 .ieee_setapp = cxgb4_ieee_setapp,
1232 .ieee_peer_getets = cxgb4_ieee_peer_ets,
1233 .ieee_peer_getpfc = cxgb4_ieee_get_pfc,
1236 .getstate = cxgb4_getstate,
1237 .setstate = cxgb4_setstate,
1238 .getpgtccfgtx = cxgb4_getpgtccfg_tx,
1239 .getpgbwgcfgtx = cxgb4_getpgbwgcfg_tx,
1240 .getpgtccfgrx = cxgb4_getpgtccfg_rx,
1241 .getpgbwgcfgrx = cxgb4_getpgbwgcfg_rx,
1242 .setpgtccfgtx = cxgb4_setpgtccfg_tx,
1243 .setpgbwgcfgtx = cxgb4_setpgbwgcfg_tx,
1244 .setpfccfg = cxgb4_setpfccfg,
1245 .getpfccfg = cxgb4_getpfccfg,
1246 .setall = cxgb4_setall,
1247 .getcap = cxgb4_getcap,
1248 .getnumtcs = cxgb4_getnumtcs,
1249 .setnumtcs = cxgb4_setnumtcs,
1250 .getpfcstate = cxgb4_getpfcstate,
1251 .setpfcstate = cxgb4_setpfcstate,
1252 .getapp = cxgb4_getapp,
1253 .setapp = cxgb4_setapp,
1255 /* DCBX configuration */
1256 .getdcbx = cxgb4_getdcbx,
1257 .setdcbx = cxgb4_setdcbx,
1260 .peer_getappinfo = cxgb4_getpeer_app,
1261 .peer_getapptable = cxgb4_getpeerapp_tbl,
1264 .cee_peer_getpg = cxgb4_cee_peer_getpg,
1265 .cee_peer_getpfc = cxgb4_cee_peer_getpfc,