typhoon: fix incorrect use of smp_wmb()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / smc91x.h
bloba6ee883d1b0edc506fdf7000f283cf5bbd4da462
1 /*------------------------------------------------------------------------
2 . smc91x.h - macros for SMSC's 91C9x/91C1xx single-chip Ethernet device.
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
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.
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.
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
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.
28 . Authors
29 . Erik Stahlman <erik@vt.edu>
30 . Daris A Nevil <dnevil@snmc.com>
31 . Nicolas Pitre <nico@fluxnic.net>
33 ---------------------------------------------------------------------------*/
34 #ifndef _SMC91X_H_
35 #define _SMC91X_H_
37 #include <linux/smc91x.h>
40 * Define your architecture specific bus configuration parameters here.
43 #if defined(CONFIG_ARCH_LUBBOCK) ||\
44 defined(CONFIG_MACH_MAINSTONE) ||\
45 defined(CONFIG_MACH_ZYLONITE) ||\
46 defined(CONFIG_MACH_LITTLETON) ||\
47 defined(CONFIG_MACH_ZYLONITE2) ||\
48 defined(CONFIG_ARCH_VIPER) ||\
49 defined(CONFIG_MACH_STARGATE2)
51 #include <asm/mach-types.h>
53 /* Now the bus width is specified in the platform data
54 * pretend here to support all I/O access types
56 #define SMC_CAN_USE_8BIT 1
57 #define SMC_CAN_USE_16BIT 1
58 #define SMC_CAN_USE_32BIT 1
59 #define SMC_NOWAIT 1
61 #define SMC_IO_SHIFT (lp->io_shift)
63 #define SMC_inb(a, r) readb((a) + (r))
64 #define SMC_inw(a, r) readw((a) + (r))
65 #define SMC_inl(a, r) readl((a) + (r))
66 #define SMC_outb(v, a, r) writeb(v, (a) + (r))
67 #define SMC_outl(v, a, r) writel(v, (a) + (r))
68 #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
69 #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
70 #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
71 #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
72 #define SMC_IRQ_FLAGS (-1) /* from resource */
74 /* We actually can't write halfwords properly if not word aligned */
75 static inline void SMC_outw(u16 val, void __iomem *ioaddr, int reg)
77 if ((machine_is_mainstone() || machine_is_stargate2()) && reg & 2) {
78 unsigned int v = val << 16;
79 v |= readl(ioaddr + (reg & ~2)) & 0xffff;
80 writel(v, ioaddr + (reg & ~2));
81 } else {
82 writew(val, ioaddr + reg);
86 #elif defined(CONFIG_REDWOOD_5) || defined(CONFIG_REDWOOD_6)
88 /* We can only do 16-bit reads and writes in the static memory space. */
89 #define SMC_CAN_USE_8BIT 0
90 #define SMC_CAN_USE_16BIT 1
91 #define SMC_CAN_USE_32BIT 0
92 #define SMC_NOWAIT 1
94 #define SMC_IO_SHIFT 0
96 #define SMC_inw(a, r) in_be16((volatile u16 *)((a) + (r)))
97 #define SMC_outw(v, a, r) out_be16((volatile u16 *)((a) + (r)), v)
98 #define SMC_insw(a, r, p, l) \
99 do { \
100 unsigned long __port = (a) + (r); \
101 u16 *__p = (u16 *)(p); \
102 int __l = (l); \
103 insw(__port, __p, __l); \
104 while (__l > 0) { \
105 *__p = swab16(*__p); \
106 __p++; \
107 __l--; \
109 } while (0)
110 #define SMC_outsw(a, r, p, l) \
111 do { \
112 unsigned long __port = (a) + (r); \
113 u16 *__p = (u16 *)(p); \
114 int __l = (l); \
115 while (__l > 0) { \
116 /* Believe it or not, the swab isn't needed. */ \
117 outw( /* swab16 */ (*__p++), __port); \
118 __l--; \
120 } while (0)
121 #define SMC_IRQ_FLAGS (0)
123 #elif defined(CONFIG_SA1100_PLEB)
124 /* We can only do 16-bit reads and writes in the static memory space. */
125 #define SMC_CAN_USE_8BIT 1
126 #define SMC_CAN_USE_16BIT 1
127 #define SMC_CAN_USE_32BIT 0
128 #define SMC_IO_SHIFT 0
129 #define SMC_NOWAIT 1
131 #define SMC_inb(a, r) readb((a) + (r))
132 #define SMC_insb(a, r, p, l) readsb((a) + (r), p, (l))
133 #define SMC_inw(a, r) readw((a) + (r))
134 #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
135 #define SMC_outb(v, a, r) writeb(v, (a) + (r))
136 #define SMC_outsb(a, r, p, l) writesb((a) + (r), p, (l))
137 #define SMC_outw(v, a, r) writew(v, (a) + (r))
138 #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
140 #define SMC_IRQ_FLAGS (-1)
142 #elif defined(CONFIG_SA1100_ASSABET)
144 #include <mach/neponset.h>
146 /* We can only do 8-bit reads and writes in the static memory space. */
147 #define SMC_CAN_USE_8BIT 1
148 #define SMC_CAN_USE_16BIT 0
149 #define SMC_CAN_USE_32BIT 0
150 #define SMC_NOWAIT 1
152 /* The first two address lines aren't connected... */
153 #define SMC_IO_SHIFT 2
155 #define SMC_inb(a, r) readb((a) + (r))
156 #define SMC_outb(v, a, r) writeb(v, (a) + (r))
157 #define SMC_insb(a, r, p, l) readsb((a) + (r), p, (l))
158 #define SMC_outsb(a, r, p, l) writesb((a) + (r), p, (l))
159 #define SMC_IRQ_FLAGS (-1) /* from resource */
161 #elif defined(CONFIG_MACH_LOGICPD_PXA270) || \
162 defined(CONFIG_MACH_NOMADIK_8815NHK)
164 #define SMC_CAN_USE_8BIT 0
165 #define SMC_CAN_USE_16BIT 1
166 #define SMC_CAN_USE_32BIT 0
167 #define SMC_IO_SHIFT 0
168 #define SMC_NOWAIT 1
170 #define SMC_inw(a, r) readw((a) + (r))
171 #define SMC_outw(v, a, r) writew(v, (a) + (r))
172 #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
173 #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
175 #elif defined(CONFIG_ARCH_INNOKOM) || \
176 defined(CONFIG_ARCH_PXA_IDP) || \
177 defined(CONFIG_ARCH_RAMSES) || \
178 defined(CONFIG_ARCH_PCM027)
180 #define SMC_CAN_USE_8BIT 1
181 #define SMC_CAN_USE_16BIT 1
182 #define SMC_CAN_USE_32BIT 1
183 #define SMC_IO_SHIFT 0
184 #define SMC_NOWAIT 1
185 #define SMC_USE_PXA_DMA 1
187 #define SMC_inb(a, r) readb((a) + (r))
188 #define SMC_inw(a, r) readw((a) + (r))
189 #define SMC_inl(a, r) readl((a) + (r))
190 #define SMC_outb(v, a, r) writeb(v, (a) + (r))
191 #define SMC_outl(v, a, r) writel(v, (a) + (r))
192 #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
193 #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
194 #define SMC_IRQ_FLAGS (-1) /* from resource */
196 /* We actually can't write halfwords properly if not word aligned */
197 static inline void
198 SMC_outw(u16 val, void __iomem *ioaddr, int reg)
200 if (reg & 2) {
201 unsigned int v = val << 16;
202 v |= readl(ioaddr + (reg & ~2)) & 0xffff;
203 writel(v, ioaddr + (reg & ~2));
204 } else {
205 writew(val, ioaddr + reg);
209 #elif defined(CONFIG_SH_SH4202_MICRODEV)
211 #define SMC_CAN_USE_8BIT 0
212 #define SMC_CAN_USE_16BIT 1
213 #define SMC_CAN_USE_32BIT 0
215 #define SMC_inb(a, r) inb((a) + (r) - 0xa0000000)
216 #define SMC_inw(a, r) inw((a) + (r) - 0xa0000000)
217 #define SMC_inl(a, r) inl((a) + (r) - 0xa0000000)
218 #define SMC_outb(v, a, r) outb(v, (a) + (r) - 0xa0000000)
219 #define SMC_outw(v, a, r) outw(v, (a) + (r) - 0xa0000000)
220 #define SMC_outl(v, a, r) outl(v, (a) + (r) - 0xa0000000)
221 #define SMC_insl(a, r, p, l) insl((a) + (r) - 0xa0000000, p, l)
222 #define SMC_outsl(a, r, p, l) outsl((a) + (r) - 0xa0000000, p, l)
223 #define SMC_insw(a, r, p, l) insw((a) + (r) - 0xa0000000, p, l)
224 #define SMC_outsw(a, r, p, l) outsw((a) + (r) - 0xa0000000, p, l)
226 #define SMC_IRQ_FLAGS (0)
228 #elif defined(CONFIG_M32R)
230 #define SMC_CAN_USE_8BIT 0
231 #define SMC_CAN_USE_16BIT 1
232 #define SMC_CAN_USE_32BIT 0
234 #define SMC_inb(a, r) inb(((u32)a) + (r))
235 #define SMC_inw(a, r) inw(((u32)a) + (r))
236 #define SMC_outb(v, a, r) outb(v, ((u32)a) + (r))
237 #define SMC_outw(v, a, r) outw(v, ((u32)a) + (r))
238 #define SMC_insw(a, r, p, l) insw(((u32)a) + (r), p, l)
239 #define SMC_outsw(a, r, p, l) outsw(((u32)a) + (r), p, l)
241 #define SMC_IRQ_FLAGS (0)
243 #define RPC_LSA_DEFAULT RPC_LED_TX_RX
244 #define RPC_LSB_DEFAULT RPC_LED_100_10
246 #elif defined(CONFIG_MACH_LPD79520) || \
247 defined(CONFIG_MACH_LPD7A400) || \
248 defined(CONFIG_MACH_LPD7A404)
250 /* The LPD7X_IOBARRIER is necessary to overcome a mismatch between the
251 * way that the CPU handles chip selects and the way that the SMC chip
252 * expects the chip select to operate. Refer to
253 * Documentation/arm/Sharp-LH/IOBarrier for details. The read from
254 * IOBARRIER is a byte, in order that we read the least-common
255 * denominator. It would be wasteful to read 32 bits from an 8-bit
256 * accessible region.
258 * There is no explicit protection against interrupts intervening
259 * between the writew and the IOBARRIER. In SMC ISR there is a
260 * preamble that performs an IOBARRIER in the extremely unlikely event
261 * that the driver interrupts itself between a writew to the chip an
262 * the IOBARRIER that follows *and* the cache is large enough that the
263 * first off-chip access while handing the interrupt is to the SMC
264 * chip. Other devices in the same address space as the SMC chip must
265 * be aware of the potential for trouble and perform a similar
266 * IOBARRIER on entry to their ISR.
269 #include <mach/constants.h> /* IOBARRIER_VIRT */
271 #define SMC_CAN_USE_8BIT 0
272 #define SMC_CAN_USE_16BIT 1
273 #define SMC_CAN_USE_32BIT 0
274 #define SMC_NOWAIT 0
275 #define LPD7X_IOBARRIER readb (IOBARRIER_VIRT)
277 #define SMC_inw(a,r)\
278 ({ unsigned short v = readw ((void*) ((a) + (r))); LPD7X_IOBARRIER; v; })
279 #define SMC_outw(v,a,r) ({ writew ((v), (a) + (r)); LPD7X_IOBARRIER; })
281 #define SMC_insw LPD7_SMC_insw
282 static inline void LPD7_SMC_insw (unsigned char* a, int r,
283 unsigned char* p, int l)
285 unsigned short* ps = (unsigned short*) p;
286 while (l-- > 0) {
287 *ps++ = readw (a + r);
288 LPD7X_IOBARRIER;
292 #define SMC_outsw LPD7_SMC_outsw
293 static inline void LPD7_SMC_outsw (unsigned char* a, int r,
294 unsigned char* p, int l)
296 unsigned short* ps = (unsigned short*) p;
297 while (l-- > 0) {
298 writew (*ps++, a + r);
299 LPD7X_IOBARRIER;
303 #define SMC_INTERRUPT_PREAMBLE LPD7X_IOBARRIER
305 #define RPC_LSA_DEFAULT RPC_LED_TX_RX
306 #define RPC_LSB_DEFAULT RPC_LED_100_10
308 #elif defined(CONFIG_ARCH_VERSATILE)
310 #define SMC_CAN_USE_8BIT 1
311 #define SMC_CAN_USE_16BIT 1
312 #define SMC_CAN_USE_32BIT 1
313 #define SMC_NOWAIT 1
315 #define SMC_inb(a, r) readb((a) + (r))
316 #define SMC_inw(a, r) readw((a) + (r))
317 #define SMC_inl(a, r) readl((a) + (r))
318 #define SMC_outb(v, a, r) writeb(v, (a) + (r))
319 #define SMC_outw(v, a, r) writew(v, (a) + (r))
320 #define SMC_outl(v, a, r) writel(v, (a) + (r))
321 #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
322 #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
323 #define SMC_IRQ_FLAGS (-1) /* from resource */
325 #elif defined(CONFIG_MN10300)
328 * MN10300/AM33 configuration
331 #include <unit/smc91111.h>
333 #elif defined(CONFIG_ARCH_MSM)
335 #define SMC_CAN_USE_8BIT 0
336 #define SMC_CAN_USE_16BIT 1
337 #define SMC_CAN_USE_32BIT 0
338 #define SMC_NOWAIT 1
340 #define SMC_inw(a, r) readw((a) + (r))
341 #define SMC_outw(v, a, r) writew(v, (a) + (r))
342 #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
343 #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
345 #define SMC_IRQ_FLAGS IRQF_TRIGGER_HIGH
347 #else
350 * Default configuration
353 #define SMC_CAN_USE_8BIT 1
354 #define SMC_CAN_USE_16BIT 1
355 #define SMC_CAN_USE_32BIT 1
356 #define SMC_NOWAIT 1
358 #define SMC_IO_SHIFT (lp->io_shift)
360 #define SMC_inb(a, r) readb((a) + (r))
361 #define SMC_inw(a, r) readw((a) + (r))
362 #define SMC_inl(a, r) readl((a) + (r))
363 #define SMC_outb(v, a, r) writeb(v, (a) + (r))
364 #define SMC_outw(v, a, r) writew(v, (a) + (r))
365 #define SMC_outl(v, a, r) writel(v, (a) + (r))
366 #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
367 #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
368 #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
369 #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
371 #define RPC_LSA_DEFAULT RPC_LED_100_10
372 #define RPC_LSB_DEFAULT RPC_LED_TX_RX
374 #endif
377 /* store this information for the driver.. */
378 struct smc_local {
380 * If I have to wait until memory is available to send a
381 * packet, I will store the skbuff here, until I get the
382 * desired memory. Then, I'll send it out and free it.
384 struct sk_buff *pending_tx_skb;
385 struct tasklet_struct tx_task;
387 /* version/revision of the SMC91x chip */
388 int version;
390 /* Contains the current active transmission mode */
391 int tcr_cur_mode;
393 /* Contains the current active receive mode */
394 int rcr_cur_mode;
396 /* Contains the current active receive/phy mode */
397 int rpc_cur_mode;
398 int ctl_rfduplx;
399 int ctl_rspeed;
401 u32 msg_enable;
402 u32 phy_type;
403 struct mii_if_info mii;
405 /* work queue */
406 struct work_struct phy_configure;
407 struct net_device *dev;
408 int work_pending;
410 spinlock_t lock;
412 #ifdef CONFIG_ARCH_PXA
413 /* DMA needs the physical address of the chip */
414 u_long physaddr;
415 struct device *device;
416 #endif
417 void __iomem *base;
418 void __iomem *datacs;
420 /* the low address lines on some platforms aren't connected... */
421 int io_shift;
423 struct smc91x_platdata cfg;
426 #define SMC_8BIT(p) ((p)->cfg.flags & SMC91X_USE_8BIT)
427 #define SMC_16BIT(p) ((p)->cfg.flags & SMC91X_USE_16BIT)
428 #define SMC_32BIT(p) ((p)->cfg.flags & SMC91X_USE_32BIT)
430 #ifdef CONFIG_ARCH_PXA
432 * Let's use the DMA engine on the XScale PXA2xx for RX packets. This is
433 * always happening in irq context so no need to worry about races. TX is
434 * different and probably not worth it for that reason, and not as critical
435 * as RX which can overrun memory and lose packets.
437 #include <linux/dma-mapping.h>
438 #include <mach/dma.h>
440 #ifdef SMC_insl
441 #undef SMC_insl
442 #define SMC_insl(a, r, p, l) \
443 smc_pxa_dma_insl(a, lp, r, dev->dma, p, l)
444 static inline void
445 smc_pxa_dma_insl(void __iomem *ioaddr, struct smc_local *lp, int reg, int dma,
446 u_char *buf, int len)
448 u_long physaddr = lp->physaddr;
449 dma_addr_t dmabuf;
451 /* fallback if no DMA available */
452 if (dma == (unsigned char)-1) {
453 readsl(ioaddr + reg, buf, len);
454 return;
457 /* 64 bit alignment is required for memory to memory DMA */
458 if ((long)buf & 4) {
459 *((u32 *)buf) = SMC_inl(ioaddr, reg);
460 buf += 4;
461 len--;
464 len *= 4;
465 dmabuf = dma_map_single(lp->device, buf, len, DMA_FROM_DEVICE);
466 DCSR(dma) = DCSR_NODESC;
467 DTADR(dma) = dmabuf;
468 DSADR(dma) = physaddr + reg;
469 DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
470 DCMD_WIDTH4 | (DCMD_LENGTH & len));
471 DCSR(dma) = DCSR_NODESC | DCSR_RUN;
472 while (!(DCSR(dma) & DCSR_STOPSTATE))
473 cpu_relax();
474 DCSR(dma) = 0;
475 dma_unmap_single(lp->device, dmabuf, len, DMA_FROM_DEVICE);
477 #endif
479 #ifdef SMC_insw
480 #undef SMC_insw
481 #define SMC_insw(a, r, p, l) \
482 smc_pxa_dma_insw(a, lp, r, dev->dma, p, l)
483 static inline void
484 smc_pxa_dma_insw(void __iomem *ioaddr, struct smc_local *lp, int reg, int dma,
485 u_char *buf, int len)
487 u_long physaddr = lp->physaddr;
488 dma_addr_t dmabuf;
490 /* fallback if no DMA available */
491 if (dma == (unsigned char)-1) {
492 readsw(ioaddr + reg, buf, len);
493 return;
496 /* 64 bit alignment is required for memory to memory DMA */
497 while ((long)buf & 6) {
498 *((u16 *)buf) = SMC_inw(ioaddr, reg);
499 buf += 2;
500 len--;
503 len *= 2;
504 dmabuf = dma_map_single(lp->device, buf, len, DMA_FROM_DEVICE);
505 DCSR(dma) = DCSR_NODESC;
506 DTADR(dma) = dmabuf;
507 DSADR(dma) = physaddr + reg;
508 DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
509 DCMD_WIDTH2 | (DCMD_LENGTH & len));
510 DCSR(dma) = DCSR_NODESC | DCSR_RUN;
511 while (!(DCSR(dma) & DCSR_STOPSTATE))
512 cpu_relax();
513 DCSR(dma) = 0;
514 dma_unmap_single(lp->device, dmabuf, len, DMA_FROM_DEVICE);
516 #endif
518 static void
519 smc_pxa_dma_irq(int dma, void *dummy)
521 DCSR(dma) = 0;
523 #endif /* CONFIG_ARCH_PXA */
527 * Everything a particular hardware setup needs should have been defined
528 * at this point. Add stubs for the undefined cases, mainly to avoid
529 * compilation warnings since they'll be optimized away, or to prevent buggy
530 * use of them.
533 #if ! SMC_CAN_USE_32BIT
534 #define SMC_inl(ioaddr, reg) ({ BUG(); 0; })
535 #define SMC_outl(x, ioaddr, reg) BUG()
536 #define SMC_insl(a, r, p, l) BUG()
537 #define SMC_outsl(a, r, p, l) BUG()
538 #endif
540 #if !defined(SMC_insl) || !defined(SMC_outsl)
541 #define SMC_insl(a, r, p, l) BUG()
542 #define SMC_outsl(a, r, p, l) BUG()
543 #endif
545 #if ! SMC_CAN_USE_16BIT
548 * Any 16-bit access is performed with two 8-bit accesses if the hardware
549 * can't do it directly. Most registers are 16-bit so those are mandatory.
551 #define SMC_outw(x, ioaddr, reg) \
552 do { \
553 unsigned int __val16 = (x); \
554 SMC_outb( __val16, ioaddr, reg ); \
555 SMC_outb( __val16 >> 8, ioaddr, reg + (1 << SMC_IO_SHIFT));\
556 } while (0)
557 #define SMC_inw(ioaddr, reg) \
558 ({ \
559 unsigned int __val16; \
560 __val16 = SMC_inb( ioaddr, reg ); \
561 __val16 |= SMC_inb( ioaddr, reg + (1 << SMC_IO_SHIFT)) << 8; \
562 __val16; \
565 #define SMC_insw(a, r, p, l) BUG()
566 #define SMC_outsw(a, r, p, l) BUG()
568 #endif
570 #if !defined(SMC_insw) || !defined(SMC_outsw)
571 #define SMC_insw(a, r, p, l) BUG()
572 #define SMC_outsw(a, r, p, l) BUG()
573 #endif
575 #if ! SMC_CAN_USE_8BIT
576 #define SMC_inb(ioaddr, reg) ({ BUG(); 0; })
577 #define SMC_outb(x, ioaddr, reg) BUG()
578 #define SMC_insb(a, r, p, l) BUG()
579 #define SMC_outsb(a, r, p, l) BUG()
580 #endif
582 #if !defined(SMC_insb) || !defined(SMC_outsb)
583 #define SMC_insb(a, r, p, l) BUG()
584 #define SMC_outsb(a, r, p, l) BUG()
585 #endif
587 #ifndef SMC_CAN_USE_DATACS
588 #define SMC_CAN_USE_DATACS 0
589 #endif
591 #ifndef SMC_IO_SHIFT
592 #define SMC_IO_SHIFT 0
593 #endif
595 #ifndef SMC_IRQ_FLAGS
596 #define SMC_IRQ_FLAGS IRQF_TRIGGER_RISING
597 #endif
599 #ifndef SMC_INTERRUPT_PREAMBLE
600 #define SMC_INTERRUPT_PREAMBLE
601 #endif
604 /* Because of bank switching, the LAN91x uses only 16 I/O ports */
605 #define SMC_IO_EXTENT (16 << SMC_IO_SHIFT)
606 #define SMC_DATA_EXTENT (4)
609 . Bank Select Register:
611 . yyyy yyyy 0000 00xx
612 . xx = bank number
613 . yyyy yyyy = 0x33, for identification purposes.
615 #define BANK_SELECT (14 << SMC_IO_SHIFT)
618 // Transmit Control Register
619 /* BANK 0 */
620 #define TCR_REG(lp) SMC_REG(lp, 0x0000, 0)
621 #define TCR_ENABLE 0x0001 // When 1 we can transmit
622 #define TCR_LOOP 0x0002 // Controls output pin LBK
623 #define TCR_FORCOL 0x0004 // When 1 will force a collision
624 #define TCR_PAD_EN 0x0080 // When 1 will pad tx frames < 64 bytes w/0
625 #define TCR_NOCRC 0x0100 // When 1 will not append CRC to tx frames
626 #define TCR_MON_CSN 0x0400 // When 1 tx monitors carrier
627 #define TCR_FDUPLX 0x0800 // When 1 enables full duplex operation
628 #define TCR_STP_SQET 0x1000 // When 1 stops tx if Signal Quality Error
629 #define TCR_EPH_LOOP 0x2000 // When 1 enables EPH block loopback
630 #define TCR_SWFDUP 0x8000 // When 1 enables Switched Full Duplex mode
632 #define TCR_CLEAR 0 /* do NOTHING */
633 /* the default settings for the TCR register : */
634 #define TCR_DEFAULT (TCR_ENABLE | TCR_PAD_EN)
637 // EPH Status Register
638 /* BANK 0 */
639 #define EPH_STATUS_REG(lp) SMC_REG(lp, 0x0002, 0)
640 #define ES_TX_SUC 0x0001 // Last TX was successful
641 #define ES_SNGL_COL 0x0002 // Single collision detected for last tx
642 #define ES_MUL_COL 0x0004 // Multiple collisions detected for last tx
643 #define ES_LTX_MULT 0x0008 // Last tx was a multicast
644 #define ES_16COL 0x0010 // 16 Collisions Reached
645 #define ES_SQET 0x0020 // Signal Quality Error Test
646 #define ES_LTXBRD 0x0040 // Last tx was a broadcast
647 #define ES_TXDEFR 0x0080 // Transmit Deferred
648 #define ES_LATCOL 0x0200 // Late collision detected on last tx
649 #define ES_LOSTCARR 0x0400 // Lost Carrier Sense
650 #define ES_EXC_DEF 0x0800 // Excessive Deferral
651 #define ES_CTR_ROL 0x1000 // Counter Roll Over indication
652 #define ES_LINK_OK 0x4000 // Driven by inverted value of nLNK pin
653 #define ES_TXUNRN 0x8000 // Tx Underrun
656 // Receive Control Register
657 /* BANK 0 */
658 #define RCR_REG(lp) SMC_REG(lp, 0x0004, 0)
659 #define RCR_RX_ABORT 0x0001 // Set if a rx frame was aborted
660 #define RCR_PRMS 0x0002 // Enable promiscuous mode
661 #define RCR_ALMUL 0x0004 // When set accepts all multicast frames
662 #define RCR_RXEN 0x0100 // IFF this is set, we can receive packets
663 #define RCR_STRIP_CRC 0x0200 // When set strips CRC from rx packets
664 #define RCR_ABORT_ENB 0x0200 // When set will abort rx on collision
665 #define RCR_FILT_CAR 0x0400 // When set filters leading 12 bit s of carrier
666 #define RCR_SOFTRST 0x8000 // resets the chip
668 /* the normal settings for the RCR register : */
669 #define RCR_DEFAULT (RCR_STRIP_CRC | RCR_RXEN)
670 #define RCR_CLEAR 0x0 // set it to a base state
673 // Counter Register
674 /* BANK 0 */
675 #define COUNTER_REG(lp) SMC_REG(lp, 0x0006, 0)
678 // Memory Information Register
679 /* BANK 0 */
680 #define MIR_REG(lp) SMC_REG(lp, 0x0008, 0)
683 // Receive/Phy Control Register
684 /* BANK 0 */
685 #define RPC_REG(lp) SMC_REG(lp, 0x000A, 0)
686 #define RPC_SPEED 0x2000 // When 1 PHY is in 100Mbps mode.
687 #define RPC_DPLX 0x1000 // When 1 PHY is in Full-Duplex Mode
688 #define RPC_ANEG 0x0800 // When 1 PHY is in Auto-Negotiate Mode
689 #define RPC_LSXA_SHFT 5 // Bits to shift LS2A,LS1A,LS0A to lsb
690 #define RPC_LSXB_SHFT 2 // Bits to get LS2B,LS1B,LS0B to lsb
692 #ifndef RPC_LSA_DEFAULT
693 #define RPC_LSA_DEFAULT RPC_LED_100
694 #endif
695 #ifndef RPC_LSB_DEFAULT
696 #define RPC_LSB_DEFAULT RPC_LED_FD
697 #endif
699 #define RPC_DEFAULT (RPC_ANEG | RPC_SPEED | RPC_DPLX)
702 /* Bank 0 0x0C is reserved */
704 // Bank Select Register
705 /* All Banks */
706 #define BSR_REG 0x000E
709 // Configuration Reg
710 /* BANK 1 */
711 #define CONFIG_REG(lp) SMC_REG(lp, 0x0000, 1)
712 #define CONFIG_EXT_PHY 0x0200 // 1=external MII, 0=internal Phy
713 #define CONFIG_GPCNTRL 0x0400 // Inverse value drives pin nCNTRL
714 #define CONFIG_NO_WAIT 0x1000 // When 1 no extra wait states on ISA bus
715 #define CONFIG_EPH_POWER_EN 0x8000 // When 0 EPH is placed into low power mode.
717 // Default is powered-up, Internal Phy, Wait States, and pin nCNTRL=low
718 #define CONFIG_DEFAULT (CONFIG_EPH_POWER_EN)
721 // Base Address Register
722 /* BANK 1 */
723 #define BASE_REG(lp) SMC_REG(lp, 0x0002, 1)
726 // Individual Address Registers
727 /* BANK 1 */
728 #define ADDR0_REG(lp) SMC_REG(lp, 0x0004, 1)
729 #define ADDR1_REG(lp) SMC_REG(lp, 0x0006, 1)
730 #define ADDR2_REG(lp) SMC_REG(lp, 0x0008, 1)
733 // General Purpose Register
734 /* BANK 1 */
735 #define GP_REG(lp) SMC_REG(lp, 0x000A, 1)
738 // Control Register
739 /* BANK 1 */
740 #define CTL_REG(lp) SMC_REG(lp, 0x000C, 1)
741 #define CTL_RCV_BAD 0x4000 // When 1 bad CRC packets are received
742 #define CTL_AUTO_RELEASE 0x0800 // When 1 tx pages are released automatically
743 #define CTL_LE_ENABLE 0x0080 // When 1 enables Link Error interrupt
744 #define CTL_CR_ENABLE 0x0040 // When 1 enables Counter Rollover interrupt
745 #define CTL_TE_ENABLE 0x0020 // When 1 enables Transmit Error interrupt
746 #define CTL_EEPROM_SELECT 0x0004 // Controls EEPROM reload & store
747 #define CTL_RELOAD 0x0002 // When set reads EEPROM into registers
748 #define CTL_STORE 0x0001 // When set stores registers into EEPROM
751 // MMU Command Register
752 /* BANK 2 */
753 #define MMU_CMD_REG(lp) SMC_REG(lp, 0x0000, 2)
754 #define MC_BUSY 1 // When 1 the last release has not completed
755 #define MC_NOP (0<<5) // No Op
756 #define MC_ALLOC (1<<5) // OR with number of 256 byte packets
757 #define MC_RESET (2<<5) // Reset MMU to initial state
758 #define MC_REMOVE (3<<5) // Remove the current rx packet
759 #define MC_RELEASE (4<<5) // Remove and release the current rx packet
760 #define MC_FREEPKT (5<<5) // Release packet in PNR register
761 #define MC_ENQUEUE (6<<5) // Enqueue the packet for transmit
762 #define MC_RSTTXFIFO (7<<5) // Reset the TX FIFOs
765 // Packet Number Register
766 /* BANK 2 */
767 #define PN_REG(lp) SMC_REG(lp, 0x0002, 2)
770 // Allocation Result Register
771 /* BANK 2 */
772 #define AR_REG(lp) SMC_REG(lp, 0x0003, 2)
773 #define AR_FAILED 0x80 // Alocation Failed
776 // TX FIFO Ports Register
777 /* BANK 2 */
778 #define TXFIFO_REG(lp) SMC_REG(lp, 0x0004, 2)
779 #define TXFIFO_TEMPTY 0x80 // TX FIFO Empty
781 // RX FIFO Ports Register
782 /* BANK 2 */
783 #define RXFIFO_REG(lp) SMC_REG(lp, 0x0005, 2)
784 #define RXFIFO_REMPTY 0x80 // RX FIFO Empty
786 #define FIFO_REG(lp) SMC_REG(lp, 0x0004, 2)
788 // Pointer Register
789 /* BANK 2 */
790 #define PTR_REG(lp) SMC_REG(lp, 0x0006, 2)
791 #define PTR_RCV 0x8000 // 1=Receive area, 0=Transmit area
792 #define PTR_AUTOINC 0x4000 // Auto increment the pointer on each access
793 #define PTR_READ 0x2000 // When 1 the operation is a read
796 // Data Register
797 /* BANK 2 */
798 #define DATA_REG(lp) SMC_REG(lp, 0x0008, 2)
801 // Interrupt Status/Acknowledge Register
802 /* BANK 2 */
803 #define INT_REG(lp) SMC_REG(lp, 0x000C, 2)
806 // Interrupt Mask Register
807 /* BANK 2 */
808 #define IM_REG(lp) SMC_REG(lp, 0x000D, 2)
809 #define IM_MDINT 0x80 // PHY MI Register 18 Interrupt
810 #define IM_ERCV_INT 0x40 // Early Receive Interrupt
811 #define IM_EPH_INT 0x20 // Set by Ethernet Protocol Handler section
812 #define IM_RX_OVRN_INT 0x10 // Set by Receiver Overruns
813 #define IM_ALLOC_INT 0x08 // Set when allocation request is completed
814 #define IM_TX_EMPTY_INT 0x04 // Set if the TX FIFO goes empty
815 #define IM_TX_INT 0x02 // Transmit Interrupt
816 #define IM_RCV_INT 0x01 // Receive Interrupt
819 // Multicast Table Registers
820 /* BANK 3 */
821 #define MCAST_REG1(lp) SMC_REG(lp, 0x0000, 3)
822 #define MCAST_REG2(lp) SMC_REG(lp, 0x0002, 3)
823 #define MCAST_REG3(lp) SMC_REG(lp, 0x0004, 3)
824 #define MCAST_REG4(lp) SMC_REG(lp, 0x0006, 3)
827 // Management Interface Register (MII)
828 /* BANK 3 */
829 #define MII_REG(lp) SMC_REG(lp, 0x0008, 3)
830 #define MII_MSK_CRS100 0x4000 // Disables CRS100 detection during tx half dup
831 #define MII_MDOE 0x0008 // MII Output Enable
832 #define MII_MCLK 0x0004 // MII Clock, pin MDCLK
833 #define MII_MDI 0x0002 // MII Input, pin MDI
834 #define MII_MDO 0x0001 // MII Output, pin MDO
837 // Revision Register
838 /* BANK 3 */
839 /* ( hi: chip id low: rev # ) */
840 #define REV_REG(lp) SMC_REG(lp, 0x000A, 3)
843 // Early RCV Register
844 /* BANK 3 */
845 /* this is NOT on SMC9192 */
846 #define ERCV_REG(lp) SMC_REG(lp, 0x000C, 3)
847 #define ERCV_RCV_DISCRD 0x0080 // When 1 discards a packet being received
848 #define ERCV_THRESHOLD 0x001F // ERCV Threshold Mask
851 // External Register
852 /* BANK 7 */
853 #define EXT_REG(lp) SMC_REG(lp, 0x0000, 7)
856 #define CHIP_9192 3
857 #define CHIP_9194 4
858 #define CHIP_9195 5
859 #define CHIP_9196 6
860 #define CHIP_91100 7
861 #define CHIP_91100FD 8
862 #define CHIP_91111FD 9
864 static const char * chip_ids[ 16 ] = {
865 NULL, NULL, NULL,
866 /* 3 */ "SMC91C90/91C92",
867 /* 4 */ "SMC91C94",
868 /* 5 */ "SMC91C95",
869 /* 6 */ "SMC91C96",
870 /* 7 */ "SMC91C100",
871 /* 8 */ "SMC91C100FD",
872 /* 9 */ "SMC91C11xFD",
873 NULL, NULL, NULL,
874 NULL, NULL, NULL};
878 . Receive status bits
880 #define RS_ALGNERR 0x8000
881 #define RS_BRODCAST 0x4000
882 #define RS_BADCRC 0x2000
883 #define RS_ODDFRAME 0x1000
884 #define RS_TOOLONG 0x0800
885 #define RS_TOOSHORT 0x0400
886 #define RS_MULTICAST 0x0001
887 #define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
891 * PHY IDs
892 * LAN83C183 == LAN91C111 Internal PHY
894 #define PHY_LAN83C183 0x0016f840
895 #define PHY_LAN83C180 0x02821c50
898 * PHY Register Addresses (LAN91C111 Internal PHY)
900 * Generic PHY registers can be found in <linux/mii.h>
902 * These phy registers are specific to our on-board phy.
905 // PHY Configuration Register 1
906 #define PHY_CFG1_REG 0x10
907 #define PHY_CFG1_LNKDIS 0x8000 // 1=Rx Link Detect Function disabled
908 #define PHY_CFG1_XMTDIS 0x4000 // 1=TP Transmitter Disabled
909 #define PHY_CFG1_XMTPDN 0x2000 // 1=TP Transmitter Powered Down
910 #define PHY_CFG1_BYPSCR 0x0400 // 1=Bypass scrambler/descrambler
911 #define PHY_CFG1_UNSCDS 0x0200 // 1=Unscramble Idle Reception Disable
912 #define PHY_CFG1_EQLZR 0x0100 // 1=Rx Equalizer Disabled
913 #define PHY_CFG1_CABLE 0x0080 // 1=STP(150ohm), 0=UTP(100ohm)
914 #define PHY_CFG1_RLVL0 0x0040 // 1=Rx Squelch level reduced by 4.5db
915 #define PHY_CFG1_TLVL_SHIFT 2 // Transmit Output Level Adjust
916 #define PHY_CFG1_TLVL_MASK 0x003C
917 #define PHY_CFG1_TRF_MASK 0x0003 // Transmitter Rise/Fall time
920 // PHY Configuration Register 2
921 #define PHY_CFG2_REG 0x11
922 #define PHY_CFG2_APOLDIS 0x0020 // 1=Auto Polarity Correction disabled
923 #define PHY_CFG2_JABDIS 0x0010 // 1=Jabber disabled
924 #define PHY_CFG2_MREG 0x0008 // 1=Multiple register access (MII mgt)
925 #define PHY_CFG2_INTMDIO 0x0004 // 1=Interrupt signaled with MDIO pulseo
927 // PHY Status Output (and Interrupt status) Register
928 #define PHY_INT_REG 0x12 // Status Output (Interrupt Status)
929 #define PHY_INT_INT 0x8000 // 1=bits have changed since last read
930 #define PHY_INT_LNKFAIL 0x4000 // 1=Link Not detected
931 #define PHY_INT_LOSSSYNC 0x2000 // 1=Descrambler has lost sync
932 #define PHY_INT_CWRD 0x1000 // 1=Invalid 4B5B code detected on rx
933 #define PHY_INT_SSD 0x0800 // 1=No Start Of Stream detected on rx
934 #define PHY_INT_ESD 0x0400 // 1=No End Of Stream detected on rx
935 #define PHY_INT_RPOL 0x0200 // 1=Reverse Polarity detected
936 #define PHY_INT_JAB 0x0100 // 1=Jabber detected
937 #define PHY_INT_SPDDET 0x0080 // 1=100Base-TX mode, 0=10Base-T mode
938 #define PHY_INT_DPLXDET 0x0040 // 1=Device in Full Duplex
940 // PHY Interrupt/Status Mask Register
941 #define PHY_MASK_REG 0x13 // Interrupt Mask
942 // Uses the same bit definitions as PHY_INT_REG
946 * SMC91C96 ethernet config and status registers.
947 * These are in the "attribute" space.
949 #define ECOR 0x8000
950 #define ECOR_RESET 0x80
951 #define ECOR_LEVEL_IRQ 0x40
952 #define ECOR_WR_ATTRIB 0x04
953 #define ECOR_ENABLE 0x01
955 #define ECSR 0x8002
956 #define ECSR_IOIS8 0x20
957 #define ECSR_PWRDWN 0x04
958 #define ECSR_INT 0x02
960 #define ATTRIB_SIZE ((64*1024) << SMC_IO_SHIFT)
964 * Macros to abstract register access according to the data bus
965 * capabilities. Please use those and not the in/out primitives.
966 * Note: the following macros do *not* select the bank -- this must
967 * be done separately as needed in the main code. The SMC_REG() macro
968 * only uses the bank argument for debugging purposes (when enabled).
970 * Note: despite inline functions being safer, everything leading to this
971 * should preferably be macros to let BUG() display the line number in
972 * the core source code since we're interested in the top call site
973 * not in any inline function location.
976 #if SMC_DEBUG > 0
977 #define SMC_REG(lp, reg, bank) \
978 ({ \
979 int __b = SMC_CURRENT_BANK(lp); \
980 if (unlikely((__b & ~0xf0) != (0x3300 | bank))) { \
981 printk( "%s: bank reg screwed (0x%04x)\n", \
982 CARDNAME, __b ); \
983 BUG(); \
985 reg<<SMC_IO_SHIFT; \
987 #else
988 #define SMC_REG(lp, reg, bank) (reg<<SMC_IO_SHIFT)
989 #endif
992 * Hack Alert: Some setups just can't write 8 or 16 bits reliably when not
993 * aligned to a 32 bit boundary. I tell you that does exist!
994 * Fortunately the affected register accesses can be easily worked around
995 * since we can write zeroes to the preceeding 16 bits without adverse
996 * effects and use a 32-bit access.
998 * Enforce it on any 32-bit capable setup for now.
1000 #define SMC_MUST_ALIGN_WRITE(lp) SMC_32BIT(lp)
1002 #define SMC_GET_PN(lp) \
1003 (SMC_8BIT(lp) ? (SMC_inb(ioaddr, PN_REG(lp))) \
1004 : (SMC_inw(ioaddr, PN_REG(lp)) & 0xFF))
1006 #define SMC_SET_PN(lp, x) \
1007 do { \
1008 if (SMC_MUST_ALIGN_WRITE(lp)) \
1009 SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 0, 2)); \
1010 else if (SMC_8BIT(lp)) \
1011 SMC_outb(x, ioaddr, PN_REG(lp)); \
1012 else \
1013 SMC_outw(x, ioaddr, PN_REG(lp)); \
1014 } while (0)
1016 #define SMC_GET_AR(lp) \
1017 (SMC_8BIT(lp) ? (SMC_inb(ioaddr, AR_REG(lp))) \
1018 : (SMC_inw(ioaddr, PN_REG(lp)) >> 8))
1020 #define SMC_GET_TXFIFO(lp) \
1021 (SMC_8BIT(lp) ? (SMC_inb(ioaddr, TXFIFO_REG(lp))) \
1022 : (SMC_inw(ioaddr, TXFIFO_REG(lp)) & 0xFF))
1024 #define SMC_GET_RXFIFO(lp) \
1025 (SMC_8BIT(lp) ? (SMC_inb(ioaddr, RXFIFO_REG(lp))) \
1026 : (SMC_inw(ioaddr, TXFIFO_REG(lp)) >> 8))
1028 #define SMC_GET_INT(lp) \
1029 (SMC_8BIT(lp) ? (SMC_inb(ioaddr, INT_REG(lp))) \
1030 : (SMC_inw(ioaddr, INT_REG(lp)) & 0xFF))
1032 #define SMC_ACK_INT(lp, x) \
1033 do { \
1034 if (SMC_8BIT(lp)) \
1035 SMC_outb(x, ioaddr, INT_REG(lp)); \
1036 else { \
1037 unsigned long __flags; \
1038 int __mask; \
1039 local_irq_save(__flags); \
1040 __mask = SMC_inw(ioaddr, INT_REG(lp)) & ~0xff; \
1041 SMC_outw(__mask | (x), ioaddr, INT_REG(lp)); \
1042 local_irq_restore(__flags); \
1044 } while (0)
1046 #define SMC_GET_INT_MASK(lp) \
1047 (SMC_8BIT(lp) ? (SMC_inb(ioaddr, IM_REG(lp))) \
1048 : (SMC_inw(ioaddr, INT_REG(lp)) >> 8))
1050 #define SMC_SET_INT_MASK(lp, x) \
1051 do { \
1052 if (SMC_8BIT(lp)) \
1053 SMC_outb(x, ioaddr, IM_REG(lp)); \
1054 else \
1055 SMC_outw((x) << 8, ioaddr, INT_REG(lp)); \
1056 } while (0)
1058 #define SMC_CURRENT_BANK(lp) SMC_inw(ioaddr, BANK_SELECT)
1060 #define SMC_SELECT_BANK(lp, x) \
1061 do { \
1062 if (SMC_MUST_ALIGN_WRITE(lp)) \
1063 SMC_outl((x)<<16, ioaddr, 12<<SMC_IO_SHIFT); \
1064 else \
1065 SMC_outw(x, ioaddr, BANK_SELECT); \
1066 } while (0)
1068 #define SMC_GET_BASE(lp) SMC_inw(ioaddr, BASE_REG(lp))
1070 #define SMC_SET_BASE(lp, x) SMC_outw(x, ioaddr, BASE_REG(lp))
1072 #define SMC_GET_CONFIG(lp) SMC_inw(ioaddr, CONFIG_REG(lp))
1074 #define SMC_SET_CONFIG(lp, x) SMC_outw(x, ioaddr, CONFIG_REG(lp))
1076 #define SMC_GET_COUNTER(lp) SMC_inw(ioaddr, COUNTER_REG(lp))
1078 #define SMC_GET_CTL(lp) SMC_inw(ioaddr, CTL_REG(lp))
1080 #define SMC_SET_CTL(lp, x) SMC_outw(x, ioaddr, CTL_REG(lp))
1082 #define SMC_GET_MII(lp) SMC_inw(ioaddr, MII_REG(lp))
1084 #define SMC_GET_GP(lp) SMC_inw(ioaddr, GP_REG(lp))
1086 #define SMC_SET_GP(lp, x) \
1087 do { \
1088 if (SMC_MUST_ALIGN_WRITE(lp)) \
1089 SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 8, 1)); \
1090 else \
1091 SMC_outw(x, ioaddr, GP_REG(lp)); \
1092 } while (0)
1094 #define SMC_SET_MII(lp, x) SMC_outw(x, ioaddr, MII_REG(lp))
1096 #define SMC_GET_MIR(lp) SMC_inw(ioaddr, MIR_REG(lp))
1098 #define SMC_SET_MIR(lp, x) SMC_outw(x, ioaddr, MIR_REG(lp))
1100 #define SMC_GET_MMU_CMD(lp) SMC_inw(ioaddr, MMU_CMD_REG(lp))
1102 #define SMC_SET_MMU_CMD(lp, x) SMC_outw(x, ioaddr, MMU_CMD_REG(lp))
1104 #define SMC_GET_FIFO(lp) SMC_inw(ioaddr, FIFO_REG(lp))
1106 #define SMC_GET_PTR(lp) SMC_inw(ioaddr, PTR_REG(lp))
1108 #define SMC_SET_PTR(lp, x) \
1109 do { \
1110 if (SMC_MUST_ALIGN_WRITE(lp)) \
1111 SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 4, 2)); \
1112 else \
1113 SMC_outw(x, ioaddr, PTR_REG(lp)); \
1114 } while (0)
1116 #define SMC_GET_EPH_STATUS(lp) SMC_inw(ioaddr, EPH_STATUS_REG(lp))
1118 #define SMC_GET_RCR(lp) SMC_inw(ioaddr, RCR_REG(lp))
1120 #define SMC_SET_RCR(lp, x) SMC_outw(x, ioaddr, RCR_REG(lp))
1122 #define SMC_GET_REV(lp) SMC_inw(ioaddr, REV_REG(lp))
1124 #define SMC_GET_RPC(lp) SMC_inw(ioaddr, RPC_REG(lp))
1126 #define SMC_SET_RPC(lp, x) \
1127 do { \
1128 if (SMC_MUST_ALIGN_WRITE(lp)) \
1129 SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 8, 0)); \
1130 else \
1131 SMC_outw(x, ioaddr, RPC_REG(lp)); \
1132 } while (0)
1134 #define SMC_GET_TCR(lp) SMC_inw(ioaddr, TCR_REG(lp))
1136 #define SMC_SET_TCR(lp, x) SMC_outw(x, ioaddr, TCR_REG(lp))
1138 #ifndef SMC_GET_MAC_ADDR
1139 #define SMC_GET_MAC_ADDR(lp, addr) \
1140 do { \
1141 unsigned int __v; \
1142 __v = SMC_inw(ioaddr, ADDR0_REG(lp)); \
1143 addr[0] = __v; addr[1] = __v >> 8; \
1144 __v = SMC_inw(ioaddr, ADDR1_REG(lp)); \
1145 addr[2] = __v; addr[3] = __v >> 8; \
1146 __v = SMC_inw(ioaddr, ADDR2_REG(lp)); \
1147 addr[4] = __v; addr[5] = __v >> 8; \
1148 } while (0)
1149 #endif
1151 #define SMC_SET_MAC_ADDR(lp, addr) \
1152 do { \
1153 SMC_outw(addr[0]|(addr[1] << 8), ioaddr, ADDR0_REG(lp)); \
1154 SMC_outw(addr[2]|(addr[3] << 8), ioaddr, ADDR1_REG(lp)); \
1155 SMC_outw(addr[4]|(addr[5] << 8), ioaddr, ADDR2_REG(lp)); \
1156 } while (0)
1158 #define SMC_SET_MCAST(lp, x) \
1159 do { \
1160 const unsigned char *mt = (x); \
1161 SMC_outw(mt[0] | (mt[1] << 8), ioaddr, MCAST_REG1(lp)); \
1162 SMC_outw(mt[2] | (mt[3] << 8), ioaddr, MCAST_REG2(lp)); \
1163 SMC_outw(mt[4] | (mt[5] << 8), ioaddr, MCAST_REG3(lp)); \
1164 SMC_outw(mt[6] | (mt[7] << 8), ioaddr, MCAST_REG4(lp)); \
1165 } while (0)
1167 #define SMC_PUT_PKT_HDR(lp, status, length) \
1168 do { \
1169 if (SMC_32BIT(lp)) \
1170 SMC_outl((status) | (length)<<16, ioaddr, \
1171 DATA_REG(lp)); \
1172 else { \
1173 SMC_outw(status, ioaddr, DATA_REG(lp)); \
1174 SMC_outw(length, ioaddr, DATA_REG(lp)); \
1176 } while (0)
1178 #define SMC_GET_PKT_HDR(lp, status, length) \
1179 do { \
1180 if (SMC_32BIT(lp)) { \
1181 unsigned int __val = SMC_inl(ioaddr, DATA_REG(lp)); \
1182 (status) = __val & 0xffff; \
1183 (length) = __val >> 16; \
1184 } else { \
1185 (status) = SMC_inw(ioaddr, DATA_REG(lp)); \
1186 (length) = SMC_inw(ioaddr, DATA_REG(lp)); \
1188 } while (0)
1190 #define SMC_PUSH_DATA(lp, p, l) \
1191 do { \
1192 if (SMC_32BIT(lp)) { \
1193 void *__ptr = (p); \
1194 int __len = (l); \
1195 void __iomem *__ioaddr = ioaddr; \
1196 if (__len >= 2 && (unsigned long)__ptr & 2) { \
1197 __len -= 2; \
1198 SMC_outw(*(u16 *)__ptr, ioaddr, \
1199 DATA_REG(lp)); \
1200 __ptr += 2; \
1202 if (SMC_CAN_USE_DATACS && lp->datacs) \
1203 __ioaddr = lp->datacs; \
1204 SMC_outsl(__ioaddr, DATA_REG(lp), __ptr, __len>>2); \
1205 if (__len & 2) { \
1206 __ptr += (__len & ~3); \
1207 SMC_outw(*((u16 *)__ptr), ioaddr, \
1208 DATA_REG(lp)); \
1210 } else if (SMC_16BIT(lp)) \
1211 SMC_outsw(ioaddr, DATA_REG(lp), p, (l) >> 1); \
1212 else if (SMC_8BIT(lp)) \
1213 SMC_outsb(ioaddr, DATA_REG(lp), p, l); \
1214 } while (0)
1216 #define SMC_PULL_DATA(lp, p, l) \
1217 do { \
1218 if (SMC_32BIT(lp)) { \
1219 void *__ptr = (p); \
1220 int __len = (l); \
1221 void __iomem *__ioaddr = ioaddr; \
1222 if ((unsigned long)__ptr & 2) { \
1223 /* \
1224 * We want 32bit alignment here. \
1225 * Since some buses perform a full \
1226 * 32bit fetch even for 16bit data \
1227 * we can't use SMC_inw() here. \
1228 * Back both source (on-chip) and \
1229 * destination pointers of 2 bytes. \
1230 * This is possible since the call to \
1231 * SMC_GET_PKT_HDR() already advanced \
1232 * the source pointer of 4 bytes, and \
1233 * the skb_reserve(skb, 2) advanced \
1234 * the destination pointer of 2 bytes. \
1235 */ \
1236 __ptr -= 2; \
1237 __len += 2; \
1238 SMC_SET_PTR(lp, \
1239 2|PTR_READ|PTR_RCV|PTR_AUTOINC); \
1241 if (SMC_CAN_USE_DATACS && lp->datacs) \
1242 __ioaddr = lp->datacs; \
1243 __len += 2; \
1244 SMC_insl(__ioaddr, DATA_REG(lp), __ptr, __len>>2); \
1245 } else if (SMC_16BIT(lp)) \
1246 SMC_insw(ioaddr, DATA_REG(lp), p, (l) >> 1); \
1247 else if (SMC_8BIT(lp)) \
1248 SMC_insb(ioaddr, DATA_REG(lp), p, l); \
1249 } while (0)
1251 #endif /* _SMC91X_H_ */