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;
93 dst_dcb_cfg->pfc_mode_enable = src_dcb_cfg->pfc_mode_enable;
98 static u8 ixgbe_dcbnl_get_state(struct net_device *netdev)
100 struct ixgbe_adapter *adapter = netdev_priv(netdev);
102 DPRINTK(DRV, INFO, "Get DCB Admin Mode.\n");
104 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
107 static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
110 struct ixgbe_adapter *adapter = netdev_priv(netdev);
112 DPRINTK(DRV, INFO, "Set DCB Admin Mode.\n");
116 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
119 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
120 DPRINTK(DRV, ERR, "Enable failed, needs MSI-X\n");
125 if (netif_running(netdev))
126 netdev->netdev_ops->ndo_stop(netdev);
127 ixgbe_reset_interrupt_capability(adapter);
128 ixgbe_napi_del_all(adapter);
129 INIT_LIST_HEAD(&netdev->napi_list);
130 kfree(adapter->tx_ring);
131 kfree(adapter->rx_ring);
132 adapter->tx_ring = NULL;
133 adapter->rx_ring = NULL;
135 adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
136 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
137 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
138 ixgbe_init_interrupt_scheme(adapter);
139 if (netif_running(netdev))
140 netdev->netdev_ops->ndo_open(netdev);
143 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
144 adapter->hw.fc.requested_mode = ixgbe_fc_default;
145 if (netif_running(netdev))
146 netdev->netdev_ops->ndo_stop(netdev);
147 ixgbe_reset_interrupt_capability(adapter);
148 ixgbe_napi_del_all(adapter);
149 INIT_LIST_HEAD(&netdev->napi_list);
150 kfree(adapter->tx_ring);
151 kfree(adapter->rx_ring);
152 adapter->tx_ring = NULL;
153 adapter->rx_ring = NULL;
155 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
156 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
157 ixgbe_init_interrupt_scheme(adapter);
158 if (netif_running(netdev))
159 netdev->netdev_ops->ndo_open(netdev);
166 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
169 struct ixgbe_adapter *adapter = netdev_priv(netdev);
172 for (i = 0; i < netdev->addr_len; i++)
173 perm_addr[i] = adapter->hw.mac.perm_addr[i];
176 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
177 u8 prio, u8 bwg_id, u8 bw_pct,
180 struct ixgbe_adapter *adapter = netdev_priv(netdev);
182 if (prio != DCB_ATTR_VALUE_UNDEFINED)
183 adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio;
184 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
185 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id;
186 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
187 adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent =
189 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
190 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
193 if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type !=
194 adapter->dcb_cfg.tc_config[tc].path[0].prio_type) ||
195 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id !=
196 adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) ||
197 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent !=
198 adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) ||
199 (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
200 adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap))
201 adapter->dcb_set_bitmap |= BIT_PG_TX;
204 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
207 struct ixgbe_adapter *adapter = netdev_priv(netdev);
209 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
211 if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
212 adapter->dcb_cfg.bw_percentage[0][bwg_id])
213 adapter->dcb_set_bitmap |= BIT_PG_RX;
216 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
217 u8 prio, u8 bwg_id, u8 bw_pct,
220 struct ixgbe_adapter *adapter = netdev_priv(netdev);
222 if (prio != DCB_ATTR_VALUE_UNDEFINED)
223 adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
224 if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
225 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
226 if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
227 adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
229 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
230 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
233 if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
234 adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
235 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
236 adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
237 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
238 adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
239 (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
240 adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap))
241 adapter->dcb_set_bitmap |= BIT_PG_RX;
244 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
247 struct ixgbe_adapter *adapter = netdev_priv(netdev);
249 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
251 if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
252 adapter->dcb_cfg.bw_percentage[1][bwg_id])
253 adapter->dcb_set_bitmap |= BIT_PG_RX;
256 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
257 u8 *prio, u8 *bwg_id, u8 *bw_pct,
260 struct ixgbe_adapter *adapter = netdev_priv(netdev);
262 *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
263 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
264 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
265 *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
268 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
271 struct ixgbe_adapter *adapter = netdev_priv(netdev);
273 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
276 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
277 u8 *prio, u8 *bwg_id, u8 *bw_pct,
280 struct ixgbe_adapter *adapter = netdev_priv(netdev);
282 *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
283 *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
284 *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
285 *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
288 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
291 struct ixgbe_adapter *adapter = netdev_priv(netdev);
293 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
296 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
299 struct ixgbe_adapter *adapter = netdev_priv(netdev);
301 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
302 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
303 adapter->dcb_cfg.tc_config[priority].dcb_pfc) {
304 adapter->dcb_set_bitmap |= BIT_PFC;
305 adapter->temp_dcb_cfg.pfc_mode_enable = true;
309 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
312 struct ixgbe_adapter *adapter = netdev_priv(netdev);
314 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
317 static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
319 struct ixgbe_adapter *adapter = netdev_priv(netdev);
322 adapter->dcb_set_bitmap &= ~BIT_BCN; /* no set for BCN */
323 if (!adapter->dcb_set_bitmap)
326 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
329 if (netif_running(netdev))
332 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
333 adapter->ring_feature[RING_F_DCB].indices);
335 clear_bit(__IXGBE_RESETTING, &adapter->state);
339 if (netif_running(netdev))
342 adapter->dcb_set_bitmap = 0x00;
343 clear_bit(__IXGBE_RESETTING, &adapter->state);
347 static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
349 struct ixgbe_adapter *adapter = netdev_priv(netdev);
352 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
354 case DCB_CAP_ATTR_PG:
357 case DCB_CAP_ATTR_PFC:
360 case DCB_CAP_ATTR_UP2TC:
363 case DCB_CAP_ATTR_PG_TCS:
366 case DCB_CAP_ATTR_PFC_TCS:
369 case DCB_CAP_ATTR_GSP:
372 case DCB_CAP_ATTR_BCN:
386 static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
388 struct ixgbe_adapter *adapter = netdev_priv(netdev);
391 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
393 case DCB_NUMTCS_ATTR_PG:
394 *num = MAX_TRAFFIC_CLASS;
396 case DCB_NUMTCS_ATTR_PFC:
397 *num = MAX_TRAFFIC_CLASS;
410 static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
415 static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
417 struct ixgbe_adapter *adapter = netdev_priv(netdev);
419 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
422 static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
427 struct dcbnl_rtnl_ops dcbnl_ops = {
428 .getstate = ixgbe_dcbnl_get_state,
429 .setstate = ixgbe_dcbnl_set_state,
430 .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
431 .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
432 .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
433 .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
434 .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
435 .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
436 .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
437 .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
438 .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
439 .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
440 .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
441 .setall = ixgbe_dcbnl_set_all,
442 .getcap = ixgbe_dcbnl_getcap,
443 .getnumtcs = ixgbe_dcbnl_getnumtcs,
444 .setnumtcs = ixgbe_dcbnl_setnumtcs,
445 .getpfcstate = ixgbe_dcbnl_getpfcstate,
446 .setpfcstate = ixgbe_dcbnl_setpfcstate,