blob: 3db594614fd39176ac0137a8fe34f31eb950e7a1 [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>
Eliezer Tamir076bb0c2013-07-10 17:13:17 +030041#include <net/busy_poll.h>
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070042
43#include <linux/mlx4/driver.h>
44#include <linux/mlx4/device.h>
45#include <linux/mlx4/cmd.h>
46#include <linux/mlx4/cq.h>
47
48#include "mlx4_en.h"
49#include "en_port.h"
50
Amir Vadaid3179662012-12-02 03:49:23 +000051int mlx4_en_setup_tc(struct net_device *dev, u8 up)
Amir Vadai897d7842012-04-04 21:33:27 +000052{
Amir Vadaibc6a4742012-05-17 00:58:10 +000053 struct mlx4_en_priv *priv = netdev_priv(dev);
54 int i;
Amir Vadaid3179662012-12-02 03:49:23 +000055 unsigned int offset = 0;
Amir Vadaibc6a4742012-05-17 00:58:10 +000056
57 if (up && up != MLX4_EN_NUM_UP)
Amir Vadai897d7842012-04-04 21:33:27 +000058 return -EINVAL;
59
Amir Vadaibc6a4742012-05-17 00:58:10 +000060 netdev_set_num_tc(dev, up);
61
62 /* Partition Tx queues evenly amongst UP's */
Amir Vadaibc6a4742012-05-17 00:58:10 +000063 for (i = 0; i < up; i++) {
Amir Vadaid3179662012-12-02 03:49:23 +000064 netdev_set_tc_queue(dev, i, priv->num_tx_rings_p_up, offset);
65 offset += priv->num_tx_rings_p_up;
Amir Vadaibc6a4742012-05-17 00:58:10 +000066 }
67
Amir Vadai897d7842012-04-04 21:33:27 +000068 return 0;
69}
70
Cong Wange0d10952013-08-01 11:10:25 +080071#ifdef CONFIG_NET_RX_BUSY_POLL
Amir Vadai9e77a2b2013-06-18 16:18:27 +030072/* must be called with local_bh_disable()d */
73static int mlx4_en_low_latency_recv(struct napi_struct *napi)
74{
75 struct mlx4_en_cq *cq = container_of(napi, struct mlx4_en_cq, napi);
76 struct net_device *dev = cq->dev;
77 struct mlx4_en_priv *priv = netdev_priv(dev);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +020078 struct mlx4_en_rx_ring *rx_ring = priv->rx_ring[cq->ring];
Amir Vadai9e77a2b2013-06-18 16:18:27 +030079 int done;
80
81 if (!priv->port_up)
82 return LL_FLUSH_FAILED;
83
84 if (!mlx4_en_cq_lock_poll(cq))
85 return LL_FLUSH_BUSY;
86
87 done = mlx4_en_process_rx_cq(dev, cq, 4);
Amir Vadai85018412013-06-18 16:18:28 +030088 if (likely(done))
89 rx_ring->cleaned += done;
90 else
91 rx_ring->misses++;
Amir Vadai9e77a2b2013-06-18 16:18:27 +030092
93 mlx4_en_cq_unlock_poll(cq);
94
95 return done;
96}
Cong Wange0d10952013-08-01 11:10:25 +080097#endif /* CONFIG_NET_RX_BUSY_POLL */
Amir Vadai9e77a2b2013-06-18 16:18:27 +030098
Amir Vadai1eb8c692012-07-18 22:33:52 +000099#ifdef CONFIG_RFS_ACCEL
100
101struct mlx4_en_filter {
102 struct list_head next;
103 struct work_struct work;
104
Eyal Perry75a353d2013-11-07 12:19:49 +0200105 u8 ip_proto;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000106 __be32 src_ip;
107 __be32 dst_ip;
108 __be16 src_port;
109 __be16 dst_port;
110
111 int rxq_index;
112 struct mlx4_en_priv *priv;
113 u32 flow_id; /* RFS infrastructure id */
114 int id; /* mlx4_en driver id */
115 u64 reg_id; /* Flow steering API id */
116 u8 activated; /* Used to prevent expiry before filter
117 * is attached
118 */
119 struct hlist_node filter_chain;
120};
121
122static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv);
123
Eyal Perry75a353d2013-11-07 12:19:49 +0200124static enum mlx4_net_trans_rule_id mlx4_ip_proto_to_trans_rule_id(u8 ip_proto)
125{
126 switch (ip_proto) {
127 case IPPROTO_UDP:
128 return MLX4_NET_TRANS_RULE_ID_UDP;
129 case IPPROTO_TCP:
130 return MLX4_NET_TRANS_RULE_ID_TCP;
131 default:
132 return -EPROTONOSUPPORT;
133 }
134};
135
Amir Vadai1eb8c692012-07-18 22:33:52 +0000136static void mlx4_en_filter_work(struct work_struct *work)
137{
138 struct mlx4_en_filter *filter = container_of(work,
139 struct mlx4_en_filter,
140 work);
141 struct mlx4_en_priv *priv = filter->priv;
Eyal Perry75a353d2013-11-07 12:19:49 +0200142 struct mlx4_spec_list spec_tcp_udp = {
143 .id = mlx4_ip_proto_to_trans_rule_id(filter->ip_proto),
Amir Vadai1eb8c692012-07-18 22:33:52 +0000144 {
145 .tcp_udp = {
146 .dst_port = filter->dst_port,
147 .dst_port_msk = (__force __be16)-1,
148 .src_port = filter->src_port,
149 .src_port_msk = (__force __be16)-1,
150 },
151 },
152 };
153 struct mlx4_spec_list spec_ip = {
154 .id = MLX4_NET_TRANS_RULE_ID_IPV4,
155 {
156 .ipv4 = {
157 .dst_ip = filter->dst_ip,
158 .dst_ip_msk = (__force __be32)-1,
159 .src_ip = filter->src_ip,
160 .src_ip_msk = (__force __be32)-1,
161 },
162 },
163 };
164 struct mlx4_spec_list spec_eth = {
165 .id = MLX4_NET_TRANS_RULE_ID_ETH,
166 };
167 struct mlx4_net_trans_rule rule = {
168 .list = LIST_HEAD_INIT(rule.list),
169 .queue_mode = MLX4_NET_TRANS_Q_LIFO,
170 .exclusive = 1,
171 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000172 .promisc_mode = MLX4_FS_REGULAR,
Amir Vadai1eb8c692012-07-18 22:33:52 +0000173 .port = priv->port,
174 .priority = MLX4_DOMAIN_RFS,
175 };
176 int rc;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000177 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
178
Eyal Perry75a353d2013-11-07 12:19:49 +0200179 if (spec_tcp_udp.id < 0) {
180 en_warn(priv, "RFS: ignoring unsupported ip protocol (%d)\n",
181 filter->ip_proto);
182 goto ignore;
183 }
Amir Vadai1eb8c692012-07-18 22:33:52 +0000184 list_add_tail(&spec_eth.list, &rule.list);
185 list_add_tail(&spec_ip.list, &rule.list);
Eyal Perry75a353d2013-11-07 12:19:49 +0200186 list_add_tail(&spec_tcp_udp.list, &rule.list);
Amir Vadai1eb8c692012-07-18 22:33:52 +0000187
Amir Vadai1eb8c692012-07-18 22:33:52 +0000188 rule.qpn = priv->rss_map.qps[filter->rxq_index].qpn;
Yan Burman6bbb6d92013-02-07 02:25:20 +0000189 memcpy(spec_eth.eth.dst_mac, priv->dev->dev_addr, ETH_ALEN);
Amir Vadai1eb8c692012-07-18 22:33:52 +0000190 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
191
192 filter->activated = 0;
193
194 if (filter->reg_id) {
195 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
196 if (rc && rc != -ENOENT)
197 en_err(priv, "Error detaching flow. rc = %d\n", rc);
198 }
199
200 rc = mlx4_flow_attach(priv->mdev->dev, &rule, &filter->reg_id);
201 if (rc)
202 en_err(priv, "Error attaching flow. err = %d\n", rc);
203
Eyal Perry75a353d2013-11-07 12:19:49 +0200204ignore:
Amir Vadai1eb8c692012-07-18 22:33:52 +0000205 mlx4_en_filter_rfs_expire(priv);
206
207 filter->activated = 1;
208}
209
210static inline struct hlist_head *
211filter_hash_bucket(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
212 __be16 src_port, __be16 dst_port)
213{
214 unsigned long l;
215 int bucket_idx;
216
217 l = (__force unsigned long)src_port |
218 ((__force unsigned long)dst_port << 2);
219 l ^= (__force unsigned long)(src_ip ^ dst_ip);
220
221 bucket_idx = hash_long(l, MLX4_EN_FILTER_HASH_SHIFT);
222
223 return &priv->filter_hash[bucket_idx];
224}
225
226static struct mlx4_en_filter *
227mlx4_en_filter_alloc(struct mlx4_en_priv *priv, int rxq_index, __be32 src_ip,
Eyal Perry75a353d2013-11-07 12:19:49 +0200228 __be32 dst_ip, u8 ip_proto, __be16 src_port,
229 __be16 dst_port, u32 flow_id)
Amir Vadai1eb8c692012-07-18 22:33:52 +0000230{
231 struct mlx4_en_filter *filter = NULL;
232
233 filter = kzalloc(sizeof(struct mlx4_en_filter), GFP_ATOMIC);
234 if (!filter)
235 return NULL;
236
237 filter->priv = priv;
238 filter->rxq_index = rxq_index;
239 INIT_WORK(&filter->work, mlx4_en_filter_work);
240
241 filter->src_ip = src_ip;
242 filter->dst_ip = dst_ip;
Eyal Perry75a353d2013-11-07 12:19:49 +0200243 filter->ip_proto = ip_proto;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000244 filter->src_port = src_port;
245 filter->dst_port = dst_port;
246
247 filter->flow_id = flow_id;
248
Amir Vadaiee64c0e2012-07-25 21:21:16 +0000249 filter->id = priv->last_filter_id++ % RPS_NO_FILTER;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000250
251 list_add_tail(&filter->next, &priv->filters);
252 hlist_add_head(&filter->filter_chain,
253 filter_hash_bucket(priv, src_ip, dst_ip, src_port,
254 dst_port));
255
256 return filter;
257}
258
259static void mlx4_en_filter_free(struct mlx4_en_filter *filter)
260{
261 struct mlx4_en_priv *priv = filter->priv;
262 int rc;
263
264 list_del(&filter->next);
265
266 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
267 if (rc && rc != -ENOENT)
268 en_err(priv, "Error detaching flow. rc = %d\n", rc);
269
270 kfree(filter);
271}
272
273static inline struct mlx4_en_filter *
274mlx4_en_filter_find(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
Eyal Perry75a353d2013-11-07 12:19:49 +0200275 u8 ip_proto, __be16 src_port, __be16 dst_port)
Amir Vadai1eb8c692012-07-18 22:33:52 +0000276{
Amir Vadai1eb8c692012-07-18 22:33:52 +0000277 struct mlx4_en_filter *filter;
278 struct mlx4_en_filter *ret = NULL;
279
Sasha Levinb67bfe02013-02-27 17:06:00 -0800280 hlist_for_each_entry(filter,
Amir Vadai1eb8c692012-07-18 22:33:52 +0000281 filter_hash_bucket(priv, src_ip, dst_ip,
282 src_port, dst_port),
283 filter_chain) {
284 if (filter->src_ip == src_ip &&
285 filter->dst_ip == dst_ip &&
Eyal Perry75a353d2013-11-07 12:19:49 +0200286 filter->ip_proto == ip_proto &&
Amir Vadai1eb8c692012-07-18 22:33:52 +0000287 filter->src_port == src_port &&
288 filter->dst_port == dst_port) {
289 ret = filter;
290 break;
291 }
292 }
293
294 return ret;
295}
296
297static int
298mlx4_en_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
299 u16 rxq_index, u32 flow_id)
300{
301 struct mlx4_en_priv *priv = netdev_priv(net_dev);
302 struct mlx4_en_filter *filter;
303 const struct iphdr *ip;
304 const __be16 *ports;
Eyal Perry75a353d2013-11-07 12:19:49 +0200305 u8 ip_proto;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000306 __be32 src_ip;
307 __be32 dst_ip;
308 __be16 src_port;
309 __be16 dst_port;
310 int nhoff = skb_network_offset(skb);
311 int ret = 0;
312
313 if (skb->protocol != htons(ETH_P_IP))
314 return -EPROTONOSUPPORT;
315
316 ip = (const struct iphdr *)(skb->data + nhoff);
317 if (ip_is_fragment(ip))
318 return -EPROTONOSUPPORT;
319
Eyal Perry75a353d2013-11-07 12:19:49 +0200320 if ((ip->protocol != IPPROTO_TCP) && (ip->protocol != IPPROTO_UDP))
321 return -EPROTONOSUPPORT;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000322 ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl);
323
Eyal Perry75a353d2013-11-07 12:19:49 +0200324 ip_proto = ip->protocol;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000325 src_ip = ip->saddr;
326 dst_ip = ip->daddr;
327 src_port = ports[0];
328 dst_port = ports[1];
329
Amir Vadai1eb8c692012-07-18 22:33:52 +0000330 spin_lock_bh(&priv->filters_lock);
Eyal Perry75a353d2013-11-07 12:19:49 +0200331 filter = mlx4_en_filter_find(priv, src_ip, dst_ip, ip_proto,
332 src_port, dst_port);
Amir Vadai1eb8c692012-07-18 22:33:52 +0000333 if (filter) {
334 if (filter->rxq_index == rxq_index)
335 goto out;
336
337 filter->rxq_index = rxq_index;
338 } else {
339 filter = mlx4_en_filter_alloc(priv, rxq_index,
Eyal Perry75a353d2013-11-07 12:19:49 +0200340 src_ip, dst_ip, ip_proto,
Amir Vadai1eb8c692012-07-18 22:33:52 +0000341 src_port, dst_port, flow_id);
342 if (!filter) {
343 ret = -ENOMEM;
344 goto err;
345 }
346 }
347
348 queue_work(priv->mdev->workqueue, &filter->work);
349
350out:
351 ret = filter->id;
352err:
353 spin_unlock_bh(&priv->filters_lock);
354
355 return ret;
356}
357
Eugenia Emantayev41d942d2013-11-07 12:19:52 +0200358void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv)
Amir Vadai1eb8c692012-07-18 22:33:52 +0000359{
360 struct mlx4_en_filter *filter, *tmp;
361 LIST_HEAD(del_list);
362
363 spin_lock_bh(&priv->filters_lock);
364 list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
365 list_move(&filter->next, &del_list);
366 hlist_del(&filter->filter_chain);
367 }
368 spin_unlock_bh(&priv->filters_lock);
369
370 list_for_each_entry_safe(filter, tmp, &del_list, next) {
371 cancel_work_sync(&filter->work);
372 mlx4_en_filter_free(filter);
373 }
374}
375
376static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv)
377{
378 struct mlx4_en_filter *filter = NULL, *tmp, *last_filter = NULL;
379 LIST_HEAD(del_list);
380 int i = 0;
381
382 spin_lock_bh(&priv->filters_lock);
383 list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
384 if (i > MLX4_EN_FILTER_EXPIRY_QUOTA)
385 break;
386
387 if (filter->activated &&
388 !work_pending(&filter->work) &&
389 rps_may_expire_flow(priv->dev,
390 filter->rxq_index, filter->flow_id,
391 filter->id)) {
392 list_move(&filter->next, &del_list);
393 hlist_del(&filter->filter_chain);
394 } else
395 last_filter = filter;
396
397 i++;
398 }
399
400 if (last_filter && (&last_filter->next != priv->filters.next))
401 list_move(&priv->filters, &last_filter->next);
402
403 spin_unlock_bh(&priv->filters_lock);
404
405 list_for_each_entry_safe(filter, tmp, &del_list, next)
406 mlx4_en_filter_free(filter);
407}
408#endif
409
Patrick McHardy80d5c362013-04-19 02:04:28 +0000410static int mlx4_en_vlan_rx_add_vid(struct net_device *dev,
411 __be16 proto, u16 vid)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700412{
413 struct mlx4_en_priv *priv = netdev_priv(dev);
414 struct mlx4_en_dev *mdev = priv->mdev;
415 int err;
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300416 int idx;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700417
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000418 en_dbg(HW, priv, "adding VLAN:%d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700419
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000420 set_bit(vid, priv->active_vlans);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700421
422 /* Add VID to port VLAN filter */
423 mutex_lock(&mdev->state_lock);
424 if (mdev->device_up && priv->port_up) {
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000425 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700426 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000427 en_err(priv, "Failed configuring VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700428 }
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300429 if (mlx4_register_vlan(mdev->dev, priv->port, vid, &idx))
Eugenia Emantayev9e19b542013-06-25 12:09:32 +0300430 en_dbg(HW, priv, "failed adding vlan %d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700431 mutex_unlock(&mdev->state_lock);
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300432
Jiri Pirko8e586132011-12-08 19:52:37 -0500433 return 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700434}
435
Patrick McHardy80d5c362013-04-19 02:04:28 +0000436static int mlx4_en_vlan_rx_kill_vid(struct net_device *dev,
437 __be16 proto, u16 vid)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700438{
439 struct mlx4_en_priv *priv = netdev_priv(dev);
440 struct mlx4_en_dev *mdev = priv->mdev;
441 int err;
442
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000443 en_dbg(HW, priv, "Killing VID:%d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700444
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000445 clear_bit(vid, priv->active_vlans);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700446
447 /* Remove VID from port VLAN filter */
448 mutex_lock(&mdev->state_lock);
Jack Morgenstein2009d002013-11-03 10:03:19 +0200449 mlx4_unregister_vlan(mdev->dev, priv->port, vid);
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300450
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700451 if (mdev->device_up && priv->port_up) {
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000452 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700453 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000454 en_err(priv, "Failed configuring VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700455 }
456 mutex_unlock(&mdev->state_lock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500457
458 return 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700459}
460
Yan Burman6bbb6d92013-02-07 02:25:20 +0000461static void mlx4_en_u64_to_mac(unsigned char dst_mac[ETH_ALEN + 2], u64 src_mac)
462{
Yan Burmanbab6a9e2013-04-02 16:49:45 +0300463 int i;
464 for (i = ETH_ALEN - 1; i >= 0; --i) {
Yan Burman6bbb6d92013-02-07 02:25:20 +0000465 dst_mac[i] = src_mac & 0xff;
466 src_mac >>= 8;
467 }
468 memset(&dst_mac[ETH_ALEN], 0, 2);
469}
470
Or Gerlitz837052d2013-12-23 16:09:44 +0200471
472static int mlx4_en_tunnel_steer_add(struct mlx4_en_priv *priv, unsigned char *addr,
473 int qpn, u64 *reg_id)
474{
475 int err;
476 struct mlx4_spec_list spec_eth_outer = { {NULL} };
477 struct mlx4_spec_list spec_vxlan = { {NULL} };
478 struct mlx4_spec_list spec_eth_inner = { {NULL} };
479
480 struct mlx4_net_trans_rule rule = {
481 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
482 .exclusive = 0,
483 .allow_loopback = 1,
484 .promisc_mode = MLX4_FS_REGULAR,
485 .priority = MLX4_DOMAIN_NIC,
486 };
487
488 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
489
490 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
491 return 0; /* do nothing */
492
493 rule.port = priv->port;
494 rule.qpn = qpn;
495 INIT_LIST_HEAD(&rule.list);
496
497 spec_eth_outer.id = MLX4_NET_TRANS_RULE_ID_ETH;
498 memcpy(spec_eth_outer.eth.dst_mac, addr, ETH_ALEN);
499 memcpy(spec_eth_outer.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
500
501 spec_vxlan.id = MLX4_NET_TRANS_RULE_ID_VXLAN; /* any vxlan header */
502 spec_eth_inner.id = MLX4_NET_TRANS_RULE_ID_ETH; /* any inner eth header */
503
504 list_add_tail(&spec_eth_outer.list, &rule.list);
505 list_add_tail(&spec_vxlan.list, &rule.list);
506 list_add_tail(&spec_eth_inner.list, &rule.list);
507
508 err = mlx4_flow_attach(priv->mdev->dev, &rule, reg_id);
509 if (err) {
510 en_err(priv, "failed to add vxlan steering rule, err %d\n", err);
511 return err;
512 }
513 en_dbg(DRV, priv, "added vxlan steering rule, mac %pM reg_id %llx\n", addr, *reg_id);
514 return 0;
515}
516
517
Yan Burman16a10ff2013-02-07 02:25:22 +0000518static int mlx4_en_uc_steer_add(struct mlx4_en_priv *priv,
519 unsigned char *mac, int *qpn, u64 *reg_id)
520{
521 struct mlx4_en_dev *mdev = priv->mdev;
522 struct mlx4_dev *dev = mdev->dev;
523 int err;
524
525 switch (dev->caps.steering_mode) {
526 case MLX4_STEERING_MODE_B0: {
527 struct mlx4_qp qp;
528 u8 gid[16] = {0};
529
530 qp.qpn = *qpn;
531 memcpy(&gid[10], mac, ETH_ALEN);
532 gid[5] = priv->port;
533
534 err = mlx4_unicast_attach(dev, &qp, gid, 0, MLX4_PROT_ETH);
535 break;
536 }
537 case MLX4_STEERING_MODE_DEVICE_MANAGED: {
538 struct mlx4_spec_list spec_eth = { {NULL} };
539 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
540
541 struct mlx4_net_trans_rule rule = {
542 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
543 .exclusive = 0,
544 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000545 .promisc_mode = MLX4_FS_REGULAR,
Yan Burman16a10ff2013-02-07 02:25:22 +0000546 .priority = MLX4_DOMAIN_NIC,
547 };
548
549 rule.port = priv->port;
550 rule.qpn = *qpn;
551 INIT_LIST_HEAD(&rule.list);
552
553 spec_eth.id = MLX4_NET_TRANS_RULE_ID_ETH;
554 memcpy(spec_eth.eth.dst_mac, mac, ETH_ALEN);
555 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
556 list_add_tail(&spec_eth.list, &rule.list);
557
558 err = mlx4_flow_attach(dev, &rule, reg_id);
559 break;
560 }
561 default:
562 return -EINVAL;
563 }
564 if (err)
565 en_warn(priv, "Failed Attaching Unicast\n");
566
567 return err;
568}
569
570static void mlx4_en_uc_steer_release(struct mlx4_en_priv *priv,
571 unsigned char *mac, int qpn, u64 reg_id)
572{
573 struct mlx4_en_dev *mdev = priv->mdev;
574 struct mlx4_dev *dev = mdev->dev;
575
576 switch (dev->caps.steering_mode) {
577 case MLX4_STEERING_MODE_B0: {
578 struct mlx4_qp qp;
579 u8 gid[16] = {0};
580
581 qp.qpn = qpn;
582 memcpy(&gid[10], mac, ETH_ALEN);
583 gid[5] = priv->port;
584
585 mlx4_unicast_detach(dev, &qp, gid, MLX4_PROT_ETH);
586 break;
587 }
588 case MLX4_STEERING_MODE_DEVICE_MANAGED: {
589 mlx4_flow_detach(dev, reg_id);
590 break;
591 }
592 default:
593 en_err(priv, "Invalid steering mode.\n");
594 }
595}
596
597static int mlx4_en_get_qp(struct mlx4_en_priv *priv)
598{
599 struct mlx4_en_dev *mdev = priv->mdev;
600 struct mlx4_dev *dev = mdev->dev;
601 struct mlx4_mac_entry *entry;
602 int index = 0;
603 int err = 0;
604 u64 reg_id;
605 int *qpn = &priv->base_qpn;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200606 u64 mac = mlx4_mac_to_u64(priv->dev->dev_addr);
Yan Burman16a10ff2013-02-07 02:25:22 +0000607
608 en_dbg(DRV, priv, "Registering MAC: %pM for adding\n",
609 priv->dev->dev_addr);
610 index = mlx4_register_mac(dev, priv->port, mac);
611 if (index < 0) {
612 err = index;
613 en_err(priv, "Failed adding MAC: %pM\n",
614 priv->dev->dev_addr);
615 return err;
616 }
617
618 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) {
619 int base_qpn = mlx4_get_base_qpn(dev, priv->port);
620 *qpn = base_qpn + index;
621 return 0;
622 }
623
624 err = mlx4_qp_reserve_range(dev, 1, 1, qpn);
625 en_dbg(DRV, priv, "Reserved qp %d\n", *qpn);
626 if (err) {
627 en_err(priv, "Failed to reserve qp for mac registration\n");
628 goto qp_err;
629 }
630
631 err = mlx4_en_uc_steer_add(priv, priv->dev->dev_addr, qpn, &reg_id);
632 if (err)
633 goto steer_err;
634
Wei Yongjun9ba75fb2014-01-07 16:56:07 +0800635 err = mlx4_en_tunnel_steer_add(priv, priv->dev->dev_addr, *qpn,
636 &priv->tunnel_reg_id);
637 if (err)
Or Gerlitz837052d2013-12-23 16:09:44 +0200638 goto tunnel_err;
639
Yan Burman16a10ff2013-02-07 02:25:22 +0000640 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
641 if (!entry) {
642 err = -ENOMEM;
643 goto alloc_err;
644 }
645 memcpy(entry->mac, priv->dev->dev_addr, sizeof(entry->mac));
646 entry->reg_id = reg_id;
647
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000648 hlist_add_head_rcu(&entry->hlist,
649 &priv->mac_hash[entry->mac[MLX4_EN_MAC_HASH_IDX]]);
Yan Burman16a10ff2013-02-07 02:25:22 +0000650
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000651 return 0;
Yan Burman16a10ff2013-02-07 02:25:22 +0000652
653alloc_err:
Or Gerlitz837052d2013-12-23 16:09:44 +0200654 if (priv->tunnel_reg_id)
655 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
656tunnel_err:
Yan Burman16a10ff2013-02-07 02:25:22 +0000657 mlx4_en_uc_steer_release(priv, priv->dev->dev_addr, *qpn, reg_id);
658
659steer_err:
660 mlx4_qp_release_range(dev, *qpn, 1);
661
662qp_err:
663 mlx4_unregister_mac(dev, priv->port, mac);
664 return err;
665}
666
667static void mlx4_en_put_qp(struct mlx4_en_priv *priv)
668{
669 struct mlx4_en_dev *mdev = priv->mdev;
670 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000671 int qpn = priv->base_qpn;
Yan Burman83a5a6c2013-03-07 03:46:56 +0000672 u64 mac;
Yan Burman16a10ff2013-02-07 02:25:22 +0000673
Yan Burman83a5a6c2013-03-07 03:46:56 +0000674 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) {
Eugenia Emantayev98133372014-03-02 10:25:01 +0200675 mac = mlx4_mac_to_u64(priv->dev->dev_addr);
Yan Burman83a5a6c2013-03-07 03:46:56 +0000676 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n",
677 priv->dev->dev_addr);
678 mlx4_unregister_mac(dev, priv->port, mac);
679 } else {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000680 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800681 struct hlist_node *tmp;
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000682 struct hlist_head *bucket;
Yan Burman83a5a6c2013-03-07 03:46:56 +0000683 unsigned int i;
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000684
Yan Burman83a5a6c2013-03-07 03:46:56 +0000685 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) {
686 bucket = &priv->mac_hash[i];
687 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Eugenia Emantayev98133372014-03-02 10:25:01 +0200688 mac = mlx4_mac_to_u64(entry->mac);
Yan Burman83a5a6c2013-03-07 03:46:56 +0000689 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n",
690 entry->mac);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000691 mlx4_en_uc_steer_release(priv, entry->mac,
692 qpn, entry->reg_id);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000693
Yan Burman83a5a6c2013-03-07 03:46:56 +0000694 mlx4_unregister_mac(dev, priv->port, mac);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000695 hlist_del_rcu(&entry->hlist);
696 kfree_rcu(entry, rcu);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000697 }
Yan Burman16a10ff2013-02-07 02:25:22 +0000698 }
Yan Burman83a5a6c2013-03-07 03:46:56 +0000699
Or Gerlitz837052d2013-12-23 16:09:44 +0200700 if (priv->tunnel_reg_id) {
701 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
702 priv->tunnel_reg_id = 0;
703 }
704
Yan Burman83a5a6c2013-03-07 03:46:56 +0000705 en_dbg(DRV, priv, "Releasing qp: port %d, qpn %d\n",
706 priv->port, qpn);
707 mlx4_qp_release_range(dev, qpn, 1);
708 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC;
Yan Burman16a10ff2013-02-07 02:25:22 +0000709 }
710}
711
712static int mlx4_en_replace_mac(struct mlx4_en_priv *priv, int qpn,
Yan Burman90bbb742013-02-07 02:25:24 +0000713 unsigned char *new_mac, unsigned char *prev_mac)
Yan Burman16a10ff2013-02-07 02:25:22 +0000714{
715 struct mlx4_en_dev *mdev = priv->mdev;
716 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000717 int err = 0;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200718 u64 new_mac_u64 = mlx4_mac_to_u64(new_mac);
Yan Burman16a10ff2013-02-07 02:25:22 +0000719
720 if (dev->caps.steering_mode != MLX4_STEERING_MODE_A0) {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000721 struct hlist_head *bucket;
722 unsigned int mac_hash;
723 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800724 struct hlist_node *tmp;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200725 u64 prev_mac_u64 = mlx4_mac_to_u64(prev_mac);
Yan Burman16a10ff2013-02-07 02:25:22 +0000726
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000727 bucket = &priv->mac_hash[prev_mac[MLX4_EN_MAC_HASH_IDX]];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800728 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000729 if (ether_addr_equal_64bits(entry->mac, prev_mac)) {
730 mlx4_en_uc_steer_release(priv, entry->mac,
731 qpn, entry->reg_id);
732 mlx4_unregister_mac(dev, priv->port,
733 prev_mac_u64);
734 hlist_del_rcu(&entry->hlist);
735 synchronize_rcu();
736 memcpy(entry->mac, new_mac, ETH_ALEN);
737 entry->reg_id = 0;
738 mac_hash = new_mac[MLX4_EN_MAC_HASH_IDX];
739 hlist_add_head_rcu(&entry->hlist,
740 &priv->mac_hash[mac_hash]);
741 mlx4_register_mac(dev, priv->port, new_mac_u64);
742 err = mlx4_en_uc_steer_add(priv, new_mac,
743 &qpn,
744 &entry->reg_id);
745 return err;
746 }
747 }
748 return -EINVAL;
Yan Burman16a10ff2013-02-07 02:25:22 +0000749 }
750
751 return __mlx4_replace_mac(dev, priv->port, qpn, new_mac_u64);
752}
753
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000754static int mlx4_en_do_set_mac(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700755{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700756 int err = 0;
757
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700758 if (priv->port_up) {
759 /* Remove old MAC and insert the new one */
Yan Burman16a10ff2013-02-07 02:25:22 +0000760 err = mlx4_en_replace_mac(priv, priv->base_qpn,
Yan Burman90bbb742013-02-07 02:25:24 +0000761 priv->dev->dev_addr, priv->prev_mac);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700762 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000763 en_err(priv, "Failed changing HW MAC address\n");
Yan Burman6bbb6d92013-02-07 02:25:20 +0000764 memcpy(priv->prev_mac, priv->dev->dev_addr,
765 sizeof(priv->prev_mac));
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700766 } else
Yan Burman48e551f2013-02-07 02:25:21 +0000767 en_dbg(HW, priv, "Port is down while registering mac, exiting...\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700768
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000769 return err;
770}
771
772static int mlx4_en_set_mac(struct net_device *dev, void *addr)
773{
774 struct mlx4_en_priv *priv = netdev_priv(dev);
775 struct mlx4_en_dev *mdev = priv->mdev;
776 struct sockaddr *saddr = addr;
777 int err;
778
779 if (!is_valid_ether_addr(saddr->sa_data))
780 return -EADDRNOTAVAIL;
781
782 memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
783
784 mutex_lock(&mdev->state_lock);
785 err = mlx4_en_do_set_mac(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700786 mutex_unlock(&mdev->state_lock);
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000787
788 return err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700789}
790
791static void mlx4_en_clear_list(struct net_device *dev)
792{
793 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000794 struct mlx4_en_mc_list *tmp, *mc_to_del;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700795
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000796 list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) {
797 list_del(&mc_to_del->list);
798 kfree(mc_to_del);
799 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700800}
801
802static void mlx4_en_cache_mclist(struct net_device *dev)
803{
804 struct mlx4_en_priv *priv = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000805 struct netdev_hw_addr *ha;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000806 struct mlx4_en_mc_list *tmp;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700807
Alexander Guller0e035672011-12-19 04:02:58 +0000808 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000809 netdev_for_each_mc_addr(ha, dev) {
810 tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC);
811 if (!tmp) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000812 mlx4_en_clear_list(dev);
813 return;
814 }
815 memcpy(tmp->addr, ha->addr, ETH_ALEN);
816 list_add_tail(&tmp->list, &priv->mc_list);
817 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700818}
819
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000820static void update_mclist_flags(struct mlx4_en_priv *priv,
821 struct list_head *dst,
822 struct list_head *src)
823{
824 struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc;
825 bool found;
826
827 /* Find all the entries that should be removed from dst,
828 * These are the entries that are not found in src
829 */
830 list_for_each_entry(dst_tmp, dst, list) {
831 found = false;
832 list_for_each_entry(src_tmp, src, list) {
dingtianhongc0623e52013-12-30 15:40:55 +0800833 if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000834 found = true;
835 break;
836 }
837 }
838 if (!found)
839 dst_tmp->action = MCLIST_REM;
840 }
841
842 /* Add entries that exist in src but not in dst
843 * mark them as need to add
844 */
845 list_for_each_entry(src_tmp, src, list) {
846 found = false;
847 list_for_each_entry(dst_tmp, dst, list) {
dingtianhongc0623e52013-12-30 15:40:55 +0800848 if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000849 dst_tmp->action = MCLIST_NONE;
850 found = true;
851 break;
852 }
853 }
854 if (!found) {
Joe Perches14f8dc42013-02-07 11:46:27 +0000855 new_mc = kmemdup(src_tmp,
856 sizeof(struct mlx4_en_mc_list),
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000857 GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +0000858 if (!new_mc)
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000859 return;
Joe Perches14f8dc42013-02-07 11:46:27 +0000860
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000861 new_mc->action = MCLIST_ADD;
862 list_add_tail(&new_mc->list, dst);
863 }
864 }
865}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700866
Yan Burman0eb74fd2013-02-07 02:25:23 +0000867static void mlx4_en_set_rx_mode(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700868{
869 struct mlx4_en_priv *priv = netdev_priv(dev);
870
871 if (!priv->port_up)
872 return;
873
Yan Burman0eb74fd2013-02-07 02:25:23 +0000874 queue_work(priv->mdev->workqueue, &priv->rx_mode_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700875}
876
Yan Burman0eb74fd2013-02-07 02:25:23 +0000877static void mlx4_en_set_promisc_mode(struct mlx4_en_priv *priv,
878 struct mlx4_en_dev *mdev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700879{
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000880 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700881
Yan Burman0eb74fd2013-02-07 02:25:23 +0000882 if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700883 if (netif_msg_rx_status(priv))
Yan Burman0eb74fd2013-02-07 02:25:23 +0000884 en_warn(priv, "Entering promiscuous mode\n");
885 priv->flags |= MLX4_EN_FLAG_PROMISC;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700886
Yan Burman0eb74fd2013-02-07 02:25:23 +0000887 /* Enable promiscouos mode */
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000888 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000889 case MLX4_STEERING_MODE_DEVICE_MANAGED:
Yan Burman0eb74fd2013-02-07 02:25:23 +0000890 err = mlx4_flow_steer_promisc_add(mdev->dev,
891 priv->port,
892 priv->base_qpn,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000893 MLX4_FS_ALL_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000894 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000895 en_err(priv, "Failed enabling promiscuous mode\n");
896 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000897 break;
898
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000899 case MLX4_STEERING_MODE_B0:
Yan Burman0eb74fd2013-02-07 02:25:23 +0000900 err = mlx4_unicast_promisc_add(mdev->dev,
901 priv->base_qpn,
902 priv->port);
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000903 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000904 en_err(priv, "Failed enabling unicast promiscuous mode\n");
905
906 /* Add the default qp number as multicast
907 * promisc
908 */
909 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
910 err = mlx4_multicast_promisc_add(mdev->dev,
911 priv->base_qpn,
912 priv->port);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000913 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000914 en_err(priv, "Failed enabling multicast promiscuous mode\n");
915 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000916 }
917 break;
918
919 case MLX4_STEERING_MODE_A0:
920 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
921 priv->port,
Yan Burman0eb74fd2013-02-07 02:25:23 +0000922 priv->base_qpn,
923 1);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000924 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000925 en_err(priv, "Failed enabling promiscuous mode\n");
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000926 break;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000927 }
928
Yan Burman0eb74fd2013-02-07 02:25:23 +0000929 /* Disable port multicast filter (unconditionally) */
930 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
931 0, MLX4_MCAST_DISABLE);
932 if (err)
933 en_err(priv, "Failed disabling multicast filter\n");
934
935 /* Disable port VLAN filter */
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000936 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700937 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000938 en_err(priv, "Failed disabling VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700939 }
Yan Burman0eb74fd2013-02-07 02:25:23 +0000940}
941
942static void mlx4_en_clear_promisc_mode(struct mlx4_en_priv *priv,
943 struct mlx4_en_dev *mdev)
944{
945 int err = 0;
946
947 if (netif_msg_rx_status(priv))
948 en_warn(priv, "Leaving promiscuous mode\n");
949 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
950
951 /* Disable promiscouos mode */
952 switch (mdev->dev->caps.steering_mode) {
953 case MLX4_STEERING_MODE_DEVICE_MANAGED:
954 err = mlx4_flow_steer_promisc_remove(mdev->dev,
955 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000956 MLX4_FS_ALL_DEFAULT);
Yan Burman0eb74fd2013-02-07 02:25:23 +0000957 if (err)
958 en_err(priv, "Failed disabling promiscuous mode\n");
959 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
960 break;
961
962 case MLX4_STEERING_MODE_B0:
963 err = mlx4_unicast_promisc_remove(mdev->dev,
964 priv->base_qpn,
965 priv->port);
966 if (err)
967 en_err(priv, "Failed disabling unicast promiscuous mode\n");
968 /* Disable Multicast promisc */
969 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
970 err = mlx4_multicast_promisc_remove(mdev->dev,
971 priv->base_qpn,
972 priv->port);
973 if (err)
974 en_err(priv, "Failed disabling multicast promiscuous mode\n");
975 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
976 }
977 break;
978
979 case MLX4_STEERING_MODE_A0:
980 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
981 priv->port,
982 priv->base_qpn, 0);
983 if (err)
984 en_err(priv, "Failed disabling promiscuous mode\n");
985 break;
986 }
987
988 /* Enable port VLAN filter */
989 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
990 if (err)
991 en_err(priv, "Failed enabling VLAN filter\n");
992}
993
994static void mlx4_en_do_multicast(struct mlx4_en_priv *priv,
995 struct net_device *dev,
996 struct mlx4_en_dev *mdev)
997{
998 struct mlx4_en_mc_list *mclist, *tmp;
999 u64 mcast_addr = 0;
1000 u8 mc_list[16] = {0};
1001 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001002
1003 /* Enable/disable the multicast filter according to IFF_ALLMULTI */
1004 if (dev->flags & IFF_ALLMULTI) {
1005 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
1006 0, MLX4_MCAST_DISABLE);
1007 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001008 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001009
1010 /* Add the default qp number as multicast promisc */
1011 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001012 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001013 case MLX4_STEERING_MODE_DEVICE_MANAGED:
1014 err = mlx4_flow_steer_promisc_add(mdev->dev,
1015 priv->port,
1016 priv->base_qpn,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001017 MLX4_FS_MC_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001018 break;
1019
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001020 case MLX4_STEERING_MODE_B0:
1021 err = mlx4_multicast_promisc_add(mdev->dev,
1022 priv->base_qpn,
1023 priv->port);
1024 break;
1025
1026 case MLX4_STEERING_MODE_A0:
1027 break;
1028 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001029 if (err)
1030 en_err(priv, "Failed entering multicast promisc mode\n");
1031 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
1032 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001033 } else {
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001034 /* Disable Multicast promisc */
1035 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001036 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001037 case MLX4_STEERING_MODE_DEVICE_MANAGED:
1038 err = mlx4_flow_steer_promisc_remove(mdev->dev,
1039 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001040 MLX4_FS_MC_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001041 break;
1042
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001043 case MLX4_STEERING_MODE_B0:
1044 err = mlx4_multicast_promisc_remove(mdev->dev,
1045 priv->base_qpn,
1046 priv->port);
1047 break;
1048
1049 case MLX4_STEERING_MODE_A0:
1050 break;
1051 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001052 if (err)
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001053 en_err(priv, "Failed disabling multicast promiscuous mode\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001054 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
1055 }
Jiri Pirkoff6e2162010-03-01 05:09:14 +00001056
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001057 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
1058 0, MLX4_MCAST_DISABLE);
1059 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001060 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001061
1062 /* Flush mcast filter and init it with broadcast address */
1063 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST,
1064 1, MLX4_MCAST_CONFIG);
1065
1066 /* Update multicast list - we cache all addresses so they won't
1067 * change while HW is updated holding the command semaphor */
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +00001068 netif_addr_lock_bh(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001069 mlx4_en_cache_mclist(dev);
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +00001070 netif_addr_unlock_bh(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001071 list_for_each_entry(mclist, &priv->mc_list, list) {
Eugenia Emantayev98133372014-03-02 10:25:01 +02001072 mcast_addr = mlx4_mac_to_u64(mclist->addr);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001073 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port,
1074 mcast_addr, 0, MLX4_MCAST_CONFIG);
1075 }
1076 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
1077 0, MLX4_MCAST_ENABLE);
1078 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001079 en_err(priv, "Failed enabling multicast filter\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001080
1081 update_mclist_flags(priv, &priv->curr_list, &priv->mc_list);
1082 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
1083 if (mclist->action == MCLIST_REM) {
1084 /* detach this address and delete from list */
1085 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
1086 mc_list[5] = priv->port;
1087 err = mlx4_multicast_detach(mdev->dev,
1088 &priv->rss_map.indir_qp,
1089 mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001090 MLX4_PROT_ETH,
1091 mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001092 if (err)
1093 en_err(priv, "Fail to detach multicast address\n");
1094
Or Gerlitz837052d2013-12-23 16:09:44 +02001095 if (mclist->tunnel_reg_id) {
1096 err = mlx4_flow_detach(priv->mdev->dev, mclist->tunnel_reg_id);
1097 if (err)
1098 en_err(priv, "Failed to detach multicast address\n");
1099 }
1100
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001101 /* remove from list */
1102 list_del(&mclist->list);
1103 kfree(mclist);
Dan Carpenter9c645082012-07-10 20:34:07 +00001104 } else if (mclist->action == MCLIST_ADD) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001105 /* attach the address */
1106 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001107 /* needed for B0 steering support */
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001108 mc_list[5] = priv->port;
1109 err = mlx4_multicast_attach(mdev->dev,
1110 &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001111 mc_list,
1112 priv->port, 0,
1113 MLX4_PROT_ETH,
1114 &mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001115 if (err)
1116 en_err(priv, "Fail to attach multicast address\n");
1117
Or Gerlitz837052d2013-12-23 16:09:44 +02001118 err = mlx4_en_tunnel_steer_add(priv, &mc_list[10], priv->base_qpn,
1119 &mclist->tunnel_reg_id);
1120 if (err)
1121 en_err(priv, "Failed to attach multicast address\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001122 }
1123 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001124 }
Yan Burman0eb74fd2013-02-07 02:25:23 +00001125}
1126
Yan Burmancc5387f2013-02-07 02:25:26 +00001127static void mlx4_en_do_uc_filter(struct mlx4_en_priv *priv,
1128 struct net_device *dev,
1129 struct mlx4_en_dev *mdev)
1130{
1131 struct netdev_hw_addr *ha;
1132 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001133 struct hlist_node *tmp;
Yan Burmancc5387f2013-02-07 02:25:26 +00001134 bool found;
1135 u64 mac;
1136 int err = 0;
1137 struct hlist_head *bucket;
1138 unsigned int i;
1139 int removed = 0;
1140 u32 prev_flags;
1141
1142 /* Note that we do not need to protect our mac_hash traversal with rcu,
1143 * since all modification code is protected by mdev->state_lock
1144 */
1145
1146 /* find what to remove */
1147 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) {
1148 bucket = &priv->mac_hash[i];
Sasha Levinb67bfe02013-02-27 17:06:00 -08001149 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Yan Burmancc5387f2013-02-07 02:25:26 +00001150 found = false;
1151 netdev_for_each_uc_addr(ha, dev) {
1152 if (ether_addr_equal_64bits(entry->mac,
1153 ha->addr)) {
1154 found = true;
1155 break;
1156 }
1157 }
1158
1159 /* MAC address of the port is not in uc list */
1160 if (ether_addr_equal_64bits(entry->mac, dev->dev_addr))
1161 found = true;
1162
1163 if (!found) {
Eugenia Emantayev98133372014-03-02 10:25:01 +02001164 mac = mlx4_mac_to_u64(entry->mac);
Yan Burmancc5387f2013-02-07 02:25:26 +00001165 mlx4_en_uc_steer_release(priv, entry->mac,
1166 priv->base_qpn,
1167 entry->reg_id);
1168 mlx4_unregister_mac(mdev->dev, priv->port, mac);
1169
1170 hlist_del_rcu(&entry->hlist);
1171 kfree_rcu(entry, rcu);
1172 en_dbg(DRV, priv, "Removed MAC %pM on port:%d\n",
1173 entry->mac, priv->port);
1174 ++removed;
1175 }
1176 }
1177 }
1178
1179 /* if we didn't remove anything, there is no use in trying to add
1180 * again once we are in a forced promisc mode state
1181 */
1182 if ((priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) && 0 == removed)
1183 return;
1184
1185 prev_flags = priv->flags;
1186 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC;
1187
1188 /* find what to add */
1189 netdev_for_each_uc_addr(ha, dev) {
1190 found = false;
1191 bucket = &priv->mac_hash[ha->addr[MLX4_EN_MAC_HASH_IDX]];
Sasha Levinb67bfe02013-02-27 17:06:00 -08001192 hlist_for_each_entry(entry, bucket, hlist) {
Yan Burmancc5387f2013-02-07 02:25:26 +00001193 if (ether_addr_equal_64bits(entry->mac, ha->addr)) {
1194 found = true;
1195 break;
1196 }
1197 }
1198
1199 if (!found) {
1200 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1201 if (!entry) {
1202 en_err(priv, "Failed adding MAC %pM on port:%d (out of memory)\n",
1203 ha->addr, priv->port);
1204 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1205 break;
1206 }
Eugenia Emantayev98133372014-03-02 10:25:01 +02001207 mac = mlx4_mac_to_u64(ha->addr);
Yan Burmancc5387f2013-02-07 02:25:26 +00001208 memcpy(entry->mac, ha->addr, ETH_ALEN);
1209 err = mlx4_register_mac(mdev->dev, priv->port, mac);
1210 if (err < 0) {
1211 en_err(priv, "Failed registering MAC %pM on port %d: %d\n",
1212 ha->addr, priv->port, err);
1213 kfree(entry);
1214 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1215 break;
1216 }
1217 err = mlx4_en_uc_steer_add(priv, ha->addr,
1218 &priv->base_qpn,
1219 &entry->reg_id);
1220 if (err) {
1221 en_err(priv, "Failed adding MAC %pM on port %d: %d\n",
1222 ha->addr, priv->port, err);
1223 mlx4_unregister_mac(mdev->dev, priv->port, mac);
1224 kfree(entry);
1225 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1226 break;
1227 } else {
1228 unsigned int mac_hash;
1229 en_dbg(DRV, priv, "Added MAC %pM on port:%d\n",
1230 ha->addr, priv->port);
1231 mac_hash = ha->addr[MLX4_EN_MAC_HASH_IDX];
1232 bucket = &priv->mac_hash[mac_hash];
1233 hlist_add_head_rcu(&entry->hlist, bucket);
1234 }
1235 }
1236 }
1237
1238 if (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) {
1239 en_warn(priv, "Forcing promiscuous mode on port:%d\n",
1240 priv->port);
1241 } else if (prev_flags & MLX4_EN_FLAG_FORCE_PROMISC) {
1242 en_warn(priv, "Stop forcing promiscuous mode on port:%d\n",
1243 priv->port);
1244 }
1245}
1246
Yan Burman0eb74fd2013-02-07 02:25:23 +00001247static void mlx4_en_do_set_rx_mode(struct work_struct *work)
1248{
1249 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1250 rx_mode_task);
1251 struct mlx4_en_dev *mdev = priv->mdev;
1252 struct net_device *dev = priv->dev;
1253
1254 mutex_lock(&mdev->state_lock);
1255 if (!mdev->device_up) {
1256 en_dbg(HW, priv, "Card is not up, ignoring rx mode change.\n");
1257 goto out;
1258 }
1259 if (!priv->port_up) {
1260 en_dbg(HW, priv, "Port is down, ignoring rx mode change.\n");
1261 goto out;
1262 }
1263
1264 if (!netif_carrier_ok(dev)) {
1265 if (!mlx4_en_QUERY_PORT(mdev, priv->port)) {
1266 if (priv->port_state.link_state) {
1267 priv->last_link_state = MLX4_DEV_EVENT_PORT_UP;
1268 netif_carrier_on(dev);
1269 en_dbg(LINK, priv, "Link Up\n");
1270 }
1271 }
1272 }
1273
Yan Burmancc5387f2013-02-07 02:25:26 +00001274 if (dev->priv_flags & IFF_UNICAST_FLT)
1275 mlx4_en_do_uc_filter(priv, dev, mdev);
1276
Yan Burman0eb74fd2013-02-07 02:25:23 +00001277 /* Promsicuous mode: disable all filters */
Yan Burmancc5387f2013-02-07 02:25:26 +00001278 if ((dev->flags & IFF_PROMISC) ||
1279 (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC)) {
Yan Burman0eb74fd2013-02-07 02:25:23 +00001280 mlx4_en_set_promisc_mode(priv, mdev);
1281 goto out;
1282 }
1283
1284 /* Not in promiscuous mode */
1285 if (priv->flags & MLX4_EN_FLAG_PROMISC)
1286 mlx4_en_clear_promisc_mode(priv, mdev);
1287
1288 mlx4_en_do_multicast(priv, dev, mdev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001289out:
1290 mutex_unlock(&mdev->state_lock);
1291}
1292
1293#ifdef CONFIG_NET_POLL_CONTROLLER
1294static void mlx4_en_netpoll(struct net_device *dev)
1295{
1296 struct mlx4_en_priv *priv = netdev_priv(dev);
1297 struct mlx4_en_cq *cq;
1298 unsigned long flags;
1299 int i;
1300
1301 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001302 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001303 spin_lock_irqsave(&cq->lock, flags);
1304 napi_synchronize(&cq->napi);
1305 mlx4_en_process_rx_cq(dev, cq, 0);
1306 spin_unlock_irqrestore(&cq->lock, flags);
1307 }
1308}
1309#endif
1310
1311static void mlx4_en_tx_timeout(struct net_device *dev)
1312{
1313 struct mlx4_en_priv *priv = netdev_priv(dev);
1314 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001315 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001316
1317 if (netif_msg_timer(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001318 en_warn(priv, "Tx timeout called on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001319
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001320 for (i = 0; i < priv->tx_ring_num; i++) {
1321 if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev, i)))
1322 continue;
1323 en_warn(priv, "TX timeout on queue: %d, QP: 0x%x, CQ: 0x%x, Cons: 0x%x, Prod: 0x%x\n",
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001324 i, priv->tx_ring[i]->qpn, priv->tx_ring[i]->cqn,
1325 priv->tx_ring[i]->cons, priv->tx_ring[i]->prod);
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001326 }
1327
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001328 priv->port_stats.tx_timeout++;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001329 en_dbg(DRV, priv, "Scheduling watchdog\n");
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001330 queue_work(mdev->workqueue, &priv->watchdog_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001331}
1332
1333
1334static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev)
1335{
1336 struct mlx4_en_priv *priv = netdev_priv(dev);
1337
1338 spin_lock_bh(&priv->stats_lock);
1339 memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats));
1340 spin_unlock_bh(&priv->stats_lock);
1341
1342 return &priv->ret_stats;
1343}
1344
1345static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv)
1346{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001347 struct mlx4_en_cq *cq;
1348 int i;
1349
1350 /* If we haven't received a specific coalescing setting
Martin Olsson98a17082009-04-22 18:21:29 +02001351 * (module param), we set the moderation parameters as follows:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001352 * - moder_cnt is set to the number of mtu sized packets to
Eric Dumazetecfd2ce2012-11-05 16:20:42 +00001353 * satisfy our coalescing target.
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001354 * - moder_time is set to a fixed value.
1355 */
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +00001356 priv->rx_frames = MLX4_EN_RX_COAL_TARGET;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -08001357 priv->rx_usecs = MLX4_EN_RX_COAL_TIME;
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001358 priv->tx_frames = MLX4_EN_TX_COAL_PKTS;
1359 priv->tx_usecs = MLX4_EN_TX_COAL_TIME;
Yan Burman48e551f2013-02-07 02:25:21 +00001360 en_dbg(INTR, priv, "Default coalesing params for mtu:%d - rx_frames:%d rx_usecs:%d\n",
1361 priv->dev->mtu, priv->rx_frames, priv->rx_usecs);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001362
1363 /* Setup cq moderation params */
1364 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001365 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001366 cq->moder_cnt = priv->rx_frames;
1367 cq->moder_time = priv->rx_usecs;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001368 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
1369 priv->last_moder_packets[i] = 0;
1370 priv->last_moder_bytes[i] = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001371 }
1372
1373 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001374 cq = priv->tx_cq[i];
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001375 cq->moder_cnt = priv->tx_frames;
1376 cq->moder_time = priv->tx_usecs;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001377 }
1378
1379 /* Reset auto-moderation params */
1380 priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW;
1381 priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW;
1382 priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH;
1383 priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH;
1384 priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -08001385 priv->adaptive_rx_coal = 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001386 priv->last_moder_jiffies = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001387 priv->last_moder_tx_packets = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001388}
1389
1390static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv)
1391{
1392 unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001393 struct mlx4_en_cq *cq;
1394 unsigned long packets;
1395 unsigned long rate;
1396 unsigned long avg_pkt_size;
1397 unsigned long rx_packets;
1398 unsigned long rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001399 unsigned long rx_pkt_diff;
1400 int moder_time;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001401 int ring, err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001402
1403 if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ)
1404 return;
1405
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001406 for (ring = 0; ring < priv->rx_ring_num; ring++) {
1407 spin_lock_bh(&priv->stats_lock);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001408 rx_packets = priv->rx_ring[ring]->packets;
1409 rx_bytes = priv->rx_ring[ring]->bytes;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001410 spin_unlock_bh(&priv->stats_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001411
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001412 rx_pkt_diff = ((unsigned long) (rx_packets -
1413 priv->last_moder_packets[ring]));
1414 packets = rx_pkt_diff;
1415 rate = packets * HZ / period;
1416 avg_pkt_size = packets ? ((unsigned long) (rx_bytes -
1417 priv->last_moder_bytes[ring])) / packets : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001418
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001419 /* Apply auto-moderation only when packet rate
1420 * exceeds a rate that it matters */
1421 if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) &&
1422 avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001423 if (rate < priv->pkt_rate_low)
1424 moder_time = priv->rx_usecs_low;
1425 else if (rate > priv->pkt_rate_high)
1426 moder_time = priv->rx_usecs_high;
1427 else
1428 moder_time = (rate - priv->pkt_rate_low) *
1429 (priv->rx_usecs_high - priv->rx_usecs_low) /
1430 (priv->pkt_rate_high - priv->pkt_rate_low) +
1431 priv->rx_usecs_low;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001432 } else {
1433 moder_time = priv->rx_usecs_low;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001434 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001435
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001436 if (moder_time != priv->last_moder_time[ring]) {
1437 priv->last_moder_time[ring] = moder_time;
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001438 cq = priv->rx_cq[ring];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001439 cq->moder_time = moder_time;
Sagi Grimberga1c66932013-06-04 05:13:26 +00001440 cq->moder_cnt = priv->rx_frames;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001441 err = mlx4_en_set_cq_moder(priv, cq);
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001442 if (err)
Yan Burman48e551f2013-02-07 02:25:21 +00001443 en_err(priv, "Failed modifying moderation for cq:%d\n",
1444 ring);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001445 }
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001446 priv->last_moder_packets[ring] = rx_packets;
1447 priv->last_moder_bytes[ring] = rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001448 }
1449
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001450 priv->last_moder_jiffies = jiffies;
1451}
1452
1453static void mlx4_en_do_get_stats(struct work_struct *work)
1454{
Jean Delvarebf6aede2009-04-02 16:56:54 -07001455 struct delayed_work *delay = to_delayed_work(work);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001456 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
1457 stats_task);
1458 struct mlx4_en_dev *mdev = priv->mdev;
1459 int err;
1460
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001461 mutex_lock(&mdev->state_lock);
1462 if (mdev->device_up) {
Jack Morgenstein6123db22013-06-25 12:09:30 +03001463 if (priv->port_up) {
1464 err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0);
1465 if (err)
1466 en_dbg(HW, priv, "Could not update stats\n");
Eugenia Emantayev2d518372013-01-24 01:54:14 +00001467
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001468 mlx4_en_auto_moderation(priv);
Jack Morgenstein6123db22013-06-25 12:09:30 +03001469 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001470
1471 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
1472 }
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +00001473 if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
Yan Burmanbfa8ab42013-03-07 03:46:55 +00001474 mlx4_en_do_set_mac(priv);
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +00001475 mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
1476 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001477 mutex_unlock(&mdev->state_lock);
1478}
1479
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001480/* mlx4_en_service_task - Run service task for tasks that needed to be done
1481 * periodically
1482 */
1483static void mlx4_en_service_task(struct work_struct *work)
1484{
1485 struct delayed_work *delay = to_delayed_work(work);
1486 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
1487 service_task);
1488 struct mlx4_en_dev *mdev = priv->mdev;
1489
1490 mutex_lock(&mdev->state_lock);
1491 if (mdev->device_up) {
Amir Vadaidc8142e2013-04-25 05:22:24 +00001492 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
1493 mlx4_en_ptp_overflow_check(mdev);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001494
1495 queue_delayed_work(mdev->workqueue, &priv->service_task,
1496 SERVICE_TASK_DELAY);
1497 }
1498 mutex_unlock(&mdev->state_lock);
1499}
1500
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001501static void mlx4_en_linkstate(struct work_struct *work)
1502{
1503 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1504 linkstate_task);
1505 struct mlx4_en_dev *mdev = priv->mdev;
1506 int linkstate = priv->link_state;
1507
1508 mutex_lock(&mdev->state_lock);
1509 /* If observable port state changed set carrier state and
1510 * report to system log */
1511 if (priv->last_link_state != linkstate) {
1512 if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001513 en_info(priv, "Link Down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001514 netif_carrier_off(priv->dev);
1515 } else {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001516 en_info(priv, "Link Up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001517 netif_carrier_on(priv->dev);
1518 }
1519 }
1520 priv->last_link_state = linkstate;
1521 mutex_unlock(&mdev->state_lock);
1522}
1523
1524
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001525int mlx4_en_start_port(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001526{
1527 struct mlx4_en_priv *priv = netdev_priv(dev);
1528 struct mlx4_en_dev *mdev = priv->mdev;
1529 struct mlx4_en_cq *cq;
1530 struct mlx4_en_tx_ring *tx_ring;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001531 int rx_index = 0;
1532 int tx_index = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001533 int err = 0;
1534 int i;
1535 int j;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001536 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001537
1538 if (priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001539 en_dbg(DRV, priv, "start port called while port already up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001540 return 0;
1541 }
1542
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001543 INIT_LIST_HEAD(&priv->mc_list);
1544 INIT_LIST_HEAD(&priv->curr_list);
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001545 INIT_LIST_HEAD(&priv->ethtool_list);
1546 memset(&priv->ethtool_rules[0], 0,
1547 sizeof(struct ethtool_flow_id) * MAX_NUM_OF_FS_RULES);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001548
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001549 /* Calculate Rx buf size */
1550 dev->mtu = min(dev->mtu, priv->max_mtu);
1551 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001552 en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_skb_size);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001553
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001554 /* Configure rx cq's and rings */
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001555 err = mlx4_en_activate_rx_rings(priv);
1556 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001557 en_err(priv, "Failed to activate RX rings\n");
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001558 return err;
1559 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001560 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001561 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001562
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001563 mlx4_en_cq_init_lock(cq);
1564
Alexander Guller76532d02011-10-09 05:26:31 +00001565 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001566 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001567 en_err(priv, "Failed activating Rx CQ\n");
Yevgeny Petrilina4233302009-04-26 20:41:34 +00001568 goto cq_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001569 }
1570 for (j = 0; j < cq->size; j++)
1571 cq->buf[j].owner_sr_opcode = MLX4_CQE_OWNER_MASK;
1572 err = mlx4_en_set_cq_moder(priv, cq);
1573 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001574 en_err(priv, "Failed setting cq moderation parameters");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001575 mlx4_en_deactivate_cq(priv, cq);
1576 goto cq_err;
1577 }
1578 mlx4_en_arm_cq(priv, cq);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001579 priv->rx_ring[i]->cqn = cq->mcq.cqn;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001580 ++rx_index;
1581 }
1582
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001583 /* Set qp number */
1584 en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port);
Yan Burman16a10ff2013-02-07 02:25:22 +00001585 err = mlx4_en_get_qp(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001586 if (err) {
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001587 en_err(priv, "Failed getting eth qp\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001588 goto cq_err;
1589 }
1590 mdev->mac_removed[priv->port] = 0;
1591
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001592 err = mlx4_en_config_rss_steer(priv);
1593 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001594 en_err(priv, "Failed configuring rss steering\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001595 goto mac_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001596 }
1597
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001598 err = mlx4_en_create_drop_qp(priv);
1599 if (err)
1600 goto rss_err;
1601
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001602 /* Configure tx cq's and rings */
1603 for (i = 0; i < priv->tx_ring_num; i++) {
1604 /* Configure cq */
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001605 cq = priv->tx_cq[i];
Alexander Guller76532d02011-10-09 05:26:31 +00001606 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001607 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001608 en_err(priv, "Failed allocating Tx CQ\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001609 goto tx_err;
1610 }
1611 err = mlx4_en_set_cq_moder(priv, cq);
1612 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001613 en_err(priv, "Failed setting cq moderation parameters");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001614 mlx4_en_deactivate_cq(priv, cq);
1615 goto tx_err;
1616 }
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001617 en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001618 cq->buf->wqe_index = cpu_to_be16(0xffff);
1619
1620 /* Configure ring */
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001621 tx_ring = priv->tx_ring[i];
Amir Vadai0e98b522012-04-04 21:33:24 +00001622 err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn,
Amir Vadaid3179662012-12-02 03:49:23 +00001623 i / priv->num_tx_rings_p_up);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001624 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001625 en_err(priv, "Failed allocating Tx ring\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001626 mlx4_en_deactivate_cq(priv, cq);
1627 goto tx_err;
1628 }
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001629 tx_ring->tx_queue = netdev_get_tx_queue(dev, i);
Yevgeny Petriline22979d2012-04-23 02:18:39 +00001630
1631 /* Arm CQ for TX completions */
1632 mlx4_en_arm_cq(priv, cq);
1633
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001634 /* Set initial ownership of all Tx TXBBs to SW (1) */
1635 for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE)
1636 *((u32 *) (tx_ring->buf + j)) = 0xffffffff;
1637 ++tx_index;
1638 }
1639
1640 /* Configure port */
1641 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
1642 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001643 priv->prof->tx_pause,
1644 priv->prof->tx_ppp,
1645 priv->prof->rx_pause,
1646 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001647 if (err) {
Yan Burman48e551f2013-02-07 02:25:21 +00001648 en_err(priv, "Failed setting port general configurations for port %d, with error %d\n",
1649 priv->port, err);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001650 goto tx_err;
1651 }
1652 /* Set default qp number */
1653 err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0);
1654 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001655 en_err(priv, "Failed setting default qp numbers\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001656 goto tx_err;
1657 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001658
Or Gerlitz837052d2013-12-23 16:09:44 +02001659 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
1660 err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC);
1661 if (err) {
1662 en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n",
1663 err);
1664 goto tx_err;
1665 }
1666 }
1667
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001668 /* Init port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001669 en_dbg(HW, priv, "Initializing port\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001670 err = mlx4_INIT_PORT(mdev->dev, priv->port);
1671 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001672 en_err(priv, "Failed Initializing port\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001673 goto tx_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001674 }
1675
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001676 /* Attach rx QP to bradcast address */
1677 memset(&mc_list[10], 0xff, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001678 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001679 if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001680 priv->port, 0, MLX4_PROT_ETH,
1681 &priv->broadcast_id))
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001682 mlx4_warn(mdev, "Failed Attaching Broadcast\n");
1683
Herbert Xub5845f92011-03-27 01:01:26 +00001684 /* Must redo promiscuous mode setup. */
1685 priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC);
1686
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001687 /* Schedule multicast task to populate multicast list */
Yan Burman0eb74fd2013-02-07 02:25:23 +00001688 queue_work(mdev->workqueue, &priv->rx_mode_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001689
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +00001690 mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap);
1691
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001692 priv->port_up = true;
Yevgeny Petrilina11faac2009-06-20 22:15:46 +00001693 netif_tx_start_all_queues(dev);
Amir Vadai3484aac2013-01-30 23:07:11 +00001694 netif_device_attach(dev);
1695
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001696 return 0;
1697
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001698tx_err:
1699 while (tx_index--) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001700 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[tx_index]);
1701 mlx4_en_deactivate_cq(priv, priv->tx_cq[tx_index]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001702 }
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001703 mlx4_en_destroy_drop_qp(priv);
1704rss_err:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001705 mlx4_en_release_rss_steer(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001706mac_err:
Yan Burman16a10ff2013-02-07 02:25:22 +00001707 mlx4_en_put_qp(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001708cq_err:
1709 while (rx_index--)
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001710 mlx4_en_deactivate_cq(priv, priv->rx_cq[rx_index]);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001711 for (i = 0; i < priv->rx_ring_num; i++)
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001712 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001713
1714 return err; /* need to close devices */
1715}
1716
1717
Amir Vadai3484aac2013-01-30 23:07:11 +00001718void mlx4_en_stop_port(struct net_device *dev, int detach)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001719{
1720 struct mlx4_en_priv *priv = netdev_priv(dev);
1721 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001722 struct mlx4_en_mc_list *mclist, *tmp;
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001723 struct ethtool_flow_id *flow, *tmp_flow;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001724 int i;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001725 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001726
1727 if (!priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001728 en_dbg(DRV, priv, "stop port called while port already down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001729 return;
1730 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001731
Eugenia Emantayev0cc5c8b2013-06-25 12:09:33 +03001732 /* close port*/
1733 mlx4_CLOSE_PORT(mdev->dev, priv->port);
1734
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001735 /* Synchronize with tx routine */
1736 netif_tx_lock_bh(dev);
Amir Vadai3484aac2013-01-30 23:07:11 +00001737 if (detach)
1738 netif_device_detach(dev);
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001739 netif_tx_stop_all_queues(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001740 netif_tx_unlock_bh(dev);
1741
Amir Vadai3484aac2013-01-30 23:07:11 +00001742 netif_tx_disable(dev);
1743
Yevgeny Petrilin7c287382010-08-24 03:45:45 +00001744 /* Set port as not active */
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001745 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001746
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001747 /* Promsicuous mode */
1748 if (mdev->dev->caps.steering_mode ==
1749 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1750 priv->flags &= ~(MLX4_EN_FLAG_PROMISC |
1751 MLX4_EN_FLAG_MC_PROMISC);
1752 mlx4_flow_steer_promisc_remove(mdev->dev,
1753 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001754 MLX4_FS_ALL_DEFAULT);
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001755 mlx4_flow_steer_promisc_remove(mdev->dev,
1756 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001757 MLX4_FS_MC_DEFAULT);
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001758 } else if (priv->flags & MLX4_EN_FLAG_PROMISC) {
1759 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
1760
1761 /* Disable promiscouos mode */
1762 mlx4_unicast_promisc_remove(mdev->dev, priv->base_qpn,
1763 priv->port);
1764
1765 /* Disable Multicast promisc */
1766 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
1767 mlx4_multicast_promisc_remove(mdev->dev, priv->base_qpn,
1768 priv->port);
1769 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
1770 }
1771 }
1772
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001773 /* Detach All multicasts */
1774 memset(&mc_list[10], 0xff, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001775 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001776 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001777 MLX4_PROT_ETH, priv->broadcast_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001778 list_for_each_entry(mclist, &priv->curr_list, list) {
1779 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001780 mc_list[5] = priv->port;
1781 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001782 mc_list, MLX4_PROT_ETH, mclist->reg_id);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001783 }
1784 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001785 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
1786 list_del(&mclist->list);
1787 kfree(mclist);
1788 }
1789
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001790 /* Flush multicast filter */
1791 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG);
1792
Hadar Hen Zion6efb5fa2013-03-21 05:55:53 +00001793 /* Remove flow steering rules for the port*/
1794 if (mdev->dev->caps.steering_mode ==
1795 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1796 ASSERT_RTNL();
1797 list_for_each_entry_safe(flow, tmp_flow,
1798 &priv->ethtool_list, list) {
1799 mlx4_flow_detach(mdev->dev, flow->id);
1800 list_del(&flow->list);
1801 }
1802 }
1803
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001804 mlx4_en_destroy_drop_qp(priv);
1805
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001806 /* Free TX Rings */
1807 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001808 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[i]);
1809 mlx4_en_deactivate_cq(priv, priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001810 }
1811 msleep(10);
1812
1813 for (i = 0; i < priv->tx_ring_num; i++)
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001814 mlx4_en_free_tx_buf(dev, priv->tx_ring[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001815
1816 /* Free RSS qps */
1817 mlx4_en_release_rss_steer(priv);
1818
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001819 /* Unregister Mac address for the port */
Yan Burman16a10ff2013-02-07 02:25:22 +00001820 mlx4_en_put_qp(priv);
Or Gerlitz5930e8d2013-10-15 16:55:22 +02001821 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN))
Matan Barak955154f2013-01-30 23:07:10 +00001822 mdev->mac_removed[priv->port] = 1;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001823
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001824 /* Free RX Rings */
1825 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001826 struct mlx4_en_cq *cq = priv->rx_cq[i];
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001827
1828 local_bh_disable();
1829 while (!mlx4_en_cq_lock_napi(cq)) {
1830 pr_info("CQ %d locked\n", i);
1831 mdelay(1);
1832 }
1833 local_bh_enable();
1834
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001835 while (test_bit(NAPI_STATE_SCHED, &cq->napi.state))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001836 msleep(1);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001837 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]);
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001838 mlx4_en_deactivate_cq(priv, cq);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001839 }
1840}
1841
1842static void mlx4_en_restart(struct work_struct *work)
1843{
1844 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1845 watchdog_task);
1846 struct mlx4_en_dev *mdev = priv->mdev;
1847 struct net_device *dev = priv->dev;
1848
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001849 en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001850
1851 mutex_lock(&mdev->state_lock);
1852 if (priv->port_up) {
Amir Vadai3484aac2013-01-30 23:07:11 +00001853 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001854 if (mlx4_en_start_port(dev))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001855 en_err(priv, "Failed restarting port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001856 }
1857 mutex_unlock(&mdev->state_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001858}
1859
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001860static void mlx4_en_clear_stats(struct net_device *dev)
1861{
1862 struct mlx4_en_priv *priv = netdev_priv(dev);
1863 struct mlx4_en_dev *mdev = priv->mdev;
1864 int i;
1865
1866 if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1))
1867 en_dbg(HW, priv, "Failed dumping statistics\n");
1868
1869 memset(&priv->stats, 0, sizeof(priv->stats));
1870 memset(&priv->pstats, 0, sizeof(priv->pstats));
1871 memset(&priv->pkstats, 0, sizeof(priv->pkstats));
1872 memset(&priv->port_stats, 0, sizeof(priv->port_stats));
1873
1874 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001875 priv->tx_ring[i]->bytes = 0;
1876 priv->tx_ring[i]->packets = 0;
1877 priv->tx_ring[i]->tx_csum = 0;
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001878 }
1879 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001880 priv->rx_ring[i]->bytes = 0;
1881 priv->rx_ring[i]->packets = 0;
1882 priv->rx_ring[i]->csum_ok = 0;
1883 priv->rx_ring[i]->csum_none = 0;
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001884 }
1885}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001886
1887static int mlx4_en_open(struct net_device *dev)
1888{
1889 struct mlx4_en_priv *priv = netdev_priv(dev);
1890 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001891 int err = 0;
1892
1893 mutex_lock(&mdev->state_lock);
1894
1895 if (!mdev->device_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001896 en_err(priv, "Cannot open - device down/disabled\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001897 err = -EBUSY;
1898 goto out;
1899 }
1900
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001901 /* Reset HW statistics and SW counters */
1902 mlx4_en_clear_stats(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001903
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001904 err = mlx4_en_start_port(dev);
1905 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001906 en_err(priv, "Failed starting port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001907
1908out:
1909 mutex_unlock(&mdev->state_lock);
1910 return err;
1911}
1912
1913
1914static int mlx4_en_close(struct net_device *dev)
1915{
1916 struct mlx4_en_priv *priv = netdev_priv(dev);
1917 struct mlx4_en_dev *mdev = priv->mdev;
1918
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001919 en_dbg(IFDOWN, priv, "Close port called\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001920
1921 mutex_lock(&mdev->state_lock);
1922
Amir Vadai3484aac2013-01-30 23:07:11 +00001923 mlx4_en_stop_port(dev, 0);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001924 netif_carrier_off(dev);
1925
1926 mutex_unlock(&mdev->state_lock);
1927 return 0;
1928}
1929
Alexander Gullerfe0af032011-10-09 05:26:46 +00001930void mlx4_en_free_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001931{
1932 int i;
1933
Amir Vadai1eb8c692012-07-18 22:33:52 +00001934#ifdef CONFIG_RFS_ACCEL
1935 free_irq_cpu_rmap(priv->dev->rx_cpu_rmap);
1936 priv->dev->rx_cpu_rmap = NULL;
1937#endif
1938
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001939 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001940 if (priv->tx_ring && priv->tx_ring[i])
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001941 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001942 if (priv->tx_cq && priv->tx_cq[i])
Alexander Gullerfe0af032011-10-09 05:26:46 +00001943 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001944 }
1945
1946 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001947 if (priv->rx_ring[i])
Thadeu Lima de Souza Cascardo68355f72012-02-06 08:39:49 +00001948 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
1949 priv->prof->rx_ring_size, priv->stride);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001950 if (priv->rx_cq[i])
Alexander Gullerfe0af032011-10-09 05:26:46 +00001951 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001952 }
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001953
1954 if (priv->base_tx_qpn) {
1955 mlx4_qp_release_range(priv->mdev->dev, priv->base_tx_qpn, priv->tx_ring_num);
1956 priv->base_tx_qpn = 0;
1957 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001958}
1959
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001960int mlx4_en_alloc_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001961{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001962 struct mlx4_en_port_profile *prof = priv->prof;
1963 int i;
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001964 int err;
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001965 int node;
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001966
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001967 err = mlx4_qp_reserve_range(priv->mdev->dev, priv->tx_ring_num, 256, &priv->base_tx_qpn);
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001968 if (err) {
1969 en_err(priv, "failed reserving range for TX rings\n");
1970 return err;
1971 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001972
1973 /* Create tx Rings */
1974 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001975 node = cpu_to_node(i % num_online_cpus());
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001976 if (mlx4_en_create_cq(priv, &priv->tx_cq[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001977 prof->tx_ring_size, i, TX, node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001978 goto err;
1979
Ido Shamayd03a68f2013-12-19 21:20:14 +02001980 if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i],
1981 priv->base_tx_qpn + i,
1982 prof->tx_ring_size, TXBB_SIZE,
1983 node, i))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001984 goto err;
1985 }
1986
1987 /* Create rx Rings */
1988 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001989 node = cpu_to_node(i % num_online_cpus());
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001990 if (mlx4_en_create_cq(priv, &priv->rx_cq[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001991 prof->rx_ring_size, i, RX, node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001992 goto err;
1993
1994 if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001995 prof->rx_ring_size, priv->stride,
1996 node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001997 goto err;
1998 }
1999
Amir Vadai1eb8c692012-07-18 22:33:52 +00002000#ifdef CONFIG_RFS_ACCEL
Amir Vadaia229e482013-03-07 03:46:57 +00002001 if (priv->mdev->dev->caps.comp_pool) {
2002 priv->dev->rx_cpu_rmap = alloc_irq_cpu_rmap(priv->mdev->dev->caps.comp_pool);
2003 if (!priv->dev->rx_cpu_rmap)
2004 goto err;
2005 }
Amir Vadai1eb8c692012-07-18 22:33:52 +00002006#endif
2007
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002008 return 0;
2009
2010err:
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002011 en_err(priv, "Failed to allocate NIC resources\n");
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002012 for (i = 0; i < priv->rx_ring_num; i++) {
2013 if (priv->rx_ring[i])
2014 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
2015 prof->rx_ring_size,
2016 priv->stride);
2017 if (priv->rx_cq[i])
2018 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
2019 }
2020 for (i = 0; i < priv->tx_ring_num; i++) {
2021 if (priv->tx_ring[i])
2022 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
2023 if (priv->tx_cq[i])
2024 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
2025 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002026 return -ENOMEM;
2027}
2028
2029
2030void mlx4_en_destroy_netdev(struct net_device *dev)
2031{
2032 struct mlx4_en_priv *priv = netdev_priv(dev);
2033 struct mlx4_en_dev *mdev = priv->mdev;
2034
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002035 en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002036
2037 /* Unregister device - this will close the port if it was up */
2038 if (priv->registered)
2039 unregister_netdev(dev);
2040
2041 if (priv->allocated)
2042 mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE);
2043
2044 cancel_delayed_work(&priv->stats_task);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00002045 cancel_delayed_work(&priv->service_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002046 /* flush any pending task for this netdev */
2047 flush_workqueue(mdev->workqueue);
2048
2049 /* Detach the netdev so tasks would not attempt to access it */
2050 mutex_lock(&mdev->state_lock);
2051 mdev->pndev[priv->port] = NULL;
2052 mutex_unlock(&mdev->state_lock);
2053
Alexander Gullerfe0af032011-10-09 05:26:46 +00002054 mlx4_en_free_resources(priv);
Amir Vadai564c2742012-04-04 21:33:26 +00002055
Amir Vadaibc6a4742012-05-17 00:58:10 +00002056 kfree(priv->tx_ring);
2057 kfree(priv->tx_cq);
2058
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002059 free_netdev(dev);
2060}
2061
2062static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
2063{
2064 struct mlx4_en_priv *priv = netdev_priv(dev);
2065 struct mlx4_en_dev *mdev = priv->mdev;
2066 int err = 0;
2067
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002068 en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002069 dev->mtu, new_mtu);
2070
2071 if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002072 en_err(priv, "Bad MTU size:%d.\n", new_mtu);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002073 return -EPERM;
2074 }
2075 dev->mtu = new_mtu;
2076
2077 if (netif_running(dev)) {
2078 mutex_lock(&mdev->state_lock);
2079 if (!mdev->device_up) {
2080 /* NIC is probably restarting - let watchdog task reset
2081 * the port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002082 en_dbg(DRV, priv, "Change MTU called with card down!?\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002083 } else {
Amir Vadai3484aac2013-01-30 23:07:11 +00002084 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002085 err = mlx4_en_start_port(dev);
2086 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002087 en_err(priv, "Failed restarting port:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002088 priv->port);
2089 queue_work(mdev->workqueue, &priv->watchdog_task);
2090 }
2091 }
2092 mutex_unlock(&mdev->state_lock);
2093 }
2094 return 0;
2095}
2096
Ben Hutchings100dbda2013-11-18 23:13:31 +00002097static int mlx4_en_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
Amir Vadaiec693d42013-04-23 06:06:49 +00002098{
2099 struct mlx4_en_priv *priv = netdev_priv(dev);
2100 struct mlx4_en_dev *mdev = priv->mdev;
2101 struct hwtstamp_config config;
2102
2103 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
2104 return -EFAULT;
2105
2106 /* reserved for future extensions */
2107 if (config.flags)
2108 return -EINVAL;
2109
2110 /* device doesn't support time stamping */
2111 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS))
2112 return -EINVAL;
2113
2114 /* TX HW timestamp */
2115 switch (config.tx_type) {
2116 case HWTSTAMP_TX_OFF:
2117 case HWTSTAMP_TX_ON:
2118 break;
2119 default:
2120 return -ERANGE;
2121 }
2122
2123 /* RX HW timestamp */
2124 switch (config.rx_filter) {
2125 case HWTSTAMP_FILTER_NONE:
2126 break;
2127 case HWTSTAMP_FILTER_ALL:
2128 case HWTSTAMP_FILTER_SOME:
2129 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2130 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2131 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2132 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2133 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2134 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2135 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2136 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
2137 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
2138 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2139 case HWTSTAMP_FILTER_PTP_V2_SYNC:
2140 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
2141 config.rx_filter = HWTSTAMP_FILTER_ALL;
2142 break;
2143 default:
2144 return -ERANGE;
2145 }
2146
2147 if (mlx4_en_timestamp_config(dev, config.tx_type, config.rx_filter)) {
2148 config.tx_type = HWTSTAMP_TX_OFF;
2149 config.rx_filter = HWTSTAMP_FILTER_NONE;
2150 }
2151
2152 return copy_to_user(ifr->ifr_data, &config,
2153 sizeof(config)) ? -EFAULT : 0;
2154}
2155
Ben Hutchings100dbda2013-11-18 23:13:31 +00002156static int mlx4_en_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
2157{
2158 struct mlx4_en_priv *priv = netdev_priv(dev);
2159
2160 return copy_to_user(ifr->ifr_data, &priv->hwtstamp_config,
2161 sizeof(priv->hwtstamp_config)) ? -EFAULT : 0;
2162}
2163
Amir Vadaiec693d42013-04-23 06:06:49 +00002164static int mlx4_en_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2165{
2166 switch (cmd) {
2167 case SIOCSHWTSTAMP:
Ben Hutchings100dbda2013-11-18 23:13:31 +00002168 return mlx4_en_hwtstamp_set(dev, ifr);
2169 case SIOCGHWTSTAMP:
2170 return mlx4_en_hwtstamp_get(dev, ifr);
Amir Vadaiec693d42013-04-23 06:06:49 +00002171 default:
2172 return -EOPNOTSUPP;
2173 }
2174}
2175
Amir Vadai60d6fe92011-11-26 19:55:19 +00002176static int mlx4_en_set_features(struct net_device *netdev,
2177 netdev_features_t features)
2178{
2179 struct mlx4_en_priv *priv = netdev_priv(netdev);
2180
2181 if (features & NETIF_F_LOOPBACK)
2182 priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
2183 else
2184 priv->ctrl_flags &=
2185 cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK);
2186
Yan Burman79aeacc2013-02-07 02:25:19 +00002187 mlx4_en_update_loopback_state(netdev, features);
2188
Amir Vadai60d6fe92011-11-26 19:55:19 +00002189 return 0;
2190
2191}
2192
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002193static int mlx4_en_set_vf_mac(struct net_device *dev, int queue, u8 *mac)
2194{
2195 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2196 struct mlx4_en_dev *mdev = en_priv->mdev;
Eugenia Emantayev98133372014-03-02 10:25:01 +02002197 u64 mac_u64 = mlx4_mac_to_u64(mac);
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002198
2199 if (!is_valid_ether_addr(mac))
2200 return -EINVAL;
2201
2202 return mlx4_set_vf_mac(mdev->dev, en_priv->port, queue, mac_u64);
2203}
2204
Rony Efraim3f7fb022013-04-25 05:22:28 +00002205static int mlx4_en_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos)
2206{
2207 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2208 struct mlx4_en_dev *mdev = en_priv->mdev;
2209
2210 return mlx4_set_vf_vlan(mdev->dev, en_priv->port, vf, vlan, qos);
2211}
2212
Rony Efraime6b6a232013-04-25 05:22:29 +00002213static int mlx4_en_set_vf_spoofchk(struct net_device *dev, int vf, bool setting)
2214{
2215 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2216 struct mlx4_en_dev *mdev = en_priv->mdev;
2217
2218 return mlx4_set_vf_spoofchk(mdev->dev, en_priv->port, vf, setting);
2219}
2220
Rony Efraim2cccb9e2013-04-25 05:22:30 +00002221static int mlx4_en_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_info *ivf)
2222{
2223 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2224 struct mlx4_en_dev *mdev = en_priv->mdev;
2225
2226 return mlx4_get_vf_config(mdev->dev, en_priv->port, vf, ivf);
2227}
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002228
Rony Efraim948e3062013-06-13 13:19:11 +03002229static int mlx4_en_set_vf_link_state(struct net_device *dev, int vf, int link_state)
2230{
2231 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2232 struct mlx4_en_dev *mdev = en_priv->mdev;
2233
2234 return mlx4_set_vf_link_state(mdev->dev, en_priv->port, vf, link_state);
2235}
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002236
2237#define PORT_ID_BYTE_LEN 8
2238static int mlx4_en_get_phys_port_id(struct net_device *dev,
2239 struct netdev_phys_port_id *ppid)
2240{
2241 struct mlx4_en_priv *priv = netdev_priv(dev);
2242 struct mlx4_dev *mdev = priv->mdev->dev;
2243 int i;
2244 u64 phys_port_id = mdev->caps.phys_port_id[priv->port];
2245
2246 if (!phys_port_id)
2247 return -EOPNOTSUPP;
2248
2249 ppid->id_len = sizeof(phys_port_id);
2250 for (i = PORT_ID_BYTE_LEN - 1; i >= 0; --i) {
2251 ppid->id[i] = phys_port_id & 0xff;
2252 phys_port_id >>= 8;
2253 }
2254 return 0;
2255}
2256
Stephen Hemminger3addc562008-11-21 17:30:58 -08002257static const struct net_device_ops mlx4_netdev_ops = {
2258 .ndo_open = mlx4_en_open,
2259 .ndo_stop = mlx4_en_close,
2260 .ndo_start_xmit = mlx4_en_xmit,
Yevgeny Petrilinf813cad2009-06-01 23:24:07 +00002261 .ndo_select_queue = mlx4_en_select_queue,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002262 .ndo_get_stats = mlx4_en_get_stats,
Yan Burman0eb74fd2013-02-07 02:25:23 +00002263 .ndo_set_rx_mode = mlx4_en_set_rx_mode,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002264 .ndo_set_mac_address = mlx4_en_set_mac,
Stephen Hemminger52255bb2009-01-09 10:45:37 +00002265 .ndo_validate_addr = eth_validate_addr,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002266 .ndo_change_mtu = mlx4_en_change_mtu,
Amir Vadaiec693d42013-04-23 06:06:49 +00002267 .ndo_do_ioctl = mlx4_en_ioctl,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002268 .ndo_tx_timeout = mlx4_en_tx_timeout,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002269 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
2270 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
2271#ifdef CONFIG_NET_POLL_CONTROLLER
2272 .ndo_poll_controller = mlx4_en_netpoll,
2273#endif
Amir Vadai60d6fe92011-11-26 19:55:19 +00002274 .ndo_set_features = mlx4_en_set_features,
Amir Vadai897d7842012-04-04 21:33:27 +00002275 .ndo_setup_tc = mlx4_en_setup_tc,
Amir Vadai1eb8c692012-07-18 22:33:52 +00002276#ifdef CONFIG_RFS_ACCEL
2277 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2278#endif
Cong Wange0d10952013-08-01 11:10:25 +08002279#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03002280 .ndo_busy_poll = mlx4_en_low_latency_recv,
Amir Vadai9e77a2b2013-06-18 16:18:27 +03002281#endif
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002282 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002283};
2284
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002285static const struct net_device_ops mlx4_netdev_ops_master = {
2286 .ndo_open = mlx4_en_open,
2287 .ndo_stop = mlx4_en_close,
2288 .ndo_start_xmit = mlx4_en_xmit,
2289 .ndo_select_queue = mlx4_en_select_queue,
2290 .ndo_get_stats = mlx4_en_get_stats,
2291 .ndo_set_rx_mode = mlx4_en_set_rx_mode,
2292 .ndo_set_mac_address = mlx4_en_set_mac,
2293 .ndo_validate_addr = eth_validate_addr,
2294 .ndo_change_mtu = mlx4_en_change_mtu,
2295 .ndo_tx_timeout = mlx4_en_tx_timeout,
2296 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
2297 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
2298 .ndo_set_vf_mac = mlx4_en_set_vf_mac,
Rony Efraim3f7fb022013-04-25 05:22:28 +00002299 .ndo_set_vf_vlan = mlx4_en_set_vf_vlan,
Rony Efraime6b6a232013-04-25 05:22:29 +00002300 .ndo_set_vf_spoofchk = mlx4_en_set_vf_spoofchk,
Rony Efraim948e3062013-06-13 13:19:11 +03002301 .ndo_set_vf_link_state = mlx4_en_set_vf_link_state,
Rony Efraim2cccb9e2013-04-25 05:22:30 +00002302 .ndo_get_vf_config = mlx4_en_get_vf_config,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002303#ifdef CONFIG_NET_POLL_CONTROLLER
2304 .ndo_poll_controller = mlx4_en_netpoll,
2305#endif
2306 .ndo_set_features = mlx4_en_set_features,
2307 .ndo_setup_tc = mlx4_en_setup_tc,
2308#ifdef CONFIG_RFS_ACCEL
2309 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2310#endif
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002311 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002312};
2313
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002314int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
2315 struct mlx4_en_port_profile *prof)
2316{
2317 struct net_device *dev;
2318 struct mlx4_en_priv *priv;
Yan Burmanc07cb4b2013-02-07 02:25:25 +00002319 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002320 int err;
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002321 u64 mac_u64;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002322
Tom Herbertf1593d22011-01-09 19:36:36 +00002323 dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv),
Amir Vadaid3179662012-12-02 03:49:23 +00002324 MAX_TX_RINGS, MAX_RX_RINGS);
Joe Perches41de8d42012-01-29 13:47:52 +00002325 if (dev == NULL)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002326 return -ENOMEM;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002327
Amir Vadaid3179662012-12-02 03:49:23 +00002328 netif_set_real_num_tx_queues(dev, prof->tx_ring_num);
2329 netif_set_real_num_rx_queues(dev, prof->rx_ring_num);
2330
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002331 SET_NETDEV_DEV(dev, &mdev->dev->pdev->dev);
Amir Vadai76a066f2014-02-25 18:17:51 +02002332 dev->dev_port = port - 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002333
2334 /*
2335 * Initialize driver private data
2336 */
2337
2338 priv = netdev_priv(dev);
2339 memset(priv, 0, sizeof(struct mlx4_en_priv));
2340 priv->dev = dev;
2341 priv->mdev = mdev;
Yevgeny Petrilinebf8c9a2012-03-06 04:03:34 +00002342 priv->ddev = &mdev->pdev->dev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002343 priv->prof = prof;
2344 priv->port = port;
2345 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002346 priv->flags = prof->flags;
Amir Vadai60d6fe92011-11-26 19:55:19 +00002347 priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE |
2348 MLX4_WQE_CTRL_SOLICITED);
Amir Vadaid3179662012-12-02 03:49:23 +00002349 priv->num_tx_rings_p_up = mdev->profile.num_tx_rings_p_up;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002350 priv->tx_ring_num = prof->tx_ring_num;
Amir Vadaid3179662012-12-02 03:49:23 +00002351
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002352 priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring *) * MAX_TX_RINGS,
Amir Vadaid3179662012-12-02 03:49:23 +00002353 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00002354 if (!priv->tx_ring) {
2355 err = -ENOMEM;
2356 goto out;
2357 }
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002358 priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq *) * MAX_TX_RINGS,
Amir Vadaid3179662012-12-02 03:49:23 +00002359 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00002360 if (!priv->tx_cq) {
2361 err = -ENOMEM;
2362 goto out;
2363 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002364 priv->rx_ring_num = prof->rx_ring_num;
Or Gerlitz08ff3232012-10-21 14:59:24 +00002365 priv->cqe_factor = (mdev->dev->caps.cqe_size == 64) ? 1 : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002366 priv->mac_index = -1;
2367 priv->msg_enable = MLX4_EN_MSG_LEVEL;
2368 spin_lock_init(&priv->stats_lock);
Yan Burman0eb74fd2013-02-07 02:25:23 +00002369 INIT_WORK(&priv->rx_mode_task, mlx4_en_do_set_rx_mode);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002370 INIT_WORK(&priv->watchdog_task, mlx4_en_restart);
2371 INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate);
2372 INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00002373 INIT_DELAYED_WORK(&priv->service_task, mlx4_en_service_task);
Amir Vadai564c2742012-04-04 21:33:26 +00002374#ifdef CONFIG_MLX4_EN_DCB
Or Gerlitz540b3a32013-04-07 03:44:07 +00002375 if (!mlx4_is_slave(priv->mdev->dev)) {
2376 if (mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_SET_ETH_SCHED) {
2377 dev->dcbnl_ops = &mlx4_en_dcbnl_ops;
2378 } else {
2379 en_info(priv, "enabling only PFC DCB ops\n");
2380 dev->dcbnl_ops = &mlx4_en_dcbnl_pfc_ops;
2381 }
2382 }
Amir Vadai564c2742012-04-04 21:33:26 +00002383#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002384
Yan Burmanc07cb4b2013-02-07 02:25:25 +00002385 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i)
2386 INIT_HLIST_HEAD(&priv->mac_hash[i]);
Yan Burman16a10ff2013-02-07 02:25:22 +00002387
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002388 /* Query for default mac and max mtu */
2389 priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port];
Yan Burman6bbb6d92013-02-07 02:25:20 +00002390
2391 /* Set default MAC */
2392 dev->addr_len = ETH_ALEN;
2393 mlx4_en_u64_to_mac(dev->dev_addr, mdev->dev->caps.def_mac[priv->port]);
2394 if (!is_valid_ether_addr(dev->dev_addr)) {
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002395 if (mlx4_is_slave(priv->mdev->dev)) {
2396 eth_hw_addr_random(dev);
2397 en_warn(priv, "Assigned random MAC address %pM\n", dev->dev_addr);
Eugenia Emantayev98133372014-03-02 10:25:01 +02002398 mac_u64 = mlx4_mac_to_u64(dev->dev_addr);
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002399 mdev->dev->caps.def_mac[priv->port] = mac_u64;
2400 } else {
2401 en_err(priv, "Port: %d, invalid mac burned: %pM, quiting\n",
2402 priv->port, dev->dev_addr);
2403 err = -EINVAL;
2404 goto out;
2405 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002406 }
2407
Yan Burman6bbb6d92013-02-07 02:25:20 +00002408 memcpy(priv->prev_mac, dev->dev_addr, sizeof(priv->prev_mac));
2409
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002410 priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
2411 DS_SIZE * MLX4_EN_MAX_RX_FRAGS);
2412 err = mlx4_en_alloc_resources(priv);
2413 if (err)
2414 goto out;
2415
Amir Vadai78fb2de2013-01-24 01:54:19 +00002416#ifdef CONFIG_RFS_ACCEL
2417 INIT_LIST_HEAD(&priv->filters);
2418 spin_lock_init(&priv->filters_lock);
2419#endif
2420
Amir Vadaiec693d42013-04-23 06:06:49 +00002421 /* Initialize time stamping config */
2422 priv->hwtstamp_config.flags = 0;
2423 priv->hwtstamp_config.tx_type = HWTSTAMP_TX_OFF;
2424 priv->hwtstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
2425
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002426 /* Allocate page for receive rings */
2427 err = mlx4_alloc_hwq_res(mdev->dev, &priv->res,
2428 MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE);
2429 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002430 en_err(priv, "Failed to allocate page for rx qps\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002431 goto out;
2432 }
2433 priv->allocated = 1;
2434
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002435 /*
2436 * Initialize netdev entry points
2437 */
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002438 if (mlx4_is_master(priv->mdev->dev))
2439 dev->netdev_ops = &mlx4_netdev_ops_master;
2440 else
2441 dev->netdev_ops = &mlx4_netdev_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002442 dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT;
Ben Hutchings1eb63a22010-09-27 08:29:34 +00002443 netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
2444 netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
Stephen Hemminger3addc562008-11-21 17:30:58 -08002445
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002446 SET_ETHTOOL_OPS(dev, &mlx4_en_ethtool_ops);
2447
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002448 /*
2449 * Set driver features
2450 */
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00002451 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
2452 if (mdev->LSO_support)
2453 dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
2454
2455 dev->vlan_features = dev->hw_features;
2456
Yevgeny Petrilinad861072011-10-18 01:51:24 +00002457 dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH;
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00002458 dev->features = dev->hw_features | NETIF_F_HIGHDMA |
Patrick McHardyf6469682013-04-19 02:04:27 +00002459 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
2460 NETIF_F_HW_VLAN_CTAG_FILTER;
Amir Vadai60d6fe92011-11-26 19:55:19 +00002461 dev->hw_features |= NETIF_F_LOOPBACK;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002462
Amir Vadai1eb8c692012-07-18 22:33:52 +00002463 if (mdev->dev->caps.steering_mode ==
2464 MLX4_STEERING_MODE_DEVICE_MANAGED)
2465 dev->hw_features |= NETIF_F_NTUPLE;
2466
Yan Burmancc5387f2013-02-07 02:25:26 +00002467 if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_A0)
2468 dev->priv_flags |= IFF_UNICAST_FLT;
2469
Or Gerlitz837052d2013-12-23 16:09:44 +02002470 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
2471 dev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2472 NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL;
2473 dev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
2474 dev->features |= NETIF_F_GSO_UDP_TUNNEL;
2475 }
2476
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002477 mdev->pndev[port] = dev;
2478
2479 netif_carrier_off(dev);
Eugenia Emantayev4801ae72013-06-25 12:09:31 +03002480 mlx4_en_set_default_moderation(priv);
2481
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002482 err = register_netdev(dev);
2483 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002484 en_err(priv, "Netdev registration failed for port %d\n", port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002485 goto out;
2486 }
Alexander Guller42341442011-10-09 05:29:35 +00002487 priv->registered = 1;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002488
2489 en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num);
2490 en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num);
2491
Yan Burman79aeacc2013-02-07 02:25:19 +00002492 mlx4_en_update_loopback_state(priv->dev, priv->dev->features);
2493
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002494 /* Configure port */
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00002495 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002496 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00002497 priv->rx_skb_size + ETH_FCS_LEN,
2498 prof->tx_pause, prof->tx_ppp,
2499 prof->rx_pause, prof->rx_ppp);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002500 if (err) {
2501 en_err(priv, "Failed setting port general configurations "
2502 "for port %d, with error %d\n", priv->port, err);
2503 goto out;
2504 }
2505
Or Gerlitz837052d2013-12-23 16:09:44 +02002506 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
2507 err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC);
2508 if (err) {
2509 en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n",
2510 err);
2511 goto out;
2512 }
2513 }
2514
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002515 /* Init port */
2516 en_warn(priv, "Initializing port\n");
2517 err = mlx4_INIT_PORT(mdev->dev, priv->port);
2518 if (err) {
2519 en_err(priv, "Failed Initializing port\n");
2520 goto out;
2521 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002522 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
Amir Vadaidc8142e2013-04-25 05:22:24 +00002523
2524 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
2525 queue_delayed_work(mdev->workqueue, &priv->service_task,
2526 SERVICE_TASK_DELAY);
2527
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002528 return 0;
2529
2530out:
2531 mlx4_en_destroy_netdev(dev);
2532 return err;
2533}
2534