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