blob: 50d5604833edc8e0ffde1f7f8974002852f8bb97 [file] [log] [blame]
/******************************************************************************
* This software may be used and distributed according to the terms of
* the GNU General Public License (GPL), incorporated herein by reference.
* Drivers based on or derived from this code fall under the GPL and must
* retain the authorship, copyright and license notice. This file is not
* a complete program and may only be used when the entire operating
* system is licensed under the GPL.
* See the file COPYING in this distribution for more information.
*
* vxge-main.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
* Virtualized Server Adapter.
* Copyright(c) 2002-2010 Exar Corp.
*
* The module loadable parameters that are supported by the driver and a brief
* explanation of all the variables:
* vlan_tag_strip:
* Strip VLAN Tag enable/disable. Instructs the device to remove
* the VLAN tag from all received tagged frames that are not
* replicated at the internal L2 switch.
* 0 - Do not strip the VLAN tag.
* 1 - Strip the VLAN tag.
*
* addr_learn_en:
* Enable learning the mac address of the guest OS interface in
* a virtualization environment.
* 0 - DISABLE
* 1 - ENABLE
*
* max_config_port:
* Maximum number of port to be supported.
* MIN -1 and MAX - 2
*
* max_config_vpath:
* This configures the maximum no of VPATH configures for each
* device function.
* MIN - 1 and MAX - 17
*
* max_config_dev:
* This configures maximum no of Device function to be enabled.
* MIN - 1 and MAX - 17
*
******************************************************************************/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/bitops.h>
#include <linux/if_vlan.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/tcp.h>
#include <net/ip.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/firmware.h>
#include <linux/net_tstamp.h>
#include <linux/prefetch.h>
#include <linux/module.h>
#include "vxge-main.h"
#include "vxge-reg.h"
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
"Virtualized Server Adapter");
static const struct pci_device_id vxge_id_table[] = {
{PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
PCI_ANY_ID},
{PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
PCI_ANY_ID},
{0}
};
MODULE_DEVICE_TABLE(pci, vxge_id_table);
VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
{0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
{[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
module_param_array(bw_percentage, uint, NULL, 0);
static struct vxge_drv_config *driver_config;
static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev);
static inline int is_vxge_card_up(struct vxgedev *vdev)
{
return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
}
static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
{
struct sk_buff **skb_ptr = NULL;
struct sk_buff **temp;
#define NR_SKB_COMPLETED 128
struct sk_buff *completed[NR_SKB_COMPLETED];
int more;
do {
more = 0;
skb_ptr = completed;
if (__netif_tx_trylock(fifo->txq)) {
vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
NR_SKB_COMPLETED, &more);
__netif_tx_unlock(fifo->txq);
}
/* free SKBs */
for (temp = completed; temp != skb_ptr; temp++)
dev_kfree_skb_irq(*temp);
} while (more);
}
static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
{
int i;
/* Complete all transmits */
for (i = 0; i < vdev->no_of_vpath; i++)
VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
}
static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
{
int i;
struct vxge_ring *ring;
/* Complete all receives*/
for (i = 0; i < vdev->no_of_vpath; i++) {
ring = &vdev->vpaths[i].ring;
vxge_hw_vpath_poll_rx(ring->handle);
}
}
/*
* vxge_callback_link_up
*
* This function is called during interrupt context to notify link up state
* change.
*/
static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
{
struct net_device *dev = hldev->ndev;
struct vxgedev *vdev = netdev_priv(dev);
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
vdev->ndev->name, __func__, __LINE__);
netdev_notice(vdev->ndev, "Link Up\n");
vdev->stats.link_up++;
netif_carrier_on(vdev->ndev);
netif_tx_wake_all_queues(vdev->ndev);
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
}
/*
* vxge_callback_link_down
*
* This function is called during interrupt context to notify link down state
* change.
*/
static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
{
struct net_device *dev = hldev->ndev;
struct vxgedev *vdev = netdev_priv(dev);
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
netdev_notice(vdev->ndev, "Link Down\n");
vdev->stats.link_down++;
netif_carrier_off(vdev->ndev);
netif_tx_stop_all_queues(vdev->ndev);
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
}
/*
* vxge_rx_alloc
*
* Allocate SKB.
*/
static struct sk_buff *
vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
{
struct net_device *dev;
struct sk_buff *skb;
struct vxge_rx_priv *rx_priv;
dev = ring->ndev;
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
/* try to allocate skb first. this one may fail */
skb = netdev_alloc_skb(dev, skb_size +
VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
if (skb == NULL) {
vxge_debug_mem(VXGE_ERR,
"%s: out of memory to allocate SKB", dev->name);
ring->stats.skb_alloc_fail++;
return NULL;
}
vxge_debug_mem(VXGE_TRACE,
"%s: %s:%d Skb : 0x%p", ring->ndev->name,
__func__, __LINE__, skb);
skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
rx_priv->skb = skb;
rx_priv->skb_data = NULL;
rx_priv->data_size = skb_size;
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
return skb;
}
/*
* vxge_rx_map
*/
static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
{
struct vxge_rx_priv *rx_priv;
dma_addr_t dma_addr;
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
rx_priv->skb_data = rx_priv->skb->data;
dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
rx_priv->data_size, PCI_DMA_FROMDEVICE);
if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
ring->stats.pci_map_fail++;
return -EIO;
}
vxge_debug_mem(VXGE_TRACE,
"%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
ring->ndev->name, __func__, __LINE__,
(unsigned long long)dma_addr);
vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
rx_priv->data_dma = dma_addr;
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
return 0;
}
/*
* vxge_rx_initial_replenish
* Allocation of RxD as an initial replenish procedure.
*/
static enum vxge_hw_status
vxge_rx_initial_replenish(void *dtrh, void *userdata)
{
struct vxge_ring *ring = (struct vxge_ring *)userdata;
struct vxge_rx_priv *rx_priv;
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
if (vxge_rx_alloc(dtrh, ring,
VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
return VXGE_HW_FAIL;
if (vxge_rx_map(dtrh, ring)) {
rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
dev_kfree_skb(rx_priv->skb);
return VXGE_HW_FAIL;
}
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
return VXGE_HW_OK;
}
static inline void
vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
{
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
skb_record_rx_queue(skb, ring->driver_id);
skb->protocol = eth_type_trans(skb, ring->ndev);
u64_stats_update_begin(&ring->stats.syncp);
ring->stats.rx_frms++;
ring->stats.rx_bytes += pkt_length;
if (skb->pkt_type == PACKET_MULTICAST)
ring->stats.rx_mcast++;
u64_stats_update_end(&ring->stats.syncp);
vxge_debug_rx(VXGE_TRACE,
"%s: %s:%d skb protocol = %d",
ring->ndev->name, __func__, __LINE__, skb->protocol);
if (ext_info->vlan &&
ring->vlan_tag_strip == VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ext_info->vlan);
napi_gro_receive(ring->napi_p, skb);
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
}
static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
struct vxge_rx_priv *rx_priv)
{
pci_dma_sync_single_for_device(ring->pdev,
rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
}
static inline void vxge_post(int *dtr_cnt, void **first_dtr,
void *post_dtr, struct __vxge_hw_ring *ringh)
{
int dtr_count = *dtr_cnt;
if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
if (*first_dtr)
vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
*first_dtr = post_dtr;
} else
vxge_hw_ring_rxd_post_post(ringh, post_dtr);
dtr_count++;
*dtr_cnt = dtr_count;
}
/*
* vxge_rx_1b_compl
*
* If the interrupt is because of a received frame or if the receive ring
* contains fresh as yet un-processed frames, this function is called.
*/
static enum vxge_hw_status
vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
u8 t_code, void *userdata)
{
struct vxge_ring *ring = (struct vxge_ring *)userdata;
struct net_device *dev = ring->ndev;
unsigned int dma_sizes;
void *first_dtr = NULL;
int dtr_cnt = 0;
int data_size;
dma_addr_t data_dma;
int pkt_length;
struct sk_buff *skb;
struct vxge_rx_priv *rx_priv;
struct vxge_hw_ring_rxd_info ext_info;
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
if (ring->budget <= 0)
goto out;
do {
prefetch((char *)dtr + L1_CACHE_BYTES);
rx_priv = vxge_hw_ring_rxd_private_get(dtr);
skb = rx_priv->skb;
data_size = rx_priv->data_size;
data_dma = rx_priv->data_dma;
prefetch(rx_priv->skb_data);
vxge_debug_rx(VXGE_TRACE,
"%s: %s:%d skb = 0x%p",
ring->ndev->name, __func__, __LINE__, skb);
vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
pkt_length = dma_sizes;
pkt_length -= ETH_FCS_LEN;
vxge_debug_rx(VXGE_TRACE,
"%s: %s:%d Packet Length = %d",
ring->ndev->name, __func__, __LINE__, pkt_length);
vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
/* check skb validity */
vxge_assert(skb);
prefetch((char *)skb + L1_CACHE_BYTES);
if (unlikely(t_code)) {
if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
VXGE_HW_OK) {
ring->stats.rx_errors++;
vxge_debug_rx(VXGE_TRACE,
"%s: %s :%d Rx T_code is %d",
ring->ndev->name, __func__,
__LINE__, t_code);
/* If the t_code is not supported and if the
* t_code is other than 0x5 (unparseable packet
* such as unknown UPV6 header), Drop it !!!
*/
vxge_re_pre_post(dtr, ring, rx_priv);
vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
ring->stats.rx_dropped++;
continue;
}
}
if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
if (!vxge_rx_map(dtr, ring)) {
skb_put(skb, pkt_length);
pci_unmap_single(ring->pdev, data_dma,
data_size, PCI_DMA_FROMDEVICE);
vxge_hw_ring_rxd_pre_post(ringh, dtr);
vxge_post(&dtr_cnt, &first_dtr, dtr,
ringh);
} else {
dev_kfree_skb(rx_priv->skb);
rx_priv->skb = skb;
rx_priv->data_size = data_size;
vxge_re_pre_post(dtr, ring, rx_priv);
vxge_post(&dtr_cnt, &first_dtr, dtr,
ringh);
ring->stats.rx_dropped++;
break;
}
} else {
vxge_re_pre_post(dtr, ring, rx_priv);
vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
ring->stats.rx_dropped++;
break;
}
} else {
struct sk_buff *skb_up;
skb_up = netdev_alloc_skb(dev, pkt_length +
VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
if (skb_up != NULL) {
skb_reserve(skb_up,
VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
pci_dma_sync_single_for_cpu(ring->pdev,
data_dma, data_size,
PCI_DMA_FROMDEVICE);
vxge_debug_mem(VXGE_TRACE,
"%s: %s:%d skb_up = %p",
ring->ndev->name, __func__,
__LINE__, skb);
memcpy(skb_up->data, skb->data, pkt_length);
vxge_re_pre_post(dtr, ring, rx_priv);
vxge_post(&dtr_cnt, &first_dtr, dtr,
ringh);
/* will netif_rx small SKB instead */
skb = skb_up;
skb_put(skb, pkt_length);
} else {
vxge_re_pre_post(dtr, ring, rx_priv);
vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
vxge_debug_rx(VXGE_ERR,
"%s: vxge_rx_1b_compl: out of "
"memory", dev->name);
ring->stats.skb_alloc_fail++;
break;
}
}
if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
!(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
(dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
skb->ip_summed = CHECKSUM_UNNECESSARY;
else
skb_checksum_none_assert(skb);
if (ring->rx_hwts) {
struct skb_shared_hwtstamps *skb_hwts;
u32 ns = *(u32 *)(skb->head + pkt_length);
skb_hwts = skb_hwtstamps(skb);
skb_hwts->hwtstamp = ns_to_ktime(ns);
}
/* rth_hash_type and rth_it_hit are non-zero regardless of
* whether rss is enabled. Only the rth_value is zero/non-zero
* if rss is disabled/enabled, so key off of that.
*/
if (ext_info.rth_value)
skb_set_hash(skb, ext_info.rth_value,
PKT_HASH_TYPE_L3);
vxge_rx_complete(ring, skb, ext_info.vlan,
pkt_length, &ext_info);
ring->budget--;
ring->pkts_processed++;
if (!ring->budget)
break;
} while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
&t_code) == VXGE_HW_OK);
if (first_dtr)
vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
out:
vxge_debug_entryexit(VXGE_TRACE,
"%s:%d Exiting...",
__func__, __LINE__);
return VXGE_HW_OK;
}
/*
* vxge_xmit_compl
*
* If an interrupt was raised to indicate DMA complete of the Tx packet,
* this function is called. It identifies the last TxD whose buffer was
* freed and frees all skbs whose data have already DMA'ed into the NICs
* internal memory.
*/
static enum vxge_hw_status
vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
enum vxge_hw_fifo_tcode t_code, void *userdata,
struct sk_buff ***skb_ptr, int nr_skb, int *more)
{
struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
struct sk_buff *skb, **done_skb = *skb_ptr;
int pkt_cnt = 0;
vxge_debug_entryexit(VXGE_TRACE,
"%s:%d Entered....", __func__, __LINE__);
do {
int frg_cnt;
skb_frag_t *frag;
int i = 0, j;
struct vxge_tx_priv *txd_priv =
vxge_hw_fifo_txdl_private_get(dtr);
skb = txd_priv->skb;
frg_cnt = skb_shinfo(skb)->nr_frags;
frag = &skb_shinfo(skb)->frags[0];
vxge_debug_tx(VXGE_TRACE,
"%s: %s:%d fifo_hw = %p dtr = %p "
"tcode = 0x%x", fifo->ndev->name, __func__,
__LINE__, fifo_hw, dtr, t_code);
/* check skb validity */
vxge_assert(skb);
vxge_debug_tx(VXGE_TRACE,
"%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
fifo->ndev->name, __func__, __LINE__,
skb, txd_priv, frg_cnt);
if (unlikely(t_code)) {
fifo->stats.tx_errors++;
vxge_debug_tx(VXGE_ERR,
"%s: tx: dtr %p completed due to "
"error t_code %01x", fifo->ndev->name,
dtr, t_code);
vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
}
/* for unfragmented skb */
pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
skb_headlen(skb), PCI_DMA_TODEVICE);
for (j = 0; j < frg_cnt; j++) {
pci_unmap_page(fifo->pdev,
txd_priv->dma_buffers[i++],
skb_frag_size(frag), PCI_DMA_TODEVICE);
frag += 1;
}
vxge_hw_fifo_txdl_free(fifo_hw, dtr);
/* Updating the statistics block */
u64_stats_update_begin(&fifo->stats.syncp);
fifo->stats.tx_frms++;
fifo->stats.tx_bytes += skb->len;
u64_stats_update_end(&fifo->stats.syncp);
*done_skb++ = skb;
if (--nr_skb <= 0) {
*more = 1;
break;
}
pkt_cnt++;
if (pkt_cnt > fifo->indicate_max_pkts)
break;
} while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
&dtr, &t_code) == VXGE_HW_OK);
*skb_ptr = done_skb;
if (netif_tx_queue_stopped(fifo->txq))
netif_tx_wake_queue(fifo->txq);
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...",
fifo->ndev->name, __func__, __LINE__);
return VXGE_HW_OK;
}
/* select a vpath to transmit the packet */
static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
{
u16 queue_len, counter = 0;
if (skb->protocol == htons(ETH_P_IP)) {
struct iphdr *ip;
struct tcphdr *th;
ip = ip_hdr(skb);
if (!ip_is_fragment(ip)) {
th = (struct tcphdr *)(((unsigned char *)ip) +
ip->ihl*4);
queue_len = vdev->no_of_vpath;
counter = (ntohs(th->source) +
ntohs(th->dest)) &
vdev->vpath_selector[queue_len - 1];
if (counter >= queue_len)
counter = queue_len - 1;
}
}
return counter;
}
static enum vxge_hw_status vxge_search_mac_addr_in_list(
struct vxge_vpath *vpath, u64 del_mac)
{
struct list_head *entry, *next;
list_for_each_safe(entry, next, &vpath->mac_addr_list) {
if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
return TRUE;
}
return FALSE;
}
static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
{
struct vxge_mac_addrs *new_mac_entry;
u8 *mac_address = NULL;
if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
return TRUE;
new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
if (!new_mac_entry) {
vxge_debug_mem(VXGE_ERR,
"%s: memory allocation failed",
VXGE_DRIVER_NAME);
return FALSE;
}
list_add(&new_mac_entry->item, &vpath->mac_addr_list);
/* Copy the new mac address to the list */
mac_address = (u8 *)&new_mac_entry->macaddr;
memcpy(mac_address, mac->macaddr, ETH_ALEN);
new_mac_entry->state = mac->state;
vpath->mac_addr_cnt++;
if (is_multicast_ether_addr(mac->macaddr))
vpath->mcast_addr_cnt++;
return TRUE;
}
/* Add a mac address to DA table */
static enum vxge_hw_status
vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
{
enum vxge_hw_status status = VXGE_HW_OK;
struct vxge_vpath *vpath;
enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
if (is_multicast_ether_addr(mac->macaddr))
duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
else
duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
vpath = &vdev->vpaths[mac->vpath_no];
status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
mac->macmask, duplicate_mode);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"DA config add entry failed for vpath:%d",
vpath->device_id);
} else
if (FALSE == vxge_mac_list_add(vpath, mac))
status = -EPERM;
return status;
}
static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
{
struct macInfo mac_info;
u8 *mac_address = NULL;
u64 mac_addr = 0, vpath_vector = 0;
int vpath_idx = 0;
enum vxge_hw_status status = VXGE_HW_OK;
struct vxge_vpath *vpath = NULL;
mac_address = (u8 *)&mac_addr;
memcpy(mac_address, mac_header, ETH_ALEN);
/* Is this mac address already in the list? */
for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
vpath = &vdev->vpaths[vpath_idx];
if (vxge_search_mac_addr_in_list(vpath, mac_addr))
return vpath_idx;
}
memset(&mac_info, 0, sizeof(struct macInfo));
memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
/* Any vpath has room to add mac address to its da table? */
for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
vpath = &vdev->vpaths[vpath_idx];
if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
/* Add this mac address to this vpath */
mac_info.vpath_no = vpath_idx;
mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
status = vxge_add_mac_addr(vdev, &mac_info);
if (status != VXGE_HW_OK)
return -EPERM;
return vpath_idx;
}
}
mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
vpath_idx = 0;
mac_info.vpath_no = vpath_idx;
/* Is the first vpath already selected as catch-basin ? */
vpath = &vdev->vpaths[vpath_idx];
if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
/* Add this mac address to this vpath */
if (FALSE == vxge_mac_list_add(vpath, &mac_info))
return -EPERM;
return vpath_idx;
}
/* Select first vpath as catch-basin */
vpath_vector = vxge_mBIT(vpath->device_id);
status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
vxge_hw_mgmt_reg_type_mrpcim,
0,
(ulong)offsetof(
struct vxge_hw_mrpcim_reg,
rts_mgr_cbasin_cfg),
vpath_vector);
if (status != VXGE_HW_OK) {
vxge_debug_tx(VXGE_ERR,
"%s: Unable to set the vpath-%d in catch-basin mode",
VXGE_DRIVER_NAME, vpath->device_id);
return -EPERM;
}
if (FALSE == vxge_mac_list_add(vpath, &mac_info))
return -EPERM;
return vpath_idx;
}
/**
* vxge_xmit
* @skb : the socket buffer containing the Tx data.
* @dev : device pointer.
*
* This function is the Tx entry point of the driver. Neterion NIC supports
* certain protocol assist features on Tx side, namely CSO, S/G, LSO.
*/
static netdev_tx_t
vxge_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct vxge_fifo *fifo = NULL;
void *dtr_priv;
void *dtr = NULL;
struct vxgedev *vdev = NULL;
enum vxge_hw_status status;
int frg_cnt, first_frg_len;
skb_frag_t *frag;
int i = 0, j = 0, avail;
u64 dma_pointer;
struct vxge_tx_priv *txdl_priv = NULL;
struct __vxge_hw_fifo *fifo_hw;
int offload_type;
int vpath_no = 0;
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
dev->name, __func__, __LINE__);
/* A buffer with no data will be dropped */
if (unlikely(skb->len <= 0)) {
vxge_debug_tx(VXGE_ERR,
"%s: Buffer has no data..", dev->name);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
vdev = netdev_priv(dev);
if (unlikely(!is_vxge_card_up(vdev))) {
vxge_debug_tx(VXGE_ERR,
"%s: vdev not initialized", dev->name);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
if (vdev->config.addr_learn_en) {
vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
if (vpath_no == -EPERM) {
vxge_debug_tx(VXGE_ERR,
"%s: Failed to store the mac address",
dev->name);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
}
if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
vpath_no = skb_get_queue_mapping(skb);
else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
vpath_no = vxge_get_vpath_no(vdev, skb);
vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
if (vpath_no >= vdev->no_of_vpath)
vpath_no = 0;
fifo = &vdev->vpaths[vpath_no].fifo;
fifo_hw = fifo->handle;
if (netif_tx_queue_stopped(fifo->txq))
return NETDEV_TX_BUSY;
avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
if (avail == 0) {
vxge_debug_tx(VXGE_ERR,
"%s: No free TXDs available", dev->name);
fifo->stats.txd_not_free++;
goto _exit0;
}
/* Last TXD? Stop tx queue to avoid dropping packets. TX
* completion will resume the queue.
*/
if (avail == 1)
netif_tx_stop_queue(fifo->txq);
status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
if (unlikely(status != VXGE_HW_OK)) {
vxge_debug_tx(VXGE_ERR,
"%s: Out of descriptors .", dev->name);
fifo->stats.txd_out_of_desc++;
goto _exit0;
}
vxge_debug_tx(VXGE_TRACE,
"%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
dev->name, __func__, __LINE__,
fifo_hw, dtr, dtr_priv);
if (skb_vlan_tag_present(skb)) {
u16 vlan_tag = skb_vlan_tag_get(skb);
vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
}
first_frg_len = skb_headlen(skb);
dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
PCI_DMA_TODEVICE);
if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
vxge_hw_fifo_txdl_free(fifo_hw, dtr);
fifo->stats.pci_map_fail++;
goto _exit0;
}
txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
txdl_priv->skb = skb;
txdl_priv->dma_buffers[j] = dma_pointer;
frg_cnt = skb_shinfo(skb)->nr_frags;
vxge_debug_tx(VXGE_TRACE,
"%s: %s:%d skb = %p txdl_priv = %p "
"frag_cnt = %d dma_pointer = 0x%llx", dev->name,
__func__, __LINE__, skb, txdl_priv,
frg_cnt, (unsigned long long)dma_pointer);
vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
first_frg_len);
frag = &skb_shinfo(skb)->frags[0];
for (i = 0; i < frg_cnt; i++) {
/* ignore 0 length fragment */
if (!skb_frag_size(frag))
continue;
dma_pointer = (u64)skb_frag_dma_map(&fifo->pdev->dev, frag,
0, skb_frag_size(frag),
DMA_TO_DEVICE);
if (unlikely(dma_mapping_error(&fifo->pdev->dev, dma_pointer)))
goto _exit2;
vxge_debug_tx(VXGE_TRACE,
"%s: %s:%d frag = %d dma_pointer = 0x%llx",
dev->name, __func__, __LINE__, i,
(unsigned long long)dma_pointer);
txdl_priv->dma_buffers[j] = dma_pointer;
vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
skb_frag_size(frag));
frag += 1;
}
offload_type = vxge_offload_type(skb);
if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
int mss = vxge_tcp_mss(skb);
if (mss) {
vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
dev->name, __func__, __LINE__, mss);
vxge_hw_fifo_txdl_mss_set(dtr, mss);
} else {
vxge_assert(skb->len <=
dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
vxge_assert(0);
goto _exit1;
}
}
if (skb->ip_summed == CHECKSUM_PARTIAL)
vxge_hw_fifo_txdl_cksum_set_bits(dtr,
VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
vxge_hw_fifo_txdl_post(fifo_hw, dtr);
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
dev->name, __func__, __LINE__);
return NETDEV_TX_OK;
_exit2:
vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
_exit1:
j = 0;
frag = &skb_shinfo(skb)->frags[0];
pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
skb_headlen(skb), PCI_DMA_TODEVICE);
for (; j < i; j++) {
pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
skb_frag_size(frag), PCI_DMA_TODEVICE);
frag += 1;
}
vxge_hw_fifo_txdl_free(fifo_hw, dtr);
_exit0:
netif_tx_stop_queue(fifo->txq);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
/*
* vxge_rx_term
*
* Function will be called by hw function to abort all outstanding receive
* descriptors.
*/
static void
vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
{
struct vxge_ring *ring = (struct vxge_ring *)userdata;
struct vxge_rx_priv *rx_priv =
vxge_hw_ring_rxd_private_get(dtrh);
vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
ring->ndev->name, __func__, __LINE__);
if (state != VXGE_HW_RXD_STATE_POSTED)
return;
pci_unmap_single(ring->pdev, rx_priv->data_dma,
rx_priv->data_size, PCI_DMA_FROMDEVICE);
dev_kfree_skb(rx_priv->skb);
rx_priv->skb_data = NULL;
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d Exiting...",
ring->ndev->name, __func__, __LINE__);
}
/*
* vxge_tx_term
*
* Function will be called to abort all outstanding tx descriptors
*/
static void
vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
{
struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
skb_frag_t *frag;
int i = 0, j, frg_cnt;
struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
struct sk_buff *skb = txd_priv->skb;
vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
if (state != VXGE_HW_TXDL_STATE_POSTED)
return;
/* check skb validity */
vxge_assert(skb);
frg_cnt = skb_shinfo(skb)->nr_frags;
frag = &skb_shinfo(skb)->frags[0];
/* for unfragmented skb */
pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
skb_headlen(skb), PCI_DMA_TODEVICE);
for (j = 0; j < frg_cnt; j++) {
pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
skb_frag_size(frag), PCI_DMA_TODEVICE);
frag += 1;
}
dev_kfree_skb(skb);
vxge_debug_entryexit(VXGE_TRACE,
"%s:%d Exiting...", __func__, __LINE__);
}
static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
{
struct list_head *entry, *next;
u64 del_mac = 0;
u8 *mac_address = (u8 *) (&del_mac);
/* Copy the mac address to delete from the list */
memcpy(mac_address, mac->macaddr, ETH_ALEN);
list_for_each_safe(entry, next, &vpath->mac_addr_list) {
if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
list_del(entry);
kfree((struct vxge_mac_addrs *)entry);
vpath->mac_addr_cnt--;
if (is_multicast_ether_addr(mac->macaddr))
vpath->mcast_addr_cnt--;
return TRUE;
}
}
return FALSE;
}
/* delete a mac address from DA table */
static enum vxge_hw_status
vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
{
enum vxge_hw_status status = VXGE_HW_OK;
struct vxge_vpath *vpath;
vpath = &vdev->vpaths[mac->vpath_no];
status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
mac->macmask);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"DA config delete entry failed for vpath:%d",
vpath->device_id);
} else
vxge_mac_list_del(vpath, mac);
return status;
}
/**
* vxge_set_multicast
* @dev: pointer to the device structure
*
* Entry point for multicast address enable/disable
* This function is a driver entry point which gets called by the kernel
* whenever multicast addresses must be enabled/disabled. This also gets
* called to set/reset promiscuous mode. Depending on the deivce flag, we
* determine, if multicast address must be enabled or if promiscuous mode
* is to be disabled etc.
*/
static void vxge_set_multicast(struct net_device *dev)
{
struct netdev_hw_addr *ha;
struct vxgedev *vdev;
int i, mcast_cnt = 0;
struct __vxge_hw_device *hldev;
struct vxge_vpath *vpath;
enum vxge_hw_status status = VXGE_HW_OK;
struct macInfo mac_info;
int vpath_idx = 0;
struct vxge_mac_addrs *mac_entry;
struct list_head *list_head;
struct list_head *entry, *next;
u8 *mac_address = NULL;
vxge_debug_entryexit(VXGE_TRACE,
"%s:%d", __func__, __LINE__);
vdev = netdev_priv(dev);
hldev = vdev->devh;
if (unlikely(!is_vxge_card_up(vdev)))
return;
if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
for (i = 0; i < vdev->no_of_vpath; i++) {
vpath = &vdev->vpaths[i];
vxge_assert(vpath->is_open);
status = vxge_hw_vpath_mcast_enable(vpath->handle);
if (status != VXGE_HW_OK)
vxge_debug_init(VXGE_ERR, "failed to enable "
"multicast, status %d", status);
vdev->all_multi_flg = 1;
}
} else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
for (i = 0; i < vdev->no_of_vpath; i++) {
vpath = &vdev->vpaths[i];
vxge_assert(vpath->is_open);
status = vxge_hw_vpath_mcast_disable(vpath->handle);
if (status != VXGE_HW_OK)
vxge_debug_init(VXGE_ERR, "failed to disable "
"multicast, status %d", status);
vdev->all_multi_flg = 0;
}
}
if (!vdev->config.addr_learn_en) {
for (i = 0; i < vdev->no_of_vpath; i++) {
vpath = &vdev->vpaths[i];
vxge_assert(vpath->is_open);
if (dev->flags & IFF_PROMISC)
status = vxge_hw_vpath_promisc_enable(
vpath->handle);
else
status = vxge_hw_vpath_promisc_disable(
vpath->handle);
if (status != VXGE_HW_OK)
vxge_debug_init(VXGE_ERR, "failed to %s promisc"
", status %d", dev->flags&IFF_PROMISC ?
"enable" : "disable", status);
}
}
memset(&mac_info, 0, sizeof(struct macInfo));
/* Update individual M_CAST address list */
if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
list_head = &vdev->vpaths[0].mac_addr_list;
if ((netdev_mc_count(dev) +
(vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
vdev->vpaths[0].max_mac_addr_cnt)
goto _set_all_mcast;
/* Delete previous MC's */
for (i = 0; i < mcast_cnt; i++) {
list_for_each_safe(entry, next, list_head) {
mac_entry = (struct vxge_mac_addrs *)entry;
/* Copy the mac address to delete */
mac_address = (u8 *)&mac_entry->macaddr;
memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
if (is_multicast_ether_addr(mac_info.macaddr)) {
for (vpath_idx = 0; vpath_idx <
vdev->no_of_vpath;
vpath_idx++) {
mac_info.vpath_no = vpath_idx;
status = vxge_del_mac_addr(
vdev,
&mac_info);
}
}
}
}
/* Add new ones */
netdev_for_each_mc_addr(ha, dev) {
memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
vpath_idx++) {
mac_info.vpath_no = vpath_idx;
mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
status = vxge_add_mac_addr(vdev, &mac_info);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"%s:%d Setting individual"
"multicast address failed",
__func__, __LINE__);
goto _set_all_mcast;
}
}
}
return;
_set_all_mcast:
mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
/* Delete previous MC's */
for (i = 0; i < mcast_cnt; i++) {
list_for_each_safe(entry, next, list_head) {
mac_entry = (struct vxge_mac_addrs *)entry;
/* Copy the mac address to delete */
mac_address = (u8 *)&mac_entry->macaddr;
memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
if (is_multicast_ether_addr(mac_info.macaddr))
break;
}
for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
vpath_idx++) {
mac_info.vpath_no = vpath_idx;
status = vxge_del_mac_addr(vdev, &mac_info);
}
}
/* Enable all multicast */
for (i = 0; i < vdev->no_of_vpath; i++) {
vpath = &vdev->vpaths[i];
vxge_assert(vpath->is_open);
status = vxge_hw_vpath_mcast_enable(vpath->handle);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"%s:%d Enabling all multicasts failed",
__func__, __LINE__);
}
vdev->all_multi_flg = 1;
}
dev->flags |= IFF_ALLMULTI;
}
vxge_debug_entryexit(VXGE_TRACE,
"%s:%d Exiting...", __func__, __LINE__);
}
/**
* vxge_set_mac_addr
* @dev: pointer to the device structure
*
* Update entry "0" (default MAC addr)
*/
static int vxge_set_mac_addr(struct net_device *dev, void *p)
{
struct sockaddr *addr = p;
struct vxgedev *vdev;
struct __vxge_hw_device *hldev;
enum vxge_hw_status status = VXGE_HW_OK;
struct macInfo mac_info_new, mac_info_old;
int vpath_idx = 0;
vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
vdev = netdev_priv(dev);
hldev = vdev->devh;
if (!is_valid_ether_addr(addr->sa_data))
return -EINVAL;
memset(&mac_info_new, 0, sizeof(struct macInfo));
memset(&mac_info_old, 0, sizeof(struct macInfo));
vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
__func__, __LINE__);
/* Get the old address */
memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
/* Copy the new address */
memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
/* First delete the old mac address from all the vpaths
as we can't specify the index while adding new mac address */
for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
if (!vpath->is_open) {
/* This can happen when this interface is added/removed
to the bonding interface. Delete this station address
from the linked list */
vxge_mac_list_del(vpath, &mac_info_old);
/* Add this new address to the linked list
for later restoring */
vxge_mac_list_add(vpath, &mac_info_new);
continue;
}
/* Delete the station address */
mac_info_old.vpath_no = vpath_idx;
status = vxge_del_mac_addr(vdev, &mac_info_old);
}
if (unlikely(!is_vxge_card_up(vdev))) {
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
return VXGE_HW_OK;
}
/* Set this mac address to all the vpaths */
for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
mac_info_new.vpath_no = vpath_idx;
mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
status = vxge_add_mac_addr(vdev, &mac_info_new);
if (status != VXGE_HW_OK)
return -EINVAL;
}
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
return status;
}
/*
* vxge_vpath_intr_enable
* @vdev: pointer to vdev
* @vp_id: vpath for which to enable the interrupts
*
* Enables the interrupts for the vpath
*/
static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
{
struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
int msix_id = 0;
int tim_msix_id[4] = {0, 1, 0, 0};
int alarm_msix_id = VXGE_ALARM_MSIX_ID;
vxge_hw_vpath_intr_enable(vpath->handle);
if (vdev->config.intr_type == INTA)
vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
else {
vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
alarm_msix_id);
msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
/* enable the alarm vector */
msix_id = (vpath->handle->vpath->hldev->first_vp_id *
VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
}
}
/*
* vxge_vpath_intr_disable
* @vdev: pointer to vdev
* @vp_id: vpath for which to disable the interrupts
*
* Disables the interrupts for the vpath
*/
static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
{
struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
struct __vxge_hw_device *hldev;
int msix_id;
hldev = pci_get_drvdata(vdev->pdev);
vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
vxge_hw_vpath_intr_disable(vpath->handle);
if (vdev->config.intr_type == INTA)
vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
else {
msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
/* disable the alarm vector */
msix_id = (vpath->handle->vpath->hldev->first_vp_id *
VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
}
}
/* list all mac addresses from DA table */
static enum vxge_hw_status
vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
{
enum vxge_hw_status status = VXGE_HW_OK;
unsigned char macmask[ETH_ALEN];
unsigned char macaddr[ETH_ALEN];
status = vxge_hw_vpath_mac_addr_get(vpath->handle,
macaddr, macmask);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"DA config list entry failed for vpath:%d",
vpath->device_id);
return status;
}
while (!ether_addr_equal(mac->macaddr, macaddr)) {
status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
macaddr, macmask);
if (status != VXGE_HW_OK)
break;
}
return status;
}
/* Store all mac addresses from the list to the DA table */
static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
{
enum vxge_hw_status status = VXGE_HW_OK;
struct macInfo mac_info;
u8 *mac_address = NULL;
struct list_head *entry, *next;
memset(&mac_info, 0, sizeof(struct macInfo));
if (vpath->is_open) {
list_for_each_safe(entry, next, &vpath->mac_addr_list) {
mac_address =
(u8 *)&
((struct vxge_mac_addrs *)entry)->macaddr;
memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
((struct vxge_mac_addrs *)entry)->state =
VXGE_LL_MAC_ADDR_IN_DA_TABLE;
/* does this mac address already exist in da table? */
status = vxge_search_mac_addr_in_da_table(vpath,
&mac_info);
if (status != VXGE_HW_OK) {
/* Add this mac address to the DA table */
status = vxge_hw_vpath_mac_addr_add(
vpath->handle, mac_info.macaddr,
mac_info.macmask,
VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"DA add entry failed for vpath:%d",
vpath->device_id);
((struct vxge_mac_addrs *)entry)->state
= VXGE_LL_MAC_ADDR_IN_LIST;
}
}
}
}
return status;
}
/* Store all vlan ids from the list to the vid table */
static enum vxge_hw_status
vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
{
enum vxge_hw_status status = VXGE_HW_OK;
struct vxgedev *vdev = vpath->vdev;
u16 vid;
if (!vpath->is_open)
return status;
for_each_set_bit(vid, vdev->active_vlans, VLAN_N_VID)
status = vxge_hw_vpath_vid_add(vpath->handle, vid);
return status;
}
/*
* vxge_reset_vpath
* @vdev: pointer to vdev
* @vp_id: vpath to reset
*
* Resets the vpath
*/
static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
{
enum vxge_hw_status status = VXGE_HW_OK;
struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
int ret = 0;
/* check if device is down already */
if (unlikely(!is_vxge_card_up(vdev)))
return 0;
/* is device reset already scheduled */
if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
return 0;
if (vpath->handle) {
if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
if (is_vxge_card_up(vdev) &&
vxge_hw_vpath_recover_from_reset(vpath->handle)
!= VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"vxge_hw_vpath_recover_from_reset"
"failed for vpath:%d", vp_id);
return status;
}
} else {
vxge_debug_init(VXGE_ERR,
"vxge_hw_vpath_reset failed for"
"vpath:%d", vp_id);
return status;
}
} else
return VXGE_HW_FAIL;
vxge_restore_vpath_mac_addr(vpath);
vxge_restore_vpath_vid_table(vpath);
/* Enable all broadcast */
vxge_hw_vpath_bcast_enable(vpath->handle);
/* Enable all multicast */
if (vdev->all_multi_flg) {
status = vxge_hw_vpath_mcast_enable(vpath->handle);
if (status != VXGE_HW_OK)
vxge_debug_init(VXGE_ERR,
"%s:%d Enabling multicast failed",
__func__, __LINE__);
}
/* Enable the interrupts */
vxge_vpath_intr_enable(vdev, vp_id);
smp_wmb();
/* Enable the flow of traffic through the vpath */
vxge_hw_vpath_enable(vpath->handle);
smp_wmb();
vxge_hw_vpath_rx_doorbell_init(vpath->handle);
vpath->ring.last_status = VXGE_HW_OK;
/* Vpath reset done */
clear_bit(vp_id, &vdev->vp_reset);
/* Start the vpath queue */
if (netif_tx_queue_stopped(vpath->fifo.txq))
netif_tx_wake_queue(vpath->fifo.txq);
return ret;
}
/* Configure CI */
static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
{
int i = 0;
/* Enable CI for RTI */
if (vdev->config.intr_type == MSI_X) {
for (i = 0; i < vdev->no_of_vpath; i++) {
struct __vxge_hw_ring *hw_ring;
hw_ring = vdev->vpaths[i].ring.handle;
vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
}
}
/* Enable CI for TTI */
for (i = 0; i < vdev->no_of_vpath; i++) {
struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
vxge_hw_vpath_tti_ci_set(hw_fifo);
/*
* For Inta (with or without napi), Set CI ON for only one
* vpath. (Have only one free running timer).
*/
if ((vdev->config.intr_type == INTA) && (i == 0))
break;
}
return;
}
static int do_vxge_reset(struct vxgedev *vdev, int event)
{
enum vxge_hw_status status;
int ret = 0, vp_id, i;
vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
/* check if device is down already */
if (unlikely(!is_vxge_card_up(vdev)))
return 0;
/* is reset already scheduled */
if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
return 0;
}
if (event == VXGE_LL_FULL_RESET) {
netif_carrier_off(vdev->ndev);
/* wait for all the vpath reset to complete */
for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
while (test_bit(vp_id, &vdev->vp_reset))
msleep(50);
}
netif_carrier_on(vdev->ndev);
/* if execution mode is set to debug, don't reset the adapter */
if (unlikely(vdev->exec_mode)) {
vxge_debug_init(VXGE_ERR,
"%s: execution mode is debug, returning..",
vdev->ndev->name);
clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
netif_tx_stop_all_queues(vdev->ndev);
return 0;
}
}
if (event == VXGE_LL_FULL_RESET) {
vxge_hw_device_wait_receive_idle(vdev->devh);
vxge_hw_device_intr_disable(vdev->devh);
switch (vdev->cric_err_event) {
case VXGE_HW_EVENT_UNKNOWN:
netif_tx_stop_all_queues(vdev->ndev);
vxge_debug_init(VXGE_ERR,
"fatal: %s: Disabling device due to"
"unknown error",
vdev->ndev->name);
ret = -EPERM;
goto out;
case VXGE_HW_EVENT_RESET_START:
break;
case VXGE_HW_EVENT_RESET_COMPLETE:
case VXGE_HW_EVENT_LINK_DOWN:
case VXGE_HW_EVENT_LINK_UP:
case VXGE_HW_EVENT_ALARM_CLEARED:
case VXGE_HW_EVENT_ECCERR:
case VXGE_HW_EVENT_MRPCIM_ECCERR:
ret = -EPERM;
goto out;
case VXGE_HW_EVENT_FIFO_ERR:
case VXGE_HW_EVENT_VPATH_ERR:
break;
case VXGE_HW_EVENT_CRITICAL_ERR:
netif_tx_stop_all_queues(vdev->ndev);
vxge_debug_init(VXGE_ERR,
"fatal: %s: Disabling device due to"
"serious error",
vdev->ndev->name);
/* SOP or device reset required */
/* This event is not currently used */
ret = -EPERM;
goto out;
case VXGE_HW_EVENT_SERR:
netif_tx_stop_all_queues(vdev->ndev);
vxge_debug_init(VXGE_ERR,
"fatal: %s: Disabling device due to"
"serious error",
vdev->ndev->name);
ret = -EPERM;
goto out;
case VXGE_HW_EVENT_SRPCIM_SERR:
case VXGE_HW_EVENT_MRPCIM_SERR:
ret = -EPERM;
goto out;
case VXGE_HW_EVENT_SLOT_FREEZE:
netif_tx_stop_all_queues(vdev->ndev);
vxge_debug_init(VXGE_ERR,
"fatal: %s: Disabling device due to"
"slot freeze",
vdev->ndev->name);
ret = -EPERM;
goto out;
default:
break;
}
}
if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
netif_tx_stop_all_queues(vdev->ndev);
if (event == VXGE_LL_FULL_RESET) {
status = vxge_reset_all_vpaths(vdev);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"fatal: %s: can not reset vpaths",
vdev->ndev->name);
ret = -EPERM;
goto out;
}
}
if (event == VXGE_LL_COMPL_RESET) {
for (i = 0; i < vdev->no_of_vpath; i++)
if (vdev->vpaths[i].handle) {
if (vxge_hw_vpath_recover_from_reset(
vdev->vpaths[i].handle)
!= VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"vxge_hw_vpath_recover_"
"from_reset failed for vpath: "
"%d", i);
ret = -EPERM;
goto out;
}
} else {
vxge_debug_init(VXGE_ERR,
"vxge_hw_vpath_reset failed for "
"vpath:%d", i);
ret = -EPERM;
goto out;
}
}
if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
/* Reprogram the DA table with populated mac addresses */
for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
}
/* enable vpath interrupts */
for (i = 0; i < vdev->no_of_vpath; i++)
vxge_vpath_intr_enable(vdev, i);
vxge_hw_device_intr_enable(vdev->devh);
smp_wmb();
/* Indicate card up */
set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
/* Get the traffic to flow through the vpaths */
for (i = 0; i < vdev->no_of_vpath; i++) {
vxge_hw_vpath_enable(vdev->vpaths[i].handle);
smp_wmb();
vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
}
netif_tx_wake_all_queues(vdev->ndev);
}
/* configure CI */
vxge_config_ci_for_tti_rti(vdev);
out:
vxge_debug_entryexit(VXGE_TRACE,
"%s:%d Exiting...", __func__, __LINE__);
/* Indicate reset done */
if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
return ret;
}
/*
* vxge_reset
* @vdev: pointer to ll device
*
* driver may reset the chip on events of serr, eccerr, etc
*/
static void vxge_reset(struct work_struct *work)
{
struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
if (!netif_running(vdev->ndev))
return;
do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
}
/**
* vxge_poll - Receive handler when Receive Polling is used.
* @dev: pointer to the device structure.
* @budget: Number of packets budgeted to be processed in this iteration.
*
* This function comes into picture only if Receive side is being handled
* through polling (called NAPI in linux). It mostly does what the normal
* Rx interrupt handler does in terms of descriptor and packet processing
* but not in an interrupt context. Also it will process a specified number
* of packets at most in one iteration. This value is passed down by the
* kernel as the function argument 'budget'.
*/
static int vxge_poll_msix(struct napi_struct *napi, int budget)
{
struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
int pkts_processed;
int budget_org = budget;
ring->budget = budget;
ring->pkts_processed = 0;
vxge_hw_vpath_poll_rx(ring->handle);
pkts_processed = ring->pkts_processed;
if (ring->pkts_processed < budget_org) {
napi_complete(napi);
/* Re enable the Rx interrupts for the vpath */
vxge_hw_channel_msix_unmask(
(struct __vxge_hw_channel *)ring->handle,
ring->rx_vector_no);
mmiowb();
}
/* We are copying and returning the local variable, in case if after
* clearing the msix interrupt above, if the interrupt fires right
* away which can preempt this NAPI thread */
return pkts_processed;
}
static int vxge_poll_inta(struct napi_struct *napi, int budget)
{
struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
int pkts_processed = 0;
int i;
int budget_org = budget;
struct vxge_ring *ring;
struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
for (i = 0; i < vdev->no_of_vpath; i++) {
ring = &vdev->vpaths[i].ring;
ring->budget = budget;
ring->pkts_processed = 0;
vxge_hw_vpath_poll_rx(ring->handle);
pkts_processed += ring->pkts_processed;
budget -= ring->pkts_processed;
if (budget <= 0)
break;
}
VXGE_COMPLETE_ALL_TX(vdev);
if (pkts_processed < budget_org) {
napi_complete(napi);
/* Re enable the Rx interrupts for the ring */
vxge_hw_device_unmask_all(hldev);
vxge_hw_device_flush_io(hldev);
}
return pkts_processed;
}
#ifdef CONFIG_NET_POLL_CONTROLLER
/**
* vxge_netpoll - netpoll event handler entry point
* @dev : pointer to the device structure.
* Description:
* This function will be called by upper layer to check for events on the
* interface in situations where interrupts are disabled. It is used for
* specific in-kernel networking tasks, such as remote consoles and kernel
* debugging over the network (example netdump in RedHat).
*/
static void vxge_netpoll(struct net_device *dev)
{
struct vxgedev *vdev = netdev_priv(dev);
struct pci_dev *pdev = vdev->pdev;
struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
const int irq = pdev->irq;
vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
if (pci_channel_offline(pdev))
return;
disable_irq(irq);
vxge_hw_device_clear_tx_rx(hldev);
vxge_hw_device_clear_tx_rx(hldev);
VXGE_COMPLETE_ALL_RX(vdev);
VXGE_COMPLETE_ALL_TX(vdev);
enable_irq(irq);
vxge_debug_entryexit(VXGE_TRACE,
"%s:%d Exiting...", __func__, __LINE__);
}
#endif
/* RTH configuration */
static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
{
enum vxge_hw_status status = VXGE_HW_OK;
struct vxge_hw_rth_hash_types hash_types;
u8 itable[256] = {0}; /* indirection table */
u8 mtable[256] = {0}; /* CPU to vpath mapping */
int index;
/*
* Filling
* - itable with bucket numbers
* - mtable with bucket-to-vpath mapping
*/
for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
itable[index] = index;
mtable[index] = index % vdev->no_of_vpath;
}
/* set indirection table, bucket-to-vpath mapping */
status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
vdev->no_of_vpath,
mtable, itable,
vdev->config.rth_bkt_sz);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"RTH indirection table configuration failed "
"for vpath:%d", vdev->vpaths[0].device_id);
return status;
}
/* Fill RTH hash types */
hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
hash_types.hash_type_tcpipv6ex_en =
vdev->config.rth_hash_type_tcpipv6ex;
hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
/*
* Because the itable_set() method uses the active_table field
* for the target virtual path the RTH config should be updated
* for all VPATHs. The h/w only uses the lowest numbered VPATH
* when steering frames.
*/
for (index = 0; index < vdev->no_of_vpath; index++) {
status = vxge_hw_vpath_rts_rth_set(
vdev->vpaths[index].handle,
vdev->config.rth_algorithm,
&hash_types,
vdev->config.rth_bkt_sz);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"RTH configuration failed for vpath:%d",
vdev->vpaths[index].device_id);
return status;
}
}
return status;
}
/* reset vpaths */
static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
{
enum vxge_hw_status status = VXGE_HW_OK;
struct vxge_vpath *vpath;
int i;
for (i = 0; i < vdev->no_of_vpath; i++) {
vpath = &vdev->vpaths[i];
if (vpath->handle) {
if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
if (is_vxge_card_up(vdev) &&
vxge_hw_vpath_recover_from_reset(
vpath->handle) != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"vxge_hw_vpath_recover_"
"from_reset failed for vpath: "
"%d", i);
return status;
}
} else {
vxge_debug_init(VXGE_ERR,
"vxge_hw_vpath_reset failed for "
"vpath:%d", i);
return status;
}
}
}
return status;
}
/* close vpaths */
static void vxge_close_vpaths(struct vxgedev *vdev, int index)
{
struct vxge_vpath *vpath;
int i;
for (i = index; i < vdev->no_of_vpath; i++) {
vpath = &vdev->vpaths[i];
if (vpath->handle && vpath->is_open) {
vxge_hw_vpath_close(vpath->handle);
vdev->stats.vpaths_open--;
}
vpath->is_open = 0;
vpath->handle = NULL;
}
}
/* open vpaths */
static int vxge_open_vpaths(struct vxgedev *vdev)
{
struct vxge_hw_vpath_attr attr;
enum vxge_hw_status status;
struct vxge_vpath *vpath;
u32 vp_id = 0;
int i;
for (i = 0; i < vdev->no_of_vpath; i++) {
vpath = &vdev->vpaths[i];
vxge_assert(vpath->is_configured);
if (!vdev->titan1) {
struct vxge_hw_vp_config *vcfg;
vcfg = &vdev->devh->config.vp_config[vpath->device_id];
vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
}
attr.vp_id = vpath->device_id;
attr.fifo_attr.callback = vxge_xmit_compl;
attr.fifo_attr.txdl_term = vxge_tx_term;
attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
attr.fifo_attr.userdata = &vpath->fifo;
attr.ring_attr.callback = vxge_rx_1b_compl;
attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
attr.ring_attr.rxd_term = vxge_rx_term;
attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
attr.ring_attr.userdata = &vpath->ring;
vpath->ring.ndev = vdev->ndev;
vpath->ring.pdev = vdev->pdev;
status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
if (status == VXGE_HW_OK) {
vpath->fifo.handle =
(struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
vpath->ring.handle =
(struct __vxge_hw_ring *)attr.ring_attr.userdata;
vpath->fifo.tx_steering_type =
vdev->config.tx_steering_type;
vpath->fifo.ndev = vdev->ndev;
vpath->fifo.pdev = vdev->pdev;
u64_stats_init(&vpath->fifo.stats.syncp);
u64_stats_init(&vpath->ring.stats.syncp);
if (vdev->config.tx_steering_type)
vpath->fifo.txq =
netdev_get_tx_queue(vdev->ndev, i);
else
vpath->fifo.txq =
netdev_get_tx_queue(vdev->ndev, 0);
vpath->fifo.indicate_max_pkts =
vdev->config.fifo_indicate_max_pkts;
vpath->fifo.tx_vector_no = 0;
vpath->ring.rx_vector_no = 0;
vpath->ring.rx_hwts = vdev->rx_hwts;
vpath->is_open = 1;
vdev->vp_handles[i] = vpath->handle;
vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
vdev->stats.vpaths_open++;
} else {
vdev->stats.vpath_open_fail++;
vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
"open with status: %d",
vdev->ndev->name, vpath->device_id,
status);
vxge_close_vpaths(vdev, 0);
return -EPERM;
}
vp_id = vpath->handle->vpath->vp_id;
vdev->vpaths_deployed |= vxge_mBIT(vp_id);
}
return VXGE_HW_OK;
}
/**
* adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
* if the interrupts are not within a range
* @fifo: pointer to transmit fifo structure
* Description: The function changes boundary timer and restriction timer
* value depends on the traffic
* Return Value: None
*/
static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
{
fifo->interrupt_count++;
if (time_before(fifo->jiffies + HZ / 100, jiffies)) {
struct __vxge_hw_fifo *hw_fifo = fifo->handle;
fifo->jiffies = jiffies;
if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
} else if (hw_fifo->rtimer != 0) {
hw_fifo->rtimer = 0;
vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
}
fifo->interrupt_count = 0;
}
}
/**
* adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
* if the interrupts are not within a range
* @ring: pointer to receive ring structure
* Description: The function increases of decreases the packet counts within
* the ranges of traffic utilization, if the interrupts due to this ring are
* not within a fixed range.
* Return Value: Nothing
*/
static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
{
ring->interrupt_count++;
if (time_before(ring->jiffies + HZ / 100, jiffies)) {
struct __vxge_hw_ring *hw_ring = ring->handle;
ring->jiffies = jiffies;
if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
} else if (hw_ring->rtimer != 0) {
hw_ring->rtimer = 0;
vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
}
ring->interrupt_count = 0;
}
}
/*
* vxge_isr_napi
* @irq: the irq of the device.
* @dev_id: a void pointer to the hldev structure of the Titan device
* @ptregs: pointer to the registers pushed on the stack.
*
* This function is the ISR handler of the device when napi is enabled. It
* identifies the reason for the interrupt and calls the relevant service
* routines.
*/
static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
{
struct net_device *dev;
struct __vxge_hw_device *hldev;
u64 reason;
enum vxge_hw_status status;
struct vxgedev *vdev = (struct vxgedev *)dev_id;
vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
dev = vdev->ndev;
hldev = pci_get_drvdata(vdev->pdev);
if (pci_channel_offline(vdev->pdev))
return IRQ_NONE;
if (unlikely(!is_vxge_card_up(vdev)))
return IRQ_HANDLED;
status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
if (status == VXGE_HW_OK) {
vxge_hw_device_mask_all(hldev);
if (reason &
VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
vdev->vpaths_deployed >>
(64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
vxge_hw_device_clear_tx_rx(hldev);
napi_schedule(&vdev->napi);
vxge_debug_intr(VXGE_TRACE,
"%s:%d Exiting...", __func__, __LINE__);
return IRQ_HANDLED;
} else
vxge_hw_device_unmask_all(hldev);
} else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
(status == VXGE_HW_ERR_CRITICAL) ||
(status == VXGE_HW_ERR_FIFO))) {
vxge_hw_device_mask_all(hldev);
vxge_hw_device_flush_io(hldev);
return IRQ_HANDLED;
} else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
return IRQ_HANDLED;
vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
return IRQ_NONE;
}
#ifdef CONFIG_PCI_MSI
static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
{
struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
adaptive_coalesce_tx_interrupts(fifo);
vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
fifo->tx_vector_no);
vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
fifo->tx_vector_no);
VXGE_COMPLETE_VPATH_TX(fifo);
vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
fifo->tx_vector_no);
mmiowb();
return IRQ_HANDLED;
}
static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
{
struct vxge_ring *ring = (struct vxge_ring *)dev_id;
adaptive_coalesce_rx_interrupts(ring);
vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
ring->rx_vector_no);
vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
ring->rx_vector_no);
napi_schedule(&ring->napi);
return IRQ_HANDLED;
}
static irqreturn_t
vxge_alarm_msix_handle(int irq, void *dev_id)
{
int i;
enum vxge_hw_status status;
struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
struct vxgedev *vdev = vpath->vdev;
int msix_id = (vpath->handle->vpath->vp_id *
VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
for (i = 0; i < vdev->no_of_vpath; i++) {
/* Reduce the chance of losing alarm interrupts by masking
* the vector. A pending bit will be set if an alarm is
* generated and on unmask the interrupt will be fired.
*/
vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
mmiowb();
status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
vdev->exec_mode);
if (status == VXGE_HW_OK) {
vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
msix_id);
mmiowb();
continue;
}
vxge_debug_intr(VXGE_ERR,
"%s: vxge_hw_vpath_alarm_process failed %x ",
VXGE_DRIVER_NAME, status);
}
return IRQ_HANDLED;
}
static int vxge_alloc_msix(struct vxgedev *vdev)
{
int j, i, ret = 0;
int msix_intr_vect = 0, temp;
vdev->intr_cnt = 0;
start:
/* Tx/Rx MSIX Vectors count */
vdev->intr_cnt = vdev->no_of_vpath * 2;
/* Alarm MSIX Vectors count */
vdev->intr_cnt++;
vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
GFP_KERNEL);
if (!vdev->entries) {
vxge_debug_init(VXGE_ERR,
"%s: memory allocation failed",
VXGE_DRIVER_NAME);
ret = -ENOMEM;
goto alloc_entries_failed;
}
vdev->vxge_entries = kcalloc(vdev->intr_cnt,
sizeof(struct vxge_msix_entry),
GFP_KERNEL);
if (!vdev->vxge_entries) {
vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
VXGE_DRIVER_NAME);
ret = -ENOMEM;
goto alloc_vxge_entries_failed;
}
for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
/* Initialize the fifo vector */
vdev->entries[j].entry = msix_intr_vect;
vdev->vxge_entries[j].entry = msix_intr_vect;
vdev->vxge_entries[j].in_use = 0;
j++;
/* Initialize the ring vector */
vdev->entries[j].entry = msix_intr_vect + 1;
vdev->vxge_entries[j].entry = msix_intr_vect + 1;
vdev->vxge_entries[j].in_use = 0;
j++;
}
/* Initialize the alarm vector */
vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
vdev->vxge_entries[j].in_use = 0;
ret = pci_enable_msix_range(vdev->pdev,
vdev->entries, 3, vdev->intr_cnt);
if (ret < 0) {
ret = -ENODEV;
goto enable_msix_failed;
} else if (ret < vdev->intr_cnt) {
pci_disable_msix(vdev->pdev);
vxge_debug_init(VXGE_ERR,
"%s: MSI-X enable failed for %d vectors, ret: %d",
VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
if (max_config_vpath != VXGE_USE_DEFAULT) {
ret = -ENODEV;
goto enable_msix_failed;
}
kfree(vdev->entries);
kfree(vdev->vxge_entries);
vdev->entries = NULL;
vdev->vxge_entries = NULL;
/* Try with less no of vector by reducing no of vpaths count */
temp = (ret - 1)/2;
vxge_close_vpaths(vdev, temp);
vdev->no_of_vpath = temp;
goto start;
}
return 0;
enable_msix_failed:
kfree(vdev->vxge_entries);
alloc_vxge_entries_failed:
kfree(vdev->entries);
alloc_entries_failed:
return ret;
}
static int vxge_enable_msix(struct vxgedev *vdev)
{
int i, ret = 0;
/* 0 - Tx, 1 - Rx */
int tim_msix_id[4] = {0, 1, 0, 0};
vdev->intr_cnt = 0;
/* allocate msix vectors */
ret = vxge_alloc_msix(vdev);
if (!ret) {
for (i = 0; i < vdev->no_of_vpath; i++) {
struct vxge_vpath *vpath = &vdev->vpaths[i];
/* If fifo or ring are not enabled, the MSIX vector for
* it should be set to 0.
*/
vpath->ring.rx_vector_no = (vpath->device_id *
VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
vpath->fifo.tx_vector_no = (vpath->device_id *
VXGE_HW_VPATH_MSIX_ACTIVE);
vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
VXGE_ALARM_MSIX_ID);
}
}
return ret;
}
static void vxge_rem_msix_isr(struct vxgedev *vdev)
{
int intr_cnt;
for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
intr_cnt++) {
if (vdev->vxge_entries[intr_cnt].in_use) {
synchronize_irq(vdev->entries[intr_cnt].vector);
free_irq(vdev->entries[intr_cnt].vector,
vdev->vxge_entries[intr_cnt].arg);
vdev->vxge_entries[intr_cnt].in_use = 0;
}
}
kfree(vdev->entries);
kfree(vdev->vxge_entries);
vdev->entries = NULL;
vdev->vxge_entries = NULL;
if (vdev->config.intr_type == MSI_X)
pci_disable_msix(vdev->pdev);
}
#endif
static void vxge_rem_isr(struct vxgedev *vdev)
{
#ifdef CONFIG_PCI_MSI
if (vdev->config.intr_type == MSI_X) {
vxge_rem_msix_isr(vdev);
} else
#endif
if (vdev->config.intr_type == INTA) {
synchronize_irq(vdev->pdev->irq);
free_irq(vdev->pdev->irq, vdev);
}
}
static int vxge_add_isr(struct vxgedev *vdev)
{
int ret = 0;
#ifdef CONFIG_PCI_MSI
int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
int pci_fun = PCI_FUNC(vdev->pdev->devfn);
if (vdev->config.intr_type == MSI_X)
ret = vxge_enable_msix(vdev);
if (ret) {
vxge_debug_init(VXGE_ERR,
"%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
vxge_debug_init(VXGE_ERR,
"%s: Defaulting to INTA", VXGE_DRIVER_NAME);
vdev->config.intr_type = INTA;
}
if (vdev->config.intr_type == MSI_X) {
for (intr_idx = 0;
intr_idx < (vdev->no_of_vpath *
VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
irq_req = 0;
switch (msix_idx) {
case 0:
snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
"%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
vdev->ndev->name,
vdev->entries[intr_cnt].entry,
pci_fun, vp_idx);
ret = request_irq(
vdev->entries[intr_cnt].vector,
vxge_tx_msix_handle, 0,
vdev->desc[intr_cnt],
&vdev->vpaths[vp_idx].fifo);
vdev->vxge_entries[intr_cnt].arg =
&vdev->vpaths[vp_idx].fifo;
irq_req = 1;
break;
case 1:
snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
"%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
vdev->ndev->name,
vdev->entries[intr_cnt].entry,
pci_fun, vp_idx);
ret = request_irq(
vdev->entries[intr_cnt].vector,
vxge_rx_msix_napi_handle,
0,
vdev->desc[intr_cnt],
&vdev->vpaths[vp_idx].ring);
vdev->vxge_entries[intr_cnt].arg =
&vdev->vpaths[vp_idx].ring;
irq_req = 1;
break;
}
if (ret) {
vxge_debug_init(VXGE_ERR,
"%s: MSIX - %d Registration failed",
vdev->ndev->name, intr_cnt);
vxge_rem_msix_isr(vdev);
vdev->config.intr_type = INTA;
vxge_debug_init(VXGE_ERR,
"%s: Defaulting to INTA"
, vdev->ndev->name);
goto INTA_MODE;
}
if (irq_req) {
/* We requested for this msix interrupt */
vdev->vxge_entries[intr_cnt].in_use = 1;
msix_idx += vdev->vpaths[vp_idx].device_id *
VXGE_HW_VPATH_MSIX_ACTIVE;
vxge_hw_vpath_msix_unmask(
vdev->vpaths[vp_idx].handle,
msix_idx);
intr_cnt++;
}
/* Point to next vpath handler */
if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
(vp_idx < (vdev->no_of_vpath - 1)))
vp_idx++;
}
intr_cnt = vdev->no_of_vpath * 2;
snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
"%s:vxge:MSI-X %d - Alarm - fn:%d",
vdev->ndev->name,
vdev->entries[intr_cnt].entry,
pci_fun);
/* For Alarm interrupts */
ret = request_irq(vdev->entries[intr_cnt].vector,
vxge_alarm_msix_handle, 0,
vdev->desc[intr_cnt],
&vdev->vpaths[0]);
if (ret) {
vxge_debug_init(VXGE_ERR,
"%s: MSIX - %d Registration failed",
vdev->ndev->name, intr_cnt);
vxge_rem_msix_isr(vdev);
vdev->config.intr_type = INTA;
vxge_debug_init(VXGE_ERR,
"%s: Defaulting to INTA",
vdev->ndev->name);
goto INTA_MODE;
}
msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
msix_idx);
vdev->vxge_entries[intr_cnt].in_use = 1;
vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
}
INTA_MODE:
#endif
if (vdev->config.intr_type == INTA) {
snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
"%s:vxge:INTA", vdev->ndev->name);
vxge_hw_device_set_intr_type(vdev->devh,
VXGE_HW_INTR_MODE_IRQLINE);
vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
ret = request_irq((int) vdev->pdev->irq,
vxge_isr_napi,
IRQF_SHARED, vdev->desc[0], vdev);
if (ret) {
vxge_debug_init(VXGE_ERR,
"%s %s-%d: ISR registration failed",
VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
return -ENODEV;
}
vxge_debug_init(VXGE_TRACE,
"new %s-%d line allocated",
"IRQ", vdev->pdev->irq);
}
return VXGE_HW_OK;
}
static void vxge_poll_vp_reset(unsigned long data)
{
struct vxgedev *vdev = (struct vxgedev *)data;
int i, j = 0;
for (i = 0; i < vdev->no_of_vpath; i++) {
if (test_bit(i, &vdev->vp_reset)) {
vxge_reset_vpath(vdev, i);
j++;
}
}
if (j && (vdev->config.intr_type != MSI_X)) {
vxge_hw_device_unmask_all(vdev->devh);
vxge_hw_device_flush_io(vdev->devh);
}
mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
}
static void vxge_poll_vp_lockup(unsigned long data)
{
struct vxgedev *vdev = (struct vxgedev *)data;
enum vxge_hw_status status = VXGE_HW_OK;
struct vxge_vpath *vpath;
struct vxge_ring *ring;
int i;
unsigned long rx_frms;
for (i = 0; i < vdev->no_of_vpath; i++) {
ring = &vdev->vpaths[i].ring;
/* Truncated to machine word size number of frames */
rx_frms = ACCESS_ONCE(ring->stats.rx_frms);
/* Did this vpath received any packets */
if (ring->stats.prev_rx_frms == rx_frms) {
status = vxge_hw_vpath_check_leak(ring->handle);
/* Did it received any packets last time */
if ((VXGE_HW_FAIL == status) &&
(VXGE_HW_FAIL == ring->last_status)) {
/* schedule vpath reset */
if (!test_and_set_bit(i, &vdev->vp_reset)) {
vpath = &vdev->vpaths[i];
/* disable interrupts for this vpath */
vxge_vpath_intr_disable(vdev, i);
/* stop the queue for this vpath */
netif_tx_stop_queue(vpath->fifo.txq);
continue;
}
}
}
ring->stats.prev_rx_frms = rx_frms;
ring->last_status = status;
}
/* Check every 1 milli second */
mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
}
static netdev_features_t vxge_fix_features(struct net_device *dev,
netdev_features_t features)
{
netdev_features_t changed = dev->features ^ features;
/* Enabling RTH requires some of the logic in vxge_device_register and a
* vpath reset. Due to these restrictions, only allow modification
* while the interface is down.
*/
if ((changed & NETIF_F_RXHASH) && netif_running(dev))
features ^= NETIF_F_RXHASH;
return features;
}
static int vxge_set_features(struct net_device *dev, netdev_features_t features)
{
struct vxgedev *vdev = netdev_priv(dev);
netdev_features_t changed = dev->features ^ features;
if (!(changed & NETIF_F_RXHASH))
return 0;
/* !netif_running() ensured by vxge_fix_features() */
vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
dev->features = features ^ NETIF_F_RXHASH;
vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
return -EIO;
}
return 0;
}
/**
* vxge_open
* @dev: pointer to the device structure.
*
* This function is the open entry point of the driver. It mainly calls a
* function to allocate Rx buffers and inserts them into the buffer
* descriptors and then enables the Rx part of the NIC.
* Return value: '0' on success and an appropriate (-)ve integer as
* defined in errno.h file on failure.
*/
static int vxge_open(struct net_device *dev)
{
enum vxge_hw_status status;
struct vxgedev *vdev;
struct __vxge_hw_device *hldev;
struct vxge_vpath *vpath;
int ret = 0;
int i;
u64 val64, function_mode;
vxge_debug_entryexit(VXGE_TRACE,
"%s: %s:%d", dev->name, __func__, __LINE__);
vdev = netdev_priv(dev);
hldev = pci_get_drvdata(vdev->pdev);
function_mode = vdev->config.device_hw_info.function_mode;
/* make sure you have link off by default every time Nic is
* initialized */
netif_carrier_off(dev);
/* Open VPATHs */
status = vxge_open_vpaths(vdev);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"%s: fatal: Vpath open failed", vdev->ndev->name);
ret = -EPERM;
goto out0;
}
vdev->mtu = dev->mtu;
status = vxge_add_isr(vdev);
if (status != VXGE_HW_OK) {
vxge_debug_init(VXGE_ERR,
"%s: fatal: ISR add failed", dev->name);
ret = -EPERM;
goto out1;
}
if (vdev->config.intr_type != MSI_X) {
netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
vdev->config.napi_weight);
napi_enable(&vdev->napi);