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