blob: 5d5d390f84bf8b58ad6e9468279a2bc94797e5d1 [file] [log] [blame]
Alexander Duyck2f90b862008-11-20 20:52:10 -08001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -08004 Copyright(c) 1999 - 2009 Intel Corporation.
Alexander Duyck2f90b862008-11-20 20:52:10 -08005
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
32/* Callbacks for DCB netlink in the kernel */
33#define BIT_DCB_MODE 0x01
34#define BIT_PFC 0x02
35#define BIT_PG_RX 0x04
36#define BIT_PG_TX 0x08
Alexander Duyck859ee3c2008-11-20 21:10:23 -080037#define BIT_BCN 0x10
PJ Waskiewicz235ea822009-02-27 15:44:48 +000038#define BIT_LINKSPEED 0x80
Alexander Duyck2f90b862008-11-20 20:52:10 -080039
40int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
41 struct ixgbe_dcb_config *dst_dcb_cfg, int tc_max)
42{
43 struct tc_configuration *src_tc_cfg = NULL;
44 struct tc_configuration *dst_tc_cfg = NULL;
45 int i;
46
47 if (!src_dcb_cfg || !dst_dcb_cfg)
48 return -EINVAL;
49
50 for (i = DCB_PG_ATTR_TC_0; i < tc_max + DCB_PG_ATTR_TC_0; i++) {
51 src_tc_cfg = &src_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0];
52 dst_tc_cfg = &dst_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0];
53
54 dst_tc_cfg->path[DCB_TX_CONFIG].prio_type =
55 src_tc_cfg->path[DCB_TX_CONFIG].prio_type;
56
57 dst_tc_cfg->path[DCB_TX_CONFIG].bwg_id =
58 src_tc_cfg->path[DCB_TX_CONFIG].bwg_id;
59
60 dst_tc_cfg->path[DCB_TX_CONFIG].bwg_percent =
61 src_tc_cfg->path[DCB_TX_CONFIG].bwg_percent;
62
63 dst_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap =
64 src_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap;
65
66 dst_tc_cfg->path[DCB_RX_CONFIG].prio_type =
67 src_tc_cfg->path[DCB_RX_CONFIG].prio_type;
68
69 dst_tc_cfg->path[DCB_RX_CONFIG].bwg_id =
70 src_tc_cfg->path[DCB_RX_CONFIG].bwg_id;
71
72 dst_tc_cfg->path[DCB_RX_CONFIG].bwg_percent =
73 src_tc_cfg->path[DCB_RX_CONFIG].bwg_percent;
74
75 dst_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap =
76 src_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap;
77 }
78
79 for (i = DCB_PG_ATTR_BW_ID_0; i < DCB_PG_ATTR_BW_ID_MAX; i++) {
80 dst_dcb_cfg->bw_percentage[DCB_TX_CONFIG]
81 [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage
82 [DCB_TX_CONFIG][i-DCB_PG_ATTR_BW_ID_0];
83 dst_dcb_cfg->bw_percentage[DCB_RX_CONFIG]
84 [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage
85 [DCB_RX_CONFIG][i-DCB_PG_ATTR_BW_ID_0];
86 }
87
88 for (i = DCB_PFC_UP_ATTR_0; i < DCB_PFC_UP_ATTR_MAX; i++) {
89 dst_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc =
90 src_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc;
91 }
92
PJ Waskiewiczea4af4f2009-03-31 21:33:25 +000093 dst_dcb_cfg->pfc_mode_enable = src_dcb_cfg->pfc_mode_enable;
94
Alexander Duyck2f90b862008-11-20 20:52:10 -080095 return 0;
96}
97
98static u8 ixgbe_dcbnl_get_state(struct net_device *netdev)
99{
100 struct ixgbe_adapter *adapter = netdev_priv(netdev);
101
102 DPRINTK(DRV, INFO, "Get DCB Admin Mode.\n");
103
104 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
105}
106
Don Skidmore1486a612008-12-21 20:09:50 -0800107static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800108{
Don Skidmore1486a612008-12-21 20:09:50 -0800109 u8 err = 0;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800110 struct ixgbe_adapter *adapter = netdev_priv(netdev);
111
112 DPRINTK(DRV, INFO, "Set DCB Admin Mode.\n");
113
114 if (state > 0) {
115 /* Turn on DCB */
Don Skidmore1486a612008-12-21 20:09:50 -0800116 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
117 goto out;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800118
Don Skidmore1486a612008-12-21 20:09:50 -0800119 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
120 DPRINTK(DRV, ERR, "Enable failed, needs MSI-X\n");
121 err = 1;
122 goto out;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800123 }
Don Skidmore1486a612008-12-21 20:09:50 -0800124
125 if (netif_running(netdev))
126 netdev->netdev_ops->ndo_stop(netdev);
Alexander Duyck7a921c92009-05-06 10:43:28 +0000127 ixgbe_clear_interrupt_scheme(adapter);
Don Skidmore1486a612008-12-21 20:09:50 -0800128
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +0000129 adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
Don Skidmore1486a612008-12-21 20:09:50 -0800130 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
131 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
132 ixgbe_init_interrupt_scheme(adapter);
Don Skidmore1486a612008-12-21 20:09:50 -0800133 if (netif_running(netdev))
134 netdev->netdev_ops->ndo_open(netdev);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800135 } else {
136 /* Turn off DCB */
137 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +0000138 adapter->hw.fc.requested_mode = ixgbe_fc_default;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800139 if (netif_running(netdev))
Don Skidmore1486a612008-12-21 20:09:50 -0800140 netdev->netdev_ops->ndo_stop(netdev);
Alexander Duyck7a921c92009-05-06 10:43:28 +0000141 ixgbe_clear_interrupt_scheme(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800142
143 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
144 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
145 ixgbe_init_interrupt_scheme(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800146 if (netif_running(netdev))
Don Skidmore1486a612008-12-21 20:09:50 -0800147 netdev->netdev_ops->ndo_open(netdev);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800148 }
149 }
Don Skidmore1486a612008-12-21 20:09:50 -0800150out:
151 return err;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800152}
153
154static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
155 u8 *perm_addr)
156{
157 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Waskiewicz Jr, Peter Paca6bee2009-05-17 12:32:48 +0000158 int i, j;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800159
160 for (i = 0; i < netdev->addr_len; i++)
161 perm_addr[i] = adapter->hw.mac.perm_addr[i];
Waskiewicz Jr, Peter Paca6bee2009-05-17 12:32:48 +0000162
163 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
164 for (j = 0; j < netdev->addr_len; j++, i++)
165 perm_addr[i] = adapter->hw.mac.san_addr[j];
166 }
Alexander Duyck2f90b862008-11-20 20:52:10 -0800167}
168
169static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
170 u8 prio, u8 bwg_id, u8 bw_pct,
171 u8 up_map)
172{
173 struct ixgbe_adapter *adapter = netdev_priv(netdev);
174
175 if (prio != DCB_ATTR_VALUE_UNDEFINED)
176 adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio;
177 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
178 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id;
179 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
180 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent =
181 bw_pct;
182 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
183 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
184 up_map;
185
186 if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type !=
187 adapter->dcb_cfg.tc_config[tc].path[0].prio_type) ||
188 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id !=
189 adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) ||
190 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent !=
191 adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) ||
192 (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
193 adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap))
194 adapter->dcb_set_bitmap |= BIT_PG_TX;
195}
196
197static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
198 u8 bw_pct)
199{
200 struct ixgbe_adapter *adapter = netdev_priv(netdev);
201
202 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
203
204 if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
205 adapter->dcb_cfg.bw_percentage[0][bwg_id])
206 adapter->dcb_set_bitmap |= BIT_PG_RX;
207}
208
209static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
210 u8 prio, u8 bwg_id, u8 bw_pct,
211 u8 up_map)
212{
213 struct ixgbe_adapter *adapter = netdev_priv(netdev);
214
215 if (prio != DCB_ATTR_VALUE_UNDEFINED)
216 adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
217 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
218 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
219 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
220 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
221 bw_pct;
222 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
223 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
224 up_map;
225
226 if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
227 adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
228 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
229 adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
230 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
231 adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
232 (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
233 adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap))
234 adapter->dcb_set_bitmap |= BIT_PG_RX;
235}
236
237static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
238 u8 bw_pct)
239{
240 struct ixgbe_adapter *adapter = netdev_priv(netdev);
241
242 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
243
244 if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
245 adapter->dcb_cfg.bw_percentage[1][bwg_id])
246 adapter->dcb_set_bitmap |= BIT_PG_RX;
247}
248
249static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
250 u8 *prio, u8 *bwg_id, u8 *bw_pct,
251 u8 *up_map)
252{
253 struct ixgbe_adapter *adapter = netdev_priv(netdev);
254
255 *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
256 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
257 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
258 *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
259}
260
261static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
262 u8 *bw_pct)
263{
264 struct ixgbe_adapter *adapter = netdev_priv(netdev);
265
266 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
267}
268
269static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
270 u8 *prio, u8 *bwg_id, u8 *bw_pct,
271 u8 *up_map)
272{
273 struct ixgbe_adapter *adapter = netdev_priv(netdev);
274
275 *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
276 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
277 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
278 *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
279}
280
281static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
282 u8 *bw_pct)
283{
284 struct ixgbe_adapter *adapter = netdev_priv(netdev);
285
286 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
287}
288
289static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
290 u8 setting)
291{
292 struct ixgbe_adapter *adapter = netdev_priv(netdev);
293
294 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
295 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
PJ Waskiewiczea4af4f2009-03-31 21:33:25 +0000296 adapter->dcb_cfg.tc_config[priority].dcb_pfc) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800297 adapter->dcb_set_bitmap |= BIT_PFC;
PJ Waskiewiczea4af4f2009-03-31 21:33:25 +0000298 adapter->temp_dcb_cfg.pfc_mode_enable = true;
299 }
Alexander Duyck2f90b862008-11-20 20:52:10 -0800300}
301
302static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
303 u8 *setting)
304{
305 struct ixgbe_adapter *adapter = netdev_priv(netdev);
306
307 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
308}
309
310static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
311{
312 struct ixgbe_adapter *adapter = netdev_priv(netdev);
313 int ret;
314
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800315 adapter->dcb_set_bitmap &= ~BIT_BCN; /* no set for BCN */
Alexander Duyck2f90b862008-11-20 20:52:10 -0800316 if (!adapter->dcb_set_bitmap)
317 return 1;
318
319 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
320 msleep(1);
321
322 if (netif_running(netdev))
323 ixgbe_down(adapter);
324
325 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
326 adapter->ring_feature[RING_F_DCB].indices);
327 if (ret) {
328 clear_bit(__IXGBE_RESETTING, &adapter->state);
329 return ret;
330 }
331
332 if (netif_running(netdev))
333 ixgbe_up(adapter);
334
335 adapter->dcb_set_bitmap = 0x00;
336 clear_bit(__IXGBE_RESETTING, &adapter->state);
337 return ret;
338}
339
Alexander Duyck46132182008-11-20 21:05:08 -0800340static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
341{
342 struct ixgbe_adapter *adapter = netdev_priv(netdev);
343 u8 rval = 0;
344
345 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
346 switch (capid) {
347 case DCB_CAP_ATTR_PG:
348 *cap = true;
349 break;
350 case DCB_CAP_ATTR_PFC:
351 *cap = true;
352 break;
353 case DCB_CAP_ATTR_UP2TC:
354 *cap = false;
355 break;
356 case DCB_CAP_ATTR_PG_TCS:
357 *cap = 0x80;
358 break;
359 case DCB_CAP_ATTR_PFC_TCS:
360 *cap = 0x80;
361 break;
362 case DCB_CAP_ATTR_GSP:
363 *cap = true;
364 break;
365 case DCB_CAP_ATTR_BCN:
366 *cap = false;
367 break;
368 default:
369 rval = -EINVAL;
370 break;
371 }
372 } else {
373 rval = -EINVAL;
374 }
375
376 return rval;
377}
378
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800379static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
380{
381 struct ixgbe_adapter *adapter = netdev_priv(netdev);
382 u8 rval = 0;
383
384 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
385 switch (tcid) {
386 case DCB_NUMTCS_ATTR_PG:
387 *num = MAX_TRAFFIC_CLASS;
388 break;
389 case DCB_NUMTCS_ATTR_PFC:
390 *num = MAX_TRAFFIC_CLASS;
391 break;
392 default:
393 rval = -EINVAL;
394 break;
395 }
396 } else {
397 rval = -EINVAL;
398 }
399
400 return rval;
401}
402
403static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
404{
405 return -EINVAL;
406}
407
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800408static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
409{
410 struct ixgbe_adapter *adapter = netdev_priv(netdev);
411
412 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
413}
414
415static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
416{
417 return;
418}
419
Alexander Duyck2f90b862008-11-20 20:52:10 -0800420struct dcbnl_rtnl_ops dcbnl_ops = {
421 .getstate = ixgbe_dcbnl_get_state,
422 .setstate = ixgbe_dcbnl_set_state,
423 .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
424 .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
425 .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
426 .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
427 .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
428 .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
429 .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
430 .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
431 .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
432 .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
433 .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
Alexander Duyck46132182008-11-20 21:05:08 -0800434 .setall = ixgbe_dcbnl_set_all,
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800435 .getcap = ixgbe_dcbnl_getcap,
436 .getnumtcs = ixgbe_dcbnl_getnumtcs,
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800437 .setnumtcs = ixgbe_dcbnl_setnumtcs,
438 .getpfcstate = ixgbe_dcbnl_getpfcstate,
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800439 .setpfcstate = ixgbe_dcbnl_setpfcstate,
Alexander Duyck2f90b862008-11-20 20:52:10 -0800440};
441