Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1 | /* |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 38 | #include <linux/slab.h> |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 39 | #include <linux/hash.h> |
| 40 | #include <net/ip.h> |
Eliezer Tamir | 076bb0c | 2013-07-10 17:13:17 +0300 | [diff] [blame] | 41 | #include <net/busy_poll.h> |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 42 | #include <net/vxlan.h> |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 43 | |
| 44 | #include <linux/mlx4/driver.h> |
| 45 | #include <linux/mlx4/device.h> |
| 46 | #include <linux/mlx4/cmd.h> |
| 47 | #include <linux/mlx4/cq.h> |
| 48 | |
| 49 | #include "mlx4_en.h" |
| 50 | #include "en_port.h" |
| 51 | |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 52 | int mlx4_en_setup_tc(struct net_device *dev, u8 up) |
Amir Vadai | 897d784 | 2012-04-04 21:33:27 +0000 | [diff] [blame] | 53 | { |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 54 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 55 | int i; |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 56 | unsigned int offset = 0; |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 57 | |
| 58 | if (up && up != MLX4_EN_NUM_UP) |
Amir Vadai | 897d784 | 2012-04-04 21:33:27 +0000 | [diff] [blame] | 59 | return -EINVAL; |
| 60 | |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 61 | netdev_set_num_tc(dev, up); |
| 62 | |
| 63 | /* Partition Tx queues evenly amongst UP's */ |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 64 | for (i = 0; i < up; i++) { |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 65 | netdev_set_tc_queue(dev, i, priv->num_tx_rings_p_up, offset); |
| 66 | offset += priv->num_tx_rings_p_up; |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Amir Vadai | 897d784 | 2012-04-04 21:33:27 +0000 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 72 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 73 | /* must be called with local_bh_disable()d */ |
| 74 | static int mlx4_en_low_latency_recv(struct napi_struct *napi) |
| 75 | { |
| 76 | struct mlx4_en_cq *cq = container_of(napi, struct mlx4_en_cq, napi); |
| 77 | struct net_device *dev = cq->dev; |
| 78 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 79 | struct mlx4_en_rx_ring *rx_ring = priv->rx_ring[cq->ring]; |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 80 | int done; |
| 81 | |
| 82 | if (!priv->port_up) |
| 83 | return LL_FLUSH_FAILED; |
| 84 | |
| 85 | if (!mlx4_en_cq_lock_poll(cq)) |
| 86 | return LL_FLUSH_BUSY; |
| 87 | |
| 88 | done = mlx4_en_process_rx_cq(dev, cq, 4); |
Amir Vadai | 8501841 | 2013-06-18 16:18:28 +0300 | [diff] [blame] | 89 | if (likely(done)) |
| 90 | rx_ring->cleaned += done; |
| 91 | else |
| 92 | rx_ring->misses++; |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 93 | |
| 94 | mlx4_en_cq_unlock_poll(cq); |
| 95 | |
| 96 | return done; |
| 97 | } |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 98 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 99 | |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 100 | #ifdef CONFIG_RFS_ACCEL |
| 101 | |
| 102 | struct mlx4_en_filter { |
| 103 | struct list_head next; |
| 104 | struct work_struct work; |
| 105 | |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 106 | u8 ip_proto; |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 107 | __be32 src_ip; |
| 108 | __be32 dst_ip; |
| 109 | __be16 src_port; |
| 110 | __be16 dst_port; |
| 111 | |
| 112 | int rxq_index; |
| 113 | struct mlx4_en_priv *priv; |
| 114 | u32 flow_id; /* RFS infrastructure id */ |
| 115 | int id; /* mlx4_en driver id */ |
| 116 | u64 reg_id; /* Flow steering API id */ |
| 117 | u8 activated; /* Used to prevent expiry before filter |
| 118 | * is attached |
| 119 | */ |
| 120 | struct hlist_node filter_chain; |
| 121 | }; |
| 122 | |
| 123 | static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv); |
| 124 | |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 125 | static enum mlx4_net_trans_rule_id mlx4_ip_proto_to_trans_rule_id(u8 ip_proto) |
| 126 | { |
| 127 | switch (ip_proto) { |
| 128 | case IPPROTO_UDP: |
| 129 | return MLX4_NET_TRANS_RULE_ID_UDP; |
| 130 | case IPPROTO_TCP: |
| 131 | return MLX4_NET_TRANS_RULE_ID_TCP; |
| 132 | default: |
Eyal Perry | c3ca520 | 2014-05-14 12:15:16 +0300 | [diff] [blame] | 133 | return MLX4_NET_TRANS_RULE_NUM; |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 134 | } |
| 135 | }; |
| 136 | |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 137 | static void mlx4_en_filter_work(struct work_struct *work) |
| 138 | { |
| 139 | struct mlx4_en_filter *filter = container_of(work, |
| 140 | struct mlx4_en_filter, |
| 141 | work); |
| 142 | struct mlx4_en_priv *priv = filter->priv; |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 143 | struct mlx4_spec_list spec_tcp_udp = { |
| 144 | .id = mlx4_ip_proto_to_trans_rule_id(filter->ip_proto), |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 145 | { |
| 146 | .tcp_udp = { |
| 147 | .dst_port = filter->dst_port, |
| 148 | .dst_port_msk = (__force __be16)-1, |
| 149 | .src_port = filter->src_port, |
| 150 | .src_port_msk = (__force __be16)-1, |
| 151 | }, |
| 152 | }, |
| 153 | }; |
| 154 | struct mlx4_spec_list spec_ip = { |
| 155 | .id = MLX4_NET_TRANS_RULE_ID_IPV4, |
| 156 | { |
| 157 | .ipv4 = { |
| 158 | .dst_ip = filter->dst_ip, |
| 159 | .dst_ip_msk = (__force __be32)-1, |
| 160 | .src_ip = filter->src_ip, |
| 161 | .src_ip_msk = (__force __be32)-1, |
| 162 | }, |
| 163 | }, |
| 164 | }; |
| 165 | struct mlx4_spec_list spec_eth = { |
| 166 | .id = MLX4_NET_TRANS_RULE_ID_ETH, |
| 167 | }; |
| 168 | struct mlx4_net_trans_rule rule = { |
| 169 | .list = LIST_HEAD_INIT(rule.list), |
| 170 | .queue_mode = MLX4_NET_TRANS_Q_LIFO, |
| 171 | .exclusive = 1, |
| 172 | .allow_loopback = 1, |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 173 | .promisc_mode = MLX4_FS_REGULAR, |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 174 | .port = priv->port, |
| 175 | .priority = MLX4_DOMAIN_RFS, |
| 176 | }; |
| 177 | int rc; |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 178 | __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16); |
| 179 | |
Eyal Perry | c3ca520 | 2014-05-14 12:15:16 +0300 | [diff] [blame] | 180 | if (spec_tcp_udp.id >= MLX4_NET_TRANS_RULE_NUM) { |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 181 | en_warn(priv, "RFS: ignoring unsupported ip protocol (%d)\n", |
| 182 | filter->ip_proto); |
| 183 | goto ignore; |
| 184 | } |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 185 | list_add_tail(&spec_eth.list, &rule.list); |
| 186 | list_add_tail(&spec_ip.list, &rule.list); |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 187 | list_add_tail(&spec_tcp_udp.list, &rule.list); |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 188 | |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 189 | rule.qpn = priv->rss_map.qps[filter->rxq_index].qpn; |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame] | 190 | memcpy(spec_eth.eth.dst_mac, priv->dev->dev_addr, ETH_ALEN); |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 191 | memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN); |
| 192 | |
| 193 | filter->activated = 0; |
| 194 | |
| 195 | if (filter->reg_id) { |
| 196 | rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id); |
| 197 | if (rc && rc != -ENOENT) |
| 198 | en_err(priv, "Error detaching flow. rc = %d\n", rc); |
| 199 | } |
| 200 | |
| 201 | rc = mlx4_flow_attach(priv->mdev->dev, &rule, &filter->reg_id); |
| 202 | if (rc) |
| 203 | en_err(priv, "Error attaching flow. err = %d\n", rc); |
| 204 | |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 205 | ignore: |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 206 | mlx4_en_filter_rfs_expire(priv); |
| 207 | |
| 208 | filter->activated = 1; |
| 209 | } |
| 210 | |
| 211 | static inline struct hlist_head * |
| 212 | filter_hash_bucket(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip, |
| 213 | __be16 src_port, __be16 dst_port) |
| 214 | { |
| 215 | unsigned long l; |
| 216 | int bucket_idx; |
| 217 | |
| 218 | l = (__force unsigned long)src_port | |
| 219 | ((__force unsigned long)dst_port << 2); |
| 220 | l ^= (__force unsigned long)(src_ip ^ dst_ip); |
| 221 | |
| 222 | bucket_idx = hash_long(l, MLX4_EN_FILTER_HASH_SHIFT); |
| 223 | |
| 224 | return &priv->filter_hash[bucket_idx]; |
| 225 | } |
| 226 | |
| 227 | static struct mlx4_en_filter * |
| 228 | mlx4_en_filter_alloc(struct mlx4_en_priv *priv, int rxq_index, __be32 src_ip, |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 229 | __be32 dst_ip, u8 ip_proto, __be16 src_port, |
| 230 | __be16 dst_port, u32 flow_id) |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 231 | { |
| 232 | struct mlx4_en_filter *filter = NULL; |
| 233 | |
| 234 | filter = kzalloc(sizeof(struct mlx4_en_filter), GFP_ATOMIC); |
| 235 | if (!filter) |
| 236 | return NULL; |
| 237 | |
| 238 | filter->priv = priv; |
| 239 | filter->rxq_index = rxq_index; |
| 240 | INIT_WORK(&filter->work, mlx4_en_filter_work); |
| 241 | |
| 242 | filter->src_ip = src_ip; |
| 243 | filter->dst_ip = dst_ip; |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 244 | filter->ip_proto = ip_proto; |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 245 | filter->src_port = src_port; |
| 246 | filter->dst_port = dst_port; |
| 247 | |
| 248 | filter->flow_id = flow_id; |
| 249 | |
Amir Vadai | ee64c0e | 2012-07-25 21:21:16 +0000 | [diff] [blame] | 250 | filter->id = priv->last_filter_id++ % RPS_NO_FILTER; |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 251 | |
| 252 | list_add_tail(&filter->next, &priv->filters); |
| 253 | hlist_add_head(&filter->filter_chain, |
| 254 | filter_hash_bucket(priv, src_ip, dst_ip, src_port, |
| 255 | dst_port)); |
| 256 | |
| 257 | return filter; |
| 258 | } |
| 259 | |
| 260 | static void mlx4_en_filter_free(struct mlx4_en_filter *filter) |
| 261 | { |
| 262 | struct mlx4_en_priv *priv = filter->priv; |
| 263 | int rc; |
| 264 | |
| 265 | list_del(&filter->next); |
| 266 | |
| 267 | rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id); |
| 268 | if (rc && rc != -ENOENT) |
| 269 | en_err(priv, "Error detaching flow. rc = %d\n", rc); |
| 270 | |
| 271 | kfree(filter); |
| 272 | } |
| 273 | |
| 274 | static inline struct mlx4_en_filter * |
| 275 | mlx4_en_filter_find(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip, |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 276 | u8 ip_proto, __be16 src_port, __be16 dst_port) |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 277 | { |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 278 | struct mlx4_en_filter *filter; |
| 279 | struct mlx4_en_filter *ret = NULL; |
| 280 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 281 | hlist_for_each_entry(filter, |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 282 | filter_hash_bucket(priv, src_ip, dst_ip, |
| 283 | src_port, dst_port), |
| 284 | filter_chain) { |
| 285 | if (filter->src_ip == src_ip && |
| 286 | filter->dst_ip == dst_ip && |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 287 | filter->ip_proto == ip_proto && |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 288 | filter->src_port == src_port && |
| 289 | filter->dst_port == dst_port) { |
| 290 | ret = filter; |
| 291 | break; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | return ret; |
| 296 | } |
| 297 | |
| 298 | static int |
| 299 | mlx4_en_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb, |
| 300 | u16 rxq_index, u32 flow_id) |
| 301 | { |
| 302 | struct mlx4_en_priv *priv = netdev_priv(net_dev); |
| 303 | struct mlx4_en_filter *filter; |
| 304 | const struct iphdr *ip; |
| 305 | const __be16 *ports; |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 306 | u8 ip_proto; |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 307 | __be32 src_ip; |
| 308 | __be32 dst_ip; |
| 309 | __be16 src_port; |
| 310 | __be16 dst_port; |
| 311 | int nhoff = skb_network_offset(skb); |
| 312 | int ret = 0; |
| 313 | |
| 314 | if (skb->protocol != htons(ETH_P_IP)) |
| 315 | return -EPROTONOSUPPORT; |
| 316 | |
| 317 | ip = (const struct iphdr *)(skb->data + nhoff); |
| 318 | if (ip_is_fragment(ip)) |
| 319 | return -EPROTONOSUPPORT; |
| 320 | |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 321 | if ((ip->protocol != IPPROTO_TCP) && (ip->protocol != IPPROTO_UDP)) |
| 322 | return -EPROTONOSUPPORT; |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 323 | ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl); |
| 324 | |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 325 | ip_proto = ip->protocol; |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 326 | src_ip = ip->saddr; |
| 327 | dst_ip = ip->daddr; |
| 328 | src_port = ports[0]; |
| 329 | dst_port = ports[1]; |
| 330 | |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 331 | spin_lock_bh(&priv->filters_lock); |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 332 | filter = mlx4_en_filter_find(priv, src_ip, dst_ip, ip_proto, |
| 333 | src_port, dst_port); |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 334 | if (filter) { |
| 335 | if (filter->rxq_index == rxq_index) |
| 336 | goto out; |
| 337 | |
| 338 | filter->rxq_index = rxq_index; |
| 339 | } else { |
| 340 | filter = mlx4_en_filter_alloc(priv, rxq_index, |
Eyal Perry | 75a353d | 2013-11-07 12:19:49 +0200 | [diff] [blame] | 341 | src_ip, dst_ip, ip_proto, |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 342 | src_port, dst_port, flow_id); |
| 343 | if (!filter) { |
| 344 | ret = -ENOMEM; |
| 345 | goto err; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | queue_work(priv->mdev->workqueue, &filter->work); |
| 350 | |
| 351 | out: |
| 352 | ret = filter->id; |
| 353 | err: |
| 354 | spin_unlock_bh(&priv->filters_lock); |
| 355 | |
| 356 | return ret; |
| 357 | } |
| 358 | |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 359 | void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv) |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 360 | { |
| 361 | struct mlx4_en_filter *filter, *tmp; |
| 362 | LIST_HEAD(del_list); |
| 363 | |
| 364 | spin_lock_bh(&priv->filters_lock); |
| 365 | list_for_each_entry_safe(filter, tmp, &priv->filters, next) { |
| 366 | list_move(&filter->next, &del_list); |
| 367 | hlist_del(&filter->filter_chain); |
| 368 | } |
| 369 | spin_unlock_bh(&priv->filters_lock); |
| 370 | |
| 371 | list_for_each_entry_safe(filter, tmp, &del_list, next) { |
| 372 | cancel_work_sync(&filter->work); |
| 373 | mlx4_en_filter_free(filter); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv) |
| 378 | { |
| 379 | struct mlx4_en_filter *filter = NULL, *tmp, *last_filter = NULL; |
| 380 | LIST_HEAD(del_list); |
| 381 | int i = 0; |
| 382 | |
| 383 | spin_lock_bh(&priv->filters_lock); |
| 384 | list_for_each_entry_safe(filter, tmp, &priv->filters, next) { |
| 385 | if (i > MLX4_EN_FILTER_EXPIRY_QUOTA) |
| 386 | break; |
| 387 | |
| 388 | if (filter->activated && |
| 389 | !work_pending(&filter->work) && |
| 390 | rps_may_expire_flow(priv->dev, |
| 391 | filter->rxq_index, filter->flow_id, |
| 392 | filter->id)) { |
| 393 | list_move(&filter->next, &del_list); |
| 394 | hlist_del(&filter->filter_chain); |
| 395 | } else |
| 396 | last_filter = filter; |
| 397 | |
| 398 | i++; |
| 399 | } |
| 400 | |
| 401 | if (last_filter && (&last_filter->next != priv->filters.next)) |
| 402 | list_move(&priv->filters, &last_filter->next); |
| 403 | |
| 404 | spin_unlock_bh(&priv->filters_lock); |
| 405 | |
| 406 | list_for_each_entry_safe(filter, tmp, &del_list, next) |
| 407 | mlx4_en_filter_free(filter); |
| 408 | } |
| 409 | #endif |
| 410 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 411 | static int mlx4_en_vlan_rx_add_vid(struct net_device *dev, |
| 412 | __be16 proto, u16 vid) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 413 | { |
| 414 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 415 | struct mlx4_en_dev *mdev = priv->mdev; |
| 416 | int err; |
Eli Cohen | 4c3eb3c | 2010-08-26 17:19:22 +0300 | [diff] [blame] | 417 | int idx; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 418 | |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 419 | en_dbg(HW, priv, "adding VLAN:%d\n", vid); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 420 | |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 421 | set_bit(vid, priv->active_vlans); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 422 | |
| 423 | /* Add VID to port VLAN filter */ |
| 424 | mutex_lock(&mdev->state_lock); |
| 425 | if (mdev->device_up && priv->port_up) { |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 426 | err = mlx4_SET_VLAN_FLTR(mdev->dev, priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 427 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 428 | en_err(priv, "Failed configuring VLAN filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 429 | } |
Eli Cohen | 4c3eb3c | 2010-08-26 17:19:22 +0300 | [diff] [blame] | 430 | if (mlx4_register_vlan(mdev->dev, priv->port, vid, &idx)) |
Eugenia Emantayev | 9e19b54 | 2013-06-25 12:09:32 +0300 | [diff] [blame] | 431 | en_dbg(HW, priv, "failed adding vlan %d\n", vid); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 432 | mutex_unlock(&mdev->state_lock); |
Eli Cohen | 4c3eb3c | 2010-08-26 17:19:22 +0300 | [diff] [blame] | 433 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 434 | return 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 437 | static int mlx4_en_vlan_rx_kill_vid(struct net_device *dev, |
| 438 | __be16 proto, u16 vid) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 439 | { |
| 440 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 441 | struct mlx4_en_dev *mdev = priv->mdev; |
| 442 | int err; |
| 443 | |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 444 | en_dbg(HW, priv, "Killing VID:%d\n", vid); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 445 | |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 446 | clear_bit(vid, priv->active_vlans); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 447 | |
| 448 | /* Remove VID from port VLAN filter */ |
| 449 | mutex_lock(&mdev->state_lock); |
Jack Morgenstein | 2009d00 | 2013-11-03 10:03:19 +0200 | [diff] [blame] | 450 | mlx4_unregister_vlan(mdev->dev, priv->port, vid); |
Eli Cohen | 4c3eb3c | 2010-08-26 17:19:22 +0300 | [diff] [blame] | 451 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 452 | if (mdev->device_up && priv->port_up) { |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 453 | err = mlx4_SET_VLAN_FLTR(mdev->dev, priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 454 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 455 | en_err(priv, "Failed configuring VLAN filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 456 | } |
| 457 | mutex_unlock(&mdev->state_lock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 458 | |
| 459 | return 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame] | 462 | static void mlx4_en_u64_to_mac(unsigned char dst_mac[ETH_ALEN + 2], u64 src_mac) |
| 463 | { |
Yan Burman | bab6a9e | 2013-04-02 16:49:45 +0300 | [diff] [blame] | 464 | int i; |
| 465 | for (i = ETH_ALEN - 1; i >= 0; --i) { |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame] | 466 | dst_mac[i] = src_mac & 0xff; |
| 467 | src_mac >>= 8; |
| 468 | } |
| 469 | memset(&dst_mac[ETH_ALEN], 0, 2); |
| 470 | } |
| 471 | |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 472 | |
| 473 | static int mlx4_en_tunnel_steer_add(struct mlx4_en_priv *priv, unsigned char *addr, |
| 474 | int qpn, u64 *reg_id) |
| 475 | { |
| 476 | int err; |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 477 | |
Or Gerlitz | 5eff6da | 2015-01-15 15:28:54 +0200 | [diff] [blame] | 478 | if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN || |
| 479 | priv->mdev->dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_STATIC) |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 480 | return 0; /* do nothing */ |
| 481 | |
Or Gerlitz | b95089d | 2014-08-27 16:47:48 +0300 | [diff] [blame] | 482 | err = mlx4_tunnel_steer_add(priv->mdev->dev, addr, priv->port, qpn, |
| 483 | MLX4_DOMAIN_NIC, reg_id); |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 484 | if (err) { |
| 485 | en_err(priv, "failed to add vxlan steering rule, err %d\n", err); |
| 486 | return err; |
| 487 | } |
| 488 | en_dbg(DRV, priv, "added vxlan steering rule, mac %pM reg_id %llx\n", addr, *reg_id); |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 493 | static int mlx4_en_uc_steer_add(struct mlx4_en_priv *priv, |
| 494 | unsigned char *mac, int *qpn, u64 *reg_id) |
| 495 | { |
| 496 | struct mlx4_en_dev *mdev = priv->mdev; |
| 497 | struct mlx4_dev *dev = mdev->dev; |
| 498 | int err; |
| 499 | |
| 500 | switch (dev->caps.steering_mode) { |
| 501 | case MLX4_STEERING_MODE_B0: { |
| 502 | struct mlx4_qp qp; |
| 503 | u8 gid[16] = {0}; |
| 504 | |
| 505 | qp.qpn = *qpn; |
| 506 | memcpy(&gid[10], mac, ETH_ALEN); |
| 507 | gid[5] = priv->port; |
| 508 | |
| 509 | err = mlx4_unicast_attach(dev, &qp, gid, 0, MLX4_PROT_ETH); |
| 510 | break; |
| 511 | } |
| 512 | case MLX4_STEERING_MODE_DEVICE_MANAGED: { |
| 513 | struct mlx4_spec_list spec_eth = { {NULL} }; |
| 514 | __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16); |
| 515 | |
| 516 | struct mlx4_net_trans_rule rule = { |
| 517 | .queue_mode = MLX4_NET_TRANS_Q_FIFO, |
| 518 | .exclusive = 0, |
| 519 | .allow_loopback = 1, |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 520 | .promisc_mode = MLX4_FS_REGULAR, |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 521 | .priority = MLX4_DOMAIN_NIC, |
| 522 | }; |
| 523 | |
| 524 | rule.port = priv->port; |
| 525 | rule.qpn = *qpn; |
| 526 | INIT_LIST_HEAD(&rule.list); |
| 527 | |
| 528 | spec_eth.id = MLX4_NET_TRANS_RULE_ID_ETH; |
| 529 | memcpy(spec_eth.eth.dst_mac, mac, ETH_ALEN); |
| 530 | memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN); |
| 531 | list_add_tail(&spec_eth.list, &rule.list); |
| 532 | |
| 533 | err = mlx4_flow_attach(dev, &rule, reg_id); |
| 534 | break; |
| 535 | } |
| 536 | default: |
| 537 | return -EINVAL; |
| 538 | } |
| 539 | if (err) |
| 540 | en_warn(priv, "Failed Attaching Unicast\n"); |
| 541 | |
| 542 | return err; |
| 543 | } |
| 544 | |
| 545 | static void mlx4_en_uc_steer_release(struct mlx4_en_priv *priv, |
| 546 | unsigned char *mac, int qpn, u64 reg_id) |
| 547 | { |
| 548 | struct mlx4_en_dev *mdev = priv->mdev; |
| 549 | struct mlx4_dev *dev = mdev->dev; |
| 550 | |
| 551 | switch (dev->caps.steering_mode) { |
| 552 | case MLX4_STEERING_MODE_B0: { |
| 553 | struct mlx4_qp qp; |
| 554 | u8 gid[16] = {0}; |
| 555 | |
| 556 | qp.qpn = qpn; |
| 557 | memcpy(&gid[10], mac, ETH_ALEN); |
| 558 | gid[5] = priv->port; |
| 559 | |
| 560 | mlx4_unicast_detach(dev, &qp, gid, MLX4_PROT_ETH); |
| 561 | break; |
| 562 | } |
| 563 | case MLX4_STEERING_MODE_DEVICE_MANAGED: { |
| 564 | mlx4_flow_detach(dev, reg_id); |
| 565 | break; |
| 566 | } |
| 567 | default: |
| 568 | en_err(priv, "Invalid steering mode.\n"); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | static int mlx4_en_get_qp(struct mlx4_en_priv *priv) |
| 573 | { |
| 574 | struct mlx4_en_dev *mdev = priv->mdev; |
| 575 | struct mlx4_dev *dev = mdev->dev; |
| 576 | struct mlx4_mac_entry *entry; |
| 577 | int index = 0; |
| 578 | int err = 0; |
Jack Morgenstein | c2a3d4b | 2014-10-27 11:37:44 +0200 | [diff] [blame] | 579 | u64 reg_id = 0; |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 580 | int *qpn = &priv->base_qpn; |
Eugenia Emantayev | 9813337 | 2014-03-02 10:25:01 +0200 | [diff] [blame] | 581 | u64 mac = mlx4_mac_to_u64(priv->dev->dev_addr); |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 582 | |
| 583 | en_dbg(DRV, priv, "Registering MAC: %pM for adding\n", |
| 584 | priv->dev->dev_addr); |
| 585 | index = mlx4_register_mac(dev, priv->port, mac); |
| 586 | if (index < 0) { |
| 587 | err = index; |
| 588 | en_err(priv, "Failed adding MAC: %pM\n", |
| 589 | priv->dev->dev_addr); |
| 590 | return err; |
| 591 | } |
| 592 | |
| 593 | if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) { |
| 594 | int base_qpn = mlx4_get_base_qpn(dev, priv->port); |
| 595 | *qpn = base_qpn + index; |
| 596 | return 0; |
| 597 | } |
| 598 | |
Matan Barak | d57febe | 2014-12-11 10:57:57 +0200 | [diff] [blame] | 599 | err = mlx4_qp_reserve_range(dev, 1, 1, qpn, MLX4_RESERVE_A0_QP); |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 600 | en_dbg(DRV, priv, "Reserved qp %d\n", *qpn); |
| 601 | if (err) { |
| 602 | en_err(priv, "Failed to reserve qp for mac registration\n"); |
| 603 | goto qp_err; |
| 604 | } |
| 605 | |
| 606 | err = mlx4_en_uc_steer_add(priv, priv->dev->dev_addr, qpn, ®_id); |
| 607 | if (err) |
| 608 | goto steer_err; |
| 609 | |
Wei Yongjun | 9ba75fb | 2014-01-07 16:56:07 +0800 | [diff] [blame] | 610 | err = mlx4_en_tunnel_steer_add(priv, priv->dev->dev_addr, *qpn, |
| 611 | &priv->tunnel_reg_id); |
| 612 | if (err) |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 613 | goto tunnel_err; |
| 614 | |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 615 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); |
| 616 | if (!entry) { |
| 617 | err = -ENOMEM; |
| 618 | goto alloc_err; |
| 619 | } |
| 620 | memcpy(entry->mac, priv->dev->dev_addr, sizeof(entry->mac)); |
Eyal Perry | b94901f | 2014-07-22 15:44:09 +0300 | [diff] [blame] | 621 | memcpy(priv->current_mac, entry->mac, sizeof(priv->current_mac)); |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 622 | entry->reg_id = reg_id; |
| 623 | |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 624 | hlist_add_head_rcu(&entry->hlist, |
| 625 | &priv->mac_hash[entry->mac[MLX4_EN_MAC_HASH_IDX]]); |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 626 | |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 627 | return 0; |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 628 | |
| 629 | alloc_err: |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 630 | if (priv->tunnel_reg_id) |
| 631 | mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id); |
| 632 | tunnel_err: |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 633 | mlx4_en_uc_steer_release(priv, priv->dev->dev_addr, *qpn, reg_id); |
| 634 | |
| 635 | steer_err: |
| 636 | mlx4_qp_release_range(dev, *qpn, 1); |
| 637 | |
| 638 | qp_err: |
| 639 | mlx4_unregister_mac(dev, priv->port, mac); |
| 640 | return err; |
| 641 | } |
| 642 | |
| 643 | static void mlx4_en_put_qp(struct mlx4_en_priv *priv) |
| 644 | { |
| 645 | struct mlx4_en_dev *mdev = priv->mdev; |
| 646 | struct mlx4_dev *dev = mdev->dev; |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 647 | int qpn = priv->base_qpn; |
Yan Burman | 83a5a6c | 2013-03-07 03:46:56 +0000 | [diff] [blame] | 648 | u64 mac; |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 649 | |
Yan Burman | 83a5a6c | 2013-03-07 03:46:56 +0000 | [diff] [blame] | 650 | if (dev->caps.steering_mode == MLX4_STEERING_MODE_A0) { |
Eugenia Emantayev | 9813337 | 2014-03-02 10:25:01 +0200 | [diff] [blame] | 651 | mac = mlx4_mac_to_u64(priv->dev->dev_addr); |
Yan Burman | 83a5a6c | 2013-03-07 03:46:56 +0000 | [diff] [blame] | 652 | en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n", |
| 653 | priv->dev->dev_addr); |
| 654 | mlx4_unregister_mac(dev, priv->port, mac); |
| 655 | } else { |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 656 | struct mlx4_mac_entry *entry; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 657 | struct hlist_node *tmp; |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 658 | struct hlist_head *bucket; |
Yan Burman | 83a5a6c | 2013-03-07 03:46:56 +0000 | [diff] [blame] | 659 | unsigned int i; |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 660 | |
Yan Burman | 83a5a6c | 2013-03-07 03:46:56 +0000 | [diff] [blame] | 661 | for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) { |
| 662 | bucket = &priv->mac_hash[i]; |
| 663 | hlist_for_each_entry_safe(entry, tmp, bucket, hlist) { |
Eugenia Emantayev | 9813337 | 2014-03-02 10:25:01 +0200 | [diff] [blame] | 664 | mac = mlx4_mac_to_u64(entry->mac); |
Yan Burman | 83a5a6c | 2013-03-07 03:46:56 +0000 | [diff] [blame] | 665 | en_dbg(DRV, priv, "Registering MAC: %pM for deleting\n", |
| 666 | entry->mac); |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 667 | mlx4_en_uc_steer_release(priv, entry->mac, |
| 668 | qpn, entry->reg_id); |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 669 | |
Yan Burman | 83a5a6c | 2013-03-07 03:46:56 +0000 | [diff] [blame] | 670 | mlx4_unregister_mac(dev, priv->port, mac); |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 671 | hlist_del_rcu(&entry->hlist); |
| 672 | kfree_rcu(entry, rcu); |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 673 | } |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 674 | } |
Yan Burman | 83a5a6c | 2013-03-07 03:46:56 +0000 | [diff] [blame] | 675 | |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 676 | if (priv->tunnel_reg_id) { |
| 677 | mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id); |
| 678 | priv->tunnel_reg_id = 0; |
| 679 | } |
| 680 | |
Yan Burman | 83a5a6c | 2013-03-07 03:46:56 +0000 | [diff] [blame] | 681 | en_dbg(DRV, priv, "Releasing qp: port %d, qpn %d\n", |
| 682 | priv->port, qpn); |
| 683 | mlx4_qp_release_range(dev, qpn, 1); |
| 684 | priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC; |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
| 688 | static int mlx4_en_replace_mac(struct mlx4_en_priv *priv, int qpn, |
Yan Burman | 90bbb74 | 2013-02-07 02:25:24 +0000 | [diff] [blame] | 689 | unsigned char *new_mac, unsigned char *prev_mac) |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 690 | { |
| 691 | struct mlx4_en_dev *mdev = priv->mdev; |
| 692 | struct mlx4_dev *dev = mdev->dev; |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 693 | int err = 0; |
Eugenia Emantayev | 9813337 | 2014-03-02 10:25:01 +0200 | [diff] [blame] | 694 | u64 new_mac_u64 = mlx4_mac_to_u64(new_mac); |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 695 | |
| 696 | if (dev->caps.steering_mode != MLX4_STEERING_MODE_A0) { |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 697 | struct hlist_head *bucket; |
| 698 | unsigned int mac_hash; |
| 699 | struct mlx4_mac_entry *entry; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 700 | struct hlist_node *tmp; |
Eugenia Emantayev | 9813337 | 2014-03-02 10:25:01 +0200 | [diff] [blame] | 701 | u64 prev_mac_u64 = mlx4_mac_to_u64(prev_mac); |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 702 | |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 703 | bucket = &priv->mac_hash[prev_mac[MLX4_EN_MAC_HASH_IDX]]; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 704 | hlist_for_each_entry_safe(entry, tmp, bucket, hlist) { |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 705 | if (ether_addr_equal_64bits(entry->mac, prev_mac)) { |
| 706 | mlx4_en_uc_steer_release(priv, entry->mac, |
| 707 | qpn, entry->reg_id); |
| 708 | mlx4_unregister_mac(dev, priv->port, |
| 709 | prev_mac_u64); |
| 710 | hlist_del_rcu(&entry->hlist); |
| 711 | synchronize_rcu(); |
| 712 | memcpy(entry->mac, new_mac, ETH_ALEN); |
| 713 | entry->reg_id = 0; |
| 714 | mac_hash = new_mac[MLX4_EN_MAC_HASH_IDX]; |
| 715 | hlist_add_head_rcu(&entry->hlist, |
| 716 | &priv->mac_hash[mac_hash]); |
| 717 | mlx4_register_mac(dev, priv->port, new_mac_u64); |
| 718 | err = mlx4_en_uc_steer_add(priv, new_mac, |
| 719 | &qpn, |
| 720 | &entry->reg_id); |
Or Gerlitz | 2a2083f | 2014-03-12 17:16:31 +0200 | [diff] [blame] | 721 | if (err) |
| 722 | return err; |
| 723 | if (priv->tunnel_reg_id) { |
| 724 | mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id); |
| 725 | priv->tunnel_reg_id = 0; |
| 726 | } |
| 727 | err = mlx4_en_tunnel_steer_add(priv, new_mac, qpn, |
| 728 | &priv->tunnel_reg_id); |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 729 | return err; |
| 730 | } |
| 731 | } |
| 732 | return -EINVAL; |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | return __mlx4_replace_mac(dev, priv->port, qpn, new_mac_u64); |
| 736 | } |
| 737 | |
Noa Osherovich | 2695bab | 2014-07-08 11:25:24 +0300 | [diff] [blame] | 738 | static int mlx4_en_do_set_mac(struct mlx4_en_priv *priv, |
| 739 | unsigned char new_mac[ETH_ALEN + 2]) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 740 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 741 | int err = 0; |
| 742 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 743 | if (priv->port_up) { |
| 744 | /* Remove old MAC and insert the new one */ |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 745 | err = mlx4_en_replace_mac(priv, priv->base_qpn, |
Noa Osherovich | 2695bab | 2014-07-08 11:25:24 +0300 | [diff] [blame] | 746 | new_mac, priv->current_mac); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 747 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 748 | en_err(priv, "Failed changing HW MAC address\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 749 | } else |
Yan Burman | 48e551f | 2013-02-07 02:25:21 +0000 | [diff] [blame] | 750 | en_dbg(HW, priv, "Port is down while registering mac, exiting...\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 751 | |
Noa Osherovich | 2695bab | 2014-07-08 11:25:24 +0300 | [diff] [blame] | 752 | if (!err) |
| 753 | memcpy(priv->current_mac, new_mac, sizeof(priv->current_mac)); |
Shani Michaelli | ee75532 | 2014-05-14 12:15:12 +0300 | [diff] [blame] | 754 | |
Yan Burman | bfa8ab4 | 2013-03-07 03:46:55 +0000 | [diff] [blame] | 755 | return err; |
| 756 | } |
| 757 | |
| 758 | static int mlx4_en_set_mac(struct net_device *dev, void *addr) |
| 759 | { |
| 760 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 761 | struct mlx4_en_dev *mdev = priv->mdev; |
| 762 | struct sockaddr *saddr = addr; |
Noa Osherovich | 2695bab | 2014-07-08 11:25:24 +0300 | [diff] [blame] | 763 | unsigned char new_mac[ETH_ALEN + 2]; |
Yan Burman | bfa8ab4 | 2013-03-07 03:46:55 +0000 | [diff] [blame] | 764 | int err; |
| 765 | |
| 766 | if (!is_valid_ether_addr(saddr->sa_data)) |
| 767 | return -EADDRNOTAVAIL; |
| 768 | |
Yan Burman | bfa8ab4 | 2013-03-07 03:46:55 +0000 | [diff] [blame] | 769 | mutex_lock(&mdev->state_lock); |
Noa Osherovich | 2695bab | 2014-07-08 11:25:24 +0300 | [diff] [blame] | 770 | memcpy(new_mac, saddr->sa_data, ETH_ALEN); |
| 771 | err = mlx4_en_do_set_mac(priv, new_mac); |
| 772 | if (!err) |
| 773 | memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 774 | mutex_unlock(&mdev->state_lock); |
Yan Burman | bfa8ab4 | 2013-03-07 03:46:55 +0000 | [diff] [blame] | 775 | |
| 776 | return err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | static void mlx4_en_clear_list(struct net_device *dev) |
| 780 | { |
| 781 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 782 | struct mlx4_en_mc_list *tmp, *mc_to_del; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 783 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 784 | list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) { |
| 785 | list_del(&mc_to_del->list); |
| 786 | kfree(mc_to_del); |
| 787 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | static void mlx4_en_cache_mclist(struct net_device *dev) |
| 791 | { |
| 792 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 793 | struct netdev_hw_addr *ha; |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 794 | struct mlx4_en_mc_list *tmp; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 795 | |
Alexander Guller | 0e03567 | 2011-12-19 04:02:58 +0000 | [diff] [blame] | 796 | mlx4_en_clear_list(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 797 | netdev_for_each_mc_addr(ha, dev) { |
| 798 | tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC); |
| 799 | if (!tmp) { |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 800 | mlx4_en_clear_list(dev); |
| 801 | return; |
| 802 | } |
| 803 | memcpy(tmp->addr, ha->addr, ETH_ALEN); |
| 804 | list_add_tail(&tmp->list, &priv->mc_list); |
| 805 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 808 | static void update_mclist_flags(struct mlx4_en_priv *priv, |
| 809 | struct list_head *dst, |
| 810 | struct list_head *src) |
| 811 | { |
| 812 | struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc; |
| 813 | bool found; |
| 814 | |
| 815 | /* Find all the entries that should be removed from dst, |
| 816 | * These are the entries that are not found in src |
| 817 | */ |
| 818 | list_for_each_entry(dst_tmp, dst, list) { |
| 819 | found = false; |
| 820 | list_for_each_entry(src_tmp, src, list) { |
dingtianhong | c0623e5 | 2013-12-30 15:40:55 +0800 | [diff] [blame] | 821 | if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) { |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 822 | found = true; |
| 823 | break; |
| 824 | } |
| 825 | } |
| 826 | if (!found) |
| 827 | dst_tmp->action = MCLIST_REM; |
| 828 | } |
| 829 | |
| 830 | /* Add entries that exist in src but not in dst |
| 831 | * mark them as need to add |
| 832 | */ |
| 833 | list_for_each_entry(src_tmp, src, list) { |
| 834 | found = false; |
| 835 | list_for_each_entry(dst_tmp, dst, list) { |
dingtianhong | c0623e5 | 2013-12-30 15:40:55 +0800 | [diff] [blame] | 836 | if (ether_addr_equal(dst_tmp->addr, src_tmp->addr)) { |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 837 | dst_tmp->action = MCLIST_NONE; |
| 838 | found = true; |
| 839 | break; |
| 840 | } |
| 841 | } |
| 842 | if (!found) { |
Joe Perches | 14f8dc4 | 2013-02-07 11:46:27 +0000 | [diff] [blame] | 843 | new_mc = kmemdup(src_tmp, |
| 844 | sizeof(struct mlx4_en_mc_list), |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 845 | GFP_KERNEL); |
Joe Perches | 14f8dc4 | 2013-02-07 11:46:27 +0000 | [diff] [blame] | 846 | if (!new_mc) |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 847 | return; |
Joe Perches | 14f8dc4 | 2013-02-07 11:46:27 +0000 | [diff] [blame] | 848 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 849 | new_mc->action = MCLIST_ADD; |
| 850 | list_add_tail(&new_mc->list, dst); |
| 851 | } |
| 852 | } |
| 853 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 854 | |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 855 | static void mlx4_en_set_rx_mode(struct net_device *dev) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 856 | { |
| 857 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 858 | |
| 859 | if (!priv->port_up) |
| 860 | return; |
| 861 | |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 862 | queue_work(priv->mdev->workqueue, &priv->rx_mode_task); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 865 | static void mlx4_en_set_promisc_mode(struct mlx4_en_priv *priv, |
| 866 | struct mlx4_en_dev *mdev) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 867 | { |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 868 | int err = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 869 | |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 870 | if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 871 | if (netif_msg_rx_status(priv)) |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 872 | en_warn(priv, "Entering promiscuous mode\n"); |
| 873 | priv->flags |= MLX4_EN_FLAG_PROMISC; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 874 | |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 875 | /* Enable promiscouos mode */ |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 876 | switch (mdev->dev->caps.steering_mode) { |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 877 | case MLX4_STEERING_MODE_DEVICE_MANAGED: |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 878 | err = mlx4_flow_steer_promisc_add(mdev->dev, |
| 879 | priv->port, |
| 880 | priv->base_qpn, |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 881 | MLX4_FS_ALL_DEFAULT); |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 882 | if (err) |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 883 | en_err(priv, "Failed enabling promiscuous mode\n"); |
| 884 | priv->flags |= MLX4_EN_FLAG_MC_PROMISC; |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 885 | break; |
| 886 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 887 | case MLX4_STEERING_MODE_B0: |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 888 | err = mlx4_unicast_promisc_add(mdev->dev, |
| 889 | priv->base_qpn, |
| 890 | priv->port); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 891 | if (err) |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 892 | en_err(priv, "Failed enabling unicast promiscuous mode\n"); |
| 893 | |
| 894 | /* Add the default qp number as multicast |
| 895 | * promisc |
| 896 | */ |
| 897 | if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) { |
| 898 | err = mlx4_multicast_promisc_add(mdev->dev, |
| 899 | priv->base_qpn, |
| 900 | priv->port); |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 901 | if (err) |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 902 | en_err(priv, "Failed enabling multicast promiscuous mode\n"); |
| 903 | priv->flags |= MLX4_EN_FLAG_MC_PROMISC; |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 904 | } |
| 905 | break; |
| 906 | |
| 907 | case MLX4_STEERING_MODE_A0: |
| 908 | err = mlx4_SET_PORT_qpn_calc(mdev->dev, |
| 909 | priv->port, |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 910 | priv->base_qpn, |
| 911 | 1); |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 912 | if (err) |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 913 | en_err(priv, "Failed enabling promiscuous mode\n"); |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 914 | break; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 917 | /* Disable port multicast filter (unconditionally) */ |
| 918 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 919 | 0, MLX4_MCAST_DISABLE); |
| 920 | if (err) |
| 921 | en_err(priv, "Failed disabling multicast filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 922 | } |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | static void mlx4_en_clear_promisc_mode(struct mlx4_en_priv *priv, |
| 926 | struct mlx4_en_dev *mdev) |
| 927 | { |
| 928 | int err = 0; |
| 929 | |
| 930 | if (netif_msg_rx_status(priv)) |
| 931 | en_warn(priv, "Leaving promiscuous mode\n"); |
| 932 | priv->flags &= ~MLX4_EN_FLAG_PROMISC; |
| 933 | |
| 934 | /* Disable promiscouos mode */ |
| 935 | switch (mdev->dev->caps.steering_mode) { |
| 936 | case MLX4_STEERING_MODE_DEVICE_MANAGED: |
| 937 | err = mlx4_flow_steer_promisc_remove(mdev->dev, |
| 938 | priv->port, |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 939 | MLX4_FS_ALL_DEFAULT); |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 940 | if (err) |
| 941 | en_err(priv, "Failed disabling promiscuous mode\n"); |
| 942 | priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; |
| 943 | break; |
| 944 | |
| 945 | case MLX4_STEERING_MODE_B0: |
| 946 | err = mlx4_unicast_promisc_remove(mdev->dev, |
| 947 | priv->base_qpn, |
| 948 | priv->port); |
| 949 | if (err) |
| 950 | en_err(priv, "Failed disabling unicast promiscuous mode\n"); |
| 951 | /* Disable Multicast promisc */ |
| 952 | if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { |
| 953 | err = mlx4_multicast_promisc_remove(mdev->dev, |
| 954 | priv->base_qpn, |
| 955 | priv->port); |
| 956 | if (err) |
| 957 | en_err(priv, "Failed disabling multicast promiscuous mode\n"); |
| 958 | priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; |
| 959 | } |
| 960 | break; |
| 961 | |
| 962 | case MLX4_STEERING_MODE_A0: |
| 963 | err = mlx4_SET_PORT_qpn_calc(mdev->dev, |
| 964 | priv->port, |
| 965 | priv->base_qpn, 0); |
| 966 | if (err) |
| 967 | en_err(priv, "Failed disabling promiscuous mode\n"); |
| 968 | break; |
| 969 | } |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | static void mlx4_en_do_multicast(struct mlx4_en_priv *priv, |
| 973 | struct net_device *dev, |
| 974 | struct mlx4_en_dev *mdev) |
| 975 | { |
| 976 | struct mlx4_en_mc_list *mclist, *tmp; |
| 977 | u64 mcast_addr = 0; |
| 978 | u8 mc_list[16] = {0}; |
| 979 | int err = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 980 | |
| 981 | /* Enable/disable the multicast filter according to IFF_ALLMULTI */ |
| 982 | if (dev->flags & IFF_ALLMULTI) { |
| 983 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 984 | 0, MLX4_MCAST_DISABLE); |
| 985 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 986 | en_err(priv, "Failed disabling multicast filter\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 987 | |
| 988 | /* Add the default qp number as multicast promisc */ |
| 989 | if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) { |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 990 | switch (mdev->dev->caps.steering_mode) { |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 991 | case MLX4_STEERING_MODE_DEVICE_MANAGED: |
| 992 | err = mlx4_flow_steer_promisc_add(mdev->dev, |
| 993 | priv->port, |
| 994 | priv->base_qpn, |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 995 | MLX4_FS_MC_DEFAULT); |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 996 | break; |
| 997 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 998 | case MLX4_STEERING_MODE_B0: |
| 999 | err = mlx4_multicast_promisc_add(mdev->dev, |
| 1000 | priv->base_qpn, |
| 1001 | priv->port); |
| 1002 | break; |
| 1003 | |
| 1004 | case MLX4_STEERING_MODE_A0: |
| 1005 | break; |
| 1006 | } |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1007 | if (err) |
| 1008 | en_err(priv, "Failed entering multicast promisc mode\n"); |
| 1009 | priv->flags |= MLX4_EN_FLAG_MC_PROMISC; |
| 1010 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1011 | } else { |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1012 | /* Disable Multicast promisc */ |
| 1013 | if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 1014 | switch (mdev->dev->caps.steering_mode) { |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 1015 | case MLX4_STEERING_MODE_DEVICE_MANAGED: |
| 1016 | err = mlx4_flow_steer_promisc_remove(mdev->dev, |
| 1017 | priv->port, |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 1018 | MLX4_FS_MC_DEFAULT); |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 1019 | break; |
| 1020 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 1021 | case MLX4_STEERING_MODE_B0: |
| 1022 | err = mlx4_multicast_promisc_remove(mdev->dev, |
| 1023 | priv->base_qpn, |
| 1024 | priv->port); |
| 1025 | break; |
| 1026 | |
| 1027 | case MLX4_STEERING_MODE_A0: |
| 1028 | break; |
| 1029 | } |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1030 | if (err) |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1031 | en_err(priv, "Failed disabling multicast promiscuous mode\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1032 | priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; |
| 1033 | } |
Jiri Pirko | ff6e216 | 2010-03-01 05:09:14 +0000 | [diff] [blame] | 1034 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1035 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 1036 | 0, MLX4_MCAST_DISABLE); |
| 1037 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1038 | en_err(priv, "Failed disabling multicast filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1039 | |
| 1040 | /* Flush mcast filter and init it with broadcast address */ |
| 1041 | mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST, |
| 1042 | 1, MLX4_MCAST_CONFIG); |
| 1043 | |
| 1044 | /* Update multicast list - we cache all addresses so they won't |
| 1045 | * change while HW is updated holding the command semaphor */ |
Eugenia Emantayev | dbd501a | 2013-01-24 01:54:16 +0000 | [diff] [blame] | 1046 | netif_addr_lock_bh(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1047 | mlx4_en_cache_mclist(dev); |
Eugenia Emantayev | dbd501a | 2013-01-24 01:54:16 +0000 | [diff] [blame] | 1048 | netif_addr_unlock_bh(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1049 | list_for_each_entry(mclist, &priv->mc_list, list) { |
Eugenia Emantayev | 9813337 | 2014-03-02 10:25:01 +0200 | [diff] [blame] | 1050 | mcast_addr = mlx4_mac_to_u64(mclist->addr); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1051 | mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, |
| 1052 | mcast_addr, 0, MLX4_MCAST_CONFIG); |
| 1053 | } |
| 1054 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 1055 | 0, MLX4_MCAST_ENABLE); |
| 1056 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1057 | en_err(priv, "Failed enabling multicast filter\n"); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1058 | |
| 1059 | update_mclist_flags(priv, &priv->curr_list, &priv->mc_list); |
| 1060 | list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { |
| 1061 | if (mclist->action == MCLIST_REM) { |
| 1062 | /* detach this address and delete from list */ |
| 1063 | memcpy(&mc_list[10], mclist->addr, ETH_ALEN); |
| 1064 | mc_list[5] = priv->port; |
| 1065 | err = mlx4_multicast_detach(mdev->dev, |
| 1066 | &priv->rss_map.indir_qp, |
| 1067 | mc_list, |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1068 | MLX4_PROT_ETH, |
| 1069 | mclist->reg_id); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1070 | if (err) |
| 1071 | en_err(priv, "Fail to detach multicast address\n"); |
| 1072 | |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 1073 | if (mclist->tunnel_reg_id) { |
| 1074 | err = mlx4_flow_detach(priv->mdev->dev, mclist->tunnel_reg_id); |
| 1075 | if (err) |
| 1076 | en_err(priv, "Failed to detach multicast address\n"); |
| 1077 | } |
| 1078 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1079 | /* remove from list */ |
| 1080 | list_del(&mclist->list); |
| 1081 | kfree(mclist); |
Dan Carpenter | 9c64508 | 2012-07-10 20:34:07 +0000 | [diff] [blame] | 1082 | } else if (mclist->action == MCLIST_ADD) { |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1083 | /* attach the address */ |
| 1084 | memcpy(&mc_list[10], mclist->addr, ETH_ALEN); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1085 | /* needed for B0 steering support */ |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1086 | mc_list[5] = priv->port; |
| 1087 | err = mlx4_multicast_attach(mdev->dev, |
| 1088 | &priv->rss_map.indir_qp, |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1089 | mc_list, |
| 1090 | priv->port, 0, |
| 1091 | MLX4_PROT_ETH, |
| 1092 | &mclist->reg_id); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1093 | if (err) |
| 1094 | en_err(priv, "Fail to attach multicast address\n"); |
| 1095 | |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 1096 | err = mlx4_en_tunnel_steer_add(priv, &mc_list[10], priv->base_qpn, |
| 1097 | &mclist->tunnel_reg_id); |
| 1098 | if (err) |
| 1099 | en_err(priv, "Failed to attach multicast address\n"); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1100 | } |
| 1101 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1102 | } |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
Yan Burman | cc5387f | 2013-02-07 02:25:26 +0000 | [diff] [blame] | 1105 | static void mlx4_en_do_uc_filter(struct mlx4_en_priv *priv, |
| 1106 | struct net_device *dev, |
| 1107 | struct mlx4_en_dev *mdev) |
| 1108 | { |
| 1109 | struct netdev_hw_addr *ha; |
| 1110 | struct mlx4_mac_entry *entry; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1111 | struct hlist_node *tmp; |
Yan Burman | cc5387f | 2013-02-07 02:25:26 +0000 | [diff] [blame] | 1112 | bool found; |
| 1113 | u64 mac; |
| 1114 | int err = 0; |
| 1115 | struct hlist_head *bucket; |
| 1116 | unsigned int i; |
| 1117 | int removed = 0; |
| 1118 | u32 prev_flags; |
| 1119 | |
| 1120 | /* Note that we do not need to protect our mac_hash traversal with rcu, |
| 1121 | * since all modification code is protected by mdev->state_lock |
| 1122 | */ |
| 1123 | |
| 1124 | /* find what to remove */ |
| 1125 | for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) { |
| 1126 | bucket = &priv->mac_hash[i]; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1127 | hlist_for_each_entry_safe(entry, tmp, bucket, hlist) { |
Yan Burman | cc5387f | 2013-02-07 02:25:26 +0000 | [diff] [blame] | 1128 | found = false; |
| 1129 | netdev_for_each_uc_addr(ha, dev) { |
| 1130 | if (ether_addr_equal_64bits(entry->mac, |
| 1131 | ha->addr)) { |
| 1132 | found = true; |
| 1133 | break; |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | /* MAC address of the port is not in uc list */ |
Noa Osherovich | 2695bab | 2014-07-08 11:25:24 +0300 | [diff] [blame] | 1138 | if (ether_addr_equal_64bits(entry->mac, |
| 1139 | priv->current_mac)) |
Yan Burman | cc5387f | 2013-02-07 02:25:26 +0000 | [diff] [blame] | 1140 | found = true; |
| 1141 | |
| 1142 | if (!found) { |
Eugenia Emantayev | 9813337 | 2014-03-02 10:25:01 +0200 | [diff] [blame] | 1143 | mac = mlx4_mac_to_u64(entry->mac); |
Yan Burman | cc5387f | 2013-02-07 02:25:26 +0000 | [diff] [blame] | 1144 | mlx4_en_uc_steer_release(priv, entry->mac, |
| 1145 | priv->base_qpn, |
| 1146 | entry->reg_id); |
| 1147 | mlx4_unregister_mac(mdev->dev, priv->port, mac); |
| 1148 | |
| 1149 | hlist_del_rcu(&entry->hlist); |
| 1150 | kfree_rcu(entry, rcu); |
| 1151 | en_dbg(DRV, priv, "Removed MAC %pM on port:%d\n", |
| 1152 | entry->mac, priv->port); |
| 1153 | ++removed; |
| 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | /* if we didn't remove anything, there is no use in trying to add |
| 1159 | * again once we are in a forced promisc mode state |
| 1160 | */ |
| 1161 | if ((priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) && 0 == removed) |
| 1162 | return; |
| 1163 | |
| 1164 | prev_flags = priv->flags; |
| 1165 | priv->flags &= ~MLX4_EN_FLAG_FORCE_PROMISC; |
| 1166 | |
| 1167 | /* find what to add */ |
| 1168 | netdev_for_each_uc_addr(ha, dev) { |
| 1169 | found = false; |
| 1170 | bucket = &priv->mac_hash[ha->addr[MLX4_EN_MAC_HASH_IDX]]; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1171 | hlist_for_each_entry(entry, bucket, hlist) { |
Yan Burman | cc5387f | 2013-02-07 02:25:26 +0000 | [diff] [blame] | 1172 | if (ether_addr_equal_64bits(entry->mac, ha->addr)) { |
| 1173 | found = true; |
| 1174 | break; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | if (!found) { |
| 1179 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); |
| 1180 | if (!entry) { |
| 1181 | en_err(priv, "Failed adding MAC %pM on port:%d (out of memory)\n", |
| 1182 | ha->addr, priv->port); |
| 1183 | priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC; |
| 1184 | break; |
| 1185 | } |
Eugenia Emantayev | 9813337 | 2014-03-02 10:25:01 +0200 | [diff] [blame] | 1186 | mac = mlx4_mac_to_u64(ha->addr); |
Yan Burman | cc5387f | 2013-02-07 02:25:26 +0000 | [diff] [blame] | 1187 | memcpy(entry->mac, ha->addr, ETH_ALEN); |
| 1188 | err = mlx4_register_mac(mdev->dev, priv->port, mac); |
| 1189 | if (err < 0) { |
| 1190 | en_err(priv, "Failed registering MAC %pM on port %d: %d\n", |
| 1191 | ha->addr, priv->port, err); |
| 1192 | kfree(entry); |
| 1193 | priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC; |
| 1194 | break; |
| 1195 | } |
| 1196 | err = mlx4_en_uc_steer_add(priv, ha->addr, |
| 1197 | &priv->base_qpn, |
| 1198 | &entry->reg_id); |
| 1199 | if (err) { |
| 1200 | en_err(priv, "Failed adding MAC %pM on port %d: %d\n", |
| 1201 | ha->addr, priv->port, err); |
| 1202 | mlx4_unregister_mac(mdev->dev, priv->port, mac); |
| 1203 | kfree(entry); |
| 1204 | priv->flags |= MLX4_EN_FLAG_FORCE_PROMISC; |
| 1205 | break; |
| 1206 | } else { |
| 1207 | unsigned int mac_hash; |
| 1208 | en_dbg(DRV, priv, "Added MAC %pM on port:%d\n", |
| 1209 | ha->addr, priv->port); |
| 1210 | mac_hash = ha->addr[MLX4_EN_MAC_HASH_IDX]; |
| 1211 | bucket = &priv->mac_hash[mac_hash]; |
| 1212 | hlist_add_head_rcu(&entry->hlist, bucket); |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | if (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC) { |
| 1218 | en_warn(priv, "Forcing promiscuous mode on port:%d\n", |
| 1219 | priv->port); |
| 1220 | } else if (prev_flags & MLX4_EN_FLAG_FORCE_PROMISC) { |
| 1221 | en_warn(priv, "Stop forcing promiscuous mode on port:%d\n", |
| 1222 | priv->port); |
| 1223 | } |
| 1224 | } |
| 1225 | |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 1226 | static void mlx4_en_do_set_rx_mode(struct work_struct *work) |
| 1227 | { |
| 1228 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 1229 | rx_mode_task); |
| 1230 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1231 | struct net_device *dev = priv->dev; |
| 1232 | |
| 1233 | mutex_lock(&mdev->state_lock); |
| 1234 | if (!mdev->device_up) { |
| 1235 | en_dbg(HW, priv, "Card is not up, ignoring rx mode change.\n"); |
| 1236 | goto out; |
| 1237 | } |
| 1238 | if (!priv->port_up) { |
| 1239 | en_dbg(HW, priv, "Port is down, ignoring rx mode change.\n"); |
| 1240 | goto out; |
| 1241 | } |
| 1242 | |
| 1243 | if (!netif_carrier_ok(dev)) { |
| 1244 | if (!mlx4_en_QUERY_PORT(mdev, priv->port)) { |
| 1245 | if (priv->port_state.link_state) { |
| 1246 | priv->last_link_state = MLX4_DEV_EVENT_PORT_UP; |
| 1247 | netif_carrier_on(dev); |
| 1248 | en_dbg(LINK, priv, "Link Up\n"); |
| 1249 | } |
| 1250 | } |
| 1251 | } |
| 1252 | |
Yan Burman | cc5387f | 2013-02-07 02:25:26 +0000 | [diff] [blame] | 1253 | if (dev->priv_flags & IFF_UNICAST_FLT) |
| 1254 | mlx4_en_do_uc_filter(priv, dev, mdev); |
| 1255 | |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 1256 | /* Promsicuous mode: disable all filters */ |
Yan Burman | cc5387f | 2013-02-07 02:25:26 +0000 | [diff] [blame] | 1257 | if ((dev->flags & IFF_PROMISC) || |
| 1258 | (priv->flags & MLX4_EN_FLAG_FORCE_PROMISC)) { |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 1259 | mlx4_en_set_promisc_mode(priv, mdev); |
| 1260 | goto out; |
| 1261 | } |
| 1262 | |
| 1263 | /* Not in promiscuous mode */ |
| 1264 | if (priv->flags & MLX4_EN_FLAG_PROMISC) |
| 1265 | mlx4_en_clear_promisc_mode(priv, mdev); |
| 1266 | |
| 1267 | mlx4_en_do_multicast(priv, dev, mdev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1268 | out: |
| 1269 | mutex_unlock(&mdev->state_lock); |
| 1270 | } |
| 1271 | |
| 1272 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1273 | static void mlx4_en_netpoll(struct net_device *dev) |
| 1274 | { |
| 1275 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1276 | struct mlx4_en_cq *cq; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1277 | int i; |
| 1278 | |
| 1279 | for (i = 0; i < priv->rx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1280 | cq = priv->rx_cq[i]; |
Chris Mason | c98235c | 2014-04-15 18:09:24 -0400 | [diff] [blame] | 1281 | napi_schedule(&cq->napi); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | #endif |
| 1285 | |
| 1286 | static void mlx4_en_tx_timeout(struct net_device *dev) |
| 1287 | { |
| 1288 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1289 | struct mlx4_en_dev *mdev = priv->mdev; |
Yevgeny Petrilin | b944ebe | 2013-06-25 12:09:34 +0300 | [diff] [blame] | 1290 | int i; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1291 | |
| 1292 | if (netif_msg_timer(priv)) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1293 | en_warn(priv, "Tx timeout called on port:%d\n", priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1294 | |
Yevgeny Petrilin | b944ebe | 2013-06-25 12:09:34 +0300 | [diff] [blame] | 1295 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 1296 | if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev, i))) |
| 1297 | continue; |
| 1298 | en_warn(priv, "TX timeout on queue: %d, QP: 0x%x, CQ: 0x%x, Cons: 0x%x, Prod: 0x%x\n", |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1299 | i, priv->tx_ring[i]->qpn, priv->tx_ring[i]->cqn, |
| 1300 | priv->tx_ring[i]->cons, priv->tx_ring[i]->prod); |
Yevgeny Petrilin | b944ebe | 2013-06-25 12:09:34 +0300 | [diff] [blame] | 1301 | } |
| 1302 | |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 1303 | priv->port_stats.tx_timeout++; |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1304 | en_dbg(DRV, priv, "Scheduling watchdog\n"); |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 1305 | queue_work(mdev->workqueue, &priv->watchdog_task); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev) |
| 1310 | { |
| 1311 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1312 | |
| 1313 | spin_lock_bh(&priv->stats_lock); |
| 1314 | memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats)); |
| 1315 | spin_unlock_bh(&priv->stats_lock); |
| 1316 | |
| 1317 | return &priv->ret_stats; |
| 1318 | } |
| 1319 | |
| 1320 | static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv) |
| 1321 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1322 | struct mlx4_en_cq *cq; |
| 1323 | int i; |
| 1324 | |
| 1325 | /* If we haven't received a specific coalescing setting |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 1326 | * (module param), we set the moderation parameters as follows: |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1327 | * - moder_cnt is set to the number of mtu sized packets to |
Eric Dumazet | ecfd2ce | 2012-11-05 16:20:42 +0000 | [diff] [blame] | 1328 | * satisfy our coalescing target. |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1329 | * - moder_time is set to a fixed value. |
| 1330 | */ |
Yevgeny Petrilin | 3db36fb | 2009-06-01 23:23:13 +0000 | [diff] [blame] | 1331 | priv->rx_frames = MLX4_EN_RX_COAL_TARGET; |
Yevgeny Petrilin | 60b9f9e | 2008-12-25 18:19:47 -0800 | [diff] [blame] | 1332 | priv->rx_usecs = MLX4_EN_RX_COAL_TIME; |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 1333 | priv->tx_frames = MLX4_EN_TX_COAL_PKTS; |
| 1334 | priv->tx_usecs = MLX4_EN_TX_COAL_TIME; |
Yan Burman | 48e551f | 2013-02-07 02:25:21 +0000 | [diff] [blame] | 1335 | en_dbg(INTR, priv, "Default coalesing params for mtu:%d - rx_frames:%d rx_usecs:%d\n", |
| 1336 | priv->dev->mtu, priv->rx_frames, priv->rx_usecs); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1337 | |
| 1338 | /* Setup cq moderation params */ |
| 1339 | for (i = 0; i < priv->rx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1340 | cq = priv->rx_cq[i]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1341 | cq->moder_cnt = priv->rx_frames; |
| 1342 | cq->moder_time = priv->rx_usecs; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 1343 | priv->last_moder_time[i] = MLX4_EN_AUTO_CONF; |
| 1344 | priv->last_moder_packets[i] = 0; |
| 1345 | priv->last_moder_bytes[i] = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | for (i = 0; i < priv->tx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1349 | cq = priv->tx_cq[i]; |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 1350 | cq->moder_cnt = priv->tx_frames; |
| 1351 | cq->moder_time = priv->tx_usecs; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | /* Reset auto-moderation params */ |
| 1355 | priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW; |
| 1356 | priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW; |
| 1357 | priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH; |
| 1358 | priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH; |
| 1359 | priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL; |
Yevgeny Petrilin | 60b9f9e | 2008-12-25 18:19:47 -0800 | [diff] [blame] | 1360 | priv->adaptive_rx_coal = 1; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1361 | priv->last_moder_jiffies = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1362 | priv->last_moder_tx_packets = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv) |
| 1366 | { |
| 1367 | unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1368 | struct mlx4_en_cq *cq; |
| 1369 | unsigned long packets; |
| 1370 | unsigned long rate; |
| 1371 | unsigned long avg_pkt_size; |
| 1372 | unsigned long rx_packets; |
| 1373 | unsigned long rx_bytes; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1374 | unsigned long rx_pkt_diff; |
| 1375 | int moder_time; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 1376 | int ring, err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1377 | |
| 1378 | if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ) |
| 1379 | return; |
| 1380 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 1381 | for (ring = 0; ring < priv->rx_ring_num; ring++) { |
| 1382 | spin_lock_bh(&priv->stats_lock); |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1383 | rx_packets = priv->rx_ring[ring]->packets; |
| 1384 | rx_bytes = priv->rx_ring[ring]->bytes; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 1385 | spin_unlock_bh(&priv->stats_lock); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1386 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 1387 | rx_pkt_diff = ((unsigned long) (rx_packets - |
| 1388 | priv->last_moder_packets[ring])); |
| 1389 | packets = rx_pkt_diff; |
| 1390 | rate = packets * HZ / period; |
| 1391 | avg_pkt_size = packets ? ((unsigned long) (rx_bytes - |
| 1392 | priv->last_moder_bytes[ring])) / packets : 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1393 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 1394 | /* Apply auto-moderation only when packet rate |
| 1395 | * exceeds a rate that it matters */ |
| 1396 | if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) && |
| 1397 | avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1398 | if (rate < priv->pkt_rate_low) |
| 1399 | moder_time = priv->rx_usecs_low; |
| 1400 | else if (rate > priv->pkt_rate_high) |
| 1401 | moder_time = priv->rx_usecs_high; |
| 1402 | else |
| 1403 | moder_time = (rate - priv->pkt_rate_low) * |
| 1404 | (priv->rx_usecs_high - priv->rx_usecs_low) / |
| 1405 | (priv->pkt_rate_high - priv->pkt_rate_low) + |
| 1406 | priv->rx_usecs_low; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 1407 | } else { |
| 1408 | moder_time = priv->rx_usecs_low; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1409 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1410 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 1411 | if (moder_time != priv->last_moder_time[ring]) { |
| 1412 | priv->last_moder_time[ring] = moder_time; |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1413 | cq = priv->rx_cq[ring]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1414 | cq->moder_time = moder_time; |
Sagi Grimberg | a1c6693 | 2013-06-04 05:13:26 +0000 | [diff] [blame] | 1415 | cq->moder_cnt = priv->rx_frames; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1416 | err = mlx4_en_set_cq_moder(priv, cq); |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 1417 | if (err) |
Yan Burman | 48e551f | 2013-02-07 02:25:21 +0000 | [diff] [blame] | 1418 | en_err(priv, "Failed modifying moderation for cq:%d\n", |
| 1419 | ring); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1420 | } |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 1421 | priv->last_moder_packets[ring] = rx_packets; |
| 1422 | priv->last_moder_bytes[ring] = rx_bytes; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1425 | priv->last_moder_jiffies = jiffies; |
| 1426 | } |
| 1427 | |
| 1428 | static void mlx4_en_do_get_stats(struct work_struct *work) |
| 1429 | { |
Jean Delvare | bf6aede | 2009-04-02 16:56:54 -0700 | [diff] [blame] | 1430 | struct delayed_work *delay = to_delayed_work(work); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1431 | struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv, |
| 1432 | stats_task); |
| 1433 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1434 | int err; |
| 1435 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1436 | mutex_lock(&mdev->state_lock); |
| 1437 | if (mdev->device_up) { |
Jack Morgenstein | 6123db2e | 2013-06-25 12:09:30 +0300 | [diff] [blame] | 1438 | if (priv->port_up) { |
| 1439 | err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0); |
| 1440 | if (err) |
| 1441 | en_dbg(HW, priv, "Could not update stats\n"); |
Eugenia Emantayev | 2d51837 | 2013-01-24 01:54:14 +0000 | [diff] [blame] | 1442 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1443 | mlx4_en_auto_moderation(priv); |
Jack Morgenstein | 6123db2e | 2013-06-25 12:09:30 +0300 | [diff] [blame] | 1444 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1445 | |
| 1446 | queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY); |
| 1447 | } |
Yevgeny Petrilin | d7e1a48 | 2010-08-24 03:46:38 +0000 | [diff] [blame] | 1448 | if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) { |
Noa Osherovich | 2695bab | 2014-07-08 11:25:24 +0300 | [diff] [blame] | 1449 | mlx4_en_do_set_mac(priv, priv->current_mac); |
Yevgeny Petrilin | d7e1a48 | 2010-08-24 03:46:38 +0000 | [diff] [blame] | 1450 | mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0; |
| 1451 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1452 | mutex_unlock(&mdev->state_lock); |
| 1453 | } |
| 1454 | |
Amir Vadai | b6c39bf | 2013-04-23 06:06:51 +0000 | [diff] [blame] | 1455 | /* mlx4_en_service_task - Run service task for tasks that needed to be done |
| 1456 | * periodically |
| 1457 | */ |
| 1458 | static void mlx4_en_service_task(struct work_struct *work) |
| 1459 | { |
| 1460 | struct delayed_work *delay = to_delayed_work(work); |
| 1461 | struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv, |
| 1462 | service_task); |
| 1463 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1464 | |
| 1465 | mutex_lock(&mdev->state_lock); |
| 1466 | if (mdev->device_up) { |
Amir Vadai | dc8142e | 2013-04-25 05:22:24 +0000 | [diff] [blame] | 1467 | if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) |
| 1468 | mlx4_en_ptp_overflow_check(mdev); |
Amir Vadai | b6c39bf | 2013-04-23 06:06:51 +0000 | [diff] [blame] | 1469 | |
| 1470 | queue_delayed_work(mdev->workqueue, &priv->service_task, |
| 1471 | SERVICE_TASK_DELAY); |
| 1472 | } |
| 1473 | mutex_unlock(&mdev->state_lock); |
| 1474 | } |
| 1475 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1476 | static void mlx4_en_linkstate(struct work_struct *work) |
| 1477 | { |
| 1478 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 1479 | linkstate_task); |
| 1480 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1481 | int linkstate = priv->link_state; |
| 1482 | |
| 1483 | mutex_lock(&mdev->state_lock); |
| 1484 | /* If observable port state changed set carrier state and |
| 1485 | * report to system log */ |
| 1486 | if (priv->last_link_state != linkstate) { |
| 1487 | if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) { |
Yevgeny Petrilin | e5cc44b | 2010-08-24 03:46:01 +0000 | [diff] [blame] | 1488 | en_info(priv, "Link Down\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1489 | netif_carrier_off(priv->dev); |
| 1490 | } else { |
Yevgeny Petrilin | e5cc44b | 2010-08-24 03:46:01 +0000 | [diff] [blame] | 1491 | en_info(priv, "Link Up\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1492 | netif_carrier_on(priv->dev); |
| 1493 | } |
| 1494 | } |
| 1495 | priv->last_link_state = linkstate; |
| 1496 | mutex_unlock(&mdev->state_lock); |
| 1497 | } |
| 1498 | |
Yuval Atias | 9e311e7 | 2014-06-09 10:24:39 +0300 | [diff] [blame] | 1499 | static int mlx4_en_init_affinity_hint(struct mlx4_en_priv *priv, int ring_idx) |
| 1500 | { |
| 1501 | struct mlx4_en_rx_ring *ring = priv->rx_ring[ring_idx]; |
| 1502 | int numa_node = priv->mdev->dev->numa_node; |
| 1503 | int ret = 0; |
| 1504 | |
| 1505 | if (!zalloc_cpumask_var(&ring->affinity_mask, GFP_KERNEL)) |
| 1506 | return -ENOMEM; |
| 1507 | |
| 1508 | ret = cpumask_set_cpu_local_first(ring_idx, numa_node, |
| 1509 | ring->affinity_mask); |
| 1510 | if (ret) |
| 1511 | free_cpumask_var(ring->affinity_mask); |
| 1512 | |
| 1513 | return ret; |
| 1514 | } |
| 1515 | |
| 1516 | static void mlx4_en_free_affinity_hint(struct mlx4_en_priv *priv, int ring_idx) |
| 1517 | { |
| 1518 | free_cpumask_var(priv->rx_ring[ring_idx]->affinity_mask); |
| 1519 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1520 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1521 | int mlx4_en_start_port(struct net_device *dev) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1522 | { |
| 1523 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1524 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1525 | struct mlx4_en_cq *cq; |
| 1526 | struct mlx4_en_tx_ring *tx_ring; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1527 | int rx_index = 0; |
| 1528 | int tx_index = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1529 | int err = 0; |
| 1530 | int i; |
| 1531 | int j; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1532 | u8 mc_list[16] = {0}; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1533 | |
| 1534 | if (priv->port_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1535 | en_dbg(DRV, priv, "start port called while port already up\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1536 | return 0; |
| 1537 | } |
| 1538 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1539 | INIT_LIST_HEAD(&priv->mc_list); |
| 1540 | INIT_LIST_HEAD(&priv->curr_list); |
Hadar Hen Zion | 0d256c0 | 2013-01-30 23:07:08 +0000 | [diff] [blame] | 1541 | INIT_LIST_HEAD(&priv->ethtool_list); |
| 1542 | memset(&priv->ethtool_rules[0], 0, |
| 1543 | sizeof(struct ethtool_flow_id) * MAX_NUM_OF_FS_RULES); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1544 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1545 | /* Calculate Rx buf size */ |
| 1546 | dev->mtu = min(dev->mtu, priv->max_mtu); |
| 1547 | mlx4_en_calc_rx_buf(dev); |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1548 | en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_skb_size); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 1549 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1550 | /* Configure rx cq's and rings */ |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 1551 | err = mlx4_en_activate_rx_rings(priv); |
| 1552 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1553 | en_err(priv, "Failed to activate RX rings\n"); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 1554 | return err; |
| 1555 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1556 | for (i = 0; i < priv->rx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1557 | cq = priv->rx_cq[i]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1558 | |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 1559 | mlx4_en_cq_init_lock(cq); |
| 1560 | |
Yuval Atias | 9e311e7 | 2014-06-09 10:24:39 +0300 | [diff] [blame] | 1561 | err = mlx4_en_init_affinity_hint(priv, i); |
| 1562 | if (err) { |
| 1563 | en_err(priv, "Failed preparing IRQ affinity hint\n"); |
| 1564 | goto cq_err; |
| 1565 | } |
| 1566 | |
Alexander Guller | 76532d0 | 2011-10-09 05:26:31 +0000 | [diff] [blame] | 1567 | err = mlx4_en_activate_cq(priv, cq, i); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1568 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1569 | en_err(priv, "Failed activating Rx CQ\n"); |
Yuval Atias | 9e311e7 | 2014-06-09 10:24:39 +0300 | [diff] [blame] | 1570 | mlx4_en_free_affinity_hint(priv, i); |
Yevgeny Petrilin | a423330 | 2009-04-26 20:41:34 +0000 | [diff] [blame] | 1571 | goto cq_err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1572 | } |
Ido Shamay | c3f2511 | 2014-12-16 13:28:54 +0200 | [diff] [blame] | 1573 | |
| 1574 | for (j = 0; j < cq->size; j++) { |
| 1575 | struct mlx4_cqe *cqe = NULL; |
| 1576 | |
| 1577 | cqe = mlx4_en_get_cqe(cq->buf, j, priv->cqe_size) + |
| 1578 | priv->cqe_factor; |
| 1579 | cqe->owner_sr_opcode = MLX4_CQE_OWNER_MASK; |
| 1580 | } |
| 1581 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1582 | err = mlx4_en_set_cq_moder(priv, cq); |
| 1583 | if (err) { |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 1584 | en_err(priv, "Failed setting cq moderation parameters\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1585 | mlx4_en_deactivate_cq(priv, cq); |
Yuval Atias | 9e311e7 | 2014-06-09 10:24:39 +0300 | [diff] [blame] | 1586 | mlx4_en_free_affinity_hint(priv, i); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1587 | goto cq_err; |
| 1588 | } |
| 1589 | mlx4_en_arm_cq(priv, cq); |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1590 | priv->rx_ring[i]->cqn = cq->mcq.cqn; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1591 | ++rx_index; |
| 1592 | } |
| 1593 | |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 1594 | /* Set qp number */ |
| 1595 | en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port); |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 1596 | err = mlx4_en_get_qp(priv); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1597 | if (err) { |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 1598 | en_err(priv, "Failed getting eth qp\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1599 | goto cq_err; |
| 1600 | } |
| 1601 | mdev->mac_removed[priv->port] = 0; |
| 1602 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1603 | err = mlx4_en_config_rss_steer(priv); |
| 1604 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1605 | en_err(priv, "Failed configuring rss steering\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1606 | goto mac_err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Hadar Hen Zion | cabdc8ee | 2012-07-05 04:03:50 +0000 | [diff] [blame] | 1609 | err = mlx4_en_create_drop_qp(priv); |
| 1610 | if (err) |
| 1611 | goto rss_err; |
| 1612 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1613 | /* Configure tx cq's and rings */ |
| 1614 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 1615 | /* Configure cq */ |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1616 | cq = priv->tx_cq[i]; |
Alexander Guller | 76532d0 | 2011-10-09 05:26:31 +0000 | [diff] [blame] | 1617 | err = mlx4_en_activate_cq(priv, cq, i); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1618 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1619 | en_err(priv, "Failed allocating Tx CQ\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1620 | goto tx_err; |
| 1621 | } |
| 1622 | err = mlx4_en_set_cq_moder(priv, cq); |
| 1623 | if (err) { |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 1624 | en_err(priv, "Failed setting cq moderation parameters\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1625 | mlx4_en_deactivate_cq(priv, cq); |
| 1626 | goto tx_err; |
| 1627 | } |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1628 | en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1629 | cq->buf->wqe_index = cpu_to_be16(0xffff); |
| 1630 | |
| 1631 | /* Configure ring */ |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1632 | tx_ring = priv->tx_ring[i]; |
Amir Vadai | 0e98b52 | 2012-04-04 21:33:24 +0000 | [diff] [blame] | 1633 | err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn, |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1634 | i / priv->num_tx_rings_p_up); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1635 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1636 | en_err(priv, "Failed allocating Tx ring\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1637 | mlx4_en_deactivate_cq(priv, cq); |
| 1638 | goto tx_err; |
| 1639 | } |
Yevgeny Petrilin | 5b263f5 | 2012-04-23 02:18:50 +0000 | [diff] [blame] | 1640 | tx_ring->tx_queue = netdev_get_tx_queue(dev, i); |
Yevgeny Petrilin | e22979d | 2012-04-23 02:18:39 +0000 | [diff] [blame] | 1641 | |
| 1642 | /* Arm CQ for TX completions */ |
| 1643 | mlx4_en_arm_cq(priv, cq); |
| 1644 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1645 | /* Set initial ownership of all Tx TXBBs to SW (1) */ |
| 1646 | for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE) |
| 1647 | *((u32 *) (tx_ring->buf + j)) = 0xffffffff; |
| 1648 | ++tx_index; |
| 1649 | } |
| 1650 | |
| 1651 | /* Configure port */ |
| 1652 | err = mlx4_SET_PORT_general(mdev->dev, priv->port, |
| 1653 | priv->rx_skb_size + ETH_FCS_LEN, |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 1654 | priv->prof->tx_pause, |
| 1655 | priv->prof->tx_ppp, |
| 1656 | priv->prof->rx_pause, |
| 1657 | priv->prof->rx_ppp); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1658 | if (err) { |
Yan Burman | 48e551f | 2013-02-07 02:25:21 +0000 | [diff] [blame] | 1659 | en_err(priv, "Failed setting port general configurations for port %d, with error %d\n", |
| 1660 | priv->port, err); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1661 | goto tx_err; |
| 1662 | } |
| 1663 | /* Set default qp number */ |
| 1664 | err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0); |
| 1665 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1666 | en_err(priv, "Failed setting default qp numbers\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1667 | goto tx_err; |
| 1668 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1669 | |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 1670 | if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) { |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 1671 | err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC, 1); |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 1672 | if (err) { |
| 1673 | en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n", |
| 1674 | err); |
| 1675 | goto tx_err; |
| 1676 | } |
| 1677 | } |
| 1678 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1679 | /* Init port */ |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1680 | en_dbg(HW, priv, "Initializing port\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1681 | err = mlx4_INIT_PORT(mdev->dev, priv->port); |
| 1682 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1683 | en_err(priv, "Failed Initializing port\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1684 | goto tx_err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1687 | /* Attach rx QP to bradcast address */ |
| 1688 | memset(&mc_list[10], 0xff, ETH_ALEN); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1689 | mc_list[5] = priv->port; /* needed for B0 steering support */ |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1690 | if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list, |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1691 | priv->port, 0, MLX4_PROT_ETH, |
| 1692 | &priv->broadcast_id)) |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1693 | mlx4_warn(mdev, "Failed Attaching Broadcast\n"); |
| 1694 | |
Herbert Xu | b5845f9 | 2011-03-27 01:01:26 +0000 | [diff] [blame] | 1695 | /* Must redo promiscuous mode setup. */ |
| 1696 | priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC); |
| 1697 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1698 | /* Schedule multicast task to populate multicast list */ |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 1699 | queue_work(mdev->workqueue, &priv->rx_mode_task); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1700 | |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 1701 | mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap); |
| 1702 | |
Or Gerlitz | a66132f | 2014-04-01 11:27:13 +0300 | [diff] [blame] | 1703 | #ifdef CONFIG_MLX4_EN_VXLAN |
Or Gerlitz | 9737c6a | 2014-11-18 17:51:27 +0200 | [diff] [blame] | 1704 | if (priv->mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 1705 | vxlan_get_rx_port(dev); |
Or Gerlitz | a66132f | 2014-04-01 11:27:13 +0300 | [diff] [blame] | 1706 | #endif |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1707 | priv->port_up = true; |
Yevgeny Petrilin | a11faac | 2009-06-20 22:15:46 +0000 | [diff] [blame] | 1708 | netif_tx_start_all_queues(dev); |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1709 | netif_device_attach(dev); |
| 1710 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1711 | return 0; |
| 1712 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1713 | tx_err: |
| 1714 | while (tx_index--) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1715 | mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[tx_index]); |
| 1716 | mlx4_en_deactivate_cq(priv, priv->tx_cq[tx_index]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1717 | } |
Hadar Hen Zion | cabdc8ee | 2012-07-05 04:03:50 +0000 | [diff] [blame] | 1718 | mlx4_en_destroy_drop_qp(priv); |
| 1719 | rss_err: |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1720 | mlx4_en_release_rss_steer(priv); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1721 | mac_err: |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 1722 | mlx4_en_put_qp(priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1723 | cq_err: |
Yuval Atias | 9e311e7 | 2014-06-09 10:24:39 +0300 | [diff] [blame] | 1724 | while (rx_index--) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1725 | mlx4_en_deactivate_cq(priv, priv->rx_cq[rx_index]); |
Yuval Atias | 9e311e7 | 2014-06-09 10:24:39 +0300 | [diff] [blame] | 1726 | mlx4_en_free_affinity_hint(priv, i); |
| 1727 | } |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 1728 | for (i = 0; i < priv->rx_ring_num; i++) |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1729 | mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1730 | |
| 1731 | return err; /* need to close devices */ |
| 1732 | } |
| 1733 | |
| 1734 | |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1735 | void mlx4_en_stop_port(struct net_device *dev, int detach) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1736 | { |
| 1737 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1738 | struct mlx4_en_dev *mdev = priv->mdev; |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1739 | struct mlx4_en_mc_list *mclist, *tmp; |
Hadar Hen Zion | 0d256c0 | 2013-01-30 23:07:08 +0000 | [diff] [blame] | 1740 | struct ethtool_flow_id *flow, *tmp_flow; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1741 | int i; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1742 | u8 mc_list[16] = {0}; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1743 | |
| 1744 | if (!priv->port_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1745 | en_dbg(DRV, priv, "stop port called while port already down\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1746 | return; |
| 1747 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1748 | |
Eugenia Emantayev | 0cc5c8b | 2013-06-25 12:09:33 +0300 | [diff] [blame] | 1749 | /* close port*/ |
| 1750 | mlx4_CLOSE_PORT(mdev->dev, priv->port); |
| 1751 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1752 | /* Synchronize with tx routine */ |
| 1753 | netif_tx_lock_bh(dev); |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1754 | if (detach) |
| 1755 | netif_device_detach(dev); |
Yevgeny Petrilin | 3c05f5e | 2009-06-20 22:15:52 +0000 | [diff] [blame] | 1756 | netif_tx_stop_all_queues(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1757 | netif_tx_unlock_bh(dev); |
| 1758 | |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1759 | netif_tx_disable(dev); |
| 1760 | |
Yevgeny Petrilin | 7c28738 | 2010-08-24 03:45:45 +0000 | [diff] [blame] | 1761 | /* Set port as not active */ |
Yevgeny Petrilin | 3c05f5e | 2009-06-20 22:15:52 +0000 | [diff] [blame] | 1762 | priv->port_up = false; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1763 | |
Aviad Yehezkel | db0e7cb | 2013-01-24 01:54:15 +0000 | [diff] [blame] | 1764 | /* Promsicuous mode */ |
| 1765 | if (mdev->dev->caps.steering_mode == |
| 1766 | MLX4_STEERING_MODE_DEVICE_MANAGED) { |
| 1767 | priv->flags &= ~(MLX4_EN_FLAG_PROMISC | |
| 1768 | MLX4_EN_FLAG_MC_PROMISC); |
| 1769 | mlx4_flow_steer_promisc_remove(mdev->dev, |
| 1770 | priv->port, |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 1771 | MLX4_FS_ALL_DEFAULT); |
Aviad Yehezkel | db0e7cb | 2013-01-24 01:54:15 +0000 | [diff] [blame] | 1772 | mlx4_flow_steer_promisc_remove(mdev->dev, |
| 1773 | priv->port, |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 1774 | MLX4_FS_MC_DEFAULT); |
Aviad Yehezkel | db0e7cb | 2013-01-24 01:54:15 +0000 | [diff] [blame] | 1775 | } else if (priv->flags & MLX4_EN_FLAG_PROMISC) { |
| 1776 | priv->flags &= ~MLX4_EN_FLAG_PROMISC; |
| 1777 | |
| 1778 | /* Disable promiscouos mode */ |
| 1779 | mlx4_unicast_promisc_remove(mdev->dev, priv->base_qpn, |
| 1780 | priv->port); |
| 1781 | |
| 1782 | /* Disable Multicast promisc */ |
| 1783 | if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { |
| 1784 | mlx4_multicast_promisc_remove(mdev->dev, priv->base_qpn, |
| 1785 | priv->port); |
| 1786 | priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; |
| 1787 | } |
| 1788 | } |
| 1789 | |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1790 | /* Detach All multicasts */ |
| 1791 | memset(&mc_list[10], 0xff, ETH_ALEN); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1792 | mc_list[5] = priv->port; /* needed for B0 steering support */ |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1793 | mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list, |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1794 | MLX4_PROT_ETH, priv->broadcast_id); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1795 | list_for_each_entry(mclist, &priv->curr_list, list) { |
| 1796 | memcpy(&mc_list[10], mclist->addr, ETH_ALEN); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1797 | mc_list[5] = priv->port; |
| 1798 | mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1799 | mc_list, MLX4_PROT_ETH, mclist->reg_id); |
Or Gerlitz | de12326 | 2014-03-13 14:52:15 +0200 | [diff] [blame] | 1800 | if (mclist->tunnel_reg_id) |
| 1801 | mlx4_flow_detach(mdev->dev, mclist->tunnel_reg_id); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1802 | } |
| 1803 | mlx4_en_clear_list(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1804 | list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { |
| 1805 | list_del(&mclist->list); |
| 1806 | kfree(mclist); |
| 1807 | } |
| 1808 | |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1809 | /* Flush multicast filter */ |
| 1810 | mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG); |
| 1811 | |
Hadar Hen Zion | 6efb5fa | 2013-03-21 05:55:53 +0000 | [diff] [blame] | 1812 | /* Remove flow steering rules for the port*/ |
| 1813 | if (mdev->dev->caps.steering_mode == |
| 1814 | MLX4_STEERING_MODE_DEVICE_MANAGED) { |
| 1815 | ASSERT_RTNL(); |
| 1816 | list_for_each_entry_safe(flow, tmp_flow, |
| 1817 | &priv->ethtool_list, list) { |
| 1818 | mlx4_flow_detach(mdev->dev, flow->id); |
| 1819 | list_del(&flow->list); |
| 1820 | } |
| 1821 | } |
| 1822 | |
Hadar Hen Zion | cabdc8ee | 2012-07-05 04:03:50 +0000 | [diff] [blame] | 1823 | mlx4_en_destroy_drop_qp(priv); |
| 1824 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1825 | /* Free TX Rings */ |
| 1826 | for (i = 0; i < priv->tx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1827 | mlx4_en_deactivate_tx_ring(priv, priv->tx_ring[i]); |
| 1828 | mlx4_en_deactivate_cq(priv, priv->tx_cq[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1829 | } |
| 1830 | msleep(10); |
| 1831 | |
| 1832 | for (i = 0; i < priv->tx_ring_num; i++) |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1833 | mlx4_en_free_tx_buf(dev, priv->tx_ring[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1834 | |
| 1835 | /* Free RSS qps */ |
| 1836 | mlx4_en_release_rss_steer(priv); |
| 1837 | |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 1838 | /* Unregister Mac address for the port */ |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 1839 | mlx4_en_put_qp(priv); |
Or Gerlitz | 5930e8d | 2013-10-15 16:55:22 +0200 | [diff] [blame] | 1840 | if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN)) |
Matan Barak | 955154f | 2013-01-30 23:07:10 +0000 | [diff] [blame] | 1841 | mdev->mac_removed[priv->port] = 1; |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 1842 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1843 | /* Free RX Rings */ |
| 1844 | for (i = 0; i < priv->rx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1845 | struct mlx4_en_cq *cq = priv->rx_cq[i]; |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 1846 | |
| 1847 | local_bh_disable(); |
| 1848 | while (!mlx4_en_cq_lock_napi(cq)) { |
| 1849 | pr_info("CQ %d locked\n", i); |
| 1850 | mdelay(1); |
| 1851 | } |
| 1852 | local_bh_enable(); |
| 1853 | |
Ido Shamay | f4a3675 | 2014-10-27 11:37:45 +0200 | [diff] [blame] | 1854 | napi_synchronize(&cq->napi); |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1855 | mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]); |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 1856 | mlx4_en_deactivate_cq(priv, cq); |
Yuval Atias | 9e311e7 | 2014-06-09 10:24:39 +0300 | [diff] [blame] | 1857 | |
| 1858 | mlx4_en_free_affinity_hint(priv, i); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | static void mlx4_en_restart(struct work_struct *work) |
| 1863 | { |
| 1864 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 1865 | watchdog_task); |
| 1866 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1867 | struct net_device *dev = priv->dev; |
| 1868 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1869 | en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port); |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 1870 | |
| 1871 | mutex_lock(&mdev->state_lock); |
| 1872 | if (priv->port_up) { |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1873 | mlx4_en_stop_port(dev, 1); |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 1874 | if (mlx4_en_start_port(dev)) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1875 | en_err(priv, "Failed restarting port %d\n", priv->port); |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 1876 | } |
| 1877 | mutex_unlock(&mdev->state_lock); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1878 | } |
| 1879 | |
Eugenia Emantayev | b477ba6 | 2012-01-19 09:42:37 +0000 | [diff] [blame] | 1880 | static void mlx4_en_clear_stats(struct net_device *dev) |
| 1881 | { |
| 1882 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1883 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1884 | int i; |
| 1885 | |
| 1886 | if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1)) |
| 1887 | en_dbg(HW, priv, "Failed dumping statistics\n"); |
| 1888 | |
| 1889 | memset(&priv->stats, 0, sizeof(priv->stats)); |
| 1890 | memset(&priv->pstats, 0, sizeof(priv->pstats)); |
| 1891 | memset(&priv->pkstats, 0, sizeof(priv->pkstats)); |
| 1892 | memset(&priv->port_stats, 0, sizeof(priv->port_stats)); |
| 1893 | |
| 1894 | for (i = 0; i < priv->tx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1895 | priv->tx_ring[i]->bytes = 0; |
| 1896 | priv->tx_ring[i]->packets = 0; |
| 1897 | priv->tx_ring[i]->tx_csum = 0; |
Eugenia Emantayev | b477ba6 | 2012-01-19 09:42:37 +0000 | [diff] [blame] | 1898 | } |
| 1899 | for (i = 0; i < priv->rx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1900 | priv->rx_ring[i]->bytes = 0; |
| 1901 | priv->rx_ring[i]->packets = 0; |
| 1902 | priv->rx_ring[i]->csum_ok = 0; |
| 1903 | priv->rx_ring[i]->csum_none = 0; |
Shani Michaeli | f8c6455 | 2014-11-09 13:51:53 +0200 | [diff] [blame] | 1904 | priv->rx_ring[i]->csum_complete = 0; |
Eugenia Emantayev | b477ba6 | 2012-01-19 09:42:37 +0000 | [diff] [blame] | 1905 | } |
| 1906 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1907 | |
| 1908 | static int mlx4_en_open(struct net_device *dev) |
| 1909 | { |
| 1910 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1911 | struct mlx4_en_dev *mdev = priv->mdev; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1912 | int err = 0; |
| 1913 | |
| 1914 | mutex_lock(&mdev->state_lock); |
| 1915 | |
| 1916 | if (!mdev->device_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1917 | en_err(priv, "Cannot open - device down/disabled\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1918 | err = -EBUSY; |
| 1919 | goto out; |
| 1920 | } |
| 1921 | |
Eugenia Emantayev | b477ba6 | 2012-01-19 09:42:37 +0000 | [diff] [blame] | 1922 | /* Reset HW statistics and SW counters */ |
| 1923 | mlx4_en_clear_stats(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1924 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1925 | err = mlx4_en_start_port(dev); |
| 1926 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1927 | en_err(priv, "Failed starting port:%d\n", priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1928 | |
| 1929 | out: |
| 1930 | mutex_unlock(&mdev->state_lock); |
| 1931 | return err; |
| 1932 | } |
| 1933 | |
| 1934 | |
| 1935 | static int mlx4_en_close(struct net_device *dev) |
| 1936 | { |
| 1937 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1938 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1939 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1940 | en_dbg(IFDOWN, priv, "Close port called\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1941 | |
| 1942 | mutex_lock(&mdev->state_lock); |
| 1943 | |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1944 | mlx4_en_stop_port(dev, 0); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1945 | netif_carrier_off(dev); |
| 1946 | |
| 1947 | mutex_unlock(&mdev->state_lock); |
| 1948 | return 0; |
| 1949 | } |
| 1950 | |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1951 | void mlx4_en_free_resources(struct mlx4_en_priv *priv) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1952 | { |
| 1953 | int i; |
| 1954 | |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 1955 | #ifdef CONFIG_RFS_ACCEL |
| 1956 | free_irq_cpu_rmap(priv->dev->rx_cpu_rmap); |
| 1957 | priv->dev->rx_cpu_rmap = NULL; |
| 1958 | #endif |
| 1959 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1960 | for (i = 0; i < priv->tx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1961 | if (priv->tx_ring && priv->tx_ring[i]) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1962 | mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]); |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1963 | if (priv->tx_cq && priv->tx_cq[i]) |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1964 | mlx4_en_destroy_cq(priv, &priv->tx_cq[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | for (i = 0; i < priv->rx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1968 | if (priv->rx_ring[i]) |
Thadeu Lima de Souza Cascardo | 68355f7 | 2012-02-06 08:39:49 +0000 | [diff] [blame] | 1969 | mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i], |
| 1970 | priv->prof->rx_ring_size, priv->stride); |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1971 | if (priv->rx_cq[i]) |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1972 | mlx4_en_destroy_cq(priv, &priv->rx_cq[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1973 | } |
Yevgeny Petrilin | 044ca2a | 2012-06-25 00:24:13 +0000 | [diff] [blame] | 1974 | |
| 1975 | if (priv->base_tx_qpn) { |
| 1976 | mlx4_qp_release_range(priv->mdev->dev, priv->base_tx_qpn, priv->tx_ring_num); |
| 1977 | priv->base_tx_qpn = 0; |
| 1978 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1981 | int mlx4_en_alloc_resources(struct mlx4_en_priv *priv) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1982 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1983 | struct mlx4_en_port_profile *prof = priv->prof; |
| 1984 | int i; |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 1985 | int node; |
Yevgeny Petrilin | 87a5c38 | 2011-03-22 22:38:52 +0000 | [diff] [blame] | 1986 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1987 | /* Create tx Rings */ |
| 1988 | for (i = 0; i < priv->tx_ring_num; i++) { |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 1989 | node = cpu_to_node(i % num_online_cpus()); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1990 | if (mlx4_en_create_cq(priv, &priv->tx_cq[i], |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 1991 | prof->tx_ring_size, i, TX, node)) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1992 | goto err; |
| 1993 | |
Ido Shamay | d03a68f | 2013-12-19 21:20:14 +0200 | [diff] [blame] | 1994 | if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i], |
Ido Shamay | d03a68f | 2013-12-19 21:20:14 +0200 | [diff] [blame] | 1995 | prof->tx_ring_size, TXBB_SIZE, |
| 1996 | node, i)) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1997 | goto err; |
| 1998 | } |
| 1999 | |
| 2000 | /* Create rx Rings */ |
| 2001 | for (i = 0; i < priv->rx_ring_num; i++) { |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 2002 | node = cpu_to_node(i % num_online_cpus()); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2003 | if (mlx4_en_create_cq(priv, &priv->rx_cq[i], |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 2004 | prof->rx_ring_size, i, RX, node)) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2005 | goto err; |
| 2006 | |
| 2007 | if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i], |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 2008 | prof->rx_ring_size, priv->stride, |
| 2009 | node)) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2010 | goto err; |
| 2011 | } |
| 2012 | |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 2013 | #ifdef CONFIG_RFS_ACCEL |
Amir Vadai | a229e48 | 2013-03-07 03:46:57 +0000 | [diff] [blame] | 2014 | if (priv->mdev->dev->caps.comp_pool) { |
| 2015 | priv->dev->rx_cpu_rmap = alloc_irq_cpu_rmap(priv->mdev->dev->caps.comp_pool); |
| 2016 | if (!priv->dev->rx_cpu_rmap) |
| 2017 | goto err; |
| 2018 | } |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 2019 | #endif |
| 2020 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2021 | return 0; |
| 2022 | |
| 2023 | err: |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 2024 | en_err(priv, "Failed to allocate NIC resources\n"); |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 2025 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 2026 | if (priv->rx_ring[i]) |
| 2027 | mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i], |
| 2028 | prof->rx_ring_size, |
| 2029 | priv->stride); |
| 2030 | if (priv->rx_cq[i]) |
| 2031 | mlx4_en_destroy_cq(priv, &priv->rx_cq[i]); |
| 2032 | } |
| 2033 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 2034 | if (priv->tx_ring[i]) |
| 2035 | mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]); |
| 2036 | if (priv->tx_cq[i]) |
| 2037 | mlx4_en_destroy_cq(priv, &priv->tx_cq[i]); |
| 2038 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2039 | return -ENOMEM; |
| 2040 | } |
| 2041 | |
| 2042 | |
| 2043 | void mlx4_en_destroy_netdev(struct net_device *dev) |
| 2044 | { |
| 2045 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 2046 | struct mlx4_en_dev *mdev = priv->mdev; |
| 2047 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 2048 | en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2049 | |
| 2050 | /* Unregister device - this will close the port if it was up */ |
| 2051 | if (priv->registered) |
| 2052 | unregister_netdev(dev); |
| 2053 | |
| 2054 | if (priv->allocated) |
| 2055 | mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE); |
| 2056 | |
| 2057 | cancel_delayed_work(&priv->stats_task); |
Amir Vadai | b6c39bf | 2013-04-23 06:06:51 +0000 | [diff] [blame] | 2058 | cancel_delayed_work(&priv->service_task); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2059 | /* flush any pending task for this netdev */ |
| 2060 | flush_workqueue(mdev->workqueue); |
| 2061 | |
| 2062 | /* Detach the netdev so tasks would not attempt to access it */ |
| 2063 | mutex_lock(&mdev->state_lock); |
| 2064 | mdev->pndev[priv->port] = NULL; |
| 2065 | mutex_unlock(&mdev->state_lock); |
| 2066 | |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 2067 | mlx4_en_free_resources(priv); |
Amir Vadai | 564c274 | 2012-04-04 21:33:26 +0000 | [diff] [blame] | 2068 | |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 2069 | kfree(priv->tx_ring); |
| 2070 | kfree(priv->tx_cq); |
| 2071 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2072 | free_netdev(dev); |
| 2073 | } |
| 2074 | |
| 2075 | static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu) |
| 2076 | { |
| 2077 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 2078 | struct mlx4_en_dev *mdev = priv->mdev; |
| 2079 | int err = 0; |
| 2080 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 2081 | en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2082 | dev->mtu, new_mtu); |
| 2083 | |
| 2084 | if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 2085 | en_err(priv, "Bad MTU size:%d.\n", new_mtu); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2086 | return -EPERM; |
| 2087 | } |
| 2088 | dev->mtu = new_mtu; |
| 2089 | |
| 2090 | if (netif_running(dev)) { |
| 2091 | mutex_lock(&mdev->state_lock); |
| 2092 | if (!mdev->device_up) { |
| 2093 | /* NIC is probably restarting - let watchdog task reset |
| 2094 | * the port */ |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 2095 | en_dbg(DRV, priv, "Change MTU called with card down!?\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2096 | } else { |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 2097 | mlx4_en_stop_port(dev, 1); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2098 | err = mlx4_en_start_port(dev); |
| 2099 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 2100 | en_err(priv, "Failed restarting port:%d\n", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2101 | priv->port); |
| 2102 | queue_work(mdev->workqueue, &priv->watchdog_task); |
| 2103 | } |
| 2104 | } |
| 2105 | mutex_unlock(&mdev->state_lock); |
| 2106 | } |
| 2107 | return 0; |
| 2108 | } |
| 2109 | |
Ben Hutchings | 100dbda | 2013-11-18 23:13:31 +0000 | [diff] [blame] | 2110 | static int mlx4_en_hwtstamp_set(struct net_device *dev, struct ifreq *ifr) |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 2111 | { |
| 2112 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 2113 | struct mlx4_en_dev *mdev = priv->mdev; |
| 2114 | struct hwtstamp_config config; |
| 2115 | |
| 2116 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) |
| 2117 | return -EFAULT; |
| 2118 | |
| 2119 | /* reserved for future extensions */ |
| 2120 | if (config.flags) |
| 2121 | return -EINVAL; |
| 2122 | |
| 2123 | /* device doesn't support time stamping */ |
| 2124 | if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)) |
| 2125 | return -EINVAL; |
| 2126 | |
| 2127 | /* TX HW timestamp */ |
| 2128 | switch (config.tx_type) { |
| 2129 | case HWTSTAMP_TX_OFF: |
| 2130 | case HWTSTAMP_TX_ON: |
| 2131 | break; |
| 2132 | default: |
| 2133 | return -ERANGE; |
| 2134 | } |
| 2135 | |
| 2136 | /* RX HW timestamp */ |
| 2137 | switch (config.rx_filter) { |
| 2138 | case HWTSTAMP_FILTER_NONE: |
| 2139 | break; |
| 2140 | case HWTSTAMP_FILTER_ALL: |
| 2141 | case HWTSTAMP_FILTER_SOME: |
| 2142 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 2143 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 2144 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 2145 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 2146 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 2147 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 2148 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 2149 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 2150 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 2151 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 2152 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 2153 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 2154 | config.rx_filter = HWTSTAMP_FILTER_ALL; |
| 2155 | break; |
| 2156 | default: |
| 2157 | return -ERANGE; |
| 2158 | } |
| 2159 | |
Saeed Mahameed | 7787fa6 | 2014-10-27 11:37:42 +0200 | [diff] [blame] | 2160 | if (mlx4_en_reset_config(dev, config, dev->features)) { |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 2161 | config.tx_type = HWTSTAMP_TX_OFF; |
| 2162 | config.rx_filter = HWTSTAMP_FILTER_NONE; |
| 2163 | } |
| 2164 | |
| 2165 | return copy_to_user(ifr->ifr_data, &config, |
| 2166 | sizeof(config)) ? -EFAULT : 0; |
| 2167 | } |
| 2168 | |
Ben Hutchings | 100dbda | 2013-11-18 23:13:31 +0000 | [diff] [blame] | 2169 | static int mlx4_en_hwtstamp_get(struct net_device *dev, struct ifreq *ifr) |
| 2170 | { |
| 2171 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 2172 | |
| 2173 | return copy_to_user(ifr->ifr_data, &priv->hwtstamp_config, |
| 2174 | sizeof(priv->hwtstamp_config)) ? -EFAULT : 0; |
| 2175 | } |
| 2176 | |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 2177 | static int mlx4_en_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 2178 | { |
| 2179 | switch (cmd) { |
| 2180 | case SIOCSHWTSTAMP: |
Ben Hutchings | 100dbda | 2013-11-18 23:13:31 +0000 | [diff] [blame] | 2181 | return mlx4_en_hwtstamp_set(dev, ifr); |
| 2182 | case SIOCGHWTSTAMP: |
| 2183 | return mlx4_en_hwtstamp_get(dev, ifr); |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 2184 | default: |
| 2185 | return -EOPNOTSUPP; |
| 2186 | } |
| 2187 | } |
| 2188 | |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 2189 | static int mlx4_en_set_features(struct net_device *netdev, |
| 2190 | netdev_features_t features) |
| 2191 | { |
| 2192 | struct mlx4_en_priv *priv = netdev_priv(netdev); |
Saeed Mahameed | 537f6f9 | 2014-10-27 11:37:43 +0200 | [diff] [blame] | 2193 | int ret = 0; |
| 2194 | |
| 2195 | if (DEV_FEATURE_CHANGED(netdev, features, NETIF_F_HW_VLAN_CTAG_RX)) { |
| 2196 | en_info(priv, "Turn %s RX vlan strip offload\n", |
| 2197 | (features & NETIF_F_HW_VLAN_CTAG_RX) ? "ON" : "OFF"); |
| 2198 | ret = mlx4_en_reset_config(netdev, priv->hwtstamp_config, |
| 2199 | features); |
| 2200 | if (ret) |
| 2201 | return ret; |
| 2202 | } |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 2203 | |
| 2204 | if (features & NETIF_F_LOOPBACK) |
| 2205 | priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK); |
| 2206 | else |
| 2207 | priv->ctrl_flags &= |
| 2208 | cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK); |
| 2209 | |
Yan Burman | 79aeacc | 2013-02-07 02:25:19 +0000 | [diff] [blame] | 2210 | mlx4_en_update_loopback_state(netdev, features); |
| 2211 | |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 2212 | return 0; |
| 2213 | |
| 2214 | } |
| 2215 | |
Rony Efraim | 8f7ba3c | 2013-04-25 05:22:27 +0000 | [diff] [blame] | 2216 | static int mlx4_en_set_vf_mac(struct net_device *dev, int queue, u8 *mac) |
| 2217 | { |
| 2218 | struct mlx4_en_priv *en_priv = netdev_priv(dev); |
| 2219 | struct mlx4_en_dev *mdev = en_priv->mdev; |
Eugenia Emantayev | 9813337 | 2014-03-02 10:25:01 +0200 | [diff] [blame] | 2220 | u64 mac_u64 = mlx4_mac_to_u64(mac); |
Rony Efraim | 8f7ba3c | 2013-04-25 05:22:27 +0000 | [diff] [blame] | 2221 | |
| 2222 | if (!is_valid_ether_addr(mac)) |
| 2223 | return -EINVAL; |
| 2224 | |
| 2225 | return mlx4_set_vf_mac(mdev->dev, en_priv->port, queue, mac_u64); |
| 2226 | } |
| 2227 | |
Rony Efraim | 3f7fb02 | 2013-04-25 05:22:28 +0000 | [diff] [blame] | 2228 | static int mlx4_en_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos) |
| 2229 | { |
| 2230 | struct mlx4_en_priv *en_priv = netdev_priv(dev); |
| 2231 | struct mlx4_en_dev *mdev = en_priv->mdev; |
| 2232 | |
| 2233 | return mlx4_set_vf_vlan(mdev->dev, en_priv->port, vf, vlan, qos); |
| 2234 | } |
| 2235 | |
Rony Efraim | e6b6a23 | 2013-04-25 05:22:29 +0000 | [diff] [blame] | 2236 | static int mlx4_en_set_vf_spoofchk(struct net_device *dev, int vf, bool setting) |
| 2237 | { |
| 2238 | struct mlx4_en_priv *en_priv = netdev_priv(dev); |
| 2239 | struct mlx4_en_dev *mdev = en_priv->mdev; |
| 2240 | |
| 2241 | return mlx4_set_vf_spoofchk(mdev->dev, en_priv->port, vf, setting); |
| 2242 | } |
| 2243 | |
Rony Efraim | 2cccb9e | 2013-04-25 05:22:30 +0000 | [diff] [blame] | 2244 | static int mlx4_en_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_info *ivf) |
| 2245 | { |
| 2246 | struct mlx4_en_priv *en_priv = netdev_priv(dev); |
| 2247 | struct mlx4_en_dev *mdev = en_priv->mdev; |
| 2248 | |
| 2249 | return mlx4_get_vf_config(mdev->dev, en_priv->port, vf, ivf); |
| 2250 | } |
Rony Efraim | 8f7ba3c | 2013-04-25 05:22:27 +0000 | [diff] [blame] | 2251 | |
Rony Efraim | 948e306 | 2013-06-13 13:19:11 +0300 | [diff] [blame] | 2252 | static int mlx4_en_set_vf_link_state(struct net_device *dev, int vf, int link_state) |
| 2253 | { |
| 2254 | struct mlx4_en_priv *en_priv = netdev_priv(dev); |
| 2255 | struct mlx4_en_dev *mdev = en_priv->mdev; |
| 2256 | |
| 2257 | return mlx4_set_vf_link_state(mdev->dev, en_priv->port, vf, link_state); |
| 2258 | } |
Hadar Hen Zion | 84c8640 | 2013-12-19 21:20:13 +0200 | [diff] [blame] | 2259 | |
| 2260 | #define PORT_ID_BYTE_LEN 8 |
| 2261 | static int mlx4_en_get_phys_port_id(struct net_device *dev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 2262 | struct netdev_phys_item_id *ppid) |
Hadar Hen Zion | 84c8640 | 2013-12-19 21:20:13 +0200 | [diff] [blame] | 2263 | { |
| 2264 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 2265 | struct mlx4_dev *mdev = priv->mdev->dev; |
| 2266 | int i; |
| 2267 | u64 phys_port_id = mdev->caps.phys_port_id[priv->port]; |
| 2268 | |
| 2269 | if (!phys_port_id) |
| 2270 | return -EOPNOTSUPP; |
| 2271 | |
| 2272 | ppid->id_len = sizeof(phys_port_id); |
| 2273 | for (i = PORT_ID_BYTE_LEN - 1; i >= 0; --i) { |
| 2274 | ppid->id[i] = phys_port_id & 0xff; |
| 2275 | phys_port_id >>= 8; |
| 2276 | } |
| 2277 | return 0; |
| 2278 | } |
| 2279 | |
Or Gerlitz | a66132f | 2014-04-01 11:27:13 +0300 | [diff] [blame] | 2280 | #ifdef CONFIG_MLX4_EN_VXLAN |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 2281 | static void mlx4_en_add_vxlan_offloads(struct work_struct *work) |
| 2282 | { |
| 2283 | int ret; |
| 2284 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 2285 | vxlan_add_task); |
| 2286 | |
| 2287 | ret = mlx4_config_vxlan_port(priv->mdev->dev, priv->vxlan_port); |
| 2288 | if (ret) |
| 2289 | goto out; |
| 2290 | |
| 2291 | ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port, |
| 2292 | VXLAN_STEER_BY_OUTER_MAC, 1); |
| 2293 | out: |
Or Gerlitz | f4a1edd | 2014-11-09 14:25:39 +0200 | [diff] [blame] | 2294 | if (ret) { |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 2295 | en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret); |
Or Gerlitz | f4a1edd | 2014-11-09 14:25:39 +0200 | [diff] [blame] | 2296 | return; |
| 2297 | } |
| 2298 | |
| 2299 | /* set offloads */ |
| 2300 | priv->dev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM | |
| 2301 | NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL; |
| 2302 | priv->dev->hw_features |= NETIF_F_GSO_UDP_TUNNEL; |
| 2303 | priv->dev->features |= NETIF_F_GSO_UDP_TUNNEL; |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | static void mlx4_en_del_vxlan_offloads(struct work_struct *work) |
| 2307 | { |
| 2308 | int ret; |
| 2309 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 2310 | vxlan_del_task); |
Or Gerlitz | f4a1edd | 2014-11-09 14:25:39 +0200 | [diff] [blame] | 2311 | /* unset offloads */ |
| 2312 | priv->dev->hw_enc_features &= ~(NETIF_F_IP_CSUM | NETIF_F_RXCSUM | |
| 2313 | NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL); |
| 2314 | priv->dev->hw_features &= ~NETIF_F_GSO_UDP_TUNNEL; |
| 2315 | priv->dev->features &= ~NETIF_F_GSO_UDP_TUNNEL; |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 2316 | |
| 2317 | ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port, |
| 2318 | VXLAN_STEER_BY_OUTER_MAC, 0); |
| 2319 | if (ret) |
| 2320 | en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret); |
| 2321 | |
| 2322 | priv->vxlan_port = 0; |
| 2323 | } |
| 2324 | |
| 2325 | static void mlx4_en_add_vxlan_port(struct net_device *dev, |
| 2326 | sa_family_t sa_family, __be16 port) |
| 2327 | { |
| 2328 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 2329 | __be16 current_port; |
| 2330 | |
Or Gerlitz | e326f2f | 2014-07-02 17:36:23 +0300 | [diff] [blame] | 2331 | if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 2332 | return; |
| 2333 | |
| 2334 | if (sa_family == AF_INET6) |
| 2335 | return; |
| 2336 | |
| 2337 | current_port = priv->vxlan_port; |
| 2338 | if (current_port && current_port != port) { |
| 2339 | en_warn(priv, "vxlan port %d configured, can't add port %d\n", |
| 2340 | ntohs(current_port), ntohs(port)); |
| 2341 | return; |
| 2342 | } |
| 2343 | |
| 2344 | priv->vxlan_port = port; |
| 2345 | queue_work(priv->mdev->workqueue, &priv->vxlan_add_task); |
| 2346 | } |
| 2347 | |
| 2348 | static void mlx4_en_del_vxlan_port(struct net_device *dev, |
| 2349 | sa_family_t sa_family, __be16 port) |
| 2350 | { |
| 2351 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 2352 | __be16 current_port; |
| 2353 | |
| 2354 | if (priv->mdev->dev->caps.tunnel_offload_mode != MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) |
| 2355 | return; |
| 2356 | |
| 2357 | if (sa_family == AF_INET6) |
| 2358 | return; |
| 2359 | |
| 2360 | current_port = priv->vxlan_port; |
| 2361 | if (current_port != port) { |
| 2362 | en_dbg(DRV, priv, "vxlan port %d isn't configured, ignoring\n", ntohs(port)); |
| 2363 | return; |
| 2364 | } |
| 2365 | |
| 2366 | queue_work(priv->mdev->workqueue, &priv->vxlan_del_task); |
| 2367 | } |
Joe Stringer | 956bdab | 2014-11-13 16:38:14 -0800 | [diff] [blame] | 2368 | |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 2369 | static netdev_features_t mlx4_en_features_check(struct sk_buff *skb, |
| 2370 | struct net_device *dev, |
| 2371 | netdev_features_t features) |
Joe Stringer | 956bdab | 2014-11-13 16:38:14 -0800 | [diff] [blame] | 2372 | { |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 2373 | return vxlan_features_check(skb, features); |
Joe Stringer | 956bdab | 2014-11-13 16:38:14 -0800 | [diff] [blame] | 2374 | } |
Or Gerlitz | a66132f | 2014-04-01 11:27:13 +0300 | [diff] [blame] | 2375 | #endif |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 2376 | |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 2377 | static const struct net_device_ops mlx4_netdev_ops = { |
| 2378 | .ndo_open = mlx4_en_open, |
| 2379 | .ndo_stop = mlx4_en_close, |
| 2380 | .ndo_start_xmit = mlx4_en_xmit, |
Yevgeny Petrilin | f813cad | 2009-06-01 23:24:07 +0000 | [diff] [blame] | 2381 | .ndo_select_queue = mlx4_en_select_queue, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 2382 | .ndo_get_stats = mlx4_en_get_stats, |
Yan Burman | 0eb74fd | 2013-02-07 02:25:23 +0000 | [diff] [blame] | 2383 | .ndo_set_rx_mode = mlx4_en_set_rx_mode, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 2384 | .ndo_set_mac_address = mlx4_en_set_mac, |
Stephen Hemminger | 52255bb | 2009-01-09 10:45:37 +0000 | [diff] [blame] | 2385 | .ndo_validate_addr = eth_validate_addr, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 2386 | .ndo_change_mtu = mlx4_en_change_mtu, |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 2387 | .ndo_do_ioctl = mlx4_en_ioctl, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 2388 | .ndo_tx_timeout = mlx4_en_tx_timeout, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 2389 | .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid, |
| 2390 | .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid, |
| 2391 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2392 | .ndo_poll_controller = mlx4_en_netpoll, |
| 2393 | #endif |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 2394 | .ndo_set_features = mlx4_en_set_features, |
Amir Vadai | 897d784 | 2012-04-04 21:33:27 +0000 | [diff] [blame] | 2395 | .ndo_setup_tc = mlx4_en_setup_tc, |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 2396 | #ifdef CONFIG_RFS_ACCEL |
| 2397 | .ndo_rx_flow_steer = mlx4_en_filter_rfs, |
| 2398 | #endif |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2399 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 8b80cda | 2013-07-10 17:13:26 +0300 | [diff] [blame] | 2400 | .ndo_busy_poll = mlx4_en_low_latency_recv, |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 2401 | #endif |
Hadar Hen Zion | 84c8640 | 2013-12-19 21:20:13 +0200 | [diff] [blame] | 2402 | .ndo_get_phys_port_id = mlx4_en_get_phys_port_id, |
Or Gerlitz | a66132f | 2014-04-01 11:27:13 +0300 | [diff] [blame] | 2403 | #ifdef CONFIG_MLX4_EN_VXLAN |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 2404 | .ndo_add_vxlan_port = mlx4_en_add_vxlan_port, |
| 2405 | .ndo_del_vxlan_port = mlx4_en_del_vxlan_port, |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 2406 | .ndo_features_check = mlx4_en_features_check, |
Or Gerlitz | a66132f | 2014-04-01 11:27:13 +0300 | [diff] [blame] | 2407 | #endif |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 2408 | }; |
| 2409 | |
Rony Efraim | 8f7ba3c | 2013-04-25 05:22:27 +0000 | [diff] [blame] | 2410 | static const struct net_device_ops mlx4_netdev_ops_master = { |
| 2411 | .ndo_open = mlx4_en_open, |
| 2412 | .ndo_stop = mlx4_en_close, |
| 2413 | .ndo_start_xmit = mlx4_en_xmit, |
| 2414 | .ndo_select_queue = mlx4_en_select_queue, |
| 2415 | .ndo_get_stats = mlx4_en_get_stats, |
| 2416 | .ndo_set_rx_mode = mlx4_en_set_rx_mode, |
| 2417 | .ndo_set_mac_address = mlx4_en_set_mac, |
| 2418 | .ndo_validate_addr = eth_validate_addr, |
| 2419 | .ndo_change_mtu = mlx4_en_change_mtu, |
| 2420 | .ndo_tx_timeout = mlx4_en_tx_timeout, |
| 2421 | .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid, |
| 2422 | .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid, |
| 2423 | .ndo_set_vf_mac = mlx4_en_set_vf_mac, |
Rony Efraim | 3f7fb02 | 2013-04-25 05:22:28 +0000 | [diff] [blame] | 2424 | .ndo_set_vf_vlan = mlx4_en_set_vf_vlan, |
Rony Efraim | e6b6a23 | 2013-04-25 05:22:29 +0000 | [diff] [blame] | 2425 | .ndo_set_vf_spoofchk = mlx4_en_set_vf_spoofchk, |
Rony Efraim | 948e306 | 2013-06-13 13:19:11 +0300 | [diff] [blame] | 2426 | .ndo_set_vf_link_state = mlx4_en_set_vf_link_state, |
Rony Efraim | 2cccb9e | 2013-04-25 05:22:30 +0000 | [diff] [blame] | 2427 | .ndo_get_vf_config = mlx4_en_get_vf_config, |
Rony Efraim | 8f7ba3c | 2013-04-25 05:22:27 +0000 | [diff] [blame] | 2428 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2429 | .ndo_poll_controller = mlx4_en_netpoll, |
| 2430 | #endif |
| 2431 | .ndo_set_features = mlx4_en_set_features, |
| 2432 | .ndo_setup_tc = mlx4_en_setup_tc, |
| 2433 | #ifdef CONFIG_RFS_ACCEL |
| 2434 | .ndo_rx_flow_steer = mlx4_en_filter_rfs, |
| 2435 | #endif |
Hadar Hen Zion | 84c8640 | 2013-12-19 21:20:13 +0200 | [diff] [blame] | 2436 | .ndo_get_phys_port_id = mlx4_en_get_phys_port_id, |
Or Gerlitz | 9737c6a | 2014-11-18 17:51:27 +0200 | [diff] [blame] | 2437 | #ifdef CONFIG_MLX4_EN_VXLAN |
| 2438 | .ndo_add_vxlan_port = mlx4_en_add_vxlan_port, |
| 2439 | .ndo_del_vxlan_port = mlx4_en_del_vxlan_port, |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 2440 | .ndo_features_check = mlx4_en_features_check, |
Or Gerlitz | 9737c6a | 2014-11-18 17:51:27 +0200 | [diff] [blame] | 2441 | #endif |
Rony Efraim | 8f7ba3c | 2013-04-25 05:22:27 +0000 | [diff] [blame] | 2442 | }; |
| 2443 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2444 | int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, |
| 2445 | struct mlx4_en_port_profile *prof) |
| 2446 | { |
| 2447 | struct net_device *dev; |
| 2448 | struct mlx4_en_priv *priv; |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 2449 | int i; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2450 | int err; |
Or Gerlitz | ef96f7d | 2013-06-04 05:13:28 +0000 | [diff] [blame] | 2451 | u64 mac_u64; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2452 | |
Tom Herbert | f1593d2 | 2011-01-09 19:36:36 +0000 | [diff] [blame] | 2453 | dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv), |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 2454 | MAX_TX_RINGS, MAX_RX_RINGS); |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 2455 | if (dev == NULL) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2456 | return -ENOMEM; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2457 | |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 2458 | netif_set_real_num_tx_queues(dev, prof->tx_ring_num); |
| 2459 | netif_set_real_num_rx_queues(dev, prof->rx_ring_num); |
| 2460 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2461 | SET_NETDEV_DEV(dev, &mdev->dev->pdev->dev); |
Amir Vadai | 76a066f | 2014-02-25 18:17:51 +0200 | [diff] [blame] | 2462 | dev->dev_port = port - 1; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2463 | |
| 2464 | /* |
| 2465 | * Initialize driver private data |
| 2466 | */ |
| 2467 | |
| 2468 | priv = netdev_priv(dev); |
| 2469 | memset(priv, 0, sizeof(struct mlx4_en_priv)); |
Eugenia Emantayev | 207af6c | 2014-10-27 11:37:46 +0200 | [diff] [blame] | 2470 | spin_lock_init(&priv->stats_lock); |
| 2471 | INIT_WORK(&priv->rx_mode_task, mlx4_en_do_set_rx_mode); |
| 2472 | INIT_WORK(&priv->watchdog_task, mlx4_en_restart); |
| 2473 | INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate); |
| 2474 | INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats); |
| 2475 | INIT_DELAYED_WORK(&priv->service_task, mlx4_en_service_task); |
| 2476 | #ifdef CONFIG_MLX4_EN_VXLAN |
| 2477 | INIT_WORK(&priv->vxlan_add_task, mlx4_en_add_vxlan_offloads); |
| 2478 | INIT_WORK(&priv->vxlan_del_task, mlx4_en_del_vxlan_offloads); |
| 2479 | #endif |
| 2480 | #ifdef CONFIG_RFS_ACCEL |
| 2481 | INIT_LIST_HEAD(&priv->filters); |
| 2482 | spin_lock_init(&priv->filters_lock); |
| 2483 | #endif |
| 2484 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2485 | priv->dev = dev; |
| 2486 | priv->mdev = mdev; |
Yevgeny Petrilin | ebf8c9a | 2012-03-06 04:03:34 +0000 | [diff] [blame] | 2487 | priv->ddev = &mdev->pdev->dev; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2488 | priv->prof = prof; |
| 2489 | priv->port = port; |
| 2490 | priv->port_up = false; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2491 | priv->flags = prof->flags; |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 2492 | priv->pflags = MLX4_EN_PRIV_FLAGS_BLUEFLAME; |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 2493 | priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE | |
| 2494 | MLX4_WQE_CTRL_SOLICITED); |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 2495 | priv->num_tx_rings_p_up = mdev->profile.num_tx_rings_p_up; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2496 | priv->tx_ring_num = prof->tx_ring_num; |
Amir Vadai | fbc6daf | 2014-07-08 11:28:12 +0300 | [diff] [blame] | 2497 | priv->tx_work_limit = MLX4_EN_DEFAULT_TX_WORK; |
Eric Dumazet | bd635c3 | 2014-11-22 17:24:19 -0800 | [diff] [blame] | 2498 | netdev_rss_key_fill(priv->rss_key, sizeof(priv->rss_key)); |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 2499 | |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 2500 | priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring *) * MAX_TX_RINGS, |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 2501 | GFP_KERNEL); |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 2502 | if (!priv->tx_ring) { |
| 2503 | err = -ENOMEM; |
| 2504 | goto out; |
| 2505 | } |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 2506 | priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq *) * MAX_TX_RINGS, |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 2507 | GFP_KERNEL); |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 2508 | if (!priv->tx_cq) { |
| 2509 | err = -ENOMEM; |
| 2510 | goto out; |
| 2511 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2512 | priv->rx_ring_num = prof->rx_ring_num; |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 2513 | priv->cqe_factor = (mdev->dev->caps.cqe_size == 64) ? 1 : 0; |
Ido Shamay | b1b6b4d | 2014-09-18 11:51:01 +0300 | [diff] [blame] | 2514 | priv->cqe_size = mdev->dev->caps.cqe_size; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2515 | priv->mac_index = -1; |
| 2516 | priv->msg_enable = MLX4_EN_MSG_LEVEL; |
Amir Vadai | 564c274 | 2012-04-04 21:33:26 +0000 | [diff] [blame] | 2517 | #ifdef CONFIG_MLX4_EN_DCB |
Or Gerlitz | 540b3a3 | 2013-04-07 03:44:07 +0000 | [diff] [blame] | 2518 | if (!mlx4_is_slave(priv->mdev->dev)) { |
| 2519 | if (mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_SET_ETH_SCHED) { |
| 2520 | dev->dcbnl_ops = &mlx4_en_dcbnl_ops; |
| 2521 | } else { |
| 2522 | en_info(priv, "enabling only PFC DCB ops\n"); |
| 2523 | dev->dcbnl_ops = &mlx4_en_dcbnl_pfc_ops; |
| 2524 | } |
| 2525 | } |
Amir Vadai | 564c274 | 2012-04-04 21:33:26 +0000 | [diff] [blame] | 2526 | #endif |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2527 | |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 2528 | for (i = 0; i < MLX4_EN_MAC_HASH_SIZE; ++i) |
| 2529 | INIT_HLIST_HEAD(&priv->mac_hash[i]); |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 2530 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2531 | /* Query for default mac and max mtu */ |
| 2532 | priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port]; |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame] | 2533 | |
Shani Michaeli | f8c6455 | 2014-11-09 13:51:53 +0200 | [diff] [blame] | 2534 | if (mdev->dev->caps.rx_checksum_flags_port[priv->port] & |
| 2535 | MLX4_RX_CSUM_MODE_VAL_NON_TCP_UDP) |
| 2536 | priv->flags |= MLX4_EN_FLAG_RX_CSUM_NON_TCP_UDP; |
| 2537 | |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame] | 2538 | /* Set default MAC */ |
| 2539 | dev->addr_len = ETH_ALEN; |
| 2540 | mlx4_en_u64_to_mac(dev->dev_addr, mdev->dev->caps.def_mac[priv->port]); |
| 2541 | if (!is_valid_ether_addr(dev->dev_addr)) { |
Or Gerlitz | ef96f7d | 2013-06-04 05:13:28 +0000 | [diff] [blame] | 2542 | if (mlx4_is_slave(priv->mdev->dev)) { |
| 2543 | eth_hw_addr_random(dev); |
| 2544 | en_warn(priv, "Assigned random MAC address %pM\n", dev->dev_addr); |
Eugenia Emantayev | 9813337 | 2014-03-02 10:25:01 +0200 | [diff] [blame] | 2545 | mac_u64 = mlx4_mac_to_u64(dev->dev_addr); |
Or Gerlitz | ef96f7d | 2013-06-04 05:13:28 +0000 | [diff] [blame] | 2546 | mdev->dev->caps.def_mac[priv->port] = mac_u64; |
| 2547 | } else { |
| 2548 | en_err(priv, "Port: %d, invalid mac burned: %pM, quiting\n", |
| 2549 | priv->port, dev->dev_addr); |
| 2550 | err = -EINVAL; |
| 2551 | goto out; |
| 2552 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Noa Osherovich | 2695bab | 2014-07-08 11:25:24 +0300 | [diff] [blame] | 2555 | memcpy(priv->current_mac, dev->dev_addr, sizeof(priv->current_mac)); |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame] | 2556 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2557 | priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) + |
| 2558 | DS_SIZE * MLX4_EN_MAX_RX_FRAGS); |
| 2559 | err = mlx4_en_alloc_resources(priv); |
| 2560 | if (err) |
| 2561 | goto out; |
| 2562 | |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 2563 | /* Initialize time stamping config */ |
| 2564 | priv->hwtstamp_config.flags = 0; |
| 2565 | priv->hwtstamp_config.tx_type = HWTSTAMP_TX_OFF; |
| 2566 | priv->hwtstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; |
| 2567 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2568 | /* Allocate page for receive rings */ |
| 2569 | err = mlx4_alloc_hwq_res(mdev->dev, &priv->res, |
| 2570 | MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE); |
| 2571 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 2572 | en_err(priv, "Failed to allocate page for rx qps\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2573 | goto out; |
| 2574 | } |
| 2575 | priv->allocated = 1; |
| 2576 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2577 | /* |
| 2578 | * Initialize netdev entry points |
| 2579 | */ |
Rony Efraim | 8f7ba3c | 2013-04-25 05:22:27 +0000 | [diff] [blame] | 2580 | if (mlx4_is_master(priv->mdev->dev)) |
| 2581 | dev->netdev_ops = &mlx4_netdev_ops_master; |
| 2582 | else |
| 2583 | dev->netdev_ops = &mlx4_netdev_ops; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2584 | dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT; |
Ben Hutchings | 1eb63a2 | 2010-09-27 08:29:34 +0000 | [diff] [blame] | 2585 | netif_set_real_num_tx_queues(dev, priv->tx_ring_num); |
| 2586 | netif_set_real_num_rx_queues(dev, priv->rx_ring_num); |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 2587 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 2588 | dev->ethtool_ops = &mlx4_en_ethtool_ops; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2589 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2590 | /* |
| 2591 | * Set driver features |
| 2592 | */ |
Michał Mirosław | c8c64cf | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 2593 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
| 2594 | if (mdev->LSO_support) |
| 2595 | dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6; |
| 2596 | |
| 2597 | dev->vlan_features = dev->hw_features; |
| 2598 | |
Yevgeny Petrilin | ad86107 | 2011-10-18 01:51:24 +0000 | [diff] [blame] | 2599 | dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH; |
Michał Mirosław | c8c64cf | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 2600 | dev->features = dev->hw_features | NETIF_F_HIGHDMA | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2601 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX | |
| 2602 | NETIF_F_HW_VLAN_CTAG_FILTER; |
Saeed Mahameed | 537f6f9 | 2014-10-27 11:37:43 +0200 | [diff] [blame] | 2603 | dev->hw_features |= NETIF_F_LOOPBACK | |
| 2604 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2605 | |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 2606 | if (mdev->dev->caps.steering_mode == |
Matan Barak | 7d077cd | 2014-12-11 10:58:00 +0200 | [diff] [blame] | 2607 | MLX4_STEERING_MODE_DEVICE_MANAGED && |
| 2608 | mdev->dev->caps.dmfs_high_steer_mode != MLX4_STEERING_DMFS_A0_STATIC) |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 2609 | dev->hw_features |= NETIF_F_NTUPLE; |
| 2610 | |
Yan Burman | cc5387f | 2013-02-07 02:25:26 +0000 | [diff] [blame] | 2611 | if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_A0) |
| 2612 | dev->priv_flags |= IFF_UNICAST_FLT; |
| 2613 | |
Eyal Perry | 947cbb0 | 2014-12-02 18:12:11 +0200 | [diff] [blame] | 2614 | /* Setting a default hash function value */ |
| 2615 | if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_TOP) { |
| 2616 | priv->rss_hash_fn = ETH_RSS_HASH_TOP; |
| 2617 | } else if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_XOR) { |
| 2618 | priv->rss_hash_fn = ETH_RSS_HASH_XOR; |
| 2619 | } else { |
| 2620 | en_warn(priv, |
| 2621 | "No RSS hash capabilities exposed, using Toeplitz\n"); |
| 2622 | priv->rss_hash_fn = ETH_RSS_HASH_TOP; |
| 2623 | } |
| 2624 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2625 | mdev->pndev[port] = dev; |
| 2626 | |
| 2627 | netif_carrier_off(dev); |
Eugenia Emantayev | 4801ae7 | 2013-06-25 12:09:31 +0300 | [diff] [blame] | 2628 | mlx4_en_set_default_moderation(priv); |
| 2629 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2630 | err = register_netdev(dev); |
| 2631 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 2632 | en_err(priv, "Netdev registration failed for port %d\n", port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2633 | goto out; |
| 2634 | } |
Alexander Guller | 4234144 | 2011-10-09 05:29:35 +0000 | [diff] [blame] | 2635 | priv->registered = 1; |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 2636 | |
| 2637 | en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num); |
| 2638 | en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num); |
| 2639 | |
Yan Burman | 79aeacc | 2013-02-07 02:25:19 +0000 | [diff] [blame] | 2640 | mlx4_en_update_loopback_state(priv->dev, priv->dev->features); |
| 2641 | |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 2642 | /* Configure port */ |
Yevgeny Petrilin | 5c8e904 | 2012-06-25 00:24:11 +0000 | [diff] [blame] | 2643 | mlx4_en_calc_rx_buf(dev); |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 2644 | err = mlx4_SET_PORT_general(mdev->dev, priv->port, |
Yevgeny Petrilin | 5c8e904 | 2012-06-25 00:24:11 +0000 | [diff] [blame] | 2645 | priv->rx_skb_size + ETH_FCS_LEN, |
| 2646 | prof->tx_pause, prof->tx_ppp, |
| 2647 | prof->rx_pause, prof->rx_ppp); |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 2648 | if (err) { |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 2649 | en_err(priv, "Failed setting port general configurations for port %d, with error %d\n", |
| 2650 | priv->port, err); |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 2651 | goto out; |
| 2652 | } |
| 2653 | |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 2654 | if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) { |
Or Gerlitz | 1b136de | 2014-03-27 14:02:04 +0200 | [diff] [blame] | 2655 | err = mlx4_SET_PORT_VXLAN(mdev->dev, priv->port, VXLAN_STEER_BY_OUTER_MAC, 1); |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 2656 | if (err) { |
| 2657 | en_err(priv, "Failed setting port L2 tunnel configuration, err %d\n", |
| 2658 | err); |
| 2659 | goto out; |
| 2660 | } |
| 2661 | } |
| 2662 | |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 2663 | /* Init port */ |
| 2664 | en_warn(priv, "Initializing port\n"); |
| 2665 | err = mlx4_INIT_PORT(mdev->dev, priv->port); |
| 2666 | if (err) { |
| 2667 | en_err(priv, "Failed Initializing port\n"); |
| 2668 | goto out; |
| 2669 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2670 | queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY); |
Amir Vadai | dc8142e | 2013-04-25 05:22:24 +0000 | [diff] [blame] | 2671 | |
| 2672 | if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) |
| 2673 | queue_delayed_work(mdev->workqueue, &priv->service_task, |
| 2674 | SERVICE_TASK_DELAY); |
| 2675 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2676 | return 0; |
| 2677 | |
| 2678 | out: |
| 2679 | mlx4_en_destroy_netdev(dev); |
| 2680 | return err; |
| 2681 | } |
| 2682 | |
Saeed Mahameed | 537f6f9 | 2014-10-27 11:37:43 +0200 | [diff] [blame] | 2683 | int mlx4_en_reset_config(struct net_device *dev, |
| 2684 | struct hwtstamp_config ts_config, |
| 2685 | netdev_features_t features) |
| 2686 | { |
| 2687 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 2688 | struct mlx4_en_dev *mdev = priv->mdev; |
| 2689 | int port_up = 0; |
| 2690 | int err = 0; |
| 2691 | |
| 2692 | if (priv->hwtstamp_config.tx_type == ts_config.tx_type && |
| 2693 | priv->hwtstamp_config.rx_filter == ts_config.rx_filter && |
| 2694 | !DEV_FEATURE_CHANGED(dev, features, NETIF_F_HW_VLAN_CTAG_RX)) |
| 2695 | return 0; /* Nothing to change */ |
| 2696 | |
| 2697 | if (DEV_FEATURE_CHANGED(dev, features, NETIF_F_HW_VLAN_CTAG_RX) && |
| 2698 | (features & NETIF_F_HW_VLAN_CTAG_RX) && |
| 2699 | (priv->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE)) { |
| 2700 | en_warn(priv, "Can't turn ON rx vlan offload while time-stamping rx filter is ON\n"); |
| 2701 | return -EINVAL; |
| 2702 | } |
| 2703 | |
| 2704 | mutex_lock(&mdev->state_lock); |
| 2705 | if (priv->port_up) { |
| 2706 | port_up = 1; |
| 2707 | mlx4_en_stop_port(dev, 1); |
| 2708 | } |
| 2709 | |
| 2710 | mlx4_en_free_resources(priv); |
| 2711 | |
| 2712 | en_warn(priv, "Changing device configuration rx filter(%x) rx vlan(%x)\n", |
| 2713 | ts_config.rx_filter, !!(features & NETIF_F_HW_VLAN_CTAG_RX)); |
| 2714 | |
| 2715 | priv->hwtstamp_config.tx_type = ts_config.tx_type; |
| 2716 | priv->hwtstamp_config.rx_filter = ts_config.rx_filter; |
| 2717 | |
| 2718 | if (DEV_FEATURE_CHANGED(dev, features, NETIF_F_HW_VLAN_CTAG_RX)) { |
| 2719 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2720 | dev->features |= NETIF_F_HW_VLAN_CTAG_RX; |
| 2721 | else |
| 2722 | dev->features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
| 2723 | } else if (ts_config.rx_filter == HWTSTAMP_FILTER_NONE) { |
| 2724 | /* RX time-stamping is OFF, update the RX vlan offload |
| 2725 | * to the latest wanted state |
| 2726 | */ |
| 2727 | if (dev->wanted_features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2728 | dev->features |= NETIF_F_HW_VLAN_CTAG_RX; |
| 2729 | else |
| 2730 | dev->features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
| 2731 | } |
| 2732 | |
| 2733 | /* RX vlan offload and RX time-stamping can't co-exist ! |
| 2734 | * Regardless of the caller's choice, |
| 2735 | * Turn Off RX vlan offload in case of time-stamping is ON |
| 2736 | */ |
| 2737 | if (ts_config.rx_filter != HWTSTAMP_FILTER_NONE) { |
| 2738 | if (dev->features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2739 | en_warn(priv, "Turning off RX vlan offload since RX time-stamping is ON\n"); |
| 2740 | dev->features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
| 2741 | } |
| 2742 | |
| 2743 | err = mlx4_en_alloc_resources(priv); |
| 2744 | if (err) { |
| 2745 | en_err(priv, "Failed reallocating port resources\n"); |
| 2746 | goto out; |
| 2747 | } |
| 2748 | if (port_up) { |
| 2749 | err = mlx4_en_start_port(dev); |
| 2750 | if (err) |
| 2751 | en_err(priv, "Failed starting port\n"); |
| 2752 | } |
| 2753 | |
| 2754 | out: |
| 2755 | mutex_unlock(&mdev->state_lock); |
| 2756 | netdev_features_change(dev); |
| 2757 | return err; |
| 2758 | } |