blob: b4b258c8ca47d47f804fc85adb665e9d08fa48df [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>
Jiri Pirko09d4d082016-02-26 17:32:24 +010043#include <net/devlink.h>
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070044
45#include <linux/mlx4/driver.h>
46#include <linux/mlx4/device.h>
47#include <linux/mlx4/cmd.h>
48#include <linux/mlx4/cq.h>
49
50#include "mlx4_en.h"
51#include "en_port.h"
52
Amir Vadaid3179662012-12-02 03:49:23 +000053int mlx4_en_setup_tc(struct net_device *dev, u8 up)
Amir Vadai897d7842012-04-04 21:33:27 +000054{
Amir Vadaibc6a4742012-05-17 00:58:10 +000055 struct mlx4_en_priv *priv = netdev_priv(dev);
56 int i;
Amir Vadaid3179662012-12-02 03:49:23 +000057 unsigned int offset = 0;
Amir Vadaibc6a4742012-05-17 00:58:10 +000058
59 if (up && up != MLX4_EN_NUM_UP)
Amir Vadai897d7842012-04-04 21:33:27 +000060 return -EINVAL;
61
Amir Vadaibc6a4742012-05-17 00:58:10 +000062 netdev_set_num_tc(dev, up);
63
64 /* Partition Tx queues evenly amongst UP's */
Amir Vadaibc6a4742012-05-17 00:58:10 +000065 for (i = 0; i < up; i++) {
Amir Vadaid3179662012-12-02 03:49:23 +000066 netdev_set_tc_queue(dev, i, priv->num_tx_rings_p_up, offset);
67 offset += priv->num_tx_rings_p_up;
Amir Vadaibc6a4742012-05-17 00:58:10 +000068 }
69
Amir Vadai897d7842012-04-04 21:33:27 +000070 return 0;
71}
72
John Fastabend16e5cc62016-02-16 21:16:43 -080073static int __mlx4_en_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
74 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -080075{
John Fastabend5eb4dce2016-02-29 11:26:13 -080076 if (tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -080077 return -EINVAL;
78
John Fastabend16e5cc62016-02-16 21:16:43 -080079 return mlx4_en_setup_tc(dev, tc->tc);
John Fastabende4c67342016-02-16 21:16:15 -080080}
81
Amir Vadai1eb8c692012-07-18 22:33:52 +000082#ifdef CONFIG_RFS_ACCEL
83
84struct mlx4_en_filter {
85 struct list_head next;
86 struct work_struct work;
87
Eyal Perry75a353d2013-11-07 12:19:49 +020088 u8 ip_proto;
Amir Vadai1eb8c692012-07-18 22:33:52 +000089 __be32 src_ip;
90 __be32 dst_ip;
91 __be16 src_port;
92 __be16 dst_port;
93
94 int rxq_index;
95 struct mlx4_en_priv *priv;
96 u32 flow_id; /* RFS infrastructure id */
97 int id; /* mlx4_en driver id */
98 u64 reg_id; /* Flow steering API id */
99 u8 activated; /* Used to prevent expiry before filter
100 * is attached
101 */
102 struct hlist_node filter_chain;
103};
104
105static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv);
106
Eyal Perry75a353d2013-11-07 12:19:49 +0200107static enum mlx4_net_trans_rule_id mlx4_ip_proto_to_trans_rule_id(u8 ip_proto)
108{
109 switch (ip_proto) {
110 case IPPROTO_UDP:
111 return MLX4_NET_TRANS_RULE_ID_UDP;
112 case IPPROTO_TCP:
113 return MLX4_NET_TRANS_RULE_ID_TCP;
114 default:
Eyal Perryc3ca5202014-05-14 12:15:16 +0300115 return MLX4_NET_TRANS_RULE_NUM;
Eyal Perry75a353d2013-11-07 12:19:49 +0200116 }
117};
118
Amir Vadai1eb8c692012-07-18 22:33:52 +0000119static void mlx4_en_filter_work(struct work_struct *work)
120{
121 struct mlx4_en_filter *filter = container_of(work,
122 struct mlx4_en_filter,
123 work);
124 struct mlx4_en_priv *priv = filter->priv;
Eyal Perry75a353d2013-11-07 12:19:49 +0200125 struct mlx4_spec_list spec_tcp_udp = {
126 .id = mlx4_ip_proto_to_trans_rule_id(filter->ip_proto),
Amir Vadai1eb8c692012-07-18 22:33:52 +0000127 {
128 .tcp_udp = {
129 .dst_port = filter->dst_port,
130 .dst_port_msk = (__force __be16)-1,
131 .src_port = filter->src_port,
132 .src_port_msk = (__force __be16)-1,
133 },
134 },
135 };
136 struct mlx4_spec_list spec_ip = {
137 .id = MLX4_NET_TRANS_RULE_ID_IPV4,
138 {
139 .ipv4 = {
140 .dst_ip = filter->dst_ip,
141 .dst_ip_msk = (__force __be32)-1,
142 .src_ip = filter->src_ip,
143 .src_ip_msk = (__force __be32)-1,
144 },
145 },
146 };
147 struct mlx4_spec_list spec_eth = {
148 .id = MLX4_NET_TRANS_RULE_ID_ETH,
149 };
150 struct mlx4_net_trans_rule rule = {
151 .list = LIST_HEAD_INIT(rule.list),
152 .queue_mode = MLX4_NET_TRANS_Q_LIFO,
153 .exclusive = 1,
154 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000155 .promisc_mode = MLX4_FS_REGULAR,
Amir Vadai1eb8c692012-07-18 22:33:52 +0000156 .port = priv->port,
157 .priority = MLX4_DOMAIN_RFS,
158 };
159 int rc;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000160 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
161
Eyal Perryc3ca5202014-05-14 12:15:16 +0300162 if (spec_tcp_udp.id >= MLX4_NET_TRANS_RULE_NUM) {
Eyal Perry75a353d2013-11-07 12:19:49 +0200163 en_warn(priv, "RFS: ignoring unsupported ip protocol (%d)\n",
164 filter->ip_proto);
165 goto ignore;
166 }
Amir Vadai1eb8c692012-07-18 22:33:52 +0000167 list_add_tail(&spec_eth.list, &rule.list);
168 list_add_tail(&spec_ip.list, &rule.list);
Eyal Perry75a353d2013-11-07 12:19:49 +0200169 list_add_tail(&spec_tcp_udp.list, &rule.list);
Amir Vadai1eb8c692012-07-18 22:33:52 +0000170
Amir Vadai1eb8c692012-07-18 22:33:52 +0000171 rule.qpn = priv->rss_map.qps[filter->rxq_index].qpn;
Yan Burman6bbb6d92013-02-07 02:25:20 +0000172 memcpy(spec_eth.eth.dst_mac, priv->dev->dev_addr, ETH_ALEN);
Amir Vadai1eb8c692012-07-18 22:33:52 +0000173 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
174
175 filter->activated = 0;
176
177 if (filter->reg_id) {
178 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
179 if (rc && rc != -ENOENT)
180 en_err(priv, "Error detaching flow. rc = %d\n", rc);
181 }
182
183 rc = mlx4_flow_attach(priv->mdev->dev, &rule, &filter->reg_id);
184 if (rc)
185 en_err(priv, "Error attaching flow. err = %d\n", rc);
186
Eyal Perry75a353d2013-11-07 12:19:49 +0200187ignore:
Amir Vadai1eb8c692012-07-18 22:33:52 +0000188 mlx4_en_filter_rfs_expire(priv);
189
190 filter->activated = 1;
191}
192
193static inline struct hlist_head *
194filter_hash_bucket(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
195 __be16 src_port, __be16 dst_port)
196{
197 unsigned long l;
198 int bucket_idx;
199
200 l = (__force unsigned long)src_port |
201 ((__force unsigned long)dst_port << 2);
202 l ^= (__force unsigned long)(src_ip ^ dst_ip);
203
204 bucket_idx = hash_long(l, MLX4_EN_FILTER_HASH_SHIFT);
205
206 return &priv->filter_hash[bucket_idx];
207}
208
209static struct mlx4_en_filter *
210mlx4_en_filter_alloc(struct mlx4_en_priv *priv, int rxq_index, __be32 src_ip,
Eyal Perry75a353d2013-11-07 12:19:49 +0200211 __be32 dst_ip, u8 ip_proto, __be16 src_port,
212 __be16 dst_port, u32 flow_id)
Amir Vadai1eb8c692012-07-18 22:33:52 +0000213{
214 struct mlx4_en_filter *filter = NULL;
215
216 filter = kzalloc(sizeof(struct mlx4_en_filter), GFP_ATOMIC);
217 if (!filter)
218 return NULL;
219
220 filter->priv = priv;
221 filter->rxq_index = rxq_index;
222 INIT_WORK(&filter->work, mlx4_en_filter_work);
223
224 filter->src_ip = src_ip;
225 filter->dst_ip = dst_ip;
Eyal Perry75a353d2013-11-07 12:19:49 +0200226 filter->ip_proto = ip_proto;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000227 filter->src_port = src_port;
228 filter->dst_port = dst_port;
229
230 filter->flow_id = flow_id;
231
Amir Vadaiee64c0e2012-07-25 21:21:16 +0000232 filter->id = priv->last_filter_id++ % RPS_NO_FILTER;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000233
234 list_add_tail(&filter->next, &priv->filters);
235 hlist_add_head(&filter->filter_chain,
236 filter_hash_bucket(priv, src_ip, dst_ip, src_port,
237 dst_port));
238
239 return filter;
240}
241
242static void mlx4_en_filter_free(struct mlx4_en_filter *filter)
243{
244 struct mlx4_en_priv *priv = filter->priv;
245 int rc;
246
247 list_del(&filter->next);
248
249 rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
250 if (rc && rc != -ENOENT)
251 en_err(priv, "Error detaching flow. rc = %d\n", rc);
252
253 kfree(filter);
254}
255
256static inline struct mlx4_en_filter *
257mlx4_en_filter_find(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
Eyal Perry75a353d2013-11-07 12:19:49 +0200258 u8 ip_proto, __be16 src_port, __be16 dst_port)
Amir Vadai1eb8c692012-07-18 22:33:52 +0000259{
Amir Vadai1eb8c692012-07-18 22:33:52 +0000260 struct mlx4_en_filter *filter;
261 struct mlx4_en_filter *ret = NULL;
262
Sasha Levinb67bfe02013-02-27 17:06:00 -0800263 hlist_for_each_entry(filter,
Amir Vadai1eb8c692012-07-18 22:33:52 +0000264 filter_hash_bucket(priv, src_ip, dst_ip,
265 src_port, dst_port),
266 filter_chain) {
267 if (filter->src_ip == src_ip &&
268 filter->dst_ip == dst_ip &&
Eyal Perry75a353d2013-11-07 12:19:49 +0200269 filter->ip_proto == ip_proto &&
Amir Vadai1eb8c692012-07-18 22:33:52 +0000270 filter->src_port == src_port &&
271 filter->dst_port == dst_port) {
272 ret = filter;
273 break;
274 }
275 }
276
277 return ret;
278}
279
280static int
281mlx4_en_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
282 u16 rxq_index, u32 flow_id)
283{
284 struct mlx4_en_priv *priv = netdev_priv(net_dev);
285 struct mlx4_en_filter *filter;
286 const struct iphdr *ip;
287 const __be16 *ports;
Eyal Perry75a353d2013-11-07 12:19:49 +0200288 u8 ip_proto;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000289 __be32 src_ip;
290 __be32 dst_ip;
291 __be16 src_port;
292 __be16 dst_port;
293 int nhoff = skb_network_offset(skb);
294 int ret = 0;
295
296 if (skb->protocol != htons(ETH_P_IP))
297 return -EPROTONOSUPPORT;
298
299 ip = (const struct iphdr *)(skb->data + nhoff);
300 if (ip_is_fragment(ip))
301 return -EPROTONOSUPPORT;
302
Eyal Perry75a353d2013-11-07 12:19:49 +0200303 if ((ip->protocol != IPPROTO_TCP) && (ip->protocol != IPPROTO_UDP))
304 return -EPROTONOSUPPORT;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000305 ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl);
306
Eyal Perry75a353d2013-11-07 12:19:49 +0200307 ip_proto = ip->protocol;
Amir Vadai1eb8c692012-07-18 22:33:52 +0000308 src_ip = ip->saddr;
309 dst_ip = ip->daddr;
310 src_port = ports[0];
311 dst_port = ports[1];
312
Amir Vadai1eb8c692012-07-18 22:33:52 +0000313 spin_lock_bh(&priv->filters_lock);
Eyal Perry75a353d2013-11-07 12:19:49 +0200314 filter = mlx4_en_filter_find(priv, src_ip, dst_ip, ip_proto,
315 src_port, dst_port);
Amir Vadai1eb8c692012-07-18 22:33:52 +0000316 if (filter) {
317 if (filter->rxq_index == rxq_index)
318 goto out;
319
320 filter->rxq_index = rxq_index;
321 } else {
322 filter = mlx4_en_filter_alloc(priv, rxq_index,
Eyal Perry75a353d2013-11-07 12:19:49 +0200323 src_ip, dst_ip, ip_proto,
Amir Vadai1eb8c692012-07-18 22:33:52 +0000324 src_port, dst_port, flow_id);
325 if (!filter) {
326 ret = -ENOMEM;
327 goto err;
328 }
329 }
330
331 queue_work(priv->mdev->workqueue, &filter->work);
332
333out:
334 ret = filter->id;
335err:
336 spin_unlock_bh(&priv->filters_lock);
337
338 return ret;
339}
340
Eugenia Emantayev41d942d2013-11-07 12:19:52 +0200341void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv)
Amir Vadai1eb8c692012-07-18 22:33:52 +0000342{
343 struct mlx4_en_filter *filter, *tmp;
344 LIST_HEAD(del_list);
345
346 spin_lock_bh(&priv->filters_lock);
347 list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
348 list_move(&filter->next, &del_list);
349 hlist_del(&filter->filter_chain);
350 }
351 spin_unlock_bh(&priv->filters_lock);
352
353 list_for_each_entry_safe(filter, tmp, &del_list, next) {
354 cancel_work_sync(&filter->work);
355 mlx4_en_filter_free(filter);
356 }
357}
358
359static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv)
360{
361 struct mlx4_en_filter *filter = NULL, *tmp, *last_filter = NULL;
362 LIST_HEAD(del_list);
363 int i = 0;
364
365 spin_lock_bh(&priv->filters_lock);
366 list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
367 if (i > MLX4_EN_FILTER_EXPIRY_QUOTA)
368 break;
369
370 if (filter->activated &&
371 !work_pending(&filter->work) &&
372 rps_may_expire_flow(priv->dev,
373 filter->rxq_index, filter->flow_id,
374 filter->id)) {
375 list_move(&filter->next, &del_list);
376 hlist_del(&filter->filter_chain);
377 } else
378 last_filter = filter;
379
380 i++;
381 }
382
383 if (last_filter && (&last_filter->next != priv->filters.next))
384 list_move(&priv->filters, &last_filter->next);
385
386 spin_unlock_bh(&priv->filters_lock);
387
388 list_for_each_entry_safe(filter, tmp, &del_list, next)
389 mlx4_en_filter_free(filter);
390}
391#endif
392
Patrick McHardy80d5c362013-04-19 02:04:28 +0000393static int mlx4_en_vlan_rx_add_vid(struct net_device *dev,
394 __be16 proto, u16 vid)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700395{
396 struct mlx4_en_priv *priv = netdev_priv(dev);
397 struct mlx4_en_dev *mdev = priv->mdev;
398 int err;
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300399 int idx;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700400
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000401 en_dbg(HW, priv, "adding VLAN:%d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700402
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000403 set_bit(vid, priv->active_vlans);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700404
405 /* Add VID to port VLAN filter */
406 mutex_lock(&mdev->state_lock);
407 if (mdev->device_up && priv->port_up) {
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000408 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700409 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000410 en_err(priv, "Failed configuring VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700411 }
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300412 if (mlx4_register_vlan(mdev->dev, priv->port, vid, &idx))
Eugenia Emantayev9e19b542013-06-25 12:09:32 +0300413 en_dbg(HW, priv, "failed adding vlan %d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700414 mutex_unlock(&mdev->state_lock);
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300415
Jiri Pirko8e586132011-12-08 19:52:37 -0500416 return 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700417}
418
Patrick McHardy80d5c362013-04-19 02:04:28 +0000419static int mlx4_en_vlan_rx_kill_vid(struct net_device *dev,
420 __be16 proto, u16 vid)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700421{
422 struct mlx4_en_priv *priv = netdev_priv(dev);
423 struct mlx4_en_dev *mdev = priv->mdev;
424 int err;
425
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000426 en_dbg(HW, priv, "Killing VID:%d\n", vid);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700427
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000428 clear_bit(vid, priv->active_vlans);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700429
430 /* Remove VID from port VLAN filter */
431 mutex_lock(&mdev->state_lock);
Jack Morgenstein2009d002013-11-03 10:03:19 +0200432 mlx4_unregister_vlan(mdev->dev, priv->port, vid);
Eli Cohen4c3eb3c2010-08-26 17:19:22 +0300433
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700434 if (mdev->device_up && priv->port_up) {
Jiri Pirkof1b553f2011-07-20 04:54:22 +0000435 err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700436 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000437 en_err(priv, "Failed configuring VLAN filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700438 }
439 mutex_unlock(&mdev->state_lock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500440
441 return 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700442}
443
Yan Burman6bbb6d92013-02-07 02:25:20 +0000444static void mlx4_en_u64_to_mac(unsigned char dst_mac[ETH_ALEN + 2], u64 src_mac)
445{
Yan Burmanbab6a9e2013-04-02 16:49:45 +0300446 int i;
447 for (i = ETH_ALEN - 1; i >= 0; --i) {
Yan Burman6bbb6d92013-02-07 02:25:20 +0000448 dst_mac[i] = src_mac & 0xff;
449 src_mac >>= 8;
450 }
451 memset(&dst_mac[ETH_ALEN], 0, 2);
452}
453
Or Gerlitz837052d2013-12-23 16:09:44 +0200454
455static int mlx4_en_tunnel_steer_add(struct mlx4_en_priv *priv, unsigned char *addr,
456 int qpn, u64 *reg_id)
457{
458 int err;
Or Gerlitz837052d2013-12-23 16:09:44 +0200459
Or Gerlitz5eff6da2015-01-15 15:28:54 +0200460 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN ||
461 priv->mdev->dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_STATIC)
Or Gerlitz837052d2013-12-23 16:09:44 +0200462 return 0; /* do nothing */
463
Or Gerlitzb95089d2014-08-27 16:47:48 +0300464 err = mlx4_tunnel_steer_add(priv->mdev->dev, addr, priv->port, qpn,
465 MLX4_DOMAIN_NIC, reg_id);
Or Gerlitz837052d2013-12-23 16:09:44 +0200466 if (err) {
467 en_err(priv, "failed to add vxlan steering rule, err %d\n", err);
468 return err;
469 }
470 en_dbg(DRV, priv, "added vxlan steering rule, mac %pM reg_id %llx\n", addr, *reg_id);
471 return 0;
472}
473
474
Yan Burman16a10ff2013-02-07 02:25:22 +0000475static int mlx4_en_uc_steer_add(struct mlx4_en_priv *priv,
476 unsigned char *mac, int *qpn, u64 *reg_id)
477{
478 struct mlx4_en_dev *mdev = priv->mdev;
479 struct mlx4_dev *dev = mdev->dev;
480 int err;
481
482 switch (dev->caps.steering_mode) {
483 case MLX4_STEERING_MODE_B0: {
484 struct mlx4_qp qp;
485 u8 gid[16] = {0};
486
487 qp.qpn = *qpn;
488 memcpy(&gid[10], mac, ETH_ALEN);
489 gid[5] = priv->port;
490
491 err = mlx4_unicast_attach(dev, &qp, gid, 0, MLX4_PROT_ETH);
492 break;
493 }
494 case MLX4_STEERING_MODE_DEVICE_MANAGED: {
495 struct mlx4_spec_list spec_eth = { {NULL} };
496 __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
497
498 struct mlx4_net_trans_rule rule = {
499 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
500 .exclusive = 0,
501 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000502 .promisc_mode = MLX4_FS_REGULAR,
Yan Burman16a10ff2013-02-07 02:25:22 +0000503 .priority = MLX4_DOMAIN_NIC,
504 };
505
506 rule.port = priv->port;
507 rule.qpn = *qpn;
508 INIT_LIST_HEAD(&rule.list);
509
510 spec_eth.id = MLX4_NET_TRANS_RULE_ID_ETH;
511 memcpy(spec_eth.eth.dst_mac, mac, ETH_ALEN);
512 memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
513 list_add_tail(&spec_eth.list, &rule.list);
514
515 err = mlx4_flow_attach(dev, &rule, reg_id);
516 break;
517 }
518 default:
519 return -EINVAL;
520 }
521 if (err)
522 en_warn(priv, "Failed Attaching Unicast\n");
523
524 return err;
525}
526
527static void mlx4_en_uc_steer_release(struct mlx4_en_priv *priv,
528 unsigned char *mac, int qpn, u64 reg_id)
529{
530 struct mlx4_en_dev *mdev = priv->mdev;
531 struct mlx4_dev *dev = mdev->dev;
532
533 switch (dev->caps.steering_mode) {
534 case MLX4_STEERING_MODE_B0: {
535 struct mlx4_qp qp;
536 u8 gid[16] = {0};
537
538 qp.qpn = qpn;
539 memcpy(&gid[10], mac, ETH_ALEN);
540 gid[5] = priv->port;
541
542 mlx4_unicast_detach(dev, &qp, gid, MLX4_PROT_ETH);
543 break;
544 }
545 case MLX4_STEERING_MODE_DEVICE_MANAGED: {
546 mlx4_flow_detach(dev, reg_id);
547 break;
548 }
549 default:
550 en_err(priv, "Invalid steering mode.\n");
551 }
552}
553
554static int mlx4_en_get_qp(struct mlx4_en_priv *priv)
555{
556 struct mlx4_en_dev *mdev = priv->mdev;
557 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000558 int index = 0;
559 int err = 0;
Yan Burman16a10ff2013-02-07 02:25:22 +0000560 int *qpn = &priv->base_qpn;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200561 u64 mac = mlx4_mac_to_u64(priv->dev->dev_addr);
Yan Burman16a10ff2013-02-07 02:25:22 +0000562
563 en_dbg(DRV, priv, "Registering MAC: %pM for adding\n",
564 priv->dev->dev_addr);
565 index = mlx4_register_mac(dev, priv->port, mac);
566 if (index < 0) {
567 err = index;
568 en_err(priv, "Failed adding MAC: %pM\n",
569 priv->dev->dev_addr);
570 return err;
571 }
572
573 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) {
574 int base_qpn = mlx4_get_base_qpn(dev, priv->port);
575 *qpn = base_qpn + index;
576 return 0;
577 }
578
Matan Barakd57febe2014-12-11 10:57:57 +0200579 err = mlx4_qp_reserve_range(dev, 1, 1, qpn, MLX4_RESERVE_A0_QP);
Yan Burman16a10ff2013-02-07 02:25:22 +0000580 en_dbg(DRV, priv, "Reserved qp %d\n", *qpn);
581 if (err) {
582 en_err(priv, "Failed to reserve qp for mac registration\n");
Ido Shamayba4b87ae2015-10-08 17:14:01 +0300583 mlx4_unregister_mac(dev, priv->port, mac);
584 return err;
Yan Burman16a10ff2013-02-07 02:25:22 +0000585 }
586
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000587 return 0;
Yan Burman16a10ff2013-02-07 02:25:22 +0000588}
589
590static void mlx4_en_put_qp(struct mlx4_en_priv *priv)
591{
592 struct mlx4_en_dev *mdev = priv->mdev;
593 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000594 int qpn = priv->base_qpn;
Yan Burman16a10ff2013-02-07 02:25:22 +0000595
Yan Burman83a5a6c2013-03-07 03:46:56 +0000596 if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) {
Ido Shamayba4b87ae2015-10-08 17:14:01 +0300597 u64 mac = mlx4_mac_to_u64(priv->dev->dev_addr);
Yan Burman83a5a6c2013-03-07 03:46:56 +0000598 en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n",
599 priv->dev->dev_addr);
600 mlx4_unregister_mac(dev, priv->port, mac);
601 } else {
Yan Burman83a5a6c2013-03-07 03:46:56 +0000602 en_dbg(DRV, priv, "Releasing qp: port %d, qpn %d\n",
603 priv->port, qpn);
604 mlx4_qp_release_range(dev, qpn, 1);
605 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC;
Yan Burman16a10ff2013-02-07 02:25:22 +0000606 }
607}
608
609static int mlx4_en_replace_mac(struct mlx4_en_priv *priv, int qpn,
Yan Burman90bbb742013-02-07 02:25:24 +0000610 unsigned char *new_mac, unsigned char *prev_mac)
Yan Burman16a10ff2013-02-07 02:25:22 +0000611{
612 struct mlx4_en_dev *mdev = priv->mdev;
613 struct mlx4_dev *dev = mdev->dev;
Yan Burman16a10ff2013-02-07 02:25:22 +0000614 int err = 0;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200615 u64 new_mac_u64 = mlx4_mac_to_u64(new_mac);
Yan Burman16a10ff2013-02-07 02:25:22 +0000616
617 if (dev->caps.steering_mode != MLX4_STEERING_MODE_A0) {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000618 struct hlist_head *bucket;
619 unsigned int mac_hash;
620 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800621 struct hlist_node *tmp;
Eugenia Emantayev98133372014-03-02 10:25:01 +0200622 u64 prev_mac_u64 = mlx4_mac_to_u64(prev_mac);
Yan Burman16a10ff2013-02-07 02:25:22 +0000623
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000624 bucket = &priv->mac_hash[prev_mac[MLX4_EN_MAC_HASH_IDX]];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800625 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000626 if (ether_addr_equal_64bits(entry->mac, prev_mac)) {
627 mlx4_en_uc_steer_release(priv, entry->mac,
628 qpn, entry->reg_id);
629 mlx4_unregister_mac(dev, priv->port,
630 prev_mac_u64);
631 hlist_del_rcu(&entry->hlist);
632 synchronize_rcu();
633 memcpy(entry->mac, new_mac, ETH_ALEN);
634 entry->reg_id = 0;
635 mac_hash = new_mac[MLX4_EN_MAC_HASH_IDX];
636 hlist_add_head_rcu(&entry->hlist,
637 &priv->mac_hash[mac_hash]);
638 mlx4_register_mac(dev, priv->port, new_mac_u64);
639 err = mlx4_en_uc_steer_add(priv, new_mac,
640 &qpn,
641 &entry->reg_id);
Or Gerlitz2a2083f2014-03-12 17:16:31 +0200642 if (err)
643 return err;
644 if (priv->tunnel_reg_id) {
645 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
646 priv->tunnel_reg_id = 0;
647 }
648 err = mlx4_en_tunnel_steer_add(priv, new_mac, qpn,
649 &priv->tunnel_reg_id);
Yan Burmanc07cb4b2013-02-07 02:25:25 +0000650 return err;
651 }
652 }
653 return -EINVAL;
Yan Burman16a10ff2013-02-07 02:25:22 +0000654 }
655
656 return __mlx4_replace_mac(dev, priv->port, qpn, new_mac_u64);
657}
658
Noa Osherovich2695bab2014-07-08 11:25:24 +0300659static int mlx4_en_do_set_mac(struct mlx4_en_priv *priv,
660 unsigned char new_mac[ETH_ALEN + 2])
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700661{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700662 int err = 0;
663
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700664 if (priv->port_up) {
665 /* Remove old MAC and insert the new one */
Yan Burman16a10ff2013-02-07 02:25:22 +0000666 err = mlx4_en_replace_mac(priv, priv->base_qpn,
Noa Osherovich2695bab2014-07-08 11:25:24 +0300667 new_mac, priv->current_mac);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700668 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000669 en_err(priv, "Failed changing HW MAC address\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700670 } else
Yan Burman48e551f2013-02-07 02:25:21 +0000671 en_dbg(HW, priv, "Port is down while registering mac, exiting...\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700672
Noa Osherovich2695bab2014-07-08 11:25:24 +0300673 if (!err)
674 memcpy(priv->current_mac, new_mac, sizeof(priv->current_mac));
Shani Michaelliee755322014-05-14 12:15:12 +0300675
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000676 return err;
677}
678
679static int mlx4_en_set_mac(struct net_device *dev, void *addr)
680{
681 struct mlx4_en_priv *priv = netdev_priv(dev);
682 struct mlx4_en_dev *mdev = priv->mdev;
683 struct sockaddr *saddr = addr;
Noa Osherovich2695bab2014-07-08 11:25:24 +0300684 unsigned char new_mac[ETH_ALEN + 2];
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000685 int err;
686
687 if (!is_valid_ether_addr(saddr->sa_data))
688 return -EADDRNOTAVAIL;
689
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000690 mutex_lock(&mdev->state_lock);
Noa Osherovich2695bab2014-07-08 11:25:24 +0300691 memcpy(new_mac, saddr->sa_data, ETH_ALEN);
692 err = mlx4_en_do_set_mac(priv, new_mac);
693 if (!err)
694 memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700695 mutex_unlock(&mdev->state_lock);
Yan Burmanbfa8ab42013-03-07 03:46:55 +0000696
697 return err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700698}
699
700static void mlx4_en_clear_list(struct net_device *dev)
701{
702 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000703 struct mlx4_en_mc_list *tmp, *mc_to_del;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700704
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000705 list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) {
706 list_del(&mc_to_del->list);
707 kfree(mc_to_del);
708 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700709}
710
711static void mlx4_en_cache_mclist(struct net_device *dev)
712{
713 struct mlx4_en_priv *priv = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000714 struct netdev_hw_addr *ha;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000715 struct mlx4_en_mc_list *tmp;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700716
Alexander Guller0e035672011-12-19 04:02:58 +0000717 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000718 netdev_for_each_mc_addr(ha, dev) {
719 tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC);
720 if (!tmp) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000721 mlx4_en_clear_list(dev);
722 return;
723 }
724 memcpy(tmp->addr, ha->addr, ETH_ALEN);
725 list_add_tail(&tmp->list, &priv->mc_list);
726 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700727}
728
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000729static void update_mclist_flags(struct mlx4_en_priv *priv,
730 struct list_head *dst,
731 struct list_head *src)
732{
733 struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc;
734 bool found;
735
736 /* Find all the entries that should be removed from dst,
737 * These are the entries that are not found in src
738 */
739 list_for_each_entry(dst_tmp, dst, list) {
740 found = false;
741 list_for_each_entry(src_tmp, src, list) {
dingtianhongc0623e52013-12-30 15:40:55 +0800742 if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000743 found = true;
744 break;
745 }
746 }
747 if (!found)
748 dst_tmp->action = MCLIST_REM;
749 }
750
751 /* Add entries that exist in src but not in dst
752 * mark them as need to add
753 */
754 list_for_each_entry(src_tmp, src, list) {
755 found = false;
756 list_for_each_entry(dst_tmp, dst, list) {
dingtianhongc0623e52013-12-30 15:40:55 +0800757 if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000758 dst_tmp->action = MCLIST_NONE;
759 found = true;
760 break;
761 }
762 }
763 if (!found) {
Joe Perches14f8dc42013-02-07 11:46:27 +0000764 new_mc = kmemdup(src_tmp,
765 sizeof(struct mlx4_en_mc_list),
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000766 GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +0000767 if (!new_mc)
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000768 return;
Joe Perches14f8dc42013-02-07 11:46:27 +0000769
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000770 new_mc->action = MCLIST_ADD;
771 list_add_tail(&new_mc->list, dst);
772 }
773 }
774}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700775
Yan Burman0eb74fd2013-02-07 02:25:23 +0000776static void mlx4_en_set_rx_mode(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700777{
778 struct mlx4_en_priv *priv = netdev_priv(dev);
779
780 if (!priv->port_up)
781 return;
782
Yan Burman0eb74fd2013-02-07 02:25:23 +0000783 queue_work(priv->mdev->workqueue, &priv->rx_mode_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700784}
785
Yan Burman0eb74fd2013-02-07 02:25:23 +0000786static void mlx4_en_set_promisc_mode(struct mlx4_en_priv *priv,
787 struct mlx4_en_dev *mdev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700788{
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000789 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700790
Yan Burman0eb74fd2013-02-07 02:25:23 +0000791 if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700792 if (netif_msg_rx_status(priv))
Yan Burman0eb74fd2013-02-07 02:25:23 +0000793 en_warn(priv, "Entering promiscuous mode\n");
794 priv->flags |= MLX4_EN_FLAG_PROMISC;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700795
Yan Burman0eb74fd2013-02-07 02:25:23 +0000796 /* Enable promiscouos mode */
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000797 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000798 case MLX4_STEERING_MODE_DEVICE_MANAGED:
Yan Burman0eb74fd2013-02-07 02:25:23 +0000799 err = mlx4_flow_steer_promisc_add(mdev->dev,
800 priv->port,
801 priv->base_qpn,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000802 MLX4_FS_ALL_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000803 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000804 en_err(priv, "Failed enabling promiscuous mode\n");
805 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000806 break;
807
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000808 case MLX4_STEERING_MODE_B0:
Yan Burman0eb74fd2013-02-07 02:25:23 +0000809 err = mlx4_unicast_promisc_add(mdev->dev,
810 priv->base_qpn,
811 priv->port);
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000812 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000813 en_err(priv, "Failed enabling unicast promiscuous mode\n");
814
815 /* Add the default qp number as multicast
816 * promisc
817 */
818 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
819 err = mlx4_multicast_promisc_add(mdev->dev,
820 priv->base_qpn,
821 priv->port);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000822 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000823 en_err(priv, "Failed enabling multicast promiscuous mode\n");
824 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000825 }
826 break;
827
828 case MLX4_STEERING_MODE_A0:
829 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
830 priv->port,
Yan Burman0eb74fd2013-02-07 02:25:23 +0000831 priv->base_qpn,
832 1);
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000833 if (err)
Yan Burman0eb74fd2013-02-07 02:25:23 +0000834 en_err(priv, "Failed enabling promiscuous mode\n");
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000835 break;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000836 }
837
Yan Burman0eb74fd2013-02-07 02:25:23 +0000838 /* Disable port multicast filter (unconditionally) */
839 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
840 0, MLX4_MCAST_DISABLE);
841 if (err)
842 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700843 }
Yan Burman0eb74fd2013-02-07 02:25:23 +0000844}
845
846static void mlx4_en_clear_promisc_mode(struct mlx4_en_priv *priv,
847 struct mlx4_en_dev *mdev)
848{
849 int err = 0;
850
851 if (netif_msg_rx_status(priv))
852 en_warn(priv, "Leaving promiscuous mode\n");
853 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
854
855 /* Disable promiscouos mode */
856 switch (mdev->dev->caps.steering_mode) {
857 case MLX4_STEERING_MODE_DEVICE_MANAGED:
858 err = mlx4_flow_steer_promisc_remove(mdev->dev,
859 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000860 MLX4_FS_ALL_DEFAULT);
Yan Burman0eb74fd2013-02-07 02:25:23 +0000861 if (err)
862 en_err(priv, "Failed disabling promiscuous mode\n");
863 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
864 break;
865
866 case MLX4_STEERING_MODE_B0:
867 err = mlx4_unicast_promisc_remove(mdev->dev,
868 priv->base_qpn,
869 priv->port);
870 if (err)
871 en_err(priv, "Failed disabling unicast promiscuous mode\n");
872 /* Disable Multicast promisc */
873 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
874 err = mlx4_multicast_promisc_remove(mdev->dev,
875 priv->base_qpn,
876 priv->port);
877 if (err)
878 en_err(priv, "Failed disabling multicast promiscuous mode\n");
879 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
880 }
881 break;
882
883 case MLX4_STEERING_MODE_A0:
884 err = mlx4_SET_PORT_qpn_calc(mdev->dev,
885 priv->port,
886 priv->base_qpn, 0);
887 if (err)
888 en_err(priv, "Failed disabling promiscuous mode\n");
889 break;
890 }
Yan Burman0eb74fd2013-02-07 02:25:23 +0000891}
892
893static void mlx4_en_do_multicast(struct mlx4_en_priv *priv,
894 struct net_device *dev,
895 struct mlx4_en_dev *mdev)
896{
897 struct mlx4_en_mc_list *mclist, *tmp;
898 u64 mcast_addr = 0;
899 u8 mc_list[16] = {0};
900 int err = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700901
902 /* Enable/disable the multicast filter according to IFF_ALLMULTI */
903 if (dev->flags & IFF_ALLMULTI) {
904 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
905 0, MLX4_MCAST_DISABLE);
906 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000907 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000908
909 /* Add the default qp number as multicast promisc */
910 if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000911 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000912 case MLX4_STEERING_MODE_DEVICE_MANAGED:
913 err = mlx4_flow_steer_promisc_add(mdev->dev,
914 priv->port,
915 priv->base_qpn,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000916 MLX4_FS_MC_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000917 break;
918
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000919 case MLX4_STEERING_MODE_B0:
920 err = mlx4_multicast_promisc_add(mdev->dev,
921 priv->base_qpn,
922 priv->port);
923 break;
924
925 case MLX4_STEERING_MODE_A0:
926 break;
927 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000928 if (err)
929 en_err(priv, "Failed entering multicast promisc mode\n");
930 priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
931 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700932 } else {
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000933 /* Disable Multicast promisc */
934 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000935 switch (mdev->dev->caps.steering_mode) {
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000936 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_MC_DEFAULT);
Hadar Hen Zion592e49d2012-07-05 04:03:48 +0000940 break;
941
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000942 case MLX4_STEERING_MODE_B0:
943 err = mlx4_multicast_promisc_remove(mdev->dev,
944 priv->base_qpn,
945 priv->port);
946 break;
947
948 case MLX4_STEERING_MODE_A0:
949 break;
950 }
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000951 if (err)
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300952 en_err(priv, "Failed disabling multicast promiscuous mode\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000953 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
954 }
Jiri Pirkoff6e2162010-03-01 05:09:14 +0000955
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700956 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
957 0, MLX4_MCAST_DISABLE);
958 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000959 en_err(priv, "Failed disabling multicast filter\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700960
961 /* Flush mcast filter and init it with broadcast address */
962 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST,
963 1, MLX4_MCAST_CONFIG);
964
965 /* Update multicast list - we cache all addresses so they won't
966 * change while HW is updated holding the command semaphor */
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +0000967 netif_addr_lock_bh(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700968 mlx4_en_cache_mclist(dev);
Eugenia Emantayevdbd501a2013-01-24 01:54:16 +0000969 netif_addr_unlock_bh(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000970 list_for_each_entry(mclist, &priv->mc_list, list) {
Eugenia Emantayev98133372014-03-02 10:25:01 +0200971 mcast_addr = mlx4_mac_to_u64(mclist->addr);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700972 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port,
973 mcast_addr, 0, MLX4_MCAST_CONFIG);
974 }
975 err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
976 0, MLX4_MCAST_ENABLE);
977 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000978 en_err(priv, "Failed enabling multicast filter\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000979
980 update_mclist_flags(priv, &priv->curr_list, &priv->mc_list);
981 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
982 if (mclist->action == MCLIST_REM) {
983 /* detach this address and delete from list */
984 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
985 mc_list[5] = priv->port;
986 err = mlx4_multicast_detach(mdev->dev,
987 &priv->rss_map.indir_qp,
988 mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000989 MLX4_PROT_ETH,
990 mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +0000991 if (err)
992 en_err(priv, "Fail to detach multicast address\n");
993
Or Gerlitz837052d2013-12-23 16:09:44 +0200994 if (mclist->tunnel_reg_id) {
995 err = mlx4_flow_detach(priv->mdev->dev, mclist->tunnel_reg_id);
996 if (err)
997 en_err(priv, "Failed to detach multicast address\n");
998 }
999
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001000 /* remove from list */
1001 list_del(&mclist->list);
1002 kfree(mclist);
Dan Carpenter9c645082012-07-10 20:34:07 +00001003 } else if (mclist->action == MCLIST_ADD) {
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001004 /* attach the address */
1005 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001006 /* needed for B0 steering support */
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001007 mc_list[5] = priv->port;
1008 err = mlx4_multicast_attach(mdev->dev,
1009 &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001010 mc_list,
1011 priv->port, 0,
1012 MLX4_PROT_ETH,
1013 &mclist->reg_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001014 if (err)
1015 en_err(priv, "Fail to attach multicast address\n");
1016
Or Gerlitz837052d2013-12-23 16:09:44 +02001017 err = mlx4_en_tunnel_steer_add(priv, &mc_list[10], priv->base_qpn,
1018 &mclist->tunnel_reg_id);
1019 if (err)
1020 en_err(priv, "Failed to attach multicast address\n");
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001021 }
1022 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001023 }
Yan Burman0eb74fd2013-02-07 02:25:23 +00001024}
1025
Yan Burmancc5387f2013-02-07 02:25:26 +00001026static void mlx4_en_do_uc_filter(struct mlx4_en_priv *priv,
1027 struct net_device *dev,
1028 struct mlx4_en_dev *mdev)
1029{
1030 struct netdev_hw_addr *ha;
1031 struct mlx4_mac_entry *entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001032 struct hlist_node *tmp;
Yan Burmancc5387f2013-02-07 02:25:26 +00001033 bool found;
1034 u64 mac;
1035 int err = 0;
1036 struct hlist_head *bucket;
1037 unsigned int i;
1038 int removed = 0;
1039 u32 prev_flags;
1040
1041 /* Note that we do not need to protect our mac_hash traversal with rcu,
1042 * since all modification code is protected by mdev->state_lock
1043 */
1044
1045 /* find what to remove */
1046 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) {
1047 bucket = &priv->mac_hash[i];
Sasha Levinb67bfe02013-02-27 17:06:00 -08001048 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
Yan Burmancc5387f2013-02-07 02:25:26 +00001049 found = false;
1050 netdev_for_each_uc_addr(ha, dev) {
1051 if (ether_addr_equal_64bits(entry->mac,
1052 ha->addr)) {
1053 found = true;
1054 break;
1055 }
1056 }
1057
1058 /* MAC address of the port is not in uc list */
Noa Osherovich2695bab2014-07-08 11:25:24 +03001059 if (ether_addr_equal_64bits(entry->mac,
1060 priv->current_mac))
Yan Burmancc5387f2013-02-07 02:25:26 +00001061 found = true;
1062
1063 if (!found) {
Eugenia Emantayev98133372014-03-02 10:25:01 +02001064 mac = mlx4_mac_to_u64(entry->mac);
Yan Burmancc5387f2013-02-07 02:25:26 +00001065 mlx4_en_uc_steer_release(priv, entry->mac,
1066 priv->base_qpn,
1067 entry->reg_id);
1068 mlx4_unregister_mac(mdev->dev, priv->port, mac);
1069
1070 hlist_del_rcu(&entry->hlist);
1071 kfree_rcu(entry, rcu);
1072 en_dbg(DRV, priv, "Removed MAC %pM on port:%d\n",
1073 entry->mac, priv->port);
1074 ++removed;
1075 }
1076 }
1077 }
1078
1079 /* if we didn't remove anything, there is no use in trying to add
1080 * again once we are in a forced promisc mode state
1081 */
1082 if ((priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) && 0 == removed)
1083 return;
1084
1085 prev_flags = priv->flags;
1086 priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC;
1087
1088 /* find what to add */
1089 netdev_for_each_uc_addr(ha, dev) {
1090 found = false;
1091 bucket = &priv->mac_hash[ha->addr[MLX4_EN_MAC_HASH_IDX]];
Sasha Levinb67bfe02013-02-27 17:06:00 -08001092 hlist_for_each_entry(entry, bucket, hlist) {
Yan Burmancc5387f2013-02-07 02:25:26 +00001093 if (ether_addr_equal_64bits(entry->mac, ha->addr)) {
1094 found = true;
1095 break;
1096 }
1097 }
1098
1099 if (!found) {
1100 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1101 if (!entry) {
1102 en_err(priv, "Failed adding MAC %pM on port:%d (out of memory)\n",
1103 ha->addr, priv->port);
1104 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1105 break;
1106 }
Eugenia Emantayev98133372014-03-02 10:25:01 +02001107 mac = mlx4_mac_to_u64(ha->addr);
Yan Burmancc5387f2013-02-07 02:25:26 +00001108 memcpy(entry->mac, ha->addr, ETH_ALEN);
1109 err = mlx4_register_mac(mdev->dev, priv->port, mac);
1110 if (err < 0) {
1111 en_err(priv, "Failed registering MAC %pM on port %d: %d\n",
1112 ha->addr, priv->port, err);
1113 kfree(entry);
1114 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1115 break;
1116 }
1117 err = mlx4_en_uc_steer_add(priv, ha->addr,
1118 &priv->base_qpn,
1119 &entry->reg_id);
1120 if (err) {
1121 en_err(priv, "Failed adding MAC %pM on port %d: %d\n",
1122 ha->addr, priv->port, err);
1123 mlx4_unregister_mac(mdev->dev, priv->port, mac);
1124 kfree(entry);
1125 priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC;
1126 break;
1127 } else {
1128 unsigned int mac_hash;
1129 en_dbg(DRV, priv, "Added MAC %pM on port:%d\n",
1130 ha->addr, priv->port);
1131 mac_hash = ha->addr[MLX4_EN_MAC_HASH_IDX];
1132 bucket = &priv->mac_hash[mac_hash];
1133 hlist_add_head_rcu(&entry->hlist, bucket);
1134 }
1135 }
1136 }
1137
1138 if (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) {
1139 en_warn(priv, "Forcing promiscuous mode on port:%d\n",
1140 priv->port);
1141 } else if (prev_flags & MLX4_EN_FLAG_FORCE_PROMISC) {
1142 en_warn(priv, "Stop forcing promiscuous mode on port:%d\n",
1143 priv->port);
1144 }
1145}
1146
Yan Burman0eb74fd2013-02-07 02:25:23 +00001147static void mlx4_en_do_set_rx_mode(struct work_struct *work)
1148{
1149 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1150 rx_mode_task);
1151 struct mlx4_en_dev *mdev = priv->mdev;
1152 struct net_device *dev = priv->dev;
1153
1154 mutex_lock(&mdev->state_lock);
1155 if (!mdev->device_up) {
1156 en_dbg(HW, priv, "Card is not up, ignoring rx mode change.\n");
1157 goto out;
1158 }
1159 if (!priv->port_up) {
1160 en_dbg(HW, priv, "Port is down, ignoring rx mode change.\n");
1161 goto out;
1162 }
1163
1164 if (!netif_carrier_ok(dev)) {
1165 if (!mlx4_en_QUERY_PORT(mdev, priv->port)) {
1166 if (priv->port_state.link_state) {
1167 priv->last_link_state = MLX4_DEV_EVENT_PORT_UP;
1168 netif_carrier_on(dev);
1169 en_dbg(LINK, priv, "Link Up\n");
1170 }
1171 }
1172 }
1173
Yan Burmancc5387f2013-02-07 02:25:26 +00001174 if (dev->priv_flags & IFF_UNICAST_FLT)
1175 mlx4_en_do_uc_filter(priv, dev, mdev);
1176
Yan Burman0eb74fd2013-02-07 02:25:23 +00001177 /* Promsicuous mode: disable all filters */
Yan Burmancc5387f2013-02-07 02:25:26 +00001178 if ((dev->flags & IFF_PROMISC) ||
1179 (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC)) {
Yan Burman0eb74fd2013-02-07 02:25:23 +00001180 mlx4_en_set_promisc_mode(priv, mdev);
1181 goto out;
1182 }
1183
1184 /* Not in promiscuous mode */
1185 if (priv->flags & MLX4_EN_FLAG_PROMISC)
1186 mlx4_en_clear_promisc_mode(priv, mdev);
1187
1188 mlx4_en_do_multicast(priv, dev, mdev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001189out:
1190 mutex_unlock(&mdev->state_lock);
1191}
1192
1193#ifdef CONFIG_NET_POLL_CONTROLLER
1194static void mlx4_en_netpoll(struct net_device *dev)
1195{
1196 struct mlx4_en_priv *priv = netdev_priv(dev);
1197 struct mlx4_en_cq *cq;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001198 int i;
1199
1200 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001201 cq = priv->rx_cq[i];
Chris Masonc98235c2014-04-15 18:09:24 -04001202 napi_schedule(&cq->napi);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001203 }
1204}
1205#endif
1206
Ido Shamayba4b87ae2015-10-08 17:14:01 +03001207static int mlx4_en_set_rss_steer_rules(struct mlx4_en_priv *priv)
1208{
1209 u64 reg_id;
1210 int err = 0;
1211 int *qpn = &priv->base_qpn;
1212 struct mlx4_mac_entry *entry;
1213
1214 err = mlx4_en_uc_steer_add(priv, priv->dev->dev_addr, qpn, &reg_id);
1215 if (err)
1216 return err;
1217
1218 err = mlx4_en_tunnel_steer_add(priv, priv->dev->dev_addr, *qpn,
1219 &priv->tunnel_reg_id);
1220 if (err)
1221 goto tunnel_err;
1222
1223 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1224 if (!entry) {
1225 err = -ENOMEM;
1226 goto alloc_err;
1227 }
1228
1229 memcpy(entry->mac, priv->dev->dev_addr, sizeof(entry->mac));
1230 memcpy(priv->current_mac, entry->mac, sizeof(priv->current_mac));
1231 entry->reg_id = reg_id;
1232 hlist_add_head_rcu(&entry->hlist,
1233 &priv->mac_hash[entry->mac[MLX4_EN_MAC_HASH_IDX]]);
1234
1235 return 0;
1236
1237alloc_err:
1238 if (priv->tunnel_reg_id)
1239 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
1240
1241tunnel_err:
1242 mlx4_en_uc_steer_release(priv, priv->dev->dev_addr, *qpn, reg_id);
1243 return err;
1244}
1245
1246static void mlx4_en_delete_rss_steer_rules(struct mlx4_en_priv *priv)
1247{
1248 u64 mac;
1249 unsigned int i;
1250 int qpn = priv->base_qpn;
1251 struct hlist_head *bucket;
1252 struct hlist_node *tmp;
1253 struct mlx4_mac_entry *entry;
1254
1255 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) {
1256 bucket = &priv->mac_hash[i];
1257 hlist_for_each_entry_safe(entry, tmp, bucket, hlist) {
1258 mac = mlx4_mac_to_u64(entry->mac);
1259 en_dbg(DRV, priv, "Registering MAC:%pM for deleting\n",
1260 entry->mac);
1261 mlx4_en_uc_steer_release(priv, entry->mac,
1262 qpn, entry->reg_id);
1263
1264 mlx4_unregister_mac(priv->mdev->dev, priv->port, mac);
1265 hlist_del_rcu(&entry->hlist);
1266 kfree_rcu(entry, rcu);
1267 }
1268 }
1269
1270 if (priv->tunnel_reg_id) {
1271 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
1272 priv->tunnel_reg_id = 0;
1273 }
1274}
1275
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001276static void mlx4_en_tx_timeout(struct net_device *dev)
1277{
1278 struct mlx4_en_priv *priv = netdev_priv(dev);
1279 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001280 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001281
1282 if (netif_msg_timer(priv))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001283 en_warn(priv, "Tx timeout called on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001284
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001285 for (i = 0; i < priv->tx_ring_num; i++) {
1286 if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev, i)))
1287 continue;
1288 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 +02001289 i, priv->tx_ring[i]->qpn, priv->tx_ring[i]->cqn,
1290 priv->tx_ring[i]->cons, priv->tx_ring[i]->prod);
Yevgeny Petrilinb944ebe2013-06-25 12:09:34 +03001291 }
1292
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001293 priv->port_stats.tx_timeout++;
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001294 en_dbg(DRV, priv, "Scheduling watchdog\n");
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001295 queue_work(mdev->workqueue, &priv->watchdog_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001296}
1297
1298
1299static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev)
1300{
1301 struct mlx4_en_priv *priv = netdev_priv(dev);
1302
1303 spin_lock_bh(&priv->stats_lock);
1304 memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats));
1305 spin_unlock_bh(&priv->stats_lock);
1306
1307 return &priv->ret_stats;
1308}
1309
1310static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv)
1311{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001312 struct mlx4_en_cq *cq;
1313 int i;
1314
1315 /* If we haven't received a specific coalescing setting
Martin Olsson98a17082009-04-22 18:21:29 +02001316 * (module param), we set the moderation parameters as follows:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001317 * - moder_cnt is set to the number of mtu sized packets to
Eric Dumazetecfd2ce2012-11-05 16:20:42 +00001318 * satisfy our coalescing target.
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001319 * - moder_time is set to a fixed value.
1320 */
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +00001321 priv->rx_frames = MLX4_EN_RX_COAL_TARGET;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -08001322 priv->rx_usecs = MLX4_EN_RX_COAL_TIME;
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001323 priv->tx_frames = MLX4_EN_TX_COAL_PKTS;
1324 priv->tx_usecs = MLX4_EN_TX_COAL_TIME;
Yan Burman48e551f2013-02-07 02:25:21 +00001325 en_dbg(INTR, priv, "Default coalesing params for mtu:%d - rx_frames:%d rx_usecs:%d\n",
1326 priv->dev->mtu, priv->rx_frames, priv->rx_usecs);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001327
1328 /* Setup cq moderation params */
1329 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001330 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001331 cq->moder_cnt = priv->rx_frames;
1332 cq->moder_time = priv->rx_usecs;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001333 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
1334 priv->last_moder_packets[i] = 0;
1335 priv->last_moder_bytes[i] = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001336 }
1337
1338 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001339 cq = priv->tx_cq[i];
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001340 cq->moder_cnt = priv->tx_frames;
1341 cq->moder_time = priv->tx_usecs;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001342 }
1343
1344 /* Reset auto-moderation params */
1345 priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW;
1346 priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW;
1347 priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH;
1348 priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH;
1349 priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL;
Yevgeny Petrilin60b9f9e2008-12-25 18:19:47 -08001350 priv->adaptive_rx_coal = 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001351 priv->last_moder_jiffies = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001352 priv->last_moder_tx_packets = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001353}
1354
1355static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv)
1356{
1357 unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001358 struct mlx4_en_cq *cq;
1359 unsigned long packets;
1360 unsigned long rate;
1361 unsigned long avg_pkt_size;
1362 unsigned long rx_packets;
1363 unsigned long rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001364 unsigned long rx_pkt_diff;
1365 int moder_time;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001366 int ring, err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001367
1368 if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ)
1369 return;
1370
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001371 for (ring = 0; ring < priv->rx_ring_num; ring++) {
1372 spin_lock_bh(&priv->stats_lock);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001373 rx_packets = priv->rx_ring[ring]->packets;
1374 rx_bytes = priv->rx_ring[ring]->bytes;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001375 spin_unlock_bh(&priv->stats_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001376
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001377 rx_pkt_diff = ((unsigned long) (rx_packets -
1378 priv->last_moder_packets[ring]));
1379 packets = rx_pkt_diff;
1380 rate = packets * HZ / period;
1381 avg_pkt_size = packets ? ((unsigned long) (rx_bytes -
1382 priv->last_moder_bytes[ring])) / packets : 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001383
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001384 /* Apply auto-moderation only when packet rate
1385 * exceeds a rate that it matters */
1386 if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) &&
1387 avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001388 if (rate < priv->pkt_rate_low)
1389 moder_time = priv->rx_usecs_low;
1390 else if (rate > priv->pkt_rate_high)
1391 moder_time = priv->rx_usecs_high;
1392 else
1393 moder_time = (rate - priv->pkt_rate_low) *
1394 (priv->rx_usecs_high - priv->rx_usecs_low) /
1395 (priv->pkt_rate_high - priv->pkt_rate_low) +
1396 priv->rx_usecs_low;
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001397 } else {
1398 moder_time = priv->rx_usecs_low;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001399 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001400
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001401 if (moder_time != priv->last_moder_time[ring]) {
1402 priv->last_moder_time[ring] = moder_time;
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001403 cq = priv->rx_cq[ring];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001404 cq->moder_time = moder_time;
Sagi Grimberga1c66932013-06-04 05:13:26 +00001405 cq->moder_cnt = priv->rx_frames;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001406 err = mlx4_en_set_cq_moder(priv, cq);
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001407 if (err)
Yan Burman48e551f2013-02-07 02:25:21 +00001408 en_err(priv, "Failed modifying moderation for cq:%d\n",
1409 ring);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001410 }
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001411 priv->last_moder_packets[ring] = rx_packets;
1412 priv->last_moder_bytes[ring] = rx_bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001413 }
1414
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001415 priv->last_moder_jiffies = jiffies;
1416}
1417
1418static void mlx4_en_do_get_stats(struct work_struct *work)
1419{
Jean Delvarebf6aede2009-04-02 16:56:54 -07001420 struct delayed_work *delay = to_delayed_work(work);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001421 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
1422 stats_task);
1423 struct mlx4_en_dev *mdev = priv->mdev;
1424 int err;
1425
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001426 mutex_lock(&mdev->state_lock);
1427 if (mdev->device_up) {
Jack Morgenstein6123db22013-06-25 12:09:30 +03001428 if (priv->port_up) {
1429 err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0);
1430 if (err)
1431 en_dbg(HW, priv, "Could not update stats\n");
Eugenia Emantayev2d518372013-01-24 01:54:14 +00001432
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001433 mlx4_en_auto_moderation(priv);
Jack Morgenstein6123db22013-06-25 12:09:30 +03001434 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001435
1436 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
1437 }
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +00001438 if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
Noa Osherovich2695bab2014-07-08 11:25:24 +03001439 mlx4_en_do_set_mac(priv, priv->current_mac);
Yevgeny Petrilind7e1a482010-08-24 03:46:38 +00001440 mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
1441 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001442 mutex_unlock(&mdev->state_lock);
1443}
1444
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001445/* mlx4_en_service_task - Run service task for tasks that needed to be done
1446 * periodically
1447 */
1448static void mlx4_en_service_task(struct work_struct *work)
1449{
1450 struct delayed_work *delay = to_delayed_work(work);
1451 struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
1452 service_task);
1453 struct mlx4_en_dev *mdev = priv->mdev;
1454
1455 mutex_lock(&mdev->state_lock);
1456 if (mdev->device_up) {
Amir Vadaidc8142e2013-04-25 05:22:24 +00001457 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
1458 mlx4_en_ptp_overflow_check(mdev);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001459
Ido Shamay07841f92015-04-30 17:32:46 +03001460 mlx4_en_recover_from_oom(priv);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00001461 queue_delayed_work(mdev->workqueue, &priv->service_task,
1462 SERVICE_TASK_DELAY);
1463 }
1464 mutex_unlock(&mdev->state_lock);
1465}
1466
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001467static void mlx4_en_linkstate(struct work_struct *work)
1468{
1469 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1470 linkstate_task);
1471 struct mlx4_en_dev *mdev = priv->mdev;
1472 int linkstate = priv->link_state;
1473
1474 mutex_lock(&mdev->state_lock);
1475 /* If observable port state changed set carrier state and
1476 * report to system log */
1477 if (priv->last_link_state != linkstate) {
1478 if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001479 en_info(priv, "Link Down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001480 netif_carrier_off(priv->dev);
1481 } else {
Yevgeny Petriline5cc44b2010-08-24 03:46:01 +00001482 en_info(priv, "Link Up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001483 netif_carrier_on(priv->dev);
1484 }
1485 }
1486 priv->last_link_state = linkstate;
1487 mutex_unlock(&mdev->state_lock);
1488}
1489
Yuval Atias9e311e72014-06-09 10:24:39 +03001490static int mlx4_en_init_affinity_hint(struct mlx4_en_priv *priv, int ring_idx)
1491{
1492 struct mlx4_en_rx_ring *ring = priv->rx_ring[ring_idx];
1493 int numa_node = priv->mdev->dev->numa_node;
Yuval Atias9e311e72014-06-09 10:24:39 +03001494
1495 if (!zalloc_cpumask_var(&ring->affinity_mask, GFP_KERNEL))
1496 return -ENOMEM;
1497
Rusty Russellf36963c2015-05-09 03:14:13 +09301498 cpumask_set_cpu(cpumask_local_spread(ring_idx, numa_node),
1499 ring->affinity_mask);
1500 return 0;
Yuval Atias9e311e72014-06-09 10:24:39 +03001501}
1502
1503static void mlx4_en_free_affinity_hint(struct mlx4_en_priv *priv, int ring_idx)
1504{
1505 free_cpumask_var(priv->rx_ring[ring_idx]->affinity_mask);
1506}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001507
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001508int mlx4_en_start_port(struct net_device *dev)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001509{
1510 struct mlx4_en_priv *priv = netdev_priv(dev);
1511 struct mlx4_en_dev *mdev = priv->mdev;
1512 struct mlx4_en_cq *cq;
1513 struct mlx4_en_tx_ring *tx_ring;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001514 int rx_index = 0;
1515 int tx_index = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001516 int err = 0;
1517 int i;
1518 int j;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001519 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001520
1521 if (priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001522 en_dbg(DRV, priv, "start port called while port already up\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001523 return 0;
1524 }
1525
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001526 INIT_LIST_HEAD(&priv->mc_list);
1527 INIT_LIST_HEAD(&priv->curr_list);
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001528 INIT_LIST_HEAD(&priv->ethtool_list);
1529 memset(&priv->ethtool_rules[0], 0,
1530 sizeof(struct ethtool_flow_id) * MAX_NUM_OF_FS_RULES);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001531
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001532 /* Calculate Rx buf size */
1533 dev->mtu = min(dev->mtu, priv->max_mtu);
1534 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001535 en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_skb_size);
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001536
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001537 /* Configure rx cq's and rings */
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001538 err = mlx4_en_activate_rx_rings(priv);
1539 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001540 en_err(priv, "Failed to activate RX rings\n");
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001541 return err;
1542 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001543 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001544 cq = priv->rx_cq[i];
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001545
Yuval Atias9e311e72014-06-09 10:24:39 +03001546 err = mlx4_en_init_affinity_hint(priv, i);
1547 if (err) {
1548 en_err(priv, "Failed preparing IRQ affinity hint\n");
1549 goto cq_err;
1550 }
1551
Alexander Guller76532d02011-10-09 05:26:31 +00001552 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001553 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001554 en_err(priv, "Failed activating Rx CQ\n");
Yuval Atias9e311e72014-06-09 10:24:39 +03001555 mlx4_en_free_affinity_hint(priv, i);
Yevgeny Petrilina4233302009-04-26 20:41:34 +00001556 goto cq_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001557 }
Ido Shamayc3f25112014-12-16 13:28:54 +02001558
1559 for (j = 0; j < cq->size; j++) {
1560 struct mlx4_cqe *cqe = NULL;
1561
1562 cqe = mlx4_en_get_cqe(cq->buf, j, priv->cqe_size) +
1563 priv->cqe_factor;
1564 cqe->owner_sr_opcode = MLX4_CQE_OWNER_MASK;
1565 }
1566
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001567 err = mlx4_en_set_cq_moder(priv, cq);
1568 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07001569 en_err(priv, "Failed setting cq moderation parameters\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001570 mlx4_en_deactivate_cq(priv, cq);
Yuval Atias9e311e72014-06-09 10:24:39 +03001571 mlx4_en_free_affinity_hint(priv, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001572 goto cq_err;
1573 }
1574 mlx4_en_arm_cq(priv, cq);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001575 priv->rx_ring[i]->cqn = cq->mcq.cqn;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001576 ++rx_index;
1577 }
1578
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001579 /* Set qp number */
1580 en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port);
Yan Burman16a10ff2013-02-07 02:25:22 +00001581 err = mlx4_en_get_qp(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001582 if (err) {
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001583 en_err(priv, "Failed getting eth qp\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001584 goto cq_err;
1585 }
1586 mdev->mac_removed[priv->port] = 0;
1587
Eran Ben Elisha6de5f7f2015-06-15 17:59:02 +03001588 priv->counter_index =
1589 mlx4_get_default_counter_index(mdev->dev, priv->port);
1590
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001591 err = mlx4_en_config_rss_steer(priv);
1592 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001593 en_err(priv, "Failed configuring rss steering\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001594 goto mac_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001595 }
1596
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001597 err = mlx4_en_create_drop_qp(priv);
1598 if (err)
1599 goto rss_err;
1600
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001601 /* Configure tx cq's and rings */
1602 for (i = 0; i < priv->tx_ring_num; i++) {
1603 /* Configure cq */
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001604 cq = priv->tx_cq[i];
Alexander Guller76532d02011-10-09 05:26:31 +00001605 err = mlx4_en_activate_cq(priv, cq, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001606 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001607 en_err(priv, "Failed allocating Tx CQ\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001608 goto tx_err;
1609 }
1610 err = mlx4_en_set_cq_moder(priv, cq);
1611 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07001612 en_err(priv, "Failed setting cq moderation parameters\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001613 mlx4_en_deactivate_cq(priv, cq);
1614 goto tx_err;
1615 }
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001616 en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001617 cq->buf->wqe_index = cpu_to_be16(0xffff);
1618
1619 /* Configure ring */
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001620 tx_ring = priv->tx_ring[i];
Amir Vadai0e98b522012-04-04 21:33:24 +00001621 err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn,
Amir Vadaid3179662012-12-02 03:49:23 +00001622 i / priv->num_tx_rings_p_up);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001623 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001624 en_err(priv, "Failed allocating Tx ring\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001625 mlx4_en_deactivate_cq(priv, cq);
1626 goto tx_err;
1627 }
Yevgeny Petrilin5b263f52012-04-23 02:18:50 +00001628 tx_ring->tx_queue = netdev_get_tx_queue(dev, i);
Yevgeny Petriline22979d2012-04-23 02:18:39 +00001629
1630 /* Arm CQ for TX completions */
1631 mlx4_en_arm_cq(priv, cq);
1632
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001633 /* Set initial ownership of all Tx TXBBs to SW (1) */
1634 for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE)
1635 *((u32 *) (tx_ring->buf + j)) = 0xffffffff;
1636 ++tx_index;
1637 }
1638
1639 /* Configure port */
1640 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
1641 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001642 priv->prof->tx_pause,
1643 priv->prof->tx_ppp,
1644 priv->prof->rx_pause,
1645 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001646 if (err) {
Yan Burman48e551f2013-02-07 02:25:21 +00001647 en_err(priv, "Failed setting port general configurations for port %d, with error %d\n",
1648 priv->port, err);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001649 goto tx_err;
1650 }
1651 /* Set default qp number */
1652 err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0);
1653 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001654 en_err(priv, "Failed setting default qp numbers\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001655 goto tx_err;
1656 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001657
Or Gerlitz837052d2013-12-23 16:09:44 +02001658 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
Or Gerlitz1b136de2014-03-27 14:02:04 +02001659 err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC, 1);
Or Gerlitz837052d2013-12-23 16:09:44 +02001660 if (err) {
1661 en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n",
1662 err);
1663 goto tx_err;
1664 }
1665 }
1666
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001667 /* Init port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001668 en_dbg(HW, priv, "Initializing port\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001669 err = mlx4_INIT_PORT(mdev->dev, priv->port);
1670 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001671 en_err(priv, "Failed Initializing port\n");
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001672 goto tx_err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001673 }
1674
Ido Shamayba4b87ae2015-10-08 17:14:01 +03001675 /* Set Unicast and VXLAN steering rules */
1676 if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_A0 &&
1677 mlx4_en_set_rss_steer_rules(priv))
1678 mlx4_warn(mdev, "Failed setting steering rules\n");
1679
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001680 /* Attach rx QP to bradcast address */
Joe Perchesc7bf7162015-03-02 19:54:47 -08001681 eth_broadcast_addr(&mc_list[10]);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001682 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001683 if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001684 priv->port, 0, MLX4_PROT_ETH,
1685 &priv->broadcast_id))
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001686 mlx4_warn(mdev, "Failed Attaching Broadcast\n");
1687
Herbert Xub5845f92011-03-27 01:01:26 +00001688 /* Must redo promiscuous mode setup. */
1689 priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC);
1690
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001691 /* Schedule multicast task to populate multicast list */
Yan Burman0eb74fd2013-02-07 02:25:23 +00001692 queue_work(mdev->workqueue, &priv->rx_mode_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001693
Or Gerlitza66132f2014-04-01 11:27:13 +03001694#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz9737c6a2014-11-18 17:51:27 +02001695 if (priv->mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
Or Gerlitz1b136de2014-03-27 14:02:04 +02001696 vxlan_get_rx_port(dev);
Or Gerlitza66132f2014-04-01 11:27:13 +03001697#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001698 priv->port_up = true;
Yevgeny Petrilina11faac2009-06-20 22:15:46 +00001699 netif_tx_start_all_queues(dev);
Amir Vadai3484aac2013-01-30 23:07:11 +00001700 netif_device_attach(dev);
1701
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001702 return 0;
1703
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001704tx_err:
1705 while (tx_index--) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001706 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[tx_index]);
1707 mlx4_en_deactivate_cq(priv, priv->tx_cq[tx_index]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001708 }
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001709 mlx4_en_destroy_drop_qp(priv);
1710rss_err:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001711 mlx4_en_release_rss_steer(priv);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001712mac_err:
Yan Burman16a10ff2013-02-07 02:25:22 +00001713 mlx4_en_put_qp(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001714cq_err:
Yuval Atias9e311e72014-06-09 10:24:39 +03001715 while (rx_index--) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001716 mlx4_en_deactivate_cq(priv, priv->rx_cq[rx_index]);
Benjamin Poirierf94813f2015-04-29 15:59:35 -07001717 mlx4_en_free_affinity_hint(priv, rx_index);
Yuval Atias9e311e72014-06-09 10:24:39 +03001718 }
Yevgeny Petrilin38aab072009-05-24 03:17:11 +00001719 for (i = 0; i < priv->rx_ring_num; i++)
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001720 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001721
1722 return err; /* need to close devices */
1723}
1724
1725
Amir Vadai3484aac2013-01-30 23:07:11 +00001726void mlx4_en_stop_port(struct net_device *dev, int detach)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001727{
1728 struct mlx4_en_priv *priv = netdev_priv(dev);
1729 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001730 struct mlx4_en_mc_list *mclist, *tmp;
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001731 struct ethtool_flow_id *flow, *tmp_flow;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001732 int i;
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001733 u8 mc_list[16] = {0};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001734
1735 if (!priv->port_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001736 en_dbg(DRV, priv, "stop port called while port already down\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001737 return;
1738 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001739
Eugenia Emantayev0cc5c8b2013-06-25 12:09:33 +03001740 /* close port*/
1741 mlx4_CLOSE_PORT(mdev->dev, priv->port);
1742
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001743 /* Synchronize with tx routine */
1744 netif_tx_lock_bh(dev);
Amir Vadai3484aac2013-01-30 23:07:11 +00001745 if (detach)
1746 netif_device_detach(dev);
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001747 netif_tx_stop_all_queues(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001748 netif_tx_unlock_bh(dev);
1749
Amir Vadai3484aac2013-01-30 23:07:11 +00001750 netif_tx_disable(dev);
1751
Yevgeny Petrilin7c287382010-08-24 03:45:45 +00001752 /* Set port as not active */
Yevgeny Petrilin3c05f5e2009-06-20 22:15:52 +00001753 priv->port_up = false;
Eran Ben Elisha6de5f7f2015-06-15 17:59:02 +03001754 priv->counter_index = MLX4_SINK_COUNTER_INDEX(mdev->dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001755
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001756 /* Promsicuous mode */
1757 if (mdev->dev->caps.steering_mode ==
1758 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1759 priv->flags &= ~(MLX4_EN_FLAG_PROMISC |
1760 MLX4_EN_FLAG_MC_PROMISC);
1761 mlx4_flow_steer_promisc_remove(mdev->dev,
1762 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001763 MLX4_FS_ALL_DEFAULT);
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001764 mlx4_flow_steer_promisc_remove(mdev->dev,
1765 priv->port,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001766 MLX4_FS_MC_DEFAULT);
Aviad Yehezkeldb0e7cb2013-01-24 01:54:15 +00001767 } else if (priv->flags & MLX4_EN_FLAG_PROMISC) {
1768 priv->flags &= ~MLX4_EN_FLAG_PROMISC;
1769
1770 /* Disable promiscouos mode */
1771 mlx4_unicast_promisc_remove(mdev->dev, priv->base_qpn,
1772 priv->port);
1773
1774 /* Disable Multicast promisc */
1775 if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
1776 mlx4_multicast_promisc_remove(mdev->dev, priv->base_qpn,
1777 priv->port);
1778 priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
1779 }
1780 }
1781
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001782 /* Detach All multicasts */
Joe Perchesc7bf7162015-03-02 19:54:47 -08001783 eth_broadcast_addr(&mc_list[10]);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001784 mc_list[5] = priv->port; /* needed for B0 steering support */
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001785 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001786 MLX4_PROT_ETH, priv->broadcast_id);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001787 list_for_each_entry(mclist, &priv->curr_list, list) {
1788 memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001789 mc_list[5] = priv->port;
1790 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001791 mc_list, MLX4_PROT_ETH, mclist->reg_id);
Or Gerlitzde123262014-03-13 14:52:15 +02001792 if (mclist->tunnel_reg_id)
1793 mlx4_flow_detach(mdev->dev, mclist->tunnel_reg_id);
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001794 }
1795 mlx4_en_clear_list(dev);
Yevgeny Petrilin6d199932012-07-05 04:03:43 +00001796 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
1797 list_del(&mclist->list);
1798 kfree(mclist);
1799 }
1800
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001801 /* Flush multicast filter */
1802 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG);
1803
Hadar Hen Zion6efb5fa2013-03-21 05:55:53 +00001804 /* Remove flow steering rules for the port*/
1805 if (mdev->dev->caps.steering_mode ==
1806 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1807 ASSERT_RTNL();
1808 list_for_each_entry_safe(flow, tmp_flow,
1809 &priv->ethtool_list, list) {
1810 mlx4_flow_detach(mdev->dev, flow->id);
1811 list_del(&flow->list);
1812 }
1813 }
1814
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001815 mlx4_en_destroy_drop_qp(priv);
1816
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001817 /* Free TX Rings */
1818 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001819 mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[i]);
1820 mlx4_en_deactivate_cq(priv, priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001821 }
1822 msleep(10);
1823
1824 for (i = 0; i < priv->tx_ring_num; i++)
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001825 mlx4_en_free_tx_buf(dev, priv->tx_ring[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001826
Ido Shamayba4b87ae2015-10-08 17:14:01 +03001827 if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_A0)
1828 mlx4_en_delete_rss_steer_rules(priv);
1829
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001830 /* Free RSS qps */
1831 mlx4_en_release_rss_steer(priv);
1832
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001833 /* Unregister Mac address for the port */
Yan Burman16a10ff2013-02-07 02:25:22 +00001834 mlx4_en_put_qp(priv);
Or Gerlitz5930e8d2013-10-15 16:55:22 +02001835 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN))
Matan Barak955154f2013-01-30 23:07:10 +00001836 mdev->mac_removed[priv->port] = 1;
Eugenia Emantayevffe455a2011-12-13 04:16:21 +00001837
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001838 /* Free RX Rings */
1839 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001840 struct mlx4_en_cq *cq = priv->rx_cq[i];
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001841
Ido Shamayf4a36752014-10-27 11:37:45 +02001842 napi_synchronize(&cq->napi);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001843 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]);
Amir Vadai9e77a2b2013-06-18 16:18:27 +03001844 mlx4_en_deactivate_cq(priv, cq);
Yuval Atias9e311e72014-06-09 10:24:39 +03001845
1846 mlx4_en_free_affinity_hint(priv, i);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001847 }
1848}
1849
1850static void mlx4_en_restart(struct work_struct *work)
1851{
1852 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
1853 watchdog_task);
1854 struct mlx4_en_dev *mdev = priv->mdev;
1855 struct net_device *dev = priv->dev;
1856
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001857 en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001858
1859 mutex_lock(&mdev->state_lock);
1860 if (priv->port_up) {
Amir Vadai3484aac2013-01-30 23:07:11 +00001861 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001862 if (mlx4_en_start_port(dev))
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001863 en_err(priv, "Failed restarting port %d\n", priv->port);
Yevgeny Petrilin1e338db2009-04-20 04:26:05 +00001864 }
1865 mutex_unlock(&mdev->state_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001866}
1867
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001868static void mlx4_en_clear_stats(struct net_device *dev)
1869{
1870 struct mlx4_en_priv *priv = netdev_priv(dev);
1871 struct mlx4_en_dev *mdev = priv->mdev;
1872 int i;
1873
1874 if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1))
1875 en_dbg(HW, priv, "Failed dumping statistics\n");
1876
1877 memset(&priv->stats, 0, sizeof(priv->stats));
1878 memset(&priv->pstats, 0, sizeof(priv->pstats));
1879 memset(&priv->pkstats, 0, sizeof(priv->pkstats));
1880 memset(&priv->port_stats, 0, sizeof(priv->port_stats));
Matan Barak0b131562015-03-30 17:45:25 +03001881 memset(&priv->rx_flowstats, 0, sizeof(priv->rx_flowstats));
1882 memset(&priv->tx_flowstats, 0, sizeof(priv->tx_flowstats));
1883 memset(&priv->rx_priority_flowstats, 0,
1884 sizeof(priv->rx_priority_flowstats));
1885 memset(&priv->tx_priority_flowstats, 0,
1886 sizeof(priv->tx_priority_flowstats));
Eran Ben Elishab42de4d2015-06-15 17:59:06 +03001887 memset(&priv->pf_stats, 0, sizeof(priv->pf_stats));
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001888
1889 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001890 priv->tx_ring[i]->bytes = 0;
1891 priv->tx_ring[i]->packets = 0;
1892 priv->tx_ring[i]->tx_csum = 0;
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001893 }
1894 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001895 priv->rx_ring[i]->bytes = 0;
1896 priv->rx_ring[i]->packets = 0;
1897 priv->rx_ring[i]->csum_ok = 0;
1898 priv->rx_ring[i]->csum_none = 0;
Shani Michaelif8c64552014-11-09 13:51:53 +02001899 priv->rx_ring[i]->csum_complete = 0;
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001900 }
1901}
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001902
1903static int mlx4_en_open(struct net_device *dev)
1904{
1905 struct mlx4_en_priv *priv = netdev_priv(dev);
1906 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001907 int err = 0;
1908
1909 mutex_lock(&mdev->state_lock);
1910
1911 if (!mdev->device_up) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001912 en_err(priv, "Cannot open - device down/disabled\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001913 err = -EBUSY;
1914 goto out;
1915 }
1916
Eugenia Emantayevb477ba62012-01-19 09:42:37 +00001917 /* Reset HW statistics and SW counters */
1918 mlx4_en_clear_stats(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001919
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001920 err = mlx4_en_start_port(dev);
1921 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001922 en_err(priv, "Failed starting port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001923
1924out:
1925 mutex_unlock(&mdev->state_lock);
1926 return err;
1927}
1928
1929
1930static int mlx4_en_close(struct net_device *dev)
1931{
1932 struct mlx4_en_priv *priv = netdev_priv(dev);
1933 struct mlx4_en_dev *mdev = priv->mdev;
1934
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001935 en_dbg(IFDOWN, priv, "Close port called\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001936
1937 mutex_lock(&mdev->state_lock);
1938
Amir Vadai3484aac2013-01-30 23:07:11 +00001939 mlx4_en_stop_port(dev, 0);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001940 netif_carrier_off(dev);
1941
1942 mutex_unlock(&mdev->state_lock);
1943 return 0;
1944}
1945
Alexander Gullerfe0af032011-10-09 05:26:46 +00001946void mlx4_en_free_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001947{
1948 int i;
1949
Amir Vadai1eb8c692012-07-18 22:33:52 +00001950#ifdef CONFIG_RFS_ACCEL
Amir Vadai1eb8c692012-07-18 22:33:52 +00001951 priv->dev->rx_cpu_rmap = NULL;
1952#endif
1953
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001954 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001955 if (priv->tx_ring && priv->tx_ring[i])
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001956 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001957 if (priv->tx_cq && priv->tx_cq[i])
Alexander Gullerfe0af032011-10-09 05:26:46 +00001958 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001959 }
1960
1961 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001962 if (priv->rx_ring[i])
Thadeu Lima de Souza Cascardo68355f72012-02-06 08:39:49 +00001963 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
1964 priv->prof->rx_ring_size, priv->stride);
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001965 if (priv->rx_cq[i])
Alexander Gullerfe0af032011-10-09 05:26:46 +00001966 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001967 }
Yevgeny Petrilin044ca2a2012-06-25 00:24:13 +00001968
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001969}
1970
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001971int mlx4_en_alloc_resources(struct mlx4_en_priv *priv)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001972{
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001973 struct mlx4_en_port_profile *prof = priv->prof;
1974 int i;
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001975 int node;
Yevgeny Petrilin87a5c382011-03-22 22:38:52 +00001976
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001977 /* Create tx Rings */
1978 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001979 node = cpu_to_node(i % num_online_cpus());
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001980 if (mlx4_en_create_cq(priv, &priv->tx_cq[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001981 prof->tx_ring_size, i, TX, node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001982 goto err;
1983
Ido Shamayd03a68f2013-12-19 21:20:14 +02001984 if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i],
Ido Shamayd03a68f2013-12-19 21:20:14 +02001985 prof->tx_ring_size, TXBB_SIZE,
1986 node, i))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001987 goto err;
1988 }
1989
1990 /* Create rx Rings */
1991 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001992 node = cpu_to_node(i % num_online_cpus());
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001993 if (mlx4_en_create_cq(priv, &priv->rx_cq[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001994 prof->rx_ring_size, i, RX, node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001995 goto err;
1996
1997 if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i],
Eugenia Emantayev163561a2013-11-07 12:19:54 +02001998 prof->rx_ring_size, priv->stride,
1999 node))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002000 goto err;
2001 }
2002
Amir Vadai1eb8c692012-07-18 22:33:52 +00002003#ifdef CONFIG_RFS_ACCEL
Matan Barakc66fa192015-05-31 09:30:16 +03002004 priv->dev->rx_cpu_rmap = mlx4_get_cpu_rmap(priv->mdev->dev, priv->port);
Amir Vadai1eb8c692012-07-18 22:33:52 +00002005#endif
2006
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002007 return 0;
2008
2009err:
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002010 en_err(priv, "Failed to allocate NIC resources\n");
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002011 for (i = 0; i < priv->rx_ring_num; i++) {
2012 if (priv->rx_ring[i])
2013 mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
2014 prof->rx_ring_size,
2015 priv->stride);
2016 if (priv->rx_cq[i])
2017 mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
2018 }
2019 for (i = 0; i < priv->tx_ring_num; i++) {
2020 if (priv->tx_ring[i])
2021 mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
2022 if (priv->tx_cq[i])
2023 mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
2024 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002025 return -ENOMEM;
2026}
2027
2028
2029void mlx4_en_destroy_netdev(struct net_device *dev)
2030{
2031 struct mlx4_en_priv *priv = netdev_priv(dev);
2032 struct mlx4_en_dev *mdev = priv->mdev;
2033
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002034 en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002035
2036 /* Unregister device - this will close the port if it was up */
Jiri Pirko09d4d082016-02-26 17:32:24 +01002037 if (priv->registered) {
2038 devlink_port_type_clear(mlx4_get_devlink_port(mdev->dev,
2039 priv->port));
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002040 unregister_netdev(dev);
Jiri Pirko09d4d082016-02-26 17:32:24 +01002041 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002042
2043 if (priv->allocated)
2044 mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE);
2045
2046 cancel_delayed_work(&priv->stats_task);
Amir Vadaib6c39bf2013-04-23 06:06:51 +00002047 cancel_delayed_work(&priv->service_task);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002048 /* flush any pending task for this netdev */
2049 flush_workqueue(mdev->workqueue);
2050
Eugenia Emantayev90683062015-12-17 15:35:38 +02002051 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
2052 mlx4_en_remove_timestamp(mdev);
2053
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002054 /* Detach the netdev so tasks would not attempt to access it */
2055 mutex_lock(&mdev->state_lock);
2056 mdev->pndev[priv->port] = NULL;
Moni Shoua5da03542015-02-03 16:48:34 +02002057 mdev->upper[priv->port] = NULL;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002058 mutex_unlock(&mdev->state_lock);
2059
Alexander Gullerfe0af032011-10-09 05:26:46 +00002060 mlx4_en_free_resources(priv);
Amir Vadai564c2742012-04-04 21:33:26 +00002061
Amir Vadaibc6a4742012-05-17 00:58:10 +00002062 kfree(priv->tx_ring);
2063 kfree(priv->tx_cq);
2064
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002065 free_netdev(dev);
2066}
2067
2068static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
2069{
2070 struct mlx4_en_priv *priv = netdev_priv(dev);
2071 struct mlx4_en_dev *mdev = priv->mdev;
2072 int err = 0;
2073
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002074 en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002075 dev->mtu, new_mtu);
2076
2077 if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002078 en_err(priv, "Bad MTU size:%d.\n", new_mtu);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002079 return -EPERM;
2080 }
2081 dev->mtu = new_mtu;
2082
2083 if (netif_running(dev)) {
2084 mutex_lock(&mdev->state_lock);
2085 if (!mdev->device_up) {
2086 /* NIC is probably restarting - let watchdog task reset
2087 * the port */
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002088 en_dbg(DRV, priv, "Change MTU called with card down!?\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002089 } else {
Amir Vadai3484aac2013-01-30 23:07:11 +00002090 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002091 err = mlx4_en_start_port(dev);
2092 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002093 en_err(priv, "Failed restarting port:%d\n",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002094 priv->port);
2095 queue_work(mdev->workqueue, &priv->watchdog_task);
2096 }
2097 }
2098 mutex_unlock(&mdev->state_lock);
2099 }
2100 return 0;
2101}
2102
Ben Hutchings100dbda2013-11-18 23:13:31 +00002103static int mlx4_en_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
Amir Vadaiec693d42013-04-23 06:06:49 +00002104{
2105 struct mlx4_en_priv *priv = netdev_priv(dev);
2106 struct mlx4_en_dev *mdev = priv->mdev;
2107 struct hwtstamp_config config;
2108
2109 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
2110 return -EFAULT;
2111
2112 /* reserved for future extensions */
2113 if (config.flags)
2114 return -EINVAL;
2115
2116 /* device doesn't support time stamping */
2117 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS))
2118 return -EINVAL;
2119
2120 /* TX HW timestamp */
2121 switch (config.tx_type) {
2122 case HWTSTAMP_TX_OFF:
2123 case HWTSTAMP_TX_ON:
2124 break;
2125 default:
2126 return -ERANGE;
2127 }
2128
2129 /* RX HW timestamp */
2130 switch (config.rx_filter) {
2131 case HWTSTAMP_FILTER_NONE:
2132 break;
2133 case HWTSTAMP_FILTER_ALL:
2134 case HWTSTAMP_FILTER_SOME:
2135 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2136 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2137 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2138 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2139 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2140 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2141 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2142 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
2143 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
2144 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2145 case HWTSTAMP_FILTER_PTP_V2_SYNC:
2146 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
2147 config.rx_filter = HWTSTAMP_FILTER_ALL;
2148 break;
2149 default:
2150 return -ERANGE;
2151 }
2152
Saeed Mahameed7787fa62014-10-27 11:37:42 +02002153 if (mlx4_en_reset_config(dev, config, dev->features)) {
Amir Vadaiec693d42013-04-23 06:06:49 +00002154 config.tx_type = HWTSTAMP_TX_OFF;
2155 config.rx_filter = HWTSTAMP_FILTER_NONE;
2156 }
2157
2158 return copy_to_user(ifr->ifr_data, &config,
2159 sizeof(config)) ? -EFAULT : 0;
2160}
2161
Ben Hutchings100dbda2013-11-18 23:13:31 +00002162static int mlx4_en_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
2163{
2164 struct mlx4_en_priv *priv = netdev_priv(dev);
2165
2166 return copy_to_user(ifr->ifr_data, &priv->hwtstamp_config,
2167 sizeof(priv->hwtstamp_config)) ? -EFAULT : 0;
2168}
2169
Amir Vadaiec693d42013-04-23 06:06:49 +00002170static int mlx4_en_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2171{
2172 switch (cmd) {
2173 case SIOCSHWTSTAMP:
Ben Hutchings100dbda2013-11-18 23:13:31 +00002174 return mlx4_en_hwtstamp_set(dev, ifr);
2175 case SIOCGHWTSTAMP:
2176 return mlx4_en_hwtstamp_get(dev, ifr);
Amir Vadaiec693d42013-04-23 06:06:49 +00002177 default:
2178 return -EOPNOTSUPP;
2179 }
2180}
2181
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03002182static netdev_features_t mlx4_en_fix_features(struct net_device *netdev,
2183 netdev_features_t features)
2184{
2185 struct mlx4_en_priv *en_priv = netdev_priv(netdev);
2186 struct mlx4_en_dev *mdev = en_priv->mdev;
2187
2188 /* Since there is no support for separate RX C-TAG/S-TAG vlan accel
2189 * enable/disable make sure S-TAG flag is always in same state as
2190 * C-TAG.
2191 */
2192 if (features & NETIF_F_HW_VLAN_CTAG_RX &&
2193 !(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN))
2194 features |= NETIF_F_HW_VLAN_STAG_RX;
2195 else
2196 features &= ~NETIF_F_HW_VLAN_STAG_RX;
2197
2198 return features;
2199}
2200
Amir Vadai60d6fe92011-11-26 19:55:19 +00002201static int mlx4_en_set_features(struct net_device *netdev,
2202 netdev_features_t features)
2203{
2204 struct mlx4_en_priv *priv = netdev_priv(netdev);
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002205 bool reset = false;
Saeed Mahameed537f6f92014-10-27 11:37:43 +02002206 int ret = 0;
2207
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002208 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_RXFCS)) {
2209 en_info(priv, "Turn %s RX-FCS\n",
2210 (features & NETIF_F_RXFCS) ? "ON" : "OFF");
2211 reset = true;
2212 }
2213
Muhammad Mahajna78500b82015-04-02 16:31:22 +03002214 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_RXALL)) {
2215 u8 ignore_fcs_value = (features & NETIF_F_RXALL) ? 1 : 0;
2216
2217 en_info(priv, "Turn %s RX-ALL\n",
2218 ignore_fcs_value ? "ON" : "OFF");
2219 ret = mlx4_SET_PORT_fcs_check(priv->mdev->dev,
2220 priv->port, ignore_fcs_value);
2221 if (ret)
2222 return ret;
2223 }
2224
Saeed Mahameed537f6f92014-10-27 11:37:43 +02002225 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_HW_VLAN_CTAG_RX)) {
2226 en_info(priv, "Turn %s RX vlan strip offload\n",
2227 (features & NETIF_F_HW_VLAN_CTAG_RX) ? "ON" : "OFF");
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002228 reset = true;
Saeed Mahameed537f6f92014-10-27 11:37:43 +02002229 }
Amir Vadai60d6fe92011-11-26 19:55:19 +00002230
Ido Shamaycfb53f32015-02-03 17:57:21 +02002231 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_HW_VLAN_CTAG_TX))
2232 en_info(priv, "Turn %s TX vlan strip offload\n",
2233 (features & NETIF_F_HW_VLAN_CTAG_TX) ? "ON" : "OFF");
2234
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03002235 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_HW_VLAN_STAG_TX))
2236 en_info(priv, "Turn %s TX S-VLAN strip offload\n",
2237 (features & NETIF_F_HW_VLAN_STAG_TX) ? "ON" : "OFF");
2238
Ido Shamay241a08c2015-04-02 16:31:07 +03002239 if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_LOOPBACK)) {
2240 en_info(priv, "Turn %s loopback\n",
2241 (features & NETIF_F_LOOPBACK) ? "ON" : "OFF");
2242 mlx4_en_update_loopback_state(netdev, features);
2243 }
Yan Burman79aeacc2013-02-07 02:25:19 +00002244
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002245 if (reset) {
2246 ret = mlx4_en_reset_config(netdev, priv->hwtstamp_config,
2247 features);
2248 if (ret)
2249 return ret;
2250 }
Amir Vadai60d6fe92011-11-26 19:55:19 +00002251
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002252 return 0;
Amir Vadai60d6fe92011-11-26 19:55:19 +00002253}
2254
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002255static int mlx4_en_set_vf_mac(struct net_device *dev, int queue, u8 *mac)
2256{
2257 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2258 struct mlx4_en_dev *mdev = en_priv->mdev;
Eugenia Emantayev98133372014-03-02 10:25:01 +02002259 u64 mac_u64 = mlx4_mac_to_u64(mac);
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002260
Jack Morgenstein6e522422016-03-02 17:47:46 +02002261 if (is_multicast_ether_addr(mac))
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002262 return -EINVAL;
2263
2264 return mlx4_set_vf_mac(mdev->dev, en_priv->port, queue, mac_u64);
2265}
2266
Rony Efraim3f7fb022013-04-25 05:22:28 +00002267static int mlx4_en_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos)
2268{
2269 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2270 struct mlx4_en_dev *mdev = en_priv->mdev;
2271
2272 return mlx4_set_vf_vlan(mdev->dev, en_priv->port, vf, vlan, qos);
2273}
2274
Ido Shamaycda373f2015-04-02 16:31:16 +03002275static int mlx4_en_set_vf_rate(struct net_device *dev, int vf, int min_tx_rate,
2276 int max_tx_rate)
2277{
2278 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2279 struct mlx4_en_dev *mdev = en_priv->mdev;
2280
2281 return mlx4_set_vf_rate(mdev->dev, en_priv->port, vf, min_tx_rate,
2282 max_tx_rate);
2283}
2284
Rony Efraime6b6a232013-04-25 05:22:29 +00002285static int mlx4_en_set_vf_spoofchk(struct net_device *dev, int vf, bool setting)
2286{
2287 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2288 struct mlx4_en_dev *mdev = en_priv->mdev;
2289
2290 return mlx4_set_vf_spoofchk(mdev->dev, en_priv->port, vf, setting);
2291}
2292
Rony Efraim2cccb9e2013-04-25 05:22:30 +00002293static int mlx4_en_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_info *ivf)
2294{
2295 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2296 struct mlx4_en_dev *mdev = en_priv->mdev;
2297
2298 return mlx4_get_vf_config(mdev->dev, en_priv->port, vf, ivf);
2299}
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002300
Rony Efraim948e3062013-06-13 13:19:11 +03002301static int mlx4_en_set_vf_link_state(struct net_device *dev, int vf, int link_state)
2302{
2303 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2304 struct mlx4_en_dev *mdev = en_priv->mdev;
2305
2306 return mlx4_set_vf_link_state(mdev->dev, en_priv->port, vf, link_state);
2307}
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002308
Eran Ben Elisha62a89052015-06-15 17:59:08 +03002309static int mlx4_en_get_vf_stats(struct net_device *dev, int vf,
2310 struct ifla_vf_stats *vf_stats)
2311{
2312 struct mlx4_en_priv *en_priv = netdev_priv(dev);
2313 struct mlx4_en_dev *mdev = en_priv->mdev;
2314
2315 return mlx4_get_vf_stats(mdev->dev, en_priv->port, vf, vf_stats);
2316}
2317
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002318#define PORT_ID_BYTE_LEN 8
2319static int mlx4_en_get_phys_port_id(struct net_device *dev,
Jiri Pirko02637fc2014-11-28 14:34:16 +01002320 struct netdev_phys_item_id *ppid)
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002321{
2322 struct mlx4_en_priv *priv = netdev_priv(dev);
2323 struct mlx4_dev *mdev = priv->mdev->dev;
2324 int i;
2325 u64 phys_port_id = mdev->caps.phys_port_id[priv->port];
2326
2327 if (!phys_port_id)
2328 return -EOPNOTSUPP;
2329
2330 ppid->id_len = sizeof(phys_port_id);
2331 for (i = PORT_ID_BYTE_LEN - 1; i >= 0; --i) {
2332 ppid->id[i] = phys_port_id & 0xff;
2333 phys_port_id >>= 8;
2334 }
2335 return 0;
2336}
2337
Or Gerlitza66132f2014-04-01 11:27:13 +03002338#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02002339static void mlx4_en_add_vxlan_offloads(struct work_struct *work)
2340{
2341 int ret;
2342 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
2343 vxlan_add_task);
2344
2345 ret = mlx4_config_vxlan_port(priv->mdev->dev, priv->vxlan_port);
2346 if (ret)
2347 goto out;
2348
2349 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port,
2350 VXLAN_STEER_BY_OUTER_MAC, 1);
2351out:
Or Gerlitzf4a1edd2014-11-09 14:25:39 +02002352 if (ret) {
Or Gerlitz1b136de2014-03-27 14:02:04 +02002353 en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret);
Or Gerlitzf4a1edd2014-11-09 14:25:39 +02002354 return;
2355 }
2356
2357 /* set offloads */
2358 priv->dev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2359 NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL;
Or Gerlitz1b136de2014-03-27 14:02:04 +02002360}
2361
2362static void mlx4_en_del_vxlan_offloads(struct work_struct *work)
2363{
2364 int ret;
2365 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
2366 vxlan_del_task);
Or Gerlitzf4a1edd2014-11-09 14:25:39 +02002367 /* unset offloads */
2368 priv->dev->hw_enc_features &= ~(NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2369 NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL);
Or Gerlitz1b136de2014-03-27 14:02:04 +02002370
2371 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port,
2372 VXLAN_STEER_BY_OUTER_MAC, 0);
2373 if (ret)
2374 en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret);
2375
2376 priv->vxlan_port = 0;
2377}
2378
2379static void mlx4_en_add_vxlan_port(struct net_device *dev,
2380 sa_family_t sa_family, __be16 port)
2381{
2382 struct mlx4_en_priv *priv = netdev_priv(dev);
2383 __be16 current_port;
2384
Or Gerlitze326f2f2014-07-02 17:36:23 +03002385 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
Or Gerlitz1b136de2014-03-27 14:02:04 +02002386 return;
2387
2388 if (sa_family == AF_INET6)
2389 return;
2390
2391 current_port = priv->vxlan_port;
2392 if (current_port && current_port != port) {
2393 en_warn(priv, "vxlan port %d configured, can't add port %d\n",
2394 ntohs(current_port), ntohs(port));
2395 return;
2396 }
2397
2398 priv->vxlan_port = port;
2399 queue_work(priv->mdev->workqueue, &priv->vxlan_add_task);
2400}
2401
2402static void mlx4_en_del_vxlan_port(struct net_device *dev,
2403 sa_family_t sa_family, __be16 port)
2404{
2405 struct mlx4_en_priv *priv = netdev_priv(dev);
2406 __be16 current_port;
2407
2408 if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
2409 return;
2410
2411 if (sa_family == AF_INET6)
2412 return;
2413
2414 current_port = priv->vxlan_port;
2415 if (current_port != port) {
2416 en_dbg(DRV, priv, "vxlan port %d isn't configured, ignoring\n", ntohs(port));
2417 return;
2418 }
2419
2420 queue_work(priv->mdev->workqueue, &priv->vxlan_del_task);
2421}
Joe Stringer956bdab2014-11-13 16:38:14 -08002422
Jesse Gross5f352272014-12-23 22:37:26 -08002423static netdev_features_t mlx4_en_features_check(struct sk_buff *skb,
2424 struct net_device *dev,
2425 netdev_features_t features)
Joe Stringer956bdab2014-11-13 16:38:14 -08002426{
Toshiaki Makita8cb65d02015-03-27 14:31:12 +09002427 features = vlan_features_check(skb, features);
Jesse Gross5f352272014-12-23 22:37:26 -08002428 return vxlan_features_check(skb, features);
Joe Stringer956bdab2014-11-13 16:38:14 -08002429}
Or Gerlitza66132f2014-04-01 11:27:13 +03002430#endif
Or Gerlitz1b136de2014-03-27 14:02:04 +02002431
Wu Fengguangde1cf8a2015-03-19 08:51:27 +08002432static int mlx4_en_set_tx_maxrate(struct net_device *dev, int queue_index, u32 maxrate)
Or Gerlitzc10e4fc2015-03-18 14:57:35 +02002433{
2434 struct mlx4_en_priv *priv = netdev_priv(dev);
2435 struct mlx4_en_tx_ring *tx_ring = priv->tx_ring[queue_index];
2436 struct mlx4_update_qp_params params;
2437 int err;
2438
2439 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_QP_RATE_LIMIT))
2440 return -EOPNOTSUPP;
2441
2442 /* rate provided to us in Mbs, check if it fits into 12 bits, if not use Gbs */
2443 if (maxrate >> 12) {
2444 params.rate_unit = MLX4_QP_RATE_LIMIT_GBS;
2445 params.rate_val = maxrate / 1000;
2446 } else if (maxrate) {
2447 params.rate_unit = MLX4_QP_RATE_LIMIT_MBS;
2448 params.rate_val = maxrate;
2449 } else { /* zero serves to revoke the QP rate-limitation */
2450 params.rate_unit = 0;
2451 params.rate_val = 0;
2452 }
2453
2454 err = mlx4_update_qp(priv->mdev->dev, tx_ring->qpn, MLX4_UPDATE_QP_RATE_LIMIT,
2455 &params);
2456 return err;
2457}
2458
Stephen Hemminger3addc562008-11-21 17:30:58 -08002459static const struct net_device_ops mlx4_netdev_ops = {
2460 .ndo_open = mlx4_en_open,
2461 .ndo_stop = mlx4_en_close,
2462 .ndo_start_xmit = mlx4_en_xmit,
Yevgeny Petrilinf813cad2009-06-01 23:24:07 +00002463 .ndo_select_queue = mlx4_en_select_queue,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002464 .ndo_get_stats = mlx4_en_get_stats,
Yan Burman0eb74fd2013-02-07 02:25:23 +00002465 .ndo_set_rx_mode = mlx4_en_set_rx_mode,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002466 .ndo_set_mac_address = mlx4_en_set_mac,
Stephen Hemminger52255bb2009-01-09 10:45:37 +00002467 .ndo_validate_addr = eth_validate_addr,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002468 .ndo_change_mtu = mlx4_en_change_mtu,
Amir Vadaiec693d42013-04-23 06:06:49 +00002469 .ndo_do_ioctl = mlx4_en_ioctl,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002470 .ndo_tx_timeout = mlx4_en_tx_timeout,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002471 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
2472 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
2473#ifdef CONFIG_NET_POLL_CONTROLLER
2474 .ndo_poll_controller = mlx4_en_netpoll,
2475#endif
Amir Vadai60d6fe92011-11-26 19:55:19 +00002476 .ndo_set_features = mlx4_en_set_features,
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03002477 .ndo_fix_features = mlx4_en_fix_features,
John Fastabende4c67342016-02-16 21:16:15 -08002478 .ndo_setup_tc = __mlx4_en_setup_tc,
Amir Vadai1eb8c692012-07-18 22:33:52 +00002479#ifdef CONFIG_RFS_ACCEL
2480 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2481#endif
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002482 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
Or Gerlitza66132f2014-04-01 11:27:13 +03002483#ifdef CONFIG_MLX4_EN_VXLAN
Or Gerlitz1b136de2014-03-27 14:02:04 +02002484 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port,
2485 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port,
Jesse Gross5f352272014-12-23 22:37:26 -08002486 .ndo_features_check = mlx4_en_features_check,
Or Gerlitza66132f2014-04-01 11:27:13 +03002487#endif
Or Gerlitzc10e4fc2015-03-18 14:57:35 +02002488 .ndo_set_tx_maxrate = mlx4_en_set_tx_maxrate,
Stephen Hemminger3addc562008-11-21 17:30:58 -08002489};
2490
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002491static const struct net_device_ops mlx4_netdev_ops_master = {
2492 .ndo_open = mlx4_en_open,
2493 .ndo_stop = mlx4_en_close,
2494 .ndo_start_xmit = mlx4_en_xmit,
2495 .ndo_select_queue = mlx4_en_select_queue,
2496 .ndo_get_stats = mlx4_en_get_stats,
2497 .ndo_set_rx_mode = mlx4_en_set_rx_mode,
2498 .ndo_set_mac_address = mlx4_en_set_mac,
2499 .ndo_validate_addr = eth_validate_addr,
2500 .ndo_change_mtu = mlx4_en_change_mtu,
2501 .ndo_tx_timeout = mlx4_en_tx_timeout,
2502 .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
2503 .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
2504 .ndo_set_vf_mac = mlx4_en_set_vf_mac,
Rony Efraim3f7fb022013-04-25 05:22:28 +00002505 .ndo_set_vf_vlan = mlx4_en_set_vf_vlan,
Ido Shamaycda373f2015-04-02 16:31:16 +03002506 .ndo_set_vf_rate = mlx4_en_set_vf_rate,
Rony Efraime6b6a232013-04-25 05:22:29 +00002507 .ndo_set_vf_spoofchk = mlx4_en_set_vf_spoofchk,
Rony Efraim948e3062013-06-13 13:19:11 +03002508 .ndo_set_vf_link_state = mlx4_en_set_vf_link_state,
Eran Ben Elisha62a89052015-06-15 17:59:08 +03002509 .ndo_get_vf_stats = mlx4_en_get_vf_stats,
Rony Efraim2cccb9e2013-04-25 05:22:30 +00002510 .ndo_get_vf_config = mlx4_en_get_vf_config,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002511#ifdef CONFIG_NET_POLL_CONTROLLER
2512 .ndo_poll_controller = mlx4_en_netpoll,
2513#endif
2514 .ndo_set_features = mlx4_en_set_features,
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03002515 .ndo_fix_features = mlx4_en_fix_features,
John Fastabende4c67342016-02-16 21:16:15 -08002516 .ndo_setup_tc = __mlx4_en_setup_tc,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002517#ifdef CONFIG_RFS_ACCEL
2518 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2519#endif
Hadar Hen Zion84c86402013-12-19 21:20:13 +02002520 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
Or Gerlitz9737c6a2014-11-18 17:51:27 +02002521#ifdef CONFIG_MLX4_EN_VXLAN
2522 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port,
2523 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port,
Jesse Gross5f352272014-12-23 22:37:26 -08002524 .ndo_features_check = mlx4_en_features_check,
Or Gerlitz9737c6a2014-11-18 17:51:27 +02002525#endif
Or Gerlitzc10e4fc2015-03-18 14:57:35 +02002526 .ndo_set_tx_maxrate = mlx4_en_set_tx_maxrate,
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002527};
2528
Moni Shoua5da03542015-02-03 16:48:34 +02002529struct mlx4_en_bond {
2530 struct work_struct work;
2531 struct mlx4_en_priv *priv;
2532 int is_bonded;
2533 struct mlx4_port_map port_map;
2534};
2535
2536static void mlx4_en_bond_work(struct work_struct *work)
2537{
2538 struct mlx4_en_bond *bond = container_of(work,
2539 struct mlx4_en_bond,
2540 work);
2541 int err = 0;
2542 struct mlx4_dev *dev = bond->priv->mdev->dev;
2543
2544 if (bond->is_bonded) {
2545 if (!mlx4_is_bonded(dev)) {
2546 err = mlx4_bond(dev);
2547 if (err)
2548 en_err(bond->priv, "Fail to bond device\n");
2549 }
2550 if (!err) {
2551 err = mlx4_port_map_set(dev, &bond->port_map);
2552 if (err)
2553 en_err(bond->priv, "Fail to set port map [%d][%d]: %d\n",
2554 bond->port_map.port1,
2555 bond->port_map.port2,
2556 err);
2557 }
2558 } else if (mlx4_is_bonded(dev)) {
2559 err = mlx4_unbond(dev);
2560 if (err)
2561 en_err(bond->priv, "Fail to unbond device\n");
2562 }
2563 dev_put(bond->priv->dev);
2564 kfree(bond);
2565}
2566
2567static int mlx4_en_queue_bond_work(struct mlx4_en_priv *priv, int is_bonded,
2568 u8 v2p_p1, u8 v2p_p2)
2569{
2570 struct mlx4_en_bond *bond = NULL;
2571
2572 bond = kzalloc(sizeof(*bond), GFP_ATOMIC);
2573 if (!bond)
2574 return -ENOMEM;
2575
2576 INIT_WORK(&bond->work, mlx4_en_bond_work);
2577 bond->priv = priv;
2578 bond->is_bonded = is_bonded;
2579 bond->port_map.port1 = v2p_p1;
2580 bond->port_map.port2 = v2p_p2;
2581 dev_hold(priv->dev);
2582 queue_work(priv->mdev->workqueue, &bond->work);
2583 return 0;
2584}
2585
2586int mlx4_en_netdev_event(struct notifier_block *this,
2587 unsigned long event, void *ptr)
2588{
2589 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
2590 u8 port = 0;
2591 struct mlx4_en_dev *mdev;
2592 struct mlx4_dev *dev;
2593 int i, num_eth_ports = 0;
2594 bool do_bond = true;
2595 struct mlx4_en_priv *priv;
2596 u8 v2p_port1 = 0;
2597 u8 v2p_port2 = 0;
2598
2599 if (!net_eq(dev_net(ndev), &init_net))
2600 return NOTIFY_DONE;
2601
2602 mdev = container_of(this, struct mlx4_en_dev, nb);
2603 dev = mdev->dev;
2604
2605 /* Go into this mode only when two network devices set on two ports
2606 * of the same mlx4 device are slaves of the same bonding master
2607 */
2608 mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) {
2609 ++num_eth_ports;
2610 if (!port && (mdev->pndev[i] == ndev))
2611 port = i;
2612 mdev->upper[i] = mdev->pndev[i] ?
2613 netdev_master_upper_dev_get(mdev->pndev[i]) : NULL;
2614 /* condition not met: network device is a slave */
2615 if (!mdev->upper[i])
2616 do_bond = false;
2617 if (num_eth_ports < 2)
2618 continue;
2619 /* condition not met: same master */
2620 if (mdev->upper[i] != mdev->upper[i-1])
2621 do_bond = false;
2622 }
2623 /* condition not met: 2 salves */
2624 do_bond = (num_eth_ports == 2) ? do_bond : false;
2625
2626 /* handle only events that come with enough info */
2627 if ((do_bond && (event != NETDEV_BONDING_INFO)) || !port)
2628 return NOTIFY_DONE;
2629
2630 priv = netdev_priv(ndev);
2631 if (do_bond) {
2632 struct netdev_notifier_bonding_info *notifier_info = ptr;
2633 struct netdev_bonding_info *bonding_info =
2634 &notifier_info->bonding_info;
2635
2636 /* required mode 1, 2 or 4 */
2637 if ((bonding_info->master.bond_mode != BOND_MODE_ACTIVEBACKUP) &&
2638 (bonding_info->master.bond_mode != BOND_MODE_XOR) &&
2639 (bonding_info->master.bond_mode != BOND_MODE_8023AD))
2640 do_bond = false;
2641
2642 /* require exactly 2 slaves */
2643 if (bonding_info->master.num_slaves != 2)
2644 do_bond = false;
2645
2646 /* calc v2p */
2647 if (do_bond) {
2648 if (bonding_info->master.bond_mode ==
2649 BOND_MODE_ACTIVEBACKUP) {
2650 /* in active-backup mode virtual ports are
2651 * mapped to the physical port of the active
2652 * slave */
2653 if (bonding_info->slave.state ==
2654 BOND_STATE_BACKUP) {
2655 if (port == 1) {
2656 v2p_port1 = 2;
2657 v2p_port2 = 2;
2658 } else {
2659 v2p_port1 = 1;
2660 v2p_port2 = 1;
2661 }
2662 } else { /* BOND_STATE_ACTIVE */
2663 if (port == 1) {
2664 v2p_port1 = 1;
2665 v2p_port2 = 1;
2666 } else {
2667 v2p_port1 = 2;
2668 v2p_port2 = 2;
2669 }
2670 }
2671 } else { /* Active-Active */
2672 /* in active-active mode a virtual port is
2673 * mapped to the native physical port if and only
2674 * if the physical port is up */
2675 __s8 link = bonding_info->slave.link;
2676
2677 if (port == 1)
2678 v2p_port2 = 2;
2679 else
2680 v2p_port1 = 1;
2681 if ((link == BOND_LINK_UP) ||
2682 (link == BOND_LINK_FAIL)) {
2683 if (port == 1)
2684 v2p_port1 = 1;
2685 else
2686 v2p_port2 = 2;
2687 } else { /* BOND_LINK_DOWN || BOND_LINK_BACK */
2688 if (port == 1)
2689 v2p_port1 = 2;
2690 else
2691 v2p_port2 = 1;
2692 }
2693 }
2694 }
2695 }
2696
2697 mlx4_en_queue_bond_work(priv, do_bond,
2698 v2p_port1, v2p_port2);
2699
2700 return NOTIFY_DONE;
2701}
2702
Matan Barak0b131562015-03-30 17:45:25 +03002703void mlx4_en_update_pfc_stats_bitmap(struct mlx4_dev *dev,
2704 struct mlx4_en_stats_bitmap *stats_bitmap,
2705 u8 rx_ppp, u8 rx_pause,
2706 u8 tx_ppp, u8 tx_pause)
2707{
Eran Ben Elishab42de4d2015-06-15 17:59:06 +03002708 int last_i = NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PF_STATS;
Matan Barak0b131562015-03-30 17:45:25 +03002709
2710 if (!mlx4_is_slave(dev) &&
2711 (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN)) {
2712 mutex_lock(&stats_bitmap->mutex);
2713 bitmap_clear(stats_bitmap->bitmap, last_i, NUM_FLOW_STATS);
2714
2715 if (rx_ppp)
2716 bitmap_set(stats_bitmap->bitmap, last_i,
2717 NUM_FLOW_PRIORITY_STATS_RX);
2718 last_i += NUM_FLOW_PRIORITY_STATS_RX;
2719
2720 if (rx_pause && !(rx_ppp))
2721 bitmap_set(stats_bitmap->bitmap, last_i,
2722 NUM_FLOW_STATS_RX);
2723 last_i += NUM_FLOW_STATS_RX;
2724
2725 if (tx_ppp)
2726 bitmap_set(stats_bitmap->bitmap, last_i,
2727 NUM_FLOW_PRIORITY_STATS_TX);
2728 last_i += NUM_FLOW_PRIORITY_STATS_TX;
2729
2730 if (tx_pause && !(tx_ppp))
2731 bitmap_set(stats_bitmap->bitmap, last_i,
2732 NUM_FLOW_STATS_TX);
2733 last_i += NUM_FLOW_STATS_TX;
2734
2735 mutex_unlock(&stats_bitmap->mutex);
2736 }
2737}
2738
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002739void mlx4_en_set_stats_bitmap(struct mlx4_dev *dev,
Matan Barak0b131562015-03-30 17:45:25 +03002740 struct mlx4_en_stats_bitmap *stats_bitmap,
2741 u8 rx_ppp, u8 rx_pause,
2742 u8 tx_ppp, u8 tx_pause)
Eran Ben Elishaffa88f32015-03-30 17:45:22 +03002743{
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002744 int last_i = 0;
2745
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002746 mutex_init(&stats_bitmap->mutex);
2747 bitmap_zero(stats_bitmap->bitmap, NUM_ALL_STATS);
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002748
2749 if (mlx4_is_slave(dev)) {
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002750 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002751 MLX4_FIND_NETDEV_STAT(rx_packets), 1);
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002752 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002753 MLX4_FIND_NETDEV_STAT(tx_packets), 1);
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002754 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002755 MLX4_FIND_NETDEV_STAT(rx_bytes), 1);
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002756 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002757 MLX4_FIND_NETDEV_STAT(tx_bytes), 1);
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002758 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002759 MLX4_FIND_NETDEV_STAT(rx_dropped), 1);
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002760 bitmap_set(stats_bitmap->bitmap, last_i +
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002761 MLX4_FIND_NETDEV_STAT(tx_dropped), 1);
2762 } else {
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002763 bitmap_set(stats_bitmap->bitmap, last_i, NUM_MAIN_STATS);
Eran Ben Elishaffa88f32015-03-30 17:45:22 +03002764 }
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002765 last_i += NUM_MAIN_STATS;
Eran Ben Elishaffa88f32015-03-30 17:45:22 +03002766
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002767 bitmap_set(stats_bitmap->bitmap, last_i, NUM_PORT_STATS);
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002768 last_i += NUM_PORT_STATS;
Eran Ben Elishaffa88f32015-03-30 17:45:22 +03002769
Eran Ben Elishab42de4d2015-06-15 17:59:06 +03002770 if (mlx4_is_master(dev))
2771 bitmap_set(stats_bitmap->bitmap, last_i,
2772 NUM_PF_STATS);
2773 last_i += NUM_PF_STATS;
2774
Matan Barak0b131562015-03-30 17:45:25 +03002775 mlx4_en_update_pfc_stats_bitmap(dev, stats_bitmap,
2776 rx_ppp, rx_pause,
2777 tx_ppp, tx_pause);
2778 last_i += NUM_FLOW_STATS;
2779
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +03002780 if (!mlx4_is_slave(dev))
Eran Ben Elisha3da8a362015-03-30 17:45:24 +03002781 bitmap_set(stats_bitmap->bitmap, last_i, NUM_PKT_STATS);
Eran Ben Elishaffa88f32015-03-30 17:45:22 +03002782}
2783
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002784int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
2785 struct mlx4_en_port_profile *prof)
2786{
2787 struct net_device *dev;
2788 struct mlx4_en_priv *priv;
Yan Burmanc07cb4b2013-02-07 02:25:25 +00002789 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002790 int err;
2791
Tom Herbertf1593d22011-01-09 19:36:36 +00002792 dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv),
Amir Vadaid3179662012-12-02 03:49:23 +00002793 MAX_TX_RINGS, MAX_RX_RINGS);
Joe Perches41de8d42012-01-29 13:47:52 +00002794 if (dev == NULL)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002795 return -ENOMEM;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002796
Amir Vadaid3179662012-12-02 03:49:23 +00002797 netif_set_real_num_tx_queues(dev, prof->tx_ring_num);
2798 netif_set_real_num_rx_queues(dev, prof->rx_ring_num);
2799
Yishai Hadas872bf2f2015-01-25 16:59:35 +02002800 SET_NETDEV_DEV(dev, &mdev->dev->persist->pdev->dev);
Amir Vadai76a066f2014-02-25 18:17:51 +02002801 dev->dev_port = port - 1;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002802
2803 /*
2804 * Initialize driver private data
2805 */
2806
2807 priv = netdev_priv(dev);
2808 memset(priv, 0, sizeof(struct mlx4_en_priv));
Eran Ben Elisha6de5f7f2015-06-15 17:59:02 +03002809 priv->counter_index = MLX4_SINK_COUNTER_INDEX(mdev->dev);
Eugenia Emantayev207af6c2014-10-27 11:37:46 +02002810 spin_lock_init(&priv->stats_lock);
2811 INIT_WORK(&priv->rx_mode_task, mlx4_en_do_set_rx_mode);
2812 INIT_WORK(&priv->watchdog_task, mlx4_en_restart);
2813 INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate);
2814 INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats);
2815 INIT_DELAYED_WORK(&priv->service_task, mlx4_en_service_task);
2816#ifdef CONFIG_MLX4_EN_VXLAN
2817 INIT_WORK(&priv->vxlan_add_task, mlx4_en_add_vxlan_offloads);
2818 INIT_WORK(&priv->vxlan_del_task, mlx4_en_del_vxlan_offloads);
2819#endif
2820#ifdef CONFIG_RFS_ACCEL
2821 INIT_LIST_HEAD(&priv->filters);
2822 spin_lock_init(&priv->filters_lock);
2823#endif
2824
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002825 priv->dev = dev;
2826 priv->mdev = mdev;
Yevgeny Petrilinebf8c9a2012-03-06 04:03:34 +00002827 priv->ddev = &mdev->pdev->dev;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002828 priv->prof = prof;
2829 priv->port = port;
2830 priv->port_up = false;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002831 priv->flags = prof->flags;
Amir Vadai0fef9d02014-07-22 15:44:10 +03002832 priv->pflags = MLX4_EN_PRIV_FLAGS_BLUEFLAME;
Amir Vadai60d6fe92011-11-26 19:55:19 +00002833 priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE |
2834 MLX4_WQE_CTRL_SOLICITED);
Amir Vadaid3179662012-12-02 03:49:23 +00002835 priv->num_tx_rings_p_up = mdev->profile.num_tx_rings_p_up;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002836 priv->tx_ring_num = prof->tx_ring_num;
Amir Vadaifbc6daf2014-07-08 11:28:12 +03002837 priv->tx_work_limit = MLX4_EN_DEFAULT_TX_WORK;
Eric Dumazetbd635c32014-11-22 17:24:19 -08002838 netdev_rss_key_fill(priv->rss_key, sizeof(priv->rss_key));
Amir Vadaid3179662012-12-02 03:49:23 +00002839
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002840 priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring *) * MAX_TX_RINGS,
Amir Vadaid3179662012-12-02 03:49:23 +00002841 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00002842 if (!priv->tx_ring) {
2843 err = -ENOMEM;
2844 goto out;
2845 }
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02002846 priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq *) * MAX_TX_RINGS,
Amir Vadaid3179662012-12-02 03:49:23 +00002847 GFP_KERNEL);
Amir Vadaibc6a4742012-05-17 00:58:10 +00002848 if (!priv->tx_cq) {
2849 err = -ENOMEM;
2850 goto out;
2851 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002852 priv->rx_ring_num = prof->rx_ring_num;
Or Gerlitz08ff3232012-10-21 14:59:24 +00002853 priv->cqe_factor = (mdev->dev->caps.cqe_size == 64) ? 1 : 0;
Ido Shamayb1b6b4d2014-09-18 11:51:01 +03002854 priv->cqe_size = mdev->dev->caps.cqe_size;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002855 priv->mac_index = -1;
2856 priv->msg_enable = MLX4_EN_MSG_LEVEL;
Amir Vadai564c2742012-04-04 21:33:26 +00002857#ifdef CONFIG_MLX4_EN_DCB
Or Gerlitz540b3a32013-04-07 03:44:07 +00002858 if (!mlx4_is_slave(priv->mdev->dev)) {
Ido Shamay3742cc62015-04-02 16:31:17 +03002859 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETS_CFG) {
Or Gerlitz540b3a32013-04-07 03:44:07 +00002860 dev->dcbnl_ops = &mlx4_en_dcbnl_ops;
2861 } else {
2862 en_info(priv, "enabling only PFC DCB ops\n");
2863 dev->dcbnl_ops = &mlx4_en_dcbnl_pfc_ops;
2864 }
2865 }
Amir Vadai564c2742012-04-04 21:33:26 +00002866#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002867
Yan Burmanc07cb4b2013-02-07 02:25:25 +00002868 for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i)
2869 INIT_HLIST_HEAD(&priv->mac_hash[i]);
Yan Burman16a10ff2013-02-07 02:25:22 +00002870
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002871 /* Query for default mac and max mtu */
2872 priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port];
Yan Burman6bbb6d92013-02-07 02:25:20 +00002873
Shani Michaelif8c64552014-11-09 13:51:53 +02002874 if (mdev->dev->caps.rx_checksum_flags_port[priv->port] &
2875 MLX4_RX_CSUM_MODE_VAL_NON_TCP_UDP)
2876 priv->flags |= MLX4_EN_FLAG_RX_CSUM_NON_TCP_UDP;
2877
Yan Burman6bbb6d92013-02-07 02:25:20 +00002878 /* Set default MAC */
2879 dev->addr_len = ETH_ALEN;
2880 mlx4_en_u64_to_mac(dev->dev_addr, mdev->dev->caps.def_mac[priv->port]);
2881 if (!is_valid_ether_addr(dev->dev_addr)) {
Jack Morgenstein2b3ddf22015-10-14 17:43:48 +03002882 en_err(priv, "Port: %d, invalid mac burned: %pM, quiting\n",
2883 priv->port, dev->dev_addr);
2884 err = -EINVAL;
2885 goto out;
2886 } else if (mlx4_is_slave(priv->mdev->dev) &&
2887 (priv->mdev->dev->port_random_macs & 1 << priv->port)) {
2888 /* Random MAC was assigned in mlx4_slave_cap
2889 * in mlx4_core module
2890 */
2891 dev->addr_assign_type |= NET_ADDR_RANDOM;
2892 en_warn(priv, "Assigned random MAC address %pM\n", dev->dev_addr);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002893 }
2894
Noa Osherovich2695bab2014-07-08 11:25:24 +03002895 memcpy(priv->current_mac, dev->dev_addr, sizeof(priv->current_mac));
Yan Burman6bbb6d92013-02-07 02:25:20 +00002896
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002897 priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
2898 DS_SIZE * MLX4_EN_MAX_RX_FRAGS);
2899 err = mlx4_en_alloc_resources(priv);
2900 if (err)
2901 goto out;
2902
Amir Vadaiec693d42013-04-23 06:06:49 +00002903 /* Initialize time stamping config */
2904 priv->hwtstamp_config.flags = 0;
2905 priv->hwtstamp_config.tx_type = HWTSTAMP_TX_OFF;
2906 priv->hwtstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
2907
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002908 /* Allocate page for receive rings */
2909 err = mlx4_alloc_hwq_res(mdev->dev, &priv->res,
2910 MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE);
2911 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00002912 en_err(priv, "Failed to allocate page for rx qps\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002913 goto out;
2914 }
2915 priv->allocated = 1;
2916
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002917 /*
2918 * Initialize netdev entry points
2919 */
Rony Efraim8f7ba3c2013-04-25 05:22:27 +00002920 if (mlx4_is_master(priv->mdev->dev))
2921 dev->netdev_ops = &mlx4_netdev_ops_master;
2922 else
2923 dev->netdev_ops = &mlx4_netdev_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002924 dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT;
Ben Hutchings1eb63a22010-09-27 08:29:34 +00002925 netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
2926 netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
Stephen Hemminger3addc562008-11-21 17:30:58 -08002927
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002928 dev->ethtool_ops = &mlx4_en_ethtool_ops;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002929
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002930 /*
2931 * Set driver features
2932 */
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00002933 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
2934 if (mdev->LSO_support)
2935 dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
2936
2937 dev->vlan_features = dev->hw_features;
2938
Yevgeny Petrilinad861072011-10-18 01:51:24 +00002939 dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH;
Michał Mirosławc8c64cf2011-04-15 04:50:49 +00002940 dev->features = dev->hw_features | NETIF_F_HIGHDMA |
Patrick McHardyf6469682013-04-19 02:04:27 +00002941 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
2942 NETIF_F_HW_VLAN_CTAG_FILTER;
Saeed Mahameed537f6f92014-10-27 11:37:43 +02002943 dev->hw_features |= NETIF_F_LOOPBACK |
2944 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002945
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03002946 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN)) {
2947 dev->features |= NETIF_F_HW_VLAN_STAG_RX |
2948 NETIF_F_HW_VLAN_STAG_FILTER;
2949 dev->hw_features |= NETIF_F_HW_VLAN_STAG_RX;
2950 }
2951
2952 if (mlx4_is_slave(mdev->dev)) {
2953 int phv;
2954
2955 err = get_phv_bit(mdev->dev, port, &phv);
2956 if (!err && phv) {
2957 dev->hw_features |= NETIF_F_HW_VLAN_STAG_TX;
2958 priv->pflags |= MLX4_EN_PRIV_FLAGS_PHV;
2959 }
2960 } else {
2961 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PHV_EN &&
2962 !(mdev->dev->caps.flags2 &
2963 MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN))
2964 dev->hw_features |= NETIF_F_HW_VLAN_STAG_TX;
2965 }
2966
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03002967 if (mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_FCS_KEEP)
2968 dev->hw_features |= NETIF_F_RXFCS;
2969
Muhammad Mahajna78500b82015-04-02 16:31:22 +03002970 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_IGNORE_FCS)
2971 dev->hw_features |= NETIF_F_RXALL;
2972
Amir Vadai1eb8c692012-07-18 22:33:52 +00002973 if (mdev->dev->caps.steering_mode ==
Matan Barak7d077cd2014-12-11 10:58:00 +02002974 MLX4_STEERING_MODE_DEVICE_MANAGED &&
2975 mdev->dev->caps.dmfs_high_steer_mode != MLX4_STEERING_DMFS_A0_STATIC)
Amir Vadai1eb8c692012-07-18 22:33:52 +00002976 dev->hw_features |= NETIF_F_NTUPLE;
2977
Yan Burmancc5387f2013-02-07 02:25:26 +00002978 if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_A0)
2979 dev->priv_flags |= IFF_UNICAST_FLT;
2980
Eyal Perry947cbb02014-12-02 18:12:11 +02002981 /* Setting a default hash function value */
2982 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_TOP) {
2983 priv->rss_hash_fn = ETH_RSS_HASH_TOP;
2984 } else if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_XOR) {
2985 priv->rss_hash_fn = ETH_RSS_HASH_XOR;
2986 } else {
2987 en_warn(priv,
2988 "No RSS hash capabilities exposed, using Toeplitz\n");
2989 priv->rss_hash_fn = ETH_RSS_HASH_TOP;
2990 }
2991
Eugenia Emantayev925ab1a2016-02-17 17:24:27 +02002992 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
2993 dev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
2994 dev->features |= NETIF_F_GSO_UDP_TUNNEL;
2995 }
2996
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002997 mdev->pndev[port] = dev;
Moni Shoua5da03542015-02-03 16:48:34 +02002998 mdev->upper[port] = NULL;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002999
3000 netif_carrier_off(dev);
Eugenia Emantayev4801ae72013-06-25 12:09:31 +03003001 mlx4_en_set_default_moderation(priv);
3002
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00003003 en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num);
3004 en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num);
3005
Yan Burman79aeacc2013-02-07 02:25:19 +00003006 mlx4_en_update_loopback_state(priv->dev, priv->dev->features);
3007
Yevgeny Petrilin90822262011-03-22 22:37:41 +00003008 /* Configure port */
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00003009 mlx4_en_calc_rx_buf(dev);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00003010 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
Yevgeny Petrilin5c8e9042012-06-25 00:24:11 +00003011 priv->rx_skb_size + ETH_FCS_LEN,
3012 prof->tx_pause, prof->tx_ppp,
3013 prof->rx_pause, prof->rx_ppp);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00003014 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07003015 en_err(priv, "Failed setting port general configurations for port %d, with error %d\n",
3016 priv->port, err);
Yevgeny Petrilin90822262011-03-22 22:37:41 +00003017 goto out;
3018 }
3019
Or Gerlitz837052d2013-12-23 16:09:44 +02003020 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
Or Gerlitz1b136de2014-03-27 14:02:04 +02003021 err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC, 1);
Or Gerlitz837052d2013-12-23 16:09:44 +02003022 if (err) {
3023 en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n",
3024 err);
3025 goto out;
3026 }
3027 }
3028
Yevgeny Petrilin90822262011-03-22 22:37:41 +00003029 /* Init port */
3030 en_warn(priv, "Initializing port\n");
3031 err = mlx4_INIT_PORT(mdev->dev, priv->port);
3032 if (err) {
3033 en_err(priv, "Failed Initializing port\n");
3034 goto out;
3035 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07003036 queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
Amir Vadaidc8142e2013-04-25 05:22:24 +00003037
Eugenia Emantayev90683062015-12-17 15:35:38 +02003038 /* Initialize time stamp mechanism */
Amir Vadaidc8142e2013-04-25 05:22:24 +00003039 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
Eugenia Emantayev90683062015-12-17 15:35:38 +02003040 mlx4_en_init_timestamp(mdev);
3041
Eugenia Emantayevfc9f5ea2015-12-17 15:35:37 +02003042 queue_delayed_work(mdev->workqueue, &priv->service_task,
3043 SERVICE_TASK_DELAY);
Amir Vadaidc8142e2013-04-25 05:22:24 +00003044
Matan Barak0b131562015-03-30 17:45:25 +03003045 mlx4_en_set_stats_bitmap(mdev->dev, &priv->stats_bitmap,
3046 mdev->profile.prof[priv->port].rx_ppp,
3047 mdev->profile.prof[priv->port].rx_pause,
3048 mdev->profile.prof[priv->port].tx_ppp,
3049 mdev->profile.prof[priv->port].tx_pause);
Eran Ben Elisha39de9612015-03-18 16:51:38 +02003050
Ido Shamaye5eda892015-03-24 15:18:38 +02003051 err = register_netdev(dev);
3052 if (err) {
3053 en_err(priv, "Netdev registration failed for port %d\n", port);
3054 goto out;
3055 }
3056
3057 priv->registered = 1;
Jiri Pirko09d4d082016-02-26 17:32:24 +01003058 devlink_port_type_eth_set(mlx4_get_devlink_port(mdev->dev, priv->port),
3059 dev);
Ido Shamaye5eda892015-03-24 15:18:38 +02003060
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07003061 return 0;
3062
3063out:
3064 mlx4_en_destroy_netdev(dev);
3065 return err;
3066}
3067
Saeed Mahameed537f6f92014-10-27 11:37:43 +02003068int mlx4_en_reset_config(struct net_device *dev,
3069 struct hwtstamp_config ts_config,
3070 netdev_features_t features)
3071{
3072 struct mlx4_en_priv *priv = netdev_priv(dev);
3073 struct mlx4_en_dev *mdev = priv->mdev;
3074 int port_up = 0;
3075 int err = 0;
3076
3077 if (priv->hwtstamp_config.tx_type == ts_config.tx_type &&
3078 priv->hwtstamp_config.rx_filter == ts_config.rx_filter &&
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03003079 !DEV_FEATURE_CHANGED(dev, features, NETIF_F_HW_VLAN_CTAG_RX) &&
3080 !DEV_FEATURE_CHANGED(dev, features, NETIF_F_RXFCS))
Saeed Mahameed537f6f92014-10-27 11:37:43 +02003081 return 0; /* Nothing to change */
3082
3083 if (DEV_FEATURE_CHANGED(dev, features, NETIF_F_HW_VLAN_CTAG_RX) &&
3084 (features & NETIF_F_HW_VLAN_CTAG_RX) &&
3085 (priv->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE)) {
3086 en_warn(priv, "Can't turn ON rx vlan offload while time-stamping rx filter is ON\n");
3087 return -EINVAL;
3088 }
3089
3090 mutex_lock(&mdev->state_lock);
3091 if (priv->port_up) {
3092 port_up = 1;
3093 mlx4_en_stop_port(dev, 1);
3094 }
3095
3096 mlx4_en_free_resources(priv);
3097
3098 en_warn(priv, "Changing device configuration rx filter(%x) rx vlan(%x)\n",
3099 ts_config.rx_filter, !!(features & NETIF_F_HW_VLAN_CTAG_RX));
3100
3101 priv->hwtstamp_config.tx_type = ts_config.tx_type;
3102 priv->hwtstamp_config.rx_filter = ts_config.rx_filter;
3103
3104 if (DEV_FEATURE_CHANGED(dev, features, NETIF_F_HW_VLAN_CTAG_RX)) {
3105 if (features & NETIF_F_HW_VLAN_CTAG_RX)
3106 dev->features |= NETIF_F_HW_VLAN_CTAG_RX;
3107 else
3108 dev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
3109 } else if (ts_config.rx_filter == HWTSTAMP_FILTER_NONE) {
3110 /* RX time-stamping is OFF, update the RX vlan offload
3111 * to the latest wanted state
3112 */
3113 if (dev->wanted_features & NETIF_F_HW_VLAN_CTAG_RX)
3114 dev->features |= NETIF_F_HW_VLAN_CTAG_RX;
3115 else
3116 dev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
3117 }
3118
Muhammad Mahajnaf0df3502015-04-02 16:31:21 +03003119 if (DEV_FEATURE_CHANGED(dev, features, NETIF_F_RXFCS)) {
3120 if (features & NETIF_F_RXFCS)
3121 dev->features |= NETIF_F_RXFCS;
3122 else
3123 dev->features &= ~NETIF_F_RXFCS;
3124 }
3125
Saeed Mahameed537f6f92014-10-27 11:37:43 +02003126 /* RX vlan offload and RX time-stamping can't co-exist !
3127 * Regardless of the caller's choice,
3128 * Turn Off RX vlan offload in case of time-stamping is ON
3129 */
3130 if (ts_config.rx_filter != HWTSTAMP_FILTER_NONE) {
3131 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
3132 en_warn(priv, "Turning off RX vlan offload since RX time-stamping is ON\n");
3133 dev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
3134 }
3135
3136 err = mlx4_en_alloc_resources(priv);
3137 if (err) {
3138 en_err(priv, "Failed reallocating port resources\n");
3139 goto out;
3140 }
3141 if (port_up) {
3142 err = mlx4_en_start_port(dev);
3143 if (err)
3144 en_err(priv, "Failed starting port\n");
3145 }
3146
3147out:
3148 mutex_unlock(&mdev->state_lock);
3149 netdev_features_change(dev);
3150 return err;
3151}