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 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 423 | u64 mlx4_en_mac_to_u64(u8 *addr) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 424 | { |
| 425 | u64 mac = 0; |
| 426 | int i; |
| 427 | |
| 428 | for (i = 0; i < ETH_ALEN; i++) { |
| 429 | mac <<= 8; |
| 430 | mac |= addr[i]; |
| 431 | } |
| 432 | return mac; |
| 433 | } |
| 434 | |
| 435 | static int mlx4_en_set_mac(struct net_device *dev, void *addr) |
| 436 | { |
| 437 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 438 | struct mlx4_en_dev *mdev = priv->mdev; |
| 439 | struct sockaddr *saddr = addr; |
| 440 | |
| 441 | if (!is_valid_ether_addr(saddr->sa_data)) |
| 442 | return -EADDRNOTAVAIL; |
| 443 | |
| 444 | memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 445 | queue_work(mdev->workqueue, &priv->mac_task); |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | static void mlx4_en_do_set_mac(struct work_struct *work) |
| 450 | { |
| 451 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 452 | mac_task); |
| 453 | struct mlx4_en_dev *mdev = priv->mdev; |
| 454 | int err = 0; |
| 455 | |
| 456 | mutex_lock(&mdev->state_lock); |
| 457 | if (priv->port_up) { |
| 458 | /* Remove old MAC and insert the new one */ |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame^] | 459 | u64 mac = mlx4_en_mac_to_u64(priv->dev->dev_addr); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 460 | err = mlx4_replace_mac(mdev->dev, priv->port, |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame^] | 461 | priv->base_qpn, mac); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 462 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 463 | en_err(priv, "Failed changing HW MAC address\n"); |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame^] | 464 | memcpy(priv->prev_mac, priv->dev->dev_addr, |
| 465 | sizeof(priv->prev_mac)); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 466 | } else |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 467 | en_dbg(HW, priv, "Port is down while " |
| 468 | "registering mac, exiting...\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 469 | |
| 470 | mutex_unlock(&mdev->state_lock); |
| 471 | } |
| 472 | |
| 473 | static void mlx4_en_clear_list(struct net_device *dev) |
| 474 | { |
| 475 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 476 | struct mlx4_en_mc_list *tmp, *mc_to_del; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 477 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 478 | list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) { |
| 479 | list_del(&mc_to_del->list); |
| 480 | kfree(mc_to_del); |
| 481 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static void mlx4_en_cache_mclist(struct net_device *dev) |
| 485 | { |
| 486 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 487 | struct netdev_hw_addr *ha; |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 488 | struct mlx4_en_mc_list *tmp; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 489 | |
Alexander Guller | 0e03567 | 2011-12-19 04:02:58 +0000 | [diff] [blame] | 490 | mlx4_en_clear_list(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 491 | netdev_for_each_mc_addr(ha, dev) { |
| 492 | tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC); |
| 493 | if (!tmp) { |
| 494 | en_err(priv, "failed to allocate multicast list\n"); |
| 495 | mlx4_en_clear_list(dev); |
| 496 | return; |
| 497 | } |
| 498 | memcpy(tmp->addr, ha->addr, ETH_ALEN); |
| 499 | list_add_tail(&tmp->list, &priv->mc_list); |
| 500 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 503 | static void update_mclist_flags(struct mlx4_en_priv *priv, |
| 504 | struct list_head *dst, |
| 505 | struct list_head *src) |
| 506 | { |
| 507 | struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc; |
| 508 | bool found; |
| 509 | |
| 510 | /* Find all the entries that should be removed from dst, |
| 511 | * These are the entries that are not found in src |
| 512 | */ |
| 513 | list_for_each_entry(dst_tmp, dst, list) { |
| 514 | found = false; |
| 515 | list_for_each_entry(src_tmp, src, list) { |
| 516 | if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) { |
| 517 | found = true; |
| 518 | break; |
| 519 | } |
| 520 | } |
| 521 | if (!found) |
| 522 | dst_tmp->action = MCLIST_REM; |
| 523 | } |
| 524 | |
| 525 | /* Add entries that exist in src but not in dst |
| 526 | * mark them as need to add |
| 527 | */ |
| 528 | list_for_each_entry(src_tmp, src, list) { |
| 529 | found = false; |
| 530 | list_for_each_entry(dst_tmp, dst, list) { |
| 531 | if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) { |
| 532 | dst_tmp->action = MCLIST_NONE; |
| 533 | found = true; |
| 534 | break; |
| 535 | } |
| 536 | } |
| 537 | if (!found) { |
| 538 | new_mc = kmalloc(sizeof(struct mlx4_en_mc_list), |
| 539 | GFP_KERNEL); |
| 540 | if (!new_mc) { |
| 541 | en_err(priv, "Failed to allocate current multicast list\n"); |
| 542 | return; |
| 543 | } |
| 544 | memcpy(new_mc, src_tmp, |
| 545 | sizeof(struct mlx4_en_mc_list)); |
| 546 | new_mc->action = MCLIST_ADD; |
| 547 | list_add_tail(&new_mc->list, dst); |
| 548 | } |
| 549 | } |
| 550 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 551 | |
| 552 | static void mlx4_en_set_multicast(struct net_device *dev) |
| 553 | { |
| 554 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 555 | |
| 556 | if (!priv->port_up) |
| 557 | return; |
| 558 | |
| 559 | queue_work(priv->mdev->workqueue, &priv->mcast_task); |
| 560 | } |
| 561 | |
| 562 | static void mlx4_en_do_set_multicast(struct work_struct *work) |
| 563 | { |
| 564 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 565 | mcast_task); |
| 566 | struct mlx4_en_dev *mdev = priv->mdev; |
| 567 | struct net_device *dev = priv->dev; |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 568 | struct mlx4_en_mc_list *mclist, *tmp; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 569 | u64 mcast_addr = 0; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 570 | u8 mc_list[16] = {0}; |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 571 | int err = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 572 | |
| 573 | mutex_lock(&mdev->state_lock); |
| 574 | if (!mdev->device_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 575 | en_dbg(HW, priv, "Card is not up, " |
| 576 | "ignoring multicast change.\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 577 | goto out; |
| 578 | } |
| 579 | if (!priv->port_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 580 | en_dbg(HW, priv, "Port is down, " |
| 581 | "ignoring multicast change.\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 582 | goto out; |
| 583 | } |
| 584 | |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 585 | if (!netif_carrier_ok(dev)) { |
| 586 | if (!mlx4_en_QUERY_PORT(mdev, priv->port)) { |
| 587 | if (priv->port_state.link_state) { |
| 588 | priv->last_link_state = MLX4_DEV_EVENT_PORT_UP; |
| 589 | netif_carrier_on(dev); |
| 590 | en_dbg(LINK, priv, "Link Up\n"); |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 595 | /* |
| 596 | * Promsicuous mode: disable all filters |
| 597 | */ |
| 598 | |
| 599 | if (dev->flags & IFF_PROMISC) { |
| 600 | if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) { |
| 601 | if (netif_msg_rx_status(priv)) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 602 | en_warn(priv, "Entering promiscuous mode\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 603 | priv->flags |= MLX4_EN_FLAG_PROMISC; |
| 604 | |
| 605 | /* Enable promiscouos mode */ |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 606 | switch (mdev->dev->caps.steering_mode) { |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 607 | case MLX4_STEERING_MODE_DEVICE_MANAGED: |
| 608 | err = mlx4_flow_steer_promisc_add(mdev->dev, |
| 609 | priv->port, |
| 610 | priv->base_qpn, |
| 611 | MLX4_FS_PROMISC_UPLINK); |
| 612 | if (err) |
| 613 | en_err(priv, "Failed enabling promiscuous mode\n"); |
| 614 | priv->flags |= MLX4_EN_FLAG_MC_PROMISC; |
| 615 | break; |
| 616 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 617 | case MLX4_STEERING_MODE_B0: |
| 618 | err = mlx4_unicast_promisc_add(mdev->dev, |
| 619 | priv->base_qpn, |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 620 | priv->port); |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 621 | if (err) |
| 622 | en_err(priv, "Failed enabling unicast promiscuous mode\n"); |
| 623 | |
| 624 | /* Add the default qp number as multicast |
| 625 | * promisc |
| 626 | */ |
| 627 | if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) { |
| 628 | err = mlx4_multicast_promisc_add(mdev->dev, |
| 629 | priv->base_qpn, |
| 630 | priv->port); |
| 631 | if (err) |
| 632 | en_err(priv, "Failed enabling multicast promiscuous mode\n"); |
| 633 | priv->flags |= MLX4_EN_FLAG_MC_PROMISC; |
| 634 | } |
| 635 | break; |
| 636 | |
| 637 | case MLX4_STEERING_MODE_A0: |
| 638 | err = mlx4_SET_PORT_qpn_calc(mdev->dev, |
| 639 | priv->port, |
| 640 | priv->base_qpn, |
| 641 | 1); |
| 642 | if (err) |
| 643 | en_err(priv, "Failed enabling promiscuous mode\n"); |
| 644 | break; |
| 645 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 646 | |
| 647 | /* Disable port multicast filter (unconditionally) */ |
| 648 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 649 | 0, MLX4_MCAST_DISABLE); |
| 650 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 651 | en_err(priv, "Failed disabling " |
| 652 | "multicast filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 653 | |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 654 | /* Disable port VLAN filter */ |
| 655 | err = mlx4_SET_VLAN_FLTR(mdev->dev, priv); |
| 656 | if (err) |
| 657 | en_err(priv, "Failed disabling VLAN filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 658 | } |
| 659 | goto out; |
| 660 | } |
| 661 | |
| 662 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 663 | * Not in promiscuous mode |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 664 | */ |
| 665 | |
| 666 | if (priv->flags & MLX4_EN_FLAG_PROMISC) { |
| 667 | if (netif_msg_rx_status(priv)) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 668 | en_warn(priv, "Leaving promiscuous mode\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 669 | priv->flags &= ~MLX4_EN_FLAG_PROMISC; |
| 670 | |
| 671 | /* Disable promiscouos mode */ |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 672 | switch (mdev->dev->caps.steering_mode) { |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 673 | case MLX4_STEERING_MODE_DEVICE_MANAGED: |
| 674 | err = mlx4_flow_steer_promisc_remove(mdev->dev, |
| 675 | priv->port, |
| 676 | MLX4_FS_PROMISC_UPLINK); |
| 677 | if (err) |
| 678 | en_err(priv, "Failed disabling promiscuous mode\n"); |
| 679 | priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; |
| 680 | break; |
| 681 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 682 | case MLX4_STEERING_MODE_B0: |
| 683 | err = mlx4_unicast_promisc_remove(mdev->dev, |
| 684 | priv->base_qpn, |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 685 | priv->port); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 686 | if (err) |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 687 | en_err(priv, "Failed disabling unicast promiscuous mode\n"); |
| 688 | /* Disable Multicast promisc */ |
| 689 | if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { |
| 690 | err = mlx4_multicast_promisc_remove(mdev->dev, |
| 691 | priv->base_qpn, |
| 692 | priv->port); |
| 693 | if (err) |
| 694 | en_err(priv, "Failed disabling multicast promiscuous mode\n"); |
| 695 | priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; |
| 696 | } |
| 697 | break; |
| 698 | |
| 699 | case MLX4_STEERING_MODE_A0: |
| 700 | err = mlx4_SET_PORT_qpn_calc(mdev->dev, |
| 701 | priv->port, |
| 702 | priv->base_qpn, 0); |
| 703 | if (err) |
| 704 | en_err(priv, "Failed disabling promiscuous mode\n"); |
| 705 | break; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 708 | /* Enable port VLAN filter */ |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 709 | err = mlx4_SET_VLAN_FLTR(mdev->dev, priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 710 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 711 | en_err(priv, "Failed enabling VLAN filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /* Enable/disable the multicast filter according to IFF_ALLMULTI */ |
| 715 | if (dev->flags & IFF_ALLMULTI) { |
| 716 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 717 | 0, MLX4_MCAST_DISABLE); |
| 718 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 719 | en_err(priv, "Failed disabling multicast filter\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 720 | |
| 721 | /* Add the default qp number as multicast promisc */ |
| 722 | if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) { |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 723 | switch (mdev->dev->caps.steering_mode) { |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 724 | case MLX4_STEERING_MODE_DEVICE_MANAGED: |
| 725 | err = mlx4_flow_steer_promisc_add(mdev->dev, |
| 726 | priv->port, |
| 727 | priv->base_qpn, |
| 728 | MLX4_FS_PROMISC_ALL_MULTI); |
| 729 | break; |
| 730 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 731 | case MLX4_STEERING_MODE_B0: |
| 732 | err = mlx4_multicast_promisc_add(mdev->dev, |
| 733 | priv->base_qpn, |
| 734 | priv->port); |
| 735 | break; |
| 736 | |
| 737 | case MLX4_STEERING_MODE_A0: |
| 738 | break; |
| 739 | } |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 740 | if (err) |
| 741 | en_err(priv, "Failed entering multicast promisc mode\n"); |
| 742 | priv->flags |= MLX4_EN_FLAG_MC_PROMISC; |
| 743 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 744 | } else { |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 745 | /* Disable Multicast promisc */ |
| 746 | if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 747 | switch (mdev->dev->caps.steering_mode) { |
Hadar Hen Zion | 592e49d | 2012-07-05 04:03:48 +0000 | [diff] [blame] | 748 | case MLX4_STEERING_MODE_DEVICE_MANAGED: |
| 749 | err = mlx4_flow_steer_promisc_remove(mdev->dev, |
| 750 | priv->port, |
| 751 | MLX4_FS_PROMISC_ALL_MULTI); |
| 752 | break; |
| 753 | |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame] | 754 | case MLX4_STEERING_MODE_B0: |
| 755 | err = mlx4_multicast_promisc_remove(mdev->dev, |
| 756 | priv->base_qpn, |
| 757 | priv->port); |
| 758 | break; |
| 759 | |
| 760 | case MLX4_STEERING_MODE_A0: |
| 761 | break; |
| 762 | } |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 763 | if (err) |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 764 | en_err(priv, "Failed disabling multicast promiscuous mode\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 765 | priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; |
| 766 | } |
Jiri Pirko | ff6e216 | 2010-03-01 05:09:14 +0000 | [diff] [blame] | 767 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 768 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 769 | 0, MLX4_MCAST_DISABLE); |
| 770 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 771 | en_err(priv, "Failed disabling multicast filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 772 | |
| 773 | /* Flush mcast filter and init it with broadcast address */ |
| 774 | mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST, |
| 775 | 1, MLX4_MCAST_CONFIG); |
| 776 | |
| 777 | /* Update multicast list - we cache all addresses so they won't |
| 778 | * change while HW is updated holding the command semaphor */ |
Eugenia Emantayev | dbd501a | 2013-01-24 01:54:16 +0000 | [diff] [blame] | 779 | netif_addr_lock_bh(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 780 | mlx4_en_cache_mclist(dev); |
Eugenia Emantayev | dbd501a | 2013-01-24 01:54:16 +0000 | [diff] [blame] | 781 | netif_addr_unlock_bh(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 782 | list_for_each_entry(mclist, &priv->mc_list, list) { |
| 783 | mcast_addr = mlx4_en_mac_to_u64(mclist->addr); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 784 | mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, |
| 785 | mcast_addr, 0, MLX4_MCAST_CONFIG); |
| 786 | } |
| 787 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 788 | 0, MLX4_MCAST_ENABLE); |
| 789 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 790 | en_err(priv, "Failed enabling multicast filter\n"); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 791 | |
| 792 | update_mclist_flags(priv, &priv->curr_list, &priv->mc_list); |
| 793 | list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { |
| 794 | if (mclist->action == MCLIST_REM) { |
| 795 | /* detach this address and delete from list */ |
| 796 | memcpy(&mc_list[10], mclist->addr, ETH_ALEN); |
| 797 | mc_list[5] = priv->port; |
| 798 | err = mlx4_multicast_detach(mdev->dev, |
| 799 | &priv->rss_map.indir_qp, |
| 800 | mc_list, |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 801 | MLX4_PROT_ETH, |
| 802 | mclist->reg_id); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 803 | if (err) |
| 804 | en_err(priv, "Fail to detach multicast address\n"); |
| 805 | |
| 806 | /* remove from list */ |
| 807 | list_del(&mclist->list); |
| 808 | kfree(mclist); |
Dan Carpenter | 9c64508 | 2012-07-10 20:34:07 +0000 | [diff] [blame] | 809 | } else if (mclist->action == MCLIST_ADD) { |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 810 | /* attach the address */ |
| 811 | memcpy(&mc_list[10], mclist->addr, ETH_ALEN); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 812 | /* needed for B0 steering support */ |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 813 | mc_list[5] = priv->port; |
| 814 | err = mlx4_multicast_attach(mdev->dev, |
| 815 | &priv->rss_map.indir_qp, |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 816 | mc_list, |
| 817 | priv->port, 0, |
| 818 | MLX4_PROT_ETH, |
| 819 | &mclist->reg_id); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 820 | if (err) |
| 821 | en_err(priv, "Fail to attach multicast address\n"); |
| 822 | |
| 823 | } |
| 824 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 825 | } |
| 826 | out: |
| 827 | mutex_unlock(&mdev->state_lock); |
| 828 | } |
| 829 | |
| 830 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 831 | static void mlx4_en_netpoll(struct net_device *dev) |
| 832 | { |
| 833 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 834 | struct mlx4_en_cq *cq; |
| 835 | unsigned long flags; |
| 836 | int i; |
| 837 | |
| 838 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 839 | cq = &priv->rx_cq[i]; |
| 840 | spin_lock_irqsave(&cq->lock, flags); |
| 841 | napi_synchronize(&cq->napi); |
| 842 | mlx4_en_process_rx_cq(dev, cq, 0); |
| 843 | spin_unlock_irqrestore(&cq->lock, flags); |
| 844 | } |
| 845 | } |
| 846 | #endif |
| 847 | |
| 848 | static void mlx4_en_tx_timeout(struct net_device *dev) |
| 849 | { |
| 850 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 851 | struct mlx4_en_dev *mdev = priv->mdev; |
| 852 | |
| 853 | if (netif_msg_timer(priv)) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 854 | en_warn(priv, "Tx timeout called on port:%d\n", priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 855 | |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 856 | priv->port_stats.tx_timeout++; |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 857 | en_dbg(DRV, priv, "Scheduling watchdog\n"); |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 858 | queue_work(mdev->workqueue, &priv->watchdog_task); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | |
| 862 | static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev) |
| 863 | { |
| 864 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 865 | |
| 866 | spin_lock_bh(&priv->stats_lock); |
| 867 | memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats)); |
| 868 | spin_unlock_bh(&priv->stats_lock); |
| 869 | |
| 870 | return &priv->ret_stats; |
| 871 | } |
| 872 | |
| 873 | static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv) |
| 874 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 875 | struct mlx4_en_cq *cq; |
| 876 | int i; |
| 877 | |
| 878 | /* If we haven't received a specific coalescing setting |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 879 | * (module param), we set the moderation parameters as follows: |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 880 | * - moder_cnt is set to the number of mtu sized packets to |
Eric Dumazet | ecfd2ce | 2012-11-05 16:20:42 +0000 | [diff] [blame] | 881 | * satisfy our coalescing target. |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 882 | * - moder_time is set to a fixed value. |
| 883 | */ |
Yevgeny Petrilin | 3db36fb | 2009-06-01 23:23:13 +0000 | [diff] [blame] | 884 | priv->rx_frames = MLX4_EN_RX_COAL_TARGET; |
Yevgeny Petrilin | 60b9f9e | 2008-12-25 18:19:47 -0800 | [diff] [blame] | 885 | priv->rx_usecs = MLX4_EN_RX_COAL_TIME; |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 886 | priv->tx_frames = MLX4_EN_TX_COAL_PKTS; |
| 887 | priv->tx_usecs = MLX4_EN_TX_COAL_TIME; |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 888 | en_dbg(INTR, priv, "Default coalesing params for mtu:%d - " |
| 889 | "rx_frames:%d rx_usecs:%d\n", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 890 | priv->dev->mtu, priv->rx_frames, priv->rx_usecs); |
| 891 | |
| 892 | /* Setup cq moderation params */ |
| 893 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 894 | cq = &priv->rx_cq[i]; |
| 895 | cq->moder_cnt = priv->rx_frames; |
| 896 | cq->moder_time = priv->rx_usecs; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 897 | priv->last_moder_time[i] = MLX4_EN_AUTO_CONF; |
| 898 | priv->last_moder_packets[i] = 0; |
| 899 | priv->last_moder_bytes[i] = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 903 | cq = &priv->tx_cq[i]; |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 904 | cq->moder_cnt = priv->tx_frames; |
| 905 | cq->moder_time = priv->tx_usecs; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | /* Reset auto-moderation params */ |
| 909 | priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW; |
| 910 | priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW; |
| 911 | priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH; |
| 912 | priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH; |
| 913 | priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL; |
Yevgeny Petrilin | 60b9f9e | 2008-12-25 18:19:47 -0800 | [diff] [blame] | 914 | priv->adaptive_rx_coal = 1; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 915 | priv->last_moder_jiffies = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 916 | priv->last_moder_tx_packets = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv) |
| 920 | { |
| 921 | unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 922 | struct mlx4_en_cq *cq; |
| 923 | unsigned long packets; |
| 924 | unsigned long rate; |
| 925 | unsigned long avg_pkt_size; |
| 926 | unsigned long rx_packets; |
| 927 | unsigned long rx_bytes; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 928 | unsigned long rx_pkt_diff; |
| 929 | int moder_time; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 930 | int ring, err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 931 | |
| 932 | if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ) |
| 933 | return; |
| 934 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 935 | for (ring = 0; ring < priv->rx_ring_num; ring++) { |
| 936 | spin_lock_bh(&priv->stats_lock); |
| 937 | rx_packets = priv->rx_ring[ring].packets; |
| 938 | rx_bytes = priv->rx_ring[ring].bytes; |
| 939 | spin_unlock_bh(&priv->stats_lock); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 940 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 941 | rx_pkt_diff = ((unsigned long) (rx_packets - |
| 942 | priv->last_moder_packets[ring])); |
| 943 | packets = rx_pkt_diff; |
| 944 | rate = packets * HZ / period; |
| 945 | avg_pkt_size = packets ? ((unsigned long) (rx_bytes - |
| 946 | priv->last_moder_bytes[ring])) / packets : 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 947 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 948 | /* Apply auto-moderation only when packet rate |
| 949 | * exceeds a rate that it matters */ |
| 950 | if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) && |
| 951 | avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 952 | if (rate < priv->pkt_rate_low) |
| 953 | moder_time = priv->rx_usecs_low; |
| 954 | else if (rate > priv->pkt_rate_high) |
| 955 | moder_time = priv->rx_usecs_high; |
| 956 | else |
| 957 | moder_time = (rate - priv->pkt_rate_low) * |
| 958 | (priv->rx_usecs_high - priv->rx_usecs_low) / |
| 959 | (priv->pkt_rate_high - priv->pkt_rate_low) + |
| 960 | priv->rx_usecs_low; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 961 | } else { |
| 962 | moder_time = priv->rx_usecs_low; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 963 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 964 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 965 | if (moder_time != priv->last_moder_time[ring]) { |
| 966 | priv->last_moder_time[ring] = moder_time; |
| 967 | cq = &priv->rx_cq[ring]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 968 | cq->moder_time = moder_time; |
| 969 | err = mlx4_en_set_cq_moder(priv, cq); |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 970 | if (err) |
| 971 | en_err(priv, "Failed modifying moderation " |
| 972 | "for cq:%d\n", ring); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 973 | } |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 974 | priv->last_moder_packets[ring] = rx_packets; |
| 975 | priv->last_moder_bytes[ring] = rx_bytes; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 978 | priv->last_moder_jiffies = jiffies; |
| 979 | } |
| 980 | |
| 981 | static void mlx4_en_do_get_stats(struct work_struct *work) |
| 982 | { |
Jean Delvare | bf6aede | 2009-04-02 16:56:54 -0700 | [diff] [blame] | 983 | struct delayed_work *delay = to_delayed_work(work); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 984 | struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv, |
| 985 | stats_task); |
| 986 | struct mlx4_en_dev *mdev = priv->mdev; |
| 987 | int err; |
| 988 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 989 | mutex_lock(&mdev->state_lock); |
| 990 | if (mdev->device_up) { |
Eugenia Emantayev | 2d51837 | 2013-01-24 01:54:14 +0000 | [diff] [blame] | 991 | err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0); |
| 992 | if (err) |
| 993 | en_dbg(HW, priv, "Could not update stats\n"); |
| 994 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 995 | if (priv->port_up) |
| 996 | mlx4_en_auto_moderation(priv); |
| 997 | |
| 998 | queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY); |
| 999 | } |
Yevgeny Petrilin | d7e1a48 | 2010-08-24 03:46:38 +0000 | [diff] [blame] | 1000 | if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) { |
| 1001 | queue_work(mdev->workqueue, &priv->mac_task); |
| 1002 | mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0; |
| 1003 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1004 | mutex_unlock(&mdev->state_lock); |
| 1005 | } |
| 1006 | |
| 1007 | static void mlx4_en_linkstate(struct work_struct *work) |
| 1008 | { |
| 1009 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 1010 | linkstate_task); |
| 1011 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1012 | int linkstate = priv->link_state; |
| 1013 | |
| 1014 | mutex_lock(&mdev->state_lock); |
| 1015 | /* If observable port state changed set carrier state and |
| 1016 | * report to system log */ |
| 1017 | if (priv->last_link_state != linkstate) { |
| 1018 | if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) { |
Yevgeny Petrilin | e5cc44b | 2010-08-24 03:46:01 +0000 | [diff] [blame] | 1019 | en_info(priv, "Link Down\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1020 | netif_carrier_off(priv->dev); |
| 1021 | } else { |
Yevgeny Petrilin | e5cc44b | 2010-08-24 03:46:01 +0000 | [diff] [blame] | 1022 | en_info(priv, "Link Up\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1023 | netif_carrier_on(priv->dev); |
| 1024 | } |
| 1025 | } |
| 1026 | priv->last_link_state = linkstate; |
| 1027 | mutex_unlock(&mdev->state_lock); |
| 1028 | } |
| 1029 | |
| 1030 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1031 | int mlx4_en_start_port(struct net_device *dev) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1032 | { |
| 1033 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1034 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1035 | struct mlx4_en_cq *cq; |
| 1036 | struct mlx4_en_tx_ring *tx_ring; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1037 | int rx_index = 0; |
| 1038 | int tx_index = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1039 | int err = 0; |
| 1040 | int i; |
| 1041 | int j; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1042 | u8 mc_list[16] = {0}; |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame^] | 1043 | u64 mac = mlx4_en_mac_to_u64(dev->dev_addr); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1044 | |
| 1045 | if (priv->port_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1046 | en_dbg(DRV, priv, "start port called while port already up\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1047 | return 0; |
| 1048 | } |
| 1049 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1050 | INIT_LIST_HEAD(&priv->mc_list); |
| 1051 | INIT_LIST_HEAD(&priv->curr_list); |
Hadar Hen Zion | 0d256c0 | 2013-01-30 23:07:08 +0000 | [diff] [blame] | 1052 | INIT_LIST_HEAD(&priv->ethtool_list); |
| 1053 | memset(&priv->ethtool_rules[0], 0, |
| 1054 | sizeof(struct ethtool_flow_id) * MAX_NUM_OF_FS_RULES); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1055 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1056 | /* Calculate Rx buf size */ |
| 1057 | dev->mtu = min(dev->mtu, priv->max_mtu); |
| 1058 | mlx4_en_calc_rx_buf(dev); |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1059 | 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] | 1060 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1061 | /* Configure rx cq's and rings */ |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 1062 | err = mlx4_en_activate_rx_rings(priv); |
| 1063 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1064 | en_err(priv, "Failed to activate RX rings\n"); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 1065 | return err; |
| 1066 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1067 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 1068 | cq = &priv->rx_cq[i]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1069 | |
Alexander Guller | 76532d0 | 2011-10-09 05:26:31 +0000 | [diff] [blame] | 1070 | err = mlx4_en_activate_cq(priv, cq, i); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1071 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1072 | en_err(priv, "Failed activating Rx CQ\n"); |
Yevgeny Petrilin | a423330 | 2009-04-26 20:41:34 +0000 | [diff] [blame] | 1073 | goto cq_err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1074 | } |
| 1075 | for (j = 0; j < cq->size; j++) |
| 1076 | cq->buf[j].owner_sr_opcode = MLX4_CQE_OWNER_MASK; |
| 1077 | err = mlx4_en_set_cq_moder(priv, cq); |
| 1078 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1079 | en_err(priv, "Failed setting cq moderation parameters"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1080 | mlx4_en_deactivate_cq(priv, cq); |
| 1081 | goto cq_err; |
| 1082 | } |
| 1083 | mlx4_en_arm_cq(priv, cq); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 1084 | priv->rx_ring[i].cqn = cq->mcq.cqn; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1085 | ++rx_index; |
| 1086 | } |
| 1087 | |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 1088 | /* Set qp number */ |
| 1089 | en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port); |
| 1090 | err = mlx4_get_eth_qp(mdev->dev, priv->port, |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame^] | 1091 | mac, &priv->base_qpn); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1092 | if (err) { |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 1093 | en_err(priv, "Failed getting eth qp\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1094 | goto cq_err; |
| 1095 | } |
| 1096 | mdev->mac_removed[priv->port] = 0; |
| 1097 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1098 | err = mlx4_en_config_rss_steer(priv); |
| 1099 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1100 | en_err(priv, "Failed configuring rss steering\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1101 | goto mac_err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Hadar Hen Zion | cabdc8ee | 2012-07-05 04:03:50 +0000 | [diff] [blame] | 1104 | err = mlx4_en_create_drop_qp(priv); |
| 1105 | if (err) |
| 1106 | goto rss_err; |
| 1107 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1108 | /* Configure tx cq's and rings */ |
| 1109 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 1110 | /* Configure cq */ |
| 1111 | cq = &priv->tx_cq[i]; |
Alexander Guller | 76532d0 | 2011-10-09 05:26:31 +0000 | [diff] [blame] | 1112 | err = mlx4_en_activate_cq(priv, cq, i); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1113 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1114 | en_err(priv, "Failed allocating Tx CQ\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1115 | goto tx_err; |
| 1116 | } |
| 1117 | err = mlx4_en_set_cq_moder(priv, cq); |
| 1118 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1119 | en_err(priv, "Failed setting cq moderation parameters"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1120 | mlx4_en_deactivate_cq(priv, cq); |
| 1121 | goto tx_err; |
| 1122 | } |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1123 | 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] | 1124 | cq->buf->wqe_index = cpu_to_be16(0xffff); |
| 1125 | |
| 1126 | /* Configure ring */ |
| 1127 | tx_ring = &priv->tx_ring[i]; |
Amir Vadai | 0e98b52 | 2012-04-04 21:33:24 +0000 | [diff] [blame] | 1128 | err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn, |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1129 | i / priv->num_tx_rings_p_up); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1130 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1131 | en_err(priv, "Failed allocating Tx ring\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1132 | mlx4_en_deactivate_cq(priv, cq); |
| 1133 | goto tx_err; |
| 1134 | } |
Yevgeny Petrilin | 5b263f5 | 2012-04-23 02:18:50 +0000 | [diff] [blame] | 1135 | tx_ring->tx_queue = netdev_get_tx_queue(dev, i); |
Yevgeny Petrilin | e22979d | 2012-04-23 02:18:39 +0000 | [diff] [blame] | 1136 | |
| 1137 | /* Arm CQ for TX completions */ |
| 1138 | mlx4_en_arm_cq(priv, cq); |
| 1139 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1140 | /* Set initial ownership of all Tx TXBBs to SW (1) */ |
| 1141 | for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE) |
| 1142 | *((u32 *) (tx_ring->buf + j)) = 0xffffffff; |
| 1143 | ++tx_index; |
| 1144 | } |
| 1145 | |
| 1146 | /* Configure port */ |
| 1147 | err = mlx4_SET_PORT_general(mdev->dev, priv->port, |
| 1148 | priv->rx_skb_size + ETH_FCS_LEN, |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 1149 | priv->prof->tx_pause, |
| 1150 | priv->prof->tx_ppp, |
| 1151 | priv->prof->rx_pause, |
| 1152 | priv->prof->rx_ppp); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1153 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1154 | en_err(priv, "Failed setting port general configurations " |
| 1155 | "for port %d, with error %d\n", priv->port, err); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1156 | goto tx_err; |
| 1157 | } |
| 1158 | /* Set default qp number */ |
| 1159 | err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0); |
| 1160 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1161 | en_err(priv, "Failed setting default qp numbers\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1162 | goto tx_err; |
| 1163 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1164 | |
| 1165 | /* Init port */ |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1166 | en_dbg(HW, priv, "Initializing port\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1167 | err = mlx4_INIT_PORT(mdev->dev, priv->port); |
| 1168 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1169 | en_err(priv, "Failed Initializing port\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1170 | goto tx_err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1173 | /* Attach rx QP to bradcast address */ |
| 1174 | memset(&mc_list[10], 0xff, ETH_ALEN); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1175 | mc_list[5] = priv->port; /* needed for B0 steering support */ |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1176 | 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] | 1177 | priv->port, 0, MLX4_PROT_ETH, |
| 1178 | &priv->broadcast_id)) |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1179 | mlx4_warn(mdev, "Failed Attaching Broadcast\n"); |
| 1180 | |
Herbert Xu | b5845f9 | 2011-03-27 01:01:26 +0000 | [diff] [blame] | 1181 | /* Must redo promiscuous mode setup. */ |
| 1182 | priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC); |
| 1183 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1184 | /* Schedule multicast task to populate multicast list */ |
| 1185 | queue_work(mdev->workqueue, &priv->mcast_task); |
| 1186 | |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 1187 | mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap); |
| 1188 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1189 | priv->port_up = true; |
Yevgeny Petrilin | a11faac | 2009-06-20 22:15:46 +0000 | [diff] [blame] | 1190 | netif_tx_start_all_queues(dev); |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1191 | netif_device_attach(dev); |
| 1192 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1193 | return 0; |
| 1194 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1195 | tx_err: |
| 1196 | while (tx_index--) { |
| 1197 | mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[tx_index]); |
| 1198 | mlx4_en_deactivate_cq(priv, &priv->tx_cq[tx_index]); |
| 1199 | } |
Hadar Hen Zion | cabdc8ee | 2012-07-05 04:03:50 +0000 | [diff] [blame] | 1200 | mlx4_en_destroy_drop_qp(priv); |
| 1201 | rss_err: |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1202 | mlx4_en_release_rss_steer(priv); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1203 | mac_err: |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame^] | 1204 | mlx4_put_eth_qp(mdev->dev, priv->port, mac, priv->base_qpn); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1205 | cq_err: |
| 1206 | while (rx_index--) |
| 1207 | mlx4_en_deactivate_cq(priv, &priv->rx_cq[rx_index]); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 1208 | for (i = 0; i < priv->rx_ring_num; i++) |
| 1209 | mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1210 | |
| 1211 | return err; /* need to close devices */ |
| 1212 | } |
| 1213 | |
| 1214 | |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1215 | void mlx4_en_stop_port(struct net_device *dev, int detach) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1216 | { |
| 1217 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1218 | struct mlx4_en_dev *mdev = priv->mdev; |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1219 | struct mlx4_en_mc_list *mclist, *tmp; |
Hadar Hen Zion | 0d256c0 | 2013-01-30 23:07:08 +0000 | [diff] [blame] | 1220 | struct ethtool_flow_id *flow, *tmp_flow; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1221 | int i; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1222 | u8 mc_list[16] = {0}; |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame^] | 1223 | u64 mac = mlx4_en_mac_to_u64(dev->dev_addr); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1224 | |
| 1225 | if (!priv->port_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1226 | en_dbg(DRV, priv, "stop port called while port already down\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1227 | return; |
| 1228 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1229 | |
| 1230 | /* Synchronize with tx routine */ |
| 1231 | netif_tx_lock_bh(dev); |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1232 | if (detach) |
| 1233 | netif_device_detach(dev); |
Yevgeny Petrilin | 3c05f5e | 2009-06-20 22:15:52 +0000 | [diff] [blame] | 1234 | netif_tx_stop_all_queues(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1235 | netif_tx_unlock_bh(dev); |
| 1236 | |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1237 | netif_tx_disable(dev); |
| 1238 | |
Yevgeny Petrilin | 7c28738 | 2010-08-24 03:45:45 +0000 | [diff] [blame] | 1239 | /* Set port as not active */ |
Yevgeny Petrilin | 3c05f5e | 2009-06-20 22:15:52 +0000 | [diff] [blame] | 1240 | priv->port_up = false; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1241 | |
Aviad Yehezkel | db0e7cb | 2013-01-24 01:54:15 +0000 | [diff] [blame] | 1242 | /* Promsicuous mode */ |
| 1243 | if (mdev->dev->caps.steering_mode == |
| 1244 | MLX4_STEERING_MODE_DEVICE_MANAGED) { |
| 1245 | priv->flags &= ~(MLX4_EN_FLAG_PROMISC | |
| 1246 | MLX4_EN_FLAG_MC_PROMISC); |
| 1247 | mlx4_flow_steer_promisc_remove(mdev->dev, |
| 1248 | priv->port, |
| 1249 | MLX4_FS_PROMISC_UPLINK); |
| 1250 | mlx4_flow_steer_promisc_remove(mdev->dev, |
| 1251 | priv->port, |
| 1252 | MLX4_FS_PROMISC_ALL_MULTI); |
| 1253 | } else if (priv->flags & MLX4_EN_FLAG_PROMISC) { |
| 1254 | priv->flags &= ~MLX4_EN_FLAG_PROMISC; |
| 1255 | |
| 1256 | /* Disable promiscouos mode */ |
| 1257 | mlx4_unicast_promisc_remove(mdev->dev, priv->base_qpn, |
| 1258 | priv->port); |
| 1259 | |
| 1260 | /* Disable Multicast promisc */ |
| 1261 | if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { |
| 1262 | mlx4_multicast_promisc_remove(mdev->dev, priv->base_qpn, |
| 1263 | priv->port); |
| 1264 | priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; |
| 1265 | } |
| 1266 | } |
| 1267 | |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1268 | /* Detach All multicasts */ |
| 1269 | memset(&mc_list[10], 0xff, ETH_ALEN); |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1270 | mc_list[5] = priv->port; /* needed for B0 steering support */ |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1271 | 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] | 1272 | MLX4_PROT_ETH, priv->broadcast_id); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1273 | list_for_each_entry(mclist, &priv->curr_list, list) { |
| 1274 | memcpy(&mc_list[10], mclist->addr, ETH_ALEN); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1275 | mc_list[5] = priv->port; |
| 1276 | mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1277 | mc_list, MLX4_PROT_ETH, mclist->reg_id); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1278 | } |
| 1279 | mlx4_en_clear_list(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 1280 | list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { |
| 1281 | list_del(&mclist->list); |
| 1282 | kfree(mclist); |
| 1283 | } |
| 1284 | |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1285 | /* Flush multicast filter */ |
| 1286 | mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG); |
| 1287 | |
Hadar Hen Zion | cabdc8ee | 2012-07-05 04:03:50 +0000 | [diff] [blame] | 1288 | mlx4_en_destroy_drop_qp(priv); |
| 1289 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1290 | /* Free TX Rings */ |
| 1291 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 1292 | mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[i]); |
| 1293 | mlx4_en_deactivate_cq(priv, &priv->tx_cq[i]); |
| 1294 | } |
| 1295 | msleep(10); |
| 1296 | |
| 1297 | for (i = 0; i < priv->tx_ring_num; i++) |
| 1298 | mlx4_en_free_tx_buf(dev, &priv->tx_ring[i]); |
| 1299 | |
| 1300 | /* Free RSS qps */ |
| 1301 | mlx4_en_release_rss_steer(priv); |
| 1302 | |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 1303 | /* Unregister Mac address for the port */ |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame^] | 1304 | mlx4_put_eth_qp(mdev->dev, priv->port, mac, priv->base_qpn); |
Matan Barak | 955154f | 2013-01-30 23:07:10 +0000 | [diff] [blame] | 1305 | if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAGS2_REASSIGN_MAC_EN)) |
| 1306 | mdev->mac_removed[priv->port] = 1; |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 1307 | |
Hadar Hen Zion | 0d256c0 | 2013-01-30 23:07:08 +0000 | [diff] [blame] | 1308 | /* Remove flow steering rules for the port*/ |
| 1309 | if (mdev->dev->caps.steering_mode == |
| 1310 | MLX4_STEERING_MODE_DEVICE_MANAGED) { |
| 1311 | ASSERT_RTNL(); |
| 1312 | list_for_each_entry_safe(flow, tmp_flow, |
| 1313 | &priv->ethtool_list, list) { |
| 1314 | mlx4_flow_detach(mdev->dev, flow->id); |
| 1315 | list_del(&flow->list); |
| 1316 | } |
| 1317 | } |
| 1318 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1319 | /* Free RX Rings */ |
| 1320 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 1321 | mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]); |
| 1322 | while (test_bit(NAPI_STATE_SCHED, &priv->rx_cq[i].napi.state)) |
| 1323 | msleep(1); |
| 1324 | mlx4_en_deactivate_cq(priv, &priv->rx_cq[i]); |
| 1325 | } |
Yevgeny Petrilin | 7c28738 | 2010-08-24 03:45:45 +0000 | [diff] [blame] | 1326 | |
| 1327 | /* close port*/ |
| 1328 | mlx4_CLOSE_PORT(mdev->dev, priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | static void mlx4_en_restart(struct work_struct *work) |
| 1332 | { |
| 1333 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 1334 | watchdog_task); |
| 1335 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1336 | struct net_device *dev = priv->dev; |
Yevgeny Petrilin | 5b263f5 | 2012-04-23 02:18:50 +0000 | [diff] [blame] | 1337 | int i; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1338 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1339 | 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] | 1340 | |
| 1341 | mutex_lock(&mdev->state_lock); |
| 1342 | if (priv->port_up) { |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1343 | mlx4_en_stop_port(dev, 1); |
Yevgeny Petrilin | 5b263f5 | 2012-04-23 02:18:50 +0000 | [diff] [blame] | 1344 | for (i = 0; i < priv->tx_ring_num; i++) |
| 1345 | netdev_tx_reset_queue(priv->tx_ring[i].tx_queue); |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 1346 | if (mlx4_en_start_port(dev)) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1347 | en_err(priv, "Failed restarting port %d\n", priv->port); |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 1348 | } |
| 1349 | mutex_unlock(&mdev->state_lock); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
Eugenia Emantayev | b477ba6 | 2012-01-19 09:42:37 +0000 | [diff] [blame] | 1352 | static void mlx4_en_clear_stats(struct net_device *dev) |
| 1353 | { |
| 1354 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1355 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1356 | int i; |
| 1357 | |
| 1358 | if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1)) |
| 1359 | en_dbg(HW, priv, "Failed dumping statistics\n"); |
| 1360 | |
| 1361 | memset(&priv->stats, 0, sizeof(priv->stats)); |
| 1362 | memset(&priv->pstats, 0, sizeof(priv->pstats)); |
| 1363 | memset(&priv->pkstats, 0, sizeof(priv->pkstats)); |
| 1364 | memset(&priv->port_stats, 0, sizeof(priv->port_stats)); |
| 1365 | |
| 1366 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 1367 | priv->tx_ring[i].bytes = 0; |
| 1368 | priv->tx_ring[i].packets = 0; |
| 1369 | priv->tx_ring[i].tx_csum = 0; |
| 1370 | } |
| 1371 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 1372 | priv->rx_ring[i].bytes = 0; |
| 1373 | priv->rx_ring[i].packets = 0; |
| 1374 | priv->rx_ring[i].csum_ok = 0; |
| 1375 | priv->rx_ring[i].csum_none = 0; |
| 1376 | } |
| 1377 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1378 | |
| 1379 | static int mlx4_en_open(struct net_device *dev) |
| 1380 | { |
| 1381 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1382 | struct mlx4_en_dev *mdev = priv->mdev; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1383 | int err = 0; |
| 1384 | |
| 1385 | mutex_lock(&mdev->state_lock); |
| 1386 | |
| 1387 | if (!mdev->device_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1388 | en_err(priv, "Cannot open - device down/disabled\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1389 | err = -EBUSY; |
| 1390 | goto out; |
| 1391 | } |
| 1392 | |
Eugenia Emantayev | b477ba6 | 2012-01-19 09:42:37 +0000 | [diff] [blame] | 1393 | /* Reset HW statistics and SW counters */ |
| 1394 | mlx4_en_clear_stats(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1395 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1396 | err = mlx4_en_start_port(dev); |
| 1397 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1398 | en_err(priv, "Failed starting port:%d\n", priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1399 | |
| 1400 | out: |
| 1401 | mutex_unlock(&mdev->state_lock); |
| 1402 | return err; |
| 1403 | } |
| 1404 | |
| 1405 | |
| 1406 | static int mlx4_en_close(struct net_device *dev) |
| 1407 | { |
| 1408 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1409 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1410 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1411 | en_dbg(IFDOWN, priv, "Close port called\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1412 | |
| 1413 | mutex_lock(&mdev->state_lock); |
| 1414 | |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1415 | mlx4_en_stop_port(dev, 0); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1416 | netif_carrier_off(dev); |
| 1417 | |
| 1418 | mutex_unlock(&mdev->state_lock); |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1422 | void mlx4_en_free_resources(struct mlx4_en_priv *priv) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1423 | { |
| 1424 | int i; |
| 1425 | |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 1426 | #ifdef CONFIG_RFS_ACCEL |
| 1427 | free_irq_cpu_rmap(priv->dev->rx_cpu_rmap); |
| 1428 | priv->dev->rx_cpu_rmap = NULL; |
| 1429 | #endif |
| 1430 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1431 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 1432 | if (priv->tx_ring[i].tx_info) |
| 1433 | mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]); |
| 1434 | if (priv->tx_cq[i].buf) |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1435 | mlx4_en_destroy_cq(priv, &priv->tx_cq[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 1439 | if (priv->rx_ring[i].rx_info) |
Thadeu Lima de Souza Cascardo | 68355f7 | 2012-02-06 08:39:49 +0000 | [diff] [blame] | 1440 | mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i], |
| 1441 | priv->prof->rx_ring_size, priv->stride); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1442 | if (priv->rx_cq[i].buf) |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1443 | mlx4_en_destroy_cq(priv, &priv->rx_cq[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1444 | } |
Yevgeny Petrilin | 044ca2a | 2012-06-25 00:24:13 +0000 | [diff] [blame] | 1445 | |
| 1446 | if (priv->base_tx_qpn) { |
| 1447 | mlx4_qp_release_range(priv->mdev->dev, priv->base_tx_qpn, priv->tx_ring_num); |
| 1448 | priv->base_tx_qpn = 0; |
| 1449 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1452 | int mlx4_en_alloc_resources(struct mlx4_en_priv *priv) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1453 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1454 | struct mlx4_en_port_profile *prof = priv->prof; |
| 1455 | int i; |
Yevgeny Petrilin | 044ca2a | 2012-06-25 00:24:13 +0000 | [diff] [blame] | 1456 | int err; |
Yevgeny Petrilin | 87a5c38 | 2011-03-22 22:38:52 +0000 | [diff] [blame] | 1457 | |
Yevgeny Petrilin | 044ca2a | 2012-06-25 00:24:13 +0000 | [diff] [blame] | 1458 | 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] | 1459 | if (err) { |
| 1460 | en_err(priv, "failed reserving range for TX rings\n"); |
| 1461 | return err; |
| 1462 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1463 | |
| 1464 | /* Create tx Rings */ |
| 1465 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 1466 | if (mlx4_en_create_cq(priv, &priv->tx_cq[i], |
| 1467 | prof->tx_ring_size, i, TX)) |
| 1468 | goto err; |
| 1469 | |
Yevgeny Petrilin | 044ca2a | 2012-06-25 00:24:13 +0000 | [diff] [blame] | 1470 | 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] | 1471 | prof->tx_ring_size, TXBB_SIZE)) |
| 1472 | goto err; |
| 1473 | } |
| 1474 | |
| 1475 | /* Create rx Rings */ |
| 1476 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 1477 | if (mlx4_en_create_cq(priv, &priv->rx_cq[i], |
| 1478 | prof->rx_ring_size, i, RX)) |
| 1479 | goto err; |
| 1480 | |
| 1481 | if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i], |
| 1482 | prof->rx_ring_size, priv->stride)) |
| 1483 | goto err; |
| 1484 | } |
| 1485 | |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 1486 | #ifdef CONFIG_RFS_ACCEL |
| 1487 | priv->dev->rx_cpu_rmap = alloc_irq_cpu_rmap(priv->rx_ring_num); |
| 1488 | if (!priv->dev->rx_cpu_rmap) |
| 1489 | goto err; |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 1490 | #endif |
| 1491 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1492 | return 0; |
| 1493 | |
| 1494 | err: |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1495 | en_err(priv, "Failed to allocate NIC resources\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1496 | return -ENOMEM; |
| 1497 | } |
| 1498 | |
| 1499 | |
| 1500 | void mlx4_en_destroy_netdev(struct net_device *dev) |
| 1501 | { |
| 1502 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1503 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1504 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1505 | en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1506 | |
| 1507 | /* Unregister device - this will close the port if it was up */ |
| 1508 | if (priv->registered) |
| 1509 | unregister_netdev(dev); |
| 1510 | |
| 1511 | if (priv->allocated) |
| 1512 | mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE); |
| 1513 | |
| 1514 | cancel_delayed_work(&priv->stats_task); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1515 | /* flush any pending task for this netdev */ |
| 1516 | flush_workqueue(mdev->workqueue); |
| 1517 | |
| 1518 | /* Detach the netdev so tasks would not attempt to access it */ |
| 1519 | mutex_lock(&mdev->state_lock); |
| 1520 | mdev->pndev[priv->port] = NULL; |
| 1521 | mutex_unlock(&mdev->state_lock); |
| 1522 | |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1523 | mlx4_en_free_resources(priv); |
Amir Vadai | 564c274 | 2012-04-04 21:33:26 +0000 | [diff] [blame] | 1524 | |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 1525 | kfree(priv->tx_ring); |
| 1526 | kfree(priv->tx_cq); |
| 1527 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1528 | free_netdev(dev); |
| 1529 | } |
| 1530 | |
| 1531 | static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu) |
| 1532 | { |
| 1533 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1534 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1535 | int err = 0; |
| 1536 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1537 | en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1538 | dev->mtu, new_mtu); |
| 1539 | |
| 1540 | if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1541 | en_err(priv, "Bad MTU size:%d.\n", new_mtu); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1542 | return -EPERM; |
| 1543 | } |
| 1544 | dev->mtu = new_mtu; |
| 1545 | |
| 1546 | if (netif_running(dev)) { |
| 1547 | mutex_lock(&mdev->state_lock); |
| 1548 | if (!mdev->device_up) { |
| 1549 | /* NIC is probably restarting - let watchdog task reset |
| 1550 | * the port */ |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1551 | en_dbg(DRV, priv, "Change MTU called with card down!?\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1552 | } else { |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1553 | mlx4_en_stop_port(dev, 1); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1554 | err = mlx4_en_start_port(dev); |
| 1555 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1556 | en_err(priv, "Failed restarting port:%d\n", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1557 | priv->port); |
| 1558 | queue_work(mdev->workqueue, &priv->watchdog_task); |
| 1559 | } |
| 1560 | } |
| 1561 | mutex_unlock(&mdev->state_lock); |
| 1562 | } |
| 1563 | return 0; |
| 1564 | } |
| 1565 | |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 1566 | static int mlx4_en_set_features(struct net_device *netdev, |
| 1567 | netdev_features_t features) |
| 1568 | { |
| 1569 | struct mlx4_en_priv *priv = netdev_priv(netdev); |
| 1570 | |
| 1571 | if (features & NETIF_F_LOOPBACK) |
| 1572 | priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK); |
| 1573 | else |
| 1574 | priv->ctrl_flags &= |
| 1575 | cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK); |
| 1576 | |
Yan Burman | 79aeacc | 2013-02-07 02:25:19 +0000 | [diff] [blame] | 1577 | mlx4_en_update_loopback_state(netdev, features); |
| 1578 | |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 1579 | return 0; |
| 1580 | |
| 1581 | } |
| 1582 | |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1583 | static const struct net_device_ops mlx4_netdev_ops = { |
| 1584 | .ndo_open = mlx4_en_open, |
| 1585 | .ndo_stop = mlx4_en_close, |
| 1586 | .ndo_start_xmit = mlx4_en_xmit, |
Yevgeny Petrilin | f813cad | 2009-06-01 23:24:07 +0000 | [diff] [blame] | 1587 | .ndo_select_queue = mlx4_en_select_queue, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1588 | .ndo_get_stats = mlx4_en_get_stats, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1589 | .ndo_set_rx_mode = mlx4_en_set_multicast, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1590 | .ndo_set_mac_address = mlx4_en_set_mac, |
Stephen Hemminger | 52255bb | 2009-01-09 10:45:37 +0000 | [diff] [blame] | 1591 | .ndo_validate_addr = eth_validate_addr, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1592 | .ndo_change_mtu = mlx4_en_change_mtu, |
| 1593 | .ndo_tx_timeout = mlx4_en_tx_timeout, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1594 | .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid, |
| 1595 | .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid, |
| 1596 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1597 | .ndo_poll_controller = mlx4_en_netpoll, |
| 1598 | #endif |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 1599 | .ndo_set_features = mlx4_en_set_features, |
Amir Vadai | 897d784 | 2012-04-04 21:33:27 +0000 | [diff] [blame] | 1600 | .ndo_setup_tc = mlx4_en_setup_tc, |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 1601 | #ifdef CONFIG_RFS_ACCEL |
| 1602 | .ndo_rx_flow_steer = mlx4_en_filter_rfs, |
| 1603 | #endif |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1604 | }; |
| 1605 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1606 | int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, |
| 1607 | struct mlx4_en_port_profile *prof) |
| 1608 | { |
| 1609 | struct net_device *dev; |
| 1610 | struct mlx4_en_priv *priv; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1611 | int err; |
| 1612 | |
Tom Herbert | f1593d2 | 2011-01-09 19:36:36 +0000 | [diff] [blame] | 1613 | dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv), |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1614 | MAX_TX_RINGS, MAX_RX_RINGS); |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 1615 | if (dev == NULL) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1616 | return -ENOMEM; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1617 | |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1618 | netif_set_real_num_tx_queues(dev, prof->tx_ring_num); |
| 1619 | netif_set_real_num_rx_queues(dev, prof->rx_ring_num); |
| 1620 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1621 | SET_NETDEV_DEV(dev, &mdev->dev->pdev->dev); |
Eli Cohen | 741a00b | 2010-05-26 19:56:24 +0000 | [diff] [blame] | 1622 | dev->dev_id = port - 1; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1623 | |
| 1624 | /* |
| 1625 | * Initialize driver private data |
| 1626 | */ |
| 1627 | |
| 1628 | priv = netdev_priv(dev); |
| 1629 | memset(priv, 0, sizeof(struct mlx4_en_priv)); |
| 1630 | priv->dev = dev; |
| 1631 | priv->mdev = mdev; |
Yevgeny Petrilin | ebf8c9a | 2012-03-06 04:03:34 +0000 | [diff] [blame] | 1632 | priv->ddev = &mdev->pdev->dev; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1633 | priv->prof = prof; |
| 1634 | priv->port = port; |
| 1635 | priv->port_up = false; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1636 | priv->flags = prof->flags; |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 1637 | priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE | |
| 1638 | MLX4_WQE_CTRL_SOLICITED); |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1639 | 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] | 1640 | priv->tx_ring_num = prof->tx_ring_num; |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1641 | |
| 1642 | priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring) * MAX_TX_RINGS, |
| 1643 | GFP_KERNEL); |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 1644 | if (!priv->tx_ring) { |
| 1645 | err = -ENOMEM; |
| 1646 | goto out; |
| 1647 | } |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1648 | priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq) * MAX_RX_RINGS, |
| 1649 | GFP_KERNEL); |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 1650 | if (!priv->tx_cq) { |
| 1651 | err = -ENOMEM; |
| 1652 | goto out; |
| 1653 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1654 | priv->rx_ring_num = prof->rx_ring_num; |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 1655 | priv->cqe_factor = (mdev->dev->caps.cqe_size == 64) ? 1 : 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1656 | priv->mac_index = -1; |
| 1657 | priv->msg_enable = MLX4_EN_MSG_LEVEL; |
| 1658 | spin_lock_init(&priv->stats_lock); |
| 1659 | INIT_WORK(&priv->mcast_task, mlx4_en_do_set_multicast); |
| 1660 | INIT_WORK(&priv->mac_task, mlx4_en_do_set_mac); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1661 | INIT_WORK(&priv->watchdog_task, mlx4_en_restart); |
| 1662 | INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate); |
| 1663 | INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats); |
Amir Vadai | 564c274 | 2012-04-04 21:33:26 +0000 | [diff] [blame] | 1664 | #ifdef CONFIG_MLX4_EN_DCB |
| 1665 | if (!mlx4_is_slave(priv->mdev->dev)) |
| 1666 | dev->dcbnl_ops = &mlx4_en_dcbnl_ops; |
| 1667 | #endif |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1668 | |
| 1669 | /* Query for default mac and max mtu */ |
| 1670 | priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port]; |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame^] | 1671 | |
| 1672 | /* Set default MAC */ |
| 1673 | dev->addr_len = ETH_ALEN; |
| 1674 | mlx4_en_u64_to_mac(dev->dev_addr, mdev->dev->caps.def_mac[priv->port]); |
| 1675 | if (!is_valid_ether_addr(dev->dev_addr)) { |
| 1676 | en_err(priv, "Port: %d, invalid mac burned: %pM, quiting\n", |
| 1677 | priv->port, dev->dev_addr); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1678 | err = -EINVAL; |
| 1679 | goto out; |
| 1680 | } |
| 1681 | |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame^] | 1682 | memcpy(priv->prev_mac, dev->dev_addr, sizeof(priv->prev_mac)); |
| 1683 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1684 | priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) + |
| 1685 | DS_SIZE * MLX4_EN_MAX_RX_FRAGS); |
| 1686 | err = mlx4_en_alloc_resources(priv); |
| 1687 | if (err) |
| 1688 | goto out; |
| 1689 | |
Amir Vadai | 78fb2de | 2013-01-24 01:54:19 +0000 | [diff] [blame] | 1690 | #ifdef CONFIG_RFS_ACCEL |
| 1691 | INIT_LIST_HEAD(&priv->filters); |
| 1692 | spin_lock_init(&priv->filters_lock); |
| 1693 | #endif |
| 1694 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1695 | /* Allocate page for receive rings */ |
| 1696 | err = mlx4_alloc_hwq_res(mdev->dev, &priv->res, |
| 1697 | MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE); |
| 1698 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1699 | en_err(priv, "Failed to allocate page for rx qps\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1700 | goto out; |
| 1701 | } |
| 1702 | priv->allocated = 1; |
| 1703 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1704 | /* |
| 1705 | * Initialize netdev entry points |
| 1706 | */ |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1707 | dev->netdev_ops = &mlx4_netdev_ops; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1708 | dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT; |
Ben Hutchings | 1eb63a2 | 2010-09-27 08:29:34 +0000 | [diff] [blame] | 1709 | netif_set_real_num_tx_queues(dev, priv->tx_ring_num); |
| 1710 | netif_set_real_num_rx_queues(dev, priv->rx_ring_num); |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1711 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1712 | SET_ETHTOOL_OPS(dev, &mlx4_en_ethtool_ops); |
| 1713 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1714 | /* |
| 1715 | * Set driver features |
| 1716 | */ |
Michał Mirosław | c8c64cf | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 1717 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
| 1718 | if (mdev->LSO_support) |
| 1719 | dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6; |
| 1720 | |
| 1721 | dev->vlan_features = dev->hw_features; |
| 1722 | |
Yevgeny Petrilin | ad86107 | 2011-10-18 01:51:24 +0000 | [diff] [blame] | 1723 | dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH; |
Michał Mirosław | c8c64cf | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 1724 | dev->features = dev->hw_features | NETIF_F_HIGHDMA | |
| 1725 | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | |
| 1726 | NETIF_F_HW_VLAN_FILTER; |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 1727 | dev->hw_features |= NETIF_F_LOOPBACK; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1728 | |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 1729 | if (mdev->dev->caps.steering_mode == |
| 1730 | MLX4_STEERING_MODE_DEVICE_MANAGED) |
| 1731 | dev->hw_features |= NETIF_F_NTUPLE; |
| 1732 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1733 | mdev->pndev[port] = dev; |
| 1734 | |
| 1735 | netif_carrier_off(dev); |
| 1736 | err = register_netdev(dev); |
| 1737 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1738 | en_err(priv, "Netdev registration failed for port %d\n", port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1739 | goto out; |
| 1740 | } |
Alexander Guller | 4234144 | 2011-10-09 05:29:35 +0000 | [diff] [blame] | 1741 | priv->registered = 1; |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1742 | |
| 1743 | en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num); |
| 1744 | en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num); |
| 1745 | |
Yan Burman | 79aeacc | 2013-02-07 02:25:19 +0000 | [diff] [blame] | 1746 | mlx4_en_update_loopback_state(priv->dev, priv->dev->features); |
| 1747 | |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 1748 | /* Configure port */ |
Yevgeny Petrilin | 5c8e904 | 2012-06-25 00:24:11 +0000 | [diff] [blame] | 1749 | mlx4_en_calc_rx_buf(dev); |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 1750 | err = mlx4_SET_PORT_general(mdev->dev, priv->port, |
Yevgeny Petrilin | 5c8e904 | 2012-06-25 00:24:11 +0000 | [diff] [blame] | 1751 | priv->rx_skb_size + ETH_FCS_LEN, |
| 1752 | prof->tx_pause, prof->tx_ppp, |
| 1753 | prof->rx_pause, prof->rx_ppp); |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 1754 | if (err) { |
| 1755 | en_err(priv, "Failed setting port general configurations " |
| 1756 | "for port %d, with error %d\n", priv->port, err); |
| 1757 | goto out; |
| 1758 | } |
| 1759 | |
| 1760 | /* Init port */ |
| 1761 | en_warn(priv, "Initializing port\n"); |
| 1762 | err = mlx4_INIT_PORT(mdev->dev, priv->port); |
| 1763 | if (err) { |
| 1764 | en_err(priv, "Failed Initializing port\n"); |
| 1765 | goto out; |
| 1766 | } |
Yevgeny Petrilin | 39f17b4 | 2011-03-22 22:37:28 +0000 | [diff] [blame] | 1767 | mlx4_en_set_default_moderation(priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1768 | queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY); |
| 1769 | return 0; |
| 1770 | |
| 1771 | out: |
| 1772 | mlx4_en_destroy_netdev(dev); |
| 1773 | return err; |
| 1774 | } |
| 1775 | |