Loading...
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 1999 - 2018 Intel Corporation. */
3
4#include "ixgbe.h"
5#include <linux/dcbnl.h>
6#include "ixgbe_dcb_82598.h"
7#include "ixgbe_dcb_82599.h"
8#include "ixgbe_sriov.h"
9
10/* Callbacks for DCB netlink in the kernel */
11#define BIT_PFC 0x02
12#define BIT_PG_RX 0x04
13#define BIT_PG_TX 0x08
14#define BIT_APP_UPCHG 0x10
15
16/* Responses for the DCB_C_SET_ALL command */
17#define DCB_HW_CHG_RST 0 /* DCB configuration changed with reset */
18#define DCB_NO_HW_CHG 1 /* DCB configuration did not change */
19#define DCB_HW_CHG 2 /* DCB configuration changed, no reset */
20
21static int ixgbe_copy_dcb_cfg(struct ixgbe_adapter *adapter, int tc_max)
22{
23 struct ixgbe_dcb_config *scfg = &adapter->temp_dcb_cfg;
24 struct ixgbe_dcb_config *dcfg = &adapter->dcb_cfg;
25 struct tc_configuration *src = NULL;
26 struct tc_configuration *dst = NULL;
27 int i, j;
28 int tx = DCB_TX_CONFIG;
29 int rx = DCB_RX_CONFIG;
30 int changes = 0;
31#ifdef IXGBE_FCOE
32 struct dcb_app app = {
33 .selector = DCB_APP_IDTYPE_ETHTYPE,
34 .protocol = ETH_P_FCOE,
35 };
36 u8 up = dcb_getapp(adapter->netdev, &app);
37
38 if (up && !(up & BIT(adapter->fcoe.up)))
39 changes |= BIT_APP_UPCHG;
40#endif
41
42 for (i = DCB_PG_ATTR_TC_0; i < tc_max + DCB_PG_ATTR_TC_0; i++) {
43 src = &scfg->tc_config[i - DCB_PG_ATTR_TC_0];
44 dst = &dcfg->tc_config[i - DCB_PG_ATTR_TC_0];
45
46 if (dst->path[tx].prio_type != src->path[tx].prio_type) {
47 dst->path[tx].prio_type = src->path[tx].prio_type;
48 changes |= BIT_PG_TX;
49 }
50
51 if (dst->path[tx].bwg_id != src->path[tx].bwg_id) {
52 dst->path[tx].bwg_id = src->path[tx].bwg_id;
53 changes |= BIT_PG_TX;
54 }
55
56 if (dst->path[tx].bwg_percent != src->path[tx].bwg_percent) {
57 dst->path[tx].bwg_percent = src->path[tx].bwg_percent;
58 changes |= BIT_PG_TX;
59 }
60
61 if (dst->path[tx].up_to_tc_bitmap !=
62 src->path[tx].up_to_tc_bitmap) {
63 dst->path[tx].up_to_tc_bitmap =
64 src->path[tx].up_to_tc_bitmap;
65 changes |= (BIT_PG_TX | BIT_PFC | BIT_APP_UPCHG);
66 }
67
68 if (dst->path[rx].prio_type != src->path[rx].prio_type) {
69 dst->path[rx].prio_type = src->path[rx].prio_type;
70 changes |= BIT_PG_RX;
71 }
72
73 if (dst->path[rx].bwg_id != src->path[rx].bwg_id) {
74 dst->path[rx].bwg_id = src->path[rx].bwg_id;
75 changes |= BIT_PG_RX;
76 }
77
78 if (dst->path[rx].bwg_percent != src->path[rx].bwg_percent) {
79 dst->path[rx].bwg_percent = src->path[rx].bwg_percent;
80 changes |= BIT_PG_RX;
81 }
82
83 if (dst->path[rx].up_to_tc_bitmap !=
84 src->path[rx].up_to_tc_bitmap) {
85 dst->path[rx].up_to_tc_bitmap =
86 src->path[rx].up_to_tc_bitmap;
87 changes |= (BIT_PG_RX | BIT_PFC | BIT_APP_UPCHG);
88 }
89 }
90
91 for (i = DCB_PG_ATTR_BW_ID_0; i < DCB_PG_ATTR_BW_ID_MAX; i++) {
92 j = i - DCB_PG_ATTR_BW_ID_0;
93 if (dcfg->bw_percentage[tx][j] != scfg->bw_percentage[tx][j]) {
94 dcfg->bw_percentage[tx][j] = scfg->bw_percentage[tx][j];
95 changes |= BIT_PG_TX;
96 }
97 if (dcfg->bw_percentage[rx][j] != scfg->bw_percentage[rx][j]) {
98 dcfg->bw_percentage[rx][j] = scfg->bw_percentage[rx][j];
99 changes |= BIT_PG_RX;
100 }
101 }
102
103 for (i = DCB_PFC_UP_ATTR_0; i < DCB_PFC_UP_ATTR_MAX; i++) {
104 j = i - DCB_PFC_UP_ATTR_0;
105 if (dcfg->tc_config[j].dcb_pfc != scfg->tc_config[j].dcb_pfc) {
106 dcfg->tc_config[j].dcb_pfc = scfg->tc_config[j].dcb_pfc;
107 changes |= BIT_PFC;
108 }
109 }
110
111 if (dcfg->pfc_mode_enable != scfg->pfc_mode_enable) {
112 dcfg->pfc_mode_enable = scfg->pfc_mode_enable;
113 changes |= BIT_PFC;
114 }
115
116 return changes;
117}
118
119static u8 ixgbe_dcbnl_get_state(struct net_device *netdev)
120{
121 struct ixgbe_adapter *adapter = netdev_priv(netdev);
122
123 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
124}
125
126static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
127{
128 struct ixgbe_adapter *adapter = netdev_priv(netdev);
129
130 /* Fail command if not in CEE mode */
131 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
132 return 1;
133
134 /* verify there is something to do, if not then exit */
135 if (!state == !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
136 return 0;
137
138 return !!ixgbe_setup_tc(netdev,
139 state ? adapter->dcb_cfg.num_tcs.pg_tcs : 0);
140}
141
142static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
143 u8 *perm_addr)
144{
145 struct ixgbe_adapter *adapter = netdev_priv(netdev);
146 int i, j;
147
148 memset(perm_addr, 0xff, MAX_ADDR_LEN);
149
150 for (i = 0; i < netdev->addr_len; i++)
151 perm_addr[i] = adapter->hw.mac.perm_addr[i];
152
153 switch (adapter->hw.mac.type) {
154 case ixgbe_mac_82599EB:
155 case ixgbe_mac_X540:
156 case ixgbe_mac_X550:
157 for (j = 0; j < netdev->addr_len; j++, i++)
158 perm_addr[i] = adapter->hw.mac.san_addr[j];
159 break;
160 default:
161 break;
162 }
163}
164
165static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
166 u8 prio, u8 bwg_id, u8 bw_pct,
167 u8 up_map)
168{
169 struct ixgbe_adapter *adapter = netdev_priv(netdev);
170
171 if (prio != DCB_ATTR_VALUE_UNDEFINED)
172 adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio;
173 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
174 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id;
175 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
176 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent =
177 bw_pct;
178 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
179 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
180 up_map;
181}
182
183static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
184 u8 bw_pct)
185{
186 struct ixgbe_adapter *adapter = netdev_priv(netdev);
187
188 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
189}
190
191static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
192 u8 prio, u8 bwg_id, u8 bw_pct,
193 u8 up_map)
194{
195 struct ixgbe_adapter *adapter = netdev_priv(netdev);
196
197 if (prio != DCB_ATTR_VALUE_UNDEFINED)
198 adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
199 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
200 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
201 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
202 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
203 bw_pct;
204 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
205 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
206 up_map;
207}
208
209static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
210 u8 bw_pct)
211{
212 struct ixgbe_adapter *adapter = netdev_priv(netdev);
213
214 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
215}
216
217static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
218 u8 *prio, u8 *bwg_id, u8 *bw_pct,
219 u8 *up_map)
220{
221 struct ixgbe_adapter *adapter = netdev_priv(netdev);
222
223 *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
224 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
225 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
226 *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
227}
228
229static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
230 u8 *bw_pct)
231{
232 struct ixgbe_adapter *adapter = netdev_priv(netdev);
233
234 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
235}
236
237static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
238 u8 *prio, u8 *bwg_id, u8 *bw_pct,
239 u8 *up_map)
240{
241 struct ixgbe_adapter *adapter = netdev_priv(netdev);
242
243 *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
244 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
245 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
246 *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
247}
248
249static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
250 u8 *bw_pct)
251{
252 struct ixgbe_adapter *adapter = netdev_priv(netdev);
253
254 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
255}
256
257static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
258 u8 setting)
259{
260 struct ixgbe_adapter *adapter = netdev_priv(netdev);
261
262 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
263 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
264 adapter->dcb_cfg.tc_config[priority].dcb_pfc)
265 adapter->temp_dcb_cfg.pfc_mode_enable = true;
266}
267
268static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
269 u8 *setting)
270{
271 struct ixgbe_adapter *adapter = netdev_priv(netdev);
272
273 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
274}
275
276static void ixgbe_dcbnl_devreset(struct net_device *dev)
277{
278 struct ixgbe_adapter *adapter = netdev_priv(dev);
279
280 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
281 usleep_range(1000, 2000);
282
283 if (netif_running(dev))
284 dev->netdev_ops->ndo_stop(dev);
285
286 ixgbe_clear_interrupt_scheme(adapter);
287 ixgbe_init_interrupt_scheme(adapter);
288
289 if (netif_running(dev))
290 dev->netdev_ops->ndo_open(dev);
291
292 clear_bit(__IXGBE_RESETTING, &adapter->state);
293}
294
295static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
296{
297 struct ixgbe_adapter *adapter = netdev_priv(netdev);
298 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
299 struct ixgbe_hw *hw = &adapter->hw;
300 int ret = DCB_NO_HW_CHG;
301 int i;
302
303 /* Fail command if not in CEE mode */
304 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
305 return DCB_NO_HW_CHG;
306
307 adapter->dcb_set_bitmap |= ixgbe_copy_dcb_cfg(adapter,
308 MAX_TRAFFIC_CLASS);
309 if (!adapter->dcb_set_bitmap)
310 return DCB_NO_HW_CHG;
311
312 if (adapter->dcb_set_bitmap & (BIT_PG_TX|BIT_PG_RX)) {
313 u16 refill[MAX_TRAFFIC_CLASS], max[MAX_TRAFFIC_CLASS];
314 u8 bwg_id[MAX_TRAFFIC_CLASS], prio_type[MAX_TRAFFIC_CLASS];
315 /* Priority to TC mapping in CEE case default to 1:1 */
316 u8 prio_tc[MAX_USER_PRIORITY];
317 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
318
319#ifdef IXGBE_FCOE
320 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
321 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
322#endif
323
324 ixgbe_dcb_calculate_tc_credits(hw, dcb_cfg, max_frame,
325 DCB_TX_CONFIG);
326 ixgbe_dcb_calculate_tc_credits(hw, dcb_cfg, max_frame,
327 DCB_RX_CONFIG);
328
329 ixgbe_dcb_unpack_refill(dcb_cfg, DCB_TX_CONFIG, refill);
330 ixgbe_dcb_unpack_max(dcb_cfg, max);
331 ixgbe_dcb_unpack_bwgid(dcb_cfg, DCB_TX_CONFIG, bwg_id);
332 ixgbe_dcb_unpack_prio(dcb_cfg, DCB_TX_CONFIG, prio_type);
333 ixgbe_dcb_unpack_map(dcb_cfg, DCB_TX_CONFIG, prio_tc);
334
335 ixgbe_dcb_hw_ets_config(hw, refill, max, bwg_id,
336 prio_type, prio_tc);
337
338 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
339 netdev_set_prio_tc_map(netdev, i, prio_tc[i]);
340
341 ret = DCB_HW_CHG_RST;
342 }
343
344 if (adapter->dcb_set_bitmap & BIT_PFC) {
345 if (dcb_cfg->pfc_mode_enable) {
346 u8 pfc_en;
347 u8 prio_tc[MAX_USER_PRIORITY];
348
349 ixgbe_dcb_unpack_map(dcb_cfg, DCB_TX_CONFIG, prio_tc);
350 ixgbe_dcb_unpack_pfc(dcb_cfg, &pfc_en);
351 ixgbe_dcb_hw_pfc_config(hw, pfc_en, prio_tc);
352 } else {
353 hw->mac.ops.fc_enable(hw);
354 }
355
356 ixgbe_set_rx_drop_en(adapter);
357
358 ret = DCB_HW_CHG;
359 }
360
361#ifdef IXGBE_FCOE
362 /* Reprogram FCoE hardware offloads when the traffic class
363 * FCoE is using changes. This happens if the APP info
364 * changes or the up2tc mapping is updated.
365 */
366 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
367 struct dcb_app app = {
368 .selector = DCB_APP_IDTYPE_ETHTYPE,
369 .protocol = ETH_P_FCOE,
370 };
371 u8 up = dcb_getapp(netdev, &app);
372
373 adapter->fcoe.up = ffs(up) - 1;
374 ixgbe_dcbnl_devreset(netdev);
375 ret = DCB_HW_CHG_RST;
376 }
377#endif
378
379 adapter->dcb_set_bitmap = 0x00;
380 return ret;
381}
382
383static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
384{
385 struct ixgbe_adapter *adapter = netdev_priv(netdev);
386
387 switch (capid) {
388 case DCB_CAP_ATTR_PG:
389 *cap = true;
390 break;
391 case DCB_CAP_ATTR_PFC:
392 *cap = true;
393 break;
394 case DCB_CAP_ATTR_UP2TC:
395 *cap = false;
396 break;
397 case DCB_CAP_ATTR_PG_TCS:
398 *cap = 0x80;
399 break;
400 case DCB_CAP_ATTR_PFC_TCS:
401 *cap = 0x80;
402 break;
403 case DCB_CAP_ATTR_GSP:
404 *cap = true;
405 break;
406 case DCB_CAP_ATTR_BCN:
407 *cap = false;
408 break;
409 case DCB_CAP_ATTR_DCBX:
410 *cap = adapter->dcbx_cap;
411 break;
412 default:
413 *cap = false;
414 break;
415 }
416
417 return 0;
418}
419
420static int ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
421{
422 struct ixgbe_adapter *adapter = netdev_priv(netdev);
423
424 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
425 switch (tcid) {
426 case DCB_NUMTCS_ATTR_PG:
427 *num = adapter->dcb_cfg.num_tcs.pg_tcs;
428 break;
429 case DCB_NUMTCS_ATTR_PFC:
430 *num = adapter->dcb_cfg.num_tcs.pfc_tcs;
431 break;
432 default:
433 return -EINVAL;
434 }
435 } else {
436 return -EINVAL;
437 }
438
439 return 0;
440}
441
442static int ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
443{
444 return -EINVAL;
445}
446
447static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
448{
449 struct ixgbe_adapter *adapter = netdev_priv(netdev);
450
451 return adapter->dcb_cfg.pfc_mode_enable;
452}
453
454static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
455{
456 struct ixgbe_adapter *adapter = netdev_priv(netdev);
457
458 adapter->temp_dcb_cfg.pfc_mode_enable = state;
459}
460
461/**
462 * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
463 * @netdev : the corresponding netdev
464 * @idtype : identifies the id as ether type or TCP/UDP port number
465 * @id: id is either ether type or TCP/UDP port number
466 *
467 * Returns : on success, returns a non-zero 802.1p user priority bitmap
468 * otherwise returns -EINVAL as the invalid user priority bitmap to indicate an
469 * error.
470 */
471static int ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
472{
473 struct ixgbe_adapter *adapter = netdev_priv(netdev);
474 struct dcb_app app = {
475 .selector = idtype,
476 .protocol = id,
477 };
478
479 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
480 return -EINVAL;
481
482 return dcb_getapp(netdev, &app);
483}
484
485static int ixgbe_dcbnl_ieee_getets(struct net_device *dev,
486 struct ieee_ets *ets)
487{
488 struct ixgbe_adapter *adapter = netdev_priv(dev);
489 struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets;
490
491 ets->ets_cap = adapter->dcb_cfg.num_tcs.pg_tcs;
492
493 /* No IEEE PFC settings available */
494 if (!my_ets)
495 return 0;
496
497 ets->cbs = my_ets->cbs;
498 memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw));
499 memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw));
500 memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa));
501 memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc));
502 return 0;
503}
504
505static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,
506 struct ieee_ets *ets)
507{
508 struct ixgbe_adapter *adapter = netdev_priv(dev);
509 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
510 int i, err;
511 __u8 max_tc = 0;
512 __u8 map_chg = 0;
513
514 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
515 return -EINVAL;
516
517 if (!adapter->ixgbe_ieee_ets) {
518 adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets),
519 GFP_KERNEL);
520 if (!adapter->ixgbe_ieee_ets)
521 return -ENOMEM;
522
523 /* initialize UP2TC mappings to invalid value */
524 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
525 adapter->ixgbe_ieee_ets->prio_tc[i] =
526 IEEE_8021QAZ_MAX_TCS;
527 /* if possible update UP2TC mappings from HW */
528 ixgbe_dcb_read_rtrup2tc(&adapter->hw,
529 adapter->ixgbe_ieee_ets->prio_tc);
530 }
531
532 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
533 if (ets->prio_tc[i] > max_tc)
534 max_tc = ets->prio_tc[i];
535 if (ets->prio_tc[i] != adapter->ixgbe_ieee_ets->prio_tc[i])
536 map_chg = 1;
537 }
538
539 memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets));
540
541 if (max_tc)
542 max_tc++;
543
544 if (max_tc > adapter->dcb_cfg.num_tcs.pg_tcs)
545 return -EINVAL;
546
547 if (max_tc != adapter->hw_tcs) {
548 err = ixgbe_setup_tc(dev, max_tc);
549 if (err)
550 return err;
551 } else if (map_chg) {
552 ixgbe_dcbnl_devreset(dev);
553 }
554
555 return ixgbe_dcb_hw_ets(&adapter->hw, ets, max_frame);
556}
557
558static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev,
559 struct ieee_pfc *pfc)
560{
561 struct ixgbe_adapter *adapter = netdev_priv(dev);
562 struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc;
563 int i;
564
565 pfc->pfc_cap = adapter->dcb_cfg.num_tcs.pfc_tcs;
566
567 /* No IEEE PFC settings available */
568 if (!my_pfc)
569 return 0;
570
571 pfc->pfc_en = my_pfc->pfc_en;
572 pfc->mbc = my_pfc->mbc;
573 pfc->delay = my_pfc->delay;
574
575 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
576 pfc->requests[i] = adapter->stats.pxoffrxc[i];
577 pfc->indications[i] = adapter->stats.pxofftxc[i];
578 }
579
580 return 0;
581}
582
583static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
584 struct ieee_pfc *pfc)
585{
586 struct ixgbe_adapter *adapter = netdev_priv(dev);
587 struct ixgbe_hw *hw = &adapter->hw;
588 u8 *prio_tc;
589 int err;
590
591 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
592 return -EINVAL;
593
594 if (!adapter->ixgbe_ieee_pfc) {
595 adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc),
596 GFP_KERNEL);
597 if (!adapter->ixgbe_ieee_pfc)
598 return -ENOMEM;
599 }
600
601 prio_tc = adapter->ixgbe_ieee_ets->prio_tc;
602 memcpy(adapter->ixgbe_ieee_pfc, pfc, sizeof(*adapter->ixgbe_ieee_pfc));
603
604 /* Enable link flow control parameters if PFC is disabled */
605 if (pfc->pfc_en)
606 err = ixgbe_dcb_hw_pfc_config(hw, pfc->pfc_en, prio_tc);
607 else
608 err = hw->mac.ops.fc_enable(hw);
609
610 ixgbe_set_rx_drop_en(adapter);
611
612 return err;
613}
614
615static int ixgbe_dcbnl_ieee_setapp(struct net_device *dev,
616 struct dcb_app *app)
617{
618 struct ixgbe_adapter *adapter = netdev_priv(dev);
619 int err;
620
621 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
622 return -EINVAL;
623
624 err = dcb_ieee_setapp(dev, app);
625 if (err)
626 return err;
627
628#ifdef IXGBE_FCOE
629 if (app->selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
630 app->protocol == ETH_P_FCOE) {
631 u8 app_mask = dcb_ieee_getapp_mask(dev, app);
632
633 if (app_mask & BIT(adapter->fcoe.up))
634 return 0;
635
636 adapter->fcoe.up = app->priority;
637 ixgbe_dcbnl_devreset(dev);
638 }
639#endif
640
641 /* VF devices should use default UP when available */
642 if (app->selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
643 app->protocol == 0) {
644 int vf;
645
646 adapter->default_up = app->priority;
647
648 for (vf = 0; vf < adapter->num_vfs; vf++) {
649 struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
650
651 if (!vfinfo->pf_qos)
652 ixgbe_set_vmvir(adapter, vfinfo->pf_vlan,
653 app->priority, vf);
654 }
655 }
656
657 return 0;
658}
659
660static int ixgbe_dcbnl_ieee_delapp(struct net_device *dev,
661 struct dcb_app *app)
662{
663 struct ixgbe_adapter *adapter = netdev_priv(dev);
664 int err;
665
666 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
667 return -EINVAL;
668
669 err = dcb_ieee_delapp(dev, app);
670
671#ifdef IXGBE_FCOE
672 if (!err && app->selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
673 app->protocol == ETH_P_FCOE) {
674 u8 app_mask = dcb_ieee_getapp_mask(dev, app);
675
676 if (app_mask & BIT(adapter->fcoe.up))
677 return 0;
678
679 adapter->fcoe.up = app_mask ?
680 ffs(app_mask) - 1 : IXGBE_FCOE_DEFTC;
681 ixgbe_dcbnl_devreset(dev);
682 }
683#endif
684 /* IF default priority is being removed clear VF default UP */
685 if (app->selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
686 app->protocol == 0 && adapter->default_up == app->priority) {
687 int vf;
688 long unsigned int app_mask = dcb_ieee_getapp_mask(dev, app);
689 int qos = app_mask ? find_first_bit(&app_mask, 8) : 0;
690
691 adapter->default_up = qos;
692
693 for (vf = 0; vf < adapter->num_vfs; vf++) {
694 struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
695
696 if (!vfinfo->pf_qos)
697 ixgbe_set_vmvir(adapter, vfinfo->pf_vlan,
698 qos, vf);
699 }
700 }
701
702 return err;
703}
704
705static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev)
706{
707 struct ixgbe_adapter *adapter = netdev_priv(dev);
708 return adapter->dcbx_cap;
709}
710
711static u8 ixgbe_dcbnl_setdcbx(struct net_device *dev, u8 mode)
712{
713 struct ixgbe_adapter *adapter = netdev_priv(dev);
714 struct ieee_ets ets = {0};
715 struct ieee_pfc pfc = {0};
716 int err = 0;
717
718 /* no support for LLD_MANAGED modes or CEE+IEEE */
719 if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
720 ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) ||
721 !(mode & DCB_CAP_DCBX_HOST))
722 return 1;
723
724 if (mode == adapter->dcbx_cap)
725 return 0;
726
727 adapter->dcbx_cap = mode;
728
729 /* ETS and PFC defaults */
730 ets.ets_cap = 8;
731 pfc.pfc_cap = 8;
732
733 if (mode & DCB_CAP_DCBX_VER_IEEE) {
734 ixgbe_dcbnl_ieee_setets(dev, &ets);
735 ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
736 } else if (mode & DCB_CAP_DCBX_VER_CEE) {
737 u8 mask = BIT_PFC | BIT_PG_TX | BIT_PG_RX | BIT_APP_UPCHG;
738
739 adapter->dcb_set_bitmap |= mask;
740 ixgbe_dcbnl_set_all(dev);
741 } else {
742 /* Drop into single TC mode strict priority as this
743 * indicates CEE and IEEE versions are disabled
744 */
745 ixgbe_dcbnl_ieee_setets(dev, &ets);
746 ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
747 err = ixgbe_setup_tc(dev, 0);
748 }
749
750 return err ? 1 : 0;
751}
752
753const struct dcbnl_rtnl_ops ixgbe_dcbnl_ops = {
754 .ieee_getets = ixgbe_dcbnl_ieee_getets,
755 .ieee_setets = ixgbe_dcbnl_ieee_setets,
756 .ieee_getpfc = ixgbe_dcbnl_ieee_getpfc,
757 .ieee_setpfc = ixgbe_dcbnl_ieee_setpfc,
758 .ieee_setapp = ixgbe_dcbnl_ieee_setapp,
759 .ieee_delapp = ixgbe_dcbnl_ieee_delapp,
760 .getstate = ixgbe_dcbnl_get_state,
761 .setstate = ixgbe_dcbnl_set_state,
762 .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
763 .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
764 .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
765 .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
766 .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
767 .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
768 .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
769 .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
770 .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
771 .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
772 .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
773 .setall = ixgbe_dcbnl_set_all,
774 .getcap = ixgbe_dcbnl_getcap,
775 .getnumtcs = ixgbe_dcbnl_getnumtcs,
776 .setnumtcs = ixgbe_dcbnl_setnumtcs,
777 .getpfcstate = ixgbe_dcbnl_getpfcstate,
778 .setpfcstate = ixgbe_dcbnl_setpfcstate,
779 .getapp = ixgbe_dcbnl_getapp,
780 .getdcbx = ixgbe_dcbnl_getdcbx,
781 .setdcbx = ixgbe_dcbnl_setdcbx,
782};
1/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2013 Intel Corporation.
5
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.
9
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.
14
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.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
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
26
27*******************************************************************************/
28
29#include "ixgbe.h"
30#include <linux/dcbnl.h>
31#include "ixgbe_dcb_82598.h"
32#include "ixgbe_dcb_82599.h"
33#include "ixgbe_sriov.h"
34
35/* Callbacks for DCB netlink in the kernel */
36#define BIT_DCB_MODE 0x01
37#define BIT_PFC 0x02
38#define BIT_PG_RX 0x04
39#define BIT_PG_TX 0x08
40#define BIT_APP_UPCHG 0x10
41#define BIT_LINKSPEED 0x80
42
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 */
47
48static int ixgbe_copy_dcb_cfg(struct ixgbe_adapter *adapter, int tc_max)
49{
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;
54 int i, j;
55 int tx = DCB_TX_CONFIG;
56 int rx = DCB_RX_CONFIG;
57 int changes = 0;
58#ifdef IXGBE_FCOE
59 struct dcb_app app = {
60 .selector = DCB_APP_IDTYPE_ETHTYPE,
61 .protocol = ETH_P_FCOE,
62 };
63 u8 up = dcb_getapp(adapter->netdev, &app);
64
65 if (up && !(up & (1 << adapter->fcoe.up)))
66 changes |= BIT_APP_UPCHG;
67#endif
68
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];
72
73 if (dst->path[tx].prio_type != src->path[tx].prio_type) {
74 dst->path[tx].prio_type = src->path[tx].prio_type;
75 changes |= BIT_PG_TX;
76 }
77
78 if (dst->path[tx].bwg_id != src->path[tx].bwg_id) {
79 dst->path[tx].bwg_id = src->path[tx].bwg_id;
80 changes |= BIT_PG_TX;
81 }
82
83 if (dst->path[tx].bwg_percent != src->path[tx].bwg_percent) {
84 dst->path[tx].bwg_percent = src->path[tx].bwg_percent;
85 changes |= BIT_PG_TX;
86 }
87
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);
93 }
94
95 if (dst->path[rx].prio_type != src->path[rx].prio_type) {
96 dst->path[rx].prio_type = src->path[rx].prio_type;
97 changes |= BIT_PG_RX;
98 }
99
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;
103 }
104
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;
108 }
109
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);
115 }
116 }
117
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;
123 }
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;
127 }
128 }
129
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;
134 changes |= BIT_PFC;
135 }
136 }
137
138 if (dcfg->pfc_mode_enable != scfg->pfc_mode_enable) {
139 dcfg->pfc_mode_enable = scfg->pfc_mode_enable;
140 changes |= BIT_PFC;
141 }
142
143 return changes;
144}
145
146static u8 ixgbe_dcbnl_get_state(struct net_device *netdev)
147{
148 struct ixgbe_adapter *adapter = netdev_priv(netdev);
149
150 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
151}
152
153static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
154{
155 struct ixgbe_adapter *adapter = netdev_priv(netdev);
156 int err = 0;
157
158 /* Fail command if not in CEE mode */
159 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
160 return 1;
161
162 /* verify there is something to do, if not then exit */
163 if (!state == !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
164 goto out;
165
166 err = ixgbe_setup_tc(netdev,
167 state ? adapter->dcb_cfg.num_tcs.pg_tcs : 0);
168out:
169 return !!err;
170}
171
172static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
173 u8 *perm_addr)
174{
175 struct ixgbe_adapter *adapter = netdev_priv(netdev);
176 int i, j;
177
178 memset(perm_addr, 0xff, MAX_ADDR_LEN);
179
180 for (i = 0; i < netdev->addr_len; i++)
181 perm_addr[i] = adapter->hw.mac.perm_addr[i];
182
183 switch (adapter->hw.mac.type) {
184 case ixgbe_mac_82599EB:
185 case ixgbe_mac_X540:
186 for (j = 0; j < netdev->addr_len; j++, i++)
187 perm_addr[i] = adapter->hw.mac.san_addr[j];
188 break;
189 default:
190 break;
191 }
192}
193
194static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
195 u8 prio, u8 bwg_id, u8 bw_pct,
196 u8 up_map)
197{
198 struct ixgbe_adapter *adapter = netdev_priv(netdev);
199
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 =
206 bw_pct;
207 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
208 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
209 up_map;
210}
211
212static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
213 u8 bw_pct)
214{
215 struct ixgbe_adapter *adapter = netdev_priv(netdev);
216
217 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
218}
219
220static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
221 u8 prio, u8 bwg_id, u8 bw_pct,
222 u8 up_map)
223{
224 struct ixgbe_adapter *adapter = netdev_priv(netdev);
225
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 =
232 bw_pct;
233 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
234 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
235 up_map;
236}
237
238static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
239 u8 bw_pct)
240{
241 struct ixgbe_adapter *adapter = netdev_priv(netdev);
242
243 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
244}
245
246static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
247 u8 *prio, u8 *bwg_id, u8 *bw_pct,
248 u8 *up_map)
249{
250 struct ixgbe_adapter *adapter = netdev_priv(netdev);
251
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;
256}
257
258static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
259 u8 *bw_pct)
260{
261 struct ixgbe_adapter *adapter = netdev_priv(netdev);
262
263 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
264}
265
266static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
267 u8 *prio, u8 *bwg_id, u8 *bw_pct,
268 u8 *up_map)
269{
270 struct ixgbe_adapter *adapter = netdev_priv(netdev);
271
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;
276}
277
278static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
279 u8 *bw_pct)
280{
281 struct ixgbe_adapter *adapter = netdev_priv(netdev);
282
283 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
284}
285
286static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
287 u8 setting)
288{
289 struct ixgbe_adapter *adapter = netdev_priv(netdev);
290
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;
295}
296
297static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
298 u8 *setting)
299{
300 struct ixgbe_adapter *adapter = netdev_priv(netdev);
301
302 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
303}
304
305static void ixgbe_dcbnl_devreset(struct net_device *dev)
306{
307 struct ixgbe_adapter *adapter = netdev_priv(dev);
308
309 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
310 usleep_range(1000, 2000);
311
312 if (netif_running(dev))
313 dev->netdev_ops->ndo_stop(dev);
314
315 ixgbe_clear_interrupt_scheme(adapter);
316 ixgbe_init_interrupt_scheme(adapter);
317
318 if (netif_running(dev))
319 dev->netdev_ops->ndo_open(dev);
320
321 clear_bit(__IXGBE_RESETTING, &adapter->state);
322}
323
324static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
325{
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;
330 int i;
331
332 /* Fail command if not in CEE mode */
333 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
334 return ret;
335
336 adapter->dcb_set_bitmap |= ixgbe_copy_dcb_cfg(adapter,
337 MAX_TRAFFIC_CLASS);
338 if (!adapter->dcb_set_bitmap)
339 return ret;
340
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;
347
348#ifdef IXGBE_FCOE
349 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
350 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
351#endif
352
353 ixgbe_dcb_calculate_tc_credits(hw, dcb_cfg, max_frame,
354 DCB_TX_CONFIG);
355 ixgbe_dcb_calculate_tc_credits(hw, dcb_cfg, max_frame,
356 DCB_RX_CONFIG);
357
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);
363
364 ixgbe_dcb_hw_ets_config(hw, refill, max, bwg_id,
365 prio_type, prio_tc);
366
367 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
368 netdev_set_prio_tc_map(netdev, i, prio_tc[i]);
369
370 ret = DCB_HW_CHG_RST;
371 }
372
373 if (adapter->dcb_set_bitmap & BIT_PFC) {
374 if (dcb_cfg->pfc_mode_enable) {
375 u8 pfc_en;
376 u8 prio_tc[MAX_USER_PRIORITY];
377
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);
381 } else {
382 hw->mac.ops.fc_enable(hw);
383 }
384
385 ixgbe_set_rx_drop_en(adapter);
386
387 ret = DCB_HW_CHG;
388 }
389
390#ifdef IXGBE_FCOE
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.
394 */
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,
399 };
400 u8 up = dcb_getapp(netdev, &app);
401
402 adapter->fcoe.up = ffs(up) - 1;
403 ixgbe_dcbnl_devreset(netdev);
404 ret = DCB_HW_CHG_RST;
405 }
406#endif
407
408 adapter->dcb_set_bitmap = 0x00;
409 return ret;
410}
411
412static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
413{
414 struct ixgbe_adapter *adapter = netdev_priv(netdev);
415
416 switch (capid) {
417 case DCB_CAP_ATTR_PG:
418 *cap = true;
419 break;
420 case DCB_CAP_ATTR_PFC:
421 *cap = true;
422 break;
423 case DCB_CAP_ATTR_UP2TC:
424 *cap = false;
425 break;
426 case DCB_CAP_ATTR_PG_TCS:
427 *cap = 0x80;
428 break;
429 case DCB_CAP_ATTR_PFC_TCS:
430 *cap = 0x80;
431 break;
432 case DCB_CAP_ATTR_GSP:
433 *cap = true;
434 break;
435 case DCB_CAP_ATTR_BCN:
436 *cap = false;
437 break;
438 case DCB_CAP_ATTR_DCBX:
439 *cap = adapter->dcbx_cap;
440 break;
441 default:
442 *cap = false;
443 break;
444 }
445
446 return 0;
447}
448
449static int ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
450{
451 struct ixgbe_adapter *adapter = netdev_priv(netdev);
452
453 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
454 switch (tcid) {
455 case DCB_NUMTCS_ATTR_PG:
456 *num = adapter->dcb_cfg.num_tcs.pg_tcs;
457 break;
458 case DCB_NUMTCS_ATTR_PFC:
459 *num = adapter->dcb_cfg.num_tcs.pfc_tcs;
460 break;
461 default:
462 return -EINVAL;
463 break;
464 }
465 } else {
466 return -EINVAL;
467 }
468
469 return 0;
470}
471
472static int ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
473{
474 return -EINVAL;
475}
476
477static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
478{
479 struct ixgbe_adapter *adapter = netdev_priv(netdev);
480
481 return adapter->dcb_cfg.pfc_mode_enable;
482}
483
484static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
485{
486 struct ixgbe_adapter *adapter = netdev_priv(netdev);
487
488 adapter->temp_dcb_cfg.pfc_mode_enable = state;
489}
490
491/**
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
496 *
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
499 * error.
500 */
501static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
502{
503 struct ixgbe_adapter *adapter = netdev_priv(netdev);
504 struct dcb_app app = {
505 .selector = idtype,
506 .protocol = id,
507 };
508
509 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
510 return 0;
511
512 return dcb_getapp(netdev, &app);
513}
514
515static int ixgbe_dcbnl_ieee_getets(struct net_device *dev,
516 struct ieee_ets *ets)
517{
518 struct ixgbe_adapter *adapter = netdev_priv(dev);
519 struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets;
520
521 ets->ets_cap = adapter->dcb_cfg.num_tcs.pg_tcs;
522
523 /* No IEEE PFC settings available */
524 if (!my_ets)
525 return 0;
526
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));
532 return 0;
533}
534
535static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,
536 struct ieee_ets *ets)
537{
538 struct ixgbe_adapter *adapter = netdev_priv(dev);
539 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
540 int i, err = 0;
541 __u8 max_tc = 0;
542 __u8 map_chg = 0;
543
544 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
545 return -EINVAL;
546
547 if (!adapter->ixgbe_ieee_ets) {
548 adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets),
549 GFP_KERNEL);
550 if (!adapter->ixgbe_ieee_ets)
551 return -ENOMEM;
552
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);
560 }
561
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])
566 map_chg = 1;
567 }
568
569 memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets));
570
571 if (max_tc)
572 max_tc++;
573
574 if (max_tc > adapter->dcb_cfg.num_tcs.pg_tcs)
575 return -EINVAL;
576
577 if (max_tc != netdev_get_num_tc(dev))
578 err = ixgbe_setup_tc(dev, max_tc);
579 else if (map_chg)
580 ixgbe_dcbnl_devreset(dev);
581
582 if (err)
583 goto err_out;
584
585 err = ixgbe_dcb_hw_ets(&adapter->hw, ets, max_frame);
586err_out:
587 return err;
588}
589
590static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev,
591 struct ieee_pfc *pfc)
592{
593 struct ixgbe_adapter *adapter = netdev_priv(dev);
594 struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc;
595 int i;
596
597 pfc->pfc_cap = adapter->dcb_cfg.num_tcs.pfc_tcs;
598
599 /* No IEEE PFC settings available */
600 if (!my_pfc)
601 return 0;
602
603 pfc->pfc_en = my_pfc->pfc_en;
604 pfc->mbc = my_pfc->mbc;
605 pfc->delay = my_pfc->delay;
606
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];
610 }
611
612 return 0;
613}
614
615static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
616 struct ieee_pfc *pfc)
617{
618 struct ixgbe_adapter *adapter = netdev_priv(dev);
619 struct ixgbe_hw *hw = &adapter->hw;
620 u8 *prio_tc;
621 int err;
622
623 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
624 return -EINVAL;
625
626 if (!adapter->ixgbe_ieee_pfc) {
627 adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc),
628 GFP_KERNEL);
629 if (!adapter->ixgbe_ieee_pfc)
630 return -ENOMEM;
631 }
632
633 prio_tc = adapter->ixgbe_ieee_ets->prio_tc;
634 memcpy(adapter->ixgbe_ieee_pfc, pfc, sizeof(*adapter->ixgbe_ieee_pfc));
635
636 /* Enable link flow control parameters if PFC is disabled */
637 if (pfc->pfc_en)
638 err = ixgbe_dcb_hw_pfc_config(hw, pfc->pfc_en, prio_tc);
639 else
640 err = hw->mac.ops.fc_enable(hw);
641
642 ixgbe_set_rx_drop_en(adapter);
643
644 return err;
645}
646
647static int ixgbe_dcbnl_ieee_setapp(struct net_device *dev,
648 struct dcb_app *app)
649{
650 struct ixgbe_adapter *adapter = netdev_priv(dev);
651 int err = -EINVAL;
652
653 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
654 return err;
655
656 err = dcb_ieee_setapp(dev, app);
657 if (err)
658 return err;
659
660#ifdef IXGBE_FCOE
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);
664
665 if (app_mask & (1 << adapter->fcoe.up))
666 return err;
667
668 adapter->fcoe.up = app->priority;
669 ixgbe_dcbnl_devreset(dev);
670 }
671#endif
672
673 /* VF devices should use default UP when available */
674 if (app->selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
675 app->protocol == 0) {
676 int vf;
677
678 adapter->default_up = app->priority;
679
680 for (vf = 0; vf < adapter->num_vfs; vf++) {
681 struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
682
683 if (!vfinfo->pf_qos)
684 ixgbe_set_vmvir(adapter, vfinfo->pf_vlan,
685 app->priority, vf);
686 }
687 }
688
689 return 0;
690}
691
692static int ixgbe_dcbnl_ieee_delapp(struct net_device *dev,
693 struct dcb_app *app)
694{
695 struct ixgbe_adapter *adapter = netdev_priv(dev);
696 int err;
697
698 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
699 return -EINVAL;
700
701 err = dcb_ieee_delapp(dev, app);
702
703#ifdef IXGBE_FCOE
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);
707
708 if (app_mask & (1 << adapter->fcoe.up))
709 return err;
710
711 adapter->fcoe.up = app_mask ?
712 ffs(app_mask) - 1 : IXGBE_FCOE_DEFTC;
713 ixgbe_dcbnl_devreset(dev);
714 }
715#endif
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) {
719 int vf;
720 long unsigned int app_mask = dcb_ieee_getapp_mask(dev, app);
721 int qos = app_mask ? find_first_bit(&app_mask, 8) : 0;
722
723 adapter->default_up = qos;
724
725 for (vf = 0; vf < adapter->num_vfs; vf++) {
726 struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
727
728 if (!vfinfo->pf_qos)
729 ixgbe_set_vmvir(adapter, vfinfo->pf_vlan,
730 qos, vf);
731 }
732 }
733
734 return err;
735}
736
737static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev)
738{
739 struct ixgbe_adapter *adapter = netdev_priv(dev);
740 return adapter->dcbx_cap;
741}
742
743static u8 ixgbe_dcbnl_setdcbx(struct net_device *dev, u8 mode)
744{
745 struct ixgbe_adapter *adapter = netdev_priv(dev);
746 struct ieee_ets ets = {0};
747 struct ieee_pfc pfc = {0};
748 int err = 0;
749
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))
754 return 1;
755
756 if (mode == adapter->dcbx_cap)
757 return 0;
758
759 adapter->dcbx_cap = mode;
760
761 /* ETS and PFC defaults */
762 ets.ets_cap = 8;
763 pfc.pfc_cap = 8;
764
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;
770
771 adapter->dcb_set_bitmap |= mask;
772 ixgbe_dcbnl_set_all(dev);
773 } else {
774 /* Drop into single TC mode strict priority as this
775 * indicates CEE and IEEE versions are disabled
776 */
777 ixgbe_dcbnl_ieee_setets(dev, &ets);
778 ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
779 err = ixgbe_setup_tc(dev, 0);
780 }
781
782 return err ? 1 : 0;
783}
784
785const 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,
814};