1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 #include <linux/dcbnl.h>
31 #include "ixgbe_dcb_82598.h"
32 #include "ixgbe_dcb_82599.h"
34 /* Callbacks for DCB netlink in the kernel */
35 #define BIT_DCB_MODE 0x01
37 #define BIT_PG_RX 0x04
38 #define BIT_PG_TX 0x08
39 #define BIT_APP_UPCHG 0x10
40 #define BIT_LINKSPEED 0x80
42 /* Responses for the DCB_C_SET_ALL command */
43 #define DCB_HW_CHG_RST 0 /* DCB configuration changed with reset */
44 #define DCB_NO_HW_CHG 1 /* DCB configuration did not change */
45 #define DCB_HW_CHG 2 /* DCB configuration changed, no reset */
47 int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config
*src_dcb_cfg
,
48 struct ixgbe_dcb_config
*dst_dcb_cfg
, int tc_max
)
50 struct tc_configuration
*src_tc_cfg
= NULL
;
51 struct tc_configuration
*dst_tc_cfg
= NULL
;
54 if (!src_dcb_cfg
|| !dst_dcb_cfg
)
57 for (i
= DCB_PG_ATTR_TC_0
; i
< tc_max
+ DCB_PG_ATTR_TC_0
; i
++) {
58 src_tc_cfg
= &src_dcb_cfg
->tc_config
[i
- DCB_PG_ATTR_TC_0
];
59 dst_tc_cfg
= &dst_dcb_cfg
->tc_config
[i
- DCB_PG_ATTR_TC_0
];
61 dst_tc_cfg
->path
[DCB_TX_CONFIG
].prio_type
=
62 src_tc_cfg
->path
[DCB_TX_CONFIG
].prio_type
;
64 dst_tc_cfg
->path
[DCB_TX_CONFIG
].bwg_id
=
65 src_tc_cfg
->path
[DCB_TX_CONFIG
].bwg_id
;
67 dst_tc_cfg
->path
[DCB_TX_CONFIG
].bwg_percent
=
68 src_tc_cfg
->path
[DCB_TX_CONFIG
].bwg_percent
;
70 dst_tc_cfg
->path
[DCB_TX_CONFIG
].up_to_tc_bitmap
=
71 src_tc_cfg
->path
[DCB_TX_CONFIG
].up_to_tc_bitmap
;
73 dst_tc_cfg
->path
[DCB_RX_CONFIG
].prio_type
=
74 src_tc_cfg
->path
[DCB_RX_CONFIG
].prio_type
;
76 dst_tc_cfg
->path
[DCB_RX_CONFIG
].bwg_id
=
77 src_tc_cfg
->path
[DCB_RX_CONFIG
].bwg_id
;
79 dst_tc_cfg
->path
[DCB_RX_CONFIG
].bwg_percent
=
80 src_tc_cfg
->path
[DCB_RX_CONFIG
].bwg_percent
;
82 dst_tc_cfg
->path
[DCB_RX_CONFIG
].up_to_tc_bitmap
=
83 src_tc_cfg
->path
[DCB_RX_CONFIG
].up_to_tc_bitmap
;
86 for (i
= DCB_PG_ATTR_BW_ID_0
; i
< DCB_PG_ATTR_BW_ID_MAX
; i
++) {
87 dst_dcb_cfg
->bw_percentage
[DCB_TX_CONFIG
]
88 [i
-DCB_PG_ATTR_BW_ID_0
] = src_dcb_cfg
->bw_percentage
89 [DCB_TX_CONFIG
][i
-DCB_PG_ATTR_BW_ID_0
];
90 dst_dcb_cfg
->bw_percentage
[DCB_RX_CONFIG
]
91 [i
-DCB_PG_ATTR_BW_ID_0
] = src_dcb_cfg
->bw_percentage
92 [DCB_RX_CONFIG
][i
-DCB_PG_ATTR_BW_ID_0
];
95 for (i
= DCB_PFC_UP_ATTR_0
; i
< DCB_PFC_UP_ATTR_MAX
; i
++) {
96 dst_dcb_cfg
->tc_config
[i
- DCB_PFC_UP_ATTR_0
].dcb_pfc
=
97 src_dcb_cfg
->tc_config
[i
- DCB_PFC_UP_ATTR_0
].dcb_pfc
;
100 dst_dcb_cfg
->pfc_mode_enable
= src_dcb_cfg
->pfc_mode_enable
;
105 static u8
ixgbe_dcbnl_get_state(struct net_device
*netdev
)
107 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
109 return !!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
);
112 static u8
ixgbe_dcbnl_set_state(struct net_device
*netdev
, u8 state
)
115 u8 prio_tc
[MAX_USER_PRIORITY
] = {0};
117 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
119 /* Fail command if not in CEE mode */
120 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
123 /* verify there is something to do, if not then exit */
124 if (!!state
!= !(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
))
128 err
= ixgbe_setup_tc(netdev
, adapter
->dcb_cfg
.num_tcs
.pg_tcs
);
129 ixgbe_dcb_unpack_map(&adapter
->dcb_cfg
, DCB_TX_CONFIG
, prio_tc
);
131 err
= ixgbe_setup_tc(netdev
, 0);
137 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++)
138 netdev_set_prio_tc_map(netdev
, i
, prio_tc
[i
]);
144 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device
*netdev
,
147 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
150 memset(perm_addr
, 0xff, MAX_ADDR_LEN
);
152 for (i
= 0; i
< netdev
->addr_len
; i
++)
153 perm_addr
[i
] = adapter
->hw
.mac
.perm_addr
[i
];
155 switch (adapter
->hw
.mac
.type
) {
156 case ixgbe_mac_82599EB
:
158 for (j
= 0; j
< netdev
->addr_len
; j
++, i
++)
159 perm_addr
[i
] = adapter
->hw
.mac
.san_addr
[j
];
166 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device
*netdev
, int tc
,
167 u8 prio
, u8 bwg_id
, u8 bw_pct
,
170 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
172 if (prio
!= DCB_ATTR_VALUE_UNDEFINED
)
173 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].prio_type
= prio
;
174 if (bwg_id
!= DCB_ATTR_VALUE_UNDEFINED
)
175 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
= bwg_id
;
176 if (bw_pct
!= DCB_ATTR_VALUE_UNDEFINED
)
177 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
=
179 if (up_map
!= DCB_ATTR_VALUE_UNDEFINED
)
180 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
=
183 if ((adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].prio_type
!=
184 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].prio_type
) ||
185 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
!=
186 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
) ||
187 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
!=
188 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
) ||
189 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
!=
190 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
))
191 adapter
->dcb_set_bitmap
|= BIT_PG_TX
;
193 if (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
!=
194 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
)
195 adapter
->dcb_set_bitmap
|= BIT_PFC
| BIT_APP_UPCHG
;
198 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device
*netdev
, int bwg_id
,
201 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
203 adapter
->temp_dcb_cfg
.bw_percentage
[0][bwg_id
] = bw_pct
;
205 if (adapter
->temp_dcb_cfg
.bw_percentage
[0][bwg_id
] !=
206 adapter
->dcb_cfg
.bw_percentage
[0][bwg_id
])
207 adapter
->dcb_set_bitmap
|= BIT_PG_TX
;
210 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device
*netdev
, int tc
,
211 u8 prio
, u8 bwg_id
, u8 bw_pct
,
214 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
216 if (prio
!= DCB_ATTR_VALUE_UNDEFINED
)
217 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].prio_type
= prio
;
218 if (bwg_id
!= DCB_ATTR_VALUE_UNDEFINED
)
219 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
= bwg_id
;
220 if (bw_pct
!= DCB_ATTR_VALUE_UNDEFINED
)
221 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
=
223 if (up_map
!= DCB_ATTR_VALUE_UNDEFINED
)
224 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
=
227 if ((adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].prio_type
!=
228 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].prio_type
) ||
229 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
!=
230 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
) ||
231 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
!=
232 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
) ||
233 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
!=
234 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
))
235 adapter
->dcb_set_bitmap
|= BIT_PG_RX
;
237 if (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
!=
238 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
)
239 adapter
->dcb_set_bitmap
|= BIT_PFC
;
242 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device
*netdev
, int bwg_id
,
245 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
247 adapter
->temp_dcb_cfg
.bw_percentage
[1][bwg_id
] = bw_pct
;
249 if (adapter
->temp_dcb_cfg
.bw_percentage
[1][bwg_id
] !=
250 adapter
->dcb_cfg
.bw_percentage
[1][bwg_id
])
251 adapter
->dcb_set_bitmap
|= BIT_PG_RX
;
254 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device
*netdev
, int tc
,
255 u8
*prio
, u8
*bwg_id
, u8
*bw_pct
,
258 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
260 *prio
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].prio_type
;
261 *bwg_id
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
;
262 *bw_pct
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
;
263 *up_map
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
;
266 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device
*netdev
, int bwg_id
,
269 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
271 *bw_pct
= adapter
->dcb_cfg
.bw_percentage
[0][bwg_id
];
274 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device
*netdev
, int tc
,
275 u8
*prio
, u8
*bwg_id
, u8
*bw_pct
,
278 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
280 *prio
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].prio_type
;
281 *bwg_id
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
;
282 *bw_pct
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
;
283 *up_map
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
;
286 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device
*netdev
, int bwg_id
,
289 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
291 *bw_pct
= adapter
->dcb_cfg
.bw_percentage
[1][bwg_id
];
294 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device
*netdev
, int priority
,
297 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
299 adapter
->temp_dcb_cfg
.tc_config
[priority
].dcb_pfc
= setting
;
300 if (adapter
->temp_dcb_cfg
.tc_config
[priority
].dcb_pfc
!=
301 adapter
->dcb_cfg
.tc_config
[priority
].dcb_pfc
) {
302 adapter
->dcb_set_bitmap
|= BIT_PFC
;
303 adapter
->temp_dcb_cfg
.pfc_mode_enable
= true;
307 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device
*netdev
, int priority
,
310 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
312 *setting
= adapter
->dcb_cfg
.tc_config
[priority
].dcb_pfc
;
316 static void ixgbe_dcbnl_devreset(struct net_device
*dev
)
318 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
320 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
321 usleep_range(1000, 2000);
323 if (netif_running(dev
))
324 dev
->netdev_ops
->ndo_stop(dev
);
326 ixgbe_clear_interrupt_scheme(adapter
);
327 ixgbe_init_interrupt_scheme(adapter
);
329 if (netif_running(dev
))
330 dev
->netdev_ops
->ndo_open(dev
);
332 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
336 static u8
ixgbe_dcbnl_set_all(struct net_device
*netdev
)
338 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
341 struct dcb_app app
= {
342 .selector
= DCB_APP_IDTYPE_ETHTYPE
,
343 .protocol
= ETH_P_FCOE
,
347 /* In IEEE mode, use the IEEE Ethertype selector value */
348 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
) {
349 app
.selector
= IEEE_8021QAZ_APP_SEL_ETHERTYPE
;
350 up
= dcb_ieee_getapp_mask(netdev
, &app
);
352 up
= dcb_getapp(netdev
, &app
);
356 /* Fail command if not in CEE mode */
357 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
360 ret
= ixgbe_copy_dcb_cfg(&adapter
->temp_dcb_cfg
, &adapter
->dcb_cfg
,
363 return DCB_NO_HW_CHG
;
365 if (adapter
->dcb_cfg
.pfc_mode_enable
) {
366 switch (adapter
->hw
.mac
.type
) {
367 case ixgbe_mac_82599EB
:
369 if (adapter
->hw
.fc
.current_mode
!= ixgbe_fc_pfc
)
370 adapter
->last_lfc_mode
=
371 adapter
->hw
.fc
.current_mode
;
376 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_pfc
;
378 switch (adapter
->hw
.mac
.type
) {
379 case ixgbe_mac_82598EB
:
380 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_none
;
382 case ixgbe_mac_82599EB
:
384 adapter
->hw
.fc
.requested_mode
= adapter
->last_lfc_mode
;
391 if (adapter
->dcb_set_bitmap
& (BIT_PG_TX
|BIT_PG_RX
)) {
392 u16 refill
[MAX_TRAFFIC_CLASS
], max
[MAX_TRAFFIC_CLASS
];
393 u8 bwg_id
[MAX_TRAFFIC_CLASS
], prio_type
[MAX_TRAFFIC_CLASS
];
394 /* Priority to TC mapping in CEE case default to 1:1 */
395 u8 prio_tc
[MAX_USER_PRIORITY
];
396 int max_frame
= adapter
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
399 if (adapter
->netdev
->features
& NETIF_F_FCOE_MTU
)
400 max_frame
= max(max_frame
, IXGBE_FCOE_JUMBO_FRAME_SIZE
);
403 ixgbe_dcb_calculate_tc_credits(&adapter
->hw
, &adapter
->dcb_cfg
,
404 max_frame
, DCB_TX_CONFIG
);
405 ixgbe_dcb_calculate_tc_credits(&adapter
->hw
, &adapter
->dcb_cfg
,
406 max_frame
, DCB_RX_CONFIG
);
408 ixgbe_dcb_unpack_refill(&adapter
->dcb_cfg
,
409 DCB_TX_CONFIG
, refill
);
410 ixgbe_dcb_unpack_max(&adapter
->dcb_cfg
, max
);
411 ixgbe_dcb_unpack_bwgid(&adapter
->dcb_cfg
,
412 DCB_TX_CONFIG
, bwg_id
);
413 ixgbe_dcb_unpack_prio(&adapter
->dcb_cfg
,
414 DCB_TX_CONFIG
, prio_type
);
415 ixgbe_dcb_unpack_map(&adapter
->dcb_cfg
,
416 DCB_TX_CONFIG
, prio_tc
);
418 ixgbe_dcb_hw_ets_config(&adapter
->hw
, refill
, max
,
419 bwg_id
, prio_type
, prio_tc
);
421 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++)
422 netdev_set_prio_tc_map(netdev
, i
, prio_tc
[i
]);
425 if (adapter
->dcb_set_bitmap
& BIT_PFC
) {
427 u8 prio_tc
[MAX_USER_PRIORITY
];
429 ixgbe_dcb_unpack_map(&adapter
->dcb_cfg
,
430 DCB_TX_CONFIG
, prio_tc
);
431 ixgbe_dcb_unpack_pfc(&adapter
->dcb_cfg
, &pfc_en
);
432 ixgbe_dcb_hw_pfc_config(&adapter
->hw
, pfc_en
, prio_tc
);
436 if (adapter
->dcb_cfg
.pfc_mode_enable
)
437 adapter
->hw
.fc
.current_mode
= ixgbe_fc_pfc
;
440 /* Reprogam FCoE hardware offloads when the traffic class
441 * FCoE is using changes. This happens if the APP info
442 * changes or the up2tc mapping is updated.
444 if ((up
&& !(up
& (1 << adapter
->fcoe
.up
))) ||
445 (adapter
->dcb_set_bitmap
& BIT_APP_UPCHG
)) {
446 adapter
->fcoe
.up
= ffs(up
) - 1;
447 ixgbe_dcbnl_devreset(netdev
);
448 ret
= DCB_HW_CHG_RST
;
452 adapter
->dcb_set_bitmap
= 0x00;
456 static u8
ixgbe_dcbnl_getcap(struct net_device
*netdev
, int capid
, u8
*cap
)
458 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
461 case DCB_CAP_ATTR_PG
:
464 case DCB_CAP_ATTR_PFC
:
467 case DCB_CAP_ATTR_UP2TC
:
470 case DCB_CAP_ATTR_PG_TCS
:
473 case DCB_CAP_ATTR_PFC_TCS
:
476 case DCB_CAP_ATTR_GSP
:
479 case DCB_CAP_ATTR_BCN
:
482 case DCB_CAP_ATTR_DCBX
:
483 *cap
= adapter
->dcbx_cap
;
493 static u8
ixgbe_dcbnl_getnumtcs(struct net_device
*netdev
, int tcid
, u8
*num
)
495 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
498 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
500 case DCB_NUMTCS_ATTR_PG
:
501 *num
= adapter
->dcb_cfg
.num_tcs
.pg_tcs
;
503 case DCB_NUMTCS_ATTR_PFC
:
504 *num
= adapter
->dcb_cfg
.num_tcs
.pfc_tcs
;
517 static u8
ixgbe_dcbnl_setnumtcs(struct net_device
*netdev
, int tcid
, u8 num
)
522 static u8
ixgbe_dcbnl_getpfcstate(struct net_device
*netdev
)
524 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
526 return adapter
->dcb_cfg
.pfc_mode_enable
;
529 static void ixgbe_dcbnl_setpfcstate(struct net_device
*netdev
, u8 state
)
531 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
533 adapter
->temp_dcb_cfg
.pfc_mode_enable
= state
;
534 if (adapter
->temp_dcb_cfg
.pfc_mode_enable
!=
535 adapter
->dcb_cfg
.pfc_mode_enable
)
536 adapter
->dcb_set_bitmap
|= BIT_PFC
;
540 * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
541 * @netdev : the corresponding netdev
542 * @idtype : identifies the id as ether type or TCP/UDP port number
543 * @id: id is either ether type or TCP/UDP port number
545 * Returns : on success, returns a non-zero 802.1p user priority bitmap
546 * otherwise returns 0 as the invalid user priority bitmap to indicate an
549 static u8
ixgbe_dcbnl_getapp(struct net_device
*netdev
, u8 idtype
, u16 id
)
551 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
552 struct dcb_app app
= {
557 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
560 return dcb_getapp(netdev
, &app
);
563 static int ixgbe_dcbnl_ieee_getets(struct net_device
*dev
,
564 struct ieee_ets
*ets
)
566 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
567 struct ieee_ets
*my_ets
= adapter
->ixgbe_ieee_ets
;
569 ets
->ets_cap
= adapter
->dcb_cfg
.num_tcs
.pg_tcs
;
571 /* No IEEE PFC settings available */
575 ets
->cbs
= my_ets
->cbs
;
576 memcpy(ets
->tc_tx_bw
, my_ets
->tc_tx_bw
, sizeof(ets
->tc_tx_bw
));
577 memcpy(ets
->tc_rx_bw
, my_ets
->tc_rx_bw
, sizeof(ets
->tc_rx_bw
));
578 memcpy(ets
->tc_tsa
, my_ets
->tc_tsa
, sizeof(ets
->tc_tsa
));
579 memcpy(ets
->prio_tc
, my_ets
->prio_tc
, sizeof(ets
->prio_tc
));
583 static int ixgbe_dcbnl_ieee_setets(struct net_device
*dev
,
584 struct ieee_ets
*ets
)
586 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
587 int max_frame
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
591 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
594 if (!adapter
->ixgbe_ieee_ets
) {
595 adapter
->ixgbe_ieee_ets
= kmalloc(sizeof(struct ieee_ets
),
597 if (!adapter
->ixgbe_ieee_ets
)
601 memcpy(adapter
->ixgbe_ieee_ets
, ets
, sizeof(*adapter
->ixgbe_ieee_ets
));
603 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++) {
604 if (ets
->prio_tc
[i
] > max_tc
)
605 max_tc
= ets
->prio_tc
[i
];
611 if (max_tc
> adapter
->dcb_cfg
.num_tcs
.pg_tcs
)
614 if (max_tc
!= netdev_get_num_tc(dev
))
615 err
= ixgbe_setup_tc(dev
, max_tc
);
620 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++)
621 netdev_set_prio_tc_map(dev
, i
, ets
->prio_tc
[i
]);
623 err
= ixgbe_dcb_hw_ets(&adapter
->hw
, ets
, max_frame
);
628 static int ixgbe_dcbnl_ieee_getpfc(struct net_device
*dev
,
629 struct ieee_pfc
*pfc
)
631 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
632 struct ieee_pfc
*my_pfc
= adapter
->ixgbe_ieee_pfc
;
635 pfc
->pfc_cap
= adapter
->dcb_cfg
.num_tcs
.pfc_tcs
;
637 /* No IEEE PFC settings available */
641 pfc
->pfc_en
= my_pfc
->pfc_en
;
642 pfc
->mbc
= my_pfc
->mbc
;
643 pfc
->delay
= my_pfc
->delay
;
645 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
646 pfc
->requests
[i
] = adapter
->stats
.pxoffrxc
[i
];
647 pfc
->indications
[i
] = adapter
->stats
.pxofftxc
[i
];
653 static int ixgbe_dcbnl_ieee_setpfc(struct net_device
*dev
,
654 struct ieee_pfc
*pfc
)
656 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
659 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
662 if (!adapter
->ixgbe_ieee_pfc
) {
663 adapter
->ixgbe_ieee_pfc
= kmalloc(sizeof(struct ieee_pfc
),
665 if (!adapter
->ixgbe_ieee_pfc
)
669 prio_tc
= adapter
->ixgbe_ieee_ets
->prio_tc
;
670 memcpy(adapter
->ixgbe_ieee_pfc
, pfc
, sizeof(*adapter
->ixgbe_ieee_pfc
));
671 return ixgbe_dcb_hw_pfc_config(&adapter
->hw
, pfc
->pfc_en
, prio_tc
);
674 static int ixgbe_dcbnl_ieee_setapp(struct net_device
*dev
,
677 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
680 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
683 err
= dcb_ieee_setapp(dev
, app
);
686 if (!err
&& app
->selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
687 app
->protocol
== ETH_P_FCOE
) {
688 u8 app_mask
= dcb_ieee_getapp_mask(dev
, app
);
690 if (app_mask
& (1 << adapter
->fcoe
.up
))
693 adapter
->fcoe
.up
= app
->priority
;
694 ixgbe_dcbnl_devreset(dev
);
700 static int ixgbe_dcbnl_ieee_delapp(struct net_device
*dev
,
703 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
706 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
709 err
= dcb_ieee_delapp(dev
, app
);
712 if (!err
&& app
->selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
713 app
->protocol
== ETH_P_FCOE
) {
714 u8 app_mask
= dcb_ieee_getapp_mask(dev
, app
);
716 if (app_mask
& (1 << adapter
->fcoe
.up
))
719 adapter
->fcoe
.up
= app_mask
?
720 ffs(app_mask
) - 1 : IXGBE_FCOE_DEFTC
;
721 ixgbe_dcbnl_devreset(dev
);
727 static u8
ixgbe_dcbnl_getdcbx(struct net_device
*dev
)
729 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
730 return adapter
->dcbx_cap
;
733 static u8
ixgbe_dcbnl_setdcbx(struct net_device
*dev
, u8 mode
)
735 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
736 struct ieee_ets ets
= {0};
737 struct ieee_pfc pfc
= {0};
740 /* no support for LLD_MANAGED modes or CEE+IEEE */
741 if ((mode
& DCB_CAP_DCBX_LLD_MANAGED
) ||
742 ((mode
& DCB_CAP_DCBX_VER_IEEE
) && (mode
& DCB_CAP_DCBX_VER_CEE
)) ||
743 !(mode
& DCB_CAP_DCBX_HOST
))
746 if (mode
== adapter
->dcbx_cap
)
749 adapter
->dcbx_cap
= mode
;
751 /* ETS and PFC defaults */
755 if (mode
& DCB_CAP_DCBX_VER_IEEE
) {
756 ixgbe_dcbnl_ieee_setets(dev
, &ets
);
757 ixgbe_dcbnl_ieee_setpfc(dev
, &pfc
);
758 } else if (mode
& DCB_CAP_DCBX_VER_CEE
) {
759 u8 mask
= BIT_PFC
| BIT_PG_TX
| BIT_PG_RX
| BIT_APP_UPCHG
;
761 adapter
->dcb_set_bitmap
|= mask
;
762 ixgbe_dcbnl_set_all(dev
);
764 /* Drop into single TC mode strict priority as this
765 * indicates CEE and IEEE versions are disabled
767 ixgbe_dcbnl_ieee_setets(dev
, &ets
);
768 ixgbe_dcbnl_ieee_setpfc(dev
, &pfc
);
769 err
= ixgbe_setup_tc(dev
, 0);
775 const struct dcbnl_rtnl_ops dcbnl_ops
= {
776 .ieee_getets
= ixgbe_dcbnl_ieee_getets
,
777 .ieee_setets
= ixgbe_dcbnl_ieee_setets
,
778 .ieee_getpfc
= ixgbe_dcbnl_ieee_getpfc
,
779 .ieee_setpfc
= ixgbe_dcbnl_ieee_setpfc
,
780 .ieee_setapp
= ixgbe_dcbnl_ieee_setapp
,
781 .ieee_delapp
= ixgbe_dcbnl_ieee_delapp
,
782 .getstate
= ixgbe_dcbnl_get_state
,
783 .setstate
= ixgbe_dcbnl_set_state
,
784 .getpermhwaddr
= ixgbe_dcbnl_get_perm_hw_addr
,
785 .setpgtccfgtx
= ixgbe_dcbnl_set_pg_tc_cfg_tx
,
786 .setpgbwgcfgtx
= ixgbe_dcbnl_set_pg_bwg_cfg_tx
,
787 .setpgtccfgrx
= ixgbe_dcbnl_set_pg_tc_cfg_rx
,
788 .setpgbwgcfgrx
= ixgbe_dcbnl_set_pg_bwg_cfg_rx
,
789 .getpgtccfgtx
= ixgbe_dcbnl_get_pg_tc_cfg_tx
,
790 .getpgbwgcfgtx
= ixgbe_dcbnl_get_pg_bwg_cfg_tx
,
791 .getpgtccfgrx
= ixgbe_dcbnl_get_pg_tc_cfg_rx
,
792 .getpgbwgcfgrx
= ixgbe_dcbnl_get_pg_bwg_cfg_rx
,
793 .setpfccfg
= ixgbe_dcbnl_set_pfc_cfg
,
794 .getpfccfg
= ixgbe_dcbnl_get_pfc_cfg
,
795 .setall
= ixgbe_dcbnl_set_all
,
796 .getcap
= ixgbe_dcbnl_getcap
,
797 .getnumtcs
= ixgbe_dcbnl_getnumtcs
,
798 .setnumtcs
= ixgbe_dcbnl_setnumtcs
,
799 .getpfcstate
= ixgbe_dcbnl_getpfcstate
,
800 .setpfcstate
= ixgbe_dcbnl_setpfcstate
,
801 .getapp
= ixgbe_dcbnl_getapp
,
802 .getdcbx
= ixgbe_dcbnl_getdcbx
,
803 .setdcbx
= ixgbe_dcbnl_setdcbx
,