blob: 2b23ca21b320acd633b35db64bfe6d00baa57d2c [file] [log] [blame]
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001/*
2 * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 *
32 */
33
34#include <linux/etherdevice.h>
35#include <linux/tcp.h>
36#include <linux/if_vlan.h>
37#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Amir Vadai1eb8c692012-07-18 22:33:52 +000039#include <linux/hash.h>
40#include <net/ip.h>
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070041
42#include <linux/mlx4/driver.h>
43#include <linux/mlx4/device.h>
44#include <linux/mlx4/cmd.h>
45#include <linux/mlx4/cq.h>
46
47#include "mlx4_en.h"
48#include "en_port.h"
49
Amir Vadai897d7842012-04-04 21:33:27 +000050static int mlx4_en_setup_tc(struct net_device *dev, u8 up)
51{
Amir Vadaibc6a4742012-05-17 00:58:10 +000052 struct mlx4_en_priv *priv = netdev_priv(dev);
53 int i;
54 unsigned int q, offset = 0;
55
56 if (up && up != MLX4_EN_NUM_UP)
Amir Vadai897d7842012-04-04 21:33:27 +000057 return -EINVAL;
58
Amir Vadaibc6a4742012-05-17 00:58:10 +000059 netdev_set_num_tc(dev, up);
60
61 /* Partition Tx queues evenly amongst UP's */
62 q = priv->tx_ring_num / up;
63 for (i = 0; i < up; i++) {
64 netdev_set_tc_queue(dev, i, q, offset);
65 offset += q;
66 }
67
Amir Vadai897d7842012-04-04 21:33:27 +000068 return 0;
69}
70
Amir Vadai1eb8c692012-07-18 22:33:52 +000071#ifdef CONFIG_RFS_ACCEL
72
73struct mlx4_en_filter {
74 struct list_head next;
75 struct work_struct work;
76
77 __be32 src_ip;
78 __be32 dst_ip;
79 __be16 src_port;
80 __be16 dst_port;
81
82 int rxq_index;
83 struct mlx4_en_priv *priv;
84 u32 flow_id; /* RFS infrastructure id */
85 int id; /* mlx4_en driver id */
86 u64 reg_id; /* Flow steering API id */
87 u8 activated; /* Used to prevent expiry before filter
88 * is attached
89 */
90 struct hlist_node filter_chain;
91};
92
93static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv);
94
95static void mlx4_en_filter_work(struct work_struct *work)
96{
97 struct mlx4_en_filter *filter = container_of(work,
98 struct mlx4_en_filter,
99 work);
100 struct mlx4_en_priv *priv = filter->priv;
101 struct mlx4_spec_list spec_tcp = {
102 .id = MLX4_NET_TRANS_RULE_ID_TCP,
103 {
104 .tcp_udp = {
105 .dst_port = filter->dst_port,
106 .dst_port_msk = (__force __be16)-1,
107 .src_port = filter->src_port,
108 .src_port_msk = (__force __be16)-1,
109 },
110 },
111 };
112 struct mlx4_spec_list spec_ip = {
113 .id = MLX4_NET_TRANS_RULE_ID_IPV4,
114 {
115 .ipv4 = {
116 .dst_ip = filter->dst_ip,
117 .dst_ip_msk = (__force __be32)-1,
118 .src_ip = filter->src_ip,
119 .src_ip_msk = (__force __be32)-1,
120 },
121 },
122 };
123 struct mlx4_spec_list spec_eth = {
124 .id = MLX4_NET_TRANS_RULE_ID_ETH,
125 };
126 struct mlx4_net_trans_rule rule = {
127 .list = LIST_HEAD_INIT(rule.list),
128 .queue_mode = MLX4_NET_TRANS_Q_LIFO,
129 .exclusive = 1,
130 .allow_loopback = 1,
131 .promisc_mode = MLX4_FS_PROMISC_NONE,
132 .port = priv->port,
133 .priority = MLX4_DOMAIN_RFS,
134 };
135 int rc;
136 __be64 mac;
137 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
138
139 list_add_tail(&spec_eth.list, &rule.list);
140 list_add_tail(&spec_ip.list, &rule.list);
141 list_add_tail(&spec_tcp.list, &rule.list);
142
143 mac = cpu_to_be64((priv->mac & MLX4_MAC_MASK) << 16);
144
145 rule.qpn = priv->rss_map.qps[filter->rxq_index].qpn;
146 memcpy(spec_eth.eth.dst_mac, &mac, ETH_ALEN);
147 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
148
149 filter->activated = 0;
150
151 if (filter->reg_id) {
152 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
153 if (rc && rc != -ENOENT)
154 en_err(priv, "Error detaching flow. rc = %d\n", rc);
155 }
156
157 rc = mlx4_flow_attach(priv->mdev->dev, &rule, &filter->reg_id);
158 if (rc)
159 en_err(priv, "Error attaching flow. err = %d\n", rc);
160
161 mlx4_en_filter_rfs_expire(priv);
162
163 filter->activated = 1;
164}
165
166static inline struct hlist_head *
167filter_hash_bucket(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
168 __be16 src_port, __be16 dst_port)
169{
170 unsigned long l;
171 int bucket_idx;
172
173 l = (__force unsigned long)src_port |
174 ((__force unsigned long)dst_port << 2);
175 l ^= (__force unsigned long)(src_ip ^ dst_ip);
176
177 bucket_idx = hash_long(l, MLX4_EN_FILTER_HASH_SHIFT);
178
179 return &priv->filter_hash[bucket_idx];
180}
181
182static struct mlx4_en_filter *
183mlx4_en_filter_alloc(struct mlx4_en_priv *priv, int rxq_index, __be32 src_ip,
184 __be32 dst_ip, __be16 src_port, __be16 dst_port,
185 u32 flow_id)
186{
187 struct mlx4_en_filter *filter = NULL;
188
189 filter = kzalloc(sizeof(struct mlx4_en_filter), GFP_ATOMIC);
190 if (!filter)
191 return NULL;
192
193 filter->priv = priv;
194 filter->rxq_index = rxq_index;
195 INIT_WORK(&filter->work, mlx4_en_filter_work);
196
197 filter->src_ip = src_ip;
198 filter->dst_ip = dst_ip;
199 filter->src_port = src_port;
200 filter->dst_port = dst_port;
201
202 filter->flow_id = flow_id;
203
Amir Vadaiee64c0e2012-07-25 21:21:16 +0000204 filter->id = priv->last_filter_id++ % RPS_NO_FILTER;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000205
206 list_add_tail(&filter->next, &priv->filters);
207 hlist_add_head(&filter->filter_chain,
208 filter_hash_bucket(priv, src_ip, dst_ip, src_port,
209 dst_port));
210
211 return filter;
212}
213
214static void mlx4_en_filter_free(struct mlx4_en_filter *filter)
215{
216 struct mlx4_en_priv *priv = filter->priv;
217 int rc;
218
219 list_del(&filter->next);
220
221 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
222 if (rc && rc != -ENOENT)
223 en_err(priv, "Error detaching flow. rc = %d\n", rc);
224
225 kfree(filter);
226}
227
228static inline struct mlx4_en_filter *
229mlx4_en_filter_find(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
230 __be16 src_port, __be16 dst_port)
231{
232 struct hlist_node *elem;
233 struct mlx4_en_filter *filter;
234 struct mlx4_en_filter *ret = NULL;
235
236 hlist_for_each_entry(filter, elem,
237 filter_hash_bucket(priv, src_ip, dst_ip,
238 src_port, dst_port),
239 filter_chain) {
240 if (filter->src_ip == src_ip &&
241 filter->dst_ip == dst_ip &&
242 filter->src_port == src_port &&
243 filter->dst_port == dst_port) {
244 ret = filter;
245 break;
246 }
247 }
248
249 return ret;
250}
251
252static int
253mlx4_en_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
254 u16 rxq_index, u32 flow_id)
255{
256 struct mlx4_en_priv *priv = netdev_priv(net_dev);
257 struct mlx4_en_filter *filter;
258 const struct iphdr *ip;
259 const __be16 *ports;
260 __be32 src_ip;
261 __be32 dst_ip;
262 __be16 src_port;
263 __be16 dst_port;
264 int nhoff = skb_network_offset(skb);
265 int ret = 0;
266
267 if (skb->protocol != htons(ETH_P_IP))
268 return -EPROTONOSUPPORT;
269
270 ip = (const struct iphdr *)(skb->data + nhoff);
271 if (ip_is_fragment(ip))
272 return -EPROTONOSUPPORT;
273
274 ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl);
275
276 src_ip = ip->saddr;
277 dst_ip = ip->daddr;
278 src_port = ports[0];
279 dst_port = ports[1];
280
281 if (ip->protocol != IPPROTO_TCP)
282 return -EPROTONOSUPPORT;
283
284 spin_lock_bh(&priv->filters_lock);
285 filter = mlx4_en_filter_find(priv, src_ip, dst_ip, src_port, dst_port);
286 if (filter) {
287 if (filter->rxq_index == rxq_index)
288 goto out;
289
290 filter->rxq_index = rxq_index;
291 } else {
292 filter = mlx4_en_filter_alloc(priv, rxq_index,
293 src_ip, dst_ip,
294 src_port, dst_port, flow_id);
295 if (!filter) {
296 ret = -ENOMEM;
297 goto err;
298 }
299 }
300
301 queue_work(priv->mdev->workqueue, &filter->work);
302
303out:
304 ret = filter->id;
305err:
306 spin_unlock_bh(&priv->filters_lock);
307
308 return ret;
309}
310
311void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv,
312 struct mlx4_en_rx_ring *rx_ring)
313{
314 struct mlx4_en_filter *filter, *tmp;
315 LIST_HEAD(del_list);
316
317 spin_lock_bh(&priv->filters_lock);
318 list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
319 list_move(&filter->next, &del_list);
320 hlist_del(&filter->filter_chain);
321 }
322 spin_unlock_bh(&priv->filters_lock);
323
324 list_for_each_entry_safe(filter, tmp, &del_list, next) {
325 cancel_work_sync(&filter->work);
326 mlx4_en_filter_free(filter);
327 }
328}
329
330static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv)
331{
332 struct mlx4_en_filter *filter = NULL, *tmp, *last_filter = NULL;
333 LIST_HEAD(del_list);
334 int i = 0;
335
336 spin_lock_bh(&priv->filters_lock);
337 list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
338 if (i > MLX4_EN_FILTER_EXPIRY_QUOTA)
339 break;
340
341 if (filter->activated &&
342 !work_pending(&filter->work) &&
343 rps_may_expire_flow(priv->dev,
344 filter->rxq_index, filter->flow_id,
345 filter->id)) {
346 list_move(&filter->next, &del_list);
347 hlist_del(&filter->filter_chain);
348 } else
349 last_filter = filter;
350
351 i++;
352 }
353
354 if (last_filter && (&last_filter->next != priv->filters.next))
355 list_move(&priv->filters, &last_filter->next);
356
357 spin_unlock_bh(&priv->filters_lock);
358
359 list_for_each_entry_safe(filter, tmp, &del_list, next)
360 mlx4_en_filter_free(filter);
361}
362#endif
363
Jiri Pirko8e586132011-12-08 19:52:37 -0500364static int mlx4_en_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700365{
366 struct mlx4_en_priv *priv = netdev_priv(dev);
367 struct mlx4_en_dev *mdev = priv->mdev;
368 int err;
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300369 int idx;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700370
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000371 en_dbg(HW, priv, "adding VLAN:%d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700372
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000373 set_bit(vid, priv->active_vlans);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700374
375 /* Add VID to port VLAN filter */
376 mutex_lock(&mdev->state_lock);
377 if (mdev->device_up && priv->port_up) {
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000378 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700379 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000380 en_err(priv, "Failed configuring VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700381 }
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300382 if (mlx4_register_vlan(mdev->dev, priv->port, vid, &idx))
383 en_err(priv, "failed adding vlan %d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700384 mutex_unlock(&mdev->state_lock);
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300385
Jiri Pirko8e586132011-12-08 19:52:37 -0500386 return 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700387}
388
Jiri Pirko8e586132011-12-08 19:52:37 -0500389static int mlx4_en_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700390{
391 struct mlx4_en_priv *priv = netdev_priv(dev);
392 struct mlx4_en_dev *mdev = priv->mdev;
393 int err;
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300394 int idx;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700395
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000396 en_dbg(HW, priv, "Killing VID:%d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700397
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000398 clear_bit(vid, priv->active_vlans);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700399
400 /* Remove VID from port VLAN filter */
401 mutex_lock(&mdev->state_lock);
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300402 if (!mlx4_find_cached_vlan(mdev->dev, priv->port, vid, &idx))
403 mlx4_unregister_vlan(mdev->dev, priv->port, idx);
404 else
405 en_err(priv, "could not find vid %d in cache\n", vid);
406
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700407 if (mdev->device_up && priv->port_up) {
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000408 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700409 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000410 en_err(priv, "Failed configuring VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700411 }
412 mutex_unlock(&mdev->state_lock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500413
414 return 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700415}
416
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000417u64 mlx4_en_mac_to_u64(u8 *addr)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700418{
419 u64 mac = 0;
420 int i;
421
422 for (i = 0; i < ETH_ALEN; i++) {
423 mac <<= 8;
424 mac |= addr[i];
425 }
426 return mac;
427}
428
429static int mlx4_en_set_mac(struct net_device *dev, void *addr)
430{
431 struct mlx4_en_priv *priv = netdev_priv(dev);
432 struct mlx4_en_dev *mdev = priv->mdev;
433 struct sockaddr *saddr = addr;
434
435 if (!is_valid_ether_addr(saddr->sa_data))
436 return -EADDRNOTAVAIL;
437
438 memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
439 priv->mac = mlx4_en_mac_to_u64(dev->dev_addr);
440 queue_work(mdev->workqueue, &priv->mac_task);
441 return 0;
442}
443
444static void mlx4_en_do_set_mac(struct work_struct *work)
445{
446 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
447 mac_task);
448 struct mlx4_en_dev *mdev = priv->mdev;
449 int err = 0;
450
451 mutex_lock(&mdev->state_lock);
452 if (priv->port_up) {
453 /* Remove old MAC and insert the new one */
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000454 err = mlx4_replace_mac(mdev->dev, priv->port,
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000455 priv->base_qpn, priv->mac);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700456 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000457 en_err(priv, "Failed changing HW MAC address\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700458 } else
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000459 en_dbg(HW, priv, "Port is down while "
460 "registering mac, exiting...\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700461
462 mutex_unlock(&mdev->state_lock);
463}
464
465static void mlx4_en_clear_list(struct net_device *dev)
466{
467 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000468 struct mlx4_en_mc_list *tmp, *mc_to_del;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700469
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000470 list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) {
471 list_del(&mc_to_del->list);
472 kfree(mc_to_del);
473 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700474}
475
476static void mlx4_en_cache_mclist(struct net_device *dev)
477{
478 struct mlx4_en_priv *priv = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000479 struct netdev_hw_addr *ha;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000480 struct mlx4_en_mc_list *tmp;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700481
Alexander Guller0e035672011-12-19 04:02:58 +0000482 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000483 netdev_for_each_mc_addr(ha, dev) {
484 tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC);
485 if (!tmp) {
486 en_err(priv, "failed to allocate multicast list\n");
487 mlx4_en_clear_list(dev);
488 return;
489 }
490 memcpy(tmp->addr, ha->addr, ETH_ALEN);
491 list_add_tail(&tmp->list, &priv->mc_list);
492 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700493}
494
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000495static void update_mclist_flags(struct mlx4_en_priv *priv,
496 struct list_head *dst,
497 struct list_head *src)
498{
499 struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc;
500 bool found;
501
502 /* Find all the entries that should be removed from dst,
503 * These are the entries that are not found in src
504 */
505 list_for_each_entry(dst_tmp, dst, list) {
506 found = false;
507 list_for_each_entry(src_tmp, src, list) {
508 if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) {
509 found = true;
510 break;
511 }
512 }
513 if (!found)
514 dst_tmp->action = MCLIST_REM;
515 }
516
517 /* Add entries that exist in src but not in dst
518 * mark them as need to add
519 */
520 list_for_each_entry(src_tmp, src, list) {
521 found = false;
522 list_for_each_entry(dst_tmp, dst, list) {
523 if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) {
524 dst_tmp->action = MCLIST_NONE;
525 found = true;
526 break;
527 }
528 }
529 if (!found) {
530 new_mc = kmalloc(sizeof(struct mlx4_en_mc_list),
531 GFP_KERNEL);
532 if (!new_mc) {
533 en_err(priv, "Failed to allocate current multicast list\n");
534 return;
535 }
536 memcpy(new_mc, src_tmp,
537 sizeof(struct mlx4_en_mc_list));
538 new_mc->action = MCLIST_ADD;
539 list_add_tail(&new_mc->list, dst);
540 }
541 }
542}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700543
544static void mlx4_en_set_multicast(struct net_device *dev)
545{
546 struct mlx4_en_priv *priv = netdev_priv(dev);
547
548 if (!priv->port_up)
549 return;
550
551 queue_work(priv->mdev->workqueue, &priv->mcast_task);
552}
553
554static void mlx4_en_do_set_multicast(struct work_struct *work)
555{
556 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
557 mcast_task);
558 struct mlx4_en_dev *mdev = priv->mdev;
559 struct net_device *dev = priv->dev;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000560 struct mlx4_en_mc_list *mclist, *tmp;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700561 u64 mcast_addr = 0;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000562 u8 mc_list[16] = {0};
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000563 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700564
565 mutex_lock(&mdev->state_lock);
566 if (!mdev->device_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000567 en_dbg(HW, priv, "Card is not up, "
568 "ignoring multicast change.\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700569 goto out;
570 }
571 if (!priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000572 en_dbg(HW, priv, "Port is down, "
573 "ignoring multicast change.\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700574 goto out;
575 }
576
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000577 if (!netif_carrier_ok(dev)) {
578 if (!mlx4_en_QUERY_PORT(mdev, priv->port)) {
579 if (priv->port_state.link_state) {
580 priv->last_link_state = MLX4_DEV_EVENT_PORT_UP;
581 netif_carrier_on(dev);
582 en_dbg(LINK, priv, "Link Up\n");
583 }
584 }
585 }
586
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700587 /*
588 * Promsicuous mode: disable all filters
589 */
590
591 if (dev->flags & IFF_PROMISC) {
592 if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) {
593 if (netif_msg_rx_status(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000594 en_warn(priv, "Entering promiscuous mode\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700595 priv->flags |= MLX4_EN_FLAG_PROMISC;
596
597 /* Enable promiscouos mode */
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000598 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000599 case MLX4_STEERING_MODE_DEVICE_MANAGED:
600 err = mlx4_flow_steer_promisc_add(mdev->dev,
601 priv->port,
602 priv->base_qpn,
603 MLX4_FS_PROMISC_UPLINK);
604 if (err)
605 en_err(priv, "Failed enabling promiscuous mode\n");
606 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
607 break;
608
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000609 case MLX4_STEERING_MODE_B0:
610 err = mlx4_unicast_promisc_add(mdev->dev,
611 priv->base_qpn,
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000612 priv->port);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000613 if (err)
614 en_err(priv, "Failed enabling unicast promiscuous mode\n");
615
616 /* Add the default qp number as multicast
617 * promisc
618 */
619 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
620 err = mlx4_multicast_promisc_add(mdev->dev,
621 priv->base_qpn,
622 priv->port);
623 if (err)
624 en_err(priv, "Failed enabling multicast promiscuous mode\n");
625 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
626 }
627 break;
628
629 case MLX4_STEERING_MODE_A0:
630 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
631 priv->port,
632 priv->base_qpn,
633 1);
634 if (err)
635 en_err(priv, "Failed enabling promiscuous mode\n");
636 break;
637 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700638
639 /* Disable port multicast filter (unconditionally) */
640 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
641 0, MLX4_MCAST_DISABLE);
642 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000643 en_err(priv, "Failed disabling "
644 "multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700645
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000646 /* Disable port VLAN filter */
647 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
648 if (err)
649 en_err(priv, "Failed disabling VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700650 }
651 goto out;
652 }
653
654 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300655 * Not in promiscuous mode
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700656 */
657
658 if (priv->flags & MLX4_EN_FLAG_PROMISC) {
659 if (netif_msg_rx_status(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000660 en_warn(priv, "Leaving promiscuous mode\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700661 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
662
663 /* Disable promiscouos mode */
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000664 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000665 case MLX4_STEERING_MODE_DEVICE_MANAGED:
666 err = mlx4_flow_steer_promisc_remove(mdev->dev,
667 priv->port,
668 MLX4_FS_PROMISC_UPLINK);
669 if (err)
670 en_err(priv, "Failed disabling promiscuous mode\n");
671 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
672 break;
673
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000674 case MLX4_STEERING_MODE_B0:
675 err = mlx4_unicast_promisc_remove(mdev->dev,
676 priv->base_qpn,
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000677 priv->port);
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000678 if (err)
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000679 en_err(priv, "Failed disabling unicast promiscuous mode\n");
680 /* Disable Multicast promisc */
681 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
682 err = mlx4_multicast_promisc_remove(mdev->dev,
683 priv->base_qpn,
684 priv->port);
685 if (err)
686 en_err(priv, "Failed disabling multicast promiscuous mode\n");
687 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
688 }
689 break;
690
691 case MLX4_STEERING_MODE_A0:
692 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
693 priv->port,
694 priv->base_qpn, 0);
695 if (err)
696 en_err(priv, "Failed disabling promiscuous mode\n");
697 break;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000698 }
699
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700700 /* Enable port VLAN filter */
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000701 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700702 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000703 en_err(priv, "Failed enabling VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700704 }
705
706 /* Enable/disable the multicast filter according to IFF_ALLMULTI */
707 if (dev->flags & IFF_ALLMULTI) {
708 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
709 0, MLX4_MCAST_DISABLE);
710 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000711 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000712
713 /* Add the default qp number as multicast promisc */
714 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000715 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000716 case MLX4_STEERING_MODE_DEVICE_MANAGED:
717 err = mlx4_flow_steer_promisc_add(mdev->dev,
718 priv->port,
719 priv->base_qpn,
720 MLX4_FS_PROMISC_ALL_MULTI);
721 break;
722
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000723 case MLX4_STEERING_MODE_B0:
724 err = mlx4_multicast_promisc_add(mdev->dev,
725 priv->base_qpn,
726 priv->port);
727 break;
728
729 case MLX4_STEERING_MODE_A0:
730 break;
731 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000732 if (err)
733 en_err(priv, "Failed entering multicast promisc mode\n");
734 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
735 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700736 } else {
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000737 /* Disable Multicast promisc */
738 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000739 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000740 case MLX4_STEERING_MODE_DEVICE_MANAGED:
741 err = mlx4_flow_steer_promisc_remove(mdev->dev,
742 priv->port,
743 MLX4_FS_PROMISC_ALL_MULTI);
744 break;
745
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000746 case MLX4_STEERING_MODE_B0:
747 err = mlx4_multicast_promisc_remove(mdev->dev,
748 priv->base_qpn,
749 priv->port);
750 break;
751
752 case MLX4_STEERING_MODE_A0:
753 break;
754 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000755 if (err)
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300756 en_err(priv, "Failed disabling multicast promiscuous mode\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000757 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
758 }
Jiri Pirkoff6e2162010-03-01 05:09:14 +0000759
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700760 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
761 0, MLX4_MCAST_DISABLE);
762 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000763 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700764
765 /* Flush mcast filter and init it with broadcast address */
766 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST,
767 1, MLX4_MCAST_CONFIG);
768
769 /* Update multicast list - we cache all addresses so they won't
770 * change while HW is updated holding the command semaphor */
771 netif_tx_lock_bh(dev);
772 mlx4_en_cache_mclist(dev);
773 netif_tx_unlock_bh(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000774 list_for_each_entry(mclist, &priv->mc_list, list) {
775 mcast_addr = mlx4_en_mac_to_u64(mclist->addr);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700776 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port,
777 mcast_addr, 0, MLX4_MCAST_CONFIG);
778 }
779 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
780 0, MLX4_MCAST_ENABLE);
781 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000782 en_err(priv, "Failed enabling multicast filter\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000783
784 update_mclist_flags(priv, &priv->curr_list, &priv->mc_list);
785 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
786 if (mclist->action == MCLIST_REM) {
787 /* detach this address and delete from list */
788 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
789 mc_list[5] = priv->port;
790 err = mlx4_multicast_detach(mdev->dev,
791 &priv->rss_map.indir_qp,
792 mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000793 MLX4_PROT_ETH,
794 mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000795 if (err)
796 en_err(priv, "Fail to detach multicast address\n");
797
798 /* remove from list */
799 list_del(&mclist->list);
800 kfree(mclist);
Dan Carpenter9c645082012-07-10 20:34:07 +0000801 } else if (mclist->action == MCLIST_ADD) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000802 /* attach the address */
803 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000804 /* needed for B0 steering support */
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000805 mc_list[5] = priv->port;
806 err = mlx4_multicast_attach(mdev->dev,
807 &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000808 mc_list,
809 priv->port, 0,
810 MLX4_PROT_ETH,
811 &mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000812 if (err)
813 en_err(priv, "Fail to attach multicast address\n");
814
815 }
816 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700817 }
818out:
819 mutex_unlock(&mdev->state_lock);
820}
821
822#ifdef CONFIG_NET_POLL_CONTROLLER
823static void mlx4_en_netpoll(struct net_device *dev)
824{
825 struct mlx4_en_priv *priv = netdev_priv(dev);
826 struct mlx4_en_cq *cq;
827 unsigned long flags;
828 int i;
829
830 for (i = 0; i < priv->rx_ring_num; i++) {
831 cq = &priv->rx_cq[i];
832 spin_lock_irqsave(&cq->lock, flags);
833 napi_synchronize(&cq->napi);
834 mlx4_en_process_rx_cq(dev, cq, 0);
835 spin_unlock_irqrestore(&cq->lock, flags);
836 }
837}
838#endif
839
840static void mlx4_en_tx_timeout(struct net_device *dev)
841{
842 struct mlx4_en_priv *priv = netdev_priv(dev);
843 struct mlx4_en_dev *mdev = priv->mdev;
844
845 if (netif_msg_timer(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000846 en_warn(priv, "Tx timeout called on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700847
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +0000848 priv->port_stats.tx_timeout++;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000849 en_dbg(DRV, priv, "Scheduling watchdog\n");
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +0000850 queue_work(mdev->workqueue, &priv->watchdog_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700851}
852
853
854static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev)
855{
856 struct mlx4_en_priv *priv = netdev_priv(dev);
857
858 spin_lock_bh(&priv->stats_lock);
859 memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats));
860 spin_unlock_bh(&priv->stats_lock);
861
862 return &priv->ret_stats;
863}
864
865static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv)
866{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700867 struct mlx4_en_cq *cq;
868 int i;
869
870 /* If we haven't received a specific coalescing setting
Martin Olsson98a17082009-04-22 18:21:29 +0200871 * (module param), we set the moderation parameters as follows:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700872 * - moder_cnt is set to the number of mtu sized packets to
Eric Dumazetecfd2ce2012-11-05 16:20:42 +0000873 * satisfy our coalescing target.
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700874 * - moder_time is set to a fixed value.
875 */
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +0000876 priv->rx_frames = MLX4_EN_RX_COAL_TARGET;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -0800877 priv->rx_usecs = MLX4_EN_RX_COAL_TIME;
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000878 priv->tx_frames = MLX4_EN_TX_COAL_PKTS;
879 priv->tx_usecs = MLX4_EN_TX_COAL_TIME;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000880 en_dbg(INTR, priv, "Default coalesing params for mtu:%d - "
881 "rx_frames:%d rx_usecs:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700882 priv->dev->mtu, priv->rx_frames, priv->rx_usecs);
883
884 /* Setup cq moderation params */
885 for (i = 0; i < priv->rx_ring_num; i++) {
886 cq = &priv->rx_cq[i];
887 cq->moder_cnt = priv->rx_frames;
888 cq->moder_time = priv->rx_usecs;
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000889 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
890 priv->last_moder_packets[i] = 0;
891 priv->last_moder_bytes[i] = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700892 }
893
894 for (i = 0; i < priv->tx_ring_num; i++) {
895 cq = &priv->tx_cq[i];
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000896 cq->moder_cnt = priv->tx_frames;
897 cq->moder_time = priv->tx_usecs;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700898 }
899
900 /* Reset auto-moderation params */
901 priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW;
902 priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW;
903 priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH;
904 priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH;
905 priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -0800906 priv->adaptive_rx_coal = 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700907 priv->last_moder_jiffies = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700908 priv->last_moder_tx_packets = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700909}
910
911static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv)
912{
913 unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700914 struct mlx4_en_cq *cq;
915 unsigned long packets;
916 unsigned long rate;
917 unsigned long avg_pkt_size;
918 unsigned long rx_packets;
919 unsigned long rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700920 unsigned long rx_pkt_diff;
921 int moder_time;
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000922 int ring, err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700923
924 if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ)
925 return;
926
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000927 for (ring = 0; ring < priv->rx_ring_num; ring++) {
928 spin_lock_bh(&priv->stats_lock);
929 rx_packets = priv->rx_ring[ring].packets;
930 rx_bytes = priv->rx_ring[ring].bytes;
931 spin_unlock_bh(&priv->stats_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700932
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000933 rx_pkt_diff = ((unsigned long) (rx_packets -
934 priv->last_moder_packets[ring]));
935 packets = rx_pkt_diff;
936 rate = packets * HZ / period;
937 avg_pkt_size = packets ? ((unsigned long) (rx_bytes -
938 priv->last_moder_bytes[ring])) / packets : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700939
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000940 /* Apply auto-moderation only when packet rate
941 * exceeds a rate that it matters */
942 if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) &&
943 avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700944 if (rate < priv->pkt_rate_low)
945 moder_time = priv->rx_usecs_low;
946 else if (rate > priv->pkt_rate_high)
947 moder_time = priv->rx_usecs_high;
948 else
949 moder_time = (rate - priv->pkt_rate_low) *
950 (priv->rx_usecs_high - priv->rx_usecs_low) /
951 (priv->pkt_rate_high - priv->pkt_rate_low) +
952 priv->rx_usecs_low;
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000953 } else {
954 moder_time = priv->rx_usecs_low;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700955 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700956
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000957 if (moder_time != priv->last_moder_time[ring]) {
958 priv->last_moder_time[ring] = moder_time;
959 cq = &priv->rx_cq[ring];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700960 cq->moder_time = moder_time;
961 err = mlx4_en_set_cq_moder(priv, cq);
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000962 if (err)
963 en_err(priv, "Failed modifying moderation "
964 "for cq:%d\n", ring);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700965 }
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000966 priv->last_moder_packets[ring] = rx_packets;
967 priv->last_moder_bytes[ring] = rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700968 }
969
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700970 priv->last_moder_jiffies = jiffies;
971}
972
973static void mlx4_en_do_get_stats(struct work_struct *work)
974{
Jean Delvarebf6aede2009-04-02 16:56:54 -0700975 struct delayed_work *delay = to_delayed_work(work);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700976 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
977 stats_task);
978 struct mlx4_en_dev *mdev = priv->mdev;
979 int err;
980
981 err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0);
982 if (err)
Frans Pop2381a552010-03-24 07:57:36 +0000983 en_dbg(HW, priv, "Could not update stats\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700984
985 mutex_lock(&mdev->state_lock);
986 if (mdev->device_up) {
987 if (priv->port_up)
988 mlx4_en_auto_moderation(priv);
989
990 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
991 }
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +0000992 if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
993 queue_work(mdev->workqueue, &priv->mac_task);
994 mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
995 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700996 mutex_unlock(&mdev->state_lock);
997}
998
999static void mlx4_en_linkstate(struct work_struct *work)
1000{
1001 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1002 linkstate_task);
1003 struct mlx4_en_dev *mdev = priv->mdev;
1004 int linkstate = priv->link_state;
1005
1006 mutex_lock(&mdev->state_lock);
1007 /* If observable port state changed set carrier state and
1008 * report to system log */
1009 if (priv->last_link_state != linkstate) {
1010 if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001011 en_info(priv, "Link Down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001012 netif_carrier_off(priv->dev);
1013 } else {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001014 en_info(priv, "Link Up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001015 netif_carrier_on(priv->dev);
1016 }
1017 }
1018 priv->last_link_state = linkstate;
1019 mutex_unlock(&mdev->state_lock);
1020}
1021
1022
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001023int mlx4_en_start_port(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001024{
1025 struct mlx4_en_priv *priv = netdev_priv(dev);
1026 struct mlx4_en_dev *mdev = priv->mdev;
1027 struct mlx4_en_cq *cq;
1028 struct mlx4_en_tx_ring *tx_ring;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001029 int rx_index = 0;
1030 int tx_index = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001031 int err = 0;
1032 int i;
1033 int j;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001034 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001035
1036 if (priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001037 en_dbg(DRV, priv, "start port called while port already up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001038 return 0;
1039 }
1040
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001041 INIT_LIST_HEAD(&priv->mc_list);
1042 INIT_LIST_HEAD(&priv->curr_list);
1043
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001044 /* Calculate Rx buf size */
1045 dev->mtu = min(dev->mtu, priv->max_mtu);
1046 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001047 en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_skb_size);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001048
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001049 /* Configure rx cq's and rings */
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001050 err = mlx4_en_activate_rx_rings(priv);
1051 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001052 en_err(priv, "Failed to activate RX rings\n");
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001053 return err;
1054 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001055 for (i = 0; i < priv->rx_ring_num; i++) {
1056 cq = &priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001057
Alexander Guller76532d02011-10-09 05:26:31 +00001058 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001059 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001060 en_err(priv, "Failed activating Rx CQ\n");
Yevgeny Petrilina4233302009-04-26 20:41:34 +00001061 goto cq_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001062 }
1063 for (j = 0; j < cq->size; j++)
1064 cq->buf[j].owner_sr_opcode = MLX4_CQE_OWNER_MASK;
1065 err = mlx4_en_set_cq_moder(priv, cq);
1066 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001067 en_err(priv, "Failed setting cq moderation parameters");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001068 mlx4_en_deactivate_cq(priv, cq);
1069 goto cq_err;
1070 }
1071 mlx4_en_arm_cq(priv, cq);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001072 priv->rx_ring[i].cqn = cq->mcq.cqn;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001073 ++rx_index;
1074 }
1075
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001076 /* Set qp number */
1077 en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port);
1078 err = mlx4_get_eth_qp(mdev->dev, priv->port,
1079 priv->mac, &priv->base_qpn);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001080 if (err) {
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001081 en_err(priv, "Failed getting eth qp\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001082 goto cq_err;
1083 }
1084 mdev->mac_removed[priv->port] = 0;
1085
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001086 err = mlx4_en_config_rss_steer(priv);
1087 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001088 en_err(priv, "Failed configuring rss steering\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001089 goto mac_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001090 }
1091
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001092 err = mlx4_en_create_drop_qp(priv);
1093 if (err)
1094 goto rss_err;
1095
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001096 /* Configure tx cq's and rings */
1097 for (i = 0; i < priv->tx_ring_num; i++) {
1098 /* Configure cq */
1099 cq = &priv->tx_cq[i];
Alexander Guller76532d02011-10-09 05:26:31 +00001100 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001101 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001102 en_err(priv, "Failed allocating Tx CQ\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001103 goto tx_err;
1104 }
1105 err = mlx4_en_set_cq_moder(priv, cq);
1106 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001107 en_err(priv, "Failed setting cq moderation parameters");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001108 mlx4_en_deactivate_cq(priv, cq);
1109 goto tx_err;
1110 }
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001111 en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001112 cq->buf->wqe_index = cpu_to_be16(0xffff);
1113
1114 /* Configure ring */
1115 tx_ring = &priv->tx_ring[i];
Amir Vadai0e98b522012-04-04 21:33:24 +00001116 err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn,
Amir Vadaibc6a4742012-05-17 00:58:10 +00001117 i / priv->mdev->profile.num_tx_rings_p_up);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001118 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001119 en_err(priv, "Failed allocating Tx ring\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001120 mlx4_en_deactivate_cq(priv, cq);
1121 goto tx_err;
1122 }
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001123 tx_ring->tx_queue = netdev_get_tx_queue(dev, i);
Yevgeny Petriline22979d2012-04-23 02:18:39 +00001124
1125 /* Arm CQ for TX completions */
1126 mlx4_en_arm_cq(priv, cq);
1127
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001128 /* Set initial ownership of all Tx TXBBs to SW (1) */
1129 for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE)
1130 *((u32 *) (tx_ring->buf + j)) = 0xffffffff;
1131 ++tx_index;
1132 }
1133
1134 /* Configure port */
1135 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
1136 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001137 priv->prof->tx_pause,
1138 priv->prof->tx_ppp,
1139 priv->prof->rx_pause,
1140 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001141 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001142 en_err(priv, "Failed setting port general configurations "
1143 "for port %d, with error %d\n", priv->port, err);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001144 goto tx_err;
1145 }
1146 /* Set default qp number */
1147 err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0);
1148 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001149 en_err(priv, "Failed setting default qp numbers\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001150 goto tx_err;
1151 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001152
1153 /* Init port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001154 en_dbg(HW, priv, "Initializing port\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001155 err = mlx4_INIT_PORT(mdev->dev, priv->port);
1156 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001157 en_err(priv, "Failed Initializing port\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001158 goto tx_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001159 }
1160
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001161 /* Attach rx QP to bradcast address */
1162 memset(&mc_list[10], 0xff, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001163 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001164 if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001165 priv->port, 0, MLX4_PROT_ETH,
1166 &priv->broadcast_id))
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001167 mlx4_warn(mdev, "Failed Attaching Broadcast\n");
1168
Herbert Xub5845f92011-03-27 01:01:26 +00001169 /* Must redo promiscuous mode setup. */
1170 priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001171 if (mdev->dev->caps.steering_mode ==
1172 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1173 mlx4_flow_steer_promisc_remove(mdev->dev,
1174 priv->port,
1175 MLX4_FS_PROMISC_UPLINK);
1176 mlx4_flow_steer_promisc_remove(mdev->dev,
1177 priv->port,
1178 MLX4_FS_PROMISC_ALL_MULTI);
1179 }
Herbert Xub5845f92011-03-27 01:01:26 +00001180
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001181 /* Schedule multicast task to populate multicast list */
1182 queue_work(mdev->workqueue, &priv->mcast_task);
1183
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +00001184 mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap);
1185
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001186 priv->port_up = true;
Yevgeny Petrilina11faac2009-06-20 22:15:46 +00001187 netif_tx_start_all_queues(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001188 return 0;
1189
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001190tx_err:
1191 while (tx_index--) {
1192 mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[tx_index]);
1193 mlx4_en_deactivate_cq(priv, &priv->tx_cq[tx_index]);
1194 }
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001195 mlx4_en_destroy_drop_qp(priv);
1196rss_err:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001197 mlx4_en_release_rss_steer(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001198mac_err:
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001199 mlx4_put_eth_qp(mdev->dev, priv->port, priv->mac, priv->base_qpn);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001200cq_err:
1201 while (rx_index--)
1202 mlx4_en_deactivate_cq(priv, &priv->rx_cq[rx_index]);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001203 for (i = 0; i < priv->rx_ring_num; i++)
1204 mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001205
1206 return err; /* need to close devices */
1207}
1208
1209
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001210void mlx4_en_stop_port(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001211{
1212 struct mlx4_en_priv *priv = netdev_priv(dev);
1213 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001214 struct mlx4_en_mc_list *mclist, *tmp;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001215 int i;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001216 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001217
1218 if (!priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001219 en_dbg(DRV, priv, "stop port called while port already down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001220 return;
1221 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001222
1223 /* Synchronize with tx routine */
1224 netif_tx_lock_bh(dev);
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001225 netif_tx_stop_all_queues(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001226 netif_tx_unlock_bh(dev);
1227
Yevgeny Petrilin7c287382010-08-24 03:45:45 +00001228 /* Set port as not active */
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001229 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001230
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001231 /* Detach All multicasts */
1232 memset(&mc_list[10], 0xff, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001233 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001234 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001235 MLX4_PROT_ETH, priv->broadcast_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001236 list_for_each_entry(mclist, &priv->curr_list, list) {
1237 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001238 mc_list[5] = priv->port;
1239 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001240 mc_list, MLX4_PROT_ETH, mclist->reg_id);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001241 }
1242 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001243 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
1244 list_del(&mclist->list);
1245 kfree(mclist);
1246 }
1247
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001248 /* Flush multicast filter */
1249 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG);
1250
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001251 mlx4_en_destroy_drop_qp(priv);
1252
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001253 /* Free TX Rings */
1254 for (i = 0; i < priv->tx_ring_num; i++) {
1255 mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[i]);
1256 mlx4_en_deactivate_cq(priv, &priv->tx_cq[i]);
1257 }
1258 msleep(10);
1259
1260 for (i = 0; i < priv->tx_ring_num; i++)
1261 mlx4_en_free_tx_buf(dev, &priv->tx_ring[i]);
1262
1263 /* Free RSS qps */
1264 mlx4_en_release_rss_steer(priv);
1265
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001266 /* Unregister Mac address for the port */
1267 mlx4_put_eth_qp(mdev->dev, priv->port, priv->mac, priv->base_qpn);
1268 mdev->mac_removed[priv->port] = 1;
1269
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001270 /* Free RX Rings */
1271 for (i = 0; i < priv->rx_ring_num; i++) {
1272 mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]);
1273 while (test_bit(NAPI_STATE_SCHED, &priv->rx_cq[i].napi.state))
1274 msleep(1);
1275 mlx4_en_deactivate_cq(priv, &priv->rx_cq[i]);
1276 }
Yevgeny Petrilin7c287382010-08-24 03:45:45 +00001277
1278 /* close port*/
1279 mlx4_CLOSE_PORT(mdev->dev, priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001280}
1281
1282static void mlx4_en_restart(struct work_struct *work)
1283{
1284 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1285 watchdog_task);
1286 struct mlx4_en_dev *mdev = priv->mdev;
1287 struct net_device *dev = priv->dev;
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001288 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001289
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001290 en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001291
1292 mutex_lock(&mdev->state_lock);
1293 if (priv->port_up) {
1294 mlx4_en_stop_port(dev);
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001295 for (i = 0; i < priv->tx_ring_num; i++)
1296 netdev_tx_reset_queue(priv->tx_ring[i].tx_queue);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001297 if (mlx4_en_start_port(dev))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001298 en_err(priv, "Failed restarting port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001299 }
1300 mutex_unlock(&mdev->state_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001301}
1302
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001303static void mlx4_en_clear_stats(struct net_device *dev)
1304{
1305 struct mlx4_en_priv *priv = netdev_priv(dev);
1306 struct mlx4_en_dev *mdev = priv->mdev;
1307 int i;
1308
1309 if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1))
1310 en_dbg(HW, priv, "Failed dumping statistics\n");
1311
1312 memset(&priv->stats, 0, sizeof(priv->stats));
1313 memset(&priv->pstats, 0, sizeof(priv->pstats));
1314 memset(&priv->pkstats, 0, sizeof(priv->pkstats));
1315 memset(&priv->port_stats, 0, sizeof(priv->port_stats));
1316
1317 for (i = 0; i < priv->tx_ring_num; i++) {
1318 priv->tx_ring[i].bytes = 0;
1319 priv->tx_ring[i].packets = 0;
1320 priv->tx_ring[i].tx_csum = 0;
1321 }
1322 for (i = 0; i < priv->rx_ring_num; i++) {
1323 priv->rx_ring[i].bytes = 0;
1324 priv->rx_ring[i].packets = 0;
1325 priv->rx_ring[i].csum_ok = 0;
1326 priv->rx_ring[i].csum_none = 0;
1327 }
1328}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001329
1330static int mlx4_en_open(struct net_device *dev)
1331{
1332 struct mlx4_en_priv *priv = netdev_priv(dev);
1333 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001334 int err = 0;
1335
1336 mutex_lock(&mdev->state_lock);
1337
1338 if (!mdev->device_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001339 en_err(priv, "Cannot open - device down/disabled\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001340 err = -EBUSY;
1341 goto out;
1342 }
1343
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001344 /* Reset HW statistics and SW counters */
1345 mlx4_en_clear_stats(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001346
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001347 err = mlx4_en_start_port(dev);
1348 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001349 en_err(priv, "Failed starting port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001350
1351out:
1352 mutex_unlock(&mdev->state_lock);
1353 return err;
1354}
1355
1356
1357static int mlx4_en_close(struct net_device *dev)
1358{
1359 struct mlx4_en_priv *priv = netdev_priv(dev);
1360 struct mlx4_en_dev *mdev = priv->mdev;
1361
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001362 en_dbg(IFDOWN, priv, "Close port called\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001363
1364 mutex_lock(&mdev->state_lock);
1365
1366 mlx4_en_stop_port(dev);
1367 netif_carrier_off(dev);
1368
1369 mutex_unlock(&mdev->state_lock);
1370 return 0;
1371}
1372
Alexander Gullerfe0af032011-10-09 05:26:46 +00001373void mlx4_en_free_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001374{
1375 int i;
1376
Amir Vadai1eb8c692012-07-18 22:33:52 +00001377#ifdef CONFIG_RFS_ACCEL
1378 free_irq_cpu_rmap(priv->dev->rx_cpu_rmap);
1379 priv->dev->rx_cpu_rmap = NULL;
1380#endif
1381
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001382 for (i = 0; i < priv->tx_ring_num; i++) {
1383 if (priv->tx_ring[i].tx_info)
1384 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
1385 if (priv->tx_cq[i].buf)
Alexander Gullerfe0af032011-10-09 05:26:46 +00001386 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001387 }
1388
1389 for (i = 0; i < priv->rx_ring_num; i++) {
1390 if (priv->rx_ring[i].rx_info)
Thadeu Lima de Souza Cascardo68355f72012-02-06 08:39:49 +00001391 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
1392 priv->prof->rx_ring_size, priv->stride);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001393 if (priv->rx_cq[i].buf)
Alexander Gullerfe0af032011-10-09 05:26:46 +00001394 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001395 }
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001396
1397 if (priv->base_tx_qpn) {
1398 mlx4_qp_release_range(priv->mdev->dev, priv->base_tx_qpn, priv->tx_ring_num);
1399 priv->base_tx_qpn = 0;
1400 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001401}
1402
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001403int mlx4_en_alloc_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001404{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001405 struct mlx4_en_port_profile *prof = priv->prof;
1406 int i;
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001407 int err;
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001408
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001409 err = mlx4_qp_reserve_range(priv->mdev->dev, priv->tx_ring_num, 256, &priv->base_tx_qpn);
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001410 if (err) {
1411 en_err(priv, "failed reserving range for TX rings\n");
1412 return err;
1413 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001414
1415 /* Create tx Rings */
1416 for (i = 0; i < priv->tx_ring_num; i++) {
1417 if (mlx4_en_create_cq(priv, &priv->tx_cq[i],
1418 prof->tx_ring_size, i, TX))
1419 goto err;
1420
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001421 if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i], priv->base_tx_qpn + i,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001422 prof->tx_ring_size, TXBB_SIZE))
1423 goto err;
1424 }
1425
1426 /* Create rx Rings */
1427 for (i = 0; i < priv->rx_ring_num; i++) {
1428 if (mlx4_en_create_cq(priv, &priv->rx_cq[i],
1429 prof->rx_ring_size, i, RX))
1430 goto err;
1431
1432 if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i],
1433 prof->rx_ring_size, priv->stride))
1434 goto err;
1435 }
1436
Amir Vadai1eb8c692012-07-18 22:33:52 +00001437#ifdef CONFIG_RFS_ACCEL
1438 priv->dev->rx_cpu_rmap = alloc_irq_cpu_rmap(priv->rx_ring_num);
1439 if (!priv->dev->rx_cpu_rmap)
1440 goto err;
1441
1442 INIT_LIST_HEAD(&priv->filters);
1443 spin_lock_init(&priv->filters_lock);
1444#endif
1445
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001446 return 0;
1447
1448err:
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001449 en_err(priv, "Failed to allocate NIC resources\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001450 return -ENOMEM;
1451}
1452
1453
1454void mlx4_en_destroy_netdev(struct net_device *dev)
1455{
1456 struct mlx4_en_priv *priv = netdev_priv(dev);
1457 struct mlx4_en_dev *mdev = priv->mdev;
1458
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001459 en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001460
1461 /* Unregister device - this will close the port if it was up */
1462 if (priv->registered)
1463 unregister_netdev(dev);
1464
1465 if (priv->allocated)
1466 mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE);
1467
1468 cancel_delayed_work(&priv->stats_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001469 /* flush any pending task for this netdev */
1470 flush_workqueue(mdev->workqueue);
1471
1472 /* Detach the netdev so tasks would not attempt to access it */
1473 mutex_lock(&mdev->state_lock);
1474 mdev->pndev[priv->port] = NULL;
1475 mutex_unlock(&mdev->state_lock);
1476
Alexander Gullerfe0af032011-10-09 05:26:46 +00001477 mlx4_en_free_resources(priv);
Amir Vadai564c2742012-04-04 21:33:26 +00001478
Amir Vadaibc6a4742012-05-17 00:58:10 +00001479 kfree(priv->tx_ring);
1480 kfree(priv->tx_cq);
1481
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001482 free_netdev(dev);
1483}
1484
1485static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
1486{
1487 struct mlx4_en_priv *priv = netdev_priv(dev);
1488 struct mlx4_en_dev *mdev = priv->mdev;
1489 int err = 0;
1490
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001491 en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001492 dev->mtu, new_mtu);
1493
1494 if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001495 en_err(priv, "Bad MTU size:%d.\n", new_mtu);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001496 return -EPERM;
1497 }
1498 dev->mtu = new_mtu;
1499
1500 if (netif_running(dev)) {
1501 mutex_lock(&mdev->state_lock);
1502 if (!mdev->device_up) {
1503 /* NIC is probably restarting - let watchdog task reset
1504 * the port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001505 en_dbg(DRV, priv, "Change MTU called with card down!?\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001506 } else {
1507 mlx4_en_stop_port(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001508 err = mlx4_en_start_port(dev);
1509 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001510 en_err(priv, "Failed restarting port:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001511 priv->port);
1512 queue_work(mdev->workqueue, &priv->watchdog_task);
1513 }
1514 }
1515 mutex_unlock(&mdev->state_lock);
1516 }
1517 return 0;
1518}
1519
Amir Vadai60d6fe92011-11-26 19:55:19 +00001520static int mlx4_en_set_features(struct net_device *netdev,
1521 netdev_features_t features)
1522{
1523 struct mlx4_en_priv *priv = netdev_priv(netdev);
1524
1525 if (features & NETIF_F_LOOPBACK)
1526 priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
1527 else
1528 priv->ctrl_flags &=
1529 cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK);
1530
1531 return 0;
1532
1533}
1534
Stephen Hemminger3addc562008-11-21 17:30:58 -08001535static const struct net_device_ops mlx4_netdev_ops = {
1536 .ndo_open = mlx4_en_open,
1537 .ndo_stop = mlx4_en_close,
1538 .ndo_start_xmit = mlx4_en_xmit,
Yevgeny Petrilinf813cad2009-06-01 23:24:07 +00001539 .ndo_select_queue = mlx4_en_select_queue,
Stephen Hemminger3addc562008-11-21 17:30:58 -08001540 .ndo_get_stats = mlx4_en_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00001541 .ndo_set_rx_mode = mlx4_en_set_multicast,
Stephen Hemminger3addc562008-11-21 17:30:58 -08001542 .ndo_set_mac_address = mlx4_en_set_mac,
Stephen Hemminger52255bb2009-01-09 10:45:37 +00001543 .ndo_validate_addr = eth_validate_addr,
Stephen Hemminger3addc562008-11-21 17:30:58 -08001544 .ndo_change_mtu = mlx4_en_change_mtu,
1545 .ndo_tx_timeout = mlx4_en_tx_timeout,
Stephen Hemminger3addc562008-11-21 17:30:58 -08001546 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
1547 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
1548#ifdef CONFIG_NET_POLL_CONTROLLER
1549 .ndo_poll_controller = mlx4_en_netpoll,
1550#endif
Amir Vadai60d6fe92011-11-26 19:55:19 +00001551 .ndo_set_features = mlx4_en_set_features,
Amir Vadai897d7842012-04-04 21:33:27 +00001552 .ndo_setup_tc = mlx4_en_setup_tc,
Amir Vadai1eb8c692012-07-18 22:33:52 +00001553#ifdef CONFIG_RFS_ACCEL
1554 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
1555#endif
Stephen Hemminger3addc562008-11-21 17:30:58 -08001556};
1557
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001558int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
1559 struct mlx4_en_port_profile *prof)
1560{
1561 struct net_device *dev;
1562 struct mlx4_en_priv *priv;
1563 int i;
1564 int err;
1565
Tom Herbertf1593d22011-01-09 19:36:36 +00001566 dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv),
1567 prof->tx_ring_num, prof->rx_ring_num);
Joe Perches41de8d42012-01-29 13:47:52 +00001568 if (dev == NULL)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001569 return -ENOMEM;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001570
1571 SET_NETDEV_DEV(dev, &mdev->dev->pdev->dev);
Eli Cohen741a00b2010-05-26 19:56:24 +00001572 dev->dev_id = port - 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001573
1574 /*
1575 * Initialize driver private data
1576 */
1577
1578 priv = netdev_priv(dev);
1579 memset(priv, 0, sizeof(struct mlx4_en_priv));
1580 priv->dev = dev;
1581 priv->mdev = mdev;
Yevgeny Petrilinebf8c9a2012-03-06 04:03:34 +00001582 priv->ddev = &mdev->pdev->dev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001583 priv->prof = prof;
1584 priv->port = port;
1585 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001586 priv->flags = prof->flags;
Amir Vadai60d6fe92011-11-26 19:55:19 +00001587 priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE |
1588 MLX4_WQE_CTRL_SOLICITED);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001589 priv->tx_ring_num = prof->tx_ring_num;
Amir Vadaibc6a4742012-05-17 00:58:10 +00001590 priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring) *
1591 priv->tx_ring_num, GFP_KERNEL);
1592 if (!priv->tx_ring) {
1593 err = -ENOMEM;
1594 goto out;
1595 }
1596 priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq) * priv->tx_ring_num,
1597 GFP_KERNEL);
1598 if (!priv->tx_cq) {
1599 err = -ENOMEM;
1600 goto out;
1601 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001602 priv->rx_ring_num = prof->rx_ring_num;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001603 priv->mac_index = -1;
1604 priv->msg_enable = MLX4_EN_MSG_LEVEL;
1605 spin_lock_init(&priv->stats_lock);
1606 INIT_WORK(&priv->mcast_task, mlx4_en_do_set_multicast);
1607 INIT_WORK(&priv->mac_task, mlx4_en_do_set_mac);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001608 INIT_WORK(&priv->watchdog_task, mlx4_en_restart);
1609 INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate);
1610 INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats);
Amir Vadai564c2742012-04-04 21:33:26 +00001611#ifdef CONFIG_MLX4_EN_DCB
1612 if (!mlx4_is_slave(priv->mdev->dev))
1613 dev->dcbnl_ops = &mlx4_en_dcbnl_ops;
1614#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001615
1616 /* Query for default mac and max mtu */
1617 priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port];
1618 priv->mac = mdev->dev->caps.def_mac[priv->port];
1619 if (ILLEGAL_MAC(priv->mac)) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001620 en_err(priv, "Port: %d, invalid mac burned: 0x%llx, quiting\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001621 priv->port, priv->mac);
1622 err = -EINVAL;
1623 goto out;
1624 }
1625
1626 priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
1627 DS_SIZE * MLX4_EN_MAX_RX_FRAGS);
1628 err = mlx4_en_alloc_resources(priv);
1629 if (err)
1630 goto out;
1631
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001632 /* Allocate page for receive rings */
1633 err = mlx4_alloc_hwq_res(mdev->dev, &priv->res,
1634 MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE);
1635 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001636 en_err(priv, "Failed to allocate page for rx qps\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001637 goto out;
1638 }
1639 priv->allocated = 1;
1640
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001641 /*
1642 * Initialize netdev entry points
1643 */
Stephen Hemminger3addc562008-11-21 17:30:58 -08001644 dev->netdev_ops = &mlx4_netdev_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001645 dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT;
Ben Hutchings1eb63a22010-09-27 08:29:34 +00001646 netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
1647 netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
Stephen Hemminger3addc562008-11-21 17:30:58 -08001648
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001649 SET_ETHTOOL_OPS(dev, &mlx4_en_ethtool_ops);
1650
1651 /* Set defualt MAC */
1652 dev->addr_len = ETH_ALEN;
Yevgeny Petrilin8bf2e582010-08-24 03:45:30 +00001653 for (i = 0; i < ETH_ALEN; i++) {
1654 dev->dev_addr[ETH_ALEN - 1 - i] = (u8) (priv->mac >> (8 * i));
1655 dev->perm_addr[ETH_ALEN - 1 - i] = (u8) (priv->mac >> (8 * i));
1656 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001657
1658 /*
1659 * Set driver features
1660 */
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00001661 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
1662 if (mdev->LSO_support)
1663 dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
1664
1665 dev->vlan_features = dev->hw_features;
1666
Yevgeny Petrilinad861072011-10-18 01:51:24 +00001667 dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH;
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00001668 dev->features = dev->hw_features | NETIF_F_HIGHDMA |
1669 NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
1670 NETIF_F_HW_VLAN_FILTER;
Amir Vadai60d6fe92011-11-26 19:55:19 +00001671 dev->hw_features |= NETIF_F_LOOPBACK;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001672
Amir Vadai1eb8c692012-07-18 22:33:52 +00001673 if (mdev->dev->caps.steering_mode ==
1674 MLX4_STEERING_MODE_DEVICE_MANAGED)
1675 dev->hw_features |= NETIF_F_NTUPLE;
1676
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001677 mdev->pndev[port] = dev;
1678
1679 netif_carrier_off(dev);
1680 err = register_netdev(dev);
1681 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001682 en_err(priv, "Netdev registration failed for port %d\n", port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001683 goto out;
1684 }
Alexander Guller42341442011-10-09 05:29:35 +00001685 priv->registered = 1;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001686
1687 en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num);
1688 en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num);
1689
Yevgeny Petrilin90822262011-03-22 22:37:41 +00001690 /* Configure port */
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00001691 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00001692 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00001693 priv->rx_skb_size + ETH_FCS_LEN,
1694 prof->tx_pause, prof->tx_ppp,
1695 prof->rx_pause, prof->rx_ppp);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00001696 if (err) {
1697 en_err(priv, "Failed setting port general configurations "
1698 "for port %d, with error %d\n", priv->port, err);
1699 goto out;
1700 }
1701
1702 /* Init port */
1703 en_warn(priv, "Initializing port\n");
1704 err = mlx4_INIT_PORT(mdev->dev, priv->port);
1705 if (err) {
1706 en_err(priv, "Failed Initializing port\n");
1707 goto out;
1708 }
Yevgeny Petrilin39f17b42011-03-22 22:37:28 +00001709 mlx4_en_set_default_moderation(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001710 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
1711 return 0;
1712
1713out:
1714 mlx4_en_destroy_netdev(dev);
1715 return err;
1716}
1717