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