blob: 333a7a0b833cfeef437498f069bbbf0f3011b36d [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 Vadaid3179662012-12-02 03:49:23 +000050int mlx4_en_setup_tc(struct net_device *dev, u8 up)
Amir Vadai897d7842012-04-04 21:33:27 +000051{
Amir Vadaibc6a4742012-05-17 00:58:10 +000052 struct mlx4_en_priv *priv = netdev_priv(dev);
53 int i;
Amir Vadaid3179662012-12-02 03:49:23 +000054 unsigned int offset = 0;
Amir Vadaibc6a4742012-05-17 00:58:10 +000055
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 */
Amir Vadaibc6a4742012-05-17 00:58:10 +000062 for (i = 0; i < up; i++) {
Amir Vadaid3179662012-12-02 03:49:23 +000063 netdev_set_tc_queue(dev, i, priv->num_tx_rings_p_up, offset);
64 offset += priv->num_tx_rings_p_up;
Amir Vadaibc6a4742012-05-17 00:58:10 +000065 }
66
Amir Vadai897d7842012-04-04 21:33:27 +000067 return 0;
68}
69
Amir Vadai1eb8c692012-07-18 22:33:52 +000070#ifdef CONFIG_RFS_ACCEL
71
72struct mlx4_en_filter {
73 struct list_head next;
74 struct work_struct work;
75
76 __be32 src_ip;
77 __be32 dst_ip;
78 __be16 src_port;
79 __be16 dst_port;
80
81 int rxq_index;
82 struct mlx4_en_priv *priv;
83 u32 flow_id; /* RFS infrastructure id */
84 int id; /* mlx4_en driver id */
85 u64 reg_id; /* Flow steering API id */
86 u8 activated; /* Used to prevent expiry before filter
87 * is attached
88 */
89 struct hlist_node filter_chain;
90};
91
92static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv);
93
94static void mlx4_en_filter_work(struct work_struct *work)
95{
96 struct mlx4_en_filter *filter = container_of(work,
97 struct mlx4_en_filter,
98 work);
99 struct mlx4_en_priv *priv = filter->priv;
100 struct mlx4_spec_list spec_tcp = {
101 .id = MLX4_NET_TRANS_RULE_ID_TCP,
102 {
103 .tcp_udp = {
104 .dst_port = filter->dst_port,
105 .dst_port_msk = (__force __be16)-1,
106 .src_port = filter->src_port,
107 .src_port_msk = (__force __be16)-1,
108 },
109 },
110 };
111 struct mlx4_spec_list spec_ip = {
112 .id = MLX4_NET_TRANS_RULE_ID_IPV4,
113 {
114 .ipv4 = {
115 .dst_ip = filter->dst_ip,
116 .dst_ip_msk = (__force __be32)-1,
117 .src_ip = filter->src_ip,
118 .src_ip_msk = (__force __be32)-1,
119 },
120 },
121 };
122 struct mlx4_spec_list spec_eth = {
123 .id = MLX4_NET_TRANS_RULE_ID_ETH,
124 };
125 struct mlx4_net_trans_rule rule = {
126 .list = LIST_HEAD_INIT(rule.list),
127 .queue_mode = MLX4_NET_TRANS_Q_LIFO,
128 .exclusive = 1,
129 .allow_loopback = 1,
130 .promisc_mode = MLX4_FS_PROMISC_NONE,
131 .port = priv->port,
132 .priority = MLX4_DOMAIN_RFS,
133 };
134 int rc;
135 __be64 mac;
136 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
137
138 list_add_tail(&spec_eth.list, &rule.list);
139 list_add_tail(&spec_ip.list, &rule.list);
140 list_add_tail(&spec_tcp.list, &rule.list);
141
142 mac = cpu_to_be64((priv->mac & MLX4_MAC_MASK) << 16);
143
144 rule.qpn = priv->rss_map.qps[filter->rxq_index].qpn;
145 memcpy(spec_eth.eth.dst_mac, &mac, ETH_ALEN);
146 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
147
148 filter->activated = 0;
149
150 if (filter->reg_id) {
151 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
152 if (rc && rc != -ENOENT)
153 en_err(priv, "Error detaching flow. rc = %d\n", rc);
154 }
155
156 rc = mlx4_flow_attach(priv->mdev->dev, &rule, &filter->reg_id);
157 if (rc)
158 en_err(priv, "Error attaching flow. err = %d\n", rc);
159
160 mlx4_en_filter_rfs_expire(priv);
161
162 filter->activated = 1;
163}
164
165static inline struct hlist_head *
166filter_hash_bucket(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
167 __be16 src_port, __be16 dst_port)
168{
169 unsigned long l;
170 int bucket_idx;
171
172 l = (__force unsigned long)src_port |
173 ((__force unsigned long)dst_port << 2);
174 l ^= (__force unsigned long)(src_ip ^ dst_ip);
175
176 bucket_idx = hash_long(l, MLX4_EN_FILTER_HASH_SHIFT);
177
178 return &priv->filter_hash[bucket_idx];
179}
180
181static struct mlx4_en_filter *
182mlx4_en_filter_alloc(struct mlx4_en_priv *priv, int rxq_index, __be32 src_ip,
183 __be32 dst_ip, __be16 src_port, __be16 dst_port,
184 u32 flow_id)
185{
186 struct mlx4_en_filter *filter = NULL;
187
188 filter = kzalloc(sizeof(struct mlx4_en_filter), GFP_ATOMIC);
189 if (!filter)
190 return NULL;
191
192 filter->priv = priv;
193 filter->rxq_index = rxq_index;
194 INIT_WORK(&filter->work, mlx4_en_filter_work);
195
196 filter->src_ip = src_ip;
197 filter->dst_ip = dst_ip;
198 filter->src_port = src_port;
199 filter->dst_port = dst_port;
200
201 filter->flow_id = flow_id;
202
Amir Vadaiee64c0e2012-07-25 21:21:16 +0000203 filter->id = priv->last_filter_id++ % RPS_NO_FILTER;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000204
205 list_add_tail(&filter->next, &priv->filters);
206 hlist_add_head(&filter->filter_chain,
207 filter_hash_bucket(priv, src_ip, dst_ip, src_port,
208 dst_port));
209
210 return filter;
211}
212
213static void mlx4_en_filter_free(struct mlx4_en_filter *filter)
214{
215 struct mlx4_en_priv *priv = filter->priv;
216 int rc;
217
218 list_del(&filter->next);
219
220 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
221 if (rc && rc != -ENOENT)
222 en_err(priv, "Error detaching flow. rc = %d\n", rc);
223
224 kfree(filter);
225}
226
227static inline struct mlx4_en_filter *
228mlx4_en_filter_find(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
229 __be16 src_port, __be16 dst_port)
230{
231 struct hlist_node *elem;
232 struct mlx4_en_filter *filter;
233 struct mlx4_en_filter *ret = NULL;
234
235 hlist_for_each_entry(filter, elem,
236 filter_hash_bucket(priv, src_ip, dst_ip,
237 src_port, dst_port),
238 filter_chain) {
239 if (filter->src_ip == src_ip &&
240 filter->dst_ip == dst_ip &&
241 filter->src_port == src_port &&
242 filter->dst_port == dst_port) {
243 ret = filter;
244 break;
245 }
246 }
247
248 return ret;
249}
250
251static int
252mlx4_en_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
253 u16 rxq_index, u32 flow_id)
254{
255 struct mlx4_en_priv *priv = netdev_priv(net_dev);
256 struct mlx4_en_filter *filter;
257 const struct iphdr *ip;
258 const __be16 *ports;
259 __be32 src_ip;
260 __be32 dst_ip;
261 __be16 src_port;
262 __be16 dst_port;
263 int nhoff = skb_network_offset(skb);
264 int ret = 0;
265
266 if (skb->protocol != htons(ETH_P_IP))
267 return -EPROTONOSUPPORT;
268
269 ip = (const struct iphdr *)(skb->data + nhoff);
270 if (ip_is_fragment(ip))
271 return -EPROTONOSUPPORT;
272
273 ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl);
274
275 src_ip = ip->saddr;
276 dst_ip = ip->daddr;
277 src_port = ports[0];
278 dst_port = ports[1];
279
280 if (ip->protocol != IPPROTO_TCP)
281 return -EPROTONOSUPPORT;
282
283 spin_lock_bh(&priv->filters_lock);
284 filter = mlx4_en_filter_find(priv, src_ip, dst_ip, src_port, dst_port);
285 if (filter) {
286 if (filter->rxq_index == rxq_index)
287 goto out;
288
289 filter->rxq_index = rxq_index;
290 } else {
291 filter = mlx4_en_filter_alloc(priv, rxq_index,
292 src_ip, dst_ip,
293 src_port, dst_port, flow_id);
294 if (!filter) {
295 ret = -ENOMEM;
296 goto err;
297 }
298 }
299
300 queue_work(priv->mdev->workqueue, &filter->work);
301
302out:
303 ret = filter->id;
304err:
305 spin_unlock_bh(&priv->filters_lock);
306
307 return ret;
308}
309
310void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv,
311 struct mlx4_en_rx_ring *rx_ring)
312{
313 struct mlx4_en_filter *filter, *tmp;
314 LIST_HEAD(del_list);
315
316 spin_lock_bh(&priv->filters_lock);
317 list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
318 list_move(&filter->next, &del_list);
319 hlist_del(&filter->filter_chain);
320 }
321 spin_unlock_bh(&priv->filters_lock);
322
323 list_for_each_entry_safe(filter, tmp, &del_list, next) {
324 cancel_work_sync(&filter->work);
325 mlx4_en_filter_free(filter);
326 }
327}
328
329static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv)
330{
331 struct mlx4_en_filter *filter = NULL, *tmp, *last_filter = NULL;
332 LIST_HEAD(del_list);
333 int i = 0;
334
335 spin_lock_bh(&priv->filters_lock);
336 list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
337 if (i > MLX4_EN_FILTER_EXPIRY_QUOTA)
338 break;
339
340 if (filter->activated &&
341 !work_pending(&filter->work) &&
342 rps_may_expire_flow(priv->dev,
343 filter->rxq_index, filter->flow_id,
344 filter->id)) {
345 list_move(&filter->next, &del_list);
346 hlist_del(&filter->filter_chain);
347 } else
348 last_filter = filter;
349
350 i++;
351 }
352
353 if (last_filter && (&last_filter->next != priv->filters.next))
354 list_move(&priv->filters, &last_filter->next);
355
356 spin_unlock_bh(&priv->filters_lock);
357
358 list_for_each_entry_safe(filter, tmp, &del_list, next)
359 mlx4_en_filter_free(filter);
360}
361#endif
362
Jiri Pirko8e586132011-12-08 19:52:37 -0500363static int mlx4_en_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700364{
365 struct mlx4_en_priv *priv = netdev_priv(dev);
366 struct mlx4_en_dev *mdev = priv->mdev;
367 int err;
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300368 int idx;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700369
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000370 en_dbg(HW, priv, "adding VLAN:%d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700371
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000372 set_bit(vid, priv->active_vlans);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700373
374 /* Add VID to port VLAN filter */
375 mutex_lock(&mdev->state_lock);
376 if (mdev->device_up && priv->port_up) {
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000377 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700378 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000379 en_err(priv, "Failed configuring VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700380 }
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300381 if (mlx4_register_vlan(mdev->dev, priv->port, vid, &idx))
382 en_err(priv, "failed adding vlan %d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700383 mutex_unlock(&mdev->state_lock);
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300384
Jiri Pirko8e586132011-12-08 19:52:37 -0500385 return 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700386}
387
Jiri Pirko8e586132011-12-08 19:52:37 -0500388static int mlx4_en_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700389{
390 struct mlx4_en_priv *priv = netdev_priv(dev);
391 struct mlx4_en_dev *mdev = priv->mdev;
392 int err;
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300393 int idx;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700394
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000395 en_dbg(HW, priv, "Killing VID:%d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700396
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000397 clear_bit(vid, priv->active_vlans);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700398
399 /* Remove VID from port VLAN filter */
400 mutex_lock(&mdev->state_lock);
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300401 if (!mlx4_find_cached_vlan(mdev->dev, priv->port, vid, &idx))
402 mlx4_unregister_vlan(mdev->dev, priv->port, idx);
403 else
404 en_err(priv, "could not find vid %d in cache\n", vid);
405
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700406 if (mdev->device_up && priv->port_up) {
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000407 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700408 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000409 en_err(priv, "Failed configuring VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700410 }
411 mutex_unlock(&mdev->state_lock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500412
413 return 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700414}
415
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000416u64 mlx4_en_mac_to_u64(u8 *addr)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700417{
418 u64 mac = 0;
419 int i;
420
421 for (i = 0; i < ETH_ALEN; i++) {
422 mac <<= 8;
423 mac |= addr[i];
424 }
425 return mac;
426}
427
428static int mlx4_en_set_mac(struct net_device *dev, void *addr)
429{
430 struct mlx4_en_priv *priv = netdev_priv(dev);
431 struct mlx4_en_dev *mdev = priv->mdev;
432 struct sockaddr *saddr = addr;
433
434 if (!is_valid_ether_addr(saddr->sa_data))
435 return -EADDRNOTAVAIL;
436
437 memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
438 priv->mac = mlx4_en_mac_to_u64(dev->dev_addr);
439 queue_work(mdev->workqueue, &priv->mac_task);
440 return 0;
441}
442
443static void mlx4_en_do_set_mac(struct work_struct *work)
444{
445 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
446 mac_task);
447 struct mlx4_en_dev *mdev = priv->mdev;
448 int err = 0;
449
450 mutex_lock(&mdev->state_lock);
451 if (priv->port_up) {
452 /* Remove old MAC and insert the new one */
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000453 err = mlx4_replace_mac(mdev->dev, priv->port,
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000454 priv->base_qpn, priv->mac);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700455 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000456 en_err(priv, "Failed changing HW MAC address\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700457 } else
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000458 en_dbg(HW, priv, "Port is down while "
459 "registering mac, exiting...\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700460
461 mutex_unlock(&mdev->state_lock);
462}
463
464static void mlx4_en_clear_list(struct net_device *dev)
465{
466 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000467 struct mlx4_en_mc_list *tmp, *mc_to_del;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700468
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000469 list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) {
470 list_del(&mc_to_del->list);
471 kfree(mc_to_del);
472 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700473}
474
475static void mlx4_en_cache_mclist(struct net_device *dev)
476{
477 struct mlx4_en_priv *priv = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000478 struct netdev_hw_addr *ha;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000479 struct mlx4_en_mc_list *tmp;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700480
Alexander Guller0e035672011-12-19 04:02:58 +0000481 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000482 netdev_for_each_mc_addr(ha, dev) {
483 tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC);
484 if (!tmp) {
485 en_err(priv, "failed to allocate multicast list\n");
486 mlx4_en_clear_list(dev);
487 return;
488 }
489 memcpy(tmp->addr, ha->addr, ETH_ALEN);
490 list_add_tail(&tmp->list, &priv->mc_list);
491 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700492}
493
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000494static void update_mclist_flags(struct mlx4_en_priv *priv,
495 struct list_head *dst,
496 struct list_head *src)
497{
498 struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc;
499 bool found;
500
501 /* Find all the entries that should be removed from dst,
502 * These are the entries that are not found in src
503 */
504 list_for_each_entry(dst_tmp, dst, list) {
505 found = false;
506 list_for_each_entry(src_tmp, src, list) {
507 if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) {
508 found = true;
509 break;
510 }
511 }
512 if (!found)
513 dst_tmp->action = MCLIST_REM;
514 }
515
516 /* Add entries that exist in src but not in dst
517 * mark them as need to add
518 */
519 list_for_each_entry(src_tmp, src, list) {
520 found = false;
521 list_for_each_entry(dst_tmp, dst, list) {
522 if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) {
523 dst_tmp->action = MCLIST_NONE;
524 found = true;
525 break;
526 }
527 }
528 if (!found) {
529 new_mc = kmalloc(sizeof(struct mlx4_en_mc_list),
530 GFP_KERNEL);
531 if (!new_mc) {
532 en_err(priv, "Failed to allocate current multicast list\n");
533 return;
534 }
535 memcpy(new_mc, src_tmp,
536 sizeof(struct mlx4_en_mc_list));
537 new_mc->action = MCLIST_ADD;
538 list_add_tail(&new_mc->list, dst);
539 }
540 }
541}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700542
543static void mlx4_en_set_multicast(struct net_device *dev)
544{
545 struct mlx4_en_priv *priv = netdev_priv(dev);
546
547 if (!priv->port_up)
548 return;
549
550 queue_work(priv->mdev->workqueue, &priv->mcast_task);
551}
552
553static void mlx4_en_do_set_multicast(struct work_struct *work)
554{
555 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
556 mcast_task);
557 struct mlx4_en_dev *mdev = priv->mdev;
558 struct net_device *dev = priv->dev;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000559 struct mlx4_en_mc_list *mclist, *tmp;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700560 u64 mcast_addr = 0;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000561 u8 mc_list[16] = {0};
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000562 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700563
564 mutex_lock(&mdev->state_lock);
565 if (!mdev->device_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000566 en_dbg(HW, priv, "Card is not up, "
567 "ignoring multicast change.\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700568 goto out;
569 }
570 if (!priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000571 en_dbg(HW, priv, "Port is down, "
572 "ignoring multicast change.\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700573 goto out;
574 }
575
Eugenia Emantayevffe455a2011-12-13 04:16:21 +0000576 if (!netif_carrier_ok(dev)) {
577 if (!mlx4_en_QUERY_PORT(mdev, priv->port)) {
578 if (priv->port_state.link_state) {
579 priv->last_link_state = MLX4_DEV_EVENT_PORT_UP;
580 netif_carrier_on(dev);
581 en_dbg(LINK, priv, "Link Up\n");
582 }
583 }
584 }
585
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700586 /*
587 * Promsicuous mode: disable all filters
588 */
589
590 if (dev->flags & IFF_PROMISC) {
591 if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) {
592 if (netif_msg_rx_status(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000593 en_warn(priv, "Entering promiscuous mode\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700594 priv->flags |= MLX4_EN_FLAG_PROMISC;
595
596 /* Enable promiscouos mode */
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000597 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000598 case MLX4_STEERING_MODE_DEVICE_MANAGED:
599 err = mlx4_flow_steer_promisc_add(mdev->dev,
600 priv->port,
601 priv->base_qpn,
602 MLX4_FS_PROMISC_UPLINK);
603 if (err)
604 en_err(priv, "Failed enabling promiscuous mode\n");
605 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
606 break;
607
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000608 case MLX4_STEERING_MODE_B0:
609 err = mlx4_unicast_promisc_add(mdev->dev,
610 priv->base_qpn,
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000611 priv->port);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000612 if (err)
613 en_err(priv, "Failed enabling unicast promiscuous mode\n");
614
615 /* Add the default qp number as multicast
616 * promisc
617 */
618 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
619 err = mlx4_multicast_promisc_add(mdev->dev,
620 priv->base_qpn,
621 priv->port);
622 if (err)
623 en_err(priv, "Failed enabling multicast promiscuous mode\n");
624 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
625 }
626 break;
627
628 case MLX4_STEERING_MODE_A0:
629 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
630 priv->port,
631 priv->base_qpn,
632 1);
633 if (err)
634 en_err(priv, "Failed enabling promiscuous mode\n");
635 break;
636 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700637
638 /* Disable port multicast filter (unconditionally) */
639 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
640 0, MLX4_MCAST_DISABLE);
641 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000642 en_err(priv, "Failed disabling "
643 "multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700644
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000645 /* Disable port VLAN filter */
646 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
647 if (err)
648 en_err(priv, "Failed disabling VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700649 }
650 goto out;
651 }
652
653 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300654 * Not in promiscuous mode
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700655 */
656
657 if (priv->flags & MLX4_EN_FLAG_PROMISC) {
658 if (netif_msg_rx_status(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000659 en_warn(priv, "Leaving promiscuous mode\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700660 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
661
662 /* Disable promiscouos mode */
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000663 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000664 case MLX4_STEERING_MODE_DEVICE_MANAGED:
665 err = mlx4_flow_steer_promisc_remove(mdev->dev,
666 priv->port,
667 MLX4_FS_PROMISC_UPLINK);
668 if (err)
669 en_err(priv, "Failed disabling promiscuous mode\n");
670 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
671 break;
672
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000673 case MLX4_STEERING_MODE_B0:
674 err = mlx4_unicast_promisc_remove(mdev->dev,
675 priv->base_qpn,
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000676 priv->port);
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000677 if (err)
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000678 en_err(priv, "Failed disabling unicast promiscuous mode\n");
679 /* Disable Multicast promisc */
680 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
681 err = mlx4_multicast_promisc_remove(mdev->dev,
682 priv->base_qpn,
683 priv->port);
684 if (err)
685 en_err(priv, "Failed disabling multicast promiscuous mode\n");
686 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
687 }
688 break;
689
690 case MLX4_STEERING_MODE_A0:
691 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
692 priv->port,
693 priv->base_qpn, 0);
694 if (err)
695 en_err(priv, "Failed disabling promiscuous mode\n");
696 break;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000697 }
698
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700699 /* Enable port VLAN filter */
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000700 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700701 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000702 en_err(priv, "Failed enabling VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700703 }
704
705 /* Enable/disable the multicast filter according to IFF_ALLMULTI */
706 if (dev->flags & IFF_ALLMULTI) {
707 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
708 0, MLX4_MCAST_DISABLE);
709 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000710 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000711
712 /* Add the default qp number as multicast promisc */
713 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000714 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000715 case MLX4_STEERING_MODE_DEVICE_MANAGED:
716 err = mlx4_flow_steer_promisc_add(mdev->dev,
717 priv->port,
718 priv->base_qpn,
719 MLX4_FS_PROMISC_ALL_MULTI);
720 break;
721
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000722 case MLX4_STEERING_MODE_B0:
723 err = mlx4_multicast_promisc_add(mdev->dev,
724 priv->base_qpn,
725 priv->port);
726 break;
727
728 case MLX4_STEERING_MODE_A0:
729 break;
730 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000731 if (err)
732 en_err(priv, "Failed entering multicast promisc mode\n");
733 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
734 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700735 } else {
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000736 /* Disable Multicast promisc */
737 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000738 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000739 case MLX4_STEERING_MODE_DEVICE_MANAGED:
740 err = mlx4_flow_steer_promisc_remove(mdev->dev,
741 priv->port,
742 MLX4_FS_PROMISC_ALL_MULTI);
743 break;
744
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000745 case MLX4_STEERING_MODE_B0:
746 err = mlx4_multicast_promisc_remove(mdev->dev,
747 priv->base_qpn,
748 priv->port);
749 break;
750
751 case MLX4_STEERING_MODE_A0:
752 break;
753 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000754 if (err)
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300755 en_err(priv, "Failed disabling multicast promiscuous mode\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000756 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
757 }
Jiri Pirkoff6e2162010-03-01 05:09:14 +0000758
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700759 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
760 0, MLX4_MCAST_DISABLE);
761 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000762 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700763
764 /* Flush mcast filter and init it with broadcast address */
765 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST,
766 1, MLX4_MCAST_CONFIG);
767
768 /* Update multicast list - we cache all addresses so they won't
769 * change while HW is updated holding the command semaphor */
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +0000770 netif_addr_lock_bh(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700771 mlx4_en_cache_mclist(dev);
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +0000772 netif_addr_unlock_bh(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000773 list_for_each_entry(mclist, &priv->mc_list, list) {
774 mcast_addr = mlx4_en_mac_to_u64(mclist->addr);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700775 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port,
776 mcast_addr, 0, MLX4_MCAST_CONFIG);
777 }
778 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
779 0, MLX4_MCAST_ENABLE);
780 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000781 en_err(priv, "Failed enabling multicast filter\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000782
783 update_mclist_flags(priv, &priv->curr_list, &priv->mc_list);
784 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
785 if (mclist->action == MCLIST_REM) {
786 /* detach this address and delete from list */
787 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
788 mc_list[5] = priv->port;
789 err = mlx4_multicast_detach(mdev->dev,
790 &priv->rss_map.indir_qp,
791 mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000792 MLX4_PROT_ETH,
793 mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000794 if (err)
795 en_err(priv, "Fail to detach multicast address\n");
796
797 /* remove from list */
798 list_del(&mclist->list);
799 kfree(mclist);
Dan Carpenter9c645082012-07-10 20:34:07 +0000800 } else if (mclist->action == MCLIST_ADD) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000801 /* attach the address */
802 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000803 /* needed for B0 steering support */
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000804 mc_list[5] = priv->port;
805 err = mlx4_multicast_attach(mdev->dev,
806 &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000807 mc_list,
808 priv->port, 0,
809 MLX4_PROT_ETH,
810 &mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000811 if (err)
812 en_err(priv, "Fail to attach multicast address\n");
813
814 }
815 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700816 }
817out:
818 mutex_unlock(&mdev->state_lock);
819}
820
821#ifdef CONFIG_NET_POLL_CONTROLLER
822static void mlx4_en_netpoll(struct net_device *dev)
823{
824 struct mlx4_en_priv *priv = netdev_priv(dev);
825 struct mlx4_en_cq *cq;
826 unsigned long flags;
827 int i;
828
829 for (i = 0; i < priv->rx_ring_num; i++) {
830 cq = &priv->rx_cq[i];
831 spin_lock_irqsave(&cq->lock, flags);
832 napi_synchronize(&cq->napi);
833 mlx4_en_process_rx_cq(dev, cq, 0);
834 spin_unlock_irqrestore(&cq->lock, flags);
835 }
836}
837#endif
838
839static void mlx4_en_tx_timeout(struct net_device *dev)
840{
841 struct mlx4_en_priv *priv = netdev_priv(dev);
842 struct mlx4_en_dev *mdev = priv->mdev;
843
844 if (netif_msg_timer(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000845 en_warn(priv, "Tx timeout called on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700846
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +0000847 priv->port_stats.tx_timeout++;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000848 en_dbg(DRV, priv, "Scheduling watchdog\n");
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +0000849 queue_work(mdev->workqueue, &priv->watchdog_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700850}
851
852
853static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev)
854{
855 struct mlx4_en_priv *priv = netdev_priv(dev);
856
857 spin_lock_bh(&priv->stats_lock);
858 memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats));
859 spin_unlock_bh(&priv->stats_lock);
860
861 return &priv->ret_stats;
862}
863
864static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv)
865{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700866 struct mlx4_en_cq *cq;
867 int i;
868
869 /* If we haven't received a specific coalescing setting
Martin Olsson98a17082009-04-22 18:21:29 +0200870 * (module param), we set the moderation parameters as follows:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700871 * - moder_cnt is set to the number of mtu sized packets to
Eric Dumazetecfd2ce2012-11-05 16:20:42 +0000872 * satisfy our coalescing target.
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700873 * - moder_time is set to a fixed value.
874 */
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +0000875 priv->rx_frames = MLX4_EN_RX_COAL_TARGET;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -0800876 priv->rx_usecs = MLX4_EN_RX_COAL_TIME;
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000877 priv->tx_frames = MLX4_EN_TX_COAL_PKTS;
878 priv->tx_usecs = MLX4_EN_TX_COAL_TIME;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000879 en_dbg(INTR, priv, "Default coalesing params for mtu:%d - "
880 "rx_frames:%d rx_usecs:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700881 priv->dev->mtu, priv->rx_frames, priv->rx_usecs);
882
883 /* Setup cq moderation params */
884 for (i = 0; i < priv->rx_ring_num; i++) {
885 cq = &priv->rx_cq[i];
886 cq->moder_cnt = priv->rx_frames;
887 cq->moder_time = priv->rx_usecs;
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000888 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
889 priv->last_moder_packets[i] = 0;
890 priv->last_moder_bytes[i] = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700891 }
892
893 for (i = 0; i < priv->tx_ring_num; i++) {
894 cq = &priv->tx_cq[i];
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000895 cq->moder_cnt = priv->tx_frames;
896 cq->moder_time = priv->tx_usecs;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700897 }
898
899 /* Reset auto-moderation params */
900 priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW;
901 priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW;
902 priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH;
903 priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH;
904 priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -0800905 priv->adaptive_rx_coal = 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700906 priv->last_moder_jiffies = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700907 priv->last_moder_tx_packets = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700908}
909
910static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv)
911{
912 unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700913 struct mlx4_en_cq *cq;
914 unsigned long packets;
915 unsigned long rate;
916 unsigned long avg_pkt_size;
917 unsigned long rx_packets;
918 unsigned long rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700919 unsigned long rx_pkt_diff;
920 int moder_time;
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000921 int ring, err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700922
923 if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ)
924 return;
925
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000926 for (ring = 0; ring < priv->rx_ring_num; ring++) {
927 spin_lock_bh(&priv->stats_lock);
928 rx_packets = priv->rx_ring[ring].packets;
929 rx_bytes = priv->rx_ring[ring].bytes;
930 spin_unlock_bh(&priv->stats_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700931
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000932 rx_pkt_diff = ((unsigned long) (rx_packets -
933 priv->last_moder_packets[ring]));
934 packets = rx_pkt_diff;
935 rate = packets * HZ / period;
936 avg_pkt_size = packets ? ((unsigned long) (rx_bytes -
937 priv->last_moder_bytes[ring])) / packets : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700938
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000939 /* Apply auto-moderation only when packet rate
940 * exceeds a rate that it matters */
941 if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) &&
942 avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700943 if (rate < priv->pkt_rate_low)
944 moder_time = priv->rx_usecs_low;
945 else if (rate > priv->pkt_rate_high)
946 moder_time = priv->rx_usecs_high;
947 else
948 moder_time = (rate - priv->pkt_rate_low) *
949 (priv->rx_usecs_high - priv->rx_usecs_low) /
950 (priv->pkt_rate_high - priv->pkt_rate_low) +
951 priv->rx_usecs_low;
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000952 } else {
953 moder_time = priv->rx_usecs_low;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700954 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700955
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000956 if (moder_time != priv->last_moder_time[ring]) {
957 priv->last_moder_time[ring] = moder_time;
958 cq = &priv->rx_cq[ring];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700959 cq->moder_time = moder_time;
960 err = mlx4_en_set_cq_moder(priv, cq);
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000961 if (err)
962 en_err(priv, "Failed modifying moderation "
963 "for cq:%d\n", ring);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700964 }
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000965 priv->last_moder_packets[ring] = rx_packets;
966 priv->last_moder_bytes[ring] = rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700967 }
968
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700969 priv->last_moder_jiffies = jiffies;
970}
971
972static void mlx4_en_do_get_stats(struct work_struct *work)
973{
Jean Delvarebf6aede2009-04-02 16:56:54 -0700974 struct delayed_work *delay = to_delayed_work(work);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700975 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
976 stats_task);
977 struct mlx4_en_dev *mdev = priv->mdev;
978 int err;
979
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700980 mutex_lock(&mdev->state_lock);
981 if (mdev->device_up) {
Eugenia Emantayev2d518372013-01-24 01:54:14 +0000982 err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0);
983 if (err)
984 en_dbg(HW, priv, "Could not update stats\n");
985
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700986 if (priv->port_up)
987 mlx4_en_auto_moderation(priv);
988
989 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
990 }
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +0000991 if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
992 queue_work(mdev->workqueue, &priv->mac_task);
993 mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
994 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700995 mutex_unlock(&mdev->state_lock);
996}
997
998static void mlx4_en_linkstate(struct work_struct *work)
999{
1000 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1001 linkstate_task);
1002 struct mlx4_en_dev *mdev = priv->mdev;
1003 int linkstate = priv->link_state;
1004
1005 mutex_lock(&mdev->state_lock);
1006 /* If observable port state changed set carrier state and
1007 * report to system log */
1008 if (priv->last_link_state != linkstate) {
1009 if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001010 en_info(priv, "Link Down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001011 netif_carrier_off(priv->dev);
1012 } else {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001013 en_info(priv, "Link Up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001014 netif_carrier_on(priv->dev);
1015 }
1016 }
1017 priv->last_link_state = linkstate;
1018 mutex_unlock(&mdev->state_lock);
1019}
1020
1021
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001022int mlx4_en_start_port(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001023{
1024 struct mlx4_en_priv *priv = netdev_priv(dev);
1025 struct mlx4_en_dev *mdev = priv->mdev;
1026 struct mlx4_en_cq *cq;
1027 struct mlx4_en_tx_ring *tx_ring;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001028 int rx_index = 0;
1029 int tx_index = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001030 int err = 0;
1031 int i;
1032 int j;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001033 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001034
1035 if (priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001036 en_dbg(DRV, priv, "start port called while port already up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001037 return 0;
1038 }
1039
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001040 INIT_LIST_HEAD(&priv->mc_list);
1041 INIT_LIST_HEAD(&priv->curr_list);
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001042 INIT_LIST_HEAD(&priv->ethtool_list);
1043 memset(&priv->ethtool_rules[0], 0,
1044 sizeof(struct ethtool_flow_id) * MAX_NUM_OF_FS_RULES);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001045
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001046 /* Calculate Rx buf size */
1047 dev->mtu = min(dev->mtu, priv->max_mtu);
1048 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001049 en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_skb_size);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001050
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001051 /* Configure rx cq's and rings */
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001052 err = mlx4_en_activate_rx_rings(priv);
1053 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001054 en_err(priv, "Failed to activate RX rings\n");
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001055 return err;
1056 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001057 for (i = 0; i < priv->rx_ring_num; i++) {
1058 cq = &priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001059
Alexander Guller76532d02011-10-09 05:26:31 +00001060 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001061 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001062 en_err(priv, "Failed activating Rx CQ\n");
Yevgeny Petrilina4233302009-04-26 20:41:34 +00001063 goto cq_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001064 }
1065 for (j = 0; j < cq->size; j++)
1066 cq->buf[j].owner_sr_opcode = MLX4_CQE_OWNER_MASK;
1067 err = mlx4_en_set_cq_moder(priv, cq);
1068 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001069 en_err(priv, "Failed setting cq moderation parameters");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001070 mlx4_en_deactivate_cq(priv, cq);
1071 goto cq_err;
1072 }
1073 mlx4_en_arm_cq(priv, cq);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001074 priv->rx_ring[i].cqn = cq->mcq.cqn;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001075 ++rx_index;
1076 }
1077
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001078 /* Set qp number */
1079 en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port);
1080 err = mlx4_get_eth_qp(mdev->dev, priv->port,
1081 priv->mac, &priv->base_qpn);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001082 if (err) {
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001083 en_err(priv, "Failed getting eth qp\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001084 goto cq_err;
1085 }
1086 mdev->mac_removed[priv->port] = 0;
1087
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001088 err = mlx4_en_config_rss_steer(priv);
1089 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001090 en_err(priv, "Failed configuring rss steering\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001091 goto mac_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001092 }
1093
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001094 err = mlx4_en_create_drop_qp(priv);
1095 if (err)
1096 goto rss_err;
1097
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001098 /* Configure tx cq's and rings */
1099 for (i = 0; i < priv->tx_ring_num; i++) {
1100 /* Configure cq */
1101 cq = &priv->tx_cq[i];
Alexander Guller76532d02011-10-09 05:26:31 +00001102 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001103 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001104 en_err(priv, "Failed allocating Tx CQ\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001105 goto tx_err;
1106 }
1107 err = mlx4_en_set_cq_moder(priv, cq);
1108 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001109 en_err(priv, "Failed setting cq moderation parameters");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001110 mlx4_en_deactivate_cq(priv, cq);
1111 goto tx_err;
1112 }
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001113 en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001114 cq->buf->wqe_index = cpu_to_be16(0xffff);
1115
1116 /* Configure ring */
1117 tx_ring = &priv->tx_ring[i];
Amir Vadai0e98b522012-04-04 21:33:24 +00001118 err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn,
Amir Vadaid3179662012-12-02 03:49:23 +00001119 i / priv->num_tx_rings_p_up);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001120 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001121 en_err(priv, "Failed allocating Tx ring\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001122 mlx4_en_deactivate_cq(priv, cq);
1123 goto tx_err;
1124 }
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001125 tx_ring->tx_queue = netdev_get_tx_queue(dev, i);
Yevgeny Petriline22979d2012-04-23 02:18:39 +00001126
1127 /* Arm CQ for TX completions */
1128 mlx4_en_arm_cq(priv, cq);
1129
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001130 /* Set initial ownership of all Tx TXBBs to SW (1) */
1131 for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE)
1132 *((u32 *) (tx_ring->buf + j)) = 0xffffffff;
1133 ++tx_index;
1134 }
1135
1136 /* Configure port */
1137 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
1138 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001139 priv->prof->tx_pause,
1140 priv->prof->tx_ppp,
1141 priv->prof->rx_pause,
1142 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001143 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001144 en_err(priv, "Failed setting port general configurations "
1145 "for port %d, with error %d\n", priv->port, err);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001146 goto tx_err;
1147 }
1148 /* Set default qp number */
1149 err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0);
1150 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001151 en_err(priv, "Failed setting default qp numbers\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001152 goto tx_err;
1153 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001154
1155 /* Init port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001156 en_dbg(HW, priv, "Initializing port\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001157 err = mlx4_INIT_PORT(mdev->dev, priv->port);
1158 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001159 en_err(priv, "Failed Initializing port\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001160 goto tx_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001161 }
1162
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001163 /* Attach rx QP to bradcast address */
1164 memset(&mc_list[10], 0xff, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001165 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001166 if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001167 priv->port, 0, MLX4_PROT_ETH,
1168 &priv->broadcast_id))
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001169 mlx4_warn(mdev, "Failed Attaching Broadcast\n");
1170
Herbert Xub5845f92011-03-27 01:01:26 +00001171 /* Must redo promiscuous mode setup. */
1172 priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC);
1173
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001174 /* Schedule multicast task to populate multicast list */
1175 queue_work(mdev->workqueue, &priv->mcast_task);
1176
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +00001177 mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap);
1178
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001179 priv->port_up = true;
Yevgeny Petrilina11faac2009-06-20 22:15:46 +00001180 netif_tx_start_all_queues(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001181 return 0;
1182
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001183tx_err:
1184 while (tx_index--) {
1185 mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[tx_index]);
1186 mlx4_en_deactivate_cq(priv, &priv->tx_cq[tx_index]);
1187 }
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001188 mlx4_en_destroy_drop_qp(priv);
1189rss_err:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001190 mlx4_en_release_rss_steer(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001191mac_err:
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001192 mlx4_put_eth_qp(mdev->dev, priv->port, priv->mac, priv->base_qpn);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001193cq_err:
1194 while (rx_index--)
1195 mlx4_en_deactivate_cq(priv, &priv->rx_cq[rx_index]);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001196 for (i = 0; i < priv->rx_ring_num; i++)
1197 mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001198
1199 return err; /* need to close devices */
1200}
1201
1202
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001203void mlx4_en_stop_port(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001204{
1205 struct mlx4_en_priv *priv = netdev_priv(dev);
1206 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001207 struct mlx4_en_mc_list *mclist, *tmp;
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001208 struct ethtool_flow_id *flow, *tmp_flow;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001209 int i;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001210 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001211
1212 if (!priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001213 en_dbg(DRV, priv, "stop port called while port already down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001214 return;
1215 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001216
1217 /* Synchronize with tx routine */
1218 netif_tx_lock_bh(dev);
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001219 netif_tx_stop_all_queues(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001220 netif_tx_unlock_bh(dev);
1221
Yevgeny Petrilin7c287382010-08-24 03:45:45 +00001222 /* Set port as not active */
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001223 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001224
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001225 /* Promsicuous mode */
1226 if (mdev->dev->caps.steering_mode ==
1227 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1228 priv->flags &= ~(MLX4_EN_FLAG_PROMISC |
1229 MLX4_EN_FLAG_MC_PROMISC);
1230 mlx4_flow_steer_promisc_remove(mdev->dev,
1231 priv->port,
1232 MLX4_FS_PROMISC_UPLINK);
1233 mlx4_flow_steer_promisc_remove(mdev->dev,
1234 priv->port,
1235 MLX4_FS_PROMISC_ALL_MULTI);
1236 } else if (priv->flags & MLX4_EN_FLAG_PROMISC) {
1237 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
1238
1239 /* Disable promiscouos mode */
1240 mlx4_unicast_promisc_remove(mdev->dev, priv->base_qpn,
1241 priv->port);
1242
1243 /* Disable Multicast promisc */
1244 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
1245 mlx4_multicast_promisc_remove(mdev->dev, priv->base_qpn,
1246 priv->port);
1247 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
1248 }
1249 }
1250
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001251 /* Detach All multicasts */
1252 memset(&mc_list[10], 0xff, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001253 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001254 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001255 MLX4_PROT_ETH, priv->broadcast_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001256 list_for_each_entry(mclist, &priv->curr_list, list) {
1257 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001258 mc_list[5] = priv->port;
1259 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001260 mc_list, MLX4_PROT_ETH, mclist->reg_id);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001261 }
1262 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001263 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
1264 list_del(&mclist->list);
1265 kfree(mclist);
1266 }
1267
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001268 /* Flush multicast filter */
1269 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG);
1270
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001271 mlx4_en_destroy_drop_qp(priv);
1272
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001273 /* Free TX Rings */
1274 for (i = 0; i < priv->tx_ring_num; i++) {
1275 mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[i]);
1276 mlx4_en_deactivate_cq(priv, &priv->tx_cq[i]);
1277 }
1278 msleep(10);
1279
1280 for (i = 0; i < priv->tx_ring_num; i++)
1281 mlx4_en_free_tx_buf(dev, &priv->tx_ring[i]);
1282
1283 /* Free RSS qps */
1284 mlx4_en_release_rss_steer(priv);
1285
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001286 /* Unregister Mac address for the port */
1287 mlx4_put_eth_qp(mdev->dev, priv->port, priv->mac, priv->base_qpn);
1288 mdev->mac_removed[priv->port] = 1;
1289
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001290 /* Remove flow steering rules for the port*/
1291 if (mdev->dev->caps.steering_mode ==
1292 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1293 ASSERT_RTNL();
1294 list_for_each_entry_safe(flow, tmp_flow,
1295 &priv->ethtool_list, list) {
1296 mlx4_flow_detach(mdev->dev, flow->id);
1297 list_del(&flow->list);
1298 }
1299 }
1300
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001301 /* Free RX Rings */
1302 for (i = 0; i < priv->rx_ring_num; i++) {
1303 mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]);
1304 while (test_bit(NAPI_STATE_SCHED, &priv->rx_cq[i].napi.state))
1305 msleep(1);
1306 mlx4_en_deactivate_cq(priv, &priv->rx_cq[i]);
1307 }
Yevgeny Petrilin7c287382010-08-24 03:45:45 +00001308
1309 /* close port*/
1310 mlx4_CLOSE_PORT(mdev->dev, priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001311}
1312
1313static void mlx4_en_restart(struct work_struct *work)
1314{
1315 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1316 watchdog_task);
1317 struct mlx4_en_dev *mdev = priv->mdev;
1318 struct net_device *dev = priv->dev;
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001319 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001320
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001321 en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001322
1323 mutex_lock(&mdev->state_lock);
1324 if (priv->port_up) {
1325 mlx4_en_stop_port(dev);
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001326 for (i = 0; i < priv->tx_ring_num; i++)
1327 netdev_tx_reset_queue(priv->tx_ring[i].tx_queue);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001328 if (mlx4_en_start_port(dev))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001329 en_err(priv, "Failed restarting port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001330 }
1331 mutex_unlock(&mdev->state_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001332}
1333
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001334static void mlx4_en_clear_stats(struct net_device *dev)
1335{
1336 struct mlx4_en_priv *priv = netdev_priv(dev);
1337 struct mlx4_en_dev *mdev = priv->mdev;
1338 int i;
1339
1340 if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1))
1341 en_dbg(HW, priv, "Failed dumping statistics\n");
1342
1343 memset(&priv->stats, 0, sizeof(priv->stats));
1344 memset(&priv->pstats, 0, sizeof(priv->pstats));
1345 memset(&priv->pkstats, 0, sizeof(priv->pkstats));
1346 memset(&priv->port_stats, 0, sizeof(priv->port_stats));
1347
1348 for (i = 0; i < priv->tx_ring_num; i++) {
1349 priv->tx_ring[i].bytes = 0;
1350 priv->tx_ring[i].packets = 0;
1351 priv->tx_ring[i].tx_csum = 0;
1352 }
1353 for (i = 0; i < priv->rx_ring_num; i++) {
1354 priv->rx_ring[i].bytes = 0;
1355 priv->rx_ring[i].packets = 0;
1356 priv->rx_ring[i].csum_ok = 0;
1357 priv->rx_ring[i].csum_none = 0;
1358 }
1359}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001360
1361static int mlx4_en_open(struct net_device *dev)
1362{
1363 struct mlx4_en_priv *priv = netdev_priv(dev);
1364 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001365 int err = 0;
1366
1367 mutex_lock(&mdev->state_lock);
1368
1369 if (!mdev->device_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001370 en_err(priv, "Cannot open - device down/disabled\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001371 err = -EBUSY;
1372 goto out;
1373 }
1374
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001375 /* Reset HW statistics and SW counters */
1376 mlx4_en_clear_stats(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001377
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001378 err = mlx4_en_start_port(dev);
1379 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001380 en_err(priv, "Failed starting port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001381
1382out:
1383 mutex_unlock(&mdev->state_lock);
1384 return err;
1385}
1386
1387
1388static int mlx4_en_close(struct net_device *dev)
1389{
1390 struct mlx4_en_priv *priv = netdev_priv(dev);
1391 struct mlx4_en_dev *mdev = priv->mdev;
1392
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001393 en_dbg(IFDOWN, priv, "Close port called\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001394
1395 mutex_lock(&mdev->state_lock);
1396
1397 mlx4_en_stop_port(dev);
1398 netif_carrier_off(dev);
1399
1400 mutex_unlock(&mdev->state_lock);
1401 return 0;
1402}
1403
Alexander Gullerfe0af032011-10-09 05:26:46 +00001404void mlx4_en_free_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001405{
1406 int i;
1407
Amir Vadai1eb8c692012-07-18 22:33:52 +00001408#ifdef CONFIG_RFS_ACCEL
1409 free_irq_cpu_rmap(priv->dev->rx_cpu_rmap);
1410 priv->dev->rx_cpu_rmap = NULL;
1411#endif
1412
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001413 for (i = 0; i < priv->tx_ring_num; i++) {
1414 if (priv->tx_ring[i].tx_info)
1415 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
1416 if (priv->tx_cq[i].buf)
Alexander Gullerfe0af032011-10-09 05:26:46 +00001417 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001418 }
1419
1420 for (i = 0; i < priv->rx_ring_num; i++) {
1421 if (priv->rx_ring[i].rx_info)
Thadeu Lima de Souza Cascardo68355f72012-02-06 08:39:49 +00001422 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
1423 priv->prof->rx_ring_size, priv->stride);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001424 if (priv->rx_cq[i].buf)
Alexander Gullerfe0af032011-10-09 05:26:46 +00001425 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001426 }
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001427
1428 if (priv->base_tx_qpn) {
1429 mlx4_qp_release_range(priv->mdev->dev, priv->base_tx_qpn, priv->tx_ring_num);
1430 priv->base_tx_qpn = 0;
1431 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001432}
1433
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001434int mlx4_en_alloc_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001435{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001436 struct mlx4_en_port_profile *prof = priv->prof;
1437 int i;
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001438 int err;
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001439
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001440 err = mlx4_qp_reserve_range(priv->mdev->dev, priv->tx_ring_num, 256, &priv->base_tx_qpn);
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001441 if (err) {
1442 en_err(priv, "failed reserving range for TX rings\n");
1443 return err;
1444 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001445
1446 /* Create tx Rings */
1447 for (i = 0; i < priv->tx_ring_num; i++) {
1448 if (mlx4_en_create_cq(priv, &priv->tx_cq[i],
1449 prof->tx_ring_size, i, TX))
1450 goto err;
1451
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001452 if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i], priv->base_tx_qpn + i,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001453 prof->tx_ring_size, TXBB_SIZE))
1454 goto err;
1455 }
1456
1457 /* Create rx Rings */
1458 for (i = 0; i < priv->rx_ring_num; i++) {
1459 if (mlx4_en_create_cq(priv, &priv->rx_cq[i],
1460 prof->rx_ring_size, i, RX))
1461 goto err;
1462
1463 if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i],
1464 prof->rx_ring_size, priv->stride))
1465 goto err;
1466 }
1467
Amir Vadai1eb8c692012-07-18 22:33:52 +00001468#ifdef CONFIG_RFS_ACCEL
1469 priv->dev->rx_cpu_rmap = alloc_irq_cpu_rmap(priv->rx_ring_num);
1470 if (!priv->dev->rx_cpu_rmap)
1471 goto err;
Amir Vadai1eb8c692012-07-18 22:33:52 +00001472#endif
1473
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001474 return 0;
1475
1476err:
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001477 en_err(priv, "Failed to allocate NIC resources\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001478 return -ENOMEM;
1479}
1480
1481
1482void mlx4_en_destroy_netdev(struct net_device *dev)
1483{
1484 struct mlx4_en_priv *priv = netdev_priv(dev);
1485 struct mlx4_en_dev *mdev = priv->mdev;
1486
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001487 en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001488
1489 /* Unregister device - this will close the port if it was up */
1490 if (priv->registered)
1491 unregister_netdev(dev);
1492
1493 if (priv->allocated)
1494 mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE);
1495
1496 cancel_delayed_work(&priv->stats_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001497 /* flush any pending task for this netdev */
1498 flush_workqueue(mdev->workqueue);
1499
1500 /* Detach the netdev so tasks would not attempt to access it */
1501 mutex_lock(&mdev->state_lock);
1502 mdev->pndev[priv->port] = NULL;
1503 mutex_unlock(&mdev->state_lock);
1504
Alexander Gullerfe0af032011-10-09 05:26:46 +00001505 mlx4_en_free_resources(priv);
Amir Vadai564c2742012-04-04 21:33:26 +00001506
Amir Vadaibc6a4742012-05-17 00:58:10 +00001507 kfree(priv->tx_ring);
1508 kfree(priv->tx_cq);
1509
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001510 free_netdev(dev);
1511}
1512
1513static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
1514{
1515 struct mlx4_en_priv *priv = netdev_priv(dev);
1516 struct mlx4_en_dev *mdev = priv->mdev;
1517 int err = 0;
1518
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001519 en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001520 dev->mtu, new_mtu);
1521
1522 if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001523 en_err(priv, "Bad MTU size:%d.\n", new_mtu);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001524 return -EPERM;
1525 }
1526 dev->mtu = new_mtu;
1527
1528 if (netif_running(dev)) {
1529 mutex_lock(&mdev->state_lock);
1530 if (!mdev->device_up) {
1531 /* NIC is probably restarting - let watchdog task reset
1532 * the port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001533 en_dbg(DRV, priv, "Change MTU called with card down!?\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001534 } else {
1535 mlx4_en_stop_port(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001536 err = mlx4_en_start_port(dev);
1537 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001538 en_err(priv, "Failed restarting port:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001539 priv->port);
1540 queue_work(mdev->workqueue, &priv->watchdog_task);
1541 }
1542 }
1543 mutex_unlock(&mdev->state_lock);
1544 }
1545 return 0;
1546}
1547
Amir Vadai60d6fe92011-11-26 19:55:19 +00001548static int mlx4_en_set_features(struct net_device *netdev,
1549 netdev_features_t features)
1550{
1551 struct mlx4_en_priv *priv = netdev_priv(netdev);
1552
1553 if (features & NETIF_F_LOOPBACK)
1554 priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
1555 else
1556 priv->ctrl_flags &=
1557 cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK);
1558
1559 return 0;
1560
1561}
1562
Stephen Hemminger3addc562008-11-21 17:30:58 -08001563static const struct net_device_ops mlx4_netdev_ops = {
1564 .ndo_open = mlx4_en_open,
1565 .ndo_stop = mlx4_en_close,
1566 .ndo_start_xmit = mlx4_en_xmit,
Yevgeny Petrilinf813cad2009-06-01 23:24:07 +00001567 .ndo_select_queue = mlx4_en_select_queue,
Stephen Hemminger3addc562008-11-21 17:30:58 -08001568 .ndo_get_stats = mlx4_en_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00001569 .ndo_set_rx_mode = mlx4_en_set_multicast,
Stephen Hemminger3addc562008-11-21 17:30:58 -08001570 .ndo_set_mac_address = mlx4_en_set_mac,
Stephen Hemminger52255bb2009-01-09 10:45:37 +00001571 .ndo_validate_addr = eth_validate_addr,
Stephen Hemminger3addc562008-11-21 17:30:58 -08001572 .ndo_change_mtu = mlx4_en_change_mtu,
1573 .ndo_tx_timeout = mlx4_en_tx_timeout,
Stephen Hemminger3addc562008-11-21 17:30:58 -08001574 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
1575 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
1576#ifdef CONFIG_NET_POLL_CONTROLLER
1577 .ndo_poll_controller = mlx4_en_netpoll,
1578#endif
Amir Vadai60d6fe92011-11-26 19:55:19 +00001579 .ndo_set_features = mlx4_en_set_features,
Amir Vadai897d7842012-04-04 21:33:27 +00001580 .ndo_setup_tc = mlx4_en_setup_tc,
Amir Vadai1eb8c692012-07-18 22:33:52 +00001581#ifdef CONFIG_RFS_ACCEL
1582 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
1583#endif
Stephen Hemminger3addc562008-11-21 17:30:58 -08001584};
1585
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001586int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
1587 struct mlx4_en_port_profile *prof)
1588{
1589 struct net_device *dev;
1590 struct mlx4_en_priv *priv;
1591 int i;
1592 int err;
1593
Tom Herbertf1593d22011-01-09 19:36:36 +00001594 dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv),
Amir Vadaid3179662012-12-02 03:49:23 +00001595 MAX_TX_RINGS, MAX_RX_RINGS);
Joe Perches41de8d42012-01-29 13:47:52 +00001596 if (dev == NULL)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001597 return -ENOMEM;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001598
Amir Vadaid3179662012-12-02 03:49:23 +00001599 netif_set_real_num_tx_queues(dev, prof->tx_ring_num);
1600 netif_set_real_num_rx_queues(dev, prof->rx_ring_num);
1601
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001602 SET_NETDEV_DEV(dev, &mdev->dev->pdev->dev);
Eli Cohen741a00b2010-05-26 19:56:24 +00001603 dev->dev_id = port - 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001604
1605 /*
1606 * Initialize driver private data
1607 */
1608
1609 priv = netdev_priv(dev);
1610 memset(priv, 0, sizeof(struct mlx4_en_priv));
1611 priv->dev = dev;
1612 priv->mdev = mdev;
Yevgeny Petrilinebf8c9a2012-03-06 04:03:34 +00001613 priv->ddev = &mdev->pdev->dev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001614 priv->prof = prof;
1615 priv->port = port;
1616 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001617 priv->flags = prof->flags;
Amir Vadai60d6fe92011-11-26 19:55:19 +00001618 priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE |
1619 MLX4_WQE_CTRL_SOLICITED);
Amir Vadaid3179662012-12-02 03:49:23 +00001620 priv->num_tx_rings_p_up = mdev->profile.num_tx_rings_p_up;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001621 priv->tx_ring_num = prof->tx_ring_num;
Amir Vadaid3179662012-12-02 03:49:23 +00001622
1623 priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring) * MAX_TX_RINGS,
1624 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00001625 if (!priv->tx_ring) {
1626 err = -ENOMEM;
1627 goto out;
1628 }
Amir Vadaid3179662012-12-02 03:49:23 +00001629 priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq) * MAX_RX_RINGS,
1630 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00001631 if (!priv->tx_cq) {
1632 err = -ENOMEM;
1633 goto out;
1634 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001635 priv->rx_ring_num = prof->rx_ring_num;
Or Gerlitz08ff3232012-10-21 14:59:24 +00001636 priv->cqe_factor = (mdev->dev->caps.cqe_size == 64) ? 1 : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001637 priv->mac_index = -1;
1638 priv->msg_enable = MLX4_EN_MSG_LEVEL;
1639 spin_lock_init(&priv->stats_lock);
1640 INIT_WORK(&priv->mcast_task, mlx4_en_do_set_multicast);
1641 INIT_WORK(&priv->mac_task, mlx4_en_do_set_mac);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001642 INIT_WORK(&priv->watchdog_task, mlx4_en_restart);
1643 INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate);
1644 INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats);
Amir Vadai564c2742012-04-04 21:33:26 +00001645#ifdef CONFIG_MLX4_EN_DCB
1646 if (!mlx4_is_slave(priv->mdev->dev))
1647 dev->dcbnl_ops = &mlx4_en_dcbnl_ops;
1648#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001649
1650 /* Query for default mac and max mtu */
1651 priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port];
1652 priv->mac = mdev->dev->caps.def_mac[priv->port];
1653 if (ILLEGAL_MAC(priv->mac)) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001654 en_err(priv, "Port: %d, invalid mac burned: 0x%llx, quiting\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001655 priv->port, priv->mac);
1656 err = -EINVAL;
1657 goto out;
1658 }
1659
1660 priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
1661 DS_SIZE * MLX4_EN_MAX_RX_FRAGS);
1662 err = mlx4_en_alloc_resources(priv);
1663 if (err)
1664 goto out;
1665
Amir Vadai78fb2de2013-01-24 01:54:19 +00001666#ifdef CONFIG_RFS_ACCEL
1667 INIT_LIST_HEAD(&priv->filters);
1668 spin_lock_init(&priv->filters_lock);
1669#endif
1670
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001671 /* Allocate page for receive rings */
1672 err = mlx4_alloc_hwq_res(mdev->dev, &priv->res,
1673 MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE);
1674 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001675 en_err(priv, "Failed to allocate page for rx qps\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001676 goto out;
1677 }
1678 priv->allocated = 1;
1679
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001680 /*
1681 * Initialize netdev entry points
1682 */
Stephen Hemminger3addc562008-11-21 17:30:58 -08001683 dev->netdev_ops = &mlx4_netdev_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001684 dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT;
Ben Hutchings1eb63a22010-09-27 08:29:34 +00001685 netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
1686 netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
Stephen Hemminger3addc562008-11-21 17:30:58 -08001687
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001688 SET_ETHTOOL_OPS(dev, &mlx4_en_ethtool_ops);
1689
1690 /* Set defualt MAC */
1691 dev->addr_len = ETH_ALEN;
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00001692 for (i = 0; i < ETH_ALEN; i++)
Yevgeny Petrilin8bf2e582010-08-24 03:45:30 +00001693 dev->dev_addr[ETH_ALEN - 1 - i] = (u8) (priv->mac >> (8 * i));
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001694
1695 /*
1696 * Set driver features
1697 */
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00001698 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
1699 if (mdev->LSO_support)
1700 dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
1701
1702 dev->vlan_features = dev->hw_features;
1703
Yevgeny Petrilinad861072011-10-18 01:51:24 +00001704 dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH;
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00001705 dev->features = dev->hw_features | NETIF_F_HIGHDMA |
1706 NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
1707 NETIF_F_HW_VLAN_FILTER;
Amir Vadai60d6fe92011-11-26 19:55:19 +00001708 dev->hw_features |= NETIF_F_LOOPBACK;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001709
Amir Vadai1eb8c692012-07-18 22:33:52 +00001710 if (mdev->dev->caps.steering_mode ==
1711 MLX4_STEERING_MODE_DEVICE_MANAGED)
1712 dev->hw_features |= NETIF_F_NTUPLE;
1713
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001714 mdev->pndev[port] = dev;
1715
1716 netif_carrier_off(dev);
1717 err = register_netdev(dev);
1718 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001719 en_err(priv, "Netdev registration failed for port %d\n", port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001720 goto out;
1721 }
Alexander Guller42341442011-10-09 05:29:35 +00001722 priv->registered = 1;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001723
1724 en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num);
1725 en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num);
1726
Yevgeny Petrilin90822262011-03-22 22:37:41 +00001727 /* Configure port */
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00001728 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00001729 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00001730 priv->rx_skb_size + ETH_FCS_LEN,
1731 prof->tx_pause, prof->tx_ppp,
1732 prof->rx_pause, prof->rx_ppp);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00001733 if (err) {
1734 en_err(priv, "Failed setting port general configurations "
1735 "for port %d, with error %d\n", priv->port, err);
1736 goto out;
1737 }
1738
1739 /* Init port */
1740 en_warn(priv, "Initializing port\n");
1741 err = mlx4_INIT_PORT(mdev->dev, priv->port);
1742 if (err) {
1743 en_err(priv, "Failed Initializing port\n");
1744 goto out;
1745 }
Yevgeny Petrilin39f17b42011-03-22 22:37:28 +00001746 mlx4_en_set_default_moderation(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001747 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
1748 return 0;
1749
1750out:
1751 mlx4_en_destroy_netdev(dev);
1752 return err;
1753}
1754