rename dev_hw_addr_random and remove redundant second
[linux/fpc-iii.git] / drivers / net / ethernet / intel / ixgbe / ixgbe_dcb_nl.c
blob79a92fe987b997d203d6afde03f428bed78bb7fb
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
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 u8 prio_tc[MAX_USER_PRIORITY] = {0};
116 int i;
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))
121 return 1;
123 /* verify there is something to do, if not then exit */
124 if (!!state != !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
125 return err;
127 if (state > 0) {
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);
130 } else {
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]);
137 return err;
140 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
141 u8 *perm_addr)
143 struct ixgbe_adapter *adapter = netdev_priv(netdev);
144 int i, j;
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:
153 case ixgbe_mac_X540:
154 for (j = 0; j < netdev->addr_len; j++, i++)
155 perm_addr[i] = adapter->hw.mac.san_addr[j];
156 break;
157 default:
158 break;
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,
164 u8 up_map)
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 =
174 bw_pct;
175 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
176 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
177 up_map;
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,
195 u8 bw_pct)
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,
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[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 =
218 bw_pct;
219 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
220 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
221 up_map;
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,
239 u8 bw_pct)
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,
252 u8 *up_map)
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,
263 u8 *bw_pct)
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,
272 u8 *up_map)
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,
283 u8 *bw_pct)
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,
291 u8 setting)
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,
304 u8 *setting)
306 struct ixgbe_adapter *adapter = netdev_priv(netdev);
308 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
311 #ifdef IXGBE_FCOE
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);
330 #endif
332 static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
334 struct ixgbe_adapter *adapter = netdev_priv(netdev);
335 int ret, i;
336 #ifdef IXGBE_FCOE
337 struct dcb_app app = {
338 .selector = DCB_APP_IDTYPE_ETHTYPE,
339 .protocol = ETH_P_FCOE,
341 u8 up;
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);
347 } else {
348 up = dcb_getapp(netdev, &app);
350 #endif
352 /* Fail command if not in CEE mode */
353 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
354 return 1;
356 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
357 MAX_TRAFFIC_CLASS);
358 if (ret)
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:
364 case ixgbe_mac_X540:
365 if (adapter->hw.fc.current_mode != ixgbe_fc_pfc)
366 adapter->last_lfc_mode =
367 adapter->hw.fc.current_mode;
368 break;
369 default:
370 break;
372 adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
373 } else {
374 switch (adapter->hw.mac.type) {
375 case ixgbe_mac_82598EB:
376 adapter->hw.fc.requested_mode = ixgbe_fc_none;
377 break;
378 case ixgbe_mac_82599EB:
379 case ixgbe_mac_X540:
380 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
381 break;
382 default:
383 break;
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;
394 #ifdef IXGBE_FCOE
395 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
396 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
397 #endif
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) {
422 u8 pfc_en;
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);
429 ret = DCB_HW_CHG;
432 if (adapter->dcb_cfg.pfc_mode_enable)
433 adapter->hw.fc.current_mode = ixgbe_fc_pfc;
435 #ifdef IXGBE_FCOE
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;
446 #endif
448 adapter->dcb_set_bitmap = 0x00;
449 return ret;
452 static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
454 struct ixgbe_adapter *adapter = netdev_priv(netdev);
456 switch (capid) {
457 case DCB_CAP_ATTR_PG:
458 *cap = true;
459 break;
460 case DCB_CAP_ATTR_PFC:
461 *cap = true;
462 break;
463 case DCB_CAP_ATTR_UP2TC:
464 *cap = false;
465 break;
466 case DCB_CAP_ATTR_PG_TCS:
467 *cap = 0x80;
468 break;
469 case DCB_CAP_ATTR_PFC_TCS:
470 *cap = 0x80;
471 break;
472 case DCB_CAP_ATTR_GSP:
473 *cap = true;
474 break;
475 case DCB_CAP_ATTR_BCN:
476 *cap = false;
477 break;
478 case DCB_CAP_ATTR_DCBX:
479 *cap = adapter->dcbx_cap;
480 break;
481 default:
482 *cap = false;
483 break;
486 return 0;
489 static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
491 struct ixgbe_adapter *adapter = netdev_priv(netdev);
492 u8 rval = 0;
494 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
495 switch (tcid) {
496 case DCB_NUMTCS_ATTR_PG:
497 *num = adapter->dcb_cfg.num_tcs.pg_tcs;
498 break;
499 case DCB_NUMTCS_ATTR_PFC:
500 *num = adapter->dcb_cfg.num_tcs.pfc_tcs;
501 break;
502 default:
503 rval = -EINVAL;
504 break;
506 } else {
507 rval = -EINVAL;
510 return rval;
513 static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
515 return -EINVAL;
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
543 * error.
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 = {
549 .selector = idtype,
550 .protocol = id,
553 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
554 return 0;
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 */
568 if (!my_ets)
569 return 0;
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));
576 return 0;
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;
584 int i;
585 __u8 max_tc = 0;
587 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
588 return -EINVAL;
590 if (!adapter->ixgbe_ieee_ets) {
591 adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets),
592 GFP_KERNEL);
593 if (!adapter->ixgbe_ieee_ets)
594 return -ENOMEM;
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];
604 if (max_tc)
605 max_tc++;
607 if (max_tc > adapter->dcb_cfg.num_tcs.pg_tcs)
608 return -EINVAL;
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;
624 int i;
626 pfc->pfc_cap = adapter->dcb_cfg.num_tcs.pfc_tcs;
628 /* No IEEE PFC settings available */
629 if (!my_pfc)
630 return 0;
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];
641 return 0;
644 static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
645 struct ieee_pfc *pfc)
647 struct ixgbe_adapter *adapter = netdev_priv(dev);
648 u8 *prio_tc;
650 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
651 return -EINVAL;
653 if (!adapter->ixgbe_ieee_pfc) {
654 adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc),
655 GFP_KERNEL);
656 if (!adapter->ixgbe_ieee_pfc)
657 return -ENOMEM;
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,
666 struct dcb_app *app)
668 struct ixgbe_adapter *adapter = netdev_priv(dev);
669 int err = -EINVAL;
671 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
672 return err;
674 err = dcb_ieee_setapp(dev, app);
676 #ifdef IXGBE_FCOE
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))
682 return err;
684 adapter->fcoe.up = app->priority;
685 ixgbe_dcbnl_devreset(dev);
687 #endif
688 return 0;
691 static int ixgbe_dcbnl_ieee_delapp(struct net_device *dev,
692 struct dcb_app *app)
694 struct ixgbe_adapter *adapter = netdev_priv(dev);
695 int err;
697 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
698 return -EINVAL;
700 err = dcb_ieee_delapp(dev, app);
702 #ifdef IXGBE_FCOE
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))
708 return err;
710 adapter->fcoe.up = app_mask ?
711 ffs(app_mask) - 1 : IXGBE_FCOE_DEFTC;
712 ixgbe_dcbnl_devreset(dev);
714 #endif
715 return err;
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))
734 return 1;
736 if (mode == adapter->dcbx_cap)
737 return 0;
739 adapter->dcbx_cap = mode;
741 /* ETS and PFC defaults */
742 ets.ets_cap = 8;
743 pfc.pfc_cap = 8;
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);
753 } else {
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);
762 return 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,