]> bbs.cooldavid.org Git - jme.git/blobdiff - jme.c
Import jme 1.0.4-backport source
[jme.git] / jme.c
diff --git a/jme.c b/jme.c
index 5f9a1313fa3e3cd13b64f37c21373ce0cb3e6a5a..83eb75a1d6a04ce5df1f605871a25d4232a80100 100644 (file)
--- a/jme.c
+++ b/jme.c
@@ -21,7 +21,6 @@
  *
  */
 
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
@@ -38,6 +37,7 @@
 #include <linux/tcp.h>
 #include <linux/udp.h>
 #include <linux/if_vlan.h>
+#include <net/ip6_checksum.h>
 #include "jme.h"
 
 static int force_pseudohp = -1;
@@ -429,21 +429,23 @@ jme_check_link(struct net_device *netdev, int testonly)
 
                jme->phylink = phylink;
 
-               ghc = jme->reg_ghc & ~(GHC_SPEED_10M |
-                                       GHC_SPEED_100M |
-                                       GHC_SPEED_1000M |
-                                       GHC_DPX);
+               ghc = jme->reg_ghc & ~(GHC_SPEED | GHC_DPX |
+                               GHC_TO_CLK_PCIE | GHC_TXMAC_CLK_PCIE |
+                               GHC_TO_CLK_GPHY | GHC_TXMAC_CLK_GPHY);
                switch (phylink & PHY_LINK_SPEED_MASK) {
                case PHY_LINK_SPEED_10M:
-                       ghc |= GHC_SPEED_10M;
+                       ghc |= GHC_SPEED_10M |
+                               GHC_TO_CLK_PCIE | GHC_TXMAC_CLK_PCIE;
                        strcat(linkmsg, "10 Mbps, ");
                        break;
                case PHY_LINK_SPEED_100M:
-                       ghc |= GHC_SPEED_100M;
+                       ghc |= GHC_SPEED_100M |
+                               GHC_TO_CLK_PCIE | GHC_TXMAC_CLK_PCIE;
                        strcat(linkmsg, "100 Mbps, ");
                        break;
                case PHY_LINK_SPEED_1000M:
-                       ghc |= GHC_SPEED_1000M;
+                       ghc |= GHC_SPEED_1000M |
+                               GHC_TO_CLK_GPHY | GHC_TXMAC_CLK_GPHY;
                        strcat(linkmsg, "1000 Mbps, ");
                        break;
                default:
@@ -463,14 +465,6 @@ jme_check_link(struct net_device *netdev, int testonly)
                                TXTRHD_TXREN |
                                ((8 << TXTRHD_TXRL_SHIFT) & TXTRHD_TXRL));
                }
-               strcat(linkmsg, (phylink & PHY_LINK_DUPLEX) ?
-                                       "Full-Duplex, " :
-                                       "Half-Duplex, ");
-
-               if (phylink & PHY_LINK_MDI_STAT)
-                       strcat(linkmsg, "MDI-X");
-               else
-                       strcat(linkmsg, "MDI");
 
                gpreg1 = GPREG1_DEFAULT;
                if (is_buggy250(jme->pdev->device, jme->chiprev)) {
@@ -492,11 +486,17 @@ jme_check_link(struct net_device *netdev, int testonly)
                                break;
                        }
                }
-               jwrite32(jme, JME_GPREG1, gpreg1);
 
-               jme->reg_ghc = ghc;
+               jwrite32(jme, JME_GPREG1, gpreg1);
                jwrite32(jme, JME_GHC, ghc);
+               jme->reg_ghc = ghc;
 
+               strcat(linkmsg, (phylink & PHY_LINK_DUPLEX) ?
+                                       "Full-Duplex, " :
+                                       "Half-Duplex, ");
+               strcat(linkmsg, (phylink & PHY_LINK_MDI_STAT) ?
+                                       "MDI-X" :
+                                       "MDI");
                msg_link(jme, "Link is up at %s.\n", linkmsg);
                netif_carrier_on(netdev);
        } else {
@@ -682,6 +682,9 @@ jme_make_new_rx_buf(struct jme_adapter *jme, int i)
                jme->dev->mtu + RX_EXTRA_LEN);
        if (unlikely(!skb))
                return -ENOMEM;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
+       skb->dev = jme->dev;
+#endif
 
        rxbi->skb = skb;
        rxbi->len = skb_tailroom(skb);
@@ -912,26 +915,25 @@ jme_alloc_and_feed_skb(struct jme_adapter *jme, int idx)
                skb_put(skb, framesize);
                skb->protocol = eth_type_trans(skb, jme->dev);
 
-               if (jme_rxsum_ok(jme, rxdesc->descwb.flags))
+               if (jme_rxsum_ok(jme, le16_to_cpu(rxdesc->descwb.flags)))
                        skb->ip_summed = CHECKSUM_UNNECESSARY;
                else
                        skb->ip_summed = CHECKSUM_NONE;
 
-               if (rxdesc->descwb.flags & RXWBFLAG_TAGON) {
+               if (rxdesc->descwb.flags & cpu_to_le16(RXWBFLAG_TAGON)) {
                        if (jme->vlgrp) {
                                jme->jme_vlan_rx(skb, jme->vlgrp,
-                                       le32_to_cpu(rxdesc->descwb.vlan));
+                                       le16_to_cpu(rxdesc->descwb.vlan));
                                NET_STAT(jme).rx_bytes += 4;
                        }
                } else {
                        jme->jme_rx(skb);
                }
 
-               if ((le16_to_cpu(rxdesc->descwb.flags) & RXWBFLAG_DEST) ==
-                               RXWBFLAG_DEST_MUL)
+               if ((rxdesc->descwb.flags & cpu_to_le16(RXWBFLAG_DEST)) ==
+                   cpu_to_le16(RXWBFLAG_DEST_MUL))
                        ++(NET_STAT(jme).multicast);
 
-               jme->dev->last_rx = jiffies;
                NET_STAT(jme).rx_bytes += framesize;
                ++(NET_STAT(jme).rx_packets);
        }
@@ -961,7 +963,7 @@ jme_process_receive(struct jme_adapter *jme, int limit)
                rxdesc = rxring->desc;
                rxdesc += i;
 
-               if ((rxdesc->descwb.flags & RXWBFLAG_OWN) ||
+               if ((rxdesc->descwb.flags & cpu_to_le16(RXWBFLAG_OWN)) ||
                !(rxdesc->descwb.desccnt & RXWBDCNT_WBCPL))
                        goto out;
 
@@ -1250,7 +1252,7 @@ static int
 jme_poll(JME_NAPI_HOLDER(holder), JME_NAPI_WEIGHT(budget))
 {
        struct jme_adapter *jme = jme_napi_priv(holder);
-       struct net_device *netdev = jme->dev;
+       DECLARE_NETDEV
        int rest;
 
        rest = jme_process_receive(jme, JME_NAPI_WEIGHT_VAL(budget));
@@ -1451,8 +1453,13 @@ out_reenable:
        jwrite32f(jme, JME_IENS, INTR_ENABLE);
 }
 
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
+static irqreturn_t
+jme_intr(int irq, void *dev_id, struct pt_regs *regs)
+#else
 static irqreturn_t
 jme_intr(int irq, void *dev_id)
+#endif
 {
        struct net_device *netdev = dev_id;
        struct jme_adapter *jme = netdev_priv(netdev);
@@ -1477,8 +1484,13 @@ jme_intr(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
+static irqreturn_t
+jme_msi(int irq, void *dev_id, struct pt_regs *regs)
+#else
 static irqreturn_t
 jme_msi(int irq, void *dev_id)
+#endif
 {
        struct net_device *netdev = dev_id;
        struct jme_adapter *jme = netdev_priv(netdev);
@@ -1519,8 +1531,13 @@ jme_request_irq(struct jme_adapter *jme)
 {
        int rc;
        struct net_device *netdev = jme->dev;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
+       irqreturn_t (*handler)(int, void *, struct pt_regs *) = jme_intr;
+       int irq_flags = SA_SHIRQ;
+#else
        irq_handler_t handler = jme_intr;
        int irq_flags = IRQF_SHARED;
+#endif
 
        if (!pci_enable_msi(jme->pdev)) {
                set_bit(JME_FLAG_MSI, &jme->flags);
@@ -1752,8 +1769,13 @@ jme_map_tx_skb(struct jme_adapter *jme, struct sk_buff *skb, int idx)
 static int
 jme_expand_header(struct jme_adapter *jme, struct sk_buff *skb)
 {
-       if (unlikely(skb_shinfo(skb)->gso_size &&
-                       skb_header_cloned(skb) &&
+       if (unlikely(
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,16)
+       skb_shinfo(skb)->tso_size
+#else
+       skb_shinfo(skb)->gso_size
+#endif
+                       && skb_header_cloned(skb) &&
                        pskb_expand_head(skb, 0, 0, GFP_ATOMIC))) {
                dev_kfree_skb(skb);
                return -1;
@@ -1763,10 +1785,13 @@ jme_expand_header(struct jme_adapter *jme, struct sk_buff *skb)
 }
 
 static int
-jme_tx_tso(struct sk_buff *skb,
-               u16 *mss, u8 *flags)
+jme_tx_tso(struct sk_buff *skb, __le16 *mss, u8 *flags)
 {
-       *mss = skb_shinfo(skb)->gso_size << TXDESC_MSS_SHIFT;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,16)
+       *mss = cpu_to_le16(skb_shinfo(skb)->tso_size << TXDESC_MSS_SHIFT);
+#else
+       *mss = cpu_to_le16(skb_shinfo(skb)->gso_size << TXDESC_MSS_SHIFT);
+#endif
        if (*mss) {
                *flags |= TXFLAG_LSEN;
 
@@ -1796,9 +1821,22 @@ jme_tx_tso(struct sk_buff *skb,
 static void
 jme_tx_csum(struct jme_adapter *jme, struct sk_buff *skb, u8 *flags)
 {
-       if (skb->ip_summed == CHECKSUM_PARTIAL) {
+#ifdef CHECKSUM_PARTIAL
+       if (skb->ip_summed == CHECKSUM_PARTIAL)
+#else
+       if (skb->ip_summed == CHECKSUM_HW)
+#endif
+       {
                u8 ip_proto;
 
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21)
+               if (skb->protocol == htons(ETH_P_IP))
+                       ip_proto = ip_hdr(skb)->protocol;
+               else if (skb->protocol == htons(ETH_P_IPV6))
+                       ip_proto = ipv6_hdr(skb)->nexthdr;
+               else
+                       ip_proto = 0;
+#else
                switch (skb->protocol) {
                case htons(ETH_P_IP):
                        ip_proto = ip_hdr(skb)->protocol;
@@ -1810,6 +1848,7 @@ jme_tx_csum(struct jme_adapter *jme, struct sk_buff *skb, u8 *flags)
                        ip_proto = 0;
                        break;
                }
+#endif
 
                switch (ip_proto) {
                case IPPROTO_TCP:
@@ -1826,16 +1865,16 @@ jme_tx_csum(struct jme_adapter *jme, struct sk_buff *skb, u8 *flags)
 }
 
 static inline void
-jme_tx_vlan(struct sk_buff *skb, u16 *vlan, u8 *flags)
+jme_tx_vlan(struct sk_buff *skb, __le16 *vlan, u8 *flags)
 {
        if (vlan_tx_tag_present(skb)) {
                *flags |= TXFLAG_TAGON;
-               *vlan = vlan_tx_tag_get(skb);
+               *vlan = cpu_to_le16(vlan_tx_tag_get(skb));
        }
 }
 
 static int
-jme_fill_first_tx_desc(struct jme_adapter *jme, struct sk_buff *skb, int idx)
+jme_fill_tx_desc(struct jme_adapter *jme, struct sk_buff *skb, int idx)
 {
        struct jme_ring *txring = jme->txring;
        struct txdesc *txdesc;
@@ -1865,6 +1904,7 @@ jme_fill_first_tx_desc(struct jme_adapter *jme, struct sk_buff *skb, int idx)
        if (jme_tx_tso(skb, &txdesc->desc1.mss, &flags))
                jme_tx_csum(jme, skb, &flags);
        jme_tx_vlan(skb, &txdesc->desc1.vlan, &flags);
+       jme_map_tx_skb(jme, skb, idx);
        txdesc->desc1.flags = flags;
        /*
         * Set tx buffer info after telling NIC to send
@@ -1934,8 +1974,7 @@ jme_start_xmit(struct sk_buff *skb, struct net_device *netdev)
                return NETDEV_TX_BUSY;
        }
 
-       jme_map_tx_skb(jme, skb, idx);
-       jme_fill_first_tx_desc(jme, skb, idx);
+       jme_fill_tx_desc(jme, skb, idx);
 
        jwrite32(jme, JME_TXCS, jme->reg_txcs |
                                TXCS_SELECT_QUEUE0 |
@@ -2039,13 +2078,20 @@ jme_change_mtu(struct net_device *netdev, int new_mtu)
 
        if (new_mtu > 1900) {
                netdev->features &= ~(NETIF_F_HW_CSUM |
-                               NETIF_F_TSO |
-                               NETIF_F_TSO6);
+                               NETIF_F_TSO
+#ifdef NETIF_F_TSO6
+                               | NETIF_F_TSO6
+#endif
+                               );
        } else {
                if (test_bit(JME_FLAG_TXCSUM, &jme->flags))
                        netdev->features |= NETIF_F_HW_CSUM;
                if (test_bit(JME_FLAG_TSO, &jme->flags))
-                       netdev->features |= NETIF_F_TSO | NETIF_F_TSO6;
+                       netdev->features |= NETIF_F_TSO
+#ifdef NETIF_F_TSO6
+                               | NETIF_F_TSO6
+#endif
+                               ;
        }
 
        netdev->mtu = new_mtu;
@@ -2428,10 +2474,18 @@ jme_set_tso(struct net_device *netdev, u32 on)
        if (on) {
                set_bit(JME_FLAG_TSO, &jme->flags);
                if (netdev->mtu <= 1900)
-                       netdev->features |= NETIF_F_TSO | NETIF_F_TSO6;
+                       netdev->features |= NETIF_F_TSO
+#ifdef NETIF_F_TSO6
+                               | NETIF_F_TSO6
+#endif
+                               ;
        } else {
                clear_bit(JME_FLAG_TSO, &jme->flags);
-               netdev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
+               netdev->features &= ~(NETIF_F_TSO
+#ifdef NETIF_F_TSO6
+                               | NETIF_F_TSO6
+#endif
+                               );
        }
 
        return 0;
@@ -2563,7 +2617,11 @@ jme_set_eeprom(struct net_device *netdev,
        return 0;
 }
 
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
+static struct ethtool_ops jme_ethtool_ops = {
+#else
 static const struct ethtool_ops jme_ethtool_ops = {
+#endif
        .get_drvinfo            = jme_get_drvinfo,
        .get_regs_len           = jme_get_regs_len,
        .get_regs               = jme_get_regs,
@@ -2592,11 +2650,13 @@ static const struct ethtool_ops jme_ethtool_ops = {
 static int
 jme_pci_dma64(struct pci_dev *pdev)
 {
-       if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK))
+       if (pdev->device == PCI_DEVICE_ID_JMICRON_JMC250 &&
+           !pci_set_dma_mask(pdev, DMA_64BIT_MASK))
                if (!pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))
                        return 1;
 
-       if (!pci_set_dma_mask(pdev, DMA_40BIT_MASK))
+       if (pdev->device == PCI_DEVICE_ID_JMICRON_JMC250 &&
+           !pci_set_dma_mask(pdev, DMA_40BIT_MASK))
                if (!pci_set_consistent_dma_mask(pdev, DMA_40BIT_MASK))
                        return 1;
 
@@ -2627,6 +2687,20 @@ jme_check_hw_ver(struct jme_adapter *jme)
        jme->chiprev = (chipmode & CM_CHIPREV_MASK) >> CM_CHIPREV_SHIFT;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
+static const struct net_device_ops jme_netdev_ops = {
+       .ndo_open               = jme_open,
+       .ndo_stop               = jme_close,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_start_xmit         = jme_start_xmit,
+       .ndo_set_mac_address    = jme_set_macaddr,
+       .ndo_set_multicast_list = jme_set_multi,
+       .ndo_change_mtu         = jme_change_mtu,
+       .ndo_tx_timeout         = jme_tx_timeout,
+       .ndo_vlan_rx_register   = jme_vlan_rx_register,
+};
+#endif
+
 static int __devinit
 jme_init_one(struct pci_dev *pdev,
             const struct pci_device_id *ent)
@@ -2676,21 +2750,27 @@ jme_init_one(struct pci_dev *pdev,
                rc = -ENOMEM;
                goto err_out_release_regions;
        }
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
+       netdev->netdev_ops = &jme_netdev_ops;
+#else
        netdev->open                    = jme_open;
        netdev->stop                    = jme_close;
        netdev->hard_start_xmit         = jme_start_xmit;
        netdev->set_mac_address         = jme_set_macaddr;
        netdev->set_multicast_list      = jme_set_multi;
        netdev->change_mtu              = jme_change_mtu;
-       netdev->ethtool_ops             = &jme_ethtool_ops;
        netdev->tx_timeout              = jme_tx_timeout;
-       netdev->watchdog_timeo          = TX_TIMEOUT;
        netdev->vlan_rx_register        = jme_vlan_rx_register;
        NETDEV_GET_STATS(netdev, &jme_get_stats);
+#endif
+       netdev->ethtool_ops             = &jme_ethtool_ops;
+       netdev->watchdog_timeo          = TX_TIMEOUT;
        netdev->features                =       NETIF_F_HW_CSUM |
                                                NETIF_F_SG |
                                                NETIF_F_TSO |
+#ifdef NETIF_F_TSO6
                                                NETIF_F_TSO6 |
+#endif
                                                NETIF_F_HW_VLAN_TX |
                                                NETIF_F_HW_VLAN_RX;
        if (using_dac)
@@ -2709,10 +2789,16 @@ jme_init_one(struct pci_dev *pdev,
        jme->jme_vlan_rx = vlan_hwaccel_rx;
        jme->old_mtu = netdev->mtu = 1500;
        jme->phylink = 0;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21)
+       jme->tx_ring_size = 1 << 9;
+       jme->tx_wake_threshold = 1 << 8;
+       jme->rx_ring_size = 1 << 8;
+#else
        jme->tx_ring_size = 1 << 10;
-       jme->tx_ring_mask = jme->tx_ring_size - 1;
        jme->tx_wake_threshold = 1 << 9;
        jme->rx_ring_size = 1 << 9;
+#endif
+       jme->tx_ring_mask = jme->tx_ring_size - 1;
        jme->rx_ring_mask = jme->rx_ring_size - 1;
        jme->msg_enable = JME_DEF_MSG_ENABLE;
        jme->regs = ioremap(pci_resource_start(pdev, 0),
@@ -2862,18 +2948,14 @@ jme_init_one(struct pci_dev *pdev,
                goto err_out_free_shadow;
        }
 
-       msg_probe(jme,
-               "JMC250 gigabit%s ver:%x rev:%x "
-               "macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
+       msg_probe(jme, "%s%s ver:%x rev:%x macaddr:%pM\n",
+               (jme->pdev->device == PCI_DEVICE_ID_JMICRON_JMC250) ?
+                       "JMC250 Gigabit Ethernet" :
+                       (jme->pdev->device == PCI_DEVICE_ID_JMICRON_JMC260) ?
+                               "JMC260 Fast Ethernet" : "Unknown",
                (jme->fpgaver != 0) ? " (FPGA)" : "",
                (jme->fpgaver != 0) ? jme->fpgaver : jme->chiprev,
-               jme->rev,
-               netdev->dev_addr[0],
-               netdev->dev_addr[1],
-               netdev->dev_addr[2],
-               netdev->dev_addr[3],
-               netdev->dev_addr[4],
-               netdev->dev_addr[5]);
+               jme->rev, netdev->dev_addr);
 
        return 0;
 
@@ -3016,7 +3098,7 @@ static struct pci_driver jme_driver = {
 static int __init
 jme_init_module(void)
 {
-       printk(KERN_INFO PFX "JMicron JMC250 gigabit ethernet "
+       printk(KERN_INFO PFX "JMicron JMC2XX ethernet "
               "driver version %s\n", DRV_VERSION);
        return pci_register_driver(&jme_driver);
 }