1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2013 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"
33 #include "ixgbe_sriov.h"
35 /* Callbacks for DCB netlink in the kernel */
36 #define BIT_DCB_MODE 0x01
38 #define BIT_PG_RX 0x04
39 #define BIT_PG_TX 0x08
40 #define BIT_APP_UPCHG 0x10
41 #define BIT_LINKSPEED 0x80
43 /* Responses for the DCB_C_SET_ALL command */
44 #define DCB_HW_CHG_RST 0 /* DCB configuration changed with reset */
45 #define DCB_NO_HW_CHG 1 /* DCB configuration did not change */
46 #define DCB_HW_CHG 2 /* DCB configuration changed, no reset */
48 static int ixgbe_copy_dcb_cfg(struct ixgbe_adapter
*adapter
, int tc_max
)
50 struct ixgbe_dcb_config
*scfg
= &adapter
->temp_dcb_cfg
;
51 struct ixgbe_dcb_config
*dcfg
= &adapter
->dcb_cfg
;
52 struct tc_configuration
*src
= NULL
;
53 struct tc_configuration
*dst
= NULL
;
55 int tx
= DCB_TX_CONFIG
;
56 int rx
= DCB_RX_CONFIG
;
59 struct dcb_app app
= {
60 .selector
= DCB_APP_IDTYPE_ETHTYPE
,
61 .protocol
= ETH_P_FCOE
,
63 u8 up
= dcb_getapp(adapter
->netdev
, &app
);
65 if (up
&& !(up
& (1 << adapter
->fcoe
.up
)))
66 changes
|= BIT_APP_UPCHG
;
69 for (i
= DCB_PG_ATTR_TC_0
; i
< tc_max
+ DCB_PG_ATTR_TC_0
; i
++) {
70 src
= &scfg
->tc_config
[i
- DCB_PG_ATTR_TC_0
];
71 dst
= &dcfg
->tc_config
[i
- DCB_PG_ATTR_TC_0
];
73 if (dst
->path
[tx
].prio_type
!= src
->path
[tx
].prio_type
) {
74 dst
->path
[tx
].prio_type
= src
->path
[tx
].prio_type
;
78 if (dst
->path
[tx
].bwg_id
!= src
->path
[tx
].bwg_id
) {
79 dst
->path
[tx
].bwg_id
= src
->path
[tx
].bwg_id
;
83 if (dst
->path
[tx
].bwg_percent
!= src
->path
[tx
].bwg_percent
) {
84 dst
->path
[tx
].bwg_percent
= src
->path
[tx
].bwg_percent
;
88 if (dst
->path
[tx
].up_to_tc_bitmap
!=
89 src
->path
[tx
].up_to_tc_bitmap
) {
90 dst
->path
[tx
].up_to_tc_bitmap
=
91 src
->path
[tx
].up_to_tc_bitmap
;
92 changes
|= (BIT_PG_TX
| BIT_PFC
| BIT_APP_UPCHG
);
95 if (dst
->path
[rx
].prio_type
!= src
->path
[rx
].prio_type
) {
96 dst
->path
[rx
].prio_type
= src
->path
[rx
].prio_type
;
100 if (dst
->path
[rx
].bwg_id
!= src
->path
[rx
].bwg_id
) {
101 dst
->path
[rx
].bwg_id
= src
->path
[rx
].bwg_id
;
102 changes
|= BIT_PG_RX
;
105 if (dst
->path
[rx
].bwg_percent
!= src
->path
[rx
].bwg_percent
) {
106 dst
->path
[rx
].bwg_percent
= src
->path
[rx
].bwg_percent
;
107 changes
|= BIT_PG_RX
;
110 if (dst
->path
[rx
].up_to_tc_bitmap
!=
111 src
->path
[rx
].up_to_tc_bitmap
) {
112 dst
->path
[rx
].up_to_tc_bitmap
=
113 src
->path
[rx
].up_to_tc_bitmap
;
114 changes
|= (BIT_PG_RX
| BIT_PFC
| BIT_APP_UPCHG
);
118 for (i
= DCB_PG_ATTR_BW_ID_0
; i
< DCB_PG_ATTR_BW_ID_MAX
; i
++) {
119 j
= i
- DCB_PG_ATTR_BW_ID_0
;
120 if (dcfg
->bw_percentage
[tx
][j
] != scfg
->bw_percentage
[tx
][j
]) {
121 dcfg
->bw_percentage
[tx
][j
] = scfg
->bw_percentage
[tx
][j
];
122 changes
|= BIT_PG_TX
;
124 if (dcfg
->bw_percentage
[rx
][j
] != scfg
->bw_percentage
[rx
][j
]) {
125 dcfg
->bw_percentage
[rx
][j
] = scfg
->bw_percentage
[rx
][j
];
126 changes
|= BIT_PG_RX
;
130 for (i
= DCB_PFC_UP_ATTR_0
; i
< DCB_PFC_UP_ATTR_MAX
; i
++) {
131 j
= i
- DCB_PFC_UP_ATTR_0
;
132 if (dcfg
->tc_config
[j
].dcb_pfc
!= scfg
->tc_config
[j
].dcb_pfc
) {
133 dcfg
->tc_config
[j
].dcb_pfc
= scfg
->tc_config
[j
].dcb_pfc
;
138 if (dcfg
->pfc_mode_enable
!= scfg
->pfc_mode_enable
) {
139 dcfg
->pfc_mode_enable
= scfg
->pfc_mode_enable
;
146 static u8
ixgbe_dcbnl_get_state(struct net_device
*netdev
)
148 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
150 return !!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
);
153 static u8
ixgbe_dcbnl_set_state(struct net_device
*netdev
, u8 state
)
155 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
158 /* Fail command if not in CEE mode */
159 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
162 /* verify there is something to do, if not then exit */
163 if (!state
== !(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
))
166 err
= ixgbe_setup_tc(netdev
,
167 state
? adapter
->dcb_cfg
.num_tcs
.pg_tcs
: 0);
172 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device
*netdev
,
175 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
178 memset(perm_addr
, 0xff, MAX_ADDR_LEN
);
180 for (i
= 0; i
< netdev
->addr_len
; i
++)
181 perm_addr
[i
] = adapter
->hw
.mac
.perm_addr
[i
];
183 switch (adapter
->hw
.mac
.type
) {
184 case ixgbe_mac_82599EB
:
186 for (j
= 0; j
< netdev
->addr_len
; j
++, i
++)
187 perm_addr
[i
] = adapter
->hw
.mac
.san_addr
[j
];
194 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device
*netdev
, int tc
,
195 u8 prio
, u8 bwg_id
, u8 bw_pct
,
198 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
200 if (prio
!= DCB_ATTR_VALUE_UNDEFINED
)
201 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].prio_type
= prio
;
202 if (bwg_id
!= DCB_ATTR_VALUE_UNDEFINED
)
203 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
= bwg_id
;
204 if (bw_pct
!= DCB_ATTR_VALUE_UNDEFINED
)
205 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
=
207 if (up_map
!= DCB_ATTR_VALUE_UNDEFINED
)
208 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
=
212 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device
*netdev
, int bwg_id
,
215 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
217 adapter
->temp_dcb_cfg
.bw_percentage
[0][bwg_id
] = bw_pct
;
220 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device
*netdev
, int tc
,
221 u8 prio
, u8 bwg_id
, u8 bw_pct
,
224 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
226 if (prio
!= DCB_ATTR_VALUE_UNDEFINED
)
227 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].prio_type
= prio
;
228 if (bwg_id
!= DCB_ATTR_VALUE_UNDEFINED
)
229 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
= bwg_id
;
230 if (bw_pct
!= DCB_ATTR_VALUE_UNDEFINED
)
231 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
=
233 if (up_map
!= DCB_ATTR_VALUE_UNDEFINED
)
234 adapter
->temp_dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
=
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
;
246 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device
*netdev
, int tc
,
247 u8
*prio
, u8
*bwg_id
, u8
*bw_pct
,
250 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
252 *prio
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].prio_type
;
253 *bwg_id
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_id
;
254 *bw_pct
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].bwg_percent
;
255 *up_map
= adapter
->dcb_cfg
.tc_config
[tc
].path
[0].up_to_tc_bitmap
;
258 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device
*netdev
, int bwg_id
,
261 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
263 *bw_pct
= adapter
->dcb_cfg
.bw_percentage
[0][bwg_id
];
266 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device
*netdev
, int tc
,
267 u8
*prio
, u8
*bwg_id
, u8
*bw_pct
,
270 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
272 *prio
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].prio_type
;
273 *bwg_id
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_id
;
274 *bw_pct
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].bwg_percent
;
275 *up_map
= adapter
->dcb_cfg
.tc_config
[tc
].path
[1].up_to_tc_bitmap
;
278 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device
*netdev
, int bwg_id
,
281 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
283 *bw_pct
= adapter
->dcb_cfg
.bw_percentage
[1][bwg_id
];
286 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device
*netdev
, int priority
,
289 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
291 adapter
->temp_dcb_cfg
.tc_config
[priority
].dcb_pfc
= setting
;
292 if (adapter
->temp_dcb_cfg
.tc_config
[priority
].dcb_pfc
!=
293 adapter
->dcb_cfg
.tc_config
[priority
].dcb_pfc
)
294 adapter
->temp_dcb_cfg
.pfc_mode_enable
= true;
297 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device
*netdev
, int priority
,
300 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
302 *setting
= adapter
->dcb_cfg
.tc_config
[priority
].dcb_pfc
;
305 static void ixgbe_dcbnl_devreset(struct net_device
*dev
)
307 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
309 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
310 usleep_range(1000, 2000);
312 if (netif_running(dev
))
313 dev
->netdev_ops
->ndo_stop(dev
);
315 ixgbe_clear_interrupt_scheme(adapter
);
316 ixgbe_init_interrupt_scheme(adapter
);
318 if (netif_running(dev
))
319 dev
->netdev_ops
->ndo_open(dev
);
321 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
324 static u8
ixgbe_dcbnl_set_all(struct net_device
*netdev
)
326 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
327 struct ixgbe_dcb_config
*dcb_cfg
= &adapter
->dcb_cfg
;
328 struct ixgbe_hw
*hw
= &adapter
->hw
;
329 int ret
= DCB_NO_HW_CHG
;
332 /* Fail command if not in CEE mode */
333 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
336 adapter
->dcb_set_bitmap
|= ixgbe_copy_dcb_cfg(adapter
,
338 if (!adapter
->dcb_set_bitmap
)
341 if (adapter
->dcb_set_bitmap
& (BIT_PG_TX
|BIT_PG_RX
)) {
342 u16 refill
[MAX_TRAFFIC_CLASS
], max
[MAX_TRAFFIC_CLASS
];
343 u8 bwg_id
[MAX_TRAFFIC_CLASS
], prio_type
[MAX_TRAFFIC_CLASS
];
344 /* Priority to TC mapping in CEE case default to 1:1 */
345 u8 prio_tc
[MAX_USER_PRIORITY
];
346 int max_frame
= adapter
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
349 if (adapter
->netdev
->features
& NETIF_F_FCOE_MTU
)
350 max_frame
= max(max_frame
, IXGBE_FCOE_JUMBO_FRAME_SIZE
);
353 ixgbe_dcb_calculate_tc_credits(hw
, dcb_cfg
, max_frame
,
355 ixgbe_dcb_calculate_tc_credits(hw
, dcb_cfg
, max_frame
,
358 ixgbe_dcb_unpack_refill(dcb_cfg
, DCB_TX_CONFIG
, refill
);
359 ixgbe_dcb_unpack_max(dcb_cfg
, max
);
360 ixgbe_dcb_unpack_bwgid(dcb_cfg
, DCB_TX_CONFIG
, bwg_id
);
361 ixgbe_dcb_unpack_prio(dcb_cfg
, DCB_TX_CONFIG
, prio_type
);
362 ixgbe_dcb_unpack_map(dcb_cfg
, DCB_TX_CONFIG
, prio_tc
);
364 ixgbe_dcb_hw_ets_config(hw
, refill
, max
, bwg_id
,
367 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++)
368 netdev_set_prio_tc_map(netdev
, i
, prio_tc
[i
]);
370 ret
= DCB_HW_CHG_RST
;
373 if (adapter
->dcb_set_bitmap
& BIT_PFC
) {
374 if (dcb_cfg
->pfc_mode_enable
) {
376 u8 prio_tc
[MAX_USER_PRIORITY
];
378 ixgbe_dcb_unpack_map(dcb_cfg
, DCB_TX_CONFIG
, prio_tc
);
379 ixgbe_dcb_unpack_pfc(dcb_cfg
, &pfc_en
);
380 ixgbe_dcb_hw_pfc_config(hw
, pfc_en
, prio_tc
);
382 hw
->mac
.ops
.fc_enable(hw
);
385 ixgbe_set_rx_drop_en(adapter
);
391 /* Reprogam FCoE hardware offloads when the traffic class
392 * FCoE is using changes. This happens if the APP info
393 * changes or the up2tc mapping is updated.
395 if (adapter
->dcb_set_bitmap
& BIT_APP_UPCHG
) {
396 struct dcb_app app
= {
397 .selector
= DCB_APP_IDTYPE_ETHTYPE
,
398 .protocol
= ETH_P_FCOE
,
400 u8 up
= dcb_getapp(netdev
, &app
);
402 adapter
->fcoe
.up
= ffs(up
) - 1;
403 ixgbe_dcbnl_devreset(netdev
);
404 ret
= DCB_HW_CHG_RST
;
408 adapter
->dcb_set_bitmap
= 0x00;
412 static u8
ixgbe_dcbnl_getcap(struct net_device
*netdev
, int capid
, u8
*cap
)
414 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
417 case DCB_CAP_ATTR_PG
:
420 case DCB_CAP_ATTR_PFC
:
423 case DCB_CAP_ATTR_UP2TC
:
426 case DCB_CAP_ATTR_PG_TCS
:
429 case DCB_CAP_ATTR_PFC_TCS
:
432 case DCB_CAP_ATTR_GSP
:
435 case DCB_CAP_ATTR_BCN
:
438 case DCB_CAP_ATTR_DCBX
:
439 *cap
= adapter
->dcbx_cap
;
449 static int ixgbe_dcbnl_getnumtcs(struct net_device
*netdev
, int tcid
, u8
*num
)
451 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
453 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
455 case DCB_NUMTCS_ATTR_PG
:
456 *num
= adapter
->dcb_cfg
.num_tcs
.pg_tcs
;
458 case DCB_NUMTCS_ATTR_PFC
:
459 *num
= adapter
->dcb_cfg
.num_tcs
.pfc_tcs
;
472 static int ixgbe_dcbnl_setnumtcs(struct net_device
*netdev
, int tcid
, u8 num
)
477 static u8
ixgbe_dcbnl_getpfcstate(struct net_device
*netdev
)
479 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
481 return adapter
->dcb_cfg
.pfc_mode_enable
;
484 static void ixgbe_dcbnl_setpfcstate(struct net_device
*netdev
, u8 state
)
486 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
488 adapter
->temp_dcb_cfg
.pfc_mode_enable
= state
;
492 * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
493 * @netdev : the corresponding netdev
494 * @idtype : identifies the id as ether type or TCP/UDP port number
495 * @id: id is either ether type or TCP/UDP port number
497 * Returns : on success, returns a non-zero 802.1p user priority bitmap
498 * otherwise returns 0 as the invalid user priority bitmap to indicate an
501 static u8
ixgbe_dcbnl_getapp(struct net_device
*netdev
, u8 idtype
, u16 id
)
503 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
504 struct dcb_app app
= {
509 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
))
512 return dcb_getapp(netdev
, &app
);
515 static int ixgbe_dcbnl_ieee_getets(struct net_device
*dev
,
516 struct ieee_ets
*ets
)
518 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
519 struct ieee_ets
*my_ets
= adapter
->ixgbe_ieee_ets
;
521 ets
->ets_cap
= adapter
->dcb_cfg
.num_tcs
.pg_tcs
;
523 /* No IEEE PFC settings available */
527 ets
->cbs
= my_ets
->cbs
;
528 memcpy(ets
->tc_tx_bw
, my_ets
->tc_tx_bw
, sizeof(ets
->tc_tx_bw
));
529 memcpy(ets
->tc_rx_bw
, my_ets
->tc_rx_bw
, sizeof(ets
->tc_rx_bw
));
530 memcpy(ets
->tc_tsa
, my_ets
->tc_tsa
, sizeof(ets
->tc_tsa
));
531 memcpy(ets
->prio_tc
, my_ets
->prio_tc
, sizeof(ets
->prio_tc
));
535 static int ixgbe_dcbnl_ieee_setets(struct net_device
*dev
,
536 struct ieee_ets
*ets
)
538 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
539 int max_frame
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
544 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
547 if (!adapter
->ixgbe_ieee_ets
) {
548 adapter
->ixgbe_ieee_ets
= kmalloc(sizeof(struct ieee_ets
),
550 if (!adapter
->ixgbe_ieee_ets
)
553 /* initialize UP2TC mappings to invalid value */
554 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++)
555 adapter
->ixgbe_ieee_ets
->prio_tc
[i
] =
556 IEEE_8021QAZ_MAX_TCS
;
557 /* if possible update UP2TC mappings from HW */
558 ixgbe_dcb_read_rtrup2tc(&adapter
->hw
,
559 adapter
->ixgbe_ieee_ets
->prio_tc
);
562 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++) {
563 if (ets
->prio_tc
[i
] > max_tc
)
564 max_tc
= ets
->prio_tc
[i
];
565 if (ets
->prio_tc
[i
] != adapter
->ixgbe_ieee_ets
->prio_tc
[i
])
569 memcpy(adapter
->ixgbe_ieee_ets
, ets
, sizeof(*adapter
->ixgbe_ieee_ets
));
574 if (max_tc
> adapter
->dcb_cfg
.num_tcs
.pg_tcs
)
577 if (max_tc
!= netdev_get_num_tc(dev
))
578 err
= ixgbe_setup_tc(dev
, max_tc
);
580 ixgbe_dcbnl_devreset(dev
);
585 err
= ixgbe_dcb_hw_ets(&adapter
->hw
, ets
, max_frame
);
590 static int ixgbe_dcbnl_ieee_getpfc(struct net_device
*dev
,
591 struct ieee_pfc
*pfc
)
593 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
594 struct ieee_pfc
*my_pfc
= adapter
->ixgbe_ieee_pfc
;
597 pfc
->pfc_cap
= adapter
->dcb_cfg
.num_tcs
.pfc_tcs
;
599 /* No IEEE PFC settings available */
603 pfc
->pfc_en
= my_pfc
->pfc_en
;
604 pfc
->mbc
= my_pfc
->mbc
;
605 pfc
->delay
= my_pfc
->delay
;
607 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
608 pfc
->requests
[i
] = adapter
->stats
.pxoffrxc
[i
];
609 pfc
->indications
[i
] = adapter
->stats
.pxofftxc
[i
];
615 static int ixgbe_dcbnl_ieee_setpfc(struct net_device
*dev
,
616 struct ieee_pfc
*pfc
)
618 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
619 struct ixgbe_hw
*hw
= &adapter
->hw
;
623 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
626 if (!adapter
->ixgbe_ieee_pfc
) {
627 adapter
->ixgbe_ieee_pfc
= kmalloc(sizeof(struct ieee_pfc
),
629 if (!adapter
->ixgbe_ieee_pfc
)
633 prio_tc
= adapter
->ixgbe_ieee_ets
->prio_tc
;
634 memcpy(adapter
->ixgbe_ieee_pfc
, pfc
, sizeof(*adapter
->ixgbe_ieee_pfc
));
636 /* Enable link flow control parameters if PFC is disabled */
638 err
= ixgbe_dcb_hw_pfc_config(hw
, pfc
->pfc_en
, prio_tc
);
640 err
= hw
->mac
.ops
.fc_enable(hw
);
642 ixgbe_set_rx_drop_en(adapter
);
647 static int ixgbe_dcbnl_ieee_setapp(struct net_device
*dev
,
650 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
653 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
656 err
= dcb_ieee_setapp(dev
, app
);
661 if (app
->selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
662 app
->protocol
== ETH_P_FCOE
) {
663 u8 app_mask
= dcb_ieee_getapp_mask(dev
, app
);
665 if (app_mask
& (1 << adapter
->fcoe
.up
))
668 adapter
->fcoe
.up
= app
->priority
;
669 ixgbe_dcbnl_devreset(dev
);
673 /* VF devices should use default UP when available */
674 if (app
->selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
675 app
->protocol
== 0) {
678 adapter
->default_up
= app
->priority
;
680 for (vf
= 0; vf
< adapter
->num_vfs
; vf
++) {
681 struct vf_data_storage
*vfinfo
= &adapter
->vfinfo
[vf
];
684 ixgbe_set_vmvir(adapter
, vfinfo
->pf_vlan
,
692 static int ixgbe_dcbnl_ieee_delapp(struct net_device
*dev
,
695 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
698 if (!(adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
))
701 err
= dcb_ieee_delapp(dev
, app
);
704 if (!err
&& app
->selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
705 app
->protocol
== ETH_P_FCOE
) {
706 u8 app_mask
= dcb_ieee_getapp_mask(dev
, app
);
708 if (app_mask
& (1 << adapter
->fcoe
.up
))
711 adapter
->fcoe
.up
= app_mask
?
712 ffs(app_mask
) - 1 : IXGBE_FCOE_DEFTC
;
713 ixgbe_dcbnl_devreset(dev
);
716 /* IF default priority is being removed clear VF default UP */
717 if (app
->selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
718 app
->protocol
== 0 && adapter
->default_up
== app
->priority
) {
720 long unsigned int app_mask
= dcb_ieee_getapp_mask(dev
, app
);
721 int qos
= app_mask
? find_first_bit(&app_mask
, 8) : 0;
723 adapter
->default_up
= qos
;
725 for (vf
= 0; vf
< adapter
->num_vfs
; vf
++) {
726 struct vf_data_storage
*vfinfo
= &adapter
->vfinfo
[vf
];
729 ixgbe_set_vmvir(adapter
, vfinfo
->pf_vlan
,
737 static u8
ixgbe_dcbnl_getdcbx(struct net_device
*dev
)
739 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
740 return adapter
->dcbx_cap
;
743 static u8
ixgbe_dcbnl_setdcbx(struct net_device
*dev
, u8 mode
)
745 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
746 struct ieee_ets ets
= {0};
747 struct ieee_pfc pfc
= {0};
750 /* no support for LLD_MANAGED modes or CEE+IEEE */
751 if ((mode
& DCB_CAP_DCBX_LLD_MANAGED
) ||
752 ((mode
& DCB_CAP_DCBX_VER_IEEE
) && (mode
& DCB_CAP_DCBX_VER_CEE
)) ||
753 !(mode
& DCB_CAP_DCBX_HOST
))
756 if (mode
== adapter
->dcbx_cap
)
759 adapter
->dcbx_cap
= mode
;
761 /* ETS and PFC defaults */
765 if (mode
& DCB_CAP_DCBX_VER_IEEE
) {
766 ixgbe_dcbnl_ieee_setets(dev
, &ets
);
767 ixgbe_dcbnl_ieee_setpfc(dev
, &pfc
);
768 } else if (mode
& DCB_CAP_DCBX_VER_CEE
) {
769 u8 mask
= BIT_PFC
| BIT_PG_TX
| BIT_PG_RX
| BIT_APP_UPCHG
;
771 adapter
->dcb_set_bitmap
|= mask
;
772 ixgbe_dcbnl_set_all(dev
);
774 /* Drop into single TC mode strict priority as this
775 * indicates CEE and IEEE versions are disabled
777 ixgbe_dcbnl_ieee_setets(dev
, &ets
);
778 ixgbe_dcbnl_ieee_setpfc(dev
, &pfc
);
779 err
= ixgbe_setup_tc(dev
, 0);
785 const struct dcbnl_rtnl_ops dcbnl_ops
= {
786 .ieee_getets
= ixgbe_dcbnl_ieee_getets
,
787 .ieee_setets
= ixgbe_dcbnl_ieee_setets
,
788 .ieee_getpfc
= ixgbe_dcbnl_ieee_getpfc
,
789 .ieee_setpfc
= ixgbe_dcbnl_ieee_setpfc
,
790 .ieee_setapp
= ixgbe_dcbnl_ieee_setapp
,
791 .ieee_delapp
= ixgbe_dcbnl_ieee_delapp
,
792 .getstate
= ixgbe_dcbnl_get_state
,
793 .setstate
= ixgbe_dcbnl_set_state
,
794 .getpermhwaddr
= ixgbe_dcbnl_get_perm_hw_addr
,
795 .setpgtccfgtx
= ixgbe_dcbnl_set_pg_tc_cfg_tx
,
796 .setpgbwgcfgtx
= ixgbe_dcbnl_set_pg_bwg_cfg_tx
,
797 .setpgtccfgrx
= ixgbe_dcbnl_set_pg_tc_cfg_rx
,
798 .setpgbwgcfgrx
= ixgbe_dcbnl_set_pg_bwg_cfg_rx
,
799 .getpgtccfgtx
= ixgbe_dcbnl_get_pg_tc_cfg_tx
,
800 .getpgbwgcfgtx
= ixgbe_dcbnl_get_pg_bwg_cfg_tx
,
801 .getpgtccfgrx
= ixgbe_dcbnl_get_pg_tc_cfg_rx
,
802 .getpgbwgcfgrx
= ixgbe_dcbnl_get_pg_bwg_cfg_rx
,
803 .setpfccfg
= ixgbe_dcbnl_set_pfc_cfg
,
804 .getpfccfg
= ixgbe_dcbnl_get_pfc_cfg
,
805 .setall
= ixgbe_dcbnl_set_all
,
806 .getcap
= ixgbe_dcbnl_getcap
,
807 .getnumtcs
= ixgbe_dcbnl_getnumtcs
,
808 .setnumtcs
= ixgbe_dcbnl_setnumtcs
,
809 .getpfcstate
= ixgbe_dcbnl_getpfcstate
,
810 .setpfcstate
= ixgbe_dcbnl_setpfcstate
,
811 .getapp
= ixgbe_dcbnl_getapp
,
812 .getdcbx
= ixgbe_dcbnl_getdcbx
,
813 .setdcbx
= ixgbe_dcbnl_setdcbx
,