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 ixgbe_init_interrupt_scheme(adapter);
149 if (netif_running(netdev))
150 netdev->netdev_ops->ndo_open(netdev);
153 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
154 if (netif_running(netdev))
155 netdev->netdev_ops->ndo_stop(netdev);
156 ixgbe_clear_interrupt_scheme(adapter);
158 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
159 adapter->temp_dcb_cfg.pfc_mode_enable = false;
160 adapter->dcb_cfg.pfc_mode_enable = false;
161 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
162 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
163 switch (adapter->hw.mac.type) {
164 case ixgbe_mac_82599EB:
166 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
172 ixgbe_init_interrupt_scheme(adapter);
173 if (netif_running(netdev))
174 netdev->netdev_ops->ndo_open(netdev);
181 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
184 struct ixgbe_adapter *adapter = netdev_priv(netdev);
187 memset(perm_addr, 0xff, MAX_ADDR_LEN);
189 for (i = 0; i < netdev->addr_len; i++)
190 perm_addr[i] = adapter->hw.mac.perm_addr[i];
192 switch (adapter->hw.mac.type) {
193 case ixgbe_mac_82599EB:
195 for (j = 0; j < netdev->addr_len; j++, i++)
196 perm_addr[i] = adapter->hw.mac.san_addr[j];
203 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
204 u8 prio, u8 bwg_id, u8 bw_pct,
207 struct ixgbe_adapter *adapter = netdev_priv(netdev);
209 if (prio != DCB_ATTR_VALUE_UNDEFINED)
210 adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio;
211 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
212 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id;
213 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
214 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent =
216 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
217 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
220 if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type !=
221 adapter->dcb_cfg.tc_config[tc].path[0].prio_type) ||
222 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id !=
223 adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) ||
224 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent !=
225 adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) ||
226 (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
227 adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap))
228 adapter->dcb_set_bitmap |= BIT_PG_TX;
231 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
234 struct ixgbe_adapter *adapter = netdev_priv(netdev);
236 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
238 if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
239 adapter->dcb_cfg.bw_percentage[0][bwg_id])
240 adapter->dcb_set_bitmap |= BIT_PG_TX;
243 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
244 u8 prio, u8 bwg_id, u8 bw_pct,
247 struct ixgbe_adapter *adapter = netdev_priv(netdev);
249 if (prio != DCB_ATTR_VALUE_UNDEFINED)
250 adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
251 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
252 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
253 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
254 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
256 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
257 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
260 if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
261 adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
262 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
263 adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
264 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
265 adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
266 (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
267 adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap))
268 adapter->dcb_set_bitmap |= BIT_PG_RX;
271 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
274 struct ixgbe_adapter *adapter = netdev_priv(netdev);
276 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
278 if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
279 adapter->dcb_cfg.bw_percentage[1][bwg_id])
280 adapter->dcb_set_bitmap |= BIT_PG_RX;
283 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
284 u8 *prio, u8 *bwg_id, u8 *bw_pct,
287 struct ixgbe_adapter *adapter = netdev_priv(netdev);
289 *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
290 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
291 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
292 *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
295 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
298 struct ixgbe_adapter *adapter = netdev_priv(netdev);
300 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
303 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
304 u8 *prio, u8 *bwg_id, u8 *bw_pct,
307 struct ixgbe_adapter *adapter = netdev_priv(netdev);
309 *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
310 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
311 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
312 *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
315 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
318 struct ixgbe_adapter *adapter = netdev_priv(netdev);
320 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
323 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
326 struct ixgbe_adapter *adapter = netdev_priv(netdev);
328 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
329 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
330 adapter->dcb_cfg.tc_config[priority].dcb_pfc) {
331 adapter->dcb_set_bitmap |= BIT_PFC;
332 adapter->temp_dcb_cfg.pfc_mode_enable = true;
336 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
339 struct ixgbe_adapter *adapter = netdev_priv(netdev);
341 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
344 static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
346 struct ixgbe_adapter *adapter = netdev_priv(netdev);
349 if (!adapter->dcb_set_bitmap ||
350 !(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
351 return DCB_NO_HW_CHG;
353 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
354 adapter->ring_feature[RING_F_DCB].indices);
357 return DCB_NO_HW_CHG;
360 * Only take down the adapter if an app change occured. FCoE
361 * may shuffle tx rings in this case and this can not be done
362 * without a reset currently.
364 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
365 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
368 if (netif_running(netdev))
369 netdev->netdev_ops->ndo_stop(netdev);
370 ixgbe_clear_interrupt_scheme(adapter);
373 if (adapter->dcb_cfg.pfc_mode_enable) {
374 switch (adapter->hw.mac.type) {
375 case ixgbe_mac_82599EB:
377 if (adapter->hw.fc.current_mode != ixgbe_fc_pfc)
378 adapter->last_lfc_mode =
379 adapter->hw.fc.current_mode;
384 adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
386 switch (adapter->hw.mac.type) {
387 case ixgbe_mac_82598EB:
388 adapter->hw.fc.requested_mode = ixgbe_fc_none;
390 case ixgbe_mac_82599EB:
392 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;
406 if (adapter->dcb_set_bitmap & BIT_PFC) {
408 ixgbe_dcb_unpack_pfc(&adapter->dcb_cfg, &pfc_en);
409 ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc_en);
413 if (adapter->dcb_set_bitmap & (BIT_PG_TX|BIT_PG_RX)) {
414 u16 refill[MAX_TRAFFIC_CLASS], max[MAX_TRAFFIC_CLASS];
415 u8 bwg_id[MAX_TRAFFIC_CLASS], prio_type[MAX_TRAFFIC_CLASS];
416 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
419 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
420 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
423 ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
424 max_frame, DCB_TX_CONFIG);
425 ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
426 max_frame, DCB_RX_CONFIG);
428 ixgbe_dcb_unpack_refill(&adapter->dcb_cfg,
429 DCB_TX_CONFIG, refill);
430 ixgbe_dcb_unpack_max(&adapter->dcb_cfg, max);
431 ixgbe_dcb_unpack_bwgid(&adapter->dcb_cfg,
432 DCB_TX_CONFIG, bwg_id);
433 ixgbe_dcb_unpack_prio(&adapter->dcb_cfg,
434 DCB_TX_CONFIG, prio_type);
436 ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
440 if (adapter->dcb_cfg.pfc_mode_enable)
441 adapter->hw.fc.current_mode = ixgbe_fc_pfc;
443 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG)
444 clear_bit(__IXGBE_RESETTING, &adapter->state);
445 adapter->dcb_set_bitmap = 0x00;
449 static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
451 struct ixgbe_adapter *adapter = netdev_priv(netdev);
454 case DCB_CAP_ATTR_PG:
457 case DCB_CAP_ATTR_PFC:
460 case DCB_CAP_ATTR_UP2TC:
463 case DCB_CAP_ATTR_PG_TCS:
466 case DCB_CAP_ATTR_PFC_TCS:
469 case DCB_CAP_ATTR_GSP:
472 case DCB_CAP_ATTR_BCN:
475 case DCB_CAP_ATTR_DCBX:
476 *cap = adapter->dcbx_cap;
486 static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
488 struct ixgbe_adapter *adapter = netdev_priv(netdev);
491 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
493 case DCB_NUMTCS_ATTR_PG:
494 *num = MAX_TRAFFIC_CLASS;
496 case DCB_NUMTCS_ATTR_PFC:
497 *num = MAX_TRAFFIC_CLASS;
510 static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
515 static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
517 struct ixgbe_adapter *adapter = netdev_priv(netdev);
519 return adapter->dcb_cfg.pfc_mode_enable;
522 static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
524 struct ixgbe_adapter *adapter = netdev_priv(netdev);
526 adapter->temp_dcb_cfg.pfc_mode_enable = state;
527 if (adapter->temp_dcb_cfg.pfc_mode_enable !=
528 adapter->dcb_cfg.pfc_mode_enable)
529 adapter->dcb_set_bitmap |= BIT_PFC;
533 * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
534 * @netdev : the corresponding netdev
535 * @idtype : identifies the id as ether type or TCP/UDP port number
536 * @id: id is either ether type or TCP/UDP port number
538 * Returns : on success, returns a non-zero 802.1p user priority bitmap
539 * otherwise returns 0 as the invalid user priority bitmap to indicate an
542 static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
544 struct ixgbe_adapter *adapter = netdev_priv(netdev);
545 struct dcb_app app = {
550 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
553 return dcb_getapp(netdev, &app);
557 * ixgbe_dcbnl_setapp - set the DCBX application user priority
558 * @netdev : the corresponding netdev
559 * @idtype : identifies the id as ether type or TCP/UDP port number
560 * @id: id is either ether type or TCP/UDP port number
561 * @up: the 802.1p user priority bitmap
563 * Returns : 0 on success or 1 on error
565 static u8 ixgbe_dcbnl_setapp(struct net_device *netdev,
566 u8 idtype, u16 id, u8 up)
568 struct ixgbe_adapter *adapter = netdev_priv(netdev);
570 struct dcb_app app = {
576 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
579 rval = dcb_setapp(netdev, &app);
582 case DCB_APP_IDTYPE_ETHTYPE:
584 if (id == ETH_P_FCOE) {
587 /* Get current programmed tc */
588 old_tc = adapter->fcoe.tc;
589 rval = ixgbe_fcoe_setapp(adapter, up);
592 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED) ||
593 !(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
596 /* The FCoE application priority may be changed multiple
597 * times in quick sucession with switches that build up
598 * TLVs. To avoid creating uneeded device resets this
599 * checks the actual HW configuration and clears
600 * BIT_APP_UPCHG if a HW configuration change is not
603 if (old_tc == adapter->fcoe.tc)
604 adapter->dcb_set_bitmap &= ~BIT_APP_UPCHG;
606 adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
610 case DCB_APP_IDTYPE_PORTNUM:
618 static int ixgbe_dcbnl_ieee_getets(struct net_device *dev,
619 struct ieee_ets *ets)
621 struct ixgbe_adapter *adapter = netdev_priv(dev);
622 struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets;
624 /* No IEEE PFC settings available */
628 ets->ets_cap = MAX_TRAFFIC_CLASS;
629 ets->cbs = my_ets->cbs;
630 memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw));
631 memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw));
632 memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa));
633 memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc));
637 static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,
638 struct ieee_ets *ets)
640 struct ixgbe_adapter *adapter = netdev_priv(dev);
641 __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
642 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
644 /* naively give each TC a bwg to map onto CEE hardware */
645 __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
647 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
650 if (!adapter->ixgbe_ieee_ets) {
651 adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets),
653 if (!adapter->ixgbe_ieee_ets)
657 memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets));
659 ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
660 err = ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
661 bwg_id, ets->tc_tsa);
665 static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev,
666 struct ieee_pfc *pfc)
668 struct ixgbe_adapter *adapter = netdev_priv(dev);
669 struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc;
672 /* No IEEE PFC settings available */
676 pfc->pfc_cap = MAX_TRAFFIC_CLASS;
677 pfc->pfc_en = my_pfc->pfc_en;
678 pfc->mbc = my_pfc->mbc;
679 pfc->delay = my_pfc->delay;
681 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
682 pfc->requests[i] = adapter->stats.pxoffrxc[i];
683 pfc->indications[i] = adapter->stats.pxofftxc[i];
689 static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
690 struct ieee_pfc *pfc)
692 struct ixgbe_adapter *adapter = netdev_priv(dev);
695 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
698 if (!adapter->ixgbe_ieee_pfc) {
699 adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc),
701 if (!adapter->ixgbe_ieee_pfc)
705 memcpy(adapter->ixgbe_ieee_pfc, pfc, sizeof(*adapter->ixgbe_ieee_pfc));
706 err = ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc->pfc_en);
710 static int ixgbe_dcbnl_ieee_setapp(struct net_device *dev,
713 struct ixgbe_adapter *adapter = netdev_priv(dev);
715 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
718 if (app->selector == 1 && app->protocol == ETH_P_FCOE) {
719 if (adapter->fcoe.tc == app->priority)
722 /* In IEEE mode map up to tc 1:1 */
723 adapter->fcoe.tc = app->priority;
724 adapter->fcoe.up = app->priority;
726 /* Force hardware reset required to push FCoE
727 * setup on {tx|rx}_rings
729 adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
730 ixgbe_dcbnl_set_all(dev);
735 dcb_setapp(dev, app);
739 static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev)
741 struct ixgbe_adapter *adapter = netdev_priv(dev);
742 return adapter->dcbx_cap;
745 static u8 ixgbe_dcbnl_setdcbx(struct net_device *dev, u8 mode)
747 struct ixgbe_adapter *adapter = netdev_priv(dev);
748 struct ieee_ets ets = {0};
749 struct ieee_pfc pfc = {0};
751 /* no support for LLD_MANAGED modes or CEE+IEEE */
752 if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
753 ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) ||
754 !(mode & DCB_CAP_DCBX_HOST))
757 if (mode == adapter->dcbx_cap)
760 adapter->dcbx_cap = mode;
762 /* ETS and PFC defaults */
766 if (mode & DCB_CAP_DCBX_VER_IEEE) {
767 ixgbe_dcbnl_ieee_setets(dev, &ets);
768 ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
769 } else if (mode & DCB_CAP_DCBX_VER_CEE) {
770 adapter->dcb_set_bitmap |= (BIT_PFC & BIT_PG_TX & BIT_PG_RX);
771 ixgbe_dcbnl_set_all(dev);
773 /* Drop into single TC mode strict priority as this
774 * indicates CEE and IEEE versions are disabled
776 ixgbe_dcbnl_ieee_setets(dev, &ets);
777 ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
778 ixgbe_dcbnl_set_state(dev, 0);
784 const struct dcbnl_rtnl_ops dcbnl_ops = {
785 .ieee_getets = ixgbe_dcbnl_ieee_getets,
786 .ieee_setets = ixgbe_dcbnl_ieee_setets,
787 .ieee_getpfc = ixgbe_dcbnl_ieee_getpfc,
788 .ieee_setpfc = ixgbe_dcbnl_ieee_setpfc,
789 .ieee_setapp = ixgbe_dcbnl_ieee_setapp,
790 .getstate = ixgbe_dcbnl_get_state,
791 .setstate = ixgbe_dcbnl_set_state,
792 .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
793 .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
794 .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
795 .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
796 .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
797 .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
798 .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
799 .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
800 .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
801 .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
802 .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
803 .setall = ixgbe_dcbnl_set_all,
804 .getcap = ixgbe_dcbnl_getcap,
805 .getnumtcs = ixgbe_dcbnl_getnumtcs,
806 .setnumtcs = ixgbe_dcbnl_setnumtcs,
807 .getpfcstate = ixgbe_dcbnl_getpfcstate,
808 .setpfcstate = ixgbe_dcbnl_setpfcstate,
809 .getapp = ixgbe_dcbnl_getapp,
810 .setapp = ixgbe_dcbnl_setapp,
811 .getdcbx = ixgbe_dcbnl_getdcbx,
812 .setdcbx = ixgbe_dcbnl_setdcbx,