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