FRV: Use generic show_interrupts()
[cris-mirror.git] / drivers / net / ixgbe / ixgbe_dcb_nl.c
blobfec4c724c37ad99775b26a9998495079672b2fb2
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
13 more details.
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".
22 Contact Information:
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 *******************************************************************************/
29 #include "ixgbe.h"
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
36 #define BIT_PFC 0x02
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;
52 int i;
54 if (!src_dcb_cfg || !dst_dcb_cfg)
55 return -EINVAL;
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;
102 return 0;
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)
114 u8 err = 0;
115 struct ixgbe_adapter *adapter = netdev_priv(netdev);
117 if (state > 0) {
118 /* Turn on DCB */
119 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
120 goto out;
122 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
123 e_err(drv, "Enable failed, needs MSI-X\n");
124 err = 1;
125 goto out;
128 if (netif_running(netdev))
129 netdev->netdev_ops->ndo_stop(netdev);
130 ixgbe_clear_interrupt_scheme(adapter);
132 switch (adapter->hw.mac.type) {
133 case ixgbe_mac_82598EB:
134 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
135 adapter->hw.fc.requested_mode = ixgbe_fc_none;
136 break;
137 case ixgbe_mac_82599EB:
138 case ixgbe_mac_X540:
139 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
140 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
141 break;
142 default:
143 break;
146 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
147 if (!netdev_get_num_tc(netdev))
148 ixgbe_setup_tc(netdev, MAX_TRAFFIC_CLASS);
150 ixgbe_init_interrupt_scheme(adapter);
151 if (netif_running(netdev))
152 netdev->netdev_ops->ndo_open(netdev);
153 } else {
154 /* Turn off DCB */
155 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
156 if (netif_running(netdev))
157 netdev->netdev_ops->ndo_stop(netdev);
158 ixgbe_clear_interrupt_scheme(adapter);
160 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
161 adapter->temp_dcb_cfg.pfc_mode_enable = false;
162 adapter->dcb_cfg.pfc_mode_enable = false;
163 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
164 switch (adapter->hw.mac.type) {
165 case ixgbe_mac_82599EB:
166 case ixgbe_mac_X540:
167 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
168 break;
169 default:
170 break;
173 ixgbe_setup_tc(netdev, 0);
175 ixgbe_init_interrupt_scheme(adapter);
176 if (netif_running(netdev))
177 netdev->netdev_ops->ndo_open(netdev);
180 out:
181 return err;
184 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
185 u8 *perm_addr)
187 struct ixgbe_adapter *adapter = netdev_priv(netdev);
188 int i, j;
190 memset(perm_addr, 0xff, MAX_ADDR_LEN);
192 for (i = 0; i < netdev->addr_len; i++)
193 perm_addr[i] = adapter->hw.mac.perm_addr[i];
195 switch (adapter->hw.mac.type) {
196 case ixgbe_mac_82599EB:
197 case ixgbe_mac_X540:
198 for (j = 0; j < netdev->addr_len; j++, i++)
199 perm_addr[i] = adapter->hw.mac.san_addr[j];
200 break;
201 default:
202 break;
206 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
207 u8 prio, u8 bwg_id, u8 bw_pct,
208 u8 up_map)
210 struct ixgbe_adapter *adapter = netdev_priv(netdev);
212 if (prio != DCB_ATTR_VALUE_UNDEFINED)
213 adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio;
214 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
215 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id;
216 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
217 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent =
218 bw_pct;
219 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
220 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
221 up_map;
223 if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type !=
224 adapter->dcb_cfg.tc_config[tc].path[0].prio_type) ||
225 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id !=
226 adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) ||
227 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent !=
228 adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) ||
229 (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
230 adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap))
231 adapter->dcb_set_bitmap |= BIT_PG_TX;
234 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
235 u8 bw_pct)
237 struct ixgbe_adapter *adapter = netdev_priv(netdev);
239 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
241 if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
242 adapter->dcb_cfg.bw_percentage[0][bwg_id])
243 adapter->dcb_set_bitmap |= BIT_PG_TX;
246 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
247 u8 prio, u8 bwg_id, u8 bw_pct,
248 u8 up_map)
250 struct ixgbe_adapter *adapter = netdev_priv(netdev);
252 if (prio != DCB_ATTR_VALUE_UNDEFINED)
253 adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
254 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
255 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
256 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
257 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
258 bw_pct;
259 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
260 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
261 up_map;
263 if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
264 adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
265 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
266 adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
267 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
268 adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
269 (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
270 adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap))
271 adapter->dcb_set_bitmap |= BIT_PG_RX;
274 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
275 u8 bw_pct)
277 struct ixgbe_adapter *adapter = netdev_priv(netdev);
279 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
281 if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
282 adapter->dcb_cfg.bw_percentage[1][bwg_id])
283 adapter->dcb_set_bitmap |= BIT_PG_RX;
286 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
287 u8 *prio, u8 *bwg_id, u8 *bw_pct,
288 u8 *up_map)
290 struct ixgbe_adapter *adapter = netdev_priv(netdev);
292 *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
293 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
294 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
295 *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
298 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
299 u8 *bw_pct)
301 struct ixgbe_adapter *adapter = netdev_priv(netdev);
303 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
306 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
307 u8 *prio, u8 *bwg_id, u8 *bw_pct,
308 u8 *up_map)
310 struct ixgbe_adapter *adapter = netdev_priv(netdev);
312 *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
313 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
314 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
315 *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
318 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
319 u8 *bw_pct)
321 struct ixgbe_adapter *adapter = netdev_priv(netdev);
323 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
326 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
327 u8 setting)
329 struct ixgbe_adapter *adapter = netdev_priv(netdev);
331 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
332 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
333 adapter->dcb_cfg.tc_config[priority].dcb_pfc) {
334 adapter->dcb_set_bitmap |= BIT_PFC;
335 adapter->temp_dcb_cfg.pfc_mode_enable = true;
339 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
340 u8 *setting)
342 struct ixgbe_adapter *adapter = netdev_priv(netdev);
344 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
347 static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
349 struct ixgbe_adapter *adapter = netdev_priv(netdev);
350 int ret;
352 if (!adapter->dcb_set_bitmap ||
353 !(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
354 return DCB_NO_HW_CHG;
356 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
357 MAX_TRAFFIC_CLASS);
359 if (ret)
360 return DCB_NO_HW_CHG;
363 * Only take down the adapter if an app change occured. FCoE
364 * may shuffle tx rings in this case and this can not be done
365 * without a reset currently.
367 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
368 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
369 msleep(1);
371 if (netif_running(netdev))
372 netdev->netdev_ops->ndo_stop(netdev);
373 ixgbe_clear_interrupt_scheme(adapter);
376 if (adapter->dcb_cfg.pfc_mode_enable) {
377 switch (adapter->hw.mac.type) {
378 case ixgbe_mac_82599EB:
379 case ixgbe_mac_X540:
380 if (adapter->hw.fc.current_mode != ixgbe_fc_pfc)
381 adapter->last_lfc_mode =
382 adapter->hw.fc.current_mode;
383 break;
384 default:
385 break;
387 adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
388 } else {
389 switch (adapter->hw.mac.type) {
390 case ixgbe_mac_82598EB:
391 adapter->hw.fc.requested_mode = ixgbe_fc_none;
392 break;
393 case ixgbe_mac_82599EB:
394 case ixgbe_mac_X540:
395 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
396 break;
397 default:
398 break;
402 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
403 ixgbe_init_interrupt_scheme(adapter);
404 if (netif_running(netdev))
405 netdev->netdev_ops->ndo_open(netdev);
406 ret = DCB_HW_CHG_RST;
409 if (adapter->dcb_set_bitmap & BIT_PFC) {
410 u8 pfc_en;
411 ixgbe_dcb_unpack_pfc(&adapter->dcb_cfg, &pfc_en);
412 ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc_en);
413 ret = DCB_HW_CHG;
416 if (adapter->dcb_set_bitmap & (BIT_PG_TX|BIT_PG_RX)) {
417 u16 refill[MAX_TRAFFIC_CLASS], max[MAX_TRAFFIC_CLASS];
418 u8 bwg_id[MAX_TRAFFIC_CLASS], prio_type[MAX_TRAFFIC_CLASS];
419 /* Priority to TC mapping in CEE case default to 1:1 */
420 u8 prio_tc[MAX_TRAFFIC_CLASS] = {0, 1, 2, 3, 4, 5, 6, 7};
421 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
423 #ifdef CONFIG_FCOE
424 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
425 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
426 #endif
428 ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
429 max_frame, DCB_TX_CONFIG);
430 ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
431 max_frame, DCB_RX_CONFIG);
433 ixgbe_dcb_unpack_refill(&adapter->dcb_cfg,
434 DCB_TX_CONFIG, refill);
435 ixgbe_dcb_unpack_max(&adapter->dcb_cfg, max);
436 ixgbe_dcb_unpack_bwgid(&adapter->dcb_cfg,
437 DCB_TX_CONFIG, bwg_id);
438 ixgbe_dcb_unpack_prio(&adapter->dcb_cfg,
439 DCB_TX_CONFIG, prio_type);
441 ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
442 bwg_id, prio_type, prio_tc);
445 if (adapter->dcb_cfg.pfc_mode_enable)
446 adapter->hw.fc.current_mode = ixgbe_fc_pfc;
448 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG)
449 clear_bit(__IXGBE_RESETTING, &adapter->state);
450 adapter->dcb_set_bitmap = 0x00;
451 return ret;
454 static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
456 struct ixgbe_adapter *adapter = netdev_priv(netdev);
458 switch (capid) {
459 case DCB_CAP_ATTR_PG:
460 *cap = true;
461 break;
462 case DCB_CAP_ATTR_PFC:
463 *cap = true;
464 break;
465 case DCB_CAP_ATTR_UP2TC:
466 *cap = false;
467 break;
468 case DCB_CAP_ATTR_PG_TCS:
469 *cap = 0x80;
470 break;
471 case DCB_CAP_ATTR_PFC_TCS:
472 *cap = 0x80;
473 break;
474 case DCB_CAP_ATTR_GSP:
475 *cap = true;
476 break;
477 case DCB_CAP_ATTR_BCN:
478 *cap = false;
479 break;
480 case DCB_CAP_ATTR_DCBX:
481 *cap = adapter->dcbx_cap;
482 break;
483 default:
484 *cap = false;
485 break;
488 return 0;
491 static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
493 struct ixgbe_adapter *adapter = netdev_priv(netdev);
494 u8 rval = 0;
496 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
497 switch (tcid) {
498 case DCB_NUMTCS_ATTR_PG:
499 *num = MAX_TRAFFIC_CLASS;
500 break;
501 case DCB_NUMTCS_ATTR_PFC:
502 *num = MAX_TRAFFIC_CLASS;
503 break;
504 default:
505 rval = -EINVAL;
506 break;
508 } else {
509 rval = -EINVAL;
512 return rval;
515 static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
517 return -EINVAL;
520 static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
522 struct ixgbe_adapter *adapter = netdev_priv(netdev);
524 return adapter->dcb_cfg.pfc_mode_enable;
527 static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
529 struct ixgbe_adapter *adapter = netdev_priv(netdev);
531 adapter->temp_dcb_cfg.pfc_mode_enable = state;
532 if (adapter->temp_dcb_cfg.pfc_mode_enable !=
533 adapter->dcb_cfg.pfc_mode_enable)
534 adapter->dcb_set_bitmap |= BIT_PFC;
538 * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
539 * @netdev : the corresponding netdev
540 * @idtype : identifies the id as ether type or TCP/UDP port number
541 * @id: id is either ether type or TCP/UDP port number
543 * Returns : on success, returns a non-zero 802.1p user priority bitmap
544 * otherwise returns 0 as the invalid user priority bitmap to indicate an
545 * error.
547 static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
549 struct ixgbe_adapter *adapter = netdev_priv(netdev);
550 struct dcb_app app = {
551 .selector = idtype,
552 .protocol = id,
555 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
556 return 0;
558 return dcb_getapp(netdev, &app);
562 * ixgbe_dcbnl_setapp - set the DCBX application user priority
563 * @netdev : the corresponding netdev
564 * @idtype : identifies the id as ether type or TCP/UDP port number
565 * @id: id is either ether type or TCP/UDP port number
566 * @up: the 802.1p user priority bitmap
568 * Returns : 0 on success or 1 on error
570 static u8 ixgbe_dcbnl_setapp(struct net_device *netdev,
571 u8 idtype, u16 id, u8 up)
573 struct ixgbe_adapter *adapter = netdev_priv(netdev);
574 u8 rval = 1;
575 struct dcb_app app = {
576 .selector = idtype,
577 .protocol = id,
578 .priority = up
581 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
582 return rval;
584 rval = dcb_setapp(netdev, &app);
586 switch (idtype) {
587 case DCB_APP_IDTYPE_ETHTYPE:
588 #ifdef IXGBE_FCOE
589 if (id == ETH_P_FCOE) {
590 u8 old_tc;
592 /* Get current programmed tc */
593 old_tc = adapter->fcoe.tc;
594 rval = ixgbe_fcoe_setapp(adapter, up);
596 if (rval ||
597 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED) ||
598 !(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
599 break;
601 /* The FCoE application priority may be changed multiple
602 * times in quick sucession with switches that build up
603 * TLVs. To avoid creating uneeded device resets this
604 * checks the actual HW configuration and clears
605 * BIT_APP_UPCHG if a HW configuration change is not
606 * need
608 if (old_tc == adapter->fcoe.tc)
609 adapter->dcb_set_bitmap &= ~BIT_APP_UPCHG;
610 else
611 adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
613 #endif
614 break;
615 case DCB_APP_IDTYPE_PORTNUM:
616 break;
617 default:
618 break;
620 return rval;
623 static int ixgbe_dcbnl_ieee_getets(struct net_device *dev,
624 struct ieee_ets *ets)
626 struct ixgbe_adapter *adapter = netdev_priv(dev);
627 struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets;
629 /* No IEEE PFC settings available */
630 if (!my_ets)
631 return -EINVAL;
633 ets->ets_cap = MAX_TRAFFIC_CLASS;
634 ets->cbs = my_ets->cbs;
635 memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw));
636 memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw));
637 memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa));
638 memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc));
639 return 0;
642 static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,
643 struct ieee_ets *ets)
645 struct ixgbe_adapter *adapter = netdev_priv(dev);
646 __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
647 __u8 prio_type[IEEE_8021QAZ_MAX_TCS];
648 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
649 int i, err;
650 __u64 *p = (__u64 *) ets->prio_tc;
651 /* naively give each TC a bwg to map onto CEE hardware */
652 __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
654 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
655 return -EINVAL;
657 if (!adapter->ixgbe_ieee_ets) {
658 adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets),
659 GFP_KERNEL);
660 if (!adapter->ixgbe_ieee_ets)
661 return -ENOMEM;
664 memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets));
666 /* Map TSA onto CEE prio type */
667 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
668 switch (ets->tc_tsa[i]) {
669 case IEEE_8021QAZ_TSA_STRICT:
670 prio_type[i] = 2;
671 break;
672 case IEEE_8021QAZ_TSA_ETS:
673 prio_type[i] = 0;
674 break;
675 default:
676 /* Hardware only supports priority strict or
677 * ETS transmission selection algorithms if
678 * we receive some other value from dcbnl
679 * throw an error
681 return -EINVAL;
685 if (*p)
686 ixgbe_dcbnl_set_state(dev, 1);
687 else
688 ixgbe_dcbnl_set_state(dev, 0);
690 ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
691 err = ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
692 bwg_id, prio_type, ets->prio_tc);
693 return err;
696 static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev,
697 struct ieee_pfc *pfc)
699 struct ixgbe_adapter *adapter = netdev_priv(dev);
700 struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc;
701 int i;
703 /* No IEEE PFC settings available */
704 if (!my_pfc)
705 return -EINVAL;
707 pfc->pfc_cap = MAX_TRAFFIC_CLASS;
708 pfc->pfc_en = my_pfc->pfc_en;
709 pfc->mbc = my_pfc->mbc;
710 pfc->delay = my_pfc->delay;
712 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
713 pfc->requests[i] = adapter->stats.pxoffrxc[i];
714 pfc->indications[i] = adapter->stats.pxofftxc[i];
717 return 0;
720 static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
721 struct ieee_pfc *pfc)
723 struct ixgbe_adapter *adapter = netdev_priv(dev);
724 int err;
726 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
727 return -EINVAL;
729 if (!adapter->ixgbe_ieee_pfc) {
730 adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc),
731 GFP_KERNEL);
732 if (!adapter->ixgbe_ieee_pfc)
733 return -ENOMEM;
736 memcpy(adapter->ixgbe_ieee_pfc, pfc, sizeof(*adapter->ixgbe_ieee_pfc));
737 err = ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc->pfc_en);
738 return err;
741 static int ixgbe_dcbnl_ieee_setapp(struct net_device *dev,
742 struct dcb_app *app)
744 struct ixgbe_adapter *adapter = netdev_priv(dev);
746 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
747 return -EINVAL;
748 #ifdef IXGBE_FCOE
749 if (app->selector == 1 && app->protocol == ETH_P_FCOE) {
750 if (adapter->fcoe.tc == app->priority)
751 goto setapp;
753 /* In IEEE mode map up to tc 1:1 */
754 adapter->fcoe.tc = app->priority;
755 adapter->fcoe.up = app->priority;
757 /* Force hardware reset required to push FCoE
758 * setup on {tx|rx}_rings
760 adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
761 ixgbe_dcbnl_set_all(dev);
764 setapp:
765 #endif
766 dcb_setapp(dev, app);
767 return 0;
770 static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev)
772 struct ixgbe_adapter *adapter = netdev_priv(dev);
773 return adapter->dcbx_cap;
776 static u8 ixgbe_dcbnl_setdcbx(struct net_device *dev, u8 mode)
778 struct ixgbe_adapter *adapter = netdev_priv(dev);
779 struct ieee_ets ets = {0};
780 struct ieee_pfc pfc = {0};
782 /* no support for LLD_MANAGED modes or CEE+IEEE */
783 if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
784 ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) ||
785 !(mode & DCB_CAP_DCBX_HOST))
786 return 1;
788 if (mode == adapter->dcbx_cap)
789 return 0;
791 adapter->dcbx_cap = mode;
793 /* ETS and PFC defaults */
794 ets.ets_cap = 8;
795 pfc.pfc_cap = 8;
797 if (mode & DCB_CAP_DCBX_VER_IEEE) {
798 ixgbe_dcbnl_ieee_setets(dev, &ets);
799 ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
800 } else if (mode & DCB_CAP_DCBX_VER_CEE) {
801 adapter->dcb_set_bitmap |= (BIT_PFC & BIT_PG_TX & BIT_PG_RX);
802 ixgbe_dcbnl_set_all(dev);
803 } else {
804 /* Drop into single TC mode strict priority as this
805 * indicates CEE and IEEE versions are disabled
807 ixgbe_dcbnl_ieee_setets(dev, &ets);
808 ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
809 ixgbe_dcbnl_set_state(dev, 0);
812 return 0;
815 const struct dcbnl_rtnl_ops dcbnl_ops = {
816 .ieee_getets = ixgbe_dcbnl_ieee_getets,
817 .ieee_setets = ixgbe_dcbnl_ieee_setets,
818 .ieee_getpfc = ixgbe_dcbnl_ieee_getpfc,
819 .ieee_setpfc = ixgbe_dcbnl_ieee_setpfc,
820 .ieee_setapp = ixgbe_dcbnl_ieee_setapp,
821 .getstate = ixgbe_dcbnl_get_state,
822 .setstate = ixgbe_dcbnl_set_state,
823 .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
824 .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
825 .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
826 .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
827 .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
828 .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
829 .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
830 .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
831 .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
832 .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
833 .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
834 .setall = ixgbe_dcbnl_set_all,
835 .getcap = ixgbe_dcbnl_getcap,
836 .getnumtcs = ixgbe_dcbnl_getnumtcs,
837 .setnumtcs = ixgbe_dcbnl_setnumtcs,
838 .getpfcstate = ixgbe_dcbnl_getpfcstate,
839 .setpfcstate = ixgbe_dcbnl_setpfcstate,
840 .getapp = ixgbe_dcbnl_getapp,
841 .setapp = ixgbe_dcbnl_setapp,
842 .getdcbx = ixgbe_dcbnl_getdcbx,
843 .setdcbx = ixgbe_dcbnl_setdcbx,