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 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. Typically used after a
46 void cxgb4_dcb_state_init(struct net_device
*dev
)
48 struct port_info
*pi
= netdev2pinfo(dev
);
49 struct port_dcb_info
*dcb
= &pi
->dcb
;
50 int version_temp
= dcb
->dcb_version
;
52 memset(dcb
, 0, sizeof(struct port_dcb_info
));
53 dcb
->state
= CXGB4_DCB_STATE_START
;
55 dcb
->dcb_version
= version_temp
;
57 netdev_dbg(dev
, "%s: Initializing DCB state for port[%d]\n",
58 __func__
, pi
->port_id
);
61 void cxgb4_dcb_version_init(struct net_device
*dev
)
63 struct port_info
*pi
= netdev2pinfo(dev
);
64 struct port_dcb_info
*dcb
= &pi
->dcb
;
66 /* Any writes here are only done on kernels that exlicitly need
67 * a specific version, say < 2.6.38 which only support CEE
69 dcb
->dcb_version
= FW_PORT_DCB_VER_AUTO
;
72 static void cxgb4_dcb_cleanup_apps(struct net_device
*dev
)
74 struct port_info
*pi
= netdev2pinfo(dev
);
75 struct adapter
*adap
= pi
->adapter
;
76 struct port_dcb_info
*dcb
= &pi
->dcb
;
80 /* zero priority implies remove */
83 for (i
= 0; i
< CXGB4_MAX_DCBX_APP_SUPPORTED
; i
++) {
84 /* Check if app list is exhausted */
85 if (!dcb
->app_priority
[i
].protocolid
)
88 app
.protocol
= dcb
->app_priority
[i
].protocolid
;
90 if (dcb
->dcb_version
== FW_PORT_DCB_VER_IEEE
) {
91 app
.priority
= dcb
->app_priority
[i
].user_prio_map
;
92 app
.selector
= dcb
->app_priority
[i
].sel_field
+ 1;
93 err
= dcb_ieee_delapp(dev
, &app
);
95 app
.selector
= !!(dcb
->app_priority
[i
].sel_field
);
96 err
= dcb_setapp(dev
, &app
);
100 dev_err(adap
->pdev_dev
,
101 "Failed DCB Clear %s Application Priority: sel=%d, prot=%d, , err=%d\n",
102 dcb_ver_array
[dcb
->dcb_version
], app
.selector
,
109 /* Finite State machine for Data Center Bridging.
111 void cxgb4_dcb_state_fsm(struct net_device
*dev
,
112 enum cxgb4_dcb_state_input transition_to
)
114 struct port_info
*pi
= netdev2pinfo(dev
);
115 struct port_dcb_info
*dcb
= &pi
->dcb
;
116 struct adapter
*adap
= pi
->adapter
;
117 enum cxgb4_dcb_state current_state
= dcb
->state
;
119 netdev_dbg(dev
, "%s: State change from %d to %d for %s\n",
120 __func__
, dcb
->state
, transition_to
, dev
->name
);
122 switch (current_state
) {
123 case CXGB4_DCB_STATE_START
: {
124 switch (transition_to
) {
125 case CXGB4_DCB_INPUT_FW_DISABLED
: {
126 /* we're going to use Host DCB */
127 dcb
->state
= CXGB4_DCB_STATE_HOST
;
128 dcb
->supported
= CXGB4_DCBX_HOST_SUPPORT
;
132 case CXGB4_DCB_INPUT_FW_ENABLED
: {
133 /* we're going to use Firmware DCB */
134 dcb
->state
= CXGB4_DCB_STATE_FW_INCOMPLETE
;
135 dcb
->supported
= DCB_CAP_DCBX_LLD_MANAGED
;
136 if (dcb
->dcb_version
== FW_PORT_DCB_VER_IEEE
)
137 dcb
->supported
|= DCB_CAP_DCBX_VER_IEEE
;
139 dcb
->supported
|= DCB_CAP_DCBX_VER_CEE
;
143 case CXGB4_DCB_INPUT_FW_INCOMPLETE
: {
144 /* expected transition */
148 case CXGB4_DCB_INPUT_FW_ALLSYNCED
: {
149 dcb
->state
= CXGB4_DCB_STATE_FW_ALLSYNCED
;
154 goto bad_state_input
;
159 case CXGB4_DCB_STATE_FW_INCOMPLETE
: {
160 switch (transition_to
) {
161 case CXGB4_DCB_INPUT_FW_ENABLED
: {
162 /* we're alreaady in firmware DCB mode */
166 case CXGB4_DCB_INPUT_FW_INCOMPLETE
: {
167 /* we're already incomplete */
171 case CXGB4_DCB_INPUT_FW_ALLSYNCED
: {
172 dcb
->state
= CXGB4_DCB_STATE_FW_ALLSYNCED
;
174 linkwatch_fire_event(dev
);
179 goto bad_state_input
;
184 case CXGB4_DCB_STATE_FW_ALLSYNCED
: {
185 switch (transition_to
) {
186 case CXGB4_DCB_INPUT_FW_ENABLED
: {
187 /* we're alreaady in firmware DCB mode */
191 case CXGB4_DCB_INPUT_FW_INCOMPLETE
: {
192 /* We were successfully running with firmware DCB but
193 * now it's telling us that it's in an "incomplete
194 * state. We need to reset back to a ground state
197 cxgb4_dcb_cleanup_apps(dev
);
198 cxgb4_dcb_state_init(dev
);
199 dcb
->state
= CXGB4_DCB_STATE_FW_INCOMPLETE
;
200 dcb
->supported
= CXGB4_DCBX_FW_SUPPORT
;
201 linkwatch_fire_event(dev
);
205 case CXGB4_DCB_INPUT_FW_ALLSYNCED
: {
206 /* we're already all sync'ed
207 * this is only applicable for IEEE or
208 * when another VI already completed negotiaton
211 linkwatch_fire_event(dev
);
216 goto bad_state_input
;
221 case CXGB4_DCB_STATE_HOST
: {
222 switch (transition_to
) {
223 case CXGB4_DCB_INPUT_FW_DISABLED
: {
224 /* we're alreaady in Host DCB mode */
229 goto bad_state_input
;
235 goto bad_state_transition
;
240 dev_err(adap
->pdev_dev
, "cxgb4_dcb_state_fsm: illegal input symbol %d\n",
244 bad_state_transition
:
245 dev_err(adap
->pdev_dev
, "cxgb4_dcb_state_fsm: bad state transition, state = %d, input = %d\n",
246 current_state
, transition_to
);
249 /* Handle a DCB/DCBX update message from the firmware.
251 void cxgb4_dcb_handle_fw_update(struct adapter
*adap
,
252 const struct fw_port_cmd
*pcmd
)
254 const union fw_port_dcb
*fwdcb
= &pcmd
->u
.dcb
;
255 int port
= FW_PORT_CMD_PORTID_G(be32_to_cpu(pcmd
->op_to_portid
));
256 struct net_device
*dev
= adap
->port
[adap
->chan_map
[port
]];
257 struct port_info
*pi
= netdev_priv(dev
);
258 struct port_dcb_info
*dcb
= &pi
->dcb
;
259 int dcb_type
= pcmd
->u
.dcb
.pgid
.type
;
260 int dcb_running_version
;
262 /* Handle Firmware DCB Control messages separately since they drive
265 if (dcb_type
== FW_PORT_DCB_TYPE_CONTROL
) {
266 enum cxgb4_dcb_state_input input
=
267 ((pcmd
->u
.dcb
.control
.all_syncd_pkd
&
268 FW_PORT_CMD_ALL_SYNCD_F
)
269 ? CXGB4_DCB_STATE_FW_ALLSYNCED
270 : CXGB4_DCB_STATE_FW_INCOMPLETE
);
272 if (dcb
->dcb_version
!= FW_PORT_DCB_VER_UNKNOWN
) {
273 dcb_running_version
= FW_PORT_CMD_DCB_VERSION_G(
275 pcmd
->u
.dcb
.control
.dcb_version_to_app_state
));
276 if (dcb_running_version
== FW_PORT_DCB_VER_CEE1D01
||
277 dcb_running_version
== FW_PORT_DCB_VER_IEEE
) {
278 dcb
->dcb_version
= dcb_running_version
;
279 dev_warn(adap
->pdev_dev
, "Interface %s is running %s\n",
281 dcb_ver_array
[dcb
->dcb_version
]);
283 dev_warn(adap
->pdev_dev
,
284 "Something screwed up, requested firmware for %s, but firmware returned %s instead\n",
285 dcb_ver_array
[dcb
->dcb_version
],
286 dcb_ver_array
[dcb_running_version
]);
287 dcb
->dcb_version
= FW_PORT_DCB_VER_UNKNOWN
;
291 cxgb4_dcb_state_fsm(dev
, input
);
295 /* It's weird, and almost certainly an error, to get Firmware DCB
296 * messages when we either haven't been told whether we're going to be
297 * doing Host or Firmware DCB; and even worse when we've been told
298 * that we're doing Host DCB!
300 if (dcb
->state
== CXGB4_DCB_STATE_START
||
301 dcb
->state
== CXGB4_DCB_STATE_HOST
) {
302 dev_err(adap
->pdev_dev
, "Receiving Firmware DCB messages in State %d\n",
307 /* Now handle the general Firmware DCB update messages ...
310 case FW_PORT_DCB_TYPE_PGID
:
311 dcb
->pgid
= be32_to_cpu(fwdcb
->pgid
.pgid
);
312 dcb
->msgs
|= CXGB4_DCB_FW_PGID
;
315 case FW_PORT_DCB_TYPE_PGRATE
:
316 dcb
->pg_num_tcs_supported
= fwdcb
->pgrate
.num_tcs_supported
;
317 memcpy(dcb
->pgrate
, &fwdcb
->pgrate
.pgrate
,
318 sizeof(dcb
->pgrate
));
319 memcpy(dcb
->tsa
, &fwdcb
->pgrate
.tsa
,
321 dcb
->msgs
|= CXGB4_DCB_FW_PGRATE
;
322 if (dcb
->msgs
& CXGB4_DCB_FW_PGID
)
323 IEEE_FAUX_SYNC(dev
, dcb
);
326 case FW_PORT_DCB_TYPE_PRIORATE
:
327 memcpy(dcb
->priorate
, &fwdcb
->priorate
.strict_priorate
,
328 sizeof(dcb
->priorate
));
329 dcb
->msgs
|= CXGB4_DCB_FW_PRIORATE
;
332 case FW_PORT_DCB_TYPE_PFC
:
333 dcb
->pfcen
= fwdcb
->pfc
.pfcen
;
334 dcb
->pfc_num_tcs_supported
= fwdcb
->pfc
.max_pfc_tcs
;
335 dcb
->msgs
|= CXGB4_DCB_FW_PFC
;
336 IEEE_FAUX_SYNC(dev
, dcb
);
339 case FW_PORT_DCB_TYPE_APP_ID
: {
340 const struct fw_port_app_priority
*fwap
= &fwdcb
->app_priority
;
342 struct app_priority
*ap
= &dcb
->app_priority
[idx
];
344 struct dcb_app app
= {
345 .protocol
= be16_to_cpu(fwap
->protocolid
),
349 /* Convert from firmware format to relevant format
350 * when using app selector
352 if (dcb
->dcb_version
== FW_PORT_DCB_VER_IEEE
) {
353 app
.selector
= (fwap
->sel_field
+ 1);
354 app
.priority
= ffs(fwap
->user_prio_map
) - 1;
355 err
= dcb_ieee_setapp(dev
, &app
);
356 IEEE_FAUX_SYNC(dev
, dcb
);
359 app
.selector
= !!(fwap
->sel_field
);
360 app
.priority
= fwap
->user_prio_map
;
361 err
= dcb_setapp(dev
, &app
);
365 dev_err(adap
->pdev_dev
,
366 "Failed DCB Set Application Priority: sel=%d, prot=%d, prio=%d, err=%d\n",
367 app
.selector
, app
.protocol
, app
.priority
, -err
);
369 ap
->user_prio_map
= fwap
->user_prio_map
;
370 ap
->sel_field
= fwap
->sel_field
;
371 ap
->protocolid
= be16_to_cpu(fwap
->protocolid
);
372 dcb
->msgs
|= CXGB4_DCB_FW_APP_ID
;
377 dev_err(adap
->pdev_dev
, "Unknown DCB update type received %x\n",
383 /* Data Center Bridging netlink operations.
387 /* Get current DCB enabled/disabled state.
389 static u8
cxgb4_getstate(struct net_device
*dev
)
391 struct port_info
*pi
= netdev2pinfo(dev
);
393 return pi
->dcb
.enabled
;
396 /* Set DCB enabled/disabled.
398 static u8
cxgb4_setstate(struct net_device
*dev
, u8 enabled
)
400 struct port_info
*pi
= netdev2pinfo(dev
);
402 /* If DCBx is host-managed, dcb is enabled by outside lldp agents */
403 if (pi
->dcb
.state
== CXGB4_DCB_STATE_HOST
) {
404 pi
->dcb
.enabled
= enabled
;
408 /* Firmware doesn't provide any mechanism to control the DCB state.
410 if (enabled
!= (pi
->dcb
.state
== CXGB4_DCB_STATE_FW_ALLSYNCED
))
416 static void cxgb4_getpgtccfg(struct net_device
*dev
, int tc
,
417 u8
*prio_type
, u8
*pgid
, u8
*bw_per
,
418 u8
*up_tc_map
, int local
)
420 struct fw_port_cmd pcmd
;
421 struct port_info
*pi
= netdev2pinfo(dev
);
422 struct adapter
*adap
= pi
->adapter
;
425 *prio_type
= *pgid
= *bw_per
= *up_tc_map
= 0;
428 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd
, pi
->port_id
);
430 INIT_PORT_DCB_READ_PEER_CMD(pcmd
, pi
->port_id
);
432 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
);
438 *pgid
= (be32_to_cpu(pcmd
.u
.dcb
.pgid
.pgid
) >> (tc
* 4)) & 0xf;
441 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd
, pi
->port_id
);
443 INIT_PORT_DCB_READ_PEER_CMD(pcmd
, pi
->port_id
);
444 pcmd
.u
.dcb
.pgrate
.type
= FW_PORT_DCB_TYPE_PGRATE
;
445 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
446 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
447 dev_err(adap
->pdev_dev
, "DCB read PGRATE failed with %d\n",
452 *bw_per
= pcmd
.u
.dcb
.pgrate
.pgrate
[*pgid
];
453 *up_tc_map
= (1 << tc
);
455 /* prio_type is link strict */
460 static void cxgb4_getpgtccfg_tx(struct net_device
*dev
, int tc
,
461 u8
*prio_type
, u8
*pgid
, u8
*bw_per
,
464 /* tc 0 is written at MSB position */
465 return cxgb4_getpgtccfg(dev
, (7 - tc
), prio_type
, pgid
, bw_per
,
470 static void cxgb4_getpgtccfg_rx(struct net_device
*dev
, int tc
,
471 u8
*prio_type
, u8
*pgid
, u8
*bw_per
,
474 /* tc 0 is written at MSB position */
475 return cxgb4_getpgtccfg(dev
, (7 - tc
), prio_type
, pgid
, bw_per
,
479 static void cxgb4_setpgtccfg_tx(struct net_device
*dev
, int tc
,
480 u8 prio_type
, u8 pgid
, u8 bw_per
,
483 struct fw_port_cmd pcmd
;
484 struct port_info
*pi
= netdev2pinfo(dev
);
485 struct adapter
*adap
= pi
->adapter
;
490 if (pgid
== DCB_ATTR_VALUE_UNDEFINED
)
492 if (bw_per
== DCB_ATTR_VALUE_UNDEFINED
)
495 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd
, pi
->port_id
);
496 pcmd
.u
.dcb
.pgid
.type
= FW_PORT_DCB_TYPE_PGID
;
498 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
499 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
500 dev_err(adap
->pdev_dev
, "DCB read PGID failed with %d\n", -err
);
504 _pgid
= be32_to_cpu(pcmd
.u
.dcb
.pgid
.pgid
);
505 _pgid
&= ~(0xF << (fw_tc
* 4));
506 _pgid
|= pgid
<< (fw_tc
* 4);
507 pcmd
.u
.dcb
.pgid
.pgid
= cpu_to_be32(_pgid
);
509 INIT_PORT_DCB_WRITE_CMD(pcmd
, pi
->port_id
);
511 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
512 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
513 dev_err(adap
->pdev_dev
, "DCB write PGID failed with %d\n",
518 memset(&pcmd
, 0, sizeof(struct fw_port_cmd
));
520 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd
, pi
->port_id
);
521 pcmd
.u
.dcb
.pgrate
.type
= FW_PORT_DCB_TYPE_PGRATE
;
523 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
524 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
525 dev_err(adap
->pdev_dev
, "DCB read PGRATE failed with %d\n",
530 pcmd
.u
.dcb
.pgrate
.pgrate
[pgid
] = bw_per
;
532 INIT_PORT_DCB_WRITE_CMD(pcmd
, pi
->port_id
);
533 if (pi
->dcb
.state
== CXGB4_DCB_STATE_HOST
)
534 pcmd
.op_to_portid
|= cpu_to_be32(FW_PORT_CMD_APPLY_F
);
536 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 static void cxgb4_getpgbwgcfg(struct net_device
*dev
, int pgid
, u8
*bw_per
,
545 struct fw_port_cmd pcmd
;
546 struct port_info
*pi
= netdev2pinfo(dev
);
547 struct adapter
*adap
= pi
->adapter
;
551 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd
, pi
->port_id
);
553 INIT_PORT_DCB_READ_PEER_CMD(pcmd
, pi
->port_id
);
555 pcmd
.u
.dcb
.pgrate
.type
= FW_PORT_DCB_TYPE_PGRATE
;
556 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
557 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
558 dev_err(adap
->pdev_dev
, "DCB read PGRATE failed with %d\n",
563 *bw_per
= pcmd
.u
.dcb
.pgrate
.pgrate
[pgid
];
566 static void cxgb4_getpgbwgcfg_tx(struct net_device
*dev
, int pgid
, u8
*bw_per
)
568 return cxgb4_getpgbwgcfg(dev
, pgid
, bw_per
, 1);
571 static void cxgb4_getpgbwgcfg_rx(struct net_device
*dev
, int pgid
, u8
*bw_per
)
573 return cxgb4_getpgbwgcfg(dev
, pgid
, bw_per
, 0);
576 static void cxgb4_setpgbwgcfg_tx(struct net_device
*dev
, int pgid
,
579 struct fw_port_cmd pcmd
;
580 struct port_info
*pi
= netdev2pinfo(dev
);
581 struct adapter
*adap
= pi
->adapter
;
584 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd
, pi
->port_id
);
585 pcmd
.u
.dcb
.pgrate
.type
= FW_PORT_DCB_TYPE_PGRATE
;
587 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
588 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
589 dev_err(adap
->pdev_dev
, "DCB read PGRATE failed with %d\n",
594 pcmd
.u
.dcb
.pgrate
.pgrate
[pgid
] = bw_per
;
596 INIT_PORT_DCB_WRITE_CMD(pcmd
, pi
->port_id
);
597 if (pi
->dcb
.state
== CXGB4_DCB_STATE_HOST
)
598 pcmd
.op_to_portid
|= cpu_to_be32(FW_PORT_CMD_APPLY_F
);
600 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
602 if (err
!= FW_PORT_DCB_CFG_SUCCESS
)
603 dev_err(adap
->pdev_dev
, "DCB write PGRATE failed with %d\n",
607 /* Return whether the specified Traffic Class Priority has Priority Pause
610 static void cxgb4_getpfccfg(struct net_device
*dev
, int priority
, u8
*pfccfg
)
612 struct port_info
*pi
= netdev2pinfo(dev
);
613 struct port_dcb_info
*dcb
= &pi
->dcb
;
615 if (!cxgb4_dcb_state_synced(dcb
->state
) ||
616 priority
>= CXGB4_MAX_PRIORITY
)
619 *pfccfg
= (pi
->dcb
.pfcen
>> (7 - priority
)) & 1;
622 /* Enable/disable Priority Pause Frames for the specified Traffic Class
625 static void cxgb4_setpfccfg(struct net_device
*dev
, int priority
, u8 pfccfg
)
627 struct fw_port_cmd pcmd
;
628 struct port_info
*pi
= netdev2pinfo(dev
);
629 struct adapter
*adap
= pi
->adapter
;
632 if (!cxgb4_dcb_state_synced(pi
->dcb
.state
) ||
633 priority
>= CXGB4_MAX_PRIORITY
)
636 INIT_PORT_DCB_WRITE_CMD(pcmd
, pi
->port_id
);
637 if (pi
->dcb
.state
== CXGB4_DCB_STATE_HOST
)
638 pcmd
.op_to_portid
|= cpu_to_be32(FW_PORT_CMD_APPLY_F
);
640 pcmd
.u
.dcb
.pfc
.type
= FW_PORT_DCB_TYPE_PFC
;
641 pcmd
.u
.dcb
.pfc
.pfcen
= pi
->dcb
.pfcen
;
644 pcmd
.u
.dcb
.pfc
.pfcen
|= (1 << (7 - priority
));
646 pcmd
.u
.dcb
.pfc
.pfcen
&= (~(1 << (7 - priority
)));
648 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
649 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
650 dev_err(adap
->pdev_dev
, "DCB PFC write failed with %d\n", -err
);
654 pi
->dcb
.pfcen
= pcmd
.u
.dcb
.pfc
.pfcen
;
657 static u8
cxgb4_setall(struct net_device
*dev
)
662 /* Return DCB capabilities.
664 static u8
cxgb4_getcap(struct net_device
*dev
, int cap_id
, u8
*caps
)
666 struct port_info
*pi
= netdev2pinfo(dev
);
669 case DCB_CAP_ATTR_PG
:
670 case DCB_CAP_ATTR_PFC
:
674 case DCB_CAP_ATTR_PG_TCS
:
675 /* 8 priorities for PG represented by bitmap */
679 case DCB_CAP_ATTR_PFC_TCS
:
680 /* 8 priorities for PFC represented by bitmap */
684 case DCB_CAP_ATTR_GSP
:
688 case DCB_CAP_ATTR_UP2TC
:
689 case DCB_CAP_ATTR_BCN
:
693 case DCB_CAP_ATTR_DCBX
:
694 *caps
= pi
->dcb
.supported
;
704 /* Return the number of Traffic Classes for the indicated Traffic Class ID.
706 static int cxgb4_getnumtcs(struct net_device
*dev
, int tcs_id
, u8
*num
)
708 struct port_info
*pi
= netdev2pinfo(dev
);
711 case DCB_NUMTCS_ATTR_PG
:
712 if (pi
->dcb
.msgs
& CXGB4_DCB_FW_PGRATE
)
713 *num
= pi
->dcb
.pg_num_tcs_supported
;
718 case DCB_NUMTCS_ATTR_PFC
:
729 /* Set the number of Traffic Classes supported for the indicated Traffic Class
732 static int cxgb4_setnumtcs(struct net_device
*dev
, int tcs_id
, u8 num
)
734 /* Setting the number of Traffic Classes isn't supported.
739 /* Return whether Priority Flow Control is enabled. */
740 static u8
cxgb4_getpfcstate(struct net_device
*dev
)
742 struct port_info
*pi
= netdev2pinfo(dev
);
744 if (!cxgb4_dcb_state_synced(pi
->dcb
.state
))
747 return pi
->dcb
.pfcen
!= 0;
750 /* Enable/disable Priority Flow Control. */
751 static void cxgb4_setpfcstate(struct net_device
*dev
, u8 state
)
753 /* We can't enable/disable Priority Flow Control but we also can't
754 * return an error ...
758 /* Return the Application User Priority Map associated with the specified
761 static int __cxgb4_getapp(struct net_device
*dev
, u8 app_idtype
, u16 app_id
,
764 struct port_info
*pi
= netdev2pinfo(dev
);
765 struct adapter
*adap
= pi
->adapter
;
768 if (!cxgb4_dcb_state_synced(pi
->dcb
.state
))
771 for (i
= 0; i
< CXGB4_MAX_DCBX_APP_SUPPORTED
; i
++) {
772 struct fw_port_cmd pcmd
;
776 INIT_PORT_DCB_READ_PEER_CMD(pcmd
, pi
->port_id
);
778 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd
, pi
->port_id
);
780 pcmd
.u
.dcb
.app_priority
.type
= FW_PORT_DCB_TYPE_APP_ID
;
781 pcmd
.u
.dcb
.app_priority
.idx
= i
;
783 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
784 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
785 dev_err(adap
->pdev_dev
, "DCB APP read failed with %d\n",
789 if (be16_to_cpu(pcmd
.u
.dcb
.app_priority
.protocolid
) == app_id
)
790 if (pcmd
.u
.dcb
.app_priority
.sel_field
== app_idtype
)
791 return pcmd
.u
.dcb
.app_priority
.user_prio_map
;
793 /* exhausted app list */
794 if (!pcmd
.u
.dcb
.app_priority
.protocolid
)
801 /* Return the Application User Priority Map associated with the specified
804 static int cxgb4_getapp(struct net_device
*dev
, u8 app_idtype
, u16 app_id
)
806 /* Convert app_idtype to firmware format before querying */
807 return __cxgb4_getapp(dev
, app_idtype
== DCB_APP_IDTYPE_ETHTYPE
?
808 app_idtype
: 3, app_id
, 0);
811 /* Write a new Application User Priority Map for the specified Application ID
813 static int __cxgb4_setapp(struct net_device
*dev
, u8 app_idtype
, u16 app_id
,
816 struct fw_port_cmd pcmd
;
817 struct port_info
*pi
= netdev2pinfo(dev
);
818 struct adapter
*adap
= pi
->adapter
;
822 if (!cxgb4_dcb_state_synced(pi
->dcb
.state
))
825 /* DCB info gets thrown away on link up */
826 if (!netif_carrier_ok(dev
))
829 for (i
= 0; i
< CXGB4_MAX_DCBX_APP_SUPPORTED
; i
++) {
830 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd
, pi
->port_id
);
831 pcmd
.u
.dcb
.app_priority
.type
= FW_PORT_DCB_TYPE_APP_ID
;
832 pcmd
.u
.dcb
.app_priority
.idx
= i
;
833 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
835 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
836 dev_err(adap
->pdev_dev
, "DCB app table read failed with %d\n",
840 if (be16_to_cpu(pcmd
.u
.dcb
.app_priority
.protocolid
) == app_id
) {
841 /* overwrite existing app table */
842 pcmd
.u
.dcb
.app_priority
.protocolid
= 0;
845 /* find first empty slot */
846 if (!pcmd
.u
.dcb
.app_priority
.protocolid
)
850 if (i
== CXGB4_MAX_DCBX_APP_SUPPORTED
) {
851 /* no empty slots available */
852 dev_err(adap
->pdev_dev
, "DCB app table full\n");
856 /* write out new app table entry */
857 INIT_PORT_DCB_WRITE_CMD(pcmd
, pi
->port_id
);
858 if (pi
->dcb
.state
== CXGB4_DCB_STATE_HOST
)
859 pcmd
.op_to_portid
|= cpu_to_be32(FW_PORT_CMD_APPLY_F
);
861 pcmd
.u
.dcb
.app_priority
.type
= FW_PORT_DCB_TYPE_APP_ID
;
862 pcmd
.u
.dcb
.app_priority
.protocolid
= cpu_to_be16(app_id
);
863 pcmd
.u
.dcb
.app_priority
.sel_field
= app_idtype
;
864 pcmd
.u
.dcb
.app_priority
.user_prio_map
= app_prio
;
865 pcmd
.u
.dcb
.app_priority
.idx
= i
;
867 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
868 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
869 dev_err(adap
->pdev_dev
, "DCB app table write failed with %d\n",
877 /* Priority for CEE inside dcb_app is bitmask, with 0 being an invalid value */
878 static int cxgb4_setapp(struct net_device
*dev
, u8 app_idtype
, u16 app_id
,
882 struct dcb_app app
= {
883 .selector
= app_idtype
,
885 .priority
= app_prio
,
888 if (app_idtype
!= DCB_APP_IDTYPE_ETHTYPE
&&
889 app_idtype
!= DCB_APP_IDTYPE_PORTNUM
)
892 /* Convert app_idtype to a format that firmware understands */
893 ret
= __cxgb4_setapp(dev
, app_idtype
== DCB_APP_IDTYPE_ETHTYPE
?
894 app_idtype
: 3, app_id
, app_prio
);
898 return dcb_setapp(dev
, &app
);
901 /* Return whether IEEE Data Center Bridging has been negotiated.
904 cxgb4_ieee_negotiation_complete(struct net_device
*dev
,
905 enum cxgb4_dcb_fw_msgs dcb_subtype
)
907 struct port_info
*pi
= netdev2pinfo(dev
);
908 struct port_dcb_info
*dcb
= &pi
->dcb
;
910 if (dcb
->state
== CXGB4_DCB_STATE_FW_ALLSYNCED
)
911 if (dcb_subtype
&& !(dcb
->msgs
& dcb_subtype
))
914 return (cxgb4_dcb_state_synced(dcb
->state
) &&
915 (dcb
->supported
& DCB_CAP_DCBX_VER_IEEE
));
918 static int cxgb4_ieee_read_ets(struct net_device
*dev
, struct ieee_ets
*ets
,
921 struct port_info
*pi
= netdev2pinfo(dev
);
922 struct port_dcb_info
*dcb
= &pi
->dcb
;
923 struct adapter
*adap
= pi
->adapter
;
925 struct fw_port_cmd pcmd
;
928 if (!(dcb
->msgs
& (CXGB4_DCB_FW_PGID
| CXGB4_DCB_FW_PGRATE
)))
931 ets
->ets_cap
= dcb
->pg_num_tcs_supported
;
935 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd
, pi
->port_id
);
937 INIT_PORT_DCB_READ_PEER_CMD(pcmd
, pi
->port_id
);
940 pcmd
.u
.dcb
.pgid
.type
= FW_PORT_DCB_TYPE_PGID
;
941 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
942 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
943 dev_err(adap
->pdev_dev
, "DCB read PGID failed with %d\n", -err
);
947 tc_info
= be32_to_cpu(pcmd
.u
.dcb
.pgid
.pgid
);
950 INIT_PORT_DCB_READ_LOCAL_CMD(pcmd
, pi
->port_id
);
952 INIT_PORT_DCB_READ_PEER_CMD(pcmd
, pi
->port_id
);
954 pcmd
.u
.dcb
.pgrate
.type
= FW_PORT_DCB_TYPE_PGRATE
;
955 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
956 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
957 dev_err(adap
->pdev_dev
, "DCB read PGRATE failed with %d\n",
962 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++) {
963 bwg
= (tc_info
>> ((7 - i
) * 4)) & 0xF;
964 ets
->prio_tc
[i
] = bwg
;
965 ets
->tc_tx_bw
[i
] = pcmd
.u
.dcb
.pgrate
.pgrate
[i
];
966 ets
->tc_rx_bw
[i
] = ets
->tc_tx_bw
[i
];
967 ets
->tc_tsa
[i
] = pcmd
.u
.dcb
.pgrate
.tsa
[i
];
973 static int cxgb4_ieee_get_ets(struct net_device
*dev
, struct ieee_ets
*ets
)
975 return cxgb4_ieee_read_ets(dev
, ets
, 1);
978 /* We reuse this for peer PFC as well, as we can't have it enabled one way */
979 static int cxgb4_ieee_get_pfc(struct net_device
*dev
, struct ieee_pfc
*pfc
)
981 struct port_info
*pi
= netdev2pinfo(dev
);
982 struct port_dcb_info
*dcb
= &pi
->dcb
;
984 memset(pfc
, 0, sizeof(struct ieee_pfc
));
986 if (!(dcb
->msgs
& CXGB4_DCB_FW_PFC
))
989 pfc
->pfc_cap
= dcb
->pfc_num_tcs_supported
;
990 pfc
->pfc_en
= bitswap_1(dcb
->pfcen
);
995 static int cxgb4_ieee_peer_ets(struct net_device
*dev
, struct ieee_ets
*ets
)
997 return cxgb4_ieee_read_ets(dev
, ets
, 0);
1000 /* Fill in the Application User Priority Map associated with the
1001 * specified Application.
1002 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
1004 static int cxgb4_ieee_getapp(struct net_device
*dev
, struct dcb_app
*app
)
1008 if (!cxgb4_ieee_negotiation_complete(dev
, CXGB4_DCB_FW_APP_ID
))
1010 if (!(app
->selector
&& app
->protocol
))
1013 /* Try querying firmware first, use firmware format */
1014 prio
= __cxgb4_getapp(dev
, app
->selector
- 1, app
->protocol
, 0);
1017 prio
= dcb_ieee_getapp_mask(dev
, app
);
1019 app
->priority
= ffs(prio
) - 1;
1023 /* Write a new Application User Priority Map for the specified Application ID.
1024 * Priority for IEEE dcb_app is an integer, with 0 being a valid value
1026 static int cxgb4_ieee_setapp(struct net_device
*dev
, struct dcb_app
*app
)
1030 if (!cxgb4_ieee_negotiation_complete(dev
, CXGB4_DCB_FW_APP_ID
))
1032 if (!(app
->selector
&& app
->protocol
))
1035 if (!(app
->selector
> IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
1036 app
->selector
< IEEE_8021QAZ_APP_SEL_ANY
))
1039 /* change selector to a format that firmware understands */
1040 ret
= __cxgb4_setapp(dev
, app
->selector
- 1, app
->protocol
,
1041 (1 << app
->priority
));
1045 return dcb_ieee_setapp(dev
, app
);
1048 /* Return our DCBX parameters.
1050 static u8
cxgb4_getdcbx(struct net_device
*dev
)
1052 struct port_info
*pi
= netdev2pinfo(dev
);
1054 /* This is already set by cxgb4_set_dcb_caps, so just return it */
1055 return pi
->dcb
.supported
;
1058 /* Set our DCBX parameters.
1060 static u8
cxgb4_setdcbx(struct net_device
*dev
, u8 dcb_request
)
1062 struct port_info
*pi
= netdev2pinfo(dev
);
1064 /* Filter out requests which exceed our capabilities.
1066 if ((dcb_request
& (CXGB4_DCBX_FW_SUPPORT
| CXGB4_DCBX_HOST_SUPPORT
))
1070 /* Can't enable DCB if we haven't successfully negotiated it.
1072 if (!cxgb4_dcb_state_synced(pi
->dcb
.state
))
1075 /* There's currently no mechanism to allow for the firmware DCBX
1076 * negotiation to be changed from the Host Driver. If the caller
1077 * requests exactly the same parameters that we already have then
1078 * we'll allow them to be successfully "set" ...
1080 if (dcb_request
!= pi
->dcb
.supported
)
1083 pi
->dcb
.supported
= dcb_request
;
1087 static int cxgb4_getpeer_app(struct net_device
*dev
,
1088 struct dcb_peer_app_info
*info
, u16
*app_count
)
1090 struct fw_port_cmd pcmd
;
1091 struct port_info
*pi
= netdev2pinfo(dev
);
1092 struct adapter
*adap
= pi
->adapter
;
1095 if (!cxgb4_dcb_state_synced(pi
->dcb
.state
))
1102 for (i
= 0; i
< CXGB4_MAX_DCBX_APP_SUPPORTED
; i
++) {
1103 INIT_PORT_DCB_READ_PEER_CMD(pcmd
, pi
->port_id
);
1104 pcmd
.u
.dcb
.app_priority
.type
= FW_PORT_DCB_TYPE_APP_ID
;
1105 pcmd
.u
.dcb
.app_priority
.idx
= *app_count
;
1106 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
1108 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
1109 dev_err(adap
->pdev_dev
, "DCB app table read failed with %d\n",
1114 /* find first empty slot */
1115 if (!pcmd
.u
.dcb
.app_priority
.protocolid
)
1122 static int cxgb4_getpeerapp_tbl(struct net_device
*dev
, struct dcb_app
*table
)
1124 struct fw_port_cmd pcmd
;
1125 struct port_info
*pi
= netdev2pinfo(dev
);
1126 struct adapter
*adap
= pi
->adapter
;
1129 if (!cxgb4_dcb_state_synced(pi
->dcb
.state
))
1132 for (i
= 0; i
< CXGB4_MAX_DCBX_APP_SUPPORTED
; i
++) {
1133 INIT_PORT_DCB_READ_PEER_CMD(pcmd
, pi
->port_id
);
1134 pcmd
.u
.dcb
.app_priority
.type
= FW_PORT_DCB_TYPE_APP_ID
;
1135 pcmd
.u
.dcb
.app_priority
.idx
= i
;
1136 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
1138 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
1139 dev_err(adap
->pdev_dev
, "DCB app table read failed with %d\n",
1144 /* find first empty slot */
1145 if (!pcmd
.u
.dcb
.app_priority
.protocolid
)
1148 table
[i
].selector
= (pcmd
.u
.dcb
.app_priority
.sel_field
+ 1);
1150 be16_to_cpu(pcmd
.u
.dcb
.app_priority
.protocolid
);
1152 ffs(pcmd
.u
.dcb
.app_priority
.user_prio_map
) - 1;
1157 /* Return Priority Group information.
1159 static int cxgb4_cee_peer_getpg(struct net_device
*dev
, struct cee_pg
*pg
)
1161 struct fw_port_cmd pcmd
;
1162 struct port_info
*pi
= netdev2pinfo(dev
);
1163 struct adapter
*adap
= pi
->adapter
;
1167 /* We're always "willing" -- the Switch Fabric always dictates the
1168 * DCBX parameters to us.
1172 INIT_PORT_DCB_READ_PEER_CMD(pcmd
, pi
->port_id
);
1173 pcmd
.u
.dcb
.pgid
.type
= FW_PORT_DCB_TYPE_PGID
;
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 PGID failed with %d\n", -err
);
1179 pgid
= be32_to_cpu(pcmd
.u
.dcb
.pgid
.pgid
);
1181 for (i
= 0; i
< CXGB4_MAX_PRIORITY
; i
++)
1182 pg
->prio_pg
[7 - i
] = (pgid
>> (i
* 4)) & 0xF;
1184 INIT_PORT_DCB_READ_PEER_CMD(pcmd
, pi
->port_id
);
1185 pcmd
.u
.dcb
.pgrate
.type
= FW_PORT_DCB_TYPE_PGRATE
;
1186 err
= t4_wr_mbox(adap
, adap
->mbox
, &pcmd
, sizeof(pcmd
), &pcmd
);
1187 if (err
!= FW_PORT_DCB_CFG_SUCCESS
) {
1188 dev_err(adap
->pdev_dev
, "DCB read PGRATE failed with %d\n",
1193 for (i
= 0; i
< CXGB4_MAX_PRIORITY
; i
++)
1194 pg
->pg_bw
[i
] = pcmd
.u
.dcb
.pgrate
.pgrate
[i
];
1196 pg
->tcs_supported
= pcmd
.u
.dcb
.pgrate
.num_tcs_supported
;
1201 /* Return Priority Flow Control information.
1203 static int cxgb4_cee_peer_getpfc(struct net_device
*dev
, struct cee_pfc
*pfc
)
1205 struct port_info
*pi
= netdev2pinfo(dev
);
1207 cxgb4_getnumtcs(dev
, DCB_NUMTCS_ATTR_PFC
, &(pfc
->tcs_supported
));
1209 /* Firmware sends this to us in a formwat that is a bit flipped version
1210 * of spec, correct it before we send it to host. This is taken care of
1211 * by bit shifting in other uses of pfcen
1213 pfc
->pfc_en
= bitswap_1(pi
->dcb
.pfcen
);
1215 pfc
->tcs_supported
= pi
->dcb
.pfc_num_tcs_supported
;
1220 const struct dcbnl_rtnl_ops cxgb4_dcb_ops
= {
1221 .ieee_getets
= cxgb4_ieee_get_ets
,
1222 .ieee_getpfc
= cxgb4_ieee_get_pfc
,
1223 .ieee_getapp
= cxgb4_ieee_getapp
,
1224 .ieee_setapp
= cxgb4_ieee_setapp
,
1225 .ieee_peer_getets
= cxgb4_ieee_peer_ets
,
1226 .ieee_peer_getpfc
= cxgb4_ieee_get_pfc
,
1229 .getstate
= cxgb4_getstate
,
1230 .setstate
= cxgb4_setstate
,
1231 .getpgtccfgtx
= cxgb4_getpgtccfg_tx
,
1232 .getpgbwgcfgtx
= cxgb4_getpgbwgcfg_tx
,
1233 .getpgtccfgrx
= cxgb4_getpgtccfg_rx
,
1234 .getpgbwgcfgrx
= cxgb4_getpgbwgcfg_rx
,
1235 .setpgtccfgtx
= cxgb4_setpgtccfg_tx
,
1236 .setpgbwgcfgtx
= cxgb4_setpgbwgcfg_tx
,
1237 .setpfccfg
= cxgb4_setpfccfg
,
1238 .getpfccfg
= cxgb4_getpfccfg
,
1239 .setall
= cxgb4_setall
,
1240 .getcap
= cxgb4_getcap
,
1241 .getnumtcs
= cxgb4_getnumtcs
,
1242 .setnumtcs
= cxgb4_setnumtcs
,
1243 .getpfcstate
= cxgb4_getpfcstate
,
1244 .setpfcstate
= cxgb4_setpfcstate
,
1245 .getapp
= cxgb4_getapp
,
1246 .setapp
= cxgb4_setapp
,
1248 /* DCBX configuration */
1249 .getdcbx
= cxgb4_getdcbx
,
1250 .setdcbx
= cxgb4_setdcbx
,
1253 .peer_getappinfo
= cxgb4_getpeer_app
,
1254 .peer_getapptable
= cxgb4_getpeerapp_tbl
,
1257 .cee_peer_getpg
= cxgb4_cee_peer_getpg
,
1258 .cee_peer_getpfc
= cxgb4_cee_peer_getpfc
,