1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2009 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 #include <linux/dcbnl.h>
32 /* Callbacks for DCB netlink in the kernel */
33 #define BIT_DCB_MODE 0x01
35 #define BIT_PG_RX 0x04
36 #define BIT_PG_TX 0x08
38 #define BIT_LINKSPEED 0x80
40 int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
41 struct ixgbe_dcb_config *dst_dcb_cfg, int tc_max)
43 struct tc_configuration *src_tc_cfg = NULL;
44 struct tc_configuration *dst_tc_cfg = NULL;
47 if (!src_dcb_cfg || !dst_dcb_cfg)
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];
54 dst_tc_cfg->path[DCB_TX_CONFIG].prio_type =
55 src_tc_cfg->path[DCB_TX_CONFIG].prio_type;
57 dst_tc_cfg->path[DCB_TX_CONFIG].bwg_id =
58 src_tc_cfg->path[DCB_TX_CONFIG].bwg_id;
60 dst_tc_cfg->path[DCB_TX_CONFIG].bwg_percent =
61 src_tc_cfg->path[DCB_TX_CONFIG].bwg_percent;
63 dst_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap =
64 src_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap;
66 dst_tc_cfg->path[DCB_RX_CONFIG].prio_type =
67 src_tc_cfg->path[DCB_RX_CONFIG].prio_type;
69 dst_tc_cfg->path[DCB_RX_CONFIG].bwg_id =
70 src_tc_cfg->path[DCB_RX_CONFIG].bwg_id;
72 dst_tc_cfg->path[DCB_RX_CONFIG].bwg_percent =
73 src_tc_cfg->path[DCB_RX_CONFIG].bwg_percent;
75 dst_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap =
76 src_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap;
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];
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;
96 static u8 ixgbe_dcbnl_get_state(struct net_device *netdev)
98 struct ixgbe_adapter *adapter = netdev_priv(netdev);
100 DPRINTK(DRV, INFO, "Get DCB Admin Mode.\n");
102 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
105 static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
108 struct ixgbe_adapter *adapter = netdev_priv(netdev);
110 DPRINTK(DRV, INFO, "Set DCB Admin Mode.\n");
114 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
117 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
118 DPRINTK(DRV, ERR, "Enable failed, needs MSI-X\n");
123 if (netif_running(netdev))
124 netdev->netdev_ops->ndo_stop(netdev);
125 ixgbe_reset_interrupt_capability(adapter);
126 ixgbe_napi_del_all(adapter);
127 INIT_LIST_HEAD(&netdev->napi_list);
128 kfree(adapter->tx_ring);
129 kfree(adapter->rx_ring);
130 adapter->tx_ring = NULL;
131 adapter->rx_ring = NULL;
133 adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
134 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
135 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
136 ixgbe_init_interrupt_scheme(adapter);
137 if (netif_running(netdev))
138 netdev->netdev_ops->ndo_open(netdev);
141 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
142 adapter->hw.fc.requested_mode = ixgbe_fc_default;
143 if (netif_running(netdev))
144 netdev->netdev_ops->ndo_stop(netdev);
145 ixgbe_reset_interrupt_capability(adapter);
146 ixgbe_napi_del_all(adapter);
147 INIT_LIST_HEAD(&netdev->napi_list);
148 kfree(adapter->tx_ring);
149 kfree(adapter->rx_ring);
150 adapter->tx_ring = NULL;
151 adapter->rx_ring = NULL;
153 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
154 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
155 ixgbe_init_interrupt_scheme(adapter);
156 if (netif_running(netdev))
157 netdev->netdev_ops->ndo_open(netdev);
164 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
167 struct ixgbe_adapter *adapter = netdev_priv(netdev);
170 for (i = 0; i < netdev->addr_len; i++)
171 perm_addr[i] = adapter->hw.mac.perm_addr[i];
174 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
175 u8 prio, u8 bwg_id, u8 bw_pct,
178 struct ixgbe_adapter *adapter = netdev_priv(netdev);
180 if (prio != DCB_ATTR_VALUE_UNDEFINED)
181 adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio;
182 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
183 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id;
184 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
185 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent =
187 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
188 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
191 if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type !=
192 adapter->dcb_cfg.tc_config[tc].path[0].prio_type) ||
193 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id !=
194 adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) ||
195 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent !=
196 adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) ||
197 (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
198 adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap))
199 adapter->dcb_set_bitmap |= BIT_PG_TX;
202 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
205 struct ixgbe_adapter *adapter = netdev_priv(netdev);
207 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
209 if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
210 adapter->dcb_cfg.bw_percentage[0][bwg_id])
211 adapter->dcb_set_bitmap |= BIT_PG_RX;
214 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
215 u8 prio, u8 bwg_id, u8 bw_pct,
218 struct ixgbe_adapter *adapter = netdev_priv(netdev);
220 if (prio != DCB_ATTR_VALUE_UNDEFINED)
221 adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
222 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
223 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
224 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
225 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
227 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
228 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
231 if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
232 adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
233 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
234 adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
235 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
236 adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
237 (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
238 adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap))
239 adapter->dcb_set_bitmap |= BIT_PG_RX;
242 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
245 struct ixgbe_adapter *adapter = netdev_priv(netdev);
247 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
249 if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
250 adapter->dcb_cfg.bw_percentage[1][bwg_id])
251 adapter->dcb_set_bitmap |= BIT_PG_RX;
254 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
255 u8 *prio, u8 *bwg_id, u8 *bw_pct,
258 struct ixgbe_adapter *adapter = netdev_priv(netdev);
260 *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
261 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
262 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
263 *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
266 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
269 struct ixgbe_adapter *adapter = netdev_priv(netdev);
271 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
274 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
275 u8 *prio, u8 *bwg_id, u8 *bw_pct,
278 struct ixgbe_adapter *adapter = netdev_priv(netdev);
280 *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
281 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
282 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
283 *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
286 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
289 struct ixgbe_adapter *adapter = netdev_priv(netdev);
291 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
294 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
297 struct ixgbe_adapter *adapter = netdev_priv(netdev);
299 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
300 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
301 adapter->dcb_cfg.tc_config[priority].dcb_pfc)
302 adapter->dcb_set_bitmap |= BIT_PFC;
305 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
308 struct ixgbe_adapter *adapter = netdev_priv(netdev);
310 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
313 static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
315 struct ixgbe_adapter *adapter = netdev_priv(netdev);
318 adapter->dcb_set_bitmap &= ~BIT_BCN; /* no set for BCN */
319 if (!adapter->dcb_set_bitmap)
322 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
325 if (netif_running(netdev))
328 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
329 adapter->ring_feature[RING_F_DCB].indices);
331 clear_bit(__IXGBE_RESETTING, &adapter->state);
335 if (netif_running(netdev))
338 adapter->dcb_set_bitmap = 0x00;
339 clear_bit(__IXGBE_RESETTING, &adapter->state);
343 static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
345 struct ixgbe_adapter *adapter = netdev_priv(netdev);
348 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
350 case DCB_CAP_ATTR_PG:
353 case DCB_CAP_ATTR_PFC:
356 case DCB_CAP_ATTR_UP2TC:
359 case DCB_CAP_ATTR_PG_TCS:
362 case DCB_CAP_ATTR_PFC_TCS:
365 case DCB_CAP_ATTR_GSP:
368 case DCB_CAP_ATTR_BCN:
382 static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
384 struct ixgbe_adapter *adapter = netdev_priv(netdev);
387 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
389 case DCB_NUMTCS_ATTR_PG:
390 *num = MAX_TRAFFIC_CLASS;
392 case DCB_NUMTCS_ATTR_PFC:
393 *num = MAX_TRAFFIC_CLASS;
406 static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
411 static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
413 struct ixgbe_adapter *adapter = netdev_priv(netdev);
415 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
418 static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
423 struct dcbnl_rtnl_ops dcbnl_ops = {
424 .getstate = ixgbe_dcbnl_get_state,
425 .setstate = ixgbe_dcbnl_set_state,
426 .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
427 .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
428 .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
429 .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
430 .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
431 .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
432 .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
433 .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
434 .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
435 .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
436 .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
437 .setall = ixgbe_dcbnl_set_all,
438 .getcap = ixgbe_dcbnl_getcap,
439 .getnumtcs = ixgbe_dcbnl_getnumtcs,
440 .setnumtcs = ixgbe_dcbnl_setnumtcs,
441 .getpfcstate = ixgbe_dcbnl_getpfcstate,
442 .setpfcstate = ixgbe_dcbnl_setpfcstate,