Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * This software may be used and distributed according to the terms of |
| 3 | * the GNU General Public License (GPL), incorporated herein by reference. |
| 4 | * Drivers based on or derived from this code fall under the GPL and must |
| 5 | * retain the authorship, copyright and license notice. This file is not |
| 6 | * a complete program and may only be used when the entire operating |
| 7 | * system is licensed under the GPL. |
| 8 | * See the file COPYING in this distribution for more information. |
| 9 | * |
Jon Mason | 926bd90 | 2010-07-15 08:47:26 +0000 | [diff] [blame] | 10 | * vxge-main.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 11 | * Virtualized Server Adapter. |
Jon Mason | 926bd90 | 2010-07-15 08:47:26 +0000 | [diff] [blame] | 12 | * Copyright(c) 2002-2010 Exar Corp. |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 13 | * |
| 14 | * The module loadable parameters that are supported by the driver and a brief |
| 15 | * explanation of all the variables: |
| 16 | * vlan_tag_strip: |
| 17 | * Strip VLAN Tag enable/disable. Instructs the device to remove |
| 18 | * the VLAN tag from all received tagged frames that are not |
| 19 | * replicated at the internal L2 switch. |
| 20 | * 0 - Do not strip the VLAN tag. |
| 21 | * 1 - Strip the VLAN tag. |
| 22 | * |
| 23 | * addr_learn_en: |
| 24 | * Enable learning the mac address of the guest OS interface in |
| 25 | * a virtualization environment. |
| 26 | * 0 - DISABLE |
| 27 | * 1 - ENABLE |
| 28 | * |
| 29 | * max_config_port: |
| 30 | * Maximum number of port to be supported. |
| 31 | * MIN -1 and MAX - 2 |
| 32 | * |
| 33 | * max_config_vpath: |
| 34 | * This configures the maximum no of VPATH configures for each |
| 35 | * device function. |
| 36 | * MIN - 1 and MAX - 17 |
| 37 | * |
| 38 | * max_config_dev: |
| 39 | * This configures maximum no of Device function to be enabled. |
| 40 | * MIN - 1 and MAX - 17 |
| 41 | * |
| 42 | ******************************************************************************/ |
| 43 | |
Joe Perches | 75f5e1c | 2010-07-27 11:47:03 +0000 | [diff] [blame] | 44 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 45 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 46 | #include <linux/if_vlan.h> |
| 47 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 48 | #include <linux/slab.h> |
Alexander Beregalov | 2b05e00 | 2009-04-04 16:36:18 -0700 | [diff] [blame] | 49 | #include <linux/tcp.h> |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 50 | #include <net/ip.h> |
| 51 | #include <linux/netdevice.h> |
| 52 | #include <linux/etherdevice.h> |
| 53 | #include "vxge-main.h" |
| 54 | #include "vxge-reg.h" |
| 55 | |
| 56 | MODULE_LICENSE("Dual BSD/GPL"); |
| 57 | MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O" |
| 58 | "Virtualized Server Adapter"); |
| 59 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 60 | static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 61 | {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID, |
| 62 | PCI_ANY_ID}, |
| 63 | {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID, |
| 64 | PCI_ANY_ID}, |
| 65 | {0} |
| 66 | }; |
| 67 | |
| 68 | MODULE_DEVICE_TABLE(pci, vxge_id_table); |
| 69 | |
| 70 | VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE); |
| 71 | VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT); |
| 72 | VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT); |
| 73 | VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT); |
| 74 | VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT); |
| 75 | VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV); |
| 76 | |
| 77 | static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] = |
| 78 | {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31}; |
| 79 | static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] = |
| 80 | {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF}; |
| 81 | module_param_array(bw_percentage, uint, NULL, 0); |
| 82 | |
| 83 | static struct vxge_drv_config *driver_config; |
| 84 | |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 85 | static enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, |
| 86 | struct macInfo *mac); |
| 87 | static enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, |
| 88 | struct macInfo *mac); |
| 89 | static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac); |
| 90 | static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac); |
| 91 | static enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath); |
| 92 | static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath); |
| 93 | static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev); |
| 94 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 95 | static inline int is_vxge_card_up(struct vxgedev *vdev) |
| 96 | { |
| 97 | return test_bit(__VXGE_STATE_CARD_UP, &vdev->state); |
| 98 | } |
| 99 | |
| 100 | static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo) |
| 101 | { |
Benjamin LaHaise | ff67df5 | 2009-08-04 10:21:03 +0000 | [diff] [blame] | 102 | struct sk_buff **skb_ptr = NULL; |
| 103 | struct sk_buff **temp; |
| 104 | #define NR_SKB_COMPLETED 128 |
| 105 | struct sk_buff *completed[NR_SKB_COMPLETED]; |
| 106 | int more; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 107 | |
Benjamin LaHaise | ff67df5 | 2009-08-04 10:21:03 +0000 | [diff] [blame] | 108 | do { |
| 109 | more = 0; |
| 110 | skb_ptr = completed; |
| 111 | |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 112 | if (__netif_tx_trylock(fifo->txq)) { |
Benjamin LaHaise | ff67df5 | 2009-08-04 10:21:03 +0000 | [diff] [blame] | 113 | vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr, |
| 114 | NR_SKB_COMPLETED, &more); |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 115 | __netif_tx_unlock(fifo->txq); |
Benjamin LaHaise | ff67df5 | 2009-08-04 10:21:03 +0000 | [diff] [blame] | 116 | } |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 117 | |
Benjamin LaHaise | ff67df5 | 2009-08-04 10:21:03 +0000 | [diff] [blame] | 118 | /* free SKBs */ |
| 119 | for (temp = completed; temp != skb_ptr; temp++) |
| 120 | dev_kfree_skb_irq(*temp); |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 121 | } while (more); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev) |
| 125 | { |
| 126 | int i; |
| 127 | |
| 128 | /* Complete all transmits */ |
| 129 | for (i = 0; i < vdev->no_of_vpath; i++) |
| 130 | VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo); |
| 131 | } |
| 132 | |
| 133 | static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev) |
| 134 | { |
| 135 | int i; |
| 136 | struct vxge_ring *ring; |
| 137 | |
| 138 | /* Complete all receives*/ |
| 139 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 140 | ring = &vdev->vpaths[i].ring; |
| 141 | vxge_hw_vpath_poll_rx(ring->handle); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /* |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 146 | * vxge_callback_link_up |
| 147 | * |
| 148 | * This function is called during interrupt context to notify link up state |
| 149 | * change. |
| 150 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 151 | static void |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 152 | vxge_callback_link_up(struct __vxge_hw_device *hldev) |
| 153 | { |
| 154 | struct net_device *dev = hldev->ndev; |
| 155 | struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev); |
| 156 | |
| 157 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d", |
| 158 | vdev->ndev->name, __func__, __LINE__); |
Joe Perches | 75f5e1c | 2010-07-27 11:47:03 +0000 | [diff] [blame] | 159 | netdev_notice(vdev->ndev, "Link Up\n"); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 160 | vdev->stats.link_up++; |
| 161 | |
| 162 | netif_carrier_on(vdev->ndev); |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 163 | netif_tx_wake_all_queues(vdev->ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 164 | |
| 165 | vxge_debug_entryexit(VXGE_TRACE, |
| 166 | "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__); |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * vxge_callback_link_down |
| 171 | * |
| 172 | * This function is called during interrupt context to notify link down state |
| 173 | * change. |
| 174 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 175 | static void |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 176 | vxge_callback_link_down(struct __vxge_hw_device *hldev) |
| 177 | { |
| 178 | struct net_device *dev = hldev->ndev; |
| 179 | struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev); |
| 180 | |
| 181 | vxge_debug_entryexit(VXGE_TRACE, |
| 182 | "%s: %s:%d", vdev->ndev->name, __func__, __LINE__); |
Joe Perches | 75f5e1c | 2010-07-27 11:47:03 +0000 | [diff] [blame] | 183 | netdev_notice(vdev->ndev, "Link Down\n"); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 184 | |
| 185 | vdev->stats.link_down++; |
| 186 | netif_carrier_off(vdev->ndev); |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 187 | netif_tx_stop_all_queues(vdev->ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 188 | |
| 189 | vxge_debug_entryexit(VXGE_TRACE, |
| 190 | "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__); |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * vxge_rx_alloc |
| 195 | * |
| 196 | * Allocate SKB. |
| 197 | */ |
| 198 | static struct sk_buff* |
| 199 | vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size) |
| 200 | { |
| 201 | struct net_device *dev; |
| 202 | struct sk_buff *skb; |
| 203 | struct vxge_rx_priv *rx_priv; |
| 204 | |
| 205 | dev = ring->ndev; |
| 206 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d", |
| 207 | ring->ndev->name, __func__, __LINE__); |
| 208 | |
| 209 | rx_priv = vxge_hw_ring_rxd_private_get(dtrh); |
| 210 | |
| 211 | /* try to allocate skb first. this one may fail */ |
| 212 | skb = netdev_alloc_skb(dev, skb_size + |
| 213 | VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN); |
| 214 | if (skb == NULL) { |
| 215 | vxge_debug_mem(VXGE_ERR, |
| 216 | "%s: out of memory to allocate SKB", dev->name); |
| 217 | ring->stats.skb_alloc_fail++; |
| 218 | return NULL; |
| 219 | } |
| 220 | |
| 221 | vxge_debug_mem(VXGE_TRACE, |
| 222 | "%s: %s:%d Skb : 0x%p", ring->ndev->name, |
| 223 | __func__, __LINE__, skb); |
| 224 | |
| 225 | skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN); |
| 226 | |
| 227 | rx_priv->skb = skb; |
Benjamin LaHaise | ea11bbe | 2009-08-04 10:21:57 +0000 | [diff] [blame] | 228 | rx_priv->skb_data = NULL; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 229 | rx_priv->data_size = skb_size; |
| 230 | vxge_debug_entryexit(VXGE_TRACE, |
| 231 | "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__); |
| 232 | |
| 233 | return skb; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * vxge_rx_map |
| 238 | */ |
| 239 | static int vxge_rx_map(void *dtrh, struct vxge_ring *ring) |
| 240 | { |
| 241 | struct vxge_rx_priv *rx_priv; |
| 242 | dma_addr_t dma_addr; |
| 243 | |
| 244 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d", |
| 245 | ring->ndev->name, __func__, __LINE__); |
| 246 | rx_priv = vxge_hw_ring_rxd_private_get(dtrh); |
| 247 | |
Benjamin LaHaise | ea11bbe | 2009-08-04 10:21:57 +0000 | [diff] [blame] | 248 | rx_priv->skb_data = rx_priv->skb->data; |
| 249 | dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data, |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 250 | rx_priv->data_size, PCI_DMA_FROMDEVICE); |
| 251 | |
Denis Kirjanov | fa15e99 | 2010-01-10 13:40:10 -0800 | [diff] [blame] | 252 | if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 253 | ring->stats.pci_map_fail++; |
| 254 | return -EIO; |
| 255 | } |
| 256 | vxge_debug_mem(VXGE_TRACE, |
| 257 | "%s: %s:%d 1 buffer mode dma_addr = 0x%llx", |
| 258 | ring->ndev->name, __func__, __LINE__, |
| 259 | (unsigned long long)dma_addr); |
| 260 | vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size); |
| 261 | |
| 262 | rx_priv->data_dma = dma_addr; |
| 263 | vxge_debug_entryexit(VXGE_TRACE, |
| 264 | "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__); |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * vxge_rx_initial_replenish |
| 271 | * Allocation of RxD as an initial replenish procedure. |
| 272 | */ |
| 273 | static enum vxge_hw_status |
| 274 | vxge_rx_initial_replenish(void *dtrh, void *userdata) |
| 275 | { |
| 276 | struct vxge_ring *ring = (struct vxge_ring *)userdata; |
| 277 | struct vxge_rx_priv *rx_priv; |
| 278 | |
| 279 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d", |
| 280 | ring->ndev->name, __func__, __LINE__); |
| 281 | if (vxge_rx_alloc(dtrh, ring, |
| 282 | VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL) |
| 283 | return VXGE_HW_FAIL; |
| 284 | |
| 285 | if (vxge_rx_map(dtrh, ring)) { |
| 286 | rx_priv = vxge_hw_ring_rxd_private_get(dtrh); |
| 287 | dev_kfree_skb(rx_priv->skb); |
| 288 | |
| 289 | return VXGE_HW_FAIL; |
| 290 | } |
| 291 | vxge_debug_entryexit(VXGE_TRACE, |
| 292 | "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__); |
| 293 | |
| 294 | return VXGE_HW_OK; |
| 295 | } |
| 296 | |
| 297 | static inline void |
| 298 | vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan, |
| 299 | int pkt_length, struct vxge_hw_ring_rxd_info *ext_info) |
| 300 | { |
| 301 | |
| 302 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d", |
| 303 | ring->ndev->name, __func__, __LINE__); |
| 304 | skb_record_rx_queue(skb, ring->driver_id); |
| 305 | skb->protocol = eth_type_trans(skb, ring->ndev); |
| 306 | |
| 307 | ring->stats.rx_frms++; |
| 308 | ring->stats.rx_bytes += pkt_length; |
| 309 | |
| 310 | if (skb->pkt_type == PACKET_MULTICAST) |
| 311 | ring->stats.rx_mcast++; |
| 312 | |
| 313 | vxge_debug_rx(VXGE_TRACE, |
| 314 | "%s: %s:%d skb protocol = %d", |
| 315 | ring->ndev->name, __func__, __LINE__, skb->protocol); |
| 316 | |
| 317 | if (ring->gro_enable) { |
| 318 | if (ring->vlgrp && ext_info->vlan && |
| 319 | (ring->vlan_tag_strip == |
| 320 | VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)) |
Sreenivasa Honnur | a5d165b | 2009-07-01 21:16:37 +0000 | [diff] [blame] | 321 | vlan_gro_receive(ring->napi_p, ring->vlgrp, |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 322 | ext_info->vlan, skb); |
| 323 | else |
Sreenivasa Honnur | a5d165b | 2009-07-01 21:16:37 +0000 | [diff] [blame] | 324 | napi_gro_receive(ring->napi_p, skb); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 325 | } else { |
| 326 | if (ring->vlgrp && vlan && |
| 327 | (ring->vlan_tag_strip == |
| 328 | VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)) |
| 329 | vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan); |
| 330 | else |
| 331 | netif_receive_skb(skb); |
| 332 | } |
| 333 | vxge_debug_entryexit(VXGE_TRACE, |
| 334 | "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__); |
| 335 | } |
| 336 | |
| 337 | static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring, |
| 338 | struct vxge_rx_priv *rx_priv) |
| 339 | { |
| 340 | pci_dma_sync_single_for_device(ring->pdev, |
| 341 | rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE); |
| 342 | |
| 343 | vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size); |
| 344 | vxge_hw_ring_rxd_pre_post(ring->handle, dtr); |
| 345 | } |
| 346 | |
| 347 | static inline void vxge_post(int *dtr_cnt, void **first_dtr, |
| 348 | void *post_dtr, struct __vxge_hw_ring *ringh) |
| 349 | { |
| 350 | int dtr_count = *dtr_cnt; |
| 351 | if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) { |
| 352 | if (*first_dtr) |
| 353 | vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr); |
| 354 | *first_dtr = post_dtr; |
| 355 | } else |
| 356 | vxge_hw_ring_rxd_post_post(ringh, post_dtr); |
| 357 | dtr_count++; |
| 358 | *dtr_cnt = dtr_count; |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * vxge_rx_1b_compl |
| 363 | * |
| 364 | * If the interrupt is because of a received frame or if the receive ring |
| 365 | * contains fresh as yet un-processed frames, this function is called. |
| 366 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 367 | static enum vxge_hw_status |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 368 | vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr, |
| 369 | u8 t_code, void *userdata) |
| 370 | { |
| 371 | struct vxge_ring *ring = (struct vxge_ring *)userdata; |
| 372 | struct net_device *dev = ring->ndev; |
| 373 | unsigned int dma_sizes; |
| 374 | void *first_dtr = NULL; |
| 375 | int dtr_cnt = 0; |
| 376 | int data_size; |
| 377 | dma_addr_t data_dma; |
| 378 | int pkt_length; |
| 379 | struct sk_buff *skb; |
| 380 | struct vxge_rx_priv *rx_priv; |
| 381 | struct vxge_hw_ring_rxd_info ext_info; |
| 382 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d", |
| 383 | ring->ndev->name, __func__, __LINE__); |
| 384 | ring->pkts_processed = 0; |
| 385 | |
Sreenivasa Honnur | 3363276 | 2010-03-28 22:08:30 +0000 | [diff] [blame] | 386 | vxge_hw_ring_replenish(ringh); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 387 | |
| 388 | do { |
Benjamin LaHaise | 3f23e43 | 2009-08-04 10:21:39 +0000 | [diff] [blame] | 389 | prefetch((char *)dtr + L1_CACHE_BYTES); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 390 | rx_priv = vxge_hw_ring_rxd_private_get(dtr); |
| 391 | skb = rx_priv->skb; |
| 392 | data_size = rx_priv->data_size; |
| 393 | data_dma = rx_priv->data_dma; |
Benjamin LaHaise | ea11bbe | 2009-08-04 10:21:57 +0000 | [diff] [blame] | 394 | prefetch(rx_priv->skb_data); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 395 | |
| 396 | vxge_debug_rx(VXGE_TRACE, |
| 397 | "%s: %s:%d skb = 0x%p", |
| 398 | ring->ndev->name, __func__, __LINE__, skb); |
| 399 | |
| 400 | vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes); |
| 401 | pkt_length = dma_sizes; |
| 402 | |
Sreenivasa Honnur | 22fa125 | 2009-07-01 21:17:24 +0000 | [diff] [blame] | 403 | pkt_length -= ETH_FCS_LEN; |
| 404 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 405 | vxge_debug_rx(VXGE_TRACE, |
| 406 | "%s: %s:%d Packet Length = %d", |
| 407 | ring->ndev->name, __func__, __LINE__, pkt_length); |
| 408 | |
| 409 | vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info); |
| 410 | |
| 411 | /* check skb validity */ |
| 412 | vxge_assert(skb); |
| 413 | |
| 414 | prefetch((char *)skb + L1_CACHE_BYTES); |
| 415 | if (unlikely(t_code)) { |
| 416 | |
| 417 | if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) != |
| 418 | VXGE_HW_OK) { |
| 419 | |
| 420 | ring->stats.rx_errors++; |
| 421 | vxge_debug_rx(VXGE_TRACE, |
| 422 | "%s: %s :%d Rx T_code is %d", |
| 423 | ring->ndev->name, __func__, |
| 424 | __LINE__, t_code); |
| 425 | |
| 426 | /* If the t_code is not supported and if the |
| 427 | * t_code is other than 0x5 (unparseable packet |
| 428 | * such as unknown UPV6 header), Drop it !!! |
| 429 | */ |
| 430 | vxge_re_pre_post(dtr, ring, rx_priv); |
| 431 | |
| 432 | vxge_post(&dtr_cnt, &first_dtr, dtr, ringh); |
| 433 | ring->stats.rx_dropped++; |
| 434 | continue; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) { |
| 439 | |
| 440 | if (vxge_rx_alloc(dtr, ring, data_size) != NULL) { |
| 441 | |
| 442 | if (!vxge_rx_map(dtr, ring)) { |
| 443 | skb_put(skb, pkt_length); |
| 444 | |
| 445 | pci_unmap_single(ring->pdev, data_dma, |
| 446 | data_size, PCI_DMA_FROMDEVICE); |
| 447 | |
| 448 | vxge_hw_ring_rxd_pre_post(ringh, dtr); |
| 449 | vxge_post(&dtr_cnt, &first_dtr, dtr, |
| 450 | ringh); |
| 451 | } else { |
| 452 | dev_kfree_skb(rx_priv->skb); |
| 453 | rx_priv->skb = skb; |
| 454 | rx_priv->data_size = data_size; |
| 455 | vxge_re_pre_post(dtr, ring, rx_priv); |
| 456 | |
| 457 | vxge_post(&dtr_cnt, &first_dtr, dtr, |
| 458 | ringh); |
| 459 | ring->stats.rx_dropped++; |
| 460 | break; |
| 461 | } |
| 462 | } else { |
| 463 | vxge_re_pre_post(dtr, ring, rx_priv); |
| 464 | |
| 465 | vxge_post(&dtr_cnt, &first_dtr, dtr, ringh); |
| 466 | ring->stats.rx_dropped++; |
| 467 | break; |
| 468 | } |
| 469 | } else { |
| 470 | struct sk_buff *skb_up; |
| 471 | |
| 472 | skb_up = netdev_alloc_skb(dev, pkt_length + |
| 473 | VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN); |
| 474 | if (skb_up != NULL) { |
| 475 | skb_reserve(skb_up, |
| 476 | VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN); |
| 477 | |
| 478 | pci_dma_sync_single_for_cpu(ring->pdev, |
| 479 | data_dma, data_size, |
| 480 | PCI_DMA_FROMDEVICE); |
| 481 | |
| 482 | vxge_debug_mem(VXGE_TRACE, |
| 483 | "%s: %s:%d skb_up = %p", |
| 484 | ring->ndev->name, __func__, |
| 485 | __LINE__, skb); |
| 486 | memcpy(skb_up->data, skb->data, pkt_length); |
| 487 | |
| 488 | vxge_re_pre_post(dtr, ring, rx_priv); |
| 489 | |
| 490 | vxge_post(&dtr_cnt, &first_dtr, dtr, |
| 491 | ringh); |
| 492 | /* will netif_rx small SKB instead */ |
| 493 | skb = skb_up; |
| 494 | skb_put(skb, pkt_length); |
| 495 | } else { |
| 496 | vxge_re_pre_post(dtr, ring, rx_priv); |
| 497 | |
| 498 | vxge_post(&dtr_cnt, &first_dtr, dtr, ringh); |
| 499 | vxge_debug_rx(VXGE_ERR, |
| 500 | "%s: vxge_rx_1b_compl: out of " |
| 501 | "memory", dev->name); |
| 502 | ring->stats.skb_alloc_fail++; |
| 503 | break; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) && |
| 508 | !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) && |
| 509 | ring->rx_csum && /* Offload Rx side CSUM */ |
| 510 | ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK && |
| 511 | ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK) |
| 512 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 513 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 514 | skb_checksum_none_assert(skb); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 515 | |
Jon Mason | 47f01db | 2010-11-11 04:25:53 +0000 | [diff] [blame^] | 516 | /* rth_hash_type and rth_it_hit are non-zero regardless of |
| 517 | * whether rss is enabled. Only the rth_value is zero/non-zero |
| 518 | * if rss is disabled/enabled, so key off of that. |
| 519 | */ |
| 520 | if (ext_info.rth_value) |
| 521 | skb->rxhash = ext_info.rth_value; |
| 522 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 523 | vxge_rx_complete(ring, skb, ext_info.vlan, |
| 524 | pkt_length, &ext_info); |
| 525 | |
| 526 | ring->budget--; |
| 527 | ring->pkts_processed++; |
| 528 | if (!ring->budget) |
| 529 | break; |
| 530 | |
| 531 | } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr, |
| 532 | &t_code) == VXGE_HW_OK); |
| 533 | |
| 534 | if (first_dtr) |
| 535 | vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr); |
| 536 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 537 | vxge_debug_entryexit(VXGE_TRACE, |
| 538 | "%s:%d Exiting...", |
| 539 | __func__, __LINE__); |
| 540 | return VXGE_HW_OK; |
| 541 | } |
| 542 | |
| 543 | /* |
| 544 | * vxge_xmit_compl |
| 545 | * |
| 546 | * If an interrupt was raised to indicate DMA complete of the Tx packet, |
| 547 | * this function is called. It identifies the last TxD whose buffer was |
| 548 | * freed and frees all skbs whose data have already DMA'ed into the NICs |
| 549 | * internal memory. |
| 550 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 551 | static enum vxge_hw_status |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 552 | vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr, |
| 553 | enum vxge_hw_fifo_tcode t_code, void *userdata, |
Benjamin LaHaise | ff67df5 | 2009-08-04 10:21:03 +0000 | [diff] [blame] | 554 | struct sk_buff ***skb_ptr, int nr_skb, int *more) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 555 | { |
| 556 | struct vxge_fifo *fifo = (struct vxge_fifo *)userdata; |
Benjamin LaHaise | ff67df5 | 2009-08-04 10:21:03 +0000 | [diff] [blame] | 557 | struct sk_buff *skb, **done_skb = *skb_ptr; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 558 | int pkt_cnt = 0; |
| 559 | |
| 560 | vxge_debug_entryexit(VXGE_TRACE, |
| 561 | "%s:%d Entered....", __func__, __LINE__); |
| 562 | |
| 563 | do { |
| 564 | int frg_cnt; |
| 565 | skb_frag_t *frag; |
| 566 | int i = 0, j; |
| 567 | struct vxge_tx_priv *txd_priv = |
| 568 | vxge_hw_fifo_txdl_private_get(dtr); |
| 569 | |
| 570 | skb = txd_priv->skb; |
| 571 | frg_cnt = skb_shinfo(skb)->nr_frags; |
| 572 | frag = &skb_shinfo(skb)->frags[0]; |
| 573 | |
| 574 | vxge_debug_tx(VXGE_TRACE, |
| 575 | "%s: %s:%d fifo_hw = %p dtr = %p " |
| 576 | "tcode = 0x%x", fifo->ndev->name, __func__, |
| 577 | __LINE__, fifo_hw, dtr, t_code); |
| 578 | /* check skb validity */ |
| 579 | vxge_assert(skb); |
| 580 | vxge_debug_tx(VXGE_TRACE, |
| 581 | "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d", |
| 582 | fifo->ndev->name, __func__, __LINE__, |
| 583 | skb, txd_priv, frg_cnt); |
| 584 | if (unlikely(t_code)) { |
| 585 | fifo->stats.tx_errors++; |
| 586 | vxge_debug_tx(VXGE_ERR, |
| 587 | "%s: tx: dtr %p completed due to " |
| 588 | "error t_code %01x", fifo->ndev->name, |
| 589 | dtr, t_code); |
| 590 | vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code); |
| 591 | } |
| 592 | |
| 593 | /* for unfragmented skb */ |
| 594 | pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++], |
| 595 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 596 | |
| 597 | for (j = 0; j < frg_cnt; j++) { |
| 598 | pci_unmap_page(fifo->pdev, |
| 599 | txd_priv->dma_buffers[i++], |
| 600 | frag->size, PCI_DMA_TODEVICE); |
| 601 | frag += 1; |
| 602 | } |
| 603 | |
| 604 | vxge_hw_fifo_txdl_free(fifo_hw, dtr); |
| 605 | |
| 606 | /* Updating the statistics block */ |
| 607 | fifo->stats.tx_frms++; |
| 608 | fifo->stats.tx_bytes += skb->len; |
| 609 | |
Benjamin LaHaise | ff67df5 | 2009-08-04 10:21:03 +0000 | [diff] [blame] | 610 | *done_skb++ = skb; |
| 611 | |
| 612 | if (--nr_skb <= 0) { |
| 613 | *more = 1; |
| 614 | break; |
| 615 | } |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 616 | |
| 617 | pkt_cnt++; |
| 618 | if (pkt_cnt > fifo->indicate_max_pkts) |
| 619 | break; |
| 620 | |
| 621 | } while (vxge_hw_fifo_txdl_next_completed(fifo_hw, |
| 622 | &dtr, &t_code) == VXGE_HW_OK); |
| 623 | |
Benjamin LaHaise | ff67df5 | 2009-08-04 10:21:03 +0000 | [diff] [blame] | 624 | *skb_ptr = done_skb; |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 625 | if (netif_tx_queue_stopped(fifo->txq)) |
| 626 | netif_tx_wake_queue(fifo->txq); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 627 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 628 | vxge_debug_entryexit(VXGE_TRACE, |
| 629 | "%s: %s:%d Exiting...", |
| 630 | fifo->ndev->name, __func__, __LINE__); |
| 631 | return VXGE_HW_OK; |
| 632 | } |
| 633 | |
Eric Dumazet | 2867975 | 2009-05-27 19:26:37 +0000 | [diff] [blame] | 634 | /* select a vpath to transmit the packet */ |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 635 | static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 636 | { |
| 637 | u16 queue_len, counter = 0; |
| 638 | if (skb->protocol == htons(ETH_P_IP)) { |
| 639 | struct iphdr *ip; |
| 640 | struct tcphdr *th; |
| 641 | |
| 642 | ip = ip_hdr(skb); |
| 643 | |
| 644 | if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) { |
| 645 | th = (struct tcphdr *)(((unsigned char *)ip) + |
| 646 | ip->ihl*4); |
| 647 | |
| 648 | queue_len = vdev->no_of_vpath; |
| 649 | counter = (ntohs(th->source) + |
| 650 | ntohs(th->dest)) & |
| 651 | vdev->vpath_selector[queue_len - 1]; |
| 652 | if (counter >= queue_len) |
| 653 | counter = queue_len - 1; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | return counter; |
| 657 | } |
| 658 | |
| 659 | static enum vxge_hw_status vxge_search_mac_addr_in_list( |
| 660 | struct vxge_vpath *vpath, u64 del_mac) |
| 661 | { |
| 662 | struct list_head *entry, *next; |
| 663 | list_for_each_safe(entry, next, &vpath->mac_addr_list) { |
| 664 | if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) |
| 665 | return TRUE; |
| 666 | } |
| 667 | return FALSE; |
| 668 | } |
| 669 | |
| 670 | static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header) |
| 671 | { |
| 672 | struct macInfo mac_info; |
| 673 | u8 *mac_address = NULL; |
| 674 | u64 mac_addr = 0, vpath_vector = 0; |
| 675 | int vpath_idx = 0; |
| 676 | enum vxge_hw_status status = VXGE_HW_OK; |
| 677 | struct vxge_vpath *vpath = NULL; |
| 678 | struct __vxge_hw_device *hldev; |
| 679 | |
| 680 | hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev); |
| 681 | |
| 682 | mac_address = (u8 *)&mac_addr; |
| 683 | memcpy(mac_address, mac_header, ETH_ALEN); |
| 684 | |
| 685 | /* Is this mac address already in the list? */ |
| 686 | for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) { |
| 687 | vpath = &vdev->vpaths[vpath_idx]; |
| 688 | if (vxge_search_mac_addr_in_list(vpath, mac_addr)) |
| 689 | return vpath_idx; |
| 690 | } |
| 691 | |
| 692 | memset(&mac_info, 0, sizeof(struct macInfo)); |
| 693 | memcpy(mac_info.macaddr, mac_header, ETH_ALEN); |
| 694 | |
| 695 | /* Any vpath has room to add mac address to its da table? */ |
| 696 | for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) { |
| 697 | vpath = &vdev->vpaths[vpath_idx]; |
| 698 | if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) { |
| 699 | /* Add this mac address to this vpath */ |
| 700 | mac_info.vpath_no = vpath_idx; |
| 701 | mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE; |
| 702 | status = vxge_add_mac_addr(vdev, &mac_info); |
| 703 | if (status != VXGE_HW_OK) |
| 704 | return -EPERM; |
| 705 | return vpath_idx; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST; |
| 710 | vpath_idx = 0; |
| 711 | mac_info.vpath_no = vpath_idx; |
| 712 | /* Is the first vpath already selected as catch-basin ? */ |
| 713 | vpath = &vdev->vpaths[vpath_idx]; |
| 714 | if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) { |
| 715 | /* Add this mac address to this vpath */ |
| 716 | if (FALSE == vxge_mac_list_add(vpath, &mac_info)) |
| 717 | return -EPERM; |
| 718 | return vpath_idx; |
| 719 | } |
| 720 | |
| 721 | /* Select first vpath as catch-basin */ |
| 722 | vpath_vector = vxge_mBIT(vpath->device_id); |
| 723 | status = vxge_hw_mgmt_reg_write(vpath->vdev->devh, |
| 724 | vxge_hw_mgmt_reg_type_mrpcim, |
| 725 | 0, |
| 726 | (ulong)offsetof( |
| 727 | struct vxge_hw_mrpcim_reg, |
| 728 | rts_mgr_cbasin_cfg), |
| 729 | vpath_vector); |
| 730 | if (status != VXGE_HW_OK) { |
| 731 | vxge_debug_tx(VXGE_ERR, |
| 732 | "%s: Unable to set the vpath-%d in catch-basin mode", |
| 733 | VXGE_DRIVER_NAME, vpath->device_id); |
| 734 | return -EPERM; |
| 735 | } |
| 736 | |
| 737 | if (FALSE == vxge_mac_list_add(vpath, &mac_info)) |
| 738 | return -EPERM; |
| 739 | |
| 740 | return vpath_idx; |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * vxge_xmit |
| 745 | * @skb : the socket buffer containing the Tx data. |
| 746 | * @dev : device pointer. |
| 747 | * |
| 748 | * This function is the Tx entry point of the driver. Neterion NIC supports |
| 749 | * certain protocol assist features on Tx side, namely CSO, S/G, LSO. |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 750 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 751 | static netdev_tx_t |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 752 | vxge_xmit(struct sk_buff *skb, struct net_device *dev) |
| 753 | { |
| 754 | struct vxge_fifo *fifo = NULL; |
| 755 | void *dtr_priv; |
| 756 | void *dtr = NULL; |
| 757 | struct vxgedev *vdev = NULL; |
| 758 | enum vxge_hw_status status; |
| 759 | int frg_cnt, first_frg_len; |
| 760 | skb_frag_t *frag; |
| 761 | int i = 0, j = 0, avail; |
| 762 | u64 dma_pointer; |
| 763 | struct vxge_tx_priv *txdl_priv = NULL; |
| 764 | struct __vxge_hw_fifo *fifo_hw; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 765 | int offload_type; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 766 | int vpath_no = 0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 767 | |
| 768 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d", |
| 769 | dev->name, __func__, __LINE__); |
| 770 | |
| 771 | /* A buffer with no data will be dropped */ |
| 772 | if (unlikely(skb->len <= 0)) { |
| 773 | vxge_debug_tx(VXGE_ERR, |
| 774 | "%s: Buffer has no data..", dev->name); |
| 775 | dev_kfree_skb(skb); |
| 776 | return NETDEV_TX_OK; |
| 777 | } |
| 778 | |
| 779 | vdev = (struct vxgedev *)netdev_priv(dev); |
| 780 | |
| 781 | if (unlikely(!is_vxge_card_up(vdev))) { |
| 782 | vxge_debug_tx(VXGE_ERR, |
| 783 | "%s: vdev not initialized", dev->name); |
| 784 | dev_kfree_skb(skb); |
| 785 | return NETDEV_TX_OK; |
| 786 | } |
| 787 | |
| 788 | if (vdev->config.addr_learn_en) { |
| 789 | vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN); |
| 790 | if (vpath_no == -EPERM) { |
| 791 | vxge_debug_tx(VXGE_ERR, |
| 792 | "%s: Failed to store the mac address", |
| 793 | dev->name); |
| 794 | dev_kfree_skb(skb); |
| 795 | return NETDEV_TX_OK; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING) |
| 800 | vpath_no = skb_get_queue_mapping(skb); |
| 801 | else if (vdev->config.tx_steering_type == TX_PORT_STEERING) |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 802 | vpath_no = vxge_get_vpath_no(vdev, skb); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 803 | |
| 804 | vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no); |
| 805 | |
| 806 | if (vpath_no >= vdev->no_of_vpath) |
| 807 | vpath_no = 0; |
| 808 | |
| 809 | fifo = &vdev->vpaths[vpath_no].fifo; |
| 810 | fifo_hw = fifo->handle; |
| 811 | |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 812 | if (netif_tx_queue_stopped(fifo->txq)) |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 813 | return NETDEV_TX_BUSY; |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 814 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 815 | avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw); |
| 816 | if (avail == 0) { |
| 817 | vxge_debug_tx(VXGE_ERR, |
| 818 | "%s: No free TXDs available", dev->name); |
| 819 | fifo->stats.txd_not_free++; |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 820 | goto _exit0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Benjamin LaHaise | 4403b37 | 2009-08-04 10:20:44 +0000 | [diff] [blame] | 823 | /* Last TXD? Stop tx queue to avoid dropping packets. TX |
| 824 | * completion will resume the queue. |
| 825 | */ |
| 826 | if (avail == 1) |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 827 | netif_tx_stop_queue(fifo->txq); |
Benjamin LaHaise | 4403b37 | 2009-08-04 10:20:44 +0000 | [diff] [blame] | 828 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 829 | status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv); |
| 830 | if (unlikely(status != VXGE_HW_OK)) { |
| 831 | vxge_debug_tx(VXGE_ERR, |
| 832 | "%s: Out of descriptors .", dev->name); |
| 833 | fifo->stats.txd_out_of_desc++; |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 834 | goto _exit0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | vxge_debug_tx(VXGE_TRACE, |
| 838 | "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p", |
| 839 | dev->name, __func__, __LINE__, |
| 840 | fifo_hw, dtr, dtr_priv); |
| 841 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 842 | if (vlan_tx_tag_present(skb)) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 843 | u16 vlan_tag = vlan_tx_tag_get(skb); |
| 844 | vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag); |
| 845 | } |
| 846 | |
| 847 | first_frg_len = skb_headlen(skb); |
| 848 | |
| 849 | dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len, |
| 850 | PCI_DMA_TODEVICE); |
| 851 | |
| 852 | if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) { |
| 853 | vxge_hw_fifo_txdl_free(fifo_hw, dtr); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 854 | fifo->stats.pci_map_fail++; |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 855 | goto _exit0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | txdl_priv = vxge_hw_fifo_txdl_private_get(dtr); |
| 859 | txdl_priv->skb = skb; |
| 860 | txdl_priv->dma_buffers[j] = dma_pointer; |
| 861 | |
| 862 | frg_cnt = skb_shinfo(skb)->nr_frags; |
| 863 | vxge_debug_tx(VXGE_TRACE, |
| 864 | "%s: %s:%d skb = %p txdl_priv = %p " |
| 865 | "frag_cnt = %d dma_pointer = 0x%llx", dev->name, |
| 866 | __func__, __LINE__, skb, txdl_priv, |
| 867 | frg_cnt, (unsigned long long)dma_pointer); |
| 868 | |
| 869 | vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer, |
| 870 | first_frg_len); |
| 871 | |
| 872 | frag = &skb_shinfo(skb)->frags[0]; |
| 873 | for (i = 0; i < frg_cnt; i++) { |
| 874 | /* ignore 0 length fragment */ |
| 875 | if (!frag->size) |
| 876 | continue; |
| 877 | |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 878 | dma_pointer = (u64) pci_map_page(fifo->pdev, frag->page, |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 879 | frag->page_offset, frag->size, |
| 880 | PCI_DMA_TODEVICE); |
| 881 | |
| 882 | if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 883 | goto _exit2; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 884 | vxge_debug_tx(VXGE_TRACE, |
| 885 | "%s: %s:%d frag = %d dma_pointer = 0x%llx", |
| 886 | dev->name, __func__, __LINE__, i, |
| 887 | (unsigned long long)dma_pointer); |
| 888 | |
| 889 | txdl_priv->dma_buffers[j] = dma_pointer; |
| 890 | vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer, |
| 891 | frag->size); |
| 892 | frag += 1; |
| 893 | } |
| 894 | |
| 895 | offload_type = vxge_offload_type(skb); |
| 896 | |
| 897 | if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 898 | int mss = vxge_tcp_mss(skb); |
| 899 | if (mss) { |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 900 | vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d", |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 901 | dev->name, __func__, __LINE__, mss); |
| 902 | vxge_hw_fifo_txdl_mss_set(dtr, mss); |
| 903 | } else { |
| 904 | vxge_assert(skb->len <= |
| 905 | dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE); |
| 906 | vxge_assert(0); |
| 907 | goto _exit1; |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 912 | vxge_hw_fifo_txdl_cksum_set_bits(dtr, |
| 913 | VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN | |
| 914 | VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN | |
| 915 | VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN); |
| 916 | |
| 917 | vxge_hw_fifo_txdl_post(fifo_hw, dtr); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 918 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 919 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...", |
| 920 | dev->name, __func__, __LINE__); |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 921 | return NETDEV_TX_OK; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 922 | |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 923 | _exit2: |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 924 | vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 925 | _exit1: |
| 926 | j = 0; |
| 927 | frag = &skb_shinfo(skb)->frags[0]; |
| 928 | |
| 929 | pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++], |
| 930 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 931 | |
| 932 | for (; j < i; j++) { |
| 933 | pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j], |
| 934 | frag->size, PCI_DMA_TODEVICE); |
| 935 | frag += 1; |
| 936 | } |
| 937 | |
| 938 | vxge_hw_fifo_txdl_free(fifo_hw, dtr); |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 939 | _exit0: |
| 940 | netif_tx_stop_queue(fifo->txq); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 941 | dev_kfree_skb(skb); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 942 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 943 | return NETDEV_TX_OK; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | /* |
| 947 | * vxge_rx_term |
| 948 | * |
| 949 | * Function will be called by hw function to abort all outstanding receive |
| 950 | * descriptors. |
| 951 | */ |
| 952 | static void |
| 953 | vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata) |
| 954 | { |
| 955 | struct vxge_ring *ring = (struct vxge_ring *)userdata; |
| 956 | struct vxge_rx_priv *rx_priv = |
| 957 | vxge_hw_ring_rxd_private_get(dtrh); |
| 958 | |
| 959 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d", |
| 960 | ring->ndev->name, __func__, __LINE__); |
| 961 | if (state != VXGE_HW_RXD_STATE_POSTED) |
| 962 | return; |
| 963 | |
| 964 | pci_unmap_single(ring->pdev, rx_priv->data_dma, |
| 965 | rx_priv->data_size, PCI_DMA_FROMDEVICE); |
| 966 | |
| 967 | dev_kfree_skb(rx_priv->skb); |
Benjamin LaHaise | ea11bbe | 2009-08-04 10:21:57 +0000 | [diff] [blame] | 968 | rx_priv->skb_data = NULL; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 969 | |
| 970 | vxge_debug_entryexit(VXGE_TRACE, |
| 971 | "%s: %s:%d Exiting...", |
| 972 | ring->ndev->name, __func__, __LINE__); |
| 973 | } |
| 974 | |
| 975 | /* |
| 976 | * vxge_tx_term |
| 977 | * |
| 978 | * Function will be called to abort all outstanding tx descriptors |
| 979 | */ |
| 980 | static void |
| 981 | vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata) |
| 982 | { |
| 983 | struct vxge_fifo *fifo = (struct vxge_fifo *)userdata; |
| 984 | skb_frag_t *frag; |
| 985 | int i = 0, j, frg_cnt; |
| 986 | struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh); |
| 987 | struct sk_buff *skb = txd_priv->skb; |
| 988 | |
| 989 | vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__); |
| 990 | |
| 991 | if (state != VXGE_HW_TXDL_STATE_POSTED) |
| 992 | return; |
| 993 | |
| 994 | /* check skb validity */ |
| 995 | vxge_assert(skb); |
| 996 | frg_cnt = skb_shinfo(skb)->nr_frags; |
| 997 | frag = &skb_shinfo(skb)->frags[0]; |
| 998 | |
| 999 | /* for unfragmented skb */ |
| 1000 | pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++], |
| 1001 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 1002 | |
| 1003 | for (j = 0; j < frg_cnt; j++) { |
| 1004 | pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++], |
| 1005 | frag->size, PCI_DMA_TODEVICE); |
| 1006 | frag += 1; |
| 1007 | } |
| 1008 | |
| 1009 | dev_kfree_skb(skb); |
| 1010 | |
| 1011 | vxge_debug_entryexit(VXGE_TRACE, |
| 1012 | "%s:%d Exiting...", __func__, __LINE__); |
| 1013 | } |
| 1014 | |
| 1015 | /** |
| 1016 | * vxge_set_multicast |
| 1017 | * @dev: pointer to the device structure |
| 1018 | * |
| 1019 | * Entry point for multicast address enable/disable |
| 1020 | * This function is a driver entry point which gets called by the kernel |
| 1021 | * whenever multicast addresses must be enabled/disabled. This also gets |
| 1022 | * called to set/reset promiscuous mode. Depending on the deivce flag, we |
| 1023 | * determine, if multicast address must be enabled or if promiscuous mode |
| 1024 | * is to be disabled etc. |
| 1025 | */ |
| 1026 | static void vxge_set_multicast(struct net_device *dev) |
| 1027 | { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1028 | struct netdev_hw_addr *ha; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1029 | struct vxgedev *vdev; |
| 1030 | int i, mcast_cnt = 0; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1031 | struct __vxge_hw_device *hldev; |
| 1032 | struct vxge_vpath *vpath; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1033 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1034 | struct macInfo mac_info; |
| 1035 | int vpath_idx = 0; |
| 1036 | struct vxge_mac_addrs *mac_entry; |
| 1037 | struct list_head *list_head; |
| 1038 | struct list_head *entry, *next; |
| 1039 | u8 *mac_address = NULL; |
| 1040 | |
| 1041 | vxge_debug_entryexit(VXGE_TRACE, |
| 1042 | "%s:%d", __func__, __LINE__); |
| 1043 | |
| 1044 | vdev = (struct vxgedev *)netdev_priv(dev); |
| 1045 | hldev = (struct __vxge_hw_device *)vdev->devh; |
| 1046 | |
| 1047 | if (unlikely(!is_vxge_card_up(vdev))) |
| 1048 | return; |
| 1049 | |
| 1050 | if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) { |
| 1051 | for (i = 0; i < vdev->no_of_vpath; i++) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1052 | vpath = &vdev->vpaths[i]; |
| 1053 | vxge_assert(vpath->is_open); |
| 1054 | status = vxge_hw_vpath_mcast_enable(vpath->handle); |
| 1055 | if (status != VXGE_HW_OK) |
| 1056 | vxge_debug_init(VXGE_ERR, "failed to enable " |
| 1057 | "multicast, status %d", status); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1058 | vdev->all_multi_flg = 1; |
| 1059 | } |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1060 | } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1061 | for (i = 0; i < vdev->no_of_vpath; i++) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1062 | vpath = &vdev->vpaths[i]; |
| 1063 | vxge_assert(vpath->is_open); |
| 1064 | status = vxge_hw_vpath_mcast_disable(vpath->handle); |
| 1065 | if (status != VXGE_HW_OK) |
| 1066 | vxge_debug_init(VXGE_ERR, "failed to disable " |
| 1067 | "multicast, status %d", status); |
| 1068 | vdev->all_multi_flg = 0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1072 | |
| 1073 | if (!vdev->config.addr_learn_en) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1074 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 1075 | vpath = &vdev->vpaths[i]; |
| 1076 | vxge_assert(vpath->is_open); |
| 1077 | |
| 1078 | if (dev->flags & IFF_PROMISC) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1079 | status = vxge_hw_vpath_promisc_enable( |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1080 | vpath->handle); |
| 1081 | else |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1082 | status = vxge_hw_vpath_promisc_disable( |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1083 | vpath->handle); |
| 1084 | if (status != VXGE_HW_OK) |
| 1085 | vxge_debug_init(VXGE_ERR, "failed to %s promisc" |
| 1086 | ", status %d", dev->flags&IFF_PROMISC ? |
| 1087 | "enable" : "disable", status); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | memset(&mac_info, 0, sizeof(struct macInfo)); |
| 1092 | /* Update individual M_CAST address list */ |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1093 | if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1094 | mcast_cnt = vdev->vpaths[0].mcast_addr_cnt; |
| 1095 | list_head = &vdev->vpaths[0].mac_addr_list; |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1096 | if ((netdev_mc_count(dev) + |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1097 | (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) > |
| 1098 | vdev->vpaths[0].max_mac_addr_cnt) |
| 1099 | goto _set_all_mcast; |
| 1100 | |
| 1101 | /* Delete previous MC's */ |
| 1102 | for (i = 0; i < mcast_cnt; i++) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1103 | list_for_each_safe(entry, next, list_head) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1104 | mac_entry = (struct vxge_mac_addrs *) entry; |
| 1105 | /* Copy the mac address to delete */ |
| 1106 | mac_address = (u8 *)&mac_entry->macaddr; |
| 1107 | memcpy(mac_info.macaddr, mac_address, ETH_ALEN); |
| 1108 | |
| 1109 | /* Is this a multicast address */ |
| 1110 | if (0x01 & mac_info.macaddr[0]) { |
| 1111 | for (vpath_idx = 0; vpath_idx < |
| 1112 | vdev->no_of_vpath; |
| 1113 | vpath_idx++) { |
| 1114 | mac_info.vpath_no = vpath_idx; |
| 1115 | status = vxge_del_mac_addr( |
| 1116 | vdev, |
| 1117 | &mac_info); |
| 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | /* Add new ones */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1124 | netdev_for_each_mc_addr(ha, dev) { |
| 1125 | memcpy(mac_info.macaddr, ha->addr, ETH_ALEN); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1126 | for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; |
| 1127 | vpath_idx++) { |
| 1128 | mac_info.vpath_no = vpath_idx; |
| 1129 | mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE; |
| 1130 | status = vxge_add_mac_addr(vdev, &mac_info); |
| 1131 | if (status != VXGE_HW_OK) { |
| 1132 | vxge_debug_init(VXGE_ERR, |
| 1133 | "%s:%d Setting individual" |
| 1134 | "multicast address failed", |
| 1135 | __func__, __LINE__); |
| 1136 | goto _set_all_mcast; |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | return; |
| 1142 | _set_all_mcast: |
| 1143 | mcast_cnt = vdev->vpaths[0].mcast_addr_cnt; |
| 1144 | /* Delete previous MC's */ |
| 1145 | for (i = 0; i < mcast_cnt; i++) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1146 | list_for_each_safe(entry, next, list_head) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1147 | mac_entry = (struct vxge_mac_addrs *) entry; |
| 1148 | /* Copy the mac address to delete */ |
| 1149 | mac_address = (u8 *)&mac_entry->macaddr; |
| 1150 | memcpy(mac_info.macaddr, mac_address, ETH_ALEN); |
| 1151 | |
| 1152 | /* Is this a multicast address */ |
| 1153 | if (0x01 & mac_info.macaddr[0]) |
| 1154 | break; |
| 1155 | } |
| 1156 | |
| 1157 | for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; |
| 1158 | vpath_idx++) { |
| 1159 | mac_info.vpath_no = vpath_idx; |
| 1160 | status = vxge_del_mac_addr(vdev, &mac_info); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | /* Enable all multicast */ |
| 1165 | for (i = 0; i < vdev->no_of_vpath; i++) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1166 | vpath = &vdev->vpaths[i]; |
| 1167 | vxge_assert(vpath->is_open); |
| 1168 | |
| 1169 | status = vxge_hw_vpath_mcast_enable(vpath->handle); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1170 | if (status != VXGE_HW_OK) { |
| 1171 | vxge_debug_init(VXGE_ERR, |
| 1172 | "%s:%d Enabling all multicasts failed", |
| 1173 | __func__, __LINE__); |
| 1174 | } |
| 1175 | vdev->all_multi_flg = 1; |
| 1176 | } |
| 1177 | dev->flags |= IFF_ALLMULTI; |
| 1178 | } |
| 1179 | |
| 1180 | vxge_debug_entryexit(VXGE_TRACE, |
| 1181 | "%s:%d Exiting...", __func__, __LINE__); |
| 1182 | } |
| 1183 | |
| 1184 | /** |
| 1185 | * vxge_set_mac_addr |
| 1186 | * @dev: pointer to the device structure |
| 1187 | * |
| 1188 | * Update entry "0" (default MAC addr) |
| 1189 | */ |
| 1190 | static int vxge_set_mac_addr(struct net_device *dev, void *p) |
| 1191 | { |
| 1192 | struct sockaddr *addr = p; |
| 1193 | struct vxgedev *vdev; |
| 1194 | struct __vxge_hw_device *hldev; |
| 1195 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1196 | struct macInfo mac_info_new, mac_info_old; |
| 1197 | int vpath_idx = 0; |
| 1198 | |
| 1199 | vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__); |
| 1200 | |
| 1201 | vdev = (struct vxgedev *)netdev_priv(dev); |
| 1202 | hldev = vdev->devh; |
| 1203 | |
| 1204 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1205 | return -EINVAL; |
| 1206 | |
| 1207 | memset(&mac_info_new, 0, sizeof(struct macInfo)); |
| 1208 | memset(&mac_info_old, 0, sizeof(struct macInfo)); |
| 1209 | |
| 1210 | vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...", |
| 1211 | __func__, __LINE__); |
| 1212 | |
| 1213 | /* Get the old address */ |
| 1214 | memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len); |
| 1215 | |
| 1216 | /* Copy the new address */ |
| 1217 | memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len); |
| 1218 | |
| 1219 | /* First delete the old mac address from all the vpaths |
| 1220 | as we can't specify the index while adding new mac address */ |
| 1221 | for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) { |
| 1222 | struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx]; |
| 1223 | if (!vpath->is_open) { |
| 1224 | /* This can happen when this interface is added/removed |
| 1225 | to the bonding interface. Delete this station address |
| 1226 | from the linked list */ |
| 1227 | vxge_mac_list_del(vpath, &mac_info_old); |
| 1228 | |
| 1229 | /* Add this new address to the linked list |
| 1230 | for later restoring */ |
| 1231 | vxge_mac_list_add(vpath, &mac_info_new); |
| 1232 | |
| 1233 | continue; |
| 1234 | } |
| 1235 | /* Delete the station address */ |
| 1236 | mac_info_old.vpath_no = vpath_idx; |
| 1237 | status = vxge_del_mac_addr(vdev, &mac_info_old); |
| 1238 | } |
| 1239 | |
| 1240 | if (unlikely(!is_vxge_card_up(vdev))) { |
| 1241 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 1242 | return VXGE_HW_OK; |
| 1243 | } |
| 1244 | |
| 1245 | /* Set this mac address to all the vpaths */ |
| 1246 | for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) { |
| 1247 | mac_info_new.vpath_no = vpath_idx; |
| 1248 | mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE; |
| 1249 | status = vxge_add_mac_addr(vdev, &mac_info_new); |
| 1250 | if (status != VXGE_HW_OK) |
| 1251 | return -EINVAL; |
| 1252 | } |
| 1253 | |
| 1254 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 1255 | |
| 1256 | return status; |
| 1257 | } |
| 1258 | |
| 1259 | /* |
| 1260 | * vxge_vpath_intr_enable |
| 1261 | * @vdev: pointer to vdev |
| 1262 | * @vp_id: vpath for which to enable the interrupts |
| 1263 | * |
| 1264 | * Enables the interrupts for the vpath |
| 1265 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1266 | static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1267 | { |
| 1268 | struct vxge_vpath *vpath = &vdev->vpaths[vp_id]; |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 1269 | int msix_id = 0; |
| 1270 | int tim_msix_id[4] = {0, 1, 0, 0}; |
| 1271 | int alarm_msix_id = VXGE_ALARM_MSIX_ID; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1272 | |
| 1273 | vxge_hw_vpath_intr_enable(vpath->handle); |
| 1274 | |
| 1275 | if (vdev->config.intr_type == INTA) |
| 1276 | vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle); |
| 1277 | else { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1278 | vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id, |
| 1279 | alarm_msix_id); |
| 1280 | |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 1281 | msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1282 | vxge_hw_vpath_msix_unmask(vpath->handle, msix_id); |
| 1283 | vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1); |
| 1284 | |
| 1285 | /* enable the alarm vector */ |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 1286 | msix_id = (vpath->handle->vpath->hldev->first_vp_id * |
| 1287 | VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id; |
| 1288 | vxge_hw_vpath_msix_unmask(vpath->handle, msix_id); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | /* |
| 1293 | * vxge_vpath_intr_disable |
| 1294 | * @vdev: pointer to vdev |
| 1295 | * @vp_id: vpath for which to disable the interrupts |
| 1296 | * |
| 1297 | * Disables the interrupts for the vpath |
| 1298 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1299 | static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1300 | { |
| 1301 | struct vxge_vpath *vpath = &vdev->vpaths[vp_id]; |
| 1302 | int msix_id; |
| 1303 | |
| 1304 | vxge_hw_vpath_intr_disable(vpath->handle); |
| 1305 | |
| 1306 | if (vdev->config.intr_type == INTA) |
| 1307 | vxge_hw_vpath_inta_mask_tx_rx(vpath->handle); |
| 1308 | else { |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 1309 | msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1310 | vxge_hw_vpath_msix_mask(vpath->handle, msix_id); |
| 1311 | vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1); |
| 1312 | |
| 1313 | /* disable the alarm vector */ |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 1314 | msix_id = (vpath->handle->vpath->hldev->first_vp_id * |
| 1315 | VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1316 | vxge_hw_vpath_msix_mask(vpath->handle, msix_id); |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | /* |
| 1321 | * vxge_reset_vpath |
| 1322 | * @vdev: pointer to vdev |
| 1323 | * @vp_id: vpath to reset |
| 1324 | * |
| 1325 | * Resets the vpath |
| 1326 | */ |
| 1327 | static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id) |
| 1328 | { |
| 1329 | enum vxge_hw_status status = VXGE_HW_OK; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1330 | struct vxge_vpath *vpath = &vdev->vpaths[vp_id]; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1331 | int ret = 0; |
| 1332 | |
| 1333 | /* check if device is down already */ |
| 1334 | if (unlikely(!is_vxge_card_up(vdev))) |
| 1335 | return 0; |
| 1336 | |
| 1337 | /* is device reset already scheduled */ |
| 1338 | if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) |
| 1339 | return 0; |
| 1340 | |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1341 | if (vpath->handle) { |
| 1342 | if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1343 | if (is_vxge_card_up(vdev) && |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1344 | vxge_hw_vpath_recover_from_reset(vpath->handle) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1345 | != VXGE_HW_OK) { |
| 1346 | vxge_debug_init(VXGE_ERR, |
| 1347 | "vxge_hw_vpath_recover_from_reset" |
| 1348 | "failed for vpath:%d", vp_id); |
| 1349 | return status; |
| 1350 | } |
| 1351 | } else { |
| 1352 | vxge_debug_init(VXGE_ERR, |
| 1353 | "vxge_hw_vpath_reset failed for" |
| 1354 | "vpath:%d", vp_id); |
| 1355 | return status; |
| 1356 | } |
| 1357 | } else |
| 1358 | return VXGE_HW_FAIL; |
| 1359 | |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1360 | vxge_restore_vpath_mac_addr(vpath); |
| 1361 | vxge_restore_vpath_vid_table(vpath); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1362 | |
| 1363 | /* Enable all broadcast */ |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1364 | vxge_hw_vpath_bcast_enable(vpath->handle); |
| 1365 | |
| 1366 | /* Enable all multicast */ |
| 1367 | if (vdev->all_multi_flg) { |
| 1368 | status = vxge_hw_vpath_mcast_enable(vpath->handle); |
| 1369 | if (status != VXGE_HW_OK) |
| 1370 | vxge_debug_init(VXGE_ERR, |
| 1371 | "%s:%d Enabling multicast failed", |
| 1372 | __func__, __LINE__); |
| 1373 | } |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1374 | |
| 1375 | /* Enable the interrupts */ |
| 1376 | vxge_vpath_intr_enable(vdev, vp_id); |
| 1377 | |
| 1378 | smp_wmb(); |
| 1379 | |
| 1380 | /* Enable the flow of traffic through the vpath */ |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1381 | vxge_hw_vpath_enable(vpath->handle); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1382 | |
| 1383 | smp_wmb(); |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1384 | vxge_hw_vpath_rx_doorbell_init(vpath->handle); |
| 1385 | vpath->ring.last_status = VXGE_HW_OK; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1386 | |
| 1387 | /* Vpath reset done */ |
| 1388 | clear_bit(vp_id, &vdev->vp_reset); |
| 1389 | |
| 1390 | /* Start the vpath queue */ |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 1391 | if (netif_tx_queue_stopped(vpath->fifo.txq)) |
| 1392 | netif_tx_wake_queue(vpath->fifo.txq); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1393 | |
| 1394 | return ret; |
| 1395 | } |
| 1396 | |
| 1397 | static int do_vxge_reset(struct vxgedev *vdev, int event) |
| 1398 | { |
| 1399 | enum vxge_hw_status status; |
| 1400 | int ret = 0, vp_id, i; |
| 1401 | |
| 1402 | vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__); |
| 1403 | |
| 1404 | if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) { |
| 1405 | /* check if device is down already */ |
| 1406 | if (unlikely(!is_vxge_card_up(vdev))) |
| 1407 | return 0; |
| 1408 | |
| 1409 | /* is reset already scheduled */ |
| 1410 | if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) |
| 1411 | return 0; |
| 1412 | } |
| 1413 | |
| 1414 | if (event == VXGE_LL_FULL_RESET) { |
| 1415 | /* wait for all the vpath reset to complete */ |
| 1416 | for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) { |
| 1417 | while (test_bit(vp_id, &vdev->vp_reset)) |
| 1418 | msleep(50); |
| 1419 | } |
| 1420 | |
| 1421 | /* if execution mode is set to debug, don't reset the adapter */ |
| 1422 | if (unlikely(vdev->exec_mode)) { |
| 1423 | vxge_debug_init(VXGE_ERR, |
| 1424 | "%s: execution mode is debug, returning..", |
| 1425 | vdev->ndev->name); |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1426 | clear_bit(__VXGE_STATE_CARD_UP, &vdev->state); |
| 1427 | netif_tx_stop_all_queues(vdev->ndev); |
| 1428 | return 0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | if (event == VXGE_LL_FULL_RESET) { |
| 1433 | vxge_hw_device_intr_disable(vdev->devh); |
| 1434 | |
| 1435 | switch (vdev->cric_err_event) { |
| 1436 | case VXGE_HW_EVENT_UNKNOWN: |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 1437 | netif_tx_stop_all_queues(vdev->ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1438 | vxge_debug_init(VXGE_ERR, |
| 1439 | "fatal: %s: Disabling device due to" |
| 1440 | "unknown error", |
| 1441 | vdev->ndev->name); |
| 1442 | ret = -EPERM; |
| 1443 | goto out; |
| 1444 | case VXGE_HW_EVENT_RESET_START: |
| 1445 | break; |
| 1446 | case VXGE_HW_EVENT_RESET_COMPLETE: |
| 1447 | case VXGE_HW_EVENT_LINK_DOWN: |
| 1448 | case VXGE_HW_EVENT_LINK_UP: |
| 1449 | case VXGE_HW_EVENT_ALARM_CLEARED: |
| 1450 | case VXGE_HW_EVENT_ECCERR: |
| 1451 | case VXGE_HW_EVENT_MRPCIM_ECCERR: |
| 1452 | ret = -EPERM; |
| 1453 | goto out; |
| 1454 | case VXGE_HW_EVENT_FIFO_ERR: |
| 1455 | case VXGE_HW_EVENT_VPATH_ERR: |
| 1456 | break; |
| 1457 | case VXGE_HW_EVENT_CRITICAL_ERR: |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 1458 | netif_tx_stop_all_queues(vdev->ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1459 | vxge_debug_init(VXGE_ERR, |
| 1460 | "fatal: %s: Disabling device due to" |
| 1461 | "serious error", |
| 1462 | vdev->ndev->name); |
| 1463 | /* SOP or device reset required */ |
| 1464 | /* This event is not currently used */ |
| 1465 | ret = -EPERM; |
| 1466 | goto out; |
| 1467 | case VXGE_HW_EVENT_SERR: |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 1468 | netif_tx_stop_all_queues(vdev->ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1469 | vxge_debug_init(VXGE_ERR, |
| 1470 | "fatal: %s: Disabling device due to" |
| 1471 | "serious error", |
| 1472 | vdev->ndev->name); |
| 1473 | ret = -EPERM; |
| 1474 | goto out; |
| 1475 | case VXGE_HW_EVENT_SRPCIM_SERR: |
| 1476 | case VXGE_HW_EVENT_MRPCIM_SERR: |
| 1477 | ret = -EPERM; |
| 1478 | goto out; |
| 1479 | case VXGE_HW_EVENT_SLOT_FREEZE: |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 1480 | netif_tx_stop_all_queues(vdev->ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1481 | vxge_debug_init(VXGE_ERR, |
| 1482 | "fatal: %s: Disabling device due to" |
| 1483 | "slot freeze", |
| 1484 | vdev->ndev->name); |
| 1485 | ret = -EPERM; |
| 1486 | goto out; |
| 1487 | default: |
| 1488 | break; |
| 1489 | |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 1494 | netif_tx_stop_all_queues(vdev->ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1495 | |
| 1496 | if (event == VXGE_LL_FULL_RESET) { |
| 1497 | status = vxge_reset_all_vpaths(vdev); |
| 1498 | if (status != VXGE_HW_OK) { |
| 1499 | vxge_debug_init(VXGE_ERR, |
| 1500 | "fatal: %s: can not reset vpaths", |
| 1501 | vdev->ndev->name); |
| 1502 | ret = -EPERM; |
| 1503 | goto out; |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | if (event == VXGE_LL_COMPL_RESET) { |
| 1508 | for (i = 0; i < vdev->no_of_vpath; i++) |
| 1509 | if (vdev->vpaths[i].handle) { |
| 1510 | if (vxge_hw_vpath_recover_from_reset( |
| 1511 | vdev->vpaths[i].handle) |
| 1512 | != VXGE_HW_OK) { |
| 1513 | vxge_debug_init(VXGE_ERR, |
| 1514 | "vxge_hw_vpath_recover_" |
| 1515 | "from_reset failed for vpath: " |
| 1516 | "%d", i); |
| 1517 | ret = -EPERM; |
| 1518 | goto out; |
| 1519 | } |
| 1520 | } else { |
| 1521 | vxge_debug_init(VXGE_ERR, |
| 1522 | "vxge_hw_vpath_reset failed for " |
| 1523 | "vpath:%d", i); |
| 1524 | ret = -EPERM; |
| 1525 | goto out; |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) { |
| 1530 | /* Reprogram the DA table with populated mac addresses */ |
| 1531 | for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) { |
| 1532 | vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]); |
| 1533 | vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]); |
| 1534 | } |
| 1535 | |
| 1536 | /* enable vpath interrupts */ |
| 1537 | for (i = 0; i < vdev->no_of_vpath; i++) |
| 1538 | vxge_vpath_intr_enable(vdev, i); |
| 1539 | |
| 1540 | vxge_hw_device_intr_enable(vdev->devh); |
| 1541 | |
| 1542 | smp_wmb(); |
| 1543 | |
| 1544 | /* Indicate card up */ |
| 1545 | set_bit(__VXGE_STATE_CARD_UP, &vdev->state); |
| 1546 | |
| 1547 | /* Get the traffic to flow through the vpaths */ |
| 1548 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 1549 | vxge_hw_vpath_enable(vdev->vpaths[i].handle); |
| 1550 | smp_wmb(); |
| 1551 | vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle); |
| 1552 | } |
| 1553 | |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 1554 | netif_tx_wake_all_queues(vdev->ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | out: |
| 1558 | vxge_debug_entryexit(VXGE_TRACE, |
| 1559 | "%s:%d Exiting...", __func__, __LINE__); |
| 1560 | |
| 1561 | /* Indicate reset done */ |
| 1562 | if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) |
| 1563 | clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state); |
| 1564 | return ret; |
| 1565 | } |
| 1566 | |
| 1567 | /* |
| 1568 | * vxge_reset |
| 1569 | * @vdev: pointer to ll device |
| 1570 | * |
| 1571 | * driver may reset the chip on events of serr, eccerr, etc |
| 1572 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1573 | static int vxge_reset(struct vxgedev *vdev) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1574 | { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1575 | return do_vxge_reset(vdev, VXGE_LL_FULL_RESET); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | /** |
| 1579 | * vxge_poll - Receive handler when Receive Polling is used. |
| 1580 | * @dev: pointer to the device structure. |
| 1581 | * @budget: Number of packets budgeted to be processed in this iteration. |
| 1582 | * |
| 1583 | * This function comes into picture only if Receive side is being handled |
| 1584 | * through polling (called NAPI in linux). It mostly does what the normal |
| 1585 | * Rx interrupt handler does in terms of descriptor and packet processing |
| 1586 | * but not in an interrupt context. Also it will process a specified number |
| 1587 | * of packets at most in one iteration. This value is passed down by the |
| 1588 | * kernel as the function argument 'budget'. |
| 1589 | */ |
| 1590 | static int vxge_poll_msix(struct napi_struct *napi, int budget) |
| 1591 | { |
| 1592 | struct vxge_ring *ring = |
| 1593 | container_of(napi, struct vxge_ring, napi); |
| 1594 | int budget_org = budget; |
| 1595 | ring->budget = budget; |
| 1596 | |
| 1597 | vxge_hw_vpath_poll_rx(ring->handle); |
| 1598 | |
| 1599 | if (ring->pkts_processed < budget_org) { |
| 1600 | napi_complete(napi); |
| 1601 | /* Re enable the Rx interrupts for the vpath */ |
| 1602 | vxge_hw_channel_msix_unmask( |
| 1603 | (struct __vxge_hw_channel *)ring->handle, |
| 1604 | ring->rx_vector_no); |
| 1605 | } |
| 1606 | |
| 1607 | return ring->pkts_processed; |
| 1608 | } |
| 1609 | |
| 1610 | static int vxge_poll_inta(struct napi_struct *napi, int budget) |
| 1611 | { |
| 1612 | struct vxgedev *vdev = container_of(napi, struct vxgedev, napi); |
| 1613 | int pkts_processed = 0; |
| 1614 | int i; |
| 1615 | int budget_org = budget; |
| 1616 | struct vxge_ring *ring; |
| 1617 | |
| 1618 | struct __vxge_hw_device *hldev = (struct __vxge_hw_device *) |
| 1619 | pci_get_drvdata(vdev->pdev); |
| 1620 | |
| 1621 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 1622 | ring = &vdev->vpaths[i].ring; |
| 1623 | ring->budget = budget; |
| 1624 | vxge_hw_vpath_poll_rx(ring->handle); |
| 1625 | pkts_processed += ring->pkts_processed; |
| 1626 | budget -= ring->pkts_processed; |
| 1627 | if (budget <= 0) |
| 1628 | break; |
| 1629 | } |
| 1630 | |
| 1631 | VXGE_COMPLETE_ALL_TX(vdev); |
| 1632 | |
| 1633 | if (pkts_processed < budget_org) { |
| 1634 | napi_complete(napi); |
| 1635 | /* Re enable the Rx interrupts for the ring */ |
| 1636 | vxge_hw_device_unmask_all(hldev); |
| 1637 | vxge_hw_device_flush_io(hldev); |
| 1638 | } |
| 1639 | |
| 1640 | return pkts_processed; |
| 1641 | } |
| 1642 | |
| 1643 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1644 | /** |
| 1645 | * vxge_netpoll - netpoll event handler entry point |
| 1646 | * @dev : pointer to the device structure. |
| 1647 | * Description: |
| 1648 | * This function will be called by upper layer to check for events on the |
| 1649 | * interface in situations where interrupts are disabled. It is used for |
| 1650 | * specific in-kernel networking tasks, such as remote consoles and kernel |
| 1651 | * debugging over the network (example netdump in RedHat). |
| 1652 | */ |
| 1653 | static void vxge_netpoll(struct net_device *dev) |
| 1654 | { |
| 1655 | struct __vxge_hw_device *hldev; |
| 1656 | struct vxgedev *vdev; |
| 1657 | |
| 1658 | vdev = (struct vxgedev *)netdev_priv(dev); |
| 1659 | hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev); |
| 1660 | |
| 1661 | vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__); |
| 1662 | |
| 1663 | if (pci_channel_offline(vdev->pdev)) |
| 1664 | return; |
| 1665 | |
| 1666 | disable_irq(dev->irq); |
| 1667 | vxge_hw_device_clear_tx_rx(hldev); |
| 1668 | |
| 1669 | vxge_hw_device_clear_tx_rx(hldev); |
| 1670 | VXGE_COMPLETE_ALL_RX(vdev); |
| 1671 | VXGE_COMPLETE_ALL_TX(vdev); |
| 1672 | |
| 1673 | enable_irq(dev->irq); |
| 1674 | |
| 1675 | vxge_debug_entryexit(VXGE_TRACE, |
| 1676 | "%s:%d Exiting...", __func__, __LINE__); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1677 | } |
| 1678 | #endif |
| 1679 | |
| 1680 | /* RTH configuration */ |
| 1681 | static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev) |
| 1682 | { |
| 1683 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1684 | struct vxge_hw_rth_hash_types hash_types; |
| 1685 | u8 itable[256] = {0}; /* indirection table */ |
| 1686 | u8 mtable[256] = {0}; /* CPU to vpath mapping */ |
| 1687 | int index; |
| 1688 | |
| 1689 | /* |
| 1690 | * Filling |
| 1691 | * - itable with bucket numbers |
| 1692 | * - mtable with bucket-to-vpath mapping |
| 1693 | */ |
| 1694 | for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) { |
| 1695 | itable[index] = index; |
| 1696 | mtable[index] = index % vdev->no_of_vpath; |
| 1697 | } |
| 1698 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1699 | /* set indirection table, bucket-to-vpath mapping */ |
| 1700 | status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles, |
| 1701 | vdev->no_of_vpath, |
| 1702 | mtable, itable, |
| 1703 | vdev->config.rth_bkt_sz); |
| 1704 | if (status != VXGE_HW_OK) { |
| 1705 | vxge_debug_init(VXGE_ERR, |
| 1706 | "RTH indirection table configuration failed " |
| 1707 | "for vpath:%d", vdev->vpaths[0].device_id); |
| 1708 | return status; |
| 1709 | } |
| 1710 | |
Jon Mason | 47f01db | 2010-11-11 04:25:53 +0000 | [diff] [blame^] | 1711 | /* Fill RTH hash types */ |
| 1712 | hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4; |
| 1713 | hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4; |
| 1714 | hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6; |
| 1715 | hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6; |
| 1716 | hash_types.hash_type_tcpipv6ex_en = |
| 1717 | vdev->config.rth_hash_type_tcpipv6ex; |
| 1718 | hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex; |
| 1719 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1720 | /* |
Jon Mason | 47f01db | 2010-11-11 04:25:53 +0000 | [diff] [blame^] | 1721 | * Because the itable_set() method uses the active_table field |
| 1722 | * for the target virtual path the RTH config should be updated |
| 1723 | * for all VPATHs. The h/w only uses the lowest numbered VPATH |
| 1724 | * when steering frames. |
| 1725 | */ |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1726 | for (index = 0; index < vdev->no_of_vpath; index++) { |
| 1727 | status = vxge_hw_vpath_rts_rth_set( |
| 1728 | vdev->vpaths[index].handle, |
| 1729 | vdev->config.rth_algorithm, |
| 1730 | &hash_types, |
| 1731 | vdev->config.rth_bkt_sz); |
| 1732 | |
| 1733 | if (status != VXGE_HW_OK) { |
| 1734 | vxge_debug_init(VXGE_ERR, |
| 1735 | "RTH configuration failed for vpath:%d", |
| 1736 | vdev->vpaths[index].device_id); |
| 1737 | return status; |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | return status; |
| 1742 | } |
| 1743 | |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1744 | static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1745 | { |
| 1746 | struct vxge_mac_addrs *new_mac_entry; |
| 1747 | u8 *mac_address = NULL; |
| 1748 | |
| 1749 | if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT) |
| 1750 | return TRUE; |
| 1751 | |
| 1752 | new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC); |
| 1753 | if (!new_mac_entry) { |
| 1754 | vxge_debug_mem(VXGE_ERR, |
| 1755 | "%s: memory allocation failed", |
| 1756 | VXGE_DRIVER_NAME); |
| 1757 | return FALSE; |
| 1758 | } |
| 1759 | |
| 1760 | list_add(&new_mac_entry->item, &vpath->mac_addr_list); |
| 1761 | |
| 1762 | /* Copy the new mac address to the list */ |
| 1763 | mac_address = (u8 *)&new_mac_entry->macaddr; |
| 1764 | memcpy(mac_address, mac->macaddr, ETH_ALEN); |
| 1765 | |
| 1766 | new_mac_entry->state = mac->state; |
| 1767 | vpath->mac_addr_cnt++; |
| 1768 | |
| 1769 | /* Is this a multicast address */ |
| 1770 | if (0x01 & mac->macaddr[0]) |
| 1771 | vpath->mcast_addr_cnt++; |
| 1772 | |
| 1773 | return TRUE; |
| 1774 | } |
| 1775 | |
| 1776 | /* Add a mac address to DA table */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1777 | static enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, |
| 1778 | struct macInfo *mac) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1779 | { |
| 1780 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1781 | struct vxge_vpath *vpath; |
| 1782 | enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode; |
| 1783 | |
| 1784 | if (0x01 & mac->macaddr[0]) /* multicast address */ |
| 1785 | duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE; |
| 1786 | else |
| 1787 | duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE; |
| 1788 | |
| 1789 | vpath = &vdev->vpaths[mac->vpath_no]; |
| 1790 | status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr, |
| 1791 | mac->macmask, duplicate_mode); |
| 1792 | if (status != VXGE_HW_OK) { |
| 1793 | vxge_debug_init(VXGE_ERR, |
| 1794 | "DA config add entry failed for vpath:%d", |
| 1795 | vpath->device_id); |
| 1796 | } else |
| 1797 | if (FALSE == vxge_mac_list_add(vpath, mac)) |
| 1798 | status = -EPERM; |
| 1799 | |
| 1800 | return status; |
| 1801 | } |
| 1802 | |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1803 | static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1804 | { |
| 1805 | struct list_head *entry, *next; |
| 1806 | u64 del_mac = 0; |
| 1807 | u8 *mac_address = (u8 *) (&del_mac); |
| 1808 | |
| 1809 | /* Copy the mac address to delete from the list */ |
| 1810 | memcpy(mac_address, mac->macaddr, ETH_ALEN); |
| 1811 | |
| 1812 | list_for_each_safe(entry, next, &vpath->mac_addr_list) { |
| 1813 | if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) { |
| 1814 | list_del(entry); |
| 1815 | kfree((struct vxge_mac_addrs *)entry); |
| 1816 | vpath->mac_addr_cnt--; |
| 1817 | |
| 1818 | /* Is this a multicast address */ |
| 1819 | if (0x01 & mac->macaddr[0]) |
| 1820 | vpath->mcast_addr_cnt--; |
| 1821 | return TRUE; |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | return FALSE; |
| 1826 | } |
| 1827 | /* delete a mac address from DA table */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1828 | static enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, |
| 1829 | struct macInfo *mac) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1830 | { |
| 1831 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1832 | struct vxge_vpath *vpath; |
| 1833 | |
| 1834 | vpath = &vdev->vpaths[mac->vpath_no]; |
| 1835 | status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr, |
| 1836 | mac->macmask); |
| 1837 | if (status != VXGE_HW_OK) { |
| 1838 | vxge_debug_init(VXGE_ERR, |
| 1839 | "DA config delete entry failed for vpath:%d", |
| 1840 | vpath->device_id); |
| 1841 | } else |
| 1842 | vxge_mac_list_del(vpath, mac); |
| 1843 | return status; |
| 1844 | } |
| 1845 | |
| 1846 | /* list all mac addresses from DA table */ |
| 1847 | enum vxge_hw_status |
| 1848 | static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, |
| 1849 | struct macInfo *mac) |
| 1850 | { |
| 1851 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1852 | unsigned char macmask[ETH_ALEN]; |
| 1853 | unsigned char macaddr[ETH_ALEN]; |
| 1854 | |
| 1855 | status = vxge_hw_vpath_mac_addr_get(vpath->handle, |
| 1856 | macaddr, macmask); |
| 1857 | if (status != VXGE_HW_OK) { |
| 1858 | vxge_debug_init(VXGE_ERR, |
| 1859 | "DA config list entry failed for vpath:%d", |
| 1860 | vpath->device_id); |
| 1861 | return status; |
| 1862 | } |
| 1863 | |
| 1864 | while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) { |
| 1865 | |
| 1866 | status = vxge_hw_vpath_mac_addr_get_next(vpath->handle, |
| 1867 | macaddr, macmask); |
| 1868 | if (status != VXGE_HW_OK) |
| 1869 | break; |
| 1870 | } |
| 1871 | |
| 1872 | return status; |
| 1873 | } |
| 1874 | |
| 1875 | /* Store all vlan ids from the list to the vid table */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1876 | static enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1877 | { |
| 1878 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1879 | struct vxgedev *vdev = vpath->vdev; |
| 1880 | u16 vid; |
| 1881 | |
| 1882 | if (vdev->vlgrp && vpath->is_open) { |
| 1883 | |
Jesse Gross | b738127 | 2010-10-20 13:56:02 +0000 | [diff] [blame] | 1884 | for (vid = 0; vid < VLAN_N_VID; vid++) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1885 | if (!vlan_group_get_device(vdev->vlgrp, vid)) |
| 1886 | continue; |
| 1887 | /* Add these vlan to the vid table */ |
| 1888 | status = vxge_hw_vpath_vid_add(vpath->handle, vid); |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | return status; |
| 1893 | } |
| 1894 | |
| 1895 | /* Store all mac addresses from the list to the DA table */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1896 | static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1897 | { |
| 1898 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1899 | struct macInfo mac_info; |
| 1900 | u8 *mac_address = NULL; |
| 1901 | struct list_head *entry, *next; |
| 1902 | |
| 1903 | memset(&mac_info, 0, sizeof(struct macInfo)); |
| 1904 | |
| 1905 | if (vpath->is_open) { |
| 1906 | |
| 1907 | list_for_each_safe(entry, next, &vpath->mac_addr_list) { |
| 1908 | mac_address = |
| 1909 | (u8 *)& |
| 1910 | ((struct vxge_mac_addrs *)entry)->macaddr; |
| 1911 | memcpy(mac_info.macaddr, mac_address, ETH_ALEN); |
| 1912 | ((struct vxge_mac_addrs *)entry)->state = |
| 1913 | VXGE_LL_MAC_ADDR_IN_DA_TABLE; |
| 1914 | /* does this mac address already exist in da table? */ |
| 1915 | status = vxge_search_mac_addr_in_da_table(vpath, |
| 1916 | &mac_info); |
| 1917 | if (status != VXGE_HW_OK) { |
| 1918 | /* Add this mac address to the DA table */ |
| 1919 | status = vxge_hw_vpath_mac_addr_add( |
| 1920 | vpath->handle, mac_info.macaddr, |
| 1921 | mac_info.macmask, |
| 1922 | VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE); |
| 1923 | if (status != VXGE_HW_OK) { |
| 1924 | vxge_debug_init(VXGE_ERR, |
| 1925 | "DA add entry failed for vpath:%d", |
| 1926 | vpath->device_id); |
| 1927 | ((struct vxge_mac_addrs *)entry)->state |
| 1928 | = VXGE_LL_MAC_ADDR_IN_LIST; |
| 1929 | } |
| 1930 | } |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | return status; |
| 1935 | } |
| 1936 | |
| 1937 | /* reset vpaths */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1938 | static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1939 | { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1940 | enum vxge_hw_status status = VXGE_HW_OK; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1941 | struct vxge_vpath *vpath; |
| 1942 | int i; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1943 | |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1944 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 1945 | vpath = &vdev->vpaths[i]; |
| 1946 | if (vpath->handle) { |
| 1947 | if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1948 | if (is_vxge_card_up(vdev) && |
| 1949 | vxge_hw_vpath_recover_from_reset( |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1950 | vpath->handle) != VXGE_HW_OK) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1951 | vxge_debug_init(VXGE_ERR, |
| 1952 | "vxge_hw_vpath_recover_" |
| 1953 | "from_reset failed for vpath: " |
| 1954 | "%d", i); |
| 1955 | return status; |
| 1956 | } |
| 1957 | } else { |
| 1958 | vxge_debug_init(VXGE_ERR, |
| 1959 | "vxge_hw_vpath_reset failed for " |
| 1960 | "vpath:%d", i); |
| 1961 | return status; |
| 1962 | } |
| 1963 | } |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1966 | return status; |
| 1967 | } |
| 1968 | |
| 1969 | /* close vpaths */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1970 | static void vxge_close_vpaths(struct vxgedev *vdev, int index) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1971 | { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1972 | struct vxge_vpath *vpath; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1973 | int i; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1974 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1975 | for (i = index; i < vdev->no_of_vpath; i++) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1976 | vpath = &vdev->vpaths[i]; |
| 1977 | |
| 1978 | if (vpath->handle && vpath->is_open) { |
| 1979 | vxge_hw_vpath_close(vpath->handle); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1980 | vdev->stats.vpaths_open--; |
| 1981 | } |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1982 | vpath->is_open = 0; |
| 1983 | vpath->handle = NULL; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | /* open vpaths */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1988 | static int vxge_open_vpaths(struct vxgedev *vdev) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1989 | { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1990 | struct vxge_hw_vpath_attr attr; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1991 | enum vxge_hw_status status; |
| 1992 | struct vxge_vpath *vpath; |
| 1993 | u32 vp_id = 0; |
| 1994 | int i; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 1995 | |
| 1996 | for (i = 0; i < vdev->no_of_vpath; i++) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 1997 | vpath = &vdev->vpaths[i]; |
| 1998 | |
| 1999 | vxge_assert(vpath->is_configured); |
| 2000 | attr.vp_id = vpath->device_id; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2001 | attr.fifo_attr.callback = vxge_xmit_compl; |
| 2002 | attr.fifo_attr.txdl_term = vxge_tx_term; |
| 2003 | attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv); |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2004 | attr.fifo_attr.userdata = &vpath->fifo; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2005 | |
| 2006 | attr.ring_attr.callback = vxge_rx_1b_compl; |
| 2007 | attr.ring_attr.rxd_init = vxge_rx_initial_replenish; |
| 2008 | attr.ring_attr.rxd_term = vxge_rx_term; |
| 2009 | attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv); |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2010 | attr.ring_attr.userdata = &vpath->ring; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2011 | |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2012 | vpath->ring.ndev = vdev->ndev; |
| 2013 | vpath->ring.pdev = vdev->pdev; |
| 2014 | status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2015 | if (status == VXGE_HW_OK) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2016 | vpath->fifo.handle = |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2017 | (struct __vxge_hw_fifo *)attr.fifo_attr.userdata; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2018 | vpath->ring.handle = |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2019 | (struct __vxge_hw_ring *)attr.ring_attr.userdata; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2020 | vpath->fifo.tx_steering_type = |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2021 | vdev->config.tx_steering_type; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2022 | vpath->fifo.ndev = vdev->ndev; |
| 2023 | vpath->fifo.pdev = vdev->pdev; |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 2024 | if (vdev->config.tx_steering_type) |
| 2025 | vpath->fifo.txq = |
| 2026 | netdev_get_tx_queue(vdev->ndev, i); |
| 2027 | else |
| 2028 | vpath->fifo.txq = |
| 2029 | netdev_get_tx_queue(vdev->ndev, 0); |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2030 | vpath->fifo.indicate_max_pkts = |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2031 | vdev->config.fifo_indicate_max_pkts; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2032 | vpath->ring.rx_vector_no = 0; |
| 2033 | vpath->ring.rx_csum = vdev->rx_csum; |
| 2034 | vpath->is_open = 1; |
| 2035 | vdev->vp_handles[i] = vpath->handle; |
| 2036 | vpath->ring.gro_enable = vdev->config.gro_enable; |
| 2037 | vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2038 | vdev->stats.vpaths_open++; |
| 2039 | } else { |
| 2040 | vdev->stats.vpath_open_fail++; |
| 2041 | vxge_debug_init(VXGE_ERR, |
| 2042 | "%s: vpath: %d failed to open " |
| 2043 | "with status: %d", |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2044 | vdev->ndev->name, vpath->device_id, |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2045 | status); |
| 2046 | vxge_close_vpaths(vdev, 0); |
| 2047 | return -EPERM; |
| 2048 | } |
| 2049 | |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2050 | vp_id = vpath->handle->vpath->vp_id; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2051 | vdev->vpaths_deployed |= vxge_mBIT(vp_id); |
| 2052 | } |
| 2053 | return VXGE_HW_OK; |
| 2054 | } |
| 2055 | |
| 2056 | /* |
| 2057 | * vxge_isr_napi |
| 2058 | * @irq: the irq of the device. |
| 2059 | * @dev_id: a void pointer to the hldev structure of the Titan device |
| 2060 | * @ptregs: pointer to the registers pushed on the stack. |
| 2061 | * |
| 2062 | * This function is the ISR handler of the device when napi is enabled. It |
| 2063 | * identifies the reason for the interrupt and calls the relevant service |
| 2064 | * routines. |
| 2065 | */ |
| 2066 | static irqreturn_t vxge_isr_napi(int irq, void *dev_id) |
| 2067 | { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2068 | struct net_device *dev; |
Sreenivasa Honnur | a5d165b | 2009-07-01 21:16:37 +0000 | [diff] [blame] | 2069 | struct __vxge_hw_device *hldev; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2070 | u64 reason; |
| 2071 | enum vxge_hw_status status; |
Sreenivasa Honnur | a5d165b | 2009-07-01 21:16:37 +0000 | [diff] [blame] | 2072 | struct vxgedev *vdev = (struct vxgedev *) dev_id;; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2073 | |
| 2074 | vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__); |
| 2075 | |
Sreenivasa Honnur | a5d165b | 2009-07-01 21:16:37 +0000 | [diff] [blame] | 2076 | dev = vdev->ndev; |
| 2077 | hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2078 | |
| 2079 | if (pci_channel_offline(vdev->pdev)) |
| 2080 | return IRQ_NONE; |
| 2081 | |
| 2082 | if (unlikely(!is_vxge_card_up(vdev))) |
| 2083 | return IRQ_NONE; |
| 2084 | |
| 2085 | status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, |
| 2086 | &reason); |
| 2087 | if (status == VXGE_HW_OK) { |
| 2088 | vxge_hw_device_mask_all(hldev); |
| 2089 | |
| 2090 | if (reason & |
| 2091 | VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT( |
| 2092 | vdev->vpaths_deployed >> |
| 2093 | (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) { |
| 2094 | |
| 2095 | vxge_hw_device_clear_tx_rx(hldev); |
| 2096 | napi_schedule(&vdev->napi); |
| 2097 | vxge_debug_intr(VXGE_TRACE, |
| 2098 | "%s:%d Exiting...", __func__, __LINE__); |
| 2099 | return IRQ_HANDLED; |
| 2100 | } else |
| 2101 | vxge_hw_device_unmask_all(hldev); |
| 2102 | } else if (unlikely((status == VXGE_HW_ERR_VPATH) || |
| 2103 | (status == VXGE_HW_ERR_CRITICAL) || |
| 2104 | (status == VXGE_HW_ERR_FIFO))) { |
| 2105 | vxge_hw_device_mask_all(hldev); |
| 2106 | vxge_hw_device_flush_io(hldev); |
| 2107 | return IRQ_HANDLED; |
| 2108 | } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE)) |
| 2109 | return IRQ_HANDLED; |
| 2110 | |
| 2111 | vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__); |
| 2112 | return IRQ_NONE; |
| 2113 | } |
| 2114 | |
| 2115 | #ifdef CONFIG_PCI_MSI |
| 2116 | |
| 2117 | static irqreturn_t |
| 2118 | vxge_tx_msix_handle(int irq, void *dev_id) |
| 2119 | { |
| 2120 | struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id; |
| 2121 | |
| 2122 | VXGE_COMPLETE_VPATH_TX(fifo); |
| 2123 | |
| 2124 | return IRQ_HANDLED; |
| 2125 | } |
| 2126 | |
| 2127 | static irqreturn_t |
| 2128 | vxge_rx_msix_napi_handle(int irq, void *dev_id) |
| 2129 | { |
| 2130 | struct vxge_ring *ring = (struct vxge_ring *)dev_id; |
| 2131 | |
| 2132 | /* MSIX_IDX for Rx is 1 */ |
| 2133 | vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle, |
| 2134 | ring->rx_vector_no); |
| 2135 | |
| 2136 | napi_schedule(&ring->napi); |
| 2137 | return IRQ_HANDLED; |
| 2138 | } |
| 2139 | |
| 2140 | static irqreturn_t |
| 2141 | vxge_alarm_msix_handle(int irq, void *dev_id) |
| 2142 | { |
| 2143 | int i; |
| 2144 | enum vxge_hw_status status; |
| 2145 | struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id; |
| 2146 | struct vxgedev *vdev = vpath->vdev; |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2147 | int msix_id = (vpath->handle->vpath->vp_id * |
| 2148 | VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2149 | |
| 2150 | for (i = 0; i < vdev->no_of_vpath; i++) { |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2151 | vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2152 | |
| 2153 | status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle, |
| 2154 | vdev->exec_mode); |
| 2155 | if (status == VXGE_HW_OK) { |
| 2156 | |
| 2157 | vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle, |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2158 | msix_id); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2159 | continue; |
| 2160 | } |
| 2161 | vxge_debug_intr(VXGE_ERR, |
| 2162 | "%s: vxge_hw_vpath_alarm_process failed %x ", |
| 2163 | VXGE_DRIVER_NAME, status); |
| 2164 | } |
| 2165 | return IRQ_HANDLED; |
| 2166 | } |
| 2167 | |
| 2168 | static int vxge_alloc_msix(struct vxgedev *vdev) |
| 2169 | { |
| 2170 | int j, i, ret = 0; |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2171 | int msix_intr_vect = 0, temp; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2172 | vdev->intr_cnt = 0; |
| 2173 | |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2174 | start: |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2175 | /* Tx/Rx MSIX Vectors count */ |
| 2176 | vdev->intr_cnt = vdev->no_of_vpath * 2; |
| 2177 | |
| 2178 | /* Alarm MSIX Vectors count */ |
| 2179 | vdev->intr_cnt++; |
| 2180 | |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 2181 | vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry), |
| 2182 | GFP_KERNEL); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2183 | if (!vdev->entries) { |
| 2184 | vxge_debug_init(VXGE_ERR, |
| 2185 | "%s: memory allocation failed", |
| 2186 | VXGE_DRIVER_NAME); |
Michal Schmidt | cc413d9 | 2010-06-24 04:13:44 +0000 | [diff] [blame] | 2187 | ret = -ENOMEM; |
| 2188 | goto alloc_entries_failed; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 2191 | vdev->vxge_entries = kcalloc(vdev->intr_cnt, |
| 2192 | sizeof(struct vxge_msix_entry), |
| 2193 | GFP_KERNEL); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2194 | if (!vdev->vxge_entries) { |
| 2195 | vxge_debug_init(VXGE_ERR, "%s: memory allocation failed", |
| 2196 | VXGE_DRIVER_NAME); |
Michal Schmidt | cc413d9 | 2010-06-24 04:13:44 +0000 | [diff] [blame] | 2197 | ret = -ENOMEM; |
| 2198 | goto alloc_vxge_entries_failed; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2201 | for (i = 0, j = 0; i < vdev->no_of_vpath; i++) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2202 | |
| 2203 | msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE; |
| 2204 | |
| 2205 | /* Initialize the fifo vector */ |
| 2206 | vdev->entries[j].entry = msix_intr_vect; |
| 2207 | vdev->vxge_entries[j].entry = msix_intr_vect; |
| 2208 | vdev->vxge_entries[j].in_use = 0; |
| 2209 | j++; |
| 2210 | |
| 2211 | /* Initialize the ring vector */ |
| 2212 | vdev->entries[j].entry = msix_intr_vect + 1; |
| 2213 | vdev->vxge_entries[j].entry = msix_intr_vect + 1; |
| 2214 | vdev->vxge_entries[j].in_use = 0; |
| 2215 | j++; |
| 2216 | } |
| 2217 | |
| 2218 | /* Initialize the alarm vector */ |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2219 | vdev->entries[j].entry = VXGE_ALARM_MSIX_ID; |
| 2220 | vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2221 | vdev->vxge_entries[j].in_use = 0; |
| 2222 | |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2223 | ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2224 | if (ret > 0) { |
| 2225 | vxge_debug_init(VXGE_ERR, |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2226 | "%s: MSI-X enable failed for %d vectors, ret: %d", |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2227 | VXGE_DRIVER_NAME, vdev->intr_cnt, ret); |
Michal Schmidt | cc413d9 | 2010-06-24 04:13:44 +0000 | [diff] [blame] | 2228 | if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) { |
| 2229 | ret = -ENODEV; |
| 2230 | goto enable_msix_failed; |
| 2231 | } |
| 2232 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2233 | kfree(vdev->entries); |
| 2234 | kfree(vdev->vxge_entries); |
| 2235 | vdev->entries = NULL; |
| 2236 | vdev->vxge_entries = NULL; |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2237 | /* Try with less no of vector by reducing no of vpaths count */ |
| 2238 | temp = (ret - 1)/2; |
| 2239 | vxge_close_vpaths(vdev, temp); |
| 2240 | vdev->no_of_vpath = temp; |
| 2241 | goto start; |
Michal Schmidt | cc413d9 | 2010-06-24 04:13:44 +0000 | [diff] [blame] | 2242 | } else if (ret < 0) { |
| 2243 | ret = -ENODEV; |
| 2244 | goto enable_msix_failed; |
| 2245 | } |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2246 | return 0; |
Michal Schmidt | cc413d9 | 2010-06-24 04:13:44 +0000 | [diff] [blame] | 2247 | |
| 2248 | enable_msix_failed: |
| 2249 | kfree(vdev->vxge_entries); |
| 2250 | alloc_vxge_entries_failed: |
| 2251 | kfree(vdev->entries); |
| 2252 | alloc_entries_failed: |
| 2253 | return ret; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | static int vxge_enable_msix(struct vxgedev *vdev) |
| 2257 | { |
| 2258 | |
| 2259 | int i, ret = 0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2260 | /* 0 - Tx, 1 - Rx */ |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2261 | int tim_msix_id[4] = {0, 1, 0, 0}; |
| 2262 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2263 | vdev->intr_cnt = 0; |
| 2264 | |
| 2265 | /* allocate msix vectors */ |
| 2266 | ret = vxge_alloc_msix(vdev); |
| 2267 | if (!ret) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2268 | for (i = 0; i < vdev->no_of_vpath; i++) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2269 | struct vxge_vpath *vpath = &vdev->vpaths[i]; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2270 | |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2271 | /* If fifo or ring are not enabled, the MSIX vector for |
| 2272 | * it should be set to 0. |
| 2273 | */ |
| 2274 | vpath->ring.rx_vector_no = (vpath->device_id * |
| 2275 | VXGE_HW_VPATH_MSIX_ACTIVE) + 1; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2276 | |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2277 | vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id, |
| 2278 | VXGE_ALARM_MSIX_ID); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | return ret; |
| 2283 | } |
| 2284 | |
| 2285 | static void vxge_rem_msix_isr(struct vxgedev *vdev) |
| 2286 | { |
| 2287 | int intr_cnt; |
| 2288 | |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2289 | for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2290 | intr_cnt++) { |
| 2291 | if (vdev->vxge_entries[intr_cnt].in_use) { |
| 2292 | synchronize_irq(vdev->entries[intr_cnt].vector); |
| 2293 | free_irq(vdev->entries[intr_cnt].vector, |
| 2294 | vdev->vxge_entries[intr_cnt].arg); |
| 2295 | vdev->vxge_entries[intr_cnt].in_use = 0; |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | kfree(vdev->entries); |
| 2300 | kfree(vdev->vxge_entries); |
| 2301 | vdev->entries = NULL; |
| 2302 | vdev->vxge_entries = NULL; |
| 2303 | |
| 2304 | if (vdev->config.intr_type == MSI_X) |
| 2305 | pci_disable_msix(vdev->pdev); |
| 2306 | } |
| 2307 | #endif |
| 2308 | |
| 2309 | static void vxge_rem_isr(struct vxgedev *vdev) |
| 2310 | { |
| 2311 | struct __vxge_hw_device *hldev; |
| 2312 | hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev); |
| 2313 | |
| 2314 | #ifdef CONFIG_PCI_MSI |
| 2315 | if (vdev->config.intr_type == MSI_X) { |
| 2316 | vxge_rem_msix_isr(vdev); |
| 2317 | } else |
| 2318 | #endif |
| 2319 | if (vdev->config.intr_type == INTA) { |
| 2320 | synchronize_irq(vdev->pdev->irq); |
Sreenivasa Honnur | a5d165b | 2009-07-01 21:16:37 +0000 | [diff] [blame] | 2321 | free_irq(vdev->pdev->irq, vdev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | static int vxge_add_isr(struct vxgedev *vdev) |
| 2326 | { |
| 2327 | int ret = 0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2328 | #ifdef CONFIG_PCI_MSI |
| 2329 | int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2330 | int pci_fun = PCI_FUNC(vdev->pdev->devfn); |
| 2331 | |
| 2332 | if (vdev->config.intr_type == MSI_X) |
| 2333 | ret = vxge_enable_msix(vdev); |
| 2334 | |
| 2335 | if (ret) { |
| 2336 | vxge_debug_init(VXGE_ERR, |
| 2337 | "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME); |
Sreenivasa Honnur | eb5f10c | 2009-10-05 01:57:29 +0000 | [diff] [blame] | 2338 | vxge_debug_init(VXGE_ERR, |
| 2339 | "%s: Defaulting to INTA", VXGE_DRIVER_NAME); |
| 2340 | vdev->config.intr_type = INTA; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | if (vdev->config.intr_type == MSI_X) { |
| 2344 | for (intr_idx = 0; |
| 2345 | intr_idx < (vdev->no_of_vpath * |
| 2346 | VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) { |
| 2347 | |
| 2348 | msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE; |
| 2349 | irq_req = 0; |
| 2350 | |
| 2351 | switch (msix_idx) { |
| 2352 | case 0: |
| 2353 | snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN, |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2354 | "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d", |
| 2355 | vdev->ndev->name, |
| 2356 | vdev->entries[intr_cnt].entry, |
| 2357 | pci_fun, vp_idx); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2358 | ret = request_irq( |
| 2359 | vdev->entries[intr_cnt].vector, |
| 2360 | vxge_tx_msix_handle, 0, |
| 2361 | vdev->desc[intr_cnt], |
| 2362 | &vdev->vpaths[vp_idx].fifo); |
| 2363 | vdev->vxge_entries[intr_cnt].arg = |
| 2364 | &vdev->vpaths[vp_idx].fifo; |
| 2365 | irq_req = 1; |
| 2366 | break; |
| 2367 | case 1: |
| 2368 | snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN, |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2369 | "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d", |
| 2370 | vdev->ndev->name, |
| 2371 | vdev->entries[intr_cnt].entry, |
| 2372 | pci_fun, vp_idx); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2373 | ret = request_irq( |
| 2374 | vdev->entries[intr_cnt].vector, |
| 2375 | vxge_rx_msix_napi_handle, |
| 2376 | 0, |
| 2377 | vdev->desc[intr_cnt], |
| 2378 | &vdev->vpaths[vp_idx].ring); |
| 2379 | vdev->vxge_entries[intr_cnt].arg = |
| 2380 | &vdev->vpaths[vp_idx].ring; |
| 2381 | irq_req = 1; |
| 2382 | break; |
| 2383 | } |
| 2384 | |
| 2385 | if (ret) { |
| 2386 | vxge_debug_init(VXGE_ERR, |
| 2387 | "%s: MSIX - %d Registration failed", |
| 2388 | vdev->ndev->name, intr_cnt); |
| 2389 | vxge_rem_msix_isr(vdev); |
Sreenivasa Honnur | eb5f10c | 2009-10-05 01:57:29 +0000 | [diff] [blame] | 2390 | vdev->config.intr_type = INTA; |
| 2391 | vxge_debug_init(VXGE_ERR, |
| 2392 | "%s: Defaulting to INTA" |
| 2393 | , vdev->ndev->name); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2394 | goto INTA_MODE; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | if (irq_req) { |
| 2398 | /* We requested for this msix interrupt */ |
| 2399 | vdev->vxge_entries[intr_cnt].in_use = 1; |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2400 | msix_idx += vdev->vpaths[vp_idx].device_id * |
| 2401 | VXGE_HW_VPATH_MSIX_ACTIVE; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2402 | vxge_hw_vpath_msix_unmask( |
| 2403 | vdev->vpaths[vp_idx].handle, |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2404 | msix_idx); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2405 | intr_cnt++; |
| 2406 | } |
| 2407 | |
| 2408 | /* Point to next vpath handler */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 2409 | if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) && |
| 2410 | (vp_idx < (vdev->no_of_vpath - 1))) |
| 2411 | vp_idx++; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2414 | intr_cnt = vdev->no_of_vpath * 2; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2415 | snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN, |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2416 | "%s:vxge:MSI-X %d - Alarm - fn:%d", |
| 2417 | vdev->ndev->name, |
| 2418 | vdev->entries[intr_cnt].entry, |
| 2419 | pci_fun); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2420 | /* For Alarm interrupts */ |
| 2421 | ret = request_irq(vdev->entries[intr_cnt].vector, |
| 2422 | vxge_alarm_msix_handle, 0, |
| 2423 | vdev->desc[intr_cnt], |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2424 | &vdev->vpaths[0]); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2425 | if (ret) { |
| 2426 | vxge_debug_init(VXGE_ERR, |
| 2427 | "%s: MSIX - %d Registration failed", |
| 2428 | vdev->ndev->name, intr_cnt); |
| 2429 | vxge_rem_msix_isr(vdev); |
Sreenivasa Honnur | eb5f10c | 2009-10-05 01:57:29 +0000 | [diff] [blame] | 2430 | vdev->config.intr_type = INTA; |
| 2431 | vxge_debug_init(VXGE_ERR, |
| 2432 | "%s: Defaulting to INTA", |
| 2433 | vdev->ndev->name); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2434 | goto INTA_MODE; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2435 | } |
| 2436 | |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2437 | msix_idx = (vdev->vpaths[0].handle->vpath->vp_id * |
| 2438 | VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2439 | vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle, |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2440 | msix_idx); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2441 | vdev->vxge_entries[intr_cnt].in_use = 1; |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2442 | vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0]; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2443 | } |
| 2444 | INTA_MODE: |
| 2445 | #endif |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2446 | |
| 2447 | if (vdev->config.intr_type == INTA) { |
Sreenivasa Honnur | b59c9457 | 2010-03-28 22:11:41 +0000 | [diff] [blame] | 2448 | snprintf(vdev->desc[0], VXGE_INTR_STRLEN, |
| 2449 | "%s:vxge:INTA", vdev->ndev->name); |
Sreenivasa Honnur | eb5f10c | 2009-10-05 01:57:29 +0000 | [diff] [blame] | 2450 | vxge_hw_device_set_intr_type(vdev->devh, |
| 2451 | VXGE_HW_INTR_MODE_IRQLINE); |
| 2452 | vxge_hw_vpath_tti_ci_set(vdev->devh, |
| 2453 | vdev->vpaths[0].device_id); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2454 | ret = request_irq((int) vdev->pdev->irq, |
| 2455 | vxge_isr_napi, |
Sreenivasa Honnur | a5d165b | 2009-07-01 21:16:37 +0000 | [diff] [blame] | 2456 | IRQF_SHARED, vdev->desc[0], vdev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2457 | if (ret) { |
| 2458 | vxge_debug_init(VXGE_ERR, |
| 2459 | "%s %s-%d: ISR registration failed", |
| 2460 | VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq); |
| 2461 | return -ENODEV; |
| 2462 | } |
| 2463 | vxge_debug_init(VXGE_TRACE, |
| 2464 | "new %s-%d line allocated", |
| 2465 | "IRQ", vdev->pdev->irq); |
| 2466 | } |
| 2467 | |
| 2468 | return VXGE_HW_OK; |
| 2469 | } |
| 2470 | |
| 2471 | static void vxge_poll_vp_reset(unsigned long data) |
| 2472 | { |
| 2473 | struct vxgedev *vdev = (struct vxgedev *)data; |
| 2474 | int i, j = 0; |
| 2475 | |
| 2476 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 2477 | if (test_bit(i, &vdev->vp_reset)) { |
| 2478 | vxge_reset_vpath(vdev, i); |
| 2479 | j++; |
| 2480 | } |
| 2481 | } |
| 2482 | if (j && (vdev->config.intr_type != MSI_X)) { |
| 2483 | vxge_hw_device_unmask_all(vdev->devh); |
| 2484 | vxge_hw_device_flush_io(vdev->devh); |
| 2485 | } |
| 2486 | |
| 2487 | mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2); |
| 2488 | } |
| 2489 | |
| 2490 | static void vxge_poll_vp_lockup(unsigned long data) |
| 2491 | { |
| 2492 | struct vxgedev *vdev = (struct vxgedev *)data; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2493 | enum vxge_hw_status status = VXGE_HW_OK; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2494 | struct vxge_vpath *vpath; |
| 2495 | struct vxge_ring *ring; |
| 2496 | int i; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2497 | |
| 2498 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 2499 | ring = &vdev->vpaths[i].ring; |
| 2500 | /* Did this vpath received any packets */ |
| 2501 | if (ring->stats.prev_rx_frms == ring->stats.rx_frms) { |
| 2502 | status = vxge_hw_vpath_check_leak(ring->handle); |
| 2503 | |
| 2504 | /* Did it received any packets last time */ |
| 2505 | if ((VXGE_HW_FAIL == status) && |
| 2506 | (VXGE_HW_FAIL == ring->last_status)) { |
| 2507 | |
| 2508 | /* schedule vpath reset */ |
| 2509 | if (!test_and_set_bit(i, &vdev->vp_reset)) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2510 | vpath = &vdev->vpaths[i]; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2511 | |
| 2512 | /* disable interrupts for this vpath */ |
| 2513 | vxge_vpath_intr_disable(vdev, i); |
| 2514 | |
| 2515 | /* stop the queue for this vpath */ |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 2516 | netif_tx_stop_queue(vpath->fifo.txq); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2517 | continue; |
| 2518 | } |
| 2519 | } |
| 2520 | } |
| 2521 | ring->stats.prev_rx_frms = ring->stats.rx_frms; |
| 2522 | ring->last_status = status; |
| 2523 | } |
| 2524 | |
| 2525 | /* Check every 1 milli second */ |
| 2526 | mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000); |
| 2527 | } |
| 2528 | |
| 2529 | /** |
| 2530 | * vxge_open |
| 2531 | * @dev: pointer to the device structure. |
| 2532 | * |
| 2533 | * This function is the open entry point of the driver. It mainly calls a |
| 2534 | * function to allocate Rx buffers and inserts them into the buffer |
| 2535 | * descriptors and then enables the Rx part of the NIC. |
| 2536 | * Return value: '0' on success and an appropriate (-)ve integer as |
| 2537 | * defined in errno.h file on failure. |
| 2538 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2539 | static int |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2540 | vxge_open(struct net_device *dev) |
| 2541 | { |
| 2542 | enum vxge_hw_status status; |
| 2543 | struct vxgedev *vdev; |
| 2544 | struct __vxge_hw_device *hldev; |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2545 | struct vxge_vpath *vpath; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2546 | int ret = 0; |
| 2547 | int i; |
| 2548 | u64 val64, function_mode; |
| 2549 | vxge_debug_entryexit(VXGE_TRACE, |
| 2550 | "%s: %s:%d", dev->name, __func__, __LINE__); |
| 2551 | |
| 2552 | vdev = (struct vxgedev *)netdev_priv(dev); |
| 2553 | hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev); |
| 2554 | function_mode = vdev->config.device_hw_info.function_mode; |
| 2555 | |
| 2556 | /* make sure you have link off by default every time Nic is |
| 2557 | * initialized */ |
| 2558 | netif_carrier_off(dev); |
| 2559 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2560 | /* Open VPATHs */ |
| 2561 | status = vxge_open_vpaths(vdev); |
| 2562 | if (status != VXGE_HW_OK) { |
| 2563 | vxge_debug_init(VXGE_ERR, |
| 2564 | "%s: fatal: Vpath open failed", vdev->ndev->name); |
| 2565 | ret = -EPERM; |
| 2566 | goto out0; |
| 2567 | } |
| 2568 | |
| 2569 | vdev->mtu = dev->mtu; |
| 2570 | |
| 2571 | status = vxge_add_isr(vdev); |
| 2572 | if (status != VXGE_HW_OK) { |
| 2573 | vxge_debug_init(VXGE_ERR, |
| 2574 | "%s: fatal: ISR add failed", dev->name); |
| 2575 | ret = -EPERM; |
| 2576 | goto out1; |
| 2577 | } |
| 2578 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2579 | if (vdev->config.intr_type != MSI_X) { |
| 2580 | netif_napi_add(dev, &vdev->napi, vxge_poll_inta, |
| 2581 | vdev->config.napi_weight); |
| 2582 | napi_enable(&vdev->napi); |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2583 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 2584 | vpath = &vdev->vpaths[i]; |
| 2585 | vpath->ring.napi_p = &vdev->napi; |
| 2586 | } |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2587 | } else { |
| 2588 | for (i = 0; i < vdev->no_of_vpath; i++) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2589 | vpath = &vdev->vpaths[i]; |
| 2590 | netif_napi_add(dev, &vpath->ring.napi, |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2591 | vxge_poll_msix, vdev->config.napi_weight); |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2592 | napi_enable(&vpath->ring.napi); |
| 2593 | vpath->ring.napi_p = &vpath->ring.napi; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | /* configure RTH */ |
| 2598 | if (vdev->config.rth_steering) { |
| 2599 | status = vxge_rth_configure(vdev); |
| 2600 | if (status != VXGE_HW_OK) { |
| 2601 | vxge_debug_init(VXGE_ERR, |
| 2602 | "%s: fatal: RTH configuration failed", |
| 2603 | dev->name); |
| 2604 | ret = -EPERM; |
| 2605 | goto out2; |
| 2606 | } |
| 2607 | } |
Jon Mason | 47f01db | 2010-11-11 04:25:53 +0000 | [diff] [blame^] | 2608 | printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name, |
| 2609 | hldev->config.rth_en ? "enabled" : "disabled"); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2610 | |
| 2611 | for (i = 0; i < vdev->no_of_vpath; i++) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2612 | vpath = &vdev->vpaths[i]; |
| 2613 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2614 | /* set initial mtu before enabling the device */ |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2615 | status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2616 | if (status != VXGE_HW_OK) { |
| 2617 | vxge_debug_init(VXGE_ERR, |
| 2618 | "%s: fatal: can not set new MTU", dev->name); |
| 2619 | ret = -EPERM; |
| 2620 | goto out2; |
| 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev); |
| 2625 | vxge_debug_init(vdev->level_trace, |
| 2626 | "%s: MTU is %d", vdev->ndev->name, vdev->mtu); |
| 2627 | VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev); |
| 2628 | |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2629 | /* Restore the DA, VID table and also multicast and promiscuous mode |
| 2630 | * states |
| 2631 | */ |
| 2632 | if (vdev->all_multi_flg) { |
| 2633 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 2634 | vpath = &vdev->vpaths[i]; |
| 2635 | vxge_restore_vpath_mac_addr(vpath); |
| 2636 | vxge_restore_vpath_vid_table(vpath); |
| 2637 | |
| 2638 | status = vxge_hw_vpath_mcast_enable(vpath->handle); |
| 2639 | if (status != VXGE_HW_OK) |
| 2640 | vxge_debug_init(VXGE_ERR, |
| 2641 | "%s:%d Enabling multicast failed", |
| 2642 | __func__, __LINE__); |
| 2643 | } |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | /* Enable vpath to sniff all unicast/multicast traffic that not |
| 2647 | * addressed to them. We allow promiscous mode for PF only |
| 2648 | */ |
| 2649 | |
| 2650 | val64 = 0; |
| 2651 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) |
| 2652 | val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i); |
| 2653 | |
| 2654 | vxge_hw_mgmt_reg_write(vdev->devh, |
| 2655 | vxge_hw_mgmt_reg_type_mrpcim, |
| 2656 | 0, |
| 2657 | (ulong)offsetof(struct vxge_hw_mrpcim_reg, |
| 2658 | rxmac_authorize_all_addr), |
| 2659 | val64); |
| 2660 | |
| 2661 | vxge_hw_mgmt_reg_write(vdev->devh, |
| 2662 | vxge_hw_mgmt_reg_type_mrpcim, |
| 2663 | 0, |
| 2664 | (ulong)offsetof(struct vxge_hw_mrpcim_reg, |
| 2665 | rxmac_authorize_all_vid), |
| 2666 | val64); |
| 2667 | |
| 2668 | vxge_set_multicast(dev); |
| 2669 | |
| 2670 | /* Enabling Bcast and mcast for all vpath */ |
| 2671 | for (i = 0; i < vdev->no_of_vpath; i++) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2672 | vpath = &vdev->vpaths[i]; |
| 2673 | status = vxge_hw_vpath_bcast_enable(vpath->handle); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2674 | if (status != VXGE_HW_OK) |
| 2675 | vxge_debug_init(VXGE_ERR, |
| 2676 | "%s : Can not enable bcast for vpath " |
| 2677 | "id %d", dev->name, i); |
| 2678 | if (vdev->config.addr_learn_en) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2679 | status = vxge_hw_vpath_mcast_enable(vpath->handle); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2680 | if (status != VXGE_HW_OK) |
| 2681 | vxge_debug_init(VXGE_ERR, |
| 2682 | "%s : Can not enable mcast for vpath " |
| 2683 | "id %d", dev->name, i); |
| 2684 | } |
| 2685 | } |
| 2686 | |
| 2687 | vxge_hw_device_setpause_data(vdev->devh, 0, |
| 2688 | vdev->config.tx_pause_enable, |
| 2689 | vdev->config.rx_pause_enable); |
| 2690 | |
| 2691 | if (vdev->vp_reset_timer.function == NULL) |
| 2692 | vxge_os_timer(vdev->vp_reset_timer, |
| 2693 | vxge_poll_vp_reset, vdev, (HZ/2)); |
| 2694 | |
| 2695 | if (vdev->vp_lockup_timer.function == NULL) |
| 2696 | vxge_os_timer(vdev->vp_lockup_timer, |
| 2697 | vxge_poll_vp_lockup, vdev, (HZ/2)); |
| 2698 | |
| 2699 | set_bit(__VXGE_STATE_CARD_UP, &vdev->state); |
| 2700 | |
| 2701 | smp_wmb(); |
| 2702 | |
| 2703 | if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) { |
| 2704 | netif_carrier_on(vdev->ndev); |
Joe Perches | 75f5e1c | 2010-07-27 11:47:03 +0000 | [diff] [blame] | 2705 | netdev_notice(vdev->ndev, "Link Up\n"); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2706 | vdev->stats.link_up++; |
| 2707 | } |
| 2708 | |
| 2709 | vxge_hw_device_intr_enable(vdev->devh); |
| 2710 | |
| 2711 | smp_wmb(); |
| 2712 | |
| 2713 | for (i = 0; i < vdev->no_of_vpath; i++) { |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2714 | vpath = &vdev->vpaths[i]; |
| 2715 | |
| 2716 | vxge_hw_vpath_enable(vpath->handle); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2717 | smp_wmb(); |
Jon Mason | 7adf7d1 | 2010-07-15 08:47:24 +0000 | [diff] [blame] | 2718 | vxge_hw_vpath_rx_doorbell_init(vpath->handle); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 2721 | netif_tx_start_all_queues(vdev->ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2722 | goto out0; |
| 2723 | |
| 2724 | out2: |
| 2725 | vxge_rem_isr(vdev); |
| 2726 | |
| 2727 | /* Disable napi */ |
| 2728 | if (vdev->config.intr_type != MSI_X) |
| 2729 | napi_disable(&vdev->napi); |
| 2730 | else { |
| 2731 | for (i = 0; i < vdev->no_of_vpath; i++) |
| 2732 | napi_disable(&vdev->vpaths[i].ring.napi); |
| 2733 | } |
| 2734 | |
| 2735 | out1: |
| 2736 | vxge_close_vpaths(vdev, 0); |
| 2737 | out0: |
| 2738 | vxge_debug_entryexit(VXGE_TRACE, |
| 2739 | "%s: %s:%d Exiting...", |
| 2740 | dev->name, __func__, __LINE__); |
| 2741 | return ret; |
| 2742 | } |
| 2743 | |
| 2744 | /* Loop throught the mac address list and delete all the entries */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2745 | static void vxge_free_mac_add_list(struct vxge_vpath *vpath) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2746 | { |
| 2747 | |
| 2748 | struct list_head *entry, *next; |
| 2749 | if (list_empty(&vpath->mac_addr_list)) |
| 2750 | return; |
| 2751 | |
| 2752 | list_for_each_safe(entry, next, &vpath->mac_addr_list) { |
| 2753 | list_del(entry); |
| 2754 | kfree((struct vxge_mac_addrs *)entry); |
| 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | static void vxge_napi_del_all(struct vxgedev *vdev) |
| 2759 | { |
| 2760 | int i; |
| 2761 | if (vdev->config.intr_type != MSI_X) |
| 2762 | netif_napi_del(&vdev->napi); |
| 2763 | else { |
| 2764 | for (i = 0; i < vdev->no_of_vpath; i++) |
| 2765 | netif_napi_del(&vdev->vpaths[i].ring.napi); |
| 2766 | } |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2767 | } |
| 2768 | |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2769 | static int do_vxge_close(struct net_device *dev, int do_io) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2770 | { |
| 2771 | enum vxge_hw_status status; |
| 2772 | struct vxgedev *vdev; |
| 2773 | struct __vxge_hw_device *hldev; |
| 2774 | int i; |
| 2775 | u64 val64, vpath_vector; |
| 2776 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d", |
| 2777 | dev->name, __func__, __LINE__); |
| 2778 | |
| 2779 | vdev = (struct vxgedev *)netdev_priv(dev); |
| 2780 | hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev); |
| 2781 | |
Sreenivasa Honnur | bd9ee68 | 2009-07-01 21:14:03 +0000 | [diff] [blame] | 2782 | if (unlikely(!is_vxge_card_up(vdev))) |
| 2783 | return 0; |
| 2784 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2785 | /* If vxge_handle_crit_err task is executing, |
| 2786 | * wait till it completes. */ |
| 2787 | while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) |
| 2788 | msleep(50); |
| 2789 | |
| 2790 | clear_bit(__VXGE_STATE_CARD_UP, &vdev->state); |
| 2791 | if (do_io) { |
| 2792 | /* Put the vpath back in normal mode */ |
| 2793 | vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id); |
| 2794 | status = vxge_hw_mgmt_reg_read(vdev->devh, |
| 2795 | vxge_hw_mgmt_reg_type_mrpcim, |
| 2796 | 0, |
| 2797 | (ulong)offsetof( |
| 2798 | struct vxge_hw_mrpcim_reg, |
| 2799 | rts_mgr_cbasin_cfg), |
| 2800 | &val64); |
| 2801 | |
| 2802 | if (status == VXGE_HW_OK) { |
| 2803 | val64 &= ~vpath_vector; |
| 2804 | status = vxge_hw_mgmt_reg_write(vdev->devh, |
| 2805 | vxge_hw_mgmt_reg_type_mrpcim, |
| 2806 | 0, |
| 2807 | (ulong)offsetof( |
| 2808 | struct vxge_hw_mrpcim_reg, |
| 2809 | rts_mgr_cbasin_cfg), |
| 2810 | val64); |
| 2811 | } |
| 2812 | |
| 2813 | /* Remove the function 0 from promiscous mode */ |
| 2814 | vxge_hw_mgmt_reg_write(vdev->devh, |
| 2815 | vxge_hw_mgmt_reg_type_mrpcim, |
| 2816 | 0, |
| 2817 | (ulong)offsetof(struct vxge_hw_mrpcim_reg, |
| 2818 | rxmac_authorize_all_addr), |
| 2819 | 0); |
| 2820 | |
| 2821 | vxge_hw_mgmt_reg_write(vdev->devh, |
| 2822 | vxge_hw_mgmt_reg_type_mrpcim, |
| 2823 | 0, |
| 2824 | (ulong)offsetof(struct vxge_hw_mrpcim_reg, |
| 2825 | rxmac_authorize_all_vid), |
| 2826 | 0); |
| 2827 | |
| 2828 | smp_wmb(); |
| 2829 | } |
| 2830 | del_timer_sync(&vdev->vp_lockup_timer); |
| 2831 | |
| 2832 | del_timer_sync(&vdev->vp_reset_timer); |
| 2833 | |
| 2834 | /* Disable napi */ |
| 2835 | if (vdev->config.intr_type != MSI_X) |
| 2836 | napi_disable(&vdev->napi); |
| 2837 | else { |
| 2838 | for (i = 0; i < vdev->no_of_vpath; i++) |
| 2839 | napi_disable(&vdev->vpaths[i].ring.napi); |
| 2840 | } |
| 2841 | |
| 2842 | netif_carrier_off(vdev->ndev); |
Joe Perches | 75f5e1c | 2010-07-27 11:47:03 +0000 | [diff] [blame] | 2843 | netdev_notice(vdev->ndev, "Link Down\n"); |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 2844 | netif_tx_stop_all_queues(vdev->ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2845 | |
| 2846 | /* Note that at this point xmit() is stopped by upper layer */ |
| 2847 | if (do_io) |
| 2848 | vxge_hw_device_intr_disable(vdev->devh); |
| 2849 | |
| 2850 | mdelay(1000); |
| 2851 | |
| 2852 | vxge_rem_isr(vdev); |
| 2853 | |
| 2854 | vxge_napi_del_all(vdev); |
| 2855 | |
| 2856 | if (do_io) |
| 2857 | vxge_reset_all_vpaths(vdev); |
| 2858 | |
| 2859 | vxge_close_vpaths(vdev, 0); |
| 2860 | |
| 2861 | vxge_debug_entryexit(VXGE_TRACE, |
| 2862 | "%s: %s:%d Exiting...", dev->name, __func__, __LINE__); |
| 2863 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2864 | clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state); |
| 2865 | |
| 2866 | return 0; |
| 2867 | } |
| 2868 | |
| 2869 | /** |
| 2870 | * vxge_close |
| 2871 | * @dev: device pointer. |
| 2872 | * |
| 2873 | * This is the stop entry point of the driver. It needs to undo exactly |
| 2874 | * whatever was done by the open entry point, thus it's usually referred to |
| 2875 | * as the close function.Among other things this function mainly stops the |
| 2876 | * Rx side of the NIC and frees all the Rx buffers in the Rx rings. |
| 2877 | * Return value: '0' on success and an appropriate (-)ve integer as |
| 2878 | * defined in errno.h file on failure. |
| 2879 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2880 | static int |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2881 | vxge_close(struct net_device *dev) |
| 2882 | { |
| 2883 | do_vxge_close(dev, 1); |
| 2884 | return 0; |
| 2885 | } |
| 2886 | |
| 2887 | /** |
| 2888 | * vxge_change_mtu |
| 2889 | * @dev: net device pointer. |
| 2890 | * @new_mtu :the new MTU size for the device. |
| 2891 | * |
| 2892 | * A driver entry point to change MTU size for the device. Before changing |
| 2893 | * the MTU the device must be stopped. |
| 2894 | */ |
| 2895 | static int vxge_change_mtu(struct net_device *dev, int new_mtu) |
| 2896 | { |
| 2897 | struct vxgedev *vdev = netdev_priv(dev); |
| 2898 | |
| 2899 | vxge_debug_entryexit(vdev->level_trace, |
| 2900 | "%s:%d", __func__, __LINE__); |
| 2901 | if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) { |
| 2902 | vxge_debug_init(vdev->level_err, |
| 2903 | "%s: mtu size is invalid", dev->name); |
| 2904 | return -EPERM; |
| 2905 | } |
| 2906 | |
| 2907 | /* check if device is down already */ |
| 2908 | if (unlikely(!is_vxge_card_up(vdev))) { |
| 2909 | /* just store new value, will use later on open() */ |
| 2910 | dev->mtu = new_mtu; |
| 2911 | vxge_debug_init(vdev->level_err, |
| 2912 | "%s", "device is down on MTU change"); |
| 2913 | return 0; |
| 2914 | } |
| 2915 | |
| 2916 | vxge_debug_init(vdev->level_trace, |
| 2917 | "trying to apply new MTU %d", new_mtu); |
| 2918 | |
| 2919 | if (vxge_close(dev)) |
| 2920 | return -EIO; |
| 2921 | |
| 2922 | dev->mtu = new_mtu; |
| 2923 | vdev->mtu = new_mtu; |
| 2924 | |
| 2925 | if (vxge_open(dev)) |
| 2926 | return -EIO; |
| 2927 | |
| 2928 | vxge_debug_init(vdev->level_trace, |
| 2929 | "%s: MTU changed to %d", vdev->ndev->name, new_mtu); |
| 2930 | |
| 2931 | vxge_debug_entryexit(vdev->level_trace, |
| 2932 | "%s:%d Exiting...", __func__, __LINE__); |
| 2933 | |
| 2934 | return 0; |
| 2935 | } |
| 2936 | |
| 2937 | /** |
Eric Dumazet | dd57f97 | 2010-08-18 03:42:54 +0000 | [diff] [blame] | 2938 | * vxge_get_stats64 |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2939 | * @dev: pointer to the device structure |
Eric Dumazet | dd57f97 | 2010-08-18 03:42:54 +0000 | [diff] [blame] | 2940 | * @stats: pointer to struct rtnl_link_stats64 |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2941 | * |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2942 | */ |
Eric Dumazet | dd57f97 | 2010-08-18 03:42:54 +0000 | [diff] [blame] | 2943 | static struct rtnl_link_stats64 * |
| 2944 | vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2945 | { |
Eric Dumazet | dd57f97 | 2010-08-18 03:42:54 +0000 | [diff] [blame] | 2946 | struct vxgedev *vdev = netdev_priv(dev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2947 | int k; |
| 2948 | |
Eric Dumazet | dd57f97 | 2010-08-18 03:42:54 +0000 | [diff] [blame] | 2949 | /* net_stats already zeroed by caller */ |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 2950 | for (k = 0; k < vdev->no_of_vpath; k++) { |
| 2951 | net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms; |
| 2952 | net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes; |
| 2953 | net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors; |
| 2954 | net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast; |
| 2955 | net_stats->rx_dropped += |
| 2956 | vdev->vpaths[k].ring.stats.rx_dropped; |
| 2957 | |
| 2958 | net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms; |
| 2959 | net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes; |
| 2960 | net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors; |
| 2961 | } |
| 2962 | |
| 2963 | return net_stats; |
| 2964 | } |
| 2965 | |
| 2966 | /** |
| 2967 | * vxge_ioctl |
| 2968 | * @dev: Device pointer. |
| 2969 | * @ifr: An IOCTL specific structure, that can contain a pointer to |
| 2970 | * a proprietary structure used to pass information to the driver. |
| 2971 | * @cmd: This is used to distinguish between the different commands that |
| 2972 | * can be passed to the IOCTL functions. |
| 2973 | * |
| 2974 | * Entry point for the Ioctl. |
| 2975 | */ |
| 2976 | static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 2977 | { |
| 2978 | return -EOPNOTSUPP; |
| 2979 | } |
| 2980 | |
| 2981 | /** |
| 2982 | * vxge_tx_watchdog |
| 2983 | * @dev: pointer to net device structure |
| 2984 | * |
| 2985 | * Watchdog for transmit side. |
| 2986 | * This function is triggered if the Tx Queue is stopped |
| 2987 | * for a pre-defined amount of time when the Interface is still up. |
| 2988 | */ |
| 2989 | static void |
| 2990 | vxge_tx_watchdog(struct net_device *dev) |
| 2991 | { |
| 2992 | struct vxgedev *vdev; |
| 2993 | |
| 2994 | vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__); |
| 2995 | |
| 2996 | vdev = (struct vxgedev *)netdev_priv(dev); |
| 2997 | |
| 2998 | vdev->cric_err_event = VXGE_HW_EVENT_RESET_START; |
| 2999 | |
| 3000 | vxge_reset(vdev); |
| 3001 | vxge_debug_entryexit(VXGE_TRACE, |
| 3002 | "%s:%d Exiting...", __func__, __LINE__); |
| 3003 | } |
| 3004 | |
| 3005 | /** |
| 3006 | * vxge_vlan_rx_register |
| 3007 | * @dev: net device pointer. |
| 3008 | * @grp: vlan group |
| 3009 | * |
| 3010 | * Vlan group registration |
| 3011 | */ |
| 3012 | static void |
| 3013 | vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) |
| 3014 | { |
| 3015 | struct vxgedev *vdev; |
| 3016 | struct vxge_vpath *vpath; |
| 3017 | int vp; |
| 3018 | u64 vid; |
| 3019 | enum vxge_hw_status status; |
| 3020 | int i; |
| 3021 | |
| 3022 | vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__); |
| 3023 | |
| 3024 | vdev = (struct vxgedev *)netdev_priv(dev); |
| 3025 | |
| 3026 | vpath = &vdev->vpaths[0]; |
| 3027 | if ((NULL == grp) && (vpath->is_open)) { |
| 3028 | /* Get the first vlan */ |
| 3029 | status = vxge_hw_vpath_vid_get(vpath->handle, &vid); |
| 3030 | |
| 3031 | while (status == VXGE_HW_OK) { |
| 3032 | |
| 3033 | /* Delete this vlan from the vid table */ |
| 3034 | for (vp = 0; vp < vdev->no_of_vpath; vp++) { |
| 3035 | vpath = &vdev->vpaths[vp]; |
| 3036 | if (!vpath->is_open) |
| 3037 | continue; |
| 3038 | |
| 3039 | vxge_hw_vpath_vid_delete(vpath->handle, vid); |
| 3040 | } |
| 3041 | |
| 3042 | /* Get the next vlan to be deleted */ |
| 3043 | vpath = &vdev->vpaths[0]; |
| 3044 | status = vxge_hw_vpath_vid_get(vpath->handle, &vid); |
| 3045 | } |
| 3046 | } |
| 3047 | |
| 3048 | vdev->vlgrp = grp; |
| 3049 | |
| 3050 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 3051 | if (vdev->vpaths[i].is_configured) |
| 3052 | vdev->vpaths[i].ring.vlgrp = grp; |
| 3053 | } |
| 3054 | |
| 3055 | vxge_debug_entryexit(VXGE_TRACE, |
| 3056 | "%s:%d Exiting...", __func__, __LINE__); |
| 3057 | } |
| 3058 | |
| 3059 | /** |
| 3060 | * vxge_vlan_rx_add_vid |
| 3061 | * @dev: net device pointer. |
| 3062 | * @vid: vid |
| 3063 | * |
| 3064 | * Add the vlan id to the devices vlan id table |
| 3065 | */ |
| 3066 | static void |
| 3067 | vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) |
| 3068 | { |
| 3069 | struct vxgedev *vdev; |
| 3070 | struct vxge_vpath *vpath; |
| 3071 | int vp_id; |
| 3072 | |
| 3073 | vdev = (struct vxgedev *)netdev_priv(dev); |
| 3074 | |
| 3075 | /* Add these vlan to the vid table */ |
| 3076 | for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) { |
| 3077 | vpath = &vdev->vpaths[vp_id]; |
| 3078 | if (!vpath->is_open) |
| 3079 | continue; |
| 3080 | vxge_hw_vpath_vid_add(vpath->handle, vid); |
| 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | /** |
| 3085 | * vxge_vlan_rx_add_vid |
| 3086 | * @dev: net device pointer. |
| 3087 | * @vid: vid |
| 3088 | * |
| 3089 | * Remove the vlan id from the device's vlan id table |
| 3090 | */ |
| 3091 | static void |
| 3092 | vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) |
| 3093 | { |
| 3094 | struct vxgedev *vdev; |
| 3095 | struct vxge_vpath *vpath; |
| 3096 | int vp_id; |
| 3097 | |
| 3098 | vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__); |
| 3099 | |
| 3100 | vdev = (struct vxgedev *)netdev_priv(dev); |
| 3101 | |
| 3102 | vlan_group_set_device(vdev->vlgrp, vid, NULL); |
| 3103 | |
| 3104 | /* Delete this vlan from the vid table */ |
| 3105 | for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) { |
| 3106 | vpath = &vdev->vpaths[vp_id]; |
| 3107 | if (!vpath->is_open) |
| 3108 | continue; |
| 3109 | vxge_hw_vpath_vid_delete(vpath->handle, vid); |
| 3110 | } |
| 3111 | vxge_debug_entryexit(VXGE_TRACE, |
| 3112 | "%s:%d Exiting...", __func__, __LINE__); |
| 3113 | } |
| 3114 | |
| 3115 | static const struct net_device_ops vxge_netdev_ops = { |
| 3116 | .ndo_open = vxge_open, |
| 3117 | .ndo_stop = vxge_close, |
Eric Dumazet | dd57f97 | 2010-08-18 03:42:54 +0000 | [diff] [blame] | 3118 | .ndo_get_stats64 = vxge_get_stats64, |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3119 | .ndo_start_xmit = vxge_xmit, |
| 3120 | .ndo_validate_addr = eth_validate_addr, |
| 3121 | .ndo_set_multicast_list = vxge_set_multicast, |
| 3122 | |
| 3123 | .ndo_do_ioctl = vxge_ioctl, |
| 3124 | |
| 3125 | .ndo_set_mac_address = vxge_set_mac_addr, |
| 3126 | .ndo_change_mtu = vxge_change_mtu, |
| 3127 | .ndo_vlan_rx_register = vxge_vlan_rx_register, |
| 3128 | .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid, |
| 3129 | .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid, |
| 3130 | |
| 3131 | .ndo_tx_timeout = vxge_tx_watchdog, |
| 3132 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3133 | .ndo_poll_controller = vxge_netpoll, |
| 3134 | #endif |
| 3135 | }; |
| 3136 | |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3137 | static int __devinit vxge_device_register(struct __vxge_hw_device *hldev, |
| 3138 | struct vxge_config *config, |
| 3139 | int high_dma, int no_of_vpath, |
| 3140 | struct vxgedev **vdev_out) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3141 | { |
| 3142 | struct net_device *ndev; |
| 3143 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3144 | struct vxgedev *vdev; |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 3145 | int ret = 0, no_of_queue = 1; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3146 | u64 stat; |
| 3147 | |
| 3148 | *vdev_out = NULL; |
Jon Mason | d03848e | 2010-07-15 08:47:23 +0000 | [diff] [blame] | 3149 | if (config->tx_steering_type) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3150 | no_of_queue = no_of_vpath; |
| 3151 | |
| 3152 | ndev = alloc_etherdev_mq(sizeof(struct vxgedev), |
| 3153 | no_of_queue); |
| 3154 | if (ndev == NULL) { |
| 3155 | vxge_debug_init( |
| 3156 | vxge_hw_device_trace_level_get(hldev), |
| 3157 | "%s : device allocation failed", __func__); |
| 3158 | ret = -ENODEV; |
| 3159 | goto _out0; |
| 3160 | } |
| 3161 | |
| 3162 | vxge_debug_entryexit( |
| 3163 | vxge_hw_device_trace_level_get(hldev), |
| 3164 | "%s: %s:%d Entering...", |
| 3165 | ndev->name, __func__, __LINE__); |
| 3166 | |
| 3167 | vdev = netdev_priv(ndev); |
| 3168 | memset(vdev, 0, sizeof(struct vxgedev)); |
| 3169 | |
| 3170 | vdev->ndev = ndev; |
| 3171 | vdev->devh = hldev; |
| 3172 | vdev->pdev = hldev->pdev; |
| 3173 | memcpy(&vdev->config, config, sizeof(struct vxge_config)); |
| 3174 | vdev->rx_csum = 1; /* Enable Rx CSUM by default. */ |
| 3175 | |
| 3176 | SET_NETDEV_DEV(ndev, &vdev->pdev->dev); |
| 3177 | |
| 3178 | ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | |
| 3179 | NETIF_F_HW_VLAN_FILTER; |
| 3180 | /* Driver entry points */ |
| 3181 | ndev->irq = vdev->pdev->irq; |
| 3182 | ndev->base_addr = (unsigned long) hldev->bar0; |
| 3183 | |
| 3184 | ndev->netdev_ops = &vxge_netdev_ops; |
| 3185 | |
| 3186 | ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT; |
| 3187 | |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3188 | vxge_initialize_ethtool_ops(ndev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3189 | |
Jon Mason | 47f01db | 2010-11-11 04:25:53 +0000 | [diff] [blame^] | 3190 | if (vdev->config.rth_steering != NO_STEERING) { |
| 3191 | ndev->features |= NETIF_F_RXHASH; |
| 3192 | hldev->config.rth_en = VXGE_HW_RTH_ENABLE; |
| 3193 | } |
| 3194 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3195 | /* Allocate memory for vpath */ |
| 3196 | vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) * |
| 3197 | no_of_vpath, GFP_KERNEL); |
| 3198 | if (!vdev->vpaths) { |
| 3199 | vxge_debug_init(VXGE_ERR, |
| 3200 | "%s: vpath memory allocation failed", |
| 3201 | vdev->ndev->name); |
| 3202 | ret = -ENODEV; |
| 3203 | goto _out1; |
| 3204 | } |
| 3205 | |
| 3206 | ndev->features |= NETIF_F_SG; |
| 3207 | |
| 3208 | ndev->features |= NETIF_F_HW_CSUM; |
| 3209 | vxge_debug_init(vxge_hw_device_trace_level_get(hldev), |
| 3210 | "%s : checksuming enabled", __func__); |
| 3211 | |
| 3212 | if (high_dma) { |
| 3213 | ndev->features |= NETIF_F_HIGHDMA; |
| 3214 | vxge_debug_init(vxge_hw_device_trace_level_get(hldev), |
| 3215 | "%s : using High DMA", __func__); |
| 3216 | } |
| 3217 | |
| 3218 | ndev->features |= NETIF_F_TSO | NETIF_F_TSO6; |
| 3219 | |
| 3220 | if (vdev->config.gro_enable) |
| 3221 | ndev->features |= NETIF_F_GRO; |
| 3222 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3223 | if (register_netdev(ndev)) { |
| 3224 | vxge_debug_init(vxge_hw_device_trace_level_get(hldev), |
| 3225 | "%s: %s : device registration failed!", |
| 3226 | ndev->name, __func__); |
| 3227 | ret = -ENODEV; |
| 3228 | goto _out2; |
| 3229 | } |
| 3230 | |
| 3231 | /* Set the factory defined MAC address initially */ |
| 3232 | ndev->addr_len = ETH_ALEN; |
| 3233 | |
| 3234 | /* Make Link state as off at this point, when the Link change |
| 3235 | * interrupt comes the state will be automatically changed to |
| 3236 | * the right state. |
| 3237 | */ |
| 3238 | netif_carrier_off(ndev); |
| 3239 | |
| 3240 | vxge_debug_init(vxge_hw_device_trace_level_get(hldev), |
| 3241 | "%s: Ethernet device registered", |
| 3242 | ndev->name); |
| 3243 | |
| 3244 | *vdev_out = vdev; |
| 3245 | |
| 3246 | /* Resetting the Device stats */ |
| 3247 | status = vxge_hw_mrpcim_stats_access( |
| 3248 | hldev, |
| 3249 | VXGE_HW_STATS_OP_CLEAR_ALL_STATS, |
| 3250 | 0, |
| 3251 | 0, |
| 3252 | &stat); |
| 3253 | |
| 3254 | if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION) |
| 3255 | vxge_debug_init( |
| 3256 | vxge_hw_device_trace_level_get(hldev), |
| 3257 | "%s: device stats clear returns" |
| 3258 | "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name); |
| 3259 | |
| 3260 | vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev), |
| 3261 | "%s: %s:%d Exiting...", |
| 3262 | ndev->name, __func__, __LINE__); |
| 3263 | |
| 3264 | return ret; |
| 3265 | _out2: |
| 3266 | kfree(vdev->vpaths); |
| 3267 | _out1: |
| 3268 | free_netdev(ndev); |
| 3269 | _out0: |
| 3270 | return ret; |
| 3271 | } |
| 3272 | |
| 3273 | /* |
| 3274 | * vxge_device_unregister |
| 3275 | * |
| 3276 | * This function will unregister and free network device |
| 3277 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3278 | static void |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3279 | vxge_device_unregister(struct __vxge_hw_device *hldev) |
| 3280 | { |
| 3281 | struct vxgedev *vdev; |
| 3282 | struct net_device *dev; |
| 3283 | char buf[IFNAMSIZ]; |
| 3284 | #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \ |
| 3285 | (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK)) |
| 3286 | u32 level_trace; |
| 3287 | #endif |
| 3288 | |
| 3289 | dev = hldev->ndev; |
| 3290 | vdev = netdev_priv(dev); |
| 3291 | #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \ |
| 3292 | (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK)) |
| 3293 | level_trace = vdev->level_trace; |
| 3294 | #endif |
| 3295 | vxge_debug_entryexit(level_trace, |
| 3296 | "%s: %s:%d", vdev->ndev->name, __func__, __LINE__); |
| 3297 | |
| 3298 | memcpy(buf, vdev->ndev->name, IFNAMSIZ); |
| 3299 | |
| 3300 | /* in 2.6 will call stop() if device is up */ |
| 3301 | unregister_netdev(dev); |
| 3302 | |
| 3303 | flush_scheduled_work(); |
| 3304 | |
| 3305 | vxge_debug_init(level_trace, "%s: ethernet device unregistered", buf); |
| 3306 | vxge_debug_entryexit(level_trace, |
| 3307 | "%s: %s:%d Exiting...", buf, __func__, __LINE__); |
| 3308 | } |
| 3309 | |
| 3310 | /* |
| 3311 | * vxge_callback_crit_err |
| 3312 | * |
| 3313 | * This function is called by the alarm handler in interrupt context. |
| 3314 | * Driver must analyze it based on the event type. |
| 3315 | */ |
| 3316 | static void |
| 3317 | vxge_callback_crit_err(struct __vxge_hw_device *hldev, |
| 3318 | enum vxge_hw_event type, u64 vp_id) |
| 3319 | { |
| 3320 | struct net_device *dev = hldev->ndev; |
| 3321 | struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev); |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 3322 | struct vxge_vpath *vpath = NULL; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3323 | int vpath_idx; |
| 3324 | |
| 3325 | vxge_debug_entryexit(vdev->level_trace, |
| 3326 | "%s: %s:%d", vdev->ndev->name, __func__, __LINE__); |
| 3327 | |
| 3328 | /* Note: This event type should be used for device wide |
| 3329 | * indications only - Serious errors, Slot freeze and critical errors |
| 3330 | */ |
| 3331 | vdev->cric_err_event = type; |
| 3332 | |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 3333 | for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) { |
| 3334 | vpath = &vdev->vpaths[vpath_idx]; |
| 3335 | if (vpath->device_id == vp_id) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3336 | break; |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 3337 | } |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3338 | |
| 3339 | if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) { |
| 3340 | if (type == VXGE_HW_EVENT_SLOT_FREEZE) { |
| 3341 | vxge_debug_init(VXGE_ERR, |
| 3342 | "%s: Slot is frozen", vdev->ndev->name); |
| 3343 | } else if (type == VXGE_HW_EVENT_SERR) { |
| 3344 | vxge_debug_init(VXGE_ERR, |
| 3345 | "%s: Encountered Serious Error", |
| 3346 | vdev->ndev->name); |
| 3347 | } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) |
| 3348 | vxge_debug_init(VXGE_ERR, |
| 3349 | "%s: Encountered Critical Error", |
| 3350 | vdev->ndev->name); |
| 3351 | } |
| 3352 | |
| 3353 | if ((type == VXGE_HW_EVENT_SERR) || |
| 3354 | (type == VXGE_HW_EVENT_SLOT_FREEZE)) { |
| 3355 | if (unlikely(vdev->exec_mode)) |
| 3356 | clear_bit(__VXGE_STATE_CARD_UP, &vdev->state); |
| 3357 | } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) { |
| 3358 | vxge_hw_device_mask_all(hldev); |
| 3359 | if (unlikely(vdev->exec_mode)) |
| 3360 | clear_bit(__VXGE_STATE_CARD_UP, &vdev->state); |
| 3361 | } else if ((type == VXGE_HW_EVENT_FIFO_ERR) || |
| 3362 | (type == VXGE_HW_EVENT_VPATH_ERR)) { |
| 3363 | |
| 3364 | if (unlikely(vdev->exec_mode)) |
| 3365 | clear_bit(__VXGE_STATE_CARD_UP, &vdev->state); |
| 3366 | else { |
| 3367 | /* check if this vpath is already set for reset */ |
| 3368 | if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) { |
| 3369 | |
| 3370 | /* disable interrupts for this vpath */ |
| 3371 | vxge_vpath_intr_disable(vdev, vpath_idx); |
| 3372 | |
| 3373 | /* stop the queue for this vpath */ |
Jon Mason | 98f45da | 2010-07-15 08:47:25 +0000 | [diff] [blame] | 3374 | netif_tx_stop_queue(vpath->fifo.txq); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3375 | } |
| 3376 | } |
| 3377 | } |
| 3378 | |
| 3379 | vxge_debug_entryexit(vdev->level_trace, |
| 3380 | "%s: %s:%d Exiting...", |
| 3381 | vdev->ndev->name, __func__, __LINE__); |
| 3382 | } |
| 3383 | |
| 3384 | static void verify_bandwidth(void) |
| 3385 | { |
| 3386 | int i, band_width, total = 0, equal_priority = 0; |
| 3387 | |
| 3388 | /* 1. If user enters 0 for some fifo, give equal priority to all */ |
| 3389 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 3390 | if (bw_percentage[i] == 0) { |
| 3391 | equal_priority = 1; |
| 3392 | break; |
| 3393 | } |
| 3394 | } |
| 3395 | |
| 3396 | if (!equal_priority) { |
| 3397 | /* 2. If sum exceeds 100, give equal priority to all */ |
| 3398 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 3399 | if (bw_percentage[i] == 0xFF) |
| 3400 | break; |
| 3401 | |
| 3402 | total += bw_percentage[i]; |
| 3403 | if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) { |
| 3404 | equal_priority = 1; |
| 3405 | break; |
| 3406 | } |
| 3407 | } |
| 3408 | } |
| 3409 | |
| 3410 | if (!equal_priority) { |
| 3411 | /* Is all the bandwidth consumed? */ |
| 3412 | if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) { |
| 3413 | if (i < VXGE_HW_MAX_VIRTUAL_PATHS) { |
| 3414 | /* Split rest of bw equally among next VPs*/ |
| 3415 | band_width = |
| 3416 | (VXGE_HW_VPATH_BANDWIDTH_MAX - total) / |
| 3417 | (VXGE_HW_MAX_VIRTUAL_PATHS - i); |
| 3418 | if (band_width < 2) /* min of 2% */ |
| 3419 | equal_priority = 1; |
| 3420 | else { |
| 3421 | for (; i < VXGE_HW_MAX_VIRTUAL_PATHS; |
| 3422 | i++) |
| 3423 | bw_percentage[i] = |
| 3424 | band_width; |
| 3425 | } |
| 3426 | } |
| 3427 | } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS) |
| 3428 | equal_priority = 1; |
| 3429 | } |
| 3430 | |
| 3431 | if (equal_priority) { |
| 3432 | vxge_debug_init(VXGE_ERR, |
| 3433 | "%s: Assigning equal bandwidth to all the vpaths", |
| 3434 | VXGE_DRIVER_NAME); |
| 3435 | bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX / |
| 3436 | VXGE_HW_MAX_VIRTUAL_PATHS; |
| 3437 | for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) |
| 3438 | bw_percentage[i] = bw_percentage[0]; |
| 3439 | } |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | /* |
| 3443 | * Vpath configuration |
| 3444 | */ |
| 3445 | static int __devinit vxge_config_vpaths( |
| 3446 | struct vxge_hw_device_config *device_config, |
| 3447 | u64 vpath_mask, struct vxge_config *config_param) |
| 3448 | { |
| 3449 | int i, no_of_vpaths = 0, default_no_vpath = 0, temp; |
| 3450 | u32 txdl_size, txdl_per_memblock; |
| 3451 | |
| 3452 | temp = driver_config->vpath_per_dev; |
| 3453 | if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) && |
| 3454 | (max_config_dev == VXGE_MAX_CONFIG_DEV)) { |
| 3455 | /* No more CPU. Return vpath number as zero.*/ |
| 3456 | if (driver_config->g_no_cpus == -1) |
| 3457 | return 0; |
| 3458 | |
| 3459 | if (!driver_config->g_no_cpus) |
| 3460 | driver_config->g_no_cpus = num_online_cpus(); |
| 3461 | |
| 3462 | driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1; |
| 3463 | if (!driver_config->vpath_per_dev) |
| 3464 | driver_config->vpath_per_dev = 1; |
| 3465 | |
| 3466 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) |
| 3467 | if (!vxge_bVALn(vpath_mask, i, 1)) |
| 3468 | continue; |
| 3469 | else |
| 3470 | default_no_vpath++; |
| 3471 | if (default_no_vpath < driver_config->vpath_per_dev) |
| 3472 | driver_config->vpath_per_dev = default_no_vpath; |
| 3473 | |
| 3474 | driver_config->g_no_cpus = driver_config->g_no_cpus - |
| 3475 | (driver_config->vpath_per_dev * 2); |
| 3476 | if (driver_config->g_no_cpus <= 0) |
| 3477 | driver_config->g_no_cpus = -1; |
| 3478 | } |
| 3479 | |
| 3480 | if (driver_config->vpath_per_dev == 1) { |
| 3481 | vxge_debug_ll_config(VXGE_TRACE, |
| 3482 | "%s: Disable tx and rx steering, " |
| 3483 | "as single vpath is configured", VXGE_DRIVER_NAME); |
| 3484 | config_param->rth_steering = NO_STEERING; |
| 3485 | config_param->tx_steering_type = NO_STEERING; |
| 3486 | device_config->rth_en = 0; |
| 3487 | } |
| 3488 | |
| 3489 | /* configure bandwidth */ |
| 3490 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) |
| 3491 | device_config->vp_config[i].min_bandwidth = bw_percentage[i]; |
| 3492 | |
| 3493 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 3494 | device_config->vp_config[i].vp_id = i; |
| 3495 | device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU; |
| 3496 | if (no_of_vpaths < driver_config->vpath_per_dev) { |
| 3497 | if (!vxge_bVALn(vpath_mask, i, 1)) { |
| 3498 | vxge_debug_ll_config(VXGE_TRACE, |
| 3499 | "%s: vpath: %d is not available", |
| 3500 | VXGE_DRIVER_NAME, i); |
| 3501 | continue; |
| 3502 | } else { |
| 3503 | vxge_debug_ll_config(VXGE_TRACE, |
| 3504 | "%s: vpath: %d available", |
| 3505 | VXGE_DRIVER_NAME, i); |
| 3506 | no_of_vpaths++; |
| 3507 | } |
| 3508 | } else { |
| 3509 | vxge_debug_ll_config(VXGE_TRACE, |
| 3510 | "%s: vpath: %d is not configured, " |
| 3511 | "max_config_vpath exceeded", |
| 3512 | VXGE_DRIVER_NAME, i); |
| 3513 | break; |
| 3514 | } |
| 3515 | |
| 3516 | /* Configure Tx fifo's */ |
| 3517 | device_config->vp_config[i].fifo.enable = |
| 3518 | VXGE_HW_FIFO_ENABLE; |
| 3519 | device_config->vp_config[i].fifo.max_frags = |
Sreenivasa Honnur | 5beefb4 | 2009-10-28 02:46:54 -0700 | [diff] [blame] | 3520 | MAX_SKB_FRAGS + 1; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3521 | device_config->vp_config[i].fifo.memblock_size = |
| 3522 | VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE; |
| 3523 | |
Sreenivasa Honnur | 5beefb4 | 2009-10-28 02:46:54 -0700 | [diff] [blame] | 3524 | txdl_size = device_config->vp_config[i].fifo.max_frags * |
| 3525 | sizeof(struct vxge_hw_fifo_txd); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3526 | txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size; |
| 3527 | |
| 3528 | device_config->vp_config[i].fifo.fifo_blocks = |
| 3529 | ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1; |
| 3530 | |
| 3531 | device_config->vp_config[i].fifo.intr = |
| 3532 | VXGE_HW_FIFO_QUEUE_INTR_DISABLE; |
| 3533 | |
| 3534 | /* Configure tti properties */ |
| 3535 | device_config->vp_config[i].tti.intr_enable = |
| 3536 | VXGE_HW_TIM_INTR_ENABLE; |
| 3537 | |
| 3538 | device_config->vp_config[i].tti.btimer_val = |
| 3539 | (VXGE_TTI_BTIMER_VAL * 1000) / 272; |
| 3540 | |
| 3541 | device_config->vp_config[i].tti.timer_ac_en = |
| 3542 | VXGE_HW_TIM_TIMER_AC_ENABLE; |
| 3543 | |
| 3544 | /* For msi-x with napi (each vector |
| 3545 | has a handler of its own) - |
| 3546 | Set CI to OFF for all vpaths */ |
| 3547 | device_config->vp_config[i].tti.timer_ci_en = |
| 3548 | VXGE_HW_TIM_TIMER_CI_DISABLE; |
| 3549 | |
| 3550 | device_config->vp_config[i].tti.timer_ri_en = |
| 3551 | VXGE_HW_TIM_TIMER_RI_DISABLE; |
| 3552 | |
| 3553 | device_config->vp_config[i].tti.util_sel = |
| 3554 | VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL; |
| 3555 | |
| 3556 | device_config->vp_config[i].tti.ltimer_val = |
| 3557 | (VXGE_TTI_LTIMER_VAL * 1000) / 272; |
| 3558 | |
| 3559 | device_config->vp_config[i].tti.rtimer_val = |
| 3560 | (VXGE_TTI_RTIMER_VAL * 1000) / 272; |
| 3561 | |
| 3562 | device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A; |
| 3563 | device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B; |
| 3564 | device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C; |
| 3565 | device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A; |
| 3566 | device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B; |
| 3567 | device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C; |
| 3568 | device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D; |
| 3569 | |
| 3570 | /* Configure Rx rings */ |
| 3571 | device_config->vp_config[i].ring.enable = |
| 3572 | VXGE_HW_RING_ENABLE; |
| 3573 | |
| 3574 | device_config->vp_config[i].ring.ring_blocks = |
| 3575 | VXGE_HW_DEF_RING_BLOCKS; |
| 3576 | device_config->vp_config[i].ring.buffer_mode = |
| 3577 | VXGE_HW_RING_RXD_BUFFER_MODE_1; |
| 3578 | device_config->vp_config[i].ring.rxds_limit = |
| 3579 | VXGE_HW_DEF_RING_RXDS_LIMIT; |
| 3580 | device_config->vp_config[i].ring.scatter_mode = |
| 3581 | VXGE_HW_RING_SCATTER_MODE_A; |
| 3582 | |
| 3583 | /* Configure rti properties */ |
| 3584 | device_config->vp_config[i].rti.intr_enable = |
| 3585 | VXGE_HW_TIM_INTR_ENABLE; |
| 3586 | |
| 3587 | device_config->vp_config[i].rti.btimer_val = |
| 3588 | (VXGE_RTI_BTIMER_VAL * 1000)/272; |
| 3589 | |
| 3590 | device_config->vp_config[i].rti.timer_ac_en = |
| 3591 | VXGE_HW_TIM_TIMER_AC_ENABLE; |
| 3592 | |
| 3593 | device_config->vp_config[i].rti.timer_ci_en = |
| 3594 | VXGE_HW_TIM_TIMER_CI_DISABLE; |
| 3595 | |
| 3596 | device_config->vp_config[i].rti.timer_ri_en = |
| 3597 | VXGE_HW_TIM_TIMER_RI_DISABLE; |
| 3598 | |
| 3599 | device_config->vp_config[i].rti.util_sel = |
| 3600 | VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL; |
| 3601 | |
| 3602 | device_config->vp_config[i].rti.urange_a = |
| 3603 | RTI_RX_URANGE_A; |
| 3604 | device_config->vp_config[i].rti.urange_b = |
| 3605 | RTI_RX_URANGE_B; |
| 3606 | device_config->vp_config[i].rti.urange_c = |
| 3607 | RTI_RX_URANGE_C; |
| 3608 | device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A; |
| 3609 | device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B; |
| 3610 | device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C; |
| 3611 | device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D; |
| 3612 | |
| 3613 | device_config->vp_config[i].rti.rtimer_val = |
| 3614 | (VXGE_RTI_RTIMER_VAL * 1000) / 272; |
| 3615 | |
| 3616 | device_config->vp_config[i].rti.ltimer_val = |
| 3617 | (VXGE_RTI_LTIMER_VAL * 1000) / 272; |
| 3618 | |
| 3619 | device_config->vp_config[i].rpa_strip_vlan_tag = |
| 3620 | vlan_tag_strip; |
| 3621 | } |
| 3622 | |
| 3623 | driver_config->vpath_per_dev = temp; |
| 3624 | return no_of_vpaths; |
| 3625 | } |
| 3626 | |
| 3627 | /* initialize device configuratrions */ |
| 3628 | static void __devinit vxge_device_config_init( |
| 3629 | struct vxge_hw_device_config *device_config, |
| 3630 | int *intr_type) |
| 3631 | { |
| 3632 | /* Used for CQRQ/SRQ. */ |
| 3633 | device_config->dma_blockpool_initial = |
| 3634 | VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE; |
| 3635 | |
| 3636 | device_config->dma_blockpool_max = |
| 3637 | VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE; |
| 3638 | |
| 3639 | if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT) |
| 3640 | max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT; |
| 3641 | |
| 3642 | #ifndef CONFIG_PCI_MSI |
| 3643 | vxge_debug_init(VXGE_ERR, |
| 3644 | "%s: This Kernel does not support " |
| 3645 | "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME); |
| 3646 | *intr_type = INTA; |
| 3647 | #endif |
| 3648 | |
| 3649 | /* Configure whether MSI-X or IRQL. */ |
| 3650 | switch (*intr_type) { |
| 3651 | case INTA: |
| 3652 | device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE; |
| 3653 | break; |
| 3654 | |
| 3655 | case MSI_X: |
| 3656 | device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX; |
| 3657 | break; |
| 3658 | } |
| 3659 | /* Timer period between device poll */ |
| 3660 | device_config->device_poll_millis = VXGE_TIMER_DELAY; |
| 3661 | |
| 3662 | /* Configure mac based steering. */ |
| 3663 | device_config->rts_mac_en = addr_learn_en; |
| 3664 | |
| 3665 | /* Configure Vpaths */ |
| 3666 | device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT; |
| 3667 | |
| 3668 | vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ", |
| 3669 | __func__); |
| 3670 | vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_initial : %d", |
| 3671 | device_config->dma_blockpool_initial); |
| 3672 | vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_max : %d", |
| 3673 | device_config->dma_blockpool_max); |
| 3674 | vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d", |
| 3675 | device_config->intr_mode); |
| 3676 | vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d", |
| 3677 | device_config->device_poll_millis); |
| 3678 | vxge_debug_ll_config(VXGE_TRACE, "rts_mac_en : %d", |
| 3679 | device_config->rts_mac_en); |
| 3680 | vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d", |
| 3681 | device_config->rth_en); |
| 3682 | vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d", |
| 3683 | device_config->rth_it_type); |
| 3684 | } |
| 3685 | |
| 3686 | static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask) |
| 3687 | { |
| 3688 | int i; |
| 3689 | |
| 3690 | vxge_debug_init(VXGE_TRACE, |
| 3691 | "%s: %d Vpath(s) opened", |
| 3692 | vdev->ndev->name, vdev->no_of_vpath); |
| 3693 | |
| 3694 | switch (vdev->config.intr_type) { |
| 3695 | case INTA: |
| 3696 | vxge_debug_init(VXGE_TRACE, |
| 3697 | "%s: Interrupt type INTA", vdev->ndev->name); |
| 3698 | break; |
| 3699 | |
| 3700 | case MSI_X: |
| 3701 | vxge_debug_init(VXGE_TRACE, |
| 3702 | "%s: Interrupt type MSI-X", vdev->ndev->name); |
| 3703 | break; |
| 3704 | } |
| 3705 | |
| 3706 | if (vdev->config.rth_steering) { |
| 3707 | vxge_debug_init(VXGE_TRACE, |
| 3708 | "%s: RTH steering enabled for TCP_IPV4", |
| 3709 | vdev->ndev->name); |
| 3710 | } else { |
| 3711 | vxge_debug_init(VXGE_TRACE, |
| 3712 | "%s: RTH steering disabled", vdev->ndev->name); |
| 3713 | } |
| 3714 | |
| 3715 | switch (vdev->config.tx_steering_type) { |
| 3716 | case NO_STEERING: |
| 3717 | vxge_debug_init(VXGE_TRACE, |
| 3718 | "%s: Tx steering disabled", vdev->ndev->name); |
| 3719 | break; |
| 3720 | case TX_PRIORITY_STEERING: |
| 3721 | vxge_debug_init(VXGE_TRACE, |
| 3722 | "%s: Unsupported tx steering option", |
| 3723 | vdev->ndev->name); |
| 3724 | vxge_debug_init(VXGE_TRACE, |
| 3725 | "%s: Tx steering disabled", vdev->ndev->name); |
| 3726 | vdev->config.tx_steering_type = 0; |
| 3727 | break; |
| 3728 | case TX_VLAN_STEERING: |
| 3729 | vxge_debug_init(VXGE_TRACE, |
| 3730 | "%s: Unsupported tx steering option", |
| 3731 | vdev->ndev->name); |
| 3732 | vxge_debug_init(VXGE_TRACE, |
| 3733 | "%s: Tx steering disabled", vdev->ndev->name); |
| 3734 | vdev->config.tx_steering_type = 0; |
| 3735 | break; |
| 3736 | case TX_MULTIQ_STEERING: |
| 3737 | vxge_debug_init(VXGE_TRACE, |
| 3738 | "%s: Tx multiqueue steering enabled", |
| 3739 | vdev->ndev->name); |
| 3740 | break; |
| 3741 | case TX_PORT_STEERING: |
| 3742 | vxge_debug_init(VXGE_TRACE, |
| 3743 | "%s: Tx port steering enabled", |
| 3744 | vdev->ndev->name); |
| 3745 | break; |
| 3746 | default: |
| 3747 | vxge_debug_init(VXGE_ERR, |
| 3748 | "%s: Unsupported tx steering type", |
| 3749 | vdev->ndev->name); |
| 3750 | vxge_debug_init(VXGE_TRACE, |
| 3751 | "%s: Tx steering disabled", vdev->ndev->name); |
| 3752 | vdev->config.tx_steering_type = 0; |
| 3753 | } |
| 3754 | |
| 3755 | if (vdev->config.gro_enable) { |
| 3756 | vxge_debug_init(VXGE_ERR, |
| 3757 | "%s: Generic receive offload enabled", |
| 3758 | vdev->ndev->name); |
| 3759 | } else |
| 3760 | vxge_debug_init(VXGE_TRACE, |
| 3761 | "%s: Generic receive offload disabled", |
| 3762 | vdev->ndev->name); |
| 3763 | |
| 3764 | if (vdev->config.addr_learn_en) |
| 3765 | vxge_debug_init(VXGE_TRACE, |
| 3766 | "%s: MAC Address learning enabled", vdev->ndev->name); |
| 3767 | |
| 3768 | vxge_debug_init(VXGE_TRACE, |
| 3769 | "%s: Rx doorbell mode enabled", vdev->ndev->name); |
| 3770 | |
| 3771 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 3772 | if (!vxge_bVALn(vpath_mask, i, 1)) |
| 3773 | continue; |
| 3774 | vxge_debug_ll_config(VXGE_TRACE, |
| 3775 | "%s: MTU size - %d", vdev->ndev->name, |
| 3776 | ((struct __vxge_hw_device *)(vdev->devh))-> |
| 3777 | config.vp_config[i].mtu); |
| 3778 | vxge_debug_init(VXGE_TRACE, |
| 3779 | "%s: VLAN tag stripping %s", vdev->ndev->name, |
| 3780 | ((struct __vxge_hw_device *)(vdev->devh))-> |
| 3781 | config.vp_config[i].rpa_strip_vlan_tag |
| 3782 | ? "Enabled" : "Disabled"); |
| 3783 | vxge_debug_init(VXGE_TRACE, |
| 3784 | "%s: Ring blocks : %d", vdev->ndev->name, |
| 3785 | ((struct __vxge_hw_device *)(vdev->devh))-> |
| 3786 | config.vp_config[i].ring.ring_blocks); |
| 3787 | vxge_debug_init(VXGE_TRACE, |
| 3788 | "%s: Fifo blocks : %d", vdev->ndev->name, |
| 3789 | ((struct __vxge_hw_device *)(vdev->devh))-> |
| 3790 | config.vp_config[i].fifo.fifo_blocks); |
| 3791 | vxge_debug_ll_config(VXGE_TRACE, |
| 3792 | "%s: Max frags : %d", vdev->ndev->name, |
| 3793 | ((struct __vxge_hw_device *)(vdev->devh))-> |
| 3794 | config.vp_config[i].fifo.max_frags); |
| 3795 | break; |
| 3796 | } |
| 3797 | } |
| 3798 | |
| 3799 | #ifdef CONFIG_PM |
| 3800 | /** |
| 3801 | * vxge_pm_suspend - vxge power management suspend entry point |
| 3802 | * |
| 3803 | */ |
| 3804 | static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state) |
| 3805 | { |
| 3806 | return -ENOSYS; |
| 3807 | } |
| 3808 | /** |
| 3809 | * vxge_pm_resume - vxge power management resume entry point |
| 3810 | * |
| 3811 | */ |
| 3812 | static int vxge_pm_resume(struct pci_dev *pdev) |
| 3813 | { |
| 3814 | return -ENOSYS; |
| 3815 | } |
| 3816 | |
| 3817 | #endif |
| 3818 | |
| 3819 | /** |
| 3820 | * vxge_io_error_detected - called when PCI error is detected |
| 3821 | * @pdev: Pointer to PCI device |
| 3822 | * @state: The current pci connection state |
| 3823 | * |
| 3824 | * This function is called after a PCI bus error affecting |
| 3825 | * this device has been detected. |
| 3826 | */ |
| 3827 | static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev, |
| 3828 | pci_channel_state_t state) |
| 3829 | { |
| 3830 | struct __vxge_hw_device *hldev = |
| 3831 | (struct __vxge_hw_device *) pci_get_drvdata(pdev); |
| 3832 | struct net_device *netdev = hldev->ndev; |
| 3833 | |
| 3834 | netif_device_detach(netdev); |
| 3835 | |
Dean Nelson | e33b992 | 2009-07-31 09:14:03 +0000 | [diff] [blame] | 3836 | if (state == pci_channel_io_perm_failure) |
| 3837 | return PCI_ERS_RESULT_DISCONNECT; |
| 3838 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3839 | if (netif_running(netdev)) { |
| 3840 | /* Bring down the card, while avoiding PCI I/O */ |
| 3841 | do_vxge_close(netdev, 0); |
| 3842 | } |
| 3843 | |
| 3844 | pci_disable_device(pdev); |
| 3845 | |
| 3846 | return PCI_ERS_RESULT_NEED_RESET; |
| 3847 | } |
| 3848 | |
| 3849 | /** |
| 3850 | * vxge_io_slot_reset - called after the pci bus has been reset. |
| 3851 | * @pdev: Pointer to PCI device |
| 3852 | * |
| 3853 | * Restart the card from scratch, as if from a cold-boot. |
| 3854 | * At this point, the card has exprienced a hard reset, |
| 3855 | * followed by fixups by BIOS, and has its config space |
| 3856 | * set up identically to what it was at cold boot. |
| 3857 | */ |
| 3858 | static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev) |
| 3859 | { |
| 3860 | struct __vxge_hw_device *hldev = |
| 3861 | (struct __vxge_hw_device *) pci_get_drvdata(pdev); |
| 3862 | struct net_device *netdev = hldev->ndev; |
| 3863 | |
| 3864 | struct vxgedev *vdev = netdev_priv(netdev); |
| 3865 | |
| 3866 | if (pci_enable_device(pdev)) { |
Joe Perches | 75f5e1c | 2010-07-27 11:47:03 +0000 | [diff] [blame] | 3867 | netdev_err(netdev, "Cannot re-enable device after reset\n"); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3868 | return PCI_ERS_RESULT_DISCONNECT; |
| 3869 | } |
| 3870 | |
| 3871 | pci_set_master(pdev); |
| 3872 | vxge_reset(vdev); |
| 3873 | |
| 3874 | return PCI_ERS_RESULT_RECOVERED; |
| 3875 | } |
| 3876 | |
| 3877 | /** |
| 3878 | * vxge_io_resume - called when traffic can start flowing again. |
| 3879 | * @pdev: Pointer to PCI device |
| 3880 | * |
| 3881 | * This callback is called when the error recovery driver tells |
| 3882 | * us that its OK to resume normal operation. |
| 3883 | */ |
| 3884 | static void vxge_io_resume(struct pci_dev *pdev) |
| 3885 | { |
| 3886 | struct __vxge_hw_device *hldev = |
| 3887 | (struct __vxge_hw_device *) pci_get_drvdata(pdev); |
| 3888 | struct net_device *netdev = hldev->ndev; |
| 3889 | |
| 3890 | if (netif_running(netdev)) { |
| 3891 | if (vxge_open(netdev)) { |
Joe Perches | 75f5e1c | 2010-07-27 11:47:03 +0000 | [diff] [blame] | 3892 | netdev_err(netdev, |
| 3893 | "Can't bring device back up after reset\n"); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3894 | return; |
| 3895 | } |
| 3896 | } |
| 3897 | |
| 3898 | netif_device_attach(netdev); |
| 3899 | } |
| 3900 | |
Sreenivasa Honnur | cb27ec6 | 2010-04-08 01:48:57 -0700 | [diff] [blame] | 3901 | static inline u32 vxge_get_num_vfs(u64 function_mode) |
| 3902 | { |
| 3903 | u32 num_functions = 0; |
| 3904 | |
| 3905 | switch (function_mode) { |
| 3906 | case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION: |
| 3907 | case VXGE_HW_FUNCTION_MODE_SRIOV_8: |
| 3908 | num_functions = 8; |
| 3909 | break; |
| 3910 | case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION: |
| 3911 | num_functions = 1; |
| 3912 | break; |
| 3913 | case VXGE_HW_FUNCTION_MODE_SRIOV: |
| 3914 | case VXGE_HW_FUNCTION_MODE_MRIOV: |
| 3915 | case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17: |
| 3916 | num_functions = 17; |
| 3917 | break; |
| 3918 | case VXGE_HW_FUNCTION_MODE_SRIOV_4: |
| 3919 | num_functions = 4; |
| 3920 | break; |
| 3921 | case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2: |
| 3922 | num_functions = 2; |
| 3923 | break; |
| 3924 | case VXGE_HW_FUNCTION_MODE_MRIOV_8: |
| 3925 | num_functions = 8; /* TODO */ |
| 3926 | break; |
| 3927 | } |
| 3928 | return num_functions; |
| 3929 | } |
| 3930 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3931 | /** |
| 3932 | * vxge_probe |
| 3933 | * @pdev : structure containing the PCI related information of the device. |
| 3934 | * @pre: List of PCI devices supported by the driver listed in vxge_id_table. |
| 3935 | * Description: |
| 3936 | * This function is called when a new PCI device gets detected and initializes |
| 3937 | * it. |
| 3938 | * Return value: |
| 3939 | * returns 0 on success and negative on failure. |
| 3940 | * |
| 3941 | */ |
| 3942 | static int __devinit |
| 3943 | vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre) |
| 3944 | { |
| 3945 | struct __vxge_hw_device *hldev; |
| 3946 | enum vxge_hw_status status; |
| 3947 | int ret; |
| 3948 | int high_dma = 0; |
| 3949 | u64 vpath_mask = 0; |
| 3950 | struct vxgedev *vdev; |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 3951 | struct vxge_config *ll_config = NULL; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3952 | struct vxge_hw_device_config *device_config = NULL; |
| 3953 | struct vxge_hw_device_attr attr; |
| 3954 | int i, j, no_of_vpath = 0, max_vpath_supported = 0; |
| 3955 | u8 *macaddr; |
| 3956 | struct vxge_mac_addrs *entry; |
| 3957 | static int bus = -1, device = -1; |
Sreenivasa Honnur | cb27ec6 | 2010-04-08 01:48:57 -0700 | [diff] [blame] | 3958 | u32 host_type; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3959 | u8 new_device = 0; |
Sreenivasa Honnur | cb27ec6 | 2010-04-08 01:48:57 -0700 | [diff] [blame] | 3960 | enum vxge_hw_status is_privileged; |
| 3961 | u32 function_mode; |
| 3962 | u32 num_vfs = 0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3963 | |
| 3964 | vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__); |
| 3965 | attr.pdev = pdev; |
| 3966 | |
Sreenivasa Honnur | cb27ec6 | 2010-04-08 01:48:57 -0700 | [diff] [blame] | 3967 | /* In SRIOV-17 mode, functions of the same adapter |
| 3968 | * can be deployed on different buses */ |
| 3969 | if ((!pdev->is_virtfn) && ((bus != pdev->bus->number) || |
| 3970 | (device != PCI_SLOT(pdev->devfn)))) |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3971 | new_device = 1; |
| 3972 | |
| 3973 | bus = pdev->bus->number; |
| 3974 | device = PCI_SLOT(pdev->devfn); |
| 3975 | |
| 3976 | if (new_device) { |
| 3977 | if (driver_config->config_dev_cnt && |
| 3978 | (driver_config->config_dev_cnt != |
| 3979 | driver_config->total_dev_cnt)) |
| 3980 | vxge_debug_init(VXGE_ERR, |
| 3981 | "%s: Configured %d of %d devices", |
| 3982 | VXGE_DRIVER_NAME, |
| 3983 | driver_config->config_dev_cnt, |
| 3984 | driver_config->total_dev_cnt); |
| 3985 | driver_config->config_dev_cnt = 0; |
| 3986 | driver_config->total_dev_cnt = 0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3987 | } |
Sreenivasa Honnur | 9002397 | 2010-04-08 01:48:30 -0700 | [diff] [blame] | 3988 | /* Now making the CPU based no of vpath calculation |
| 3989 | * applicable for individual functions as well. |
| 3990 | */ |
| 3991 | driver_config->g_no_cpus = 0; |
Sreenivasa Honnur | 657205b | 2009-10-05 01:52:54 +0000 | [diff] [blame] | 3992 | driver_config->vpath_per_dev = max_config_vpath; |
| 3993 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 3994 | driver_config->total_dev_cnt++; |
| 3995 | if (++driver_config->config_dev_cnt > max_config_dev) { |
| 3996 | ret = 0; |
| 3997 | goto _exit0; |
| 3998 | } |
| 3999 | |
| 4000 | device_config = kzalloc(sizeof(struct vxge_hw_device_config), |
| 4001 | GFP_KERNEL); |
| 4002 | if (!device_config) { |
| 4003 | ret = -ENOMEM; |
| 4004 | vxge_debug_init(VXGE_ERR, |
| 4005 | "device_config : malloc failed %s %d", |
| 4006 | __FILE__, __LINE__); |
| 4007 | goto _exit0; |
| 4008 | } |
| 4009 | |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4010 | ll_config = kzalloc(sizeof(*ll_config), GFP_KERNEL); |
| 4011 | if (!ll_config) { |
| 4012 | ret = -ENOMEM; |
| 4013 | vxge_debug_init(VXGE_ERR, |
| 4014 | "ll_config : malloc failed %s %d", |
| 4015 | __FILE__, __LINE__); |
| 4016 | goto _exit0; |
| 4017 | } |
| 4018 | ll_config->tx_steering_type = TX_MULTIQ_STEERING; |
| 4019 | ll_config->intr_type = MSI_X; |
| 4020 | ll_config->napi_weight = NEW_NAPI_WEIGHT; |
| 4021 | ll_config->rth_steering = RTH_STEERING; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4022 | |
| 4023 | /* get the default configuration parameters */ |
| 4024 | vxge_hw_device_config_default_get(device_config); |
| 4025 | |
| 4026 | /* initialize configuration parameters */ |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4027 | vxge_device_config_init(device_config, &ll_config->intr_type); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4028 | |
| 4029 | ret = pci_enable_device(pdev); |
| 4030 | if (ret) { |
| 4031 | vxge_debug_init(VXGE_ERR, |
| 4032 | "%s : can not enable PCI device", __func__); |
| 4033 | goto _exit0; |
| 4034 | } |
| 4035 | |
Denis Kirjanov | b3837ce | 2009-12-25 18:48:33 -0800 | [diff] [blame] | 4036 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4037 | vxge_debug_ll_config(VXGE_TRACE, |
| 4038 | "%s : using 64bit DMA", __func__); |
| 4039 | |
| 4040 | high_dma = 1; |
| 4041 | |
| 4042 | if (pci_set_consistent_dma_mask(pdev, |
Denis Kirjanov | b3837ce | 2009-12-25 18:48:33 -0800 | [diff] [blame] | 4043 | DMA_BIT_MASK(64))) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4044 | vxge_debug_init(VXGE_ERR, |
| 4045 | "%s : unable to obtain 64bit DMA for " |
| 4046 | "consistent allocations", __func__); |
| 4047 | ret = -ENOMEM; |
| 4048 | goto _exit1; |
| 4049 | } |
Denis Kirjanov | b3837ce | 2009-12-25 18:48:33 -0800 | [diff] [blame] | 4050 | } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4051 | vxge_debug_ll_config(VXGE_TRACE, |
| 4052 | "%s : using 32bit DMA", __func__); |
| 4053 | } else { |
| 4054 | ret = -ENOMEM; |
| 4055 | goto _exit1; |
| 4056 | } |
| 4057 | |
| 4058 | if (pci_request_regions(pdev, VXGE_DRIVER_NAME)) { |
| 4059 | vxge_debug_init(VXGE_ERR, |
| 4060 | "%s : request regions failed", __func__); |
| 4061 | ret = -ENODEV; |
| 4062 | goto _exit1; |
| 4063 | } |
| 4064 | |
| 4065 | pci_set_master(pdev); |
| 4066 | |
| 4067 | attr.bar0 = pci_ioremap_bar(pdev, 0); |
| 4068 | if (!attr.bar0) { |
| 4069 | vxge_debug_init(VXGE_ERR, |
| 4070 | "%s : cannot remap io memory bar0", __func__); |
| 4071 | ret = -ENODEV; |
| 4072 | goto _exit2; |
| 4073 | } |
| 4074 | vxge_debug_ll_config(VXGE_TRACE, |
| 4075 | "pci ioremap bar0: %p:0x%llx", |
| 4076 | attr.bar0, |
| 4077 | (unsigned long long)pci_resource_start(pdev, 0)); |
| 4078 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4079 | status = vxge_hw_device_hw_info_get(attr.bar0, |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4080 | &ll_config->device_hw_info); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4081 | if (status != VXGE_HW_OK) { |
| 4082 | vxge_debug_init(VXGE_ERR, |
| 4083 | "%s: Reading of hardware info failed." |
| 4084 | "Please try upgrading the firmware.", VXGE_DRIVER_NAME); |
| 4085 | ret = -EINVAL; |
Sreenivasa Honnur | 7975d1e | 2009-07-01 21:12:23 +0000 | [diff] [blame] | 4086 | goto _exit3; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4087 | } |
| 4088 | |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4089 | if (ll_config->device_hw_info.fw_version.major != |
Sreenivasa Honnur | 22fa125 | 2009-07-01 21:17:24 +0000 | [diff] [blame] | 4090 | VXGE_DRIVER_FW_VERSION_MAJOR) { |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4091 | vxge_debug_init(VXGE_ERR, |
Sreenivasa Honnur | 22fa125 | 2009-07-01 21:17:24 +0000 | [diff] [blame] | 4092 | "%s: Incorrect firmware version." |
| 4093 | "Please upgrade the firmware to version 1.x.x", |
| 4094 | VXGE_DRIVER_NAME); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4095 | ret = -EINVAL; |
Sreenivasa Honnur | 7975d1e | 2009-07-01 21:12:23 +0000 | [diff] [blame] | 4096 | goto _exit3; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4097 | } |
| 4098 | |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4099 | vpath_mask = ll_config->device_hw_info.vpath_mask; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4100 | if (vpath_mask == 0) { |
| 4101 | vxge_debug_ll_config(VXGE_TRACE, |
| 4102 | "%s: No vpaths available in device", VXGE_DRIVER_NAME); |
| 4103 | ret = -EINVAL; |
Sreenivasa Honnur | 7975d1e | 2009-07-01 21:12:23 +0000 | [diff] [blame] | 4104 | goto _exit3; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | vxge_debug_ll_config(VXGE_TRACE, |
| 4108 | "%s:%d Vpath mask = %llx", __func__, __LINE__, |
| 4109 | (unsigned long long)vpath_mask); |
| 4110 | |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4111 | function_mode = ll_config->device_hw_info.function_mode; |
| 4112 | host_type = ll_config->device_hw_info.host_type; |
Sreenivasa Honnur | cb27ec6 | 2010-04-08 01:48:57 -0700 | [diff] [blame] | 4113 | is_privileged = __vxge_hw_device_is_privilaged(host_type, |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4114 | ll_config->device_hw_info.func_id); |
Sreenivasa Honnur | cb27ec6 | 2010-04-08 01:48:57 -0700 | [diff] [blame] | 4115 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4116 | /* Check how many vpaths are available */ |
| 4117 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 4118 | if (!((vpath_mask) & vxge_mBIT(i))) |
| 4119 | continue; |
| 4120 | max_vpath_supported++; |
| 4121 | } |
| 4122 | |
Sreenivasa Honnur | cb27ec6 | 2010-04-08 01:48:57 -0700 | [diff] [blame] | 4123 | if (new_device) |
| 4124 | num_vfs = vxge_get_num_vfs(function_mode) - 1; |
| 4125 | |
Sivakumar Subramani | 5dbc901 | 2009-06-16 18:48:55 +0000 | [diff] [blame] | 4126 | /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */ |
Sreenivasa Honnur | cb27ec6 | 2010-04-08 01:48:57 -0700 | [diff] [blame] | 4127 | if (is_sriov(function_mode) && (max_config_dev > 1) && |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4128 | (ll_config->intr_type != INTA) && |
Sreenivasa Honnur | cb27ec6 | 2010-04-08 01:48:57 -0700 | [diff] [blame] | 4129 | (is_privileged == VXGE_HW_OK)) { |
| 4130 | ret = pci_enable_sriov(pdev, ((max_config_dev - 1) < num_vfs) |
| 4131 | ? (max_config_dev - 1) : num_vfs); |
| 4132 | if (ret) |
| 4133 | vxge_debug_ll_config(VXGE_ERR, |
| 4134 | "Failed in enabling SRIOV mode: %d\n", ret); |
Sivakumar Subramani | 5dbc901 | 2009-06-16 18:48:55 +0000 | [diff] [blame] | 4135 | } |
| 4136 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4137 | /* |
| 4138 | * Configure vpaths and get driver configured number of vpaths |
| 4139 | * which is less than or equal to the maximum vpaths per function. |
| 4140 | */ |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4141 | no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4142 | if (!no_of_vpath) { |
| 4143 | vxge_debug_ll_config(VXGE_ERR, |
| 4144 | "%s: No more vpaths to configure", VXGE_DRIVER_NAME); |
| 4145 | ret = 0; |
Sreenivasa Honnur | 7975d1e | 2009-07-01 21:12:23 +0000 | [diff] [blame] | 4146 | goto _exit3; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | /* Setting driver callbacks */ |
| 4150 | attr.uld_callbacks.link_up = vxge_callback_link_up; |
| 4151 | attr.uld_callbacks.link_down = vxge_callback_link_down; |
| 4152 | attr.uld_callbacks.crit_err = vxge_callback_crit_err; |
| 4153 | |
| 4154 | status = vxge_hw_device_initialize(&hldev, &attr, device_config); |
| 4155 | if (status != VXGE_HW_OK) { |
| 4156 | vxge_debug_init(VXGE_ERR, |
| 4157 | "Failed to initialize device (%d)", status); |
| 4158 | ret = -EINVAL; |
Sreenivasa Honnur | 7975d1e | 2009-07-01 21:12:23 +0000 | [diff] [blame] | 4159 | goto _exit3; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4160 | } |
| 4161 | |
Sreenivasa Honnur | fa41fd1 | 2009-10-05 01:56:35 +0000 | [diff] [blame] | 4162 | /* if FCS stripping is not disabled in MAC fail driver load */ |
| 4163 | if (vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask) != VXGE_HW_OK) { |
| 4164 | vxge_debug_init(VXGE_ERR, |
| 4165 | "%s: FCS stripping is not disabled in MAC" |
| 4166 | " failing driver load", VXGE_DRIVER_NAME); |
| 4167 | ret = -EINVAL; |
| 4168 | goto _exit4; |
| 4169 | } |
| 4170 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4171 | vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL); |
| 4172 | |
| 4173 | /* set private device info */ |
| 4174 | pci_set_drvdata(pdev, hldev); |
| 4175 | |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4176 | ll_config->gro_enable = VXGE_GRO_ALWAYS_AGGREGATE; |
| 4177 | ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS; |
| 4178 | ll_config->addr_learn_en = addr_learn_en; |
| 4179 | ll_config->rth_algorithm = RTH_ALG_JENKINS; |
Jon Mason | 47f01db | 2010-11-11 04:25:53 +0000 | [diff] [blame^] | 4180 | ll_config->rth_hash_type_tcpipv4 = 1; |
| 4181 | ll_config->rth_hash_type_ipv4 = 0; |
| 4182 | ll_config->rth_hash_type_tcpipv6 = 0; |
| 4183 | ll_config->rth_hash_type_ipv6 = 0; |
| 4184 | ll_config->rth_hash_type_tcpipv6ex = 0; |
| 4185 | ll_config->rth_hash_type_ipv6ex = 0; |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4186 | ll_config->rth_bkt_sz = RTH_BUCKET_SIZE; |
| 4187 | ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE; |
| 4188 | ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4189 | |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4190 | if (vxge_device_register(hldev, ll_config, high_dma, no_of_vpath, |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4191 | &vdev)) { |
| 4192 | ret = -EINVAL; |
Sreenivasa Honnur | 7975d1e | 2009-07-01 21:12:23 +0000 | [diff] [blame] | 4193 | goto _exit4; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL); |
| 4197 | VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev), |
| 4198 | vxge_hw_device_trace_level_get(hldev)); |
| 4199 | |
| 4200 | /* set private HW device info */ |
| 4201 | hldev->ndev = vdev->ndev; |
| 4202 | vdev->mtu = VXGE_HW_DEFAULT_MTU; |
| 4203 | vdev->bar0 = attr.bar0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4204 | vdev->max_vpath_supported = max_vpath_supported; |
| 4205 | vdev->no_of_vpath = no_of_vpath; |
| 4206 | |
| 4207 | /* Virtual Path count */ |
| 4208 | for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 4209 | if (!vxge_bVALn(vpath_mask, i, 1)) |
| 4210 | continue; |
| 4211 | if (j >= vdev->no_of_vpath) |
| 4212 | break; |
| 4213 | |
| 4214 | vdev->vpaths[j].is_configured = 1; |
| 4215 | vdev->vpaths[j].device_id = i; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4216 | vdev->vpaths[j].ring.driver_id = j; |
| 4217 | vdev->vpaths[j].vdev = vdev; |
| 4218 | vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath; |
| 4219 | memcpy((u8 *)vdev->vpaths[j].macaddr, |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4220 | ll_config->device_hw_info.mac_addrs[i], |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4221 | ETH_ALEN); |
| 4222 | |
| 4223 | /* Initialize the mac address list header */ |
| 4224 | INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list); |
| 4225 | |
| 4226 | vdev->vpaths[j].mac_addr_cnt = 0; |
| 4227 | vdev->vpaths[j].mcast_addr_cnt = 0; |
| 4228 | j++; |
| 4229 | } |
| 4230 | vdev->exec_mode = VXGE_EXEC_MODE_DISABLE; |
| 4231 | vdev->max_config_port = max_config_port; |
| 4232 | |
| 4233 | vdev->vlan_tag_strip = vlan_tag_strip; |
| 4234 | |
| 4235 | /* map the hashing selector table to the configured vpaths */ |
| 4236 | for (i = 0; i < vdev->no_of_vpath; i++) |
| 4237 | vdev->vpath_selector[i] = vpath_selector[i]; |
| 4238 | |
| 4239 | macaddr = (u8 *)vdev->vpaths[0].macaddr; |
| 4240 | |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4241 | ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0'; |
| 4242 | ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0'; |
| 4243 | ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0'; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4244 | |
| 4245 | vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s", |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4246 | vdev->ndev->name, ll_config->device_hw_info.serial_number); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4247 | |
| 4248 | vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s", |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4249 | vdev->ndev->name, ll_config->device_hw_info.part_number); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4250 | |
| 4251 | vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter", |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4252 | vdev->ndev->name, ll_config->device_hw_info.product_desc); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4253 | |
hartleys | bf54e73 | 2010-01-05 06:59:23 +0000 | [diff] [blame] | 4254 | vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM", |
| 4255 | vdev->ndev->name, macaddr); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4256 | |
| 4257 | vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d", |
| 4258 | vdev->ndev->name, vxge_hw_device_link_width_get(hldev)); |
| 4259 | |
| 4260 | vxge_debug_init(VXGE_TRACE, |
| 4261 | "%s: Firmware version : %s Date : %s", vdev->ndev->name, |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4262 | ll_config->device_hw_info.fw_version.version, |
| 4263 | ll_config->device_hw_info.fw_date.date); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4264 | |
Sreenivasa Honnur | 0a25bdc | 2009-07-01 21:18:06 +0000 | [diff] [blame] | 4265 | if (new_device) { |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4266 | switch (ll_config->device_hw_info.function_mode) { |
Sreenivasa Honnur | 0a25bdc | 2009-07-01 21:18:06 +0000 | [diff] [blame] | 4267 | case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION: |
| 4268 | vxge_debug_init(VXGE_TRACE, |
| 4269 | "%s: Single Function Mode Enabled", vdev->ndev->name); |
| 4270 | break; |
| 4271 | case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION: |
| 4272 | vxge_debug_init(VXGE_TRACE, |
| 4273 | "%s: Multi Function Mode Enabled", vdev->ndev->name); |
| 4274 | break; |
| 4275 | case VXGE_HW_FUNCTION_MODE_SRIOV: |
| 4276 | vxge_debug_init(VXGE_TRACE, |
| 4277 | "%s: Single Root IOV Mode Enabled", vdev->ndev->name); |
| 4278 | break; |
| 4279 | case VXGE_HW_FUNCTION_MODE_MRIOV: |
| 4280 | vxge_debug_init(VXGE_TRACE, |
| 4281 | "%s: Multi Root IOV Mode Enabled", vdev->ndev->name); |
| 4282 | break; |
| 4283 | } |
| 4284 | } |
| 4285 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4286 | vxge_print_parm(vdev, vpath_mask); |
| 4287 | |
| 4288 | /* Store the fw version for ethttool option */ |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4289 | strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4290 | memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN); |
| 4291 | memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN); |
| 4292 | |
| 4293 | /* Copy the station mac address to the list */ |
| 4294 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 4295 | entry = (struct vxge_mac_addrs *) |
| 4296 | kzalloc(sizeof(struct vxge_mac_addrs), |
| 4297 | GFP_KERNEL); |
| 4298 | if (NULL == entry) { |
| 4299 | vxge_debug_init(VXGE_ERR, |
| 4300 | "%s: mac_addr_list : memory allocation failed", |
| 4301 | vdev->ndev->name); |
| 4302 | ret = -EPERM; |
Sreenivasa Honnur | 7975d1e | 2009-07-01 21:12:23 +0000 | [diff] [blame] | 4303 | goto _exit5; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4304 | } |
| 4305 | macaddr = (u8 *)&entry->macaddr; |
| 4306 | memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN); |
| 4307 | list_add(&entry->item, &vdev->vpaths[i].mac_addr_list); |
| 4308 | vdev->vpaths[i].mac_addr_cnt = 1; |
| 4309 | } |
| 4310 | |
Sreenivasa Honnur | 914d0d7 | 2009-07-01 21:13:12 +0000 | [diff] [blame] | 4311 | kfree(device_config); |
Sreenivasa Honnur | eb5f10c | 2009-10-05 01:57:29 +0000 | [diff] [blame] | 4312 | |
| 4313 | /* |
| 4314 | * INTA is shared in multi-function mode. This is unlike the INTA |
| 4315 | * implementation in MR mode, where each VH has its own INTA message. |
| 4316 | * - INTA is masked (disabled) as long as at least one function sets |
| 4317 | * its TITAN_MASK_ALL_INT.ALARM bit. |
| 4318 | * - INTA is unmasked (enabled) when all enabled functions have cleared |
| 4319 | * their own TITAN_MASK_ALL_INT.ALARM bit. |
| 4320 | * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up. |
| 4321 | * Though this driver leaves the top level interrupts unmasked while |
| 4322 | * leaving the required module interrupt bits masked on exit, there |
| 4323 | * could be a rougue driver around that does not follow this procedure |
| 4324 | * resulting in a failure to generate interrupts. The following code is |
| 4325 | * present to prevent such a failure. |
| 4326 | */ |
| 4327 | |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4328 | if (ll_config->device_hw_info.function_mode == |
Sreenivasa Honnur | eb5f10c | 2009-10-05 01:57:29 +0000 | [diff] [blame] | 4329 | VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) |
| 4330 | if (vdev->config.intr_type == INTA) |
| 4331 | vxge_hw_device_unmask_all(hldev); |
| 4332 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4333 | vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...", |
| 4334 | vdev->ndev->name, __func__, __LINE__); |
| 4335 | |
| 4336 | vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL); |
| 4337 | VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev), |
| 4338 | vxge_hw_device_trace_level_get(hldev)); |
| 4339 | |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4340 | kfree(ll_config); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4341 | return 0; |
| 4342 | |
Sreenivasa Honnur | 7975d1e | 2009-07-01 21:12:23 +0000 | [diff] [blame] | 4343 | _exit5: |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4344 | for (i = 0; i < vdev->no_of_vpath; i++) |
| 4345 | vxge_free_mac_add_list(&vdev->vpaths[i]); |
| 4346 | |
| 4347 | vxge_device_unregister(hldev); |
Sreenivasa Honnur | 7975d1e | 2009-07-01 21:12:23 +0000 | [diff] [blame] | 4348 | _exit4: |
Sivakumar Subramani | 5dbc901 | 2009-06-16 18:48:55 +0000 | [diff] [blame] | 4349 | pci_disable_sriov(pdev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4350 | vxge_hw_device_terminate(hldev); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4351 | _exit3: |
| 4352 | iounmap(attr.bar0); |
| 4353 | _exit2: |
| 4354 | pci_release_regions(pdev); |
| 4355 | _exit1: |
| 4356 | pci_disable_device(pdev); |
| 4357 | _exit0: |
Prarit Bhargava | 7dad171 | 2010-06-02 05:51:19 -0700 | [diff] [blame] | 4358 | kfree(ll_config); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4359 | kfree(device_config); |
| 4360 | driver_config->config_dev_cnt--; |
| 4361 | pci_set_drvdata(pdev, NULL); |
| 4362 | return ret; |
| 4363 | } |
| 4364 | |
| 4365 | /** |
| 4366 | * vxge_rem_nic - Free the PCI device |
| 4367 | * @pdev: structure containing the PCI related information of the device. |
| 4368 | * Description: This function is called by the Pci subsystem to release a |
| 4369 | * PCI device and free up all resource held up by the device. |
| 4370 | */ |
| 4371 | static void __devexit |
| 4372 | vxge_remove(struct pci_dev *pdev) |
| 4373 | { |
| 4374 | struct __vxge_hw_device *hldev; |
| 4375 | struct vxgedev *vdev = NULL; |
| 4376 | struct net_device *dev; |
| 4377 | int i = 0; |
| 4378 | #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \ |
| 4379 | (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK)) |
| 4380 | u32 level_trace; |
| 4381 | #endif |
| 4382 | |
| 4383 | hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev); |
| 4384 | |
| 4385 | if (hldev == NULL) |
| 4386 | return; |
| 4387 | dev = hldev->ndev; |
| 4388 | vdev = netdev_priv(dev); |
| 4389 | |
| 4390 | #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \ |
| 4391 | (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK)) |
| 4392 | level_trace = vdev->level_trace; |
| 4393 | #endif |
| 4394 | vxge_debug_entryexit(level_trace, |
| 4395 | "%s:%d", __func__, __LINE__); |
| 4396 | |
| 4397 | vxge_debug_init(level_trace, |
| 4398 | "%s : removing PCI device...", __func__); |
| 4399 | vxge_device_unregister(hldev); |
| 4400 | |
| 4401 | for (i = 0; i < vdev->no_of_vpath; i++) { |
| 4402 | vxge_free_mac_add_list(&vdev->vpaths[i]); |
| 4403 | vdev->vpaths[i].mcast_addr_cnt = 0; |
| 4404 | vdev->vpaths[i].mac_addr_cnt = 0; |
| 4405 | } |
| 4406 | |
| 4407 | kfree(vdev->vpaths); |
| 4408 | |
| 4409 | iounmap(vdev->bar0); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4410 | |
Sivakumar Subramani | 5dbc901 | 2009-06-16 18:48:55 +0000 | [diff] [blame] | 4411 | pci_disable_sriov(pdev); |
| 4412 | |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4413 | /* we are safe to free it now */ |
| 4414 | free_netdev(dev); |
| 4415 | |
| 4416 | vxge_debug_init(level_trace, |
| 4417 | "%s:%d Device unregistered", __func__, __LINE__); |
| 4418 | |
| 4419 | vxge_hw_device_terminate(hldev); |
| 4420 | |
| 4421 | pci_disable_device(pdev); |
| 4422 | pci_release_regions(pdev); |
| 4423 | pci_set_drvdata(pdev, NULL); |
| 4424 | vxge_debug_entryexit(level_trace, |
| 4425 | "%s:%d Exiting...", __func__, __LINE__); |
| 4426 | } |
| 4427 | |
| 4428 | static struct pci_error_handlers vxge_err_handler = { |
| 4429 | .error_detected = vxge_io_error_detected, |
| 4430 | .slot_reset = vxge_io_slot_reset, |
| 4431 | .resume = vxge_io_resume, |
| 4432 | }; |
| 4433 | |
| 4434 | static struct pci_driver vxge_driver = { |
| 4435 | .name = VXGE_DRIVER_NAME, |
| 4436 | .id_table = vxge_id_table, |
| 4437 | .probe = vxge_probe, |
| 4438 | .remove = __devexit_p(vxge_remove), |
| 4439 | #ifdef CONFIG_PM |
| 4440 | .suspend = vxge_pm_suspend, |
| 4441 | .resume = vxge_pm_resume, |
| 4442 | #endif |
| 4443 | .err_handler = &vxge_err_handler, |
| 4444 | }; |
| 4445 | |
| 4446 | static int __init |
| 4447 | vxge_starter(void) |
| 4448 | { |
| 4449 | int ret = 0; |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4450 | |
Joe Perches | 75f5e1c | 2010-07-27 11:47:03 +0000 | [diff] [blame] | 4451 | pr_info("Copyright(c) 2002-2010 Exar Corp.\n"); |
| 4452 | pr_info("Driver version: %s\n", DRV_VERSION); |
Ramkrishna Vepa | 703da5a | 2009-04-01 18:15:13 +0000 | [diff] [blame] | 4453 | |
| 4454 | verify_bandwidth(); |
| 4455 | |
| 4456 | driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL); |
| 4457 | if (!driver_config) |
| 4458 | return -ENOMEM; |
| 4459 | |
| 4460 | ret = pci_register_driver(&vxge_driver); |
| 4461 | |
| 4462 | if (driver_config->config_dev_cnt && |
| 4463 | (driver_config->config_dev_cnt != driver_config->total_dev_cnt)) |
| 4464 | vxge_debug_init(VXGE_ERR, |
| 4465 | "%s: Configured %d of %d devices", |
| 4466 | VXGE_DRIVER_NAME, driver_config->config_dev_cnt, |
| 4467 | driver_config->total_dev_cnt); |
| 4468 | |
| 4469 | if (ret) |
| 4470 | kfree(driver_config); |
| 4471 | |
| 4472 | return ret; |
| 4473 | } |
| 4474 | |
| 4475 | static void __exit |
| 4476 | vxge_closer(void) |
| 4477 | { |
| 4478 | pci_unregister_driver(&vxge_driver); |
| 4479 | kfree(driver_config); |
| 4480 | } |
| 4481 | module_init(vxge_starter); |
| 4482 | module_exit(vxge_closer); |