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);
134 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++)
135 netdev_set_prio_tc_map(netdev
, i
, prio_tc
[i
]);
140 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device
*netdev
,
143 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
146 memset(perm_addr
, 0xff, MAX_ADDR_LEN
);
148 for (i
= 0; i
< netdev
->addr_len
; i
++)
149 perm_addr
[i
] = adapter
->hw
.mac
.perm_addr
[i
];
151 switch (adapter
->hw
.mac
.type
) {
152 case ixgbe_mac_82599EB
:
154 for (j
= 0; j
< netdev
->addr_len
; j
++, i
++)
155 perm_addr
[i
] = adapter
->hw
.mac
.san_addr
[j
];
162 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device
*netdev
, int tc
,
163 u8 prio
, u8 bwg_id
, u8 bw_pct
,
166 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
168 if (prio
!= DCB_ATTR_VALUE_UNDEFINED
)
169 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].prio_type
= prio
;
170 if (bwg_id
!= DCB_ATTR_VALUE_UNDEFINED
)
171 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
= bwg_id
;
172 if (bw_pct
!= DCB_ATTR_VALUE_UNDEFINED
)
173 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
=
175 if (up_map
!= DCB_ATTR_VALUE_UNDEFINED
)
176 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
=
179 if ((adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].prio_type
!=
180 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].prio_type
) ||
181 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
!=
182 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
) ||
183 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
!=
184 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
) ||
185 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
!=
186 adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
))
187 adapter
->dcb_set_bitmap
|= BIT_PG_TX
;
189 if (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_PFC
| BIT_APP_UPCHG
;
194 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device
*netdev
, int bwg_id
,
197 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
199 adapter
->temp_dcb_cfg
.bw_percentage
[0][bwg_id
] = bw_pct
;
201 if (adapter
->temp_dcb_cfg
.bw_percentage
[0][bwg_id
] !=
202 adapter
->dcb_cfg
.bw_percentage
[0][bwg_id
])
203 adapter
->dcb_set_bitmap
|= BIT_PG_TX
;
206 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device
*netdev
, int tc
,
207 u8 prio
, u8 bwg_id
, u8 bw_pct
,
210 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
212 if (prio
!= DCB_ATTR_VALUE_UNDEFINED
)
213 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].prio_type
= prio
;
214 if (bwg_id
!= DCB_ATTR_VALUE_UNDEFINED
)
215 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
= bwg_id
;
216 if (bw_pct
!= DCB_ATTR_VALUE_UNDEFINED
)
217 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
=
219 if (up_map
!= DCB_ATTR_VALUE_UNDEFINED
)
220 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
=
223 if ((adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].prio_type
!=
224 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].prio_type
) ||
225 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
!=
226 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
) ||
227 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
!=
228 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
) ||
229 (adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
!=
230 adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
))
231 adapter
->dcb_set_bitmap
|= BIT_PG_RX
;
233 if (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_PFC
;
238 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device
*netdev
, int bwg_id
,
241 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
243 adapter
->temp_dcb_cfg
.bw_percentage
[1][bwg_id
] = bw_pct
;
245 if (adapter
->temp_dcb_cfg
.bw_percentage
[1][bwg_id
] !=
246 adapter
->dcb_cfg
.bw_percentage
[1][bwg_id
])
247 adapter
->dcb_set_bitmap
|= BIT_PG_RX
;
250 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device
*netdev
, int tc
,
251 u8
*prio
, u8
*bwg_id
, u8
*bw_pct
,
254 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
256 *prio
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].prio_type
;
257 *bwg_id
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
;
258 *bw_pct
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
;
259 *up_map
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
;
262 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device
*netdev
, int bwg_id
,
265 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
267 *bw_pct
= adapter
->dcb_cfg
.bw_percentage
[0][bwg_id
];
270 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device
*netdev
, int tc
,
271 u8
*prio
, u8
*bwg_id
, u8
*bw_pct
,
274 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
276 *prio
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].prio_type
;
277 *bwg_id
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
;
278 *bw_pct
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
;
279 *up_map
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
;
282 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device
*netdev
, int bwg_id
,
285 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
287 *bw_pct
= adapter
->dcb_cfg
.bw_percentage
[1][bwg_id
];
290 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device
*netdev
, int priority
,
293 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
295 adapter
->temp_dcb_cfg
.tc_config
[priority
].dcb_pfc
= setting
;
296 if (adapter
->temp_dcb_cfg
.tc_config
[priority
].dcb_pfc
!=
297 adapter
->dcb_cfg
.tc_config
[priority
].dcb_pfc
) {
298 adapter
->dcb_set_bitmap
|= BIT_PFC
;
299 adapter
->temp_dcb_cfg
.pfc_mode_enable
= true;
303 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device
*netdev
, int priority
,
306 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
308 *setting
= adapter
->dcb_cfg
.tc_config
[priority
].dcb_pfc
;
312 static void ixgbe_dcbnl_devreset(struct net_device
*dev
)
314 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
316 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
317 usleep_range(1000, 2000);
319 if (netif_running(dev
))
320 dev
->netdev_ops
->ndo_stop(dev
);
322 ixgbe_clear_interrupt_scheme(adapter
);
323 ixgbe_init_interrupt_scheme(adapter
);
325 if (netif_running(dev
))
326 dev
->netdev_ops
->ndo_open(dev
);
328 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
332 static u8
ixgbe_dcbnl_set_all(struct net_device
*netdev
)
334 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
337 struct dcb_app app
= {
338 .selector
= DCB_APP_IDTYPE_ETHTYPE
,
339 .protocol
= ETH_P_FCOE
,
343 /* In IEEE mode, use the IEEE Ethertype selector value */
344 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
) {
345 app
.selector
= IEEE_8021QAZ_APP_SEL_ETHERTYPE
;
346 up
= dcb_ieee_getapp_mask(netdev
, &app
);
348 up
= dcb_getapp(netdev
, &app
);
352 /* Fail command if not in CEE mode */
353 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
356 ret
= ixgbe_copy_dcb_cfg(&adapter
->temp_dcb_cfg
, &adapter
->dcb_cfg
,
359 return DCB_NO_HW_CHG
;
361 if (adapter
->dcb_cfg
.pfc_mode_enable
) {
362 switch (adapter
->hw
.mac
.type
) {
363 case ixgbe_mac_82599EB
:
365 if (adapter
->hw
.fc
.current_mode
!= ixgbe_fc_pfc
)
366 adapter
->last_lfc_mode
=
367 adapter
->hw
.fc
.current_mode
;
372 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_pfc
;
374 switch (adapter
->hw
.mac
.type
) {
375 case ixgbe_mac_82598EB
:
376 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_none
;
378 case ixgbe_mac_82599EB
:
380 adapter
->hw
.fc
.requested_mode
= adapter
->last_lfc_mode
;
387 if (adapter
->dcb_set_bitmap
& (BIT_PG_TX
|BIT_PG_RX
)) {
388 u16 refill
[MAX_TRAFFIC_CLASS
], max
[MAX_TRAFFIC_CLASS
];
389 u8 bwg_id
[MAX_TRAFFIC_CLASS
], prio_type
[MAX_TRAFFIC_CLASS
];
390 /* Priority to TC mapping in CEE case default to 1:1 */
391 u8 prio_tc
[MAX_USER_PRIORITY
];
392 int max_frame
= adapter
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
395 if (adapter
->netdev
->features
& NETIF_F_FCOE_MTU
)
396 max_frame
= max(max_frame
, IXGBE_FCOE_JUMBO_FRAME_SIZE
);
399 ixgbe_dcb_calculate_tc_credits(&adapter
->hw
, &adapter
->dcb_cfg
,
400 max_frame
, DCB_TX_CONFIG
);
401 ixgbe_dcb_calculate_tc_credits(&adapter
->hw
, &adapter
->dcb_cfg
,
402 max_frame
, DCB_RX_CONFIG
);
404 ixgbe_dcb_unpack_refill(&adapter
->dcb_cfg
,
405 DCB_TX_CONFIG
, refill
);
406 ixgbe_dcb_unpack_max(&adapter
->dcb_cfg
, max
);
407 ixgbe_dcb_unpack_bwgid(&adapter
->dcb_cfg
,
408 DCB_TX_CONFIG
, bwg_id
);
409 ixgbe_dcb_unpack_prio(&adapter
->dcb_cfg
,
410 DCB_TX_CONFIG
, prio_type
);
411 ixgbe_dcb_unpack_map(&adapter
->dcb_cfg
,
412 DCB_TX_CONFIG
, prio_tc
);
414 ixgbe_dcb_hw_ets_config(&adapter
->hw
, refill
, max
,
415 bwg_id
, prio_type
, prio_tc
);
417 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++)
418 netdev_set_prio_tc_map(netdev
, i
, prio_tc
[i
]);
421 if (adapter
->dcb_set_bitmap
& BIT_PFC
) {
423 u8 prio_tc
[MAX_USER_PRIORITY
];
425 ixgbe_dcb_unpack_map(&adapter
->dcb_cfg
,
426 DCB_TX_CONFIG
, prio_tc
);
427 ixgbe_dcb_unpack_pfc(&adapter
->dcb_cfg
, &pfc_en
);
428 ixgbe_dcb_hw_pfc_config(&adapter
->hw
, pfc_en
, prio_tc
);
432 if (adapter
->dcb_cfg
.pfc_mode_enable
)
433 adapter
->hw
.fc
.current_mode
= ixgbe_fc_pfc
;
436 /* Reprogam FCoE hardware offloads when the traffic class
437 * FCoE is using changes. This happens if the APP info
438 * changes or the up2tc mapping is updated.
440 if ((up
&& !(up
& (1 << adapter
->fcoe
.up
))) ||
441 (adapter
->dcb_set_bitmap
& BIT_APP_UPCHG
)) {
442 adapter
->fcoe
.up
= ffs(up
) - 1;
443 ixgbe_dcbnl_devreset(netdev
);
444 ret
= DCB_HW_CHG_RST
;
448 adapter
->dcb_set_bitmap
= 0x00;
452 static u8
ixgbe_dcbnl_getcap(struct net_device
*netdev
, int capid
, u8
*cap
)
454 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
457 case DCB_CAP_ATTR_PG
:
460 case DCB_CAP_ATTR_PFC
:
463 case DCB_CAP_ATTR_UP2TC
:
466 case DCB_CAP_ATTR_PG_TCS
:
469 case DCB_CAP_ATTR_PFC_TCS
:
472 case DCB_CAP_ATTR_GSP
:
475 case DCB_CAP_ATTR_BCN
:
478 case DCB_CAP_ATTR_DCBX
:
479 *cap
= adapter
->dcbx_cap
;
489 static u8
ixgbe_dcbnl_getnumtcs(struct net_device
*netdev
, int tcid
, u8
*num
)
491 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
494 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
496 case DCB_NUMTCS_ATTR_PG
:
497 *num
= adapter
->dcb_cfg
.num_tcs
.pg_tcs
;
499 case DCB_NUMTCS_ATTR_PFC
:
500 *num
= adapter
->dcb_cfg
.num_tcs
.pfc_tcs
;
513 static u8
ixgbe_dcbnl_setnumtcs(struct net_device
*netdev
, int tcid
, u8 num
)
518 static u8
ixgbe_dcbnl_getpfcstate(struct net_device
*netdev
)
520 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
522 return adapter
->dcb_cfg
.pfc_mode_enable
;
525 static void ixgbe_dcbnl_setpfcstate(struct net_device
*netdev
, u8 state
)
527 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
529 adapter
->temp_dcb_cfg
.pfc_mode_enable
= state
;
530 if (adapter
->temp_dcb_cfg
.pfc_mode_enable
!=
531 adapter
->dcb_cfg
.pfc_mode_enable
)
532 adapter
->dcb_set_bitmap
|= BIT_PFC
;
536 * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
537 * @netdev : the corresponding netdev
538 * @idtype : identifies the id as ether type or TCP/UDP port number
539 * @id: id is either ether type or TCP/UDP port number
541 * Returns : on success, returns a non-zero 802.1p user priority bitmap
542 * otherwise returns 0 as the invalid user priority bitmap to indicate an
545 static u8
ixgbe_dcbnl_getapp(struct net_device
*netdev
, u8 idtype
, u16 id
)
547 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
548 struct dcb_app app
= {
553 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
556 return dcb_getapp(netdev
, &app
);
559 static int ixgbe_dcbnl_ieee_getets(struct net_device
*dev
,
560 struct ieee_ets
*ets
)
562 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
563 struct ieee_ets
*my_ets
= adapter
->ixgbe_ieee_ets
;
565 ets
->ets_cap
= adapter
->dcb_cfg
.num_tcs
.pg_tcs
;
567 /* No IEEE PFC settings available */
571 ets
->cbs
= my_ets
->cbs
;
572 memcpy(ets
->tc_tx_bw
, my_ets
->tc_tx_bw
, sizeof(ets
->tc_tx_bw
));
573 memcpy(ets
->tc_rx_bw
, my_ets
->tc_rx_bw
, sizeof(ets
->tc_rx_bw
));
574 memcpy(ets
->tc_tsa
, my_ets
->tc_tsa
, sizeof(ets
->tc_tsa
));
575 memcpy(ets
->prio_tc
, my_ets
->prio_tc
, sizeof(ets
->prio_tc
));
579 static int ixgbe_dcbnl_ieee_setets(struct net_device
*dev
,
580 struct ieee_ets
*ets
)
582 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
583 int max_frame
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
587 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
590 if (!adapter
->ixgbe_ieee_ets
) {
591 adapter
->ixgbe_ieee_ets
= kmalloc(sizeof(struct ieee_ets
),
593 if (!adapter
->ixgbe_ieee_ets
)
597 memcpy(adapter
->ixgbe_ieee_ets
, ets
, sizeof(*adapter
->ixgbe_ieee_ets
));
599 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++) {
600 if (ets
->prio_tc
[i
] > max_tc
)
601 max_tc
= ets
->prio_tc
[i
];
607 if (max_tc
> adapter
->dcb_cfg
.num_tcs
.pg_tcs
)
610 if (max_tc
!= netdev_get_num_tc(dev
))
611 ixgbe_setup_tc(dev
, max_tc
);
613 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++)
614 netdev_set_prio_tc_map(dev
, i
, ets
->prio_tc
[i
]);
616 return ixgbe_dcb_hw_ets(&adapter
->hw
, ets
, max_frame
);
619 static int ixgbe_dcbnl_ieee_getpfc(struct net_device
*dev
,
620 struct ieee_pfc
*pfc
)
622 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
623 struct ieee_pfc
*my_pfc
= adapter
->ixgbe_ieee_pfc
;
626 pfc
->pfc_cap
= adapter
->dcb_cfg
.num_tcs
.pfc_tcs
;
628 /* No IEEE PFC settings available */
632 pfc
->pfc_en
= my_pfc
->pfc_en
;
633 pfc
->mbc
= my_pfc
->mbc
;
634 pfc
->delay
= my_pfc
->delay
;
636 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
637 pfc
->requests
[i
] = adapter
->stats
.pxoffrxc
[i
];
638 pfc
->indications
[i
] = adapter
->stats
.pxofftxc
[i
];
644 static int ixgbe_dcbnl_ieee_setpfc(struct net_device
*dev
,
645 struct ieee_pfc
*pfc
)
647 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
650 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
653 if (!adapter
->ixgbe_ieee_pfc
) {
654 adapter
->ixgbe_ieee_pfc
= kmalloc(sizeof(struct ieee_pfc
),
656 if (!adapter
->ixgbe_ieee_pfc
)
660 prio_tc
= adapter
->ixgbe_ieee_ets
->prio_tc
;
661 memcpy(adapter
->ixgbe_ieee_pfc
, pfc
, sizeof(*adapter
->ixgbe_ieee_pfc
));
662 return ixgbe_dcb_hw_pfc_config(&adapter
->hw
, pfc
->pfc_en
, prio_tc
);
665 static int ixgbe_dcbnl_ieee_setapp(struct net_device
*dev
,
668 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
671 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
674 err
= dcb_ieee_setapp(dev
, app
);
677 if (!err
&& app
->selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
678 app
->protocol
== ETH_P_FCOE
) {
679 u8 app_mask
= dcb_ieee_getapp_mask(dev
, app
);
681 if (app_mask
& (1 << adapter
->fcoe
.up
))
684 adapter
->fcoe
.up
= app
->priority
;
685 ixgbe_dcbnl_devreset(dev
);
691 static int ixgbe_dcbnl_ieee_delapp(struct net_device
*dev
,
694 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
697 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
700 err
= dcb_ieee_delapp(dev
, app
);
703 if (!err
&& app
->selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
704 app
->protocol
== ETH_P_FCOE
) {
705 u8 app_mask
= dcb_ieee_getapp_mask(dev
, app
);
707 if (app_mask
& (1 << adapter
->fcoe
.up
))
710 adapter
->fcoe
.up
= app_mask
?
711 ffs(app_mask
) - 1 : IXGBE_FCOE_DEFTC
;
712 ixgbe_dcbnl_devreset(dev
);
718 static u8
ixgbe_dcbnl_getdcbx(struct net_device
*dev
)
720 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
721 return adapter
->dcbx_cap
;
724 static u8
ixgbe_dcbnl_setdcbx(struct net_device
*dev
, u8 mode
)
726 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
727 struct ieee_ets ets
= {0};
728 struct ieee_pfc pfc
= {0};
730 /* no support for LLD_MANAGED modes or CEE+IEEE */
731 if ((mode
& DCB_CAP_DCBX_LLD_MANAGED
) ||
732 ((mode
& DCB_CAP_DCBX_VER_IEEE
) && (mode
& DCB_CAP_DCBX_VER_CEE
)) ||
733 !(mode
& DCB_CAP_DCBX_HOST
))
736 if (mode
== adapter
->dcbx_cap
)
739 adapter
->dcbx_cap
= mode
;
741 /* ETS and PFC defaults */
745 if (mode
& DCB_CAP_DCBX_VER_IEEE
) {
746 ixgbe_dcbnl_ieee_setets(dev
, &ets
);
747 ixgbe_dcbnl_ieee_setpfc(dev
, &pfc
);
748 } else if (mode
& DCB_CAP_DCBX_VER_CEE
) {
749 u8 mask
= BIT_PFC
| BIT_PG_TX
| BIT_PG_RX
| BIT_APP_UPCHG
;
751 adapter
->dcb_set_bitmap
|= mask
;
752 ixgbe_dcbnl_set_all(dev
);
754 /* Drop into single TC mode strict priority as this
755 * indicates CEE and IEEE versions are disabled
757 ixgbe_dcbnl_ieee_setets(dev
, &ets
);
758 ixgbe_dcbnl_ieee_setpfc(dev
, &pfc
);
759 ixgbe_setup_tc(dev
, 0);
765 const struct dcbnl_rtnl_ops dcbnl_ops
= {
766 .ieee_getets
= ixgbe_dcbnl_ieee_getets
,
767 .ieee_setets
= ixgbe_dcbnl_ieee_setets
,
768 .ieee_getpfc
= ixgbe_dcbnl_ieee_getpfc
,
769 .ieee_setpfc
= ixgbe_dcbnl_ieee_setpfc
,
770 .ieee_setapp
= ixgbe_dcbnl_ieee_setapp
,
771 .ieee_delapp
= ixgbe_dcbnl_ieee_delapp
,
772 .getstate
= ixgbe_dcbnl_get_state
,
773 .setstate
= ixgbe_dcbnl_set_state
,
774 .getpermhwaddr
= ixgbe_dcbnl_get_perm_hw_addr
,
775 .setpgtccfgtx
= ixgbe_dcbnl_set_pg_tc_cfg_tx
,
776 .setpgbwgcfgtx
= ixgbe_dcbnl_set_pg_bwg_cfg_tx
,
777 .setpgtccfgrx
= ixgbe_dcbnl_set_pg_tc_cfg_rx
,
778 .setpgbwgcfgrx
= ixgbe_dcbnl_set_pg_bwg_cfg_rx
,
779 .getpgtccfgtx
= ixgbe_dcbnl_get_pg_tc_cfg_tx
,
780 .getpgbwgcfgtx
= ixgbe_dcbnl_get_pg_bwg_cfg_tx
,
781 .getpgtccfgrx
= ixgbe_dcbnl_get_pg_tc_cfg_rx
,
782 .getpgbwgcfgrx
= ixgbe_dcbnl_get_pg_bwg_cfg_rx
,
783 .setpfccfg
= ixgbe_dcbnl_set_pfc_cfg
,
784 .getpfccfg
= ixgbe_dcbnl_get_pfc_cfg
,
785 .setall
= ixgbe_dcbnl_set_all
,
786 .getcap
= ixgbe_dcbnl_getcap
,
787 .getnumtcs
= ixgbe_dcbnl_getnumtcs
,
788 .setnumtcs
= ixgbe_dcbnl_setnumtcs
,
789 .getpfcstate
= ixgbe_dcbnl_getpfcstate
,
790 .setpfcstate
= ixgbe_dcbnl_setpfcstate
,
791 .getapp
= ixgbe_dcbnl_getapp
,
792 .getdcbx
= ixgbe_dcbnl_getdcbx
,
793 .setdcbx
= ixgbe_dcbnl_setdcbx
,