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