ixgbe: DCB, do not reset on CEE pg changes
[deliverable/linux.git] / drivers / net / ixgbe / ixgbe_dcb_nl.c
1 /*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2010 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
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_RESETLINK 0x40
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
48 int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
49 struct ixgbe_dcb_config *dst_dcb_cfg, int tc_max)
50 {
51 struct tc_configuration *src_tc_cfg = NULL;
52 struct tc_configuration *dst_tc_cfg = NULL;
53 int i;
54
55 if (!src_dcb_cfg || !dst_dcb_cfg)
56 return -EINVAL;
57
58 for (i = DCB_PG_ATTR_TC_0; i < tc_max + DCB_PG_ATTR_TC_0; i++) {
59 src_tc_cfg = &src_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0];
60 dst_tc_cfg = &dst_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0];
61
62 dst_tc_cfg->path[DCB_TX_CONFIG].prio_type =
63 src_tc_cfg->path[DCB_TX_CONFIG].prio_type;
64
65 dst_tc_cfg->path[DCB_TX_CONFIG].bwg_id =
66 src_tc_cfg->path[DCB_TX_CONFIG].bwg_id;
67
68 dst_tc_cfg->path[DCB_TX_CONFIG].bwg_percent =
69 src_tc_cfg->path[DCB_TX_CONFIG].bwg_percent;
70
71 dst_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap =
72 src_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap;
73
74 dst_tc_cfg->path[DCB_RX_CONFIG].prio_type =
75 src_tc_cfg->path[DCB_RX_CONFIG].prio_type;
76
77 dst_tc_cfg->path[DCB_RX_CONFIG].bwg_id =
78 src_tc_cfg->path[DCB_RX_CONFIG].bwg_id;
79
80 dst_tc_cfg->path[DCB_RX_CONFIG].bwg_percent =
81 src_tc_cfg->path[DCB_RX_CONFIG].bwg_percent;
82
83 dst_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap =
84 src_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap;
85 }
86
87 for (i = DCB_PG_ATTR_BW_ID_0; i < DCB_PG_ATTR_BW_ID_MAX; i++) {
88 dst_dcb_cfg->bw_percentage[DCB_TX_CONFIG]
89 [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage
90 [DCB_TX_CONFIG][i-DCB_PG_ATTR_BW_ID_0];
91 dst_dcb_cfg->bw_percentage[DCB_RX_CONFIG]
92 [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage
93 [DCB_RX_CONFIG][i-DCB_PG_ATTR_BW_ID_0];
94 }
95
96 for (i = DCB_PFC_UP_ATTR_0; i < DCB_PFC_UP_ATTR_MAX; i++) {
97 dst_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc =
98 src_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc;
99 }
100
101 dst_dcb_cfg->pfc_mode_enable = src_dcb_cfg->pfc_mode_enable;
102
103 return 0;
104 }
105
106 static u8 ixgbe_dcbnl_get_state(struct net_device *netdev)
107 {
108 struct ixgbe_adapter *adapter = netdev_priv(netdev);
109
110 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
111 }
112
113 static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
114 {
115 u8 err = 0;
116 struct ixgbe_adapter *adapter = netdev_priv(netdev);
117
118 if (state > 0) {
119 /* Turn on DCB */
120 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
121 goto out;
122
123 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
124 e_err(drv, "Enable failed, needs MSI-X\n");
125 err = 1;
126 goto out;
127 }
128
129 if (netif_running(netdev))
130 netdev->netdev_ops->ndo_stop(netdev);
131 ixgbe_clear_interrupt_scheme(adapter);
132
133 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
134 switch (adapter->hw.mac.type) {
135 case ixgbe_mac_82598EB:
136 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
137 adapter->hw.fc.requested_mode = ixgbe_fc_none;
138 break;
139 case ixgbe_mac_82599EB:
140 case ixgbe_mac_X540:
141 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
142 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
143 break;
144 default:
145 break;
146 }
147
148 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
149 ixgbe_init_interrupt_scheme(adapter);
150 if (netif_running(netdev))
151 netdev->netdev_ops->ndo_open(netdev);
152 } else {
153 /* Turn off DCB */
154 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
155 if (netif_running(netdev))
156 netdev->netdev_ops->ndo_stop(netdev);
157 ixgbe_clear_interrupt_scheme(adapter);
158
159 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
160 adapter->temp_dcb_cfg.pfc_mode_enable = false;
161 adapter->dcb_cfg.pfc_mode_enable = false;
162 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
163 adapter->flags |= IXGBE_FLAG_RSS_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;
171 }
172
173 ixgbe_init_interrupt_scheme(adapter);
174 if (netif_running(netdev))
175 netdev->netdev_ops->ndo_open(netdev);
176 }
177 }
178 out:
179 return err;
180 }
181
182 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
183 u8 *perm_addr)
184 {
185 struct ixgbe_adapter *adapter = netdev_priv(netdev);
186 int i, j;
187
188 memset(perm_addr, 0xff, MAX_ADDR_LEN);
189
190 for (i = 0; i < netdev->addr_len; i++)
191 perm_addr[i] = adapter->hw.mac.perm_addr[i];
192
193 switch (adapter->hw.mac.type) {
194 case ixgbe_mac_82599EB:
195 case ixgbe_mac_X540:
196 for (j = 0; j < netdev->addr_len; j++, i++)
197 perm_addr[i] = adapter->hw.mac.san_addr[j];
198 break;
199 default:
200 break;
201 }
202 }
203
204 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
205 u8 prio, u8 bwg_id, u8 bw_pct,
206 u8 up_map)
207 {
208 struct ixgbe_adapter *adapter = netdev_priv(netdev);
209
210 if (prio != DCB_ATTR_VALUE_UNDEFINED)
211 adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio;
212 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
213 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id;
214 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
215 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent =
216 bw_pct;
217 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
218 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
219 up_map;
220
221 if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type !=
222 adapter->dcb_cfg.tc_config[tc].path[0].prio_type) ||
223 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id !=
224 adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) ||
225 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent !=
226 adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) ||
227 (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
228 adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap))
229 adapter->dcb_set_bitmap |= BIT_PG_TX;
230 }
231
232 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
233 u8 bw_pct)
234 {
235 struct ixgbe_adapter *adapter = netdev_priv(netdev);
236
237 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
238
239 if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
240 adapter->dcb_cfg.bw_percentage[0][bwg_id])
241 adapter->dcb_set_bitmap |= BIT_PG_TX;
242 }
243
244 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
245 u8 prio, u8 bwg_id, u8 bw_pct,
246 u8 up_map)
247 {
248 struct ixgbe_adapter *adapter = netdev_priv(netdev);
249
250 if (prio != DCB_ATTR_VALUE_UNDEFINED)
251 adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
252 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
253 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
254 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
255 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
256 bw_pct;
257 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
258 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
259 up_map;
260
261 if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
262 adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
263 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
264 adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
265 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
266 adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
267 (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
268 adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap))
269 adapter->dcb_set_bitmap |= BIT_PG_RX;
270 }
271
272 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
273 u8 bw_pct)
274 {
275 struct ixgbe_adapter *adapter = netdev_priv(netdev);
276
277 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
278
279 if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
280 adapter->dcb_cfg.bw_percentage[1][bwg_id])
281 adapter->dcb_set_bitmap |= BIT_PG_RX;
282 }
283
284 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
285 u8 *prio, u8 *bwg_id, u8 *bw_pct,
286 u8 *up_map)
287 {
288 struct ixgbe_adapter *adapter = netdev_priv(netdev);
289
290 *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
291 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
292 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
293 *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
294 }
295
296 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
297 u8 *bw_pct)
298 {
299 struct ixgbe_adapter *adapter = netdev_priv(netdev);
300
301 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
302 }
303
304 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
305 u8 *prio, u8 *bwg_id, u8 *bw_pct,
306 u8 *up_map)
307 {
308 struct ixgbe_adapter *adapter = netdev_priv(netdev);
309
310 *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
311 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
312 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
313 *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
314 }
315
316 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
317 u8 *bw_pct)
318 {
319 struct ixgbe_adapter *adapter = netdev_priv(netdev);
320
321 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
322 }
323
324 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
325 u8 setting)
326 {
327 struct ixgbe_adapter *adapter = netdev_priv(netdev);
328
329 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
330 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
331 adapter->dcb_cfg.tc_config[priority].dcb_pfc) {
332 adapter->dcb_set_bitmap |= BIT_PFC;
333 adapter->temp_dcb_cfg.pfc_mode_enable = true;
334 }
335 }
336
337 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
338 u8 *setting)
339 {
340 struct ixgbe_adapter *adapter = netdev_priv(netdev);
341
342 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
343 }
344
345 static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
346 {
347 struct ixgbe_adapter *adapter = netdev_priv(netdev);
348 bool do_reset;
349 int ret;
350
351 if (!adapter->dcb_set_bitmap)
352 return DCB_NO_HW_CHG;
353
354 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
355 adapter->ring_feature[RING_F_DCB].indices);
356
357 if (ret)
358 return DCB_NO_HW_CHG;
359
360 /*
361 * Only take down the adapter if the configuration change
362 * requires a reset.
363 */
364 do_reset = adapter->dcb_set_bitmap & (BIT_RESETLINK | BIT_APP_UPCHG);
365
366 if (do_reset) {
367 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
368 msleep(1);
369
370 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
371 if (netif_running(netdev))
372 netdev->netdev_ops->ndo_stop(netdev);
373 ixgbe_clear_interrupt_scheme(adapter);
374 } else {
375 if (netif_running(netdev))
376 ixgbe_down(adapter);
377 }
378 }
379
380 if (adapter->dcb_cfg.pfc_mode_enable) {
381 switch (adapter->hw.mac.type) {
382 case ixgbe_mac_82599EB:
383 case ixgbe_mac_X540:
384 if (adapter->hw.fc.current_mode != ixgbe_fc_pfc)
385 adapter->last_lfc_mode =
386 adapter->hw.fc.current_mode;
387 break;
388 default:
389 break;
390 }
391 adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
392 } else {
393 switch (adapter->hw.mac.type) {
394 case ixgbe_mac_82598EB:
395 adapter->hw.fc.requested_mode = ixgbe_fc_none;
396 break;
397 case ixgbe_mac_82599EB:
398 case ixgbe_mac_X540:
399 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
400 break;
401 default:
402 break;
403 }
404 }
405
406 if (do_reset) {
407 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
408 ixgbe_init_interrupt_scheme(adapter);
409 if (netif_running(netdev))
410 netdev->netdev_ops->ndo_open(netdev);
411 } else {
412 if (netif_running(netdev))
413 ixgbe_up(adapter);
414 }
415 ret = DCB_HW_CHG_RST;
416 }
417
418 if (adapter->dcb_set_bitmap & BIT_PFC) {
419 u8 pfc_en;
420 ixgbe_dcb_unpack_pfc(&adapter->dcb_cfg, &pfc_en);
421
422 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
423 ixgbe_dcb_config_pfc_82598(&adapter->hw, pfc_en);
424 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
425 ixgbe_dcb_config_pfc_82599(&adapter->hw, pfc_en);
426 ret = DCB_HW_CHG;
427 }
428
429 if (adapter->dcb_set_bitmap & (BIT_PG_TX|BIT_PG_RX)) {
430 u16 refill[MAX_TRAFFIC_CLASS], max[MAX_TRAFFIC_CLASS];
431 u8 bwg_id[MAX_TRAFFIC_CLASS], prio_type[MAX_TRAFFIC_CLASS];
432 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
433
434 #ifdef CONFIG_FCOE
435 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
436 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
437 #endif
438
439 ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
440 max_frame, DCB_TX_CONFIG);
441 ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
442 max_frame, DCB_RX_CONFIG);
443
444 ixgbe_dcb_unpack_refill(&adapter->dcb_cfg,
445 DCB_TX_CONFIG, refill);
446 ixgbe_dcb_unpack_max(&adapter->dcb_cfg, max);
447 ixgbe_dcb_unpack_bwgid(&adapter->dcb_cfg,
448 DCB_TX_CONFIG, bwg_id);
449 ixgbe_dcb_unpack_prio(&adapter->dcb_cfg,
450 DCB_TX_CONFIG, prio_type);
451
452 ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
453 bwg_id, prio_type);
454 }
455
456 if (adapter->dcb_cfg.pfc_mode_enable)
457 adapter->hw.fc.current_mode = ixgbe_fc_pfc;
458
459 if (do_reset)
460 clear_bit(__IXGBE_RESETTING, &adapter->state);
461 adapter->dcb_set_bitmap = 0x00;
462 return ret;
463 }
464
465 static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
466 {
467 struct ixgbe_adapter *adapter = netdev_priv(netdev);
468 u8 rval = 0;
469
470 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
471 switch (capid) {
472 case DCB_CAP_ATTR_PG:
473 *cap = true;
474 break;
475 case DCB_CAP_ATTR_PFC:
476 *cap = true;
477 break;
478 case DCB_CAP_ATTR_UP2TC:
479 *cap = false;
480 break;
481 case DCB_CAP_ATTR_PG_TCS:
482 *cap = 0x80;
483 break;
484 case DCB_CAP_ATTR_PFC_TCS:
485 *cap = 0x80;
486 break;
487 case DCB_CAP_ATTR_GSP:
488 *cap = true;
489 break;
490 case DCB_CAP_ATTR_BCN:
491 *cap = false;
492 break;
493 default:
494 rval = -EINVAL;
495 break;
496 }
497 } else {
498 rval = -EINVAL;
499 }
500
501 return rval;
502 }
503
504 static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
505 {
506 struct ixgbe_adapter *adapter = netdev_priv(netdev);
507 u8 rval = 0;
508
509 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
510 switch (tcid) {
511 case DCB_NUMTCS_ATTR_PG:
512 *num = MAX_TRAFFIC_CLASS;
513 break;
514 case DCB_NUMTCS_ATTR_PFC:
515 *num = MAX_TRAFFIC_CLASS;
516 break;
517 default:
518 rval = -EINVAL;
519 break;
520 }
521 } else {
522 rval = -EINVAL;
523 }
524
525 return rval;
526 }
527
528 static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
529 {
530 return -EINVAL;
531 }
532
533 static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
534 {
535 struct ixgbe_adapter *adapter = netdev_priv(netdev);
536
537 return adapter->dcb_cfg.pfc_mode_enable;
538 }
539
540 static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
541 {
542 struct ixgbe_adapter *adapter = netdev_priv(netdev);
543
544 adapter->temp_dcb_cfg.pfc_mode_enable = state;
545 if (adapter->temp_dcb_cfg.pfc_mode_enable !=
546 adapter->dcb_cfg.pfc_mode_enable)
547 adapter->dcb_set_bitmap |= BIT_PFC;
548 }
549
550 /**
551 * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
552 * @netdev : the corresponding netdev
553 * @idtype : identifies the id as ether type or TCP/UDP port number
554 * @id: id is either ether type or TCP/UDP port number
555 *
556 * Returns : on success, returns a non-zero 802.1p user priority bitmap
557 * otherwise returns 0 as the invalid user priority bitmap to indicate an
558 * error.
559 */
560 static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
561 {
562 u8 rval = 0;
563
564 switch (idtype) {
565 case DCB_APP_IDTYPE_ETHTYPE:
566 #ifdef IXGBE_FCOE
567 if (id == ETH_P_FCOE)
568 rval = ixgbe_fcoe_getapp(netdev_priv(netdev));
569 #endif
570 break;
571 case DCB_APP_IDTYPE_PORTNUM:
572 break;
573 default:
574 break;
575 }
576 return rval;
577 }
578
579 /**
580 * ixgbe_dcbnl_setapp - set the DCBX application user priority
581 * @netdev : the corresponding netdev
582 * @idtype : identifies the id as ether type or TCP/UDP port number
583 * @id: id is either ether type or TCP/UDP port number
584 * @up: the 802.1p user priority bitmap
585 *
586 * Returns : 0 on success or 1 on error
587 */
588 static u8 ixgbe_dcbnl_setapp(struct net_device *netdev,
589 u8 idtype, u16 id, u8 up)
590 {
591 u8 rval = 1;
592
593 switch (idtype) {
594 case DCB_APP_IDTYPE_ETHTYPE:
595 #ifdef IXGBE_FCOE
596 if (id == ETH_P_FCOE) {
597 u8 old_tc;
598 struct ixgbe_adapter *adapter = netdev_priv(netdev);
599
600 /* Get current programmed tc */
601 old_tc = adapter->fcoe.tc;
602 rval = ixgbe_fcoe_setapp(adapter, up);
603
604 if (rval ||
605 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED) ||
606 !(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
607 break;
608
609 /* The FCoE application priority may be changed multiple
610 * times in quick sucession with switches that build up
611 * TLVs. To avoid creating uneeded device resets this
612 * checks the actual HW configuration and clears
613 * BIT_APP_UPCHG if a HW configuration change is not
614 * need
615 */
616 if (old_tc == adapter->fcoe.tc)
617 adapter->dcb_set_bitmap &= ~BIT_APP_UPCHG;
618 else
619 adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
620 }
621 #endif
622 break;
623 case DCB_APP_IDTYPE_PORTNUM:
624 break;
625 default:
626 break;
627 }
628 return rval;
629 }
630
631 static int ixgbe_dcbnl_ieee_getets(struct net_device *dev,
632 struct ieee_ets *ets)
633 {
634 struct ixgbe_adapter *adapter = netdev_priv(dev);
635 struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets;
636
637 /* No IEEE PFC settings available */
638 if (!my_ets)
639 return -EINVAL;
640
641 ets->ets_cap = MAX_TRAFFIC_CLASS;
642 ets->cbs = my_ets->cbs;
643 memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw));
644 memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw));
645 memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa));
646 memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc));
647 return 0;
648 }
649
650 static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,
651 struct ieee_ets *ets)
652 {
653 struct ixgbe_adapter *adapter = netdev_priv(dev);
654 __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
655 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
656 int err;
657 /* naively give each TC a bwg to map onto CEE hardware */
658 __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
659
660 if (!adapter->ixgbe_ieee_ets) {
661 adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets),
662 GFP_KERNEL);
663 if (!adapter->ixgbe_ieee_ets)
664 return -ENOMEM;
665 }
666
667
668 memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets));
669
670 ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
671 err = ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
672 bwg_id, ets->tc_tsa);
673 return err;
674 }
675
676 static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev,
677 struct ieee_pfc *pfc)
678 {
679 struct ixgbe_adapter *adapter = netdev_priv(dev);
680 struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc;
681 int i;
682
683 /* No IEEE PFC settings available */
684 if (!my_pfc)
685 return -EINVAL;
686
687 pfc->pfc_cap = MAX_TRAFFIC_CLASS;
688 pfc->pfc_en = my_pfc->pfc_en;
689 pfc->mbc = my_pfc->mbc;
690 pfc->delay = my_pfc->delay;
691
692 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
693 pfc->requests[i] = adapter->stats.pxoffrxc[i];
694 pfc->indications[i] = adapter->stats.pxofftxc[i];
695 }
696
697 return 0;
698 }
699
700 static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
701 struct ieee_pfc *pfc)
702 {
703 struct ixgbe_adapter *adapter = netdev_priv(dev);
704 int err;
705
706 if (!adapter->ixgbe_ieee_pfc) {
707 adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc),
708 GFP_KERNEL);
709 if (!adapter->ixgbe_ieee_pfc)
710 return -ENOMEM;
711 }
712
713 memcpy(adapter->ixgbe_ieee_pfc, pfc, sizeof(*adapter->ixgbe_ieee_pfc));
714 err = ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc->pfc_en);
715 return err;
716 }
717
718 const struct dcbnl_rtnl_ops dcbnl_ops = {
719 .ieee_getets = ixgbe_dcbnl_ieee_getets,
720 .ieee_setets = ixgbe_dcbnl_ieee_setets,
721 .ieee_getpfc = ixgbe_dcbnl_ieee_getpfc,
722 .ieee_setpfc = ixgbe_dcbnl_ieee_setpfc,
723 .getstate = ixgbe_dcbnl_get_state,
724 .setstate = ixgbe_dcbnl_set_state,
725 .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
726 .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
727 .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
728 .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
729 .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
730 .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
731 .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
732 .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
733 .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
734 .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
735 .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
736 .setall = ixgbe_dcbnl_set_all,
737 .getcap = ixgbe_dcbnl_getcap,
738 .getnumtcs = ixgbe_dcbnl_getnumtcs,
739 .setnumtcs = ixgbe_dcbnl_setnumtcs,
740 .getpfcstate = ixgbe_dcbnl_getpfcstate,
741 .setpfcstate = ixgbe_dcbnl_setpfcstate,
742 .getapp = ixgbe_dcbnl_getapp,
743 .setapp = ixgbe_dcbnl_setapp,
744 };
745
This page took 0.082651 seconds and 6 git commands to generate.