blob: 79c6f467d17e80a450a01992e43f6383fe80df85 [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>
Or Gerlitz1b136de2014-03-27 14:02:04 +020042#include <net/vxlan.h>
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070043
44#include <linux/mlx4/driver.h>
45#include <linux/mlx4/device.h>
46#include <linux/mlx4/cmd.h>
47#include <linux/mlx4/cq.h>
48
49#include "mlx4_en.h"
50#include "en_port.h"
51
Amir Vadaid3179662012-12-02 03:49:23 +000052int mlx4_en_setup_tc(struct net_device *dev, u8 up)
Amir Vadai897d7842012-04-04 21:33:27 +000053{
Amir Vadaibc6a4742012-05-17 00:58:10 +000054 struct mlx4_en_priv *priv = netdev_priv(dev);
55 int i;
Amir Vadaid3179662012-12-02 03:49:23 +000056 unsigned int offset = 0;
Amir Vadaibc6a4742012-05-17 00:58:10 +000057
58 if (up && up != MLX4_EN_NUM_UP)
Amir Vadai897d7842012-04-04 21:33:27 +000059 return -EINVAL;
60
Amir Vadaibc6a4742012-05-17 00:58:10 +000061 netdev_set_num_tc(dev, up);
62
63 /* Partition Tx queues evenly amongst UP's */
Amir Vadaibc6a4742012-05-17 00:58:10 +000064 for (i = 0; i < up; i++) {
Amir Vadaid3179662012-12-02 03:49:23 +000065 netdev_set_tc_queue(dev, i, priv->num_tx_rings_p_up, offset);
66 offset += priv->num_tx_rings_p_up;
Amir Vadaibc6a4742012-05-17 00:58:10 +000067 }
68
Amir Vadai897d7842012-04-04 21:33:27 +000069 return 0;
70}
71
Cong Wange0d10952013-08-01 11:10:25 +080072#ifdef CONFIG_NET_RX_BUSY_POLL
Amir Vadai9e77a2b2013-06-18 16:18:27 +030073/* must be called with local_bh_disable()d */
74static int mlx4_en_low_latency_recv(struct napi_struct *napi)
75{
76 struct mlx4_en_cq *cq = container_of(napi, struct mlx4_en_cq, napi);
77 struct net_device *dev = cq->dev;
78 struct mlx4_en_priv *priv = netdev_priv(dev);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +020079 struct mlx4_en_rx_ring *rx_ring = priv->rx_ring[cq->ring];
Amir Vadai9e77a2b2013-06-18 16:18:27 +030080 int done;
81
82 if (!priv->port_up)
83 return LL_FLUSH_FAILED;
84
85 if (!mlx4_en_cq_lock_poll(cq))
86 return LL_FLUSH_BUSY;
87
88 done = mlx4_en_process_rx_cq(dev, cq, 4);
Amir Vadai85018412013-06-18 16:18:28 +030089 if (likely(done))
90 rx_ring->cleaned += done;
91 else
92 rx_ring->misses++;
Amir Vadai9e77a2b2013-06-18 16:18:27 +030093
94 mlx4_en_cq_unlock_poll(cq);
95
96 return done;
97}
Cong Wange0d10952013-08-01 11:10:25 +080098#endif /* CONFIG_NET_RX_BUSY_POLL */
Amir Vadai9e77a2b2013-06-18 16:18:27 +030099
Amir Vadai1eb8c692012-07-18 22:33:52 +0000100#ifdef CONFIG_RFS_ACCEL
101
102struct mlx4_en_filter {
103 struct list_head next;
104 struct work_struct work;
105
Eyal Perry75a353d2013-11-07 12:19:49 +0200106 u8 ip_proto;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000107 __be32 src_ip;
108 __be32 dst_ip;
109 __be16 src_port;
110 __be16 dst_port;
111
112 int rxq_index;
113 struct mlx4_en_priv *priv;
114 u32 flow_id; /* RFS infrastructure id */
115 int id; /* mlx4_en driver id */
116 u64 reg_id; /* Flow steering API id */
117 u8 activated; /* Used to prevent expiry before filter
118 * is attached
119 */
120 struct hlist_node filter_chain;
121};
122
123static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv);
124
Eyal Perry75a353d2013-11-07 12:19:49 +0200125static enum mlx4_net_trans_rule_id mlx4_ip_proto_to_trans_rule_id(u8 ip_proto)
126{
127 switch (ip_proto) {
128 case IPPROTO_UDP:
129 return MLX4_NET_TRANS_RULE_ID_UDP;
130 case IPPROTO_TCP:
131 return MLX4_NET_TRANS_RULE_ID_TCP;
132 default:
133 return -EPROTONOSUPPORT;
134 }
135};
136
Amir Vadai1eb8c692012-07-18 22:33:52 +0000137static void mlx4_en_filter_work(struct work_struct *work)
138{
139 struct mlx4_en_filter *filter = container_of(work,
140 struct mlx4_en_filter,
141 work);
142 struct mlx4_en_priv *priv = filter->priv;
Eyal Perry75a353d2013-11-07 12:19:49 +0200143 struct mlx4_spec_list spec_tcp_udp = {
144 .id = mlx4_ip_proto_to_trans_rule_id(filter->ip_proto),
Amir Vadai1eb8c692012-07-18 22:33:52 +0000145 {
146 .tcp_udp = {
147 .dst_port = filter->dst_port,
148 .dst_port_msk = (__force __be16)-1,
149 .src_port = filter->src_port,
150 .src_port_msk = (__force __be16)-1,
151 },
152 },
153 };
154 struct mlx4_spec_list spec_ip = {
155 .id = MLX4_NET_TRANS_RULE_ID_IPV4,
156 {
157 .ipv4 = {
158 .dst_ip = filter->dst_ip,
159 .dst_ip_msk = (__force __be32)-1,
160 .src_ip = filter->src_ip,
161 .src_ip_msk = (__force __be32)-1,
162 },
163 },
164 };
165 struct mlx4_spec_list spec_eth = {
166 .id = MLX4_NET_TRANS_RULE_ID_ETH,
167 };
168 struct mlx4_net_trans_rule rule = {
169 .list = LIST_HEAD_INIT(rule.list),
170 .queue_mode = MLX4_NET_TRANS_Q_LIFO,
171 .exclusive = 1,
172 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000173 .promisc_mode = MLX4_FS_REGULAR,
Amir Vadai1eb8c692012-07-18 22:33:52 +0000174 .port = priv->port,
175 .priority = MLX4_DOMAIN_RFS,
176 };
177 int rc;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000178 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
179
Eyal Perry75a353d2013-11-07 12:19:49 +0200180 if (spec_tcp_udp.id < 0) {
181 en_warn(priv, "RFS: ignoring unsupported ip protocol (%d)\n",
182 filter->ip_proto);
183 goto ignore;
184 }
Amir Vadai1eb8c692012-07-18 22:33:52 +0000185 list_add_tail(&spec_eth.list, &rule.list);
186 list_add_tail(&spec_ip.list, &rule.list);
Eyal Perry75a353d2013-11-07 12:19:49 +0200187 list_add_tail(&spec_tcp_udp.list, &rule.list);
Amir Vadai1eb8c692012-07-18 22:33:52 +0000188
Amir Vadai1eb8c692012-07-18 22:33:52 +0000189 rule.qpn = priv->rss_map.qps[filter->rxq_index].qpn;
Yan Burman6bbb6d92013-02-07 02:25:20 +0000190 memcpy(spec_eth.eth.dst_mac, priv->dev->dev_addr, ETH_ALEN);
Amir Vadai1eb8c692012-07-18 22:33:52 +0000191 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
192
193 filter->activated = 0;
194
195 if (filter->reg_id) {
196 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
197 if (rc && rc != -ENOENT)
198 en_err(priv, "Error detaching flow. rc = %d\n", rc);
199 }
200
201 rc = mlx4_flow_attach(priv->mdev->dev, &rule, &filter->reg_id);
202 if (rc)
203 en_err(priv, "Error attaching flow. err = %d\n", rc);
204
Eyal Perry75a353d2013-11-07 12:19:49 +0200205ignore:
Amir Vadai1eb8c692012-07-18 22:33:52 +0000206 mlx4_en_filter_rfs_expire(priv);
207
208 filter->activated = 1;
209}
210
211static inline struct hlist_head *
212filter_hash_bucket(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
213 __be16 src_port, __be16 dst_port)
214{
215 unsigned long l;
216 int bucket_idx;
217
218 l = (__force unsigned long)src_port |
219 ((__force unsigned long)dst_port << 2);
220 l ^= (__force unsigned long)(src_ip ^ dst_ip);
221
222 bucket_idx = hash_long(l, MLX4_EN_FILTER_HASH_SHIFT);
223
224 return &priv->filter_hash[bucket_idx];
225}
226
227static struct mlx4_en_filter *
228mlx4_en_filter_alloc(struct mlx4_en_priv *priv, int rxq_index, __be32 src_ip,
Eyal Perry75a353d2013-11-07 12:19:49 +0200229 __be32 dst_ip, u8 ip_proto, __be16 src_port,
230 __be16 dst_port, u32 flow_id)
Amir Vadai1eb8c692012-07-18 22:33:52 +0000231{
232 struct mlx4_en_filter *filter = NULL;
233
234 filter = kzalloc(sizeof(struct mlx4_en_filter), GFP_ATOMIC);
235 if (!filter)
236 return NULL;
237
238 filter->priv = priv;
239 filter->rxq_index = rxq_index;
240 INIT_WORK(&filter->work, mlx4_en_filter_work);
241
242 filter->src_ip = src_ip;
243 filter->dst_ip = dst_ip;
Eyal Perry75a353d2013-11-07 12:19:49 +0200244 filter->ip_proto = ip_proto;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000245 filter->src_port = src_port;
246 filter->dst_port = dst_port;
247
248 filter->flow_id = flow_id;
249
Amir Vadaiee64c0e2012-07-25 21:21:16 +0000250 filter->id = priv->last_filter_id++ % RPS_NO_FILTER;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000251
252 list_add_tail(&filter->next, &priv->filters);
253 hlist_add_head(&filter->filter_chain,
254 filter_hash_bucket(priv, src_ip, dst_ip, src_port,
255 dst_port));
256
257 return filter;
258}
259
260static void mlx4_en_filter_free(struct mlx4_en_filter *filter)
261{
262 struct mlx4_en_priv *priv = filter->priv;
263 int rc;
264
265 list_del(&filter->next);
266
267 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
268 if (rc && rc != -ENOENT)
269 en_err(priv, "Error detaching flow. rc = %d\n", rc);
270
271 kfree(filter);
272}
273
274static inline struct mlx4_en_filter *
275mlx4_en_filter_find(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
Eyal Perry75a353d2013-11-07 12:19:49 +0200276 u8 ip_proto, __be16 src_port, __be16 dst_port)
Amir Vadai1eb8c692012-07-18 22:33:52 +0000277{
Amir Vadai1eb8c692012-07-18 22:33:52 +0000278 struct mlx4_en_filter *filter;
279 struct mlx4_en_filter *ret = NULL;
280
Sasha Levinb67bfe02013-02-27 17:06:00 -0800281 hlist_for_each_entry(filter,
Amir Vadai1eb8c692012-07-18 22:33:52 +0000282 filter_hash_bucket(priv, src_ip, dst_ip,
283 src_port, dst_port),
284 filter_chain) {
285 if (filter->src_ip == src_ip &&
286 filter->dst_ip == dst_ip &&
Eyal Perry75a353d2013-11-07 12:19:49 +0200287 filter->ip_proto == ip_proto &&
Amir Vadai1eb8c692012-07-18 22:33:52 +0000288 filter->src_port == src_port &&
289 filter->dst_port == dst_port) {
290 ret = filter;
291 break;
292 }
293 }
294
295 return ret;
296}
297
298static int
299mlx4_en_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
300 u16 rxq_index, u32 flow_id)
301{
302 struct mlx4_en_priv *priv = netdev_priv(net_dev);
303 struct mlx4_en_filter *filter;
304 const struct iphdr *ip;
305 const __be16 *ports;
Eyal Perry75a353d2013-11-07 12:19:49 +0200306 u8 ip_proto;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000307 __be32 src_ip;
308 __be32 dst_ip;
309 __be16 src_port;
310 __be16 dst_port;
311 int nhoff = skb_network_offset(skb);
312 int ret = 0;
313
314 if (skb->protocol != htons(ETH_P_IP))
315 return -EPROTONOSUPPORT;
316
317 ip = (const struct iphdr *)(skb->data + nhoff);
318 if (ip_is_fragment(ip))
319 return -EPROTONOSUPPORT;
320
Eyal Perry75a353d2013-11-07 12:19:49 +0200321 if ((ip->protocol != IPPROTO_TCP) && (ip->protocol != IPPROTO_UDP))
322 return -EPROTONOSUPPORT;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000323 ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl);
324
Eyal Perry75a353d2013-11-07 12:19:49 +0200325 ip_proto = ip->protocol;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000326 src_ip = ip->saddr;
327 dst_ip = ip->daddr;
328 src_port = ports[0];
329 dst_port = ports[1];
330
Amir Vadai1eb8c692012-07-18 22:33:52 +0000331 spin_lock_bh(&priv->filters_lock);
Eyal Perry75a353d2013-11-07 12:19:49 +0200332 filter = mlx4_en_filter_find(priv, src_ip, dst_ip, ip_proto,
333 src_port, dst_port);
Amir Vadai1eb8c692012-07-18 22:33:52 +0000334 if (filter) {
335 if (filter->rxq_index == rxq_index)
336 goto out;
337
338 filter->rxq_index = rxq_index;
339 } else {
340 filter = mlx4_en_filter_alloc(priv, rxq_index,
Eyal Perry75a353d2013-11-07 12:19:49 +0200341 src_ip, dst_ip, ip_proto,
Amir Vadai1eb8c692012-07-18 22:33:52 +0000342 src_port, dst_port, flow_id);
343 if (!filter) {
344 ret = -ENOMEM;
345 goto err;
346 }
347 }
348
349 queue_work(priv->mdev->workqueue, &filter->work);
350
351out:
352 ret = filter->id;
353err:
354 spin_unlock_bh(&priv->filters_lock);
355
356 return ret;
357}
358
Eugenia Emantayev41d942d2013-11-07 12:19:52 +0200359void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv)
Amir Vadai1eb8c692012-07-18 22:33:52 +0000360{
361 struct mlx4_en_filter *filter, *tmp;
362 LIST_HEAD(del_list);
363
364 spin_lock_bh(&priv->filters_lock);
365 list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
366 list_move(&filter->next, &del_list);
367 hlist_del(&filter->filter_chain);
368 }
369 spin_unlock_bh(&priv->filters_lock);
370
371 list_for_each_entry_safe(filter, tmp, &del_list, next) {
372 cancel_work_sync(&filter->work);
373 mlx4_en_filter_free(filter);
374 }
375}
376
377static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv)
378{
379 struct mlx4_en_filter *filter = NULL, *tmp, *last_filter = NULL;
380 LIST_HEAD(del_list);
381 int i = 0;
382
383 spin_lock_bh(&priv->filters_lock);
384 list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
385 if (i > MLX4_EN_FILTER_EXPIRY_QUOTA)
386 break;
387
388 if (filter->activated &&
389 !work_pending(&filter->work) &&
390 rps_may_expire_flow(priv->dev,
391 filter->rxq_index, filter->flow_id,
392 filter->id)) {
393 list_move(&filter->next, &del_list);
394 hlist_del(&filter->filter_chain);
395 } else
396 last_filter = filter;
397
398 i++;
399 }
400
401 if (last_filter && (&last_filter->next != priv->filters.next))
402 list_move(&priv->filters, &last_filter->next);
403
404 spin_unlock_bh(&priv->filters_lock);
405
406 list_for_each_entry_safe(filter, tmp, &del_list, next)
407 mlx4_en_filter_free(filter);
408}
409#endif
410
Patrick McHardy80d5c362013-04-19 02:04:28 +0000411static int mlx4_en_vlan_rx_add_vid(struct net_device *dev,
412 __be16 proto, u16 vid)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700413{
414 struct mlx4_en_priv *priv = netdev_priv(dev);
415 struct mlx4_en_dev *mdev = priv->mdev;
416 int err;
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300417 int idx;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700418
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000419 en_dbg(HW, priv, "adding VLAN:%d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700420
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000421 set_bit(vid, priv->active_vlans);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700422
423 /* Add VID to port VLAN filter */
424 mutex_lock(&mdev->state_lock);
425 if (mdev->device_up && priv->port_up) {
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000426 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700427 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000428 en_err(priv, "Failed configuring VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700429 }
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300430 if (mlx4_register_vlan(mdev->dev, priv->port, vid, &idx))
Eugenia Emantayev9e19b542013-06-25 12:09:32 +0300431 en_dbg(HW, priv, "failed adding vlan %d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700432 mutex_unlock(&mdev->state_lock);
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300433
Jiri Pirko8e586132011-12-08 19:52:37 -0500434 return 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700435}
436
Patrick McHardy80d5c362013-04-19 02:04:28 +0000437static int mlx4_en_vlan_rx_kill_vid(struct net_device *dev,
438 __be16 proto, u16 vid)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700439{
440 struct mlx4_en_priv *priv = netdev_priv(dev);
441 struct mlx4_en_dev *mdev = priv->mdev;
442 int err;
443
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000444 en_dbg(HW, priv, "Killing VID:%d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700445
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000446 clear_bit(vid, priv->active_vlans);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700447
448 /* Remove VID from port VLAN filter */
449 mutex_lock(&mdev->state_lock);
Jack Morgenstein2009d002013-11-03 10:03:19 +0200450 mlx4_unregister_vlan(mdev->dev, priv->port, vid);
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300451
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700452 if (mdev->device_up && priv->port_up) {
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000453 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700454 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000455 en_err(priv, "Failed configuring VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700456 }
457 mutex_unlock(&mdev->state_lock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500458
459 return 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700460}
461
Yan Burman6bbb6d92013-02-07 02:25:20 +0000462static void mlx4_en_u64_to_mac(unsigned char dst_mac[ETH_ALEN + 2], u64 src_mac)
463{
Yan Burmanbab6a9e2013-04-02 16:49:45 +0300464 int i;
465 for (i = ETH_ALEN - 1; i >= 0; --i) {
Yan Burman6bbb6d92013-02-07 02:25:20 +0000466 dst_mac[i] = src_mac & 0xff;
467 src_mac >>= 8;
468 }
469 memset(&dst_mac[ETH_ALEN], 0, 2);
470}
471
Or Gerlitz837052d2013-12-23 16:09:44 +0200472
473static int mlx4_en_tunnel_steer_add(struct mlx4_en_priv *priv, unsigned char *addr,
474 int qpn, u64 *reg_id)
475{
476 int err;
477 struct mlx4_spec_list spec_eth_outer = { {NULL} };
478 struct mlx4_spec_list spec_vxlan = { {NULL} };
479 struct mlx4_spec_list spec_eth_inner = { {NULL} };
480
481 struct mlx4_net_trans_rule rule = {
482 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
483 .exclusive = 0,
484 .allow_loopback = 1,
485 .promisc_mode = MLX4_FS_REGULAR,
486 .priority = MLX4_DOMAIN_NIC,
487 };
488
489 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
490
491 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
492 return 0; /* do nothing */
493
494 rule.port = priv->port;
495 rule.qpn = qpn;
496 INIT_LIST_HEAD(&rule.list);
497
498 spec_eth_outer.id = MLX4_NET_TRANS_RULE_ID_ETH;
499 memcpy(spec_eth_outer.eth.dst_mac, addr, ETH_ALEN);
500 memcpy(spec_eth_outer.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
501
502 spec_vxlan.id = MLX4_NET_TRANS_RULE_ID_VXLAN; /* any vxlan header */
503 spec_eth_inner.id = MLX4_NET_TRANS_RULE_ID_ETH; /* any inner eth header */
504
505 list_add_tail(&spec_eth_outer.list, &rule.list);
506 list_add_tail(&spec_vxlan.list, &rule.list);
507 list_add_tail(&spec_eth_inner.list, &rule.list);
508
509 err = mlx4_flow_attach(priv->mdev->dev, &rule, reg_id);
510 if (err) {
511 en_err(priv, "failed to add vxlan steering rule, err %d\n", err);
512 return err;
513 }
514 en_dbg(DRV, priv, "added vxlan steering rule, mac %pM reg_id %llx\n", addr, *reg_id);
515 return 0;
516}
517
518
Yan Burman16a10ff2013-02-07 02:25:22 +0000519static int mlx4_en_uc_steer_add(struct mlx4_en_priv *priv,
520 unsigned char *mac, int *qpn, u64 *reg_id)
521{
522 struct mlx4_en_dev *mdev = priv->mdev;
523 struct mlx4_dev *dev = mdev->dev;
524 int err;
525
526 switch (dev->caps.steering_mode) {
527 case MLX4_STEERING_MODE_B0: {
528 struct mlx4_qp qp;
529 u8 gid[16] = {0};
530
531 qp.qpn = *qpn;
532 memcpy(&gid[10], mac, ETH_ALEN);
533 gid[5] = priv->port;
534
535 err = mlx4_unicast_attach(dev, &qp, gid, 0, MLX4_PROT_ETH);
536 break;
537 }
538 case MLX4_STEERING_MODE_DEVICE_MANAGED: {
539 struct mlx4_spec_list spec_eth = { {NULL} };
540 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
541
542 struct mlx4_net_trans_rule rule = {
543 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
544 .exclusive = 0,
545 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000546 .promisc_mode = MLX4_FS_REGULAR,
Yan Burman16a10ff2013-02-07 02:25:22 +0000547 .priority = MLX4_DOMAIN_NIC,
548 };
549
550 rule.port = priv->port;
551 rule.qpn = *qpn;
552 INIT_LIST_HEAD(&rule.list);
553
554 spec_eth.id = MLX4_NET_TRANS_RULE_ID_ETH;
555 memcpy(spec_eth.eth.dst_mac, mac, ETH_ALEN);
556 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
557 list_add_tail(&spec_eth.list, &rule.list);
558
559 err = mlx4_flow_attach(dev, &rule, reg_id);
560 break;
561 }
562 default:
563 return -EINVAL;
564 }
565 if (err)
566 en_warn(priv, "Failed Attaching Unicast\n");
567
568 return err;
569}
570
571static void mlx4_en_uc_steer_release(struct mlx4_en_priv *priv,
572 unsigned char *mac, int qpn, u64 reg_id)
573{
574 struct mlx4_en_dev *mdev = priv->mdev;
575 struct mlx4_dev *dev = mdev->dev;
576
577 switch (dev->caps.steering_mode) {
578 case MLX4_STEERING_MODE_B0: {
579 struct mlx4_qp qp;
580 u8 gid[16] = {0};
581
582 qp.qpn = qpn;
583 memcpy(&gid[10], mac, ETH_ALEN);
584 gid[5] = priv->port;
585
586 mlx4_unicast_detach(dev, &qp, gid, MLX4_PROT_ETH);
587 break;
588 }
589 case MLX4_STEERING_MODE_DEVICE_MANAGED: {
590 mlx4_flow_detach(dev, reg_id);
591 break;
592 }
593 default:
594 en_err(priv, "Invalid steering mode.\n");
595 }
596}
597
598static int mlx4_en_get_qp(struct mlx4_en_priv *priv)
599{
600 struct mlx4_en_dev *mdev = priv->mdev;
601 struct mlx4_dev *dev = mdev->dev;
602 struct mlx4_mac_entry *entry;
603 int index = 0;
604 int err = 0;
605 u64 reg_id;
606 int *qpn = &priv->base_qpn;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200607 u64 mac = mlx4_mac_to_u64(priv->dev->dev_addr);
Yan Burman16a10ff2013-02-07 02:25:22 +0000608
609 en_dbg(DRV, priv, "Registering MAC: %pM for adding\n",
610 priv->dev->dev_addr);
611 index = mlx4_register_mac(dev, priv->port, mac);
612 if (index < 0) {
613 err = index;
614 en_err(priv, "Failed adding MAC: %pM\n",
615 priv->dev->dev_addr);
616 return err;
617 }
618
619 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) {
620 int base_qpn = mlx4_get_base_qpn(dev, priv->port);
621 *qpn = base_qpn + index;
622 return 0;
623 }
624
625 err = mlx4_qp_reserve_range(dev, 1, 1, qpn);
626 en_dbg(DRV, priv, "Reserved qp %d\n", *qpn);
627 if (err) {
628 en_err(priv, "Failed to reserve qp for mac registration\n");
629 goto qp_err;
630 }
631
632 err = mlx4_en_uc_steer_add(priv, priv->dev->dev_addr, qpn, &reg_id);
633 if (err)
634 goto steer_err;
635
Wei Yongjun9ba75fb2014-01-07 16:56:07 +0800636 err = mlx4_en_tunnel_steer_add(priv, priv->dev->dev_addr, *qpn,
637 &priv->tunnel_reg_id);
638 if (err)
Or Gerlitz837052d2013-12-23 16:09:44 +0200639 goto tunnel_err;
640
Yan Burman16a10ff2013-02-07 02:25:22 +0000641 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
642 if (!entry) {
643 err = -ENOMEM;
644 goto alloc_err;
645 }
646 memcpy(entry->mac, priv->dev->dev_addr, sizeof(entry->mac));
647 entry->reg_id = reg_id;
648
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000649 hlist_add_head_rcu(&entry->hlist,
650 &priv->mac_hash[entry->mac[MLX4_EN_MAC_HASH_IDX]]);
Yan Burman16a10ff2013-02-07 02:25:22 +0000651
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000652 return 0;
Yan Burman16a10ff2013-02-07 02:25:22 +0000653
654alloc_err:
Or Gerlitz837052d2013-12-23 16:09:44 +0200655 if (priv->tunnel_reg_id)
656 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
657tunnel_err:
Yan Burman16a10ff2013-02-07 02:25:22 +0000658 mlx4_en_uc_steer_release(priv, priv->dev->dev_addr, *qpn, reg_id);
659
660steer_err:
661 mlx4_qp_release_range(dev, *qpn, 1);
662
663qp_err:
664 mlx4_unregister_mac(dev, priv->port, mac);
665 return err;
666}
667
668static void mlx4_en_put_qp(struct mlx4_en_priv *priv)
669{
670 struct mlx4_en_dev *mdev = priv->mdev;
671 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000672 int qpn = priv->base_qpn;
Yan Burman83a5a6c2013-03-07 03:46:56 +0000673 u64 mac;
Yan Burman16a10ff2013-02-07 02:25:22 +0000674
Yan Burman83a5a6c2013-03-07 03:46:56 +0000675 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) {
Eugenia Emantayev98133372014-03-02 10:25:01 +0200676 mac = mlx4_mac_to_u64(priv->dev->dev_addr);
Yan Burman83a5a6c2013-03-07 03:46:56 +0000677 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n",
678 priv->dev->dev_addr);
679 mlx4_unregister_mac(dev, priv->port, mac);
680 } else {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000681 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800682 struct hlist_node *tmp;
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000683 struct hlist_head *bucket;
Yan Burman83a5a6c2013-03-07 03:46:56 +0000684 unsigned int i;
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000685
Yan Burman83a5a6c2013-03-07 03:46:56 +0000686 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) {
687 bucket = &priv->mac_hash[i];
688 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Eugenia Emantayev98133372014-03-02 10:25:01 +0200689 mac = mlx4_mac_to_u64(entry->mac);
Yan Burman83a5a6c2013-03-07 03:46:56 +0000690 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n",
691 entry->mac);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000692 mlx4_en_uc_steer_release(priv, entry->mac,
693 qpn, entry->reg_id);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000694
Yan Burman83a5a6c2013-03-07 03:46:56 +0000695 mlx4_unregister_mac(dev, priv->port, mac);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000696 hlist_del_rcu(&entry->hlist);
697 kfree_rcu(entry, rcu);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000698 }
Yan Burman16a10ff2013-02-07 02:25:22 +0000699 }
Yan Burman83a5a6c2013-03-07 03:46:56 +0000700
Or Gerlitz837052d2013-12-23 16:09:44 +0200701 if (priv->tunnel_reg_id) {
702 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
703 priv->tunnel_reg_id = 0;
704 }
705
Yan Burman83a5a6c2013-03-07 03:46:56 +0000706 en_dbg(DRV, priv, "Releasing qp: port %d, qpn %d\n",
707 priv->port, qpn);
708 mlx4_qp_release_range(dev, qpn, 1);
709 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC;
Yan Burman16a10ff2013-02-07 02:25:22 +0000710 }
711}
712
713static int mlx4_en_replace_mac(struct mlx4_en_priv *priv, int qpn,
Yan Burman90bbb742013-02-07 02:25:24 +0000714 unsigned char *new_mac, unsigned char *prev_mac)
Yan Burman16a10ff2013-02-07 02:25:22 +0000715{
716 struct mlx4_en_dev *mdev = priv->mdev;
717 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000718 int err = 0;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200719 u64 new_mac_u64 = mlx4_mac_to_u64(new_mac);
Yan Burman16a10ff2013-02-07 02:25:22 +0000720
721 if (dev->caps.steering_mode != MLX4_STEERING_MODE_A0) {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000722 struct hlist_head *bucket;
723 unsigned int mac_hash;
724 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800725 struct hlist_node *tmp;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200726 u64 prev_mac_u64 = mlx4_mac_to_u64(prev_mac);
Yan Burman16a10ff2013-02-07 02:25:22 +0000727
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000728 bucket = &priv->mac_hash[prev_mac[MLX4_EN_MAC_HASH_IDX]];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800729 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000730 if (ether_addr_equal_64bits(entry->mac, prev_mac)) {
731 mlx4_en_uc_steer_release(priv, entry->mac,
732 qpn, entry->reg_id);
733 mlx4_unregister_mac(dev, priv->port,
734 prev_mac_u64);
735 hlist_del_rcu(&entry->hlist);
736 synchronize_rcu();
737 memcpy(entry->mac, new_mac, ETH_ALEN);
738 entry->reg_id = 0;
739 mac_hash = new_mac[MLX4_EN_MAC_HASH_IDX];
740 hlist_add_head_rcu(&entry->hlist,
741 &priv->mac_hash[mac_hash]);
742 mlx4_register_mac(dev, priv->port, new_mac_u64);
743 err = mlx4_en_uc_steer_add(priv, new_mac,
744 &qpn,
745 &entry->reg_id);
Or Gerlitz2a2083f2014-03-12 17:16:31 +0200746 if (err)
747 return err;
748 if (priv->tunnel_reg_id) {
749 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
750 priv->tunnel_reg_id = 0;
751 }
752 err = mlx4_en_tunnel_steer_add(priv, new_mac, qpn,
753 &priv->tunnel_reg_id);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000754 return err;
755 }
756 }
757 return -EINVAL;
Yan Burman16a10ff2013-02-07 02:25:22 +0000758 }
759
760 return __mlx4_replace_mac(dev, priv->port, qpn, new_mac_u64);
761}
762
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000763static int mlx4_en_do_set_mac(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700764{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700765 int err = 0;
766
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700767 if (priv->port_up) {
768 /* Remove old MAC and insert the new one */
Yan Burman16a10ff2013-02-07 02:25:22 +0000769 err = mlx4_en_replace_mac(priv, priv->base_qpn,
Yan Burman90bbb742013-02-07 02:25:24 +0000770 priv->dev->dev_addr, priv->prev_mac);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700771 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000772 en_err(priv, "Failed changing HW MAC address\n");
Yan Burman6bbb6d92013-02-07 02:25:20 +0000773 memcpy(priv->prev_mac, priv->dev->dev_addr,
774 sizeof(priv->prev_mac));
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700775 } else
Yan Burman48e551f2013-02-07 02:25:21 +0000776 en_dbg(HW, priv, "Port is down while registering mac, exiting...\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700777
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000778 return err;
779}
780
781static int mlx4_en_set_mac(struct net_device *dev, void *addr)
782{
783 struct mlx4_en_priv *priv = netdev_priv(dev);
784 struct mlx4_en_dev *mdev = priv->mdev;
785 struct sockaddr *saddr = addr;
786 int err;
787
788 if (!is_valid_ether_addr(saddr->sa_data))
789 return -EADDRNOTAVAIL;
790
791 memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
792
793 mutex_lock(&mdev->state_lock);
794 err = mlx4_en_do_set_mac(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700795 mutex_unlock(&mdev->state_lock);
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000796
797 return err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700798}
799
800static void mlx4_en_clear_list(struct net_device *dev)
801{
802 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000803 struct mlx4_en_mc_list *tmp, *mc_to_del;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700804
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000805 list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) {
806 list_del(&mc_to_del->list);
807 kfree(mc_to_del);
808 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700809}
810
811static void mlx4_en_cache_mclist(struct net_device *dev)
812{
813 struct mlx4_en_priv *priv = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000814 struct netdev_hw_addr *ha;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000815 struct mlx4_en_mc_list *tmp;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700816
Alexander Guller0e035672011-12-19 04:02:58 +0000817 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000818 netdev_for_each_mc_addr(ha, dev) {
819 tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC);
820 if (!tmp) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000821 mlx4_en_clear_list(dev);
822 return;
823 }
824 memcpy(tmp->addr, ha->addr, ETH_ALEN);
825 list_add_tail(&tmp->list, &priv->mc_list);
826 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700827}
828
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000829static void update_mclist_flags(struct mlx4_en_priv *priv,
830 struct list_head *dst,
831 struct list_head *src)
832{
833 struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc;
834 bool found;
835
836 /* Find all the entries that should be removed from dst,
837 * These are the entries that are not found in src
838 */
839 list_for_each_entry(dst_tmp, dst, list) {
840 found = false;
841 list_for_each_entry(src_tmp, src, list) {
dingtianhongc0623e52013-12-30 15:40:55 +0800842 if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000843 found = true;
844 break;
845 }
846 }
847 if (!found)
848 dst_tmp->action = MCLIST_REM;
849 }
850
851 /* Add entries that exist in src but not in dst
852 * mark them as need to add
853 */
854 list_for_each_entry(src_tmp, src, list) {
855 found = false;
856 list_for_each_entry(dst_tmp, dst, list) {
dingtianhongc0623e52013-12-30 15:40:55 +0800857 if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000858 dst_tmp->action = MCLIST_NONE;
859 found = true;
860 break;
861 }
862 }
863 if (!found) {
Joe Perches14f8dc42013-02-07 11:46:27 +0000864 new_mc = kmemdup(src_tmp,
865 sizeof(struct mlx4_en_mc_list),
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000866 GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +0000867 if (!new_mc)
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000868 return;
Joe Perches14f8dc42013-02-07 11:46:27 +0000869
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000870 new_mc->action = MCLIST_ADD;
871 list_add_tail(&new_mc->list, dst);
872 }
873 }
874}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700875
Yan Burman0eb74fd2013-02-07 02:25:23 +0000876static void mlx4_en_set_rx_mode(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700877{
878 struct mlx4_en_priv *priv = netdev_priv(dev);
879
880 if (!priv->port_up)
881 return;
882
Yan Burman0eb74fd2013-02-07 02:25:23 +0000883 queue_work(priv->mdev->workqueue, &priv->rx_mode_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700884}
885
Yan Burman0eb74fd2013-02-07 02:25:23 +0000886static void mlx4_en_set_promisc_mode(struct mlx4_en_priv *priv,
887 struct mlx4_en_dev *mdev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700888{
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000889 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700890
Yan Burman0eb74fd2013-02-07 02:25:23 +0000891 if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700892 if (netif_msg_rx_status(priv))
Yan Burman0eb74fd2013-02-07 02:25:23 +0000893 en_warn(priv, "Entering promiscuous mode\n");
894 priv->flags |= MLX4_EN_FLAG_PROMISC;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700895
Yan Burman0eb74fd2013-02-07 02:25:23 +0000896 /* Enable promiscouos mode */
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000897 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000898 case MLX4_STEERING_MODE_DEVICE_MANAGED:
Yan Burman0eb74fd2013-02-07 02:25:23 +0000899 err = mlx4_flow_steer_promisc_add(mdev->dev,
900 priv->port,
901 priv->base_qpn,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000902 MLX4_FS_ALL_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000903 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000904 en_err(priv, "Failed enabling promiscuous mode\n");
905 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000906 break;
907
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000908 case MLX4_STEERING_MODE_B0:
Yan Burman0eb74fd2013-02-07 02:25:23 +0000909 err = mlx4_unicast_promisc_add(mdev->dev,
910 priv->base_qpn,
911 priv->port);
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000912 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000913 en_err(priv, "Failed enabling unicast promiscuous mode\n");
914
915 /* Add the default qp number as multicast
916 * promisc
917 */
918 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
919 err = mlx4_multicast_promisc_add(mdev->dev,
920 priv->base_qpn,
921 priv->port);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000922 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000923 en_err(priv, "Failed enabling multicast promiscuous mode\n");
924 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000925 }
926 break;
927
928 case MLX4_STEERING_MODE_A0:
929 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
930 priv->port,
Yan Burman0eb74fd2013-02-07 02:25:23 +0000931 priv->base_qpn,
932 1);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000933 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000934 en_err(priv, "Failed enabling promiscuous mode\n");
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000935 break;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000936 }
937
Yan Burman0eb74fd2013-02-07 02:25:23 +0000938 /* Disable port multicast filter (unconditionally) */
939 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
940 0, MLX4_MCAST_DISABLE);
941 if (err)
942 en_err(priv, "Failed disabling multicast filter\n");
943
944 /* Disable port VLAN filter */
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000945 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700946 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000947 en_err(priv, "Failed disabling VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700948 }
Yan Burman0eb74fd2013-02-07 02:25:23 +0000949}
950
951static void mlx4_en_clear_promisc_mode(struct mlx4_en_priv *priv,
952 struct mlx4_en_dev *mdev)
953{
954 int err = 0;
955
956 if (netif_msg_rx_status(priv))
957 en_warn(priv, "Leaving promiscuous mode\n");
958 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
959
960 /* Disable promiscouos mode */
961 switch (mdev->dev->caps.steering_mode) {
962 case MLX4_STEERING_MODE_DEVICE_MANAGED:
963 err = mlx4_flow_steer_promisc_remove(mdev->dev,
964 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000965 MLX4_FS_ALL_DEFAULT);
Yan Burman0eb74fd2013-02-07 02:25:23 +0000966 if (err)
967 en_err(priv, "Failed disabling promiscuous mode\n");
968 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
969 break;
970
971 case MLX4_STEERING_MODE_B0:
972 err = mlx4_unicast_promisc_remove(mdev->dev,
973 priv->base_qpn,
974 priv->port);
975 if (err)
976 en_err(priv, "Failed disabling unicast promiscuous mode\n");
977 /* Disable Multicast promisc */
978 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
979 err = mlx4_multicast_promisc_remove(mdev->dev,
980 priv->base_qpn,
981 priv->port);
982 if (err)
983 en_err(priv, "Failed disabling multicast promiscuous mode\n");
984 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
985 }
986 break;
987
988 case MLX4_STEERING_MODE_A0:
989 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
990 priv->port,
991 priv->base_qpn, 0);
992 if (err)
993 en_err(priv, "Failed disabling promiscuous mode\n");
994 break;
995 }
996
997 /* Enable port VLAN filter */
998 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
999 if (err)
1000 en_err(priv, "Failed enabling VLAN filter\n");
1001}
1002
1003static void mlx4_en_do_multicast(struct mlx4_en_priv *priv,
1004 struct net_device *dev,
1005 struct mlx4_en_dev *mdev)
1006{
1007 struct mlx4_en_mc_list *mclist, *tmp;
1008 u64 mcast_addr = 0;
1009 u8 mc_list[16] = {0};
1010 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001011
1012 /* Enable/disable the multicast filter according to IFF_ALLMULTI */
1013 if (dev->flags & IFF_ALLMULTI) {
1014 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
1015 0, MLX4_MCAST_DISABLE);
1016 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001017 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001018
1019 /* Add the default qp number as multicast promisc */
1020 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001021 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001022 case MLX4_STEERING_MODE_DEVICE_MANAGED:
1023 err = mlx4_flow_steer_promisc_add(mdev->dev,
1024 priv->port,
1025 priv->base_qpn,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001026 MLX4_FS_MC_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001027 break;
1028
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001029 case MLX4_STEERING_MODE_B0:
1030 err = mlx4_multicast_promisc_add(mdev->dev,
1031 priv->base_qpn,
1032 priv->port);
1033 break;
1034
1035 case MLX4_STEERING_MODE_A0:
1036 break;
1037 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001038 if (err)
1039 en_err(priv, "Failed entering multicast promisc mode\n");
1040 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
1041 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001042 } else {
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001043 /* Disable Multicast promisc */
1044 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001045 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001046 case MLX4_STEERING_MODE_DEVICE_MANAGED:
1047 err = mlx4_flow_steer_promisc_remove(mdev->dev,
1048 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001049 MLX4_FS_MC_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001050 break;
1051
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001052 case MLX4_STEERING_MODE_B0:
1053 err = mlx4_multicast_promisc_remove(mdev->dev,
1054 priv->base_qpn,
1055 priv->port);
1056 break;
1057
1058 case MLX4_STEERING_MODE_A0:
1059 break;
1060 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001061 if (err)
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001062 en_err(priv, "Failed disabling multicast promiscuous mode\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001063 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
1064 }
Jiri Pirkoff6e2162010-03-01 05:09:14 +00001065
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001066 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
1067 0, MLX4_MCAST_DISABLE);
1068 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001069 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001070
1071 /* Flush mcast filter and init it with broadcast address */
1072 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST,
1073 1, MLX4_MCAST_CONFIG);
1074
1075 /* Update multicast list - we cache all addresses so they won't
1076 * change while HW is updated holding the command semaphor */
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +00001077 netif_addr_lock_bh(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001078 mlx4_en_cache_mclist(dev);
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +00001079 netif_addr_unlock_bh(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001080 list_for_each_entry(mclist, &priv->mc_list, list) {
Eugenia Emantayev98133372014-03-02 10:25:01 +02001081 mcast_addr = mlx4_mac_to_u64(mclist->addr);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001082 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port,
1083 mcast_addr, 0, MLX4_MCAST_CONFIG);
1084 }
1085 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
1086 0, MLX4_MCAST_ENABLE);
1087 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001088 en_err(priv, "Failed enabling multicast filter\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001089
1090 update_mclist_flags(priv, &priv->curr_list, &priv->mc_list);
1091 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
1092 if (mclist->action == MCLIST_REM) {
1093 /* detach this address and delete from list */
1094 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
1095 mc_list[5] = priv->port;
1096 err = mlx4_multicast_detach(mdev->dev,
1097 &priv->rss_map.indir_qp,
1098 mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001099 MLX4_PROT_ETH,
1100 mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001101 if (err)
1102 en_err(priv, "Fail to detach multicast address\n");
1103
Or Gerlitz837052d2013-12-23 16:09:44 +02001104 if (mclist->tunnel_reg_id) {
1105 err = mlx4_flow_detach(priv->mdev->dev, mclist->tunnel_reg_id);
1106 if (err)
1107 en_err(priv, "Failed to detach multicast address\n");
1108 }
1109
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001110 /* remove from list */
1111 list_del(&mclist->list);
1112 kfree(mclist);
Dan Carpenter9c645082012-07-10 20:34:07 +00001113 } else if (mclist->action == MCLIST_ADD) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001114 /* attach the address */
1115 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001116 /* needed for B0 steering support */
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001117 mc_list[5] = priv->port;
1118 err = mlx4_multicast_attach(mdev->dev,
1119 &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001120 mc_list,
1121 priv->port, 0,
1122 MLX4_PROT_ETH,
1123 &mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001124 if (err)
1125 en_err(priv, "Fail to attach multicast address\n");
1126
Or Gerlitz837052d2013-12-23 16:09:44 +02001127 err = mlx4_en_tunnel_steer_add(priv, &mc_list[10], priv->base_qpn,
1128 &mclist->tunnel_reg_id);
1129 if (err)
1130 en_err(priv, "Failed to attach multicast address\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001131 }
1132 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001133 }
Yan Burman0eb74fd2013-02-07 02:25:23 +00001134}
1135
Yan Burmancc5387f2013-02-07 02:25:26 +00001136static void mlx4_en_do_uc_filter(struct mlx4_en_priv *priv,
1137 struct net_device *dev,
1138 struct mlx4_en_dev *mdev)
1139{
1140 struct netdev_hw_addr *ha;
1141 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001142 struct hlist_node *tmp;
Yan Burmancc5387f2013-02-07 02:25:26 +00001143 bool found;
1144 u64 mac;
1145 int err = 0;
1146 struct hlist_head *bucket;
1147 unsigned int i;
1148 int removed = 0;
1149 u32 prev_flags;
1150
1151 /* Note that we do not need to protect our mac_hash traversal with rcu,
1152 * since all modification code is protected by mdev->state_lock
1153 */
1154
1155 /* find what to remove */
1156 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) {
1157 bucket = &priv->mac_hash[i];
Sasha Levinb67bfe02013-02-27 17:06:00 -08001158 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Yan Burmancc5387f2013-02-07 02:25:26 +00001159 found = false;
1160 netdev_for_each_uc_addr(ha, dev) {
1161 if (ether_addr_equal_64bits(entry->mac,
1162 ha->addr)) {
1163 found = true;
1164 break;
1165 }
1166 }
1167
1168 /* MAC address of the port is not in uc list */
1169 if (ether_addr_equal_64bits(entry->mac, dev->dev_addr))
1170 found = true;
1171
1172 if (!found) {
Eugenia Emantayev98133372014-03-02 10:25:01 +02001173 mac = mlx4_mac_to_u64(entry->mac);
Yan Burmancc5387f2013-02-07 02:25:26 +00001174 mlx4_en_uc_steer_release(priv, entry->mac,
1175 priv->base_qpn,
1176 entry->reg_id);
1177 mlx4_unregister_mac(mdev->dev, priv->port, mac);
1178
1179 hlist_del_rcu(&entry->hlist);
1180 kfree_rcu(entry, rcu);
1181 en_dbg(DRV, priv, "Removed MAC %pM on port:%d\n",
1182 entry->mac, priv->port);
1183 ++removed;
1184 }
1185 }
1186 }
1187
1188 /* if we didn't remove anything, there is no use in trying to add
1189 * again once we are in a forced promisc mode state
1190 */
1191 if ((priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) && 0 == removed)
1192 return;
1193
1194 prev_flags = priv->flags;
1195 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC;
1196
1197 /* find what to add */
1198 netdev_for_each_uc_addr(ha, dev) {
1199 found = false;
1200 bucket = &priv->mac_hash[ha->addr[MLX4_EN_MAC_HASH_IDX]];
Sasha Levinb67bfe02013-02-27 17:06:00 -08001201 hlist_for_each_entry(entry, bucket, hlist) {
Yan Burmancc5387f2013-02-07 02:25:26 +00001202 if (ether_addr_equal_64bits(entry->mac, ha->addr)) {
1203 found = true;
1204 break;
1205 }
1206 }
1207
1208 if (!found) {
1209 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1210 if (!entry) {
1211 en_err(priv, "Failed adding MAC %pM on port:%d (out of memory)\n",
1212 ha->addr, priv->port);
1213 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1214 break;
1215 }
Eugenia Emantayev98133372014-03-02 10:25:01 +02001216 mac = mlx4_mac_to_u64(ha->addr);
Yan Burmancc5387f2013-02-07 02:25:26 +00001217 memcpy(entry->mac, ha->addr, ETH_ALEN);
1218 err = mlx4_register_mac(mdev->dev, priv->port, mac);
1219 if (err < 0) {
1220 en_err(priv, "Failed registering MAC %pM on port %d: %d\n",
1221 ha->addr, priv->port, err);
1222 kfree(entry);
1223 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1224 break;
1225 }
1226 err = mlx4_en_uc_steer_add(priv, ha->addr,
1227 &priv->base_qpn,
1228 &entry->reg_id);
1229 if (err) {
1230 en_err(priv, "Failed adding MAC %pM on port %d: %d\n",
1231 ha->addr, priv->port, err);
1232 mlx4_unregister_mac(mdev->dev, priv->port, mac);
1233 kfree(entry);
1234 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1235 break;
1236 } else {
1237 unsigned int mac_hash;
1238 en_dbg(DRV, priv, "Added MAC %pM on port:%d\n",
1239 ha->addr, priv->port);
1240 mac_hash = ha->addr[MLX4_EN_MAC_HASH_IDX];
1241 bucket = &priv->mac_hash[mac_hash];
1242 hlist_add_head_rcu(&entry->hlist, bucket);
1243 }
1244 }
1245 }
1246
1247 if (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) {
1248 en_warn(priv, "Forcing promiscuous mode on port:%d\n",
1249 priv->port);
1250 } else if (prev_flags & MLX4_EN_FLAG_FORCE_PROMISC) {
1251 en_warn(priv, "Stop forcing promiscuous mode on port:%d\n",
1252 priv->port);
1253 }
1254}
1255
Yan Burman0eb74fd2013-02-07 02:25:23 +00001256static void mlx4_en_do_set_rx_mode(struct work_struct *work)
1257{
1258 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1259 rx_mode_task);
1260 struct mlx4_en_dev *mdev = priv->mdev;
1261 struct net_device *dev = priv->dev;
1262
1263 mutex_lock(&mdev->state_lock);
1264 if (!mdev->device_up) {
1265 en_dbg(HW, priv, "Card is not up, ignoring rx mode change.\n");
1266 goto out;
1267 }
1268 if (!priv->port_up) {
1269 en_dbg(HW, priv, "Port is down, ignoring rx mode change.\n");
1270 goto out;
1271 }
1272
1273 if (!netif_carrier_ok(dev)) {
1274 if (!mlx4_en_QUERY_PORT(mdev, priv->port)) {
1275 if (priv->port_state.link_state) {
1276 priv->last_link_state = MLX4_DEV_EVENT_PORT_UP;
1277 netif_carrier_on(dev);
1278 en_dbg(LINK, priv, "Link Up\n");
1279 }
1280 }
1281 }
1282
Yan Burmancc5387f2013-02-07 02:25:26 +00001283 if (dev->priv_flags & IFF_UNICAST_FLT)
1284 mlx4_en_do_uc_filter(priv, dev, mdev);
1285
Yan Burman0eb74fd2013-02-07 02:25:23 +00001286 /* Promsicuous mode: disable all filters */
Yan Burmancc5387f2013-02-07 02:25:26 +00001287 if ((dev->flags & IFF_PROMISC) ||
1288 (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC)) {
Yan Burman0eb74fd2013-02-07 02:25:23 +00001289 mlx4_en_set_promisc_mode(priv, mdev);
1290 goto out;
1291 }
1292
1293 /* Not in promiscuous mode */
1294 if (priv->flags & MLX4_EN_FLAG_PROMISC)
1295 mlx4_en_clear_promisc_mode(priv, mdev);
1296
1297 mlx4_en_do_multicast(priv, dev, mdev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001298out:
1299 mutex_unlock(&mdev->state_lock);
1300}
1301
1302#ifdef CONFIG_NET_POLL_CONTROLLER
1303static void mlx4_en_netpoll(struct net_device *dev)
1304{
1305 struct mlx4_en_priv *priv = netdev_priv(dev);
1306 struct mlx4_en_cq *cq;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001307 int i;
1308
1309 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001310 cq = priv->rx_cq[i];
Chris Masonc98235c2014-04-15 18:09:24 -04001311 napi_schedule(&cq->napi);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001312 }
1313}
1314#endif
1315
1316static void mlx4_en_tx_timeout(struct net_device *dev)
1317{
1318 struct mlx4_en_priv *priv = netdev_priv(dev);
1319 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001320 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001321
1322 if (netif_msg_timer(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001323 en_warn(priv, "Tx timeout called on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001324
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001325 for (i = 0; i < priv->tx_ring_num; i++) {
1326 if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev, i)))
1327 continue;
1328 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 +02001329 i, priv->tx_ring[i]->qpn, priv->tx_ring[i]->cqn,
1330 priv->tx_ring[i]->cons, priv->tx_ring[i]->prod);
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001331 }
1332
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001333 priv->port_stats.tx_timeout++;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001334 en_dbg(DRV, priv, "Scheduling watchdog\n");
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001335 queue_work(mdev->workqueue, &priv->watchdog_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001336}
1337
1338
1339static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev)
1340{
1341 struct mlx4_en_priv *priv = netdev_priv(dev);
1342
1343 spin_lock_bh(&priv->stats_lock);
1344 memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats));
1345 spin_unlock_bh(&priv->stats_lock);
1346
1347 return &priv->ret_stats;
1348}
1349
1350static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv)
1351{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001352 struct mlx4_en_cq *cq;
1353 int i;
1354
1355 /* If we haven't received a specific coalescing setting
Martin Olsson98a17082009-04-22 18:21:29 +02001356 * (module param), we set the moderation parameters as follows:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001357 * - moder_cnt is set to the number of mtu sized packets to
Eric Dumazetecfd2ce2012-11-05 16:20:42 +00001358 * satisfy our coalescing target.
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001359 * - moder_time is set to a fixed value.
1360 */
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +00001361 priv->rx_frames = MLX4_EN_RX_COAL_TARGET;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -08001362 priv->rx_usecs = MLX4_EN_RX_COAL_TIME;
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001363 priv->tx_frames = MLX4_EN_TX_COAL_PKTS;
1364 priv->tx_usecs = MLX4_EN_TX_COAL_TIME;
Yan Burman48e551f2013-02-07 02:25:21 +00001365 en_dbg(INTR, priv, "Default coalesing params for mtu:%d - rx_frames:%d rx_usecs:%d\n",
1366 priv->dev->mtu, priv->rx_frames, priv->rx_usecs);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001367
1368 /* Setup cq moderation params */
1369 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001370 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001371 cq->moder_cnt = priv->rx_frames;
1372 cq->moder_time = priv->rx_usecs;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001373 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
1374 priv->last_moder_packets[i] = 0;
1375 priv->last_moder_bytes[i] = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001376 }
1377
1378 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001379 cq = priv->tx_cq[i];
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001380 cq->moder_cnt = priv->tx_frames;
1381 cq->moder_time = priv->tx_usecs;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001382 }
1383
1384 /* Reset auto-moderation params */
1385 priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW;
1386 priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW;
1387 priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH;
1388 priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH;
1389 priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -08001390 priv->adaptive_rx_coal = 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001391 priv->last_moder_jiffies = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001392 priv->last_moder_tx_packets = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001393}
1394
1395static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv)
1396{
1397 unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001398 struct mlx4_en_cq *cq;
1399 unsigned long packets;
1400 unsigned long rate;
1401 unsigned long avg_pkt_size;
1402 unsigned long rx_packets;
1403 unsigned long rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001404 unsigned long rx_pkt_diff;
1405 int moder_time;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001406 int ring, err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001407
1408 if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ)
1409 return;
1410
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001411 for (ring = 0; ring < priv->rx_ring_num; ring++) {
1412 spin_lock_bh(&priv->stats_lock);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001413 rx_packets = priv->rx_ring[ring]->packets;
1414 rx_bytes = priv->rx_ring[ring]->bytes;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001415 spin_unlock_bh(&priv->stats_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001416
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001417 rx_pkt_diff = ((unsigned long) (rx_packets -
1418 priv->last_moder_packets[ring]));
1419 packets = rx_pkt_diff;
1420 rate = packets * HZ / period;
1421 avg_pkt_size = packets ? ((unsigned long) (rx_bytes -
1422 priv->last_moder_bytes[ring])) / packets : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001423
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001424 /* Apply auto-moderation only when packet rate
1425 * exceeds a rate that it matters */
1426 if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) &&
1427 avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001428 if (rate < priv->pkt_rate_low)
1429 moder_time = priv->rx_usecs_low;
1430 else if (rate > priv->pkt_rate_high)
1431 moder_time = priv->rx_usecs_high;
1432 else
1433 moder_time = (rate - priv->pkt_rate_low) *
1434 (priv->rx_usecs_high - priv->rx_usecs_low) /
1435 (priv->pkt_rate_high - priv->pkt_rate_low) +
1436 priv->rx_usecs_low;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001437 } else {
1438 moder_time = priv->rx_usecs_low;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001439 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001440
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001441 if (moder_time != priv->last_moder_time[ring]) {
1442 priv->last_moder_time[ring] = moder_time;
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001443 cq = priv->rx_cq[ring];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001444 cq->moder_time = moder_time;
Sagi Grimberga1c66932013-06-04 05:13:26 +00001445 cq->moder_cnt = priv->rx_frames;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001446 err = mlx4_en_set_cq_moder(priv, cq);
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001447 if (err)
Yan Burman48e551f2013-02-07 02:25:21 +00001448 en_err(priv, "Failed modifying moderation for cq:%d\n",
1449 ring);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001450 }
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001451 priv->last_moder_packets[ring] = rx_packets;
1452 priv->last_moder_bytes[ring] = rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001453 }
1454
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001455 priv->last_moder_jiffies = jiffies;
1456}
1457
1458static void mlx4_en_do_get_stats(struct work_struct *work)
1459{
Jean Delvarebf6aede2009-04-02 16:56:54 -07001460 struct delayed_work *delay = to_delayed_work(work);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001461 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
1462 stats_task);
1463 struct mlx4_en_dev *mdev = priv->mdev;
1464 int err;
1465
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001466 mutex_lock(&mdev->state_lock);
1467 if (mdev->device_up) {
Jack Morgenstein6123db2e2013-06-25 12:09:30 +03001468 if (priv->port_up) {
1469 err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0);
1470 if (err)
1471 en_dbg(HW, priv, "Could not update stats\n");
Eugenia Emantayev2d518372013-01-24 01:54:14 +00001472
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001473 mlx4_en_auto_moderation(priv);
Jack Morgenstein6123db2e2013-06-25 12:09:30 +03001474 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001475
1476 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
1477 }
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +00001478 if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
Yan Burmanbfa8ab42013-03-07 03:46:55 +00001479 mlx4_en_do_set_mac(priv);
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +00001480 mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
1481 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001482 mutex_unlock(&mdev->state_lock);
1483}
1484
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001485/* mlx4_en_service_task - Run service task for tasks that needed to be done
1486 * periodically
1487 */
1488static void mlx4_en_service_task(struct work_struct *work)
1489{
1490 struct delayed_work *delay = to_delayed_work(work);
1491 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
1492 service_task);
1493 struct mlx4_en_dev *mdev = priv->mdev;
1494
1495 mutex_lock(&mdev->state_lock);
1496 if (mdev->device_up) {
Amir Vadaidc8142e2013-04-25 05:22:24 +00001497 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
1498 mlx4_en_ptp_overflow_check(mdev);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001499
1500 queue_delayed_work(mdev->workqueue, &priv->service_task,
1501 SERVICE_TASK_DELAY);
1502 }
1503 mutex_unlock(&mdev->state_lock);
1504}
1505
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001506static void mlx4_en_linkstate(struct work_struct *work)
1507{
1508 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1509 linkstate_task);
1510 struct mlx4_en_dev *mdev = priv->mdev;
1511 int linkstate = priv->link_state;
1512
1513 mutex_lock(&mdev->state_lock);
1514 /* If observable port state changed set carrier state and
1515 * report to system log */
1516 if (priv->last_link_state != linkstate) {
1517 if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001518 en_info(priv, "Link Down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001519 netif_carrier_off(priv->dev);
1520 } else {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001521 en_info(priv, "Link Up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001522 netif_carrier_on(priv->dev);
1523 }
1524 }
1525 priv->last_link_state = linkstate;
1526 mutex_unlock(&mdev->state_lock);
1527}
1528
1529
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001530int mlx4_en_start_port(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001531{
1532 struct mlx4_en_priv *priv = netdev_priv(dev);
1533 struct mlx4_en_dev *mdev = priv->mdev;
1534 struct mlx4_en_cq *cq;
1535 struct mlx4_en_tx_ring *tx_ring;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001536 int rx_index = 0;
1537 int tx_index = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001538 int err = 0;
1539 int i;
1540 int j;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001541 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001542
1543 if (priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001544 en_dbg(DRV, priv, "start port called while port already up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001545 return 0;
1546 }
1547
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001548 INIT_LIST_HEAD(&priv->mc_list);
1549 INIT_LIST_HEAD(&priv->curr_list);
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001550 INIT_LIST_HEAD(&priv->ethtool_list);
1551 memset(&priv->ethtool_rules[0], 0,
1552 sizeof(struct ethtool_flow_id) * MAX_NUM_OF_FS_RULES);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001553
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001554 /* Calculate Rx buf size */
1555 dev->mtu = min(dev->mtu, priv->max_mtu);
1556 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001557 en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_skb_size);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001558
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001559 /* Configure rx cq's and rings */
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001560 err = mlx4_en_activate_rx_rings(priv);
1561 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001562 en_err(priv, "Failed to activate RX rings\n");
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001563 return err;
1564 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001565 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001566 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001567
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001568 mlx4_en_cq_init_lock(cq);
1569
Alexander Guller76532d02011-10-09 05:26:31 +00001570 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001571 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001572 en_err(priv, "Failed activating Rx CQ\n");
Yevgeny Petrilina4233302009-04-26 20:41:34 +00001573 goto cq_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001574 }
1575 for (j = 0; j < cq->size; j++)
1576 cq->buf[j].owner_sr_opcode = MLX4_CQE_OWNER_MASK;
1577 err = mlx4_en_set_cq_moder(priv, cq);
1578 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07001579 en_err(priv, "Failed setting cq moderation parameters\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001580 mlx4_en_deactivate_cq(priv, cq);
1581 goto cq_err;
1582 }
1583 mlx4_en_arm_cq(priv, cq);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001584 priv->rx_ring[i]->cqn = cq->mcq.cqn;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001585 ++rx_index;
1586 }
1587
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001588 /* Set qp number */
1589 en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port);
Yan Burman16a10ff2013-02-07 02:25:22 +00001590 err = mlx4_en_get_qp(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001591 if (err) {
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001592 en_err(priv, "Failed getting eth qp\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001593 goto cq_err;
1594 }
1595 mdev->mac_removed[priv->port] = 0;
1596
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001597 err = mlx4_en_config_rss_steer(priv);
1598 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001599 en_err(priv, "Failed configuring rss steering\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001600 goto mac_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001601 }
1602
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001603 err = mlx4_en_create_drop_qp(priv);
1604 if (err)
1605 goto rss_err;
1606
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001607 /* Configure tx cq's and rings */
1608 for (i = 0; i < priv->tx_ring_num; i++) {
1609 /* Configure cq */
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001610 cq = priv->tx_cq[i];
Alexander Guller76532d02011-10-09 05:26:31 +00001611 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001612 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001613 en_err(priv, "Failed allocating Tx CQ\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001614 goto tx_err;
1615 }
1616 err = mlx4_en_set_cq_moder(priv, cq);
1617 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07001618 en_err(priv, "Failed setting cq moderation parameters\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001619 mlx4_en_deactivate_cq(priv, cq);
1620 goto tx_err;
1621 }
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001622 en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001623 cq->buf->wqe_index = cpu_to_be16(0xffff);
1624
1625 /* Configure ring */
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001626 tx_ring = priv->tx_ring[i];
Amir Vadai0e98b522012-04-04 21:33:24 +00001627 err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn,
Amir Vadaid3179662012-12-02 03:49:23 +00001628 i / priv->num_tx_rings_p_up);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001629 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001630 en_err(priv, "Failed allocating Tx ring\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001631 mlx4_en_deactivate_cq(priv, cq);
1632 goto tx_err;
1633 }
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001634 tx_ring->tx_queue = netdev_get_tx_queue(dev, i);
Yevgeny Petriline22979d2012-04-23 02:18:39 +00001635
1636 /* Arm CQ for TX completions */
1637 mlx4_en_arm_cq(priv, cq);
1638
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001639 /* Set initial ownership of all Tx TXBBs to SW (1) */
1640 for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE)
1641 *((u32 *) (tx_ring->buf + j)) = 0xffffffff;
1642 ++tx_index;
1643 }
1644
1645 /* Configure port */
1646 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
1647 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001648 priv->prof->tx_pause,
1649 priv->prof->tx_ppp,
1650 priv->prof->rx_pause,
1651 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001652 if (err) {
Yan Burman48e551f2013-02-07 02:25:21 +00001653 en_err(priv, "Failed setting port general configurations for port %d, with error %d\n",
1654 priv->port, err);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001655 goto tx_err;
1656 }
1657 /* Set default qp number */
1658 err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0);
1659 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001660 en_err(priv, "Failed setting default qp numbers\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001661 goto tx_err;
1662 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001663
Or Gerlitz837052d2013-12-23 16:09:44 +02001664 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
Or Gerlitz1b136de2014-03-27 14:02:04 +02001665 err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC, 1);
Or Gerlitz837052d2013-12-23 16:09:44 +02001666 if (err) {
1667 en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n",
1668 err);
1669 goto tx_err;
1670 }
1671 }
1672
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001673 /* Init port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001674 en_dbg(HW, priv, "Initializing port\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001675 err = mlx4_INIT_PORT(mdev->dev, priv->port);
1676 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001677 en_err(priv, "Failed Initializing port\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001678 goto tx_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001679 }
1680
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001681 /* Attach rx QP to bradcast address */
1682 memset(&mc_list[10], 0xff, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001683 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001684 if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001685 priv->port, 0, MLX4_PROT_ETH,
1686 &priv->broadcast_id))
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001687 mlx4_warn(mdev, "Failed Attaching Broadcast\n");
1688
Herbert Xub5845f92011-03-27 01:01:26 +00001689 /* Must redo promiscuous mode setup. */
1690 priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC);
1691
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001692 /* Schedule multicast task to populate multicast list */
Yan Burman0eb74fd2013-02-07 02:25:23 +00001693 queue_work(mdev->workqueue, &priv->rx_mode_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001694
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +00001695 mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap);
1696
Or Gerlitza66132f2014-04-01 11:27:13 +03001697#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02001698 if (priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS)
1699 vxlan_get_rx_port(dev);
Or Gerlitza66132f2014-04-01 11:27:13 +03001700#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001701 priv->port_up = true;
Yevgeny Petrilina11faac2009-06-20 22:15:46 +00001702 netif_tx_start_all_queues(dev);
Amir Vadai3484aac2013-01-30 23:07:11 +00001703 netif_device_attach(dev);
1704
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001705 return 0;
1706
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001707tx_err:
1708 while (tx_index--) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001709 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[tx_index]);
1710 mlx4_en_deactivate_cq(priv, priv->tx_cq[tx_index]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001711 }
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001712 mlx4_en_destroy_drop_qp(priv);
1713rss_err:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001714 mlx4_en_release_rss_steer(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001715mac_err:
Yan Burman16a10ff2013-02-07 02:25:22 +00001716 mlx4_en_put_qp(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001717cq_err:
1718 while (rx_index--)
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001719 mlx4_en_deactivate_cq(priv, priv->rx_cq[rx_index]);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001720 for (i = 0; i < priv->rx_ring_num; i++)
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001721 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001722
1723 return err; /* need to close devices */
1724}
1725
1726
Amir Vadai3484aac2013-01-30 23:07:11 +00001727void mlx4_en_stop_port(struct net_device *dev, int detach)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001728{
1729 struct mlx4_en_priv *priv = netdev_priv(dev);
1730 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001731 struct mlx4_en_mc_list *mclist, *tmp;
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001732 struct ethtool_flow_id *flow, *tmp_flow;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001733 int i;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001734 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001735
1736 if (!priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001737 en_dbg(DRV, priv, "stop port called while port already down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001738 return;
1739 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001740
Eugenia Emantayev0cc5c8b2013-06-25 12:09:33 +03001741 /* close port*/
1742 mlx4_CLOSE_PORT(mdev->dev, priv->port);
1743
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001744 /* Synchronize with tx routine */
1745 netif_tx_lock_bh(dev);
Amir Vadai3484aac2013-01-30 23:07:11 +00001746 if (detach)
1747 netif_device_detach(dev);
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001748 netif_tx_stop_all_queues(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001749 netif_tx_unlock_bh(dev);
1750
Amir Vadai3484aac2013-01-30 23:07:11 +00001751 netif_tx_disable(dev);
1752
Yevgeny Petrilin7c287382010-08-24 03:45:45 +00001753 /* Set port as not active */
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001754 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001755
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001756 /* Promsicuous mode */
1757 if (mdev->dev->caps.steering_mode ==
1758 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1759 priv->flags &= ~(MLX4_EN_FLAG_PROMISC |
1760 MLX4_EN_FLAG_MC_PROMISC);
1761 mlx4_flow_steer_promisc_remove(mdev->dev,
1762 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001763 MLX4_FS_ALL_DEFAULT);
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001764 mlx4_flow_steer_promisc_remove(mdev->dev,
1765 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001766 MLX4_FS_MC_DEFAULT);
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001767 } else if (priv->flags & MLX4_EN_FLAG_PROMISC) {
1768 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
1769
1770 /* Disable promiscouos mode */
1771 mlx4_unicast_promisc_remove(mdev->dev, priv->base_qpn,
1772 priv->port);
1773
1774 /* Disable Multicast promisc */
1775 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
1776 mlx4_multicast_promisc_remove(mdev->dev, priv->base_qpn,
1777 priv->port);
1778 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
1779 }
1780 }
1781
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001782 /* Detach All multicasts */
1783 memset(&mc_list[10], 0xff, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001784 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001785 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001786 MLX4_PROT_ETH, priv->broadcast_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001787 list_for_each_entry(mclist, &priv->curr_list, list) {
1788 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001789 mc_list[5] = priv->port;
1790 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001791 mc_list, MLX4_PROT_ETH, mclist->reg_id);
Or Gerlitzde123262014-03-13 14:52:15 +02001792 if (mclist->tunnel_reg_id)
1793 mlx4_flow_detach(mdev->dev, mclist->tunnel_reg_id);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001794 }
1795 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001796 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
1797 list_del(&mclist->list);
1798 kfree(mclist);
1799 }
1800
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001801 /* Flush multicast filter */
1802 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG);
1803
Hadar Hen Zion6efb5fa2013-03-21 05:55:53 +00001804 /* Remove flow steering rules for the port*/
1805 if (mdev->dev->caps.steering_mode ==
1806 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1807 ASSERT_RTNL();
1808 list_for_each_entry_safe(flow, tmp_flow,
1809 &priv->ethtool_list, list) {
1810 mlx4_flow_detach(mdev->dev, flow->id);
1811 list_del(&flow->list);
1812 }
1813 }
1814
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001815 mlx4_en_destroy_drop_qp(priv);
1816
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001817 /* Free TX Rings */
1818 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001819 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[i]);
1820 mlx4_en_deactivate_cq(priv, priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001821 }
1822 msleep(10);
1823
1824 for (i = 0; i < priv->tx_ring_num; i++)
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001825 mlx4_en_free_tx_buf(dev, priv->tx_ring[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001826
1827 /* Free RSS qps */
1828 mlx4_en_release_rss_steer(priv);
1829
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001830 /* Unregister Mac address for the port */
Yan Burman16a10ff2013-02-07 02:25:22 +00001831 mlx4_en_put_qp(priv);
Or Gerlitz5930e8d2013-10-15 16:55:22 +02001832 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN))
Matan Barak955154f2013-01-30 23:07:10 +00001833 mdev->mac_removed[priv->port] = 1;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001834
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001835 /* Free RX Rings */
1836 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001837 struct mlx4_en_cq *cq = priv->rx_cq[i];
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001838
1839 local_bh_disable();
1840 while (!mlx4_en_cq_lock_napi(cq)) {
1841 pr_info("CQ %d locked\n", i);
1842 mdelay(1);
1843 }
1844 local_bh_enable();
1845
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001846 while (test_bit(NAPI_STATE_SCHED, &cq->napi.state))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001847 msleep(1);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001848 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]);
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001849 mlx4_en_deactivate_cq(priv, cq);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001850 }
1851}
1852
1853static void mlx4_en_restart(struct work_struct *work)
1854{
1855 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1856 watchdog_task);
1857 struct mlx4_en_dev *mdev = priv->mdev;
1858 struct net_device *dev = priv->dev;
1859
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001860 en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001861
1862 mutex_lock(&mdev->state_lock);
1863 if (priv->port_up) {
Amir Vadai3484aac2013-01-30 23:07:11 +00001864 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001865 if (mlx4_en_start_port(dev))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001866 en_err(priv, "Failed restarting port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001867 }
1868 mutex_unlock(&mdev->state_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001869}
1870
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001871static void mlx4_en_clear_stats(struct net_device *dev)
1872{
1873 struct mlx4_en_priv *priv = netdev_priv(dev);
1874 struct mlx4_en_dev *mdev = priv->mdev;
1875 int i;
1876
1877 if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1))
1878 en_dbg(HW, priv, "Failed dumping statistics\n");
1879
1880 memset(&priv->stats, 0, sizeof(priv->stats));
1881 memset(&priv->pstats, 0, sizeof(priv->pstats));
1882 memset(&priv->pkstats, 0, sizeof(priv->pkstats));
1883 memset(&priv->port_stats, 0, sizeof(priv->port_stats));
1884
1885 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001886 priv->tx_ring[i]->bytes = 0;
1887 priv->tx_ring[i]->packets = 0;
1888 priv->tx_ring[i]->tx_csum = 0;
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001889 }
1890 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001891 priv->rx_ring[i]->bytes = 0;
1892 priv->rx_ring[i]->packets = 0;
1893 priv->rx_ring[i]->csum_ok = 0;
1894 priv->rx_ring[i]->csum_none = 0;
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001895 }
1896}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001897
1898static int mlx4_en_open(struct net_device *dev)
1899{
1900 struct mlx4_en_priv *priv = netdev_priv(dev);
1901 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001902 int err = 0;
1903
1904 mutex_lock(&mdev->state_lock);
1905
1906 if (!mdev->device_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001907 en_err(priv, "Cannot open - device down/disabled\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001908 err = -EBUSY;
1909 goto out;
1910 }
1911
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001912 /* Reset HW statistics and SW counters */
1913 mlx4_en_clear_stats(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001914
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001915 err = mlx4_en_start_port(dev);
1916 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001917 en_err(priv, "Failed starting port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001918
1919out:
1920 mutex_unlock(&mdev->state_lock);
1921 return err;
1922}
1923
1924
1925static int mlx4_en_close(struct net_device *dev)
1926{
1927 struct mlx4_en_priv *priv = netdev_priv(dev);
1928 struct mlx4_en_dev *mdev = priv->mdev;
1929
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001930 en_dbg(IFDOWN, priv, "Close port called\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001931
1932 mutex_lock(&mdev->state_lock);
1933
Amir Vadai3484aac2013-01-30 23:07:11 +00001934 mlx4_en_stop_port(dev, 0);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001935 netif_carrier_off(dev);
1936
1937 mutex_unlock(&mdev->state_lock);
1938 return 0;
1939}
1940
Alexander Gullerfe0af032011-10-09 05:26:46 +00001941void mlx4_en_free_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001942{
1943 int i;
1944
Amir Vadai1eb8c692012-07-18 22:33:52 +00001945#ifdef CONFIG_RFS_ACCEL
1946 free_irq_cpu_rmap(priv->dev->rx_cpu_rmap);
1947 priv->dev->rx_cpu_rmap = NULL;
1948#endif
1949
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001950 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001951 if (priv->tx_ring && priv->tx_ring[i])
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001952 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001953 if (priv->tx_cq && priv->tx_cq[i])
Alexander Gullerfe0af032011-10-09 05:26:46 +00001954 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001955 }
1956
1957 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001958 if (priv->rx_ring[i])
Thadeu Lima de Souza Cascardo68355f72012-02-06 08:39:49 +00001959 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
1960 priv->prof->rx_ring_size, priv->stride);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001961 if (priv->rx_cq[i])
Alexander Gullerfe0af032011-10-09 05:26:46 +00001962 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001963 }
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001964
1965 if (priv->base_tx_qpn) {
1966 mlx4_qp_release_range(priv->mdev->dev, priv->base_tx_qpn, priv->tx_ring_num);
1967 priv->base_tx_qpn = 0;
1968 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001969}
1970
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001971int mlx4_en_alloc_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001972{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001973 struct mlx4_en_port_profile *prof = priv->prof;
1974 int i;
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001975 int err;
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001976 int node;
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001977
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001978 err = mlx4_qp_reserve_range(priv->mdev->dev, priv->tx_ring_num, 256, &priv->base_tx_qpn);
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001979 if (err) {
1980 en_err(priv, "failed reserving range for TX rings\n");
1981 return err;
1982 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001983
1984 /* Create tx Rings */
1985 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001986 node = cpu_to_node(i % num_online_cpus());
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001987 if (mlx4_en_create_cq(priv, &priv->tx_cq[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001988 prof->tx_ring_size, i, TX, node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001989 goto err;
1990
Ido Shamayd03a68f2013-12-19 21:20:14 +02001991 if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i],
1992 priv->base_tx_qpn + i,
1993 prof->tx_ring_size, TXBB_SIZE,
1994 node, i))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001995 goto err;
1996 }
1997
1998 /* Create rx Rings */
1999 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev163561a2013-11-07 12:19:54 +02002000 node = cpu_to_node(i % num_online_cpus());
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002001 if (mlx4_en_create_cq(priv, &priv->rx_cq[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02002002 prof->rx_ring_size, i, RX, node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002003 goto err;
2004
2005 if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02002006 prof->rx_ring_size, priv->stride,
2007 node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002008 goto err;
2009 }
2010
Amir Vadai1eb8c692012-07-18 22:33:52 +00002011#ifdef CONFIG_RFS_ACCEL
Amir Vadaia229e482013-03-07 03:46:57 +00002012 if (priv->mdev->dev->caps.comp_pool) {
2013 priv->dev->rx_cpu_rmap = alloc_irq_cpu_rmap(priv->mdev->dev->caps.comp_pool);
2014 if (!priv->dev->rx_cpu_rmap)
2015 goto err;
2016 }
Amir Vadai1eb8c692012-07-18 22:33:52 +00002017#endif
2018
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002019 return 0;
2020
2021err:
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002022 en_err(priv, "Failed to allocate NIC resources\n");
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002023 for (i = 0; i < priv->rx_ring_num; i++) {
2024 if (priv->rx_ring[i])
2025 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
2026 prof->rx_ring_size,
2027 priv->stride);
2028 if (priv->rx_cq[i])
2029 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
2030 }
2031 for (i = 0; i < priv->tx_ring_num; i++) {
2032 if (priv->tx_ring[i])
2033 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
2034 if (priv->tx_cq[i])
2035 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
2036 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002037 return -ENOMEM;
2038}
2039
2040
2041void mlx4_en_destroy_netdev(struct net_device *dev)
2042{
2043 struct mlx4_en_priv *priv = netdev_priv(dev);
2044 struct mlx4_en_dev *mdev = priv->mdev;
2045
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002046 en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002047
2048 /* Unregister device - this will close the port if it was up */
2049 if (priv->registered)
2050 unregister_netdev(dev);
2051
2052 if (priv->allocated)
2053 mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE);
2054
2055 cancel_delayed_work(&priv->stats_task);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00002056 cancel_delayed_work(&priv->service_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002057 /* flush any pending task for this netdev */
2058 flush_workqueue(mdev->workqueue);
2059
2060 /* Detach the netdev so tasks would not attempt to access it */
2061 mutex_lock(&mdev->state_lock);
2062 mdev->pndev[priv->port] = NULL;
2063 mutex_unlock(&mdev->state_lock);
2064
Alexander Gullerfe0af032011-10-09 05:26:46 +00002065 mlx4_en_free_resources(priv);
Amir Vadai564c2742012-04-04 21:33:26 +00002066
Amir Vadaibc6a4742012-05-17 00:58:10 +00002067 kfree(priv->tx_ring);
2068 kfree(priv->tx_cq);
2069
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002070 free_netdev(dev);
2071}
2072
2073static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
2074{
2075 struct mlx4_en_priv *priv = netdev_priv(dev);
2076 struct mlx4_en_dev *mdev = priv->mdev;
2077 int err = 0;
2078
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002079 en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002080 dev->mtu, new_mtu);
2081
2082 if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002083 en_err(priv, "Bad MTU size:%d.\n", new_mtu);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002084 return -EPERM;
2085 }
2086 dev->mtu = new_mtu;
2087
2088 if (netif_running(dev)) {
2089 mutex_lock(&mdev->state_lock);
2090 if (!mdev->device_up) {
2091 /* NIC is probably restarting - let watchdog task reset
2092 * the port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002093 en_dbg(DRV, priv, "Change MTU called with card down!?\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002094 } else {
Amir Vadai3484aac2013-01-30 23:07:11 +00002095 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002096 err = mlx4_en_start_port(dev);
2097 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002098 en_err(priv, "Failed restarting port:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002099 priv->port);
2100 queue_work(mdev->workqueue, &priv->watchdog_task);
2101 }
2102 }
2103 mutex_unlock(&mdev->state_lock);
2104 }
2105 return 0;
2106}
2107
Ben Hutchings100dbda2013-11-18 23:13:31 +00002108static int mlx4_en_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
Amir Vadaiec693d42013-04-23 06:06:49 +00002109{
2110 struct mlx4_en_priv *priv = netdev_priv(dev);
2111 struct mlx4_en_dev *mdev = priv->mdev;
2112 struct hwtstamp_config config;
2113
2114 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
2115 return -EFAULT;
2116
2117 /* reserved for future extensions */
2118 if (config.flags)
2119 return -EINVAL;
2120
2121 /* device doesn't support time stamping */
2122 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS))
2123 return -EINVAL;
2124
2125 /* TX HW timestamp */
2126 switch (config.tx_type) {
2127 case HWTSTAMP_TX_OFF:
2128 case HWTSTAMP_TX_ON:
2129 break;
2130 default:
2131 return -ERANGE;
2132 }
2133
2134 /* RX HW timestamp */
2135 switch (config.rx_filter) {
2136 case HWTSTAMP_FILTER_NONE:
2137 break;
2138 case HWTSTAMP_FILTER_ALL:
2139 case HWTSTAMP_FILTER_SOME:
2140 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2141 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2142 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2143 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2144 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2145 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2146 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2147 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
2148 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
2149 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2150 case HWTSTAMP_FILTER_PTP_V2_SYNC:
2151 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
2152 config.rx_filter = HWTSTAMP_FILTER_ALL;
2153 break;
2154 default:
2155 return -ERANGE;
2156 }
2157
2158 if (mlx4_en_timestamp_config(dev, config.tx_type, config.rx_filter)) {
2159 config.tx_type = HWTSTAMP_TX_OFF;
2160 config.rx_filter = HWTSTAMP_FILTER_NONE;
2161 }
2162
2163 return copy_to_user(ifr->ifr_data, &config,
2164 sizeof(config)) ? -EFAULT : 0;
2165}
2166
Ben Hutchings100dbda2013-11-18 23:13:31 +00002167static int mlx4_en_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
2168{
2169 struct mlx4_en_priv *priv = netdev_priv(dev);
2170
2171 return copy_to_user(ifr->ifr_data, &priv->hwtstamp_config,
2172 sizeof(priv->hwtstamp_config)) ? -EFAULT : 0;
2173}
2174
Amir Vadaiec693d42013-04-23 06:06:49 +00002175static int mlx4_en_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2176{
2177 switch (cmd) {
2178 case SIOCSHWTSTAMP:
Ben Hutchings100dbda2013-11-18 23:13:31 +00002179 return mlx4_en_hwtstamp_set(dev, ifr);
2180 case SIOCGHWTSTAMP:
2181 return mlx4_en_hwtstamp_get(dev, ifr);
Amir Vadaiec693d42013-04-23 06:06:49 +00002182 default:
2183 return -EOPNOTSUPP;
2184 }
2185}
2186
Amir Vadai60d6fe92011-11-26 19:55:19 +00002187static int mlx4_en_set_features(struct net_device *netdev,
2188 netdev_features_t features)
2189{
2190 struct mlx4_en_priv *priv = netdev_priv(netdev);
2191
2192 if (features & NETIF_F_LOOPBACK)
2193 priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
2194 else
2195 priv->ctrl_flags &=
2196 cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK);
2197
Yan Burman79aeacc2013-02-07 02:25:19 +00002198 mlx4_en_update_loopback_state(netdev, features);
2199
Amir Vadai60d6fe92011-11-26 19:55:19 +00002200 return 0;
2201
2202}
2203
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002204static int mlx4_en_set_vf_mac(struct net_device *dev, int queue, u8 *mac)
2205{
2206 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2207 struct mlx4_en_dev *mdev = en_priv->mdev;
Eugenia Emantayev98133372014-03-02 10:25:01 +02002208 u64 mac_u64 = mlx4_mac_to_u64(mac);
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002209
2210 if (!is_valid_ether_addr(mac))
2211 return -EINVAL;
2212
2213 return mlx4_set_vf_mac(mdev->dev, en_priv->port, queue, mac_u64);
2214}
2215
Rony Efraim3f7fb022013-04-25 05:22:28 +00002216static int mlx4_en_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos)
2217{
2218 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2219 struct mlx4_en_dev *mdev = en_priv->mdev;
2220
2221 return mlx4_set_vf_vlan(mdev->dev, en_priv->port, vf, vlan, qos);
2222}
2223
Rony Efraime6b6a232013-04-25 05:22:29 +00002224static int mlx4_en_set_vf_spoofchk(struct net_device *dev, int vf, bool setting)
2225{
2226 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2227 struct mlx4_en_dev *mdev = en_priv->mdev;
2228
2229 return mlx4_set_vf_spoofchk(mdev->dev, en_priv->port, vf, setting);
2230}
2231
Rony Efraim2cccb9e2013-04-25 05:22:30 +00002232static int mlx4_en_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_info *ivf)
2233{
2234 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2235 struct mlx4_en_dev *mdev = en_priv->mdev;
2236
2237 return mlx4_get_vf_config(mdev->dev, en_priv->port, vf, ivf);
2238}
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002239
Rony Efraim948e3062013-06-13 13:19:11 +03002240static int mlx4_en_set_vf_link_state(struct net_device *dev, int vf, int link_state)
2241{
2242 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2243 struct mlx4_en_dev *mdev = en_priv->mdev;
2244
2245 return mlx4_set_vf_link_state(mdev->dev, en_priv->port, vf, link_state);
2246}
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002247
2248#define PORT_ID_BYTE_LEN 8
2249static int mlx4_en_get_phys_port_id(struct net_device *dev,
2250 struct netdev_phys_port_id *ppid)
2251{
2252 struct mlx4_en_priv *priv = netdev_priv(dev);
2253 struct mlx4_dev *mdev = priv->mdev->dev;
2254 int i;
2255 u64 phys_port_id = mdev->caps.phys_port_id[priv->port];
2256
2257 if (!phys_port_id)
2258 return -EOPNOTSUPP;
2259
2260 ppid->id_len = sizeof(phys_port_id);
2261 for (i = PORT_ID_BYTE_LEN - 1; i >= 0; --i) {
2262 ppid->id[i] = phys_port_id & 0xff;
2263 phys_port_id >>= 8;
2264 }
2265 return 0;
2266}
2267
Or Gerlitza66132f2014-04-01 11:27:13 +03002268#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02002269static void mlx4_en_add_vxlan_offloads(struct work_struct *work)
2270{
2271 int ret;
2272 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
2273 vxlan_add_task);
2274
2275 ret = mlx4_config_vxlan_port(priv->mdev->dev, priv->vxlan_port);
2276 if (ret)
2277 goto out;
2278
2279 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port,
2280 VXLAN_STEER_BY_OUTER_MAC, 1);
2281out:
2282 if (ret)
2283 en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret);
2284}
2285
2286static void mlx4_en_del_vxlan_offloads(struct work_struct *work)
2287{
2288 int ret;
2289 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
2290 vxlan_del_task);
2291
2292 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port,
2293 VXLAN_STEER_BY_OUTER_MAC, 0);
2294 if (ret)
2295 en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret);
2296
2297 priv->vxlan_port = 0;
2298}
2299
2300static void mlx4_en_add_vxlan_port(struct net_device *dev,
2301 sa_family_t sa_family, __be16 port)
2302{
2303 struct mlx4_en_priv *priv = netdev_priv(dev);
2304 __be16 current_port;
2305
2306 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS))
2307 return;
2308
2309 if (sa_family == AF_INET6)
2310 return;
2311
2312 current_port = priv->vxlan_port;
2313 if (current_port && current_port != port) {
2314 en_warn(priv, "vxlan port %d configured, can't add port %d\n",
2315 ntohs(current_port), ntohs(port));
2316 return;
2317 }
2318
2319 priv->vxlan_port = port;
2320 queue_work(priv->mdev->workqueue, &priv->vxlan_add_task);
2321}
2322
2323static void mlx4_en_del_vxlan_port(struct net_device *dev,
2324 sa_family_t sa_family, __be16 port)
2325{
2326 struct mlx4_en_priv *priv = netdev_priv(dev);
2327 __be16 current_port;
2328
2329 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
2330 return;
2331
2332 if (sa_family == AF_INET6)
2333 return;
2334
2335 current_port = priv->vxlan_port;
2336 if (current_port != port) {
2337 en_dbg(DRV, priv, "vxlan port %d isn't configured, ignoring\n", ntohs(port));
2338 return;
2339 }
2340
2341 queue_work(priv->mdev->workqueue, &priv->vxlan_del_task);
2342}
Or Gerlitza66132f2014-04-01 11:27:13 +03002343#endif
Or Gerlitz1b136de2014-03-27 14:02:04 +02002344
Stephen Hemminger3addc562008-11-21 17:30:58 -08002345static const struct net_device_ops mlx4_netdev_ops = {
2346 .ndo_open = mlx4_en_open,
2347 .ndo_stop = mlx4_en_close,
2348 .ndo_start_xmit = mlx4_en_xmit,
Yevgeny Petrilinf813cad2009-06-01 23:24:07 +00002349 .ndo_select_queue = mlx4_en_select_queue,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002350 .ndo_get_stats = mlx4_en_get_stats,
Yan Burman0eb74fd2013-02-07 02:25:23 +00002351 .ndo_set_rx_mode = mlx4_en_set_rx_mode,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002352 .ndo_set_mac_address = mlx4_en_set_mac,
Stephen Hemminger52255bb2009-01-09 10:45:37 +00002353 .ndo_validate_addr = eth_validate_addr,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002354 .ndo_change_mtu = mlx4_en_change_mtu,
Amir Vadaiec693d42013-04-23 06:06:49 +00002355 .ndo_do_ioctl = mlx4_en_ioctl,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002356 .ndo_tx_timeout = mlx4_en_tx_timeout,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002357 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
2358 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
2359#ifdef CONFIG_NET_POLL_CONTROLLER
2360 .ndo_poll_controller = mlx4_en_netpoll,
2361#endif
Amir Vadai60d6fe92011-11-26 19:55:19 +00002362 .ndo_set_features = mlx4_en_set_features,
Amir Vadai897d7842012-04-04 21:33:27 +00002363 .ndo_setup_tc = mlx4_en_setup_tc,
Amir Vadai1eb8c692012-07-18 22:33:52 +00002364#ifdef CONFIG_RFS_ACCEL
2365 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2366#endif
Cong Wange0d10952013-08-01 11:10:25 +08002367#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03002368 .ndo_busy_poll = mlx4_en_low_latency_recv,
Amir Vadai9e77a2b2013-06-18 16:18:27 +03002369#endif
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002370 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
Or Gerlitza66132f2014-04-01 11:27:13 +03002371#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02002372 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port,
2373 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port,
Or Gerlitza66132f2014-04-01 11:27:13 +03002374#endif
Stephen Hemminger3addc562008-11-21 17:30:58 -08002375};
2376
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002377static const struct net_device_ops mlx4_netdev_ops_master = {
2378 .ndo_open = mlx4_en_open,
2379 .ndo_stop = mlx4_en_close,
2380 .ndo_start_xmit = mlx4_en_xmit,
2381 .ndo_select_queue = mlx4_en_select_queue,
2382 .ndo_get_stats = mlx4_en_get_stats,
2383 .ndo_set_rx_mode = mlx4_en_set_rx_mode,
2384 .ndo_set_mac_address = mlx4_en_set_mac,
2385 .ndo_validate_addr = eth_validate_addr,
2386 .ndo_change_mtu = mlx4_en_change_mtu,
2387 .ndo_tx_timeout = mlx4_en_tx_timeout,
2388 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
2389 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
2390 .ndo_set_vf_mac = mlx4_en_set_vf_mac,
Rony Efraim3f7fb022013-04-25 05:22:28 +00002391 .ndo_set_vf_vlan = mlx4_en_set_vf_vlan,
Rony Efraime6b6a232013-04-25 05:22:29 +00002392 .ndo_set_vf_spoofchk = mlx4_en_set_vf_spoofchk,
Rony Efraim948e3062013-06-13 13:19:11 +03002393 .ndo_set_vf_link_state = mlx4_en_set_vf_link_state,
Rony Efraim2cccb9e2013-04-25 05:22:30 +00002394 .ndo_get_vf_config = mlx4_en_get_vf_config,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002395#ifdef CONFIG_NET_POLL_CONTROLLER
2396 .ndo_poll_controller = mlx4_en_netpoll,
2397#endif
2398 .ndo_set_features = mlx4_en_set_features,
2399 .ndo_setup_tc = mlx4_en_setup_tc,
2400#ifdef CONFIG_RFS_ACCEL
2401 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2402#endif
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002403 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002404};
2405
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002406int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
2407 struct mlx4_en_port_profile *prof)
2408{
2409 struct net_device *dev;
2410 struct mlx4_en_priv *priv;
Yan Burmanc07cb4b2013-02-07 02:25:25 +00002411 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002412 int err;
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002413 u64 mac_u64;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002414
Tom Herbertf1593d22011-01-09 19:36:36 +00002415 dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv),
Amir Vadaid3179662012-12-02 03:49:23 +00002416 MAX_TX_RINGS, MAX_RX_RINGS);
Joe Perches41de8d42012-01-29 13:47:52 +00002417 if (dev == NULL)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002418 return -ENOMEM;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002419
Amir Vadaid3179662012-12-02 03:49:23 +00002420 netif_set_real_num_tx_queues(dev, prof->tx_ring_num);
2421 netif_set_real_num_rx_queues(dev, prof->rx_ring_num);
2422
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002423 SET_NETDEV_DEV(dev, &mdev->dev->pdev->dev);
Amir Vadai76a066f2014-02-25 18:17:51 +02002424 dev->dev_port = port - 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002425
2426 /*
2427 * Initialize driver private data
2428 */
2429
2430 priv = netdev_priv(dev);
2431 memset(priv, 0, sizeof(struct mlx4_en_priv));
2432 priv->dev = dev;
2433 priv->mdev = mdev;
Yevgeny Petrilinebf8c9a2012-03-06 04:03:34 +00002434 priv->ddev = &mdev->pdev->dev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002435 priv->prof = prof;
2436 priv->port = port;
2437 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002438 priv->flags = prof->flags;
Amir Vadai60d6fe92011-11-26 19:55:19 +00002439 priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE |
2440 MLX4_WQE_CTRL_SOLICITED);
Amir Vadaid3179662012-12-02 03:49:23 +00002441 priv->num_tx_rings_p_up = mdev->profile.num_tx_rings_p_up;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002442 priv->tx_ring_num = prof->tx_ring_num;
Amir Vadaid3179662012-12-02 03:49:23 +00002443
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002444 priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring *) * MAX_TX_RINGS,
Amir Vadaid3179662012-12-02 03:49:23 +00002445 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00002446 if (!priv->tx_ring) {
2447 err = -ENOMEM;
2448 goto out;
2449 }
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002450 priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq *) * MAX_TX_RINGS,
Amir Vadaid3179662012-12-02 03:49:23 +00002451 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00002452 if (!priv->tx_cq) {
2453 err = -ENOMEM;
2454 goto out;
2455 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002456 priv->rx_ring_num = prof->rx_ring_num;
Or Gerlitz08ff3232012-10-21 14:59:24 +00002457 priv->cqe_factor = (mdev->dev->caps.cqe_size == 64) ? 1 : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002458 priv->mac_index = -1;
2459 priv->msg_enable = MLX4_EN_MSG_LEVEL;
2460 spin_lock_init(&priv->stats_lock);
Yan Burman0eb74fd2013-02-07 02:25:23 +00002461 INIT_WORK(&priv->rx_mode_task, mlx4_en_do_set_rx_mode);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002462 INIT_WORK(&priv->watchdog_task, mlx4_en_restart);
2463 INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate);
2464 INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00002465 INIT_DELAYED_WORK(&priv->service_task, mlx4_en_service_task);
Or Gerlitza66132f2014-04-01 11:27:13 +03002466#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02002467 INIT_WORK(&priv->vxlan_add_task, mlx4_en_add_vxlan_offloads);
2468 INIT_WORK(&priv->vxlan_del_task, mlx4_en_del_vxlan_offloads);
Or Gerlitza66132f2014-04-01 11:27:13 +03002469#endif
Amir Vadai564c2742012-04-04 21:33:26 +00002470#ifdef CONFIG_MLX4_EN_DCB
Or Gerlitz540b3a32013-04-07 03:44:07 +00002471 if (!mlx4_is_slave(priv->mdev->dev)) {
2472 if (mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_SET_ETH_SCHED) {
2473 dev->dcbnl_ops = &mlx4_en_dcbnl_ops;
2474 } else {
2475 en_info(priv, "enabling only PFC DCB ops\n");
2476 dev->dcbnl_ops = &mlx4_en_dcbnl_pfc_ops;
2477 }
2478 }
Amir Vadai564c2742012-04-04 21:33:26 +00002479#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002480
Yan Burmanc07cb4b2013-02-07 02:25:25 +00002481 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i)
2482 INIT_HLIST_HEAD(&priv->mac_hash[i]);
Yan Burman16a10ff2013-02-07 02:25:22 +00002483
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002484 /* Query for default mac and max mtu */
2485 priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port];
Yan Burman6bbb6d92013-02-07 02:25:20 +00002486
2487 /* Set default MAC */
2488 dev->addr_len = ETH_ALEN;
2489 mlx4_en_u64_to_mac(dev->dev_addr, mdev->dev->caps.def_mac[priv->port]);
2490 if (!is_valid_ether_addr(dev->dev_addr)) {
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002491 if (mlx4_is_slave(priv->mdev->dev)) {
2492 eth_hw_addr_random(dev);
2493 en_warn(priv, "Assigned random MAC address %pM\n", dev->dev_addr);
Eugenia Emantayev98133372014-03-02 10:25:01 +02002494 mac_u64 = mlx4_mac_to_u64(dev->dev_addr);
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002495 mdev->dev->caps.def_mac[priv->port] = mac_u64;
2496 } else {
2497 en_err(priv, "Port: %d, invalid mac burned: %pM, quiting\n",
2498 priv->port, dev->dev_addr);
2499 err = -EINVAL;
2500 goto out;
2501 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002502 }
2503
Yan Burman6bbb6d92013-02-07 02:25:20 +00002504 memcpy(priv->prev_mac, dev->dev_addr, sizeof(priv->prev_mac));
2505
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002506 priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
2507 DS_SIZE * MLX4_EN_MAX_RX_FRAGS);
2508 err = mlx4_en_alloc_resources(priv);
2509 if (err)
2510 goto out;
2511
Amir Vadai78fb2de2013-01-24 01:54:19 +00002512#ifdef CONFIG_RFS_ACCEL
2513 INIT_LIST_HEAD(&priv->filters);
2514 spin_lock_init(&priv->filters_lock);
2515#endif
2516
Amir Vadaiec693d42013-04-23 06:06:49 +00002517 /* Initialize time stamping config */
2518 priv->hwtstamp_config.flags = 0;
2519 priv->hwtstamp_config.tx_type = HWTSTAMP_TX_OFF;
2520 priv->hwtstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
2521
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002522 /* Allocate page for receive rings */
2523 err = mlx4_alloc_hwq_res(mdev->dev, &priv->res,
2524 MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE);
2525 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002526 en_err(priv, "Failed to allocate page for rx qps\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002527 goto out;
2528 }
2529 priv->allocated = 1;
2530
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002531 /*
2532 * Initialize netdev entry points
2533 */
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002534 if (mlx4_is_master(priv->mdev->dev))
2535 dev->netdev_ops = &mlx4_netdev_ops_master;
2536 else
2537 dev->netdev_ops = &mlx4_netdev_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002538 dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT;
Ben Hutchings1eb63a22010-09-27 08:29:34 +00002539 netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
2540 netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
Stephen Hemminger3addc562008-11-21 17:30:58 -08002541
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002542 dev->ethtool_ops = &mlx4_en_ethtool_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002543
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002544 /*
2545 * Set driver features
2546 */
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00002547 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
2548 if (mdev->LSO_support)
2549 dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
2550
2551 dev->vlan_features = dev->hw_features;
2552
Yevgeny Petrilinad861072011-10-18 01:51:24 +00002553 dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH;
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00002554 dev->features = dev->hw_features | NETIF_F_HIGHDMA |
Patrick McHardyf6469682013-04-19 02:04:27 +00002555 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
2556 NETIF_F_HW_VLAN_CTAG_FILTER;
Amir Vadai60d6fe92011-11-26 19:55:19 +00002557 dev->hw_features |= NETIF_F_LOOPBACK;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002558
Amir Vadai1eb8c692012-07-18 22:33:52 +00002559 if (mdev->dev->caps.steering_mode ==
2560 MLX4_STEERING_MODE_DEVICE_MANAGED)
2561 dev->hw_features |= NETIF_F_NTUPLE;
2562
Yan Burmancc5387f2013-02-07 02:25:26 +00002563 if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_A0)
2564 dev->priv_flags |= IFF_UNICAST_FLT;
2565
Or Gerlitz837052d2013-12-23 16:09:44 +02002566 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
2567 dev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2568 NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL;
2569 dev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
2570 dev->features |= NETIF_F_GSO_UDP_TUNNEL;
2571 }
2572
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002573 mdev->pndev[port] = dev;
2574
2575 netif_carrier_off(dev);
Eugenia Emantayev4801ae72013-06-25 12:09:31 +03002576 mlx4_en_set_default_moderation(priv);
2577
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002578 err = register_netdev(dev);
2579 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002580 en_err(priv, "Netdev registration failed for port %d\n", port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002581 goto out;
2582 }
Alexander Guller42341442011-10-09 05:29:35 +00002583 priv->registered = 1;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002584
2585 en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num);
2586 en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num);
2587
Yan Burman79aeacc2013-02-07 02:25:19 +00002588 mlx4_en_update_loopback_state(priv->dev, priv->dev->features);
2589
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002590 /* Configure port */
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00002591 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002592 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00002593 priv->rx_skb_size + ETH_FCS_LEN,
2594 prof->tx_pause, prof->tx_ppp,
2595 prof->rx_pause, prof->rx_ppp);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002596 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07002597 en_err(priv, "Failed setting port general configurations for port %d, with error %d\n",
2598 priv->port, err);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002599 goto out;
2600 }
2601
Or Gerlitz837052d2013-12-23 16:09:44 +02002602 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
Or Gerlitz1b136de2014-03-27 14:02:04 +02002603 err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC, 1);
Or Gerlitz837052d2013-12-23 16:09:44 +02002604 if (err) {
2605 en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n",
2606 err);
2607 goto out;
2608 }
2609 }
2610
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002611 /* Init port */
2612 en_warn(priv, "Initializing port\n");
2613 err = mlx4_INIT_PORT(mdev->dev, priv->port);
2614 if (err) {
2615 en_err(priv, "Failed Initializing port\n");
2616 goto out;
2617 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002618 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
Amir Vadaidc8142e2013-04-25 05:22:24 +00002619
2620 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
2621 queue_delayed_work(mdev->workqueue, &priv->service_task,
2622 SERVICE_TASK_DELAY);
2623
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002624 return 0;
2625
2626out:
2627 mlx4_en_destroy_netdev(dev);
2628 return err;
2629}
2630