rt2x00: Move generic TX frame writing code into rt2x00queue
authorIvo van Doorn <IvDoorn@gmail.com>
Fri, 6 Jun 2008 20:50:28 +0000 (22:50 +0200)
committerJohn W. Linville <linville@tuxdriver.com>
Sat, 14 Jun 2008 16:17:56 +0000 (12:17 -0400)
The write_tx_data functions in rt2x00pci and rt2x00usb have
a lot in common. This moves that duplicate code into
rt2x00queue_write_tx_frame().

Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/rt2x00/rt2x00.h
drivers/net/wireless/rt2x00/rt2x00lib.h
drivers/net/wireless/rt2x00/rt2x00mac.c
drivers/net/wireless/rt2x00/rt2x00pci.c
drivers/net/wireless/rt2x00/rt2x00pci.h
drivers/net/wireless/rt2x00/rt2x00queue.c
drivers/net/wireless/rt2x00/rt2x00usb.c
drivers/net/wireless/rt2x00/rt2x00usb.h

index 2f79336297cac1422aab48776b25bf5ede8af4f1..c7da3c25237e86cff1454214848864040291d324 100644 (file)
@@ -546,8 +546,7 @@ struct rt2x00lib_ops {
        void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
                               struct sk_buff *skb,
                               struct txentry_desc *txdesc);
-       int (*write_tx_data) (struct rt2x00_dev *rt2x00dev,
-                             struct data_queue *queue, struct sk_buff *skb);
+       int (*write_tx_data) (struct queue_entry *entry);
        int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
                                struct sk_buff *skb);
        void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
index c4ce534e3cdbbac56c52177aa4bc02179da897aa..558f45bf27e33684825705d8dfd8489be80c9b25 100644 (file)
@@ -101,6 +101,7 @@ void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
 /*
  * Queue handlers.
  */
+int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb);
 void rt2x00queue_init_rx(struct rt2x00_dev *rt2x00dev);
 void rt2x00queue_init_tx(struct rt2x00_dev *rt2x00dev);
 int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev);
index 97d9095037b90c4bbe6c0c84b4537ca27c66a908..e7f544c404bcb9082f21196df27124bf599b6a6f 100644 (file)
@@ -89,7 +89,7 @@ static int rt2x00mac_tx_rts_cts(struct rt2x00_dev *rt2x00dev,
        memset(skbdesc, 0, sizeof(*skbdesc));
        skbdesc->flags |= FRAME_DESC_DRIVER_GENERATED;
 
-       if (rt2x00dev->ops->lib->write_tx_data(rt2x00dev, queue, skb)) {
+       if (rt2x00queue_write_tx_frame(queue, skb)) {
                WARNING(rt2x00dev, "Failed to send RTS/CTS frame.\n");
                return NETDEV_TX_BUSY;
        }
@@ -158,7 +158,7 @@ int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
                }
        }
 
-       if (rt2x00dev->ops->lib->write_tx_data(rt2x00dev, queue, skb)) {
+       if (rt2x00queue_write_tx_frame(queue, skb)) {
                ieee80211_stop_queue(rt2x00dev->hw, qid);
                return NETDEV_TX_BUSY;
        }
@@ -166,9 +166,6 @@ int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
        if (rt2x00queue_full(queue))
                ieee80211_stop_queue(rt2x00dev->hw, qid);
 
-       if (rt2x00dev->ops->lib->kick_tx_queue)
-               rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, qid);
-
        return NETDEV_TX_OK;
 }
 EXPORT_SYMBOL_GPL(rt2x00mac_tx);
index 70a3d135f64ec22fee19567322dc549771f34327..a6bac75de9f2c855698acadf2670a2264db49a79 100644 (file)
 /*
  * TX data handlers.
  */
-int rt2x00pci_write_tx_data(struct rt2x00_dev *rt2x00dev,
-                           struct data_queue *queue, struct sk_buff *skb)
+int rt2x00pci_write_tx_data(struct queue_entry *entry)
 {
-       struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX);
        struct queue_entry_priv_pci *entry_priv = entry->priv_data;
        struct skb_frame_desc *skbdesc;
-       struct txentry_desc txdesc;
        u32 word;
 
-       if (rt2x00queue_full(queue))
-               return -EINVAL;
-
        rt2x00_desc_read(entry_priv->desc, 0, &word);
 
-       if (rt2x00_get_field32(word, TXD_ENTRY_OWNER_NIC) ||
-           rt2x00_get_field32(word, TXD_ENTRY_VALID)) {
-               ERROR(rt2x00dev,
-                     "Arrived at non-free entry in the non-full queue %d.\n"
+       /*
+        * This should not happen, we already checked the entry
+        * was ours. When the hardware disagrees there has been
+        * a queue corruption!
+        */
+       if (unlikely(rt2x00_get_field32(word, TXD_ENTRY_OWNER_NIC) ||
+                    rt2x00_get_field32(word, TXD_ENTRY_VALID))) {
+               ERROR(entry->queue->rt2x00dev,
+                     "Corrupt queue %d, accessing entry which is not ours.\n"
                      "Please file bug report to %s.\n",
                      entry->queue->qid, DRV_PROJECT);
                return -EINVAL;
        }
 
-       /*
-        * Copy all TX descriptor information into txdesc,
-        * after that we are free to use the skb->cb array
-        * for our information.
-        */
-       entry->skb = skb;
-       rt2x00queue_create_tx_descriptor(entry, &txdesc);
-
        /*
         * Fill in skb descriptor
         */
-       skbdesc = get_skb_frame_desc(skb);
+       skbdesc = get_skb_frame_desc(entry->skb);
        memset(skbdesc, 0, sizeof(*skbdesc));
-       skbdesc->data = skb->data;
-       skbdesc->data_len = skb->len;
+       skbdesc->data = entry->skb->data;
+       skbdesc->data_len = entry->skb->len;
        skbdesc->desc = entry_priv->desc;
-       skbdesc->desc_len = queue->desc_size;
+       skbdesc->desc_len = entry->queue->desc_size;
        skbdesc->entry = entry;
 
-       memcpy(entry_priv->data, skb->data, skb->len);
-
-       rt2x00queue_write_tx_descriptor(entry, &txdesc);
-       rt2x00queue_index_inc(queue, Q_INDEX);
+       memcpy(entry_priv->data, entry->skb->data, entry->skb->len);
 
        return 0;
 }
@@ -178,6 +166,7 @@ void rt2x00pci_txdone(struct rt2x00_dev *rt2x00dev, struct queue_entry *entry,
        rt2x00_set_field32(&word, TXD_ENTRY_VALID, 0);
        rt2x00_desc_write(entry_priv->desc, 0, word);
 
+       __clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
        rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE);
 
        /*
index 37c851e442c166687a355abc1c72c3342494863c..87c4a0cd78db13c6e835d5ec2a23ef9cfcb7f47a 100644 (file)
@@ -87,11 +87,14 @@ rt2x00pci_register_multiwrite(struct rt2x00_dev *rt2x00dev,
        memcpy_toio(rt2x00dev->csr.base + offset, value, length);
 }
 
-/*
- * TX data handlers.
+/**
+ * rt2x00pci_write_tx_data - Initialize data for TX operation
+ * @entry: The entry where the frame is located
+ *
+ * This function will initialize the DMA and skb descriptor
+ * to prepare the entry for the actual TX operation.
  */
-int rt2x00pci_write_tx_data(struct rt2x00_dev *rt2x00dev,
-                           struct data_queue *queue, struct sk_buff *skb);
+int rt2x00pci_write_tx_data(struct queue_entry *entry);
 
 /**
  * struct queue_entry_priv_pci: Per entry PCI specific information
index 6f3aa0f71f9f4638c975a89586e7a604b405421d..f875b7ab09fe9bc741eb5885bc38dd1d03b57c0b 100644 (file)
@@ -188,6 +188,43 @@ void rt2x00queue_write_tx_descriptor(struct queue_entry *entry,
 }
 EXPORT_SYMBOL_GPL(rt2x00queue_write_tx_descriptor);
 
+int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb)
+{
+       struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX);
+       struct txentry_desc txdesc;
+
+       if (unlikely(rt2x00queue_full(queue)))
+               return -EINVAL;
+
+       if (__test_and_set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags)) {
+               ERROR(queue->rt2x00dev,
+                     "Arrived at non-free entry in the non-full queue %d.\n"
+                     "Please file bug report to %s.\n",
+                     queue->qid, DRV_PROJECT);
+               return -EINVAL;
+       }
+
+       /*
+        * Copy all TX descriptor information into txdesc,
+        * after that we are free to use the skb->cb array
+        * for our information.
+        */
+       entry->skb = skb;
+       rt2x00queue_create_tx_descriptor(entry, &txdesc);
+
+       if (unlikely(queue->rt2x00dev->ops->lib->write_tx_data(entry))) {
+               __clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
+               return -EIO;
+       }
+
+       __set_bit(ENTRY_DATA_PENDING, &entry->flags);
+
+       rt2x00queue_index_inc(queue, Q_INDEX);
+       rt2x00queue_write_tx_descriptor(entry, &txdesc);
+
+       return 0;
+}
+
 struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
                                         const enum data_queue_qid queue)
 {
index cdac9280fe4286f213b03f0624de8d54ce9a24a2..fdf505beb79c5ab9a73403fad102cb5e9fbef501 100644 (file)
@@ -173,71 +173,42 @@ static void rt2x00usb_interrupt_txdone(struct urb *urb)
                ieee80211_wake_queue(rt2x00dev->hw, qid);
 }
 
-int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
-                           struct data_queue *queue, struct sk_buff *skb)
+int rt2x00usb_write_tx_data(struct queue_entry *entry)
 {
+       struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
        struct usb_device *usb_dev = rt2x00dev_usb_dev(rt2x00dev);
-       struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX);
        struct queue_entry_priv_usb *entry_priv = entry->priv_data;
        struct skb_frame_desc *skbdesc;
-       struct txentry_desc txdesc;
        u32 length;
 
-       if (rt2x00queue_full(queue))
-               return -EINVAL;
-
-       if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags)) {
-               ERROR(rt2x00dev,
-                     "Arrived at non-free entry in the non-full queue %d.\n"
-                     "Please file bug report to %s.\n",
-                     entry->queue->qid, DRV_PROJECT);
-               return -EINVAL;
-       }
-
-       /*
-        * Copy all TX descriptor information into txdesc,
-        * after that we are free to use the skb->cb array
-        * for our information.
-        */
-       entry->skb = skb;
-       rt2x00queue_create_tx_descriptor(entry, &txdesc);
-
        /*
         * Add the descriptor in front of the skb.
         */
-       skb_push(skb, queue->desc_size);
-       memset(skb->data, 0, queue->desc_size);
+       skb_push(entry->skb, entry->queue->desc_size);
+       memset(entry->skb->data, 0, entry->queue->desc_size);
 
        /*
         * Fill in skb descriptor
         */
-       skbdesc = get_skb_frame_desc(skb);
+       skbdesc = get_skb_frame_desc(entry->skb);
        memset(skbdesc, 0, sizeof(*skbdesc));
-       skbdesc->data = skb->data + queue->desc_size;
-       skbdesc->data_len = skb->len - queue->desc_size;
-       skbdesc->desc = skb->data;
-       skbdesc->desc_len = queue->desc_size;
+       skbdesc->data = entry->skb->data + entry->queue->desc_size;
+       skbdesc->data_len = entry->skb->len - entry->queue->desc_size;
+       skbdesc->desc = entry->skb->data;
+       skbdesc->desc_len = entry->queue->desc_size;
        skbdesc->entry = entry;
 
-       rt2x00queue_write_tx_descriptor(entry, &txdesc);
-
        /*
         * USB devices cannot blindly pass the skb->len as the
         * length of the data to usb_fill_bulk_urb. Pass the skb
         * to the driver to determine what the length should be.
         */
-       length = rt2x00dev->ops->lib->get_tx_data_len(rt2x00dev, skb);
-
-       /*
-        * Initialize URB and send the frame to the device.
-        */
-       __set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
-       __set_bit(ENTRY_DATA_PENDING, &entry->flags);
+       length = rt2x00dev->ops->lib->get_tx_data_len(rt2x00dev, entry->skb);
 
-       usb_fill_bulk_urb(entry_priv->urb, usb_dev, usb_sndbulkpipe(usb_dev, 1),
-                         skb->data, length, rt2x00usb_interrupt_txdone, entry);
-
-       rt2x00queue_index_inc(queue, Q_INDEX);
+       usb_fill_bulk_urb(entry_priv->urb, usb_dev,
+                         usb_sndbulkpipe(usb_dev, 1),
+                         entry->skb->data, length,
+                         rt2x00usb_interrupt_txdone, entry);
 
        return 0;
 }
index 460d32c444d136c902096c17efd84707123cd6b9..b1187c812e7f9d145a9ad12626cedf4b075b2274 100644 (file)
@@ -212,11 +212,14 @@ static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
  */
 void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
 
-/*
- * TX data handlers.
+/**
+ * rt2x00usb_write_tx_data - Initialize URB for TX operation
+ * @entry: The entry where the frame is located
+ *
+ * This function will initialize the URB and skb descriptor
+ * to prepare the entry for the actual TX operation.
  */
-int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
-                           struct data_queue *queue, struct sk_buff *skb);
+int rt2x00usb_write_tx_data(struct queue_entry *entry);
 
 /**
  * struct queue_entry_priv_usb: Per entry USB specific information