1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2011 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 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
119 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
122 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
123 e_err(drv
, "Enable failed, needs MSI-X\n");
128 if (netif_running(netdev
))
129 netdev
->netdev_ops
->ndo_stop(netdev
);
130 ixgbe_clear_interrupt_scheme(adapter
);
132 adapter
->flags
&= ~IXGBE_FLAG_RSS_ENABLED
;
133 switch (adapter
->hw
.mac
.type
) {
134 case ixgbe_mac_82598EB
:
135 adapter
->last_lfc_mode
= adapter
->hw
.fc
.current_mode
;
136 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_none
;
138 case ixgbe_mac_82599EB
:
140 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
141 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
147 adapter
->flags
|= IXGBE_FLAG_DCB_ENABLED
;
148 if (!netdev_get_num_tc(netdev
))
149 ixgbe_setup_tc(netdev
, MAX_TRAFFIC_CLASS
);
151 ixgbe_init_interrupt_scheme(adapter
);
152 if (netif_running(netdev
))
153 netdev
->netdev_ops
->ndo_open(netdev
);
156 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
157 if (netif_running(netdev
))
158 netdev
->netdev_ops
->ndo_stop(netdev
);
159 ixgbe_clear_interrupt_scheme(adapter
);
161 adapter
->hw
.fc
.requested_mode
= adapter
->last_lfc_mode
;
162 adapter
->temp_dcb_cfg
.pfc_mode_enable
= false;
163 adapter
->dcb_cfg
.pfc_mode_enable
= false;
164 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
165 adapter
->flags
|= IXGBE_FLAG_RSS_ENABLED
;
166 switch (adapter
->hw
.mac
.type
) {
167 case ixgbe_mac_82599EB
:
169 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
175 ixgbe_setup_tc(netdev
, 0);
177 ixgbe_init_interrupt_scheme(adapter
);
178 if (netif_running(netdev
))
179 netdev
->netdev_ops
->ndo_open(netdev
);
186 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device
*netdev
,
189 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
192 memset(perm_addr
, 0xff, MAX_ADDR_LEN
);
194 for (i
= 0; i
< netdev
->addr_len
; i
++)
195 perm_addr
[i
] = adapter
->hw
.mac
.perm_addr
[i
];
197 switch (adapter
->hw
.mac
.type
) {
198 case ixgbe_mac_82599EB
:
200 for (j
= 0; j
< netdev
->addr_len
; j
++, i
++)
201 perm_addr
[i
] = adapter
->hw
.mac
.san_addr
[j
];
208 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device
*netdev
, int tc
,
209 u8 prio
, u8 bwg_id
, u8 bw_pct
,
212 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
214 if (prio
!= DCB_ATTR_VALUE_UNDEFINED
)
215 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].prio_type
= prio
;
216 if (bwg_id
!= DCB_ATTR_VALUE_UNDEFINED
)
217 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
= bwg_id
;
218 if (bw_pct
!= DCB_ATTR_VALUE_UNDEFINED
)
219 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
=
221 if (up_map
!= DCB_ATTR_VALUE_UNDEFINED
)
222 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
=
225 if ((adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].prio_type
!=
226 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].prio_type
) ||
227 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
!=
228 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
) ||
229 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
!=
230 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
) ||
231 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
!=
232 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
))
233 adapter
->dcb_set_bitmap
|= BIT_PG_TX
;
236 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device
*netdev
, int bwg_id
,
239 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
241 adapter
->temp_dcb_cfg
.bw_percentage
[0][bwg_id
] = bw_pct
;
243 if (adapter
->temp_dcb_cfg
.bw_percentage
[0][bwg_id
] !=
244 adapter
->dcb_cfg
.bw_percentage
[0][bwg_id
])
245 adapter
->dcb_set_bitmap
|= BIT_PG_TX
;
248 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device
*netdev
, int tc
,
249 u8 prio
, u8 bwg_id
, u8 bw_pct
,
252 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
254 if (prio
!= DCB_ATTR_VALUE_UNDEFINED
)
255 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].prio_type
= prio
;
256 if (bwg_id
!= DCB_ATTR_VALUE_UNDEFINED
)
257 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
= bwg_id
;
258 if (bw_pct
!= DCB_ATTR_VALUE_UNDEFINED
)
259 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
=
261 if (up_map
!= DCB_ATTR_VALUE_UNDEFINED
)
262 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
=
265 if ((adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].prio_type
!=
266 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].prio_type
) ||
267 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
!=
268 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
) ||
269 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
!=
270 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
) ||
271 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
!=
272 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
))
273 adapter
->dcb_set_bitmap
|= BIT_PG_RX
;
276 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device
*netdev
, int bwg_id
,
279 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
281 adapter
->temp_dcb_cfg
.bw_percentage
[1][bwg_id
] = bw_pct
;
283 if (adapter
->temp_dcb_cfg
.bw_percentage
[1][bwg_id
] !=
284 adapter
->dcb_cfg
.bw_percentage
[1][bwg_id
])
285 adapter
->dcb_set_bitmap
|= BIT_PG_RX
;
288 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device
*netdev
, int tc
,
289 u8
*prio
, u8
*bwg_id
, u8
*bw_pct
,
292 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
294 *prio
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].prio_type
;
295 *bwg_id
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
;
296 *bw_pct
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
;
297 *up_map
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
;
300 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device
*netdev
, int bwg_id
,
303 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
305 *bw_pct
= adapter
->dcb_cfg
.bw_percentage
[0][bwg_id
];
308 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device
*netdev
, int tc
,
309 u8
*prio
, u8
*bwg_id
, u8
*bw_pct
,
312 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
314 *prio
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].prio_type
;
315 *bwg_id
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
;
316 *bw_pct
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
;
317 *up_map
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
;
320 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device
*netdev
, int bwg_id
,
323 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
325 *bw_pct
= adapter
->dcb_cfg
.bw_percentage
[1][bwg_id
];
328 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device
*netdev
, int priority
,
331 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
333 adapter
->temp_dcb_cfg
.tc_config
[priority
].dcb_pfc
= setting
;
334 if (adapter
->temp_dcb_cfg
.tc_config
[priority
].dcb_pfc
!=
335 adapter
->dcb_cfg
.tc_config
[priority
].dcb_pfc
) {
336 adapter
->dcb_set_bitmap
|= BIT_PFC
;
337 adapter
->temp_dcb_cfg
.pfc_mode_enable
= true;
341 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device
*netdev
, int priority
,
344 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
346 *setting
= adapter
->dcb_cfg
.tc_config
[priority
].dcb_pfc
;
349 static u8
ixgbe_dcbnl_set_all(struct net_device
*netdev
)
351 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
354 if (!adapter
->dcb_set_bitmap
||
355 !(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
356 return DCB_NO_HW_CHG
;
358 ret
= ixgbe_copy_dcb_cfg(&adapter
->temp_dcb_cfg
, &adapter
->dcb_cfg
,
362 return DCB_NO_HW_CHG
;
365 * Only take down the adapter if an app change occured. FCoE
366 * may shuffle tx rings in this case and this can not be done
367 * without a reset currently.
369 if (adapter
->dcb_set_bitmap
& BIT_APP_UPCHG
) {
370 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
373 if (netif_running(netdev
))
374 netdev
->netdev_ops
->ndo_stop(netdev
);
375 ixgbe_clear_interrupt_scheme(adapter
);
378 if (adapter
->dcb_cfg
.pfc_mode_enable
) {
379 switch (adapter
->hw
.mac
.type
) {
380 case ixgbe_mac_82599EB
:
382 if (adapter
->hw
.fc
.current_mode
!= ixgbe_fc_pfc
)
383 adapter
->last_lfc_mode
=
384 adapter
->hw
.fc
.current_mode
;
389 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_pfc
;
391 switch (adapter
->hw
.mac
.type
) {
392 case ixgbe_mac_82598EB
:
393 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_none
;
395 case ixgbe_mac_82599EB
:
397 adapter
->hw
.fc
.requested_mode
= adapter
->last_lfc_mode
;
404 if (adapter
->dcb_set_bitmap
& BIT_APP_UPCHG
) {
405 ixgbe_init_interrupt_scheme(adapter
);
406 if (netif_running(netdev
))
407 netdev
->netdev_ops
->ndo_open(netdev
);
408 ret
= DCB_HW_CHG_RST
;
411 if (adapter
->dcb_set_bitmap
& BIT_PFC
) {
413 ixgbe_dcb_unpack_pfc(&adapter
->dcb_cfg
, &pfc_en
);
414 ixgbe_dcb_hw_pfc_config(&adapter
->hw
, pfc_en
);
418 if (adapter
->dcb_set_bitmap
& (BIT_PG_TX
|BIT_PG_RX
)) {
419 u16 refill
[MAX_TRAFFIC_CLASS
], max
[MAX_TRAFFIC_CLASS
];
420 u8 bwg_id
[MAX_TRAFFIC_CLASS
], prio_type
[MAX_TRAFFIC_CLASS
];
421 int max_frame
= adapter
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
424 if (adapter
->netdev
->features
& NETIF_F_FCOE_MTU
)
425 max_frame
= max(max_frame
, IXGBE_FCOE_JUMBO_FRAME_SIZE
);
428 ixgbe_dcb_calculate_tc_credits(&adapter
->hw
, &adapter
->dcb_cfg
,
429 max_frame
, DCB_TX_CONFIG
);
430 ixgbe_dcb_calculate_tc_credits(&adapter
->hw
, &adapter
->dcb_cfg
,
431 max_frame
, DCB_RX_CONFIG
);
433 ixgbe_dcb_unpack_refill(&adapter
->dcb_cfg
,
434 DCB_TX_CONFIG
, refill
);
435 ixgbe_dcb_unpack_max(&adapter
->dcb_cfg
, max
);
436 ixgbe_dcb_unpack_bwgid(&adapter
->dcb_cfg
,
437 DCB_TX_CONFIG
, bwg_id
);
438 ixgbe_dcb_unpack_prio(&adapter
->dcb_cfg
,
439 DCB_TX_CONFIG
, prio_type
);
441 ixgbe_dcb_hw_ets_config(&adapter
->hw
, refill
, max
,
445 if (adapter
->dcb_cfg
.pfc_mode_enable
)
446 adapter
->hw
.fc
.current_mode
= ixgbe_fc_pfc
;
448 if (adapter
->dcb_set_bitmap
& BIT_APP_UPCHG
)
449 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
450 adapter
->dcb_set_bitmap
= 0x00;
454 static u8
ixgbe_dcbnl_getcap(struct net_device
*netdev
, int capid
, u8
*cap
)
456 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
459 case DCB_CAP_ATTR_PG
:
462 case DCB_CAP_ATTR_PFC
:
465 case DCB_CAP_ATTR_UP2TC
:
468 case DCB_CAP_ATTR_PG_TCS
:
471 case DCB_CAP_ATTR_PFC_TCS
:
474 case DCB_CAP_ATTR_GSP
:
477 case DCB_CAP_ATTR_BCN
:
480 case DCB_CAP_ATTR_DCBX
:
481 *cap
= adapter
->dcbx_cap
;
491 static u8
ixgbe_dcbnl_getnumtcs(struct net_device
*netdev
, int tcid
, u8
*num
)
493 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
496 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
498 case DCB_NUMTCS_ATTR_PG
:
499 *num
= MAX_TRAFFIC_CLASS
;
501 case DCB_NUMTCS_ATTR_PFC
:
502 *num
= MAX_TRAFFIC_CLASS
;
515 static u8
ixgbe_dcbnl_setnumtcs(struct net_device
*netdev
, int tcid
, u8 num
)
520 static u8
ixgbe_dcbnl_getpfcstate(struct net_device
*netdev
)
522 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
524 return adapter
->dcb_cfg
.pfc_mode_enable
;
527 static void ixgbe_dcbnl_setpfcstate(struct net_device
*netdev
, u8 state
)
529 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
531 adapter
->temp_dcb_cfg
.pfc_mode_enable
= state
;
532 if (adapter
->temp_dcb_cfg
.pfc_mode_enable
!=
533 adapter
->dcb_cfg
.pfc_mode_enable
)
534 adapter
->dcb_set_bitmap
|= BIT_PFC
;
538 * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
539 * @netdev : the corresponding netdev
540 * @idtype : identifies the id as ether type or TCP/UDP port number
541 * @id: id is either ether type or TCP/UDP port number
543 * Returns : on success, returns a non-zero 802.1p user priority bitmap
544 * otherwise returns 0 as the invalid user priority bitmap to indicate an
547 static u8
ixgbe_dcbnl_getapp(struct net_device
*netdev
, u8 idtype
, u16 id
)
549 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
550 struct dcb_app app
= {
555 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
558 return dcb_getapp(netdev
, &app
);
562 * ixgbe_dcbnl_setapp - set the DCBX application user priority
563 * @netdev : the corresponding netdev
564 * @idtype : identifies the id as ether type or TCP/UDP port number
565 * @id: id is either ether type or TCP/UDP port number
566 * @up: the 802.1p user priority bitmap
568 * Returns : 0 on success or 1 on error
570 static u8
ixgbe_dcbnl_setapp(struct net_device
*netdev
,
571 u8 idtype
, u16 id
, u8 up
)
573 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
575 struct dcb_app app
= {
581 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
584 rval
= dcb_setapp(netdev
, &app
);
587 case DCB_APP_IDTYPE_ETHTYPE
:
589 if (id
== ETH_P_FCOE
) {
592 /* Get current programmed tc */
593 old_tc
= adapter
->fcoe
.tc
;
594 rval
= ixgbe_fcoe_setapp(adapter
, up
);
597 !(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) ||
598 !(adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
))
601 /* The FCoE application priority may be changed multiple
602 * times in quick sucession with switches that build up
603 * TLVs. To avoid creating uneeded device resets this
604 * checks the actual HW configuration and clears
605 * BIT_APP_UPCHG if a HW configuration change is not
608 if (old_tc
== adapter
->fcoe
.tc
)
609 adapter
->dcb_set_bitmap
&= ~BIT_APP_UPCHG
;
611 adapter
->dcb_set_bitmap
|= BIT_APP_UPCHG
;
615 case DCB_APP_IDTYPE_PORTNUM
:
623 static int ixgbe_dcbnl_ieee_getets(struct net_device
*dev
,
624 struct ieee_ets
*ets
)
626 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
627 struct ieee_ets
*my_ets
= adapter
->ixgbe_ieee_ets
;
629 /* No IEEE PFC settings available */
633 ets
->ets_cap
= MAX_TRAFFIC_CLASS
;
634 ets
->cbs
= my_ets
->cbs
;
635 memcpy(ets
->tc_tx_bw
, my_ets
->tc_tx_bw
, sizeof(ets
->tc_tx_bw
));
636 memcpy(ets
->tc_rx_bw
, my_ets
->tc_rx_bw
, sizeof(ets
->tc_rx_bw
));
637 memcpy(ets
->tc_tsa
, my_ets
->tc_tsa
, sizeof(ets
->tc_tsa
));
638 memcpy(ets
->prio_tc
, my_ets
->prio_tc
, sizeof(ets
->prio_tc
));
642 static int ixgbe_dcbnl_ieee_setets(struct net_device
*dev
,
643 struct ieee_ets
*ets
)
645 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
646 __u16 refill
[IEEE_8021QAZ_MAX_TCS
], max
[IEEE_8021QAZ_MAX_TCS
];
647 int max_frame
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
649 /* naively give each TC a bwg to map onto CEE hardware */
650 __u8 bwg_id
[IEEE_8021QAZ_MAX_TCS
] = {0, 1, 2, 3, 4, 5, 6, 7};
652 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
655 if (!adapter
->ixgbe_ieee_ets
) {
656 adapter
->ixgbe_ieee_ets
= kmalloc(sizeof(struct ieee_ets
),
658 if (!adapter
->ixgbe_ieee_ets
)
662 memcpy(adapter
->ixgbe_ieee_ets
, ets
, sizeof(*adapter
->ixgbe_ieee_ets
));
664 ixgbe_ieee_credits(ets
->tc_tx_bw
, refill
, max
, max_frame
);
665 err
= ixgbe_dcb_hw_ets_config(&adapter
->hw
, refill
, max
,
666 bwg_id
, ets
->tc_tsa
);
670 static int ixgbe_dcbnl_ieee_getpfc(struct net_device
*dev
,
671 struct ieee_pfc
*pfc
)
673 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
674 struct ieee_pfc
*my_pfc
= adapter
->ixgbe_ieee_pfc
;
677 /* No IEEE PFC settings available */
681 pfc
->pfc_cap
= MAX_TRAFFIC_CLASS
;
682 pfc
->pfc_en
= my_pfc
->pfc_en
;
683 pfc
->mbc
= my_pfc
->mbc
;
684 pfc
->delay
= my_pfc
->delay
;
686 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
687 pfc
->requests
[i
] = adapter
->stats
.pxoffrxc
[i
];
688 pfc
->indications
[i
] = adapter
->stats
.pxofftxc
[i
];
694 static int ixgbe_dcbnl_ieee_setpfc(struct net_device
*dev
,
695 struct ieee_pfc
*pfc
)
697 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
700 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
703 if (!adapter
->ixgbe_ieee_pfc
) {
704 adapter
->ixgbe_ieee_pfc
= kmalloc(sizeof(struct ieee_pfc
),
706 if (!adapter
->ixgbe_ieee_pfc
)
710 memcpy(adapter
->ixgbe_ieee_pfc
, pfc
, sizeof(*adapter
->ixgbe_ieee_pfc
));
711 err
= ixgbe_dcb_hw_pfc_config(&adapter
->hw
, pfc
->pfc_en
);
715 static int ixgbe_dcbnl_ieee_setapp(struct net_device
*dev
,
718 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
720 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
723 if (app
->selector
== 1 && app
->protocol
== ETH_P_FCOE
) {
724 if (adapter
->fcoe
.tc
== app
->priority
)
727 /* In IEEE mode map up to tc 1:1 */
728 adapter
->fcoe
.tc
= app
->priority
;
729 adapter
->fcoe
.up
= app
->priority
;
731 /* Force hardware reset required to push FCoE
732 * setup on {tx|rx}_rings
734 adapter
->dcb_set_bitmap
|= BIT_APP_UPCHG
;
735 ixgbe_dcbnl_set_all(dev
);
740 dcb_setapp(dev
, app
);
744 static u8
ixgbe_dcbnl_getdcbx(struct net_device
*dev
)
746 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
747 return adapter
->dcbx_cap
;
750 static u8
ixgbe_dcbnl_setdcbx(struct net_device
*dev
, u8 mode
)
752 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
753 struct ieee_ets ets
= {0};
754 struct ieee_pfc pfc
= {0};
756 /* no support for LLD_MANAGED modes or CEE+IEEE */
757 if ((mode
& DCB_CAP_DCBX_LLD_MANAGED
) ||
758 ((mode
& DCB_CAP_DCBX_VER_IEEE
) && (mode
& DCB_CAP_DCBX_VER_CEE
)) ||
759 !(mode
& DCB_CAP_DCBX_HOST
))
762 if (mode
== adapter
->dcbx_cap
)
765 adapter
->dcbx_cap
= mode
;
767 /* ETS and PFC defaults */
771 if (mode
& DCB_CAP_DCBX_VER_IEEE
) {
772 ixgbe_dcbnl_ieee_setets(dev
, &ets
);
773 ixgbe_dcbnl_ieee_setpfc(dev
, &pfc
);
774 } else if (mode
& DCB_CAP_DCBX_VER_CEE
) {
775 adapter
->dcb_set_bitmap
|= (BIT_PFC
& BIT_PG_TX
& BIT_PG_RX
);
776 ixgbe_dcbnl_set_all(dev
);
778 /* Drop into single TC mode strict priority as this
779 * indicates CEE and IEEE versions are disabled
781 ixgbe_dcbnl_ieee_setets(dev
, &ets
);
782 ixgbe_dcbnl_ieee_setpfc(dev
, &pfc
);
783 ixgbe_dcbnl_set_state(dev
, 0);
789 const struct dcbnl_rtnl_ops dcbnl_ops
= {
790 .ieee_getets
= ixgbe_dcbnl_ieee_getets
,
791 .ieee_setets
= ixgbe_dcbnl_ieee_setets
,
792 .ieee_getpfc
= ixgbe_dcbnl_ieee_getpfc
,
793 .ieee_setpfc
= ixgbe_dcbnl_ieee_setpfc
,
794 .ieee_setapp
= ixgbe_dcbnl_ieee_setapp
,
795 .getstate
= ixgbe_dcbnl_get_state
,
796 .setstate
= ixgbe_dcbnl_set_state
,
797 .getpermhwaddr
= ixgbe_dcbnl_get_perm_hw_addr
,
798 .setpgtccfgtx
= ixgbe_dcbnl_set_pg_tc_cfg_tx
,
799 .setpgbwgcfgtx
= ixgbe_dcbnl_set_pg_bwg_cfg_tx
,
800 .setpgtccfgrx
= ixgbe_dcbnl_set_pg_tc_cfg_rx
,
801 .setpgbwgcfgrx
= ixgbe_dcbnl_set_pg_bwg_cfg_rx
,
802 .getpgtccfgtx
= ixgbe_dcbnl_get_pg_tc_cfg_tx
,
803 .getpgbwgcfgtx
= ixgbe_dcbnl_get_pg_bwg_cfg_tx
,
804 .getpgtccfgrx
= ixgbe_dcbnl_get_pg_tc_cfg_rx
,
805 .getpgbwgcfgrx
= ixgbe_dcbnl_get_pg_bwg_cfg_rx
,
806 .setpfccfg
= ixgbe_dcbnl_set_pfc_cfg
,
807 .getpfccfg
= ixgbe_dcbnl_get_pfc_cfg
,
808 .setall
= ixgbe_dcbnl_set_all
,
809 .getcap
= ixgbe_dcbnl_getcap
,
810 .getnumtcs
= ixgbe_dcbnl_getnumtcs
,
811 .setnumtcs
= ixgbe_dcbnl_setnumtcs
,
812 .getpfcstate
= ixgbe_dcbnl_getpfcstate
,
813 .setpfcstate
= ixgbe_dcbnl_setpfcstate
,
814 .getapp
= ixgbe_dcbnl_getapp
,
815 .setapp
= ixgbe_dcbnl_setapp
,
816 .getdcbx
= ixgbe_dcbnl_getdcbx
,
817 .setdcbx
= ixgbe_dcbnl_setdcbx
,