diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2005-11-09 12:10:05 -0500 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-11-11 08:31:35 -0500 |
commit | 05d9c84dfbbb654f60d98d465b58d4c68222ef1c (patch) | |
tree | 721025a8eab0b818f4e5eba19001cba521560220 /drivers/net/saa9730.c | |
parent | 62ff0d0a0769f08806d3f50449a78f17420971e8 (diff) |
[PATCH] SAA9730: Driver overhaul
o Try to work around some of the undocumented "features" of the SAA9730
o Use netdev_priv() instead of the previous broken mechanism to allocate
the private data structure.
o Try to make sure we don't leak resources on exit.
o No more need to call SET_MODULE_OWNER in 2.6.
o Use pci_free_consistent instead of homegrown architecture-specific
allocation.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
drivers/net/saa9730.c | 531 +++++++++++++++++++++++---------------------------
1 files changed, 249 insertions(+), 282 deletions(-)
Signed-off-by: Jeff Garzik <jgarzik@pobox.com>
Diffstat (limited to 'drivers/net/saa9730.c')
-rw-r--r-- | drivers/net/saa9730.c | 533 |
1 files changed, 250 insertions, 283 deletions
diff --git a/drivers/net/saa9730.c b/drivers/net/saa9730.c index 451e78d241a0..b2acedbefa8f 100644 --- a/drivers/net/saa9730.c +++ b/drivers/net/saa9730.c | |||
@@ -1,8 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * Carsten Langgaard, carstenl@mips.com | 2 | * Copyright (C) 2000, 2005 MIPS Technologies, Inc. All rights reserved. |
3 | * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved. | 3 | * Authors: Carsten Langgaard <carstenl@mips.com> |
4 | * | 4 | * Maciej W. Rozycki <macro@mips.com> |
5 | * ######################################################################## | 5 | * Copyright (C) 2004 Ralf Baechle <ralf@linux-mips.org> |
6 | * | 6 | * |
7 | * This program is free software; you can distribute it and/or modify it | 7 | * This program is free software; you can distribute it and/or modify it |
8 | * under the terms of the GNU General Public License (Version 2) as | 8 | * under the terms of the GNU General Public License (Version 2) as |
@@ -17,15 +17,13 @@ | |||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
18 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | 18 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. |
19 | * | 19 | * |
20 | * ######################################################################## | ||
21 | * | ||
22 | * SAA9730 ethernet driver. | 20 | * SAA9730 ethernet driver. |
23 | * | 21 | * |
24 | * Changes: | 22 | * Changes: |
25 | * Angelo Dell'Aera <buffer@antifork.org> : Conversion to the new PCI API (pci_driver). | 23 | * Angelo Dell'Aera <buffer@antifork.org> : Conversion to the new PCI API |
26 | * Conversion to spinlocks. | 24 | * (pci_driver). |
27 | * Error handling fixes. | 25 | * Conversion to spinlocks. |
28 | * | 26 | * Error handling fixes. |
29 | */ | 27 | */ |
30 | 28 | ||
31 | #include <linux/init.h> | 29 | #include <linux/init.h> |
@@ -36,8 +34,11 @@ | |||
36 | #include <linux/skbuff.h> | 34 | #include <linux/skbuff.h> |
37 | #include <linux/pci.h> | 35 | #include <linux/pci.h> |
38 | #include <linux/spinlock.h> | 36 | #include <linux/spinlock.h> |
37 | #include <linux/types.h> | ||
39 | 38 | ||
40 | #include <asm/addrspace.h> | 39 | #include <asm/addrspace.h> |
40 | #include <asm/io.h> | ||
41 | |||
41 | #include <asm/mips-boards/prom.h> | 42 | #include <asm/mips-boards/prom.h> |
42 | 43 | ||
43 | #include "saa9730.h" | 44 | #include "saa9730.h" |
@@ -51,7 +52,7 @@ int lan_saa9730_debug; | |||
51 | #define DRV_MODULE_NAME "saa9730" | 52 | #define DRV_MODULE_NAME "saa9730" |
52 | 53 | ||
53 | static struct pci_device_id saa9730_pci_tbl[] = { | 54 | static struct pci_device_id saa9730_pci_tbl[] = { |
54 | { PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA9370, | 55 | { PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA9730, |
55 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, | 56 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, |
56 | { 0, } | 57 | { 0, } |
57 | }; | 58 | }; |
@@ -61,50 +62,48 @@ MODULE_DEVICE_TABLE(pci, saa9730_pci_tbl); | |||
61 | /* Non-zero only if the current card is a PCI with BIOS-set IRQ. */ | 62 | /* Non-zero only if the current card is a PCI with BIOS-set IRQ. */ |
62 | static unsigned int pci_irq_line; | 63 | static unsigned int pci_irq_line; |
63 | 64 | ||
64 | #define INL(a) inl((unsigned long)a) | ||
65 | #define OUTL(x,a) outl(x,(unsigned long)a) | ||
66 | |||
67 | static void evm_saa9730_enable_lan_int(struct lan_saa9730_private *lp) | 65 | static void evm_saa9730_enable_lan_int(struct lan_saa9730_private *lp) |
68 | { | 66 | { |
69 | OUTL(INL(&lp->evm_saa9730_regs->InterruptBlock1) | EVM_LAN_INT, | 67 | outl(readl(&lp->evm_saa9730_regs->InterruptBlock1) | EVM_LAN_INT, |
70 | &lp->evm_saa9730_regs->InterruptBlock1); | 68 | &lp->evm_saa9730_regs->InterruptBlock1); |
71 | OUTL(INL(&lp->evm_saa9730_regs->InterruptStatus1) | EVM_LAN_INT, | 69 | outl(readl(&lp->evm_saa9730_regs->InterruptStatus1) | EVM_LAN_INT, |
72 | &lp->evm_saa9730_regs->InterruptStatus1); | 70 | &lp->evm_saa9730_regs->InterruptStatus1); |
73 | OUTL(INL(&lp->evm_saa9730_regs->InterruptEnable1) | EVM_LAN_INT | | 71 | outl(readl(&lp->evm_saa9730_regs->InterruptEnable1) | EVM_LAN_INT | |
74 | EVM_MASTER_EN, &lp->evm_saa9730_regs->InterruptEnable1); | 72 | EVM_MASTER_EN, &lp->evm_saa9730_regs->InterruptEnable1); |
75 | } | 73 | } |
74 | |||
76 | static void evm_saa9730_disable_lan_int(struct lan_saa9730_private *lp) | 75 | static void evm_saa9730_disable_lan_int(struct lan_saa9730_private *lp) |
77 | { | 76 | { |
78 | OUTL(INL(&lp->evm_saa9730_regs->InterruptBlock1) & ~EVM_LAN_INT, | 77 | outl(readl(&lp->evm_saa9730_regs->InterruptBlock1) & ~EVM_LAN_INT, |
79 | &lp->evm_saa9730_regs->InterruptBlock1); | 78 | &lp->evm_saa9730_regs->InterruptBlock1); |
80 | OUTL(INL(&lp->evm_saa9730_regs->InterruptEnable1) & ~EVM_LAN_INT, | 79 | outl(readl(&lp->evm_saa9730_regs->InterruptEnable1) & ~EVM_LAN_INT, |
81 | &lp->evm_saa9730_regs->InterruptEnable1); | 80 | &lp->evm_saa9730_regs->InterruptEnable1); |
82 | } | 81 | } |
83 | 82 | ||
84 | static void evm_saa9730_clear_lan_int(struct lan_saa9730_private *lp) | 83 | static void evm_saa9730_clear_lan_int(struct lan_saa9730_private *lp) |
85 | { | 84 | { |
86 | OUTL(EVM_LAN_INT, &lp->evm_saa9730_regs->InterruptStatus1); | 85 | outl(EVM_LAN_INT, &lp->evm_saa9730_regs->InterruptStatus1); |
87 | } | 86 | } |
88 | 87 | ||
89 | static void evm_saa9730_block_lan_int(struct lan_saa9730_private *lp) | 88 | static void evm_saa9730_block_lan_int(struct lan_saa9730_private *lp) |
90 | { | 89 | { |
91 | OUTL(INL(&lp->evm_saa9730_regs->InterruptBlock1) & ~EVM_LAN_INT, | 90 | outl(readl(&lp->evm_saa9730_regs->InterruptBlock1) & ~EVM_LAN_INT, |
92 | &lp->evm_saa9730_regs->InterruptBlock1); | 91 | &lp->evm_saa9730_regs->InterruptBlock1); |
93 | } | 92 | } |
94 | 93 | ||
95 | static void evm_saa9730_unblock_lan_int(struct lan_saa9730_private *lp) | 94 | static void evm_saa9730_unblock_lan_int(struct lan_saa9730_private *lp) |
96 | { | 95 | { |
97 | OUTL(INL(&lp->evm_saa9730_regs->InterruptBlock1) | EVM_LAN_INT, | 96 | outl(readl(&lp->evm_saa9730_regs->InterruptBlock1) | EVM_LAN_INT, |
98 | &lp->evm_saa9730_regs->InterruptBlock1); | 97 | &lp->evm_saa9730_regs->InterruptBlock1); |
99 | } | 98 | } |
100 | 99 | ||
101 | static void show_saa9730_regs(struct lan_saa9730_private *lp) | 100 | static void __attribute_used__ show_saa9730_regs(struct lan_saa9730_private *lp) |
102 | { | 101 | { |
103 | int i, j; | 102 | int i, j; |
104 | printk("TxmBufferA = %x\n", lp->TxmBuffer[0][0]); | 103 | printk("TxmBufferA = %p\n", lp->TxmBuffer[0][0]); |
105 | printk("TxmBufferB = %x\n", lp->TxmBuffer[1][0]); | 104 | printk("TxmBufferB = %p\n", lp->TxmBuffer[1][0]); |
106 | printk("RcvBufferA = %x\n", lp->RcvBuffer[0][0]); | 105 | printk("RcvBufferA = %p\n", lp->RcvBuffer[0][0]); |
107 | printk("RcvBufferB = %x\n", lp->RcvBuffer[1][0]); | 106 | printk("RcvBufferB = %p\n", lp->RcvBuffer[1][0]); |
108 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { | 107 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { |
109 | for (j = 0; j < LAN_SAA9730_TXM_Q_SIZE; j++) { | 108 | for (j = 0; j < LAN_SAA9730_TXM_Q_SIZE; j++) { |
110 | printk("TxmBuffer[%d][%d] = %x\n", i, j, | 109 | printk("TxmBuffer[%d][%d] = %x\n", i, j, |
@@ -120,13 +119,13 @@ static void show_saa9730_regs(struct lan_saa9730_private *lp) | |||
120 | } | 119 | } |
121 | } | 120 | } |
122 | printk("lp->evm_saa9730_regs->InterruptBlock1 = %x\n", | 121 | printk("lp->evm_saa9730_regs->InterruptBlock1 = %x\n", |
123 | INL(&lp->evm_saa9730_regs->InterruptBlock1)); | 122 | readl(&lp->evm_saa9730_regs->InterruptBlock1)); |
124 | printk("lp->evm_saa9730_regs->InterruptStatus1 = %x\n", | 123 | printk("lp->evm_saa9730_regs->InterruptStatus1 = %x\n", |
125 | INL(&lp->evm_saa9730_regs->InterruptStatus1)); | 124 | readl(&lp->evm_saa9730_regs->InterruptStatus1)); |
126 | printk("lp->evm_saa9730_regs->InterruptEnable1 = %x\n", | 125 | printk("lp->evm_saa9730_regs->InterruptEnable1 = %x\n", |
127 | INL(&lp->evm_saa9730_regs->InterruptEnable1)); | 126 | readl(&lp->evm_saa9730_regs->InterruptEnable1)); |
128 | printk("lp->lan_saa9730_regs->Ok2Use = %x\n", | 127 | printk("lp->lan_saa9730_regs->Ok2Use = %x\n", |
129 | INL(&lp->lan_saa9730_regs->Ok2Use)); | 128 | readl(&lp->lan_saa9730_regs->Ok2Use)); |
130 | printk("lp->NextTxmBufferIndex = %x\n", lp->NextTxmBufferIndex); | 129 | printk("lp->NextTxmBufferIndex = %x\n", lp->NextTxmBufferIndex); |
131 | printk("lp->NextTxmPacketIndex = %x\n", lp->NextTxmPacketIndex); | 130 | printk("lp->NextTxmPacketIndex = %x\n", lp->NextTxmPacketIndex); |
132 | printk("lp->PendingTxmBufferIndex = %x\n", | 131 | printk("lp->PendingTxmBufferIndex = %x\n", |
@@ -134,23 +133,23 @@ static void show_saa9730_regs(struct lan_saa9730_private *lp) | |||
134 | printk("lp->PendingTxmPacketIndex = %x\n", | 133 | printk("lp->PendingTxmPacketIndex = %x\n", |
135 | lp->PendingTxmPacketIndex); | 134 | lp->PendingTxmPacketIndex); |
136 | printk("lp->lan_saa9730_regs->LanDmaCtl = %x\n", | 135 | printk("lp->lan_saa9730_regs->LanDmaCtl = %x\n", |
137 | INL(&lp->lan_saa9730_regs->LanDmaCtl)); | 136 | readl(&lp->lan_saa9730_regs->LanDmaCtl)); |
138 | printk("lp->lan_saa9730_regs->DmaStatus = %x\n", | 137 | printk("lp->lan_saa9730_regs->DmaStatus = %x\n", |
139 | INL(&lp->lan_saa9730_regs->DmaStatus)); | 138 | readl(&lp->lan_saa9730_regs->DmaStatus)); |
140 | printk("lp->lan_saa9730_regs->CamCtl = %x\n", | 139 | printk("lp->lan_saa9730_regs->CamCtl = %x\n", |
141 | INL(&lp->lan_saa9730_regs->CamCtl)); | 140 | readl(&lp->lan_saa9730_regs->CamCtl)); |
142 | printk("lp->lan_saa9730_regs->TxCtl = %x\n", | 141 | printk("lp->lan_saa9730_regs->TxCtl = %x\n", |
143 | INL(&lp->lan_saa9730_regs->TxCtl)); | 142 | readl(&lp->lan_saa9730_regs->TxCtl)); |
144 | printk("lp->lan_saa9730_regs->TxStatus = %x\n", | 143 | printk("lp->lan_saa9730_regs->TxStatus = %x\n", |
145 | INL(&lp->lan_saa9730_regs->TxStatus)); | 144 | readl(&lp->lan_saa9730_regs->TxStatus)); |
146 | printk("lp->lan_saa9730_regs->RxCtl = %x\n", | 145 | printk("lp->lan_saa9730_regs->RxCtl = %x\n", |
147 | INL(&lp->lan_saa9730_regs->RxCtl)); | 146 | readl(&lp->lan_saa9730_regs->RxCtl)); |
148 | printk("lp->lan_saa9730_regs->RxStatus = %x\n", | 147 | printk("lp->lan_saa9730_regs->RxStatus = %x\n", |
149 | INL(&lp->lan_saa9730_regs->RxStatus)); | 148 | readl(&lp->lan_saa9730_regs->RxStatus)); |
150 | for (i = 0; i < LAN_SAA9730_CAM_DWORDS; i++) { | 149 | for (i = 0; i < LAN_SAA9730_CAM_DWORDS; i++) { |
151 | OUTL(i, &lp->lan_saa9730_regs->CamAddress); | 150 | outl(i, &lp->lan_saa9730_regs->CamAddress); |
152 | printk("lp->lan_saa9730_regs->CamData = %x\n", | 151 | printk("lp->lan_saa9730_regs->CamData = %x\n", |
153 | INL(&lp->lan_saa9730_regs->CamData)); | 152 | readl(&lp->lan_saa9730_regs->CamData)); |
154 | } | 153 | } |
155 | printk("lp->stats.tx_packets = %lx\n", lp->stats.tx_packets); | 154 | printk("lp->stats.tx_packets = %lx\n", lp->stats.tx_packets); |
156 | printk("lp->stats.tx_errors = %lx\n", lp->stats.tx_errors); | 155 | printk("lp->stats.tx_errors = %lx\n", lp->stats.tx_errors); |
@@ -178,17 +177,17 @@ static void show_saa9730_regs(struct lan_saa9730_private *lp) | |||
178 | lp->stats.rx_length_errors); | 177 | lp->stats.rx_length_errors); |
179 | 178 | ||
180 | printk("lp->lan_saa9730_regs->DebugPCIMasterAddr = %x\n", | 179 | printk("lp->lan_saa9730_regs->DebugPCIMasterAddr = %x\n", |
181 | INL(&lp->lan_saa9730_regs->DebugPCIMasterAddr)); | 180 | readl(&lp->lan_saa9730_regs->DebugPCIMasterAddr)); |
182 | printk("lp->lan_saa9730_regs->DebugLanTxStateMachine = %x\n", | 181 | printk("lp->lan_saa9730_regs->DebugLanTxStateMachine = %x\n", |
183 | INL(&lp->lan_saa9730_regs->DebugLanTxStateMachine)); | 182 | readl(&lp->lan_saa9730_regs->DebugLanTxStateMachine)); |
184 | printk("lp->lan_saa9730_regs->DebugLanRxStateMachine = %x\n", | 183 | printk("lp->lan_saa9730_regs->DebugLanRxStateMachine = %x\n", |
185 | INL(&lp->lan_saa9730_regs->DebugLanRxStateMachine)); | 184 | readl(&lp->lan_saa9730_regs->DebugLanRxStateMachine)); |
186 | printk("lp->lan_saa9730_regs->DebugLanTxFifoPointers = %x\n", | 185 | printk("lp->lan_saa9730_regs->DebugLanTxFifoPointers = %x\n", |
187 | INL(&lp->lan_saa9730_regs->DebugLanTxFifoPointers)); | 186 | readl(&lp->lan_saa9730_regs->DebugLanTxFifoPointers)); |
188 | printk("lp->lan_saa9730_regs->DebugLanRxFifoPointers = %x\n", | 187 | printk("lp->lan_saa9730_regs->DebugLanRxFifoPointers = %x\n", |
189 | INL(&lp->lan_saa9730_regs->DebugLanRxFifoPointers)); | 188 | readl(&lp->lan_saa9730_regs->DebugLanRxFifoPointers)); |
190 | printk("lp->lan_saa9730_regs->DebugLanCtlStateMachine = %x\n", | 189 | printk("lp->lan_saa9730_regs->DebugLanCtlStateMachine = %x\n", |
191 | INL(&lp->lan_saa9730_regs->DebugLanCtlStateMachine)); | 190 | readl(&lp->lan_saa9730_regs->DebugLanCtlStateMachine)); |
192 | } | 191 | } |
193 | 192 | ||
194 | static void lan_saa9730_buffer_init(struct lan_saa9730_private *lp) | 193 | static void lan_saa9730_buffer_init(struct lan_saa9730_private *lp) |
@@ -214,39 +213,52 @@ static void lan_saa9730_buffer_init(struct lan_saa9730_private *lp) | |||
214 | } | 213 | } |
215 | } | 214 | } |
216 | 215 | ||
217 | static int lan_saa9730_allocate_buffers(struct lan_saa9730_private *lp) | 216 | static void lan_saa9730_free_buffers(struct pci_dev *pdev, |
217 | struct lan_saa9730_private *lp) | ||
218 | { | ||
219 | pci_free_consistent(pdev, lp->buffer_size, lp->buffer_start, | ||
220 | lp->dma_addr); | ||
221 | } | ||
222 | |||
223 | static int lan_saa9730_allocate_buffers(struct pci_dev *pdev, | ||
224 | struct lan_saa9730_private *lp) | ||
218 | { | 225 | { |
219 | unsigned int mem_size; | ||
220 | void *Pa; | 226 | void *Pa; |
221 | unsigned int i, j, RcvBufferSize, TxmBufferSize; | 227 | unsigned int i, j, rxoffset, txoffset; |
222 | unsigned int buffer_start; | 228 | int ret; |
229 | |||
230 | /* Initialize buffer space */ | ||
231 | lp->DmaRcvPackets = LAN_SAA9730_RCV_Q_SIZE; | ||
232 | lp->DmaTxmPackets = LAN_SAA9730_TXM_Q_SIZE; | ||
233 | |||
234 | /* Initialize Rx Buffer Index */ | ||
235 | lp->NextRcvPacketIndex = 0; | ||
236 | lp->NextRcvBufferIndex = 0; | ||
237 | |||
238 | /* Set current buffer index & next available packet index */ | ||
239 | lp->NextTxmPacketIndex = 0; | ||
240 | lp->NextTxmBufferIndex = 0; | ||
241 | lp->PendingTxmPacketIndex = 0; | ||
242 | lp->PendingTxmBufferIndex = 0; | ||
223 | 243 | ||
224 | /* | 244 | /* |
225 | * Allocate all RX and TX packets in one chunk. | 245 | * Allocate all RX and TX packets in one chunk. |
226 | * The Rx and Tx packets must be PACKET_SIZE aligned. | 246 | * The Rx and Tx packets must be PACKET_SIZE aligned. |
227 | */ | 247 | */ |
228 | mem_size = ((LAN_SAA9730_RCV_Q_SIZE + LAN_SAA9730_TXM_Q_SIZE) * | 248 | lp->buffer_size = ((LAN_SAA9730_RCV_Q_SIZE + LAN_SAA9730_TXM_Q_SIZE) * |
229 | LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_BUFFERS) + | 249 | LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_BUFFERS) + |
230 | LAN_SAA9730_PACKET_SIZE; | 250 | LAN_SAA9730_PACKET_SIZE; |
231 | buffer_start = | 251 | lp->buffer_start = pci_alloc_consistent(pdev, lp->buffer_size, |
232 | (unsigned int) kmalloc(mem_size, GFP_DMA | GFP_KERNEL); | 252 | &lp->dma_addr); |
233 | 253 | if (!lp->buffer_start) { | |
234 | if (!buffer_start) | 254 | ret = -ENOMEM; |
235 | return -ENOMEM; | 255 | goto out; |
256 | } | ||
236 | 257 | ||
237 | /* | 258 | Pa = (void *)ALIGN((unsigned long)lp->buffer_start, |
238 | * Set DMA buffer to kseg1 (uncached). | 259 | LAN_SAA9730_PACKET_SIZE); |
239 | * Make sure to flush before using it uncached. | ||
240 | */ | ||
241 | Pa = (void *) KSEG1ADDR((buffer_start + LAN_SAA9730_PACKET_SIZE) & | ||
242 | ~(LAN_SAA9730_PACKET_SIZE - 1)); | ||
243 | dma_cache_wback_inv((unsigned long) Pa, mem_size); | ||
244 | 260 | ||
245 | /* Initialize buffer space */ | 261 | rxoffset = Pa - lp->buffer_start; |
246 | RcvBufferSize = LAN_SAA9730_PACKET_SIZE; | ||
247 | TxmBufferSize = LAN_SAA9730_PACKET_SIZE; | ||
248 | lp->DmaRcvPackets = LAN_SAA9730_RCV_Q_SIZE; | ||
249 | lp->DmaTxmPackets = LAN_SAA9730_TXM_Q_SIZE; | ||
250 | 262 | ||
251 | /* Init RX buffers */ | 263 | /* Init RX buffers */ |
252 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { | 264 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { |
@@ -254,19 +266,21 @@ static int lan_saa9730_allocate_buffers(struct lan_saa9730_private *lp) | |||
254 | *(unsigned int *) Pa = | 266 | *(unsigned int *) Pa = |
255 | cpu_to_le32(RXSF_READY << | 267 | cpu_to_le32(RXSF_READY << |
256 | RX_STAT_CTL_OWNER_SHF); | 268 | RX_STAT_CTL_OWNER_SHF); |
257 | lp->RcvBuffer[i][j] = (unsigned int) Pa; | 269 | lp->RcvBuffer[i][j] = Pa; |
258 | Pa += RcvBufferSize; | 270 | Pa += LAN_SAA9730_PACKET_SIZE; |
259 | } | 271 | } |
260 | } | 272 | } |
261 | 273 | ||
274 | txoffset = Pa - lp->buffer_start; | ||
275 | |||
262 | /* Init TX buffers */ | 276 | /* Init TX buffers */ |
263 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { | 277 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { |
264 | for (j = 0; j < LAN_SAA9730_TXM_Q_SIZE; j++) { | 278 | for (j = 0; j < LAN_SAA9730_TXM_Q_SIZE; j++) { |
265 | *(unsigned int *) Pa = | 279 | *(unsigned int *) Pa = |
266 | cpu_to_le32(TXSF_EMPTY << | 280 | cpu_to_le32(TXSF_EMPTY << |
267 | TX_STAT_CTL_OWNER_SHF); | 281 | TX_STAT_CTL_OWNER_SHF); |
268 | lp->TxmBuffer[i][j] = (unsigned int) Pa; | 282 | lp->TxmBuffer[i][j] = Pa; |
269 | Pa += TxmBufferSize; | 283 | Pa += LAN_SAA9730_PACKET_SIZE; |
270 | } | 284 | } |
271 | } | 285 | } |
272 | 286 | ||
@@ -274,38 +288,33 @@ static int lan_saa9730_allocate_buffers(struct lan_saa9730_private *lp) | |||
274 | * Set rx buffer A and rx buffer B to point to the first two buffer | 288 | * Set rx buffer A and rx buffer B to point to the first two buffer |
275 | * spaces. | 289 | * spaces. |
276 | */ | 290 | */ |
277 | OUTL(PHYSADDR(lp->RcvBuffer[0][0]), | 291 | outl(lp->dma_addr + rxoffset, |
278 | &lp->lan_saa9730_regs->RxBuffA); | 292 | &lp->lan_saa9730_regs->RxBuffA); |
279 | OUTL(PHYSADDR(lp->RcvBuffer[1][0]), | 293 | outl(lp->dma_addr + rxoffset + |
294 | LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_RCV_Q_SIZE, | ||
280 | &lp->lan_saa9730_regs->RxBuffB); | 295 | &lp->lan_saa9730_regs->RxBuffB); |
281 | 296 | ||
282 | /* Initialize Buffer Index */ | ||
283 | lp->NextRcvPacketIndex = 0; | ||
284 | lp->NextRcvToUseIsA = 1; | ||
285 | |||
286 | /* Set current buffer index & next availble packet index */ | ||
287 | lp->NextTxmPacketIndex = 0; | ||
288 | lp->NextTxmBufferIndex = 0; | ||
289 | lp->PendingTxmPacketIndex = 0; | ||
290 | lp->PendingTxmBufferIndex = 0; | ||
291 | |||
292 | /* | 297 | /* |
293 | * Set txm_buf_a and txm_buf_b to point to the first two buffer | 298 | * Set txm_buf_a and txm_buf_b to point to the first two buffer |
294 | * space | 299 | * space |
295 | */ | 300 | */ |
296 | OUTL(PHYSADDR(lp->TxmBuffer[0][0]), | 301 | outl(lp->dma_addr + txoffset, |
297 | &lp->lan_saa9730_regs->TxBuffA); | 302 | &lp->lan_saa9730_regs->TxBuffA); |
298 | OUTL(PHYSADDR(lp->TxmBuffer[1][0]), | 303 | outl(lp->dma_addr + txoffset + |
304 | LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_TXM_Q_SIZE, | ||
299 | &lp->lan_saa9730_regs->TxBuffB); | 305 | &lp->lan_saa9730_regs->TxBuffB); |
300 | 306 | ||
301 | /* Set packet number */ | 307 | /* Set packet number */ |
302 | OUTL((lp->DmaRcvPackets << PK_COUNT_RX_A_SHF) | | 308 | outl((lp->DmaRcvPackets << PK_COUNT_RX_A_SHF) | |
303 | (lp->DmaRcvPackets << PK_COUNT_RX_B_SHF) | | 309 | (lp->DmaRcvPackets << PK_COUNT_RX_B_SHF) | |
304 | (lp->DmaTxmPackets << PK_COUNT_TX_A_SHF) | | 310 | (lp->DmaTxmPackets << PK_COUNT_TX_A_SHF) | |
305 | (lp->DmaTxmPackets << PK_COUNT_TX_B_SHF), | 311 | (lp->DmaTxmPackets << PK_COUNT_TX_B_SHF), |
306 | &lp->lan_saa9730_regs->PacketCount); | 312 | &lp->lan_saa9730_regs->PacketCount); |
307 | 313 | ||
308 | return 0; | 314 | return 0; |
315 | |||
316 | out: | ||
317 | return ret; | ||
309 | } | 318 | } |
310 | 319 | ||
311 | static int lan_saa9730_cam_load(struct lan_saa9730_private *lp) | 320 | static int lan_saa9730_cam_load(struct lan_saa9730_private *lp) |
@@ -317,8 +326,8 @@ static int lan_saa9730_cam_load(struct lan_saa9730_private *lp) | |||
317 | 326 | ||
318 | for (i = 0; i < LAN_SAA9730_CAM_DWORDS; i++) { | 327 | for (i = 0; i < LAN_SAA9730_CAM_DWORDS; i++) { |
319 | /* First set address to where data is written */ | 328 | /* First set address to where data is written */ |
320 | OUTL(i, &lp->lan_saa9730_regs->CamAddress); | 329 | outl(i, &lp->lan_saa9730_regs->CamAddress); |
321 | OUTL((NetworkAddress[0] << 24) | (NetworkAddress[1] << 16) | 330 | outl((NetworkAddress[0] << 24) | (NetworkAddress[1] << 16) |
322 | | (NetworkAddress[2] << 8) | NetworkAddress[3], | 331 | | (NetworkAddress[2] << 8) | NetworkAddress[3], |
323 | &lp->lan_saa9730_regs->CamData); | 332 | &lp->lan_saa9730_regs->CamData); |
324 | NetworkAddress += 4; | 333 | NetworkAddress += 4; |
@@ -328,8 +337,7 @@ static int lan_saa9730_cam_load(struct lan_saa9730_private *lp) | |||
328 | 337 | ||
329 | static int lan_saa9730_cam_init(struct net_device *dev) | 338 | static int lan_saa9730_cam_init(struct net_device *dev) |
330 | { | 339 | { |
331 | struct lan_saa9730_private *lp = | 340 | struct lan_saa9730_private *lp = netdev_priv(dev); |
332 | (struct lan_saa9730_private *) dev->priv; | ||
333 | unsigned int i; | 341 | unsigned int i; |
334 | 342 | ||
335 | /* Copy MAC-address into all entries. */ | 343 | /* Copy MAC-address into all entries. */ |
@@ -347,7 +355,7 @@ static int lan_saa9730_mii_init(struct lan_saa9730_private *lp) | |||
347 | 355 | ||
348 | /* Check link status, spin here till station is not busy. */ | 356 | /* Check link status, spin here till station is not busy. */ |
349 | i = 0; | 357 | i = 0; |
350 | while (INL(&lp->lan_saa9730_regs->StationMgmtCtl) & MD_CA_BUSY) { | 358 | while (readl(&lp->lan_saa9730_regs->StationMgmtCtl) & MD_CA_BUSY) { |
351 | i++; | 359 | i++; |
352 | if (i > 100) { | 360 | if (i > 100) { |
353 | printk("Error: lan_saa9730_mii_init: timeout\n"); | 361 | printk("Error: lan_saa9730_mii_init: timeout\n"); |
@@ -357,12 +365,12 @@ static int lan_saa9730_mii_init(struct lan_saa9730_private *lp) | |||
357 | } | 365 | } |
358 | 366 | ||
359 | /* Now set the control and address register. */ | 367 | /* Now set the control and address register. */ |
360 | OUTL(MD_CA_BUSY | PHY_STATUS | PHY_ADDRESS << MD_CA_PHY_SHF, | 368 | outl(MD_CA_BUSY | PHY_STATUS | PHY_ADDRESS << MD_CA_PHY_SHF, |
361 | &lp->lan_saa9730_regs->StationMgmtCtl); | 369 | &lp->lan_saa9730_regs->StationMgmtCtl); |
362 | 370 | ||
363 | /* check link status, spin here till station is not busy */ | 371 | /* check link status, spin here till station is not busy */ |
364 | i = 0; | 372 | i = 0; |
365 | while (INL(&lp->lan_saa9730_regs->StationMgmtCtl) & MD_CA_BUSY) { | 373 | while (readl(&lp->lan_saa9730_regs->StationMgmtCtl) & MD_CA_BUSY) { |
366 | i++; | 374 | i++; |
367 | if (i > 100) { | 375 | if (i > 100) { |
368 | printk("Error: lan_saa9730_mii_init: timeout\n"); | 376 | printk("Error: lan_saa9730_mii_init: timeout\n"); |
@@ -375,7 +383,7 @@ static int lan_saa9730_mii_init(struct lan_saa9730_private *lp) | |||
375 | mdelay(1); | 383 | mdelay(1); |
376 | 384 | ||
377 | /* Check the link status. */ | 385 | /* Check the link status. */ |
378 | if (INL(&lp->lan_saa9730_regs->StationMgmtData) & | 386 | if (readl(&lp->lan_saa9730_regs->StationMgmtData) & |
379 | PHY_STATUS_LINK_UP) { | 387 | PHY_STATUS_LINK_UP) { |
380 | /* Link is up. */ | 388 | /* Link is up. */ |
381 | return 0; | 389 | return 0; |
@@ -383,14 +391,14 @@ static int lan_saa9730_mii_init(struct lan_saa9730_private *lp) | |||
383 | /* Link is down, reset the PHY first. */ | 391 | /* Link is down, reset the PHY first. */ |
384 | 392 | ||
385 | /* set PHY address = 'CONTROL' */ | 393 | /* set PHY address = 'CONTROL' */ |
386 | OUTL(PHY_ADDRESS << MD_CA_PHY_SHF | MD_CA_WR | PHY_CONTROL, | 394 | outl(PHY_ADDRESS << MD_CA_PHY_SHF | MD_CA_WR | PHY_CONTROL, |
387 | &lp->lan_saa9730_regs->StationMgmtCtl); | 395 | &lp->lan_saa9730_regs->StationMgmtCtl); |
388 | 396 | ||
389 | /* Wait for 1 ms. */ | 397 | /* Wait for 1 ms. */ |
390 | mdelay(1); | 398 | mdelay(1); |
391 | 399 | ||
392 | /* set 'CONTROL' = force reset and renegotiate */ | 400 | /* set 'CONTROL' = force reset and renegotiate */ |
393 | OUTL(PHY_CONTROL_RESET | PHY_CONTROL_AUTO_NEG | | 401 | outl(PHY_CONTROL_RESET | PHY_CONTROL_AUTO_NEG | |
394 | PHY_CONTROL_RESTART_AUTO_NEG, | 402 | PHY_CONTROL_RESTART_AUTO_NEG, |
395 | &lp->lan_saa9730_regs->StationMgmtData); | 403 | &lp->lan_saa9730_regs->StationMgmtData); |
396 | 404 | ||
@@ -398,12 +406,12 @@ static int lan_saa9730_mii_init(struct lan_saa9730_private *lp) | |||
398 | mdelay(50); | 406 | mdelay(50); |
399 | 407 | ||
400 | /* set 'BUSY' to start operation */ | 408 | /* set 'BUSY' to start operation */ |
401 | OUTL(MD_CA_BUSY | PHY_ADDRESS << MD_CA_PHY_SHF | MD_CA_WR | | 409 | outl(MD_CA_BUSY | PHY_ADDRESS << MD_CA_PHY_SHF | MD_CA_WR | |
402 | PHY_CONTROL, &lp->lan_saa9730_regs->StationMgmtCtl); | 410 | PHY_CONTROL, &lp->lan_saa9730_regs->StationMgmtCtl); |
403 | 411 | ||
404 | /* await completion */ | 412 | /* await completion */ |
405 | i = 0; | 413 | i = 0; |
406 | while (INL(&lp->lan_saa9730_regs->StationMgmtCtl) & | 414 | while (readl(&lp->lan_saa9730_regs->StationMgmtCtl) & |
407 | MD_CA_BUSY) { | 415 | MD_CA_BUSY) { |
408 | i++; | 416 | i++; |
409 | if (i > 100) { | 417 | if (i > 100) { |
@@ -419,13 +427,13 @@ static int lan_saa9730_mii_init(struct lan_saa9730_private *lp) | |||
419 | 427 | ||
420 | for (l = 0; l < 2; l++) { | 428 | for (l = 0; l < 2; l++) { |
421 | /* set PHY address = 'STATUS' */ | 429 | /* set PHY address = 'STATUS' */ |
422 | OUTL(MD_CA_BUSY | PHY_ADDRESS << MD_CA_PHY_SHF | | 430 | outl(MD_CA_BUSY | PHY_ADDRESS << MD_CA_PHY_SHF | |
423 | PHY_STATUS, | 431 | PHY_STATUS, |
424 | &lp->lan_saa9730_regs->StationMgmtCtl); | 432 | &lp->lan_saa9730_regs->StationMgmtCtl); |
425 | 433 | ||
426 | /* await completion */ | 434 | /* await completion */ |
427 | i = 0; | 435 | i = 0; |
428 | while (INL(&lp->lan_saa9730_regs->StationMgmtCtl) & | 436 | while (readl(&lp->lan_saa9730_regs->StationMgmtCtl) & |
429 | MD_CA_BUSY) { | 437 | MD_CA_BUSY) { |
430 | i++; | 438 | i++; |
431 | if (i > 100) { | 439 | if (i > 100) { |
@@ -440,7 +448,7 @@ static int lan_saa9730_mii_init(struct lan_saa9730_private *lp) | |||
440 | mdelay(3000); | 448 | mdelay(3000); |
441 | 449 | ||
442 | /* check the link status */ | 450 | /* check the link status */ |
443 | if (INL(&lp->lan_saa9730_regs->StationMgmtData) & | 451 | if (readl(&lp->lan_saa9730_regs->StationMgmtData) & |
444 | PHY_STATUS_LINK_UP) { | 452 | PHY_STATUS_LINK_UP) { |
445 | /* link is up */ | 453 | /* link is up */ |
446 | break; | 454 | break; |
@@ -454,7 +462,7 @@ static int lan_saa9730_mii_init(struct lan_saa9730_private *lp) | |||
454 | static int lan_saa9730_control_init(struct lan_saa9730_private *lp) | 462 | static int lan_saa9730_control_init(struct lan_saa9730_private *lp) |
455 | { | 463 | { |
456 | /* Initialize DMA control register. */ | 464 | /* Initialize DMA control register. */ |
457 | OUTL((LANMB_ANY << DMA_CTL_MAX_XFER_SHF) | | 465 | outl((LANMB_ANY << DMA_CTL_MAX_XFER_SHF) | |
458 | (LANEND_LITTLE << DMA_CTL_ENDIAN_SHF) | | 466 | (LANEND_LITTLE << DMA_CTL_ENDIAN_SHF) | |
459 | (LAN_SAA9730_RCV_Q_INT_THRESHOLD << DMA_CTL_RX_INT_COUNT_SHF) | 467 | (LAN_SAA9730_RCV_Q_INT_THRESHOLD << DMA_CTL_RX_INT_COUNT_SHF) |
460 | | DMA_CTL_RX_INT_TO_EN | DMA_CTL_RX_INT_EN | | 468 | | DMA_CTL_RX_INT_TO_EN | DMA_CTL_RX_INT_EN | |
@@ -462,27 +470,27 @@ static int lan_saa9730_control_init(struct lan_saa9730_private *lp) | |||
462 | &lp->lan_saa9730_regs->LanDmaCtl); | 470 | &lp->lan_saa9730_regs->LanDmaCtl); |
463 | 471 | ||
464 | /* Initial MAC control register. */ | 472 | /* Initial MAC control register. */ |
465 | OUTL((MACCM_MII << MAC_CONTROL_CONN_SHF) | MAC_CONTROL_FULL_DUP, | 473 | outl((MACCM_MII << MAC_CONTROL_CONN_SHF) | MAC_CONTROL_FULL_DUP, |
466 | &lp->lan_saa9730_regs->MacCtl); | 474 | &lp->lan_saa9730_regs->MacCtl); |
467 | 475 | ||
468 | /* Initialize CAM control register. */ | 476 | /* Initialize CAM control register. */ |
469 | OUTL(CAM_CONTROL_COMP_EN | CAM_CONTROL_BROAD_ACC, | 477 | outl(CAM_CONTROL_COMP_EN | CAM_CONTROL_BROAD_ACC, |
470 | &lp->lan_saa9730_regs->CamCtl); | 478 | &lp->lan_saa9730_regs->CamCtl); |
471 | 479 | ||
472 | /* | 480 | /* |
473 | * Initialize CAM enable register, only turn on first entry, should | 481 | * Initialize CAM enable register, only turn on first entry, should |
474 | * contain own addr. | 482 | * contain own addr. |
475 | */ | 483 | */ |
476 | OUTL(0x0001, &lp->lan_saa9730_regs->CamEnable); | 484 | outl(0x0001, &lp->lan_saa9730_regs->CamEnable); |
477 | 485 | ||
478 | /* Initialize Tx control register */ | 486 | /* Initialize Tx control register */ |
479 | OUTL(TX_CTL_EN_COMP, &lp->lan_saa9730_regs->TxCtl); | 487 | outl(TX_CTL_EN_COMP, &lp->lan_saa9730_regs->TxCtl); |
480 | 488 | ||
481 | /* Initialize Rcv control register */ | 489 | /* Initialize Rcv control register */ |
482 | OUTL(RX_CTL_STRIP_CRC, &lp->lan_saa9730_regs->RxCtl); | 490 | outl(RX_CTL_STRIP_CRC, &lp->lan_saa9730_regs->RxCtl); |
483 | 491 | ||
484 | /* Reset DMA engine */ | 492 | /* Reset DMA engine */ |
485 | OUTL(DMA_TEST_SW_RESET, &lp->lan_saa9730_regs->DmaTest); | 493 | outl(DMA_TEST_SW_RESET, &lp->lan_saa9730_regs->DmaTest); |
486 | 494 | ||
487 | return 0; | 495 | return 0; |
488 | } | 496 | } |
@@ -492,13 +500,13 @@ static int lan_saa9730_stop(struct lan_saa9730_private *lp) | |||
492 | int i; | 500 | int i; |
493 | 501 | ||
494 | /* Stop DMA first */ | 502 | /* Stop DMA first */ |
495 | OUTL(INL(&lp->lan_saa9730_regs->LanDmaCtl) & | 503 | outl(readl(&lp->lan_saa9730_regs->LanDmaCtl) & |
496 | ~(DMA_CTL_EN_TX_DMA | DMA_CTL_EN_RX_DMA), | 504 | ~(DMA_CTL_EN_TX_DMA | DMA_CTL_EN_RX_DMA), |
497 | &lp->lan_saa9730_regs->LanDmaCtl); | 505 | &lp->lan_saa9730_regs->LanDmaCtl); |
498 | 506 | ||
499 | /* Set the SW Reset bits in DMA and MAC control registers */ | 507 | /* Set the SW Reset bits in DMA and MAC control registers */ |
500 | OUTL(DMA_TEST_SW_RESET, &lp->lan_saa9730_regs->DmaTest); | 508 | outl(DMA_TEST_SW_RESET, &lp->lan_saa9730_regs->DmaTest); |
501 | OUTL(INL(&lp->lan_saa9730_regs->MacCtl) | MAC_CONTROL_RESET, | 509 | outl(readl(&lp->lan_saa9730_regs->MacCtl) | MAC_CONTROL_RESET, |
502 | &lp->lan_saa9730_regs->MacCtl); | 510 | &lp->lan_saa9730_regs->MacCtl); |
503 | 511 | ||
504 | /* | 512 | /* |
@@ -506,7 +514,7 @@ static int lan_saa9730_stop(struct lan_saa9730_private *lp) | |||
506 | * when the reset is done. | 514 | * when the reset is done. |
507 | */ | 515 | */ |
508 | i = 0; | 516 | i = 0; |
509 | while (INL(&lp->lan_saa9730_regs->MacCtl) & MAC_CONTROL_RESET) { | 517 | while (readl(&lp->lan_saa9730_regs->MacCtl) & MAC_CONTROL_RESET) { |
510 | i++; | 518 | i++; |
511 | if (i > 100) { | 519 | if (i > 100) { |
512 | printk | 520 | printk |
@@ -524,7 +532,7 @@ static int lan_saa9730_dma_init(struct lan_saa9730_private *lp) | |||
524 | /* Stop lan controller. */ | 532 | /* Stop lan controller. */ |
525 | lan_saa9730_stop(lp); | 533 | lan_saa9730_stop(lp); |
526 | 534 | ||
527 | OUTL(LAN_SAA9730_DEFAULT_TIME_OUT_CNT, | 535 | outl(LAN_SAA9730_DEFAULT_TIME_OUT_CNT, |
528 | &lp->lan_saa9730_regs->Timeout); | 536 | &lp->lan_saa9730_regs->Timeout); |
529 | 537 | ||
530 | return 0; | 538 | return 0; |
@@ -536,28 +544,27 @@ static int lan_saa9730_start(struct lan_saa9730_private *lp) | |||
536 | 544 | ||
537 | /* Initialize Rx Buffer Index */ | 545 | /* Initialize Rx Buffer Index */ |
538 | lp->NextRcvPacketIndex = 0; | 546 | lp->NextRcvPacketIndex = 0; |
539 | lp->NextRcvToUseIsA = 1; | 547 | lp->NextRcvBufferIndex = 0; |
540 | 548 | ||
541 | /* Set current buffer index & next availble packet index */ | 549 | /* Set current buffer index & next available packet index */ |
542 | lp->NextTxmPacketIndex = 0; | 550 | lp->NextTxmPacketIndex = 0; |
543 | lp->NextTxmBufferIndex = 0; | 551 | lp->NextTxmBufferIndex = 0; |
544 | lp->PendingTxmPacketIndex = 0; | 552 | lp->PendingTxmPacketIndex = 0; |
545 | lp->PendingTxmBufferIndex = 0; | 553 | lp->PendingTxmBufferIndex = 0; |
546 | 554 | ||
547 | OUTL(INL(&lp->lan_saa9730_regs->LanDmaCtl) | DMA_CTL_EN_TX_DMA | | 555 | outl(readl(&lp->lan_saa9730_regs->LanDmaCtl) | DMA_CTL_EN_TX_DMA | |
548 | DMA_CTL_EN_RX_DMA, &lp->lan_saa9730_regs->LanDmaCtl); | 556 | DMA_CTL_EN_RX_DMA, &lp->lan_saa9730_regs->LanDmaCtl); |
549 | 557 | ||
550 | /* For Tx, turn on MAC then DMA */ | 558 | /* For Tx, turn on MAC then DMA */ |
551 | OUTL(INL(&lp->lan_saa9730_regs->TxCtl) | TX_CTL_TX_EN, | 559 | outl(readl(&lp->lan_saa9730_regs->TxCtl) | TX_CTL_TX_EN, |
552 | &lp->lan_saa9730_regs->TxCtl); | 560 | &lp->lan_saa9730_regs->TxCtl); |
553 | 561 | ||
554 | /* For Rx, turn on DMA then MAC */ | 562 | /* For Rx, turn on DMA then MAC */ |
555 | OUTL(INL(&lp->lan_saa9730_regs->RxCtl) | RX_CTL_RX_EN, | 563 | outl(readl(&lp->lan_saa9730_regs->RxCtl) | RX_CTL_RX_EN, |
556 | &lp->lan_saa9730_regs->RxCtl); | 564 | &lp->lan_saa9730_regs->RxCtl); |
557 | 565 | ||
558 | /* Set Ok2Use to let hardware owns the buffers */ | 566 | /* Set Ok2Use to let hardware own the buffers. */ |
559 | OUTL(OK2USE_RX_A | OK2USE_RX_B | OK2USE_TX_A | OK2USE_TX_B, | 567 | outl(OK2USE_RX_A | OK2USE_RX_B, &lp->lan_saa9730_regs->Ok2Use); |
560 | &lp->lan_saa9730_regs->Ok2Use); | ||
561 | 568 | ||
562 | return 0; | 569 | return 0; |
563 | } | 570 | } |
@@ -572,8 +579,7 @@ static int lan_saa9730_restart(struct lan_saa9730_private *lp) | |||
572 | 579 | ||
573 | static int lan_saa9730_tx(struct net_device *dev) | 580 | static int lan_saa9730_tx(struct net_device *dev) |
574 | { | 581 | { |
575 | struct lan_saa9730_private *lp = | 582 | struct lan_saa9730_private *lp = netdev_priv(dev); |
576 | (struct lan_saa9730_private *) dev->priv; | ||
577 | unsigned int *pPacket; | 583 | unsigned int *pPacket; |
578 | unsigned int tx_status; | 584 | unsigned int tx_status; |
579 | 585 | ||
@@ -581,13 +587,11 @@ static int lan_saa9730_tx(struct net_device *dev) | |||
581 | printk("lan_saa9730_tx interrupt\n"); | 587 | printk("lan_saa9730_tx interrupt\n"); |
582 | 588 | ||
583 | /* Clear interrupt. */ | 589 | /* Clear interrupt. */ |
584 | OUTL(DMA_STATUS_MAC_TX_INT, &lp->lan_saa9730_regs->DmaStatus); | 590 | outl(DMA_STATUS_MAC_TX_INT, &lp->lan_saa9730_regs->DmaStatus); |
585 | 591 | ||
586 | while (1) { | 592 | while (1) { |
587 | pPacket = | 593 | pPacket = lp->TxmBuffer[lp->PendingTxmBufferIndex] |
588 | (unsigned int *) lp->TxmBuffer[lp-> | 594 | [lp->PendingTxmPacketIndex]; |
589 | PendingTxmBufferIndex] | ||
590 | [lp->PendingTxmPacketIndex]; | ||
591 | 595 | ||
592 | /* Get status of first packet transmitted. */ | 596 | /* Get status of first packet transmitted. */ |
593 | tx_status = le32_to_cpu(*pPacket); | 597 | tx_status = le32_to_cpu(*pPacket); |
@@ -605,23 +609,22 @@ static int lan_saa9730_tx(struct net_device *dev) | |||
605 | lp->stats.tx_errors++; | 609 | lp->stats.tx_errors++; |
606 | if (tx_status & | 610 | if (tx_status & |
607 | (TX_STATUS_EX_COLL << TX_STAT_CTL_STATUS_SHF)) | 611 | (TX_STATUS_EX_COLL << TX_STAT_CTL_STATUS_SHF)) |
608 | lp->stats.tx_aborted_errors++; | 612 | lp->stats.tx_aborted_errors++; |
609 | if (tx_status & | 613 | if (tx_status & |
610 | (TX_STATUS_LATE_COLL << | 614 | (TX_STATUS_LATE_COLL << TX_STAT_CTL_STATUS_SHF)) |
611 | TX_STAT_CTL_STATUS_SHF)) lp->stats. | 615 | lp->stats.tx_window_errors++; |
612 | tx_window_errors++; | ||
613 | if (tx_status & | 616 | if (tx_status & |
614 | (TX_STATUS_L_CARR << TX_STAT_CTL_STATUS_SHF)) | 617 | (TX_STATUS_L_CARR << TX_STAT_CTL_STATUS_SHF)) |
615 | lp->stats.tx_carrier_errors++; | 618 | lp->stats.tx_carrier_errors++; |
616 | if (tx_status & | 619 | if (tx_status & |
617 | (TX_STATUS_UNDER << TX_STAT_CTL_STATUS_SHF)) | 620 | (TX_STATUS_UNDER << TX_STAT_CTL_STATUS_SHF)) |
618 | lp->stats.tx_fifo_errors++; | 621 | lp->stats.tx_fifo_errors++; |
619 | if (tx_status & | 622 | if (tx_status & |
620 | (TX_STATUS_SQ_ERR << TX_STAT_CTL_STATUS_SHF)) | 623 | (TX_STATUS_SQ_ERR << TX_STAT_CTL_STATUS_SHF)) |
621 | lp->stats.tx_heartbeat_errors++; | 624 | lp->stats.tx_heartbeat_errors++; |
622 | 625 | ||
623 | lp->stats.collisions += | 626 | lp->stats.collisions += |
624 | tx_status & TX_STATUS_TX_COLL_MSK; | 627 | tx_status & TX_STATUS_TX_COLL_MSK; |
625 | } | 628 | } |
626 | 629 | ||
627 | /* Free buffer. */ | 630 | /* Free buffer. */ |
@@ -636,21 +639,15 @@ static int lan_saa9730_tx(struct net_device *dev) | |||
636 | } | 639 | } |
637 | } | 640 | } |
638 | 641 | ||
639 | /* Make sure A and B are available to hardware. */ | 642 | /* The tx buffer is no longer full. */ |
640 | OUTL(OK2USE_TX_A | OK2USE_TX_B, &lp->lan_saa9730_regs->Ok2Use); | 643 | netif_wake_queue(dev); |
641 | |||
642 | if (netif_queue_stopped(dev)) { | ||
643 | /* The tx buffer is no longer full. */ | ||
644 | netif_wake_queue(dev); | ||
645 | } | ||
646 | 644 | ||
647 | return 0; | 645 | return 0; |
648 | } | 646 | } |
649 | 647 | ||
650 | static int lan_saa9730_rx(struct net_device *dev) | 648 | static int lan_saa9730_rx(struct net_device *dev) |
651 | { | 649 | { |
652 | struct lan_saa9730_private *lp = | 650 | struct lan_saa9730_private *lp = netdev_priv(dev); |
653 | (struct lan_saa9730_private *) dev->priv; | ||
654 | int len = 0; | 651 | int len = 0; |
655 | struct sk_buff *skb = 0; | 652 | struct sk_buff *skb = 0; |
656 | unsigned int rx_status; | 653 | unsigned int rx_status; |
@@ -663,16 +660,13 @@ static int lan_saa9730_rx(struct net_device *dev) | |||
663 | printk("lan_saa9730_rx interrupt\n"); | 660 | printk("lan_saa9730_rx interrupt\n"); |
664 | 661 | ||
665 | /* Clear receive interrupts. */ | 662 | /* Clear receive interrupts. */ |
666 | OUTL(DMA_STATUS_MAC_RX_INT | DMA_STATUS_RX_INT | | 663 | outl(DMA_STATUS_MAC_RX_INT | DMA_STATUS_RX_INT | |
667 | DMA_STATUS_RX_TO_INT, &lp->lan_saa9730_regs->DmaStatus); | 664 | DMA_STATUS_RX_TO_INT, &lp->lan_saa9730_regs->DmaStatus); |
668 | 665 | ||
669 | /* Address next packet */ | 666 | /* Address next packet */ |
670 | if (lp->NextRcvToUseIsA) | 667 | BufferIndex = lp->NextRcvBufferIndex; |
671 | BufferIndex = 0; | ||
672 | else | ||
673 | BufferIndex = 1; | ||
674 | PacketIndex = lp->NextRcvPacketIndex; | 668 | PacketIndex = lp->NextRcvPacketIndex; |
675 | pPacket = (unsigned int *) lp->RcvBuffer[BufferIndex][PacketIndex]; | 669 | pPacket = lp->RcvBuffer[BufferIndex][PacketIndex]; |
676 | rx_status = le32_to_cpu(*pPacket); | 670 | rx_status = le32_to_cpu(*pPacket); |
677 | 671 | ||
678 | /* Process each packet. */ | 672 | /* Process each packet. */ |
@@ -715,51 +709,39 @@ static int lan_saa9730_rx(struct net_device *dev) | |||
715 | lp->stats.rx_errors++; | 709 | lp->stats.rx_errors++; |
716 | if (rx_status & | 710 | if (rx_status & |
717 | (RX_STATUS_CRC_ERR << RX_STAT_CTL_STATUS_SHF)) | 711 | (RX_STATUS_CRC_ERR << RX_STAT_CTL_STATUS_SHF)) |
718 | lp->stats.rx_crc_errors++; | 712 | lp->stats.rx_crc_errors++; |
719 | if (rx_status & | 713 | if (rx_status & |
720 | (RX_STATUS_ALIGN_ERR << | 714 | (RX_STATUS_ALIGN_ERR << RX_STAT_CTL_STATUS_SHF)) |
721 | RX_STAT_CTL_STATUS_SHF)) lp->stats. | 715 | lp->stats.rx_frame_errors++; |
722 | rx_frame_errors++; | ||
723 | if (rx_status & | 716 | if (rx_status & |
724 | (RX_STATUS_OVERFLOW << RX_STAT_CTL_STATUS_SHF)) | 717 | (RX_STATUS_OVERFLOW << RX_STAT_CTL_STATUS_SHF)) |
725 | lp->stats.rx_fifo_errors++; | 718 | lp->stats.rx_fifo_errors++; |
726 | if (rx_status & | 719 | if (rx_status & |
727 | (RX_STATUS_LONG_ERR << RX_STAT_CTL_STATUS_SHF)) | 720 | (RX_STATUS_LONG_ERR << RX_STAT_CTL_STATUS_SHF)) |
728 | lp->stats.rx_length_errors++; | 721 | lp->stats.rx_length_errors++; |
729 | } | 722 | } |
730 | 723 | ||
731 | /* Indicate we have processed the buffer. */ | 724 | /* Indicate we have processed the buffer. */ |
732 | *pPacket = | 725 | *pPacket = cpu_to_le32(RXSF_READY << RX_STAT_CTL_OWNER_SHF); |
733 | cpu_to_le32(RXSF_READY << RX_STAT_CTL_OWNER_SHF); | 726 | |
727 | /* Make sure A or B is available to hardware as appropriate. */ | ||
728 | outl(BufferIndex ? OK2USE_RX_B : OK2USE_RX_A, | ||
729 | &lp->lan_saa9730_regs->Ok2Use); | ||
734 | 730 | ||
735 | /* Go to next packet in sequence. */ | 731 | /* Go to next packet in sequence. */ |
736 | lp->NextRcvPacketIndex++; | 732 | lp->NextRcvPacketIndex++; |
737 | if (lp->NextRcvPacketIndex >= LAN_SAA9730_RCV_Q_SIZE) { | 733 | if (lp->NextRcvPacketIndex >= LAN_SAA9730_RCV_Q_SIZE) { |
738 | lp->NextRcvPacketIndex = 0; | 734 | lp->NextRcvPacketIndex = 0; |
739 | if (BufferIndex) { | 735 | lp->NextRcvBufferIndex ^= 1; |
740 | lp->NextRcvToUseIsA = 1; | ||
741 | } else { | ||
742 | lp->NextRcvToUseIsA = 0; | ||
743 | } | ||
744 | } | 736 | } |
745 | OUTL(OK2USE_RX_A | OK2USE_RX_B, | ||
746 | &lp->lan_saa9730_regs->Ok2Use); | ||
747 | 737 | ||
748 | /* Address next packet */ | 738 | /* Address next packet */ |
749 | if (lp->NextRcvToUseIsA) | 739 | BufferIndex = lp->NextRcvBufferIndex; |
750 | BufferIndex = 0; | ||
751 | else | ||
752 | BufferIndex = 1; | ||
753 | PacketIndex = lp->NextRcvPacketIndex; | 740 | PacketIndex = lp->NextRcvPacketIndex; |
754 | pPacket = | 741 | pPacket = lp->RcvBuffer[BufferIndex][PacketIndex]; |
755 | (unsigned int *) lp-> | ||
756 | RcvBuffer[BufferIndex][PacketIndex]; | ||
757 | rx_status = le32_to_cpu(*pPacket); | 742 | rx_status = le32_to_cpu(*pPacket); |
758 | } | 743 | } |
759 | 744 | ||
760 | /* Make sure A and B are available to hardware. */ | ||
761 | OUTL(OK2USE_RX_A | OK2USE_RX_B, &lp->lan_saa9730_regs->Ok2Use); | ||
762 | |||
763 | return 0; | 745 | return 0; |
764 | } | 746 | } |
765 | 747 | ||
@@ -767,8 +749,7 @@ static irqreturn_t lan_saa9730_interrupt(const int irq, void *dev_id, | |||
767 | struct pt_regs *regs) | 749 | struct pt_regs *regs) |
768 | { | 750 | { |
769 | struct net_device *dev = (struct net_device *) dev_id; | 751 | struct net_device *dev = (struct net_device *) dev_id; |
770 | struct lan_saa9730_private *lp = | 752 | struct lan_saa9730_private *lp = netdev_priv(dev); |
771 | (struct lan_saa9730_private *) dev->priv; | ||
772 | 753 | ||
773 | if (lan_saa9730_debug > 5) | 754 | if (lan_saa9730_debug > 5) |
774 | printk("lan_saa9730_interrupt\n"); | 755 | printk("lan_saa9730_interrupt\n"); |
@@ -780,11 +761,11 @@ static irqreturn_t lan_saa9730_interrupt(const int irq, void *dev_id, | |||
780 | evm_saa9730_clear_lan_int(lp); | 761 | evm_saa9730_clear_lan_int(lp); |
781 | 762 | ||
782 | /* Service pending transmit interrupts. */ | 763 | /* Service pending transmit interrupts. */ |
783 | if (INL(&lp->lan_saa9730_regs->DmaStatus) & DMA_STATUS_MAC_TX_INT) | 764 | if (readl(&lp->lan_saa9730_regs->DmaStatus) & DMA_STATUS_MAC_TX_INT) |
784 | lan_saa9730_tx(dev); | 765 | lan_saa9730_tx(dev); |
785 | 766 | ||
786 | /* Service pending receive interrupts. */ | 767 | /* Service pending receive interrupts. */ |
787 | if (INL(&lp->lan_saa9730_regs->DmaStatus) & | 768 | if (readl(&lp->lan_saa9730_regs->DmaStatus) & |
788 | (DMA_STATUS_MAC_RX_INT | DMA_STATUS_RX_INT | | 769 | (DMA_STATUS_MAC_RX_INT | DMA_STATUS_RX_INT | |
789 | DMA_STATUS_RX_TO_INT)) lan_saa9730_rx(dev); | 770 | DMA_STATUS_RX_TO_INT)) lan_saa9730_rx(dev); |
790 | 771 | ||
@@ -794,15 +775,9 @@ static irqreturn_t lan_saa9730_interrupt(const int irq, void *dev_id, | |||
794 | return IRQ_HANDLED; | 775 | return IRQ_HANDLED; |
795 | } | 776 | } |
796 | 777 | ||
797 | static int lan_saa9730_open_fail(struct net_device *dev) | ||
798 | { | ||
799 | return -ENODEV; | ||
800 | } | ||
801 | |||
802 | static int lan_saa9730_open(struct net_device *dev) | 778 | static int lan_saa9730_open(struct net_device *dev) |
803 | { | 779 | { |
804 | struct lan_saa9730_private *lp = | 780 | struct lan_saa9730_private *lp = netdev_priv(dev); |
805 | (struct lan_saa9730_private *) dev->priv; | ||
806 | 781 | ||
807 | /* Associate IRQ with lan_saa9730_interrupt */ | 782 | /* Associate IRQ with lan_saa9730_interrupt */ |
808 | if (request_irq(dev->irq, &lan_saa9730_interrupt, 0, "SAA9730 Eth", | 783 | if (request_irq(dev->irq, &lan_saa9730_interrupt, 0, "SAA9730 Eth", |
@@ -834,15 +809,13 @@ static int lan_saa9730_write(struct lan_saa9730_private *lp, | |||
834 | int PacketIndex; | 809 | int PacketIndex; |
835 | 810 | ||
836 | if (lan_saa9730_debug > 5) | 811 | if (lan_saa9730_debug > 5) |
837 | printk("lan_saa9730_write: skb=%08x\n", | 812 | printk("lan_saa9730_write: skb=%p\n", skb); |
838 | (unsigned int) skb); | ||
839 | 813 | ||
840 | BufferIndex = lp->NextTxmBufferIndex; | 814 | BufferIndex = lp->NextTxmBufferIndex; |
841 | PacketIndex = lp->NextTxmPacketIndex; | 815 | PacketIndex = lp->NextTxmPacketIndex; |
842 | 816 | ||
843 | tx_status = | 817 | tx_status = le32_to_cpu(*(unsigned int *)lp->TxmBuffer[BufferIndex] |
844 | le32_to_cpu(*(unsigned int *) lp-> | 818 | [PacketIndex]); |
845 | TxmBuffer[BufferIndex][PacketIndex]); | ||
846 | if ((tx_status & TX_STAT_CTL_OWNER_MSK) != | 819 | if ((tx_status & TX_STAT_CTL_OWNER_MSK) != |
847 | (TXSF_EMPTY << TX_STAT_CTL_OWNER_SHF)) { | 820 | (TXSF_EMPTY << TX_STAT_CTL_OWNER_SHF)) { |
848 | if (lan_saa9730_debug > 4) | 821 | if (lan_saa9730_debug > 4) |
@@ -858,29 +831,29 @@ static int lan_saa9730_write(struct lan_saa9730_private *lp, | |||
858 | lp->NextTxmBufferIndex ^= 1; | 831 | lp->NextTxmBufferIndex ^= 1; |
859 | } | 832 | } |
860 | 833 | ||
861 | pbPacketData = | 834 | pbPacketData = lp->TxmBuffer[BufferIndex][PacketIndex]; |
862 | (unsigned char *) lp->TxmBuffer[BufferIndex][PacketIndex]; | ||
863 | pbPacketData += 4; | 835 | pbPacketData += 4; |
864 | 836 | ||
865 | /* copy the bits */ | 837 | /* copy the bits */ |
866 | memcpy(pbPacketData, pbData, len); | 838 | memcpy(pbPacketData, pbData, len); |
867 | 839 | ||
868 | /* Set transmit status for hardware */ | 840 | /* Set transmit status for hardware */ |
869 | *(unsigned int *) lp->TxmBuffer[BufferIndex][PacketIndex] = | 841 | *(unsigned int *)lp->TxmBuffer[BufferIndex][PacketIndex] = |
870 | cpu_to_le32((TXSF_READY << TX_STAT_CTL_OWNER_SHF) | | 842 | cpu_to_le32((TXSF_READY << TX_STAT_CTL_OWNER_SHF) | |
871 | (TX_STAT_CTL_INT_AFTER_TX << TX_STAT_CTL_FRAME_SHF) | 843 | (TX_STAT_CTL_INT_AFTER_TX << |
872 | | (len << TX_STAT_CTL_LENGTH_SHF)); | 844 | TX_STAT_CTL_FRAME_SHF) | |
873 | 845 | (len << TX_STAT_CTL_LENGTH_SHF)); | |
874 | /* Set hardware tx buffer. */ | 846 | |
875 | OUTL(OK2USE_TX_A | OK2USE_TX_B, &lp->lan_saa9730_regs->Ok2Use); | 847 | /* Make sure A or B is available to hardware as appropriate. */ |
848 | outl(BufferIndex ? OK2USE_TX_B : OK2USE_TX_A, | ||
849 | &lp->lan_saa9730_regs->Ok2Use); | ||
876 | 850 | ||
877 | return 0; | 851 | return 0; |
878 | } | 852 | } |
879 | 853 | ||
880 | static void lan_saa9730_tx_timeout(struct net_device *dev) | 854 | static void lan_saa9730_tx_timeout(struct net_device *dev) |
881 | { | 855 | { |
882 | struct lan_saa9730_private *lp = | 856 | struct lan_saa9730_private *lp = netdev_priv(dev); |
883 | (struct lan_saa9730_private *) dev->priv; | ||
884 | 857 | ||
885 | /* Transmitter timeout, serious problems */ | 858 | /* Transmitter timeout, serious problems */ |
886 | lp->stats.tx_errors++; | 859 | lp->stats.tx_errors++; |
@@ -889,20 +862,19 @@ static void lan_saa9730_tx_timeout(struct net_device *dev) | |||
889 | lan_saa9730_restart(lp); | 862 | lan_saa9730_restart(lp); |
890 | 863 | ||
891 | dev->trans_start = jiffies; | 864 | dev->trans_start = jiffies; |
892 | netif_start_queue(dev); | 865 | netif_wake_queue(dev); |
893 | } | 866 | } |
894 | 867 | ||
895 | static int lan_saa9730_start_xmit(struct sk_buff *skb, | 868 | static int lan_saa9730_start_xmit(struct sk_buff *skb, |
896 | struct net_device *dev) | 869 | struct net_device *dev) |
897 | { | 870 | { |
898 | struct lan_saa9730_private *lp = | 871 | struct lan_saa9730_private *lp = netdev_priv(dev); |
899 | (struct lan_saa9730_private *) dev->priv; | ||
900 | unsigned long flags; | 872 | unsigned long flags; |
901 | int skblen; | 873 | int skblen; |
902 | int len; | 874 | int len; |
903 | 875 | ||
904 | if (lan_saa9730_debug > 4) | 876 | if (lan_saa9730_debug > 4) |
905 | printk("Send packet: skb=%08x\n", (unsigned int) skb); | 877 | printk("Send packet: skb=%p\n", skb); |
906 | 878 | ||
907 | skblen = skb->len; | 879 | skblen = skb->len; |
908 | 880 | ||
@@ -912,8 +884,7 @@ static int lan_saa9730_start_xmit(struct sk_buff *skb, | |||
912 | 884 | ||
913 | if (lan_saa9730_write(lp, skb, skblen)) { | 885 | if (lan_saa9730_write(lp, skb, skblen)) { |
914 | spin_unlock_irqrestore(&lp->lock, flags); | 886 | spin_unlock_irqrestore(&lp->lock, flags); |
915 | printk("Error when writing packet to controller: skb=%08x\n", | 887 | printk("Error when writing packet to controller: skb=%p\n", skb); |
916 | (unsigned int) skb); | ||
917 | netif_stop_queue(dev); | 888 | netif_stop_queue(dev); |
918 | return -1; | 889 | return -1; |
919 | } | 890 | } |
@@ -922,7 +893,7 @@ static int lan_saa9730_start_xmit(struct sk_buff *skb, | |||
922 | lp->stats.tx_packets++; | 893 | lp->stats.tx_packets++; |
923 | 894 | ||
924 | dev->trans_start = jiffies; | 895 | dev->trans_start = jiffies; |
925 | netif_start_queue(dev); | 896 | netif_wake_queue(dev); |
926 | dev_kfree_skb(skb); | 897 | dev_kfree_skb(skb); |
927 | 898 | ||
928 | spin_unlock_irqrestore(&lp->lock, flags); | 899 | spin_unlock_irqrestore(&lp->lock, flags); |
@@ -932,8 +903,7 @@ static int lan_saa9730_start_xmit(struct sk_buff *skb, | |||
932 | 903 | ||
933 | static int lan_saa9730_close(struct net_device *dev) | 904 | static int lan_saa9730_close(struct net_device *dev) |
934 | { | 905 | { |
935 | struct lan_saa9730_private *lp = | 906 | struct lan_saa9730_private *lp = netdev_priv(dev); |
936 | (struct lan_saa9730_private *) dev->priv; | ||
937 | 907 | ||
938 | if (lan_saa9730_debug > 1) | 908 | if (lan_saa9730_debug > 1) |
939 | printk("lan_saa9730_close:\n"); | 909 | printk("lan_saa9730_close:\n"); |
@@ -955,29 +925,27 @@ static int lan_saa9730_close(struct net_device *dev) | |||
955 | static struct net_device_stats *lan_saa9730_get_stats(struct net_device | 925 | static struct net_device_stats *lan_saa9730_get_stats(struct net_device |
956 | *dev) | 926 | *dev) |
957 | { | 927 | { |
958 | struct lan_saa9730_private *lp = | 928 | struct lan_saa9730_private *lp = netdev_priv(dev); |
959 | (struct lan_saa9730_private *) dev->priv; | ||
960 | 929 | ||
961 | return &lp->stats; | 930 | return &lp->stats; |
962 | } | 931 | } |
963 | 932 | ||
964 | static void lan_saa9730_set_multicast(struct net_device *dev) | 933 | static void lan_saa9730_set_multicast(struct net_device *dev) |
965 | { | 934 | { |
966 | struct lan_saa9730_private *lp = | 935 | struct lan_saa9730_private *lp = netdev_priv(dev); |
967 | (struct lan_saa9730_private *) dev->priv; | ||
968 | 936 | ||
969 | /* Stop the controller */ | 937 | /* Stop the controller */ |
970 | lan_saa9730_stop(lp); | 938 | lan_saa9730_stop(lp); |
971 | 939 | ||
972 | if (dev->flags & IFF_PROMISC) { | 940 | if (dev->flags & IFF_PROMISC) { |
973 | /* accept all packets */ | 941 | /* accept all packets */ |
974 | OUTL(CAM_CONTROL_COMP_EN | CAM_CONTROL_STATION_ACC | | 942 | outl(CAM_CONTROL_COMP_EN | CAM_CONTROL_STATION_ACC | |
975 | CAM_CONTROL_GROUP_ACC | CAM_CONTROL_BROAD_ACC, | 943 | CAM_CONTROL_GROUP_ACC | CAM_CONTROL_BROAD_ACC, |
976 | &lp->lan_saa9730_regs->CamCtl); | 944 | &lp->lan_saa9730_regs->CamCtl); |
977 | } else { | 945 | } else { |
978 | if (dev->flags & IFF_ALLMULTI) { | 946 | if (dev->flags & IFF_ALLMULTI) { |
979 | /* accept all multicast packets */ | 947 | /* accept all multicast packets */ |
980 | OUTL(CAM_CONTROL_COMP_EN | CAM_CONTROL_GROUP_ACC | | 948 | outl(CAM_CONTROL_COMP_EN | CAM_CONTROL_GROUP_ACC | |
981 | CAM_CONTROL_BROAD_ACC, | 949 | CAM_CONTROL_BROAD_ACC, |
982 | &lp->lan_saa9730_regs->CamCtl); | 950 | &lp->lan_saa9730_regs->CamCtl); |
983 | } else { | 951 | } else { |
@@ -994,10 +962,13 @@ static void lan_saa9730_set_multicast(struct net_device *dev) | |||
994 | static void __devexit saa9730_remove_one(struct pci_dev *pdev) | 962 | static void __devexit saa9730_remove_one(struct pci_dev *pdev) |
995 | { | 963 | { |
996 | struct net_device *dev = pci_get_drvdata(pdev); | 964 | struct net_device *dev = pci_get_drvdata(pdev); |
965 | struct lan_saa9730_private *lp = netdev_priv(dev); | ||
997 | 966 | ||
998 | if (dev) { | 967 | if (dev) { |
999 | unregister_netdev(dev); | 968 | unregister_netdev(dev); |
1000 | kfree(dev->priv); | 969 | lan_saa9730_free_buffers(pdev, lp); |
970 | iounmap(lp->lan_saa9730_regs); | ||
971 | iounmap(lp->evm_saa9730_regs); | ||
1001 | free_netdev(dev); | 972 | free_netdev(dev); |
1002 | pci_release_regions(pdev); | 973 | pci_release_regions(pdev); |
1003 | pci_disable_device(pdev); | 974 | pci_disable_device(pdev); |
@@ -1006,75 +977,67 @@ static void __devexit saa9730_remove_one(struct pci_dev *pdev) | |||
1006 | } | 977 | } |
1007 | 978 | ||
1008 | 979 | ||
1009 | static int lan_saa9730_init(struct net_device *dev, int ioaddr, int irq) | 980 | static int lan_saa9730_init(struct net_device *dev, struct pci_dev *pdev, |
981 | unsigned long ioaddr, int irq) | ||
1010 | { | 982 | { |
1011 | struct lan_saa9730_private *lp; | 983 | struct lan_saa9730_private *lp = netdev_priv(dev); |
1012 | unsigned char ethernet_addr[6]; | 984 | unsigned char ethernet_addr[6]; |
1013 | int ret = 0; | 985 | int ret; |
1014 | 986 | ||
1015 | dev->open = lan_saa9730_open_fail; | 987 | if (get_ethernet_addr(ethernet_addr)) { |
1016 | 988 | ret = -ENODEV; | |
1017 | if (get_ethernet_addr(ethernet_addr)) | 989 | goto out; |
1018 | return -ENODEV; | 990 | } |
1019 | 991 | ||
1020 | memcpy(dev->dev_addr, ethernet_addr, 6); | 992 | memcpy(dev->dev_addr, ethernet_addr, 6); |
1021 | dev->base_addr = ioaddr; | 993 | dev->base_addr = ioaddr; |
1022 | dev->irq = irq; | 994 | dev->irq = irq; |
1023 | 995 | ||
1024 | /* | 996 | lp->pci_dev = pdev; |
1025 | * Make certain the data structures used by the controller are aligned | ||
1026 | * and DMAble. | ||
1027 | */ | ||
1028 | /* | ||
1029 | * XXX: that is obviously broken - kfree() won't be happy with us. | ||
1030 | */ | ||
1031 | lp = (struct lan_saa9730_private *) (((unsigned long) | ||
1032 | kmalloc(sizeof(*lp) + 7, | ||
1033 | GFP_DMA | GFP_KERNEL) | ||
1034 | + 7) & ~7); | ||
1035 | |||
1036 | if (!lp) | ||
1037 | return -ENOMEM; | ||
1038 | |||
1039 | dev->priv = lp; | ||
1040 | memset(lp, 0, sizeof(*lp)); | ||
1041 | 997 | ||
1042 | /* Set SAA9730 LAN base address. */ | 998 | /* Set SAA9730 LAN base address. */ |
1043 | lp->lan_saa9730_regs = (t_lan_saa9730_regmap *) (ioaddr + | 999 | lp->lan_saa9730_regs = ioremap(ioaddr + SAA9730_LAN_REGS_ADDR, |
1044 | SAA9730_LAN_REGS_ADDR); | 1000 | SAA9730_LAN_REGS_SIZE); |
1001 | if (!lp->lan_saa9730_regs) { | ||
1002 | ret = -ENOMEM; | ||
1003 | goto out; | ||
1004 | } | ||
1045 | 1005 | ||
1046 | /* Set SAA9730 EVM base address. */ | 1006 | /* Set SAA9730 EVM base address. */ |
1047 | lp->evm_saa9730_regs = (t_evm_saa9730_regmap *) (ioaddr + | 1007 | lp->evm_saa9730_regs = ioremap(ioaddr + SAA9730_EVM_REGS_ADDR, |
1048 | SAA9730_EVM_REGS_ADDR); | 1008 | SAA9730_EVM_REGS_SIZE); |
1009 | if (!lp->evm_saa9730_regs) { | ||
1010 | ret = -ENOMEM; | ||
1011 | goto out_iounmap_lan; | ||
1012 | } | ||
1049 | 1013 | ||
1050 | /* Allocate LAN RX/TX frame buffer space. */ | 1014 | /* Allocate LAN RX/TX frame buffer space. */ |
1051 | /* FIXME: a leak */ | 1015 | if ((ret = lan_saa9730_allocate_buffers(pdev, lp))) |
1052 | if ((ret = lan_saa9730_allocate_buffers(lp))) | 1016 | goto out_iounmap; |
1053 | goto out; | ||
1054 | 1017 | ||
1055 | /* Stop LAN controller. */ | 1018 | /* Stop LAN controller. */ |
1056 | if ((ret = lan_saa9730_stop(lp))) | 1019 | if ((ret = lan_saa9730_stop(lp))) |
1057 | goto out; | 1020 | goto out_free_consistent; |
1058 | 1021 | ||
1059 | /* Initialize CAM registers. */ | 1022 | /* Initialize CAM registers. */ |
1060 | if ((ret = lan_saa9730_cam_init(dev))) | 1023 | if ((ret = lan_saa9730_cam_init(dev))) |
1061 | goto out; | 1024 | goto out_free_consistent; |
1062 | 1025 | ||
1063 | /* Initialize MII registers. */ | 1026 | /* Initialize MII registers. */ |
1064 | if ((ret = lan_saa9730_mii_init(lp))) | 1027 | if ((ret = lan_saa9730_mii_init(lp))) |
1065 | goto out; | 1028 | goto out_free_consistent; |
1066 | 1029 | ||
1067 | /* Initialize control registers. */ | 1030 | /* Initialize control registers. */ |
1068 | if ((ret = lan_saa9730_control_init(lp))) | 1031 | if ((ret = lan_saa9730_control_init(lp))) |
1069 | goto out; | 1032 | goto out_free_consistent; |
1070 | 1033 | ||
1071 | /* Load CAM registers. */ | 1034 | /* Load CAM registers. */ |
1072 | if ((ret = lan_saa9730_cam_load(lp))) | 1035 | if ((ret = lan_saa9730_cam_load(lp))) |
1073 | goto out; | 1036 | goto out_free_consistent; |
1074 | 1037 | ||
1075 | /* Initialize DMA context registers. */ | 1038 | /* Initialize DMA context registers. */ |
1076 | if ((ret = lan_saa9730_dma_init(lp))) | 1039 | if ((ret = lan_saa9730_dma_init(lp))) |
1077 | goto out; | 1040 | goto out_free_consistent; |
1078 | 1041 | ||
1079 | spin_lock_init(&lp->lock); | 1042 | spin_lock_init(&lp->lock); |
1080 | 1043 | ||
@@ -1087,43 +1050,42 @@ static int lan_saa9730_init(struct net_device *dev, int ioaddr, int irq) | |||
1087 | dev->watchdog_timeo = (HZ >> 1); | 1050 | dev->watchdog_timeo = (HZ >> 1); |
1088 | dev->dma = 0; | 1051 | dev->dma = 0; |
1089 | 1052 | ||
1090 | ret = register_netdev(dev); | 1053 | ret = register_netdev (dev); |
1091 | if (ret) | 1054 | if (ret) |
1092 | goto out; | 1055 | goto out_free_consistent; |
1056 | |||
1093 | return 0; | 1057 | return 0; |
1094 | 1058 | ||
1095 | out: | 1059 | out_free_consistent: |
1096 | kfree(dev->priv); | 1060 | lan_saa9730_free_buffers(pdev, lp); |
1061 | out_iounmap: | ||
1062 | iounmap(lp->evm_saa9730_regs); | ||
1063 | out_iounmap_lan: | ||
1064 | iounmap(lp->lan_saa9730_regs); | ||
1065 | out: | ||
1097 | return ret; | 1066 | return ret; |
1098 | } | 1067 | } |
1099 | 1068 | ||
1100 | 1069 | ||
1101 | static int __devinit saa9730_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | 1070 | static int __devinit saa9730_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
1102 | { | 1071 | { |
1103 | struct net_device *dev; | 1072 | struct net_device *dev = NULL; |
1104 | unsigned int pci_ioaddr; | 1073 | unsigned long pci_ioaddr; |
1105 | int err; | 1074 | int err; |
1106 | 1075 | ||
1107 | if (lan_saa9730_debug > 1) | 1076 | if (lan_saa9730_debug > 1) |
1108 | printk("saa9730.c: PCI bios is present, checking for devices...\n"); | 1077 | printk("saa9730.c: PCI bios is present, checking for devices...\n"); |
1109 | 1078 | ||
1110 | err = -ENOMEM; | ||
1111 | dev = alloc_etherdev(0); | ||
1112 | if (!dev) | ||
1113 | goto out; | ||
1114 | |||
1115 | SET_MODULE_OWNER(dev); | ||
1116 | |||
1117 | err = pci_enable_device(pdev); | 1079 | err = pci_enable_device(pdev); |
1118 | if (err) { | 1080 | if (err) { |
1119 | printk(KERN_ERR "Cannot enable PCI device, aborting.\n"); | 1081 | printk(KERN_ERR "Cannot enable PCI device, aborting.\n"); |
1120 | goto out1; | 1082 | goto out; |
1121 | } | 1083 | } |
1122 | 1084 | ||
1123 | err = pci_request_regions(pdev, DRV_MODULE_NAME); | 1085 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
1124 | if (err) { | 1086 | if (err) { |
1125 | printk(KERN_ERR "Cannot obtain PCI resources, aborting.\n"); | 1087 | printk(KERN_ERR "Cannot obtain PCI resources, aborting.\n"); |
1126 | goto out2; | 1088 | goto out_disable_pdev; |
1127 | } | 1089 | } |
1128 | 1090 | ||
1129 | pci_irq_line = pdev->irq; | 1091 | pci_irq_line = pdev->irq; |
@@ -1132,24 +1094,29 @@ static int __devinit saa9730_init_one(struct pci_dev *pdev, const struct pci_dev | |||
1132 | pci_ioaddr = pci_resource_start(pdev, 1); | 1094 | pci_ioaddr = pci_resource_start(pdev, 1); |
1133 | pci_set_master(pdev); | 1095 | pci_set_master(pdev); |
1134 | 1096 | ||
1135 | printk("Found SAA9730 (PCI) at %#x, irq %d.\n", | 1097 | printk("Found SAA9730 (PCI) at %lx, irq %d.\n", |
1136 | pci_ioaddr, pci_irq_line); | 1098 | pci_ioaddr, pci_irq_line); |
1137 | 1099 | ||
1138 | err = lan_saa9730_init(dev, pci_ioaddr, pci_irq_line); | 1100 | dev = alloc_etherdev(sizeof(struct lan_saa9730_private)); |
1101 | if (!dev) | ||
1102 | goto out_disable_pdev; | ||
1103 | |||
1104 | err = lan_saa9730_init(dev, pdev, pci_ioaddr, pci_irq_line); | ||
1139 | if (err) { | 1105 | if (err) { |
1140 | printk("Lan init failed"); | 1106 | printk("LAN init failed"); |
1141 | goto out2; | 1107 | goto out_free_netdev; |
1142 | } | 1108 | } |
1143 | 1109 | ||
1144 | pci_set_drvdata(pdev, dev); | 1110 | pci_set_drvdata(pdev, dev); |
1145 | SET_NETDEV_DEV(dev, &pdev->dev); | 1111 | SET_NETDEV_DEV(dev, &pdev->dev); |
1146 | return 0; | 1112 | return 0; |
1147 | 1113 | ||
1148 | out2: | 1114 | out_free_netdev: |
1149 | pci_disable_device(pdev); | ||
1150 | out1: | ||
1151 | free_netdev(dev); | 1115 | free_netdev(dev); |
1116 | out_disable_pdev: | ||
1117 | pci_disable_device(pdev); | ||
1152 | out: | 1118 | out: |
1119 | pci_set_drvdata(pdev, NULL); | ||
1153 | return err; | 1120 | return err; |
1154 | } | 1121 | } |
1155 | 1122 | ||
@@ -1175,6 +1142,6 @@ static void __exit saa9730_cleanup(void) | |||
1175 | module_init(saa9730_init); | 1142 | module_init(saa9730_init); |
1176 | module_exit(saa9730_cleanup); | 1143 | module_exit(saa9730_cleanup); |
1177 | 1144 | ||
1178 | 1145 | MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>"); | |
1179 | 1146 | MODULE_DESCRIPTION("Philips SAA9730 ethernet driver"); | |
1180 | MODULE_LICENSE("GPL"); | 1147 | MODULE_LICENSE("GPL"); |