clocksource: sh_mtu2/cmt_register() should be static.
[linux-2.6] / drivers / net / ixgbe / ixgbe_dcb_nl.c
1 /*******************************************************************************
2
3   Intel 10 Gigabit PCI Express Linux driver
4   Copyright(c) 1999 - 2009 Intel Corporation.
5
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
37 #define BIT_BCN         0x10
38 #define BIT_LINKSPEED   0x80
39
40 int 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
93         dst_dcb_cfg->pfc_mode_enable = src_dcb_cfg->pfc_mode_enable;
94
95         return 0;
96 }
97
98 static 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
107 static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
108 {
109         u8 err = 0;
110         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 */
116                 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
117                         goto out;
118
119                 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
120                         DPRINTK(DRV, ERR, "Enable failed, needs MSI-X\n");
121                         err = 1;
122                         goto out;
123                 }
124
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;
134
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);
141         } else {
142                 /* Turn off DCB */
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;
154
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);
160                 }
161         }
162 out:
163         return err;
164 }
165
166 static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
167                                          u8 *perm_addr)
168 {
169         struct ixgbe_adapter *adapter = netdev_priv(netdev);
170         int i;
171
172         for (i = 0; i < netdev->addr_len; i++)
173                 perm_addr[i] = adapter->hw.mac.perm_addr[i];
174 }
175
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,
178                                          u8 up_map)
179 {
180         struct ixgbe_adapter *adapter = netdev_priv(netdev);
181
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 =
188                         bw_pct;
189         if (up_map != DCB_ATTR_VALUE_UNDEFINED)
190                 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
191                         up_map;
192
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;
202 }
203
204 static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
205                                           u8 bw_pct)
206 {
207         struct ixgbe_adapter *adapter = netdev_priv(netdev);
208
209         adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
210
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;
214 }
215
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,
218                                          u8 up_map)
219 {
220         struct ixgbe_adapter *adapter = netdev_priv(netdev);
221
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 =
228                         bw_pct;
229         if (up_map != DCB_ATTR_VALUE_UNDEFINED)
230                 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
231                         up_map;
232
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;
242 }
243
244 static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
245                                           u8 bw_pct)
246 {
247         struct ixgbe_adapter *adapter = netdev_priv(netdev);
248
249         adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
250
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;
254 }
255
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,
258                                          u8 *up_map)
259 {
260         struct ixgbe_adapter *adapter = netdev_priv(netdev);
261
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;
266 }
267
268 static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
269                                           u8 *bw_pct)
270 {
271         struct ixgbe_adapter *adapter = netdev_priv(netdev);
272
273         *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
274 }
275
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,
278                                          u8 *up_map)
279 {
280         struct ixgbe_adapter *adapter = netdev_priv(netdev);
281
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;
286 }
287
288 static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
289                                           u8 *bw_pct)
290 {
291         struct ixgbe_adapter *adapter = netdev_priv(netdev);
292
293         *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
294 }
295
296 static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
297                                     u8 setting)
298 {
299         struct ixgbe_adapter *adapter = netdev_priv(netdev);
300
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;
306         }
307 }
308
309 static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
310                                     u8 *setting)
311 {
312         struct ixgbe_adapter *adapter = netdev_priv(netdev);
313
314         *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
315 }
316
317 static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
318 {
319         struct ixgbe_adapter *adapter = netdev_priv(netdev);
320         int ret;
321
322         adapter->dcb_set_bitmap &= ~BIT_BCN;    /* no set for BCN */
323         if (!adapter->dcb_set_bitmap)
324                 return 1;
325
326         while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
327                 msleep(1);
328
329         if (netif_running(netdev))
330                 ixgbe_down(adapter);
331
332         ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
333                                  adapter->ring_feature[RING_F_DCB].indices);
334         if (ret) {
335                 clear_bit(__IXGBE_RESETTING, &adapter->state);
336                 return ret;
337         }
338
339         if (netif_running(netdev))
340                 ixgbe_up(adapter);
341
342         adapter->dcb_set_bitmap = 0x00;
343         clear_bit(__IXGBE_RESETTING, &adapter->state);
344         return ret;
345 }
346
347 static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
348 {
349         struct ixgbe_adapter *adapter = netdev_priv(netdev);
350         u8 rval = 0;
351
352         if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
353                 switch (capid) {
354                 case DCB_CAP_ATTR_PG:
355                         *cap = true;
356                         break;
357                 case DCB_CAP_ATTR_PFC:
358                         *cap = true;
359                         break;
360                 case DCB_CAP_ATTR_UP2TC:
361                         *cap = false;
362                         break;
363                 case DCB_CAP_ATTR_PG_TCS:
364                         *cap = 0x80;
365                         break;
366                 case DCB_CAP_ATTR_PFC_TCS:
367                         *cap = 0x80;
368                         break;
369                 case DCB_CAP_ATTR_GSP:
370                         *cap = true;
371                         break;
372                 case DCB_CAP_ATTR_BCN:
373                         *cap = false;
374                         break;
375                 default:
376                         rval = -EINVAL;
377                         break;
378                 }
379         } else {
380                 rval = -EINVAL;
381         }
382
383         return rval;
384 }
385
386 static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
387 {
388         struct ixgbe_adapter *adapter = netdev_priv(netdev);
389         u8 rval = 0;
390
391         if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
392                 switch (tcid) {
393                 case DCB_NUMTCS_ATTR_PG:
394                         *num = MAX_TRAFFIC_CLASS;
395                         break;
396                 case DCB_NUMTCS_ATTR_PFC:
397                         *num = MAX_TRAFFIC_CLASS;
398                         break;
399                 default:
400                         rval = -EINVAL;
401                         break;
402                 }
403         } else {
404                 rval = -EINVAL;
405         }
406
407         return rval;
408 }
409
410 static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
411 {
412         return -EINVAL;
413 }
414
415 static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
416 {
417         struct ixgbe_adapter *adapter = netdev_priv(netdev);
418
419         return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
420 }
421
422 static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
423 {
424         return;
425 }
426
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,
447 };
448