include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / firewire / net.c
index 47dcb45..7142eee 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/mutex.h>
 #include <linux/netdevice.h>
 #include <linux/skbuff.h>
+#include <linux/slab.h>
 #include <linux/spinlock.h>
 
 #include <asm/unaligned.h>
@@ -663,8 +664,6 @@ static int fwnet_finish_incoming_packet(struct net_device *net,
        if (netif_queue_stopped(net))
                netif_wake_queue(net);
 
-       net->last_rx = jiffies;
-
        return 0;
 }
 
@@ -810,29 +809,27 @@ static void fwnet_receive_packet(struct fw_card *card, struct fw_request *r,
                int speed, unsigned long long offset, void *payload,
                size_t length, void *callback_data)
 {
-       struct fwnet_device *dev;
-       int status;
+       struct fwnet_device *dev = callback_data;
+       int rcode;
 
-       dev = callback_data;
-       if (tcode != TCODE_WRITE_BLOCK_REQUEST
-           || destination != card->node_id     /* <- FIXME */
-           || generation != card->generation   /* <- FIXME */
-           || offset != dev->handler.offset) {
-               fw_send_response(card, r, RCODE_CONFLICT_ERROR);
+       if (destination == IEEE1394_ALL_NODES) {
+               kfree(r);
 
                return;
        }
 
-       status = fwnet_incoming_packet(dev, payload, length,
-                                      source, generation, false);
-       if (status != 0) {
+       if (offset != dev->handler.offset)
+               rcode = RCODE_ADDRESS_ERROR;
+       else if (tcode != TCODE_WRITE_BLOCK_REQUEST)
+               rcode = RCODE_TYPE_ERROR;
+       else if (fwnet_incoming_packet(dev, payload, length,
+                                      source, generation, false) != 0) {
                fw_error("Incoming packet failure\n");
-               fw_send_response(card, r, RCODE_CONFLICT_ERROR);
+               rcode = RCODE_CONFLICT_ERROR;
+       } else
+               rcode = RCODE_COMPLETE;
 
-               return;
-       }
-
-       fw_send_response(card, r, RCODE_COMPLETE);
+       fw_send_response(card, r, rcode);
 }
 
 static void fwnet_receive_broadcast(struct fw_iso_context *context,
@@ -897,20 +894,31 @@ static void fwnet_receive_broadcast(struct fw_iso_context *context,
 
 static struct kmem_cache *fwnet_packet_task_cache;
 
+static void fwnet_free_ptask(struct fwnet_packet_task *ptask)
+{
+       dev_kfree_skb_any(ptask->skb);
+       kmem_cache_free(fwnet_packet_task_cache, ptask);
+}
+
 static int fwnet_send_packet(struct fwnet_packet_task *ptask);
 
 static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
 {
-       struct fwnet_device *dev;
+       struct fwnet_device *dev = ptask->dev;
        unsigned long flags;
-
-       dev = ptask->dev;
+       bool free;
 
        spin_lock_irqsave(&dev->lock, flags);
-       list_del(&ptask->pt_link);
-       spin_unlock_irqrestore(&dev->lock, flags);
 
-       ptask->outstanding_pkts--; /* FIXME access inside lock */
+       ptask->outstanding_pkts--;
+
+       /* Check whether we or the networking TX soft-IRQ is last user. */
+       free = (ptask->outstanding_pkts == 0 && !list_empty(&ptask->pt_link));
+
+       if (ptask->outstanding_pkts == 0)
+               list_del(&ptask->pt_link);
+
+       spin_unlock_irqrestore(&dev->lock, flags);
 
        if (ptask->outstanding_pkts > 0) {
                u16 dg_size;
@@ -955,10 +963,10 @@ static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
                        ptask->max_payload = skb->len + RFC2374_FRAG_HDR_SIZE;
                }
                fwnet_send_packet(ptask);
-       } else {
-               dev_kfree_skb_any(ptask->skb);
-               kmem_cache_free(fwnet_packet_task_cache, ptask);
        }
+
+       if (free)
+               fwnet_free_ptask(ptask);
 }
 
 static void fwnet_write_complete(struct fw_card *card, int rcode,
@@ -981,6 +989,7 @@ static int fwnet_send_packet(struct fwnet_packet_task *ptask)
        unsigned tx_len;
        struct rfc2734_header *bufhdr;
        unsigned long flags;
+       bool free;
 
        dev = ptask->dev;
        tx_len = ptask->max_payload;
@@ -1026,12 +1035,16 @@ static int fwnet_send_packet(struct fwnet_packet_task *ptask)
                                generation, SCODE_100, 0ULL, ptask->skb->data,
                                tx_len + 8, fwnet_write_complete, ptask);
 
-               /* FIXME race? */
                spin_lock_irqsave(&dev->lock, flags);
-               list_add_tail(&ptask->pt_link, &dev->broadcasted_list);
+
+               /* If the AT tasklet already ran, we may be last user. */
+               free = (ptask->outstanding_pkts == 0 && list_empty(&ptask->pt_link));
+               if (!free)
+                       list_add_tail(&ptask->pt_link, &dev->broadcasted_list);
+
                spin_unlock_irqrestore(&dev->lock, flags);
 
-               return 0;
+               goto out;
        }
 
        fw_send_request(dev->card, &ptask->transaction,
@@ -1039,12 +1052,19 @@ static int fwnet_send_packet(struct fwnet_packet_task *ptask)
                        ptask->generation, ptask->speed, ptask->fifo_addr,
                        ptask->skb->data, tx_len, fwnet_write_complete, ptask);
 
-       /* FIXME race? */
        spin_lock_irqsave(&dev->lock, flags);
-       list_add_tail(&ptask->pt_link, &dev->sent_list);
+
+       /* If the AT tasklet already ran, we may be last user. */
+       free = (ptask->outstanding_pkts == 0 && list_empty(&ptask->pt_link));
+       if (!free)
+               list_add_tail(&ptask->pt_link, &dev->sent_list);
+
        spin_unlock_irqrestore(&dev->lock, flags);
 
        dev->netdev->trans_start = jiffies;
+ out:
+       if (free)
+               fwnet_free_ptask(ptask);
 
        return 0;
 }
@@ -1190,7 +1210,7 @@ static int fwnet_stop(struct net_device *net)
        return 0;
 }
 
-static int fwnet_tx(struct sk_buff *skb, struct net_device *net)
+static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)
 {
        struct fwnet_header hdr_buf;
        struct fwnet_device *dev = netdev_priv(net);
@@ -1302,6 +1322,8 @@ static int fwnet_tx(struct sk_buff *skb, struct net_device *net)
        spin_unlock_irqrestore(&dev->lock, flags);
 
        ptask->max_payload = max_payload;
+       INIT_LIST_HEAD(&ptask->pt_link);
+
        fwnet_send_packet(ptask);
 
        return NETDEV_TX_OK;
@@ -1344,7 +1366,7 @@ static void fwnet_get_drvinfo(struct net_device *net,
        strcpy(info->bus_info, "ieee1394");
 }
 
-static struct ethtool_ops fwnet_ethtool_ops = {
+static const struct ethtool_ops fwnet_ethtool_ops = {
        .get_drvinfo = fwnet_get_drvinfo,
 };