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_clear_interrupt_scheme(adapter);
129 adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
130 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
131 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
132 ixgbe_init_interrupt_scheme(adapter);
133 if (netif_running(netdev))
134 netdev->netdev_ops->ndo_open(netdev);
137 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
138 adapter->hw.fc.requested_mode = ixgbe_fc_default;
139 if (netif_running(netdev))
140 netdev->netdev_ops->ndo_stop(netdev);
141 ixgbe_clear_interrupt_scheme(adapter);
143 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
144 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
145 ixgbe_init_interrupt_scheme(adapter);
146 if (netif_running(netdev))
147 netdev->netdev_ops->ndo_open(netdev);
154 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
157 struct ixgbe_adapter *adapter = netdev_priv(netdev);
160 for (i = 0; i < netdev->addr_len; i++)
161 perm_addr[i] = adapter->hw.mac.perm_addr[i];
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];
169 static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
170 u8 prio, u8 bwg_id, u8 bw_pct,
173 struct ixgbe_adapter *adapter = netdev_priv(netdev);
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 =
182 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
183 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
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;
197 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
200 struct ixgbe_adapter *adapter = netdev_priv(netdev);
202 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
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;
209 static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
210 u8 prio, u8 bwg_id, u8 bw_pct,
213 struct ixgbe_adapter *adapter = netdev_priv(netdev);
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 =
222 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
223 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
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;
237 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
240 struct ixgbe_adapter *adapter = netdev_priv(netdev);
242 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
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;
249 static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
250 u8 *prio, u8 *bwg_id, u8 *bw_pct,
253 struct ixgbe_adapter *adapter = netdev_priv(netdev);
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;
261 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
264 struct ixgbe_adapter *adapter = netdev_priv(netdev);
266 *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
269 static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
270 u8 *prio, u8 *bwg_id, u8 *bw_pct,
273 struct ixgbe_adapter *adapter = netdev_priv(netdev);
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;
281 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
284 struct ixgbe_adapter *adapter = netdev_priv(netdev);
286 *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
289 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
292 struct ixgbe_adapter *adapter = netdev_priv(netdev);
294 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
295 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
296 adapter->dcb_cfg.tc_config[priority].dcb_pfc) {
297 adapter->dcb_set_bitmap |= BIT_PFC;
298 adapter->temp_dcb_cfg.pfc_mode_enable = true;
302 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
305 struct ixgbe_adapter *adapter = netdev_priv(netdev);
307 *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
310 static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
312 struct ixgbe_adapter *adapter = netdev_priv(netdev);
315 adapter->dcb_set_bitmap &= ~BIT_BCN; /* no set for BCN */
316 if (!adapter->dcb_set_bitmap)
319 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
322 if (netif_running(netdev))
325 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
326 adapter->ring_feature[RING_F_DCB].indices);
328 clear_bit(__IXGBE_RESETTING, &adapter->state);
332 if (netif_running(netdev))
335 adapter->dcb_set_bitmap = 0x00;
336 clear_bit(__IXGBE_RESETTING, &adapter->state);
340 static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
342 struct ixgbe_adapter *adapter = netdev_priv(netdev);
345 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
347 case DCB_CAP_ATTR_PG:
350 case DCB_CAP_ATTR_PFC:
353 case DCB_CAP_ATTR_UP2TC:
356 case DCB_CAP_ATTR_PG_TCS:
359 case DCB_CAP_ATTR_PFC_TCS:
362 case DCB_CAP_ATTR_GSP:
365 case DCB_CAP_ATTR_BCN:
379 static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
381 struct ixgbe_adapter *adapter = netdev_priv(netdev);
384 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
386 case DCB_NUMTCS_ATTR_PG:
387 *num = MAX_TRAFFIC_CLASS;
389 case DCB_NUMTCS_ATTR_PFC:
390 *num = MAX_TRAFFIC_CLASS;
403 static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
408 static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
410 struct ixgbe_adapter *adapter = netdev_priv(netdev);
412 return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
415 static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
420 struct 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,
434 .setall = ixgbe_dcbnl_set_all,
435 .getcap = ixgbe_dcbnl_getcap,
436 .getnumtcs = ixgbe_dcbnl_getnumtcs,
437 .setnumtcs = ixgbe_dcbnl_setnumtcs,
438 .getpfcstate = ixgbe_dcbnl_getpfcstate,
439 .setpfcstate = ixgbe_dcbnl_setpfcstate,