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
);
117 /* Fail command if not in CEE mode */
118 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
121 /* verify there is something to do, if not then exit */
122 if (!!state
!= !(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
))
126 err
= ixgbe_setup_tc(netdev
, adapter
->dcb_cfg
.num_tcs
.pg_tcs
);
128 err
= ixgbe_setup_tc(netdev
, 0);
133 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device
*netdev
,
136 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
139 memset(perm_addr
, 0xff, MAX_ADDR_LEN
);
141 for (i
= 0; i
< netdev
->addr_len
; i
++)
142 perm_addr
[i
] = adapter
->hw
.mac
.perm_addr
[i
];
144 switch (adapter
->hw
.mac
.type
) {
145 case ixgbe_mac_82599EB
:
147 for (j
= 0; j
< netdev
->addr_len
; j
++, i
++)
148 perm_addr
[i
] = adapter
->hw
.mac
.san_addr
[j
];
155 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device
*netdev
, int tc
,
156 u8 prio
, u8 bwg_id
, u8 bw_pct
,
159 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
161 /* Abort a bad configuration */
162 if (ffs(up_map
) > adapter
->dcb_cfg
.num_tcs
.pg_tcs
)
165 if (prio
!= DCB_ATTR_VALUE_UNDEFINED
)
166 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].prio_type
= prio
;
167 if (bwg_id
!= DCB_ATTR_VALUE_UNDEFINED
)
168 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
= bwg_id
;
169 if (bw_pct
!= DCB_ATTR_VALUE_UNDEFINED
)
170 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
=
172 if (up_map
!= DCB_ATTR_VALUE_UNDEFINED
)
173 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
=
176 if ((adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].prio_type
!=
177 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].prio_type
) ||
178 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
!=
179 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
) ||
180 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
!=
181 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
) ||
182 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
!=
183 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
))
184 adapter
->dcb_set_bitmap
|= BIT_PG_TX
;
186 if (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
!=
187 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
)
188 adapter
->dcb_set_bitmap
|= BIT_PFC
;
191 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device
*netdev
, int bwg_id
,
194 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
196 adapter
->temp_dcb_cfg
.bw_percentage
[0][bwg_id
] = bw_pct
;
198 if (adapter
->temp_dcb_cfg
.bw_percentage
[0][bwg_id
] !=
199 adapter
->dcb_cfg
.bw_percentage
[0][bwg_id
])
200 adapter
->dcb_set_bitmap
|= BIT_PG_TX
;
203 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device
*netdev
, int tc
,
204 u8 prio
, u8 bwg_id
, u8 bw_pct
,
207 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
209 /* Abort bad configurations */
210 if (ffs(up_map
) > adapter
->dcb_cfg
.num_tcs
.pg_tcs
)
213 if (prio
!= DCB_ATTR_VALUE_UNDEFINED
)
214 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].prio_type
= prio
;
215 if (bwg_id
!= DCB_ATTR_VALUE_UNDEFINED
)
216 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
= bwg_id
;
217 if (bw_pct
!= DCB_ATTR_VALUE_UNDEFINED
)
218 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
=
220 if (up_map
!= DCB_ATTR_VALUE_UNDEFINED
)
221 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
=
224 if ((adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].prio_type
!=
225 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].prio_type
) ||
226 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
!=
227 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
) ||
228 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
!=
229 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
) ||
230 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
!=
231 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
))
232 adapter
->dcb_set_bitmap
|= BIT_PG_RX
;
234 if (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
!=
235 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
)
236 adapter
->dcb_set_bitmap
|= BIT_PFC
;
239 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device
*netdev
, int bwg_id
,
242 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
244 adapter
->temp_dcb_cfg
.bw_percentage
[1][bwg_id
] = bw_pct
;
246 if (adapter
->temp_dcb_cfg
.bw_percentage
[1][bwg_id
] !=
247 adapter
->dcb_cfg
.bw_percentage
[1][bwg_id
])
248 adapter
->dcb_set_bitmap
|= BIT_PG_RX
;
251 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device
*netdev
, int tc
,
252 u8
*prio
, u8
*bwg_id
, u8
*bw_pct
,
255 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
257 *prio
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].prio_type
;
258 *bwg_id
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
;
259 *bw_pct
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
;
260 *up_map
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
;
263 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device
*netdev
, int bwg_id
,
266 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
268 *bw_pct
= adapter
->dcb_cfg
.bw_percentage
[0][bwg_id
];
271 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device
*netdev
, int tc
,
272 u8
*prio
, u8
*bwg_id
, u8
*bw_pct
,
275 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
277 *prio
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].prio_type
;
278 *bwg_id
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
;
279 *bw_pct
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
;
280 *up_map
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
;
283 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device
*netdev
, int bwg_id
,
286 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
288 *bw_pct
= adapter
->dcb_cfg
.bw_percentage
[1][bwg_id
];
291 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device
*netdev
, int priority
,
294 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
296 adapter
->temp_dcb_cfg
.tc_config
[priority
].dcb_pfc
= setting
;
297 if (adapter
->temp_dcb_cfg
.tc_config
[priority
].dcb_pfc
!=
298 adapter
->dcb_cfg
.tc_config
[priority
].dcb_pfc
) {
299 adapter
->dcb_set_bitmap
|= BIT_PFC
;
300 adapter
->temp_dcb_cfg
.pfc_mode_enable
= true;
304 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device
*netdev
, int priority
,
307 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
309 *setting
= adapter
->dcb_cfg
.tc_config
[priority
].dcb_pfc
;
312 static u8
ixgbe_dcbnl_set_all(struct net_device
*netdev
)
314 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
317 struct dcb_app app
= {
318 .selector
= DCB_APP_IDTYPE_ETHTYPE
,
319 .protocol
= ETH_P_FCOE
,
323 /* In IEEE mode, use the IEEE Ethertype selector value */
324 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
) {
325 app
.selector
= IEEE_8021QAZ_APP_SEL_ETHERTYPE
;
326 up
= dcb_ieee_getapp_mask(netdev
, &app
);
328 up
= dcb_getapp(netdev
, &app
);
332 /* Fail command if not in CEE mode */
333 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
336 ret
= ixgbe_copy_dcb_cfg(&adapter
->temp_dcb_cfg
, &adapter
->dcb_cfg
,
339 return DCB_NO_HW_CHG
;
342 if (up
&& !(up
& (1 << adapter
->fcoe
.up
)))
343 adapter
->dcb_set_bitmap
|= BIT_APP_UPCHG
;
346 * Only take down the adapter if an app change occurred. FCoE
347 * may shuffle tx rings in this case and this can not be done
348 * without a reset currently.
350 if (adapter
->dcb_set_bitmap
& BIT_APP_UPCHG
) {
351 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
352 usleep_range(1000, 2000);
354 adapter
->fcoe
.up
= ffs(up
) - 1;
356 if (netif_running(netdev
))
357 netdev
->netdev_ops
->ndo_stop(netdev
);
358 ixgbe_clear_interrupt_scheme(adapter
);
362 if (adapter
->dcb_cfg
.pfc_mode_enable
) {
363 switch (adapter
->hw
.mac
.type
) {
364 case ixgbe_mac_82599EB
:
366 if (adapter
->hw
.fc
.current_mode
!= ixgbe_fc_pfc
)
367 adapter
->last_lfc_mode
=
368 adapter
->hw
.fc
.current_mode
;
373 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_pfc
;
375 switch (adapter
->hw
.mac
.type
) {
376 case ixgbe_mac_82598EB
:
377 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_none
;
379 case ixgbe_mac_82599EB
:
381 adapter
->hw
.fc
.requested_mode
= adapter
->last_lfc_mode
;
389 if (adapter
->dcb_set_bitmap
& BIT_APP_UPCHG
) {
390 ixgbe_init_interrupt_scheme(adapter
);
391 if (netif_running(netdev
))
392 netdev
->netdev_ops
->ndo_open(netdev
);
393 ret
= DCB_HW_CHG_RST
;
397 if (adapter
->dcb_set_bitmap
& (BIT_PG_TX
|BIT_PG_RX
)) {
398 u16 refill
[MAX_TRAFFIC_CLASS
], max
[MAX_TRAFFIC_CLASS
];
399 u8 bwg_id
[MAX_TRAFFIC_CLASS
], prio_type
[MAX_TRAFFIC_CLASS
];
400 /* Priority to TC mapping in CEE case default to 1:1 */
401 u8 prio_tc
[MAX_USER_PRIORITY
];
402 int max_frame
= adapter
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
405 if (adapter
->netdev
->features
& NETIF_F_FCOE_MTU
)
406 max_frame
= max(max_frame
, IXGBE_FCOE_JUMBO_FRAME_SIZE
);
409 ixgbe_dcb_calculate_tc_credits(&adapter
->hw
, &adapter
->dcb_cfg
,
410 max_frame
, DCB_TX_CONFIG
);
411 ixgbe_dcb_calculate_tc_credits(&adapter
->hw
, &adapter
->dcb_cfg
,
412 max_frame
, DCB_RX_CONFIG
);
414 ixgbe_dcb_unpack_refill(&adapter
->dcb_cfg
,
415 DCB_TX_CONFIG
, refill
);
416 ixgbe_dcb_unpack_max(&adapter
->dcb_cfg
, max
);
417 ixgbe_dcb_unpack_bwgid(&adapter
->dcb_cfg
,
418 DCB_TX_CONFIG
, bwg_id
);
419 ixgbe_dcb_unpack_prio(&adapter
->dcb_cfg
,
420 DCB_TX_CONFIG
, prio_type
);
421 ixgbe_dcb_unpack_map(&adapter
->dcb_cfg
,
422 DCB_TX_CONFIG
, prio_tc
);
424 ixgbe_dcb_hw_ets_config(&adapter
->hw
, refill
, max
,
425 bwg_id
, prio_type
, prio_tc
);
427 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++)
428 netdev_set_prio_tc_map(netdev
, i
, prio_tc
[i
]);
431 if (adapter
->dcb_set_bitmap
& BIT_PFC
) {
433 u8 prio_tc
[MAX_USER_PRIORITY
];
435 ixgbe_dcb_unpack_map(&adapter
->dcb_cfg
,
436 DCB_TX_CONFIG
, prio_tc
);
437 ixgbe_dcb_unpack_pfc(&adapter
->dcb_cfg
, &pfc_en
);
438 ixgbe_dcb_hw_pfc_config(&adapter
->hw
, pfc_en
, prio_tc
);
442 if (adapter
->dcb_cfg
.pfc_mode_enable
)
443 adapter
->hw
.fc
.current_mode
= ixgbe_fc_pfc
;
445 if (adapter
->dcb_set_bitmap
& BIT_APP_UPCHG
)
446 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
447 adapter
->dcb_set_bitmap
= 0x00;
451 static u8
ixgbe_dcbnl_getcap(struct net_device
*netdev
, int capid
, u8
*cap
)
453 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
456 case DCB_CAP_ATTR_PG
:
459 case DCB_CAP_ATTR_PFC
:
462 case DCB_CAP_ATTR_UP2TC
:
465 case DCB_CAP_ATTR_PG_TCS
:
468 case DCB_CAP_ATTR_PFC_TCS
:
471 case DCB_CAP_ATTR_GSP
:
474 case DCB_CAP_ATTR_BCN
:
477 case DCB_CAP_ATTR_DCBX
:
478 *cap
= adapter
->dcbx_cap
;
488 static u8
ixgbe_dcbnl_getnumtcs(struct net_device
*netdev
, int tcid
, u8
*num
)
490 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
493 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
495 case DCB_NUMTCS_ATTR_PG
:
496 *num
= adapter
->dcb_cfg
.num_tcs
.pg_tcs
;
498 case DCB_NUMTCS_ATTR_PFC
:
499 *num
= adapter
->dcb_cfg
.num_tcs
.pfc_tcs
;
512 static u8
ixgbe_dcbnl_setnumtcs(struct net_device
*netdev
, int tcid
, u8 num
)
517 static u8
ixgbe_dcbnl_getpfcstate(struct net_device
*netdev
)
519 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
521 return adapter
->dcb_cfg
.pfc_mode_enable
;
524 static void ixgbe_dcbnl_setpfcstate(struct net_device
*netdev
, u8 state
)
526 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
528 adapter
->temp_dcb_cfg
.pfc_mode_enable
= state
;
529 if (adapter
->temp_dcb_cfg
.pfc_mode_enable
!=
530 adapter
->dcb_cfg
.pfc_mode_enable
)
531 adapter
->dcb_set_bitmap
|= BIT_PFC
;
535 * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
536 * @netdev : the corresponding netdev
537 * @idtype : identifies the id as ether type or TCP/UDP port number
538 * @id: id is either ether type or TCP/UDP port number
540 * Returns : on success, returns a non-zero 802.1p user priority bitmap
541 * otherwise returns 0 as the invalid user priority bitmap to indicate an
544 static u8
ixgbe_dcbnl_getapp(struct net_device
*netdev
, u8 idtype
, u16 id
)
546 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
547 struct dcb_app app
= {
552 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
555 return dcb_getapp(netdev
, &app
);
558 static int ixgbe_dcbnl_ieee_getets(struct net_device
*dev
,
559 struct ieee_ets
*ets
)
561 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
562 struct ieee_ets
*my_ets
= adapter
->ixgbe_ieee_ets
;
564 /* No IEEE PFC settings available */
568 ets
->ets_cap
= adapter
->dcb_cfg
.num_tcs
.pg_tcs
;
569 ets
->cbs
= my_ets
->cbs
;
570 memcpy(ets
->tc_tx_bw
, my_ets
->tc_tx_bw
, sizeof(ets
->tc_tx_bw
));
571 memcpy(ets
->tc_rx_bw
, my_ets
->tc_rx_bw
, sizeof(ets
->tc_rx_bw
));
572 memcpy(ets
->tc_tsa
, my_ets
->tc_tsa
, sizeof(ets
->tc_tsa
));
573 memcpy(ets
->prio_tc
, my_ets
->prio_tc
, sizeof(ets
->prio_tc
));
577 static int ixgbe_dcbnl_ieee_setets(struct net_device
*dev
,
578 struct ieee_ets
*ets
)
580 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
581 int max_frame
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
585 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
588 if (!adapter
->ixgbe_ieee_ets
) {
589 adapter
->ixgbe_ieee_ets
= kmalloc(sizeof(struct ieee_ets
),
591 if (!adapter
->ixgbe_ieee_ets
)
595 memcpy(adapter
->ixgbe_ieee_ets
, ets
, sizeof(*adapter
->ixgbe_ieee_ets
));
597 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++) {
598 if (ets
->prio_tc
[i
] > max_tc
)
599 max_tc
= ets
->prio_tc
[i
];
605 if (max_tc
> adapter
->dcb_cfg
.num_tcs
.pg_tcs
)
608 if (max_tc
!= netdev_get_num_tc(dev
))
609 ixgbe_setup_tc(dev
, max_tc
);
611 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++)
612 netdev_set_prio_tc_map(dev
, i
, ets
->prio_tc
[i
]);
614 return ixgbe_dcb_hw_ets(&adapter
->hw
, ets
, max_frame
);
617 static int ixgbe_dcbnl_ieee_getpfc(struct net_device
*dev
,
618 struct ieee_pfc
*pfc
)
620 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
621 struct ieee_pfc
*my_pfc
= adapter
->ixgbe_ieee_pfc
;
624 /* No IEEE PFC settings available */
628 pfc
->pfc_cap
= adapter
->dcb_cfg
.num_tcs
.pfc_tcs
;
629 pfc
->pfc_en
= my_pfc
->pfc_en
;
630 pfc
->mbc
= my_pfc
->mbc
;
631 pfc
->delay
= my_pfc
->delay
;
633 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
634 pfc
->requests
[i
] = adapter
->stats
.pxoffrxc
[i
];
635 pfc
->indications
[i
] = adapter
->stats
.pxofftxc
[i
];
641 static int ixgbe_dcbnl_ieee_setpfc(struct net_device
*dev
,
642 struct ieee_pfc
*pfc
)
644 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
647 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
650 if (!adapter
->ixgbe_ieee_pfc
) {
651 adapter
->ixgbe_ieee_pfc
= kmalloc(sizeof(struct ieee_pfc
),
653 if (!adapter
->ixgbe_ieee_pfc
)
657 prio_tc
= adapter
->ixgbe_ieee_ets
->prio_tc
;
658 memcpy(adapter
->ixgbe_ieee_pfc
, pfc
, sizeof(*adapter
->ixgbe_ieee_pfc
));
659 return ixgbe_dcb_hw_pfc_config(&adapter
->hw
, pfc
->pfc_en
, prio_tc
);
663 static void ixgbe_dcbnl_devreset(struct net_device
*dev
)
665 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
667 if (netif_running(dev
))
668 dev
->netdev_ops
->ndo_stop(dev
);
670 ixgbe_clear_interrupt_scheme(adapter
);
671 ixgbe_init_interrupt_scheme(adapter
);
673 if (netif_running(dev
))
674 dev
->netdev_ops
->ndo_open(dev
);
678 static int ixgbe_dcbnl_ieee_setapp(struct net_device
*dev
,
681 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
684 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
687 err
= dcb_ieee_setapp(dev
, app
);
690 if (!err
&& app
->selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
691 app
->protocol
== ETH_P_FCOE
) {
692 u8 app_mask
= dcb_ieee_getapp_mask(dev
, app
);
694 if (app_mask
& (1 << adapter
->fcoe
.up
))
697 adapter
->fcoe
.up
= app
->priority
;
698 ixgbe_dcbnl_devreset(dev
);
704 static int ixgbe_dcbnl_ieee_delapp(struct net_device
*dev
,
707 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
710 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
713 err
= dcb_ieee_delapp(dev
, app
);
716 if (!err
&& app
->selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
717 app
->protocol
== ETH_P_FCOE
) {
718 u8 app_mask
= dcb_ieee_getapp_mask(dev
, app
);
720 if (app_mask
& (1 << adapter
->fcoe
.up
))
723 adapter
->fcoe
.up
= app_mask
?
724 ffs(app_mask
) - 1 : IXGBE_FCOE_DEFTC
;
725 ixgbe_dcbnl_devreset(dev
);
731 static u8
ixgbe_dcbnl_getdcbx(struct net_device
*dev
)
733 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
734 return adapter
->dcbx_cap
;
737 static u8
ixgbe_dcbnl_setdcbx(struct net_device
*dev
, u8 mode
)
739 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
740 struct ieee_ets ets
= {0};
741 struct ieee_pfc pfc
= {0};
743 /* no support for LLD_MANAGED modes or CEE+IEEE */
744 if ((mode
& DCB_CAP_DCBX_LLD_MANAGED
) ||
745 ((mode
& DCB_CAP_DCBX_VER_IEEE
) && (mode
& DCB_CAP_DCBX_VER_CEE
)) ||
746 !(mode
& DCB_CAP_DCBX_HOST
))
749 if (mode
== adapter
->dcbx_cap
)
752 adapter
->dcbx_cap
= mode
;
754 /* ETS and PFC defaults */
758 if (mode
& DCB_CAP_DCBX_VER_IEEE
) {
759 ixgbe_dcbnl_ieee_setets(dev
, &ets
);
760 ixgbe_dcbnl_ieee_setpfc(dev
, &pfc
);
761 } else if (mode
& DCB_CAP_DCBX_VER_CEE
) {
762 adapter
->dcb_set_bitmap
|= (BIT_PFC
& BIT_PG_TX
& BIT_PG_RX
);
763 ixgbe_dcbnl_set_all(dev
);
765 /* Drop into single TC mode strict priority as this
766 * indicates CEE and IEEE versions are disabled
768 ixgbe_dcbnl_ieee_setets(dev
, &ets
);
769 ixgbe_dcbnl_ieee_setpfc(dev
, &pfc
);
770 ixgbe_setup_tc(dev
, 0);
776 const struct dcbnl_rtnl_ops dcbnl_ops
= {
777 .ieee_getets
= ixgbe_dcbnl_ieee_getets
,
778 .ieee_setets
= ixgbe_dcbnl_ieee_setets
,
779 .ieee_getpfc
= ixgbe_dcbnl_ieee_getpfc
,
780 .ieee_setpfc
= ixgbe_dcbnl_ieee_setpfc
,
781 .ieee_setapp
= ixgbe_dcbnl_ieee_setapp
,
782 .ieee_delapp
= ixgbe_dcbnl_ieee_delapp
,
783 .getstate
= ixgbe_dcbnl_get_state
,
784 .setstate
= ixgbe_dcbnl_set_state
,
785 .getpermhwaddr
= ixgbe_dcbnl_get_perm_hw_addr
,
786 .setpgtccfgtx
= ixgbe_dcbnl_set_pg_tc_cfg_tx
,
787 .setpgbwgcfgtx
= ixgbe_dcbnl_set_pg_bwg_cfg_tx
,
788 .setpgtccfgrx
= ixgbe_dcbnl_set_pg_tc_cfg_rx
,
789 .setpgbwgcfgrx
= ixgbe_dcbnl_set_pg_bwg_cfg_rx
,
790 .getpgtccfgtx
= ixgbe_dcbnl_get_pg_tc_cfg_tx
,
791 .getpgbwgcfgtx
= ixgbe_dcbnl_get_pg_bwg_cfg_tx
,
792 .getpgtccfgrx
= ixgbe_dcbnl_get_pg_tc_cfg_rx
,
793 .getpgbwgcfgrx
= ixgbe_dcbnl_get_pg_bwg_cfg_rx
,
794 .setpfccfg
= ixgbe_dcbnl_set_pfc_cfg
,
795 .getpfccfg
= ixgbe_dcbnl_get_pfc_cfg
,
796 .setall
= ixgbe_dcbnl_set_all
,
797 .getcap
= ixgbe_dcbnl_getcap
,
798 .getnumtcs
= ixgbe_dcbnl_getnumtcs
,
799 .setnumtcs
= ixgbe_dcbnl_setnumtcs
,
800 .getpfcstate
= ixgbe_dcbnl_getpfcstate
,
801 .setpfcstate
= ixgbe_dcbnl_setpfcstate
,
802 .getapp
= ixgbe_dcbnl_getapp
,
803 .getdcbx
= ixgbe_dcbnl_getdcbx
,
804 .setdcbx
= ixgbe_dcbnl_setdcbx
,