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