]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/s2io.c
Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-2.6-omap-h63xx.git] / drivers / net / s2io.c
index 6bfb191634e76c391aa8935f313062fc638ccbb9..24feb00600eea835b1c50da642f610157a9e5f62 100644 (file)
@@ -37,7 +37,7 @@
  * tx_fifo_len: This too is an array of 8. Each element defines the number of
  * Tx descriptors that can be associated with each corresponding FIFO.
  * intr_type: This defines the type of interrupt. The values can be 0(INTA),
- *     1(MSI), 2(MSI_X). Default value is '0(INTA)'
+ *     2(MSI_X). Default value is '0(INTA)'
  * lro: Specifies whether to enable Large Receive Offload (LRO) or not.
  *     Possible values '1' for enable '0' for disable. Default is '0'
  * lro_max_pkts: This parameter defines maximum number of packets can be
@@ -84,7 +84,7 @@
 #include "s2io.h"
 #include "s2io-regs.h"
 
-#define DRV_VERSION "2.0.23.1"
+#define DRV_VERSION "2.0.25.1"
 
 /* S2io Driver name & version. */
 static char s2io_driver_name[] = "Neterion";
@@ -282,6 +282,7 @@ static char ethtool_driver_stats_keys[][ETH_GSTRING_LEN] = {
        ("lro_flush_due_to_max_pkts"),
        ("lro_avg_aggr_pkts"),
        ("mem_alloc_fail_cnt"),
+       ("pci_map_fail_cnt"),
        ("watchdog_timer_cnt"),
        ("mem_allocated"),
        ("mem_freed"),
@@ -426,7 +427,7 @@ S2IO_PARM_INT(bimodal, 0);
 S2IO_PARM_INT(l3l4hdr_size, 128);
 /* Frequency of Rx desc syncs expressed as power of 2 */
 S2IO_PARM_INT(rxsync_frequency, 3);
-/* Interrupt type. Values can be 0(INTA), 1(MSI), 2(MSI_X) */
+/* Interrupt type. Values can be 0(INTA), 2(MSI_X) */
 S2IO_PARM_INT(intr_type, 0);
 /* Large receive offload feature */
 S2IO_PARM_INT(lro, 0);
@@ -2271,6 +2272,7 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
        u64 Buffer0_ptr = 0, Buffer1_ptr = 0;
        struct RxD1 *rxdp1;
        struct RxD3 *rxdp3;
+       struct swStat *stats = &nic->mac_control.stats_info->sw_stat;
 
        mac_control = &nic->mac_control;
        config = &nic->config;
@@ -2360,6 +2362,11 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
                        rxdp1->Buffer0_ptr = pci_map_single
                            (nic->pdev, skb->data, size - NET_IP_ALIGN,
                                PCI_DMA_FROMDEVICE);
+                       if( (rxdp1->Buffer0_ptr == 0) ||
+                               (rxdp1->Buffer0_ptr ==
+                               DMA_ERROR_CODE))
+                               goto pci_map_failed;
+
                        rxdp->Control_2 = 
                                SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN);
 
@@ -2395,6 +2402,10 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
                                pci_dma_sync_single_for_device(nic->pdev,
                                (dma_addr_t) rxdp3->Buffer0_ptr,
                                    BUF0_LEN, PCI_DMA_FROMDEVICE);
+                       if( (rxdp3->Buffer0_ptr == 0) ||
+                               (rxdp3->Buffer0_ptr == DMA_ERROR_CODE))
+                               goto pci_map_failed;
+
                        rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
                        if (nic->rxd_mode == RXD_MODE_3B) {
                                /* Two buffer mode */
@@ -2407,12 +2418,22 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
                                (nic->pdev, skb->data, dev->mtu + 4,
                                                PCI_DMA_FROMDEVICE);
 
-                               /* Buffer-1 will be dummy buffer. Not used */
-                               if (!(rxdp3->Buffer1_ptr)) {
-                                       rxdp3->Buffer1_ptr =
+                               if( (rxdp3->Buffer2_ptr == 0) ||
+                                       (rxdp3->Buffer2_ptr == DMA_ERROR_CODE))
+                                       goto pci_map_failed;
+
+                               rxdp3->Buffer1_ptr =
                                                pci_map_single(nic->pdev,
                                                ba->ba_1, BUF1_LEN,
                                                PCI_DMA_FROMDEVICE);
+                               if( (rxdp3->Buffer1_ptr == 0) ||
+                                       (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) {
+                                       pci_unmap_single
+                                               (nic->pdev,
+                                               (dma_addr_t)rxdp3->Buffer2_ptr,
+                                               dev->mtu + 4,
+                                               PCI_DMA_FROMDEVICE);
+                                       goto pci_map_failed;
                                }
                                rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
                                rxdp->Control_2 |= SET_BUFFER2_SIZE_3
@@ -2451,6 +2472,11 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
        }
 
        return SUCCESS;
+pci_map_failed:
+       stats->pci_map_fail_cnt++;
+       stats->mem_freed += skb->truesize;
+       dev_kfree_skb_irq(skb);
+       return -ENOMEM;
 }
 
 static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
@@ -3356,23 +3382,8 @@ static void s2io_reset(struct s2io_nic * sp)
        /* Back up  the PCI-X CMD reg, dont want to lose MMRBC, OST settings */
        pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER, &(pci_cmd));
 
-       if (sp->device_type == XFRAME_II_DEVICE) {
-               int ret;
-               ret = pci_set_power_state(sp->pdev, 3);
-               if (!ret)
-                       ret = pci_set_power_state(sp->pdev, 0);
-               else {
-                       DBG_PRINT(ERR_DBG,"%s PME based SW_Reset failed!\n",
-                                       __FUNCTION__);
-                       goto old_way;
-               }
-               msleep(20);
-               goto new_way;
-       }
-old_way:
        val64 = SW_RESET_ALL;
        writeq(val64, &bar0->sw_reset);
-new_way:
        if (strstr(sp->product_name, "CX4")) {
                msleep(750);
        }
@@ -3662,56 +3673,6 @@ static void store_xmsi_data(struct s2io_nic *nic)
        }
 }
 
-int s2io_enable_msi(struct s2io_nic *nic)
-{
-       struct XENA_dev_config __iomem *bar0 = nic->bar0;
-       u16 msi_ctrl, msg_val;
-       struct config_param *config = &nic->config;
-       struct net_device *dev = nic->dev;
-       u64 val64, tx_mat, rx_mat;
-       int i, err;
-
-       val64 = readq(&bar0->pic_control);
-       val64 &= ~BIT(1);
-       writeq(val64, &bar0->pic_control);
-
-       err = pci_enable_msi(nic->pdev);
-       if (err) {
-               DBG_PRINT(ERR_DBG, "%s: enabling MSI failed\n",
-                         nic->dev->name);
-               return err;
-       }
-
-       /*
-        * Enable MSI and use MSI-1 in stead of the standard MSI-0
-        * for interrupt handling.
-        */
-       pci_read_config_word(nic->pdev, 0x4c, &msg_val);
-       msg_val ^= 0x1;
-       pci_write_config_word(nic->pdev, 0x4c, msg_val);
-       pci_read_config_word(nic->pdev, 0x4c, &msg_val);
-
-       pci_read_config_word(nic->pdev, 0x42, &msi_ctrl);
-       msi_ctrl |= 0x10;
-       pci_write_config_word(nic->pdev, 0x42, msi_ctrl);
-
-       /* program MSI-1 into all usable Tx_Mat and Rx_Mat fields */
-       tx_mat = readq(&bar0->tx_mat0_n[0]);
-       for (i=0; i<config->tx_fifo_num; i++) {
-               tx_mat |= TX_MAT_SET(i, 1);
-       }
-       writeq(tx_mat, &bar0->tx_mat0_n[0]);
-
-       rx_mat = readq(&bar0->rx_mat);
-       for (i=0; i<config->rx_ring_num; i++) {
-               rx_mat |= RX_MAT_SET(i, 1);
-       }
-       writeq(rx_mat, &bar0->rx_mat);
-
-       dev->irq = nic->pdev->irq;
-       return 0;
-}
-
 static int s2io_enable_msi_x(struct s2io_nic *nic)
 {
        struct XENA_dev_config __iomem *bar0 = nic->bar0;
@@ -3932,6 +3893,7 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
        struct mac_info *mac_control;
        struct config_param *config;
        int offload_type;
+       struct swStat *stats = &sp->mac_control.stats_info->sw_stat;
 
        mac_control = &sp->mac_control;
        config = &sp->config;
@@ -4016,11 +3978,18 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
                txdp->Buffer_Pointer = pci_map_single(sp->pdev,
                                        sp->ufo_in_band_v,
                                        sizeof(u64), PCI_DMA_TODEVICE);
+               if((txdp->Buffer_Pointer == 0) ||
+                       (txdp->Buffer_Pointer == DMA_ERROR_CODE))
+                       goto pci_map_failed;
                txdp++;
        }
 
        txdp->Buffer_Pointer = pci_map_single
            (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
+       if((txdp->Buffer_Pointer == 0) ||
+               (txdp->Buffer_Pointer == DMA_ERROR_CODE))
+               goto pci_map_failed;
+
        txdp->Host_Control = (unsigned long) skb;
        txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len);
        if (offload_type == SKB_GSO_UDP)
@@ -4076,6 +4045,13 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
        dev->trans_start = jiffies;
        spin_unlock_irqrestore(&sp->tx_lock, flags);
 
+       return 0;
+pci_map_failed:
+       stats->pci_map_fail_cnt++;
+       netif_stop_queue(dev);
+       stats->mem_freed += skb->truesize;
+       dev_kfree_skb(skb);
+       spin_unlock_irqrestore(&sp->tx_lock, flags);
        return 0;
 }
 
@@ -4117,39 +4093,6 @@ static int s2io_chk_rx_buffers(struct s2io_nic *sp, int rng_n)
        return 0;
 }
 
-static irqreturn_t s2io_msi_handle(int irq, void *dev_id)
-{
-       struct net_device *dev = (struct net_device *) dev_id;
-       struct s2io_nic *sp = dev->priv;
-       int i;
-       struct mac_info *mac_control;
-       struct config_param *config;
-
-       atomic_inc(&sp->isr_cnt);
-       mac_control = &sp->mac_control;
-       config = &sp->config;
-       DBG_PRINT(INTR_DBG, "%s: MSI handler\n", __FUNCTION__);
-
-       /* If Intr is because of Rx Traffic */
-       for (i = 0; i < config->rx_ring_num; i++)
-               rx_intr_handler(&mac_control->rings[i]);
-
-       /* If Intr is because of Tx Traffic */
-       for (i = 0; i < config->tx_fifo_num; i++)
-               tx_intr_handler(&mac_control->fifos[i]);
-
-       /*
-        * If the Rx buffer count is below the panic threshold then
-        * reallocate the buffers from the interrupt handler itself,
-        * else schedule a tasklet to reallocate the buffers.
-        */
-       for (i = 0; i < config->rx_ring_num; i++)
-               s2io_chk_rx_buffers(sp, i);
-
-       atomic_dec(&sp->isr_cnt);
-       return IRQ_HANDLED;
-}
-
 static irqreturn_t s2io_msix_ring_handle(int irq, void *dev_id)
 {
        struct ring_info *ring = (struct ring_info *)dev_id;
@@ -4860,15 +4803,15 @@ static void s2io_ethtool_gringparam(struct net_device *dev,
                ering->rx_max_pending = MAX_RX_DESC_2;
 
        ering->tx_max_pending = MAX_TX_DESC;
-       for (i = 0 ; i < sp->config.tx_fifo_num ; i++) {
+       for (i = 0 ; i < sp->config.tx_fifo_num ; i++) 
                tx_desc_count += sp->config.tx_cfg[i].fifo_len;
-       }
+       
        DBG_PRINT(INFO_DBG,"\nmax txds : %d\n",sp->config.max_txds);
        ering->tx_pending = tx_desc_count;
        rx_desc_count = 0;
-       for (i = 0 ; i < sp->config.rx_ring_num ; i++) {
+       for (i = 0 ; i < sp->config.rx_ring_num ; i++) 
                rx_desc_count += sp->config.rx_cfg[i].num_rxd;
-       }
+
        ering->rx_pending = rx_desc_count;
 
        ering->rx_mini_max_pending = 0;
@@ -5852,6 +5795,7 @@ static void s2io_get_ethtool_stats(struct net_device *dev,
        else
                tmp_stats[i++] = 0;
        tmp_stats[i++] = stat_info->sw_stat.mem_alloc_fail_cnt;
+       tmp_stats[i++] = stat_info->sw_stat.pci_map_fail_cnt;
        tmp_stats[i++] = stat_info->sw_stat.watchdog_timer_cnt;
        tmp_stats[i++] = stat_info->sw_stat.mem_allocated;
        tmp_stats[i++] = stat_info->sw_stat.mem_freed;
@@ -6195,6 +6139,7 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
                                u64 *temp2, int size)
 {
        struct net_device *dev = sp->dev;
+       struct swStat *stats = &sp->mac_control.stats_info->sw_stat;
 
        if ((sp->rxd_mode == RXD_MODE_1) && (rxdp->Host_Control == 0)) {
                struct RxD1 *rxdp1 = (struct RxD1 *)rxdp;
@@ -6227,6 +6172,10 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
                                pci_map_single( sp->pdev, (*skb)->data,
                                        size - NET_IP_ALIGN,
                                        PCI_DMA_FROMDEVICE);
+                       if( (rxdp1->Buffer0_ptr == 0) ||
+                               (rxdp1->Buffer0_ptr == DMA_ERROR_CODE)) {
+                               goto memalloc_failed;
+                       }
                        rxdp->Host_Control = (unsigned long) (*skb);
                }
        } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) {
@@ -6252,19 +6201,46 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
                                pci_map_single(sp->pdev, (*skb)->data,
                                               dev->mtu + 4,
                                               PCI_DMA_FROMDEVICE);
+                       if( (rxdp3->Buffer2_ptr == 0) ||
+                               (rxdp3->Buffer2_ptr == DMA_ERROR_CODE)) {
+                               goto memalloc_failed;
+                       }
                        rxdp3->Buffer0_ptr = *temp0 =
                                pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN,
                                                PCI_DMA_FROMDEVICE);
+                       if( (rxdp3->Buffer0_ptr == 0) ||
+                               (rxdp3->Buffer0_ptr == DMA_ERROR_CODE)) {
+                               pci_unmap_single (sp->pdev,
+                                       (dma_addr_t)rxdp3->Buffer2_ptr,
+                                       dev->mtu + 4, PCI_DMA_FROMDEVICE);
+                               goto memalloc_failed;
+                       }
                        rxdp->Host_Control = (unsigned long) (*skb);
 
                        /* Buffer-1 will be dummy buffer not used */
                        rxdp3->Buffer1_ptr = *temp1 =
                                pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN,
                                                PCI_DMA_FROMDEVICE);
+                       if( (rxdp3->Buffer1_ptr == 0) ||
+                               (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) {
+                               pci_unmap_single (sp->pdev,
+                                       (dma_addr_t)rxdp3->Buffer0_ptr,
+                                       BUF0_LEN, PCI_DMA_FROMDEVICE);
+                               pci_unmap_single (sp->pdev,
+                                       (dma_addr_t)rxdp3->Buffer2_ptr,
+                                       dev->mtu + 4, PCI_DMA_FROMDEVICE);
+                               goto memalloc_failed;
+                       }
                }
        }
        return 0;
+       memalloc_failed:
+               stats->pci_map_fail_cnt++;
+               stats->mem_freed += (*skb)->truesize;
+               dev_kfree_skb(*skb);
+               return -ENOMEM;
 }
+
 static void set_rxd_buffer_size(struct s2io_nic *sp, struct RxD_t *rxdp,
                                int size)
 {
@@ -6332,9 +6308,7 @@ static int s2io_add_isr(struct s2io_nic * sp)
        struct net_device *dev = sp->dev;
        int err = 0;
 
-       if (sp->intr_type == MSI)
-               ret = s2io_enable_msi(sp);
-       else if (sp->intr_type == MSI_X)
+       if (sp->intr_type == MSI_X)
                ret = s2io_enable_msi_x(sp);
        if (ret) {
                DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
@@ -6345,16 +6319,6 @@ static int s2io_add_isr(struct s2io_nic * sp)
        store_xmsi_data(sp);
 
        /* After proper initialization of H/W, register ISR */
-       if (sp->intr_type == MSI) {
-               err = request_irq((int) sp->pdev->irq, s2io_msi_handle,
-                       IRQF_SHARED, sp->name, dev);
-               if (err) {
-                       pci_disable_msi(sp->pdev);
-                       DBG_PRINT(ERR_DBG, "%s: MSI registration failed\n",
-                                 dev->name);
-                       return -1;
-               }
-       }
        if (sp->intr_type == MSI_X) {
                int i, msix_tx_cnt=0,msix_rx_cnt=0;
 
@@ -6441,14 +6405,6 @@ static void s2io_rem_isr(struct s2io_nic * sp)
                pci_disable_msix(sp->pdev);
        } else {
                free_irq(sp->pdev->irq, dev);
-               if (sp->intr_type == MSI) {
-                       u16 val;
-
-                       pci_disable_msi(sp->pdev);
-                       pci_read_config_word(sp->pdev, 0x4c, &val);
-                       val ^= 0x1;
-                       pci_write_config_word(sp->pdev, 0x4c, val);
-               }
        }
        /* Waiting till all Interrupt handlers are complete */
        cnt = 0;
@@ -6781,6 +6737,7 @@ static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
        }
 
        /* Updating statistics */
+       sp->stats.rx_packets++;
        rxdp->Host_Control = 0;
        if (sp->rxd_mode == RXD_MODE_1) {
                int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2);
@@ -6994,7 +6951,7 @@ static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type)
                *dev_intr_type = INTA;
        }
 #else
-       if (*dev_intr_type > MSI_X) {
+       if ((*dev_intr_type != INTA) && (*dev_intr_type != MSI_X)) {
                DBG_PRINT(ERR_DBG, "s2io: Wrong intr_type requested. "
                          "Defaulting to INTA\n");
                *dev_intr_type = INTA;
@@ -7103,28 +7060,10 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
                pci_disable_device(pdev);
                return -ENOMEM;
        }
-       if (dev_intr_type != MSI_X) {
-               if (pci_request_regions(pdev, s2io_driver_name)) {
-                       DBG_PRINT(ERR_DBG, "Request Regions failed\n");
-                       pci_disable_device(pdev);
-                       return -ENODEV;
-               }
-       }
-       else {
-               if (!(request_mem_region(pci_resource_start(pdev, 0),
-                                pci_resource_len(pdev, 0), s2io_driver_name))) {
-                       DBG_PRINT(ERR_DBG, "bar0 Request Regions failed\n");
-                       pci_disable_device(pdev);
-                       return -ENODEV;
-               }
-               if (!(request_mem_region(pci_resource_start(pdev, 2),
-                                pci_resource_len(pdev, 2), s2io_driver_name))) {
-                       DBG_PRINT(ERR_DBG, "bar1 Request Regions failed\n");
-                       release_mem_region(pci_resource_start(pdev, 0),
-                                   pci_resource_len(pdev, 0));
-                       pci_disable_device(pdev);
-                       return -ENODEV;
-               }
+       if ((ret = pci_request_regions(pdev, s2io_driver_name))) {
+               DBG_PRINT(ERR_DBG, "%s: Request Regions failed - %x \n", __FUNCTION__, ret);
+               pci_disable_device(pdev);
+               return -ENODEV;
        }
 
        dev = alloc_etherdev(sizeof(struct s2io_nic));
@@ -7434,9 +7373,6 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
                case INTA:
                    DBG_PRINT(ERR_DBG, "%s: Interrupt type INTA\n", dev->name);
                    break;
-               case MSI:
-                   DBG_PRINT(ERR_DBG, "%s: Interrupt type MSI\n", dev->name);
-                   break;
                case MSI_X:
                    DBG_PRINT(ERR_DBG, "%s: Interrupt type MSI-X\n", dev->name);
                    break;
@@ -7476,14 +7412,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
       mem_alloc_failed:
        free_shared_mem(sp);
        pci_disable_device(pdev);
-       if (dev_intr_type != MSI_X)
-               pci_release_regions(pdev);
-       else {
-               release_mem_region(pci_resource_start(pdev, 0),
-                       pci_resource_len(pdev, 0));
-               release_mem_region(pci_resource_start(pdev, 2),
-                       pci_resource_len(pdev, 2));
-       }
+       pci_release_regions(pdev);
        pci_set_drvdata(pdev, NULL);
        free_netdev(dev);
 
@@ -7518,14 +7447,7 @@ static void __devexit s2io_rem_nic(struct pci_dev *pdev)
        free_shared_mem(sp);
        iounmap(sp->bar0);
        iounmap(sp->bar1);
-       if (sp->intr_type != MSI_X)
-               pci_release_regions(pdev);
-       else {
-               release_mem_region(pci_resource_start(pdev, 0),
-                       pci_resource_len(pdev, 0));
-               release_mem_region(pci_resource_start(pdev, 2),
-                       pci_resource_len(pdev, 2));
-       }
+       pci_release_regions(pdev);
        pci_set_drvdata(pdev, NULL);
        free_netdev(dev);
        pci_disable_device(pdev);