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