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 /* verify there is something to do, if not then exit */
118 if (!!state != !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
123 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
124 e_err(drv, "Enable failed, needs MSI-X\n");
129 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
131 switch (adapter->hw.mac.type) {
132 case ixgbe_mac_82598EB:
133 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
134 adapter->hw.fc.requested_mode = ixgbe_fc_none;
136 case ixgbe_mac_82599EB:
138 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
144 ixgbe_setup_tc(netdev, MAX_TRAFFIC_CLASS);
147 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
148 adapter->temp_dcb_cfg.pfc_mode_enable = false;
149 adapter->dcb_cfg.pfc_mode_enable = false;
150 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
151 switch (adapter->hw.mac.type) {
152 case ixgbe_mac_82599EB:
154 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
155 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
160 ixgbe_setup_tc(netdev, 0);
167 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
170 struct ixgbe_adapter *adapter = netdev_priv(netdev);
173 memset(perm_addr, 0xff, MAX_ADDR_LEN);
175 for (i = 0; i < netdev->addr_len; i++)
176 perm_addr[i] = adapter->hw.mac.perm_addr[i];
178 switch (adapter->hw.mac.type) {
179 case ixgbe_mac_82599EB:
181 for (j = 0; j < netdev->addr_len; j++, i++)
182 perm_addr[i] = adapter->hw.mac.san_addr[j];
189 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
190 u8 prio, u8 bwg_id, u8 bw_pct,
193 struct ixgbe_adapter *adapter = netdev_priv(netdev);
195 if (prio != DCB_ATTR_VALUE_UNDEFINED)
196 adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio;
197 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
198 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id;
199 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
200 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent =
202 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
203 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
206 if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type !=
207 adapter->dcb_cfg.tc_config[tc].path[0].prio_type) ||
208 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id !=
209 adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) ||
210 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent !=
211 adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) ||
212 (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
213 adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap))
214 adapter->dcb_set_bitmap |= BIT_PG_TX;
217 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
220 struct ixgbe_adapter *adapter = netdev_priv(netdev);
222 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
224 if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
225 adapter->dcb_cfg.bw_percentage[0][bwg_id])
226 adapter->dcb_set_bitmap |= BIT_PG_TX;
229 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
230 u8 prio, u8 bwg_id, u8 bw_pct,
233 struct ixgbe_adapter *adapter = netdev_priv(netdev);
235 if (prio != DCB_ATTR_VALUE_UNDEFINED)
236 adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
237 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
238 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
239 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
240 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
242 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
243 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
246 if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
247 adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
248 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
249 adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
250 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
251 adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
252 (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
253 adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap))
254 adapter->dcb_set_bitmap |= BIT_PG_RX;
257 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
260 struct ixgbe_adapter *adapter = netdev_priv(netdev);
262 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
264 if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
265 adapter->dcb_cfg.bw_percentage[1][bwg_id])
266 adapter->dcb_set_bitmap |= BIT_PG_RX;
269 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
270 u8 *prio, u8 *bwg_id, u8 *bw_pct,
273 struct ixgbe_adapter *adapter = netdev_priv(netdev);
275 *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
276 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
277 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
278 *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
281 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
284 struct ixgbe_adapter *adapter = netdev_priv(netdev);
286 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
289 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
290 u8 *prio, u8 *bwg_id, u8 *bw_pct,
293 struct ixgbe_adapter *adapter = netdev_priv(netdev);
295 *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
296 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
297 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
298 *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
301 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
304 struct ixgbe_adapter *adapter = netdev_priv(netdev);
306 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
309 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
312 struct ixgbe_adapter *adapter = netdev_priv(netdev);
314 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
315 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
316 adapter->dcb_cfg.tc_config[priority].dcb_pfc) {
317 adapter->dcb_set_bitmap |= BIT_PFC;
318 adapter->temp_dcb_cfg.pfc_mode_enable = true;
322 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
325 struct ixgbe_adapter *adapter = netdev_priv(netdev);
327 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
330 static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
332 struct ixgbe_adapter *adapter = netdev_priv(netdev);
333 struct dcb_app app = {
334 .selector = DCB_APP_IDTYPE_ETHTYPE,
335 .protocol = ETH_P_FCOE,
337 u8 up = dcb_getapp(netdev, &app);
340 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
343 return DCB_NO_HW_CHG;
345 /* In IEEE mode app data must be parsed into DCBX format for
348 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
352 if (up && (up != (1 << adapter->fcoe.up)))
353 adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
356 * Only take down the adapter if an app change occurred. FCoE
357 * may shuffle tx rings in this case and this can not be done
358 * without a reset currently.
360 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
361 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
362 usleep_range(1000, 2000);
364 ixgbe_fcoe_setapp(adapter, up);
366 if (netif_running(netdev))
367 netdev->netdev_ops->ndo_stop(netdev);
368 ixgbe_clear_interrupt_scheme(adapter);
372 if (adapter->dcb_cfg.pfc_mode_enable) {
373 switch (adapter->hw.mac.type) {
374 case ixgbe_mac_82599EB:
376 if (adapter->hw.fc.current_mode != ixgbe_fc_pfc)
377 adapter->last_lfc_mode =
378 adapter->hw.fc.current_mode;
383 adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
385 switch (adapter->hw.mac.type) {
386 case ixgbe_mac_82598EB:
387 adapter->hw.fc.requested_mode = ixgbe_fc_none;
389 case ixgbe_mac_82599EB:
391 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
399 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
400 ixgbe_init_interrupt_scheme(adapter);
401 if (netif_running(netdev))
402 netdev->netdev_ops->ndo_open(netdev);
403 ret = DCB_HW_CHG_RST;
407 if (adapter->dcb_set_bitmap & BIT_PFC) {
409 ixgbe_dcb_unpack_pfc(&adapter->dcb_cfg, &pfc_en);
410 ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc_en);
414 if (adapter->dcb_set_bitmap & (BIT_PG_TX|BIT_PG_RX)) {
415 u16 refill[MAX_TRAFFIC_CLASS], max[MAX_TRAFFIC_CLASS];
416 u8 bwg_id[MAX_TRAFFIC_CLASS], prio_type[MAX_TRAFFIC_CLASS];
417 /* Priority to TC mapping in CEE case default to 1:1 */
418 u8 prio_tc[MAX_TRAFFIC_CLASS] = {0, 1, 2, 3, 4, 5, 6, 7};
419 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
422 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
423 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
426 ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
427 max_frame, DCB_TX_CONFIG);
428 ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
429 max_frame, DCB_RX_CONFIG);
431 ixgbe_dcb_unpack_refill(&adapter->dcb_cfg,
432 DCB_TX_CONFIG, refill);
433 ixgbe_dcb_unpack_max(&adapter->dcb_cfg, max);
434 ixgbe_dcb_unpack_bwgid(&adapter->dcb_cfg,
435 DCB_TX_CONFIG, bwg_id);
436 ixgbe_dcb_unpack_prio(&adapter->dcb_cfg,
437 DCB_TX_CONFIG, prio_type);
439 ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
440 bwg_id, prio_type, prio_tc);
443 if (adapter->dcb_cfg.pfc_mode_enable)
444 adapter->hw.fc.current_mode = ixgbe_fc_pfc;
446 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG)
447 clear_bit(__IXGBE_RESETTING, &adapter->state);
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 = MAX_TRAFFIC_CLASS;
499 case DCB_NUMTCS_ATTR_PFC:
500 *num = MAX_TRAFFIC_CLASS;
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 /* No IEEE PFC settings available */
569 ets->ets_cap = MAX_TRAFFIC_CLASS;
570 ets->cbs = my_ets->cbs;
571 memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw));
572 memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw));
573 memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa));
574 memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc));
578 static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,
579 struct ieee_ets *ets)
581 struct ixgbe_adapter *adapter = netdev_priv(dev);
582 __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
583 __u8 prio_type[IEEE_8021QAZ_MAX_TCS];
584 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
586 __u64 *p = (__u64 *) ets->prio_tc;
587 /* naively give each TC a bwg to map onto CEE hardware */
588 __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
590 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
593 if (!adapter->ixgbe_ieee_ets) {
594 adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets),
596 if (!adapter->ixgbe_ieee_ets)
600 memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets));
602 /* Map TSA onto CEE prio type */
603 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
604 switch (ets->tc_tsa[i]) {
605 case IEEE_8021QAZ_TSA_STRICT:
608 case IEEE_8021QAZ_TSA_ETS:
612 /* Hardware only supports priority strict or
613 * ETS transmission selection algorithms if
614 * we receive some other value from dcbnl
622 ixgbe_dcbnl_set_state(dev, 1);
624 ixgbe_dcbnl_set_state(dev, 0);
626 ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
627 err = ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
628 bwg_id, prio_type, ets->prio_tc);
632 static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev,
633 struct ieee_pfc *pfc)
635 struct ixgbe_adapter *adapter = netdev_priv(dev);
636 struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc;
639 /* No IEEE PFC settings available */
643 pfc->pfc_cap = MAX_TRAFFIC_CLASS;
644 pfc->pfc_en = my_pfc->pfc_en;
645 pfc->mbc = my_pfc->mbc;
646 pfc->delay = my_pfc->delay;
648 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
649 pfc->requests[i] = adapter->stats.pxoffrxc[i];
650 pfc->indications[i] = adapter->stats.pxofftxc[i];
656 static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
657 struct ieee_pfc *pfc)
659 struct ixgbe_adapter *adapter = netdev_priv(dev);
662 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
665 if (!adapter->ixgbe_ieee_pfc) {
666 adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc),
668 if (!adapter->ixgbe_ieee_pfc)
672 memcpy(adapter->ixgbe_ieee_pfc, pfc, sizeof(*adapter->ixgbe_ieee_pfc));
673 err = ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc->pfc_en);
677 static int ixgbe_dcbnl_ieee_setapp(struct net_device *dev,
680 struct ixgbe_adapter *adapter = netdev_priv(dev);
682 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
685 dcb_setapp(dev, app);
688 if (app->selector == 1 && app->protocol == ETH_P_FCOE &&
689 adapter->fcoe.tc == app->priority)
690 ixgbe_dcbnl_set_all(dev);
695 static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev)
697 struct ixgbe_adapter *adapter = netdev_priv(dev);
698 return adapter->dcbx_cap;
701 static u8 ixgbe_dcbnl_setdcbx(struct net_device *dev, u8 mode)
703 struct ixgbe_adapter *adapter = netdev_priv(dev);
704 struct ieee_ets ets = {0};
705 struct ieee_pfc pfc = {0};
707 /* no support for LLD_MANAGED modes or CEE+IEEE */
708 if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
709 ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) ||
710 !(mode & DCB_CAP_DCBX_HOST))
713 if (mode == adapter->dcbx_cap)
716 adapter->dcbx_cap = mode;
718 /* ETS and PFC defaults */
722 if (mode & DCB_CAP_DCBX_VER_IEEE) {
723 ixgbe_dcbnl_ieee_setets(dev, &ets);
724 ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
725 } else if (mode & DCB_CAP_DCBX_VER_CEE) {
726 adapter->dcb_set_bitmap |= (BIT_PFC & BIT_PG_TX & BIT_PG_RX);
727 ixgbe_dcbnl_set_all(dev);
729 /* Drop into single TC mode strict priority as this
730 * indicates CEE and IEEE versions are disabled
732 ixgbe_dcbnl_ieee_setets(dev, &ets);
733 ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
734 ixgbe_dcbnl_set_state(dev, 0);
740 const struct dcbnl_rtnl_ops dcbnl_ops = {
741 .ieee_getets = ixgbe_dcbnl_ieee_getets,
742 .ieee_setets = ixgbe_dcbnl_ieee_setets,
743 .ieee_getpfc = ixgbe_dcbnl_ieee_getpfc,
744 .ieee_setpfc = ixgbe_dcbnl_ieee_setpfc,
745 .ieee_setapp = ixgbe_dcbnl_ieee_setapp,
746 .getstate = ixgbe_dcbnl_get_state,
747 .setstate = ixgbe_dcbnl_set_state,
748 .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
749 .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
750 .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
751 .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
752 .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
753 .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
754 .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
755 .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
756 .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
757 .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
758 .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
759 .setall = ixgbe_dcbnl_set_all,
760 .getcap = ixgbe_dcbnl_getcap,
761 .getnumtcs = ixgbe_dcbnl_getnumtcs,
762 .setnumtcs = ixgbe_dcbnl_setnumtcs,
763 .getpfcstate = ixgbe_dcbnl_getpfcstate,
764 .setpfcstate = ixgbe_dcbnl_setpfcstate,
765 .getapp = ixgbe_dcbnl_getapp,
766 .getdcbx = ixgbe_dcbnl_getdcbx,
767 .setdcbx = ixgbe_dcbnl_setdcbx,