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