2012-10-19 22:08:24

by Mark Einon

[permalink] [raw]
Subject: [PATCH 1/3] staging: et131x: Remove fbr_lookup.real_physaddr

fbr_lookup.real_physaddr is only being used as a pseudonym for
fbr_lookup.ring_physaddr, so remove it and rename all instances to
ring_physaddr.

Signed-off-by: Mark Einon <[email protected]>
---
drivers/staging/et131x/et131x.c | 31 ++++++-------------------------
1 file changed, 6 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c
index 23d166b..3fd8142 100644
--- a/drivers/staging/et131x/et131x.c
+++ b/drivers/staging/et131x/et131x.c
@@ -299,7 +299,6 @@ struct fbr_lookup {
dma_addr_t ring_physaddr;
void *mem_virtaddrs[MAX_DESC_PER_RING_RX / FBR_CHUNKS];
dma_addr_t mem_physaddrs[MAX_DESC_PER_RING_RX / FBR_CHUNKS];
- u64 real_physaddr;
u64 offset;
u32 local_full;
u32 num_entries;
@@ -1903,9 +1902,9 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
/* Set the address and parameters of Free buffer ring 1 (and 0 if
* required) into the 1310's registers
*/
- writel((u32) (rx_local->fbr[0]->real_physaddr >> 32),
+ writel((u32) (rx_local->fbr[0]->ring_physaddr >> 32),
&rx_dma->fbr1_base_hi);
- writel((u32) rx_local->fbr[0]->real_physaddr, &rx_dma->fbr1_base_lo);
+ writel((u32) rx_local->fbr[0]->ring_physaddr, &rx_dma->fbr1_base_lo);
writel(rx_local->fbr[0]->num_entries - 1, &rx_dma->fbr1_num_des);
writel(ET_DMA10_WRAP, &rx_dma->fbr1_full_offset);

@@ -1927,9 +1926,9 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
fbr_entry++;
}

- writel((u32) (rx_local->fbr[1]->real_physaddr >> 32),
+ writel((u32) (rx_local->fbr[1]->ring_physaddr >> 32),
&rx_dma->fbr0_base_hi);
- writel((u32) rx_local->fbr[1]->real_physaddr, &rx_dma->fbr0_base_lo);
+ writel((u32) rx_local->fbr[1]->ring_physaddr, &rx_dma->fbr0_base_lo);
writel(rx_local->fbr[1]->num_entries - 1, &rx_dma->fbr0_num_des);
writel(ET_DMA10_WRAP, &rx_dma->fbr0_full_offset);

@@ -2378,18 +2377,9 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
return -ENOMEM;
}

- /* Save physical address
- *
- * NOTE: dma_alloc_coherent(), used above to alloc DMA regions,
- * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
- * are ever returned, make sure the high part is retrieved here
- * before storing the adjusted address.
- */
- rx_ring->fbr[0]->real_physaddr = rx_ring->fbr[0]->ring_physaddr;
-
/* Align Free Buffer Ring 1 on a 4K boundary */
et131x_align_allocated_memory(adapter,
- &rx_ring->fbr[0]->real_physaddr,
+ &rx_ring->fbr[0]->ring_physaddr,
&rx_ring->fbr[0]->offset, 0x0FFF);

rx_ring->fbr[0]->ring_virtaddr =
@@ -2410,18 +2400,9 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
return -ENOMEM;
}

- /* Save physical address
- *
- * NOTE: dma_alloc_coherent(), used above to alloc DMA regions,
- * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
- * are ever returned, make sure the high part is retrieved here before
- * storing the adjusted address.
- */
- rx_ring->fbr[1]->real_physaddr = rx_ring->fbr[1]->ring_physaddr;
-
/* Align Free Buffer Ring 0 on a 4K boundary */
et131x_align_allocated_memory(adapter,
- &rx_ring->fbr[1]->real_physaddr,
+ &rx_ring->fbr[1]->ring_physaddr,
&rx_ring->fbr[1]->offset, 0x0FFF);

rx_ring->fbr[1]->ring_virtaddr =
--
1.7.9.5


2012-10-19 22:08:27

by Mark Einon

[permalink] [raw]
Subject: [PATCH 2/3] staging: et131x: Use upper_32_bits() instead of '>> 32'

>From a previous comment by Alan Cox:
'>> 32 of a 32bit value is undefined in C. The compiler is free
to do what it likes with this...'

Change all uses of '>> 32' to use upper_32_bits() and use
the corresponding lower_32_bits() to match.

Also remove an incorrect comment about dma alloc always returning 32bit
addresses.

Signed-off-by: Mark Einon <[email protected]>
---
drivers/staging/et131x/et131x.c | 55 ++++++++++++++++++---------------------
1 file changed, 25 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c
index 3fd8142..32f909a 100644
--- a/drivers/staging/et131x/et131x.c
+++ b/drivers/staging/et131x/et131x.c
@@ -1859,25 +1859,17 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
/* Halt RXDMA to perform the reconfigure. */
et131x_rx_dma_disable(adapter);

- /* Load the completion writeback physical address
- *
- * NOTE : dma_alloc_coherent(), used above to alloc DMA regions,
- * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
- * are ever returned, make sure the high part is retrieved here
- * before storing the adjusted address.
- */
- writel((u32) ((u64)rx_local->rx_status_bus >> 32),
- &rx_dma->dma_wb_base_hi);
- writel((u32) rx_local->rx_status_bus, &rx_dma->dma_wb_base_lo);
+ /* Load the completion writeback physical address */
+ writel(upper_32_bits(rx_local->rx_status_bus), &rx_dma->dma_wb_base_hi);
+ writel(lower_32_bits(rx_local->rx_status_bus), &rx_dma->dma_wb_base_lo);

memset(rx_local->rx_status_block, 0, sizeof(struct rx_status_block));

/* Set the address and parameters of the packet status ring into the
* 1310's registers
*/
- writel((u32) ((u64)rx_local->ps_ring_physaddr >> 32),
- &rx_dma->psr_base_hi);
- writel((u32) rx_local->ps_ring_physaddr, &rx_dma->psr_base_lo);
+ writel(upper_32_bits(rx_local->ps_ring_physaddr), &rx_dma->psr_base_hi);
+ writel(lower_32_bits(rx_local->ps_ring_physaddr), &rx_dma->psr_base_lo);
writel(rx_local->psr_num_entries - 1, &rx_dma->psr_num_des);
writel(0, &rx_dma->psr_full_offset);

@@ -1902,9 +1894,10 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
/* Set the address and parameters of Free buffer ring 1 (and 0 if
* required) into the 1310's registers
*/
- writel((u32) (rx_local->fbr[0]->ring_physaddr >> 32),
+ writel(upper_32_bits(rx_local->fbr[0]->ring_physaddr),
&rx_dma->fbr1_base_hi);
- writel((u32) rx_local->fbr[0]->ring_physaddr, &rx_dma->fbr1_base_lo);
+ writel(lower_32_bits(rx_local->fbr[0]->ring_physaddr),
+ &rx_dma->fbr1_base_lo);
writel(rx_local->fbr[0]->num_entries - 1, &rx_dma->fbr1_num_des);
writel(ET_DMA10_WRAP, &rx_dma->fbr1_full_offset);

@@ -1926,9 +1919,10 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
fbr_entry++;
}

- writel((u32) (rx_local->fbr[1]->ring_physaddr >> 32),
+ writel(upper_32_bits(rx_local->fbr[1]->ring_physaddr),
&rx_dma->fbr0_base_hi);
- writel((u32) rx_local->fbr[1]->ring_physaddr, &rx_dma->fbr0_base_lo);
+ writel(lower_32_bits(rx_local->fbr[1]->ring_physaddr),
+ &rx_dma->fbr0_base_lo);
writel(rx_local->fbr[1]->num_entries - 1, &rx_dma->fbr0_num_des);
writel(ET_DMA10_WRAP, &rx_dma->fbr0_full_offset);

@@ -1970,18 +1964,19 @@ static void et131x_config_tx_dma_regs(struct et131x_adapter *adapter)
struct txdma_regs __iomem *txdma = &adapter->regs->txdma;

/* Load the hardware with the start of the transmit descriptor ring. */
- writel((u32) ((u64)adapter->tx_ring.tx_desc_ring_pa >> 32),
+ writel(upper_32_bits(adapter->tx_ring.tx_desc_ring_pa),
&txdma->pr_base_hi);
- writel((u32) adapter->tx_ring.tx_desc_ring_pa,
+ writel(lower_32_bits(adapter->tx_ring.tx_desc_ring_pa),
&txdma->pr_base_lo);

/* Initialise the transmit DMA engine */
writel(NUM_DESC_PER_RING_TX - 1, &txdma->pr_num_des);

/* Load the completion writeback physical address */
- writel((u32)((u64)adapter->tx_ring.tx_status_pa >> 32),
- &txdma->dma_wb_base_hi);
- writel((u32)adapter->tx_ring.tx_status_pa, &txdma->dma_wb_base_lo);
+ writel(upper_32_bits(adapter->tx_ring.tx_status_pa),
+ &txdma->dma_wb_base_hi);
+ writel(lower_32_bits(adapter->tx_ring.tx_status_pa),
+ &txdma->dma_wb_base_lo);

*adapter->tx_ring.tx_status = 0;

@@ -2460,16 +2455,16 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
* so the device can access it
*/
rx_ring->fbr[0]->bus_high[index] =
- (u32) (fbr1_tmp_physaddr >> 32);
+ upper_32_bits(fbr1_tmp_physaddr);
rx_ring->fbr[0]->bus_low[index] =
- (u32) fbr1_tmp_physaddr;
+ lower_32_bits(fbr1_tmp_physaddr);

fbr1_tmp_physaddr += rx_ring->fbr[0]->buffsize;

rx_ring->fbr[0]->buffer1[index] =
- rx_ring->fbr[0]->virt[index];
+ rx_ring->fbr[0]->virt[index];
rx_ring->fbr[0]->buffer2[index] =
- rx_ring->fbr[0]->virt[index] - 4;
+ rx_ring->fbr[0]->virt[index] - 4;
}
}

@@ -2508,16 +2503,16 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
(j * rx_ring->fbr[1]->buffsize) + fbr0_offset;

rx_ring->fbr[1]->bus_high[index] =
- (u32) (fbr0_tmp_physaddr >> 32);
+ upper_32_bits(fbr0_tmp_physaddr);
rx_ring->fbr[1]->bus_low[index] =
- (u32) fbr0_tmp_physaddr;
+ lower_32_bits(fbr0_tmp_physaddr);

fbr0_tmp_physaddr += rx_ring->fbr[1]->buffsize;

rx_ring->fbr[1]->buffer1[index] =
- rx_ring->fbr[1]->virt[index];
+ rx_ring->fbr[1]->virt[index];
rx_ring->fbr[1]->buffer2[index] =
- rx_ring->fbr[1]->virt[index] - 4;
+ rx_ring->fbr[1]->virt[index] - 4;
}
}
#endif
--
1.7.9.5

2012-10-19 22:08:40

by Mark Einon

[permalink] [raw]
Subject: [PATCH 3/3] staging: et131x: Remove USE_FBR0 define and #ifdefs

USE_FBR0 has always been defined, even in the original driver code.
Remove the define and #ifdef code to leave the code in the same state.

Signed-off-by: Mark Einon <[email protected]>
---
drivers/staging/et131x/et131x.c | 58 +++++----------------------------------
1 file changed, 7 insertions(+), 51 deletions(-)

diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c
index 32f909a..c33cafd 100644
--- a/drivers/staging/et131x/et131x.c
+++ b/drivers/staging/et131x/et131x.c
@@ -176,20 +176,13 @@ MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver for the ET1310 by Agere S
#define PARM_DMA_CACHE_DEF 0

/* RX defines */
-#define USE_FBR0 1
#define FBR_CHUNKS 32
#define MAX_DESC_PER_RING_RX 1024

/* number of RFDs - default and min */
-#ifdef USE_FBR0
#define RFD_LOW_WATER_MARK 40
#define NIC_DEFAULT_NUM_RFD 1024
#define NUM_FBRS 2
-#else
-#define RFD_LOW_WATER_MARK 20
-#define NIC_DEFAULT_NUM_RFD 256
-#define NUM_FBRS 1
-#endif

#define NIC_MIN_NUM_RFD 64
#define NUM_PACKETS_HANDLED 256
@@ -871,7 +864,7 @@ static void et131x_rx_dma_enable(struct et131x_adapter *adapter)
csr |= 0x1000;
else if (adapter->rx_ring.fbr[0]->buffsize == 16384)
csr |= 0x1800;
-#ifdef USE_FBR0
+
csr |= 0x0400; /* FBR0 enable */
if (adapter->rx_ring.fbr[1]->buffsize == 256)
csr |= 0x0100;
@@ -879,7 +872,6 @@ static void et131x_rx_dma_enable(struct et131x_adapter *adapter)
csr |= 0x0200;
else if (adapter->rx_ring.fbr[1]->buffsize == 1024)
csr |= 0x0300;
-#endif
writel(csr, &adapter->regs->rxdma.csr);

csr = readl(&adapter->regs->rxdma.csr);
@@ -1909,7 +1901,6 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
((rx_local->fbr[0]->num_entries * LO_MARK_PERCENT_FOR_RX) / 100) - 1,
&rx_dma->fbr1_min_des);

-#ifdef USE_FBR0
/* Now's the best time to initialize FBR0 contents */
fbr_entry = (struct fbr_desc *) rx_local->fbr[1]->ring_virtaddr;
for (entry = 0; entry < rx_local->fbr[1]->num_entries; entry++) {
@@ -1933,7 +1924,6 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
writel(
((rx_local->fbr[1]->num_entries * LO_MARK_PERCENT_FOR_RX) / 100) - 1,
&rx_dma->fbr0_min_des);
-#endif

/* Program the number of packets we will receive before generating an
* interrupt.
@@ -2305,9 +2295,7 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
rx_ring = &adapter->rx_ring;

/* Alloc memory for the lookup table */
-#ifdef USE_FBR0
rx_ring->fbr[1] = kmalloc(sizeof(struct fbr_lookup), GFP_KERNEL);
-#endif
rx_ring->fbr[0] = kmalloc(sizeof(struct fbr_lookup), GFP_KERNEL);

/* The first thing we will do is configure the sizes of the buffer
@@ -2329,35 +2317,25 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
*/

if (adapter->registry_jumbo_packet < 2048) {
-#ifdef USE_FBR0
rx_ring->fbr[1]->buffsize = 256;
rx_ring->fbr[1]->num_entries = 512;
-#endif
rx_ring->fbr[0]->buffsize = 2048;
rx_ring->fbr[0]->num_entries = 512;
} else if (adapter->registry_jumbo_packet < 4096) {
-#ifdef USE_FBR0
rx_ring->fbr[1]->buffsize = 512;
rx_ring->fbr[1]->num_entries = 1024;
-#endif
rx_ring->fbr[0]->buffsize = 4096;
rx_ring->fbr[0]->num_entries = 512;
} else {
-#ifdef USE_FBR0
rx_ring->fbr[1]->buffsize = 1024;
rx_ring->fbr[1]->num_entries = 768;
-#endif
rx_ring->fbr[0]->buffsize = 16384;
rx_ring->fbr[0]->num_entries = 128;
}

-#ifdef USE_FBR0
adapter->rx_ring.psr_num_entries =
adapter->rx_ring.fbr[1]->num_entries +
adapter->rx_ring.fbr[0]->num_entries;
-#else
- adapter->rx_ring.psr_num_entries = adapter->rx_ring.fbr[0]->num_entries;
-#endif

/* Allocate an area of memory for Free Buffer Ring 1 */
bufsize = (sizeof(struct fbr_desc) * rx_ring->fbr[0]->num_entries) +
@@ -2381,7 +2359,6 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
(void *)((u8 *) rx_ring->fbr[0]->ring_virtaddr +
rx_ring->fbr[0]->offset);

-#ifdef USE_FBR0
/* Allocate an area of memory for Free Buffer Ring 0 */
bufsize = (sizeof(struct fbr_desc) * rx_ring->fbr[1]->num_entries) +
0xfff;
@@ -2403,7 +2380,7 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
rx_ring->fbr[1]->ring_virtaddr =
(void *)((u8 *) rx_ring->fbr[1]->ring_virtaddr +
rx_ring->fbr[1]->offset);
-#endif
+
for (i = 0; i < (rx_ring->fbr[0]->num_entries / FBR_CHUNKS); i++) {
u64 fbr1_tmp_physaddr;
u64 fbr1_offset;
@@ -2468,7 +2445,6 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
}
}

-#ifdef USE_FBR0
/* Same for FBR0 (if in use) */
for (i = 0; i < (rx_ring->fbr[1]->num_entries / FBR_CHUNKS); i++) {
u64 fbr0_tmp_physaddr;
@@ -2515,7 +2491,6 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
rx_ring->fbr[1]->virt[index] - 4;
}
}
-#endif

/* Allocate an area of memory for FIFO of Packet Status ring entries */
pktstat_ringsize =
@@ -2644,7 +2619,6 @@ static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter)
rx_ring->fbr[0]->ring_virtaddr = NULL;
}

-#ifdef USE_FBR0
/* Now the same for Free Buffer Ring 0 */
if (rx_ring->fbr[1]->ring_virtaddr) {
/* First the packet memory */
@@ -2679,7 +2653,6 @@ static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter)

rx_ring->fbr[1]->ring_virtaddr = NULL;
}
-#endif

/* Free Packet Status Ring */
if (rx_ring->ps_ring_virtaddr) {
@@ -2709,10 +2682,7 @@ static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter)
}

/* Free the FBR Lookup Table */
-#ifdef USE_FBR0
kfree(rx_ring->fbr[1]);
-#endif
-
kfree(rx_ring->fbr[0]);

/* Reset Counters */
@@ -2808,9 +2778,7 @@ static void nic_return_rfd(struct et131x_adapter *adapter, struct rfd *rfd)
* need to clean up OOB data
*/
if (
-#ifdef USE_FBR0
(ring_index == 0 && buff_index < rx_local->fbr[1]->num_entries) ||
-#endif
(ring_index == 1 && buff_index < rx_local->fbr[0]->num_entries)) {
spin_lock_irqsave(&adapter->fbr_lock, flags);

@@ -2831,9 +2799,7 @@ static void nic_return_rfd(struct et131x_adapter *adapter, struct rfd *rfd)
&rx_local->fbr[0]->local_full,
rx_local->fbr[0]->num_entries - 1),
&rx_dma->fbr1_full_offset);
- }
-#ifdef USE_FBR0
- else {
+ } else {
struct fbr_desc *next = (struct fbr_desc *)
rx_local->fbr[1]->ring_virtaddr +
INDEX10(rx_local->fbr[1]->local_full);
@@ -2851,7 +2817,6 @@ static void nic_return_rfd(struct et131x_adapter *adapter, struct rfd *rfd)
rx_local->fbr[1]->num_entries - 1),
&rx_dma->fbr0_full_offset);
}
-#endif
spin_unlock_irqrestore(&adapter->fbr_lock, flags);
} else {
dev_err(&adapter->pdev->dev,
@@ -2934,20 +2899,11 @@ static struct rfd *nic_rx_pkts(struct et131x_adapter *adapter)
writel(rx_local->local_psr_full,
&adapter->regs->rxdma.psr_full_offset);

-#ifndef USE_FBR0
- if (ring_index != 1)
- return NULL;
-#endif
-
-#ifdef USE_FBR0
if (ring_index > 1 ||
- (ring_index == 0 &&
- buff_index > rx_local->fbr[1]->num_entries - 1) ||
- (ring_index == 1 &&
- buff_index > rx_local->fbr[0]->num_entries - 1)) {
-#else
- if (ring_index != 1 || buff_index > rx_local->fbr[0]->num_entries - 1) {
-#endif
+ (ring_index == 0 &&
+ buff_index > rx_local->fbr[1]->num_entries - 1) ||
+ (ring_index == 1 &&
+ buff_index > rx_local->fbr[0]->num_entries - 1)) {
/* Illegal buffer or ring index cannot be used by S/W*/
dev_err(&adapter->pdev->dev,
"NICRxPkts PSR Entry %d indicates "
--
1.7.9.5