blob: f72a4f57905ab3f4d7d57f79ebf9a8e99e779549 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*------------------------------------------------------------------------
2 . smc91x.h - macros for SMSC's 91C9x/91C1xx single-chip Ethernet device.
3 .
4 . Copyright (C) 1996 by Erik Stahlman
5 . Copyright (C) 2001 Standard Microsystems Corporation
6 . Developed by Simple Network Magic Corporation
7 . Copyright (C) 2003 Monta Vista Software, Inc.
8 . Unified SMC91x driver by Nicolas Pitre
9 .
10 . This program is free software; you can redistribute it and/or modify
11 . it under the terms of the GNU General Public License as published by
12 . the Free Software Foundation; either version 2 of the License, or
13 . (at your option) any later version.
14 .
15 . This program is distributed in the hope that it will be useful,
16 . but WITHOUT ANY WARRANTY; without even the implied warranty of
17 . MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 . GNU General Public License for more details.
19 .
20 . You should have received a copy of the GNU General Public License
21 . along with this program; if not, write to the Free Software
22 . Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 .
24 . Information contained in this file was obtained from the LAN91C111
25 . manual from SMC. To get a copy, if you really want one, you can find
26 . information under www.smsc.com.
27 .
28 . Authors
29 . Erik Stahlman <erik@vt.edu>
30 . Daris A Nevil <dnevil@snmc.com>
31 . Nicolas Pitre <nico@cam.org>
32 .
33 ---------------------------------------------------------------------------*/
34#ifndef _SMC91X_H_
35#define _SMC91X_H_
36
37
38/*
39 * Define your architecture specific bus configuration parameters here.
40 */
41
42#if defined(CONFIG_ARCH_LUBBOCK)
43
44/* We can only do 16-bit reads and writes in the static memory space. */
45#define SMC_CAN_USE_8BIT 0
46#define SMC_CAN_USE_16BIT 1
47#define SMC_CAN_USE_32BIT 0
48#define SMC_NOWAIT 1
49
50/* The first two address lines aren't connected... */
51#define SMC_IO_SHIFT 2
52
53#define SMC_inw(a, r) readw((a) + (r))
54#define SMC_outw(v, a, r) writew(v, (a) + (r))
55#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
56#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
57
58#elif defined(CONFIG_REDWOOD_5) || defined(CONFIG_REDWOOD_6)
59
60/* We can only do 16-bit reads and writes in the static memory space. */
61#define SMC_CAN_USE_8BIT 0
62#define SMC_CAN_USE_16BIT 1
63#define SMC_CAN_USE_32BIT 0
64#define SMC_NOWAIT 1
65
66#define SMC_IO_SHIFT 0
67
68#define SMC_inw(a, r) in_be16((volatile u16 *)((a) + (r)))
69#define SMC_outw(v, a, r) out_be16((volatile u16 *)((a) + (r)), v)
70#define SMC_insw(a, r, p, l) \
71 do { \
72 unsigned long __port = (a) + (r); \
73 u16 *__p = (u16 *)(p); \
74 int __l = (l); \
75 insw(__port, __p, __l); \
76 while (__l > 0) { \
77 *__p = swab16(*__p); \
78 __p++; \
79 __l--; \
80 } \
81 } while (0)
82#define SMC_outsw(a, r, p, l) \
83 do { \
84 unsigned long __port = (a) + (r); \
85 u16 *__p = (u16 *)(p); \
86 int __l = (l); \
87 while (__l > 0) { \
88 /* Believe it or not, the swab isn't needed. */ \
89 outw( /* swab16 */ (*__p++), __port); \
90 __l--; \
91 } \
92 } while (0)
Russell King9ded96f2006-01-08 01:02:07 -080093#define SMC_IRQ_FLAGS (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95#elif defined(CONFIG_SA1100_PLEB)
96/* We can only do 16-bit reads and writes in the static memory space. */
97#define SMC_CAN_USE_8BIT 1
98#define SMC_CAN_USE_16BIT 1
99#define SMC_CAN_USE_32BIT 0
100#define SMC_IO_SHIFT 0
101#define SMC_NOWAIT 1
102
Russell King1cf99be2005-11-12 21:49:36 +0000103#define SMC_inb(a, r) readb((a) + (r))
104#define SMC_insb(a, r, p, l) readsb((a) + (r), p, (l))
105#define SMC_inw(a, r) readw((a) + (r))
106#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
107#define SMC_outb(v, a, r) writeb(v, (a) + (r))
108#define SMC_outsb(a, r, p, l) writesb((a) + (r), p, (l))
109#define SMC_outw(v, a, r) writew(v, (a) + (r))
110#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Russell King9ded96f2006-01-08 01:02:07 -0800112#define SMC_IRQ_FLAGS (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114#elif defined(CONFIG_SA1100_ASSABET)
115
116#include <asm/arch/neponset.h>
117
118/* We can only do 8-bit reads and writes in the static memory space. */
119#define SMC_CAN_USE_8BIT 1
120#define SMC_CAN_USE_16BIT 0
121#define SMC_CAN_USE_32BIT 0
122#define SMC_NOWAIT 1
123
124/* The first two address lines aren't connected... */
125#define SMC_IO_SHIFT 2
126
127#define SMC_inb(a, r) readb((a) + (r))
128#define SMC_outb(v, a, r) writeb(v, (a) + (r))
129#define SMC_insb(a, r, p, l) readsb((a) + (r), p, (l))
130#define SMC_outsb(a, r, p, l) writesb((a) + (r), p, (l))
131
Lennert Buytenhekb0348b92006-03-28 17:19:50 +0200132#elif defined(CONFIG_MACH_LOGICPD_PXA270)
133
134#define SMC_CAN_USE_8BIT 0
135#define SMC_CAN_USE_16BIT 1
136#define SMC_CAN_USE_32BIT 0
137#define SMC_IO_SHIFT 0
138#define SMC_NOWAIT 1
139#define SMC_USE_PXA_DMA 1
140
141#define SMC_inb(a, r) readb((a) + (r))
142#define SMC_inw(a, r) readw((a) + (r))
143#define SMC_inl(a, r) readl((a) + (r))
144#define SMC_outb(v, a, r) writeb(v, (a) + (r))
145#define SMC_outw(v, a, r) writew(v, (a) + (r))
146#define SMC_outl(v, a, r) writel(v, (a) + (r))
147#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
148#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#elif defined(CONFIG_ARCH_INNOKOM) || \
151 defined(CONFIG_MACH_MAINSTONE) || \
152 defined(CONFIG_ARCH_PXA_IDP) || \
153 defined(CONFIG_ARCH_RAMSES)
154
155#define SMC_CAN_USE_8BIT 1
156#define SMC_CAN_USE_16BIT 1
157#define SMC_CAN_USE_32BIT 1
158#define SMC_IO_SHIFT 0
159#define SMC_NOWAIT 1
160#define SMC_USE_PXA_DMA 1
161
162#define SMC_inb(a, r) readb((a) + (r))
163#define SMC_inw(a, r) readw((a) + (r))
164#define SMC_inl(a, r) readl((a) + (r))
165#define SMC_outb(v, a, r) writeb(v, (a) + (r))
166#define SMC_outl(v, a, r) writel(v, (a) + (r))
167#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
168#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
169
170/* We actually can't write halfwords properly if not word aligned */
171static inline void
Nicolas Pitreeb1d6982005-05-12 20:19:09 -0400172SMC_outw(u16 val, void __iomem *ioaddr, int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 if (reg & 2) {
175 unsigned int v = val << 16;
176 v |= readl(ioaddr + (reg & ~2)) & 0xffff;
177 writel(v, ioaddr + (reg & ~2));
178 } else {
179 writew(val, ioaddr + reg);
180 }
181}
182
183#elif defined(CONFIG_ARCH_OMAP)
184
185/* We can only do 16-bit reads and writes in the static memory space. */
186#define SMC_CAN_USE_8BIT 0
187#define SMC_CAN_USE_16BIT 1
188#define SMC_CAN_USE_32BIT 0
189#define SMC_IO_SHIFT 0
190#define SMC_NOWAIT 1
191
192#define SMC_inb(a, r) readb((a) + (r))
193#define SMC_outb(v, a, r) writeb(v, (a) + (r))
194#define SMC_inw(a, r) readw((a) + (r))
195#define SMC_outw(v, a, r) writew(v, (a) + (r))
196#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
197#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
198#define SMC_inl(a, r) readl((a) + (r))
199#define SMC_outl(v, a, r) writel(v, (a) + (r))
200#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
201#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
202
David Brownell5f13e7e2005-05-16 08:53:52 -0700203#include <asm/mach-types.h>
204#include <asm/arch/cpu.h>
205
Russell King9ded96f2006-01-08 01:02:07 -0800206#define SMC_IRQ_FLAGS (( \
David Brownell5f13e7e2005-05-16 08:53:52 -0700207 machine_is_omap_h2() \
208 || machine_is_omap_h3() \
Tony Lindgrenaf44f5b2005-06-30 06:40:18 -0700209 || (machine_is_omap_innovator() && !cpu_is_omap1510()) \
Russell King9ded96f2006-01-08 01:02:07 -0800210 ) ? SA_TRIGGER_FALLING : SA_TRIGGER_RISING)
David Brownell5f13e7e2005-05-16 08:53:52 -0700211
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213#elif defined(CONFIG_SH_SH4202_MICRODEV)
214
215#define SMC_CAN_USE_8BIT 0
216#define SMC_CAN_USE_16BIT 1
217#define SMC_CAN_USE_32BIT 0
218
219#define SMC_inb(a, r) inb((a) + (r) - 0xa0000000)
220#define SMC_inw(a, r) inw((a) + (r) - 0xa0000000)
221#define SMC_inl(a, r) inl((a) + (r) - 0xa0000000)
222#define SMC_outb(v, a, r) outb(v, (a) + (r) - 0xa0000000)
223#define SMC_outw(v, a, r) outw(v, (a) + (r) - 0xa0000000)
224#define SMC_outl(v, a, r) outl(v, (a) + (r) - 0xa0000000)
225#define SMC_insl(a, r, p, l) insl((a) + (r) - 0xa0000000, p, l)
226#define SMC_outsl(a, r, p, l) outsl((a) + (r) - 0xa0000000, p, l)
227#define SMC_insw(a, r, p, l) insw((a) + (r) - 0xa0000000, p, l)
228#define SMC_outsw(a, r, p, l) outsw((a) + (r) - 0xa0000000, p, l)
229
Russell King9ded96f2006-01-08 01:02:07 -0800230#define SMC_IRQ_FLAGS (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232#elif defined(CONFIG_ISA)
233
234#define SMC_CAN_USE_8BIT 1
235#define SMC_CAN_USE_16BIT 1
236#define SMC_CAN_USE_32BIT 0
237
238#define SMC_inb(a, r) inb((a) + (r))
239#define SMC_inw(a, r) inw((a) + (r))
240#define SMC_outb(v, a, r) outb(v, (a) + (r))
241#define SMC_outw(v, a, r) outw(v, (a) + (r))
242#define SMC_insw(a, r, p, l) insw((a) + (r), p, l)
243#define SMC_outsw(a, r, p, l) outsw((a) + (r), p, l)
244
245#elif defined(CONFIG_M32R)
246
247#define SMC_CAN_USE_8BIT 0
248#define SMC_CAN_USE_16BIT 1
249#define SMC_CAN_USE_32BIT 0
250
Hirokazu Takataf3ac9fb2005-10-30 15:00:06 -0800251#define SMC_inb(a, r) inb((u32)a) + (r))
252#define SMC_inw(a, r) inw(((u32)a) + (r))
253#define SMC_outb(v, a, r) outb(v, ((u32)a) + (r))
254#define SMC_outw(v, a, r) outw(v, ((u32)a) + (r))
255#define SMC_insw(a, r, p, l) insw(((u32)a) + (r), p, l)
256#define SMC_outsw(a, r, p, l) outsw(((u32)a) + (r), p, l)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Russell King9ded96f2006-01-08 01:02:07 -0800258#define SMC_IRQ_FLAGS (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260#define RPC_LSA_DEFAULT RPC_LED_TX_RX
261#define RPC_LSB_DEFAULT RPC_LED_100_10
262
263#elif defined(CONFIG_MACH_LPD7A400) || defined(CONFIG_MACH_LPD7A404)
264
265/* The LPD7A40X_IOBARRIER is necessary to overcome a mismatch between
266 * the way that the CPU handles chip selects and the way that the SMC
267 * chip expects the chip select to operate. Refer to
268 * Documentation/arm/Sharp-LH/IOBarrier for details. The read from
269 * IOBARRIER is a byte as a least-common denominator of possible
270 * regions to use as the barrier. It would be wasteful to read 32
271 * bits from a byte oriented region.
272 *
273 * There is no explicit protection against interrupts intervening
274 * between the writew and the IOBARRIER. In SMC ISR there is a
275 * preamble that performs an IOBARRIER in the extremely unlikely event
276 * that the driver interrupts itself between a writew to the chip an
277 * the IOBARRIER that follows *and* the cache is large enough that the
278 * first off-chip access while handing the interrupt is to the SMC
279 * chip. Other devices in the same address space as the SMC chip must
280 * be aware of the potential for trouble and perform a similar
281 * IOBARRIER on entry to their ISR.
282 */
283
284#include <asm/arch/constants.h> /* IOBARRIER_VIRT */
285
286#define SMC_CAN_USE_8BIT 0
287#define SMC_CAN_USE_16BIT 1
288#define SMC_CAN_USE_32BIT 0
289#define SMC_NOWAIT 0
290#define LPD7A40X_IOBARRIER readb (IOBARRIER_VIRT)
291
292#define SMC_inw(a,r) readw ((void*) ((a) + (r)))
293#define SMC_insw(a,r,p,l) readsw ((void*) ((a) + (r)), p, l)
294#define SMC_outw(v,a,r) ({ writew ((v), (a) + (r)); LPD7A40X_IOBARRIER; })
295
Nicolas Pitre09779c62006-03-20 11:54:27 -0500296#define SMC_outsw LPD7A40X_SMC_outsw
297
298static inline void LPD7A40X_SMC_outsw(unsigned long a, int r,
299 unsigned char* p, int l)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
301 unsigned short* ps = (unsigned short*) p;
302 while (l-- > 0) {
303 writew (*ps++, a + r);
304 LPD7A40X_IOBARRIER;
305 }
306}
307
308#define SMC_INTERRUPT_PREAMBLE LPD7A40X_IOBARRIER
309
310#define RPC_LSA_DEFAULT RPC_LED_TX_RX
311#define RPC_LSB_DEFAULT RPC_LED_100_10
312
Pete Popov55793452005-11-09 22:46:05 -0500313#elif defined(CONFIG_SOC_AU1X00)
314
315#include <au1xxx.h>
316
317/* We can only do 16-bit reads and writes in the static memory space. */
318#define SMC_CAN_USE_8BIT 0
319#define SMC_CAN_USE_16BIT 1
320#define SMC_CAN_USE_32BIT 0
321#define SMC_IO_SHIFT 0
322#define SMC_NOWAIT 1
323
324#define SMC_inw(a, r) au_readw((unsigned long)((a) + (r)))
325#define SMC_insw(a, r, p, l) \
326 do { \
327 unsigned long _a = (unsigned long)((a) + (r)); \
328 int _l = (l); \
329 u16 *_p = (u16 *)(p); \
330 while (_l-- > 0) \
331 *_p++ = au_readw(_a); \
332 } while(0)
333#define SMC_outw(v, a, r) au_writew(v, (unsigned long)((a) + (r)))
334#define SMC_outsw(a, r, p, l) \
335 do { \
336 unsigned long _a = (unsigned long)((a) + (r)); \
337 int _l = (l); \
338 const u16 *_p = (const u16 *)(p); \
339 while (_l-- > 0) \
340 au_writew(*_p++ , _a); \
341 } while(0)
342
Russell King9ded96f2006-01-08 01:02:07 -0800343#define SMC_IRQ_FLAGS (0)
Pete Popov55793452005-11-09 22:46:05 -0500344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345#else
346
347#define SMC_CAN_USE_8BIT 1
348#define SMC_CAN_USE_16BIT 1
349#define SMC_CAN_USE_32BIT 1
350#define SMC_NOWAIT 1
351
352#define SMC_inb(a, r) readb((a) + (r))
353#define SMC_inw(a, r) readw((a) + (r))
354#define SMC_inl(a, r) readl((a) + (r))
355#define SMC_outb(v, a, r) writeb(v, (a) + (r))
356#define SMC_outw(v, a, r) writew(v, (a) + (r))
357#define SMC_outl(v, a, r) writel(v, (a) + (r))
358#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
359#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
360
361#define RPC_LSA_DEFAULT RPC_LED_100_10
362#define RPC_LSB_DEFAULT RPC_LED_TX_RX
363
364#endif
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#ifdef SMC_USE_PXA_DMA
367/*
368 * Let's use the DMA engine on the XScale PXA2xx for RX packets. This is
369 * always happening in irq context so no need to worry about races. TX is
370 * different and probably not worth it for that reason, and not as critical
371 * as RX which can overrun memory and lose packets.
372 */
373#include <linux/dma-mapping.h>
374#include <asm/dma.h>
375#include <asm/arch/pxa-regs.h>
376
377#ifdef SMC_insl
378#undef SMC_insl
379#define SMC_insl(a, r, p, l) \
380 smc_pxa_dma_insl(a, lp->physaddr, r, dev->dma, p, l)
381static inline void
Nicolas Pitreeb1d6982005-05-12 20:19:09 -0400382smc_pxa_dma_insl(void __iomem *ioaddr, u_long physaddr, int reg, int dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 u_char *buf, int len)
384{
385 dma_addr_t dmabuf;
386
387 /* fallback if no DMA available */
388 if (dma == (unsigned char)-1) {
389 readsl(ioaddr + reg, buf, len);
390 return;
391 }
392
393 /* 64 bit alignment is required for memory to memory DMA */
394 if ((long)buf & 4) {
395 *((u32 *)buf) = SMC_inl(ioaddr, reg);
396 buf += 4;
397 len--;
398 }
399
400 len *= 4;
401 dmabuf = dma_map_single(NULL, buf, len, DMA_FROM_DEVICE);
402 DCSR(dma) = DCSR_NODESC;
403 DTADR(dma) = dmabuf;
404 DSADR(dma) = physaddr + reg;
405 DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
406 DCMD_WIDTH4 | (DCMD_LENGTH & len));
407 DCSR(dma) = DCSR_NODESC | DCSR_RUN;
408 while (!(DCSR(dma) & DCSR_STOPSTATE))
409 cpu_relax();
410 DCSR(dma) = 0;
411 dma_unmap_single(NULL, dmabuf, len, DMA_FROM_DEVICE);
412}
413#endif
414
415#ifdef SMC_insw
416#undef SMC_insw
417#define SMC_insw(a, r, p, l) \
418 smc_pxa_dma_insw(a, lp->physaddr, r, dev->dma, p, l)
419static inline void
Nicolas Pitreeb1d6982005-05-12 20:19:09 -0400420smc_pxa_dma_insw(void __iomem *ioaddr, u_long physaddr, int reg, int dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 u_char *buf, int len)
422{
423 dma_addr_t dmabuf;
424
425 /* fallback if no DMA available */
426 if (dma == (unsigned char)-1) {
427 readsw(ioaddr + reg, buf, len);
428 return;
429 }
430
431 /* 64 bit alignment is required for memory to memory DMA */
432 while ((long)buf & 6) {
433 *((u16 *)buf) = SMC_inw(ioaddr, reg);
434 buf += 2;
435 len--;
436 }
437
438 len *= 2;
439 dmabuf = dma_map_single(NULL, buf, len, DMA_FROM_DEVICE);
440 DCSR(dma) = DCSR_NODESC;
441 DTADR(dma) = dmabuf;
442 DSADR(dma) = physaddr + reg;
443 DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
444 DCMD_WIDTH2 | (DCMD_LENGTH & len));
445 DCSR(dma) = DCSR_NODESC | DCSR_RUN;
446 while (!(DCSR(dma) & DCSR_STOPSTATE))
447 cpu_relax();
448 DCSR(dma) = 0;
449 dma_unmap_single(NULL, dmabuf, len, DMA_FROM_DEVICE);
450}
451#endif
452
453static void
454smc_pxa_dma_irq(int dma, void *dummy, struct pt_regs *regs)
455{
456 DCSR(dma) = 0;
457}
458#endif /* SMC_USE_PXA_DMA */
459
460
Nicolas Pitre09779c62006-03-20 11:54:27 -0500461/*
462 * Everything a particular hardware setup needs should have been defined
463 * at this point. Add stubs for the undefined cases, mainly to avoid
464 * compilation warnings since they'll be optimized away, or to prevent buggy
465 * use of them.
466 */
467
468#if ! SMC_CAN_USE_32BIT
469#define SMC_inl(ioaddr, reg) ({ BUG(); 0; })
470#define SMC_outl(x, ioaddr, reg) BUG()
471#define SMC_insl(a, r, p, l) BUG()
472#define SMC_outsl(a, r, p, l) BUG()
473#endif
474
475#if !defined(SMC_insl) || !defined(SMC_outsl)
476#define SMC_insl(a, r, p, l) BUG()
477#define SMC_outsl(a, r, p, l) BUG()
478#endif
479
480#if ! SMC_CAN_USE_16BIT
481
482/*
483 * Any 16-bit access is performed with two 8-bit accesses if the hardware
484 * can't do it directly. Most registers are 16-bit so those are mandatory.
485 */
486#define SMC_outw(x, ioaddr, reg) \
487 do { \
488 unsigned int __val16 = (x); \
489 SMC_outb( __val16, ioaddr, reg ); \
490 SMC_outb( __val16 >> 8, ioaddr, reg + (1 << SMC_IO_SHIFT));\
491 } while (0)
492#define SMC_inw(ioaddr, reg) \
493 ({ \
494 unsigned int __val16; \
495 __val16 = SMC_inb( ioaddr, reg ); \
496 __val16 |= SMC_inb( ioaddr, reg + (1 << SMC_IO_SHIFT)) << 8; \
497 __val16; \
498 })
499
500#define SMC_insw(a, r, p, l) BUG()
501#define SMC_outsw(a, r, p, l) BUG()
502
503#endif
504
505#if !defined(SMC_insw) || !defined(SMC_outsw)
506#define SMC_insw(a, r, p, l) BUG()
507#define SMC_outsw(a, r, p, l) BUG()
508#endif
509
510#if ! SMC_CAN_USE_8BIT
511#define SMC_inb(ioaddr, reg) ({ BUG(); 0; })
512#define SMC_outb(x, ioaddr, reg) BUG()
513#define SMC_insb(a, r, p, l) BUG()
514#define SMC_outsb(a, r, p, l) BUG()
515#endif
516
517#if !defined(SMC_insb) || !defined(SMC_outsb)
518#define SMC_insb(a, r, p, l) BUG()
519#define SMC_outsb(a, r, p, l) BUG()
520#endif
521
522#ifndef SMC_CAN_USE_DATACS
523#define SMC_CAN_USE_DATACS 0
524#endif
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526#ifndef SMC_IO_SHIFT
527#define SMC_IO_SHIFT 0
528#endif
Nicolas Pitre09779c62006-03-20 11:54:27 -0500529
530#ifndef SMC_IRQ_FLAGS
531#define SMC_IRQ_FLAGS SA_TRIGGER_RISING
532#endif
533
534#ifndef SMC_INTERRUPT_PREAMBLE
535#define SMC_INTERRUPT_PREAMBLE
536#endif
537
538
539/* Because of bank switching, the LAN91x uses only 16 I/O ports */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540#define SMC_IO_EXTENT (16 << SMC_IO_SHIFT)
541#define SMC_DATA_EXTENT (4)
542
543/*
544 . Bank Select Register:
545 .
546 . yyyy yyyy 0000 00xx
547 . xx = bank number
548 . yyyy yyyy = 0x33, for identification purposes.
549*/
550#define BANK_SELECT (14 << SMC_IO_SHIFT)
551
552
553// Transmit Control Register
554/* BANK 0 */
555#define TCR_REG SMC_REG(0x0000, 0)
556#define TCR_ENABLE 0x0001 // When 1 we can transmit
557#define TCR_LOOP 0x0002 // Controls output pin LBK
558#define TCR_FORCOL 0x0004 // When 1 will force a collision
559#define TCR_PAD_EN 0x0080 // When 1 will pad tx frames < 64 bytes w/0
560#define TCR_NOCRC 0x0100 // When 1 will not append CRC to tx frames
561#define TCR_MON_CSN 0x0400 // When 1 tx monitors carrier
562#define TCR_FDUPLX 0x0800 // When 1 enables full duplex operation
563#define TCR_STP_SQET 0x1000 // When 1 stops tx if Signal Quality Error
564#define TCR_EPH_LOOP 0x2000 // When 1 enables EPH block loopback
565#define TCR_SWFDUP 0x8000 // When 1 enables Switched Full Duplex mode
566
567#define TCR_CLEAR 0 /* do NOTHING */
568/* the default settings for the TCR register : */
569#define TCR_DEFAULT (TCR_ENABLE | TCR_PAD_EN)
570
571
572// EPH Status Register
573/* BANK 0 */
574#define EPH_STATUS_REG SMC_REG(0x0002, 0)
575#define ES_TX_SUC 0x0001 // Last TX was successful
576#define ES_SNGL_COL 0x0002 // Single collision detected for last tx
577#define ES_MUL_COL 0x0004 // Multiple collisions detected for last tx
578#define ES_LTX_MULT 0x0008 // Last tx was a multicast
579#define ES_16COL 0x0010 // 16 Collisions Reached
580#define ES_SQET 0x0020 // Signal Quality Error Test
581#define ES_LTXBRD 0x0040 // Last tx was a broadcast
582#define ES_TXDEFR 0x0080 // Transmit Deferred
583#define ES_LATCOL 0x0200 // Late collision detected on last tx
584#define ES_LOSTCARR 0x0400 // Lost Carrier Sense
585#define ES_EXC_DEF 0x0800 // Excessive Deferral
586#define ES_CTR_ROL 0x1000 // Counter Roll Over indication
587#define ES_LINK_OK 0x4000 // Driven by inverted value of nLNK pin
588#define ES_TXUNRN 0x8000 // Tx Underrun
589
590
591// Receive Control Register
592/* BANK 0 */
593#define RCR_REG SMC_REG(0x0004, 0)
594#define RCR_RX_ABORT 0x0001 // Set if a rx frame was aborted
595#define RCR_PRMS 0x0002 // Enable promiscuous mode
596#define RCR_ALMUL 0x0004 // When set accepts all multicast frames
597#define RCR_RXEN 0x0100 // IFF this is set, we can receive packets
598#define RCR_STRIP_CRC 0x0200 // When set strips CRC from rx packets
599#define RCR_ABORT_ENB 0x0200 // When set will abort rx on collision
600#define RCR_FILT_CAR 0x0400 // When set filters leading 12 bit s of carrier
601#define RCR_SOFTRST 0x8000 // resets the chip
602
603/* the normal settings for the RCR register : */
604#define RCR_DEFAULT (RCR_STRIP_CRC | RCR_RXEN)
605#define RCR_CLEAR 0x0 // set it to a base state
606
607
608// Counter Register
609/* BANK 0 */
610#define COUNTER_REG SMC_REG(0x0006, 0)
611
612
613// Memory Information Register
614/* BANK 0 */
615#define MIR_REG SMC_REG(0x0008, 0)
616
617
618// Receive/Phy Control Register
619/* BANK 0 */
620#define RPC_REG SMC_REG(0x000A, 0)
621#define RPC_SPEED 0x2000 // When 1 PHY is in 100Mbps mode.
622#define RPC_DPLX 0x1000 // When 1 PHY is in Full-Duplex Mode
623#define RPC_ANEG 0x0800 // When 1 PHY is in Auto-Negotiate Mode
624#define RPC_LSXA_SHFT 5 // Bits to shift LS2A,LS1A,LS0A to lsb
625#define RPC_LSXB_SHFT 2 // Bits to get LS2B,LS1B,LS0B to lsb
626#define RPC_LED_100_10 (0x00) // LED = 100Mbps OR's with 10Mbps link detect
627#define RPC_LED_RES (0x01) // LED = Reserved
628#define RPC_LED_10 (0x02) // LED = 10Mbps link detect
629#define RPC_LED_FD (0x03) // LED = Full Duplex Mode
630#define RPC_LED_TX_RX (0x04) // LED = TX or RX packet occurred
631#define RPC_LED_100 (0x05) // LED = 100Mbps link dectect
632#define RPC_LED_TX (0x06) // LED = TX packet occurred
633#define RPC_LED_RX (0x07) // LED = RX packet occurred
634
635#ifndef RPC_LSA_DEFAULT
636#define RPC_LSA_DEFAULT RPC_LED_100
637#endif
638#ifndef RPC_LSB_DEFAULT
639#define RPC_LSB_DEFAULT RPC_LED_FD
640#endif
641
642#define RPC_DEFAULT (RPC_ANEG | (RPC_LSA_DEFAULT << RPC_LSXA_SHFT) | (RPC_LSB_DEFAULT << RPC_LSXB_SHFT) | RPC_SPEED | RPC_DPLX)
643
644
645/* Bank 0 0x0C is reserved */
646
647// Bank Select Register
648/* All Banks */
649#define BSR_REG 0x000E
650
651
652// Configuration Reg
653/* BANK 1 */
654#define CONFIG_REG SMC_REG(0x0000, 1)
655#define CONFIG_EXT_PHY 0x0200 // 1=external MII, 0=internal Phy
656#define CONFIG_GPCNTRL 0x0400 // Inverse value drives pin nCNTRL
657#define CONFIG_NO_WAIT 0x1000 // When 1 no extra wait states on ISA bus
658#define CONFIG_EPH_POWER_EN 0x8000 // When 0 EPH is placed into low power mode.
659
660// Default is powered-up, Internal Phy, Wait States, and pin nCNTRL=low
661#define CONFIG_DEFAULT (CONFIG_EPH_POWER_EN)
662
663
664// Base Address Register
665/* BANK 1 */
666#define BASE_REG SMC_REG(0x0002, 1)
667
668
669// Individual Address Registers
670/* BANK 1 */
671#define ADDR0_REG SMC_REG(0x0004, 1)
672#define ADDR1_REG SMC_REG(0x0006, 1)
673#define ADDR2_REG SMC_REG(0x0008, 1)
674
675
676// General Purpose Register
677/* BANK 1 */
678#define GP_REG SMC_REG(0x000A, 1)
679
680
681// Control Register
682/* BANK 1 */
683#define CTL_REG SMC_REG(0x000C, 1)
684#define CTL_RCV_BAD 0x4000 // When 1 bad CRC packets are received
685#define CTL_AUTO_RELEASE 0x0800 // When 1 tx pages are released automatically
686#define CTL_LE_ENABLE 0x0080 // When 1 enables Link Error interrupt
687#define CTL_CR_ENABLE 0x0040 // When 1 enables Counter Rollover interrupt
688#define CTL_TE_ENABLE 0x0020 // When 1 enables Transmit Error interrupt
689#define CTL_EEPROM_SELECT 0x0004 // Controls EEPROM reload & store
690#define CTL_RELOAD 0x0002 // When set reads EEPROM into registers
691#define CTL_STORE 0x0001 // When set stores registers into EEPROM
692
693
694// MMU Command Register
695/* BANK 2 */
696#define MMU_CMD_REG SMC_REG(0x0000, 2)
697#define MC_BUSY 1 // When 1 the last release has not completed
698#define MC_NOP (0<<5) // No Op
699#define MC_ALLOC (1<<5) // OR with number of 256 byte packets
700#define MC_RESET (2<<5) // Reset MMU to initial state
701#define MC_REMOVE (3<<5) // Remove the current rx packet
702#define MC_RELEASE (4<<5) // Remove and release the current rx packet
703#define MC_FREEPKT (5<<5) // Release packet in PNR register
704#define MC_ENQUEUE (6<<5) // Enqueue the packet for transmit
705#define MC_RSTTXFIFO (7<<5) // Reset the TX FIFOs
706
707
708// Packet Number Register
709/* BANK 2 */
710#define PN_REG SMC_REG(0x0002, 2)
711
712
713// Allocation Result Register
714/* BANK 2 */
715#define AR_REG SMC_REG(0x0003, 2)
716#define AR_FAILED 0x80 // Alocation Failed
717
718
719// TX FIFO Ports Register
720/* BANK 2 */
721#define TXFIFO_REG SMC_REG(0x0004, 2)
722#define TXFIFO_TEMPTY 0x80 // TX FIFO Empty
723
724// RX FIFO Ports Register
725/* BANK 2 */
726#define RXFIFO_REG SMC_REG(0x0005, 2)
727#define RXFIFO_REMPTY 0x80 // RX FIFO Empty
728
729#define FIFO_REG SMC_REG(0x0004, 2)
730
731// Pointer Register
732/* BANK 2 */
733#define PTR_REG SMC_REG(0x0006, 2)
734#define PTR_RCV 0x8000 // 1=Receive area, 0=Transmit area
735#define PTR_AUTOINC 0x4000 // Auto increment the pointer on each access
736#define PTR_READ 0x2000 // When 1 the operation is a read
737
738
739// Data Register
740/* BANK 2 */
741#define DATA_REG SMC_REG(0x0008, 2)
742
743
744// Interrupt Status/Acknowledge Register
745/* BANK 2 */
746#define INT_REG SMC_REG(0x000C, 2)
747
748
749// Interrupt Mask Register
750/* BANK 2 */
751#define IM_REG SMC_REG(0x000D, 2)
752#define IM_MDINT 0x80 // PHY MI Register 18 Interrupt
753#define IM_ERCV_INT 0x40 // Early Receive Interrupt
754#define IM_EPH_INT 0x20 // Set by Ethernet Protocol Handler section
755#define IM_RX_OVRN_INT 0x10 // Set by Receiver Overruns
756#define IM_ALLOC_INT 0x08 // Set when allocation request is completed
757#define IM_TX_EMPTY_INT 0x04 // Set if the TX FIFO goes empty
758#define IM_TX_INT 0x02 // Transmit Interrupt
759#define IM_RCV_INT 0x01 // Receive Interrupt
760
761
762// Multicast Table Registers
763/* BANK 3 */
764#define MCAST_REG1 SMC_REG(0x0000, 3)
765#define MCAST_REG2 SMC_REG(0x0002, 3)
766#define MCAST_REG3 SMC_REG(0x0004, 3)
767#define MCAST_REG4 SMC_REG(0x0006, 3)
768
769
770// Management Interface Register (MII)
771/* BANK 3 */
772#define MII_REG SMC_REG(0x0008, 3)
773#define MII_MSK_CRS100 0x4000 // Disables CRS100 detection during tx half dup
774#define MII_MDOE 0x0008 // MII Output Enable
775#define MII_MCLK 0x0004 // MII Clock, pin MDCLK
776#define MII_MDI 0x0002 // MII Input, pin MDI
777#define MII_MDO 0x0001 // MII Output, pin MDO
778
779
780// Revision Register
781/* BANK 3 */
782/* ( hi: chip id low: rev # ) */
783#define REV_REG SMC_REG(0x000A, 3)
784
785
786// Early RCV Register
787/* BANK 3 */
788/* this is NOT on SMC9192 */
789#define ERCV_REG SMC_REG(0x000C, 3)
790#define ERCV_RCV_DISCRD 0x0080 // When 1 discards a packet being received
791#define ERCV_THRESHOLD 0x001F // ERCV Threshold Mask
792
793
794// External Register
795/* BANK 7 */
796#define EXT_REG SMC_REG(0x0000, 7)
797
798
799#define CHIP_9192 3
800#define CHIP_9194 4
801#define CHIP_9195 5
802#define CHIP_9196 6
803#define CHIP_91100 7
804#define CHIP_91100FD 8
805#define CHIP_91111FD 9
806
807static const char * chip_ids[ 16 ] = {
808 NULL, NULL, NULL,
809 /* 3 */ "SMC91C90/91C92",
810 /* 4 */ "SMC91C94",
811 /* 5 */ "SMC91C95",
812 /* 6 */ "SMC91C96",
813 /* 7 */ "SMC91C100",
814 /* 8 */ "SMC91C100FD",
815 /* 9 */ "SMC91C11xFD",
816 NULL, NULL, NULL,
817 NULL, NULL, NULL};
818
819
820/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 . Receive status bits
822*/
823#define RS_ALGNERR 0x8000
824#define RS_BRODCAST 0x4000
825#define RS_BADCRC 0x2000
826#define RS_ODDFRAME 0x1000
827#define RS_TOOLONG 0x0800
828#define RS_TOOSHORT 0x0400
829#define RS_MULTICAST 0x0001
830#define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
831
832
833/*
834 * PHY IDs
835 * LAN83C183 == LAN91C111 Internal PHY
836 */
837#define PHY_LAN83C183 0x0016f840
838#define PHY_LAN83C180 0x02821c50
839
840/*
841 * PHY Register Addresses (LAN91C111 Internal PHY)
842 *
843 * Generic PHY registers can be found in <linux/mii.h>
844 *
845 * These phy registers are specific to our on-board phy.
846 */
847
848// PHY Configuration Register 1
849#define PHY_CFG1_REG 0x10
850#define PHY_CFG1_LNKDIS 0x8000 // 1=Rx Link Detect Function disabled
851#define PHY_CFG1_XMTDIS 0x4000 // 1=TP Transmitter Disabled
852#define PHY_CFG1_XMTPDN 0x2000 // 1=TP Transmitter Powered Down
853#define PHY_CFG1_BYPSCR 0x0400 // 1=Bypass scrambler/descrambler
854#define PHY_CFG1_UNSCDS 0x0200 // 1=Unscramble Idle Reception Disable
855#define PHY_CFG1_EQLZR 0x0100 // 1=Rx Equalizer Disabled
856#define PHY_CFG1_CABLE 0x0080 // 1=STP(150ohm), 0=UTP(100ohm)
857#define PHY_CFG1_RLVL0 0x0040 // 1=Rx Squelch level reduced by 4.5db
858#define PHY_CFG1_TLVL_SHIFT 2 // Transmit Output Level Adjust
859#define PHY_CFG1_TLVL_MASK 0x003C
860#define PHY_CFG1_TRF_MASK 0x0003 // Transmitter Rise/Fall time
861
862
863// PHY Configuration Register 2
864#define PHY_CFG2_REG 0x11
865#define PHY_CFG2_APOLDIS 0x0020 // 1=Auto Polarity Correction disabled
866#define PHY_CFG2_JABDIS 0x0010 // 1=Jabber disabled
867#define PHY_CFG2_MREG 0x0008 // 1=Multiple register access (MII mgt)
868#define PHY_CFG2_INTMDIO 0x0004 // 1=Interrupt signaled with MDIO pulseo
869
870// PHY Status Output (and Interrupt status) Register
871#define PHY_INT_REG 0x12 // Status Output (Interrupt Status)
872#define PHY_INT_INT 0x8000 // 1=bits have changed since last read
873#define PHY_INT_LNKFAIL 0x4000 // 1=Link Not detected
874#define PHY_INT_LOSSSYNC 0x2000 // 1=Descrambler has lost sync
875#define PHY_INT_CWRD 0x1000 // 1=Invalid 4B5B code detected on rx
876#define PHY_INT_SSD 0x0800 // 1=No Start Of Stream detected on rx
877#define PHY_INT_ESD 0x0400 // 1=No End Of Stream detected on rx
878#define PHY_INT_RPOL 0x0200 // 1=Reverse Polarity detected
879#define PHY_INT_JAB 0x0100 // 1=Jabber detected
880#define PHY_INT_SPDDET 0x0080 // 1=100Base-TX mode, 0=10Base-T mode
881#define PHY_INT_DPLXDET 0x0040 // 1=Device in Full Duplex
882
883// PHY Interrupt/Status Mask Register
884#define PHY_MASK_REG 0x13 // Interrupt Mask
885// Uses the same bit definitions as PHY_INT_REG
886
887
888/*
889 * SMC91C96 ethernet config and status registers.
890 * These are in the "attribute" space.
891 */
892#define ECOR 0x8000
893#define ECOR_RESET 0x80
894#define ECOR_LEVEL_IRQ 0x40
895#define ECOR_WR_ATTRIB 0x04
896#define ECOR_ENABLE 0x01
897
898#define ECSR 0x8002
899#define ECSR_IOIS8 0x20
900#define ECSR_PWRDWN 0x04
901#define ECSR_INT 0x02
902
903#define ATTRIB_SIZE ((64*1024) << SMC_IO_SHIFT)
904
905
906/*
907 * Macros to abstract register access according to the data bus
908 * capabilities. Please use those and not the in/out primitives.
909 * Note: the following macros do *not* select the bank -- this must
910 * be done separately as needed in the main code. The SMC_REG() macro
911 * only uses the bank argument for debugging purposes (when enabled).
Nicolas Pitre09779c62006-03-20 11:54:27 -0500912 *
913 * Note: despite inline functions being safer, everything leading to this
914 * should preferably be macros to let BUG() display the line number in
915 * the core source code since we're interested in the top call site
916 * not in any inline function location.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 */
918
919#if SMC_DEBUG > 0
920#define SMC_REG(reg, bank) \
921 ({ \
922 int __b = SMC_CURRENT_BANK(); \
923 if (unlikely((__b & ~0xf0) != (0x3300 | bank))) { \
924 printk( "%s: bank reg screwed (0x%04x)\n", \
925 CARDNAME, __b ); \
926 BUG(); \
927 } \
928 reg<<SMC_IO_SHIFT; \
929 })
930#else
931#define SMC_REG(reg, bank) (reg<<SMC_IO_SHIFT)
932#endif
933
Nicolas Pitre09779c62006-03-20 11:54:27 -0500934/*
935 * Hack Alert: Some setups just can't write 8 or 16 bits reliably when not
936 * aligned to a 32 bit boundary. I tell you that does exist!
937 * Fortunately the affected register accesses can be easily worked around
938 * since we can write zeroes to the preceeding 16 bits without adverse
939 * effects and use a 32-bit access.
940 *
941 * Enforce it on any 32-bit capable setup for now.
942 */
943#define SMC_MUST_ALIGN_WRITE SMC_CAN_USE_32BIT
944
945#define SMC_GET_PN() \
946 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, PN_REG)) \
947 : (SMC_inw(ioaddr, PN_REG) & 0xFF) )
948
949#define SMC_SET_PN(x) \
950 do { \
951 if (SMC_MUST_ALIGN_WRITE) \
952 SMC_outl((x)<<16, ioaddr, SMC_REG(0, 2)); \
953 else if (SMC_CAN_USE_8BIT) \
954 SMC_outb(x, ioaddr, PN_REG); \
955 else \
956 SMC_outw(x, ioaddr, PN_REG); \
957 } while (0)
958
959#define SMC_GET_AR() \
960 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, AR_REG)) \
961 : (SMC_inw(ioaddr, PN_REG) >> 8) )
962
963#define SMC_GET_TXFIFO() \
964 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, TXFIFO_REG)) \
965 : (SMC_inw(ioaddr, TXFIFO_REG) & 0xFF) )
966
967#define SMC_GET_RXFIFO() \
968 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, RXFIFO_REG)) \
969 : (SMC_inw(ioaddr, TXFIFO_REG) >> 8) )
970
971#define SMC_GET_INT() \
972 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, INT_REG)) \
973 : (SMC_inw(ioaddr, INT_REG) & 0xFF) )
974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975#define SMC_ACK_INT(x) \
976 do { \
Nicolas Pitre09779c62006-03-20 11:54:27 -0500977 if (SMC_CAN_USE_8BIT) \
978 SMC_outb(x, ioaddr, INT_REG); \
979 else { \
980 unsigned long __flags; \
981 int __mask; \
982 local_irq_save(__flags); \
983 __mask = SMC_inw( ioaddr, INT_REG ) & ~0xff; \
984 SMC_outw( __mask | (x), ioaddr, INT_REG ); \
985 local_irq_restore(__flags); \
986 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Nicolas Pitre09779c62006-03-20 11:54:27 -0500989#define SMC_GET_INT_MASK() \
990 ( SMC_CAN_USE_8BIT ? (SMC_inb(ioaddr, IM_REG)) \
991 : (SMC_inw( ioaddr, INT_REG ) >> 8) )
992
993#define SMC_SET_INT_MASK(x) \
994 do { \
995 if (SMC_CAN_USE_8BIT) \
996 SMC_outb(x, ioaddr, IM_REG); \
997 else \
998 SMC_outw((x) << 8, ioaddr, INT_REG); \
999 } while (0)
1000
1001#define SMC_CURRENT_BANK() SMC_inw(ioaddr, BANK_SELECT)
1002
1003#define SMC_SELECT_BANK(x) \
1004 do { \
1005 if (SMC_MUST_ALIGN_WRITE) \
1006 SMC_outl((x)<<16, ioaddr, 12<<SMC_IO_SHIFT); \
1007 else \
1008 SMC_outw(x, ioaddr, BANK_SELECT); \
1009 } while (0)
1010
1011#define SMC_GET_BASE() SMC_inw(ioaddr, BASE_REG)
1012
1013#define SMC_SET_BASE(x) SMC_outw(x, ioaddr, BASE_REG)
1014
1015#define SMC_GET_CONFIG() SMC_inw(ioaddr, CONFIG_REG)
1016
1017#define SMC_SET_CONFIG(x) SMC_outw(x, ioaddr, CONFIG_REG)
1018
1019#define SMC_GET_COUNTER() SMC_inw(ioaddr, COUNTER_REG)
1020
1021#define SMC_GET_CTL() SMC_inw(ioaddr, CTL_REG)
1022
1023#define SMC_SET_CTL(x) SMC_outw(x, ioaddr, CTL_REG)
1024
1025#define SMC_GET_MII() SMC_inw(ioaddr, MII_REG)
1026
1027#define SMC_SET_MII(x) SMC_outw(x, ioaddr, MII_REG)
1028
1029#define SMC_GET_MIR() SMC_inw(ioaddr, MIR_REG)
1030
1031#define SMC_SET_MIR(x) SMC_outw(x, ioaddr, MIR_REG)
1032
1033#define SMC_GET_MMU_CMD() SMC_inw(ioaddr, MMU_CMD_REG)
1034
1035#define SMC_SET_MMU_CMD(x) SMC_outw(x, ioaddr, MMU_CMD_REG)
1036
1037#define SMC_GET_FIFO() SMC_inw(ioaddr, FIFO_REG)
1038
1039#define SMC_GET_PTR() SMC_inw(ioaddr, PTR_REG)
1040
1041#define SMC_SET_PTR(x) \
1042 do { \
1043 if (SMC_MUST_ALIGN_WRITE) \
1044 SMC_outl((x)<<16, ioaddr, SMC_REG(4, 2)); \
1045 else \
1046 SMC_outw(x, ioaddr, PTR_REG); \
1047 } while (0)
1048
1049#define SMC_GET_EPH_STATUS() SMC_inw(ioaddr, EPH_STATUS_REG)
1050
1051#define SMC_GET_RCR() SMC_inw(ioaddr, RCR_REG)
1052
1053#define SMC_SET_RCR(x) SMC_outw(x, ioaddr, RCR_REG)
1054
1055#define SMC_GET_REV() SMC_inw(ioaddr, REV_REG)
1056
1057#define SMC_GET_RPC() SMC_inw(ioaddr, RPC_REG)
1058
1059#define SMC_SET_RPC(x) \
1060 do { \
1061 if (SMC_MUST_ALIGN_WRITE) \
1062 SMC_outl((x)<<16, ioaddr, SMC_REG(8, 0)); \
1063 else \
1064 SMC_outw(x, ioaddr, RPC_REG); \
1065 } while (0)
1066
1067#define SMC_GET_TCR() SMC_inw(ioaddr, TCR_REG)
1068
1069#define SMC_SET_TCR(x) SMC_outw(x, ioaddr, TCR_REG)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071#ifndef SMC_GET_MAC_ADDR
1072#define SMC_GET_MAC_ADDR(addr) \
1073 do { \
1074 unsigned int __v; \
1075 __v = SMC_inw( ioaddr, ADDR0_REG ); \
1076 addr[0] = __v; addr[1] = __v >> 8; \
1077 __v = SMC_inw( ioaddr, ADDR1_REG ); \
1078 addr[2] = __v; addr[3] = __v >> 8; \
1079 __v = SMC_inw( ioaddr, ADDR2_REG ); \
1080 addr[4] = __v; addr[5] = __v >> 8; \
1081 } while (0)
1082#endif
1083
1084#define SMC_SET_MAC_ADDR(addr) \
1085 do { \
1086 SMC_outw( addr[0]|(addr[1] << 8), ioaddr, ADDR0_REG ); \
1087 SMC_outw( addr[2]|(addr[3] << 8), ioaddr, ADDR1_REG ); \
1088 SMC_outw( addr[4]|(addr[5] << 8), ioaddr, ADDR2_REG ); \
1089 } while (0)
1090
1091#define SMC_SET_MCAST(x) \
1092 do { \
1093 const unsigned char *mt = (x); \
1094 SMC_outw( mt[0] | (mt[1] << 8), ioaddr, MCAST_REG1 ); \
1095 SMC_outw( mt[2] | (mt[3] << 8), ioaddr, MCAST_REG2 ); \
1096 SMC_outw( mt[4] | (mt[5] << 8), ioaddr, MCAST_REG3 ); \
1097 SMC_outw( mt[6] | (mt[7] << 8), ioaddr, MCAST_REG4 ); \
1098 } while (0)
1099
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100#define SMC_PUT_PKT_HDR(status, length) \
1101 do { \
Nicolas Pitre09779c62006-03-20 11:54:27 -05001102 if (SMC_CAN_USE_32BIT) \
1103 SMC_outl((status) | (length)<<16, ioaddr, DATA_REG); \
1104 else { \
1105 SMC_outw(status, ioaddr, DATA_REG); \
1106 SMC_outw(length, ioaddr, DATA_REG); \
1107 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 } while (0)
Nicolas Pitre09779c62006-03-20 11:54:27 -05001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110#define SMC_GET_PKT_HDR(status, length) \
1111 do { \
Nicolas Pitre09779c62006-03-20 11:54:27 -05001112 if (SMC_CAN_USE_32BIT) { \
1113 unsigned int __val = SMC_inl(ioaddr, DATA_REG); \
1114 (status) = __val & 0xffff; \
1115 (length) = __val >> 16; \
1116 } else { \
1117 (status) = SMC_inw(ioaddr, DATA_REG); \
1118 (length) = SMC_inw(ioaddr, DATA_REG); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 } \
1120 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122#define SMC_PUSH_DATA(p, l) \
Nicolas Pitre09779c62006-03-20 11:54:27 -05001123 do { \
1124 if (SMC_CAN_USE_32BIT) { \
1125 void *__ptr = (p); \
1126 int __len = (l); \
1127 void *__ioaddr = ioaddr; \
1128 if (__len >= 2 && (unsigned long)__ptr & 2) { \
1129 __len -= 2; \
1130 SMC_outw(*(u16 *)__ptr, ioaddr, DATA_REG); \
1131 __ptr += 2; \
1132 } \
1133 if (SMC_CAN_USE_DATACS && lp->datacs) \
1134 __ioaddr = lp->datacs; \
1135 SMC_outsl(__ioaddr, DATA_REG, __ptr, __len>>2); \
1136 if (__len & 2) { \
1137 __ptr += (__len & ~3); \
1138 SMC_outw(*((u16 *)__ptr), ioaddr, DATA_REG); \
1139 } \
1140 } else if (SMC_CAN_USE_16BIT) \
1141 SMC_outsw(ioaddr, DATA_REG, p, (l) >> 1); \
1142 else if (SMC_CAN_USE_8BIT) \
1143 SMC_outsb(ioaddr, DATA_REG, p, l); \
1144 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146#define SMC_PULL_DATA(p, l) \
Nicolas Pitre09779c62006-03-20 11:54:27 -05001147 do { \
1148 if (SMC_CAN_USE_32BIT) { \
1149 void *__ptr = (p); \
1150 int __len = (l); \
1151 void *__ioaddr = ioaddr; \
1152 if ((unsigned long)__ptr & 2) { \
1153 /* \
1154 * We want 32bit alignment here. \
1155 * Since some buses perform a full \
1156 * 32bit fetch even for 16bit data \
1157 * we can't use SMC_inw() here. \
1158 * Back both source (on-chip) and \
1159 * destination pointers of 2 bytes. \
1160 * This is possible since the call to \
1161 * SMC_GET_PKT_HDR() already advanced \
1162 * the source pointer of 4 bytes, and \
1163 * the skb_reserve(skb, 2) advanced \
1164 * the destination pointer of 2 bytes. \
1165 */ \
1166 __ptr -= 2; \
1167 __len += 2; \
1168 SMC_SET_PTR(2|PTR_READ|PTR_RCV|PTR_AUTOINC); \
1169 } \
1170 if (SMC_CAN_USE_DATACS && lp->datacs) \
1171 __ioaddr = lp->datacs; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 __len += 2; \
Nicolas Pitre09779c62006-03-20 11:54:27 -05001173 SMC_insl(__ioaddr, DATA_REG, __ptr, __len>>2); \
1174 } else if (SMC_CAN_USE_16BIT) \
1175 SMC_insw(ioaddr, DATA_REG, p, (l) >> 1); \
1176 else if (SMC_CAN_USE_8BIT) \
1177 SMC_insb(ioaddr, DATA_REG, p, l); \
1178 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
1180#endif /* _SMC91X_H_ */