diff options
Diffstat (limited to 'drivers/net/zorro8390.c')
-rw-r--r-- | drivers/net/zorro8390.c | 673 |
1 files changed, 333 insertions, 340 deletions
diff --git a/drivers/net/zorro8390.c b/drivers/net/zorro8390.c index 8c7c522a056a..15e7751a273c 100644 --- a/drivers/net/zorro8390.c +++ b/drivers/net/zorro8390.c | |||
@@ -19,6 +19,8 @@ | |||
19 | * Ethernet Controllers. | 19 | * Ethernet Controllers. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
23 | |||
22 | #include <linux/module.h> | 24 | #include <linux/module.h> |
23 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
24 | #include <linux/errno.h> | 26 | #include <linux/errno.h> |
@@ -34,115 +36,242 @@ | |||
34 | #include <asm/amigaints.h> | 36 | #include <asm/amigaints.h> |
35 | #include <asm/amigahw.h> | 37 | #include <asm/amigahw.h> |
36 | 38 | ||
37 | #define EI_SHIFT(x) (ei_local->reg_offset[x]) | 39 | #define EI_SHIFT(x) (ei_local->reg_offset[x]) |
38 | #define ei_inb(port) in_8(port) | 40 | #define ei_inb(port) in_8(port) |
39 | #define ei_outb(val,port) out_8(port,val) | 41 | #define ei_outb(val, port) out_8(port, val) |
40 | #define ei_inb_p(port) in_8(port) | 42 | #define ei_inb_p(port) in_8(port) |
41 | #define ei_outb_p(val,port) out_8(port,val) | 43 | #define ei_outb_p(val, port) out_8(port, val) |
42 | 44 | ||
43 | static const char version[] = | 45 | static const char version[] = |
44 | "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n"; | 46 | "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n"; |
45 | 47 | ||
46 | #include "lib8390.c" | 48 | #include "lib8390.c" |
47 | 49 | ||
48 | #define DRV_NAME "zorro8390" | 50 | #define DRV_NAME "zorro8390" |
49 | 51 | ||
50 | #define NE_BASE (dev->base_addr) | 52 | #define NE_BASE (dev->base_addr) |
51 | #define NE_CMD (0x00*2) | 53 | #define NE_CMD (0x00 * 2) |
52 | #define NE_DATAPORT (0x10*2) /* NatSemi-defined port window offset. */ | 54 | #define NE_DATAPORT (0x10 * 2) /* NatSemi-defined port window offset */ |
53 | #define NE_RESET (0x1f*2) /* Issue a read to reset, a write to clear. */ | 55 | #define NE_RESET (0x1f * 2) /* Issue a read to reset, |
54 | #define NE_IO_EXTENT (0x20*2) | 56 | * a write to clear. */ |
55 | 57 | #define NE_IO_EXTENT (0x20 * 2) | |
56 | #define NE_EN0_ISR (0x07*2) | 58 | |
57 | #define NE_EN0_DCFG (0x0e*2) | 59 | #define NE_EN0_ISR (0x07 * 2) |
58 | 60 | #define NE_EN0_DCFG (0x0e * 2) | |
59 | #define NE_EN0_RSARLO (0x08*2) | 61 | |
60 | #define NE_EN0_RSARHI (0x09*2) | 62 | #define NE_EN0_RSARLO (0x08 * 2) |
61 | #define NE_EN0_RCNTLO (0x0a*2) | 63 | #define NE_EN0_RSARHI (0x09 * 2) |
62 | #define NE_EN0_RXCR (0x0c*2) | 64 | #define NE_EN0_RCNTLO (0x0a * 2) |
63 | #define NE_EN0_TXCR (0x0d*2) | 65 | #define NE_EN0_RXCR (0x0c * 2) |
64 | #define NE_EN0_RCNTHI (0x0b*2) | 66 | #define NE_EN0_TXCR (0x0d * 2) |
65 | #define NE_EN0_IMR (0x0f*2) | 67 | #define NE_EN0_RCNTHI (0x0b * 2) |
68 | #define NE_EN0_IMR (0x0f * 2) | ||
66 | 69 | ||
67 | #define NESM_START_PG 0x40 /* First page of TX buffer */ | 70 | #define NESM_START_PG 0x40 /* First page of TX buffer */ |
68 | #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */ | 71 | #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */ |
69 | 72 | ||
70 | 73 | #define WORDSWAP(a) ((((a) >> 8) & 0xff) | ((a) << 8)) | |
71 | #define WORDSWAP(a) ((((a)>>8)&0xff) | ((a)<<8)) | ||
72 | |||
73 | 74 | ||
74 | static struct card_info { | 75 | static struct card_info { |
75 | zorro_id id; | 76 | zorro_id id; |
76 | const char *name; | 77 | const char *name; |
77 | unsigned int offset; | 78 | unsigned int offset; |
78 | } cards[] __devinitdata = { | 79 | } cards[] __devinitdata = { |
79 | { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE2, "Ariadne II", 0x0600 }, | 80 | { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE2, "Ariadne II", 0x0600 }, |
80 | { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, "X-Surf", 0x8600 }, | 81 | { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, "X-Surf", 0x8600 }, |
81 | }; | 82 | }; |
82 | 83 | ||
83 | static int __devinit zorro8390_init_one(struct zorro_dev *z, | 84 | /* Hard reset the card. This used to pause for the same period that a |
84 | const struct zorro_device_id *ent); | 85 | * 8390 reset command required, but that shouldn't be necessary. |
85 | static int __devinit zorro8390_init(struct net_device *dev, | 86 | */ |
86 | unsigned long board, const char *name, | 87 | static void zorro8390_reset_8390(struct net_device *dev) |
87 | unsigned long ioaddr); | 88 | { |
88 | static int zorro8390_open(struct net_device *dev); | 89 | unsigned long reset_start_time = jiffies; |
89 | static int zorro8390_close(struct net_device *dev); | 90 | |
90 | static void zorro8390_reset_8390(struct net_device *dev); | 91 | if (ei_debug > 1) |
92 | netdev_dbg(dev, "resetting - t=%ld...\n", jiffies); | ||
93 | |||
94 | z_writeb(z_readb(NE_BASE + NE_RESET), NE_BASE + NE_RESET); | ||
95 | |||
96 | ei_status.txing = 0; | ||
97 | ei_status.dmaing = 0; | ||
98 | |||
99 | /* This check _should_not_ be necessary, omit eventually. */ | ||
100 | while ((z_readb(NE_BASE + NE_EN0_ISR) & ENISR_RESET) == 0) | ||
101 | if (time_after(jiffies, reset_start_time + 2 * HZ / 100)) { | ||
102 | netdev_warn(dev, "%s: did not complete\n", __func__); | ||
103 | break; | ||
104 | } | ||
105 | z_writeb(ENISR_RESET, NE_BASE + NE_EN0_ISR); /* Ack intr */ | ||
106 | } | ||
107 | |||
108 | /* Grab the 8390 specific header. Similar to the block_input routine, but | ||
109 | * we don't need to be concerned with ring wrap as the header will be at | ||
110 | * the start of a page, so we optimize accordingly. | ||
111 | */ | ||
91 | static void zorro8390_get_8390_hdr(struct net_device *dev, | 112 | static void zorro8390_get_8390_hdr(struct net_device *dev, |
92 | struct e8390_pkt_hdr *hdr, int ring_page); | 113 | struct e8390_pkt_hdr *hdr, int ring_page) |
114 | { | ||
115 | int nic_base = dev->base_addr; | ||
116 | int cnt; | ||
117 | short *ptrs; | ||
118 | |||
119 | /* This *shouldn't* happen. | ||
120 | * If it does, it's the last thing you'll see | ||
121 | */ | ||
122 | if (ei_status.dmaing) { | ||
123 | netdev_err(dev, "%s: DMAing conflict [DMAstat:%d][irqlock:%d]\n", | ||
124 | __func__, ei_status.dmaing, ei_status.irqlock); | ||
125 | return; | ||
126 | } | ||
127 | |||
128 | ei_status.dmaing |= 0x01; | ||
129 | z_writeb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD); | ||
130 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); | ||
131 | z_writeb(sizeof(struct e8390_pkt_hdr), nic_base + NE_EN0_RCNTLO); | ||
132 | z_writeb(0, nic_base + NE_EN0_RCNTHI); | ||
133 | z_writeb(0, nic_base + NE_EN0_RSARLO); /* On page boundary */ | ||
134 | z_writeb(ring_page, nic_base + NE_EN0_RSARHI); | ||
135 | z_writeb(E8390_RREAD+E8390_START, nic_base + NE_CMD); | ||
136 | |||
137 | ptrs = (short *)hdr; | ||
138 | for (cnt = 0; cnt < sizeof(struct e8390_pkt_hdr) >> 1; cnt++) | ||
139 | *ptrs++ = z_readw(NE_BASE + NE_DATAPORT); | ||
140 | |||
141 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr */ | ||
142 | |||
143 | hdr->count = WORDSWAP(hdr->count); | ||
144 | |||
145 | ei_status.dmaing &= ~0x01; | ||
146 | } | ||
147 | |||
148 | /* Block input and output, similar to the Crynwr packet driver. | ||
149 | * If you are porting to a new ethercard, look at the packet driver source | ||
150 | * for hints. The NEx000 doesn't share the on-board packet memory -- | ||
151 | * you have to put the packet out through the "remote DMA" dataport | ||
152 | * using z_writeb. | ||
153 | */ | ||
93 | static void zorro8390_block_input(struct net_device *dev, int count, | 154 | static void zorro8390_block_input(struct net_device *dev, int count, |
94 | struct sk_buff *skb, int ring_offset); | 155 | struct sk_buff *skb, int ring_offset) |
95 | static void zorro8390_block_output(struct net_device *dev, const int count, | 156 | { |
157 | int nic_base = dev->base_addr; | ||
158 | char *buf = skb->data; | ||
159 | short *ptrs; | ||
160 | int cnt; | ||
161 | |||
162 | /* This *shouldn't* happen. | ||
163 | * If it does, it's the last thing you'll see | ||
164 | */ | ||
165 | if (ei_status.dmaing) { | ||
166 | netdev_err(dev, "%s: DMAing conflict [DMAstat:%d][irqlock:%d]\n", | ||
167 | __func__, ei_status.dmaing, ei_status.irqlock); | ||
168 | return; | ||
169 | } | ||
170 | ei_status.dmaing |= 0x01; | ||
171 | z_writeb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD); | ||
172 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); | ||
173 | z_writeb(count & 0xff, nic_base + NE_EN0_RCNTLO); | ||
174 | z_writeb(count >> 8, nic_base + NE_EN0_RCNTHI); | ||
175 | z_writeb(ring_offset & 0xff, nic_base + NE_EN0_RSARLO); | ||
176 | z_writeb(ring_offset >> 8, nic_base + NE_EN0_RSARHI); | ||
177 | z_writeb(E8390_RREAD+E8390_START, nic_base + NE_CMD); | ||
178 | ptrs = (short *)buf; | ||
179 | for (cnt = 0; cnt < count >> 1; cnt++) | ||
180 | *ptrs++ = z_readw(NE_BASE + NE_DATAPORT); | ||
181 | if (count & 0x01) | ||
182 | buf[count - 1] = z_readb(NE_BASE + NE_DATAPORT); | ||
183 | |||
184 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr */ | ||
185 | ei_status.dmaing &= ~0x01; | ||
186 | } | ||
187 | |||
188 | static void zorro8390_block_output(struct net_device *dev, int count, | ||
96 | const unsigned char *buf, | 189 | const unsigned char *buf, |
97 | const int start_page); | 190 | const int start_page) |
98 | static void __devexit zorro8390_remove_one(struct zorro_dev *z); | 191 | { |
192 | int nic_base = NE_BASE; | ||
193 | unsigned long dma_start; | ||
194 | short *ptrs; | ||
195 | int cnt; | ||
196 | |||
197 | /* Round the count up for word writes. Do we need to do this? | ||
198 | * What effect will an odd byte count have on the 8390? | ||
199 | * I should check someday. | ||
200 | */ | ||
201 | if (count & 0x01) | ||
202 | count++; | ||
203 | |||
204 | /* This *shouldn't* happen. | ||
205 | * If it does, it's the last thing you'll see | ||
206 | */ | ||
207 | if (ei_status.dmaing) { | ||
208 | netdev_err(dev, "%s: DMAing conflict [DMAstat:%d][irqlock:%d]\n", | ||
209 | __func__, ei_status.dmaing, ei_status.irqlock); | ||
210 | return; | ||
211 | } | ||
212 | ei_status.dmaing |= 0x01; | ||
213 | /* We should already be in page 0, but to be safe... */ | ||
214 | z_writeb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD); | ||
215 | |||
216 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); | ||
217 | |||
218 | /* Now the normal output. */ | ||
219 | z_writeb(count & 0xff, nic_base + NE_EN0_RCNTLO); | ||
220 | z_writeb(count >> 8, nic_base + NE_EN0_RCNTHI); | ||
221 | z_writeb(0x00, nic_base + NE_EN0_RSARLO); | ||
222 | z_writeb(start_page, nic_base + NE_EN0_RSARHI); | ||
223 | |||
224 | z_writeb(E8390_RWRITE + E8390_START, nic_base + NE_CMD); | ||
225 | ptrs = (short *)buf; | ||
226 | for (cnt = 0; cnt < count >> 1; cnt++) | ||
227 | z_writew(*ptrs++, NE_BASE + NE_DATAPORT); | ||
228 | |||
229 | dma_start = jiffies; | ||
230 | |||
231 | while ((z_readb(NE_BASE + NE_EN0_ISR) & ENISR_RDC) == 0) | ||
232 | if (time_after(jiffies, dma_start + 2 * HZ / 100)) { | ||
233 | /* 20ms */ | ||
234 | netdev_err(dev, "timeout waiting for Tx RDC\n"); | ||
235 | zorro8390_reset_8390(dev); | ||
236 | __NS8390_init(dev, 1); | ||
237 | break; | ||
238 | } | ||
239 | |||
240 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr */ | ||
241 | ei_status.dmaing &= ~0x01; | ||
242 | } | ||
99 | 243 | ||
100 | static struct zorro_device_id zorro8390_zorro_tbl[] __devinitdata = { | 244 | static int zorro8390_open(struct net_device *dev) |
101 | { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE2, }, | 245 | { |
102 | { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, }, | 246 | __ei_open(dev); |
103 | { 0 } | 247 | return 0; |
104 | }; | 248 | } |
105 | MODULE_DEVICE_TABLE(zorro, zorro8390_zorro_tbl); | ||
106 | 249 | ||
107 | static struct zorro_driver zorro8390_driver = { | 250 | static int zorro8390_close(struct net_device *dev) |
108 | .name = "zorro8390", | 251 | { |
109 | .id_table = zorro8390_zorro_tbl, | 252 | if (ei_debug > 1) |
110 | .probe = zorro8390_init_one, | 253 | netdev_dbg(dev, "Shutting down ethercard\n"); |
111 | .remove = __devexit_p(zorro8390_remove_one), | 254 | __ei_close(dev); |
112 | }; | 255 | return 0; |
256 | } | ||
113 | 257 | ||
114 | static int __devinit zorro8390_init_one(struct zorro_dev *z, | 258 | static void __devexit zorro8390_remove_one(struct zorro_dev *z) |
115 | const struct zorro_device_id *ent) | ||
116 | { | 259 | { |
117 | struct net_device *dev; | 260 | struct net_device *dev = zorro_get_drvdata(z); |
118 | unsigned long board, ioaddr; | 261 | |
119 | int err, i; | 262 | unregister_netdev(dev); |
120 | 263 | free_irq(IRQ_AMIGA_PORTS, dev); | |
121 | for (i = ARRAY_SIZE(cards)-1; i >= 0; i--) | 264 | release_mem_region(ZTWO_PADDR(dev->base_addr), NE_IO_EXTENT * 2); |
122 | if (z->id == cards[i].id) | ||
123 | break; | ||
124 | if (i < 0) | ||
125 | return -ENODEV; | ||
126 | |||
127 | board = z->resource.start; | ||
128 | ioaddr = board+cards[i].offset; | ||
129 | dev = ____alloc_ei_netdev(0); | ||
130 | if (!dev) | ||
131 | return -ENOMEM; | ||
132 | if (!request_mem_region(ioaddr, NE_IO_EXTENT*2, DRV_NAME)) { | ||
133 | free_netdev(dev); | ||
134 | return -EBUSY; | ||
135 | } | ||
136 | if ((err = zorro8390_init(dev, board, cards[i].name, | ||
137 | ZTWO_VADDR(ioaddr)))) { | ||
138 | release_mem_region(ioaddr, NE_IO_EXTENT*2); | ||
139 | free_netdev(dev); | 265 | free_netdev(dev); |
140 | return err; | ||
141 | } | ||
142 | zorro_set_drvdata(z, dev); | ||
143 | return 0; | ||
144 | } | 266 | } |
145 | 267 | ||
268 | static struct zorro_device_id zorro8390_zorro_tbl[] __devinitdata = { | ||
269 | { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE2, }, | ||
270 | { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, }, | ||
271 | { 0 } | ||
272 | }; | ||
273 | MODULE_DEVICE_TABLE(zorro, zorro8390_zorro_tbl); | ||
274 | |||
146 | static const struct net_device_ops zorro8390_netdev_ops = { | 275 | static const struct net_device_ops zorro8390_netdev_ops = { |
147 | .ndo_open = zorro8390_open, | 276 | .ndo_open = zorro8390_open, |
148 | .ndo_stop = zorro8390_close, | 277 | .ndo_stop = zorro8390_close, |
@@ -151,7 +280,7 @@ static const struct net_device_ops zorro8390_netdev_ops = { | |||
151 | .ndo_get_stats = __ei_get_stats, | 280 | .ndo_get_stats = __ei_get_stats, |
152 | .ndo_set_multicast_list = __ei_set_multicast_list, | 281 | .ndo_set_multicast_list = __ei_set_multicast_list, |
153 | .ndo_validate_addr = eth_validate_addr, | 282 | .ndo_validate_addr = eth_validate_addr, |
154 | .ndo_set_mac_address = eth_mac_addr, | 283 | .ndo_set_mac_address = eth_mac_addr, |
155 | .ndo_change_mtu = eth_change_mtu, | 284 | .ndo_change_mtu = eth_change_mtu, |
156 | #ifdef CONFIG_NET_POLL_CONTROLLER | 285 | #ifdef CONFIG_NET_POLL_CONTROLLER |
157 | .ndo_poll_controller = __ei_poll, | 286 | .ndo_poll_controller = __ei_poll, |
@@ -162,295 +291,159 @@ static int __devinit zorro8390_init(struct net_device *dev, | |||
162 | unsigned long board, const char *name, | 291 | unsigned long board, const char *name, |
163 | unsigned long ioaddr) | 292 | unsigned long ioaddr) |
164 | { | 293 | { |
165 | int i; | 294 | int i; |
166 | int err; | 295 | int err; |
167 | unsigned char SA_prom[32]; | 296 | unsigned char SA_prom[32]; |
168 | int start_page, stop_page; | 297 | int start_page, stop_page; |
169 | static u32 zorro8390_offsets[16] = { | 298 | static u32 zorro8390_offsets[16] = { |
170 | 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, | 299 | 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, |
171 | 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e, | 300 | 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e, |
172 | }; | ||
173 | |||
174 | /* Reset card. Who knows what dain-bramaged state it was left in. */ | ||
175 | { | ||
176 | unsigned long reset_start_time = jiffies; | ||
177 | |||
178 | z_writeb(z_readb(ioaddr + NE_RESET), ioaddr + NE_RESET); | ||
179 | |||
180 | while ((z_readb(ioaddr + NE_EN0_ISR) & ENISR_RESET) == 0) | ||
181 | if (time_after(jiffies, reset_start_time + 2*HZ/100)) { | ||
182 | printk(KERN_WARNING " not found (no reset ack).\n"); | ||
183 | return -ENODEV; | ||
184 | } | ||
185 | |||
186 | z_writeb(0xff, ioaddr + NE_EN0_ISR); /* Ack all intr. */ | ||
187 | } | ||
188 | |||
189 | /* Read the 16 bytes of station address PROM. | ||
190 | We must first initialize registers, similar to NS8390_init(eifdev, 0). | ||
191 | We can't reliably read the SAPROM address without this. | ||
192 | (I learned the hard way!). */ | ||
193 | { | ||
194 | struct { | ||
195 | u32 value; | ||
196 | u32 offset; | ||
197 | } program_seq[] = { | ||
198 | {E8390_NODMA+E8390_PAGE0+E8390_STOP, NE_CMD}, /* Select page 0*/ | ||
199 | {0x48, NE_EN0_DCFG}, /* Set byte-wide (0x48) access. */ | ||
200 | {0x00, NE_EN0_RCNTLO}, /* Clear the count regs. */ | ||
201 | {0x00, NE_EN0_RCNTHI}, | ||
202 | {0x00, NE_EN0_IMR}, /* Mask completion irq. */ | ||
203 | {0xFF, NE_EN0_ISR}, | ||
204 | {E8390_RXOFF, NE_EN0_RXCR}, /* 0x20 Set to monitor */ | ||
205 | {E8390_TXOFF, NE_EN0_TXCR}, /* 0x02 and loopback mode. */ | ||
206 | {32, NE_EN0_RCNTLO}, | ||
207 | {0x00, NE_EN0_RCNTHI}, | ||
208 | {0x00, NE_EN0_RSARLO}, /* DMA starting at 0x0000. */ | ||
209 | {0x00, NE_EN0_RSARHI}, | ||
210 | {E8390_RREAD+E8390_START, NE_CMD}, | ||
211 | }; | 301 | }; |
212 | for (i = 0; i < ARRAY_SIZE(program_seq); i++) { | ||
213 | z_writeb(program_seq[i].value, ioaddr + program_seq[i].offset); | ||
214 | } | ||
215 | } | ||
216 | for (i = 0; i < 16; i++) { | ||
217 | SA_prom[i] = z_readb(ioaddr + NE_DATAPORT); | ||
218 | (void)z_readb(ioaddr + NE_DATAPORT); | ||
219 | } | ||
220 | 302 | ||
221 | /* We must set the 8390 for word mode. */ | 303 | /* Reset card. Who knows what dain-bramaged state it was left in. */ |
222 | z_writeb(0x49, ioaddr + NE_EN0_DCFG); | 304 | { |
223 | start_page = NESM_START_PG; | 305 | unsigned long reset_start_time = jiffies; |
224 | stop_page = NESM_STOP_PG; | ||
225 | 306 | ||
226 | dev->base_addr = ioaddr; | 307 | z_writeb(z_readb(ioaddr + NE_RESET), ioaddr + NE_RESET); |
227 | dev->irq = IRQ_AMIGA_PORTS; | ||
228 | 308 | ||
229 | /* Install the Interrupt handler */ | 309 | while ((z_readb(ioaddr + NE_EN0_ISR) & ENISR_RESET) == 0) |
230 | i = request_irq(IRQ_AMIGA_PORTS, __ei_interrupt, IRQF_SHARED, DRV_NAME, dev); | 310 | if (time_after(jiffies, |
231 | if (i) return i; | 311 | reset_start_time + 2 * HZ / 100)) { |
312 | netdev_warn(dev, "not found (no reset ack)\n"); | ||
313 | return -ENODEV; | ||
314 | } | ||
232 | 315 | ||
233 | for(i = 0; i < ETHER_ADDR_LEN; i++) | 316 | z_writeb(0xff, ioaddr + NE_EN0_ISR); /* Ack all intr. */ |
234 | dev->dev_addr[i] = SA_prom[i]; | 317 | } |
235 | |||
236 | #ifdef DEBUG | ||
237 | printk("%pM", dev->dev_addr); | ||
238 | #endif | ||
239 | 318 | ||
240 | ei_status.name = name; | 319 | /* Read the 16 bytes of station address PROM. |
241 | ei_status.tx_start_page = start_page; | 320 | * We must first initialize registers, |
242 | ei_status.stop_page = stop_page; | 321 | * similar to NS8390_init(eifdev, 0). |
243 | ei_status.word16 = 1; | 322 | * We can't reliably read the SAPROM address without this. |
323 | * (I learned the hard way!). | ||
324 | */ | ||
325 | { | ||
326 | static const struct { | ||
327 | u32 value; | ||
328 | u32 offset; | ||
329 | } program_seq[] = { | ||
330 | {E8390_NODMA + E8390_PAGE0 + E8390_STOP, NE_CMD}, | ||
331 | /* Select page 0 */ | ||
332 | {0x48, NE_EN0_DCFG}, /* 0x48: Set byte-wide access */ | ||
333 | {0x00, NE_EN0_RCNTLO}, /* Clear the count regs */ | ||
334 | {0x00, NE_EN0_RCNTHI}, | ||
335 | {0x00, NE_EN0_IMR}, /* Mask completion irq */ | ||
336 | {0xFF, NE_EN0_ISR}, | ||
337 | {E8390_RXOFF, NE_EN0_RXCR}, /* 0x20 Set to monitor */ | ||
338 | {E8390_TXOFF, NE_EN0_TXCR}, /* 0x02 and loopback mode */ | ||
339 | {32, NE_EN0_RCNTLO}, | ||
340 | {0x00, NE_EN0_RCNTHI}, | ||
341 | {0x00, NE_EN0_RSARLO}, /* DMA starting at 0x0000 */ | ||
342 | {0x00, NE_EN0_RSARHI}, | ||
343 | {E8390_RREAD + E8390_START, NE_CMD}, | ||
344 | }; | ||
345 | for (i = 0; i < ARRAY_SIZE(program_seq); i++) | ||
346 | z_writeb(program_seq[i].value, | ||
347 | ioaddr + program_seq[i].offset); | ||
348 | } | ||
349 | for (i = 0; i < 16; i++) { | ||
350 | SA_prom[i] = z_readb(ioaddr + NE_DATAPORT); | ||
351 | (void)z_readb(ioaddr + NE_DATAPORT); | ||
352 | } | ||
244 | 353 | ||
245 | ei_status.rx_start_page = start_page + TX_PAGES; | 354 | /* We must set the 8390 for word mode. */ |
355 | z_writeb(0x49, ioaddr + NE_EN0_DCFG); | ||
356 | start_page = NESM_START_PG; | ||
357 | stop_page = NESM_STOP_PG; | ||
246 | 358 | ||
247 | ei_status.reset_8390 = &zorro8390_reset_8390; | 359 | dev->base_addr = ioaddr; |
248 | ei_status.block_input = &zorro8390_block_input; | 360 | dev->irq = IRQ_AMIGA_PORTS; |
249 | ei_status.block_output = &zorro8390_block_output; | ||
250 | ei_status.get_8390_hdr = &zorro8390_get_8390_hdr; | ||
251 | ei_status.reg_offset = zorro8390_offsets; | ||
252 | 361 | ||
253 | dev->netdev_ops = &zorro8390_netdev_ops; | 362 | /* Install the Interrupt handler */ |
254 | __NS8390_init(dev, 0); | 363 | i = request_irq(IRQ_AMIGA_PORTS, __ei_interrupt, |
255 | err = register_netdev(dev); | 364 | IRQF_SHARED, DRV_NAME, dev); |
256 | if (err) { | 365 | if (i) |
257 | free_irq(IRQ_AMIGA_PORTS, dev); | 366 | return i; |
258 | return err; | ||
259 | } | ||
260 | 367 | ||
261 | printk(KERN_INFO "%s: %s at 0x%08lx, Ethernet Address %pM\n", | 368 | for (i = 0; i < ETHER_ADDR_LEN; i++) |
262 | dev->name, name, board, dev->dev_addr); | 369 | dev->dev_addr[i] = SA_prom[i]; |
263 | 370 | ||
264 | return 0; | 371 | pr_debug("Found ethernet address: %pM\n", dev->dev_addr); |
265 | } | ||
266 | 372 | ||
267 | static int zorro8390_open(struct net_device *dev) | 373 | ei_status.name = name; |
268 | { | 374 | ei_status.tx_start_page = start_page; |
269 | __ei_open(dev); | 375 | ei_status.stop_page = stop_page; |
270 | return 0; | 376 | ei_status.word16 = 1; |
271 | } | ||
272 | 377 | ||
273 | static int zorro8390_close(struct net_device *dev) | 378 | ei_status.rx_start_page = start_page + TX_PAGES; |
274 | { | ||
275 | if (ei_debug > 1) | ||
276 | printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name); | ||
277 | __ei_close(dev); | ||
278 | return 0; | ||
279 | } | ||
280 | 379 | ||
281 | /* Hard reset the card. This used to pause for the same period that a | 380 | ei_status.reset_8390 = zorro8390_reset_8390; |
282 | 8390 reset command required, but that shouldn't be necessary. */ | 381 | ei_status.block_input = zorro8390_block_input; |
283 | static void zorro8390_reset_8390(struct net_device *dev) | 382 | ei_status.block_output = zorro8390_block_output; |
284 | { | 383 | ei_status.get_8390_hdr = zorro8390_get_8390_hdr; |
285 | unsigned long reset_start_time = jiffies; | 384 | ei_status.reg_offset = zorro8390_offsets; |
286 | 385 | ||
287 | if (ei_debug > 1) | 386 | dev->netdev_ops = &zorro8390_netdev_ops; |
288 | printk(KERN_DEBUG "resetting the 8390 t=%ld...\n", jiffies); | 387 | __NS8390_init(dev, 0); |
289 | 388 | err = register_netdev(dev); | |
290 | z_writeb(z_readb(NE_BASE + NE_RESET), NE_BASE + NE_RESET); | 389 | if (err) { |
291 | 390 | free_irq(IRQ_AMIGA_PORTS, dev); | |
292 | ei_status.txing = 0; | 391 | return err; |
293 | ei_status.dmaing = 0; | ||
294 | |||
295 | /* This check _should_not_ be necessary, omit eventually. */ | ||
296 | while ((z_readb(NE_BASE+NE_EN0_ISR) & ENISR_RESET) == 0) | ||
297 | if (time_after(jiffies, reset_start_time + 2*HZ/100)) { | ||
298 | printk(KERN_WARNING "%s: ne_reset_8390() did not complete.\n", | ||
299 | dev->name); | ||
300 | break; | ||
301 | } | 392 | } |
302 | z_writeb(ENISR_RESET, NE_BASE + NE_EN0_ISR); /* Ack intr. */ | ||
303 | } | ||
304 | 393 | ||
305 | /* Grab the 8390 specific header. Similar to the block_input routine, but | 394 | netdev_info(dev, "%s at 0x%08lx, Ethernet Address %pM\n", |
306 | we don't need to be concerned with ring wrap as the header will be at | 395 | name, board, dev->dev_addr); |
307 | the start of a page, so we optimize accordingly. */ | ||
308 | 396 | ||
309 | static void zorro8390_get_8390_hdr(struct net_device *dev, | 397 | return 0; |
310 | struct e8390_pkt_hdr *hdr, int ring_page) | ||
311 | { | ||
312 | int nic_base = dev->base_addr; | ||
313 | int cnt; | ||
314 | short *ptrs; | ||
315 | |||
316 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ | ||
317 | if (ei_status.dmaing) { | ||
318 | printk(KERN_ERR "%s: DMAing conflict in ne_get_8390_hdr " | ||
319 | "[DMAstat:%d][irqlock:%d].\n", dev->name, ei_status.dmaing, | ||
320 | ei_status.irqlock); | ||
321 | return; | ||
322 | } | ||
323 | |||
324 | ei_status.dmaing |= 0x01; | ||
325 | z_writeb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); | ||
326 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); | ||
327 | z_writeb(sizeof(struct e8390_pkt_hdr), nic_base + NE_EN0_RCNTLO); | ||
328 | z_writeb(0, nic_base + NE_EN0_RCNTHI); | ||
329 | z_writeb(0, nic_base + NE_EN0_RSARLO); /* On page boundary */ | ||
330 | z_writeb(ring_page, nic_base + NE_EN0_RSARHI); | ||
331 | z_writeb(E8390_RREAD+E8390_START, nic_base + NE_CMD); | ||
332 | |||
333 | ptrs = (short*)hdr; | ||
334 | for (cnt = 0; cnt < (sizeof(struct e8390_pkt_hdr)>>1); cnt++) | ||
335 | *ptrs++ = z_readw(NE_BASE + NE_DATAPORT); | ||
336 | |||
337 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */ | ||
338 | |||
339 | hdr->count = WORDSWAP(hdr->count); | ||
340 | |||
341 | ei_status.dmaing &= ~0x01; | ||
342 | } | 398 | } |
343 | 399 | ||
344 | /* Block input and output, similar to the Crynwr packet driver. If you | 400 | static int __devinit zorro8390_init_one(struct zorro_dev *z, |
345 | are porting to a new ethercard, look at the packet driver source for hints. | 401 | const struct zorro_device_id *ent) |
346 | The NEx000 doesn't share the on-board packet memory -- you have to put | ||
347 | the packet out through the "remote DMA" dataport using z_writeb. */ | ||
348 | |||
349 | static void zorro8390_block_input(struct net_device *dev, int count, | ||
350 | struct sk_buff *skb, int ring_offset) | ||
351 | { | 402 | { |
352 | int nic_base = dev->base_addr; | 403 | struct net_device *dev; |
353 | char *buf = skb->data; | 404 | unsigned long board, ioaddr; |
354 | short *ptrs; | 405 | int err, i; |
355 | int cnt; | 406 | |
356 | 407 | for (i = ARRAY_SIZE(cards) - 1; i >= 0; i--) | |
357 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ | 408 | if (z->id == cards[i].id) |
358 | if (ei_status.dmaing) { | 409 | break; |
359 | printk(KERN_ERR "%s: DMAing conflict in ne_block_input " | 410 | if (i < 0) |
360 | "[DMAstat:%d][irqlock:%d].\n", | 411 | return -ENODEV; |
361 | dev->name, ei_status.dmaing, ei_status.irqlock); | ||
362 | return; | ||
363 | } | ||
364 | ei_status.dmaing |= 0x01; | ||
365 | z_writeb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); | ||
366 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); | ||
367 | z_writeb(count & 0xff, nic_base + NE_EN0_RCNTLO); | ||
368 | z_writeb(count >> 8, nic_base + NE_EN0_RCNTHI); | ||
369 | z_writeb(ring_offset & 0xff, nic_base + NE_EN0_RSARLO); | ||
370 | z_writeb(ring_offset >> 8, nic_base + NE_EN0_RSARHI); | ||
371 | z_writeb(E8390_RREAD+E8390_START, nic_base + NE_CMD); | ||
372 | ptrs = (short*)buf; | ||
373 | for (cnt = 0; cnt < (count>>1); cnt++) | ||
374 | *ptrs++ = z_readw(NE_BASE + NE_DATAPORT); | ||
375 | if (count & 0x01) | ||
376 | buf[count-1] = z_readb(NE_BASE + NE_DATAPORT); | ||
377 | |||
378 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */ | ||
379 | ei_status.dmaing &= ~0x01; | ||
380 | } | ||
381 | 412 | ||
382 | static void zorro8390_block_output(struct net_device *dev, int count, | 413 | board = z->resource.start; |
383 | const unsigned char *buf, | 414 | ioaddr = board + cards[i].offset; |
384 | const int start_page) | 415 | dev = ____alloc_ei_netdev(0); |
385 | { | 416 | if (!dev) |
386 | int nic_base = NE_BASE; | 417 | return -ENOMEM; |
387 | unsigned long dma_start; | 418 | if (!request_mem_region(ioaddr, NE_IO_EXTENT * 2, DRV_NAME)) { |
388 | short *ptrs; | 419 | free_netdev(dev); |
389 | int cnt; | 420 | return -EBUSY; |
390 | |||
391 | /* Round the count up for word writes. Do we need to do this? | ||
392 | What effect will an odd byte count have on the 8390? | ||
393 | I should check someday. */ | ||
394 | if (count & 0x01) | ||
395 | count++; | ||
396 | |||
397 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ | ||
398 | if (ei_status.dmaing) { | ||
399 | printk(KERN_ERR "%s: DMAing conflict in ne_block_output." | ||
400 | "[DMAstat:%d][irqlock:%d]\n", dev->name, ei_status.dmaing, | ||
401 | ei_status.irqlock); | ||
402 | return; | ||
403 | } | ||
404 | ei_status.dmaing |= 0x01; | ||
405 | /* We should already be in page 0, but to be safe... */ | ||
406 | z_writeb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD); | ||
407 | |||
408 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); | ||
409 | |||
410 | /* Now the normal output. */ | ||
411 | z_writeb(count & 0xff, nic_base + NE_EN0_RCNTLO); | ||
412 | z_writeb(count >> 8, nic_base + NE_EN0_RCNTHI); | ||
413 | z_writeb(0x00, nic_base + NE_EN0_RSARLO); | ||
414 | z_writeb(start_page, nic_base + NE_EN0_RSARHI); | ||
415 | |||
416 | z_writeb(E8390_RWRITE+E8390_START, nic_base + NE_CMD); | ||
417 | ptrs = (short*)buf; | ||
418 | for (cnt = 0; cnt < count>>1; cnt++) | ||
419 | z_writew(*ptrs++, NE_BASE+NE_DATAPORT); | ||
420 | |||
421 | dma_start = jiffies; | ||
422 | |||
423 | while ((z_readb(NE_BASE + NE_EN0_ISR) & ENISR_RDC) == 0) | ||
424 | if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */ | ||
425 | printk(KERN_ERR "%s: timeout waiting for Tx RDC.\n", | ||
426 | dev->name); | ||
427 | zorro8390_reset_8390(dev); | ||
428 | __NS8390_init(dev,1); | ||
429 | break; | ||
430 | } | 421 | } |
431 | 422 | err = zorro8390_init(dev, board, cards[i].name, ZTWO_VADDR(ioaddr)); | |
432 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */ | 423 | if (err) { |
433 | ei_status.dmaing &= ~0x01; | 424 | release_mem_region(ioaddr, NE_IO_EXTENT * 2); |
425 | free_netdev(dev); | ||
426 | return err; | ||
427 | } | ||
428 | zorro_set_drvdata(z, dev); | ||
429 | return 0; | ||
434 | } | 430 | } |
435 | 431 | ||
436 | static void __devexit zorro8390_remove_one(struct zorro_dev *z) | 432 | static struct zorro_driver zorro8390_driver = { |
437 | { | 433 | .name = "zorro8390", |
438 | struct net_device *dev = zorro_get_drvdata(z); | 434 | .id_table = zorro8390_zorro_tbl, |
439 | 435 | .probe = zorro8390_init_one, | |
440 | unregister_netdev(dev); | 436 | .remove = __devexit_p(zorro8390_remove_one), |
441 | free_irq(IRQ_AMIGA_PORTS, dev); | 437 | }; |
442 | release_mem_region(ZTWO_PADDR(dev->base_addr), NE_IO_EXTENT*2); | ||
443 | free_netdev(dev); | ||
444 | } | ||
445 | 438 | ||
446 | static int __init zorro8390_init_module(void) | 439 | static int __init zorro8390_init_module(void) |
447 | { | 440 | { |
448 | return zorro_register_driver(&zorro8390_driver); | 441 | return zorro_register_driver(&zorro8390_driver); |
449 | } | 442 | } |
450 | 443 | ||
451 | static void __exit zorro8390_cleanup_module(void) | 444 | static void __exit zorro8390_cleanup_module(void) |
452 | { | 445 | { |
453 | zorro_unregister_driver(&zorro8390_driver); | 446 | zorro_unregister_driver(&zorro8390_driver); |
454 | } | 447 | } |
455 | 448 | ||
456 | module_init(zorro8390_init_module); | 449 | module_init(zorro8390_init_module); |