blob: 32f5ec7374723d1315f4234f77b12ffbe5adcfe0 [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
Or Gerlitz5eff6da2015-01-15 15:28:54 +0200478 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN ||
479 priv->mdev->dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_STATIC)
Or Gerlitz837052d2013-12-23 16:09:44 +0200480 return 0; /* do nothing */
481
Or Gerlitzb95089d2014-08-27 16:47:48 +0300482 err = mlx4_tunnel_steer_add(priv->mdev->dev, addr, priv->port, qpn,
483 MLX4_DOMAIN_NIC, reg_id);
Or Gerlitz837052d2013-12-23 16:09:44 +0200484 if (err) {
485 en_err(priv, "failed to add vxlan steering rule, err %d\n", err);
486 return err;
487 }
488 en_dbg(DRV, priv, "added vxlan steering rule, mac %pM reg_id %llx\n", addr, *reg_id);
489 return 0;
490}
491
492
Yan Burman16a10ff2013-02-07 02:25:22 +0000493static int mlx4_en_uc_steer_add(struct mlx4_en_priv *priv,
494 unsigned char *mac, int *qpn, u64 *reg_id)
495{
496 struct mlx4_en_dev *mdev = priv->mdev;
497 struct mlx4_dev *dev = mdev->dev;
498 int err;
499
500 switch (dev->caps.steering_mode) {
501 case MLX4_STEERING_MODE_B0: {
502 struct mlx4_qp qp;
503 u8 gid[16] = {0};
504
505 qp.qpn = *qpn;
506 memcpy(&gid[10], mac, ETH_ALEN);
507 gid[5] = priv->port;
508
509 err = mlx4_unicast_attach(dev, &qp, gid, 0, MLX4_PROT_ETH);
510 break;
511 }
512 case MLX4_STEERING_MODE_DEVICE_MANAGED: {
513 struct mlx4_spec_list spec_eth = { {NULL} };
514 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
515
516 struct mlx4_net_trans_rule rule = {
517 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
518 .exclusive = 0,
519 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000520 .promisc_mode = MLX4_FS_REGULAR,
Yan Burman16a10ff2013-02-07 02:25:22 +0000521 .priority = MLX4_DOMAIN_NIC,
522 };
523
524 rule.port = priv->port;
525 rule.qpn = *qpn;
526 INIT_LIST_HEAD(&rule.list);
527
528 spec_eth.id = MLX4_NET_TRANS_RULE_ID_ETH;
529 memcpy(spec_eth.eth.dst_mac, mac, ETH_ALEN);
530 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
531 list_add_tail(&spec_eth.list, &rule.list);
532
533 err = mlx4_flow_attach(dev, &rule, reg_id);
534 break;
535 }
536 default:
537 return -EINVAL;
538 }
539 if (err)
540 en_warn(priv, "Failed Attaching Unicast\n");
541
542 return err;
543}
544
545static void mlx4_en_uc_steer_release(struct mlx4_en_priv *priv,
546 unsigned char *mac, int qpn, u64 reg_id)
547{
548 struct mlx4_en_dev *mdev = priv->mdev;
549 struct mlx4_dev *dev = mdev->dev;
550
551 switch (dev->caps.steering_mode) {
552 case MLX4_STEERING_MODE_B0: {
553 struct mlx4_qp qp;
554 u8 gid[16] = {0};
555
556 qp.qpn = qpn;
557 memcpy(&gid[10], mac, ETH_ALEN);
558 gid[5] = priv->port;
559
560 mlx4_unicast_detach(dev, &qp, gid, MLX4_PROT_ETH);
561 break;
562 }
563 case MLX4_STEERING_MODE_DEVICE_MANAGED: {
564 mlx4_flow_detach(dev, reg_id);
565 break;
566 }
567 default:
568 en_err(priv, "Invalid steering mode.\n");
569 }
570}
571
572static int mlx4_en_get_qp(struct mlx4_en_priv *priv)
573{
574 struct mlx4_en_dev *mdev = priv->mdev;
575 struct mlx4_dev *dev = mdev->dev;
576 struct mlx4_mac_entry *entry;
577 int index = 0;
578 int err = 0;
Jack Morgensteinc2a3d4b2014-10-27 11:37:44 +0200579 u64 reg_id = 0;
Yan Burman16a10ff2013-02-07 02:25:22 +0000580 int *qpn = &priv->base_qpn;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200581 u64 mac = mlx4_mac_to_u64(priv->dev->dev_addr);
Yan Burman16a10ff2013-02-07 02:25:22 +0000582
583 en_dbg(DRV, priv, "Registering MAC: %pM for adding\n",
584 priv->dev->dev_addr);
585 index = mlx4_register_mac(dev, priv->port, mac);
586 if (index < 0) {
587 err = index;
588 en_err(priv, "Failed adding MAC: %pM\n",
589 priv->dev->dev_addr);
590 return err;
591 }
592
593 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) {
594 int base_qpn = mlx4_get_base_qpn(dev, priv->port);
595 *qpn = base_qpn + index;
596 return 0;
597 }
598
Matan Barakd57febe2014-12-11 10:57:57 +0200599 err = mlx4_qp_reserve_range(dev, 1, 1, qpn, MLX4_RESERVE_A0_QP);
Yan Burman16a10ff2013-02-07 02:25:22 +0000600 en_dbg(DRV, priv, "Reserved qp %d\n", *qpn);
601 if (err) {
602 en_err(priv, "Failed to reserve qp for mac registration\n");
603 goto qp_err;
604 }
605
606 err = mlx4_en_uc_steer_add(priv, priv->dev->dev_addr, qpn, &reg_id);
607 if (err)
608 goto steer_err;
609
Wei Yongjun9ba75fb2014-01-07 16:56:07 +0800610 err = mlx4_en_tunnel_steer_add(priv, priv->dev->dev_addr, *qpn,
611 &priv->tunnel_reg_id);
612 if (err)
Or Gerlitz837052d2013-12-23 16:09:44 +0200613 goto tunnel_err;
614
Yan Burman16a10ff2013-02-07 02:25:22 +0000615 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
616 if (!entry) {
617 err = -ENOMEM;
618 goto alloc_err;
619 }
620 memcpy(entry->mac, priv->dev->dev_addr, sizeof(entry->mac));
Eyal Perryb94901f2014-07-22 15:44:09 +0300621 memcpy(priv->current_mac, entry->mac, sizeof(priv->current_mac));
Yan Burman16a10ff2013-02-07 02:25:22 +0000622 entry->reg_id = reg_id;
623
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000624 hlist_add_head_rcu(&entry->hlist,
625 &priv->mac_hash[entry->mac[MLX4_EN_MAC_HASH_IDX]]);
Yan Burman16a10ff2013-02-07 02:25:22 +0000626
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000627 return 0;
Yan Burman16a10ff2013-02-07 02:25:22 +0000628
629alloc_err:
Or Gerlitz837052d2013-12-23 16:09:44 +0200630 if (priv->tunnel_reg_id)
631 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
632tunnel_err:
Yan Burman16a10ff2013-02-07 02:25:22 +0000633 mlx4_en_uc_steer_release(priv, priv->dev->dev_addr, *qpn, reg_id);
634
635steer_err:
636 mlx4_qp_release_range(dev, *qpn, 1);
637
638qp_err:
639 mlx4_unregister_mac(dev, priv->port, mac);
640 return err;
641}
642
643static void mlx4_en_put_qp(struct mlx4_en_priv *priv)
644{
645 struct mlx4_en_dev *mdev = priv->mdev;
646 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000647 int qpn = priv->base_qpn;
Yan Burman83a5a6c2013-03-07 03:46:56 +0000648 u64 mac;
Yan Burman16a10ff2013-02-07 02:25:22 +0000649
Yan Burman83a5a6c2013-03-07 03:46:56 +0000650 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) {
Eugenia Emantayev98133372014-03-02 10:25:01 +0200651 mac = mlx4_mac_to_u64(priv->dev->dev_addr);
Yan Burman83a5a6c2013-03-07 03:46:56 +0000652 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n",
653 priv->dev->dev_addr);
654 mlx4_unregister_mac(dev, priv->port, mac);
655 } else {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000656 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800657 struct hlist_node *tmp;
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000658 struct hlist_head *bucket;
Yan Burman83a5a6c2013-03-07 03:46:56 +0000659 unsigned int i;
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000660
Yan Burman83a5a6c2013-03-07 03:46:56 +0000661 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) {
662 bucket = &priv->mac_hash[i];
663 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Eugenia Emantayev98133372014-03-02 10:25:01 +0200664 mac = mlx4_mac_to_u64(entry->mac);
Yan Burman83a5a6c2013-03-07 03:46:56 +0000665 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n",
666 entry->mac);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000667 mlx4_en_uc_steer_release(priv, entry->mac,
668 qpn, entry->reg_id);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000669
Yan Burman83a5a6c2013-03-07 03:46:56 +0000670 mlx4_unregister_mac(dev, priv->port, mac);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000671 hlist_del_rcu(&entry->hlist);
672 kfree_rcu(entry, rcu);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000673 }
Yan Burman16a10ff2013-02-07 02:25:22 +0000674 }
Yan Burman83a5a6c2013-03-07 03:46:56 +0000675
Or Gerlitz837052d2013-12-23 16:09:44 +0200676 if (priv->tunnel_reg_id) {
677 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
678 priv->tunnel_reg_id = 0;
679 }
680
Yan Burman83a5a6c2013-03-07 03:46:56 +0000681 en_dbg(DRV, priv, "Releasing qp: port %d, qpn %d\n",
682 priv->port, qpn);
683 mlx4_qp_release_range(dev, qpn, 1);
684 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC;
Yan Burman16a10ff2013-02-07 02:25:22 +0000685 }
686}
687
688static int mlx4_en_replace_mac(struct mlx4_en_priv *priv, int qpn,
Yan Burman90bbb742013-02-07 02:25:24 +0000689 unsigned char *new_mac, unsigned char *prev_mac)
Yan Burman16a10ff2013-02-07 02:25:22 +0000690{
691 struct mlx4_en_dev *mdev = priv->mdev;
692 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000693 int err = 0;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200694 u64 new_mac_u64 = mlx4_mac_to_u64(new_mac);
Yan Burman16a10ff2013-02-07 02:25:22 +0000695
696 if (dev->caps.steering_mode != MLX4_STEERING_MODE_A0) {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000697 struct hlist_head *bucket;
698 unsigned int mac_hash;
699 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800700 struct hlist_node *tmp;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200701 u64 prev_mac_u64 = mlx4_mac_to_u64(prev_mac);
Yan Burman16a10ff2013-02-07 02:25:22 +0000702
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000703 bucket = &priv->mac_hash[prev_mac[MLX4_EN_MAC_HASH_IDX]];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800704 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000705 if (ether_addr_equal_64bits(entry->mac, prev_mac)) {
706 mlx4_en_uc_steer_release(priv, entry->mac,
707 qpn, entry->reg_id);
708 mlx4_unregister_mac(dev, priv->port,
709 prev_mac_u64);
710 hlist_del_rcu(&entry->hlist);
711 synchronize_rcu();
712 memcpy(entry->mac, new_mac, ETH_ALEN);
713 entry->reg_id = 0;
714 mac_hash = new_mac[MLX4_EN_MAC_HASH_IDX];
715 hlist_add_head_rcu(&entry->hlist,
716 &priv->mac_hash[mac_hash]);
717 mlx4_register_mac(dev, priv->port, new_mac_u64);
718 err = mlx4_en_uc_steer_add(priv, new_mac,
719 &qpn,
720 &entry->reg_id);
Or Gerlitz2a2083f2014-03-12 17:16:31 +0200721 if (err)
722 return err;
723 if (priv->tunnel_reg_id) {
724 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
725 priv->tunnel_reg_id = 0;
726 }
727 err = mlx4_en_tunnel_steer_add(priv, new_mac, qpn,
728 &priv->tunnel_reg_id);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000729 return err;
730 }
731 }
732 return -EINVAL;
Yan Burman16a10ff2013-02-07 02:25:22 +0000733 }
734
735 return __mlx4_replace_mac(dev, priv->port, qpn, new_mac_u64);
736}
737
Noa Osherovich2695bab2014-07-08 11:25:24 +0300738static int mlx4_en_do_set_mac(struct mlx4_en_priv *priv,
739 unsigned char new_mac[ETH_ALEN + 2])
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700740{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700741 int err = 0;
742
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700743 if (priv->port_up) {
744 /* Remove old MAC and insert the new one */
Yan Burman16a10ff2013-02-07 02:25:22 +0000745 err = mlx4_en_replace_mac(priv, priv->base_qpn,
Noa Osherovich2695bab2014-07-08 11:25:24 +0300746 new_mac, priv->current_mac);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700747 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000748 en_err(priv, "Failed changing HW MAC address\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700749 } else
Yan Burman48e551f2013-02-07 02:25:21 +0000750 en_dbg(HW, priv, "Port is down while registering mac, exiting...\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700751
Noa Osherovich2695bab2014-07-08 11:25:24 +0300752 if (!err)
753 memcpy(priv->current_mac, new_mac, sizeof(priv->current_mac));
Shani Michaelliee755322014-05-14 12:15:12 +0300754
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000755 return err;
756}
757
758static int mlx4_en_set_mac(struct net_device *dev, void *addr)
759{
760 struct mlx4_en_priv *priv = netdev_priv(dev);
761 struct mlx4_en_dev *mdev = priv->mdev;
762 struct sockaddr *saddr = addr;
Noa Osherovich2695bab2014-07-08 11:25:24 +0300763 unsigned char new_mac[ETH_ALEN + 2];
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000764 int err;
765
766 if (!is_valid_ether_addr(saddr->sa_data))
767 return -EADDRNOTAVAIL;
768
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000769 mutex_lock(&mdev->state_lock);
Noa Osherovich2695bab2014-07-08 11:25:24 +0300770 memcpy(new_mac, saddr->sa_data, ETH_ALEN);
771 err = mlx4_en_do_set_mac(priv, new_mac);
772 if (!err)
773 memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700774 mutex_unlock(&mdev->state_lock);
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000775
776 return err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700777}
778
779static void mlx4_en_clear_list(struct net_device *dev)
780{
781 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000782 struct mlx4_en_mc_list *tmp, *mc_to_del;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700783
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000784 list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) {
785 list_del(&mc_to_del->list);
786 kfree(mc_to_del);
787 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700788}
789
790static void mlx4_en_cache_mclist(struct net_device *dev)
791{
792 struct mlx4_en_priv *priv = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000793 struct netdev_hw_addr *ha;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000794 struct mlx4_en_mc_list *tmp;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700795
Alexander Guller0e035672011-12-19 04:02:58 +0000796 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000797 netdev_for_each_mc_addr(ha, dev) {
798 tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC);
799 if (!tmp) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000800 mlx4_en_clear_list(dev);
801 return;
802 }
803 memcpy(tmp->addr, ha->addr, ETH_ALEN);
804 list_add_tail(&tmp->list, &priv->mc_list);
805 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700806}
807
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000808static void update_mclist_flags(struct mlx4_en_priv *priv,
809 struct list_head *dst,
810 struct list_head *src)
811{
812 struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc;
813 bool found;
814
815 /* Find all the entries that should be removed from dst,
816 * These are the entries that are not found in src
817 */
818 list_for_each_entry(dst_tmp, dst, list) {
819 found = false;
820 list_for_each_entry(src_tmp, src, list) {
dingtianhongc0623e52013-12-30 15:40:55 +0800821 if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000822 found = true;
823 break;
824 }
825 }
826 if (!found)
827 dst_tmp->action = MCLIST_REM;
828 }
829
830 /* Add entries that exist in src but not in dst
831 * mark them as need to add
832 */
833 list_for_each_entry(src_tmp, src, list) {
834 found = false;
835 list_for_each_entry(dst_tmp, dst, list) {
dingtianhongc0623e52013-12-30 15:40:55 +0800836 if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000837 dst_tmp->action = MCLIST_NONE;
838 found = true;
839 break;
840 }
841 }
842 if (!found) {
Joe Perches14f8dc42013-02-07 11:46:27 +0000843 new_mc = kmemdup(src_tmp,
844 sizeof(struct mlx4_en_mc_list),
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000845 GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +0000846 if (!new_mc)
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000847 return;
Joe Perches14f8dc42013-02-07 11:46:27 +0000848
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000849 new_mc->action = MCLIST_ADD;
850 list_add_tail(&new_mc->list, dst);
851 }
852 }
853}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700854
Yan Burman0eb74fd2013-02-07 02:25:23 +0000855static void mlx4_en_set_rx_mode(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700856{
857 struct mlx4_en_priv *priv = netdev_priv(dev);
858
859 if (!priv->port_up)
860 return;
861
Yan Burman0eb74fd2013-02-07 02:25:23 +0000862 queue_work(priv->mdev->workqueue, &priv->rx_mode_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700863}
864
Yan Burman0eb74fd2013-02-07 02:25:23 +0000865static void mlx4_en_set_promisc_mode(struct mlx4_en_priv *priv,
866 struct mlx4_en_dev *mdev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700867{
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000868 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700869
Yan Burman0eb74fd2013-02-07 02:25:23 +0000870 if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700871 if (netif_msg_rx_status(priv))
Yan Burman0eb74fd2013-02-07 02:25:23 +0000872 en_warn(priv, "Entering promiscuous mode\n");
873 priv->flags |= MLX4_EN_FLAG_PROMISC;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700874
Yan Burman0eb74fd2013-02-07 02:25:23 +0000875 /* Enable promiscouos mode */
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000876 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000877 case MLX4_STEERING_MODE_DEVICE_MANAGED:
Yan Burman0eb74fd2013-02-07 02:25:23 +0000878 err = mlx4_flow_steer_promisc_add(mdev->dev,
879 priv->port,
880 priv->base_qpn,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000881 MLX4_FS_ALL_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000882 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000883 en_err(priv, "Failed enabling promiscuous mode\n");
884 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000885 break;
886
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000887 case MLX4_STEERING_MODE_B0:
Yan Burman0eb74fd2013-02-07 02:25:23 +0000888 err = mlx4_unicast_promisc_add(mdev->dev,
889 priv->base_qpn,
890 priv->port);
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000891 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000892 en_err(priv, "Failed enabling unicast promiscuous mode\n");
893
894 /* Add the default qp number as multicast
895 * promisc
896 */
897 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
898 err = mlx4_multicast_promisc_add(mdev->dev,
899 priv->base_qpn,
900 priv->port);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000901 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000902 en_err(priv, "Failed enabling multicast promiscuous mode\n");
903 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000904 }
905 break;
906
907 case MLX4_STEERING_MODE_A0:
908 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
909 priv->port,
Yan Burman0eb74fd2013-02-07 02:25:23 +0000910 priv->base_qpn,
911 1);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000912 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000913 en_err(priv, "Failed enabling promiscuous mode\n");
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000914 break;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000915 }
916
Yan Burman0eb74fd2013-02-07 02:25:23 +0000917 /* Disable port multicast filter (unconditionally) */
918 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
919 0, MLX4_MCAST_DISABLE);
920 if (err)
921 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700922 }
Yan Burman0eb74fd2013-02-07 02:25:23 +0000923}
924
925static void mlx4_en_clear_promisc_mode(struct mlx4_en_priv *priv,
926 struct mlx4_en_dev *mdev)
927{
928 int err = 0;
929
930 if (netif_msg_rx_status(priv))
931 en_warn(priv, "Leaving promiscuous mode\n");
932 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
933
934 /* Disable promiscouos mode */
935 switch (mdev->dev->caps.steering_mode) {
936 case MLX4_STEERING_MODE_DEVICE_MANAGED:
937 err = mlx4_flow_steer_promisc_remove(mdev->dev,
938 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000939 MLX4_FS_ALL_DEFAULT);
Yan Burman0eb74fd2013-02-07 02:25:23 +0000940 if (err)
941 en_err(priv, "Failed disabling promiscuous mode\n");
942 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
943 break;
944
945 case MLX4_STEERING_MODE_B0:
946 err = mlx4_unicast_promisc_remove(mdev->dev,
947 priv->base_qpn,
948 priv->port);
949 if (err)
950 en_err(priv, "Failed disabling unicast promiscuous mode\n");
951 /* Disable Multicast promisc */
952 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
953 err = mlx4_multicast_promisc_remove(mdev->dev,
954 priv->base_qpn,
955 priv->port);
956 if (err)
957 en_err(priv, "Failed disabling multicast promiscuous mode\n");
958 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
959 }
960 break;
961
962 case MLX4_STEERING_MODE_A0:
963 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
964 priv->port,
965 priv->base_qpn, 0);
966 if (err)
967 en_err(priv, "Failed disabling promiscuous mode\n");
968 break;
969 }
Yan Burman0eb74fd2013-02-07 02:25:23 +0000970}
971
972static void mlx4_en_do_multicast(struct mlx4_en_priv *priv,
973 struct net_device *dev,
974 struct mlx4_en_dev *mdev)
975{
976 struct mlx4_en_mc_list *mclist, *tmp;
977 u64 mcast_addr = 0;
978 u8 mc_list[16] = {0};
979 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700980
981 /* Enable/disable the multicast filter according to IFF_ALLMULTI */
982 if (dev->flags & IFF_ALLMULTI) {
983 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
984 0, MLX4_MCAST_DISABLE);
985 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000986 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000987
988 /* Add the default qp number as multicast promisc */
989 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000990 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000991 case MLX4_STEERING_MODE_DEVICE_MANAGED:
992 err = mlx4_flow_steer_promisc_add(mdev->dev,
993 priv->port,
994 priv->base_qpn,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000995 MLX4_FS_MC_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000996 break;
997
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000998 case MLX4_STEERING_MODE_B0:
999 err = mlx4_multicast_promisc_add(mdev->dev,
1000 priv->base_qpn,
1001 priv->port);
1002 break;
1003
1004 case MLX4_STEERING_MODE_A0:
1005 break;
1006 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001007 if (err)
1008 en_err(priv, "Failed entering multicast promisc mode\n");
1009 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
1010 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001011 } else {
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001012 /* Disable Multicast promisc */
1013 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001014 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001015 case MLX4_STEERING_MODE_DEVICE_MANAGED:
1016 err = mlx4_flow_steer_promisc_remove(mdev->dev,
1017 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001018 MLX4_FS_MC_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +00001019 break;
1020
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +00001021 case MLX4_STEERING_MODE_B0:
1022 err = mlx4_multicast_promisc_remove(mdev->dev,
1023 priv->base_qpn,
1024 priv->port);
1025 break;
1026
1027 case MLX4_STEERING_MODE_A0:
1028 break;
1029 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001030 if (err)
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001031 en_err(priv, "Failed disabling multicast promiscuous mode\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001032 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
1033 }
Jiri Pirkoff6e2162010-03-01 05:09:14 +00001034
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001035 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
1036 0, MLX4_MCAST_DISABLE);
1037 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001038 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001039
1040 /* Flush mcast filter and init it with broadcast address */
1041 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST,
1042 1, MLX4_MCAST_CONFIG);
1043
1044 /* Update multicast list - we cache all addresses so they won't
1045 * change while HW is updated holding the command semaphor */
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +00001046 netif_addr_lock_bh(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001047 mlx4_en_cache_mclist(dev);
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +00001048 netif_addr_unlock_bh(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001049 list_for_each_entry(mclist, &priv->mc_list, list) {
Eugenia Emantayev98133372014-03-02 10:25:01 +02001050 mcast_addr = mlx4_mac_to_u64(mclist->addr);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001051 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port,
1052 mcast_addr, 0, MLX4_MCAST_CONFIG);
1053 }
1054 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
1055 0, MLX4_MCAST_ENABLE);
1056 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001057 en_err(priv, "Failed enabling multicast filter\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001058
1059 update_mclist_flags(priv, &priv->curr_list, &priv->mc_list);
1060 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
1061 if (mclist->action == MCLIST_REM) {
1062 /* detach this address and delete from list */
1063 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
1064 mc_list[5] = priv->port;
1065 err = mlx4_multicast_detach(mdev->dev,
1066 &priv->rss_map.indir_qp,
1067 mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001068 MLX4_PROT_ETH,
1069 mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001070 if (err)
1071 en_err(priv, "Fail to detach multicast address\n");
1072
Or Gerlitz837052d2013-12-23 16:09:44 +02001073 if (mclist->tunnel_reg_id) {
1074 err = mlx4_flow_detach(priv->mdev->dev, mclist->tunnel_reg_id);
1075 if (err)
1076 en_err(priv, "Failed to detach multicast address\n");
1077 }
1078
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001079 /* remove from list */
1080 list_del(&mclist->list);
1081 kfree(mclist);
Dan Carpenter9c645082012-07-10 20:34:07 +00001082 } else if (mclist->action == MCLIST_ADD) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001083 /* attach the address */
1084 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001085 /* needed for B0 steering support */
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001086 mc_list[5] = priv->port;
1087 err = mlx4_multicast_attach(mdev->dev,
1088 &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001089 mc_list,
1090 priv->port, 0,
1091 MLX4_PROT_ETH,
1092 &mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001093 if (err)
1094 en_err(priv, "Fail to attach multicast address\n");
1095
Or Gerlitz837052d2013-12-23 16:09:44 +02001096 err = mlx4_en_tunnel_steer_add(priv, &mc_list[10], priv->base_qpn,
1097 &mclist->tunnel_reg_id);
1098 if (err)
1099 en_err(priv, "Failed to attach multicast address\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001100 }
1101 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001102 }
Yan Burman0eb74fd2013-02-07 02:25:23 +00001103}
1104
Yan Burmancc5387f2013-02-07 02:25:26 +00001105static void mlx4_en_do_uc_filter(struct mlx4_en_priv *priv,
1106 struct net_device *dev,
1107 struct mlx4_en_dev *mdev)
1108{
1109 struct netdev_hw_addr *ha;
1110 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001111 struct hlist_node *tmp;
Yan Burmancc5387f2013-02-07 02:25:26 +00001112 bool found;
1113 u64 mac;
1114 int err = 0;
1115 struct hlist_head *bucket;
1116 unsigned int i;
1117 int removed = 0;
1118 u32 prev_flags;
1119
1120 /* Note that we do not need to protect our mac_hash traversal with rcu,
1121 * since all modification code is protected by mdev->state_lock
1122 */
1123
1124 /* find what to remove */
1125 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) {
1126 bucket = &priv->mac_hash[i];
Sasha Levinb67bfe02013-02-27 17:06:00 -08001127 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Yan Burmancc5387f2013-02-07 02:25:26 +00001128 found = false;
1129 netdev_for_each_uc_addr(ha, dev) {
1130 if (ether_addr_equal_64bits(entry->mac,
1131 ha->addr)) {
1132 found = true;
1133 break;
1134 }
1135 }
1136
1137 /* MAC address of the port is not in uc list */
Noa Osherovich2695bab2014-07-08 11:25:24 +03001138 if (ether_addr_equal_64bits(entry->mac,
1139 priv->current_mac))
Yan Burmancc5387f2013-02-07 02:25:26 +00001140 found = true;
1141
1142 if (!found) {
Eugenia Emantayev98133372014-03-02 10:25:01 +02001143 mac = mlx4_mac_to_u64(entry->mac);
Yan Burmancc5387f2013-02-07 02:25:26 +00001144 mlx4_en_uc_steer_release(priv, entry->mac,
1145 priv->base_qpn,
1146 entry->reg_id);
1147 mlx4_unregister_mac(mdev->dev, priv->port, mac);
1148
1149 hlist_del_rcu(&entry->hlist);
1150 kfree_rcu(entry, rcu);
1151 en_dbg(DRV, priv, "Removed MAC %pM on port:%d\n",
1152 entry->mac, priv->port);
1153 ++removed;
1154 }
1155 }
1156 }
1157
1158 /* if we didn't remove anything, there is no use in trying to add
1159 * again once we are in a forced promisc mode state
1160 */
1161 if ((priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) && 0 == removed)
1162 return;
1163
1164 prev_flags = priv->flags;
1165 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC;
1166
1167 /* find what to add */
1168 netdev_for_each_uc_addr(ha, dev) {
1169 found = false;
1170 bucket = &priv->mac_hash[ha->addr[MLX4_EN_MAC_HASH_IDX]];
Sasha Levinb67bfe02013-02-27 17:06:00 -08001171 hlist_for_each_entry(entry, bucket, hlist) {
Yan Burmancc5387f2013-02-07 02:25:26 +00001172 if (ether_addr_equal_64bits(entry->mac, ha->addr)) {
1173 found = true;
1174 break;
1175 }
1176 }
1177
1178 if (!found) {
1179 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1180 if (!entry) {
1181 en_err(priv, "Failed adding MAC %pM on port:%d (out of memory)\n",
1182 ha->addr, priv->port);
1183 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1184 break;
1185 }
Eugenia Emantayev98133372014-03-02 10:25:01 +02001186 mac = mlx4_mac_to_u64(ha->addr);
Yan Burmancc5387f2013-02-07 02:25:26 +00001187 memcpy(entry->mac, ha->addr, ETH_ALEN);
1188 err = mlx4_register_mac(mdev->dev, priv->port, mac);
1189 if (err < 0) {
1190 en_err(priv, "Failed registering MAC %pM on port %d: %d\n",
1191 ha->addr, priv->port, err);
1192 kfree(entry);
1193 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1194 break;
1195 }
1196 err = mlx4_en_uc_steer_add(priv, ha->addr,
1197 &priv->base_qpn,
1198 &entry->reg_id);
1199 if (err) {
1200 en_err(priv, "Failed adding MAC %pM on port %d: %d\n",
1201 ha->addr, priv->port, err);
1202 mlx4_unregister_mac(mdev->dev, priv->port, mac);
1203 kfree(entry);
1204 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1205 break;
1206 } else {
1207 unsigned int mac_hash;
1208 en_dbg(DRV, priv, "Added MAC %pM on port:%d\n",
1209 ha->addr, priv->port);
1210 mac_hash = ha->addr[MLX4_EN_MAC_HASH_IDX];
1211 bucket = &priv->mac_hash[mac_hash];
1212 hlist_add_head_rcu(&entry->hlist, bucket);
1213 }
1214 }
1215 }
1216
1217 if (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) {
1218 en_warn(priv, "Forcing promiscuous mode on port:%d\n",
1219 priv->port);
1220 } else if (prev_flags & MLX4_EN_FLAG_FORCE_PROMISC) {
1221 en_warn(priv, "Stop forcing promiscuous mode on port:%d\n",
1222 priv->port);
1223 }
1224}
1225
Yan Burman0eb74fd2013-02-07 02:25:23 +00001226static void mlx4_en_do_set_rx_mode(struct work_struct *work)
1227{
1228 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1229 rx_mode_task);
1230 struct mlx4_en_dev *mdev = priv->mdev;
1231 struct net_device *dev = priv->dev;
1232
1233 mutex_lock(&mdev->state_lock);
1234 if (!mdev->device_up) {
1235 en_dbg(HW, priv, "Card is not up, ignoring rx mode change.\n");
1236 goto out;
1237 }
1238 if (!priv->port_up) {
1239 en_dbg(HW, priv, "Port is down, ignoring rx mode change.\n");
1240 goto out;
1241 }
1242
1243 if (!netif_carrier_ok(dev)) {
1244 if (!mlx4_en_QUERY_PORT(mdev, priv->port)) {
1245 if (priv->port_state.link_state) {
1246 priv->last_link_state = MLX4_DEV_EVENT_PORT_UP;
1247 netif_carrier_on(dev);
1248 en_dbg(LINK, priv, "Link Up\n");
1249 }
1250 }
1251 }
1252
Yan Burmancc5387f2013-02-07 02:25:26 +00001253 if (dev->priv_flags & IFF_UNICAST_FLT)
1254 mlx4_en_do_uc_filter(priv, dev, mdev);
1255
Yan Burman0eb74fd2013-02-07 02:25:23 +00001256 /* Promsicuous mode: disable all filters */
Yan Burmancc5387f2013-02-07 02:25:26 +00001257 if ((dev->flags & IFF_PROMISC) ||
1258 (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC)) {
Yan Burman0eb74fd2013-02-07 02:25:23 +00001259 mlx4_en_set_promisc_mode(priv, mdev);
1260 goto out;
1261 }
1262
1263 /* Not in promiscuous mode */
1264 if (priv->flags & MLX4_EN_FLAG_PROMISC)
1265 mlx4_en_clear_promisc_mode(priv, mdev);
1266
1267 mlx4_en_do_multicast(priv, dev, mdev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001268out:
1269 mutex_unlock(&mdev->state_lock);
1270}
1271
1272#ifdef CONFIG_NET_POLL_CONTROLLER
1273static void mlx4_en_netpoll(struct net_device *dev)
1274{
1275 struct mlx4_en_priv *priv = netdev_priv(dev);
1276 struct mlx4_en_cq *cq;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001277 int i;
1278
1279 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001280 cq = priv->rx_cq[i];
Chris Masonc98235c2014-04-15 18:09:24 -04001281 napi_schedule(&cq->napi);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001282 }
1283}
1284#endif
1285
1286static void mlx4_en_tx_timeout(struct net_device *dev)
1287{
1288 struct mlx4_en_priv *priv = netdev_priv(dev);
1289 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001290 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001291
1292 if (netif_msg_timer(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001293 en_warn(priv, "Tx timeout called on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001294
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001295 for (i = 0; i < priv->tx_ring_num; i++) {
1296 if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev, i)))
1297 continue;
1298 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 +02001299 i, priv->tx_ring[i]->qpn, priv->tx_ring[i]->cqn,
1300 priv->tx_ring[i]->cons, priv->tx_ring[i]->prod);
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001301 }
1302
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001303 priv->port_stats.tx_timeout++;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001304 en_dbg(DRV, priv, "Scheduling watchdog\n");
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001305 queue_work(mdev->workqueue, &priv->watchdog_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001306}
1307
1308
1309static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev)
1310{
1311 struct mlx4_en_priv *priv = netdev_priv(dev);
1312
1313 spin_lock_bh(&priv->stats_lock);
1314 memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats));
1315 spin_unlock_bh(&priv->stats_lock);
1316
1317 return &priv->ret_stats;
1318}
1319
1320static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv)
1321{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001322 struct mlx4_en_cq *cq;
1323 int i;
1324
1325 /* If we haven't received a specific coalescing setting
Martin Olsson98a17082009-04-22 18:21:29 +02001326 * (module param), we set the moderation parameters as follows:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001327 * - moder_cnt is set to the number of mtu sized packets to
Eric Dumazetecfd2ce2012-11-05 16:20:42 +00001328 * satisfy our coalescing target.
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001329 * - moder_time is set to a fixed value.
1330 */
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +00001331 priv->rx_frames = MLX4_EN_RX_COAL_TARGET;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -08001332 priv->rx_usecs = MLX4_EN_RX_COAL_TIME;
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001333 priv->tx_frames = MLX4_EN_TX_COAL_PKTS;
1334 priv->tx_usecs = MLX4_EN_TX_COAL_TIME;
Yan Burman48e551f2013-02-07 02:25:21 +00001335 en_dbg(INTR, priv, "Default coalesing params for mtu:%d - rx_frames:%d rx_usecs:%d\n",
1336 priv->dev->mtu, priv->rx_frames, priv->rx_usecs);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001337
1338 /* Setup cq moderation params */
1339 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001340 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001341 cq->moder_cnt = priv->rx_frames;
1342 cq->moder_time = priv->rx_usecs;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001343 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
1344 priv->last_moder_packets[i] = 0;
1345 priv->last_moder_bytes[i] = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001346 }
1347
1348 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001349 cq = priv->tx_cq[i];
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001350 cq->moder_cnt = priv->tx_frames;
1351 cq->moder_time = priv->tx_usecs;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001352 }
1353
1354 /* Reset auto-moderation params */
1355 priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW;
1356 priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW;
1357 priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH;
1358 priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH;
1359 priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -08001360 priv->adaptive_rx_coal = 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001361 priv->last_moder_jiffies = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001362 priv->last_moder_tx_packets = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001363}
1364
1365static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv)
1366{
1367 unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001368 struct mlx4_en_cq *cq;
1369 unsigned long packets;
1370 unsigned long rate;
1371 unsigned long avg_pkt_size;
1372 unsigned long rx_packets;
1373 unsigned long rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001374 unsigned long rx_pkt_diff;
1375 int moder_time;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001376 int ring, err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001377
1378 if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ)
1379 return;
1380
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001381 for (ring = 0; ring < priv->rx_ring_num; ring++) {
1382 spin_lock_bh(&priv->stats_lock);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001383 rx_packets = priv->rx_ring[ring]->packets;
1384 rx_bytes = priv->rx_ring[ring]->bytes;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001385 spin_unlock_bh(&priv->stats_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001386
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001387 rx_pkt_diff = ((unsigned long) (rx_packets -
1388 priv->last_moder_packets[ring]));
1389 packets = rx_pkt_diff;
1390 rate = packets * HZ / period;
1391 avg_pkt_size = packets ? ((unsigned long) (rx_bytes -
1392 priv->last_moder_bytes[ring])) / packets : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001393
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001394 /* Apply auto-moderation only when packet rate
1395 * exceeds a rate that it matters */
1396 if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) &&
1397 avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001398 if (rate < priv->pkt_rate_low)
1399 moder_time = priv->rx_usecs_low;
1400 else if (rate > priv->pkt_rate_high)
1401 moder_time = priv->rx_usecs_high;
1402 else
1403 moder_time = (rate - priv->pkt_rate_low) *
1404 (priv->rx_usecs_high - priv->rx_usecs_low) /
1405 (priv->pkt_rate_high - priv->pkt_rate_low) +
1406 priv->rx_usecs_low;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001407 } else {
1408 moder_time = priv->rx_usecs_low;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001409 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001410
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001411 if (moder_time != priv->last_moder_time[ring]) {
1412 priv->last_moder_time[ring] = moder_time;
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001413 cq = priv->rx_cq[ring];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001414 cq->moder_time = moder_time;
Sagi Grimberga1c66932013-06-04 05:13:26 +00001415 cq->moder_cnt = priv->rx_frames;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001416 err = mlx4_en_set_cq_moder(priv, cq);
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001417 if (err)
Yan Burman48e551f2013-02-07 02:25:21 +00001418 en_err(priv, "Failed modifying moderation for cq:%d\n",
1419 ring);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001420 }
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001421 priv->last_moder_packets[ring] = rx_packets;
1422 priv->last_moder_bytes[ring] = rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001423 }
1424
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001425 priv->last_moder_jiffies = jiffies;
1426}
1427
1428static void mlx4_en_do_get_stats(struct work_struct *work)
1429{
Jean Delvarebf6aede2009-04-02 16:56:54 -07001430 struct delayed_work *delay = to_delayed_work(work);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001431 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
1432 stats_task);
1433 struct mlx4_en_dev *mdev = priv->mdev;
1434 int err;
1435
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001436 mutex_lock(&mdev->state_lock);
1437 if (mdev->device_up) {
Jack Morgenstein6123db22013-06-25 12:09:30 +03001438 if (priv->port_up) {
1439 err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0);
1440 if (err)
1441 en_dbg(HW, priv, "Could not update stats\n");
Eugenia Emantayev2d518372013-01-24 01:54:14 +00001442
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001443 mlx4_en_auto_moderation(priv);
Jack Morgenstein6123db22013-06-25 12:09:30 +03001444 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001445
1446 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
1447 }
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +00001448 if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
Noa Osherovich2695bab2014-07-08 11:25:24 +03001449 mlx4_en_do_set_mac(priv, priv->current_mac);
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +00001450 mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
1451 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001452 mutex_unlock(&mdev->state_lock);
1453}
1454
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001455/* mlx4_en_service_task - Run service task for tasks that needed to be done
1456 * periodically
1457 */
1458static void mlx4_en_service_task(struct work_struct *work)
1459{
1460 struct delayed_work *delay = to_delayed_work(work);
1461 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
1462 service_task);
1463 struct mlx4_en_dev *mdev = priv->mdev;
1464
1465 mutex_lock(&mdev->state_lock);
1466 if (mdev->device_up) {
Amir Vadaidc8142e2013-04-25 05:22:24 +00001467 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
1468 mlx4_en_ptp_overflow_check(mdev);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001469
Ido Shamay07841f92015-04-30 17:32:46 +03001470 mlx4_en_recover_from_oom(priv);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001471 queue_delayed_work(mdev->workqueue, &priv->service_task,
1472 SERVICE_TASK_DELAY);
1473 }
1474 mutex_unlock(&mdev->state_lock);
1475}
1476
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001477static void mlx4_en_linkstate(struct work_struct *work)
1478{
1479 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1480 linkstate_task);
1481 struct mlx4_en_dev *mdev = priv->mdev;
1482 int linkstate = priv->link_state;
1483
1484 mutex_lock(&mdev->state_lock);
1485 /* If observable port state changed set carrier state and
1486 * report to system log */
1487 if (priv->last_link_state != linkstate) {
1488 if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001489 en_info(priv, "Link Down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001490 netif_carrier_off(priv->dev);
1491 } else {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001492 en_info(priv, "Link Up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001493 netif_carrier_on(priv->dev);
1494 }
1495 }
1496 priv->last_link_state = linkstate;
1497 mutex_unlock(&mdev->state_lock);
1498}
1499
Yuval Atias9e311e72014-06-09 10:24:39 +03001500static int mlx4_en_init_affinity_hint(struct mlx4_en_priv *priv, int ring_idx)
1501{
1502 struct mlx4_en_rx_ring *ring = priv->rx_ring[ring_idx];
1503 int numa_node = priv->mdev->dev->numa_node;
1504 int ret = 0;
1505
1506 if (!zalloc_cpumask_var(&ring->affinity_mask, GFP_KERNEL))
1507 return -ENOMEM;
1508
1509 ret = cpumask_set_cpu_local_first(ring_idx, numa_node,
1510 ring->affinity_mask);
1511 if (ret)
1512 free_cpumask_var(ring->affinity_mask);
1513
1514 return ret;
1515}
1516
1517static void mlx4_en_free_affinity_hint(struct mlx4_en_priv *priv, int ring_idx)
1518{
1519 free_cpumask_var(priv->rx_ring[ring_idx]->affinity_mask);
1520}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001521
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001522int mlx4_en_start_port(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001523{
1524 struct mlx4_en_priv *priv = netdev_priv(dev);
1525 struct mlx4_en_dev *mdev = priv->mdev;
1526 struct mlx4_en_cq *cq;
1527 struct mlx4_en_tx_ring *tx_ring;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001528 int rx_index = 0;
1529 int tx_index = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001530 int err = 0;
1531 int i;
1532 int j;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001533 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001534
1535 if (priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001536 en_dbg(DRV, priv, "start port called while port already up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001537 return 0;
1538 }
1539
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001540 INIT_LIST_HEAD(&priv->mc_list);
1541 INIT_LIST_HEAD(&priv->curr_list);
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001542 INIT_LIST_HEAD(&priv->ethtool_list);
1543 memset(&priv->ethtool_rules[0], 0,
1544 sizeof(struct ethtool_flow_id) * MAX_NUM_OF_FS_RULES);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001545
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001546 /* Calculate Rx buf size */
1547 dev->mtu = min(dev->mtu, priv->max_mtu);
1548 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001549 en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_skb_size);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001550
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001551 /* Configure rx cq's and rings */
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001552 err = mlx4_en_activate_rx_rings(priv);
1553 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001554 en_err(priv, "Failed to activate RX rings\n");
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001555 return err;
1556 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001557 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001558 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001559
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001560 mlx4_en_cq_init_lock(cq);
1561
Yuval Atias9e311e72014-06-09 10:24:39 +03001562 err = mlx4_en_init_affinity_hint(priv, i);
1563 if (err) {
1564 en_err(priv, "Failed preparing IRQ affinity hint\n");
1565 goto cq_err;
1566 }
1567
Alexander Guller76532d02011-10-09 05:26:31 +00001568 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001569 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001570 en_err(priv, "Failed activating Rx CQ\n");
Yuval Atias9e311e72014-06-09 10:24:39 +03001571 mlx4_en_free_affinity_hint(priv, i);
Yevgeny Petrilina4233302009-04-26 20:41:34 +00001572 goto cq_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001573 }
Ido Shamayc3f25112014-12-16 13:28:54 +02001574
1575 for (j = 0; j < cq->size; j++) {
1576 struct mlx4_cqe *cqe = NULL;
1577
1578 cqe = mlx4_en_get_cqe(cq->buf, j, priv->cqe_size) +
1579 priv->cqe_factor;
1580 cqe->owner_sr_opcode = MLX4_CQE_OWNER_MASK;
1581 }
1582
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001583 err = mlx4_en_set_cq_moder(priv, cq);
1584 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07001585 en_err(priv, "Failed setting cq moderation parameters\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001586 mlx4_en_deactivate_cq(priv, cq);
Yuval Atias9e311e72014-06-09 10:24:39 +03001587 mlx4_en_free_affinity_hint(priv, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001588 goto cq_err;
1589 }
1590 mlx4_en_arm_cq(priv, cq);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001591 priv->rx_ring[i]->cqn = cq->mcq.cqn;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001592 ++rx_index;
1593 }
1594
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001595 /* Set qp number */
1596 en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port);
Yan Burman16a10ff2013-02-07 02:25:22 +00001597 err = mlx4_en_get_qp(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001598 if (err) {
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001599 en_err(priv, "Failed getting eth qp\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001600 goto cq_err;
1601 }
1602 mdev->mac_removed[priv->port] = 0;
1603
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001604 err = mlx4_en_config_rss_steer(priv);
1605 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001606 en_err(priv, "Failed configuring rss steering\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001607 goto mac_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001608 }
1609
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001610 err = mlx4_en_create_drop_qp(priv);
1611 if (err)
1612 goto rss_err;
1613
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001614 /* Configure tx cq's and rings */
1615 for (i = 0; i < priv->tx_ring_num; i++) {
1616 /* Configure cq */
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001617 cq = priv->tx_cq[i];
Alexander Guller76532d02011-10-09 05:26:31 +00001618 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001619 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001620 en_err(priv, "Failed allocating Tx CQ\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001621 goto tx_err;
1622 }
1623 err = mlx4_en_set_cq_moder(priv, cq);
1624 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07001625 en_err(priv, "Failed setting cq moderation parameters\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001626 mlx4_en_deactivate_cq(priv, cq);
1627 goto tx_err;
1628 }
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001629 en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001630 cq->buf->wqe_index = cpu_to_be16(0xffff);
1631
1632 /* Configure ring */
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001633 tx_ring = priv->tx_ring[i];
Amir Vadai0e98b522012-04-04 21:33:24 +00001634 err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn,
Amir Vadaid3179662012-12-02 03:49:23 +00001635 i / priv->num_tx_rings_p_up);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001636 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001637 en_err(priv, "Failed allocating Tx ring\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001638 mlx4_en_deactivate_cq(priv, cq);
1639 goto tx_err;
1640 }
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001641 tx_ring->tx_queue = netdev_get_tx_queue(dev, i);
Yevgeny Petriline22979d2012-04-23 02:18:39 +00001642
1643 /* Arm CQ for TX completions */
1644 mlx4_en_arm_cq(priv, cq);
1645
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001646 /* Set initial ownership of all Tx TXBBs to SW (1) */
1647 for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE)
1648 *((u32 *) (tx_ring->buf + j)) = 0xffffffff;
1649 ++tx_index;
1650 }
1651
1652 /* Configure port */
1653 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
1654 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001655 priv->prof->tx_pause,
1656 priv->prof->tx_ppp,
1657 priv->prof->rx_pause,
1658 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001659 if (err) {
Yan Burman48e551f2013-02-07 02:25:21 +00001660 en_err(priv, "Failed setting port general configurations for port %d, with error %d\n",
1661 priv->port, err);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001662 goto tx_err;
1663 }
1664 /* Set default qp number */
1665 err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0);
1666 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001667 en_err(priv, "Failed setting default qp numbers\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001668 goto tx_err;
1669 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001670
Or Gerlitz837052d2013-12-23 16:09:44 +02001671 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
Or Gerlitz1b136de2014-03-27 14:02:04 +02001672 err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC, 1);
Or Gerlitz837052d2013-12-23 16:09:44 +02001673 if (err) {
1674 en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n",
1675 err);
1676 goto tx_err;
1677 }
1678 }
1679
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001680 /* Init port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001681 en_dbg(HW, priv, "Initializing port\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001682 err = mlx4_INIT_PORT(mdev->dev, priv->port);
1683 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001684 en_err(priv, "Failed Initializing port\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001685 goto tx_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001686 }
1687
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001688 /* Attach rx QP to bradcast address */
Joe Perchesc7bf7162015-03-02 19:54:47 -08001689 eth_broadcast_addr(&mc_list[10]);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001690 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001691 if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001692 priv->port, 0, MLX4_PROT_ETH,
1693 &priv->broadcast_id))
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001694 mlx4_warn(mdev, "Failed Attaching Broadcast\n");
1695
Herbert Xub5845f92011-03-27 01:01:26 +00001696 /* Must redo promiscuous mode setup. */
1697 priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC);
1698
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001699 /* Schedule multicast task to populate multicast list */
Yan Burman0eb74fd2013-02-07 02:25:23 +00001700 queue_work(mdev->workqueue, &priv->rx_mode_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001701
Or Gerlitza66132f2014-04-01 11:27:13 +03001702#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz9737c6a2014-11-18 17:51:27 +02001703 if (priv->mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
Or Gerlitz1b136de2014-03-27 14:02:04 +02001704 vxlan_get_rx_port(dev);
Or Gerlitza66132f2014-04-01 11:27:13 +03001705#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001706 priv->port_up = true;
Yevgeny Petrilina11faac2009-06-20 22:15:46 +00001707 netif_tx_start_all_queues(dev);
Amir Vadai3484aac2013-01-30 23:07:11 +00001708 netif_device_attach(dev);
1709
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001710 return 0;
1711
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001712tx_err:
1713 while (tx_index--) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001714 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[tx_index]);
1715 mlx4_en_deactivate_cq(priv, priv->tx_cq[tx_index]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001716 }
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001717 mlx4_en_destroy_drop_qp(priv);
1718rss_err:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001719 mlx4_en_release_rss_steer(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001720mac_err:
Yan Burman16a10ff2013-02-07 02:25:22 +00001721 mlx4_en_put_qp(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001722cq_err:
Yuval Atias9e311e72014-06-09 10:24:39 +03001723 while (rx_index--) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001724 mlx4_en_deactivate_cq(priv, priv->rx_cq[rx_index]);
Benjamin Poirierf94813f2015-04-29 15:59:35 -07001725 mlx4_en_free_affinity_hint(priv, rx_index);
Yuval Atias9e311e72014-06-09 10:24:39 +03001726 }
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001727 for (i = 0; i < priv->rx_ring_num; i++)
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001728 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001729
1730 return err; /* need to close devices */
1731}
1732
1733
Amir Vadai3484aac2013-01-30 23:07:11 +00001734void mlx4_en_stop_port(struct net_device *dev, int detach)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001735{
1736 struct mlx4_en_priv *priv = netdev_priv(dev);
1737 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001738 struct mlx4_en_mc_list *mclist, *tmp;
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001739 struct ethtool_flow_id *flow, *tmp_flow;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001740 int i;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001741 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001742
1743 if (!priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001744 en_dbg(DRV, priv, "stop port called while port already down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001745 return;
1746 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001747
Eugenia Emantayev0cc5c8b2013-06-25 12:09:33 +03001748 /* close port*/
1749 mlx4_CLOSE_PORT(mdev->dev, priv->port);
1750
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001751 /* Synchronize with tx routine */
1752 netif_tx_lock_bh(dev);
Amir Vadai3484aac2013-01-30 23:07:11 +00001753 if (detach)
1754 netif_device_detach(dev);
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001755 netif_tx_stop_all_queues(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001756 netif_tx_unlock_bh(dev);
1757
Amir Vadai3484aac2013-01-30 23:07:11 +00001758 netif_tx_disable(dev);
1759
Yevgeny Petrilin7c287382010-08-24 03:45:45 +00001760 /* Set port as not active */
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001761 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001762
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001763 /* Promsicuous mode */
1764 if (mdev->dev->caps.steering_mode ==
1765 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1766 priv->flags &= ~(MLX4_EN_FLAG_PROMISC |
1767 MLX4_EN_FLAG_MC_PROMISC);
1768 mlx4_flow_steer_promisc_remove(mdev->dev,
1769 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001770 MLX4_FS_ALL_DEFAULT);
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001771 mlx4_flow_steer_promisc_remove(mdev->dev,
1772 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001773 MLX4_FS_MC_DEFAULT);
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001774 } else if (priv->flags & MLX4_EN_FLAG_PROMISC) {
1775 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
1776
1777 /* Disable promiscouos mode */
1778 mlx4_unicast_promisc_remove(mdev->dev, priv->base_qpn,
1779 priv->port);
1780
1781 /* Disable Multicast promisc */
1782 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
1783 mlx4_multicast_promisc_remove(mdev->dev, priv->base_qpn,
1784 priv->port);
1785 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
1786 }
1787 }
1788
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001789 /* Detach All multicasts */
Joe Perchesc7bf7162015-03-02 19:54:47 -08001790 eth_broadcast_addr(&mc_list[10]);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001791 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001792 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001793 MLX4_PROT_ETH, priv->broadcast_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001794 list_for_each_entry(mclist, &priv->curr_list, list) {
1795 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001796 mc_list[5] = priv->port;
1797 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001798 mc_list, MLX4_PROT_ETH, mclist->reg_id);
Or Gerlitzde123262014-03-13 14:52:15 +02001799 if (mclist->tunnel_reg_id)
1800 mlx4_flow_detach(mdev->dev, mclist->tunnel_reg_id);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001801 }
1802 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001803 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
1804 list_del(&mclist->list);
1805 kfree(mclist);
1806 }
1807
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001808 /* Flush multicast filter */
1809 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG);
1810
Hadar Hen Zion6efb5fa2013-03-21 05:55:53 +00001811 /* Remove flow steering rules for the port*/
1812 if (mdev->dev->caps.steering_mode ==
1813 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1814 ASSERT_RTNL();
1815 list_for_each_entry_safe(flow, tmp_flow,
1816 &priv->ethtool_list, list) {
1817 mlx4_flow_detach(mdev->dev, flow->id);
1818 list_del(&flow->list);
1819 }
1820 }
1821
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001822 mlx4_en_destroy_drop_qp(priv);
1823
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001824 /* Free TX Rings */
1825 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001826 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[i]);
1827 mlx4_en_deactivate_cq(priv, priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001828 }
1829 msleep(10);
1830
1831 for (i = 0; i < priv->tx_ring_num; i++)
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001832 mlx4_en_free_tx_buf(dev, priv->tx_ring[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001833
1834 /* Free RSS qps */
1835 mlx4_en_release_rss_steer(priv);
1836
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001837 /* Unregister Mac address for the port */
Yan Burman16a10ff2013-02-07 02:25:22 +00001838 mlx4_en_put_qp(priv);
Or Gerlitz5930e8d2013-10-15 16:55:22 +02001839 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN))
Matan Barak955154f2013-01-30 23:07:10 +00001840 mdev->mac_removed[priv->port] = 1;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001841
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001842 /* Free RX Rings */
1843 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001844 struct mlx4_en_cq *cq = priv->rx_cq[i];
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001845
1846 local_bh_disable();
1847 while (!mlx4_en_cq_lock_napi(cq)) {
1848 pr_info("CQ %d locked\n", i);
1849 mdelay(1);
1850 }
1851 local_bh_enable();
1852
Ido Shamayf4a36752014-10-27 11:37:45 +02001853 napi_synchronize(&cq->napi);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001854 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]);
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001855 mlx4_en_deactivate_cq(priv, cq);
Yuval Atias9e311e72014-06-09 10:24:39 +03001856
1857 mlx4_en_free_affinity_hint(priv, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001858 }
1859}
1860
1861static void mlx4_en_restart(struct work_struct *work)
1862{
1863 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1864 watchdog_task);
1865 struct mlx4_en_dev *mdev = priv->mdev;
1866 struct net_device *dev = priv->dev;
1867
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001868 en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001869
1870 mutex_lock(&mdev->state_lock);
1871 if (priv->port_up) {
Amir Vadai3484aac2013-01-30 23:07:11 +00001872 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001873 if (mlx4_en_start_port(dev))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001874 en_err(priv, "Failed restarting port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001875 }
1876 mutex_unlock(&mdev->state_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001877}
1878
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001879static void mlx4_en_clear_stats(struct net_device *dev)
1880{
1881 struct mlx4_en_priv *priv = netdev_priv(dev);
1882 struct mlx4_en_dev *mdev = priv->mdev;
1883 int i;
1884
1885 if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1))
1886 en_dbg(HW, priv, "Failed dumping statistics\n");
1887
1888 memset(&priv->stats, 0, sizeof(priv->stats));
1889 memset(&priv->pstats, 0, sizeof(priv->pstats));
1890 memset(&priv->pkstats, 0, sizeof(priv->pkstats));
1891 memset(&priv->port_stats, 0, sizeof(priv->port_stats));
Matan Barak0b131562015-03-30 17:45:25 +03001892 memset(&priv->rx_flowstats, 0, sizeof(priv->rx_flowstats));
1893 memset(&priv->tx_flowstats, 0, sizeof(priv->tx_flowstats));
1894 memset(&priv->rx_priority_flowstats, 0,
1895 sizeof(priv->rx_priority_flowstats));
1896 memset(&priv->tx_priority_flowstats, 0,
1897 sizeof(priv->tx_priority_flowstats));
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001898
1899 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001900 priv->tx_ring[i]->bytes = 0;
1901 priv->tx_ring[i]->packets = 0;
1902 priv->tx_ring[i]->tx_csum = 0;
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001903 }
1904 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001905 priv->rx_ring[i]->bytes = 0;
1906 priv->rx_ring[i]->packets = 0;
1907 priv->rx_ring[i]->csum_ok = 0;
1908 priv->rx_ring[i]->csum_none = 0;
Shani Michaelif8c64552014-11-09 13:51:53 +02001909 priv->rx_ring[i]->csum_complete = 0;
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001910 }
1911}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001912
1913static int mlx4_en_open(struct net_device *dev)
1914{
1915 struct mlx4_en_priv *priv = netdev_priv(dev);
1916 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001917 int err = 0;
1918
1919 mutex_lock(&mdev->state_lock);
1920
1921 if (!mdev->device_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001922 en_err(priv, "Cannot open - device down/disabled\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001923 err = -EBUSY;
1924 goto out;
1925 }
1926
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001927 /* Reset HW statistics and SW counters */
1928 mlx4_en_clear_stats(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001929
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001930 err = mlx4_en_start_port(dev);
1931 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001932 en_err(priv, "Failed starting port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001933
1934out:
1935 mutex_unlock(&mdev->state_lock);
1936 return err;
1937}
1938
1939
1940static int mlx4_en_close(struct net_device *dev)
1941{
1942 struct mlx4_en_priv *priv = netdev_priv(dev);
1943 struct mlx4_en_dev *mdev = priv->mdev;
1944
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001945 en_dbg(IFDOWN, priv, "Close port called\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001946
1947 mutex_lock(&mdev->state_lock);
1948
Amir Vadai3484aac2013-01-30 23:07:11 +00001949 mlx4_en_stop_port(dev, 0);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001950 netif_carrier_off(dev);
1951
1952 mutex_unlock(&mdev->state_lock);
1953 return 0;
1954}
1955
Alexander Gullerfe0af032011-10-09 05:26:46 +00001956void mlx4_en_free_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001957{
1958 int i;
1959
Amir Vadai1eb8c692012-07-18 22:33:52 +00001960#ifdef CONFIG_RFS_ACCEL
1961 free_irq_cpu_rmap(priv->dev->rx_cpu_rmap);
1962 priv->dev->rx_cpu_rmap = NULL;
1963#endif
1964
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001965 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001966 if (priv->tx_ring && priv->tx_ring[i])
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001967 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001968 if (priv->tx_cq && priv->tx_cq[i])
Alexander Gullerfe0af032011-10-09 05:26:46 +00001969 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001970 }
1971
1972 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001973 if (priv->rx_ring[i])
Thadeu Lima de Souza Cascardo68355f72012-02-06 08:39:49 +00001974 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
1975 priv->prof->rx_ring_size, priv->stride);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001976 if (priv->rx_cq[i])
Alexander Gullerfe0af032011-10-09 05:26:46 +00001977 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001978 }
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001979
1980 if (priv->base_tx_qpn) {
1981 mlx4_qp_release_range(priv->mdev->dev, priv->base_tx_qpn, priv->tx_ring_num);
1982 priv->base_tx_qpn = 0;
1983 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001984}
1985
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001986int mlx4_en_alloc_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001987{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001988 struct mlx4_en_port_profile *prof = priv->prof;
1989 int i;
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001990 int node;
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001991
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001992 /* Create tx Rings */
1993 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001994 node = cpu_to_node(i % num_online_cpus());
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001995 if (mlx4_en_create_cq(priv, &priv->tx_cq[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001996 prof->tx_ring_size, i, TX, node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001997 goto err;
1998
Ido Shamayd03a68f2013-12-19 21:20:14 +02001999 if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i],
Ido Shamayd03a68f2013-12-19 21:20:14 +02002000 prof->tx_ring_size, TXBB_SIZE,
2001 node, i))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002002 goto err;
2003 }
2004
2005 /* Create rx Rings */
2006 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev163561a2013-11-07 12:19:54 +02002007 node = cpu_to_node(i % num_online_cpus());
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002008 if (mlx4_en_create_cq(priv, &priv->rx_cq[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02002009 prof->rx_ring_size, i, RX, node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002010 goto err;
2011
2012 if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02002013 prof->rx_ring_size, priv->stride,
2014 node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002015 goto err;
2016 }
2017
Amir Vadai1eb8c692012-07-18 22:33:52 +00002018#ifdef CONFIG_RFS_ACCEL
Amir Vadaia229e482013-03-07 03:46:57 +00002019 if (priv->mdev->dev->caps.comp_pool) {
2020 priv->dev->rx_cpu_rmap = alloc_irq_cpu_rmap(priv->mdev->dev->caps.comp_pool);
2021 if (!priv->dev->rx_cpu_rmap)
2022 goto err;
2023 }
Amir Vadai1eb8c692012-07-18 22:33:52 +00002024#endif
2025
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002026 return 0;
2027
2028err:
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002029 en_err(priv, "Failed to allocate NIC resources\n");
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002030 for (i = 0; i < priv->rx_ring_num; i++) {
2031 if (priv->rx_ring[i])
2032 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
2033 prof->rx_ring_size,
2034 priv->stride);
2035 if (priv->rx_cq[i])
2036 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
2037 }
2038 for (i = 0; i < priv->tx_ring_num; i++) {
2039 if (priv->tx_ring[i])
2040 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
2041 if (priv->tx_cq[i])
2042 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
2043 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002044 return -ENOMEM;
2045}
2046
2047
2048void mlx4_en_destroy_netdev(struct net_device *dev)
2049{
2050 struct mlx4_en_priv *priv = netdev_priv(dev);
2051 struct mlx4_en_dev *mdev = priv->mdev;
2052
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002053 en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002054
2055 /* Unregister device - this will close the port if it was up */
2056 if (priv->registered)
2057 unregister_netdev(dev);
2058
2059 if (priv->allocated)
2060 mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE);
2061
2062 cancel_delayed_work(&priv->stats_task);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00002063 cancel_delayed_work(&priv->service_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002064 /* flush any pending task for this netdev */
2065 flush_workqueue(mdev->workqueue);
2066
2067 /* Detach the netdev so tasks would not attempt to access it */
2068 mutex_lock(&mdev->state_lock);
2069 mdev->pndev[priv->port] = NULL;
Moni Shoua5da03542015-02-03 16:48:34 +02002070 mdev->upper[priv->port] = NULL;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002071 mutex_unlock(&mdev->state_lock);
2072
Alexander Gullerfe0af032011-10-09 05:26:46 +00002073 mlx4_en_free_resources(priv);
Amir Vadai564c2742012-04-04 21:33:26 +00002074
Amir Vadaibc6a4742012-05-17 00:58:10 +00002075 kfree(priv->tx_ring);
2076 kfree(priv->tx_cq);
2077
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002078 free_netdev(dev);
2079}
2080
2081static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
2082{
2083 struct mlx4_en_priv *priv = netdev_priv(dev);
2084 struct mlx4_en_dev *mdev = priv->mdev;
2085 int err = 0;
2086
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002087 en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002088 dev->mtu, new_mtu);
2089
2090 if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002091 en_err(priv, "Bad MTU size:%d.\n", new_mtu);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002092 return -EPERM;
2093 }
2094 dev->mtu = new_mtu;
2095
2096 if (netif_running(dev)) {
2097 mutex_lock(&mdev->state_lock);
2098 if (!mdev->device_up) {
2099 /* NIC is probably restarting - let watchdog task reset
2100 * the port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002101 en_dbg(DRV, priv, "Change MTU called with card down!?\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002102 } else {
Amir Vadai3484aac2013-01-30 23:07:11 +00002103 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002104 err = mlx4_en_start_port(dev);
2105 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002106 en_err(priv, "Failed restarting port:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002107 priv->port);
2108 queue_work(mdev->workqueue, &priv->watchdog_task);
2109 }
2110 }
2111 mutex_unlock(&mdev->state_lock);
2112 }
2113 return 0;
2114}
2115
Ben Hutchings100dbda2013-11-18 23:13:31 +00002116static int mlx4_en_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
Amir Vadaiec693d42013-04-23 06:06:49 +00002117{
2118 struct mlx4_en_priv *priv = netdev_priv(dev);
2119 struct mlx4_en_dev *mdev = priv->mdev;
2120 struct hwtstamp_config config;
2121
2122 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
2123 return -EFAULT;
2124
2125 /* reserved for future extensions */
2126 if (config.flags)
2127 return -EINVAL;
2128
2129 /* device doesn't support time stamping */
2130 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS))
2131 return -EINVAL;
2132
2133 /* TX HW timestamp */
2134 switch (config.tx_type) {
2135 case HWTSTAMP_TX_OFF:
2136 case HWTSTAMP_TX_ON:
2137 break;
2138 default:
2139 return -ERANGE;
2140 }
2141
2142 /* RX HW timestamp */
2143 switch (config.rx_filter) {
2144 case HWTSTAMP_FILTER_NONE:
2145 break;
2146 case HWTSTAMP_FILTER_ALL:
2147 case HWTSTAMP_FILTER_SOME:
2148 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2149 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2150 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2151 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2152 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2153 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2154 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2155 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
2156 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
2157 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2158 case HWTSTAMP_FILTER_PTP_V2_SYNC:
2159 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
2160 config.rx_filter = HWTSTAMP_FILTER_ALL;
2161 break;
2162 default:
2163 return -ERANGE;
2164 }
2165
Saeed Mahameed7787fa62014-10-27 11:37:42 +02002166 if (mlx4_en_reset_config(dev, config, dev->features)) {
Amir Vadaiec693d42013-04-23 06:06:49 +00002167 config.tx_type = HWTSTAMP_TX_OFF;
2168 config.rx_filter = HWTSTAMP_FILTER_NONE;
2169 }
2170
2171 return copy_to_user(ifr->ifr_data, &config,
2172 sizeof(config)) ? -EFAULT : 0;
2173}
2174
Ben Hutchings100dbda2013-11-18 23:13:31 +00002175static int mlx4_en_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
2176{
2177 struct mlx4_en_priv *priv = netdev_priv(dev);
2178
2179 return copy_to_user(ifr->ifr_data, &priv->hwtstamp_config,
2180 sizeof(priv->hwtstamp_config)) ? -EFAULT : 0;
2181}
2182
Amir Vadaiec693d42013-04-23 06:06:49 +00002183static int mlx4_en_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2184{
2185 switch (cmd) {
2186 case SIOCSHWTSTAMP:
Ben Hutchings100dbda2013-11-18 23:13:31 +00002187 return mlx4_en_hwtstamp_set(dev, ifr);
2188 case SIOCGHWTSTAMP:
2189 return mlx4_en_hwtstamp_get(dev, ifr);
Amir Vadaiec693d42013-04-23 06:06:49 +00002190 default:
2191 return -EOPNOTSUPP;
2192 }
2193}
2194
Amir Vadai60d6fe92011-11-26 19:55:19 +00002195static int mlx4_en_set_features(struct net_device *netdev,
2196 netdev_features_t features)
2197{
2198 struct mlx4_en_priv *priv = netdev_priv(netdev);
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002199 bool reset = false;
Saeed Mahameed537f6f92014-10-27 11:37:43 +02002200 int ret = 0;
2201
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002202 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_RXFCS)) {
2203 en_info(priv, "Turn %s RX-FCS\n",
2204 (features & NETIF_F_RXFCS) ? "ON" : "OFF");
2205 reset = true;
2206 }
2207
Muhammad Mahajna78500b82015-04-02 16:31:22 +03002208 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_RXALL)) {
2209 u8 ignore_fcs_value = (features & NETIF_F_RXALL) ? 1 : 0;
2210
2211 en_info(priv, "Turn %s RX-ALL\n",
2212 ignore_fcs_value ? "ON" : "OFF");
2213 ret = mlx4_SET_PORT_fcs_check(priv->mdev->dev,
2214 priv->port, ignore_fcs_value);
2215 if (ret)
2216 return ret;
2217 }
2218
Saeed Mahameed537f6f92014-10-27 11:37:43 +02002219 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_HW_VLAN_CTAG_RX)) {
2220 en_info(priv, "Turn %s RX vlan strip offload\n",
2221 (features & NETIF_F_HW_VLAN_CTAG_RX) ? "ON" : "OFF");
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002222 reset = true;
Saeed Mahameed537f6f92014-10-27 11:37:43 +02002223 }
Amir Vadai60d6fe92011-11-26 19:55:19 +00002224
Ido Shamaycfb53f32015-02-03 17:57:21 +02002225 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_HW_VLAN_CTAG_TX))
2226 en_info(priv, "Turn %s TX vlan strip offload\n",
2227 (features & NETIF_F_HW_VLAN_CTAG_TX) ? "ON" : "OFF");
2228
Ido Shamay241a08c2015-04-02 16:31:07 +03002229 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_LOOPBACK)) {
2230 en_info(priv, "Turn %s loopback\n",
2231 (features & NETIF_F_LOOPBACK) ? "ON" : "OFF");
2232 mlx4_en_update_loopback_state(netdev, features);
2233 }
Yan Burman79aeacc2013-02-07 02:25:19 +00002234
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002235 if (reset) {
2236 ret = mlx4_en_reset_config(netdev, priv->hwtstamp_config,
2237 features);
2238 if (ret)
2239 return ret;
2240 }
Amir Vadai60d6fe92011-11-26 19:55:19 +00002241
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002242 return 0;
Amir Vadai60d6fe92011-11-26 19:55:19 +00002243}
2244
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002245static int mlx4_en_set_vf_mac(struct net_device *dev, int queue, u8 *mac)
2246{
2247 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2248 struct mlx4_en_dev *mdev = en_priv->mdev;
Eugenia Emantayev98133372014-03-02 10:25:01 +02002249 u64 mac_u64 = mlx4_mac_to_u64(mac);
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002250
2251 if (!is_valid_ether_addr(mac))
2252 return -EINVAL;
2253
2254 return mlx4_set_vf_mac(mdev->dev, en_priv->port, queue, mac_u64);
2255}
2256
Rony Efraim3f7fb022013-04-25 05:22:28 +00002257static int mlx4_en_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos)
2258{
2259 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2260 struct mlx4_en_dev *mdev = en_priv->mdev;
2261
2262 return mlx4_set_vf_vlan(mdev->dev, en_priv->port, vf, vlan, qos);
2263}
2264
Ido Shamaycda373f2015-04-02 16:31:16 +03002265static int mlx4_en_set_vf_rate(struct net_device *dev, int vf, int min_tx_rate,
2266 int max_tx_rate)
2267{
2268 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2269 struct mlx4_en_dev *mdev = en_priv->mdev;
2270
2271 return mlx4_set_vf_rate(mdev->dev, en_priv->port, vf, min_tx_rate,
2272 max_tx_rate);
2273}
2274
Rony Efraime6b6a232013-04-25 05:22:29 +00002275static int mlx4_en_set_vf_spoofchk(struct net_device *dev, int vf, bool setting)
2276{
2277 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2278 struct mlx4_en_dev *mdev = en_priv->mdev;
2279
2280 return mlx4_set_vf_spoofchk(mdev->dev, en_priv->port, vf, setting);
2281}
2282
Rony Efraim2cccb9e2013-04-25 05:22:30 +00002283static int mlx4_en_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_info *ivf)
2284{
2285 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2286 struct mlx4_en_dev *mdev = en_priv->mdev;
2287
2288 return mlx4_get_vf_config(mdev->dev, en_priv->port, vf, ivf);
2289}
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002290
Rony Efraim948e3062013-06-13 13:19:11 +03002291static int mlx4_en_set_vf_link_state(struct net_device *dev, int vf, int link_state)
2292{
2293 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2294 struct mlx4_en_dev *mdev = en_priv->mdev;
2295
2296 return mlx4_set_vf_link_state(mdev->dev, en_priv->port, vf, link_state);
2297}
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002298
2299#define PORT_ID_BYTE_LEN 8
2300static int mlx4_en_get_phys_port_id(struct net_device *dev,
Jiri Pirko02637fc2014-11-28 14:34:16 +01002301 struct netdev_phys_item_id *ppid)
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002302{
2303 struct mlx4_en_priv *priv = netdev_priv(dev);
2304 struct mlx4_dev *mdev = priv->mdev->dev;
2305 int i;
2306 u64 phys_port_id = mdev->caps.phys_port_id[priv->port];
2307
2308 if (!phys_port_id)
2309 return -EOPNOTSUPP;
2310
2311 ppid->id_len = sizeof(phys_port_id);
2312 for (i = PORT_ID_BYTE_LEN - 1; i >= 0; --i) {
2313 ppid->id[i] = phys_port_id & 0xff;
2314 phys_port_id >>= 8;
2315 }
2316 return 0;
2317}
2318
Or Gerlitza66132f2014-04-01 11:27:13 +03002319#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02002320static void mlx4_en_add_vxlan_offloads(struct work_struct *work)
2321{
2322 int ret;
2323 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
2324 vxlan_add_task);
2325
2326 ret = mlx4_config_vxlan_port(priv->mdev->dev, priv->vxlan_port);
2327 if (ret)
2328 goto out;
2329
2330 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port,
2331 VXLAN_STEER_BY_OUTER_MAC, 1);
2332out:
Or Gerlitzf4a1edd2014-11-09 14:25:39 +02002333 if (ret) {
Or Gerlitz1b136de2014-03-27 14:02:04 +02002334 en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret);
Or Gerlitzf4a1edd2014-11-09 14:25:39 +02002335 return;
2336 }
2337
2338 /* set offloads */
2339 priv->dev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2340 NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL;
2341 priv->dev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
2342 priv->dev->features |= NETIF_F_GSO_UDP_TUNNEL;
Or Gerlitz1b136de2014-03-27 14:02:04 +02002343}
2344
2345static void mlx4_en_del_vxlan_offloads(struct work_struct *work)
2346{
2347 int ret;
2348 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
2349 vxlan_del_task);
Or Gerlitzf4a1edd2014-11-09 14:25:39 +02002350 /* unset offloads */
2351 priv->dev->hw_enc_features &= ~(NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2352 NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL);
2353 priv->dev->hw_features &= ~NETIF_F_GSO_UDP_TUNNEL;
2354 priv->dev->features &= ~NETIF_F_GSO_UDP_TUNNEL;
Or Gerlitz1b136de2014-03-27 14:02:04 +02002355
2356 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port,
2357 VXLAN_STEER_BY_OUTER_MAC, 0);
2358 if (ret)
2359 en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret);
2360
2361 priv->vxlan_port = 0;
2362}
2363
2364static void mlx4_en_add_vxlan_port(struct net_device *dev,
2365 sa_family_t sa_family, __be16 port)
2366{
2367 struct mlx4_en_priv *priv = netdev_priv(dev);
2368 __be16 current_port;
2369
Or Gerlitze326f2f2014-07-02 17:36:23 +03002370 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
Or Gerlitz1b136de2014-03-27 14:02:04 +02002371 return;
2372
2373 if (sa_family == AF_INET6)
2374 return;
2375
2376 current_port = priv->vxlan_port;
2377 if (current_port && current_port != port) {
2378 en_warn(priv, "vxlan port %d configured, can't add port %d\n",
2379 ntohs(current_port), ntohs(port));
2380 return;
2381 }
2382
2383 priv->vxlan_port = port;
2384 queue_work(priv->mdev->workqueue, &priv->vxlan_add_task);
2385}
2386
2387static void mlx4_en_del_vxlan_port(struct net_device *dev,
2388 sa_family_t sa_family, __be16 port)
2389{
2390 struct mlx4_en_priv *priv = netdev_priv(dev);
2391 __be16 current_port;
2392
2393 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
2394 return;
2395
2396 if (sa_family == AF_INET6)
2397 return;
2398
2399 current_port = priv->vxlan_port;
2400 if (current_port != port) {
2401 en_dbg(DRV, priv, "vxlan port %d isn't configured, ignoring\n", ntohs(port));
2402 return;
2403 }
2404
2405 queue_work(priv->mdev->workqueue, &priv->vxlan_del_task);
2406}
Joe Stringer956bdab2014-11-13 16:38:14 -08002407
Jesse Gross5f352272014-12-23 22:37:26 -08002408static netdev_features_t mlx4_en_features_check(struct sk_buff *skb,
2409 struct net_device *dev,
2410 netdev_features_t features)
Joe Stringer956bdab2014-11-13 16:38:14 -08002411{
Toshiaki Makita8cb65d02015-03-27 14:31:12 +09002412 features = vlan_features_check(skb, features);
Jesse Gross5f352272014-12-23 22:37:26 -08002413 return vxlan_features_check(skb, features);
Joe Stringer956bdab2014-11-13 16:38:14 -08002414}
Or Gerlitza66132f2014-04-01 11:27:13 +03002415#endif
Or Gerlitz1b136de2014-03-27 14:02:04 +02002416
Wu Fengguangde1cf8a2015-03-19 08:51:27 +08002417static int mlx4_en_set_tx_maxrate(struct net_device *dev, int queue_index, u32 maxrate)
Or Gerlitzc10e4fc2015-03-18 14:57:35 +02002418{
2419 struct mlx4_en_priv *priv = netdev_priv(dev);
2420 struct mlx4_en_tx_ring *tx_ring = priv->tx_ring[queue_index];
2421 struct mlx4_update_qp_params params;
2422 int err;
2423
2424 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_QP_RATE_LIMIT))
2425 return -EOPNOTSUPP;
2426
2427 /* rate provided to us in Mbs, check if it fits into 12 bits, if not use Gbs */
2428 if (maxrate >> 12) {
2429 params.rate_unit = MLX4_QP_RATE_LIMIT_GBS;
2430 params.rate_val = maxrate / 1000;
2431 } else if (maxrate) {
2432 params.rate_unit = MLX4_QP_RATE_LIMIT_MBS;
2433 params.rate_val = maxrate;
2434 } else { /* zero serves to revoke the QP rate-limitation */
2435 params.rate_unit = 0;
2436 params.rate_val = 0;
2437 }
2438
2439 err = mlx4_update_qp(priv->mdev->dev, tx_ring->qpn, MLX4_UPDATE_QP_RATE_LIMIT,
2440 &params);
2441 return err;
2442}
2443
Stephen Hemminger3addc562008-11-21 17:30:58 -08002444static const struct net_device_ops mlx4_netdev_ops = {
2445 .ndo_open = mlx4_en_open,
2446 .ndo_stop = mlx4_en_close,
2447 .ndo_start_xmit = mlx4_en_xmit,
Yevgeny Petrilinf813cad2009-06-01 23:24:07 +00002448 .ndo_select_queue = mlx4_en_select_queue,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002449 .ndo_get_stats = mlx4_en_get_stats,
Yan Burman0eb74fd2013-02-07 02:25:23 +00002450 .ndo_set_rx_mode = mlx4_en_set_rx_mode,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002451 .ndo_set_mac_address = mlx4_en_set_mac,
Stephen Hemminger52255bb2009-01-09 10:45:37 +00002452 .ndo_validate_addr = eth_validate_addr,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002453 .ndo_change_mtu = mlx4_en_change_mtu,
Amir Vadaiec693d42013-04-23 06:06:49 +00002454 .ndo_do_ioctl = mlx4_en_ioctl,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002455 .ndo_tx_timeout = mlx4_en_tx_timeout,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002456 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
2457 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
2458#ifdef CONFIG_NET_POLL_CONTROLLER
2459 .ndo_poll_controller = mlx4_en_netpoll,
2460#endif
Amir Vadai60d6fe92011-11-26 19:55:19 +00002461 .ndo_set_features = mlx4_en_set_features,
Amir Vadai897d7842012-04-04 21:33:27 +00002462 .ndo_setup_tc = mlx4_en_setup_tc,
Amir Vadai1eb8c692012-07-18 22:33:52 +00002463#ifdef CONFIG_RFS_ACCEL
2464 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2465#endif
Cong Wange0d10952013-08-01 11:10:25 +08002466#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03002467 .ndo_busy_poll = mlx4_en_low_latency_recv,
Amir Vadai9e77a2b2013-06-18 16:18:27 +03002468#endif
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002469 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
Or Gerlitza66132f2014-04-01 11:27:13 +03002470#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02002471 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port,
2472 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port,
Jesse Gross5f352272014-12-23 22:37:26 -08002473 .ndo_features_check = mlx4_en_features_check,
Or Gerlitza66132f2014-04-01 11:27:13 +03002474#endif
Or Gerlitzc10e4fc2015-03-18 14:57:35 +02002475 .ndo_set_tx_maxrate = mlx4_en_set_tx_maxrate,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002476};
2477
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002478static const struct net_device_ops mlx4_netdev_ops_master = {
2479 .ndo_open = mlx4_en_open,
2480 .ndo_stop = mlx4_en_close,
2481 .ndo_start_xmit = mlx4_en_xmit,
2482 .ndo_select_queue = mlx4_en_select_queue,
2483 .ndo_get_stats = mlx4_en_get_stats,
2484 .ndo_set_rx_mode = mlx4_en_set_rx_mode,
2485 .ndo_set_mac_address = mlx4_en_set_mac,
2486 .ndo_validate_addr = eth_validate_addr,
2487 .ndo_change_mtu = mlx4_en_change_mtu,
2488 .ndo_tx_timeout = mlx4_en_tx_timeout,
2489 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
2490 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
2491 .ndo_set_vf_mac = mlx4_en_set_vf_mac,
Rony Efraim3f7fb022013-04-25 05:22:28 +00002492 .ndo_set_vf_vlan = mlx4_en_set_vf_vlan,
Ido Shamaycda373f2015-04-02 16:31:16 +03002493 .ndo_set_vf_rate = mlx4_en_set_vf_rate,
Rony Efraime6b6a232013-04-25 05:22:29 +00002494 .ndo_set_vf_spoofchk = mlx4_en_set_vf_spoofchk,
Rony Efraim948e3062013-06-13 13:19:11 +03002495 .ndo_set_vf_link_state = mlx4_en_set_vf_link_state,
Rony Efraim2cccb9e2013-04-25 05:22:30 +00002496 .ndo_get_vf_config = mlx4_en_get_vf_config,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002497#ifdef CONFIG_NET_POLL_CONTROLLER
2498 .ndo_poll_controller = mlx4_en_netpoll,
2499#endif
2500 .ndo_set_features = mlx4_en_set_features,
2501 .ndo_setup_tc = mlx4_en_setup_tc,
2502#ifdef CONFIG_RFS_ACCEL
2503 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2504#endif
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002505 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
Or Gerlitz9737c6a2014-11-18 17:51:27 +02002506#ifdef CONFIG_MLX4_EN_VXLAN
2507 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port,
2508 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port,
Jesse Gross5f352272014-12-23 22:37:26 -08002509 .ndo_features_check = mlx4_en_features_check,
Or Gerlitz9737c6a2014-11-18 17:51:27 +02002510#endif
Or Gerlitzc10e4fc2015-03-18 14:57:35 +02002511 .ndo_set_tx_maxrate = mlx4_en_set_tx_maxrate,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002512};
2513
Moni Shoua5da03542015-02-03 16:48:34 +02002514struct mlx4_en_bond {
2515 struct work_struct work;
2516 struct mlx4_en_priv *priv;
2517 int is_bonded;
2518 struct mlx4_port_map port_map;
2519};
2520
2521static void mlx4_en_bond_work(struct work_struct *work)
2522{
2523 struct mlx4_en_bond *bond = container_of(work,
2524 struct mlx4_en_bond,
2525 work);
2526 int err = 0;
2527 struct mlx4_dev *dev = bond->priv->mdev->dev;
2528
2529 if (bond->is_bonded) {
2530 if (!mlx4_is_bonded(dev)) {
2531 err = mlx4_bond(dev);
2532 if (err)
2533 en_err(bond->priv, "Fail to bond device\n");
2534 }
2535 if (!err) {
2536 err = mlx4_port_map_set(dev, &bond->port_map);
2537 if (err)
2538 en_err(bond->priv, "Fail to set port map [%d][%d]: %d\n",
2539 bond->port_map.port1,
2540 bond->port_map.port2,
2541 err);
2542 }
2543 } else if (mlx4_is_bonded(dev)) {
2544 err = mlx4_unbond(dev);
2545 if (err)
2546 en_err(bond->priv, "Fail to unbond device\n");
2547 }
2548 dev_put(bond->priv->dev);
2549 kfree(bond);
2550}
2551
2552static int mlx4_en_queue_bond_work(struct mlx4_en_priv *priv, int is_bonded,
2553 u8 v2p_p1, u8 v2p_p2)
2554{
2555 struct mlx4_en_bond *bond = NULL;
2556
2557 bond = kzalloc(sizeof(*bond), GFP_ATOMIC);
2558 if (!bond)
2559 return -ENOMEM;
2560
2561 INIT_WORK(&bond->work, mlx4_en_bond_work);
2562 bond->priv = priv;
2563 bond->is_bonded = is_bonded;
2564 bond->port_map.port1 = v2p_p1;
2565 bond->port_map.port2 = v2p_p2;
2566 dev_hold(priv->dev);
2567 queue_work(priv->mdev->workqueue, &bond->work);
2568 return 0;
2569}
2570
2571int mlx4_en_netdev_event(struct notifier_block *this,
2572 unsigned long event, void *ptr)
2573{
2574 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
2575 u8 port = 0;
2576 struct mlx4_en_dev *mdev;
2577 struct mlx4_dev *dev;
2578 int i, num_eth_ports = 0;
2579 bool do_bond = true;
2580 struct mlx4_en_priv *priv;
2581 u8 v2p_port1 = 0;
2582 u8 v2p_port2 = 0;
2583
2584 if (!net_eq(dev_net(ndev), &init_net))
2585 return NOTIFY_DONE;
2586
2587 mdev = container_of(this, struct mlx4_en_dev, nb);
2588 dev = mdev->dev;
2589
2590 /* Go into this mode only when two network devices set on two ports
2591 * of the same mlx4 device are slaves of the same bonding master
2592 */
2593 mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) {
2594 ++num_eth_ports;
2595 if (!port && (mdev->pndev[i] == ndev))
2596 port = i;
2597 mdev->upper[i] = mdev->pndev[i] ?
2598 netdev_master_upper_dev_get(mdev->pndev[i]) : NULL;
2599 /* condition not met: network device is a slave */
2600 if (!mdev->upper[i])
2601 do_bond = false;
2602 if (num_eth_ports < 2)
2603 continue;
2604 /* condition not met: same master */
2605 if (mdev->upper[i] != mdev->upper[i-1])
2606 do_bond = false;
2607 }
2608 /* condition not met: 2 salves */
2609 do_bond = (num_eth_ports == 2) ? do_bond : false;
2610
2611 /* handle only events that come with enough info */
2612 if ((do_bond && (event != NETDEV_BONDING_INFO)) || !port)
2613 return NOTIFY_DONE;
2614
2615 priv = netdev_priv(ndev);
2616 if (do_bond) {
2617 struct netdev_notifier_bonding_info *notifier_info = ptr;
2618 struct netdev_bonding_info *bonding_info =
2619 &notifier_info->bonding_info;
2620
2621 /* required mode 1, 2 or 4 */
2622 if ((bonding_info->master.bond_mode != BOND_MODE_ACTIVEBACKUP) &&
2623 (bonding_info->master.bond_mode != BOND_MODE_XOR) &&
2624 (bonding_info->master.bond_mode != BOND_MODE_8023AD))
2625 do_bond = false;
2626
2627 /* require exactly 2 slaves */
2628 if (bonding_info->master.num_slaves != 2)
2629 do_bond = false;
2630
2631 /* calc v2p */
2632 if (do_bond) {
2633 if (bonding_info->master.bond_mode ==
2634 BOND_MODE_ACTIVEBACKUP) {
2635 /* in active-backup mode virtual ports are
2636 * mapped to the physical port of the active
2637 * slave */
2638 if (bonding_info->slave.state ==
2639 BOND_STATE_BACKUP) {
2640 if (port == 1) {
2641 v2p_port1 = 2;
2642 v2p_port2 = 2;
2643 } else {
2644 v2p_port1 = 1;
2645 v2p_port2 = 1;
2646 }
2647 } else { /* BOND_STATE_ACTIVE */
2648 if (port == 1) {
2649 v2p_port1 = 1;
2650 v2p_port2 = 1;
2651 } else {
2652 v2p_port1 = 2;
2653 v2p_port2 = 2;
2654 }
2655 }
2656 } else { /* Active-Active */
2657 /* in active-active mode a virtual port is
2658 * mapped to the native physical port if and only
2659 * if the physical port is up */
2660 __s8 link = bonding_info->slave.link;
2661
2662 if (port == 1)
2663 v2p_port2 = 2;
2664 else
2665 v2p_port1 = 1;
2666 if ((link == BOND_LINK_UP) ||
2667 (link == BOND_LINK_FAIL)) {
2668 if (port == 1)
2669 v2p_port1 = 1;
2670 else
2671 v2p_port2 = 2;
2672 } else { /* BOND_LINK_DOWN || BOND_LINK_BACK */
2673 if (port == 1)
2674 v2p_port1 = 2;
2675 else
2676 v2p_port2 = 1;
2677 }
2678 }
2679 }
2680 }
2681
2682 mlx4_en_queue_bond_work(priv, do_bond,
2683 v2p_port1, v2p_port2);
2684
2685 return NOTIFY_DONE;
2686}
2687
Matan Barak0b131562015-03-30 17:45:25 +03002688void mlx4_en_update_pfc_stats_bitmap(struct mlx4_dev *dev,
2689 struct mlx4_en_stats_bitmap *stats_bitmap,
2690 u8 rx_ppp, u8 rx_pause,
2691 u8 tx_ppp, u8 tx_pause)
2692{
2693 int last_i = NUM_MAIN_STATS + NUM_PORT_STATS;
2694
2695 if (!mlx4_is_slave(dev) &&
2696 (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN)) {
2697 mutex_lock(&stats_bitmap->mutex);
2698 bitmap_clear(stats_bitmap->bitmap, last_i, NUM_FLOW_STATS);
2699
2700 if (rx_ppp)
2701 bitmap_set(stats_bitmap->bitmap, last_i,
2702 NUM_FLOW_PRIORITY_STATS_RX);
2703 last_i += NUM_FLOW_PRIORITY_STATS_RX;
2704
2705 if (rx_pause && !(rx_ppp))
2706 bitmap_set(stats_bitmap->bitmap, last_i,
2707 NUM_FLOW_STATS_RX);
2708 last_i += NUM_FLOW_STATS_RX;
2709
2710 if (tx_ppp)
2711 bitmap_set(stats_bitmap->bitmap, last_i,
2712 NUM_FLOW_PRIORITY_STATS_TX);
2713 last_i += NUM_FLOW_PRIORITY_STATS_TX;
2714
2715 if (tx_pause && !(tx_ppp))
2716 bitmap_set(stats_bitmap->bitmap, last_i,
2717 NUM_FLOW_STATS_TX);
2718 last_i += NUM_FLOW_STATS_TX;
2719
2720 mutex_unlock(&stats_bitmap->mutex);
2721 }
2722}
2723
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002724void mlx4_en_set_stats_bitmap(struct mlx4_dev *dev,
Matan Barak0b131562015-03-30 17:45:25 +03002725 struct mlx4_en_stats_bitmap *stats_bitmap,
2726 u8 rx_ppp, u8 rx_pause,
2727 u8 tx_ppp, u8 tx_pause)
Eran Ben Elishaffa88f32015-03-30 17:45:22 +03002728{
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002729 int last_i = 0;
2730
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002731 mutex_init(&stats_bitmap->mutex);
2732 bitmap_zero(stats_bitmap->bitmap, NUM_ALL_STATS);
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002733
2734 if (mlx4_is_slave(dev)) {
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002735 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002736 MLX4_FIND_NETDEV_STAT(rx_packets), 1);
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002737 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002738 MLX4_FIND_NETDEV_STAT(tx_packets), 1);
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002739 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002740 MLX4_FIND_NETDEV_STAT(rx_bytes), 1);
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002741 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002742 MLX4_FIND_NETDEV_STAT(tx_bytes), 1);
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002743 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002744 MLX4_FIND_NETDEV_STAT(rx_dropped), 1);
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002745 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002746 MLX4_FIND_NETDEV_STAT(tx_dropped), 1);
2747 } else {
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002748 bitmap_set(stats_bitmap->bitmap, last_i, NUM_MAIN_STATS);
Eran Ben Elishaffa88f32015-03-30 17:45:22 +03002749 }
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002750 last_i += NUM_MAIN_STATS;
Eran Ben Elishaffa88f32015-03-30 17:45:22 +03002751
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002752 bitmap_set(stats_bitmap->bitmap, last_i, NUM_PORT_STATS);
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002753 last_i += NUM_PORT_STATS;
Eran Ben Elishaffa88f32015-03-30 17:45:22 +03002754
Matan Barak0b131562015-03-30 17:45:25 +03002755 mlx4_en_update_pfc_stats_bitmap(dev, stats_bitmap,
2756 rx_ppp, rx_pause,
2757 tx_ppp, tx_pause);
2758 last_i += NUM_FLOW_STATS;
2759
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002760 if (!mlx4_is_slave(dev))
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002761 bitmap_set(stats_bitmap->bitmap, last_i, NUM_PKT_STATS);
Eran Ben Elishaffa88f32015-03-30 17:45:22 +03002762}
2763
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002764int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
2765 struct mlx4_en_port_profile *prof)
2766{
2767 struct net_device *dev;
2768 struct mlx4_en_priv *priv;
Yan Burmanc07cb4b2013-02-07 02:25:25 +00002769 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002770 int err;
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002771 u64 mac_u64;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002772
Tom Herbertf1593d22011-01-09 19:36:36 +00002773 dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv),
Amir Vadaid3179662012-12-02 03:49:23 +00002774 MAX_TX_RINGS, MAX_RX_RINGS);
Joe Perches41de8d42012-01-29 13:47:52 +00002775 if (dev == NULL)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002776 return -ENOMEM;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002777
Amir Vadaid3179662012-12-02 03:49:23 +00002778 netif_set_real_num_tx_queues(dev, prof->tx_ring_num);
2779 netif_set_real_num_rx_queues(dev, prof->rx_ring_num);
2780
Yishai Hadas872bf2f2015-01-25 16:59:35 +02002781 SET_NETDEV_DEV(dev, &mdev->dev->persist->pdev->dev);
Amir Vadai76a066f2014-02-25 18:17:51 +02002782 dev->dev_port = port - 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002783
2784 /*
2785 * Initialize driver private data
2786 */
2787
2788 priv = netdev_priv(dev);
2789 memset(priv, 0, sizeof(struct mlx4_en_priv));
Eugenia Emantayev207af6c2014-10-27 11:37:46 +02002790 spin_lock_init(&priv->stats_lock);
2791 INIT_WORK(&priv->rx_mode_task, mlx4_en_do_set_rx_mode);
2792 INIT_WORK(&priv->watchdog_task, mlx4_en_restart);
2793 INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate);
2794 INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats);
2795 INIT_DELAYED_WORK(&priv->service_task, mlx4_en_service_task);
2796#ifdef CONFIG_MLX4_EN_VXLAN
2797 INIT_WORK(&priv->vxlan_add_task, mlx4_en_add_vxlan_offloads);
2798 INIT_WORK(&priv->vxlan_del_task, mlx4_en_del_vxlan_offloads);
2799#endif
2800#ifdef CONFIG_RFS_ACCEL
2801 INIT_LIST_HEAD(&priv->filters);
2802 spin_lock_init(&priv->filters_lock);
2803#endif
2804
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002805 priv->dev = dev;
2806 priv->mdev = mdev;
Yevgeny Petrilinebf8c9a2012-03-06 04:03:34 +00002807 priv->ddev = &mdev->pdev->dev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002808 priv->prof = prof;
2809 priv->port = port;
2810 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002811 priv->flags = prof->flags;
Amir Vadai0fef9d02014-07-22 15:44:10 +03002812 priv->pflags = MLX4_EN_PRIV_FLAGS_BLUEFLAME;
Amir Vadai60d6fe92011-11-26 19:55:19 +00002813 priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE |
2814 MLX4_WQE_CTRL_SOLICITED);
Amir Vadaid3179662012-12-02 03:49:23 +00002815 priv->num_tx_rings_p_up = mdev->profile.num_tx_rings_p_up;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002816 priv->tx_ring_num = prof->tx_ring_num;
Amir Vadaifbc6daf2014-07-08 11:28:12 +03002817 priv->tx_work_limit = MLX4_EN_DEFAULT_TX_WORK;
Eric Dumazetbd635c32014-11-22 17:24:19 -08002818 netdev_rss_key_fill(priv->rss_key, sizeof(priv->rss_key));
Amir Vadaid3179662012-12-02 03:49:23 +00002819
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002820 priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring *) * MAX_TX_RINGS,
Amir Vadaid3179662012-12-02 03:49:23 +00002821 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00002822 if (!priv->tx_ring) {
2823 err = -ENOMEM;
2824 goto out;
2825 }
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002826 priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq *) * MAX_TX_RINGS,
Amir Vadaid3179662012-12-02 03:49:23 +00002827 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00002828 if (!priv->tx_cq) {
2829 err = -ENOMEM;
2830 goto out;
2831 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002832 priv->rx_ring_num = prof->rx_ring_num;
Or Gerlitz08ff3232012-10-21 14:59:24 +00002833 priv->cqe_factor = (mdev->dev->caps.cqe_size == 64) ? 1 : 0;
Ido Shamayb1b6b4d2014-09-18 11:51:01 +03002834 priv->cqe_size = mdev->dev->caps.cqe_size;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002835 priv->mac_index = -1;
2836 priv->msg_enable = MLX4_EN_MSG_LEVEL;
Amir Vadai564c2742012-04-04 21:33:26 +00002837#ifdef CONFIG_MLX4_EN_DCB
Or Gerlitz540b3a32013-04-07 03:44:07 +00002838 if (!mlx4_is_slave(priv->mdev->dev)) {
Ido Shamay3742cc62015-04-02 16:31:17 +03002839 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETS_CFG) {
Or Gerlitz540b3a32013-04-07 03:44:07 +00002840 dev->dcbnl_ops = &mlx4_en_dcbnl_ops;
2841 } else {
2842 en_info(priv, "enabling only PFC DCB ops\n");
2843 dev->dcbnl_ops = &mlx4_en_dcbnl_pfc_ops;
2844 }
2845 }
Amir Vadai564c2742012-04-04 21:33:26 +00002846#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002847
Yan Burmanc07cb4b2013-02-07 02:25:25 +00002848 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i)
2849 INIT_HLIST_HEAD(&priv->mac_hash[i]);
Yan Burman16a10ff2013-02-07 02:25:22 +00002850
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002851 /* Query for default mac and max mtu */
2852 priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port];
Yan Burman6bbb6d92013-02-07 02:25:20 +00002853
Shani Michaelif8c64552014-11-09 13:51:53 +02002854 if (mdev->dev->caps.rx_checksum_flags_port[priv->port] &
2855 MLX4_RX_CSUM_MODE_VAL_NON_TCP_UDP)
2856 priv->flags |= MLX4_EN_FLAG_RX_CSUM_NON_TCP_UDP;
2857
Yan Burman6bbb6d92013-02-07 02:25:20 +00002858 /* Set default MAC */
2859 dev->addr_len = ETH_ALEN;
2860 mlx4_en_u64_to_mac(dev->dev_addr, mdev->dev->caps.def_mac[priv->port]);
2861 if (!is_valid_ether_addr(dev->dev_addr)) {
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002862 if (mlx4_is_slave(priv->mdev->dev)) {
2863 eth_hw_addr_random(dev);
2864 en_warn(priv, "Assigned random MAC address %pM\n", dev->dev_addr);
Eugenia Emantayev98133372014-03-02 10:25:01 +02002865 mac_u64 = mlx4_mac_to_u64(dev->dev_addr);
Or Gerlitzef96f7d2013-06-04 05:13:28 +00002866 mdev->dev->caps.def_mac[priv->port] = mac_u64;
2867 } else {
2868 en_err(priv, "Port: %d, invalid mac burned: %pM, quiting\n",
2869 priv->port, dev->dev_addr);
2870 err = -EINVAL;
2871 goto out;
2872 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002873 }
2874
Noa Osherovich2695bab2014-07-08 11:25:24 +03002875 memcpy(priv->current_mac, dev->dev_addr, sizeof(priv->current_mac));
Yan Burman6bbb6d92013-02-07 02:25:20 +00002876
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002877 priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
2878 DS_SIZE * MLX4_EN_MAX_RX_FRAGS);
2879 err = mlx4_en_alloc_resources(priv);
2880 if (err)
2881 goto out;
2882
Amir Vadaiec693d42013-04-23 06:06:49 +00002883 /* Initialize time stamping config */
2884 priv->hwtstamp_config.flags = 0;
2885 priv->hwtstamp_config.tx_type = HWTSTAMP_TX_OFF;
2886 priv->hwtstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
2887
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002888 /* Allocate page for receive rings */
2889 err = mlx4_alloc_hwq_res(mdev->dev, &priv->res,
2890 MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE);
2891 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002892 en_err(priv, "Failed to allocate page for rx qps\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002893 goto out;
2894 }
2895 priv->allocated = 1;
2896
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002897 /*
2898 * Initialize netdev entry points
2899 */
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002900 if (mlx4_is_master(priv->mdev->dev))
2901 dev->netdev_ops = &mlx4_netdev_ops_master;
2902 else
2903 dev->netdev_ops = &mlx4_netdev_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002904 dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT;
Ben Hutchings1eb63a22010-09-27 08:29:34 +00002905 netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
2906 netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
Stephen Hemminger3addc562008-11-21 17:30:58 -08002907
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002908 dev->ethtool_ops = &mlx4_en_ethtool_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002909
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002910 /*
2911 * Set driver features
2912 */
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00002913 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
2914 if (mdev->LSO_support)
2915 dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
2916
2917 dev->vlan_features = dev->hw_features;
2918
Yevgeny Petrilinad861072011-10-18 01:51:24 +00002919 dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH;
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00002920 dev->features = dev->hw_features | NETIF_F_HIGHDMA |
Patrick McHardyf6469682013-04-19 02:04:27 +00002921 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
2922 NETIF_F_HW_VLAN_CTAG_FILTER;
Saeed Mahameed537f6f92014-10-27 11:37:43 +02002923 dev->hw_features |= NETIF_F_LOOPBACK |
2924 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002925
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002926 if (mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_FCS_KEEP)
2927 dev->hw_features |= NETIF_F_RXFCS;
2928
Muhammad Mahajna78500b82015-04-02 16:31:22 +03002929 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_IGNORE_FCS)
2930 dev->hw_features |= NETIF_F_RXALL;
2931
Amir Vadai1eb8c692012-07-18 22:33:52 +00002932 if (mdev->dev->caps.steering_mode ==
Matan Barak7d077cd2014-12-11 10:58:00 +02002933 MLX4_STEERING_MODE_DEVICE_MANAGED &&
2934 mdev->dev->caps.dmfs_high_steer_mode != MLX4_STEERING_DMFS_A0_STATIC)
Amir Vadai1eb8c692012-07-18 22:33:52 +00002935 dev->hw_features |= NETIF_F_NTUPLE;
2936
Yan Burmancc5387f2013-02-07 02:25:26 +00002937 if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_A0)
2938 dev->priv_flags |= IFF_UNICAST_FLT;
2939
Eyal Perry947cbb02014-12-02 18:12:11 +02002940 /* Setting a default hash function value */
2941 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_TOP) {
2942 priv->rss_hash_fn = ETH_RSS_HASH_TOP;
2943 } else if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_XOR) {
2944 priv->rss_hash_fn = ETH_RSS_HASH_XOR;
2945 } else {
2946 en_warn(priv,
2947 "No RSS hash capabilities exposed, using Toeplitz\n");
2948 priv->rss_hash_fn = ETH_RSS_HASH_TOP;
2949 }
2950
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002951 mdev->pndev[port] = dev;
Moni Shoua5da03542015-02-03 16:48:34 +02002952 mdev->upper[port] = NULL;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002953
2954 netif_carrier_off(dev);
Eugenia Emantayev4801ae72013-06-25 12:09:31 +03002955 mlx4_en_set_default_moderation(priv);
2956
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002957 en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num);
2958 en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num);
2959
Yan Burman79aeacc2013-02-07 02:25:19 +00002960 mlx4_en_update_loopback_state(priv->dev, priv->dev->features);
2961
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002962 /* Configure port */
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00002963 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002964 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00002965 priv->rx_skb_size + ETH_FCS_LEN,
2966 prof->tx_pause, prof->tx_ppp,
2967 prof->rx_pause, prof->rx_ppp);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002968 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07002969 en_err(priv, "Failed setting port general configurations for port %d, with error %d\n",
2970 priv->port, err);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002971 goto out;
2972 }
2973
Or Gerlitz837052d2013-12-23 16:09:44 +02002974 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
Or Gerlitz1b136de2014-03-27 14:02:04 +02002975 err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC, 1);
Or Gerlitz837052d2013-12-23 16:09:44 +02002976 if (err) {
2977 en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n",
2978 err);
2979 goto out;
2980 }
2981 }
2982
Yevgeny Petrilin90822262011-03-22 22:37:41 +00002983 /* Init port */
2984 en_warn(priv, "Initializing port\n");
2985 err = mlx4_INIT_PORT(mdev->dev, priv->port);
2986 if (err) {
2987 en_err(priv, "Failed Initializing port\n");
2988 goto out;
2989 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002990 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
Amir Vadaidc8142e2013-04-25 05:22:24 +00002991
2992 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
2993 queue_delayed_work(mdev->workqueue, &priv->service_task,
2994 SERVICE_TASK_DELAY);
2995
Matan Barak0b131562015-03-30 17:45:25 +03002996 mlx4_en_set_stats_bitmap(mdev->dev, &priv->stats_bitmap,
2997 mdev->profile.prof[priv->port].rx_ppp,
2998 mdev->profile.prof[priv->port].rx_pause,
2999 mdev->profile.prof[priv->port].tx_ppp,
3000 mdev->profile.prof[priv->port].tx_pause);
Eran Ben Elisha39de9612015-03-18 16:51:38 +02003001
Ido Shamaye5eda892015-03-24 15:18:38 +02003002 err = register_netdev(dev);
3003 if (err) {
3004 en_err(priv, "Netdev registration failed for port %d\n", port);
3005 goto out;
3006 }
3007
3008 priv->registered = 1;
3009
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07003010 return 0;
3011
3012out:
3013 mlx4_en_destroy_netdev(dev);
3014 return err;
3015}
3016
Saeed Mahameed537f6f92014-10-27 11:37:43 +02003017int mlx4_en_reset_config(struct net_device *dev,
3018 struct hwtstamp_config ts_config,
3019 netdev_features_t features)
3020{
3021 struct mlx4_en_priv *priv = netdev_priv(dev);
3022 struct mlx4_en_dev *mdev = priv->mdev;
3023 int port_up = 0;
3024 int err = 0;
3025
3026 if (priv->hwtstamp_config.tx_type == ts_config.tx_type &&
3027 priv->hwtstamp_config.rx_filter == ts_config.rx_filter &&
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03003028 !DEV_FEATURE_CHANGED(dev, features, NETIF_F_HW_VLAN_CTAG_RX) &&
3029 !DEV_FEATURE_CHANGED(dev, features, NETIF_F_RXFCS))
Saeed Mahameed537f6f92014-10-27 11:37:43 +02003030 return 0; /* Nothing to change */
3031
3032 if (DEV_FEATURE_CHANGED(dev, features, NETIF_F_HW_VLAN_CTAG_RX) &&
3033 (features & NETIF_F_HW_VLAN_CTAG_RX) &&
3034 (priv->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE)) {
3035 en_warn(priv, "Can't turn ON rx vlan offload while time-stamping rx filter is ON\n");
3036 return -EINVAL;
3037 }
3038
3039 mutex_lock(&mdev->state_lock);
3040 if (priv->port_up) {
3041 port_up = 1;
3042 mlx4_en_stop_port(dev, 1);
3043 }
3044
3045 mlx4_en_free_resources(priv);
3046
3047 en_warn(priv, "Changing device configuration rx filter(%x) rx vlan(%x)\n",
3048 ts_config.rx_filter, !!(features & NETIF_F_HW_VLAN_CTAG_RX));
3049
3050 priv->hwtstamp_config.tx_type = ts_config.tx_type;
3051 priv->hwtstamp_config.rx_filter = ts_config.rx_filter;
3052
3053 if (DEV_FEATURE_CHANGED(dev, features, NETIF_F_HW_VLAN_CTAG_RX)) {
3054 if (features & NETIF_F_HW_VLAN_CTAG_RX)
3055 dev->features |= NETIF_F_HW_VLAN_CTAG_RX;
3056 else
3057 dev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
3058 } else if (ts_config.rx_filter == HWTSTAMP_FILTER_NONE) {
3059 /* RX time-stamping is OFF, update the RX vlan offload
3060 * to the latest wanted state
3061 */
3062 if (dev->wanted_features & NETIF_F_HW_VLAN_CTAG_RX)
3063 dev->features |= NETIF_F_HW_VLAN_CTAG_RX;
3064 else
3065 dev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
3066 }
3067
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03003068 if (DEV_FEATURE_CHANGED(dev, features, NETIF_F_RXFCS)) {
3069 if (features & NETIF_F_RXFCS)
3070 dev->features |= NETIF_F_RXFCS;
3071 else
3072 dev->features &= ~NETIF_F_RXFCS;
3073 }
3074
Saeed Mahameed537f6f92014-10-27 11:37:43 +02003075 /* RX vlan offload and RX time-stamping can't co-exist !
3076 * Regardless of the caller's choice,
3077 * Turn Off RX vlan offload in case of time-stamping is ON
3078 */
3079 if (ts_config.rx_filter != HWTSTAMP_FILTER_NONE) {
3080 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
3081 en_warn(priv, "Turning off RX vlan offload since RX time-stamping is ON\n");
3082 dev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
3083 }
3084
3085 err = mlx4_en_alloc_resources(priv);
3086 if (err) {
3087 en_err(priv, "Failed reallocating port resources\n");
3088 goto out;
3089 }
3090 if (port_up) {
3091 err = mlx4_en_start_port(dev);
3092 if (err)
3093 en_err(priv, "Failed starting port\n");
3094 }
3095
3096out:
3097 mutex_unlock(&mdev->state_lock);
3098 netdev_features_change(dev);
3099 return err;
3100}