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