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> |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 39 | |
| 40 | #include <linux/mlx4/driver.h> |
| 41 | #include <linux/mlx4/device.h> |
| 42 | #include <linux/mlx4/cmd.h> |
| 43 | #include <linux/mlx4/cq.h> |
| 44 | |
| 45 | #include "mlx4_en.h" |
| 46 | #include "en_port.h" |
| 47 | |
Amir Vadai | 897d784 | 2012-04-04 21:33:27 +0000 | [diff] [blame] | 48 | static int mlx4_en_setup_tc(struct net_device *dev, u8 up) |
| 49 | { |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 50 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 51 | int i; |
| 52 | unsigned int q, offset = 0; |
| 53 | |
| 54 | if (up && up != MLX4_EN_NUM_UP) |
Amir Vadai | 897d784 | 2012-04-04 21:33:27 +0000 | [diff] [blame] | 55 | return -EINVAL; |
| 56 | |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 57 | netdev_set_num_tc(dev, up); |
| 58 | |
| 59 | /* Partition Tx queues evenly amongst UP's */ |
| 60 | q = priv->tx_ring_num / up; |
| 61 | for (i = 0; i < up; i++) { |
| 62 | netdev_set_tc_queue(dev, i, q, offset); |
| 63 | offset += q; |
| 64 | } |
| 65 | |
Amir Vadai | 897d784 | 2012-04-04 21:33:27 +0000 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 69 | 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] | 70 | { |
| 71 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 72 | struct mlx4_en_dev *mdev = priv->mdev; |
| 73 | int err; |
Eli Cohen | 4c3eb3c | 2010-08-26 17:19:22 +0300 | [diff] [blame] | 74 | int idx; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 75 | |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 76 | en_dbg(HW, priv, "adding VLAN:%d\n", vid); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 77 | |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 78 | set_bit(vid, priv->active_vlans); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 79 | |
| 80 | /* Add VID to port VLAN filter */ |
| 81 | mutex_lock(&mdev->state_lock); |
| 82 | if (mdev->device_up && priv->port_up) { |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 83 | err = mlx4_SET_VLAN_FLTR(mdev->dev, priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 84 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 85 | en_err(priv, "Failed configuring VLAN filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 86 | } |
Eli Cohen | 4c3eb3c | 2010-08-26 17:19:22 +0300 | [diff] [blame] | 87 | if (mlx4_register_vlan(mdev->dev, priv->port, vid, &idx)) |
| 88 | en_err(priv, "failed adding vlan %d\n", vid); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 89 | mutex_unlock(&mdev->state_lock); |
Eli Cohen | 4c3eb3c | 2010-08-26 17:19:22 +0300 | [diff] [blame] | 90 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 91 | return 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 94 | 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] | 95 | { |
| 96 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 97 | struct mlx4_en_dev *mdev = priv->mdev; |
| 98 | int err; |
Eli Cohen | 4c3eb3c | 2010-08-26 17:19:22 +0300 | [diff] [blame] | 99 | int idx; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 100 | |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 101 | en_dbg(HW, priv, "Killing VID:%d\n", vid); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 102 | |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 103 | clear_bit(vid, priv->active_vlans); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 104 | |
| 105 | /* Remove VID from port VLAN filter */ |
| 106 | mutex_lock(&mdev->state_lock); |
Eli Cohen | 4c3eb3c | 2010-08-26 17:19:22 +0300 | [diff] [blame] | 107 | if (!mlx4_find_cached_vlan(mdev->dev, priv->port, vid, &idx)) |
| 108 | mlx4_unregister_vlan(mdev->dev, priv->port, idx); |
| 109 | else |
| 110 | en_err(priv, "could not find vid %d in cache\n", vid); |
| 111 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 112 | if (mdev->device_up && priv->port_up) { |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 113 | err = mlx4_SET_VLAN_FLTR(mdev->dev, priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 114 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 115 | en_err(priv, "Failed configuring VLAN filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 116 | } |
| 117 | mutex_unlock(&mdev->state_lock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 118 | |
| 119 | return 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 122 | u64 mlx4_en_mac_to_u64(u8 *addr) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 123 | { |
| 124 | u64 mac = 0; |
| 125 | int i; |
| 126 | |
| 127 | for (i = 0; i < ETH_ALEN; i++) { |
| 128 | mac <<= 8; |
| 129 | mac |= addr[i]; |
| 130 | } |
| 131 | return mac; |
| 132 | } |
| 133 | |
| 134 | static int mlx4_en_set_mac(struct net_device *dev, void *addr) |
| 135 | { |
| 136 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 137 | struct mlx4_en_dev *mdev = priv->mdev; |
| 138 | struct sockaddr *saddr = addr; |
| 139 | |
| 140 | if (!is_valid_ether_addr(saddr->sa_data)) |
| 141 | return -EADDRNOTAVAIL; |
| 142 | |
| 143 | memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN); |
| 144 | priv->mac = mlx4_en_mac_to_u64(dev->dev_addr); |
| 145 | queue_work(mdev->workqueue, &priv->mac_task); |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static void mlx4_en_do_set_mac(struct work_struct *work) |
| 150 | { |
| 151 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 152 | mac_task); |
| 153 | struct mlx4_en_dev *mdev = priv->mdev; |
| 154 | int err = 0; |
| 155 | |
| 156 | mutex_lock(&mdev->state_lock); |
| 157 | if (priv->port_up) { |
| 158 | /* Remove old MAC and insert the new one */ |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 159 | err = mlx4_replace_mac(mdev->dev, priv->port, |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 160 | priv->base_qpn, priv->mac); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 161 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 162 | en_err(priv, "Failed changing HW MAC address\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 163 | } else |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 164 | en_dbg(HW, priv, "Port is down while " |
| 165 | "registering mac, exiting...\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 166 | |
| 167 | mutex_unlock(&mdev->state_lock); |
| 168 | } |
| 169 | |
| 170 | static void mlx4_en_clear_list(struct net_device *dev) |
| 171 | { |
| 172 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 173 | struct mlx4_en_mc_list *tmp, *mc_to_del; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 174 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 175 | list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) { |
| 176 | list_del(&mc_to_del->list); |
| 177 | kfree(mc_to_del); |
| 178 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static void mlx4_en_cache_mclist(struct net_device *dev) |
| 182 | { |
| 183 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 184 | struct netdev_hw_addr *ha; |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 185 | struct mlx4_en_mc_list *tmp; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 186 | |
Alexander Guller | 0e03567 | 2011-12-19 04:02:58 +0000 | [diff] [blame] | 187 | mlx4_en_clear_list(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 188 | netdev_for_each_mc_addr(ha, dev) { |
| 189 | tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC); |
| 190 | if (!tmp) { |
| 191 | en_err(priv, "failed to allocate multicast list\n"); |
| 192 | mlx4_en_clear_list(dev); |
| 193 | return; |
| 194 | } |
| 195 | memcpy(tmp->addr, ha->addr, ETH_ALEN); |
| 196 | list_add_tail(&tmp->list, &priv->mc_list); |
| 197 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 200 | static void update_mclist_flags(struct mlx4_en_priv *priv, |
| 201 | struct list_head *dst, |
| 202 | struct list_head *src) |
| 203 | { |
| 204 | struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc; |
| 205 | bool found; |
| 206 | |
| 207 | /* Find all the entries that should be removed from dst, |
| 208 | * These are the entries that are not found in src |
| 209 | */ |
| 210 | list_for_each_entry(dst_tmp, dst, list) { |
| 211 | found = false; |
| 212 | list_for_each_entry(src_tmp, src, list) { |
| 213 | if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) { |
| 214 | found = true; |
| 215 | break; |
| 216 | } |
| 217 | } |
| 218 | if (!found) |
| 219 | dst_tmp->action = MCLIST_REM; |
| 220 | } |
| 221 | |
| 222 | /* Add entries that exist in src but not in dst |
| 223 | * mark them as need to add |
| 224 | */ |
| 225 | list_for_each_entry(src_tmp, src, list) { |
| 226 | found = false; |
| 227 | list_for_each_entry(dst_tmp, dst, list) { |
| 228 | if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) { |
| 229 | dst_tmp->action = MCLIST_NONE; |
| 230 | found = true; |
| 231 | break; |
| 232 | } |
| 233 | } |
| 234 | if (!found) { |
| 235 | new_mc = kmalloc(sizeof(struct mlx4_en_mc_list), |
| 236 | GFP_KERNEL); |
| 237 | if (!new_mc) { |
| 238 | en_err(priv, "Failed to allocate current multicast list\n"); |
| 239 | return; |
| 240 | } |
| 241 | memcpy(new_mc, src_tmp, |
| 242 | sizeof(struct mlx4_en_mc_list)); |
| 243 | new_mc->action = MCLIST_ADD; |
| 244 | list_add_tail(&new_mc->list, dst); |
| 245 | } |
| 246 | } |
| 247 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 248 | |
| 249 | static void mlx4_en_set_multicast(struct net_device *dev) |
| 250 | { |
| 251 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 252 | |
| 253 | if (!priv->port_up) |
| 254 | return; |
| 255 | |
| 256 | queue_work(priv->mdev->workqueue, &priv->mcast_task); |
| 257 | } |
| 258 | |
| 259 | static void mlx4_en_do_set_multicast(struct work_struct *work) |
| 260 | { |
| 261 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 262 | mcast_task); |
| 263 | struct mlx4_en_dev *mdev = priv->mdev; |
| 264 | struct net_device *dev = priv->dev; |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 265 | struct mlx4_en_mc_list *mclist, *tmp; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 266 | u64 mcast_addr = 0; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 267 | u8 mc_list[16] = {0}; |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame^] | 268 | int err = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 269 | |
| 270 | mutex_lock(&mdev->state_lock); |
| 271 | if (!mdev->device_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 272 | en_dbg(HW, priv, "Card is not up, " |
| 273 | "ignoring multicast change.\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 274 | goto out; |
| 275 | } |
| 276 | if (!priv->port_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 277 | en_dbg(HW, priv, "Port is down, " |
| 278 | "ignoring multicast change.\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 279 | goto out; |
| 280 | } |
| 281 | |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 282 | if (!netif_carrier_ok(dev)) { |
| 283 | if (!mlx4_en_QUERY_PORT(mdev, priv->port)) { |
| 284 | if (priv->port_state.link_state) { |
| 285 | priv->last_link_state = MLX4_DEV_EVENT_PORT_UP; |
| 286 | netif_carrier_on(dev); |
| 287 | en_dbg(LINK, priv, "Link Up\n"); |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 292 | /* |
| 293 | * Promsicuous mode: disable all filters |
| 294 | */ |
| 295 | |
| 296 | if (dev->flags & IFF_PROMISC) { |
| 297 | if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) { |
| 298 | if (netif_msg_rx_status(priv)) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 299 | en_warn(priv, "Entering promiscuous mode\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 300 | priv->flags |= MLX4_EN_FLAG_PROMISC; |
| 301 | |
| 302 | /* Enable promiscouos mode */ |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame^] | 303 | switch (mdev->dev->caps.steering_mode) { |
| 304 | case MLX4_STEERING_MODE_B0: |
| 305 | err = mlx4_unicast_promisc_add(mdev->dev, |
| 306 | priv->base_qpn, |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 307 | priv->port); |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame^] | 308 | if (err) |
| 309 | en_err(priv, "Failed enabling unicast promiscuous mode\n"); |
| 310 | |
| 311 | /* Add the default qp number as multicast |
| 312 | * promisc |
| 313 | */ |
| 314 | if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) { |
| 315 | err = mlx4_multicast_promisc_add(mdev->dev, |
| 316 | priv->base_qpn, |
| 317 | priv->port); |
| 318 | if (err) |
| 319 | en_err(priv, "Failed enabling multicast promiscuous mode\n"); |
| 320 | priv->flags |= MLX4_EN_FLAG_MC_PROMISC; |
| 321 | } |
| 322 | break; |
| 323 | |
| 324 | case MLX4_STEERING_MODE_A0: |
| 325 | err = mlx4_SET_PORT_qpn_calc(mdev->dev, |
| 326 | priv->port, |
| 327 | priv->base_qpn, |
| 328 | 1); |
| 329 | if (err) |
| 330 | en_err(priv, "Failed enabling promiscuous mode\n"); |
| 331 | break; |
| 332 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 333 | |
| 334 | /* Disable port multicast filter (unconditionally) */ |
| 335 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 336 | 0, MLX4_MCAST_DISABLE); |
| 337 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 338 | en_err(priv, "Failed disabling " |
| 339 | "multicast filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 340 | |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 341 | /* Disable port VLAN filter */ |
| 342 | err = mlx4_SET_VLAN_FLTR(mdev->dev, priv); |
| 343 | if (err) |
| 344 | en_err(priv, "Failed disabling VLAN filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 345 | } |
| 346 | goto out; |
| 347 | } |
| 348 | |
| 349 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 350 | * Not in promiscuous mode |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 351 | */ |
| 352 | |
| 353 | if (priv->flags & MLX4_EN_FLAG_PROMISC) { |
| 354 | if (netif_msg_rx_status(priv)) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 355 | en_warn(priv, "Leaving promiscuous mode\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 356 | priv->flags &= ~MLX4_EN_FLAG_PROMISC; |
| 357 | |
| 358 | /* Disable promiscouos mode */ |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame^] | 359 | switch (mdev->dev->caps.steering_mode) { |
| 360 | case MLX4_STEERING_MODE_B0: |
| 361 | err = mlx4_unicast_promisc_remove(mdev->dev, |
| 362 | priv->base_qpn, |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 363 | priv->port); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 364 | if (err) |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame^] | 365 | en_err(priv, "Failed disabling unicast promiscuous mode\n"); |
| 366 | /* Disable Multicast promisc */ |
| 367 | if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { |
| 368 | err = mlx4_multicast_promisc_remove(mdev->dev, |
| 369 | priv->base_qpn, |
| 370 | priv->port); |
| 371 | if (err) |
| 372 | en_err(priv, "Failed disabling multicast promiscuous mode\n"); |
| 373 | priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; |
| 374 | } |
| 375 | break; |
| 376 | |
| 377 | case MLX4_STEERING_MODE_A0: |
| 378 | err = mlx4_SET_PORT_qpn_calc(mdev->dev, |
| 379 | priv->port, |
| 380 | priv->base_qpn, 0); |
| 381 | if (err) |
| 382 | en_err(priv, "Failed disabling promiscuous mode\n"); |
| 383 | break; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 386 | /* Enable port VLAN filter */ |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 387 | err = mlx4_SET_VLAN_FLTR(mdev->dev, priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 388 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 389 | en_err(priv, "Failed enabling VLAN filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /* Enable/disable the multicast filter according to IFF_ALLMULTI */ |
| 393 | if (dev->flags & IFF_ALLMULTI) { |
| 394 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 395 | 0, MLX4_MCAST_DISABLE); |
| 396 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 397 | en_err(priv, "Failed disabling multicast filter\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 398 | |
| 399 | /* Add the default qp number as multicast promisc */ |
| 400 | if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) { |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame^] | 401 | switch (mdev->dev->caps.steering_mode) { |
| 402 | case MLX4_STEERING_MODE_B0: |
| 403 | err = mlx4_multicast_promisc_add(mdev->dev, |
| 404 | priv->base_qpn, |
| 405 | priv->port); |
| 406 | break; |
| 407 | |
| 408 | case MLX4_STEERING_MODE_A0: |
| 409 | break; |
| 410 | } |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 411 | if (err) |
| 412 | en_err(priv, "Failed entering multicast promisc mode\n"); |
| 413 | priv->flags |= MLX4_EN_FLAG_MC_PROMISC; |
| 414 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 415 | } else { |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 416 | /* Disable Multicast promisc */ |
| 417 | if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) { |
Hadar Hen Zion | c96d97f | 2012-07-05 04:03:44 +0000 | [diff] [blame^] | 418 | switch (mdev->dev->caps.steering_mode) { |
| 419 | case MLX4_STEERING_MODE_B0: |
| 420 | err = mlx4_multicast_promisc_remove(mdev->dev, |
| 421 | priv->base_qpn, |
| 422 | priv->port); |
| 423 | break; |
| 424 | |
| 425 | case MLX4_STEERING_MODE_A0: |
| 426 | break; |
| 427 | } |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 428 | if (err) |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 429 | en_err(priv, "Failed disabling multicast promiscuous mode\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 430 | priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC; |
| 431 | } |
Jiri Pirko | ff6e216 | 2010-03-01 05:09:14 +0000 | [diff] [blame] | 432 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 433 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 434 | 0, MLX4_MCAST_DISABLE); |
| 435 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 436 | en_err(priv, "Failed disabling multicast filter\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 437 | |
| 438 | /* Flush mcast filter and init it with broadcast address */ |
| 439 | mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST, |
| 440 | 1, MLX4_MCAST_CONFIG); |
| 441 | |
| 442 | /* Update multicast list - we cache all addresses so they won't |
| 443 | * change while HW is updated holding the command semaphor */ |
| 444 | netif_tx_lock_bh(dev); |
| 445 | mlx4_en_cache_mclist(dev); |
| 446 | netif_tx_unlock_bh(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 447 | list_for_each_entry(mclist, &priv->mc_list, list) { |
| 448 | mcast_addr = mlx4_en_mac_to_u64(mclist->addr); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 449 | mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, |
| 450 | mcast_addr, 0, MLX4_MCAST_CONFIG); |
| 451 | } |
| 452 | err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, |
| 453 | 0, MLX4_MCAST_ENABLE); |
| 454 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 455 | en_err(priv, "Failed enabling multicast filter\n"); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 456 | |
| 457 | update_mclist_flags(priv, &priv->curr_list, &priv->mc_list); |
| 458 | list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { |
| 459 | if (mclist->action == MCLIST_REM) { |
| 460 | /* detach this address and delete from list */ |
| 461 | memcpy(&mc_list[10], mclist->addr, ETH_ALEN); |
| 462 | mc_list[5] = priv->port; |
| 463 | err = mlx4_multicast_detach(mdev->dev, |
| 464 | &priv->rss_map.indir_qp, |
| 465 | mc_list, |
| 466 | MLX4_PROT_ETH); |
| 467 | if (err) |
| 468 | en_err(priv, "Fail to detach multicast address\n"); |
| 469 | |
| 470 | /* remove from list */ |
| 471 | list_del(&mclist->list); |
| 472 | kfree(mclist); |
| 473 | } |
| 474 | |
| 475 | if (mclist->action == MCLIST_ADD) { |
| 476 | /* attach the address */ |
| 477 | memcpy(&mc_list[10], mclist->addr, ETH_ALEN); |
| 478 | mc_list[5] = priv->port; |
| 479 | err = mlx4_multicast_attach(mdev->dev, |
| 480 | &priv->rss_map.indir_qp, |
| 481 | mc_list, 0, |
| 482 | MLX4_PROT_ETH); |
| 483 | if (err) |
| 484 | en_err(priv, "Fail to attach multicast address\n"); |
| 485 | |
| 486 | } |
| 487 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 488 | } |
| 489 | out: |
| 490 | mutex_unlock(&mdev->state_lock); |
| 491 | } |
| 492 | |
| 493 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 494 | static void mlx4_en_netpoll(struct net_device *dev) |
| 495 | { |
| 496 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 497 | struct mlx4_en_cq *cq; |
| 498 | unsigned long flags; |
| 499 | int i; |
| 500 | |
| 501 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 502 | cq = &priv->rx_cq[i]; |
| 503 | spin_lock_irqsave(&cq->lock, flags); |
| 504 | napi_synchronize(&cq->napi); |
| 505 | mlx4_en_process_rx_cq(dev, cq, 0); |
| 506 | spin_unlock_irqrestore(&cq->lock, flags); |
| 507 | } |
| 508 | } |
| 509 | #endif |
| 510 | |
| 511 | static void mlx4_en_tx_timeout(struct net_device *dev) |
| 512 | { |
| 513 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 514 | struct mlx4_en_dev *mdev = priv->mdev; |
| 515 | |
| 516 | if (netif_msg_timer(priv)) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 517 | en_warn(priv, "Tx timeout called on port:%d\n", priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 518 | |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 519 | priv->port_stats.tx_timeout++; |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 520 | en_dbg(DRV, priv, "Scheduling watchdog\n"); |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 521 | queue_work(mdev->workqueue, &priv->watchdog_task); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | |
| 525 | static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev) |
| 526 | { |
| 527 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 528 | |
| 529 | spin_lock_bh(&priv->stats_lock); |
| 530 | memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats)); |
| 531 | spin_unlock_bh(&priv->stats_lock); |
| 532 | |
| 533 | return &priv->ret_stats; |
| 534 | } |
| 535 | |
| 536 | static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv) |
| 537 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 538 | struct mlx4_en_cq *cq; |
| 539 | int i; |
| 540 | |
| 541 | /* If we haven't received a specific coalescing setting |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 542 | * (module param), we set the moderation parameters as follows: |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 543 | * - moder_cnt is set to the number of mtu sized packets to |
| 544 | * satisfy our coelsing target. |
| 545 | * - moder_time is set to a fixed value. |
| 546 | */ |
Yevgeny Petrilin | 3db36fb | 2009-06-01 23:23:13 +0000 | [diff] [blame] | 547 | priv->rx_frames = MLX4_EN_RX_COAL_TARGET; |
Yevgeny Petrilin | 60b9f9e | 2008-12-25 18:19:47 -0800 | [diff] [blame] | 548 | priv->rx_usecs = MLX4_EN_RX_COAL_TIME; |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 549 | priv->tx_frames = MLX4_EN_TX_COAL_PKTS; |
| 550 | priv->tx_usecs = MLX4_EN_TX_COAL_TIME; |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 551 | en_dbg(INTR, priv, "Default coalesing params for mtu:%d - " |
| 552 | "rx_frames:%d rx_usecs:%d\n", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 553 | priv->dev->mtu, priv->rx_frames, priv->rx_usecs); |
| 554 | |
| 555 | /* Setup cq moderation params */ |
| 556 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 557 | cq = &priv->rx_cq[i]; |
| 558 | cq->moder_cnt = priv->rx_frames; |
| 559 | cq->moder_time = priv->rx_usecs; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 560 | priv->last_moder_time[i] = MLX4_EN_AUTO_CONF; |
| 561 | priv->last_moder_packets[i] = 0; |
| 562 | priv->last_moder_bytes[i] = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 566 | cq = &priv->tx_cq[i]; |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 567 | cq->moder_cnt = priv->tx_frames; |
| 568 | cq->moder_time = priv->tx_usecs; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /* Reset auto-moderation params */ |
| 572 | priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW; |
| 573 | priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW; |
| 574 | priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH; |
| 575 | priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH; |
| 576 | priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL; |
Yevgeny Petrilin | 60b9f9e | 2008-12-25 18:19:47 -0800 | [diff] [blame] | 577 | priv->adaptive_rx_coal = 1; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 578 | priv->last_moder_jiffies = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 579 | priv->last_moder_tx_packets = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv) |
| 583 | { |
| 584 | unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 585 | struct mlx4_en_cq *cq; |
| 586 | unsigned long packets; |
| 587 | unsigned long rate; |
| 588 | unsigned long avg_pkt_size; |
| 589 | unsigned long rx_packets; |
| 590 | unsigned long rx_bytes; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 591 | unsigned long rx_pkt_diff; |
| 592 | int moder_time; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 593 | int ring, err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 594 | |
| 595 | if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ) |
| 596 | return; |
| 597 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 598 | for (ring = 0; ring < priv->rx_ring_num; ring++) { |
| 599 | spin_lock_bh(&priv->stats_lock); |
| 600 | rx_packets = priv->rx_ring[ring].packets; |
| 601 | rx_bytes = priv->rx_ring[ring].bytes; |
| 602 | spin_unlock_bh(&priv->stats_lock); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 603 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 604 | rx_pkt_diff = ((unsigned long) (rx_packets - |
| 605 | priv->last_moder_packets[ring])); |
| 606 | packets = rx_pkt_diff; |
| 607 | rate = packets * HZ / period; |
| 608 | avg_pkt_size = packets ? ((unsigned long) (rx_bytes - |
| 609 | priv->last_moder_bytes[ring])) / packets : 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 610 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 611 | /* Apply auto-moderation only when packet rate |
| 612 | * exceeds a rate that it matters */ |
| 613 | if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) && |
| 614 | avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 615 | if (rate < priv->pkt_rate_low) |
| 616 | moder_time = priv->rx_usecs_low; |
| 617 | else if (rate > priv->pkt_rate_high) |
| 618 | moder_time = priv->rx_usecs_high; |
| 619 | else |
| 620 | moder_time = (rate - priv->pkt_rate_low) * |
| 621 | (priv->rx_usecs_high - priv->rx_usecs_low) / |
| 622 | (priv->pkt_rate_high - priv->pkt_rate_low) + |
| 623 | priv->rx_usecs_low; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 624 | } else { |
| 625 | moder_time = priv->rx_usecs_low; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 626 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 627 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 628 | if (moder_time != priv->last_moder_time[ring]) { |
| 629 | priv->last_moder_time[ring] = moder_time; |
| 630 | cq = &priv->rx_cq[ring]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 631 | cq->moder_time = moder_time; |
| 632 | err = mlx4_en_set_cq_moder(priv, cq); |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 633 | if (err) |
| 634 | en_err(priv, "Failed modifying moderation " |
| 635 | "for cq:%d\n", ring); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 636 | } |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 637 | priv->last_moder_packets[ring] = rx_packets; |
| 638 | priv->last_moder_bytes[ring] = rx_bytes; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 641 | priv->last_moder_jiffies = jiffies; |
| 642 | } |
| 643 | |
| 644 | static void mlx4_en_do_get_stats(struct work_struct *work) |
| 645 | { |
Jean Delvare | bf6aede | 2009-04-02 16:56:54 -0700 | [diff] [blame] | 646 | struct delayed_work *delay = to_delayed_work(work); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 647 | struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv, |
| 648 | stats_task); |
| 649 | struct mlx4_en_dev *mdev = priv->mdev; |
| 650 | int err; |
| 651 | |
| 652 | err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0); |
| 653 | if (err) |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 654 | en_dbg(HW, priv, "Could not update stats\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 655 | |
| 656 | mutex_lock(&mdev->state_lock); |
| 657 | if (mdev->device_up) { |
| 658 | if (priv->port_up) |
| 659 | mlx4_en_auto_moderation(priv); |
| 660 | |
| 661 | queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY); |
| 662 | } |
Yevgeny Petrilin | d7e1a48 | 2010-08-24 03:46:38 +0000 | [diff] [blame] | 663 | if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) { |
| 664 | queue_work(mdev->workqueue, &priv->mac_task); |
| 665 | mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0; |
| 666 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 667 | mutex_unlock(&mdev->state_lock); |
| 668 | } |
| 669 | |
| 670 | static void mlx4_en_linkstate(struct work_struct *work) |
| 671 | { |
| 672 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 673 | linkstate_task); |
| 674 | struct mlx4_en_dev *mdev = priv->mdev; |
| 675 | int linkstate = priv->link_state; |
| 676 | |
| 677 | mutex_lock(&mdev->state_lock); |
| 678 | /* If observable port state changed set carrier state and |
| 679 | * report to system log */ |
| 680 | if (priv->last_link_state != linkstate) { |
| 681 | if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) { |
Yevgeny Petrilin | e5cc44b | 2010-08-24 03:46:01 +0000 | [diff] [blame] | 682 | en_info(priv, "Link Down\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 683 | netif_carrier_off(priv->dev); |
| 684 | } else { |
Yevgeny Petrilin | e5cc44b | 2010-08-24 03:46:01 +0000 | [diff] [blame] | 685 | en_info(priv, "Link Up\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 686 | netif_carrier_on(priv->dev); |
| 687 | } |
| 688 | } |
| 689 | priv->last_link_state = linkstate; |
| 690 | mutex_unlock(&mdev->state_lock); |
| 691 | } |
| 692 | |
| 693 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 694 | int mlx4_en_start_port(struct net_device *dev) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 695 | { |
| 696 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 697 | struct mlx4_en_dev *mdev = priv->mdev; |
| 698 | struct mlx4_en_cq *cq; |
| 699 | struct mlx4_en_tx_ring *tx_ring; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 700 | int rx_index = 0; |
| 701 | int tx_index = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 702 | int err = 0; |
| 703 | int i; |
| 704 | int j; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 705 | u8 mc_list[16] = {0}; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 706 | |
| 707 | if (priv->port_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 708 | en_dbg(DRV, priv, "start port called while port already up\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 709 | return 0; |
| 710 | } |
| 711 | |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 712 | INIT_LIST_HEAD(&priv->mc_list); |
| 713 | INIT_LIST_HEAD(&priv->curr_list); |
| 714 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 715 | /* Calculate Rx buf size */ |
| 716 | dev->mtu = min(dev->mtu, priv->max_mtu); |
| 717 | mlx4_en_calc_rx_buf(dev); |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 718 | 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] | 719 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 720 | /* Configure rx cq's and rings */ |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 721 | err = mlx4_en_activate_rx_rings(priv); |
| 722 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 723 | en_err(priv, "Failed to activate RX rings\n"); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 724 | return err; |
| 725 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 726 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 727 | cq = &priv->rx_cq[i]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 728 | |
Alexander Guller | 76532d0 | 2011-10-09 05:26:31 +0000 | [diff] [blame] | 729 | err = mlx4_en_activate_cq(priv, cq, i); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 730 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 731 | en_err(priv, "Failed activating Rx CQ\n"); |
Yevgeny Petrilin | a423330 | 2009-04-26 20:41:34 +0000 | [diff] [blame] | 732 | goto cq_err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 733 | } |
| 734 | for (j = 0; j < cq->size; j++) |
| 735 | cq->buf[j].owner_sr_opcode = MLX4_CQE_OWNER_MASK; |
| 736 | err = mlx4_en_set_cq_moder(priv, cq); |
| 737 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 738 | en_err(priv, "Failed setting cq moderation parameters"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 739 | mlx4_en_deactivate_cq(priv, cq); |
| 740 | goto cq_err; |
| 741 | } |
| 742 | mlx4_en_arm_cq(priv, cq); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 743 | priv->rx_ring[i].cqn = cq->mcq.cqn; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 744 | ++rx_index; |
| 745 | } |
| 746 | |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 747 | /* Set qp number */ |
| 748 | en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port); |
| 749 | err = mlx4_get_eth_qp(mdev->dev, priv->port, |
| 750 | priv->mac, &priv->base_qpn); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 751 | if (err) { |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 752 | en_err(priv, "Failed getting eth qp\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 753 | goto cq_err; |
| 754 | } |
| 755 | mdev->mac_removed[priv->port] = 0; |
| 756 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 757 | err = mlx4_en_config_rss_steer(priv); |
| 758 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 759 | en_err(priv, "Failed configuring rss steering\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 760 | goto mac_err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | /* Configure tx cq's and rings */ |
| 764 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 765 | /* Configure cq */ |
| 766 | cq = &priv->tx_cq[i]; |
Alexander Guller | 76532d0 | 2011-10-09 05:26:31 +0000 | [diff] [blame] | 767 | err = mlx4_en_activate_cq(priv, cq, i); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 768 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 769 | en_err(priv, "Failed allocating Tx CQ\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 770 | goto tx_err; |
| 771 | } |
| 772 | err = mlx4_en_set_cq_moder(priv, cq); |
| 773 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 774 | en_err(priv, "Failed setting cq moderation parameters"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 775 | mlx4_en_deactivate_cq(priv, cq); |
| 776 | goto tx_err; |
| 777 | } |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 778 | 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] | 779 | cq->buf->wqe_index = cpu_to_be16(0xffff); |
| 780 | |
| 781 | /* Configure ring */ |
| 782 | tx_ring = &priv->tx_ring[i]; |
Amir Vadai | 0e98b52 | 2012-04-04 21:33:24 +0000 | [diff] [blame] | 783 | err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn, |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 784 | i / priv->mdev->profile.num_tx_rings_p_up); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 785 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 786 | en_err(priv, "Failed allocating Tx ring\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 787 | mlx4_en_deactivate_cq(priv, cq); |
| 788 | goto tx_err; |
| 789 | } |
Yevgeny Petrilin | 5b263f5 | 2012-04-23 02:18:50 +0000 | [diff] [blame] | 790 | tx_ring->tx_queue = netdev_get_tx_queue(dev, i); |
Yevgeny Petrilin | e22979d | 2012-04-23 02:18:39 +0000 | [diff] [blame] | 791 | |
| 792 | /* Arm CQ for TX completions */ |
| 793 | mlx4_en_arm_cq(priv, cq); |
| 794 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 795 | /* Set initial ownership of all Tx TXBBs to SW (1) */ |
| 796 | for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE) |
| 797 | *((u32 *) (tx_ring->buf + j)) = 0xffffffff; |
| 798 | ++tx_index; |
| 799 | } |
| 800 | |
| 801 | /* Configure port */ |
| 802 | err = mlx4_SET_PORT_general(mdev->dev, priv->port, |
| 803 | priv->rx_skb_size + ETH_FCS_LEN, |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 804 | priv->prof->tx_pause, |
| 805 | priv->prof->tx_ppp, |
| 806 | priv->prof->rx_pause, |
| 807 | priv->prof->rx_ppp); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 808 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 809 | en_err(priv, "Failed setting port general configurations " |
| 810 | "for port %d, with error %d\n", priv->port, err); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 811 | goto tx_err; |
| 812 | } |
| 813 | /* Set default qp number */ |
| 814 | err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0); |
| 815 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 816 | en_err(priv, "Failed setting default qp numbers\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 817 | goto tx_err; |
| 818 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 819 | |
| 820 | /* Init port */ |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 821 | en_dbg(HW, priv, "Initializing port\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 822 | err = mlx4_INIT_PORT(mdev->dev, priv->port); |
| 823 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 824 | en_err(priv, "Failed Initializing port\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 825 | goto tx_err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 828 | /* Attach rx QP to bradcast address */ |
| 829 | memset(&mc_list[10], 0xff, ETH_ALEN); |
| 830 | mc_list[5] = priv->port; |
| 831 | if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list, |
| 832 | 0, MLX4_PROT_ETH)) |
| 833 | mlx4_warn(mdev, "Failed Attaching Broadcast\n"); |
| 834 | |
Herbert Xu | b5845f9 | 2011-03-27 01:01:26 +0000 | [diff] [blame] | 835 | /* Must redo promiscuous mode setup. */ |
| 836 | priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC); |
| 837 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 838 | /* Schedule multicast task to populate multicast list */ |
| 839 | queue_work(mdev->workqueue, &priv->mcast_task); |
| 840 | |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 841 | mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap); |
| 842 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 843 | priv->port_up = true; |
Yevgeny Petrilin | a11faac | 2009-06-20 22:15:46 +0000 | [diff] [blame] | 844 | netif_tx_start_all_queues(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 845 | return 0; |
| 846 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 847 | tx_err: |
| 848 | while (tx_index--) { |
| 849 | mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[tx_index]); |
| 850 | mlx4_en_deactivate_cq(priv, &priv->tx_cq[tx_index]); |
| 851 | } |
| 852 | |
| 853 | mlx4_en_release_rss_steer(priv); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 854 | mac_err: |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 855 | mlx4_put_eth_qp(mdev->dev, priv->port, priv->mac, priv->base_qpn); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 856 | cq_err: |
| 857 | while (rx_index--) |
| 858 | mlx4_en_deactivate_cq(priv, &priv->rx_cq[rx_index]); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 859 | for (i = 0; i < priv->rx_ring_num; i++) |
| 860 | mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 861 | |
| 862 | return err; /* need to close devices */ |
| 863 | } |
| 864 | |
| 865 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 866 | void mlx4_en_stop_port(struct net_device *dev) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 867 | { |
| 868 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 869 | struct mlx4_en_dev *mdev = priv->mdev; |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 870 | struct mlx4_en_mc_list *mclist, *tmp; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 871 | int i; |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 872 | u8 mc_list[16] = {0}; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 873 | |
| 874 | if (!priv->port_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 875 | en_dbg(DRV, priv, "stop port called while port already down\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 876 | return; |
| 877 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 878 | |
| 879 | /* Synchronize with tx routine */ |
| 880 | netif_tx_lock_bh(dev); |
Yevgeny Petrilin | 3c05f5e | 2009-06-20 22:15:52 +0000 | [diff] [blame] | 881 | netif_tx_stop_all_queues(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 882 | netif_tx_unlock_bh(dev); |
| 883 | |
Yevgeny Petrilin | 7c28738 | 2010-08-24 03:45:45 +0000 | [diff] [blame] | 884 | /* Set port as not active */ |
Yevgeny Petrilin | 3c05f5e | 2009-06-20 22:15:52 +0000 | [diff] [blame] | 885 | priv->port_up = false; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 886 | |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 887 | /* Detach All multicasts */ |
| 888 | memset(&mc_list[10], 0xff, ETH_ALEN); |
| 889 | mc_list[5] = priv->port; |
| 890 | mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list, |
| 891 | MLX4_PROT_ETH); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 892 | list_for_each_entry(mclist, &priv->curr_list, list) { |
| 893 | memcpy(&mc_list[10], mclist->addr, ETH_ALEN); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 894 | mc_list[5] = priv->port; |
| 895 | mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, |
| 896 | mc_list, MLX4_PROT_ETH); |
| 897 | } |
| 898 | mlx4_en_clear_list(dev); |
Yevgeny Petrilin | 6d19993 | 2012-07-05 04:03:43 +0000 | [diff] [blame] | 899 | list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { |
| 900 | list_del(&mclist->list); |
| 901 | kfree(mclist); |
| 902 | } |
| 903 | |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 904 | /* Flush multicast filter */ |
| 905 | mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG); |
| 906 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 907 | /* Free TX Rings */ |
| 908 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 909 | mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[i]); |
| 910 | mlx4_en_deactivate_cq(priv, &priv->tx_cq[i]); |
| 911 | } |
| 912 | msleep(10); |
| 913 | |
| 914 | for (i = 0; i < priv->tx_ring_num; i++) |
| 915 | mlx4_en_free_tx_buf(dev, &priv->tx_ring[i]); |
| 916 | |
| 917 | /* Free RSS qps */ |
| 918 | mlx4_en_release_rss_steer(priv); |
| 919 | |
Eugenia Emantayev | ffe455a | 2011-12-13 04:16:21 +0000 | [diff] [blame] | 920 | /* Unregister Mac address for the port */ |
| 921 | mlx4_put_eth_qp(mdev->dev, priv->port, priv->mac, priv->base_qpn); |
| 922 | mdev->mac_removed[priv->port] = 1; |
| 923 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 924 | /* Free RX Rings */ |
| 925 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 926 | mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]); |
| 927 | while (test_bit(NAPI_STATE_SCHED, &priv->rx_cq[i].napi.state)) |
| 928 | msleep(1); |
| 929 | mlx4_en_deactivate_cq(priv, &priv->rx_cq[i]); |
| 930 | } |
Yevgeny Petrilin | 7c28738 | 2010-08-24 03:45:45 +0000 | [diff] [blame] | 931 | |
| 932 | /* close port*/ |
| 933 | mlx4_CLOSE_PORT(mdev->dev, priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | static void mlx4_en_restart(struct work_struct *work) |
| 937 | { |
| 938 | struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, |
| 939 | watchdog_task); |
| 940 | struct mlx4_en_dev *mdev = priv->mdev; |
| 941 | struct net_device *dev = priv->dev; |
Yevgeny Petrilin | 5b263f5 | 2012-04-23 02:18:50 +0000 | [diff] [blame] | 942 | int i; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 943 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 944 | 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] | 945 | |
| 946 | mutex_lock(&mdev->state_lock); |
| 947 | if (priv->port_up) { |
| 948 | mlx4_en_stop_port(dev); |
Yevgeny Petrilin | 5b263f5 | 2012-04-23 02:18:50 +0000 | [diff] [blame] | 949 | for (i = 0; i < priv->tx_ring_num; i++) |
| 950 | netdev_tx_reset_queue(priv->tx_ring[i].tx_queue); |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 951 | if (mlx4_en_start_port(dev)) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 952 | en_err(priv, "Failed restarting port %d\n", priv->port); |
Yevgeny Petrilin | 1e338db | 2009-04-20 04:26:05 +0000 | [diff] [blame] | 953 | } |
| 954 | mutex_unlock(&mdev->state_lock); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Eugenia Emantayev | b477ba6 | 2012-01-19 09:42:37 +0000 | [diff] [blame] | 957 | static void mlx4_en_clear_stats(struct net_device *dev) |
| 958 | { |
| 959 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 960 | struct mlx4_en_dev *mdev = priv->mdev; |
| 961 | int i; |
| 962 | |
| 963 | if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1)) |
| 964 | en_dbg(HW, priv, "Failed dumping statistics\n"); |
| 965 | |
| 966 | memset(&priv->stats, 0, sizeof(priv->stats)); |
| 967 | memset(&priv->pstats, 0, sizeof(priv->pstats)); |
| 968 | memset(&priv->pkstats, 0, sizeof(priv->pkstats)); |
| 969 | memset(&priv->port_stats, 0, sizeof(priv->port_stats)); |
| 970 | |
| 971 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 972 | priv->tx_ring[i].bytes = 0; |
| 973 | priv->tx_ring[i].packets = 0; |
| 974 | priv->tx_ring[i].tx_csum = 0; |
| 975 | } |
| 976 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 977 | priv->rx_ring[i].bytes = 0; |
| 978 | priv->rx_ring[i].packets = 0; |
| 979 | priv->rx_ring[i].csum_ok = 0; |
| 980 | priv->rx_ring[i].csum_none = 0; |
| 981 | } |
| 982 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 983 | |
| 984 | static int mlx4_en_open(struct net_device *dev) |
| 985 | { |
| 986 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 987 | struct mlx4_en_dev *mdev = priv->mdev; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 988 | int err = 0; |
| 989 | |
| 990 | mutex_lock(&mdev->state_lock); |
| 991 | |
| 992 | if (!mdev->device_up) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 993 | en_err(priv, "Cannot open - device down/disabled\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 994 | err = -EBUSY; |
| 995 | goto out; |
| 996 | } |
| 997 | |
Eugenia Emantayev | b477ba6 | 2012-01-19 09:42:37 +0000 | [diff] [blame] | 998 | /* Reset HW statistics and SW counters */ |
| 999 | mlx4_en_clear_stats(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1000 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1001 | err = mlx4_en_start_port(dev); |
| 1002 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1003 | en_err(priv, "Failed starting port:%d\n", priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1004 | |
| 1005 | out: |
| 1006 | mutex_unlock(&mdev->state_lock); |
| 1007 | return err; |
| 1008 | } |
| 1009 | |
| 1010 | |
| 1011 | static int mlx4_en_close(struct net_device *dev) |
| 1012 | { |
| 1013 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1014 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1015 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1016 | en_dbg(IFDOWN, priv, "Close port called\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1017 | |
| 1018 | mutex_lock(&mdev->state_lock); |
| 1019 | |
| 1020 | mlx4_en_stop_port(dev); |
| 1021 | netif_carrier_off(dev); |
| 1022 | |
| 1023 | mutex_unlock(&mdev->state_lock); |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1027 | void mlx4_en_free_resources(struct mlx4_en_priv *priv) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1028 | { |
| 1029 | int i; |
| 1030 | |
| 1031 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 1032 | if (priv->tx_ring[i].tx_info) |
| 1033 | mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]); |
| 1034 | if (priv->tx_cq[i].buf) |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1035 | mlx4_en_destroy_cq(priv, &priv->tx_cq[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 1039 | if (priv->rx_ring[i].rx_info) |
Thadeu Lima de Souza Cascardo | 68355f7 | 2012-02-06 08:39:49 +0000 | [diff] [blame] | 1040 | mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i], |
| 1041 | priv->prof->rx_ring_size, priv->stride); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1042 | if (priv->rx_cq[i].buf) |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1043 | mlx4_en_destroy_cq(priv, &priv->rx_cq[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1044 | } |
Yevgeny Petrilin | 044ca2a | 2012-06-25 00:24:13 +0000 | [diff] [blame] | 1045 | |
| 1046 | if (priv->base_tx_qpn) { |
| 1047 | mlx4_qp_release_range(priv->mdev->dev, priv->base_tx_qpn, priv->tx_ring_num); |
| 1048 | priv->base_tx_qpn = 0; |
| 1049 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1052 | int mlx4_en_alloc_resources(struct mlx4_en_priv *priv) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1053 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1054 | struct mlx4_en_port_profile *prof = priv->prof; |
| 1055 | int i; |
Yevgeny Petrilin | 044ca2a | 2012-06-25 00:24:13 +0000 | [diff] [blame] | 1056 | int err; |
Yevgeny Petrilin | 87a5c38 | 2011-03-22 22:38:52 +0000 | [diff] [blame] | 1057 | |
Yevgeny Petrilin | 044ca2a | 2012-06-25 00:24:13 +0000 | [diff] [blame] | 1058 | 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] | 1059 | if (err) { |
| 1060 | en_err(priv, "failed reserving range for TX rings\n"); |
| 1061 | return err; |
| 1062 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1063 | |
| 1064 | /* Create tx Rings */ |
| 1065 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 1066 | if (mlx4_en_create_cq(priv, &priv->tx_cq[i], |
| 1067 | prof->tx_ring_size, i, TX)) |
| 1068 | goto err; |
| 1069 | |
Yevgeny Petrilin | 044ca2a | 2012-06-25 00:24:13 +0000 | [diff] [blame] | 1070 | 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] | 1071 | prof->tx_ring_size, TXBB_SIZE)) |
| 1072 | goto err; |
| 1073 | } |
| 1074 | |
| 1075 | /* Create rx Rings */ |
| 1076 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 1077 | if (mlx4_en_create_cq(priv, &priv->rx_cq[i], |
| 1078 | prof->rx_ring_size, i, RX)) |
| 1079 | goto err; |
| 1080 | |
| 1081 | if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i], |
| 1082 | prof->rx_ring_size, priv->stride)) |
| 1083 | goto err; |
| 1084 | } |
| 1085 | |
| 1086 | return 0; |
| 1087 | |
| 1088 | err: |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1089 | en_err(priv, "Failed to allocate NIC resources\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1090 | return -ENOMEM; |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | void mlx4_en_destroy_netdev(struct net_device *dev) |
| 1095 | { |
| 1096 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1097 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1098 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1099 | en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1100 | |
| 1101 | /* Unregister device - this will close the port if it was up */ |
| 1102 | if (priv->registered) |
| 1103 | unregister_netdev(dev); |
| 1104 | |
| 1105 | if (priv->allocated) |
| 1106 | mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE); |
| 1107 | |
| 1108 | cancel_delayed_work(&priv->stats_task); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1109 | /* flush any pending task for this netdev */ |
| 1110 | flush_workqueue(mdev->workqueue); |
| 1111 | |
| 1112 | /* Detach the netdev so tasks would not attempt to access it */ |
| 1113 | mutex_lock(&mdev->state_lock); |
| 1114 | mdev->pndev[priv->port] = NULL; |
| 1115 | mutex_unlock(&mdev->state_lock); |
| 1116 | |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 1117 | mlx4_en_free_resources(priv); |
Amir Vadai | 564c274 | 2012-04-04 21:33:26 +0000 | [diff] [blame] | 1118 | |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 1119 | kfree(priv->tx_ring); |
| 1120 | kfree(priv->tx_cq); |
| 1121 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1122 | free_netdev(dev); |
| 1123 | } |
| 1124 | |
| 1125 | static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu) |
| 1126 | { |
| 1127 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1128 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1129 | int err = 0; |
| 1130 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1131 | en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1132 | dev->mtu, new_mtu); |
| 1133 | |
| 1134 | if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1135 | en_err(priv, "Bad MTU size:%d.\n", new_mtu); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1136 | return -EPERM; |
| 1137 | } |
| 1138 | dev->mtu = new_mtu; |
| 1139 | |
| 1140 | if (netif_running(dev)) { |
| 1141 | mutex_lock(&mdev->state_lock); |
| 1142 | if (!mdev->device_up) { |
| 1143 | /* NIC is probably restarting - let watchdog task reset |
| 1144 | * the port */ |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1145 | en_dbg(DRV, priv, "Change MTU called with card down!?\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1146 | } else { |
| 1147 | mlx4_en_stop_port(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1148 | err = mlx4_en_start_port(dev); |
| 1149 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1150 | en_err(priv, "Failed restarting port:%d\n", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1151 | priv->port); |
| 1152 | queue_work(mdev->workqueue, &priv->watchdog_task); |
| 1153 | } |
| 1154 | } |
| 1155 | mutex_unlock(&mdev->state_lock); |
| 1156 | } |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 1160 | static int mlx4_en_set_features(struct net_device *netdev, |
| 1161 | netdev_features_t features) |
| 1162 | { |
| 1163 | struct mlx4_en_priv *priv = netdev_priv(netdev); |
| 1164 | |
| 1165 | if (features & NETIF_F_LOOPBACK) |
| 1166 | priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK); |
| 1167 | else |
| 1168 | priv->ctrl_flags &= |
| 1169 | cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK); |
| 1170 | |
| 1171 | return 0; |
| 1172 | |
| 1173 | } |
| 1174 | |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1175 | static const struct net_device_ops mlx4_netdev_ops = { |
| 1176 | .ndo_open = mlx4_en_open, |
| 1177 | .ndo_stop = mlx4_en_close, |
| 1178 | .ndo_start_xmit = mlx4_en_xmit, |
Yevgeny Petrilin | f813cad | 2009-06-01 23:24:07 +0000 | [diff] [blame] | 1179 | .ndo_select_queue = mlx4_en_select_queue, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1180 | .ndo_get_stats = mlx4_en_get_stats, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1181 | .ndo_set_rx_mode = mlx4_en_set_multicast, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1182 | .ndo_set_mac_address = mlx4_en_set_mac, |
Stephen Hemminger | 52255bb | 2009-01-09 10:45:37 +0000 | [diff] [blame] | 1183 | .ndo_validate_addr = eth_validate_addr, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1184 | .ndo_change_mtu = mlx4_en_change_mtu, |
| 1185 | .ndo_tx_timeout = mlx4_en_tx_timeout, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1186 | .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid, |
| 1187 | .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid, |
| 1188 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1189 | .ndo_poll_controller = mlx4_en_netpoll, |
| 1190 | #endif |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 1191 | .ndo_set_features = mlx4_en_set_features, |
Amir Vadai | 897d784 | 2012-04-04 21:33:27 +0000 | [diff] [blame] | 1192 | .ndo_setup_tc = mlx4_en_setup_tc, |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1193 | }; |
| 1194 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1195 | int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, |
| 1196 | struct mlx4_en_port_profile *prof) |
| 1197 | { |
| 1198 | struct net_device *dev; |
| 1199 | struct mlx4_en_priv *priv; |
| 1200 | int i; |
| 1201 | int err; |
| 1202 | |
Tom Herbert | f1593d2 | 2011-01-09 19:36:36 +0000 | [diff] [blame] | 1203 | dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv), |
| 1204 | prof->tx_ring_num, prof->rx_ring_num); |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 1205 | if (dev == NULL) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1206 | return -ENOMEM; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1207 | |
| 1208 | SET_NETDEV_DEV(dev, &mdev->dev->pdev->dev); |
Eli Cohen | 741a00b | 2010-05-26 19:56:24 +0000 | [diff] [blame] | 1209 | dev->dev_id = port - 1; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1210 | |
| 1211 | /* |
| 1212 | * Initialize driver private data |
| 1213 | */ |
| 1214 | |
| 1215 | priv = netdev_priv(dev); |
| 1216 | memset(priv, 0, sizeof(struct mlx4_en_priv)); |
| 1217 | priv->dev = dev; |
| 1218 | priv->mdev = mdev; |
Yevgeny Petrilin | ebf8c9a | 2012-03-06 04:03:34 +0000 | [diff] [blame] | 1219 | priv->ddev = &mdev->pdev->dev; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1220 | priv->prof = prof; |
| 1221 | priv->port = port; |
| 1222 | priv->port_up = false; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1223 | priv->flags = prof->flags; |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 1224 | priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE | |
| 1225 | MLX4_WQE_CTRL_SOLICITED); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1226 | priv->tx_ring_num = prof->tx_ring_num; |
Amir Vadai | bc6a474 | 2012-05-17 00:58:10 +0000 | [diff] [blame] | 1227 | priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring) * |
| 1228 | priv->tx_ring_num, GFP_KERNEL); |
| 1229 | if (!priv->tx_ring) { |
| 1230 | err = -ENOMEM; |
| 1231 | goto out; |
| 1232 | } |
| 1233 | priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq) * priv->tx_ring_num, |
| 1234 | GFP_KERNEL); |
| 1235 | if (!priv->tx_cq) { |
| 1236 | err = -ENOMEM; |
| 1237 | goto out; |
| 1238 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1239 | priv->rx_ring_num = prof->rx_ring_num; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1240 | priv->mac_index = -1; |
| 1241 | priv->msg_enable = MLX4_EN_MSG_LEVEL; |
| 1242 | spin_lock_init(&priv->stats_lock); |
| 1243 | INIT_WORK(&priv->mcast_task, mlx4_en_do_set_multicast); |
| 1244 | INIT_WORK(&priv->mac_task, mlx4_en_do_set_mac); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1245 | INIT_WORK(&priv->watchdog_task, mlx4_en_restart); |
| 1246 | INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate); |
| 1247 | INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats); |
Amir Vadai | 564c274 | 2012-04-04 21:33:26 +0000 | [diff] [blame] | 1248 | #ifdef CONFIG_MLX4_EN_DCB |
| 1249 | if (!mlx4_is_slave(priv->mdev->dev)) |
| 1250 | dev->dcbnl_ops = &mlx4_en_dcbnl_ops; |
| 1251 | #endif |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1252 | |
| 1253 | /* Query for default mac and max mtu */ |
| 1254 | priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port]; |
| 1255 | priv->mac = mdev->dev->caps.def_mac[priv->port]; |
| 1256 | if (ILLEGAL_MAC(priv->mac)) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1257 | en_err(priv, "Port: %d, invalid mac burned: 0x%llx, quiting\n", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1258 | priv->port, priv->mac); |
| 1259 | err = -EINVAL; |
| 1260 | goto out; |
| 1261 | } |
| 1262 | |
| 1263 | priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) + |
| 1264 | DS_SIZE * MLX4_EN_MAX_RX_FRAGS); |
| 1265 | err = mlx4_en_alloc_resources(priv); |
| 1266 | if (err) |
| 1267 | goto out; |
| 1268 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1269 | /* Allocate page for receive rings */ |
| 1270 | err = mlx4_alloc_hwq_res(mdev->dev, &priv->res, |
| 1271 | MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE); |
| 1272 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1273 | en_err(priv, "Failed to allocate page for rx qps\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1274 | goto out; |
| 1275 | } |
| 1276 | priv->allocated = 1; |
| 1277 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1278 | /* |
| 1279 | * Initialize netdev entry points |
| 1280 | */ |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1281 | dev->netdev_ops = &mlx4_netdev_ops; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1282 | dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT; |
Ben Hutchings | 1eb63a2 | 2010-09-27 08:29:34 +0000 | [diff] [blame] | 1283 | netif_set_real_num_tx_queues(dev, priv->tx_ring_num); |
| 1284 | netif_set_real_num_rx_queues(dev, priv->rx_ring_num); |
Stephen Hemminger | 3addc56 | 2008-11-21 17:30:58 -0800 | [diff] [blame] | 1285 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1286 | SET_ETHTOOL_OPS(dev, &mlx4_en_ethtool_ops); |
| 1287 | |
| 1288 | /* Set defualt MAC */ |
| 1289 | dev->addr_len = ETH_ALEN; |
Yevgeny Petrilin | 8bf2e58 | 2010-08-24 03:45:30 +0000 | [diff] [blame] | 1290 | for (i = 0; i < ETH_ALEN; i++) { |
| 1291 | dev->dev_addr[ETH_ALEN - 1 - i] = (u8) (priv->mac >> (8 * i)); |
| 1292 | dev->perm_addr[ETH_ALEN - 1 - i] = (u8) (priv->mac >> (8 * i)); |
| 1293 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1294 | |
| 1295 | /* |
| 1296 | * Set driver features |
| 1297 | */ |
Michał Mirosław | c8c64cf | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 1298 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
| 1299 | if (mdev->LSO_support) |
| 1300 | dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6; |
| 1301 | |
| 1302 | dev->vlan_features = dev->hw_features; |
| 1303 | |
Yevgeny Petrilin | ad86107 | 2011-10-18 01:51:24 +0000 | [diff] [blame] | 1304 | dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH; |
Michał Mirosław | c8c64cf | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 1305 | dev->features = dev->hw_features | NETIF_F_HIGHDMA | |
| 1306 | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | |
| 1307 | NETIF_F_HW_VLAN_FILTER; |
Amir Vadai | 60d6fe9 | 2011-11-26 19:55:19 +0000 | [diff] [blame] | 1308 | dev->hw_features |= NETIF_F_LOOPBACK; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1309 | |
| 1310 | mdev->pndev[port] = dev; |
| 1311 | |
| 1312 | netif_carrier_off(dev); |
| 1313 | err = register_netdev(dev); |
| 1314 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1315 | en_err(priv, "Netdev registration failed for port %d\n", port); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1316 | goto out; |
| 1317 | } |
Alexander Guller | 4234144 | 2011-10-09 05:29:35 +0000 | [diff] [blame] | 1318 | priv->registered = 1; |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1319 | |
| 1320 | en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num); |
| 1321 | en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num); |
| 1322 | |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 1323 | /* Configure port */ |
Yevgeny Petrilin | 5c8e904 | 2012-06-25 00:24:11 +0000 | [diff] [blame] | 1324 | mlx4_en_calc_rx_buf(dev); |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 1325 | err = mlx4_SET_PORT_general(mdev->dev, priv->port, |
Yevgeny Petrilin | 5c8e904 | 2012-06-25 00:24:11 +0000 | [diff] [blame] | 1326 | priv->rx_skb_size + ETH_FCS_LEN, |
| 1327 | prof->tx_pause, prof->tx_ppp, |
| 1328 | prof->rx_pause, prof->rx_ppp); |
Yevgeny Petrilin | 9082226 | 2011-03-22 22:37:41 +0000 | [diff] [blame] | 1329 | if (err) { |
| 1330 | en_err(priv, "Failed setting port general configurations " |
| 1331 | "for port %d, with error %d\n", priv->port, err); |
| 1332 | goto out; |
| 1333 | } |
| 1334 | |
| 1335 | /* Init port */ |
| 1336 | en_warn(priv, "Initializing port\n"); |
| 1337 | err = mlx4_INIT_PORT(mdev->dev, priv->port); |
| 1338 | if (err) { |
| 1339 | en_err(priv, "Failed Initializing port\n"); |
| 1340 | goto out; |
| 1341 | } |
Yevgeny Petrilin | 39f17b4 | 2011-03-22 22:37:28 +0000 | [diff] [blame] | 1342 | mlx4_en_set_default_moderation(priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1343 | queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY); |
| 1344 | return 0; |
| 1345 | |
| 1346 | out: |
| 1347 | mlx4_en_destroy_netdev(dev); |
| 1348 | return err; |
| 1349 | } |
| 1350 | |