Re: [PATCH 15/24] RT2x00: Merge PCI and USB version of data_entry structure

2006-07-26 Thread Ivo van Doorn
>From Ivo van Doorn <[EMAIL PROTECTED]>

Merge the data_entry structure for USB and PCI into
a single structure. This means that all access to the data_addr
and desc_addr should now be performed through the functions:
rt2x00pci_desc_addr()
rt2x00pci_data_addr()
And for usb:
rt2x00usb_urb()
rt2x00usb_rxdata_addr()
rt2x00usb_rxdesc_addr()
rt2x00usb_txdata_addr()
rt2x00usb_txdesc_addr()

Signed-off-by: Ivo van Doorn <[EMAIL PROTECTED]>

diff -rU3 wireless-dev-eeprom/drivers/net/wireless/d80211/rt2x00/rt2400pci.c 
wireless-dev-ringentry/drivers/net/wireless/d80211/rt2x00/rt2400pci.c
--- wireless-dev-eeprom/drivers/net/wireless/d80211/rt2x00/rt2400pci.c  
2006-07-23 22:41:51.0 +0200
+++ wireless-dev-ringentry/drivers/net/wireless/d80211/rt2x00/rt2400pci.c   
2006-07-25 10:44:12.0 +0200
@@ -1039,7 +1039,7 @@
 
while (1) {
entry = rt2x00_get_data_entry(ring);
-   rxd = entry->desc_addr;
+   rxd = rt2x00pci_desc_addr(entry);
 
if (rt2x00_get_field32(rxd->word0, RXD_W0_OWNER_NIC))
break;
@@ -1058,7 +1058,8 @@
 
skb_reserve(skb, NET_IP_ALIGN);
 
-   memcpy(skb_put(skb, size), entry->data_addr, size);
+   memcpy(skb_put(skb, size), rt2x00pci_data_addr(entry),
+   size);
 
rt2x00dev->rx_params.ssi =
rt2x00_get_field32(rxd->word2, RXD_W2_RSSI);
@@ -1100,7 +1101,7 @@
 
while (!rt2x00_ring_empty(ring)) {
entry = rt2x00_get_data_entry_done(ring);
-   txd = entry->desc_addr;
+   txd = rt2x00pci_desc_addr(entry);
 
if (rt2x00_get_field32(txd->word0, TXD_W0_OWNER_NIC) ||
!rt2x00_get_field32(txd->word0, TXD_W0_VALID))
@@ -1237,10 +1238,10 @@
  * DMA ring functions.
  */
 static int rt2400pci_alloc_ring(struct rt2x00_dev *rt2x00dev,
-   struct data_ring *ring, void (*handler)(void *),
+   unsigned short type, void (*handler)(void *),
const u16 max_entries, const u16 data_size, const u16 desc_size)
 {
-   struct data_entry *entry;
+   struct data_ring *ring = &rt2x00dev->ring[type];
unsigned int i;
 
/*
@@ -1261,15 +1262,15 @@
 
rt2x00_ring_index_clear(ring);
 
+   ring->type = type;
ring->stats.limit = max_entries;
-   ring->entry_size = sizeof(struct data_entry);
ring->data_size = data_size;
ring->desc_size = desc_size;
 
/*
 * Allocate all ring entries.
 */
-   ring->entry = kmalloc(ring->stats.limit * ring->entry_size,
+   ring->entry = kmalloc(ring->stats.limit * sizeof(struct data_entry),
GFP_KERNEL);
if (!ring->entry)
return -ENOMEM;
@@ -1288,15 +1289,14 @@
 * Initialize all ring entries to contain valid
 * addresses.
 */
-   entry = ring->entry;
for (i = 0; i < ring->stats.limit; i++) {
-   entry[i].skb = NULL;
-   entry[i].desc_addr = ring->data_addr
+   ring->entry[i].skb = NULL;
+   ring->entry[i].priv = ring->data_addr
+ (i * ring->desc_size);
-   entry[i].data_addr = ring->data_addr
+   ring->entry[i].data_addr = ring->data_addr
+ (ring->stats.limit * ring->desc_size)
+ (i * ring->data_size);
-   entry[i].data_dma = ring->data_dma
+   ring->entry[i].data_dma = ring->data_dma
+ (ring->stats.limit * ring->desc_size)
+ (i * ring->data_size);
}
@@ -1329,19 +1329,19 @@
SET_FLAG(rt2x00dev, DEVICE_SUPPORT_ATIM);
 
if (rt2400pci_alloc_ring(
-   rt2x00dev, &rt2x00dev->ring[RING_RX], rt2400pci_rxdone,
+   rt2x00dev, RING_RX, rt2400pci_rxdone,
RX_ENTRIES, DATA_FRAME_SIZE, sizeof(struct rxd)) ||
rt2400pci_alloc_ring(
-   rt2x00dev, &rt2x00dev->ring[RING_TX], rt2400pci_txdone,
+   rt2x00dev, RING_TX, rt2400pci_txdone,
 TX_ENTRIES, DATA_FRAME_SIZE, sizeof(struct txd)) ||
rt2400pci_alloc_ring(
-   rt2x00dev, &rt2x00dev->ring[RING_ATIM], rt2400pci_txdone,
+   rt2x00dev, RING_ATIM, rt2400pci_txdone,
ATIM_ENTRIES, DATA_FRAME_SIZE, sizeof(struct txd)) ||
rt2400pci_alloc_ring(
-   rt2x00dev, &rt2x00dev->ring[RING_PRIO], rt2400pci_txdone,
+   rt2x00dev, RING_PRIO, rt2400pci_txdone,
TX_ENTRIES, DATA_FRAME_SIZE, sizeof(struct txd)) ||
rt2400pci_alloc_ring(
-   rt2x00dev, &rt2x00dev->ring[RING_BEACON], rt2400pci_beacondone,
+   rt2x00dev, RING_BEACON, rt2400pci_beacondone,
BEACON_ENTRIES, MGMT_FRAME_SIZE, sizeof(struct txd))) {
  

[PATCH 15/24] RT2x00: Merge PCI and USB version of data_entry structure

2006-07-26 Thread Ivo van Doorn
>From Ivo van Doorn <[EMAIL PROTECTED]>

Merge the data_entry structure for USB and PCI into
a single structure. This means that all access to the data_addr
and desc_addr should now be performed through the functions:
rt2x00pci_desc_addr()
rt2x00pci_data_addr()
And for usb:
rt2x00usb_urb()
rt2x00usb_rxdata_addr()
rt2x00usb_rxdesc_addr()
rt2x00usb_txdata_addr()
rt2x00usb_txdesc_addr()

Signed-off-by: Ivo van Doorn <[EMAIL PROTECTED]>

---

diff -rU3 wireless-dev-eeprom/drivers/net/wireless/d80211/rt2x00/rt2400pci.c 
wireless-dev-ringentry/drivers/net/wireless/d80211/rt2x00/rt2400pci.c
--- wireless-dev-eeprom/drivers/net/wireless/d80211/rt2x00/rt2400pci.c  
2006-07-23 22:41:51.0 +0200
+++ wireless-dev-ringentry/drivers/net/wireless/d80211/rt2x00/rt2400pci.c   
2006-07-25 10:44:12.0 +0200
@@ -1039,7 +1039,7 @@
 
while (1) {
entry = rt2x00_get_data_entry(ring);
-   rxd = entry->desc_addr;
+   rxd = rt2x00pci_desc_addr(entry);
 
if (rt2x00_get_field32(rxd->word0, RXD_W0_OWNER_NIC))
break;
@@ -1058,7 +1058,8 @@
 
skb_reserve(skb, NET_IP_ALIGN);
 
-   memcpy(skb_put(skb, size), entry->data_addr, size);
+   memcpy(skb_put(skb, size), rt2x00pci_data_addr(entry),
+   size);
 
rt2x00dev->rx_params.ssi =
rt2x00_get_field32(rxd->word2, RXD_W2_RSSI);
@@ -1100,7 +1101,7 @@
 
while (!rt2x00_ring_empty(ring)) {
entry = rt2x00_get_data_entry_done(ring);
-   txd = entry->desc_addr;
+   txd = rt2x00pci_desc_addr(entry);
 
if (rt2x00_get_field32(txd->word0, TXD_W0_OWNER_NIC) ||
!rt2x00_get_field32(txd->word0, TXD_W0_VALID))
@@ -1237,10 +1238,10 @@
  * DMA ring functions.
  */
 static int rt2400pci_alloc_ring(struct rt2x00_dev *rt2x00dev,
-   struct data_ring *ring, void (*handler)(void *),
+   unsigned short type, void (*handler)(void *),
const u16 max_entries, const u16 data_size, const u16 desc_size)
 {
-   struct data_entry *entry;
+   struct data_ring *ring = &rt2x00dev->ring[type];
unsigned int i;
 
/*
@@ -1261,15 +1262,15 @@
 
rt2x00_ring_index_clear(ring);
 
+   ring->type = type;
ring->stats.limit = max_entries;
-   ring->entry_size = sizeof(struct data_entry);
ring->data_size = data_size;
ring->desc_size = desc_size;
 
/*
 * Allocate all ring entries.
 */
-   ring->entry = kmalloc(ring->stats.limit * ring->entry_size,
+   ring->entry = kmalloc(ring->stats.limit * sizeof(struct data_entry),
GFP_KERNEL);
if (!ring->entry)
return -ENOMEM;
@@ -1288,15 +1289,14 @@
 * Initialize all ring entries to contain valid
 * addresses.
 */
-   entry = ring->entry;
for (i = 0; i < ring->stats.limit; i++) {
-   entry[i].skb = NULL;
-   entry[i].desc_addr = ring->data_addr
+   ring->entry[i].skb = NULL;
+   ring->entry[i].priv = ring->data_addr
+ (i * ring->desc_size);
-   entry[i].data_addr = ring->data_addr
+   ring->entry[i].data_addr = ring->data_addr
+ (ring->stats.limit * ring->desc_size)
+ (i * ring->data_size);
-   entry[i].data_dma = ring->data_dma
+   ring->entry[i].data_dma = ring->data_dma
+ (ring->stats.limit * ring->desc_size)
+ (i * ring->data_size);
}
@@ -1329,19 +1329,19 @@
SET_FLAG(rt2x00dev, DEVICE_SUPPORT_ATIM);
 
if (rt2400pci_alloc_ring(
-   rt2x00dev, &rt2x00dev->ring[RING_RX], rt2400pci_rxdone,
+   rt2x00dev, RING_RX, rt2400pci_rxdone,
RX_ENTRIES, DATA_FRAME_SIZE, sizeof(struct rxd)) ||
rt2400pci_alloc_ring(
-   rt2x00dev, &rt2x00dev->ring[RING_TX], rt2400pci_txdone,
+   rt2x00dev, RING_TX, rt2400pci_txdone,
 TX_ENTRIES, DATA_FRAME_SIZE, sizeof(struct txd)) ||
rt2400pci_alloc_ring(
-   rt2x00dev, &rt2x00dev->ring[RING_ATIM], rt2400pci_txdone,
+   rt2x00dev, RING_ATIM, rt2400pci_txdone,
ATIM_ENTRIES, DATA_FRAME_SIZE, sizeof(struct txd)) ||
rt2400pci_alloc_ring(
-   rt2x00dev, &rt2x00dev->ring[RING_PRIO], rt2400pci_txdone,
+   rt2x00dev, RING_PRIO, rt2400pci_txdone,
TX_ENTRIES, DATA_FRAME_SIZE, sizeof(struct txd)) ||
rt2400pci_alloc_ring(
-   rt2x00dev, &rt2x00dev->ring[RING_BEACON], rt2400pci_beacondone,
+   rt2x00dev, RING_BEACON, rt2400pci_beacondone,
BEACON_ENTRIES, MGMT_FRAME_SIZE, sizeof(struct txd))) {