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