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