blob: abddcf8c40aa120c4d4ade2822ccef68d00ea434 [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:
Eyal Perryc3ca5202014-05-14 12:15:16 +0300133 return MLX4_NET_TRANS_RULE_NUM;
Eyal Perry75a353d2013-11-07 12:19:49 +0200134 }
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 Perryc3ca5202014-05-14 12:15:16 +0300180 if (spec_tcp_udp.id >= MLX4_NET_TRANS_RULE_NUM) {
Eyal Perry75a353d2013-11-07 12:19:49 +0200181 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;
Or Gerlitz837052d2013-12-23 16:09:44 +0200477
478 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
479 return 0; /* do nothing */
480
Or Gerlitzb95089d2014-08-27 16:47:48 +0300481 err = mlx4_tunnel_steer_add(priv->mdev->dev, addr, priv->port, qpn,
482 MLX4_DOMAIN_NIC, reg_id);
Or Gerlitz837052d2013-12-23 16:09:44 +0200483 if (err) {
484 en_err(priv, "failed to add vxlan steering rule, err %d\n", err);
485 return err;
486 }
487 en_dbg(DRV, priv, "added vxlan steering rule, mac %pM reg_id %llx\n", addr, *reg_id);
488 return 0;
489}
490
491
Yan Burman16a10ff2013-02-07 02:25:22 +0000492static int mlx4_en_uc_steer_add(struct mlx4_en_priv *priv,
493 unsigned char *mac, int *qpn, u64 *reg_id)
494{
495 struct mlx4_en_dev *mdev = priv->mdev;
496 struct mlx4_dev *dev = mdev->dev;
497 int err;
498
499 switch (dev->caps.steering_mode) {
500 case MLX4_STEERING_MODE_B0: {
501 struct mlx4_qp qp;
502 u8 gid[16] = {0};
503
504 qp.qpn = *qpn;
505 memcpy(&gid[10], mac, ETH_ALEN);
506 gid[5] = priv->port;
507
508 err = mlx4_unicast_attach(dev, &qp, gid, 0, MLX4_PROT_ETH);
509 break;
510 }
511 case MLX4_STEERING_MODE_DEVICE_MANAGED: {
512 struct mlx4_spec_list spec_eth = { {NULL} };
513 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
514
515 struct mlx4_net_trans_rule rule = {
516 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
517 .exclusive = 0,
518 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000519 .promisc_mode = MLX4_FS_REGULAR,
Yan Burman16a10ff2013-02-07 02:25:22 +0000520 .priority = MLX4_DOMAIN_NIC,
521 };
522
523 rule.port = priv->port;
524 rule.qpn = *qpn;
525 INIT_LIST_HEAD(&rule.list);
526
527 spec_eth.id = MLX4_NET_TRANS_RULE_ID_ETH;
528 memcpy(spec_eth.eth.dst_mac, mac, ETH_ALEN);
529 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
530 list_add_tail(&spec_eth.list, &rule.list);
531
532 err = mlx4_flow_attach(dev, &rule, reg_id);
533 break;
534 }
535 default:
536 return -EINVAL;
537 }
538 if (err)
539 en_warn(priv, "Failed Attaching Unicast\n");
540
541 return err;
542}
543
544static void mlx4_en_uc_steer_release(struct mlx4_en_priv *priv,
545 unsigned char *mac, int qpn, u64 reg_id)
546{
547 struct mlx4_en_dev *mdev = priv->mdev;
548 struct mlx4_dev *dev = mdev->dev;
549
550 switch (dev->caps.steering_mode) {
551 case MLX4_STEERING_MODE_B0: {
552 struct mlx4_qp qp;
553 u8 gid[16] = {0};
554
555 qp.qpn = qpn;
556 memcpy(&gid[10], mac, ETH_ALEN);
557 gid[5] = priv->port;
558
559 mlx4_unicast_detach(dev, &qp, gid, MLX4_PROT_ETH);
560 break;
561 }
562 case MLX4_STEERING_MODE_DEVICE_MANAGED: {
563 mlx4_flow_detach(dev, reg_id);
564 break;
565 }
566 default:
567 en_err(priv, "Invalid steering mode.\n");
568 }
569}
570
571static int mlx4_en_get_qp(struct mlx4_en_priv *priv)
572{
573 struct mlx4_en_dev *mdev = priv->mdev;
574 struct mlx4_dev *dev = mdev->dev;
575 struct mlx4_mac_entry *entry;
576 int index = 0;
577 int err = 0;
578 u64 reg_id;
579 int *qpn = &priv->base_qpn;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200580 u64 mac = mlx4_mac_to_u64(priv->dev->dev_addr);
Yan Burman16a10ff2013-02-07 02:25:22 +0000581
582 en_dbg(DRV, priv, "Registering MAC: %pM for adding\n",
583 priv->dev->dev_addr);
584 index = mlx4_register_mac(dev, priv->port, mac);
585 if (index < 0) {
586 err = index;
587 en_err(priv, "Failed adding MAC: %pM\n",
588 priv->dev->dev_addr);
589 return err;
590 }
591
592 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) {
593 int base_qpn = mlx4_get_base_qpn(dev, priv->port);
594 *qpn = base_qpn + index;
595 return 0;
596 }
597
598 err = mlx4_qp_reserve_range(dev, 1, 1, qpn);
599 en_dbg(DRV, priv, "Reserved qp %d\n", *qpn);
600 if (err) {
601 en_err(priv, "Failed to reserve qp for mac registration\n");
602 goto qp_err;
603 }
604
605 err = mlx4_en_uc_steer_add(priv, priv->dev->dev_addr, qpn, &reg_id);
606 if (err)
607 goto steer_err;
608
Wei Yongjun9ba75fb2014-01-07 16:56:07 +0800609 err = mlx4_en_tunnel_steer_add(priv, priv->dev->dev_addr, *qpn,
610 &priv->tunnel_reg_id);
611 if (err)
Or Gerlitz837052d2013-12-23 16:09:44 +0200612 goto tunnel_err;
613
Yan Burman16a10ff2013-02-07 02:25:22 +0000614 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
615 if (!entry) {
616 err = -ENOMEM;
617 goto alloc_err;
618 }
619 memcpy(entry->mac, priv->dev->dev_addr, sizeof(entry->mac));
Eyal Perryb94901f2014-07-22 15:44:09 +0300620 memcpy(priv->current_mac, entry->mac, sizeof(priv->current_mac));
Yan Burman16a10ff2013-02-07 02:25:22 +0000621 entry->reg_id = reg_id;
622
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000623 hlist_add_head_rcu(&entry->hlist,
624 &priv->mac_hash[entry->mac[MLX4_EN_MAC_HASH_IDX]]);
Yan Burman16a10ff2013-02-07 02:25:22 +0000625
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000626 return 0;
Yan Burman16a10ff2013-02-07 02:25:22 +0000627
628alloc_err:
Or Gerlitz837052d2013-12-23 16:09:44 +0200629 if (priv->tunnel_reg_id)
630 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
631tunnel_err:
Yan Burman16a10ff2013-02-07 02:25:22 +0000632 mlx4_en_uc_steer_release(priv, priv->dev->dev_addr, *qpn, reg_id);
633
634steer_err:
635 mlx4_qp_release_range(dev, *qpn, 1);
636
637qp_err:
638 mlx4_unregister_mac(dev, priv->port, mac);
639 return err;
640}
641
642static void mlx4_en_put_qp(struct mlx4_en_priv *priv)
643{
644 struct mlx4_en_dev *mdev = priv->mdev;
645 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000646 int qpn = priv->base_qpn;
Yan Burman83a5a6c2013-03-07 03:46:56 +0000647 u64 mac;
Yan Burman16a10ff2013-02-07 02:25:22 +0000648
Yan Burman83a5a6c2013-03-07 03:46:56 +0000649 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) {
Eugenia Emantayev98133372014-03-02 10:25:01 +0200650 mac = mlx4_mac_to_u64(priv->dev->dev_addr);
Yan Burman83a5a6c2013-03-07 03:46:56 +0000651 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n",
652 priv->dev->dev_addr);
653 mlx4_unregister_mac(dev, priv->port, mac);
654 } else {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000655 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800656 struct hlist_node *tmp;
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000657 struct hlist_head *bucket;
Yan Burman83a5a6c2013-03-07 03:46:56 +0000658 unsigned int i;
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000659
Yan Burman83a5a6c2013-03-07 03:46:56 +0000660 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) {
661 bucket = &priv->mac_hash[i];
662 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Eugenia Emantayev98133372014-03-02 10:25:01 +0200663 mac = mlx4_mac_to_u64(entry->mac);
Yan Burman83a5a6c2013-03-07 03:46:56 +0000664 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n",
665 entry->mac);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000666 mlx4_en_uc_steer_release(priv, entry->mac,
667 qpn, entry->reg_id);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000668
Yan Burman83a5a6c2013-03-07 03:46:56 +0000669 mlx4_unregister_mac(dev, priv->port, mac);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000670 hlist_del_rcu(&entry->hlist);
671 kfree_rcu(entry, rcu);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000672 }
Yan Burman16a10ff2013-02-07 02:25:22 +0000673 }
Yan Burman83a5a6c2013-03-07 03:46:56 +0000674
Or Gerlitz837052d2013-12-23 16:09:44 +0200675 if (priv->tunnel_reg_id) {
676 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
677 priv->tunnel_reg_id = 0;
678 }
679
Yan Burman83a5a6c2013-03-07 03:46:56 +0000680 en_dbg(DRV, priv, "Releasing qp: port %d, qpn %d\n",
681 priv->port, qpn);
682 mlx4_qp_release_range(dev, qpn, 1);
683 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC;
Yan Burman16a10ff2013-02-07 02:25:22 +0000684 }
685}
686
687static int mlx4_en_replace_mac(struct mlx4_en_priv *priv, int qpn,
Yan Burman90bbb742013-02-07 02:25:24 +0000688 unsigned char *new_mac, unsigned char *prev_mac)
Yan Burman16a10ff2013-02-07 02:25:22 +0000689{
690 struct mlx4_en_dev *mdev = priv->mdev;
691 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000692 int err = 0;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200693 u64 new_mac_u64 = mlx4_mac_to_u64(new_mac);
Yan Burman16a10ff2013-02-07 02:25:22 +0000694
695 if (dev->caps.steering_mode != MLX4_STEERING_MODE_A0) {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000696 struct hlist_head *bucket;
697 unsigned int mac_hash;
698 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800699 struct hlist_node *tmp;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200700 u64 prev_mac_u64 = mlx4_mac_to_u64(prev_mac);
Yan Burman16a10ff2013-02-07 02:25:22 +0000701
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000702 bucket = &priv->mac_hash[prev_mac[MLX4_EN_MAC_HASH_IDX]];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800703 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000704 if (ether_addr_equal_64bits(entry->mac, prev_mac)) {
705 mlx4_en_uc_steer_release(priv, entry->mac,
706 qpn, entry->reg_id);
707 mlx4_unregister_mac(dev, priv->port,
708 prev_mac_u64);
709 hlist_del_rcu(&entry->hlist);
710 synchronize_rcu();
711 memcpy(entry->mac, new_mac, ETH_ALEN);
712 entry->reg_id = 0;
713 mac_hash = new_mac[MLX4_EN_MAC_HASH_IDX];
714 hlist_add_head_rcu(&entry->hlist,
715 &priv->mac_hash[mac_hash]);
716 mlx4_register_mac(dev, priv->port, new_mac_u64);
717 err = mlx4_en_uc_steer_add(priv, new_mac,
718 &qpn,
719 &entry->reg_id);
Or Gerlitz2a2083f2014-03-12 17:16:31 +0200720 if (err)
721 return err;
722 if (priv->tunnel_reg_id) {
723 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
724 priv->tunnel_reg_id = 0;
725 }
726 err = mlx4_en_tunnel_steer_add(priv, new_mac, qpn,
727 &priv->tunnel_reg_id);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000728 return err;
729 }
730 }
731 return -EINVAL;
Yan Burman16a10ff2013-02-07 02:25:22 +0000732 }
733
734 return __mlx4_replace_mac(dev, priv->port, qpn, new_mac_u64);
735}
736
Noa Osherovich2695bab2014-07-08 11:25:24 +0300737static int mlx4_en_do_set_mac(struct mlx4_en_priv *priv,
738 unsigned char new_mac[ETH_ALEN + 2])
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700739{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700740 int err = 0;
741
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700742 if (priv->port_up) {
743 /* Remove old MAC and insert the new one */
Yan Burman16a10ff2013-02-07 02:25:22 +0000744 err = mlx4_en_replace_mac(priv, priv->base_qpn,
Noa Osherovich2695bab2014-07-08 11:25:24 +0300745 new_mac, priv->current_mac);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700746 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000747 en_err(priv, "Failed changing HW MAC address\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700748 } else
Yan Burman48e551f2013-02-07 02:25:21 +0000749 en_dbg(HW, priv, "Port is down while registering mac, exiting...\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700750
Noa Osherovich2695bab2014-07-08 11:25:24 +0300751 if (!err)
752 memcpy(priv->current_mac, new_mac, sizeof(priv->current_mac));
Shani Michaelliee755322014-05-14 12:15:12 +0300753
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000754 return err;
755}
756
757static int mlx4_en_set_mac(struct net_device *dev, void *addr)
758{
759 struct mlx4_en_priv *priv = netdev_priv(dev);
760 struct mlx4_en_dev *mdev = priv->mdev;
761 struct sockaddr *saddr = addr;
Noa Osherovich2695bab2014-07-08 11:25:24 +0300762 unsigned char new_mac[ETH_ALEN + 2];
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000763 int err;
764
765 if (!is_valid_ether_addr(saddr->sa_data))
766 return -EADDRNOTAVAIL;
767
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000768 mutex_lock(&mdev->state_lock);
Noa Osherovich2695bab2014-07-08 11:25:24 +0300769 memcpy(new_mac, saddr->sa_data, ETH_ALEN);
770 err = mlx4_en_do_set_mac(priv, new_mac);
771 if (!err)
772 memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700773 mutex_unlock(&mdev->state_lock);
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000774
775 return err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700776}
777
778static void mlx4_en_clear_list(struct net_device *dev)
779{
780 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000781 struct mlx4_en_mc_list *tmp, *mc_to_del;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700782
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000783 list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) {
784 list_del(&mc_to_del->list);
785 kfree(mc_to_del);
786 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700787}
788
789static void mlx4_en_cache_mclist(struct net_device *dev)
790{
791 struct mlx4_en_priv *priv = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000792 struct netdev_hw_addr *ha;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000793 struct mlx4_en_mc_list *tmp;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700794
Alexander Guller0e035672011-12-19 04:02:58 +0000795 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000796 netdev_for_each_mc_addr(ha, dev) {
797 tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC);
798 if (!tmp) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000799 mlx4_en_clear_list(dev);
800 return;
801 }
802 memcpy(tmp->addr, ha->addr, ETH_ALEN);
803 list_add_tail(&tmp->list, &priv->mc_list);
804 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700805}
806
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000807static void update_mclist_flags(struct mlx4_en_priv *priv,
808 struct list_head *dst,
809 struct list_head *src)
810{
811 struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc;
812 bool found;
813
814 /* Find all the entries that should be removed from dst,
815 * These are the entries that are not found in src
816 */
817 list_for_each_entry(dst_tmp, dst, list) {
818 found = false;
819 list_for_each_entry(src_tmp, src, list) {
dingtianhongc0623e52013-12-30 15:40:55 +0800820 if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000821 found = true;
822 break;
823 }
824 }
825 if (!found)
826 dst_tmp->action = MCLIST_REM;
827 }
828
829 /* Add entries that exist in src but not in dst
830 * mark them as need to add
831 */
832 list_for_each_entry(src_tmp, src, list) {
833 found = false;
834 list_for_each_entry(dst_tmp, dst, list) {
dingtianhongc0623e52013-12-30 15:40:55 +0800835 if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000836 dst_tmp->action = MCLIST_NONE;
837 found = true;
838 break;
839 }
840 }
841 if (!found) {
Joe Perches14f8dc42013-02-07 11:46:27 +0000842 new_mc = kmemdup(src_tmp,
843 sizeof(struct mlx4_en_mc_list),
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000844 GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +0000845 if (!new_mc)
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000846 return;
Joe Perches14f8dc42013-02-07 11:46:27 +0000847
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000848 new_mc->action = MCLIST_ADD;
849 list_add_tail(&new_mc->list, dst);
850 }
851 }
852}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700853
Yan Burman0eb74fd2013-02-07 02:25:23 +0000854static void mlx4_en_set_rx_mode(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700855{
856 struct mlx4_en_priv *priv = netdev_priv(dev);
857
858 if (!priv->port_up)
859 return;
860
Yan Burman0eb74fd2013-02-07 02:25:23 +0000861 queue_work(priv->mdev->workqueue, &priv->rx_mode_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700862}
863
Yan Burman0eb74fd2013-02-07 02:25:23 +0000864static void mlx4_en_set_promisc_mode(struct mlx4_en_priv *priv,
865 struct mlx4_en_dev *mdev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700866{
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000867 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700868
Yan Burman0eb74fd2013-02-07 02:25:23 +0000869 if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700870 if (netif_msg_rx_status(priv))
Yan Burman0eb74fd2013-02-07 02:25:23 +0000871 en_warn(priv, "Entering promiscuous mode\n");
872 priv->flags |= MLX4_EN_FLAG_PROMISC;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700873
Yan Burman0eb74fd2013-02-07 02:25:23 +0000874 /* Enable promiscouos mode */
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000875 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000876 case MLX4_STEERING_MODE_DEVICE_MANAGED:
Yan Burman0eb74fd2013-02-07 02:25:23 +0000877 err = mlx4_flow_steer_promisc_add(mdev->dev,
878 priv->port,
879 priv->base_qpn,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000880 MLX4_FS_ALL_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000881 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000882 en_err(priv, "Failed enabling promiscuous mode\n");
883 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000884 break;
885
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000886 case MLX4_STEERING_MODE_B0:
Yan Burman0eb74fd2013-02-07 02:25:23 +0000887 err = mlx4_unicast_promisc_add(mdev->dev,
888 priv->base_qpn,
889 priv->port);
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000890 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000891 en_err(priv, "Failed enabling unicast promiscuous mode\n");
892
893 /* Add the default qp number as multicast
894 * promisc
895 */
896 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
897 err = mlx4_multicast_promisc_add(mdev->dev,
898 priv->base_qpn,
899 priv->port);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000900 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000901 en_err(priv, "Failed enabling multicast promiscuous mode\n");
902 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000903 }
904 break;
905
906 case MLX4_STEERING_MODE_A0:
907 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
908 priv->port,
Yan Burman0eb74fd2013-02-07 02:25:23 +0000909 priv->base_qpn,
910 1);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000911 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000912 en_err(priv, "Failed enabling promiscuous mode\n");
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000913 break;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000914 }
915
Yan Burman0eb74fd2013-02-07 02:25:23 +0000916 /* Disable port multicast filter (unconditionally) */
917 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
918 0, MLX4_MCAST_DISABLE);
919 if (err)
920 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700921 }
Yan Burman0eb74fd2013-02-07 02:25:23 +0000922}
923
924static void mlx4_en_clear_promisc_mode(struct mlx4_en_priv *priv,
925 struct mlx4_en_dev *mdev)
926{
927 int err = 0;
928
929 if (netif_msg_rx_status(priv))
930 en_warn(priv, "Leaving promiscuous mode\n");
931 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
932
933 /* Disable promiscouos mode */
934 switch (mdev->dev->caps.steering_mode) {
935 case MLX4_STEERING_MODE_DEVICE_MANAGED:
936 err = mlx4_flow_steer_promisc_remove(mdev->dev,
937 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000938 MLX4_FS_ALL_DEFAULT);
Yan Burman0eb74fd2013-02-07 02:25:23 +0000939 if (err)
940 en_err(priv, "Failed disabling promiscuous mode\n");
941 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
942 break;
943
944 case MLX4_STEERING_MODE_B0:
945 err = mlx4_unicast_promisc_remove(mdev->dev,
946 priv->base_qpn,
947 priv->port);
948 if (err)
949 en_err(priv, "Failed disabling unicast promiscuous mode\n");
950 /* Disable Multicast promisc */
951 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
952 err = mlx4_multicast_promisc_remove(mdev->dev,
953 priv->base_qpn,
954 priv->port);
955 if (err)
956 en_err(priv, "Failed disabling multicast promiscuous mode\n");
957 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
958 }
959 break;
960
961 case MLX4_STEERING_MODE_A0:
962 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
963 priv->port,
964 priv->base_qpn, 0);
965 if (err)
966 en_err(priv, "Failed disabling promiscuous mode\n");
967 break;
968 }
Yan Burman0eb74fd2013-02-07 02:25:23 +0000969}
970
971static void mlx4_en_do_multicast(struct mlx4_en_priv *priv,
972 struct net_device *dev,
973 struct mlx4_en_dev *mdev)
974{
975 struct mlx4_en_mc_list *mclist, *tmp;
976 u64 mcast_addr = 0;
977 u8 mc_list[16] = {0};
978 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700979
980 /* Enable/disable the multicast filter according to IFF_ALLMULTI */
981 if (dev->flags & IFF_ALLMULTI) {
982 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
983 0, MLX4_MCAST_DISABLE);
984 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000985 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000986
987 /* Add the default qp number as multicast promisc */
988 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000989 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000990 case MLX4_STEERING_MODE_DEVICE_MANAGED:
991 err = mlx4_flow_steer_promisc_add(mdev->dev,
992 priv->port,
993 priv->base_qpn,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000994 MLX4_FS_MC_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000995 break;
996
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000997 case MLX4_STEERING_MODE_B0:
998 err = mlx4_multicast_promisc_add(mdev->dev,
999 priv->base_qpn,
1000 priv->port);
1001 break;
1002
1003 case MLX4_STEERING_MODE_A0:
1004 break;
1005 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001006 if (err)
1007 en_err(priv, "Failed entering multicast promisc mode\n");
1008 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
1009 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001010 } else {
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001011 /* Disable Multicast promisc */
1012 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001013 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001014 case MLX4_STEERING_MODE_DEVICE_MANAGED:
1015 err = mlx4_flow_steer_promisc_remove(mdev->dev,
1016 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001017 MLX4_FS_MC_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001018 break;
1019
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001020 case MLX4_STEERING_MODE_B0:
1021 err = mlx4_multicast_promisc_remove(mdev->dev,
1022 priv->base_qpn,
1023 priv->port);
1024 break;
1025
1026 case MLX4_STEERING_MODE_A0:
1027 break;
1028 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001029 if (err)
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001030 en_err(priv, "Failed disabling multicast promiscuous mode\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001031 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
1032 }
Jiri Pirkoff6e2162010-03-01 05:09:14 +00001033
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001034 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
1035 0, MLX4_MCAST_DISABLE);
1036 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001037 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001038
1039 /* Flush mcast filter and init it with broadcast address */
1040 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST,
1041 1, MLX4_MCAST_CONFIG);
1042
1043 /* Update multicast list - we cache all addresses so they won't
1044 * change while HW is updated holding the command semaphor */
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +00001045 netif_addr_lock_bh(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001046 mlx4_en_cache_mclist(dev);
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +00001047 netif_addr_unlock_bh(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001048 list_for_each_entry(mclist, &priv->mc_list, list) {
Eugenia Emantayev98133372014-03-02 10:25:01 +02001049 mcast_addr = mlx4_mac_to_u64(mclist->addr);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001050 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port,
1051 mcast_addr, 0, MLX4_MCAST_CONFIG);
1052 }
1053 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
1054 0, MLX4_MCAST_ENABLE);
1055 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001056 en_err(priv, "Failed enabling multicast filter\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001057
1058 update_mclist_flags(priv, &priv->curr_list, &priv->mc_list);
1059 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
1060 if (mclist->action == MCLIST_REM) {
1061 /* detach this address and delete from list */
1062 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
1063 mc_list[5] = priv->port;
1064 err = mlx4_multicast_detach(mdev->dev,
1065 &priv->rss_map.indir_qp,
1066 mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001067 MLX4_PROT_ETH,
1068 mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001069 if (err)
1070 en_err(priv, "Fail to detach multicast address\n");
1071
Or Gerlitz837052d2013-12-23 16:09:44 +02001072 if (mclist->tunnel_reg_id) {
1073 err = mlx4_flow_detach(priv->mdev->dev, mclist->tunnel_reg_id);
1074 if (err)
1075 en_err(priv, "Failed to detach multicast address\n");
1076 }
1077
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001078 /* remove from list */
1079 list_del(&mclist->list);
1080 kfree(mclist);
Dan Carpenter9c645082012-07-10 20:34:07 +00001081 } else if (mclist->action == MCLIST_ADD) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001082 /* attach the address */
1083 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001084 /* needed for B0 steering support */
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001085 mc_list[5] = priv->port;
1086 err = mlx4_multicast_attach(mdev->dev,
1087 &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001088 mc_list,
1089 priv->port, 0,
1090 MLX4_PROT_ETH,
1091 &mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001092 if (err)
1093 en_err(priv, "Fail to attach multicast address\n");
1094
Or Gerlitz837052d2013-12-23 16:09:44 +02001095 err = mlx4_en_tunnel_steer_add(priv, &mc_list[10], priv->base_qpn,
1096 &mclist->tunnel_reg_id);
1097 if (err)
1098 en_err(priv, "Failed to attach multicast address\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001099 }
1100 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001101 }
Yan Burman0eb74fd2013-02-07 02:25:23 +00001102}
1103
Yan Burmancc5387f2013-02-07 02:25:26 +00001104static void mlx4_en_do_uc_filter(struct mlx4_en_priv *priv,
1105 struct net_device *dev,
1106 struct mlx4_en_dev *mdev)
1107{
1108 struct netdev_hw_addr *ha;
1109 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001110 struct hlist_node *tmp;
Yan Burmancc5387f2013-02-07 02:25:26 +00001111 bool found;
1112 u64 mac;
1113 int err = 0;
1114 struct hlist_head *bucket;
1115 unsigned int i;
1116 int removed = 0;
1117 u32 prev_flags;
1118
1119 /* Note that we do not need to protect our mac_hash traversal with rcu,
1120 * since all modification code is protected by mdev->state_lock
1121 */
1122
1123 /* find what to remove */
1124 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) {
1125 bucket = &priv->mac_hash[i];
Sasha Levinb67bfe02013-02-27 17:06:00 -08001126 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Yan Burmancc5387f2013-02-07 02:25:26 +00001127 found = false;
1128 netdev_for_each_uc_addr(ha, dev) {
1129 if (ether_addr_equal_64bits(entry->mac,
1130 ha->addr)) {
1131 found = true;
1132 break;
1133 }
1134 }
1135
1136 /* MAC address of the port is not in uc list */
Noa Osherovich2695bab2014-07-08 11:25:24 +03001137 if (ether_addr_equal_64bits(entry->mac,
1138 priv->current_mac))
Yan Burmancc5387f2013-02-07 02:25:26 +00001139 found = true;
1140
1141 if (!found) {
Eugenia Emantayev98133372014-03-02 10:25:01 +02001142 mac = mlx4_mac_to_u64(entry->mac);
Yan Burmancc5387f2013-02-07 02:25:26 +00001143 mlx4_en_uc_steer_release(priv, entry->mac,
1144 priv->base_qpn,
1145 entry->reg_id);
1146 mlx4_unregister_mac(mdev->dev, priv->port, mac);
1147
1148 hlist_del_rcu(&entry->hlist);
1149 kfree_rcu(entry, rcu);
1150 en_dbg(DRV, priv, "Removed MAC %pM on port:%d\n",
1151 entry->mac, priv->port);
1152 ++removed;
1153 }
1154 }
1155 }
1156
1157 /* if we didn't remove anything, there is no use in trying to add
1158 * again once we are in a forced promisc mode state
1159 */
1160 if ((priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) && 0 == removed)
1161 return;
1162
1163 prev_flags = priv->flags;
1164 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC;
1165
1166 /* find what to add */
1167 netdev_for_each_uc_addr(ha, dev) {
1168 found = false;
1169 bucket = &priv->mac_hash[ha->addr[MLX4_EN_MAC_HASH_IDX]];
Sasha Levinb67bfe02013-02-27 17:06:00 -08001170 hlist_for_each_entry(entry, bucket, hlist) {
Yan Burmancc5387f2013-02-07 02:25:26 +00001171 if (ether_addr_equal_64bits(entry->mac, ha->addr)) {
1172 found = true;
1173 break;
1174 }
1175 }
1176
1177 if (!found) {
1178 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1179 if (!entry) {
1180 en_err(priv, "Failed adding MAC %pM on port:%d (out of memory)\n",
1181 ha->addr, priv->port);
1182 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1183 break;
1184 }
Eugenia Emantayev98133372014-03-02 10:25:01 +02001185 mac = mlx4_mac_to_u64(ha->addr);
Yan Burmancc5387f2013-02-07 02:25:26 +00001186 memcpy(entry->mac, ha->addr, ETH_ALEN);
1187 err = mlx4_register_mac(mdev->dev, priv->port, mac);
1188 if (err < 0) {
1189 en_err(priv, "Failed registering MAC %pM on port %d: %d\n",
1190 ha->addr, priv->port, err);
1191 kfree(entry);
1192 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1193 break;
1194 }
1195 err = mlx4_en_uc_steer_add(priv, ha->addr,
1196 &priv->base_qpn,
1197 &entry->reg_id);
1198 if (err) {
1199 en_err(priv, "Failed adding MAC %pM on port %d: %d\n",
1200 ha->addr, priv->port, err);
1201 mlx4_unregister_mac(mdev->dev, priv->port, mac);
1202 kfree(entry);
1203 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1204 break;
1205 } else {
1206 unsigned int mac_hash;
1207 en_dbg(DRV, priv, "Added MAC %pM on port:%d\n",
1208 ha->addr, priv->port);
1209 mac_hash = ha->addr[MLX4_EN_MAC_HASH_IDX];
1210 bucket = &priv->mac_hash[mac_hash];
1211 hlist_add_head_rcu(&entry->hlist, bucket);
1212 }
1213 }
1214 }
1215
1216 if (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) {
1217 en_warn(priv, "Forcing promiscuous mode on port:%d\n",
1218 priv->port);
1219 } else if (prev_flags & MLX4_EN_FLAG_FORCE_PROMISC) {
1220 en_warn(priv, "Stop forcing promiscuous mode on port:%d\n",
1221 priv->port);
1222 }
1223}
1224
Yan Burman0eb74fd2013-02-07 02:25:23 +00001225static void mlx4_en_do_set_rx_mode(struct work_struct *work)
1226{
1227 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1228 rx_mode_task);
1229 struct mlx4_en_dev *mdev = priv->mdev;
1230 struct net_device *dev = priv->dev;
1231
1232 mutex_lock(&mdev->state_lock);
1233 if (!mdev->device_up) {
1234 en_dbg(HW, priv, "Card is not up, ignoring rx mode change.\n");
1235 goto out;
1236 }
1237 if (!priv->port_up) {
1238 en_dbg(HW, priv, "Port is down, ignoring rx mode change.\n");
1239 goto out;
1240 }
1241
1242 if (!netif_carrier_ok(dev)) {
1243 if (!mlx4_en_QUERY_PORT(mdev, priv->port)) {
1244 if (priv->port_state.link_state) {
1245 priv->last_link_state = MLX4_DEV_EVENT_PORT_UP;
1246 netif_carrier_on(dev);
1247 en_dbg(LINK, priv, "Link Up\n");
1248 }
1249 }
1250 }
1251
Yan Burmancc5387f2013-02-07 02:25:26 +00001252 if (dev->priv_flags & IFF_UNICAST_FLT)
1253 mlx4_en_do_uc_filter(priv, dev, mdev);
1254
Yan Burman0eb74fd2013-02-07 02:25:23 +00001255 /* Promsicuous mode: disable all filters */
Yan Burmancc5387f2013-02-07 02:25:26 +00001256 if ((dev->flags & IFF_PROMISC) ||
1257 (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC)) {
Yan Burman0eb74fd2013-02-07 02:25:23 +00001258 mlx4_en_set_promisc_mode(priv, mdev);
1259 goto out;
1260 }
1261
1262 /* Not in promiscuous mode */
1263 if (priv->flags & MLX4_EN_FLAG_PROMISC)
1264 mlx4_en_clear_promisc_mode(priv, mdev);
1265
1266 mlx4_en_do_multicast(priv, dev, mdev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001267out:
1268 mutex_unlock(&mdev->state_lock);
1269}
1270
1271#ifdef CONFIG_NET_POLL_CONTROLLER
1272static void mlx4_en_netpoll(struct net_device *dev)
1273{
1274 struct mlx4_en_priv *priv = netdev_priv(dev);
1275 struct mlx4_en_cq *cq;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001276 int i;
1277
1278 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001279 cq = priv->rx_cq[i];
Chris Masonc98235c2014-04-15 18:09:24 -04001280 napi_schedule(&cq->napi);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001281 }
1282}
1283#endif
1284
1285static void mlx4_en_tx_timeout(struct net_device *dev)
1286{
1287 struct mlx4_en_priv *priv = netdev_priv(dev);
1288 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001289 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001290
1291 if (netif_msg_timer(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001292 en_warn(priv, "Tx timeout called on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001293
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001294 for (i = 0; i < priv->tx_ring_num; i++) {
1295 if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev, i)))
1296 continue;
1297 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 +02001298 i, priv->tx_ring[i]->qpn, priv->tx_ring[i]->cqn,
1299 priv->tx_ring[i]->cons, priv->tx_ring[i]->prod);
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001300 }
1301
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001302 priv->port_stats.tx_timeout++;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001303 en_dbg(DRV, priv, "Scheduling watchdog\n");
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001304 queue_work(mdev->workqueue, &priv->watchdog_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001305}
1306
1307
1308static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev)
1309{
1310 struct mlx4_en_priv *priv = netdev_priv(dev);
1311
1312 spin_lock_bh(&priv->stats_lock);
1313 memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats));
1314 spin_unlock_bh(&priv->stats_lock);
1315
1316 return &priv->ret_stats;
1317}
1318
1319static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv)
1320{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001321 struct mlx4_en_cq *cq;
1322 int i;
1323
1324 /* If we haven't received a specific coalescing setting
Martin Olsson98a17082009-04-22 18:21:29 +02001325 * (module param), we set the moderation parameters as follows:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001326 * - moder_cnt is set to the number of mtu sized packets to
Eric Dumazetecfd2ce2012-11-05 16:20:42 +00001327 * satisfy our coalescing target.
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001328 * - moder_time is set to a fixed value.
1329 */
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +00001330 priv->rx_frames = MLX4_EN_RX_COAL_TARGET;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -08001331 priv->rx_usecs = MLX4_EN_RX_COAL_TIME;
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001332 priv->tx_frames = MLX4_EN_TX_COAL_PKTS;
1333 priv->tx_usecs = MLX4_EN_TX_COAL_TIME;
Yan Burman48e551f2013-02-07 02:25:21 +00001334 en_dbg(INTR, priv, "Default coalesing params for mtu:%d - rx_frames:%d rx_usecs:%d\n",
1335 priv->dev->mtu, priv->rx_frames, priv->rx_usecs);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001336
1337 /* Setup cq moderation params */
1338 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001339 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001340 cq->moder_cnt = priv->rx_frames;
1341 cq->moder_time = priv->rx_usecs;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001342 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
1343 priv->last_moder_packets[i] = 0;
1344 priv->last_moder_bytes[i] = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001345 }
1346
1347 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001348 cq = priv->tx_cq[i];
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001349 cq->moder_cnt = priv->tx_frames;
1350 cq->moder_time = priv->tx_usecs;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001351 }
1352
1353 /* Reset auto-moderation params */
1354 priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW;
1355 priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW;
1356 priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH;
1357 priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH;
1358 priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -08001359 priv->adaptive_rx_coal = 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001360 priv->last_moder_jiffies = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001361 priv->last_moder_tx_packets = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001362}
1363
1364static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv)
1365{
1366 unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001367 struct mlx4_en_cq *cq;
1368 unsigned long packets;
1369 unsigned long rate;
1370 unsigned long avg_pkt_size;
1371 unsigned long rx_packets;
1372 unsigned long rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001373 unsigned long rx_pkt_diff;
1374 int moder_time;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001375 int ring, err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001376
1377 if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ)
1378 return;
1379
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001380 for (ring = 0; ring < priv->rx_ring_num; ring++) {
1381 spin_lock_bh(&priv->stats_lock);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001382 rx_packets = priv->rx_ring[ring]->packets;
1383 rx_bytes = priv->rx_ring[ring]->bytes;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001384 spin_unlock_bh(&priv->stats_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001385
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001386 rx_pkt_diff = ((unsigned long) (rx_packets -
1387 priv->last_moder_packets[ring]));
1388 packets = rx_pkt_diff;
1389 rate = packets * HZ / period;
1390 avg_pkt_size = packets ? ((unsigned long) (rx_bytes -
1391 priv->last_moder_bytes[ring])) / packets : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001392
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001393 /* Apply auto-moderation only when packet rate
1394 * exceeds a rate that it matters */
1395 if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) &&
1396 avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001397 if (rate < priv->pkt_rate_low)
1398 moder_time = priv->rx_usecs_low;
1399 else if (rate > priv->pkt_rate_high)
1400 moder_time = priv->rx_usecs_high;
1401 else
1402 moder_time = (rate - priv->pkt_rate_low) *
1403 (priv->rx_usecs_high - priv->rx_usecs_low) /
1404 (priv->pkt_rate_high - priv->pkt_rate_low) +
1405 priv->rx_usecs_low;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001406 } else {
1407 moder_time = priv->rx_usecs_low;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001408 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001409
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001410 if (moder_time != priv->last_moder_time[ring]) {
1411 priv->last_moder_time[ring] = moder_time;
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001412 cq = priv->rx_cq[ring];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001413 cq->moder_time = moder_time;
Sagi Grimberga1c66932013-06-04 05:13:26 +00001414 cq->moder_cnt = priv->rx_frames;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001415 err = mlx4_en_set_cq_moder(priv, cq);
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001416 if (err)
Yan Burman48e551f2013-02-07 02:25:21 +00001417 en_err(priv, "Failed modifying moderation for cq:%d\n",
1418 ring);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001419 }
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001420 priv->last_moder_packets[ring] = rx_packets;
1421 priv->last_moder_bytes[ring] = rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001422 }
1423
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001424 priv->last_moder_jiffies = jiffies;
1425}
1426
1427static void mlx4_en_do_get_stats(struct work_struct *work)
1428{
Jean Delvarebf6aede2009-04-02 16:56:54 -07001429 struct delayed_work *delay = to_delayed_work(work);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001430 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
1431 stats_task);
1432 struct mlx4_en_dev *mdev = priv->mdev;
1433 int err;
1434
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001435 mutex_lock(&mdev->state_lock);
1436 if (mdev->device_up) {
Jack Morgenstein6123db2e2013-06-25 12:09:30 +03001437 if (priv->port_up) {
1438 err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0);
1439 if (err)
1440 en_dbg(HW, priv, "Could not update stats\n");
Eugenia Emantayev2d518372013-01-24 01:54:14 +00001441
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001442 mlx4_en_auto_moderation(priv);
Jack Morgenstein6123db2e2013-06-25 12:09:30 +03001443 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001444
1445 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
1446 }
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +00001447 if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
Noa Osherovich2695bab2014-07-08 11:25:24 +03001448 mlx4_en_do_set_mac(priv, priv->current_mac);
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +00001449 mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
1450 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001451 mutex_unlock(&mdev->state_lock);
1452}
1453
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001454/* mlx4_en_service_task - Run service task for tasks that needed to be done
1455 * periodically
1456 */
1457static void mlx4_en_service_task(struct work_struct *work)
1458{
1459 struct delayed_work *delay = to_delayed_work(work);
1460 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
1461 service_task);
1462 struct mlx4_en_dev *mdev = priv->mdev;
1463
1464 mutex_lock(&mdev->state_lock);
1465 if (mdev->device_up) {
Amir Vadaidc8142e2013-04-25 05:22:24 +00001466 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
1467 mlx4_en_ptp_overflow_check(mdev);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001468
1469 queue_delayed_work(mdev->workqueue, &priv->service_task,
1470 SERVICE_TASK_DELAY);
1471 }
1472 mutex_unlock(&mdev->state_lock);
1473}
1474
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001475static void mlx4_en_linkstate(struct work_struct *work)
1476{
1477 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1478 linkstate_task);
1479 struct mlx4_en_dev *mdev = priv->mdev;
1480 int linkstate = priv->link_state;
1481
1482 mutex_lock(&mdev->state_lock);
1483 /* If observable port state changed set carrier state and
1484 * report to system log */
1485 if (priv->last_link_state != linkstate) {
1486 if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001487 en_info(priv, "Link Down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001488 netif_carrier_off(priv->dev);
1489 } else {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001490 en_info(priv, "Link Up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001491 netif_carrier_on(priv->dev);
1492 }
1493 }
1494 priv->last_link_state = linkstate;
1495 mutex_unlock(&mdev->state_lock);
1496}
1497
Yuval Atias9e311e72014-06-09 10:24:39 +03001498static int mlx4_en_init_affinity_hint(struct mlx4_en_priv *priv, int ring_idx)
1499{
1500 struct mlx4_en_rx_ring *ring = priv->rx_ring[ring_idx];
1501 int numa_node = priv->mdev->dev->numa_node;
1502 int ret = 0;
1503
1504 if (!zalloc_cpumask_var(&ring->affinity_mask, GFP_KERNEL))
1505 return -ENOMEM;
1506
1507 ret = cpumask_set_cpu_local_first(ring_idx, numa_node,
1508 ring->affinity_mask);
1509 if (ret)
1510 free_cpumask_var(ring->affinity_mask);
1511
1512 return ret;
1513}
1514
1515static void mlx4_en_free_affinity_hint(struct mlx4_en_priv *priv, int ring_idx)
1516{
1517 free_cpumask_var(priv->rx_ring[ring_idx]->affinity_mask);
1518}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001519
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001520int mlx4_en_start_port(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001521{
1522 struct mlx4_en_priv *priv = netdev_priv(dev);
1523 struct mlx4_en_dev *mdev = priv->mdev;
1524 struct mlx4_en_cq *cq;
1525 struct mlx4_en_tx_ring *tx_ring;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001526 int rx_index = 0;
1527 int tx_index = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001528 int err = 0;
1529 int i;
1530 int j;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001531 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001532
1533 if (priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001534 en_dbg(DRV, priv, "start port called while port already up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001535 return 0;
1536 }
1537
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001538 INIT_LIST_HEAD(&priv->mc_list);
1539 INIT_LIST_HEAD(&priv->curr_list);
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001540 INIT_LIST_HEAD(&priv->ethtool_list);
1541 memset(&priv->ethtool_rules[0], 0,
1542 sizeof(struct ethtool_flow_id) * MAX_NUM_OF_FS_RULES);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001543
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001544 /* Calculate Rx buf size */
1545 dev->mtu = min(dev->mtu, priv->max_mtu);
1546 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001547 en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_skb_size);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001548
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001549 /* Configure rx cq's and rings */
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001550 err = mlx4_en_activate_rx_rings(priv);
1551 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001552 en_err(priv, "Failed to activate RX rings\n");
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001553 return err;
1554 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001555 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001556 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001557
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001558 mlx4_en_cq_init_lock(cq);
1559
Yuval Atias9e311e72014-06-09 10:24:39 +03001560 err = mlx4_en_init_affinity_hint(priv, i);
1561 if (err) {
1562 en_err(priv, "Failed preparing IRQ affinity hint\n");
1563 goto cq_err;
1564 }
1565
Alexander Guller76532d02011-10-09 05:26:31 +00001566 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001567 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001568 en_err(priv, "Failed activating Rx CQ\n");
Yuval Atias9e311e72014-06-09 10:24:39 +03001569 mlx4_en_free_affinity_hint(priv, i);
Yevgeny Petrilina4233302009-04-26 20:41:34 +00001570 goto cq_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001571 }
1572 for (j = 0; j < cq->size; j++)
1573 cq->buf[j].owner_sr_opcode = MLX4_CQE_OWNER_MASK;
1574 err = mlx4_en_set_cq_moder(priv, cq);
1575 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07001576 en_err(priv, "Failed setting cq moderation parameters\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001577 mlx4_en_deactivate_cq(priv, cq);
Yuval Atias9e311e72014-06-09 10:24:39 +03001578 mlx4_en_free_affinity_hint(priv, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001579 goto cq_err;
1580 }
1581 mlx4_en_arm_cq(priv, cq);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001582 priv->rx_ring[i]->cqn = cq->mcq.cqn;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001583 ++rx_index;
1584 }
1585
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001586 /* Set qp number */
1587 en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port);
Yan Burman16a10ff2013-02-07 02:25:22 +00001588 err = mlx4_en_get_qp(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001589 if (err) {
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001590 en_err(priv, "Failed getting eth qp\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001591 goto cq_err;
1592 }
1593 mdev->mac_removed[priv->port] = 0;
1594
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001595 err = mlx4_en_config_rss_steer(priv);
1596 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001597 en_err(priv, "Failed configuring rss steering\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001598 goto mac_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001599 }
1600
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001601 err = mlx4_en_create_drop_qp(priv);
1602 if (err)
1603 goto rss_err;
1604
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001605 /* Configure tx cq's and rings */
1606 for (i = 0; i < priv->tx_ring_num; i++) {
1607 /* Configure cq */
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001608 cq = priv->tx_cq[i];
Alexander Guller76532d02011-10-09 05:26:31 +00001609 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001610 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001611 en_err(priv, "Failed allocating Tx CQ\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001612 goto tx_err;
1613 }
1614 err = mlx4_en_set_cq_moder(priv, cq);
1615 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07001616 en_err(priv, "Failed setting cq moderation parameters\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001617 mlx4_en_deactivate_cq(priv, cq);
1618 goto tx_err;
1619 }
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001620 en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001621 cq->buf->wqe_index = cpu_to_be16(0xffff);
1622
1623 /* Configure ring */
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001624 tx_ring = priv->tx_ring[i];
Amir Vadai0e98b522012-04-04 21:33:24 +00001625 err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn,
Amir Vadaid3179662012-12-02 03:49:23 +00001626 i / priv->num_tx_rings_p_up);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001627 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001628 en_err(priv, "Failed allocating Tx ring\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001629 mlx4_en_deactivate_cq(priv, cq);
1630 goto tx_err;
1631 }
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001632 tx_ring->tx_queue = netdev_get_tx_queue(dev, i);
Yevgeny Petriline22979d2012-04-23 02:18:39 +00001633
1634 /* Arm CQ for TX completions */
1635 mlx4_en_arm_cq(priv, cq);
1636
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001637 /* Set initial ownership of all Tx TXBBs to SW (1) */
1638 for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE)
1639 *((u32 *) (tx_ring->buf + j)) = 0xffffffff;
1640 ++tx_index;
1641 }
1642
1643 /* Configure port */
1644 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
1645 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001646 priv->prof->tx_pause,
1647 priv->prof->tx_ppp,
1648 priv->prof->rx_pause,
1649 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001650 if (err) {
Yan Burman48e551f2013-02-07 02:25:21 +00001651 en_err(priv, "Failed setting port general configurations for port %d, with error %d\n",
1652 priv->port, err);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001653 goto tx_err;
1654 }
1655 /* Set default qp number */
1656 err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0);
1657 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001658 en_err(priv, "Failed setting default qp numbers\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001659 goto tx_err;
1660 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001661
Or Gerlitz837052d2013-12-23 16:09:44 +02001662 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
Or Gerlitz1b136de2014-03-27 14:02:04 +02001663 err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC, 1);
Or Gerlitz837052d2013-12-23 16:09:44 +02001664 if (err) {
1665 en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n",
1666 err);
1667 goto tx_err;
1668 }
1669 }
1670
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001671 /* Init port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001672 en_dbg(HW, priv, "Initializing port\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001673 err = mlx4_INIT_PORT(mdev->dev, priv->port);
1674 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001675 en_err(priv, "Failed Initializing port\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001676 goto tx_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001677 }
1678
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001679 /* Attach rx QP to bradcast address */
1680 memset(&mc_list[10], 0xff, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001681 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001682 if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001683 priv->port, 0, MLX4_PROT_ETH,
1684 &priv->broadcast_id))
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001685 mlx4_warn(mdev, "Failed Attaching Broadcast\n");
1686
Herbert Xub5845f92011-03-27 01:01:26 +00001687 /* Must redo promiscuous mode setup. */
1688 priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC);
1689
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001690 /* Schedule multicast task to populate multicast list */
Yan Burman0eb74fd2013-02-07 02:25:23 +00001691 queue_work(mdev->workqueue, &priv->rx_mode_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001692
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +00001693 mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap);
1694
Or Gerlitza66132f2014-04-01 11:27:13 +03001695#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02001696 if (priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS)
1697 vxlan_get_rx_port(dev);
Or Gerlitza66132f2014-04-01 11:27:13 +03001698#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001699 priv->port_up = true;
Yevgeny Petrilina11faac2009-06-20 22:15:46 +00001700 netif_tx_start_all_queues(dev);
Amir Vadai3484aac2013-01-30 23:07:11 +00001701 netif_device_attach(dev);
1702
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001703 return 0;
1704
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001705tx_err:
1706 while (tx_index--) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001707 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[tx_index]);
1708 mlx4_en_deactivate_cq(priv, priv->tx_cq[tx_index]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001709 }
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001710 mlx4_en_destroy_drop_qp(priv);
1711rss_err:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001712 mlx4_en_release_rss_steer(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001713mac_err:
Yan Burman16a10ff2013-02-07 02:25:22 +00001714 mlx4_en_put_qp(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001715cq_err:
Yuval Atias9e311e72014-06-09 10:24:39 +03001716 while (rx_index--) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001717 mlx4_en_deactivate_cq(priv, priv->rx_cq[rx_index]);
Yuval Atias9e311e72014-06-09 10:24:39 +03001718 mlx4_en_free_affinity_hint(priv, i);
1719 }
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);
Yuval Atias9e311e72014-06-09 10:24:39 +03001850
1851 mlx4_en_free_affinity_hint(priv, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001852 }
1853}
1854
1855static void mlx4_en_restart(struct work_struct *work)
1856{
1857 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1858 watchdog_task);
1859 struct mlx4_en_dev *mdev = priv->mdev;
1860 struct net_device *dev = priv->dev;
1861
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001862 en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001863
1864 mutex_lock(&mdev->state_lock);
1865 if (priv->port_up) {
Amir Vadai3484aac2013-01-30 23:07:11 +00001866 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001867 if (mlx4_en_start_port(dev))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001868 en_err(priv, "Failed restarting port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001869 }
1870 mutex_unlock(&mdev->state_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001871}
1872
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001873static void mlx4_en_clear_stats(struct net_device *dev)
1874{
1875 struct mlx4_en_priv *priv = netdev_priv(dev);
1876 struct mlx4_en_dev *mdev = priv->mdev;
1877 int i;
1878
1879 if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1))
1880 en_dbg(HW, priv, "Failed dumping statistics\n");
1881
1882 memset(&priv->stats, 0, sizeof(priv->stats));
1883 memset(&priv->pstats, 0, sizeof(priv->pstats));
1884 memset(&priv->pkstats, 0, sizeof(priv->pkstats));
1885 memset(&priv->port_stats, 0, sizeof(priv->port_stats));
1886
1887 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001888 priv->tx_ring[i]->bytes = 0;
1889 priv->tx_ring[i]->packets = 0;
1890 priv->tx_ring[i]->tx_csum = 0;
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001891 }
1892 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001893 priv->rx_ring[i]->bytes = 0;
1894 priv->rx_ring[i]->packets = 0;
1895 priv->rx_ring[i]->csum_ok = 0;
1896 priv->rx_ring[i]->csum_none = 0;
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001897 }
1898}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001899
1900static int mlx4_en_open(struct net_device *dev)
1901{
1902 struct mlx4_en_priv *priv = netdev_priv(dev);
1903 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001904 int err = 0;
1905
1906 mutex_lock(&mdev->state_lock);
1907
1908 if (!mdev->device_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001909 en_err(priv, "Cannot open - device down/disabled\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001910 err = -EBUSY;
1911 goto out;
1912 }
1913
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001914 /* Reset HW statistics and SW counters */
1915 mlx4_en_clear_stats(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001916
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001917 err = mlx4_en_start_port(dev);
1918 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001919 en_err(priv, "Failed starting port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001920
1921out:
1922 mutex_unlock(&mdev->state_lock);
1923 return err;
1924}
1925
1926
1927static int mlx4_en_close(struct net_device *dev)
1928{
1929 struct mlx4_en_priv *priv = netdev_priv(dev);
1930 struct mlx4_en_dev *mdev = priv->mdev;
1931
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001932 en_dbg(IFDOWN, priv, "Close port called\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001933
1934 mutex_lock(&mdev->state_lock);
1935
Amir Vadai3484aac2013-01-30 23:07:11 +00001936 mlx4_en_stop_port(dev, 0);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001937 netif_carrier_off(dev);
1938
1939 mutex_unlock(&mdev->state_lock);
1940 return 0;
1941}
1942
Alexander Gullerfe0af032011-10-09 05:26:46 +00001943void mlx4_en_free_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001944{
1945 int i;
1946
Amir Vadai1eb8c692012-07-18 22:33:52 +00001947#ifdef CONFIG_RFS_ACCEL
1948 free_irq_cpu_rmap(priv->dev->rx_cpu_rmap);
1949 priv->dev->rx_cpu_rmap = NULL;
1950#endif
1951
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001952 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001953 if (priv->tx_ring && priv->tx_ring[i])
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001954 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001955 if (priv->tx_cq && priv->tx_cq[i])
Alexander Gullerfe0af032011-10-09 05:26:46 +00001956 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001957 }
1958
1959 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001960 if (priv->rx_ring[i])
Thadeu Lima de Souza Cascardo68355f72012-02-06 08:39:49 +00001961 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
1962 priv->prof->rx_ring_size, priv->stride);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001963 if (priv->rx_cq[i])
Alexander Gullerfe0af032011-10-09 05:26:46 +00001964 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001965 }
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001966
1967 if (priv->base_tx_qpn) {
1968 mlx4_qp_release_range(priv->mdev->dev, priv->base_tx_qpn, priv->tx_ring_num);
1969 priv->base_tx_qpn = 0;
1970 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001971}
1972
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001973int mlx4_en_alloc_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001974{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001975 struct mlx4_en_port_profile *prof = priv->prof;
1976 int i;
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001977 int err;
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001978 int node;
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001979
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001980 err = mlx4_qp_reserve_range(priv->mdev->dev, priv->tx_ring_num, 256, &priv->base_tx_qpn);
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001981 if (err) {
1982 en_err(priv, "failed reserving range for TX rings\n");
1983 return err;
1984 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001985
1986 /* Create tx Rings */
1987 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001988 node = cpu_to_node(i % num_online_cpus());
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001989 if (mlx4_en_create_cq(priv, &priv->tx_cq[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001990 prof->tx_ring_size, i, TX, node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001991 goto err;
1992
Ido Shamayd03a68f2013-12-19 21:20:14 +02001993 if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i],
1994 priv->base_tx_qpn + i,
1995 prof->tx_ring_size, TXBB_SIZE,
1996 node, i))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001997 goto err;
1998 }
1999
2000 /* Create rx Rings */
2001 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev163561a2013-11-07 12:19:54 +02002002 node = cpu_to_node(i % num_online_cpus());
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002003 if (mlx4_en_create_cq(priv, &priv->rx_cq[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02002004 prof->rx_ring_size, i, RX, node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002005 goto err;
2006
2007 if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02002008 prof->rx_ring_size, priv->stride,
2009 node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002010 goto err;
2011 }
2012
Amir Vadai1eb8c692012-07-18 22:33:52 +00002013#ifdef CONFIG_RFS_ACCEL
Amir Vadaia229e482013-03-07 03:46:57 +00002014 if (priv->mdev->dev->caps.comp_pool) {
2015 priv->dev->rx_cpu_rmap = alloc_irq_cpu_rmap(priv->mdev->dev->caps.comp_pool);
2016 if (!priv->dev->rx_cpu_rmap)
2017 goto err;
2018 }
Amir Vadai1eb8c692012-07-18 22:33:52 +00002019#endif
2020
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002021 return 0;
2022
2023err:
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002024 en_err(priv, "Failed to allocate NIC resources\n");
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002025 for (i = 0; i < priv->rx_ring_num; i++) {
2026 if (priv->rx_ring[i])
2027 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
2028 prof->rx_ring_size,
2029 priv->stride);
2030 if (priv->rx_cq[i])
2031 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
2032 }
2033 for (i = 0; i < priv->tx_ring_num; i++) {
2034 if (priv->tx_ring[i])
2035 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
2036 if (priv->tx_cq[i])
2037 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
2038 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002039 return -ENOMEM;
2040}
2041
2042
2043void mlx4_en_destroy_netdev(struct net_device *dev)
2044{
2045 struct mlx4_en_priv *priv = netdev_priv(dev);
2046 struct mlx4_en_dev *mdev = priv->mdev;
2047
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002048 en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002049
2050 /* Unregister device - this will close the port if it was up */
2051 if (priv->registered)
2052 unregister_netdev(dev);
2053
2054 if (priv->allocated)
2055 mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE);
2056
2057 cancel_delayed_work(&priv->stats_task);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00002058 cancel_delayed_work(&priv->service_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002059 /* flush any pending task for this netdev */
2060 flush_workqueue(mdev->workqueue);
2061
2062 /* Detach the netdev so tasks would not attempt to access it */
2063 mutex_lock(&mdev->state_lock);
2064 mdev->pndev[priv->port] = NULL;
2065 mutex_unlock(&mdev->state_lock);
2066
Alexander Gullerfe0af032011-10-09 05:26:46 +00002067 mlx4_en_free_resources(priv);
Amir Vadai564c2742012-04-04 21:33:26 +00002068
Amir Vadaibc6a4742012-05-17 00:58:10 +00002069 kfree(priv->tx_ring);
2070 kfree(priv->tx_cq);
2071
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002072 free_netdev(dev);
2073}
2074
2075static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
2076{
2077 struct mlx4_en_priv *priv = netdev_priv(dev);
2078 struct mlx4_en_dev *mdev = priv->mdev;
2079 int err = 0;
2080
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002081 en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002082 dev->mtu, new_mtu);
2083
2084 if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002085 en_err(priv, "Bad MTU size:%d.\n", new_mtu);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002086 return -EPERM;
2087 }
2088 dev->mtu = new_mtu;
2089
2090 if (netif_running(dev)) {
2091 mutex_lock(&mdev->state_lock);
2092 if (!mdev->device_up) {
2093 /* NIC is probably restarting - let watchdog task reset
2094 * the port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002095 en_dbg(DRV, priv, "Change MTU called with card down!?\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002096 } else {
Amir Vadai3484aac2013-01-30 23:07:11 +00002097 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002098 err = mlx4_en_start_port(dev);
2099 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002100 en_err(priv, "Failed restarting port:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002101 priv->port);
2102 queue_work(mdev->workqueue, &priv->watchdog_task);
2103 }
2104 }
2105 mutex_unlock(&mdev->state_lock);
2106 }
2107 return 0;
2108}
2109
Ben Hutchings100dbda2013-11-18 23:13:31 +00002110static int mlx4_en_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
Amir Vadaiec693d42013-04-23 06:06:49 +00002111{
2112 struct mlx4_en_priv *priv = netdev_priv(dev);
2113 struct mlx4_en_dev *mdev = priv->mdev;
2114 struct hwtstamp_config config;
2115
2116 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
2117 return -EFAULT;
2118
2119 /* reserved for future extensions */
2120 if (config.flags)
2121 return -EINVAL;
2122
2123 /* device doesn't support time stamping */
2124 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS))
2125 return -EINVAL;
2126
2127 /* TX HW timestamp */
2128 switch (config.tx_type) {
2129 case HWTSTAMP_TX_OFF:
2130 case HWTSTAMP_TX_ON:
2131 break;
2132 default:
2133 return -ERANGE;
2134 }
2135
2136 /* RX HW timestamp */
2137 switch (config.rx_filter) {
2138 case HWTSTAMP_FILTER_NONE:
2139 break;
2140 case HWTSTAMP_FILTER_ALL:
2141 case HWTSTAMP_FILTER_SOME:
2142 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2143 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2144 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2145 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2146 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2147 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2148 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2149 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
2150 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
2151 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2152 case HWTSTAMP_FILTER_PTP_V2_SYNC:
2153 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
2154 config.rx_filter = HWTSTAMP_FILTER_ALL;
2155 break;
2156 default:
2157 return -ERANGE;
2158 }
2159
2160 if (mlx4_en_timestamp_config(dev, config.tx_type, config.rx_filter)) {
2161 config.tx_type = HWTSTAMP_TX_OFF;
2162 config.rx_filter = HWTSTAMP_FILTER_NONE;
2163 }
2164
2165 return copy_to_user(ifr->ifr_data, &config,
2166 sizeof(config)) ? -EFAULT : 0;
2167}
2168
Ben Hutchings100dbda2013-11-18 23:13:31 +00002169static int mlx4_en_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
2170{
2171 struct mlx4_en_priv *priv = netdev_priv(dev);
2172
2173 return copy_to_user(ifr->ifr_data, &priv->hwtstamp_config,
2174 sizeof(priv->hwtstamp_config)) ? -EFAULT : 0;
2175}
2176
Amir Vadaiec693d42013-04-23 06:06:49 +00002177static int mlx4_en_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2178{
2179 switch (cmd) {
2180 case SIOCSHWTSTAMP:
Ben Hutchings100dbda2013-11-18 23:13:31 +00002181 return mlx4_en_hwtstamp_set(dev, ifr);
2182 case SIOCGHWTSTAMP:
2183 return mlx4_en_hwtstamp_get(dev, ifr);
Amir Vadaiec693d42013-04-23 06:06:49 +00002184 default:
2185 return -EOPNOTSUPP;
2186 }
2187}
2188
Amir Vadai60d6fe92011-11-26 19:55:19 +00002189static int mlx4_en_set_features(struct net_device *netdev,
2190 netdev_features_t features)
2191{
2192 struct mlx4_en_priv *priv = netdev_priv(netdev);
2193
2194 if (features & NETIF_F_LOOPBACK)
2195 priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
2196 else
2197 priv->ctrl_flags &=
2198 cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK);
2199
Yan Burman79aeacc2013-02-07 02:25:19 +00002200 mlx4_en_update_loopback_state(netdev, features);
2201
Amir Vadai60d6fe92011-11-26 19:55:19 +00002202 return 0;
2203
2204}
2205
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002206static int mlx4_en_set_vf_mac(struct net_device *dev, int queue, u8 *mac)
2207{
2208 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2209 struct mlx4_en_dev *mdev = en_priv->mdev;
Eugenia Emantayev98133372014-03-02 10:25:01 +02002210 u64 mac_u64 = mlx4_mac_to_u64(mac);
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002211
2212 if (!is_valid_ether_addr(mac))
2213 return -EINVAL;
2214
2215 return mlx4_set_vf_mac(mdev->dev, en_priv->port, queue, mac_u64);
2216}
2217
Rony Efraim3f7fb022013-04-25 05:22:28 +00002218static int mlx4_en_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos)
2219{
2220 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2221 struct mlx4_en_dev *mdev = en_priv->mdev;
2222
2223 return mlx4_set_vf_vlan(mdev->dev, en_priv->port, vf, vlan, qos);
2224}
2225
Rony Efraime6b6a232013-04-25 05:22:29 +00002226static int mlx4_en_set_vf_spoofchk(struct net_device *dev, int vf, bool setting)
2227{
2228 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2229 struct mlx4_en_dev *mdev = en_priv->mdev;
2230
2231 return mlx4_set_vf_spoofchk(mdev->dev, en_priv->port, vf, setting);
2232}
2233
Rony Efraim2cccb9e2013-04-25 05:22:30 +00002234static int mlx4_en_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_info *ivf)
2235{
2236 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2237 struct mlx4_en_dev *mdev = en_priv->mdev;
2238
2239 return mlx4_get_vf_config(mdev->dev, en_priv->port, vf, ivf);
2240}
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002241
Rony Efraim948e3062013-06-13 13:19:11 +03002242static int mlx4_en_set_vf_link_state(struct net_device *dev, int vf, int link_state)
2243{
2244 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2245 struct mlx4_en_dev *mdev = en_priv->mdev;
2246
2247 return mlx4_set_vf_link_state(mdev->dev, en_priv->port, vf, link_state);
2248}
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002249
2250#define PORT_ID_BYTE_LEN 8
2251static int mlx4_en_get_phys_port_id(struct net_device *dev,
2252 struct netdev_phys_port_id *ppid)
2253{
2254 struct mlx4_en_priv *priv = netdev_priv(dev);
2255 struct mlx4_dev *mdev = priv->mdev->dev;
2256 int i;
2257 u64 phys_port_id = mdev->caps.phys_port_id[priv->port];
2258
2259 if (!phys_port_id)
2260 return -EOPNOTSUPP;
2261
2262 ppid->id_len = sizeof(phys_port_id);
2263 for (i = PORT_ID_BYTE_LEN - 1; i >= 0; --i) {
2264 ppid->id[i] = phys_port_id & 0xff;
2265 phys_port_id >>= 8;
2266 }
2267 return 0;
2268}
2269
Or Gerlitza66132f2014-04-01 11:27:13 +03002270#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02002271static void mlx4_en_add_vxlan_offloads(struct work_struct *work)
2272{
2273 int ret;
2274 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
2275 vxlan_add_task);
2276
2277 ret = mlx4_config_vxlan_port(priv->mdev->dev, priv->vxlan_port);
2278 if (ret)
2279 goto out;
2280
2281 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port,
2282 VXLAN_STEER_BY_OUTER_MAC, 1);
2283out:
2284 if (ret)
2285 en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret);
2286}
2287
2288static void mlx4_en_del_vxlan_offloads(struct work_struct *work)
2289{
2290 int ret;
2291 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
2292 vxlan_del_task);
2293
2294 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port,
2295 VXLAN_STEER_BY_OUTER_MAC, 0);
2296 if (ret)
2297 en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret);
2298
2299 priv->vxlan_port = 0;
2300}
2301
2302static void mlx4_en_add_vxlan_port(struct net_device *dev,
2303 sa_family_t sa_family, __be16 port)
2304{
2305 struct mlx4_en_priv *priv = netdev_priv(dev);
2306 __be16 current_port;
2307
Or Gerlitze326f2f2014-07-02 17:36:23 +03002308 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
Or Gerlitz1b136de2014-03-27 14:02:04 +02002309 return;
2310
2311 if (sa_family == AF_INET6)
2312 return;
2313
2314 current_port = priv->vxlan_port;
2315 if (current_port && current_port != port) {
2316 en_warn(priv, "vxlan port %d configured, can't add port %d\n",
2317 ntohs(current_port), ntohs(port));
2318 return;
2319 }
2320
2321 priv->vxlan_port = port;
2322 queue_work(priv->mdev->workqueue, &priv->vxlan_add_task);
2323}
2324
2325static void mlx4_en_del_vxlan_port(struct net_device *dev,
2326 sa_family_t sa_family, __be16 port)
2327{
2328 struct mlx4_en_priv *priv = netdev_priv(dev);
2329 __be16 current_port;
2330
2331 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
2332 return;
2333
2334 if (sa_family == AF_INET6)
2335 return;
2336
2337 current_port = priv->vxlan_port;
2338 if (current_port != port) {
2339 en_dbg(DRV, priv, "vxlan port %d isn't configured, ignoring\n", ntohs(port));
2340 return;
2341 }
2342
2343 queue_work(priv->mdev->workqueue, &priv->vxlan_del_task);
2344}
Or Gerlitza66132f2014-04-01 11:27:13 +03002345#endif
Or Gerlitz1b136de2014-03-27 14:02:04 +02002346
Stephen Hemminger3addc562008-11-21 17:30:58 -08002347static const struct net_device_ops mlx4_netdev_ops = {
2348 .ndo_open = mlx4_en_open,
2349 .ndo_stop = mlx4_en_close,
2350 .ndo_start_xmit = mlx4_en_xmit,
Yevgeny Petrilinf813cad2009-06-01 23:24:07 +00002351 .ndo_select_queue = mlx4_en_select_queue,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002352 .ndo_get_stats = mlx4_en_get_stats,
Yan Burman0eb74fd2013-02-07 02:25:23 +00002353 .ndo_set_rx_mode = mlx4_en_set_rx_mode,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002354 .ndo_set_mac_address = mlx4_en_set_mac,
Stephen Hemminger52255bb2009-01-09 10:45:37 +00002355 .ndo_validate_addr = eth_validate_addr,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002356 .ndo_change_mtu = mlx4_en_change_mtu,
Amir Vadaiec693d42013-04-23 06:06:49 +00002357 .ndo_do_ioctl = mlx4_en_ioctl,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002358 .ndo_tx_timeout = mlx4_en_tx_timeout,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002359 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
2360 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
2361#ifdef CONFIG_NET_POLL_CONTROLLER
2362 .ndo_poll_controller = mlx4_en_netpoll,
2363#endif
Amir Vadai60d6fe92011-11-26 19:55:19 +00002364 .ndo_set_features = mlx4_en_set_features,
Amir Vadai897d7842012-04-04 21:33:27 +00002365 .ndo_setup_tc = mlx4_en_setup_tc,
Amir Vadai1eb8c692012-07-18 22:33:52 +00002366#ifdef CONFIG_RFS_ACCEL
2367 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2368#endif
Cong Wange0d10952013-08-01 11:10:25 +08002369#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03002370 .ndo_busy_poll = mlx4_en_low_latency_recv,
Amir Vadai9e77a2b2013-06-18 16:18:27 +03002371#endif
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002372 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
Or Gerlitza66132f2014-04-01 11:27:13 +03002373#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02002374 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port,
2375 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port,
Or Gerlitza66132f2014-04-01 11:27:13 +03002376#endif
Stephen Hemminger3addc562008-11-21 17:30:58 -08002377};
2378
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002379static const struct net_device_ops mlx4_netdev_ops_master = {
2380 .ndo_open = mlx4_en_open,
2381 .ndo_stop = mlx4_en_close,
2382 .ndo_start_xmit = mlx4_en_xmit,
2383 .ndo_select_queue = mlx4_en_select_queue,
2384 .ndo_get_stats = mlx4_en_get_stats,
2385 .ndo_set_rx_mode = mlx4_en_set_rx_mode,
2386 .ndo_set_mac_address = mlx4_en_set_mac,
2387 .ndo_validate_addr = eth_validate_addr,
2388 .ndo_change_mtu = mlx4_en_change_mtu,
2389 .ndo_tx_timeout = mlx4_en_tx_timeout,
2390 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
2391 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
2392 .ndo_set_vf_mac = mlx4_en_set_vf_mac,
Rony Efraim3f7fb022013-04-25 05:22:28 +00002393 .ndo_set_vf_vlan = mlx4_en_set_vf_vlan,
Rony Efraime6b6a232013-04-25 05:22:29 +00002394 .ndo_set_vf_spoofchk = mlx4_en_set_vf_spoofchk,
Rony Efraim948e3062013-06-13 13:19:11 +03002395 .ndo_set_vf_link_state = mlx4_en_set_vf_link_state,
Rony Efraim2cccb9e2013-04-25 05:22:30 +00002396 .ndo_get_vf_config = mlx4_en_get_vf_config,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002397#ifdef CONFIG_NET_POLL_CONTROLLER
2398 .ndo_poll_controller = mlx4_en_netpoll,
2399#endif
2400 .ndo_set_features = mlx4_en_set_features,
2401 .ndo_setup_tc = mlx4_en_setup_tc,
2402#ifdef CONFIG_RFS_ACCEL
2403 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2404#endif
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002405 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002406};
2407
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002408int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
2409 struct mlx4_en_port_profile *prof)
2410{
2411 struct net_device *dev;
2412 struct mlx4_en_priv *priv;
Yan Burmanc07cb4b2013-02-07 02:25:25 +00002413 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002414 int err;
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002415 u64 mac_u64;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002416
Tom Herbertf1593d22011-01-09 19:36:36 +00002417 dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv),
Amir Vadaid3179662012-12-02 03:49:23 +00002418 MAX_TX_RINGS, MAX_RX_RINGS);
Joe Perches41de8d42012-01-29 13:47:52 +00002419 if (dev == NULL)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002420 return -ENOMEM;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002421
Amir Vadaid3179662012-12-02 03:49:23 +00002422 netif_set_real_num_tx_queues(dev, prof->tx_ring_num);
2423 netif_set_real_num_rx_queues(dev, prof->rx_ring_num);
2424
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002425 SET_NETDEV_DEV(dev, &mdev->dev->pdev->dev);
Amir Vadai76a066f2014-02-25 18:17:51 +02002426 dev->dev_port = port - 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002427
2428 /*
2429 * Initialize driver private data
2430 */
2431
2432 priv = netdev_priv(dev);
2433 memset(priv, 0, sizeof(struct mlx4_en_priv));
2434 priv->dev = dev;
2435 priv->mdev = mdev;
Yevgeny Petrilinebf8c9a2012-03-06 04:03:34 +00002436 priv->ddev = &mdev->pdev->dev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002437 priv->prof = prof;
2438 priv->port = port;
2439 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002440 priv->flags = prof->flags;
Amir Vadai0fef9d02014-07-22 15:44:10 +03002441 priv->pflags = MLX4_EN_PRIV_FLAGS_BLUEFLAME;
Amir Vadai60d6fe92011-11-26 19:55:19 +00002442 priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE |
2443 MLX4_WQE_CTRL_SOLICITED);
Amir Vadaid3179662012-12-02 03:49:23 +00002444 priv->num_tx_rings_p_up = mdev->profile.num_tx_rings_p_up;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002445 priv->tx_ring_num = prof->tx_ring_num;
Amir Vadaifbc6daf2014-07-08 11:28:12 +03002446 priv->tx_work_limit = MLX4_EN_DEFAULT_TX_WORK;
Amir Vadaid3179662012-12-02 03:49:23 +00002447
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002448 priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring *) * MAX_TX_RINGS,
Amir Vadaid3179662012-12-02 03:49:23 +00002449 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00002450 if (!priv->tx_ring) {
2451 err = -ENOMEM;
2452 goto out;
2453 }
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002454 priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq *) * MAX_TX_RINGS,
Amir Vadaid3179662012-12-02 03:49:23 +00002455 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00002456 if (!priv->tx_cq) {
2457 err = -ENOMEM;
2458 goto out;
2459 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002460 priv->rx_ring_num = prof->rx_ring_num;
Or Gerlitz08ff3232012-10-21 14:59:24 +00002461 priv->cqe_factor = (mdev->dev->caps.cqe_size == 64) ? 1 : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002462 priv->mac_index = -1;
2463 priv->msg_enable = MLX4_EN_MSG_LEVEL;
2464 spin_lock_init(&priv->stats_lock);
Yan Burman0eb74fd2013-02-07 02:25:23 +00002465 INIT_WORK(&priv->rx_mode_task, mlx4_en_do_set_rx_mode);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002466 INIT_WORK(&priv->watchdog_task, mlx4_en_restart);
2467 INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate);
2468 INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00002469 INIT_DELAYED_WORK(&priv->service_task, mlx4_en_service_task);
Or Gerlitza66132f2014-04-01 11:27:13 +03002470#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02002471 INIT_WORK(&priv->vxlan_add_task, mlx4_en_add_vxlan_offloads);
2472 INIT_WORK(&priv->vxlan_del_task, mlx4_en_del_vxlan_offloads);
Or Gerlitza66132f2014-04-01 11:27:13 +03002473#endif
Amir Vadai564c2742012-04-04 21:33:26 +00002474#ifdef CONFIG_MLX4_EN_DCB
Or Gerlitz540b3a32013-04-07 03:44:07 +00002475 if (!mlx4_is_slave(priv->mdev->dev)) {
2476 if (mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_SET_ETH_SCHED) {
2477 dev->dcbnl_ops = &mlx4_en_dcbnl_ops;
2478 } else {
2479 en_info(priv, "enabling only PFC DCB ops\n");
2480 dev->dcbnl_ops = &mlx4_en_dcbnl_pfc_ops;
2481 }
2482 }
Amir Vadai564c2742012-04-04 21:33:26 +00002483#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002484
Yan Burmanc07cb4b2013-02-07 02:25:25 +00002485 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i)
2486 INIT_HLIST_HEAD(&priv->mac_hash[i]);
Yan Burman16a10ff2013-02-07 02:25:22 +00002487
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002488 /* Query for default mac and max mtu */
2489 priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port];
Yan Burman6bbb6d92013-02-07 02:25:20 +00002490
2491 /* Set default MAC */
2492 dev->addr_len = ETH_ALEN;
2493 mlx4_en_u64_to_mac(dev->dev_addr, mdev->dev->caps.def_mac[priv->port]);
2494 if (!is_valid_ether_addr(dev->dev_addr)) {
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002495 if (mlx4_is_slave(priv->mdev->dev)) {
2496 eth_hw_addr_random(dev);
2497 en_warn(priv, "Assigned random MAC address %pM\n", dev->dev_addr);
Eugenia Emantayev98133372014-03-02 10:25:01 +02002498 mac_u64 = mlx4_mac_to_u64(dev->dev_addr);
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002499 mdev->dev->caps.def_mac[priv->port] = mac_u64;
2500 } else {
2501 en_err(priv, "Port: %d, invalid mac burned: %pM, quiting\n",
2502 priv->port, dev->dev_addr);
2503 err = -EINVAL;
2504 goto out;
2505 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002506 }
2507
Noa Osherovich2695bab2014-07-08 11:25:24 +03002508 memcpy(priv->current_mac, dev->dev_addr, sizeof(priv->current_mac));
Yan Burman6bbb6d92013-02-07 02:25:20 +00002509
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002510 priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
2511 DS_SIZE * MLX4_EN_MAX_RX_FRAGS);
2512 err = mlx4_en_alloc_resources(priv);
2513 if (err)
2514 goto out;
2515
Amir Vadai78fb2de2013-01-24 01:54:19 +00002516#ifdef CONFIG_RFS_ACCEL
2517 INIT_LIST_HEAD(&priv->filters);
2518 spin_lock_init(&priv->filters_lock);
2519#endif
2520
Amir Vadaiec693d42013-04-23 06:06:49 +00002521 /* Initialize time stamping config */
2522 priv->hwtstamp_config.flags = 0;
2523 priv->hwtstamp_config.tx_type = HWTSTAMP_TX_OFF;
2524 priv->hwtstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
2525
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002526 /* Allocate page for receive rings */
2527 err = mlx4_alloc_hwq_res(mdev->dev, &priv->res,
2528 MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE);
2529 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002530 en_err(priv, "Failed to allocate page for rx qps\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002531 goto out;
2532 }
2533 priv->allocated = 1;
2534
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002535 /*
2536 * Initialize netdev entry points
2537 */
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002538 if (mlx4_is_master(priv->mdev->dev))
2539 dev->netdev_ops = &mlx4_netdev_ops_master;
2540 else
2541 dev->netdev_ops = &mlx4_netdev_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002542 dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT;
Ben Hutchings1eb63a22010-09-27 08:29:34 +00002543 netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
2544 netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
Stephen Hemminger3addc562008-11-21 17:30:58 -08002545
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002546 dev->ethtool_ops = &mlx4_en_ethtool_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002547
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002548 /*
2549 * Set driver features
2550 */
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00002551 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
2552 if (mdev->LSO_support)
2553 dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
2554
2555 dev->vlan_features = dev->hw_features;
2556
Yevgeny Petrilinad861072011-10-18 01:51:24 +00002557 dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH;
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00002558 dev->features = dev->hw_features | NETIF_F_HIGHDMA |
Patrick McHardyf6469682013-04-19 02:04:27 +00002559 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
2560 NETIF_F_HW_VLAN_CTAG_FILTER;
Amir Vadai60d6fe92011-11-26 19:55:19 +00002561 dev->hw_features |= NETIF_F_LOOPBACK;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002562
Amir Vadai1eb8c692012-07-18 22:33:52 +00002563 if (mdev->dev->caps.steering_mode ==
2564 MLX4_STEERING_MODE_DEVICE_MANAGED)
2565 dev->hw_features |= NETIF_F_NTUPLE;
2566
Yan Burmancc5387f2013-02-07 02:25:26 +00002567 if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_A0)
2568 dev->priv_flags |= IFF_UNICAST_FLT;
2569
Or Gerlitz837052d2013-12-23 16:09:44 +02002570 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
2571 dev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2572 NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL;
2573 dev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
2574 dev->features |= NETIF_F_GSO_UDP_TUNNEL;
2575 }
2576
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002577 mdev->pndev[port] = dev;
2578
2579 netif_carrier_off(dev);
Eugenia Emantayev4801ae72013-06-25 12:09:31 +03002580 mlx4_en_set_default_moderation(priv);
2581
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002582 err = register_netdev(dev);
2583 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002584 en_err(priv, "Netdev registration failed for port %d\n", port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002585 goto out;
2586 }
Alexander Guller42341442011-10-09 05:29:35 +00002587 priv->registered = 1;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002588
2589 en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num);
2590 en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num);
2591
Yan Burman79aeacc2013-02-07 02:25:19 +00002592 mlx4_en_update_loopback_state(priv->dev, priv->dev->features);
2593
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002594 /* Configure port */
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00002595 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002596 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00002597 priv->rx_skb_size + ETH_FCS_LEN,
2598 prof->tx_pause, prof->tx_ppp,
2599 prof->rx_pause, prof->rx_ppp);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002600 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07002601 en_err(priv, "Failed setting port general configurations for port %d, with error %d\n",
2602 priv->port, err);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002603 goto out;
2604 }
2605
Or Gerlitz837052d2013-12-23 16:09:44 +02002606 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
Or Gerlitz1b136de2014-03-27 14:02:04 +02002607 err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC, 1);
Or Gerlitz837052d2013-12-23 16:09:44 +02002608 if (err) {
2609 en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n",
2610 err);
2611 goto out;
2612 }
2613 }
2614
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002615 /* Init port */
2616 en_warn(priv, "Initializing port\n");
2617 err = mlx4_INIT_PORT(mdev->dev, priv->port);
2618 if (err) {
2619 en_err(priv, "Failed Initializing port\n");
2620 goto out;
2621 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002622 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
Amir Vadaidc8142e2013-04-25 05:22:24 +00002623
2624 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
2625 queue_delayed_work(mdev->workqueue, &priv->service_task,
2626 SERVICE_TASK_DELAY);
2627
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002628 return 0;
2629
2630out:
2631 mlx4_en_destroy_netdev(dev);
2632 return err;
2633}
2634