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