CAN: add controller hardware name for Softing cards
[linux-2.6.git] / drivers / net / niu.c
index c0437fd..9fb59d3 100644 (file)
@@ -4489,6 +4489,9 @@ static int niu_alloc_channels(struct niu *np)
 {
        struct niu_parent *parent = np->parent;
        int first_rx_channel, first_tx_channel;
+       int num_rx_rings, num_tx_rings;
+       struct rx_ring_info *rx_rings;
+       struct tx_ring_info *tx_rings;
        int i, port, err;
 
        port = np->port;
@@ -4498,18 +4501,21 @@ static int niu_alloc_channels(struct niu *np)
                first_tx_channel += parent->txchan_per_port[i];
        }
 
-       np->num_rx_rings = parent->rxchan_per_port[port];
-       np->num_tx_rings = parent->txchan_per_port[port];
+       num_rx_rings = parent->rxchan_per_port[port];
+       num_tx_rings = parent->txchan_per_port[port];
 
-       netif_set_real_num_rx_queues(np->dev, np->num_rx_rings);
-       netif_set_real_num_tx_queues(np->dev, np->num_tx_rings);
-
-       np->rx_rings = kcalloc(np->num_rx_rings, sizeof(struct rx_ring_info),
-                              GFP_KERNEL);
+       rx_rings = kcalloc(num_rx_rings, sizeof(struct rx_ring_info),
+                          GFP_KERNEL);
        err = -ENOMEM;
-       if (!np->rx_rings)
+       if (!rx_rings)
                goto out_err;
 
+       np->num_rx_rings = num_rx_rings;
+       smp_wmb();
+       np->rx_rings = rx_rings;
+
+       netif_set_real_num_rx_queues(np->dev, num_rx_rings);
+
        for (i = 0; i < np->num_rx_rings; i++) {
                struct rx_ring_info *rp = &np->rx_rings[i];
 
@@ -4538,12 +4544,18 @@ static int niu_alloc_channels(struct niu *np)
                        return err;
        }
 
-       np->tx_rings = kcalloc(np->num_tx_rings, sizeof(struct tx_ring_info),
-                              GFP_KERNEL);
+       tx_rings = kcalloc(num_tx_rings, sizeof(struct tx_ring_info),
+                          GFP_KERNEL);
        err = -ENOMEM;
-       if (!np->tx_rings)
+       if (!tx_rings)
                goto out_err;
 
+       np->num_tx_rings = num_tx_rings;
+       smp_wmb();
+       np->tx_rings = tx_rings;
+
+       netif_set_real_num_tx_queues(np->dev, num_tx_rings);
+
        for (i = 0; i < np->num_tx_rings; i++) {
                struct tx_ring_info *rp = &np->tx_rings[i];
 
@@ -6246,11 +6258,17 @@ static void niu_sync_mac_stats(struct niu *np)
 static void niu_get_rx_stats(struct niu *np)
 {
        unsigned long pkts, dropped, errors, bytes;
+       struct rx_ring_info *rx_rings;
        int i;
 
        pkts = dropped = errors = bytes = 0;
+
+       rx_rings = ACCESS_ONCE(np->rx_rings);
+       if (!rx_rings)
+               goto no_rings;
+
        for (i = 0; i < np->num_rx_rings; i++) {
-               struct rx_ring_info *rp = &np->rx_rings[i];
+               struct rx_ring_info *rp = &rx_rings[i];
 
                niu_sync_rx_discard_stats(np, rp, 0);
 
@@ -6259,6 +6277,8 @@ static void niu_get_rx_stats(struct niu *np)
                dropped += rp->rx_dropped;
                errors += rp->rx_errors;
        }
+
+no_rings:
        np->dev->stats.rx_packets = pkts;
        np->dev->stats.rx_bytes = bytes;
        np->dev->stats.rx_dropped = dropped;
@@ -6268,16 +6288,24 @@ static void niu_get_rx_stats(struct niu *np)
 static void niu_get_tx_stats(struct niu *np)
 {
        unsigned long pkts, errors, bytes;
+       struct tx_ring_info *tx_rings;
        int i;
 
        pkts = errors = bytes = 0;
+
+       tx_rings = ACCESS_ONCE(np->tx_rings);
+       if (!tx_rings)
+               goto no_rings;
+
        for (i = 0; i < np->num_tx_rings; i++) {
-               struct tx_ring_info *rp = &np->tx_rings[i];
+               struct tx_ring_info *rp = &tx_rings[i];
 
                pkts += rp->tx_packets;
                bytes += rp->tx_bytes;
                errors += rp->tx_errors;
        }
+
+no_rings:
        np->dev->stats.tx_packets = pkts;
        np->dev->stats.tx_bytes = bytes;
        np->dev->stats.tx_errors = errors;
@@ -6287,9 +6315,10 @@ static struct net_device_stats *niu_get_stats(struct net_device *dev)
 {
        struct niu *np = netdev_priv(dev);
 
-       niu_get_rx_stats(np);
-       niu_get_tx_stats(np);
-
+       if (netif_running(dev)) {
+               niu_get_rx_stats(np);
+               niu_get_tx_stats(np);
+       }
        return &dev->stats;
 }
 
@@ -6589,7 +6618,7 @@ static u64 niu_compute_tx_flags(struct sk_buff *skb, struct ethhdr *ehdr,
                             (ip_proto == IPPROTO_UDP ?
                              TXHDR_CSUM_UDP : TXHDR_CSUM_SCTP));
 
-               start = skb_transport_offset(skb) -
+               start = skb_checksum_start_offset(skb) -
                        (pad_bytes + sizeof(struct tx_pkt_hdr));
                stuff = start + skb->csum_offset;
 
@@ -7090,24 +7119,20 @@ static int niu_get_hash_opts(struct niu *np, struct ethtool_rxnfc *nfc)
 static void niu_get_ip4fs_from_tcam_key(struct niu_tcam_entry *tp,
                                        struct ethtool_rx_flow_spec *fsp)
 {
+       u32 tmp;
+       u16 prt;
+
+       tmp = (tp->key[3] & TCAM_V4KEY3_SADDR) >> TCAM_V4KEY3_SADDR_SHIFT;
+       fsp->h_u.tcp_ip4_spec.ip4src = cpu_to_be32(tmp);
+
+       tmp = (tp->key[3] & TCAM_V4KEY3_DADDR) >> TCAM_V4KEY3_DADDR_SHIFT;
+       fsp->h_u.tcp_ip4_spec.ip4dst = cpu_to_be32(tmp);
+
+       tmp = (tp->key_mask[3] & TCAM_V4KEY3_SADDR) >> TCAM_V4KEY3_SADDR_SHIFT;
+       fsp->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(tmp);
 
-       fsp->h_u.tcp_ip4_spec.ip4src = (tp->key[3] & TCAM_V4KEY3_SADDR) >>
-               TCAM_V4KEY3_SADDR_SHIFT;
-       fsp->h_u.tcp_ip4_spec.ip4dst = (tp->key[3] & TCAM_V4KEY3_DADDR) >>
-               TCAM_V4KEY3_DADDR_SHIFT;
-       fsp->m_u.tcp_ip4_spec.ip4src = (tp->key_mask[3] & TCAM_V4KEY3_SADDR) >>
-               TCAM_V4KEY3_SADDR_SHIFT;
-       fsp->m_u.tcp_ip4_spec.ip4dst = (tp->key_mask[3] & TCAM_V4KEY3_DADDR) >>
-               TCAM_V4KEY3_DADDR_SHIFT;
-
-       fsp->h_u.tcp_ip4_spec.ip4src =
-               cpu_to_be32(fsp->h_u.tcp_ip4_spec.ip4src);
-       fsp->m_u.tcp_ip4_spec.ip4src =
-               cpu_to_be32(fsp->m_u.tcp_ip4_spec.ip4src);
-       fsp->h_u.tcp_ip4_spec.ip4dst =
-               cpu_to_be32(fsp->h_u.tcp_ip4_spec.ip4dst);
-       fsp->m_u.tcp_ip4_spec.ip4dst =
-               cpu_to_be32(fsp->m_u.tcp_ip4_spec.ip4dst);
+       tmp = (tp->key_mask[3] & TCAM_V4KEY3_DADDR) >> TCAM_V4KEY3_DADDR_SHIFT;
+       fsp->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(tmp);
 
        fsp->h_u.tcp_ip4_spec.tos = (tp->key[2] & TCAM_V4KEY2_TOS) >>
                TCAM_V4KEY2_TOS_SHIFT;
@@ -7118,54 +7143,40 @@ static void niu_get_ip4fs_from_tcam_key(struct niu_tcam_entry *tp,
        case TCP_V4_FLOW:
        case UDP_V4_FLOW:
        case SCTP_V4_FLOW:
-               fsp->h_u.tcp_ip4_spec.psrc =
-                       ((tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
-                        TCAM_V4KEY2_PORT_SPI_SHIFT) >> 16;
-               fsp->h_u.tcp_ip4_spec.pdst =
-                       ((tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
-                        TCAM_V4KEY2_PORT_SPI_SHIFT) & 0xffff;
-               fsp->m_u.tcp_ip4_spec.psrc =
-                       ((tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
-                        TCAM_V4KEY2_PORT_SPI_SHIFT) >> 16;
-               fsp->m_u.tcp_ip4_spec.pdst =
-                       ((tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
-                        TCAM_V4KEY2_PORT_SPI_SHIFT) & 0xffff;
+               prt = ((tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT) >> 16;
+               fsp->h_u.tcp_ip4_spec.psrc = cpu_to_be16(prt);
+
+               prt = ((tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT) & 0xffff;
+               fsp->h_u.tcp_ip4_spec.pdst = cpu_to_be16(prt);
 
-               fsp->h_u.tcp_ip4_spec.psrc =
-                       cpu_to_be16(fsp->h_u.tcp_ip4_spec.psrc);
-               fsp->h_u.tcp_ip4_spec.pdst =
-                       cpu_to_be16(fsp->h_u.tcp_ip4_spec.pdst);
-               fsp->m_u.tcp_ip4_spec.psrc =
-                       cpu_to_be16(fsp->m_u.tcp_ip4_spec.psrc);
-               fsp->m_u.tcp_ip4_spec.pdst =
-                       cpu_to_be16(fsp->m_u.tcp_ip4_spec.pdst);
+               prt = ((tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT) >> 16;
+               fsp->m_u.tcp_ip4_spec.psrc = cpu_to_be16(prt);
+
+               prt = ((tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
+                        TCAM_V4KEY2_PORT_SPI_SHIFT) & 0xffff;
+               fsp->m_u.tcp_ip4_spec.pdst = cpu_to_be16(prt);
                break;
        case AH_V4_FLOW:
        case ESP_V4_FLOW:
-               fsp->h_u.ah_ip4_spec.spi =
-                       (tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
-                       TCAM_V4KEY2_PORT_SPI_SHIFT;
-               fsp->m_u.ah_ip4_spec.spi =
-                       (tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
+               tmp = (tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
                        TCAM_V4KEY2_PORT_SPI_SHIFT;
+               fsp->h_u.ah_ip4_spec.spi = cpu_to_be32(tmp);
 
-               fsp->h_u.ah_ip4_spec.spi =
-                       cpu_to_be32(fsp->h_u.ah_ip4_spec.spi);
-               fsp->m_u.ah_ip4_spec.spi =
-                       cpu_to_be32(fsp->m_u.ah_ip4_spec.spi);
+               tmp = (tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT;
+               fsp->m_u.ah_ip4_spec.spi = cpu_to_be32(tmp);
                break;
        case IP_USER_FLOW:
-               fsp->h_u.usr_ip4_spec.l4_4_bytes =
-                       (tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
-                       TCAM_V4KEY2_PORT_SPI_SHIFT;
-               fsp->m_u.usr_ip4_spec.l4_4_bytes =
-                       (tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
+               tmp = (tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
                        TCAM_V4KEY2_PORT_SPI_SHIFT;
+               fsp->h_u.usr_ip4_spec.l4_4_bytes = cpu_to_be32(tmp);
 
-               fsp->h_u.usr_ip4_spec.l4_4_bytes =
-                       cpu_to_be32(fsp->h_u.usr_ip4_spec.l4_4_bytes);
-               fsp->m_u.usr_ip4_spec.l4_4_bytes =
-                       cpu_to_be32(fsp->m_u.usr_ip4_spec.l4_4_bytes);
+               tmp = (tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT;
+               fsp->m_u.usr_ip4_spec.l4_4_bytes = cpu_to_be32(tmp);
 
                fsp->h_u.usr_ip4_spec.proto =
                        (tp->key[2] & TCAM_V4KEY2_PROTO) >>
@@ -9935,7 +9946,7 @@ static int niu_suspend(struct pci_dev *pdev, pm_message_t state)
        if (!netif_running(dev))
                return 0;
 
-       flush_scheduled_work();
+       flush_work_sync(&np->reset_task);
        niu_netif_stop(np);
 
        del_timer_sync(&np->timer);