blob: bf566e8a455e485978c66d8478166b0c885e64af [file] [log] [blame]
Alexander Duyck2f90b862008-11-20 20:52:10 -08001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Shannon Nelson8c47eaa2010-01-13 01:49:34 +00004 Copyright(c) 1999 - 2010 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>
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +000031#include "ixgbe_dcb_82598.h"
32#include "ixgbe_dcb_82599.h"
Alexander Duyck2f90b862008-11-20 20:52:10 -080033
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
Yi Zou8de8b2e2009-09-03 14:55:50 +000039#define BIT_APP_UPCHG 0x10
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +000040#define BIT_RESETLINK 0x40
PJ Waskiewicz235ea822009-02-27 15:44:48 +000041#define BIT_LINKSPEED 0x80
Alexander Duyck2f90b862008-11-20 20:52:10 -080042
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +000043/* 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
Alexander Duyck2f90b862008-11-20 20:52:10 -080048int 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
PJ Waskiewiczea4af4f2009-03-31 21:33:25 +0000101 dst_dcb_cfg->pfc_mode_enable = src_dcb_cfg->pfc_mode_enable;
102
Alexander Duyck2f90b862008-11-20 20:52:10 -0800103 return 0;
104}
105
106static u8 ixgbe_dcbnl_get_state(struct net_device *netdev)
107{
108 struct ixgbe_adapter *adapter = netdev_priv(netdev);
109
Alexander Duyck2f90b862008-11-20 20:52:10 -0800110 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
111}
112
Don Skidmore1486a612008-12-21 20:09:50 -0800113static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800114{
Don Skidmore1486a612008-12-21 20:09:50 -0800115 u8 err = 0;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800116 struct ixgbe_adapter *adapter = netdev_priv(netdev);
117
Alexander Duyck2f90b862008-11-20 20:52:10 -0800118 if (state > 0) {
119 /* Turn on DCB */
Don Skidmore1486a612008-12-21 20:09:50 -0800120 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
121 goto out;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800122
Don Skidmore1486a612008-12-21 20:09:50 -0800123 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Emil Tantilov396e7992010-07-01 20:05:12 +0000124 e_err(drv, "Enable failed, needs MSI-X\n");
Don Skidmore1486a612008-12-21 20:09:50 -0800125 err = 1;
126 goto out;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800127 }
Don Skidmore1486a612008-12-21 20:09:50 -0800128
129 if (netif_running(netdev))
130 netdev->netdev_ops->ndo_stop(netdev);
Alexander Duyck7a921c92009-05-06 10:43:28 +0000131 ixgbe_clear_interrupt_scheme(adapter);
Don Skidmore1486a612008-12-21 20:09:50 -0800132
Don Skidmoreb93a2222010-11-16 19:27:17 -0800133 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
134 switch (adapter->hw.mac.type) {
135 case ixgbe_mac_82598EB:
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +0000136 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
137 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Don Skidmoreb93a2222010-11-16 19:27:17 -0800138 break;
139 case ixgbe_mac_82599EB:
140 case ixgbe_mac_X540:
Yi Zou8faa2a72009-07-09 02:29:50 +0000141 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
142 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Don Skidmoreb93a2222010-11-16 19:27:17 -0800143 break;
144 default:
145 break;
Yi Zou8faa2a72009-07-09 02:29:50 +0000146 }
Don Skidmoreb93a2222010-11-16 19:27:17 -0800147
Don Skidmore1486a612008-12-21 20:09:50 -0800148 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
149 ixgbe_init_interrupt_scheme(adapter);
Don Skidmore1486a612008-12-21 20:09:50 -0800150 if (netif_running(netdev))
151 netdev->netdev_ops->ndo_open(netdev);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800152 } else {
153 /* Turn off DCB */
154 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
155 if (netif_running(netdev))
Don Skidmore1486a612008-12-21 20:09:50 -0800156 netdev->netdev_ops->ndo_stop(netdev);
Alexander Duyck7a921c92009-05-06 10:43:28 +0000157 ixgbe_clear_interrupt_scheme(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800158
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +0000159 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;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800162 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
163 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Don Skidmoreb93a2222010-11-16 19:27:17 -0800164 switch (adapter->hw.mac.type) {
165 case ixgbe_mac_82599EB:
166 case ixgbe_mac_X540:
Yi Zou8faa2a72009-07-09 02:29:50 +0000167 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmoreb93a2222010-11-16 19:27:17 -0800168 break;
169 default:
170 break;
171 }
Yi Zou0d551582009-07-22 14:07:12 +0000172
Alexander Duyck2f90b862008-11-20 20:52:10 -0800173 ixgbe_init_interrupt_scheme(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800174 if (netif_running(netdev))
Don Skidmore1486a612008-12-21 20:09:50 -0800175 netdev->netdev_ops->ndo_open(netdev);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800176 }
177 }
Don Skidmore1486a612008-12-21 20:09:50 -0800178out:
179 return err;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800180}
181
182static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
183 u8 *perm_addr)
184{
185 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Waskiewicz Jr, Peter Paca6bee2009-05-17 12:32:48 +0000186 int i, j;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800187
Lucy Liu86e713a2009-07-16 13:43:10 +0000188 memset(perm_addr, 0xff, MAX_ADDR_LEN);
189
Alexander Duyck2f90b862008-11-20 20:52:10 -0800190 for (i = 0; i < netdev->addr_len; i++)
191 perm_addr[i] = adapter->hw.mac.perm_addr[i];
Waskiewicz Jr, Peter Paca6bee2009-05-17 12:32:48 +0000192
Don Skidmoreb93a2222010-11-16 19:27:17 -0800193 switch (adapter->hw.mac.type) {
194 case ixgbe_mac_82599EB:
195 case ixgbe_mac_X540:
Waskiewicz Jr, Peter Paca6bee2009-05-17 12:32:48 +0000196 for (j = 0; j < netdev->addr_len; j++, i++)
197 perm_addr[i] = adapter->hw.mac.san_addr[j];
Don Skidmoreb93a2222010-11-16 19:27:17 -0800198 break;
199 default:
200 break;
Waskiewicz Jr, Peter Paca6bee2009-05-17 12:32:48 +0000201 }
Alexander Duyck2f90b862008-11-20 20:52:10 -0800202}
203
204static 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 !=
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000228 adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap)) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800229 adapter->dcb_set_bitmap |= BIT_PG_TX;
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000230 adapter->dcb_set_bitmap |= BIT_RESETLINK;
231 }
Alexander Duyck2f90b862008-11-20 20:52:10 -0800232}
233
234static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
235 u8 bw_pct)
236{
237 struct ixgbe_adapter *adapter = netdev_priv(netdev);
238
239 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
240
241 if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000242 adapter->dcb_cfg.bw_percentage[0][bwg_id]) {
John Fastabendebe1b302010-01-27 16:37:44 +0000243 adapter->dcb_set_bitmap |= BIT_PG_TX;
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000244 adapter->dcb_set_bitmap |= BIT_RESETLINK;
245 }
Alexander Duyck2f90b862008-11-20 20:52:10 -0800246}
247
248static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
249 u8 prio, u8 bwg_id, u8 bw_pct,
250 u8 up_map)
251{
252 struct ixgbe_adapter *adapter = netdev_priv(netdev);
253
254 if (prio != DCB_ATTR_VALUE_UNDEFINED)
255 adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
256 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
257 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
258 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
259 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
260 bw_pct;
261 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
262 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
263 up_map;
264
265 if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
266 adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
267 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
268 adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
269 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
270 adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
271 (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000272 adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap)) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800273 adapter->dcb_set_bitmap |= BIT_PG_RX;
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000274 adapter->dcb_set_bitmap |= BIT_RESETLINK;
275 }
Alexander Duyck2f90b862008-11-20 20:52:10 -0800276}
277
278static void ixgbe_dcbnl_set_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 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
284
285 if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000286 adapter->dcb_cfg.bw_percentage[1][bwg_id]) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800287 adapter->dcb_set_bitmap |= BIT_PG_RX;
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000288 adapter->dcb_set_bitmap |= BIT_RESETLINK;
289 }
Alexander Duyck2f90b862008-11-20 20:52:10 -0800290}
291
292static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
293 u8 *prio, u8 *bwg_id, u8 *bw_pct,
294 u8 *up_map)
295{
296 struct ixgbe_adapter *adapter = netdev_priv(netdev);
297
298 *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
299 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
300 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
301 *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
302}
303
304static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
305 u8 *bw_pct)
306{
307 struct ixgbe_adapter *adapter = netdev_priv(netdev);
308
309 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
310}
311
312static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
313 u8 *prio, u8 *bwg_id, u8 *bw_pct,
314 u8 *up_map)
315{
316 struct ixgbe_adapter *adapter = netdev_priv(netdev);
317
318 *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
319 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
320 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
321 *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
322}
323
324static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
325 u8 *bw_pct)
326{
327 struct ixgbe_adapter *adapter = netdev_priv(netdev);
328
329 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
330}
331
332static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
333 u8 setting)
334{
335 struct ixgbe_adapter *adapter = netdev_priv(netdev);
336
337 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
338 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
PJ Waskiewiczea4af4f2009-03-31 21:33:25 +0000339 adapter->dcb_cfg.tc_config[priority].dcb_pfc) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800340 adapter->dcb_set_bitmap |= BIT_PFC;
PJ Waskiewiczea4af4f2009-03-31 21:33:25 +0000341 adapter->temp_dcb_cfg.pfc_mode_enable = true;
342 }
Alexander Duyck2f90b862008-11-20 20:52:10 -0800343}
344
345static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
346 u8 *setting)
347{
348 struct ixgbe_adapter *adapter = netdev_priv(netdev);
349
350 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
351}
352
353static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
354{
355 struct ixgbe_adapter *adapter = netdev_priv(netdev);
356 int ret;
357
358 if (!adapter->dcb_set_bitmap)
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000359 return DCB_NO_HW_CHG;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800360
John Fastabend3ce1cc52010-01-27 16:38:06 +0000361 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
362 adapter->ring_feature[RING_F_DCB].indices);
363
364 if (ret)
365 return DCB_NO_HW_CHG;
366
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000367 /*
368 * Only take down the adapter if the configuration change
369 * requires a reset.
370 */
371 if (adapter->dcb_set_bitmap & BIT_RESETLINK) {
372 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
373 msleep(1);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800374
Yi Zou8de8b2e2009-09-03 14:55:50 +0000375 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
376 if (netif_running(netdev))
377 netdev->netdev_ops->ndo_stop(netdev);
378 ixgbe_clear_interrupt_scheme(adapter);
379 } else {
380 if (netif_running(netdev))
381 ixgbe_down(adapter);
382 }
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000383 }
Alexander Duyck2f90b862008-11-20 20:52:10 -0800384
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +0000385 if (adapter->dcb_cfg.pfc_mode_enable) {
Don Skidmoreb93a2222010-11-16 19:27:17 -0800386 switch (adapter->hw.mac.type) {
387 case ixgbe_mac_82599EB:
388 case ixgbe_mac_X540:
389 if (adapter->hw.fc.current_mode != ixgbe_fc_pfc)
390 adapter->last_lfc_mode =
391 adapter->hw.fc.current_mode;
392 break;
393 default:
394 break;
395 }
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +0000396 adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
397 } else {
Don Skidmoreb93a2222010-11-16 19:27:17 -0800398 switch (adapter->hw.mac.type) {
399 case ixgbe_mac_82598EB:
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +0000400 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Don Skidmoreb93a2222010-11-16 19:27:17 -0800401 break;
402 case ixgbe_mac_82599EB:
403 case ixgbe_mac_X540:
404 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
405 break;
406 default:
407 break;
408 }
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +0000409 }
410
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000411 if (adapter->dcb_set_bitmap & BIT_RESETLINK) {
Yi Zou8de8b2e2009-09-03 14:55:50 +0000412 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
413 ixgbe_init_interrupt_scheme(adapter);
414 if (netif_running(netdev))
415 netdev->netdev_ops->ndo_open(netdev);
416 } else {
417 if (netif_running(netdev))
418 ixgbe_up(adapter);
419 }
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000420 ret = DCB_HW_CHG_RST;
421 } else if (adapter->dcb_set_bitmap & BIT_PFC) {
422 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
423 ixgbe_dcb_config_pfc_82598(&adapter->hw,
424 &adapter->dcb_cfg);
425 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
426 ixgbe_dcb_config_pfc_82599(&adapter->hw,
427 &adapter->dcb_cfg);
428 ret = DCB_HW_CHG;
429 }
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +0000430 if (adapter->dcb_cfg.pfc_mode_enable)
431 adapter->hw.fc.current_mode = ixgbe_fc_pfc;
432
Peter P Waskiewicz Jr62551d32009-05-17 12:35:57 +0000433 if (adapter->dcb_set_bitmap & BIT_RESETLINK)
434 clear_bit(__IXGBE_RESETTING, &adapter->state);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800435 adapter->dcb_set_bitmap = 0x00;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800436 return ret;
437}
438
Alexander Duyck46132182008-11-20 21:05:08 -0800439static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
440{
441 struct ixgbe_adapter *adapter = netdev_priv(netdev);
442 u8 rval = 0;
443
444 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
445 switch (capid) {
446 case DCB_CAP_ATTR_PG:
447 *cap = true;
448 break;
449 case DCB_CAP_ATTR_PFC:
450 *cap = true;
451 break;
452 case DCB_CAP_ATTR_UP2TC:
453 *cap = false;
454 break;
455 case DCB_CAP_ATTR_PG_TCS:
456 *cap = 0x80;
457 break;
458 case DCB_CAP_ATTR_PFC_TCS:
459 *cap = 0x80;
460 break;
461 case DCB_CAP_ATTR_GSP:
462 *cap = true;
463 break;
464 case DCB_CAP_ATTR_BCN:
465 *cap = false;
466 break;
467 default:
468 rval = -EINVAL;
469 break;
470 }
471 } else {
472 rval = -EINVAL;
473 }
474
475 return rval;
476}
477
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800478static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
479{
480 struct ixgbe_adapter *adapter = netdev_priv(netdev);
481 u8 rval = 0;
482
483 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
484 switch (tcid) {
485 case DCB_NUMTCS_ATTR_PG:
486 *num = MAX_TRAFFIC_CLASS;
487 break;
488 case DCB_NUMTCS_ATTR_PFC:
489 *num = MAX_TRAFFIC_CLASS;
490 break;
491 default:
492 rval = -EINVAL;
493 break;
494 }
495 } else {
496 rval = -EINVAL;
497 }
498
499 return rval;
500}
501
502static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
503{
504 return -EINVAL;
505}
506
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800507static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
508{
509 struct ixgbe_adapter *adapter = netdev_priv(netdev);
510
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +0000511 return adapter->dcb_cfg.pfc_mode_enable;
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800512}
513
514static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
515{
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +0000516 struct ixgbe_adapter *adapter = netdev_priv(netdev);
517
518 adapter->temp_dcb_cfg.pfc_mode_enable = state;
519 if (adapter->temp_dcb_cfg.pfc_mode_enable !=
520 adapter->dcb_cfg.pfc_mode_enable)
521 adapter->dcb_set_bitmap |= BIT_PFC;
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800522}
523
Yi Zou6ee16522009-08-31 12:34:28 +0000524/**
525 * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
526 * @netdev : the corresponding netdev
527 * @idtype : identifies the id as ether type or TCP/UDP port number
528 * @id: id is either ether type or TCP/UDP port number
529 *
530 * Returns : on success, returns a non-zero 802.1p user priority bitmap
531 * otherwise returns 0 as the invalid user priority bitmap to indicate an
532 * error.
533 */
534static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
535{
536 u8 rval = 0;
537
538 switch (idtype) {
539 case DCB_APP_IDTYPE_ETHTYPE:
540#ifdef IXGBE_FCOE
541 if (id == ETH_P_FCOE)
542 rval = ixgbe_fcoe_getapp(netdev_priv(netdev));
543#endif
544 break;
545 case DCB_APP_IDTYPE_PORTNUM:
546 break;
547 default:
548 break;
549 }
550 return rval;
551}
552
553/**
554 * ixgbe_dcbnl_setapp - set the DCBX application user priority
555 * @netdev : the corresponding netdev
556 * @idtype : identifies the id as ether type or TCP/UDP port number
557 * @id: id is either ether type or TCP/UDP port number
558 * @up: the 802.1p user priority bitmap
559 *
560 * Returns : 0 on success or 1 on error
561 */
562static u8 ixgbe_dcbnl_setapp(struct net_device *netdev,
563 u8 idtype, u16 id, u8 up)
564{
565 u8 rval = 1;
566
567 switch (idtype) {
568 case DCB_APP_IDTYPE_ETHTYPE:
569#ifdef IXGBE_FCOE
Yi Zou8de8b2e2009-09-03 14:55:50 +0000570 if (id == ETH_P_FCOE) {
571 u8 tc;
572 struct ixgbe_adapter *adapter;
573
574 adapter = netdev_priv(netdev);
575 tc = adapter->fcoe.tc;
576 rval = ixgbe_fcoe_setapp(adapter, up);
577 if ((!rval) && (tc != adapter->fcoe.tc) &&
578 (adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
579 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
580 adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
581 adapter->dcb_set_bitmap |= BIT_RESETLINK;
582 }
583 }
Yi Zou6ee16522009-08-31 12:34:28 +0000584#endif
585 break;
586 case DCB_APP_IDTYPE_PORTNUM:
587 break;
588 default:
589 break;
590 }
591 return rval;
592}
593
Stephen Hemminger32953542009-10-05 06:01:03 +0000594const struct dcbnl_rtnl_ops dcbnl_ops = {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800595 .getstate = ixgbe_dcbnl_get_state,
596 .setstate = ixgbe_dcbnl_set_state,
597 .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
598 .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
599 .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
600 .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
601 .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
602 .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
603 .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
604 .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
605 .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
606 .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
607 .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
Alexander Duyck46132182008-11-20 21:05:08 -0800608 .setall = ixgbe_dcbnl_set_all,
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800609 .getcap = ixgbe_dcbnl_getcap,
610 .getnumtcs = ixgbe_dcbnl_getnumtcs,
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800611 .setnumtcs = ixgbe_dcbnl_setnumtcs,
612 .getpfcstate = ixgbe_dcbnl_getpfcstate,
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800613 .setpfcstate = ixgbe_dcbnl_setpfcstate,
Yi Zou6ee16522009-08-31 12:34:28 +0000614 .getapp = ixgbe_dcbnl_getapp,
615 .setapp = ixgbe_dcbnl_setapp,
Alexander Duyck2f90b862008-11-20 20:52:10 -0800616};
617