11ccea77eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2ae150435SJeff Kirsher /*------------------------------------------------------------------------
3ae150435SJeff Kirsher . smc91x.h - macros for SMSC's 91C9x/91C1xx single-chip Ethernet device.
4ae150435SJeff Kirsher .
5ae150435SJeff Kirsher . Copyright (C) 1996 by Erik Stahlman
6ae150435SJeff Kirsher . Copyright (C) 2001 Standard Microsystems Corporation
7ae150435SJeff Kirsher . Developed by Simple Network Magic Corporation
8ae150435SJeff Kirsher . Copyright (C) 2003 Monta Vista Software, Inc.
9ae150435SJeff Kirsher . Unified SMC91x driver by Nicolas Pitre
10ae150435SJeff Kirsher .
11ae150435SJeff Kirsher .
12ae150435SJeff Kirsher . Information contained in this file was obtained from the LAN91C111
13ae150435SJeff Kirsher . manual from SMC. To get a copy, if you really want one, you can find
14ae150435SJeff Kirsher . information under www.smsc.com.
15ae150435SJeff Kirsher .
16ae150435SJeff Kirsher . Authors
17ae150435SJeff Kirsher . Erik Stahlman <erik@vt.edu>
18ae150435SJeff Kirsher . Daris A Nevil <dnevil@snmc.com>
19ae150435SJeff Kirsher . Nicolas Pitre <nico@fluxnic.net>
20ae150435SJeff Kirsher .
21ae150435SJeff Kirsher ---------------------------------------------------------------------------*/
22ae150435SJeff Kirsher #ifndef _SMC91X_H_
23ae150435SJeff Kirsher #define _SMC91X_H_
24ae150435SJeff Kirsher
25d24c8f24SRobert Jarzmik #include <linux/dmaengine.h>
26ae150435SJeff Kirsher #include <linux/smc91x.h>
27ae150435SJeff Kirsher
28ae150435SJeff Kirsher /*
292fb04fdfSRussell King * Any 16-bit access is performed with two 8-bit accesses if the hardware
302fb04fdfSRussell King * can't do it directly. Most registers are 16-bit so those are mandatory.
312fb04fdfSRussell King */
322fb04fdfSRussell King #define SMC_outw_b(x, a, r) \
332fb04fdfSRussell King do { \
342fb04fdfSRussell King unsigned int __val16 = (x); \
352fb04fdfSRussell King unsigned int __reg = (r); \
362fb04fdfSRussell King SMC_outb(__val16, a, __reg); \
372fb04fdfSRussell King SMC_outb(__val16 >> 8, a, __reg + (1 << SMC_IO_SHIFT)); \
382fb04fdfSRussell King } while (0)
392fb04fdfSRussell King
402fb04fdfSRussell King #define SMC_inw_b(a, r) \
412fb04fdfSRussell King ({ \
422fb04fdfSRussell King unsigned int __val16; \
432fb04fdfSRussell King unsigned int __reg = r; \
442fb04fdfSRussell King __val16 = SMC_inb(a, __reg); \
452fb04fdfSRussell King __val16 |= SMC_inb(a, __reg + (1 << SMC_IO_SHIFT)) << 8; \
462fb04fdfSRussell King __val16; \
472fb04fdfSRussell King })
482fb04fdfSRussell King
492fb04fdfSRussell King /*
50ae150435SJeff Kirsher * Define your architecture specific bus configuration parameters here.
51ae150435SJeff Kirsher */
52ae150435SJeff Kirsher
53b70661c7SArnd Bergmann #if defined(CONFIG_ARM)
54ae150435SJeff Kirsher
5525c07e2cSRobert Jarzmik #include <asm/mach-types.h>
5625c07e2cSRobert Jarzmik
57ae150435SJeff Kirsher /* Now the bus width is specified in the platform data
58ae150435SJeff Kirsher * pretend here to support all I/O access types
59ae150435SJeff Kirsher */
60ae150435SJeff Kirsher #define SMC_CAN_USE_8BIT 1
61ae150435SJeff Kirsher #define SMC_CAN_USE_16BIT 1
62ae150435SJeff Kirsher #define SMC_CAN_USE_32BIT 1
63ae150435SJeff Kirsher #define SMC_NOWAIT 1
64ae150435SJeff Kirsher
65ae150435SJeff Kirsher #define SMC_IO_SHIFT (lp->io_shift)
66ae150435SJeff Kirsher
67ae150435SJeff Kirsher #define SMC_inb(a, r) readb((a) + (r))
682fb04fdfSRussell King #define SMC_inw(a, r) \
692fb04fdfSRussell King ({ \
702fb04fdfSRussell King unsigned int __smc_r = r; \
712fb04fdfSRussell King SMC_16BIT(lp) ? readw((a) + __smc_r) : \
722fb04fdfSRussell King SMC_8BIT(lp) ? SMC_inw_b(a, __smc_r) : \
732fb04fdfSRussell King ({ BUG(); 0; }); \
742fb04fdfSRussell King })
752fb04fdfSRussell King
76ae150435SJeff Kirsher #define SMC_inl(a, r) readl((a) + (r))
77ae150435SJeff Kirsher #define SMC_outb(v, a, r) writeb(v, (a) + (r))
78d09d747aSRobert Jarzmik #define SMC_outw(lp, v, a, r) \
792fb04fdfSRussell King do { \
802fb04fdfSRussell King unsigned int __v = v, __smc_r = r; \
812fb04fdfSRussell King if (SMC_16BIT(lp)) \
82d09d747aSRobert Jarzmik __SMC_outw(lp, __v, a, __smc_r); \
832fb04fdfSRussell King else if (SMC_8BIT(lp)) \
842fb04fdfSRussell King SMC_outw_b(__v, a, __smc_r); \
852fb04fdfSRussell King else \
862fb04fdfSRussell King BUG(); \
872fb04fdfSRussell King } while (0)
882fb04fdfSRussell King
89ae150435SJeff Kirsher #define SMC_outl(v, a, r) writel(v, (a) + (r))
902fb04fdfSRussell King #define SMC_insb(a, r, p, l) readsb((a) + (r), p, l)
912fb04fdfSRussell King #define SMC_outsb(a, r, p, l) writesb((a) + (r), p, l)
92ae150435SJeff Kirsher #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
93ae150435SJeff Kirsher #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
94ae150435SJeff Kirsher #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
95ae150435SJeff Kirsher #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
96ae150435SJeff Kirsher #define SMC_IRQ_FLAGS (-1) /* from resource */
97ae150435SJeff Kirsher
98ae150435SJeff Kirsher /* We actually can't write halfwords properly if not word aligned */
_SMC_outw_align4(u16 val,void __iomem * ioaddr,int reg,bool use_align4_workaround)99d09d747aSRobert Jarzmik static inline void _SMC_outw_align4(u16 val, void __iomem *ioaddr, int reg,
100d09d747aSRobert Jarzmik bool use_align4_workaround)
101ae150435SJeff Kirsher {
102d09d747aSRobert Jarzmik if (use_align4_workaround) {
103ae150435SJeff Kirsher unsigned int v = val << 16;
104ae150435SJeff Kirsher v |= readl(ioaddr + (reg & ~2)) & 0xffff;
105ae150435SJeff Kirsher writel(v, ioaddr + (reg & ~2));
106ae150435SJeff Kirsher } else {
107ae150435SJeff Kirsher writew(val, ioaddr + reg);
108ae150435SJeff Kirsher }
109ae150435SJeff Kirsher }
110ae150435SJeff Kirsher
111d09d747aSRobert Jarzmik #define __SMC_outw(lp, v, a, r) \
112d09d747aSRobert Jarzmik _SMC_outw_align4((v), (a), (r), \
113d09d747aSRobert Jarzmik IS_BUILTIN(CONFIG_ARCH_PXA) && ((r) & 2) && \
114d09d747aSRobert Jarzmik (lp)->cfg.pxa_u16_align4)
115d09d747aSRobert Jarzmik
116d09d747aSRobert Jarzmik
117ae150435SJeff Kirsher #elif defined(CONFIG_SH_SH4202_MICRODEV)
118ae150435SJeff Kirsher
119ae150435SJeff Kirsher #define SMC_CAN_USE_8BIT 0
120ae150435SJeff Kirsher #define SMC_CAN_USE_16BIT 1
121ae150435SJeff Kirsher #define SMC_CAN_USE_32BIT 0
122ae150435SJeff Kirsher
123ae150435SJeff Kirsher #define SMC_inb(a, r) inb((a) + (r) - 0xa0000000)
124ae150435SJeff Kirsher #define SMC_inw(a, r) inw((a) + (r) - 0xa0000000)
125ae150435SJeff Kirsher #define SMC_inl(a, r) inl((a) + (r) - 0xa0000000)
126ae150435SJeff Kirsher #define SMC_outb(v, a, r) outb(v, (a) + (r) - 0xa0000000)
127d09d747aSRobert Jarzmik #define SMC_outw(lp, v, a, r) outw(v, (a) + (r) - 0xa0000000)
128ae150435SJeff Kirsher #define SMC_outl(v, a, r) outl(v, (a) + (r) - 0xa0000000)
129ae150435SJeff Kirsher #define SMC_insl(a, r, p, l) insl((a) + (r) - 0xa0000000, p, l)
130ae150435SJeff Kirsher #define SMC_outsl(a, r, p, l) outsl((a) + (r) - 0xa0000000, p, l)
131ae150435SJeff Kirsher #define SMC_insw(a, r, p, l) insw((a) + (r) - 0xa0000000, p, l)
132ae150435SJeff Kirsher #define SMC_outsw(a, r, p, l) outsw((a) + (r) - 0xa0000000, p, l)
133ae150435SJeff Kirsher
134ae150435SJeff Kirsher #define SMC_IRQ_FLAGS (0)
135ae150435SJeff Kirsher
1366321b54aSMichael Schmitz #elif defined(CONFIG_ATARI)
1376321b54aSMichael Schmitz
1386321b54aSMichael Schmitz #define SMC_CAN_USE_8BIT 1
1396321b54aSMichael Schmitz #define SMC_CAN_USE_16BIT 1
1406321b54aSMichael Schmitz #define SMC_CAN_USE_32BIT 1
1416321b54aSMichael Schmitz #define SMC_NOWAIT 1
1426321b54aSMichael Schmitz
1436321b54aSMichael Schmitz #define SMC_inb(a, r) readb((a) + (r))
1446321b54aSMichael Schmitz #define SMC_inw(a, r) readw((a) + (r))
1456321b54aSMichael Schmitz #define SMC_inl(a, r) readl((a) + (r))
1466321b54aSMichael Schmitz #define SMC_outb(v, a, r) writeb(v, (a) + (r))
147d09d747aSRobert Jarzmik #define SMC_outw(lp, v, a, r) writew(v, (a) + (r))
1486321b54aSMichael Schmitz #define SMC_outl(v, a, r) writel(v, (a) + (r))
1496321b54aSMichael Schmitz #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
1506321b54aSMichael Schmitz #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
1516321b54aSMichael Schmitz #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
1526321b54aSMichael Schmitz #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
1536321b54aSMichael Schmitz
1546321b54aSMichael Schmitz #define RPC_LSA_DEFAULT RPC_LED_100_10
1556321b54aSMichael Schmitz #define RPC_LSB_DEFAULT RPC_LED_TX_RX
1566321b54aSMichael Schmitz
157ae150435SJeff Kirsher #elif defined(CONFIG_COLDFIRE)
158ae150435SJeff Kirsher
159ae150435SJeff Kirsher #define SMC_CAN_USE_8BIT 0
160ae150435SJeff Kirsher #define SMC_CAN_USE_16BIT 1
161ae150435SJeff Kirsher #define SMC_CAN_USE_32BIT 0
162ae150435SJeff Kirsher #define SMC_NOWAIT 1
163ae150435SJeff Kirsher
mcf_insw(void * a,unsigned char * p,int l)164ae150435SJeff Kirsher static inline void mcf_insw(void *a, unsigned char *p, int l)
165ae150435SJeff Kirsher {
166ae150435SJeff Kirsher u16 *wp = (u16 *) p;
167ae150435SJeff Kirsher while (l-- > 0)
168ae150435SJeff Kirsher *wp++ = readw(a);
169ae150435SJeff Kirsher }
170ae150435SJeff Kirsher
mcf_outsw(void * a,unsigned char * p,int l)171ae150435SJeff Kirsher static inline void mcf_outsw(void *a, unsigned char *p, int l)
172ae150435SJeff Kirsher {
173ae150435SJeff Kirsher u16 *wp = (u16 *) p;
174ae150435SJeff Kirsher while (l-- > 0)
175ae150435SJeff Kirsher writew(*wp++, a);
176ae150435SJeff Kirsher }
177ae150435SJeff Kirsher
178*d6598435SThorsten Blum #define SMC_inw(a, r) ioread16be((a) + (r))
179*d6598435SThorsten Blum #define SMC_outw(lp, v, a, r) iowrite16be(v, (a) + (r))
180ae150435SJeff Kirsher #define SMC_insw(a, r, p, l) mcf_insw(a + r, p, l)
181ae150435SJeff Kirsher #define SMC_outsw(a, r, p, l) mcf_outsw(a + r, p, l)
182ae150435SJeff Kirsher
183cf68ca1eSMichael Opdenacker #define SMC_IRQ_FLAGS 0
184ae150435SJeff Kirsher
185ae150435SJeff Kirsher #else
186ae150435SJeff Kirsher
187ae150435SJeff Kirsher /*
188ae150435SJeff Kirsher * Default configuration
189ae150435SJeff Kirsher */
190ae150435SJeff Kirsher
191ae150435SJeff Kirsher #define SMC_CAN_USE_8BIT 1
192ae150435SJeff Kirsher #define SMC_CAN_USE_16BIT 1
193ae150435SJeff Kirsher #define SMC_CAN_USE_32BIT 1
194ae150435SJeff Kirsher #define SMC_NOWAIT 1
195ae150435SJeff Kirsher
196ae150435SJeff Kirsher #define SMC_IO_SHIFT (lp->io_shift)
197ae150435SJeff Kirsher
1984ba73aa1SWill Deacon #define SMC_inb(a, r) ioread8((a) + (r))
1994ba73aa1SWill Deacon #define SMC_inw(a, r) ioread16((a) + (r))
2004ba73aa1SWill Deacon #define SMC_inl(a, r) ioread32((a) + (r))
2014ba73aa1SWill Deacon #define SMC_outb(v, a, r) iowrite8(v, (a) + (r))
202d09d747aSRobert Jarzmik #define SMC_outw(lp, v, a, r) iowrite16(v, (a) + (r))
2034ba73aa1SWill Deacon #define SMC_outl(v, a, r) iowrite32(v, (a) + (r))
2044ba73aa1SWill Deacon #define SMC_insw(a, r, p, l) ioread16_rep((a) + (r), p, l)
2054ba73aa1SWill Deacon #define SMC_outsw(a, r, p, l) iowrite16_rep((a) + (r), p, l)
2064ba73aa1SWill Deacon #define SMC_insl(a, r, p, l) ioread32_rep((a) + (r), p, l)
2074ba73aa1SWill Deacon #define SMC_outsl(a, r, p, l) iowrite32_rep((a) + (r), p, l)
208ae150435SJeff Kirsher
209ae150435SJeff Kirsher #define RPC_LSA_DEFAULT RPC_LED_100_10
210ae150435SJeff Kirsher #define RPC_LSB_DEFAULT RPC_LED_TX_RX
211ae150435SJeff Kirsher
212ae150435SJeff Kirsher #endif
213ae150435SJeff Kirsher
214ae150435SJeff Kirsher
215ae150435SJeff Kirsher /* store this information for the driver.. */
216ae150435SJeff Kirsher struct smc_local {
217ae150435SJeff Kirsher /*
218ae150435SJeff Kirsher * If I have to wait until memory is available to send a
219ae150435SJeff Kirsher * packet, I will store the skbuff here, until I get the
220ae150435SJeff Kirsher * desired memory. Then, I'll send it out and free it.
221ae150435SJeff Kirsher */
222ae150435SJeff Kirsher struct sk_buff *pending_tx_skb;
223ae150435SJeff Kirsher struct tasklet_struct tx_task;
224ae150435SJeff Kirsher
2257d2911c4STony Lindgren struct gpio_desc *power_gpio;
2267d2911c4STony Lindgren struct gpio_desc *reset_gpio;
2277d2911c4STony Lindgren
228ae150435SJeff Kirsher /* version/revision of the SMC91x chip */
229ae150435SJeff Kirsher int version;
230ae150435SJeff Kirsher
231ae150435SJeff Kirsher /* Contains the current active transmission mode */
232ae150435SJeff Kirsher int tcr_cur_mode;
233ae150435SJeff Kirsher
234ae150435SJeff Kirsher /* Contains the current active receive mode */
235ae150435SJeff Kirsher int rcr_cur_mode;
236ae150435SJeff Kirsher
237ae150435SJeff Kirsher /* Contains the current active receive/phy mode */
238ae150435SJeff Kirsher int rpc_cur_mode;
239ae150435SJeff Kirsher int ctl_rfduplx;
240ae150435SJeff Kirsher int ctl_rspeed;
241ae150435SJeff Kirsher
242ae150435SJeff Kirsher u32 msg_enable;
243ae150435SJeff Kirsher u32 phy_type;
244ae150435SJeff Kirsher struct mii_if_info mii;
245ae150435SJeff Kirsher
246ae150435SJeff Kirsher /* work queue */
247ae150435SJeff Kirsher struct work_struct phy_configure;
248ae150435SJeff Kirsher struct net_device *dev;
249ae150435SJeff Kirsher int work_pending;
250ae150435SJeff Kirsher
251ae150435SJeff Kirsher spinlock_t lock;
252ae150435SJeff Kirsher
253ae150435SJeff Kirsher #ifdef CONFIG_ARCH_PXA
254ae150435SJeff Kirsher /* DMA needs the physical address of the chip */
255ae150435SJeff Kirsher u_long physaddr;
256ae150435SJeff Kirsher struct device *device;
257ae150435SJeff Kirsher #endif
258d24c8f24SRobert Jarzmik struct dma_chan *dma_chan;
259ae150435SJeff Kirsher void __iomem *base;
260ae150435SJeff Kirsher void __iomem *datacs;
261ae150435SJeff Kirsher
262ae150435SJeff Kirsher /* the low address lines on some platforms aren't connected... */
263ae150435SJeff Kirsher int io_shift;
264d09d747aSRobert Jarzmik /* on some platforms a u16 write must be 4-bytes aligned */
265d09d747aSRobert Jarzmik bool half_word_align4;
266ae150435SJeff Kirsher
267ae150435SJeff Kirsher struct smc91x_platdata cfg;
268ae150435SJeff Kirsher };
269ae150435SJeff Kirsher
270ae150435SJeff Kirsher #define SMC_8BIT(p) ((p)->cfg.flags & SMC91X_USE_8BIT)
271ae150435SJeff Kirsher #define SMC_16BIT(p) ((p)->cfg.flags & SMC91X_USE_16BIT)
272ae150435SJeff Kirsher #define SMC_32BIT(p) ((p)->cfg.flags & SMC91X_USE_32BIT)
273ae150435SJeff Kirsher
274ae150435SJeff Kirsher #ifdef CONFIG_ARCH_PXA
275ae150435SJeff Kirsher /*
276ae150435SJeff Kirsher * Let's use the DMA engine on the XScale PXA2xx for RX packets. This is
277ae150435SJeff Kirsher * always happening in irq context so no need to worry about races. TX is
278ae150435SJeff Kirsher * different and probably not worth it for that reason, and not as critical
279ae150435SJeff Kirsher * as RX which can overrun memory and lose packets.
280ae150435SJeff Kirsher */
281ae150435SJeff Kirsher #include <linux/dma-mapping.h>
282ae150435SJeff Kirsher
283ae150435SJeff Kirsher #ifdef SMC_insl
284ae150435SJeff Kirsher #undef SMC_insl
285ae150435SJeff Kirsher #define SMC_insl(a, r, p, l) \
286ae150435SJeff Kirsher smc_pxa_dma_insl(a, lp, r, dev->dma, p, l)
287ae150435SJeff Kirsher static inline void
smc_pxa_dma_inpump(struct smc_local * lp,u_char * buf,int len)288d24c8f24SRobert Jarzmik smc_pxa_dma_inpump(struct smc_local *lp, u_char *buf, int len)
289d24c8f24SRobert Jarzmik {
290d24c8f24SRobert Jarzmik dma_addr_t dmabuf;
291d24c8f24SRobert Jarzmik struct dma_async_tx_descriptor *tx;
292d24c8f24SRobert Jarzmik dma_cookie_t cookie;
293d24c8f24SRobert Jarzmik enum dma_status status;
294d24c8f24SRobert Jarzmik struct dma_tx_state state;
295d24c8f24SRobert Jarzmik
296d24c8f24SRobert Jarzmik dmabuf = dma_map_single(lp->device, buf, len, DMA_FROM_DEVICE);
297d24c8f24SRobert Jarzmik tx = dmaengine_prep_slave_single(lp->dma_chan, dmabuf, len,
298d24c8f24SRobert Jarzmik DMA_DEV_TO_MEM, 0);
299d24c8f24SRobert Jarzmik if (tx) {
300d24c8f24SRobert Jarzmik cookie = dmaengine_submit(tx);
301d24c8f24SRobert Jarzmik dma_async_issue_pending(lp->dma_chan);
302d24c8f24SRobert Jarzmik do {
303d24c8f24SRobert Jarzmik status = dmaengine_tx_status(lp->dma_chan, cookie,
304d24c8f24SRobert Jarzmik &state);
305d24c8f24SRobert Jarzmik cpu_relax();
306d24c8f24SRobert Jarzmik } while (status != DMA_COMPLETE && status != DMA_ERROR &&
307d24c8f24SRobert Jarzmik state.residue);
308d24c8f24SRobert Jarzmik dmaengine_terminate_all(lp->dma_chan);
309d24c8f24SRobert Jarzmik }
310d24c8f24SRobert Jarzmik dma_unmap_single(lp->device, dmabuf, len, DMA_FROM_DEVICE);
311d24c8f24SRobert Jarzmik }
312d24c8f24SRobert Jarzmik
313d24c8f24SRobert Jarzmik static inline void
smc_pxa_dma_insl(void __iomem * ioaddr,struct smc_local * lp,int reg,int dma,u_char * buf,int len)314ae150435SJeff Kirsher smc_pxa_dma_insl(void __iomem *ioaddr, struct smc_local *lp, int reg, int dma,
315ae150435SJeff Kirsher u_char *buf, int len)
316ae150435SJeff Kirsher {
317d24c8f24SRobert Jarzmik struct dma_slave_config config;
318d24c8f24SRobert Jarzmik int ret;
319ae150435SJeff Kirsher
320ae150435SJeff Kirsher /* fallback if no DMA available */
321d24c8f24SRobert Jarzmik if (!lp->dma_chan) {
322ae150435SJeff Kirsher readsl(ioaddr + reg, buf, len);
323ae150435SJeff Kirsher return;
324ae150435SJeff Kirsher }
325ae150435SJeff Kirsher
326ae150435SJeff Kirsher /* 64 bit alignment is required for memory to memory DMA */
327ae150435SJeff Kirsher if ((long)buf & 4) {
328ae150435SJeff Kirsher *((u32 *)buf) = SMC_inl(ioaddr, reg);
329ae150435SJeff Kirsher buf += 4;
330ae150435SJeff Kirsher len--;
331ae150435SJeff Kirsher }
332ae150435SJeff Kirsher
333d24c8f24SRobert Jarzmik memset(&config, 0, sizeof(config));
334d24c8f24SRobert Jarzmik config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
335d24c8f24SRobert Jarzmik config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
336d24c8f24SRobert Jarzmik config.src_addr = lp->physaddr + reg;
337d24c8f24SRobert Jarzmik config.dst_addr = lp->physaddr + reg;
338d24c8f24SRobert Jarzmik config.src_maxburst = 32;
339d24c8f24SRobert Jarzmik config.dst_maxburst = 32;
340d24c8f24SRobert Jarzmik ret = dmaengine_slave_config(lp->dma_chan, &config);
341d24c8f24SRobert Jarzmik if (ret) {
342d24c8f24SRobert Jarzmik dev_err(lp->device, "dma channel configuration failed: %d\n",
343d24c8f24SRobert Jarzmik ret);
344d24c8f24SRobert Jarzmik return;
345d24c8f24SRobert Jarzmik }
346d24c8f24SRobert Jarzmik
347ae150435SJeff Kirsher len *= 4;
348d24c8f24SRobert Jarzmik smc_pxa_dma_inpump(lp, buf, len);
349ae150435SJeff Kirsher }
350ae150435SJeff Kirsher #endif
351ae150435SJeff Kirsher
352ae150435SJeff Kirsher #ifdef SMC_insw
353ae150435SJeff Kirsher #undef SMC_insw
354ae150435SJeff Kirsher #define SMC_insw(a, r, p, l) \
355ae150435SJeff Kirsher smc_pxa_dma_insw(a, lp, r, dev->dma, p, l)
356ae150435SJeff Kirsher static inline void
smc_pxa_dma_insw(void __iomem * ioaddr,struct smc_local * lp,int reg,int dma,u_char * buf,int len)357ae150435SJeff Kirsher smc_pxa_dma_insw(void __iomem *ioaddr, struct smc_local *lp, int reg, int dma,
358ae150435SJeff Kirsher u_char *buf, int len)
359ae150435SJeff Kirsher {
360d24c8f24SRobert Jarzmik struct dma_slave_config config;
361d24c8f24SRobert Jarzmik int ret;
362ae150435SJeff Kirsher
363ae150435SJeff Kirsher /* fallback if no DMA available */
364d24c8f24SRobert Jarzmik if (!lp->dma_chan) {
365ae150435SJeff Kirsher readsw(ioaddr + reg, buf, len);
366ae150435SJeff Kirsher return;
367ae150435SJeff Kirsher }
368ae150435SJeff Kirsher
369ae150435SJeff Kirsher /* 64 bit alignment is required for memory to memory DMA */
370ae150435SJeff Kirsher while ((long)buf & 6) {
371ae150435SJeff Kirsher *((u16 *)buf) = SMC_inw(ioaddr, reg);
372ae150435SJeff Kirsher buf += 2;
373ae150435SJeff Kirsher len--;
374ae150435SJeff Kirsher }
375ae150435SJeff Kirsher
376d24c8f24SRobert Jarzmik memset(&config, 0, sizeof(config));
377d24c8f24SRobert Jarzmik config.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
378d24c8f24SRobert Jarzmik config.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
379d24c8f24SRobert Jarzmik config.src_addr = lp->physaddr + reg;
380d24c8f24SRobert Jarzmik config.dst_addr = lp->physaddr + reg;
381d24c8f24SRobert Jarzmik config.src_maxburst = 32;
382d24c8f24SRobert Jarzmik config.dst_maxburst = 32;
383d24c8f24SRobert Jarzmik ret = dmaengine_slave_config(lp->dma_chan, &config);
384d24c8f24SRobert Jarzmik if (ret) {
385d24c8f24SRobert Jarzmik dev_err(lp->device, "dma channel configuration failed: %d\n",
386d24c8f24SRobert Jarzmik ret);
387d24c8f24SRobert Jarzmik return;
388d24c8f24SRobert Jarzmik }
389d24c8f24SRobert Jarzmik
390ae150435SJeff Kirsher len *= 2;
391d24c8f24SRobert Jarzmik smc_pxa_dma_inpump(lp, buf, len);
392ae150435SJeff Kirsher }
393ae150435SJeff Kirsher #endif
394ae150435SJeff Kirsher
395ae150435SJeff Kirsher #endif /* CONFIG_ARCH_PXA */
396ae150435SJeff Kirsher
397ae150435SJeff Kirsher
398ae150435SJeff Kirsher /*
399ae150435SJeff Kirsher * Everything a particular hardware setup needs should have been defined
400ae150435SJeff Kirsher * at this point. Add stubs for the undefined cases, mainly to avoid
401ae150435SJeff Kirsher * compilation warnings since they'll be optimized away, or to prevent buggy
402ae150435SJeff Kirsher * use of them.
403ae150435SJeff Kirsher */
404ae150435SJeff Kirsher
405ae150435SJeff Kirsher #if ! SMC_CAN_USE_32BIT
406ae150435SJeff Kirsher #define SMC_inl(ioaddr, reg) ({ BUG(); 0; })
407ae150435SJeff Kirsher #define SMC_outl(x, ioaddr, reg) BUG()
408ae150435SJeff Kirsher #define SMC_insl(a, r, p, l) BUG()
409ae150435SJeff Kirsher #define SMC_outsl(a, r, p, l) BUG()
410ae150435SJeff Kirsher #endif
411ae150435SJeff Kirsher
412ae150435SJeff Kirsher #if !defined(SMC_insl) || !defined(SMC_outsl)
413ae150435SJeff Kirsher #define SMC_insl(a, r, p, l) BUG()
414ae150435SJeff Kirsher #define SMC_outsl(a, r, p, l) BUG()
415ae150435SJeff Kirsher #endif
416ae150435SJeff Kirsher
417ae150435SJeff Kirsher #if ! SMC_CAN_USE_16BIT
418ae150435SJeff Kirsher
419d09d747aSRobert Jarzmik #define SMC_outw(lp, x, ioaddr, reg) SMC_outw_b(x, ioaddr, reg)
4202fb04fdfSRussell King #define SMC_inw(ioaddr, reg) SMC_inw_b(ioaddr, reg)
421ae150435SJeff Kirsher #define SMC_insw(a, r, p, l) BUG()
422ae150435SJeff Kirsher #define SMC_outsw(a, r, p, l) BUG()
423ae150435SJeff Kirsher
424ae150435SJeff Kirsher #endif
425ae150435SJeff Kirsher
426ae150435SJeff Kirsher #if !defined(SMC_insw) || !defined(SMC_outsw)
427ae150435SJeff Kirsher #define SMC_insw(a, r, p, l) BUG()
428ae150435SJeff Kirsher #define SMC_outsw(a, r, p, l) BUG()
429ae150435SJeff Kirsher #endif
430ae150435SJeff Kirsher
431ae150435SJeff Kirsher #if ! SMC_CAN_USE_8BIT
432daa7ee8dSSudip Mukherjee #undef SMC_inb
433ae150435SJeff Kirsher #define SMC_inb(ioaddr, reg) ({ BUG(); 0; })
434daa7ee8dSSudip Mukherjee #undef SMC_outb
435ae150435SJeff Kirsher #define SMC_outb(x, ioaddr, reg) BUG()
436ae150435SJeff Kirsher #define SMC_insb(a, r, p, l) BUG()
437ae150435SJeff Kirsher #define SMC_outsb(a, r, p, l) BUG()
438ae150435SJeff Kirsher #endif
439ae150435SJeff Kirsher
440ae150435SJeff Kirsher #if !defined(SMC_insb) || !defined(SMC_outsb)
441ae150435SJeff Kirsher #define SMC_insb(a, r, p, l) BUG()
442ae150435SJeff Kirsher #define SMC_outsb(a, r, p, l) BUG()
443ae150435SJeff Kirsher #endif
444ae150435SJeff Kirsher
445ae150435SJeff Kirsher #ifndef SMC_CAN_USE_DATACS
446ae150435SJeff Kirsher #define SMC_CAN_USE_DATACS 0
447ae150435SJeff Kirsher #endif
448ae150435SJeff Kirsher
449ae150435SJeff Kirsher #ifndef SMC_IO_SHIFT
450ae150435SJeff Kirsher #define SMC_IO_SHIFT 0
451ae150435SJeff Kirsher #endif
452ae150435SJeff Kirsher
453ae150435SJeff Kirsher #ifndef SMC_IRQ_FLAGS
454ae150435SJeff Kirsher #define SMC_IRQ_FLAGS IRQF_TRIGGER_RISING
455ae150435SJeff Kirsher #endif
456ae150435SJeff Kirsher
457ae150435SJeff Kirsher #ifndef SMC_INTERRUPT_PREAMBLE
458ae150435SJeff Kirsher #define SMC_INTERRUPT_PREAMBLE
459ae150435SJeff Kirsher #endif
460ae150435SJeff Kirsher
461ae150435SJeff Kirsher
462ae150435SJeff Kirsher /* Because of bank switching, the LAN91x uses only 16 I/O ports */
463ae150435SJeff Kirsher #define SMC_IO_EXTENT (16 << SMC_IO_SHIFT)
464ae150435SJeff Kirsher #define SMC_DATA_EXTENT (4)
465ae150435SJeff Kirsher
466ae150435SJeff Kirsher /*
467ae150435SJeff Kirsher . Bank Select Register:
468ae150435SJeff Kirsher .
469ae150435SJeff Kirsher . yyyy yyyy 0000 00xx
470ae150435SJeff Kirsher . xx = bank number
471ae150435SJeff Kirsher . yyyy yyyy = 0x33, for identification purposes.
472ae150435SJeff Kirsher */
473ae150435SJeff Kirsher #define BANK_SELECT (14 << SMC_IO_SHIFT)
474ae150435SJeff Kirsher
475ae150435SJeff Kirsher
476ae150435SJeff Kirsher // Transmit Control Register
477ae150435SJeff Kirsher /* BANK 0 */
478ae150435SJeff Kirsher #define TCR_REG(lp) SMC_REG(lp, 0x0000, 0)
479ae150435SJeff Kirsher #define TCR_ENABLE 0x0001 // When 1 we can transmit
480ae150435SJeff Kirsher #define TCR_LOOP 0x0002 // Controls output pin LBK
481ae150435SJeff Kirsher #define TCR_FORCOL 0x0004 // When 1 will force a collision
482ae150435SJeff Kirsher #define TCR_PAD_EN 0x0080 // When 1 will pad tx frames < 64 bytes w/0
483ae150435SJeff Kirsher #define TCR_NOCRC 0x0100 // When 1 will not append CRC to tx frames
484ae150435SJeff Kirsher #define TCR_MON_CSN 0x0400 // When 1 tx monitors carrier
485ae150435SJeff Kirsher #define TCR_FDUPLX 0x0800 // When 1 enables full duplex operation
486ae150435SJeff Kirsher #define TCR_STP_SQET 0x1000 // When 1 stops tx if Signal Quality Error
487ae150435SJeff Kirsher #define TCR_EPH_LOOP 0x2000 // When 1 enables EPH block loopback
488ae150435SJeff Kirsher #define TCR_SWFDUP 0x8000 // When 1 enables Switched Full Duplex mode
489ae150435SJeff Kirsher
490ae150435SJeff Kirsher #define TCR_CLEAR 0 /* do NOTHING */
491ae150435SJeff Kirsher /* the default settings for the TCR register : */
492ae150435SJeff Kirsher #define TCR_DEFAULT (TCR_ENABLE | TCR_PAD_EN)
493ae150435SJeff Kirsher
494ae150435SJeff Kirsher
495ae150435SJeff Kirsher // EPH Status Register
496ae150435SJeff Kirsher /* BANK 0 */
497ae150435SJeff Kirsher #define EPH_STATUS_REG(lp) SMC_REG(lp, 0x0002, 0)
498ae150435SJeff Kirsher #define ES_TX_SUC 0x0001 // Last TX was successful
499ae150435SJeff Kirsher #define ES_SNGL_COL 0x0002 // Single collision detected for last tx
500ae150435SJeff Kirsher #define ES_MUL_COL 0x0004 // Multiple collisions detected for last tx
501ae150435SJeff Kirsher #define ES_LTX_MULT 0x0008 // Last tx was a multicast
502ae150435SJeff Kirsher #define ES_16COL 0x0010 // 16 Collisions Reached
503ae150435SJeff Kirsher #define ES_SQET 0x0020 // Signal Quality Error Test
504ae150435SJeff Kirsher #define ES_LTXBRD 0x0040 // Last tx was a broadcast
505ae150435SJeff Kirsher #define ES_TXDEFR 0x0080 // Transmit Deferred
506ae150435SJeff Kirsher #define ES_LATCOL 0x0200 // Late collision detected on last tx
507ae150435SJeff Kirsher #define ES_LOSTCARR 0x0400 // Lost Carrier Sense
508ae150435SJeff Kirsher #define ES_EXC_DEF 0x0800 // Excessive Deferral
509ae150435SJeff Kirsher #define ES_CTR_ROL 0x1000 // Counter Roll Over indication
510ae150435SJeff Kirsher #define ES_LINK_OK 0x4000 // Driven by inverted value of nLNK pin
511ae150435SJeff Kirsher #define ES_TXUNRN 0x8000 // Tx Underrun
512ae150435SJeff Kirsher
513ae150435SJeff Kirsher
514ae150435SJeff Kirsher // Receive Control Register
515ae150435SJeff Kirsher /* BANK 0 */
516ae150435SJeff Kirsher #define RCR_REG(lp) SMC_REG(lp, 0x0004, 0)
517ae150435SJeff Kirsher #define RCR_RX_ABORT 0x0001 // Set if a rx frame was aborted
518ae150435SJeff Kirsher #define RCR_PRMS 0x0002 // Enable promiscuous mode
519ae150435SJeff Kirsher #define RCR_ALMUL 0x0004 // When set accepts all multicast frames
520ae150435SJeff Kirsher #define RCR_RXEN 0x0100 // IFF this is set, we can receive packets
521ae150435SJeff Kirsher #define RCR_STRIP_CRC 0x0200 // When set strips CRC from rx packets
522ae150435SJeff Kirsher #define RCR_ABORT_ENB 0x0200 // When set will abort rx on collision
523ae150435SJeff Kirsher #define RCR_FILT_CAR 0x0400 // When set filters leading 12 bit s of carrier
524ae150435SJeff Kirsher #define RCR_SOFTRST 0x8000 // resets the chip
525ae150435SJeff Kirsher
526ae150435SJeff Kirsher /* the normal settings for the RCR register : */
527ae150435SJeff Kirsher #define RCR_DEFAULT (RCR_STRIP_CRC | RCR_RXEN)
528ae150435SJeff Kirsher #define RCR_CLEAR 0x0 // set it to a base state
529ae150435SJeff Kirsher
530ae150435SJeff Kirsher
531ae150435SJeff Kirsher // Counter Register
532ae150435SJeff Kirsher /* BANK 0 */
533ae150435SJeff Kirsher #define COUNTER_REG(lp) SMC_REG(lp, 0x0006, 0)
534ae150435SJeff Kirsher
535ae150435SJeff Kirsher
536ae150435SJeff Kirsher // Memory Information Register
537ae150435SJeff Kirsher /* BANK 0 */
538ae150435SJeff Kirsher #define MIR_REG(lp) SMC_REG(lp, 0x0008, 0)
539ae150435SJeff Kirsher
540ae150435SJeff Kirsher
541ae150435SJeff Kirsher // Receive/Phy Control Register
542ae150435SJeff Kirsher /* BANK 0 */
543ae150435SJeff Kirsher #define RPC_REG(lp) SMC_REG(lp, 0x000A, 0)
544ae150435SJeff Kirsher #define RPC_SPEED 0x2000 // When 1 PHY is in 100Mbps mode.
545ae150435SJeff Kirsher #define RPC_DPLX 0x1000 // When 1 PHY is in Full-Duplex Mode
546ae150435SJeff Kirsher #define RPC_ANEG 0x0800 // When 1 PHY is in Auto-Negotiate Mode
547ae150435SJeff Kirsher #define RPC_LSXA_SHFT 5 // Bits to shift LS2A,LS1A,LS0A to lsb
548ae150435SJeff Kirsher #define RPC_LSXB_SHFT 2 // Bits to get LS2B,LS1B,LS0B to lsb
549ae150435SJeff Kirsher
550ae150435SJeff Kirsher #ifndef RPC_LSA_DEFAULT
551ae150435SJeff Kirsher #define RPC_LSA_DEFAULT RPC_LED_100
552ae150435SJeff Kirsher #endif
553ae150435SJeff Kirsher #ifndef RPC_LSB_DEFAULT
554ae150435SJeff Kirsher #define RPC_LSB_DEFAULT RPC_LED_FD
555ae150435SJeff Kirsher #endif
556ae150435SJeff Kirsher
557ae150435SJeff Kirsher #define RPC_DEFAULT (RPC_ANEG | RPC_SPEED | RPC_DPLX)
558ae150435SJeff Kirsher
559ae150435SJeff Kirsher
560ae150435SJeff Kirsher /* Bank 0 0x0C is reserved */
561ae150435SJeff Kirsher
562ae150435SJeff Kirsher // Bank Select Register
563ae150435SJeff Kirsher /* All Banks */
564ae150435SJeff Kirsher #define BSR_REG 0x000E
565ae150435SJeff Kirsher
566ae150435SJeff Kirsher
567ae150435SJeff Kirsher // Configuration Reg
568ae150435SJeff Kirsher /* BANK 1 */
569ae150435SJeff Kirsher #define CONFIG_REG(lp) SMC_REG(lp, 0x0000, 1)
570ae150435SJeff Kirsher #define CONFIG_EXT_PHY 0x0200 // 1=external MII, 0=internal Phy
571ae150435SJeff Kirsher #define CONFIG_GPCNTRL 0x0400 // Inverse value drives pin nCNTRL
572ae150435SJeff Kirsher #define CONFIG_NO_WAIT 0x1000 // When 1 no extra wait states on ISA bus
573ae150435SJeff Kirsher #define CONFIG_EPH_POWER_EN 0x8000 // When 0 EPH is placed into low power mode.
574ae150435SJeff Kirsher
575ae150435SJeff Kirsher // Default is powered-up, Internal Phy, Wait States, and pin nCNTRL=low
576ae150435SJeff Kirsher #define CONFIG_DEFAULT (CONFIG_EPH_POWER_EN)
577ae150435SJeff Kirsher
578ae150435SJeff Kirsher
579ae150435SJeff Kirsher // Base Address Register
580ae150435SJeff Kirsher /* BANK 1 */
581ae150435SJeff Kirsher #define BASE_REG(lp) SMC_REG(lp, 0x0002, 1)
582ae150435SJeff Kirsher
583ae150435SJeff Kirsher
584ae150435SJeff Kirsher // Individual Address Registers
585ae150435SJeff Kirsher /* BANK 1 */
586ae150435SJeff Kirsher #define ADDR0_REG(lp) SMC_REG(lp, 0x0004, 1)
587ae150435SJeff Kirsher #define ADDR1_REG(lp) SMC_REG(lp, 0x0006, 1)
588ae150435SJeff Kirsher #define ADDR2_REG(lp) SMC_REG(lp, 0x0008, 1)
589ae150435SJeff Kirsher
590ae150435SJeff Kirsher
591ae150435SJeff Kirsher // General Purpose Register
592ae150435SJeff Kirsher /* BANK 1 */
593ae150435SJeff Kirsher #define GP_REG(lp) SMC_REG(lp, 0x000A, 1)
594ae150435SJeff Kirsher
595ae150435SJeff Kirsher
596ae150435SJeff Kirsher // Control Register
597ae150435SJeff Kirsher /* BANK 1 */
598ae150435SJeff Kirsher #define CTL_REG(lp) SMC_REG(lp, 0x000C, 1)
599ae150435SJeff Kirsher #define CTL_RCV_BAD 0x4000 // When 1 bad CRC packets are received
600ae150435SJeff Kirsher #define CTL_AUTO_RELEASE 0x0800 // When 1 tx pages are released automatically
601ae150435SJeff Kirsher #define CTL_LE_ENABLE 0x0080 // When 1 enables Link Error interrupt
602ae150435SJeff Kirsher #define CTL_CR_ENABLE 0x0040 // When 1 enables Counter Rollover interrupt
603ae150435SJeff Kirsher #define CTL_TE_ENABLE 0x0020 // When 1 enables Transmit Error interrupt
604ae150435SJeff Kirsher #define CTL_EEPROM_SELECT 0x0004 // Controls EEPROM reload & store
605ae150435SJeff Kirsher #define CTL_RELOAD 0x0002 // When set reads EEPROM into registers
606ae150435SJeff Kirsher #define CTL_STORE 0x0001 // When set stores registers into EEPROM
607ae150435SJeff Kirsher
608ae150435SJeff Kirsher
609ae150435SJeff Kirsher // MMU Command Register
610ae150435SJeff Kirsher /* BANK 2 */
611ae150435SJeff Kirsher #define MMU_CMD_REG(lp) SMC_REG(lp, 0x0000, 2)
612ae150435SJeff Kirsher #define MC_BUSY 1 // When 1 the last release has not completed
613ae150435SJeff Kirsher #define MC_NOP (0<<5) // No Op
614ae150435SJeff Kirsher #define MC_ALLOC (1<<5) // OR with number of 256 byte packets
615ae150435SJeff Kirsher #define MC_RESET (2<<5) // Reset MMU to initial state
616ae150435SJeff Kirsher #define MC_REMOVE (3<<5) // Remove the current rx packet
617ae150435SJeff Kirsher #define MC_RELEASE (4<<5) // Remove and release the current rx packet
618ae150435SJeff Kirsher #define MC_FREEPKT (5<<5) // Release packet in PNR register
619ae150435SJeff Kirsher #define MC_ENQUEUE (6<<5) // Enqueue the packet for transmit
620ae150435SJeff Kirsher #define MC_RSTTXFIFO (7<<5) // Reset the TX FIFOs
621ae150435SJeff Kirsher
622ae150435SJeff Kirsher
623ae150435SJeff Kirsher // Packet Number Register
624ae150435SJeff Kirsher /* BANK 2 */
625ae150435SJeff Kirsher #define PN_REG(lp) SMC_REG(lp, 0x0002, 2)
626ae150435SJeff Kirsher
627ae150435SJeff Kirsher
628ae150435SJeff Kirsher // Allocation Result Register
629ae150435SJeff Kirsher /* BANK 2 */
630ae150435SJeff Kirsher #define AR_REG(lp) SMC_REG(lp, 0x0003, 2)
631ae150435SJeff Kirsher #define AR_FAILED 0x80 // Alocation Failed
632ae150435SJeff Kirsher
633ae150435SJeff Kirsher
634ae150435SJeff Kirsher // TX FIFO Ports Register
635ae150435SJeff Kirsher /* BANK 2 */
636ae150435SJeff Kirsher #define TXFIFO_REG(lp) SMC_REG(lp, 0x0004, 2)
637ae150435SJeff Kirsher #define TXFIFO_TEMPTY 0x80 // TX FIFO Empty
638ae150435SJeff Kirsher
639ae150435SJeff Kirsher // RX FIFO Ports Register
640ae150435SJeff Kirsher /* BANK 2 */
641ae150435SJeff Kirsher #define RXFIFO_REG(lp) SMC_REG(lp, 0x0005, 2)
642ae150435SJeff Kirsher #define RXFIFO_REMPTY 0x80 // RX FIFO Empty
643ae150435SJeff Kirsher
644ae150435SJeff Kirsher #define FIFO_REG(lp) SMC_REG(lp, 0x0004, 2)
645ae150435SJeff Kirsher
646ae150435SJeff Kirsher // Pointer Register
647ae150435SJeff Kirsher /* BANK 2 */
648ae150435SJeff Kirsher #define PTR_REG(lp) SMC_REG(lp, 0x0006, 2)
649ae150435SJeff Kirsher #define PTR_RCV 0x8000 // 1=Receive area, 0=Transmit area
650ae150435SJeff Kirsher #define PTR_AUTOINC 0x4000 // Auto increment the pointer on each access
651ae150435SJeff Kirsher #define PTR_READ 0x2000 // When 1 the operation is a read
652ae150435SJeff Kirsher
653ae150435SJeff Kirsher
654ae150435SJeff Kirsher // Data Register
655ae150435SJeff Kirsher /* BANK 2 */
656ae150435SJeff Kirsher #define DATA_REG(lp) SMC_REG(lp, 0x0008, 2)
657ae150435SJeff Kirsher
658ae150435SJeff Kirsher
659ae150435SJeff Kirsher // Interrupt Status/Acknowledge Register
660ae150435SJeff Kirsher /* BANK 2 */
661ae150435SJeff Kirsher #define INT_REG(lp) SMC_REG(lp, 0x000C, 2)
662ae150435SJeff Kirsher
663ae150435SJeff Kirsher
664ae150435SJeff Kirsher // Interrupt Mask Register
665ae150435SJeff Kirsher /* BANK 2 */
666ae150435SJeff Kirsher #define IM_REG(lp) SMC_REG(lp, 0x000D, 2)
667ae150435SJeff Kirsher #define IM_MDINT 0x80 // PHY MI Register 18 Interrupt
668ae150435SJeff Kirsher #define IM_ERCV_INT 0x40 // Early Receive Interrupt
669ae150435SJeff Kirsher #define IM_EPH_INT 0x20 // Set by Ethernet Protocol Handler section
670ae150435SJeff Kirsher #define IM_RX_OVRN_INT 0x10 // Set by Receiver Overruns
671ae150435SJeff Kirsher #define IM_ALLOC_INT 0x08 // Set when allocation request is completed
672ae150435SJeff Kirsher #define IM_TX_EMPTY_INT 0x04 // Set if the TX FIFO goes empty
673ae150435SJeff Kirsher #define IM_TX_INT 0x02 // Transmit Interrupt
674ae150435SJeff Kirsher #define IM_RCV_INT 0x01 // Receive Interrupt
675ae150435SJeff Kirsher
676ae150435SJeff Kirsher
677ae150435SJeff Kirsher // Multicast Table Registers
678ae150435SJeff Kirsher /* BANK 3 */
679ae150435SJeff Kirsher #define MCAST_REG1(lp) SMC_REG(lp, 0x0000, 3)
680ae150435SJeff Kirsher #define MCAST_REG2(lp) SMC_REG(lp, 0x0002, 3)
681ae150435SJeff Kirsher #define MCAST_REG3(lp) SMC_REG(lp, 0x0004, 3)
682ae150435SJeff Kirsher #define MCAST_REG4(lp) SMC_REG(lp, 0x0006, 3)
683ae150435SJeff Kirsher
684ae150435SJeff Kirsher
685ae150435SJeff Kirsher // Management Interface Register (MII)
686ae150435SJeff Kirsher /* BANK 3 */
687ae150435SJeff Kirsher #define MII_REG(lp) SMC_REG(lp, 0x0008, 3)
688ae150435SJeff Kirsher #define MII_MSK_CRS100 0x4000 // Disables CRS100 detection during tx half dup
689ae150435SJeff Kirsher #define MII_MDOE 0x0008 // MII Output Enable
690ae150435SJeff Kirsher #define MII_MCLK 0x0004 // MII Clock, pin MDCLK
691ae150435SJeff Kirsher #define MII_MDI 0x0002 // MII Input, pin MDI
692ae150435SJeff Kirsher #define MII_MDO 0x0001 // MII Output, pin MDO
693ae150435SJeff Kirsher
694ae150435SJeff Kirsher
695ae150435SJeff Kirsher // Revision Register
696ae150435SJeff Kirsher /* BANK 3 */
697ae150435SJeff Kirsher /* ( hi: chip id low: rev # ) */
698ae150435SJeff Kirsher #define REV_REG(lp) SMC_REG(lp, 0x000A, 3)
699ae150435SJeff Kirsher
700ae150435SJeff Kirsher
701ae150435SJeff Kirsher // Early RCV Register
702ae150435SJeff Kirsher /* BANK 3 */
703ae150435SJeff Kirsher /* this is NOT on SMC9192 */
704ae150435SJeff Kirsher #define ERCV_REG(lp) SMC_REG(lp, 0x000C, 3)
705ae150435SJeff Kirsher #define ERCV_RCV_DISCRD 0x0080 // When 1 discards a packet being received
706ae150435SJeff Kirsher #define ERCV_THRESHOLD 0x001F // ERCV Threshold Mask
707ae150435SJeff Kirsher
708ae150435SJeff Kirsher
709ae150435SJeff Kirsher // External Register
710ae150435SJeff Kirsher /* BANK 7 */
711ae150435SJeff Kirsher #define EXT_REG(lp) SMC_REG(lp, 0x0000, 7)
712ae150435SJeff Kirsher
713ae150435SJeff Kirsher
714ae150435SJeff Kirsher #define CHIP_9192 3
715ae150435SJeff Kirsher #define CHIP_9194 4
716ae150435SJeff Kirsher #define CHIP_9195 5
717ae150435SJeff Kirsher #define CHIP_9196 6
718ae150435SJeff Kirsher #define CHIP_91100 7
719ae150435SJeff Kirsher #define CHIP_91100FD 8
720ae150435SJeff Kirsher #define CHIP_91111FD 9
721ae150435SJeff Kirsher
722ae150435SJeff Kirsher static const char * chip_ids[ 16 ] = {
723ae150435SJeff Kirsher NULL, NULL, NULL,
724ae150435SJeff Kirsher /* 3 */ "SMC91C90/91C92",
725ae150435SJeff Kirsher /* 4 */ "SMC91C94",
726ae150435SJeff Kirsher /* 5 */ "SMC91C95",
727ae150435SJeff Kirsher /* 6 */ "SMC91C96",
728ae150435SJeff Kirsher /* 7 */ "SMC91C100",
729ae150435SJeff Kirsher /* 8 */ "SMC91C100FD",
730ae150435SJeff Kirsher /* 9 */ "SMC91C11xFD",
731ae150435SJeff Kirsher NULL, NULL, NULL,
732ae150435SJeff Kirsher NULL, NULL, NULL};
733ae150435SJeff Kirsher
734ae150435SJeff Kirsher
735ae150435SJeff Kirsher /*
736ae150435SJeff Kirsher . Receive status bits
737ae150435SJeff Kirsher */
738ae150435SJeff Kirsher #define RS_ALGNERR 0x8000
739ae150435SJeff Kirsher #define RS_BRODCAST 0x4000
740ae150435SJeff Kirsher #define RS_BADCRC 0x2000
741ae150435SJeff Kirsher #define RS_ODDFRAME 0x1000
742ae150435SJeff Kirsher #define RS_TOOLONG 0x0800
743ae150435SJeff Kirsher #define RS_TOOSHORT 0x0400
744ae150435SJeff Kirsher #define RS_MULTICAST 0x0001
745ae150435SJeff Kirsher #define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
746ae150435SJeff Kirsher
747ae150435SJeff Kirsher
748ae150435SJeff Kirsher /*
749ae150435SJeff Kirsher * PHY IDs
750ae150435SJeff Kirsher * LAN83C183 == LAN91C111 Internal PHY
751ae150435SJeff Kirsher */
752ae150435SJeff Kirsher #define PHY_LAN83C183 0x0016f840
753ae150435SJeff Kirsher #define PHY_LAN83C180 0x02821c50
754ae150435SJeff Kirsher
755ae150435SJeff Kirsher /*
756ae150435SJeff Kirsher * PHY Register Addresses (LAN91C111 Internal PHY)
757ae150435SJeff Kirsher *
758ae150435SJeff Kirsher * Generic PHY registers can be found in <linux/mii.h>
759ae150435SJeff Kirsher *
760ae150435SJeff Kirsher * These phy registers are specific to our on-board phy.
761ae150435SJeff Kirsher */
762ae150435SJeff Kirsher
763ae150435SJeff Kirsher // PHY Configuration Register 1
764ae150435SJeff Kirsher #define PHY_CFG1_REG 0x10
765ae150435SJeff Kirsher #define PHY_CFG1_LNKDIS 0x8000 // 1=Rx Link Detect Function disabled
766ae150435SJeff Kirsher #define PHY_CFG1_XMTDIS 0x4000 // 1=TP Transmitter Disabled
767ae150435SJeff Kirsher #define PHY_CFG1_XMTPDN 0x2000 // 1=TP Transmitter Powered Down
768ae150435SJeff Kirsher #define PHY_CFG1_BYPSCR 0x0400 // 1=Bypass scrambler/descrambler
769ae150435SJeff Kirsher #define PHY_CFG1_UNSCDS 0x0200 // 1=Unscramble Idle Reception Disable
770ae150435SJeff Kirsher #define PHY_CFG1_EQLZR 0x0100 // 1=Rx Equalizer Disabled
771ae150435SJeff Kirsher #define PHY_CFG1_CABLE 0x0080 // 1=STP(150ohm), 0=UTP(100ohm)
772ae150435SJeff Kirsher #define PHY_CFG1_RLVL0 0x0040 // 1=Rx Squelch level reduced by 4.5db
773ae150435SJeff Kirsher #define PHY_CFG1_TLVL_SHIFT 2 // Transmit Output Level Adjust
774ae150435SJeff Kirsher #define PHY_CFG1_TLVL_MASK 0x003C
775ae150435SJeff Kirsher #define PHY_CFG1_TRF_MASK 0x0003 // Transmitter Rise/Fall time
776ae150435SJeff Kirsher
777ae150435SJeff Kirsher
778ae150435SJeff Kirsher // PHY Configuration Register 2
779ae150435SJeff Kirsher #define PHY_CFG2_REG 0x11
780ae150435SJeff Kirsher #define PHY_CFG2_APOLDIS 0x0020 // 1=Auto Polarity Correction disabled
781ae150435SJeff Kirsher #define PHY_CFG2_JABDIS 0x0010 // 1=Jabber disabled
782ae150435SJeff Kirsher #define PHY_CFG2_MREG 0x0008 // 1=Multiple register access (MII mgt)
783ae150435SJeff Kirsher #define PHY_CFG2_INTMDIO 0x0004 // 1=Interrupt signaled with MDIO pulseo
784ae150435SJeff Kirsher
785ae150435SJeff Kirsher // PHY Status Output (and Interrupt status) Register
786ae150435SJeff Kirsher #define PHY_INT_REG 0x12 // Status Output (Interrupt Status)
787ae150435SJeff Kirsher #define PHY_INT_INT 0x8000 // 1=bits have changed since last read
788ae150435SJeff Kirsher #define PHY_INT_LNKFAIL 0x4000 // 1=Link Not detected
789ae150435SJeff Kirsher #define PHY_INT_LOSSSYNC 0x2000 // 1=Descrambler has lost sync
790ae150435SJeff Kirsher #define PHY_INT_CWRD 0x1000 // 1=Invalid 4B5B code detected on rx
791ae150435SJeff Kirsher #define PHY_INT_SSD 0x0800 // 1=No Start Of Stream detected on rx
792ae150435SJeff Kirsher #define PHY_INT_ESD 0x0400 // 1=No End Of Stream detected on rx
793ae150435SJeff Kirsher #define PHY_INT_RPOL 0x0200 // 1=Reverse Polarity detected
794ae150435SJeff Kirsher #define PHY_INT_JAB 0x0100 // 1=Jabber detected
795ae150435SJeff Kirsher #define PHY_INT_SPDDET 0x0080 // 1=100Base-TX mode, 0=10Base-T mode
796ae150435SJeff Kirsher #define PHY_INT_DPLXDET 0x0040 // 1=Device in Full Duplex
797ae150435SJeff Kirsher
798ae150435SJeff Kirsher // PHY Interrupt/Status Mask Register
799ae150435SJeff Kirsher #define PHY_MASK_REG 0x13 // Interrupt Mask
800ae150435SJeff Kirsher // Uses the same bit definitions as PHY_INT_REG
801ae150435SJeff Kirsher
802ae150435SJeff Kirsher
803ae150435SJeff Kirsher /*
804ae150435SJeff Kirsher * SMC91C96 ethernet config and status registers.
805ae150435SJeff Kirsher * These are in the "attribute" space.
806ae150435SJeff Kirsher */
807ae150435SJeff Kirsher #define ECOR 0x8000
808ae150435SJeff Kirsher #define ECOR_RESET 0x80
809ae150435SJeff Kirsher #define ECOR_LEVEL_IRQ 0x40
810ae150435SJeff Kirsher #define ECOR_WR_ATTRIB 0x04
811ae150435SJeff Kirsher #define ECOR_ENABLE 0x01
812ae150435SJeff Kirsher
813ae150435SJeff Kirsher #define ECSR 0x8002
814ae150435SJeff Kirsher #define ECSR_IOIS8 0x20
815ae150435SJeff Kirsher #define ECSR_PWRDWN 0x04
816ae150435SJeff Kirsher #define ECSR_INT 0x02
817ae150435SJeff Kirsher
818ae150435SJeff Kirsher #define ATTRIB_SIZE ((64*1024) << SMC_IO_SHIFT)
819ae150435SJeff Kirsher
820ae150435SJeff Kirsher
821ae150435SJeff Kirsher /*
822ae150435SJeff Kirsher * Macros to abstract register access according to the data bus
823ae150435SJeff Kirsher * capabilities. Please use those and not the in/out primitives.
824ae150435SJeff Kirsher * Note: the following macros do *not* select the bank -- this must
825ae150435SJeff Kirsher * be done separately as needed in the main code. The SMC_REG() macro
826ae150435SJeff Kirsher * only uses the bank argument for debugging purposes (when enabled).
827ae150435SJeff Kirsher *
828ae150435SJeff Kirsher * Note: despite inline functions being safer, everything leading to this
829ae150435SJeff Kirsher * should preferably be macros to let BUG() display the line number in
830ae150435SJeff Kirsher * the core source code since we're interested in the top call site
831ae150435SJeff Kirsher * not in any inline function location.
832ae150435SJeff Kirsher */
833ae150435SJeff Kirsher
834ae150435SJeff Kirsher #if SMC_DEBUG > 0
835ae150435SJeff Kirsher #define SMC_REG(lp, reg, bank) \
836ae150435SJeff Kirsher ({ \
837ae150435SJeff Kirsher int __b = SMC_CURRENT_BANK(lp); \
838ae150435SJeff Kirsher if (unlikely((__b & ~0xf0) != (0x3300 | bank))) { \
8396389aa45SBen Boeckel pr_err("%s: bank reg screwed (0x%04x)\n", \
840ae150435SJeff Kirsher CARDNAME, __b); \
841ae150435SJeff Kirsher BUG(); \
842ae150435SJeff Kirsher } \
843ae150435SJeff Kirsher reg<<SMC_IO_SHIFT; \
844ae150435SJeff Kirsher })
845ae150435SJeff Kirsher #else
846ae150435SJeff Kirsher #define SMC_REG(lp, reg, bank) (reg<<SMC_IO_SHIFT)
847ae150435SJeff Kirsher #endif
848ae150435SJeff Kirsher
849ae150435SJeff Kirsher /*
850ae150435SJeff Kirsher * Hack Alert: Some setups just can't write 8 or 16 bits reliably when not
851ae150435SJeff Kirsher * aligned to a 32 bit boundary. I tell you that does exist!
852ae150435SJeff Kirsher * Fortunately the affected register accesses can be easily worked around
853ae150435SJeff Kirsher * since we can write zeroes to the preceding 16 bits without adverse
854ae150435SJeff Kirsher * effects and use a 32-bit access.
855ae150435SJeff Kirsher *
856ae150435SJeff Kirsher * Enforce it on any 32-bit capable setup for now.
857ae150435SJeff Kirsher */
858ae150435SJeff Kirsher #define SMC_MUST_ALIGN_WRITE(lp) SMC_32BIT(lp)
859ae150435SJeff Kirsher
860ae150435SJeff Kirsher #define SMC_GET_PN(lp) \
861ae150435SJeff Kirsher (SMC_8BIT(lp) ? (SMC_inb(ioaddr, PN_REG(lp))) \
862ae150435SJeff Kirsher : (SMC_inw(ioaddr, PN_REG(lp)) & 0xFF))
863ae150435SJeff Kirsher
864ae150435SJeff Kirsher #define SMC_SET_PN(lp, x) \
865ae150435SJeff Kirsher do { \
866ae150435SJeff Kirsher if (SMC_MUST_ALIGN_WRITE(lp)) \
867ae150435SJeff Kirsher SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 0, 2)); \
868ae150435SJeff Kirsher else if (SMC_8BIT(lp)) \
869ae150435SJeff Kirsher SMC_outb(x, ioaddr, PN_REG(lp)); \
870ae150435SJeff Kirsher else \
871d09d747aSRobert Jarzmik SMC_outw(lp, x, ioaddr, PN_REG(lp)); \
872ae150435SJeff Kirsher } while (0)
873ae150435SJeff Kirsher
874ae150435SJeff Kirsher #define SMC_GET_AR(lp) \
875ae150435SJeff Kirsher (SMC_8BIT(lp) ? (SMC_inb(ioaddr, AR_REG(lp))) \
876ae150435SJeff Kirsher : (SMC_inw(ioaddr, PN_REG(lp)) >> 8))
877ae150435SJeff Kirsher
878ae150435SJeff Kirsher #define SMC_GET_TXFIFO(lp) \
879ae150435SJeff Kirsher (SMC_8BIT(lp) ? (SMC_inb(ioaddr, TXFIFO_REG(lp))) \
880ae150435SJeff Kirsher : (SMC_inw(ioaddr, TXFIFO_REG(lp)) & 0xFF))
881ae150435SJeff Kirsher
882ae150435SJeff Kirsher #define SMC_GET_RXFIFO(lp) \
883ae150435SJeff Kirsher (SMC_8BIT(lp) ? (SMC_inb(ioaddr, RXFIFO_REG(lp))) \
884ae150435SJeff Kirsher : (SMC_inw(ioaddr, TXFIFO_REG(lp)) >> 8))
885ae150435SJeff Kirsher
886ae150435SJeff Kirsher #define SMC_GET_INT(lp) \
887ae150435SJeff Kirsher (SMC_8BIT(lp) ? (SMC_inb(ioaddr, INT_REG(lp))) \
888ae150435SJeff Kirsher : (SMC_inw(ioaddr, INT_REG(lp)) & 0xFF))
889ae150435SJeff Kirsher
890ae150435SJeff Kirsher #define SMC_ACK_INT(lp, x) \
891ae150435SJeff Kirsher do { \
892ae150435SJeff Kirsher if (SMC_8BIT(lp)) \
893ae150435SJeff Kirsher SMC_outb(x, ioaddr, INT_REG(lp)); \
894ae150435SJeff Kirsher else { \
895ae150435SJeff Kirsher unsigned long __flags; \
896ae150435SJeff Kirsher int __mask; \
897ae150435SJeff Kirsher local_irq_save(__flags); \
898ae150435SJeff Kirsher __mask = SMC_inw(ioaddr, INT_REG(lp)) & ~0xff; \
899d09d747aSRobert Jarzmik SMC_outw(lp, __mask | (x), ioaddr, INT_REG(lp)); \
900ae150435SJeff Kirsher local_irq_restore(__flags); \
901ae150435SJeff Kirsher } \
902ae150435SJeff Kirsher } while (0)
903ae150435SJeff Kirsher
904ae150435SJeff Kirsher #define SMC_GET_INT_MASK(lp) \
905ae150435SJeff Kirsher (SMC_8BIT(lp) ? (SMC_inb(ioaddr, IM_REG(lp))) \
906ae150435SJeff Kirsher : (SMC_inw(ioaddr, INT_REG(lp)) >> 8))
907ae150435SJeff Kirsher
908ae150435SJeff Kirsher #define SMC_SET_INT_MASK(lp, x) \
909ae150435SJeff Kirsher do { \
910ae150435SJeff Kirsher if (SMC_8BIT(lp)) \
911ae150435SJeff Kirsher SMC_outb(x, ioaddr, IM_REG(lp)); \
912ae150435SJeff Kirsher else \
913d09d747aSRobert Jarzmik SMC_outw(lp, (x) << 8, ioaddr, INT_REG(lp)); \
914ae150435SJeff Kirsher } while (0)
915ae150435SJeff Kirsher
916ae150435SJeff Kirsher #define SMC_CURRENT_BANK(lp) SMC_inw(ioaddr, BANK_SELECT)
917ae150435SJeff Kirsher
918ae150435SJeff Kirsher #define SMC_SELECT_BANK(lp, x) \
919ae150435SJeff Kirsher do { \
920ae150435SJeff Kirsher if (SMC_MUST_ALIGN_WRITE(lp)) \
921ae150435SJeff Kirsher SMC_outl((x)<<16, ioaddr, 12<<SMC_IO_SHIFT); \
922ae150435SJeff Kirsher else \
923d09d747aSRobert Jarzmik SMC_outw(lp, x, ioaddr, BANK_SELECT); \
924ae150435SJeff Kirsher } while (0)
925ae150435SJeff Kirsher
926ae150435SJeff Kirsher #define SMC_GET_BASE(lp) SMC_inw(ioaddr, BASE_REG(lp))
927ae150435SJeff Kirsher
928d09d747aSRobert Jarzmik #define SMC_SET_BASE(lp, x) SMC_outw(lp, x, ioaddr, BASE_REG(lp))
929ae150435SJeff Kirsher
930ae150435SJeff Kirsher #define SMC_GET_CONFIG(lp) SMC_inw(ioaddr, CONFIG_REG(lp))
931ae150435SJeff Kirsher
932d09d747aSRobert Jarzmik #define SMC_SET_CONFIG(lp, x) SMC_outw(lp, x, ioaddr, CONFIG_REG(lp))
933ae150435SJeff Kirsher
934ae150435SJeff Kirsher #define SMC_GET_COUNTER(lp) SMC_inw(ioaddr, COUNTER_REG(lp))
935ae150435SJeff Kirsher
936ae150435SJeff Kirsher #define SMC_GET_CTL(lp) SMC_inw(ioaddr, CTL_REG(lp))
937ae150435SJeff Kirsher
938d09d747aSRobert Jarzmik #define SMC_SET_CTL(lp, x) SMC_outw(lp, x, ioaddr, CTL_REG(lp))
939ae150435SJeff Kirsher
940ae150435SJeff Kirsher #define SMC_GET_MII(lp) SMC_inw(ioaddr, MII_REG(lp))
941ae150435SJeff Kirsher
942ae150435SJeff Kirsher #define SMC_GET_GP(lp) SMC_inw(ioaddr, GP_REG(lp))
943ae150435SJeff Kirsher
944ae150435SJeff Kirsher #define SMC_SET_GP(lp, x) \
945ae150435SJeff Kirsher do { \
946ae150435SJeff Kirsher if (SMC_MUST_ALIGN_WRITE(lp)) \
947ae150435SJeff Kirsher SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 8, 1)); \
948ae150435SJeff Kirsher else \
949d09d747aSRobert Jarzmik SMC_outw(lp, x, ioaddr, GP_REG(lp)); \
950ae150435SJeff Kirsher } while (0)
951ae150435SJeff Kirsher
952d09d747aSRobert Jarzmik #define SMC_SET_MII(lp, x) SMC_outw(lp, x, ioaddr, MII_REG(lp))
953ae150435SJeff Kirsher
954ae150435SJeff Kirsher #define SMC_GET_MIR(lp) SMC_inw(ioaddr, MIR_REG(lp))
955ae150435SJeff Kirsher
956d09d747aSRobert Jarzmik #define SMC_SET_MIR(lp, x) SMC_outw(lp, x, ioaddr, MIR_REG(lp))
957ae150435SJeff Kirsher
958ae150435SJeff Kirsher #define SMC_GET_MMU_CMD(lp) SMC_inw(ioaddr, MMU_CMD_REG(lp))
959ae150435SJeff Kirsher
960d09d747aSRobert Jarzmik #define SMC_SET_MMU_CMD(lp, x) SMC_outw(lp, x, ioaddr, MMU_CMD_REG(lp))
961ae150435SJeff Kirsher
962ae150435SJeff Kirsher #define SMC_GET_FIFO(lp) SMC_inw(ioaddr, FIFO_REG(lp))
963ae150435SJeff Kirsher
964ae150435SJeff Kirsher #define SMC_GET_PTR(lp) SMC_inw(ioaddr, PTR_REG(lp))
965ae150435SJeff Kirsher
966ae150435SJeff Kirsher #define SMC_SET_PTR(lp, x) \
967ae150435SJeff Kirsher do { \
968ae150435SJeff Kirsher if (SMC_MUST_ALIGN_WRITE(lp)) \
969ae150435SJeff Kirsher SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 4, 2)); \
970ae150435SJeff Kirsher else \
971d09d747aSRobert Jarzmik SMC_outw(lp, x, ioaddr, PTR_REG(lp)); \
972ae150435SJeff Kirsher } while (0)
973ae150435SJeff Kirsher
974ae150435SJeff Kirsher #define SMC_GET_EPH_STATUS(lp) SMC_inw(ioaddr, EPH_STATUS_REG(lp))
975ae150435SJeff Kirsher
976ae150435SJeff Kirsher #define SMC_GET_RCR(lp) SMC_inw(ioaddr, RCR_REG(lp))
977ae150435SJeff Kirsher
978d09d747aSRobert Jarzmik #define SMC_SET_RCR(lp, x) SMC_outw(lp, x, ioaddr, RCR_REG(lp))
979ae150435SJeff Kirsher
980ae150435SJeff Kirsher #define SMC_GET_REV(lp) SMC_inw(ioaddr, REV_REG(lp))
981ae150435SJeff Kirsher
982ae150435SJeff Kirsher #define SMC_GET_RPC(lp) SMC_inw(ioaddr, RPC_REG(lp))
983ae150435SJeff Kirsher
984ae150435SJeff Kirsher #define SMC_SET_RPC(lp, x) \
985ae150435SJeff Kirsher do { \
986ae150435SJeff Kirsher if (SMC_MUST_ALIGN_WRITE(lp)) \
987ae150435SJeff Kirsher SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 8, 0)); \
988ae150435SJeff Kirsher else \
989d09d747aSRobert Jarzmik SMC_outw(lp, x, ioaddr, RPC_REG(lp)); \
990ae150435SJeff Kirsher } while (0)
991ae150435SJeff Kirsher
992ae150435SJeff Kirsher #define SMC_GET_TCR(lp) SMC_inw(ioaddr, TCR_REG(lp))
993ae150435SJeff Kirsher
994d09d747aSRobert Jarzmik #define SMC_SET_TCR(lp, x) SMC_outw(lp, x, ioaddr, TCR_REG(lp))
995ae150435SJeff Kirsher
996ae150435SJeff Kirsher #ifndef SMC_GET_MAC_ADDR
997ae150435SJeff Kirsher #define SMC_GET_MAC_ADDR(lp, addr) \
998ae150435SJeff Kirsher do { \
999ae150435SJeff Kirsher unsigned int __v; \
1000ae150435SJeff Kirsher __v = SMC_inw(ioaddr, ADDR0_REG(lp)); \
1001ae150435SJeff Kirsher addr[0] = __v; addr[1] = __v >> 8; \
1002ae150435SJeff Kirsher __v = SMC_inw(ioaddr, ADDR1_REG(lp)); \
1003ae150435SJeff Kirsher addr[2] = __v; addr[3] = __v >> 8; \
1004ae150435SJeff Kirsher __v = SMC_inw(ioaddr, ADDR2_REG(lp)); \
1005ae150435SJeff Kirsher addr[4] = __v; addr[5] = __v >> 8; \
1006ae150435SJeff Kirsher } while (0)
1007ae150435SJeff Kirsher #endif
1008ae150435SJeff Kirsher
1009ae150435SJeff Kirsher #define SMC_SET_MAC_ADDR(lp, addr) \
1010ae150435SJeff Kirsher do { \
1011d09d747aSRobert Jarzmik SMC_outw(lp, addr[0] | (addr[1] << 8), ioaddr, ADDR0_REG(lp)); \
1012d09d747aSRobert Jarzmik SMC_outw(lp, addr[2] | (addr[3] << 8), ioaddr, ADDR1_REG(lp)); \
1013d09d747aSRobert Jarzmik SMC_outw(lp, addr[4] | (addr[5] << 8), ioaddr, ADDR2_REG(lp)); \
1014ae150435SJeff Kirsher } while (0)
1015ae150435SJeff Kirsher
1016ae150435SJeff Kirsher #define SMC_SET_MCAST(lp, x) \
1017ae150435SJeff Kirsher do { \
1018ae150435SJeff Kirsher const unsigned char *mt = (x); \
1019d09d747aSRobert Jarzmik SMC_outw(lp, mt[0] | (mt[1] << 8), ioaddr, MCAST_REG1(lp)); \
1020d09d747aSRobert Jarzmik SMC_outw(lp, mt[2] | (mt[3] << 8), ioaddr, MCAST_REG2(lp)); \
1021d09d747aSRobert Jarzmik SMC_outw(lp, mt[4] | (mt[5] << 8), ioaddr, MCAST_REG3(lp)); \
1022d09d747aSRobert Jarzmik SMC_outw(lp, mt[6] | (mt[7] << 8), ioaddr, MCAST_REG4(lp)); \
1023ae150435SJeff Kirsher } while (0)
1024ae150435SJeff Kirsher
1025ae150435SJeff Kirsher #define SMC_PUT_PKT_HDR(lp, status, length) \
1026ae150435SJeff Kirsher do { \
1027ae150435SJeff Kirsher if (SMC_32BIT(lp)) \
1028ae150435SJeff Kirsher SMC_outl((status) | (length)<<16, ioaddr, \
1029ae150435SJeff Kirsher DATA_REG(lp)); \
1030ae150435SJeff Kirsher else { \
1031d09d747aSRobert Jarzmik SMC_outw(lp, status, ioaddr, DATA_REG(lp)); \
1032d09d747aSRobert Jarzmik SMC_outw(lp, length, ioaddr, DATA_REG(lp)); \
1033ae150435SJeff Kirsher } \
1034ae150435SJeff Kirsher } while (0)
1035ae150435SJeff Kirsher
1036ae150435SJeff Kirsher #define SMC_GET_PKT_HDR(lp, status, length) \
1037ae150435SJeff Kirsher do { \
1038ae150435SJeff Kirsher if (SMC_32BIT(lp)) { \
1039ae150435SJeff Kirsher unsigned int __val = SMC_inl(ioaddr, DATA_REG(lp)); \
1040ae150435SJeff Kirsher (status) = __val & 0xffff; \
1041ae150435SJeff Kirsher (length) = __val >> 16; \
1042ae150435SJeff Kirsher } else { \
1043ae150435SJeff Kirsher (status) = SMC_inw(ioaddr, DATA_REG(lp)); \
1044ae150435SJeff Kirsher (length) = SMC_inw(ioaddr, DATA_REG(lp)); \
1045ae150435SJeff Kirsher } \
1046ae150435SJeff Kirsher } while (0)
1047ae150435SJeff Kirsher
1048ae150435SJeff Kirsher #define SMC_PUSH_DATA(lp, p, l) \
1049ae150435SJeff Kirsher do { \
1050ae150435SJeff Kirsher if (SMC_32BIT(lp)) { \
1051ae150435SJeff Kirsher void *__ptr = (p); \
1052ae150435SJeff Kirsher int __len = (l); \
1053ae150435SJeff Kirsher void __iomem *__ioaddr = ioaddr; \
1054ae150435SJeff Kirsher if (__len >= 2 && (unsigned long)__ptr & 2) { \
1055ae150435SJeff Kirsher __len -= 2; \
1056e9e4ea74SWill Deacon SMC_outsw(ioaddr, DATA_REG(lp), __ptr, 1); \
1057ae150435SJeff Kirsher __ptr += 2; \
1058ae150435SJeff Kirsher } \
1059ae150435SJeff Kirsher if (SMC_CAN_USE_DATACS && lp->datacs) \
1060ae150435SJeff Kirsher __ioaddr = lp->datacs; \
1061ae150435SJeff Kirsher SMC_outsl(__ioaddr, DATA_REG(lp), __ptr, __len>>2); \
1062ae150435SJeff Kirsher if (__len & 2) { \
1063ae150435SJeff Kirsher __ptr += (__len & ~3); \
1064e9e4ea74SWill Deacon SMC_outsw(ioaddr, DATA_REG(lp), __ptr, 1); \
1065ae150435SJeff Kirsher } \
1066ae150435SJeff Kirsher } else if (SMC_16BIT(lp)) \
1067ae150435SJeff Kirsher SMC_outsw(ioaddr, DATA_REG(lp), p, (l) >> 1); \
1068ae150435SJeff Kirsher else if (SMC_8BIT(lp)) \
1069ae150435SJeff Kirsher SMC_outsb(ioaddr, DATA_REG(lp), p, l); \
1070ae150435SJeff Kirsher } while (0)
1071ae150435SJeff Kirsher
1072ae150435SJeff Kirsher #define SMC_PULL_DATA(lp, p, l) \
1073ae150435SJeff Kirsher do { \
1074ae150435SJeff Kirsher if (SMC_32BIT(lp)) { \
1075ae150435SJeff Kirsher void *__ptr = (p); \
1076ae150435SJeff Kirsher int __len = (l); \
1077ae150435SJeff Kirsher void __iomem *__ioaddr = ioaddr; \
1078ae150435SJeff Kirsher if ((unsigned long)__ptr & 2) { \
1079ae150435SJeff Kirsher /* \
1080ae150435SJeff Kirsher * We want 32bit alignment here. \
1081ae150435SJeff Kirsher * Since some buses perform a full \
1082ae150435SJeff Kirsher * 32bit fetch even for 16bit data \
1083ae150435SJeff Kirsher * we can't use SMC_inw() here. \
1084ae150435SJeff Kirsher * Back both source (on-chip) and \
1085ae150435SJeff Kirsher * destination pointers of 2 bytes. \
1086ae150435SJeff Kirsher * This is possible since the call to \
1087ae150435SJeff Kirsher * SMC_GET_PKT_HDR() already advanced \
1088ae150435SJeff Kirsher * the source pointer of 4 bytes, and \
1089ae150435SJeff Kirsher * the skb_reserve(skb, 2) advanced \
1090ae150435SJeff Kirsher * the destination pointer of 2 bytes. \
1091ae150435SJeff Kirsher */ \
1092ae150435SJeff Kirsher __ptr -= 2; \
1093ae150435SJeff Kirsher __len += 2; \
1094ae150435SJeff Kirsher SMC_SET_PTR(lp, \
1095ae150435SJeff Kirsher 2|PTR_READ|PTR_RCV|PTR_AUTOINC); \
1096ae150435SJeff Kirsher } \
1097ae150435SJeff Kirsher if (SMC_CAN_USE_DATACS && lp->datacs) \
1098ae150435SJeff Kirsher __ioaddr = lp->datacs; \
1099ae150435SJeff Kirsher __len += 2; \
1100ae150435SJeff Kirsher SMC_insl(__ioaddr, DATA_REG(lp), __ptr, __len>>2); \
1101ae150435SJeff Kirsher } else if (SMC_16BIT(lp)) \
1102ae150435SJeff Kirsher SMC_insw(ioaddr, DATA_REG(lp), p, (l) >> 1); \
1103ae150435SJeff Kirsher else if (SMC_8BIT(lp)) \
1104ae150435SJeff Kirsher SMC_insb(ioaddr, DATA_REG(lp), p, l); \
1105ae150435SJeff Kirsher } while (0)
1106ae150435SJeff Kirsher
1107ae150435SJeff Kirsher #endif /* _SMC91X_H_ */
1108