1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /* sunhme.c: Sparc HME/BigMac 10/100baseT half/full duplex auto switching,
3*4882a593Smuzhiyun * auto carrier detecting ethernet driver. Also known as the
4*4882a593Smuzhiyun * "Happy Meal Ethernet" found on SunSwift SBUS cards.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 1996, 1998, 1999, 2002, 2003,
7*4882a593Smuzhiyun * 2006, 2008 David S. Miller (davem@davemloft.net)
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * Changes :
10*4882a593Smuzhiyun * 2000/11/11 Willy Tarreau <willy AT meta-x.org>
11*4882a593Smuzhiyun * - port to non-sparc architectures. Tested only on x86 and
12*4882a593Smuzhiyun * only currently works with QFE PCI cards.
13*4882a593Smuzhiyun * - ability to specify the MAC address at module load time by passing this
14*4882a593Smuzhiyun * argument : macaddr=0x00,0x10,0x20,0x30,0x40,0x50
15*4882a593Smuzhiyun */
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include <linux/module.h>
18*4882a593Smuzhiyun #include <linux/kernel.h>
19*4882a593Smuzhiyun #include <linux/types.h>
20*4882a593Smuzhiyun #include <linux/fcntl.h>
21*4882a593Smuzhiyun #include <linux/interrupt.h>
22*4882a593Smuzhiyun #include <linux/ioport.h>
23*4882a593Smuzhiyun #include <linux/in.h>
24*4882a593Smuzhiyun #include <linux/slab.h>
25*4882a593Smuzhiyun #include <linux/string.h>
26*4882a593Smuzhiyun #include <linux/delay.h>
27*4882a593Smuzhiyun #include <linux/init.h>
28*4882a593Smuzhiyun #include <linux/ethtool.h>
29*4882a593Smuzhiyun #include <linux/mii.h>
30*4882a593Smuzhiyun #include <linux/crc32.h>
31*4882a593Smuzhiyun #include <linux/random.h>
32*4882a593Smuzhiyun #include <linux/errno.h>
33*4882a593Smuzhiyun #include <linux/netdevice.h>
34*4882a593Smuzhiyun #include <linux/etherdevice.h>
35*4882a593Smuzhiyun #include <linux/skbuff.h>
36*4882a593Smuzhiyun #include <linux/mm.h>
37*4882a593Smuzhiyun #include <linux/bitops.h>
38*4882a593Smuzhiyun #include <linux/dma-mapping.h>
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #include <asm/io.h>
41*4882a593Smuzhiyun #include <asm/dma.h>
42*4882a593Smuzhiyun #include <asm/byteorder.h>
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun #ifdef CONFIG_SPARC
45*4882a593Smuzhiyun #include <linux/of.h>
46*4882a593Smuzhiyun #include <linux/of_device.h>
47*4882a593Smuzhiyun #include <asm/idprom.h>
48*4882a593Smuzhiyun #include <asm/openprom.h>
49*4882a593Smuzhiyun #include <asm/oplib.h>
50*4882a593Smuzhiyun #include <asm/prom.h>
51*4882a593Smuzhiyun #include <asm/auxio.h>
52*4882a593Smuzhiyun #endif
53*4882a593Smuzhiyun #include <linux/uaccess.h>
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun #include <asm/irq.h>
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun #ifdef CONFIG_PCI
58*4882a593Smuzhiyun #include <linux/pci.h>
59*4882a593Smuzhiyun #endif
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun #include "sunhme.h"
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun #define DRV_NAME "sunhme"
64*4882a593Smuzhiyun #define DRV_VERSION "3.10"
65*4882a593Smuzhiyun #define DRV_RELDATE "August 26, 2008"
66*4882a593Smuzhiyun #define DRV_AUTHOR "David S. Miller (davem@davemloft.net)"
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun static char version[] =
69*4882a593Smuzhiyun DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " " DRV_AUTHOR "\n";
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun MODULE_VERSION(DRV_VERSION);
72*4882a593Smuzhiyun MODULE_AUTHOR(DRV_AUTHOR);
73*4882a593Smuzhiyun MODULE_DESCRIPTION("Sun HappyMealEthernet(HME) 10/100baseT ethernet driver");
74*4882a593Smuzhiyun MODULE_LICENSE("GPL");
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun static int macaddr[6];
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun /* accept MAC address of the form macaddr=0x08,0x00,0x20,0x30,0x40,0x50 */
79*4882a593Smuzhiyun module_param_array(macaddr, int, NULL, 0);
80*4882a593Smuzhiyun MODULE_PARM_DESC(macaddr, "Happy Meal MAC address to set");
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun #ifdef CONFIG_SBUS
83*4882a593Smuzhiyun static struct quattro *qfe_sbus_list;
84*4882a593Smuzhiyun #endif
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun #ifdef CONFIG_PCI
87*4882a593Smuzhiyun static struct quattro *qfe_pci_list;
88*4882a593Smuzhiyun #endif
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun #undef HMEDEBUG
91*4882a593Smuzhiyun #undef SXDEBUG
92*4882a593Smuzhiyun #undef RXDEBUG
93*4882a593Smuzhiyun #undef TXDEBUG
94*4882a593Smuzhiyun #undef TXLOGGING
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun #ifdef TXLOGGING
97*4882a593Smuzhiyun struct hme_tx_logent {
98*4882a593Smuzhiyun unsigned int tstamp;
99*4882a593Smuzhiyun int tx_new, tx_old;
100*4882a593Smuzhiyun unsigned int action;
101*4882a593Smuzhiyun #define TXLOG_ACTION_IRQ 0x01
102*4882a593Smuzhiyun #define TXLOG_ACTION_TXMIT 0x02
103*4882a593Smuzhiyun #define TXLOG_ACTION_TBUSY 0x04
104*4882a593Smuzhiyun #define TXLOG_ACTION_NBUFS 0x08
105*4882a593Smuzhiyun unsigned int status;
106*4882a593Smuzhiyun };
107*4882a593Smuzhiyun #define TX_LOG_LEN 128
108*4882a593Smuzhiyun static struct hme_tx_logent tx_log[TX_LOG_LEN];
109*4882a593Smuzhiyun static int txlog_cur_entry;
tx_add_log(struct happy_meal * hp,unsigned int a,unsigned int s)110*4882a593Smuzhiyun static __inline__ void tx_add_log(struct happy_meal *hp, unsigned int a, unsigned int s)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun struct hme_tx_logent *tlp;
113*4882a593Smuzhiyun unsigned long flags;
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun local_irq_save(flags);
116*4882a593Smuzhiyun tlp = &tx_log[txlog_cur_entry];
117*4882a593Smuzhiyun tlp->tstamp = (unsigned int)jiffies;
118*4882a593Smuzhiyun tlp->tx_new = hp->tx_new;
119*4882a593Smuzhiyun tlp->tx_old = hp->tx_old;
120*4882a593Smuzhiyun tlp->action = a;
121*4882a593Smuzhiyun tlp->status = s;
122*4882a593Smuzhiyun txlog_cur_entry = (txlog_cur_entry + 1) & (TX_LOG_LEN - 1);
123*4882a593Smuzhiyun local_irq_restore(flags);
124*4882a593Smuzhiyun }
tx_dump_log(void)125*4882a593Smuzhiyun static __inline__ void tx_dump_log(void)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun int i, this;
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun this = txlog_cur_entry;
130*4882a593Smuzhiyun for (i = 0; i < TX_LOG_LEN; i++) {
131*4882a593Smuzhiyun printk("TXLOG[%d]: j[%08x] tx[N(%d)O(%d)] action[%08x] stat[%08x]\n", i,
132*4882a593Smuzhiyun tx_log[this].tstamp,
133*4882a593Smuzhiyun tx_log[this].tx_new, tx_log[this].tx_old,
134*4882a593Smuzhiyun tx_log[this].action, tx_log[this].status);
135*4882a593Smuzhiyun this = (this + 1) & (TX_LOG_LEN - 1);
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun }
tx_dump_ring(struct happy_meal * hp)138*4882a593Smuzhiyun static __inline__ void tx_dump_ring(struct happy_meal *hp)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun struct hmeal_init_block *hb = hp->happy_block;
141*4882a593Smuzhiyun struct happy_meal_txd *tp = &hb->happy_meal_txd[0];
142*4882a593Smuzhiyun int i;
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun for (i = 0; i < TX_RING_SIZE; i+=4) {
145*4882a593Smuzhiyun printk("TXD[%d..%d]: [%08x:%08x] [%08x:%08x] [%08x:%08x] [%08x:%08x]\n",
146*4882a593Smuzhiyun i, i + 4,
147*4882a593Smuzhiyun le32_to_cpu(tp[i].tx_flags), le32_to_cpu(tp[i].tx_addr),
148*4882a593Smuzhiyun le32_to_cpu(tp[i + 1].tx_flags), le32_to_cpu(tp[i + 1].tx_addr),
149*4882a593Smuzhiyun le32_to_cpu(tp[i + 2].tx_flags), le32_to_cpu(tp[i + 2].tx_addr),
150*4882a593Smuzhiyun le32_to_cpu(tp[i + 3].tx_flags), le32_to_cpu(tp[i + 3].tx_addr));
151*4882a593Smuzhiyun }
152*4882a593Smuzhiyun }
153*4882a593Smuzhiyun #else
154*4882a593Smuzhiyun #define tx_add_log(hp, a, s) do { } while(0)
155*4882a593Smuzhiyun #define tx_dump_log() do { } while(0)
156*4882a593Smuzhiyun #define tx_dump_ring(hp) do { } while(0)
157*4882a593Smuzhiyun #endif
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun #ifdef HMEDEBUG
160*4882a593Smuzhiyun #define HMD(x) printk x
161*4882a593Smuzhiyun #else
162*4882a593Smuzhiyun #define HMD(x)
163*4882a593Smuzhiyun #endif
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun /* #define AUTO_SWITCH_DEBUG */
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun #ifdef AUTO_SWITCH_DEBUG
168*4882a593Smuzhiyun #define ASD(x) printk x
169*4882a593Smuzhiyun #else
170*4882a593Smuzhiyun #define ASD(x)
171*4882a593Smuzhiyun #endif
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun #define DEFAULT_IPG0 16 /* For lance-mode only */
174*4882a593Smuzhiyun #define DEFAULT_IPG1 8 /* For all modes */
175*4882a593Smuzhiyun #define DEFAULT_IPG2 4 /* For all modes */
176*4882a593Smuzhiyun #define DEFAULT_JAMSIZE 4 /* Toe jam */
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun /* NOTE: In the descriptor writes one _must_ write the address
179*4882a593Smuzhiyun * member _first_. The card must not be allowed to see
180*4882a593Smuzhiyun * the updated descriptor flags until the address is
181*4882a593Smuzhiyun * correct. I've added a write memory barrier between
182*4882a593Smuzhiyun * the two stores so that I can sleep well at night... -DaveM
183*4882a593Smuzhiyun */
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun #if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
sbus_hme_write32(void __iomem * reg,u32 val)186*4882a593Smuzhiyun static void sbus_hme_write32(void __iomem *reg, u32 val)
187*4882a593Smuzhiyun {
188*4882a593Smuzhiyun sbus_writel(val, reg);
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun
sbus_hme_read32(void __iomem * reg)191*4882a593Smuzhiyun static u32 sbus_hme_read32(void __iomem *reg)
192*4882a593Smuzhiyun {
193*4882a593Smuzhiyun return sbus_readl(reg);
194*4882a593Smuzhiyun }
195*4882a593Smuzhiyun
sbus_hme_write_rxd(struct happy_meal_rxd * rxd,u32 flags,u32 addr)196*4882a593Smuzhiyun static void sbus_hme_write_rxd(struct happy_meal_rxd *rxd, u32 flags, u32 addr)
197*4882a593Smuzhiyun {
198*4882a593Smuzhiyun rxd->rx_addr = (__force hme32)addr;
199*4882a593Smuzhiyun dma_wmb();
200*4882a593Smuzhiyun rxd->rx_flags = (__force hme32)flags;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun
sbus_hme_write_txd(struct happy_meal_txd * txd,u32 flags,u32 addr)203*4882a593Smuzhiyun static void sbus_hme_write_txd(struct happy_meal_txd *txd, u32 flags, u32 addr)
204*4882a593Smuzhiyun {
205*4882a593Smuzhiyun txd->tx_addr = (__force hme32)addr;
206*4882a593Smuzhiyun dma_wmb();
207*4882a593Smuzhiyun txd->tx_flags = (__force hme32)flags;
208*4882a593Smuzhiyun }
209*4882a593Smuzhiyun
sbus_hme_read_desc32(hme32 * p)210*4882a593Smuzhiyun static u32 sbus_hme_read_desc32(hme32 *p)
211*4882a593Smuzhiyun {
212*4882a593Smuzhiyun return (__force u32)*p;
213*4882a593Smuzhiyun }
214*4882a593Smuzhiyun
pci_hme_write32(void __iomem * reg,u32 val)215*4882a593Smuzhiyun static void pci_hme_write32(void __iomem *reg, u32 val)
216*4882a593Smuzhiyun {
217*4882a593Smuzhiyun writel(val, reg);
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun
pci_hme_read32(void __iomem * reg)220*4882a593Smuzhiyun static u32 pci_hme_read32(void __iomem *reg)
221*4882a593Smuzhiyun {
222*4882a593Smuzhiyun return readl(reg);
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun
pci_hme_write_rxd(struct happy_meal_rxd * rxd,u32 flags,u32 addr)225*4882a593Smuzhiyun static void pci_hme_write_rxd(struct happy_meal_rxd *rxd, u32 flags, u32 addr)
226*4882a593Smuzhiyun {
227*4882a593Smuzhiyun rxd->rx_addr = (__force hme32)cpu_to_le32(addr);
228*4882a593Smuzhiyun dma_wmb();
229*4882a593Smuzhiyun rxd->rx_flags = (__force hme32)cpu_to_le32(flags);
230*4882a593Smuzhiyun }
231*4882a593Smuzhiyun
pci_hme_write_txd(struct happy_meal_txd * txd,u32 flags,u32 addr)232*4882a593Smuzhiyun static void pci_hme_write_txd(struct happy_meal_txd *txd, u32 flags, u32 addr)
233*4882a593Smuzhiyun {
234*4882a593Smuzhiyun txd->tx_addr = (__force hme32)cpu_to_le32(addr);
235*4882a593Smuzhiyun dma_wmb();
236*4882a593Smuzhiyun txd->tx_flags = (__force hme32)cpu_to_le32(flags);
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun
pci_hme_read_desc32(hme32 * p)239*4882a593Smuzhiyun static u32 pci_hme_read_desc32(hme32 *p)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun return le32_to_cpup((__le32 *)p);
242*4882a593Smuzhiyun }
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun #define hme_write32(__hp, __reg, __val) \
245*4882a593Smuzhiyun ((__hp)->write32((__reg), (__val)))
246*4882a593Smuzhiyun #define hme_read32(__hp, __reg) \
247*4882a593Smuzhiyun ((__hp)->read32(__reg))
248*4882a593Smuzhiyun #define hme_write_rxd(__hp, __rxd, __flags, __addr) \
249*4882a593Smuzhiyun ((__hp)->write_rxd((__rxd), (__flags), (__addr)))
250*4882a593Smuzhiyun #define hme_write_txd(__hp, __txd, __flags, __addr) \
251*4882a593Smuzhiyun ((__hp)->write_txd((__txd), (__flags), (__addr)))
252*4882a593Smuzhiyun #define hme_read_desc32(__hp, __p) \
253*4882a593Smuzhiyun ((__hp)->read_desc32(__p))
254*4882a593Smuzhiyun #define hme_dma_map(__hp, __ptr, __size, __dir) \
255*4882a593Smuzhiyun ((__hp)->dma_map((__hp)->dma_dev, (__ptr), (__size), (__dir)))
256*4882a593Smuzhiyun #define hme_dma_unmap(__hp, __addr, __size, __dir) \
257*4882a593Smuzhiyun ((__hp)->dma_unmap((__hp)->dma_dev, (__addr), (__size), (__dir)))
258*4882a593Smuzhiyun #define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \
259*4882a593Smuzhiyun ((__hp)->dma_sync_for_cpu((__hp)->dma_dev, (__addr), (__size), (__dir)))
260*4882a593Smuzhiyun #define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \
261*4882a593Smuzhiyun ((__hp)->dma_sync_for_device((__hp)->dma_dev, (__addr), (__size), (__dir)))
262*4882a593Smuzhiyun #else
263*4882a593Smuzhiyun #ifdef CONFIG_SBUS
264*4882a593Smuzhiyun /* SBUS only compilation */
265*4882a593Smuzhiyun #define hme_write32(__hp, __reg, __val) \
266*4882a593Smuzhiyun sbus_writel((__val), (__reg))
267*4882a593Smuzhiyun #define hme_read32(__hp, __reg) \
268*4882a593Smuzhiyun sbus_readl(__reg)
269*4882a593Smuzhiyun #define hme_write_rxd(__hp, __rxd, __flags, __addr) \
270*4882a593Smuzhiyun do { (__rxd)->rx_addr = (__force hme32)(u32)(__addr); \
271*4882a593Smuzhiyun dma_wmb(); \
272*4882a593Smuzhiyun (__rxd)->rx_flags = (__force hme32)(u32)(__flags); \
273*4882a593Smuzhiyun } while(0)
274*4882a593Smuzhiyun #define hme_write_txd(__hp, __txd, __flags, __addr) \
275*4882a593Smuzhiyun do { (__txd)->tx_addr = (__force hme32)(u32)(__addr); \
276*4882a593Smuzhiyun dma_wmb(); \
277*4882a593Smuzhiyun (__txd)->tx_flags = (__force hme32)(u32)(__flags); \
278*4882a593Smuzhiyun } while(0)
279*4882a593Smuzhiyun #define hme_read_desc32(__hp, __p) ((__force u32)(hme32)*(__p))
280*4882a593Smuzhiyun #define hme_dma_map(__hp, __ptr, __size, __dir) \
281*4882a593Smuzhiyun dma_map_single((__hp)->dma_dev, (__ptr), (__size), (__dir))
282*4882a593Smuzhiyun #define hme_dma_unmap(__hp, __addr, __size, __dir) \
283*4882a593Smuzhiyun dma_unmap_single((__hp)->dma_dev, (__addr), (__size), (__dir))
284*4882a593Smuzhiyun #define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \
285*4882a593Smuzhiyun dma_dma_sync_single_for_cpu((__hp)->dma_dev, (__addr), (__size), (__dir))
286*4882a593Smuzhiyun #define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \
287*4882a593Smuzhiyun dma_dma_sync_single_for_device((__hp)->dma_dev, (__addr), (__size), (__dir))
288*4882a593Smuzhiyun #else
289*4882a593Smuzhiyun /* PCI only compilation */
290*4882a593Smuzhiyun #define hme_write32(__hp, __reg, __val) \
291*4882a593Smuzhiyun writel((__val), (__reg))
292*4882a593Smuzhiyun #define hme_read32(__hp, __reg) \
293*4882a593Smuzhiyun readl(__reg)
294*4882a593Smuzhiyun #define hme_write_rxd(__hp, __rxd, __flags, __addr) \
295*4882a593Smuzhiyun do { (__rxd)->rx_addr = (__force hme32)cpu_to_le32(__addr); \
296*4882a593Smuzhiyun dma_wmb(); \
297*4882a593Smuzhiyun (__rxd)->rx_flags = (__force hme32)cpu_to_le32(__flags); \
298*4882a593Smuzhiyun } while(0)
299*4882a593Smuzhiyun #define hme_write_txd(__hp, __txd, __flags, __addr) \
300*4882a593Smuzhiyun do { (__txd)->tx_addr = (__force hme32)cpu_to_le32(__addr); \
301*4882a593Smuzhiyun dma_wmb(); \
302*4882a593Smuzhiyun (__txd)->tx_flags = (__force hme32)cpu_to_le32(__flags); \
303*4882a593Smuzhiyun } while(0)
hme_read_desc32(struct happy_meal * hp,hme32 * p)304*4882a593Smuzhiyun static inline u32 hme_read_desc32(struct happy_meal *hp, hme32 *p)
305*4882a593Smuzhiyun {
306*4882a593Smuzhiyun return le32_to_cpup((__le32 *)p);
307*4882a593Smuzhiyun }
308*4882a593Smuzhiyun #define hme_dma_map(__hp, __ptr, __size, __dir) \
309*4882a593Smuzhiyun pci_map_single((__hp)->dma_dev, (__ptr), (__size), (__dir))
310*4882a593Smuzhiyun #define hme_dma_unmap(__hp, __addr, __size, __dir) \
311*4882a593Smuzhiyun pci_unmap_single((__hp)->dma_dev, (__addr), (__size), (__dir))
312*4882a593Smuzhiyun #define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \
313*4882a593Smuzhiyun pci_dma_sync_single_for_cpu((__hp)->dma_dev, (__addr), (__size), (__dir))
314*4882a593Smuzhiyun #define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \
315*4882a593Smuzhiyun pci_dma_sync_single_for_device((__hp)->dma_dev, (__addr), (__size), (__dir))
316*4882a593Smuzhiyun #endif
317*4882a593Smuzhiyun #endif
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun /* Oh yes, the MIF BitBang is mighty fun to program. BitBucket is more like it. */
BB_PUT_BIT(struct happy_meal * hp,void __iomem * tregs,int bit)321*4882a593Smuzhiyun static void BB_PUT_BIT(struct happy_meal *hp, void __iomem *tregs, int bit)
322*4882a593Smuzhiyun {
323*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBDATA, bit);
324*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBCLOCK, 0);
325*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBCLOCK, 1);
326*4882a593Smuzhiyun }
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun #if 0
329*4882a593Smuzhiyun static u32 BB_GET_BIT(struct happy_meal *hp, void __iomem *tregs, int internal)
330*4882a593Smuzhiyun {
331*4882a593Smuzhiyun u32 ret;
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBCLOCK, 0);
334*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBCLOCK, 1);
335*4882a593Smuzhiyun ret = hme_read32(hp, tregs + TCVR_CFG);
336*4882a593Smuzhiyun if (internal)
337*4882a593Smuzhiyun ret &= TCV_CFG_MDIO0;
338*4882a593Smuzhiyun else
339*4882a593Smuzhiyun ret &= TCV_CFG_MDIO1;
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun return ret;
342*4882a593Smuzhiyun }
343*4882a593Smuzhiyun #endif
344*4882a593Smuzhiyun
BB_GET_BIT2(struct happy_meal * hp,void __iomem * tregs,int internal)345*4882a593Smuzhiyun static u32 BB_GET_BIT2(struct happy_meal *hp, void __iomem *tregs, int internal)
346*4882a593Smuzhiyun {
347*4882a593Smuzhiyun u32 retval;
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBCLOCK, 0);
350*4882a593Smuzhiyun udelay(1);
351*4882a593Smuzhiyun retval = hme_read32(hp, tregs + TCVR_CFG);
352*4882a593Smuzhiyun if (internal)
353*4882a593Smuzhiyun retval &= TCV_CFG_MDIO0;
354*4882a593Smuzhiyun else
355*4882a593Smuzhiyun retval &= TCV_CFG_MDIO1;
356*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBCLOCK, 1);
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun return retval;
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun #define TCVR_FAILURE 0x80000000 /* Impossible MIF read value */
362*4882a593Smuzhiyun
happy_meal_bb_read(struct happy_meal * hp,void __iomem * tregs,int reg)363*4882a593Smuzhiyun static int happy_meal_bb_read(struct happy_meal *hp,
364*4882a593Smuzhiyun void __iomem *tregs, int reg)
365*4882a593Smuzhiyun {
366*4882a593Smuzhiyun u32 tmp;
367*4882a593Smuzhiyun int retval = 0;
368*4882a593Smuzhiyun int i;
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun ASD(("happy_meal_bb_read: reg=%d ", reg));
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun /* Enable the MIF BitBang outputs. */
373*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBOENAB, 1);
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun /* Force BitBang into the idle state. */
376*4882a593Smuzhiyun for (i = 0; i < 32; i++)
377*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 1);
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun /* Give it the read sequence. */
380*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 0);
381*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 1);
382*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 1);
383*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 0);
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun /* Give it the PHY address. */
386*4882a593Smuzhiyun tmp = hp->paddr & 0xff;
387*4882a593Smuzhiyun for (i = 4; i >= 0; i--)
388*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, ((tmp >> i) & 1));
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun /* Tell it what register we want to read. */
391*4882a593Smuzhiyun tmp = (reg & 0xff);
392*4882a593Smuzhiyun for (i = 4; i >= 0; i--)
393*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, ((tmp >> i) & 1));
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun /* Close down the MIF BitBang outputs. */
396*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBOENAB, 0);
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun /* Now read in the value. */
399*4882a593Smuzhiyun (void) BB_GET_BIT2(hp, tregs, (hp->tcvr_type == internal));
400*4882a593Smuzhiyun for (i = 15; i >= 0; i--)
401*4882a593Smuzhiyun retval |= BB_GET_BIT2(hp, tregs, (hp->tcvr_type == internal));
402*4882a593Smuzhiyun (void) BB_GET_BIT2(hp, tregs, (hp->tcvr_type == internal));
403*4882a593Smuzhiyun (void) BB_GET_BIT2(hp, tregs, (hp->tcvr_type == internal));
404*4882a593Smuzhiyun (void) BB_GET_BIT2(hp, tregs, (hp->tcvr_type == internal));
405*4882a593Smuzhiyun ASD(("value=%x\n", retval));
406*4882a593Smuzhiyun return retval;
407*4882a593Smuzhiyun }
408*4882a593Smuzhiyun
happy_meal_bb_write(struct happy_meal * hp,void __iomem * tregs,int reg,unsigned short value)409*4882a593Smuzhiyun static void happy_meal_bb_write(struct happy_meal *hp,
410*4882a593Smuzhiyun void __iomem *tregs, int reg,
411*4882a593Smuzhiyun unsigned short value)
412*4882a593Smuzhiyun {
413*4882a593Smuzhiyun u32 tmp;
414*4882a593Smuzhiyun int i;
415*4882a593Smuzhiyun
416*4882a593Smuzhiyun ASD(("happy_meal_bb_write: reg=%d value=%x\n", reg, value));
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun /* Enable the MIF BitBang outputs. */
419*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBOENAB, 1);
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun /* Force BitBang into the idle state. */
422*4882a593Smuzhiyun for (i = 0; i < 32; i++)
423*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 1);
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun /* Give it write sequence. */
426*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 0);
427*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 1);
428*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 0);
429*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 1);
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun /* Give it the PHY address. */
432*4882a593Smuzhiyun tmp = (hp->paddr & 0xff);
433*4882a593Smuzhiyun for (i = 4; i >= 0; i--)
434*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, ((tmp >> i) & 1));
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun /* Tell it what register we will be writing. */
437*4882a593Smuzhiyun tmp = (reg & 0xff);
438*4882a593Smuzhiyun for (i = 4; i >= 0; i--)
439*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, ((tmp >> i) & 1));
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun /* Tell it to become ready for the bits. */
442*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 1);
443*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, 0);
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun for (i = 15; i >= 0; i--)
446*4882a593Smuzhiyun BB_PUT_BIT(hp, tregs, ((value >> i) & 1));
447*4882a593Smuzhiyun
448*4882a593Smuzhiyun /* Close down the MIF BitBang outputs. */
449*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_BBOENAB, 0);
450*4882a593Smuzhiyun }
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun #define TCVR_READ_TRIES 16
453*4882a593Smuzhiyun
happy_meal_tcvr_read(struct happy_meal * hp,void __iomem * tregs,int reg)454*4882a593Smuzhiyun static int happy_meal_tcvr_read(struct happy_meal *hp,
455*4882a593Smuzhiyun void __iomem *tregs, int reg)
456*4882a593Smuzhiyun {
457*4882a593Smuzhiyun int tries = TCVR_READ_TRIES;
458*4882a593Smuzhiyun int retval;
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun ASD(("happy_meal_tcvr_read: reg=0x%02x ", reg));
461*4882a593Smuzhiyun if (hp->tcvr_type == none) {
462*4882a593Smuzhiyun ASD(("no transceiver, value=TCVR_FAILURE\n"));
463*4882a593Smuzhiyun return TCVR_FAILURE;
464*4882a593Smuzhiyun }
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun if (!(hp->happy_flags & HFLAG_FENABLE)) {
467*4882a593Smuzhiyun ASD(("doing bit bang\n"));
468*4882a593Smuzhiyun return happy_meal_bb_read(hp, tregs, reg);
469*4882a593Smuzhiyun }
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_FRAME,
472*4882a593Smuzhiyun (FRAME_READ | (hp->paddr << 23) | ((reg & 0xff) << 18)));
473*4882a593Smuzhiyun while (!(hme_read32(hp, tregs + TCVR_FRAME) & 0x10000) && --tries)
474*4882a593Smuzhiyun udelay(20);
475*4882a593Smuzhiyun if (!tries) {
476*4882a593Smuzhiyun printk(KERN_ERR "happy meal: Aieee, transceiver MIF read bolixed\n");
477*4882a593Smuzhiyun return TCVR_FAILURE;
478*4882a593Smuzhiyun }
479*4882a593Smuzhiyun retval = hme_read32(hp, tregs + TCVR_FRAME) & 0xffff;
480*4882a593Smuzhiyun ASD(("value=%04x\n", retval));
481*4882a593Smuzhiyun return retval;
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun #define TCVR_WRITE_TRIES 16
485*4882a593Smuzhiyun
happy_meal_tcvr_write(struct happy_meal * hp,void __iomem * tregs,int reg,unsigned short value)486*4882a593Smuzhiyun static void happy_meal_tcvr_write(struct happy_meal *hp,
487*4882a593Smuzhiyun void __iomem *tregs, int reg,
488*4882a593Smuzhiyun unsigned short value)
489*4882a593Smuzhiyun {
490*4882a593Smuzhiyun int tries = TCVR_WRITE_TRIES;
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun ASD(("happy_meal_tcvr_write: reg=0x%02x value=%04x\n", reg, value));
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun /* Welcome to Sun Microsystems, can I take your order please? */
495*4882a593Smuzhiyun if (!(hp->happy_flags & HFLAG_FENABLE)) {
496*4882a593Smuzhiyun happy_meal_bb_write(hp, tregs, reg, value);
497*4882a593Smuzhiyun return;
498*4882a593Smuzhiyun }
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun /* Would you like fries with that? */
501*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_FRAME,
502*4882a593Smuzhiyun (FRAME_WRITE | (hp->paddr << 23) |
503*4882a593Smuzhiyun ((reg & 0xff) << 18) | (value & 0xffff)));
504*4882a593Smuzhiyun while (!(hme_read32(hp, tregs + TCVR_FRAME) & 0x10000) && --tries)
505*4882a593Smuzhiyun udelay(20);
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun /* Anything else? */
508*4882a593Smuzhiyun if (!tries)
509*4882a593Smuzhiyun printk(KERN_ERR "happy meal: Aieee, transceiver MIF write bolixed\n");
510*4882a593Smuzhiyun
511*4882a593Smuzhiyun /* Fifty-two cents is your change, have a nice day. */
512*4882a593Smuzhiyun }
513*4882a593Smuzhiyun
514*4882a593Smuzhiyun /* Auto negotiation. The scheme is very simple. We have a timer routine
515*4882a593Smuzhiyun * that keeps watching the auto negotiation process as it progresses.
516*4882a593Smuzhiyun * The DP83840 is first told to start doing it's thing, we set up the time
517*4882a593Smuzhiyun * and place the timer state machine in it's initial state.
518*4882a593Smuzhiyun *
519*4882a593Smuzhiyun * Here the timer peeks at the DP83840 status registers at each click to see
520*4882a593Smuzhiyun * if the auto negotiation has completed, we assume here that the DP83840 PHY
521*4882a593Smuzhiyun * will time out at some point and just tell us what (didn't) happen. For
522*4882a593Smuzhiyun * complete coverage we only allow so many of the ticks at this level to run,
523*4882a593Smuzhiyun * when this has expired we print a warning message and try another strategy.
524*4882a593Smuzhiyun * This "other" strategy is to force the interface into various speed/duplex
525*4882a593Smuzhiyun * configurations and we stop when we see a link-up condition before the
526*4882a593Smuzhiyun * maximum number of "peek" ticks have occurred.
527*4882a593Smuzhiyun *
528*4882a593Smuzhiyun * Once a valid link status has been detected we configure the BigMAC and
529*4882a593Smuzhiyun * the rest of the Happy Meal to speak the most efficient protocol we could
530*4882a593Smuzhiyun * get a clean link for. The priority for link configurations, highest first
531*4882a593Smuzhiyun * is:
532*4882a593Smuzhiyun * 100 Base-T Full Duplex
533*4882a593Smuzhiyun * 100 Base-T Half Duplex
534*4882a593Smuzhiyun * 10 Base-T Full Duplex
535*4882a593Smuzhiyun * 10 Base-T Half Duplex
536*4882a593Smuzhiyun *
537*4882a593Smuzhiyun * We start a new timer now, after a successful auto negotiation status has
538*4882a593Smuzhiyun * been detected. This timer just waits for the link-up bit to get set in
539*4882a593Smuzhiyun * the BMCR of the DP83840. When this occurs we print a kernel log message
540*4882a593Smuzhiyun * describing the link type in use and the fact that it is up.
541*4882a593Smuzhiyun *
542*4882a593Smuzhiyun * If a fatal error of some sort is signalled and detected in the interrupt
543*4882a593Smuzhiyun * service routine, and the chip is reset, or the link is ifconfig'd down
544*4882a593Smuzhiyun * and then back up, this entire process repeats itself all over again.
545*4882a593Smuzhiyun */
try_next_permutation(struct happy_meal * hp,void __iomem * tregs)546*4882a593Smuzhiyun static int try_next_permutation(struct happy_meal *hp, void __iomem *tregs)
547*4882a593Smuzhiyun {
548*4882a593Smuzhiyun hp->sw_bmcr = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun /* Downgrade from full to half duplex. Only possible
551*4882a593Smuzhiyun * via ethtool.
552*4882a593Smuzhiyun */
553*4882a593Smuzhiyun if (hp->sw_bmcr & BMCR_FULLDPLX) {
554*4882a593Smuzhiyun hp->sw_bmcr &= ~(BMCR_FULLDPLX);
555*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR, hp->sw_bmcr);
556*4882a593Smuzhiyun return 0;
557*4882a593Smuzhiyun }
558*4882a593Smuzhiyun
559*4882a593Smuzhiyun /* Downgrade from 100 to 10. */
560*4882a593Smuzhiyun if (hp->sw_bmcr & BMCR_SPEED100) {
561*4882a593Smuzhiyun hp->sw_bmcr &= ~(BMCR_SPEED100);
562*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR, hp->sw_bmcr);
563*4882a593Smuzhiyun return 0;
564*4882a593Smuzhiyun }
565*4882a593Smuzhiyun
566*4882a593Smuzhiyun /* We've tried everything. */
567*4882a593Smuzhiyun return -1;
568*4882a593Smuzhiyun }
569*4882a593Smuzhiyun
display_link_mode(struct happy_meal * hp,void __iomem * tregs)570*4882a593Smuzhiyun static void display_link_mode(struct happy_meal *hp, void __iomem *tregs)
571*4882a593Smuzhiyun {
572*4882a593Smuzhiyun printk(KERN_INFO "%s: Link is up using ", hp->dev->name);
573*4882a593Smuzhiyun if (hp->tcvr_type == external)
574*4882a593Smuzhiyun printk("external ");
575*4882a593Smuzhiyun else
576*4882a593Smuzhiyun printk("internal ");
577*4882a593Smuzhiyun printk("transceiver at ");
578*4882a593Smuzhiyun hp->sw_lpa = happy_meal_tcvr_read(hp, tregs, MII_LPA);
579*4882a593Smuzhiyun if (hp->sw_lpa & (LPA_100HALF | LPA_100FULL)) {
580*4882a593Smuzhiyun if (hp->sw_lpa & LPA_100FULL)
581*4882a593Smuzhiyun printk("100Mb/s, Full Duplex.\n");
582*4882a593Smuzhiyun else
583*4882a593Smuzhiyun printk("100Mb/s, Half Duplex.\n");
584*4882a593Smuzhiyun } else {
585*4882a593Smuzhiyun if (hp->sw_lpa & LPA_10FULL)
586*4882a593Smuzhiyun printk("10Mb/s, Full Duplex.\n");
587*4882a593Smuzhiyun else
588*4882a593Smuzhiyun printk("10Mb/s, Half Duplex.\n");
589*4882a593Smuzhiyun }
590*4882a593Smuzhiyun }
591*4882a593Smuzhiyun
display_forced_link_mode(struct happy_meal * hp,void __iomem * tregs)592*4882a593Smuzhiyun static void display_forced_link_mode(struct happy_meal *hp, void __iomem *tregs)
593*4882a593Smuzhiyun {
594*4882a593Smuzhiyun printk(KERN_INFO "%s: Link has been forced up using ", hp->dev->name);
595*4882a593Smuzhiyun if (hp->tcvr_type == external)
596*4882a593Smuzhiyun printk("external ");
597*4882a593Smuzhiyun else
598*4882a593Smuzhiyun printk("internal ");
599*4882a593Smuzhiyun printk("transceiver at ");
600*4882a593Smuzhiyun hp->sw_bmcr = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
601*4882a593Smuzhiyun if (hp->sw_bmcr & BMCR_SPEED100)
602*4882a593Smuzhiyun printk("100Mb/s, ");
603*4882a593Smuzhiyun else
604*4882a593Smuzhiyun printk("10Mb/s, ");
605*4882a593Smuzhiyun if (hp->sw_bmcr & BMCR_FULLDPLX)
606*4882a593Smuzhiyun printk("Full Duplex.\n");
607*4882a593Smuzhiyun else
608*4882a593Smuzhiyun printk("Half Duplex.\n");
609*4882a593Smuzhiyun }
610*4882a593Smuzhiyun
set_happy_link_modes(struct happy_meal * hp,void __iomem * tregs)611*4882a593Smuzhiyun static int set_happy_link_modes(struct happy_meal *hp, void __iomem *tregs)
612*4882a593Smuzhiyun {
613*4882a593Smuzhiyun int full;
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun /* All we care about is making sure the bigmac tx_cfg has a
616*4882a593Smuzhiyun * proper duplex setting.
617*4882a593Smuzhiyun */
618*4882a593Smuzhiyun if (hp->timer_state == arbwait) {
619*4882a593Smuzhiyun hp->sw_lpa = happy_meal_tcvr_read(hp, tregs, MII_LPA);
620*4882a593Smuzhiyun if (!(hp->sw_lpa & (LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL)))
621*4882a593Smuzhiyun goto no_response;
622*4882a593Smuzhiyun if (hp->sw_lpa & LPA_100FULL)
623*4882a593Smuzhiyun full = 1;
624*4882a593Smuzhiyun else if (hp->sw_lpa & LPA_100HALF)
625*4882a593Smuzhiyun full = 0;
626*4882a593Smuzhiyun else if (hp->sw_lpa & LPA_10FULL)
627*4882a593Smuzhiyun full = 1;
628*4882a593Smuzhiyun else
629*4882a593Smuzhiyun full = 0;
630*4882a593Smuzhiyun } else {
631*4882a593Smuzhiyun /* Forcing a link mode. */
632*4882a593Smuzhiyun hp->sw_bmcr = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
633*4882a593Smuzhiyun if (hp->sw_bmcr & BMCR_FULLDPLX)
634*4882a593Smuzhiyun full = 1;
635*4882a593Smuzhiyun else
636*4882a593Smuzhiyun full = 0;
637*4882a593Smuzhiyun }
638*4882a593Smuzhiyun
639*4882a593Smuzhiyun /* Before changing other bits in the tx_cfg register, and in
640*4882a593Smuzhiyun * general any of other the TX config registers too, you
641*4882a593Smuzhiyun * must:
642*4882a593Smuzhiyun * 1) Clear Enable
643*4882a593Smuzhiyun * 2) Poll with reads until that bit reads back as zero
644*4882a593Smuzhiyun * 3) Make TX configuration changes
645*4882a593Smuzhiyun * 4) Set Enable once more
646*4882a593Smuzhiyun */
647*4882a593Smuzhiyun hme_write32(hp, hp->bigmacregs + BMAC_TXCFG,
648*4882a593Smuzhiyun hme_read32(hp, hp->bigmacregs + BMAC_TXCFG) &
649*4882a593Smuzhiyun ~(BIGMAC_TXCFG_ENABLE));
650*4882a593Smuzhiyun while (hme_read32(hp, hp->bigmacregs + BMAC_TXCFG) & BIGMAC_TXCFG_ENABLE)
651*4882a593Smuzhiyun barrier();
652*4882a593Smuzhiyun if (full) {
653*4882a593Smuzhiyun hp->happy_flags |= HFLAG_FULL;
654*4882a593Smuzhiyun hme_write32(hp, hp->bigmacregs + BMAC_TXCFG,
655*4882a593Smuzhiyun hme_read32(hp, hp->bigmacregs + BMAC_TXCFG) |
656*4882a593Smuzhiyun BIGMAC_TXCFG_FULLDPLX);
657*4882a593Smuzhiyun } else {
658*4882a593Smuzhiyun hp->happy_flags &= ~(HFLAG_FULL);
659*4882a593Smuzhiyun hme_write32(hp, hp->bigmacregs + BMAC_TXCFG,
660*4882a593Smuzhiyun hme_read32(hp, hp->bigmacregs + BMAC_TXCFG) &
661*4882a593Smuzhiyun ~(BIGMAC_TXCFG_FULLDPLX));
662*4882a593Smuzhiyun }
663*4882a593Smuzhiyun hme_write32(hp, hp->bigmacregs + BMAC_TXCFG,
664*4882a593Smuzhiyun hme_read32(hp, hp->bigmacregs + BMAC_TXCFG) |
665*4882a593Smuzhiyun BIGMAC_TXCFG_ENABLE);
666*4882a593Smuzhiyun return 0;
667*4882a593Smuzhiyun no_response:
668*4882a593Smuzhiyun return 1;
669*4882a593Smuzhiyun }
670*4882a593Smuzhiyun
671*4882a593Smuzhiyun static int happy_meal_init(struct happy_meal *hp);
672*4882a593Smuzhiyun
is_lucent_phy(struct happy_meal * hp)673*4882a593Smuzhiyun static int is_lucent_phy(struct happy_meal *hp)
674*4882a593Smuzhiyun {
675*4882a593Smuzhiyun void __iomem *tregs = hp->tcvregs;
676*4882a593Smuzhiyun unsigned short mr2, mr3;
677*4882a593Smuzhiyun int ret = 0;
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun mr2 = happy_meal_tcvr_read(hp, tregs, 2);
680*4882a593Smuzhiyun mr3 = happy_meal_tcvr_read(hp, tregs, 3);
681*4882a593Smuzhiyun if ((mr2 & 0xffff) == 0x0180 &&
682*4882a593Smuzhiyun ((mr3 & 0xffff) >> 10) == 0x1d)
683*4882a593Smuzhiyun ret = 1;
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun return ret;
686*4882a593Smuzhiyun }
687*4882a593Smuzhiyun
happy_meal_timer(struct timer_list * t)688*4882a593Smuzhiyun static void happy_meal_timer(struct timer_list *t)
689*4882a593Smuzhiyun {
690*4882a593Smuzhiyun struct happy_meal *hp = from_timer(hp, t, happy_timer);
691*4882a593Smuzhiyun void __iomem *tregs = hp->tcvregs;
692*4882a593Smuzhiyun int restart_timer = 0;
693*4882a593Smuzhiyun
694*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
695*4882a593Smuzhiyun
696*4882a593Smuzhiyun hp->timer_ticks++;
697*4882a593Smuzhiyun switch(hp->timer_state) {
698*4882a593Smuzhiyun case arbwait:
699*4882a593Smuzhiyun /* Only allow for 5 ticks, thats 10 seconds and much too
700*4882a593Smuzhiyun * long to wait for arbitration to complete.
701*4882a593Smuzhiyun */
702*4882a593Smuzhiyun if (hp->timer_ticks >= 10) {
703*4882a593Smuzhiyun /* Enter force mode. */
704*4882a593Smuzhiyun do_force_mode:
705*4882a593Smuzhiyun hp->sw_bmcr = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
706*4882a593Smuzhiyun printk(KERN_NOTICE "%s: Auto-Negotiation unsuccessful, trying force link mode\n",
707*4882a593Smuzhiyun hp->dev->name);
708*4882a593Smuzhiyun hp->sw_bmcr = BMCR_SPEED100;
709*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR, hp->sw_bmcr);
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun if (!is_lucent_phy(hp)) {
712*4882a593Smuzhiyun /* OK, seems we need do disable the transceiver for the first
713*4882a593Smuzhiyun * tick to make sure we get an accurate link state at the
714*4882a593Smuzhiyun * second tick.
715*4882a593Smuzhiyun */
716*4882a593Smuzhiyun hp->sw_csconfig = happy_meal_tcvr_read(hp, tregs, DP83840_CSCONFIG);
717*4882a593Smuzhiyun hp->sw_csconfig &= ~(CSCONFIG_TCVDISAB);
718*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, DP83840_CSCONFIG, hp->sw_csconfig);
719*4882a593Smuzhiyun }
720*4882a593Smuzhiyun hp->timer_state = ltrywait;
721*4882a593Smuzhiyun hp->timer_ticks = 0;
722*4882a593Smuzhiyun restart_timer = 1;
723*4882a593Smuzhiyun } else {
724*4882a593Smuzhiyun /* Anything interesting happen? */
725*4882a593Smuzhiyun hp->sw_bmsr = happy_meal_tcvr_read(hp, tregs, MII_BMSR);
726*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_ANEGCOMPLETE) {
727*4882a593Smuzhiyun int ret;
728*4882a593Smuzhiyun
729*4882a593Smuzhiyun /* Just what we've been waiting for... */
730*4882a593Smuzhiyun ret = set_happy_link_modes(hp, tregs);
731*4882a593Smuzhiyun if (ret) {
732*4882a593Smuzhiyun /* Ooops, something bad happened, go to force
733*4882a593Smuzhiyun * mode.
734*4882a593Smuzhiyun *
735*4882a593Smuzhiyun * XXX Broken hubs which don't support 802.3u
736*4882a593Smuzhiyun * XXX auto-negotiation make this happen as well.
737*4882a593Smuzhiyun */
738*4882a593Smuzhiyun goto do_force_mode;
739*4882a593Smuzhiyun }
740*4882a593Smuzhiyun
741*4882a593Smuzhiyun /* Success, at least so far, advance our state engine. */
742*4882a593Smuzhiyun hp->timer_state = lupwait;
743*4882a593Smuzhiyun restart_timer = 1;
744*4882a593Smuzhiyun } else {
745*4882a593Smuzhiyun restart_timer = 1;
746*4882a593Smuzhiyun }
747*4882a593Smuzhiyun }
748*4882a593Smuzhiyun break;
749*4882a593Smuzhiyun
750*4882a593Smuzhiyun case lupwait:
751*4882a593Smuzhiyun /* Auto negotiation was successful and we are awaiting a
752*4882a593Smuzhiyun * link up status. I have decided to let this timer run
753*4882a593Smuzhiyun * forever until some sort of error is signalled, reporting
754*4882a593Smuzhiyun * a message to the user at 10 second intervals.
755*4882a593Smuzhiyun */
756*4882a593Smuzhiyun hp->sw_bmsr = happy_meal_tcvr_read(hp, tregs, MII_BMSR);
757*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_LSTATUS) {
758*4882a593Smuzhiyun /* Wheee, it's up, display the link mode in use and put
759*4882a593Smuzhiyun * the timer to sleep.
760*4882a593Smuzhiyun */
761*4882a593Smuzhiyun display_link_mode(hp, tregs);
762*4882a593Smuzhiyun hp->timer_state = asleep;
763*4882a593Smuzhiyun restart_timer = 0;
764*4882a593Smuzhiyun } else {
765*4882a593Smuzhiyun if (hp->timer_ticks >= 10) {
766*4882a593Smuzhiyun printk(KERN_NOTICE "%s: Auto negotiation successful, link still "
767*4882a593Smuzhiyun "not completely up.\n", hp->dev->name);
768*4882a593Smuzhiyun hp->timer_ticks = 0;
769*4882a593Smuzhiyun restart_timer = 1;
770*4882a593Smuzhiyun } else {
771*4882a593Smuzhiyun restart_timer = 1;
772*4882a593Smuzhiyun }
773*4882a593Smuzhiyun }
774*4882a593Smuzhiyun break;
775*4882a593Smuzhiyun
776*4882a593Smuzhiyun case ltrywait:
777*4882a593Smuzhiyun /* Making the timeout here too long can make it take
778*4882a593Smuzhiyun * annoyingly long to attempt all of the link mode
779*4882a593Smuzhiyun * permutations, but then again this is essentially
780*4882a593Smuzhiyun * error recovery code for the most part.
781*4882a593Smuzhiyun */
782*4882a593Smuzhiyun hp->sw_bmsr = happy_meal_tcvr_read(hp, tregs, MII_BMSR);
783*4882a593Smuzhiyun hp->sw_csconfig = happy_meal_tcvr_read(hp, tregs, DP83840_CSCONFIG);
784*4882a593Smuzhiyun if (hp->timer_ticks == 1) {
785*4882a593Smuzhiyun if (!is_lucent_phy(hp)) {
786*4882a593Smuzhiyun /* Re-enable transceiver, we'll re-enable the transceiver next
787*4882a593Smuzhiyun * tick, then check link state on the following tick.
788*4882a593Smuzhiyun */
789*4882a593Smuzhiyun hp->sw_csconfig |= CSCONFIG_TCVDISAB;
790*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs,
791*4882a593Smuzhiyun DP83840_CSCONFIG, hp->sw_csconfig);
792*4882a593Smuzhiyun }
793*4882a593Smuzhiyun restart_timer = 1;
794*4882a593Smuzhiyun break;
795*4882a593Smuzhiyun }
796*4882a593Smuzhiyun if (hp->timer_ticks == 2) {
797*4882a593Smuzhiyun if (!is_lucent_phy(hp)) {
798*4882a593Smuzhiyun hp->sw_csconfig &= ~(CSCONFIG_TCVDISAB);
799*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs,
800*4882a593Smuzhiyun DP83840_CSCONFIG, hp->sw_csconfig);
801*4882a593Smuzhiyun }
802*4882a593Smuzhiyun restart_timer = 1;
803*4882a593Smuzhiyun break;
804*4882a593Smuzhiyun }
805*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_LSTATUS) {
806*4882a593Smuzhiyun /* Force mode selection success. */
807*4882a593Smuzhiyun display_forced_link_mode(hp, tregs);
808*4882a593Smuzhiyun set_happy_link_modes(hp, tregs); /* XXX error? then what? */
809*4882a593Smuzhiyun hp->timer_state = asleep;
810*4882a593Smuzhiyun restart_timer = 0;
811*4882a593Smuzhiyun } else {
812*4882a593Smuzhiyun if (hp->timer_ticks >= 4) { /* 6 seconds or so... */
813*4882a593Smuzhiyun int ret;
814*4882a593Smuzhiyun
815*4882a593Smuzhiyun ret = try_next_permutation(hp, tregs);
816*4882a593Smuzhiyun if (ret == -1) {
817*4882a593Smuzhiyun /* Aieee, tried them all, reset the
818*4882a593Smuzhiyun * chip and try all over again.
819*4882a593Smuzhiyun */
820*4882a593Smuzhiyun
821*4882a593Smuzhiyun /* Let the user know... */
822*4882a593Smuzhiyun printk(KERN_NOTICE "%s: Link down, cable problem?\n",
823*4882a593Smuzhiyun hp->dev->name);
824*4882a593Smuzhiyun
825*4882a593Smuzhiyun ret = happy_meal_init(hp);
826*4882a593Smuzhiyun if (ret) {
827*4882a593Smuzhiyun /* ho hum... */
828*4882a593Smuzhiyun printk(KERN_ERR "%s: Error, cannot re-init the "
829*4882a593Smuzhiyun "Happy Meal.\n", hp->dev->name);
830*4882a593Smuzhiyun }
831*4882a593Smuzhiyun goto out;
832*4882a593Smuzhiyun }
833*4882a593Smuzhiyun if (!is_lucent_phy(hp)) {
834*4882a593Smuzhiyun hp->sw_csconfig = happy_meal_tcvr_read(hp, tregs,
835*4882a593Smuzhiyun DP83840_CSCONFIG);
836*4882a593Smuzhiyun hp->sw_csconfig |= CSCONFIG_TCVDISAB;
837*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs,
838*4882a593Smuzhiyun DP83840_CSCONFIG, hp->sw_csconfig);
839*4882a593Smuzhiyun }
840*4882a593Smuzhiyun hp->timer_ticks = 0;
841*4882a593Smuzhiyun restart_timer = 1;
842*4882a593Smuzhiyun } else {
843*4882a593Smuzhiyun restart_timer = 1;
844*4882a593Smuzhiyun }
845*4882a593Smuzhiyun }
846*4882a593Smuzhiyun break;
847*4882a593Smuzhiyun
848*4882a593Smuzhiyun case asleep:
849*4882a593Smuzhiyun default:
850*4882a593Smuzhiyun /* Can't happens.... */
851*4882a593Smuzhiyun printk(KERN_ERR "%s: Aieee, link timer is asleep but we got one anyways!\n",
852*4882a593Smuzhiyun hp->dev->name);
853*4882a593Smuzhiyun restart_timer = 0;
854*4882a593Smuzhiyun hp->timer_ticks = 0;
855*4882a593Smuzhiyun hp->timer_state = asleep; /* foo on you */
856*4882a593Smuzhiyun break;
857*4882a593Smuzhiyun }
858*4882a593Smuzhiyun
859*4882a593Smuzhiyun if (restart_timer) {
860*4882a593Smuzhiyun hp->happy_timer.expires = jiffies + ((12 * HZ)/10); /* 1.2 sec. */
861*4882a593Smuzhiyun add_timer(&hp->happy_timer);
862*4882a593Smuzhiyun }
863*4882a593Smuzhiyun
864*4882a593Smuzhiyun out:
865*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
866*4882a593Smuzhiyun }
867*4882a593Smuzhiyun
868*4882a593Smuzhiyun #define TX_RESET_TRIES 32
869*4882a593Smuzhiyun #define RX_RESET_TRIES 32
870*4882a593Smuzhiyun
871*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_tx_reset(struct happy_meal * hp,void __iomem * bregs)872*4882a593Smuzhiyun static void happy_meal_tx_reset(struct happy_meal *hp, void __iomem *bregs)
873*4882a593Smuzhiyun {
874*4882a593Smuzhiyun int tries = TX_RESET_TRIES;
875*4882a593Smuzhiyun
876*4882a593Smuzhiyun HMD(("happy_meal_tx_reset: reset, "));
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun /* Would you like to try our SMCC Delux? */
879*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_TXSWRESET, 0);
880*4882a593Smuzhiyun while ((hme_read32(hp, bregs + BMAC_TXSWRESET) & 1) && --tries)
881*4882a593Smuzhiyun udelay(20);
882*4882a593Smuzhiyun
883*4882a593Smuzhiyun /* Lettuce, tomato, buggy hardware (no extra charge)? */
884*4882a593Smuzhiyun if (!tries)
885*4882a593Smuzhiyun printk(KERN_ERR "happy meal: Transceiver BigMac ATTACK!");
886*4882a593Smuzhiyun
887*4882a593Smuzhiyun /* Take care. */
888*4882a593Smuzhiyun HMD(("done\n"));
889*4882a593Smuzhiyun }
890*4882a593Smuzhiyun
891*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_rx_reset(struct happy_meal * hp,void __iomem * bregs)892*4882a593Smuzhiyun static void happy_meal_rx_reset(struct happy_meal *hp, void __iomem *bregs)
893*4882a593Smuzhiyun {
894*4882a593Smuzhiyun int tries = RX_RESET_TRIES;
895*4882a593Smuzhiyun
896*4882a593Smuzhiyun HMD(("happy_meal_rx_reset: reset, "));
897*4882a593Smuzhiyun
898*4882a593Smuzhiyun /* We have a special on GNU/Viking hardware bugs today. */
899*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_RXSWRESET, 0);
900*4882a593Smuzhiyun while ((hme_read32(hp, bregs + BMAC_RXSWRESET) & 1) && --tries)
901*4882a593Smuzhiyun udelay(20);
902*4882a593Smuzhiyun
903*4882a593Smuzhiyun /* Will that be all? */
904*4882a593Smuzhiyun if (!tries)
905*4882a593Smuzhiyun printk(KERN_ERR "happy meal: Receiver BigMac ATTACK!");
906*4882a593Smuzhiyun
907*4882a593Smuzhiyun /* Don't forget your vik_1137125_wa. Have a nice day. */
908*4882a593Smuzhiyun HMD(("done\n"));
909*4882a593Smuzhiyun }
910*4882a593Smuzhiyun
911*4882a593Smuzhiyun #define STOP_TRIES 16
912*4882a593Smuzhiyun
913*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_stop(struct happy_meal * hp,void __iomem * gregs)914*4882a593Smuzhiyun static void happy_meal_stop(struct happy_meal *hp, void __iomem *gregs)
915*4882a593Smuzhiyun {
916*4882a593Smuzhiyun int tries = STOP_TRIES;
917*4882a593Smuzhiyun
918*4882a593Smuzhiyun HMD(("happy_meal_stop: reset, "));
919*4882a593Smuzhiyun
920*4882a593Smuzhiyun /* We're consolidating our STB products, it's your lucky day. */
921*4882a593Smuzhiyun hme_write32(hp, gregs + GREG_SWRESET, GREG_RESET_ALL);
922*4882a593Smuzhiyun while (hme_read32(hp, gregs + GREG_SWRESET) && --tries)
923*4882a593Smuzhiyun udelay(20);
924*4882a593Smuzhiyun
925*4882a593Smuzhiyun /* Come back next week when we are "Sun Microelectronics". */
926*4882a593Smuzhiyun if (!tries)
927*4882a593Smuzhiyun printk(KERN_ERR "happy meal: Fry guys.");
928*4882a593Smuzhiyun
929*4882a593Smuzhiyun /* Remember: "Different name, same old buggy as shit hardware." */
930*4882a593Smuzhiyun HMD(("done\n"));
931*4882a593Smuzhiyun }
932*4882a593Smuzhiyun
933*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_get_counters(struct happy_meal * hp,void __iomem * bregs)934*4882a593Smuzhiyun static void happy_meal_get_counters(struct happy_meal *hp, void __iomem *bregs)
935*4882a593Smuzhiyun {
936*4882a593Smuzhiyun struct net_device_stats *stats = &hp->dev->stats;
937*4882a593Smuzhiyun
938*4882a593Smuzhiyun stats->rx_crc_errors += hme_read32(hp, bregs + BMAC_RCRCECTR);
939*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_RCRCECTR, 0);
940*4882a593Smuzhiyun
941*4882a593Smuzhiyun stats->rx_frame_errors += hme_read32(hp, bregs + BMAC_UNALECTR);
942*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_UNALECTR, 0);
943*4882a593Smuzhiyun
944*4882a593Smuzhiyun stats->rx_length_errors += hme_read32(hp, bregs + BMAC_GLECTR);
945*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_GLECTR, 0);
946*4882a593Smuzhiyun
947*4882a593Smuzhiyun stats->tx_aborted_errors += hme_read32(hp, bregs + BMAC_EXCTR);
948*4882a593Smuzhiyun
949*4882a593Smuzhiyun stats->collisions +=
950*4882a593Smuzhiyun (hme_read32(hp, bregs + BMAC_EXCTR) +
951*4882a593Smuzhiyun hme_read32(hp, bregs + BMAC_LTCTR));
952*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_EXCTR, 0);
953*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_LTCTR, 0);
954*4882a593Smuzhiyun }
955*4882a593Smuzhiyun
956*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_poll_stop(struct happy_meal * hp,void __iomem * tregs)957*4882a593Smuzhiyun static void happy_meal_poll_stop(struct happy_meal *hp, void __iomem *tregs)
958*4882a593Smuzhiyun {
959*4882a593Smuzhiyun ASD(("happy_meal_poll_stop: "));
960*4882a593Smuzhiyun
961*4882a593Smuzhiyun /* If polling disabled or not polling already, nothing to do. */
962*4882a593Smuzhiyun if ((hp->happy_flags & (HFLAG_POLLENABLE | HFLAG_POLL)) !=
963*4882a593Smuzhiyun (HFLAG_POLLENABLE | HFLAG_POLL)) {
964*4882a593Smuzhiyun HMD(("not polling, return\n"));
965*4882a593Smuzhiyun return;
966*4882a593Smuzhiyun }
967*4882a593Smuzhiyun
968*4882a593Smuzhiyun /* Shut up the MIF. */
969*4882a593Smuzhiyun ASD(("were polling, mif ints off, "));
970*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_IMASK, 0xffff);
971*4882a593Smuzhiyun
972*4882a593Smuzhiyun /* Turn off polling. */
973*4882a593Smuzhiyun ASD(("polling off, "));
974*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG,
975*4882a593Smuzhiyun hme_read32(hp, tregs + TCVR_CFG) & ~(TCV_CFG_PENABLE));
976*4882a593Smuzhiyun
977*4882a593Smuzhiyun /* We are no longer polling. */
978*4882a593Smuzhiyun hp->happy_flags &= ~(HFLAG_POLL);
979*4882a593Smuzhiyun
980*4882a593Smuzhiyun /* Let the bits set. */
981*4882a593Smuzhiyun udelay(200);
982*4882a593Smuzhiyun ASD(("done\n"));
983*4882a593Smuzhiyun }
984*4882a593Smuzhiyun
985*4882a593Smuzhiyun /* Only Sun can take such nice parts and fuck up the programming interface
986*4882a593Smuzhiyun * like this. Good job guys...
987*4882a593Smuzhiyun */
988*4882a593Smuzhiyun #define TCVR_RESET_TRIES 16 /* It should reset quickly */
989*4882a593Smuzhiyun #define TCVR_UNISOLATE_TRIES 32 /* Dis-isolation can take longer. */
990*4882a593Smuzhiyun
991*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_tcvr_reset(struct happy_meal * hp,void __iomem * tregs)992*4882a593Smuzhiyun static int happy_meal_tcvr_reset(struct happy_meal *hp, void __iomem *tregs)
993*4882a593Smuzhiyun {
994*4882a593Smuzhiyun u32 tconfig;
995*4882a593Smuzhiyun int result, tries = TCVR_RESET_TRIES;
996*4882a593Smuzhiyun
997*4882a593Smuzhiyun tconfig = hme_read32(hp, tregs + TCVR_CFG);
998*4882a593Smuzhiyun ASD(("happy_meal_tcvr_reset: tcfg<%08lx> ", tconfig));
999*4882a593Smuzhiyun if (hp->tcvr_type == external) {
1000*4882a593Smuzhiyun ASD(("external<"));
1001*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG, tconfig & ~(TCV_CFG_PSELECT));
1002*4882a593Smuzhiyun hp->tcvr_type = internal;
1003*4882a593Smuzhiyun hp->paddr = TCV_PADDR_ITX;
1004*4882a593Smuzhiyun ASD(("ISOLATE,"));
1005*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR,
1006*4882a593Smuzhiyun (BMCR_LOOPBACK|BMCR_PDOWN|BMCR_ISOLATE));
1007*4882a593Smuzhiyun result = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
1008*4882a593Smuzhiyun if (result == TCVR_FAILURE) {
1009*4882a593Smuzhiyun ASD(("phyread_fail>\n"));
1010*4882a593Smuzhiyun return -1;
1011*4882a593Smuzhiyun }
1012*4882a593Smuzhiyun ASD(("phyread_ok,PSELECT>"));
1013*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG, tconfig | TCV_CFG_PSELECT);
1014*4882a593Smuzhiyun hp->tcvr_type = external;
1015*4882a593Smuzhiyun hp->paddr = TCV_PADDR_ETX;
1016*4882a593Smuzhiyun } else {
1017*4882a593Smuzhiyun if (tconfig & TCV_CFG_MDIO1) {
1018*4882a593Smuzhiyun ASD(("internal<PSELECT,"));
1019*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG, (tconfig | TCV_CFG_PSELECT));
1020*4882a593Smuzhiyun ASD(("ISOLATE,"));
1021*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR,
1022*4882a593Smuzhiyun (BMCR_LOOPBACK|BMCR_PDOWN|BMCR_ISOLATE));
1023*4882a593Smuzhiyun result = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
1024*4882a593Smuzhiyun if (result == TCVR_FAILURE) {
1025*4882a593Smuzhiyun ASD(("phyread_fail>\n"));
1026*4882a593Smuzhiyun return -1;
1027*4882a593Smuzhiyun }
1028*4882a593Smuzhiyun ASD(("phyread_ok,~PSELECT>"));
1029*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG, (tconfig & ~(TCV_CFG_PSELECT)));
1030*4882a593Smuzhiyun hp->tcvr_type = internal;
1031*4882a593Smuzhiyun hp->paddr = TCV_PADDR_ITX;
1032*4882a593Smuzhiyun }
1033*4882a593Smuzhiyun }
1034*4882a593Smuzhiyun
1035*4882a593Smuzhiyun ASD(("BMCR_RESET "));
1036*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR, BMCR_RESET);
1037*4882a593Smuzhiyun
1038*4882a593Smuzhiyun while (--tries) {
1039*4882a593Smuzhiyun result = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
1040*4882a593Smuzhiyun if (result == TCVR_FAILURE)
1041*4882a593Smuzhiyun return -1;
1042*4882a593Smuzhiyun hp->sw_bmcr = result;
1043*4882a593Smuzhiyun if (!(result & BMCR_RESET))
1044*4882a593Smuzhiyun break;
1045*4882a593Smuzhiyun udelay(20);
1046*4882a593Smuzhiyun }
1047*4882a593Smuzhiyun if (!tries) {
1048*4882a593Smuzhiyun ASD(("BMCR RESET FAILED!\n"));
1049*4882a593Smuzhiyun return -1;
1050*4882a593Smuzhiyun }
1051*4882a593Smuzhiyun ASD(("RESET_OK\n"));
1052*4882a593Smuzhiyun
1053*4882a593Smuzhiyun /* Get fresh copies of the PHY registers. */
1054*4882a593Smuzhiyun hp->sw_bmsr = happy_meal_tcvr_read(hp, tregs, MII_BMSR);
1055*4882a593Smuzhiyun hp->sw_physid1 = happy_meal_tcvr_read(hp, tregs, MII_PHYSID1);
1056*4882a593Smuzhiyun hp->sw_physid2 = happy_meal_tcvr_read(hp, tregs, MII_PHYSID2);
1057*4882a593Smuzhiyun hp->sw_advertise = happy_meal_tcvr_read(hp, tregs, MII_ADVERTISE);
1058*4882a593Smuzhiyun
1059*4882a593Smuzhiyun ASD(("UNISOLATE"));
1060*4882a593Smuzhiyun hp->sw_bmcr &= ~(BMCR_ISOLATE);
1061*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR, hp->sw_bmcr);
1062*4882a593Smuzhiyun
1063*4882a593Smuzhiyun tries = TCVR_UNISOLATE_TRIES;
1064*4882a593Smuzhiyun while (--tries) {
1065*4882a593Smuzhiyun result = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
1066*4882a593Smuzhiyun if (result == TCVR_FAILURE)
1067*4882a593Smuzhiyun return -1;
1068*4882a593Smuzhiyun if (!(result & BMCR_ISOLATE))
1069*4882a593Smuzhiyun break;
1070*4882a593Smuzhiyun udelay(20);
1071*4882a593Smuzhiyun }
1072*4882a593Smuzhiyun if (!tries) {
1073*4882a593Smuzhiyun ASD((" FAILED!\n"));
1074*4882a593Smuzhiyun return -1;
1075*4882a593Smuzhiyun }
1076*4882a593Smuzhiyun ASD((" SUCCESS and CSCONFIG_DFBYPASS\n"));
1077*4882a593Smuzhiyun if (!is_lucent_phy(hp)) {
1078*4882a593Smuzhiyun result = happy_meal_tcvr_read(hp, tregs,
1079*4882a593Smuzhiyun DP83840_CSCONFIG);
1080*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs,
1081*4882a593Smuzhiyun DP83840_CSCONFIG, (result | CSCONFIG_DFBYPASS));
1082*4882a593Smuzhiyun }
1083*4882a593Smuzhiyun return 0;
1084*4882a593Smuzhiyun }
1085*4882a593Smuzhiyun
1086*4882a593Smuzhiyun /* Figure out whether we have an internal or external transceiver.
1087*4882a593Smuzhiyun *
1088*4882a593Smuzhiyun * hp->happy_lock must be held
1089*4882a593Smuzhiyun */
happy_meal_transceiver_check(struct happy_meal * hp,void __iomem * tregs)1090*4882a593Smuzhiyun static void happy_meal_transceiver_check(struct happy_meal *hp, void __iomem *tregs)
1091*4882a593Smuzhiyun {
1092*4882a593Smuzhiyun unsigned long tconfig = hme_read32(hp, tregs + TCVR_CFG);
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun ASD(("happy_meal_transceiver_check: tcfg=%08lx ", tconfig));
1095*4882a593Smuzhiyun if (hp->happy_flags & HFLAG_POLL) {
1096*4882a593Smuzhiyun /* If we are polling, we must stop to get the transceiver type. */
1097*4882a593Smuzhiyun ASD(("<polling> "));
1098*4882a593Smuzhiyun if (hp->tcvr_type == internal) {
1099*4882a593Smuzhiyun if (tconfig & TCV_CFG_MDIO1) {
1100*4882a593Smuzhiyun ASD(("<internal> <poll stop> "));
1101*4882a593Smuzhiyun happy_meal_poll_stop(hp, tregs);
1102*4882a593Smuzhiyun hp->paddr = TCV_PADDR_ETX;
1103*4882a593Smuzhiyun hp->tcvr_type = external;
1104*4882a593Smuzhiyun ASD(("<external>\n"));
1105*4882a593Smuzhiyun tconfig &= ~(TCV_CFG_PENABLE);
1106*4882a593Smuzhiyun tconfig |= TCV_CFG_PSELECT;
1107*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG, tconfig);
1108*4882a593Smuzhiyun }
1109*4882a593Smuzhiyun } else {
1110*4882a593Smuzhiyun if (hp->tcvr_type == external) {
1111*4882a593Smuzhiyun ASD(("<external> "));
1112*4882a593Smuzhiyun if (!(hme_read32(hp, tregs + TCVR_STATUS) >> 16)) {
1113*4882a593Smuzhiyun ASD(("<poll stop> "));
1114*4882a593Smuzhiyun happy_meal_poll_stop(hp, tregs);
1115*4882a593Smuzhiyun hp->paddr = TCV_PADDR_ITX;
1116*4882a593Smuzhiyun hp->tcvr_type = internal;
1117*4882a593Smuzhiyun ASD(("<internal>\n"));
1118*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG,
1119*4882a593Smuzhiyun hme_read32(hp, tregs + TCVR_CFG) &
1120*4882a593Smuzhiyun ~(TCV_CFG_PSELECT));
1121*4882a593Smuzhiyun }
1122*4882a593Smuzhiyun ASD(("\n"));
1123*4882a593Smuzhiyun } else {
1124*4882a593Smuzhiyun ASD(("<none>\n"));
1125*4882a593Smuzhiyun }
1126*4882a593Smuzhiyun }
1127*4882a593Smuzhiyun } else {
1128*4882a593Smuzhiyun u32 reread = hme_read32(hp, tregs + TCVR_CFG);
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun /* Else we can just work off of the MDIO bits. */
1131*4882a593Smuzhiyun ASD(("<not polling> "));
1132*4882a593Smuzhiyun if (reread & TCV_CFG_MDIO1) {
1133*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG, tconfig | TCV_CFG_PSELECT);
1134*4882a593Smuzhiyun hp->paddr = TCV_PADDR_ETX;
1135*4882a593Smuzhiyun hp->tcvr_type = external;
1136*4882a593Smuzhiyun ASD(("<external>\n"));
1137*4882a593Smuzhiyun } else {
1138*4882a593Smuzhiyun if (reread & TCV_CFG_MDIO0) {
1139*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG,
1140*4882a593Smuzhiyun tconfig & ~(TCV_CFG_PSELECT));
1141*4882a593Smuzhiyun hp->paddr = TCV_PADDR_ITX;
1142*4882a593Smuzhiyun hp->tcvr_type = internal;
1143*4882a593Smuzhiyun ASD(("<internal>\n"));
1144*4882a593Smuzhiyun } else {
1145*4882a593Smuzhiyun printk(KERN_ERR "happy meal: Transceiver and a coke please.");
1146*4882a593Smuzhiyun hp->tcvr_type = none; /* Grrr... */
1147*4882a593Smuzhiyun ASD(("<none>\n"));
1148*4882a593Smuzhiyun }
1149*4882a593Smuzhiyun }
1150*4882a593Smuzhiyun }
1151*4882a593Smuzhiyun }
1152*4882a593Smuzhiyun
1153*4882a593Smuzhiyun /* The receive ring buffers are a bit tricky to get right. Here goes...
1154*4882a593Smuzhiyun *
1155*4882a593Smuzhiyun * The buffers we dma into must be 64 byte aligned. So we use a special
1156*4882a593Smuzhiyun * alloc_skb() routine for the happy meal to allocate 64 bytes more than
1157*4882a593Smuzhiyun * we really need.
1158*4882a593Smuzhiyun *
1159*4882a593Smuzhiyun * We use skb_reserve() to align the data block we get in the skb. We
1160*4882a593Smuzhiyun * also program the etxregs->cfg register to use an offset of 2. This
1161*4882a593Smuzhiyun * imperical constant plus the ethernet header size will always leave
1162*4882a593Smuzhiyun * us with a nicely aligned ip header once we pass things up to the
1163*4882a593Smuzhiyun * protocol layers.
1164*4882a593Smuzhiyun *
1165*4882a593Smuzhiyun * The numbers work out to:
1166*4882a593Smuzhiyun *
1167*4882a593Smuzhiyun * Max ethernet frame size 1518
1168*4882a593Smuzhiyun * Ethernet header size 14
1169*4882a593Smuzhiyun * Happy Meal base offset 2
1170*4882a593Smuzhiyun *
1171*4882a593Smuzhiyun * Say a skb data area is at 0xf001b010, and its size alloced is
1172*4882a593Smuzhiyun * (ETH_FRAME_LEN + 64 + 2) = (1514 + 64 + 2) = 1580 bytes.
1173*4882a593Smuzhiyun *
1174*4882a593Smuzhiyun * First our alloc_skb() routine aligns the data base to a 64 byte
1175*4882a593Smuzhiyun * boundary. We now have 0xf001b040 as our skb data address. We
1176*4882a593Smuzhiyun * plug this into the receive descriptor address.
1177*4882a593Smuzhiyun *
1178*4882a593Smuzhiyun * Next, we skb_reserve() 2 bytes to account for the Happy Meal offset.
1179*4882a593Smuzhiyun * So now the data we will end up looking at starts at 0xf001b042. When
1180*4882a593Smuzhiyun * the packet arrives, we will check out the size received and subtract
1181*4882a593Smuzhiyun * this from the skb->length. Then we just pass the packet up to the
1182*4882a593Smuzhiyun * protocols as is, and allocate a new skb to replace this slot we have
1183*4882a593Smuzhiyun * just received from.
1184*4882a593Smuzhiyun *
1185*4882a593Smuzhiyun * The ethernet layer will strip the ether header from the front of the
1186*4882a593Smuzhiyun * skb we just sent to it, this leaves us with the ip header sitting
1187*4882a593Smuzhiyun * nicely aligned at 0xf001b050. Also, for tcp and udp packets the
1188*4882a593Smuzhiyun * Happy Meal has even checksummed the tcp/udp data for us. The 16
1189*4882a593Smuzhiyun * bit checksum is obtained from the low bits of the receive descriptor
1190*4882a593Smuzhiyun * flags, thus:
1191*4882a593Smuzhiyun *
1192*4882a593Smuzhiyun * skb->csum = rxd->rx_flags & 0xffff;
1193*4882a593Smuzhiyun * skb->ip_summed = CHECKSUM_COMPLETE;
1194*4882a593Smuzhiyun *
1195*4882a593Smuzhiyun * before sending off the skb to the protocols, and we are good as gold.
1196*4882a593Smuzhiyun */
happy_meal_clean_rings(struct happy_meal * hp)1197*4882a593Smuzhiyun static void happy_meal_clean_rings(struct happy_meal *hp)
1198*4882a593Smuzhiyun {
1199*4882a593Smuzhiyun int i;
1200*4882a593Smuzhiyun
1201*4882a593Smuzhiyun for (i = 0; i < RX_RING_SIZE; i++) {
1202*4882a593Smuzhiyun if (hp->rx_skbs[i] != NULL) {
1203*4882a593Smuzhiyun struct sk_buff *skb = hp->rx_skbs[i];
1204*4882a593Smuzhiyun struct happy_meal_rxd *rxd;
1205*4882a593Smuzhiyun u32 dma_addr;
1206*4882a593Smuzhiyun
1207*4882a593Smuzhiyun rxd = &hp->happy_block->happy_meal_rxd[i];
1208*4882a593Smuzhiyun dma_addr = hme_read_desc32(hp, &rxd->rx_addr);
1209*4882a593Smuzhiyun dma_unmap_single(hp->dma_dev, dma_addr,
1210*4882a593Smuzhiyun RX_BUF_ALLOC_SIZE, DMA_FROM_DEVICE);
1211*4882a593Smuzhiyun dev_kfree_skb_any(skb);
1212*4882a593Smuzhiyun hp->rx_skbs[i] = NULL;
1213*4882a593Smuzhiyun }
1214*4882a593Smuzhiyun }
1215*4882a593Smuzhiyun
1216*4882a593Smuzhiyun for (i = 0; i < TX_RING_SIZE; i++) {
1217*4882a593Smuzhiyun if (hp->tx_skbs[i] != NULL) {
1218*4882a593Smuzhiyun struct sk_buff *skb = hp->tx_skbs[i];
1219*4882a593Smuzhiyun struct happy_meal_txd *txd;
1220*4882a593Smuzhiyun u32 dma_addr;
1221*4882a593Smuzhiyun int frag;
1222*4882a593Smuzhiyun
1223*4882a593Smuzhiyun hp->tx_skbs[i] = NULL;
1224*4882a593Smuzhiyun
1225*4882a593Smuzhiyun for (frag = 0; frag <= skb_shinfo(skb)->nr_frags; frag++) {
1226*4882a593Smuzhiyun txd = &hp->happy_block->happy_meal_txd[i];
1227*4882a593Smuzhiyun dma_addr = hme_read_desc32(hp, &txd->tx_addr);
1228*4882a593Smuzhiyun if (!frag)
1229*4882a593Smuzhiyun dma_unmap_single(hp->dma_dev, dma_addr,
1230*4882a593Smuzhiyun (hme_read_desc32(hp, &txd->tx_flags)
1231*4882a593Smuzhiyun & TXFLAG_SIZE),
1232*4882a593Smuzhiyun DMA_TO_DEVICE);
1233*4882a593Smuzhiyun else
1234*4882a593Smuzhiyun dma_unmap_page(hp->dma_dev, dma_addr,
1235*4882a593Smuzhiyun (hme_read_desc32(hp, &txd->tx_flags)
1236*4882a593Smuzhiyun & TXFLAG_SIZE),
1237*4882a593Smuzhiyun DMA_TO_DEVICE);
1238*4882a593Smuzhiyun
1239*4882a593Smuzhiyun if (frag != skb_shinfo(skb)->nr_frags)
1240*4882a593Smuzhiyun i++;
1241*4882a593Smuzhiyun }
1242*4882a593Smuzhiyun
1243*4882a593Smuzhiyun dev_kfree_skb_any(skb);
1244*4882a593Smuzhiyun }
1245*4882a593Smuzhiyun }
1246*4882a593Smuzhiyun }
1247*4882a593Smuzhiyun
1248*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_init_rings(struct happy_meal * hp)1249*4882a593Smuzhiyun static void happy_meal_init_rings(struct happy_meal *hp)
1250*4882a593Smuzhiyun {
1251*4882a593Smuzhiyun struct hmeal_init_block *hb = hp->happy_block;
1252*4882a593Smuzhiyun int i;
1253*4882a593Smuzhiyun
1254*4882a593Smuzhiyun HMD(("happy_meal_init_rings: counters to zero, "));
1255*4882a593Smuzhiyun hp->rx_new = hp->rx_old = hp->tx_new = hp->tx_old = 0;
1256*4882a593Smuzhiyun
1257*4882a593Smuzhiyun /* Free any skippy bufs left around in the rings. */
1258*4882a593Smuzhiyun HMD(("clean, "));
1259*4882a593Smuzhiyun happy_meal_clean_rings(hp);
1260*4882a593Smuzhiyun
1261*4882a593Smuzhiyun /* Now get new skippy bufs for the receive ring. */
1262*4882a593Smuzhiyun HMD(("init rxring, "));
1263*4882a593Smuzhiyun for (i = 0; i < RX_RING_SIZE; i++) {
1264*4882a593Smuzhiyun struct sk_buff *skb;
1265*4882a593Smuzhiyun u32 mapping;
1266*4882a593Smuzhiyun
1267*4882a593Smuzhiyun skb = happy_meal_alloc_skb(RX_BUF_ALLOC_SIZE, GFP_ATOMIC);
1268*4882a593Smuzhiyun if (!skb) {
1269*4882a593Smuzhiyun hme_write_rxd(hp, &hb->happy_meal_rxd[i], 0, 0);
1270*4882a593Smuzhiyun continue;
1271*4882a593Smuzhiyun }
1272*4882a593Smuzhiyun hp->rx_skbs[i] = skb;
1273*4882a593Smuzhiyun
1274*4882a593Smuzhiyun /* Because we reserve afterwards. */
1275*4882a593Smuzhiyun skb_put(skb, (ETH_FRAME_LEN + RX_OFFSET + 4));
1276*4882a593Smuzhiyun mapping = dma_map_single(hp->dma_dev, skb->data, RX_BUF_ALLOC_SIZE,
1277*4882a593Smuzhiyun DMA_FROM_DEVICE);
1278*4882a593Smuzhiyun if (dma_mapping_error(hp->dma_dev, mapping)) {
1279*4882a593Smuzhiyun dev_kfree_skb_any(skb);
1280*4882a593Smuzhiyun hme_write_rxd(hp, &hb->happy_meal_rxd[i], 0, 0);
1281*4882a593Smuzhiyun continue;
1282*4882a593Smuzhiyun }
1283*4882a593Smuzhiyun hme_write_rxd(hp, &hb->happy_meal_rxd[i],
1284*4882a593Smuzhiyun (RXFLAG_OWN | ((RX_BUF_ALLOC_SIZE - RX_OFFSET) << 16)),
1285*4882a593Smuzhiyun mapping);
1286*4882a593Smuzhiyun skb_reserve(skb, RX_OFFSET);
1287*4882a593Smuzhiyun }
1288*4882a593Smuzhiyun
1289*4882a593Smuzhiyun HMD(("init txring, "));
1290*4882a593Smuzhiyun for (i = 0; i < TX_RING_SIZE; i++)
1291*4882a593Smuzhiyun hme_write_txd(hp, &hb->happy_meal_txd[i], 0, 0);
1292*4882a593Smuzhiyun
1293*4882a593Smuzhiyun HMD(("done\n"));
1294*4882a593Smuzhiyun }
1295*4882a593Smuzhiyun
1296*4882a593Smuzhiyun /* hp->happy_lock must be held */
1297*4882a593Smuzhiyun static void
happy_meal_begin_auto_negotiation(struct happy_meal * hp,void __iomem * tregs,const struct ethtool_link_ksettings * ep)1298*4882a593Smuzhiyun happy_meal_begin_auto_negotiation(struct happy_meal *hp,
1299*4882a593Smuzhiyun void __iomem *tregs,
1300*4882a593Smuzhiyun const struct ethtool_link_ksettings *ep)
1301*4882a593Smuzhiyun {
1302*4882a593Smuzhiyun int timeout;
1303*4882a593Smuzhiyun
1304*4882a593Smuzhiyun /* Read all of the registers we are interested in now. */
1305*4882a593Smuzhiyun hp->sw_bmsr = happy_meal_tcvr_read(hp, tregs, MII_BMSR);
1306*4882a593Smuzhiyun hp->sw_bmcr = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
1307*4882a593Smuzhiyun hp->sw_physid1 = happy_meal_tcvr_read(hp, tregs, MII_PHYSID1);
1308*4882a593Smuzhiyun hp->sw_physid2 = happy_meal_tcvr_read(hp, tregs, MII_PHYSID2);
1309*4882a593Smuzhiyun
1310*4882a593Smuzhiyun /* XXX Check BMSR_ANEGCAPABLE, should not be necessary though. */
1311*4882a593Smuzhiyun
1312*4882a593Smuzhiyun hp->sw_advertise = happy_meal_tcvr_read(hp, tregs, MII_ADVERTISE);
1313*4882a593Smuzhiyun if (!ep || ep->base.autoneg == AUTONEG_ENABLE) {
1314*4882a593Smuzhiyun /* Advertise everything we can support. */
1315*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_10HALF)
1316*4882a593Smuzhiyun hp->sw_advertise |= (ADVERTISE_10HALF);
1317*4882a593Smuzhiyun else
1318*4882a593Smuzhiyun hp->sw_advertise &= ~(ADVERTISE_10HALF);
1319*4882a593Smuzhiyun
1320*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_10FULL)
1321*4882a593Smuzhiyun hp->sw_advertise |= (ADVERTISE_10FULL);
1322*4882a593Smuzhiyun else
1323*4882a593Smuzhiyun hp->sw_advertise &= ~(ADVERTISE_10FULL);
1324*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_100HALF)
1325*4882a593Smuzhiyun hp->sw_advertise |= (ADVERTISE_100HALF);
1326*4882a593Smuzhiyun else
1327*4882a593Smuzhiyun hp->sw_advertise &= ~(ADVERTISE_100HALF);
1328*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_100FULL)
1329*4882a593Smuzhiyun hp->sw_advertise |= (ADVERTISE_100FULL);
1330*4882a593Smuzhiyun else
1331*4882a593Smuzhiyun hp->sw_advertise &= ~(ADVERTISE_100FULL);
1332*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_ADVERTISE, hp->sw_advertise);
1333*4882a593Smuzhiyun
1334*4882a593Smuzhiyun /* XXX Currently no Happy Meal cards I know off support 100BaseT4,
1335*4882a593Smuzhiyun * XXX and this is because the DP83840 does not support it, changes
1336*4882a593Smuzhiyun * XXX would need to be made to the tx/rx logic in the driver as well
1337*4882a593Smuzhiyun * XXX so I completely skip checking for it in the BMSR for now.
1338*4882a593Smuzhiyun */
1339*4882a593Smuzhiyun
1340*4882a593Smuzhiyun #ifdef AUTO_SWITCH_DEBUG
1341*4882a593Smuzhiyun ASD(("%s: Advertising [ ", hp->dev->name));
1342*4882a593Smuzhiyun if (hp->sw_advertise & ADVERTISE_10HALF)
1343*4882a593Smuzhiyun ASD(("10H "));
1344*4882a593Smuzhiyun if (hp->sw_advertise & ADVERTISE_10FULL)
1345*4882a593Smuzhiyun ASD(("10F "));
1346*4882a593Smuzhiyun if (hp->sw_advertise & ADVERTISE_100HALF)
1347*4882a593Smuzhiyun ASD(("100H "));
1348*4882a593Smuzhiyun if (hp->sw_advertise & ADVERTISE_100FULL)
1349*4882a593Smuzhiyun ASD(("100F "));
1350*4882a593Smuzhiyun #endif
1351*4882a593Smuzhiyun
1352*4882a593Smuzhiyun /* Enable Auto-Negotiation, this is usually on already... */
1353*4882a593Smuzhiyun hp->sw_bmcr |= BMCR_ANENABLE;
1354*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR, hp->sw_bmcr);
1355*4882a593Smuzhiyun
1356*4882a593Smuzhiyun /* Restart it to make sure it is going. */
1357*4882a593Smuzhiyun hp->sw_bmcr |= BMCR_ANRESTART;
1358*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR, hp->sw_bmcr);
1359*4882a593Smuzhiyun
1360*4882a593Smuzhiyun /* BMCR_ANRESTART self clears when the process has begun. */
1361*4882a593Smuzhiyun
1362*4882a593Smuzhiyun timeout = 64; /* More than enough. */
1363*4882a593Smuzhiyun while (--timeout) {
1364*4882a593Smuzhiyun hp->sw_bmcr = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
1365*4882a593Smuzhiyun if (!(hp->sw_bmcr & BMCR_ANRESTART))
1366*4882a593Smuzhiyun break; /* got it. */
1367*4882a593Smuzhiyun udelay(10);
1368*4882a593Smuzhiyun }
1369*4882a593Smuzhiyun if (!timeout) {
1370*4882a593Smuzhiyun printk(KERN_ERR "%s: Happy Meal would not start auto negotiation "
1371*4882a593Smuzhiyun "BMCR=0x%04x\n", hp->dev->name, hp->sw_bmcr);
1372*4882a593Smuzhiyun printk(KERN_NOTICE "%s: Performing force link detection.\n",
1373*4882a593Smuzhiyun hp->dev->name);
1374*4882a593Smuzhiyun goto force_link;
1375*4882a593Smuzhiyun } else {
1376*4882a593Smuzhiyun hp->timer_state = arbwait;
1377*4882a593Smuzhiyun }
1378*4882a593Smuzhiyun } else {
1379*4882a593Smuzhiyun force_link:
1380*4882a593Smuzhiyun /* Force the link up, trying first a particular mode.
1381*4882a593Smuzhiyun * Either we are here at the request of ethtool or
1382*4882a593Smuzhiyun * because the Happy Meal would not start to autoneg.
1383*4882a593Smuzhiyun */
1384*4882a593Smuzhiyun
1385*4882a593Smuzhiyun /* Disable auto-negotiation in BMCR, enable the duplex and
1386*4882a593Smuzhiyun * speed setting, init the timer state machine, and fire it off.
1387*4882a593Smuzhiyun */
1388*4882a593Smuzhiyun if (!ep || ep->base.autoneg == AUTONEG_ENABLE) {
1389*4882a593Smuzhiyun hp->sw_bmcr = BMCR_SPEED100;
1390*4882a593Smuzhiyun } else {
1391*4882a593Smuzhiyun if (ep->base.speed == SPEED_100)
1392*4882a593Smuzhiyun hp->sw_bmcr = BMCR_SPEED100;
1393*4882a593Smuzhiyun else
1394*4882a593Smuzhiyun hp->sw_bmcr = 0;
1395*4882a593Smuzhiyun if (ep->base.duplex == DUPLEX_FULL)
1396*4882a593Smuzhiyun hp->sw_bmcr |= BMCR_FULLDPLX;
1397*4882a593Smuzhiyun }
1398*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR, hp->sw_bmcr);
1399*4882a593Smuzhiyun
1400*4882a593Smuzhiyun if (!is_lucent_phy(hp)) {
1401*4882a593Smuzhiyun /* OK, seems we need do disable the transceiver for the first
1402*4882a593Smuzhiyun * tick to make sure we get an accurate link state at the
1403*4882a593Smuzhiyun * second tick.
1404*4882a593Smuzhiyun */
1405*4882a593Smuzhiyun hp->sw_csconfig = happy_meal_tcvr_read(hp, tregs,
1406*4882a593Smuzhiyun DP83840_CSCONFIG);
1407*4882a593Smuzhiyun hp->sw_csconfig &= ~(CSCONFIG_TCVDISAB);
1408*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, DP83840_CSCONFIG,
1409*4882a593Smuzhiyun hp->sw_csconfig);
1410*4882a593Smuzhiyun }
1411*4882a593Smuzhiyun hp->timer_state = ltrywait;
1412*4882a593Smuzhiyun }
1413*4882a593Smuzhiyun
1414*4882a593Smuzhiyun hp->timer_ticks = 0;
1415*4882a593Smuzhiyun hp->happy_timer.expires = jiffies + (12 * HZ)/10; /* 1.2 sec. */
1416*4882a593Smuzhiyun add_timer(&hp->happy_timer);
1417*4882a593Smuzhiyun }
1418*4882a593Smuzhiyun
1419*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_init(struct happy_meal * hp)1420*4882a593Smuzhiyun static int happy_meal_init(struct happy_meal *hp)
1421*4882a593Smuzhiyun {
1422*4882a593Smuzhiyun void __iomem *gregs = hp->gregs;
1423*4882a593Smuzhiyun void __iomem *etxregs = hp->etxregs;
1424*4882a593Smuzhiyun void __iomem *erxregs = hp->erxregs;
1425*4882a593Smuzhiyun void __iomem *bregs = hp->bigmacregs;
1426*4882a593Smuzhiyun void __iomem *tregs = hp->tcvregs;
1427*4882a593Smuzhiyun u32 regtmp, rxcfg;
1428*4882a593Smuzhiyun unsigned char *e = &hp->dev->dev_addr[0];
1429*4882a593Smuzhiyun
1430*4882a593Smuzhiyun /* If auto-negotiation timer is running, kill it. */
1431*4882a593Smuzhiyun del_timer(&hp->happy_timer);
1432*4882a593Smuzhiyun
1433*4882a593Smuzhiyun HMD(("happy_meal_init: happy_flags[%08x] ",
1434*4882a593Smuzhiyun hp->happy_flags));
1435*4882a593Smuzhiyun if (!(hp->happy_flags & HFLAG_INIT)) {
1436*4882a593Smuzhiyun HMD(("set HFLAG_INIT, "));
1437*4882a593Smuzhiyun hp->happy_flags |= HFLAG_INIT;
1438*4882a593Smuzhiyun happy_meal_get_counters(hp, bregs);
1439*4882a593Smuzhiyun }
1440*4882a593Smuzhiyun
1441*4882a593Smuzhiyun /* Stop polling. */
1442*4882a593Smuzhiyun HMD(("to happy_meal_poll_stop\n"));
1443*4882a593Smuzhiyun happy_meal_poll_stop(hp, tregs);
1444*4882a593Smuzhiyun
1445*4882a593Smuzhiyun /* Stop transmitter and receiver. */
1446*4882a593Smuzhiyun HMD(("happy_meal_init: to happy_meal_stop\n"));
1447*4882a593Smuzhiyun happy_meal_stop(hp, gregs);
1448*4882a593Smuzhiyun
1449*4882a593Smuzhiyun /* Alloc and reset the tx/rx descriptor chains. */
1450*4882a593Smuzhiyun HMD(("happy_meal_init: to happy_meal_init_rings\n"));
1451*4882a593Smuzhiyun happy_meal_init_rings(hp);
1452*4882a593Smuzhiyun
1453*4882a593Smuzhiyun /* Shut up the MIF. */
1454*4882a593Smuzhiyun HMD(("happy_meal_init: Disable all MIF irqs (old[%08x]), ",
1455*4882a593Smuzhiyun hme_read32(hp, tregs + TCVR_IMASK)));
1456*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_IMASK, 0xffff);
1457*4882a593Smuzhiyun
1458*4882a593Smuzhiyun /* See if we can enable the MIF frame on this card to speak to the DP83840. */
1459*4882a593Smuzhiyun if (hp->happy_flags & HFLAG_FENABLE) {
1460*4882a593Smuzhiyun HMD(("use frame old[%08x], ",
1461*4882a593Smuzhiyun hme_read32(hp, tregs + TCVR_CFG)));
1462*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG,
1463*4882a593Smuzhiyun hme_read32(hp, tregs + TCVR_CFG) & ~(TCV_CFG_BENABLE));
1464*4882a593Smuzhiyun } else {
1465*4882a593Smuzhiyun HMD(("use bitbang old[%08x], ",
1466*4882a593Smuzhiyun hme_read32(hp, tregs + TCVR_CFG)));
1467*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG,
1468*4882a593Smuzhiyun hme_read32(hp, tregs + TCVR_CFG) | TCV_CFG_BENABLE);
1469*4882a593Smuzhiyun }
1470*4882a593Smuzhiyun
1471*4882a593Smuzhiyun /* Check the state of the transceiver. */
1472*4882a593Smuzhiyun HMD(("to happy_meal_transceiver_check\n"));
1473*4882a593Smuzhiyun happy_meal_transceiver_check(hp, tregs);
1474*4882a593Smuzhiyun
1475*4882a593Smuzhiyun /* Put the Big Mac into a sane state. */
1476*4882a593Smuzhiyun HMD(("happy_meal_init: "));
1477*4882a593Smuzhiyun switch(hp->tcvr_type) {
1478*4882a593Smuzhiyun case none:
1479*4882a593Smuzhiyun /* Cannot operate if we don't know the transceiver type! */
1480*4882a593Smuzhiyun HMD(("AAIEEE no transceiver type, EAGAIN"));
1481*4882a593Smuzhiyun return -EAGAIN;
1482*4882a593Smuzhiyun
1483*4882a593Smuzhiyun case internal:
1484*4882a593Smuzhiyun /* Using the MII buffers. */
1485*4882a593Smuzhiyun HMD(("internal, using MII, "));
1486*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_XIFCFG, 0);
1487*4882a593Smuzhiyun break;
1488*4882a593Smuzhiyun
1489*4882a593Smuzhiyun case external:
1490*4882a593Smuzhiyun /* Not using the MII, disable it. */
1491*4882a593Smuzhiyun HMD(("external, disable MII, "));
1492*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_XIFCFG, BIGMAC_XCFG_MIIDISAB);
1493*4882a593Smuzhiyun break;
1494*4882a593Smuzhiyun }
1495*4882a593Smuzhiyun
1496*4882a593Smuzhiyun if (happy_meal_tcvr_reset(hp, tregs))
1497*4882a593Smuzhiyun return -EAGAIN;
1498*4882a593Smuzhiyun
1499*4882a593Smuzhiyun /* Reset the Happy Meal Big Mac transceiver and the receiver. */
1500*4882a593Smuzhiyun HMD(("tx/rx reset, "));
1501*4882a593Smuzhiyun happy_meal_tx_reset(hp, bregs);
1502*4882a593Smuzhiyun happy_meal_rx_reset(hp, bregs);
1503*4882a593Smuzhiyun
1504*4882a593Smuzhiyun /* Set jam size and inter-packet gaps to reasonable defaults. */
1505*4882a593Smuzhiyun HMD(("jsize/ipg1/ipg2, "));
1506*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_JSIZE, DEFAULT_JAMSIZE);
1507*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_IGAP1, DEFAULT_IPG1);
1508*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_IGAP2, DEFAULT_IPG2);
1509*4882a593Smuzhiyun
1510*4882a593Smuzhiyun /* Load up the MAC address and random seed. */
1511*4882a593Smuzhiyun HMD(("rseed/macaddr, "));
1512*4882a593Smuzhiyun
1513*4882a593Smuzhiyun /* The docs recommend to use the 10LSB of our MAC here. */
1514*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_RSEED, ((e[5] | e[4]<<8)&0x3ff));
1515*4882a593Smuzhiyun
1516*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_MACADDR2, ((e[4] << 8) | e[5]));
1517*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_MACADDR1, ((e[2] << 8) | e[3]));
1518*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_MACADDR0, ((e[0] << 8) | e[1]));
1519*4882a593Smuzhiyun
1520*4882a593Smuzhiyun HMD(("htable, "));
1521*4882a593Smuzhiyun if ((hp->dev->flags & IFF_ALLMULTI) ||
1522*4882a593Smuzhiyun (netdev_mc_count(hp->dev) > 64)) {
1523*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE0, 0xffff);
1524*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE1, 0xffff);
1525*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE2, 0xffff);
1526*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE3, 0xffff);
1527*4882a593Smuzhiyun } else if ((hp->dev->flags & IFF_PROMISC) == 0) {
1528*4882a593Smuzhiyun u16 hash_table[4];
1529*4882a593Smuzhiyun struct netdev_hw_addr *ha;
1530*4882a593Smuzhiyun u32 crc;
1531*4882a593Smuzhiyun
1532*4882a593Smuzhiyun memset(hash_table, 0, sizeof(hash_table));
1533*4882a593Smuzhiyun netdev_for_each_mc_addr(ha, hp->dev) {
1534*4882a593Smuzhiyun crc = ether_crc_le(6, ha->addr);
1535*4882a593Smuzhiyun crc >>= 26;
1536*4882a593Smuzhiyun hash_table[crc >> 4] |= 1 << (crc & 0xf);
1537*4882a593Smuzhiyun }
1538*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE0, hash_table[0]);
1539*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE1, hash_table[1]);
1540*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE2, hash_table[2]);
1541*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE3, hash_table[3]);
1542*4882a593Smuzhiyun } else {
1543*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE3, 0);
1544*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE2, 0);
1545*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE1, 0);
1546*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE0, 0);
1547*4882a593Smuzhiyun }
1548*4882a593Smuzhiyun
1549*4882a593Smuzhiyun /* Set the RX and TX ring ptrs. */
1550*4882a593Smuzhiyun HMD(("ring ptrs rxr[%08x] txr[%08x]\n",
1551*4882a593Smuzhiyun ((__u32)hp->hblock_dvma + hblock_offset(happy_meal_rxd, 0)),
1552*4882a593Smuzhiyun ((__u32)hp->hblock_dvma + hblock_offset(happy_meal_txd, 0))));
1553*4882a593Smuzhiyun hme_write32(hp, erxregs + ERX_RING,
1554*4882a593Smuzhiyun ((__u32)hp->hblock_dvma + hblock_offset(happy_meal_rxd, 0)));
1555*4882a593Smuzhiyun hme_write32(hp, etxregs + ETX_RING,
1556*4882a593Smuzhiyun ((__u32)hp->hblock_dvma + hblock_offset(happy_meal_txd, 0)));
1557*4882a593Smuzhiyun
1558*4882a593Smuzhiyun /* Parity issues in the ERX unit of some HME revisions can cause some
1559*4882a593Smuzhiyun * registers to not be written unless their parity is even. Detect such
1560*4882a593Smuzhiyun * lost writes and simply rewrite with a low bit set (which will be ignored
1561*4882a593Smuzhiyun * since the rxring needs to be 2K aligned).
1562*4882a593Smuzhiyun */
1563*4882a593Smuzhiyun if (hme_read32(hp, erxregs + ERX_RING) !=
1564*4882a593Smuzhiyun ((__u32)hp->hblock_dvma + hblock_offset(happy_meal_rxd, 0)))
1565*4882a593Smuzhiyun hme_write32(hp, erxregs + ERX_RING,
1566*4882a593Smuzhiyun ((__u32)hp->hblock_dvma + hblock_offset(happy_meal_rxd, 0))
1567*4882a593Smuzhiyun | 0x4);
1568*4882a593Smuzhiyun
1569*4882a593Smuzhiyun /* Set the supported burst sizes. */
1570*4882a593Smuzhiyun HMD(("happy_meal_init: old[%08x] bursts<",
1571*4882a593Smuzhiyun hme_read32(hp, gregs + GREG_CFG)));
1572*4882a593Smuzhiyun
1573*4882a593Smuzhiyun #ifndef CONFIG_SPARC
1574*4882a593Smuzhiyun /* It is always PCI and can handle 64byte bursts. */
1575*4882a593Smuzhiyun hme_write32(hp, gregs + GREG_CFG, GREG_CFG_BURST64);
1576*4882a593Smuzhiyun #else
1577*4882a593Smuzhiyun if ((hp->happy_bursts & DMA_BURST64) &&
1578*4882a593Smuzhiyun ((hp->happy_flags & HFLAG_PCI) != 0
1579*4882a593Smuzhiyun #ifdef CONFIG_SBUS
1580*4882a593Smuzhiyun || sbus_can_burst64()
1581*4882a593Smuzhiyun #endif
1582*4882a593Smuzhiyun || 0)) {
1583*4882a593Smuzhiyun u32 gcfg = GREG_CFG_BURST64;
1584*4882a593Smuzhiyun
1585*4882a593Smuzhiyun /* I have no idea if I should set the extended
1586*4882a593Smuzhiyun * transfer mode bit for Cheerio, so for now I
1587*4882a593Smuzhiyun * do not. -DaveM
1588*4882a593Smuzhiyun */
1589*4882a593Smuzhiyun #ifdef CONFIG_SBUS
1590*4882a593Smuzhiyun if ((hp->happy_flags & HFLAG_PCI) == 0) {
1591*4882a593Smuzhiyun struct platform_device *op = hp->happy_dev;
1592*4882a593Smuzhiyun if (sbus_can_dma_64bit()) {
1593*4882a593Smuzhiyun sbus_set_sbus64(&op->dev,
1594*4882a593Smuzhiyun hp->happy_bursts);
1595*4882a593Smuzhiyun gcfg |= GREG_CFG_64BIT;
1596*4882a593Smuzhiyun }
1597*4882a593Smuzhiyun }
1598*4882a593Smuzhiyun #endif
1599*4882a593Smuzhiyun
1600*4882a593Smuzhiyun HMD(("64>"));
1601*4882a593Smuzhiyun hme_write32(hp, gregs + GREG_CFG, gcfg);
1602*4882a593Smuzhiyun } else if (hp->happy_bursts & DMA_BURST32) {
1603*4882a593Smuzhiyun HMD(("32>"));
1604*4882a593Smuzhiyun hme_write32(hp, gregs + GREG_CFG, GREG_CFG_BURST32);
1605*4882a593Smuzhiyun } else if (hp->happy_bursts & DMA_BURST16) {
1606*4882a593Smuzhiyun HMD(("16>"));
1607*4882a593Smuzhiyun hme_write32(hp, gregs + GREG_CFG, GREG_CFG_BURST16);
1608*4882a593Smuzhiyun } else {
1609*4882a593Smuzhiyun HMD(("XXX>"));
1610*4882a593Smuzhiyun hme_write32(hp, gregs + GREG_CFG, 0);
1611*4882a593Smuzhiyun }
1612*4882a593Smuzhiyun #endif /* CONFIG_SPARC */
1613*4882a593Smuzhiyun
1614*4882a593Smuzhiyun /* Turn off interrupts we do not want to hear. */
1615*4882a593Smuzhiyun HMD((", enable global interrupts, "));
1616*4882a593Smuzhiyun hme_write32(hp, gregs + GREG_IMASK,
1617*4882a593Smuzhiyun (GREG_IMASK_GOTFRAME | GREG_IMASK_RCNTEXP |
1618*4882a593Smuzhiyun GREG_IMASK_SENTFRAME | GREG_IMASK_TXPERR));
1619*4882a593Smuzhiyun
1620*4882a593Smuzhiyun /* Set the transmit ring buffer size. */
1621*4882a593Smuzhiyun HMD(("tx rsize=%d oreg[%08x], ", (int)TX_RING_SIZE,
1622*4882a593Smuzhiyun hme_read32(hp, etxregs + ETX_RSIZE)));
1623*4882a593Smuzhiyun hme_write32(hp, etxregs + ETX_RSIZE, (TX_RING_SIZE >> ETX_RSIZE_SHIFT) - 1);
1624*4882a593Smuzhiyun
1625*4882a593Smuzhiyun /* Enable transmitter DVMA. */
1626*4882a593Smuzhiyun HMD(("tx dma enable old[%08x], ",
1627*4882a593Smuzhiyun hme_read32(hp, etxregs + ETX_CFG)));
1628*4882a593Smuzhiyun hme_write32(hp, etxregs + ETX_CFG,
1629*4882a593Smuzhiyun hme_read32(hp, etxregs + ETX_CFG) | ETX_CFG_DMAENABLE);
1630*4882a593Smuzhiyun
1631*4882a593Smuzhiyun /* This chip really rots, for the receiver sometimes when you
1632*4882a593Smuzhiyun * write to its control registers not all the bits get there
1633*4882a593Smuzhiyun * properly. I cannot think of a sane way to provide complete
1634*4882a593Smuzhiyun * coverage for this hardware bug yet.
1635*4882a593Smuzhiyun */
1636*4882a593Smuzhiyun HMD(("erx regs bug old[%08x]\n",
1637*4882a593Smuzhiyun hme_read32(hp, erxregs + ERX_CFG)));
1638*4882a593Smuzhiyun hme_write32(hp, erxregs + ERX_CFG, ERX_CFG_DEFAULT(RX_OFFSET));
1639*4882a593Smuzhiyun regtmp = hme_read32(hp, erxregs + ERX_CFG);
1640*4882a593Smuzhiyun hme_write32(hp, erxregs + ERX_CFG, ERX_CFG_DEFAULT(RX_OFFSET));
1641*4882a593Smuzhiyun if (hme_read32(hp, erxregs + ERX_CFG) != ERX_CFG_DEFAULT(RX_OFFSET)) {
1642*4882a593Smuzhiyun printk(KERN_ERR "happy meal: Eieee, rx config register gets greasy fries.\n");
1643*4882a593Smuzhiyun printk(KERN_ERR "happy meal: Trying to set %08x, reread gives %08x\n",
1644*4882a593Smuzhiyun ERX_CFG_DEFAULT(RX_OFFSET), regtmp);
1645*4882a593Smuzhiyun /* XXX Should return failure here... */
1646*4882a593Smuzhiyun }
1647*4882a593Smuzhiyun
1648*4882a593Smuzhiyun /* Enable Big Mac hash table filter. */
1649*4882a593Smuzhiyun HMD(("happy_meal_init: enable hash rx_cfg_old[%08x], ",
1650*4882a593Smuzhiyun hme_read32(hp, bregs + BMAC_RXCFG)));
1651*4882a593Smuzhiyun rxcfg = BIGMAC_RXCFG_HENABLE | BIGMAC_RXCFG_REJME;
1652*4882a593Smuzhiyun if (hp->dev->flags & IFF_PROMISC)
1653*4882a593Smuzhiyun rxcfg |= BIGMAC_RXCFG_PMISC;
1654*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_RXCFG, rxcfg);
1655*4882a593Smuzhiyun
1656*4882a593Smuzhiyun /* Let the bits settle in the chip. */
1657*4882a593Smuzhiyun udelay(10);
1658*4882a593Smuzhiyun
1659*4882a593Smuzhiyun /* Ok, configure the Big Mac transmitter. */
1660*4882a593Smuzhiyun HMD(("BIGMAC init, "));
1661*4882a593Smuzhiyun regtmp = 0;
1662*4882a593Smuzhiyun if (hp->happy_flags & HFLAG_FULL)
1663*4882a593Smuzhiyun regtmp |= BIGMAC_TXCFG_FULLDPLX;
1664*4882a593Smuzhiyun
1665*4882a593Smuzhiyun /* Don't turn on the "don't give up" bit for now. It could cause hme
1666*4882a593Smuzhiyun * to deadlock with the PHY if a Jabber occurs.
1667*4882a593Smuzhiyun */
1668*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_TXCFG, regtmp /*| BIGMAC_TXCFG_DGIVEUP*/);
1669*4882a593Smuzhiyun
1670*4882a593Smuzhiyun /* Give up after 16 TX attempts. */
1671*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_ALIMIT, 16);
1672*4882a593Smuzhiyun
1673*4882a593Smuzhiyun /* Enable the output drivers no matter what. */
1674*4882a593Smuzhiyun regtmp = BIGMAC_XCFG_ODENABLE;
1675*4882a593Smuzhiyun
1676*4882a593Smuzhiyun /* If card can do lance mode, enable it. */
1677*4882a593Smuzhiyun if (hp->happy_flags & HFLAG_LANCE)
1678*4882a593Smuzhiyun regtmp |= (DEFAULT_IPG0 << 5) | BIGMAC_XCFG_LANCE;
1679*4882a593Smuzhiyun
1680*4882a593Smuzhiyun /* Disable the MII buffers if using external transceiver. */
1681*4882a593Smuzhiyun if (hp->tcvr_type == external)
1682*4882a593Smuzhiyun regtmp |= BIGMAC_XCFG_MIIDISAB;
1683*4882a593Smuzhiyun
1684*4882a593Smuzhiyun HMD(("XIF config old[%08x], ",
1685*4882a593Smuzhiyun hme_read32(hp, bregs + BMAC_XIFCFG)));
1686*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_XIFCFG, regtmp);
1687*4882a593Smuzhiyun
1688*4882a593Smuzhiyun /* Start things up. */
1689*4882a593Smuzhiyun HMD(("tx old[%08x] and rx [%08x] ON!\n",
1690*4882a593Smuzhiyun hme_read32(hp, bregs + BMAC_TXCFG),
1691*4882a593Smuzhiyun hme_read32(hp, bregs + BMAC_RXCFG)));
1692*4882a593Smuzhiyun
1693*4882a593Smuzhiyun /* Set larger TX/RX size to allow for 802.1q */
1694*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_TXMAX, ETH_FRAME_LEN + 8);
1695*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_RXMAX, ETH_FRAME_LEN + 8);
1696*4882a593Smuzhiyun
1697*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_TXCFG,
1698*4882a593Smuzhiyun hme_read32(hp, bregs + BMAC_TXCFG) | BIGMAC_TXCFG_ENABLE);
1699*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_RXCFG,
1700*4882a593Smuzhiyun hme_read32(hp, bregs + BMAC_RXCFG) | BIGMAC_RXCFG_ENABLE);
1701*4882a593Smuzhiyun
1702*4882a593Smuzhiyun /* Get the autonegotiation started, and the watch timer ticking. */
1703*4882a593Smuzhiyun happy_meal_begin_auto_negotiation(hp, tregs, NULL);
1704*4882a593Smuzhiyun
1705*4882a593Smuzhiyun /* Success. */
1706*4882a593Smuzhiyun return 0;
1707*4882a593Smuzhiyun }
1708*4882a593Smuzhiyun
1709*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_set_initial_advertisement(struct happy_meal * hp)1710*4882a593Smuzhiyun static void happy_meal_set_initial_advertisement(struct happy_meal *hp)
1711*4882a593Smuzhiyun {
1712*4882a593Smuzhiyun void __iomem *tregs = hp->tcvregs;
1713*4882a593Smuzhiyun void __iomem *bregs = hp->bigmacregs;
1714*4882a593Smuzhiyun void __iomem *gregs = hp->gregs;
1715*4882a593Smuzhiyun
1716*4882a593Smuzhiyun happy_meal_stop(hp, gregs);
1717*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_IMASK, 0xffff);
1718*4882a593Smuzhiyun if (hp->happy_flags & HFLAG_FENABLE)
1719*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG,
1720*4882a593Smuzhiyun hme_read32(hp, tregs + TCVR_CFG) & ~(TCV_CFG_BENABLE));
1721*4882a593Smuzhiyun else
1722*4882a593Smuzhiyun hme_write32(hp, tregs + TCVR_CFG,
1723*4882a593Smuzhiyun hme_read32(hp, tregs + TCVR_CFG) | TCV_CFG_BENABLE);
1724*4882a593Smuzhiyun happy_meal_transceiver_check(hp, tregs);
1725*4882a593Smuzhiyun switch(hp->tcvr_type) {
1726*4882a593Smuzhiyun case none:
1727*4882a593Smuzhiyun return;
1728*4882a593Smuzhiyun case internal:
1729*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_XIFCFG, 0);
1730*4882a593Smuzhiyun break;
1731*4882a593Smuzhiyun case external:
1732*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_XIFCFG, BIGMAC_XCFG_MIIDISAB);
1733*4882a593Smuzhiyun break;
1734*4882a593Smuzhiyun }
1735*4882a593Smuzhiyun if (happy_meal_tcvr_reset(hp, tregs))
1736*4882a593Smuzhiyun return;
1737*4882a593Smuzhiyun
1738*4882a593Smuzhiyun /* Latch PHY registers as of now. */
1739*4882a593Smuzhiyun hp->sw_bmsr = happy_meal_tcvr_read(hp, tregs, MII_BMSR);
1740*4882a593Smuzhiyun hp->sw_advertise = happy_meal_tcvr_read(hp, tregs, MII_ADVERTISE);
1741*4882a593Smuzhiyun
1742*4882a593Smuzhiyun /* Advertise everything we can support. */
1743*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_10HALF)
1744*4882a593Smuzhiyun hp->sw_advertise |= (ADVERTISE_10HALF);
1745*4882a593Smuzhiyun else
1746*4882a593Smuzhiyun hp->sw_advertise &= ~(ADVERTISE_10HALF);
1747*4882a593Smuzhiyun
1748*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_10FULL)
1749*4882a593Smuzhiyun hp->sw_advertise |= (ADVERTISE_10FULL);
1750*4882a593Smuzhiyun else
1751*4882a593Smuzhiyun hp->sw_advertise &= ~(ADVERTISE_10FULL);
1752*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_100HALF)
1753*4882a593Smuzhiyun hp->sw_advertise |= (ADVERTISE_100HALF);
1754*4882a593Smuzhiyun else
1755*4882a593Smuzhiyun hp->sw_advertise &= ~(ADVERTISE_100HALF);
1756*4882a593Smuzhiyun if (hp->sw_bmsr & BMSR_100FULL)
1757*4882a593Smuzhiyun hp->sw_advertise |= (ADVERTISE_100FULL);
1758*4882a593Smuzhiyun else
1759*4882a593Smuzhiyun hp->sw_advertise &= ~(ADVERTISE_100FULL);
1760*4882a593Smuzhiyun
1761*4882a593Smuzhiyun /* Update the PHY advertisement register. */
1762*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_ADVERTISE, hp->sw_advertise);
1763*4882a593Smuzhiyun }
1764*4882a593Smuzhiyun
1765*4882a593Smuzhiyun /* Once status is latched (by happy_meal_interrupt) it is cleared by
1766*4882a593Smuzhiyun * the hardware, so we cannot re-read it and get a correct value.
1767*4882a593Smuzhiyun *
1768*4882a593Smuzhiyun * hp->happy_lock must be held
1769*4882a593Smuzhiyun */
happy_meal_is_not_so_happy(struct happy_meal * hp,u32 status)1770*4882a593Smuzhiyun static int happy_meal_is_not_so_happy(struct happy_meal *hp, u32 status)
1771*4882a593Smuzhiyun {
1772*4882a593Smuzhiyun int reset = 0;
1773*4882a593Smuzhiyun
1774*4882a593Smuzhiyun /* Only print messages for non-counter related interrupts. */
1775*4882a593Smuzhiyun if (status & (GREG_STAT_STSTERR | GREG_STAT_TFIFO_UND |
1776*4882a593Smuzhiyun GREG_STAT_MAXPKTERR | GREG_STAT_RXERR |
1777*4882a593Smuzhiyun GREG_STAT_RXPERR | GREG_STAT_RXTERR | GREG_STAT_EOPERR |
1778*4882a593Smuzhiyun GREG_STAT_MIFIRQ | GREG_STAT_TXEACK | GREG_STAT_TXLERR |
1779*4882a593Smuzhiyun GREG_STAT_TXPERR | GREG_STAT_TXTERR | GREG_STAT_SLVERR |
1780*4882a593Smuzhiyun GREG_STAT_SLVPERR))
1781*4882a593Smuzhiyun printk(KERN_ERR "%s: Error interrupt for happy meal, status = %08x\n",
1782*4882a593Smuzhiyun hp->dev->name, status);
1783*4882a593Smuzhiyun
1784*4882a593Smuzhiyun if (status & GREG_STAT_RFIFOVF) {
1785*4882a593Smuzhiyun /* Receive FIFO overflow is harmless and the hardware will take
1786*4882a593Smuzhiyun care of it, just some packets are lost. Who cares. */
1787*4882a593Smuzhiyun printk(KERN_DEBUG "%s: Happy Meal receive FIFO overflow.\n", hp->dev->name);
1788*4882a593Smuzhiyun }
1789*4882a593Smuzhiyun
1790*4882a593Smuzhiyun if (status & GREG_STAT_STSTERR) {
1791*4882a593Smuzhiyun /* BigMAC SQE link test failed. */
1792*4882a593Smuzhiyun printk(KERN_ERR "%s: Happy Meal BigMAC SQE test failed.\n", hp->dev->name);
1793*4882a593Smuzhiyun reset = 1;
1794*4882a593Smuzhiyun }
1795*4882a593Smuzhiyun
1796*4882a593Smuzhiyun if (status & GREG_STAT_TFIFO_UND) {
1797*4882a593Smuzhiyun /* Transmit FIFO underrun, again DMA error likely. */
1798*4882a593Smuzhiyun printk(KERN_ERR "%s: Happy Meal transmitter FIFO underrun, DMA error.\n",
1799*4882a593Smuzhiyun hp->dev->name);
1800*4882a593Smuzhiyun reset = 1;
1801*4882a593Smuzhiyun }
1802*4882a593Smuzhiyun
1803*4882a593Smuzhiyun if (status & GREG_STAT_MAXPKTERR) {
1804*4882a593Smuzhiyun /* Driver error, tried to transmit something larger
1805*4882a593Smuzhiyun * than ethernet max mtu.
1806*4882a593Smuzhiyun */
1807*4882a593Smuzhiyun printk(KERN_ERR "%s: Happy Meal MAX Packet size error.\n", hp->dev->name);
1808*4882a593Smuzhiyun reset = 1;
1809*4882a593Smuzhiyun }
1810*4882a593Smuzhiyun
1811*4882a593Smuzhiyun if (status & GREG_STAT_NORXD) {
1812*4882a593Smuzhiyun /* This is harmless, it just means the system is
1813*4882a593Smuzhiyun * quite loaded and the incoming packet rate was
1814*4882a593Smuzhiyun * faster than the interrupt handler could keep up
1815*4882a593Smuzhiyun * with.
1816*4882a593Smuzhiyun */
1817*4882a593Smuzhiyun printk(KERN_INFO "%s: Happy Meal out of receive "
1818*4882a593Smuzhiyun "descriptors, packet dropped.\n",
1819*4882a593Smuzhiyun hp->dev->name);
1820*4882a593Smuzhiyun }
1821*4882a593Smuzhiyun
1822*4882a593Smuzhiyun if (status & (GREG_STAT_RXERR|GREG_STAT_RXPERR|GREG_STAT_RXTERR)) {
1823*4882a593Smuzhiyun /* All sorts of DMA receive errors. */
1824*4882a593Smuzhiyun printk(KERN_ERR "%s: Happy Meal rx DMA errors [ ", hp->dev->name);
1825*4882a593Smuzhiyun if (status & GREG_STAT_RXERR)
1826*4882a593Smuzhiyun printk("GenericError ");
1827*4882a593Smuzhiyun if (status & GREG_STAT_RXPERR)
1828*4882a593Smuzhiyun printk("ParityError ");
1829*4882a593Smuzhiyun if (status & GREG_STAT_RXTERR)
1830*4882a593Smuzhiyun printk("RxTagBotch ");
1831*4882a593Smuzhiyun printk("]\n");
1832*4882a593Smuzhiyun reset = 1;
1833*4882a593Smuzhiyun }
1834*4882a593Smuzhiyun
1835*4882a593Smuzhiyun if (status & GREG_STAT_EOPERR) {
1836*4882a593Smuzhiyun /* Driver bug, didn't set EOP bit in tx descriptor given
1837*4882a593Smuzhiyun * to the happy meal.
1838*4882a593Smuzhiyun */
1839*4882a593Smuzhiyun printk(KERN_ERR "%s: EOP not set in happy meal transmit descriptor!\n",
1840*4882a593Smuzhiyun hp->dev->name);
1841*4882a593Smuzhiyun reset = 1;
1842*4882a593Smuzhiyun }
1843*4882a593Smuzhiyun
1844*4882a593Smuzhiyun if (status & GREG_STAT_MIFIRQ) {
1845*4882a593Smuzhiyun /* MIF signalled an interrupt, were we polling it? */
1846*4882a593Smuzhiyun printk(KERN_ERR "%s: Happy Meal MIF interrupt.\n", hp->dev->name);
1847*4882a593Smuzhiyun }
1848*4882a593Smuzhiyun
1849*4882a593Smuzhiyun if (status &
1850*4882a593Smuzhiyun (GREG_STAT_TXEACK|GREG_STAT_TXLERR|GREG_STAT_TXPERR|GREG_STAT_TXTERR)) {
1851*4882a593Smuzhiyun /* All sorts of transmit DMA errors. */
1852*4882a593Smuzhiyun printk(KERN_ERR "%s: Happy Meal tx DMA errors [ ", hp->dev->name);
1853*4882a593Smuzhiyun if (status & GREG_STAT_TXEACK)
1854*4882a593Smuzhiyun printk("GenericError ");
1855*4882a593Smuzhiyun if (status & GREG_STAT_TXLERR)
1856*4882a593Smuzhiyun printk("LateError ");
1857*4882a593Smuzhiyun if (status & GREG_STAT_TXPERR)
1858*4882a593Smuzhiyun printk("ParityError ");
1859*4882a593Smuzhiyun if (status & GREG_STAT_TXTERR)
1860*4882a593Smuzhiyun printk("TagBotch ");
1861*4882a593Smuzhiyun printk("]\n");
1862*4882a593Smuzhiyun reset = 1;
1863*4882a593Smuzhiyun }
1864*4882a593Smuzhiyun
1865*4882a593Smuzhiyun if (status & (GREG_STAT_SLVERR|GREG_STAT_SLVPERR)) {
1866*4882a593Smuzhiyun /* Bus or parity error when cpu accessed happy meal registers
1867*4882a593Smuzhiyun * or it's internal FIFO's. Should never see this.
1868*4882a593Smuzhiyun */
1869*4882a593Smuzhiyun printk(KERN_ERR "%s: Happy Meal register access SBUS slave (%s) error.\n",
1870*4882a593Smuzhiyun hp->dev->name,
1871*4882a593Smuzhiyun (status & GREG_STAT_SLVPERR) ? "parity" : "generic");
1872*4882a593Smuzhiyun reset = 1;
1873*4882a593Smuzhiyun }
1874*4882a593Smuzhiyun
1875*4882a593Smuzhiyun if (reset) {
1876*4882a593Smuzhiyun printk(KERN_NOTICE "%s: Resetting...\n", hp->dev->name);
1877*4882a593Smuzhiyun happy_meal_init(hp);
1878*4882a593Smuzhiyun return 1;
1879*4882a593Smuzhiyun }
1880*4882a593Smuzhiyun return 0;
1881*4882a593Smuzhiyun }
1882*4882a593Smuzhiyun
1883*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_mif_interrupt(struct happy_meal * hp)1884*4882a593Smuzhiyun static void happy_meal_mif_interrupt(struct happy_meal *hp)
1885*4882a593Smuzhiyun {
1886*4882a593Smuzhiyun void __iomem *tregs = hp->tcvregs;
1887*4882a593Smuzhiyun
1888*4882a593Smuzhiyun printk(KERN_INFO "%s: Link status change.\n", hp->dev->name);
1889*4882a593Smuzhiyun hp->sw_bmcr = happy_meal_tcvr_read(hp, tregs, MII_BMCR);
1890*4882a593Smuzhiyun hp->sw_lpa = happy_meal_tcvr_read(hp, tregs, MII_LPA);
1891*4882a593Smuzhiyun
1892*4882a593Smuzhiyun /* Use the fastest transmission protocol possible. */
1893*4882a593Smuzhiyun if (hp->sw_lpa & LPA_100FULL) {
1894*4882a593Smuzhiyun printk(KERN_INFO "%s: Switching to 100Mbps at full duplex.", hp->dev->name);
1895*4882a593Smuzhiyun hp->sw_bmcr |= (BMCR_FULLDPLX | BMCR_SPEED100);
1896*4882a593Smuzhiyun } else if (hp->sw_lpa & LPA_100HALF) {
1897*4882a593Smuzhiyun printk(KERN_INFO "%s: Switching to 100MBps at half duplex.", hp->dev->name);
1898*4882a593Smuzhiyun hp->sw_bmcr |= BMCR_SPEED100;
1899*4882a593Smuzhiyun } else if (hp->sw_lpa & LPA_10FULL) {
1900*4882a593Smuzhiyun printk(KERN_INFO "%s: Switching to 10MBps at full duplex.", hp->dev->name);
1901*4882a593Smuzhiyun hp->sw_bmcr |= BMCR_FULLDPLX;
1902*4882a593Smuzhiyun } else {
1903*4882a593Smuzhiyun printk(KERN_INFO "%s: Using 10Mbps at half duplex.", hp->dev->name);
1904*4882a593Smuzhiyun }
1905*4882a593Smuzhiyun happy_meal_tcvr_write(hp, tregs, MII_BMCR, hp->sw_bmcr);
1906*4882a593Smuzhiyun
1907*4882a593Smuzhiyun /* Finally stop polling and shut up the MIF. */
1908*4882a593Smuzhiyun happy_meal_poll_stop(hp, tregs);
1909*4882a593Smuzhiyun }
1910*4882a593Smuzhiyun
1911*4882a593Smuzhiyun #ifdef TXDEBUG
1912*4882a593Smuzhiyun #define TXD(x) printk x
1913*4882a593Smuzhiyun #else
1914*4882a593Smuzhiyun #define TXD(x)
1915*4882a593Smuzhiyun #endif
1916*4882a593Smuzhiyun
1917*4882a593Smuzhiyun /* hp->happy_lock must be held */
happy_meal_tx(struct happy_meal * hp)1918*4882a593Smuzhiyun static void happy_meal_tx(struct happy_meal *hp)
1919*4882a593Smuzhiyun {
1920*4882a593Smuzhiyun struct happy_meal_txd *txbase = &hp->happy_block->happy_meal_txd[0];
1921*4882a593Smuzhiyun struct happy_meal_txd *this;
1922*4882a593Smuzhiyun struct net_device *dev = hp->dev;
1923*4882a593Smuzhiyun int elem;
1924*4882a593Smuzhiyun
1925*4882a593Smuzhiyun elem = hp->tx_old;
1926*4882a593Smuzhiyun TXD(("TX<"));
1927*4882a593Smuzhiyun while (elem != hp->tx_new) {
1928*4882a593Smuzhiyun struct sk_buff *skb;
1929*4882a593Smuzhiyun u32 flags, dma_addr, dma_len;
1930*4882a593Smuzhiyun int frag;
1931*4882a593Smuzhiyun
1932*4882a593Smuzhiyun TXD(("[%d]", elem));
1933*4882a593Smuzhiyun this = &txbase[elem];
1934*4882a593Smuzhiyun flags = hme_read_desc32(hp, &this->tx_flags);
1935*4882a593Smuzhiyun if (flags & TXFLAG_OWN)
1936*4882a593Smuzhiyun break;
1937*4882a593Smuzhiyun skb = hp->tx_skbs[elem];
1938*4882a593Smuzhiyun if (skb_shinfo(skb)->nr_frags) {
1939*4882a593Smuzhiyun int last;
1940*4882a593Smuzhiyun
1941*4882a593Smuzhiyun last = elem + skb_shinfo(skb)->nr_frags;
1942*4882a593Smuzhiyun last &= (TX_RING_SIZE - 1);
1943*4882a593Smuzhiyun flags = hme_read_desc32(hp, &txbase[last].tx_flags);
1944*4882a593Smuzhiyun if (flags & TXFLAG_OWN)
1945*4882a593Smuzhiyun break;
1946*4882a593Smuzhiyun }
1947*4882a593Smuzhiyun hp->tx_skbs[elem] = NULL;
1948*4882a593Smuzhiyun dev->stats.tx_bytes += skb->len;
1949*4882a593Smuzhiyun
1950*4882a593Smuzhiyun for (frag = 0; frag <= skb_shinfo(skb)->nr_frags; frag++) {
1951*4882a593Smuzhiyun dma_addr = hme_read_desc32(hp, &this->tx_addr);
1952*4882a593Smuzhiyun dma_len = hme_read_desc32(hp, &this->tx_flags);
1953*4882a593Smuzhiyun
1954*4882a593Smuzhiyun dma_len &= TXFLAG_SIZE;
1955*4882a593Smuzhiyun if (!frag)
1956*4882a593Smuzhiyun dma_unmap_single(hp->dma_dev, dma_addr, dma_len, DMA_TO_DEVICE);
1957*4882a593Smuzhiyun else
1958*4882a593Smuzhiyun dma_unmap_page(hp->dma_dev, dma_addr, dma_len, DMA_TO_DEVICE);
1959*4882a593Smuzhiyun
1960*4882a593Smuzhiyun elem = NEXT_TX(elem);
1961*4882a593Smuzhiyun this = &txbase[elem];
1962*4882a593Smuzhiyun }
1963*4882a593Smuzhiyun
1964*4882a593Smuzhiyun dev_consume_skb_irq(skb);
1965*4882a593Smuzhiyun dev->stats.tx_packets++;
1966*4882a593Smuzhiyun }
1967*4882a593Smuzhiyun hp->tx_old = elem;
1968*4882a593Smuzhiyun TXD((">"));
1969*4882a593Smuzhiyun
1970*4882a593Smuzhiyun if (netif_queue_stopped(dev) &&
1971*4882a593Smuzhiyun TX_BUFFS_AVAIL(hp) > (MAX_SKB_FRAGS + 1))
1972*4882a593Smuzhiyun netif_wake_queue(dev);
1973*4882a593Smuzhiyun }
1974*4882a593Smuzhiyun
1975*4882a593Smuzhiyun #ifdef RXDEBUG
1976*4882a593Smuzhiyun #define RXD(x) printk x
1977*4882a593Smuzhiyun #else
1978*4882a593Smuzhiyun #define RXD(x)
1979*4882a593Smuzhiyun #endif
1980*4882a593Smuzhiyun
1981*4882a593Smuzhiyun /* Originally I used to handle the allocation failure by just giving back just
1982*4882a593Smuzhiyun * that one ring buffer to the happy meal. Problem is that usually when that
1983*4882a593Smuzhiyun * condition is triggered, the happy meal expects you to do something reasonable
1984*4882a593Smuzhiyun * with all of the packets it has DMA'd in. So now I just drop the entire
1985*4882a593Smuzhiyun * ring when we cannot get a new skb and give them all back to the happy meal,
1986*4882a593Smuzhiyun * maybe things will be "happier" now.
1987*4882a593Smuzhiyun *
1988*4882a593Smuzhiyun * hp->happy_lock must be held
1989*4882a593Smuzhiyun */
happy_meal_rx(struct happy_meal * hp,struct net_device * dev)1990*4882a593Smuzhiyun static void happy_meal_rx(struct happy_meal *hp, struct net_device *dev)
1991*4882a593Smuzhiyun {
1992*4882a593Smuzhiyun struct happy_meal_rxd *rxbase = &hp->happy_block->happy_meal_rxd[0];
1993*4882a593Smuzhiyun struct happy_meal_rxd *this;
1994*4882a593Smuzhiyun int elem = hp->rx_new, drops = 0;
1995*4882a593Smuzhiyun u32 flags;
1996*4882a593Smuzhiyun
1997*4882a593Smuzhiyun RXD(("RX<"));
1998*4882a593Smuzhiyun this = &rxbase[elem];
1999*4882a593Smuzhiyun while (!((flags = hme_read_desc32(hp, &this->rx_flags)) & RXFLAG_OWN)) {
2000*4882a593Smuzhiyun struct sk_buff *skb;
2001*4882a593Smuzhiyun int len = flags >> 16;
2002*4882a593Smuzhiyun u16 csum = flags & RXFLAG_CSUM;
2003*4882a593Smuzhiyun u32 dma_addr = hme_read_desc32(hp, &this->rx_addr);
2004*4882a593Smuzhiyun
2005*4882a593Smuzhiyun RXD(("[%d ", elem));
2006*4882a593Smuzhiyun
2007*4882a593Smuzhiyun /* Check for errors. */
2008*4882a593Smuzhiyun if ((len < ETH_ZLEN) || (flags & RXFLAG_OVERFLOW)) {
2009*4882a593Smuzhiyun RXD(("ERR(%08x)]", flags));
2010*4882a593Smuzhiyun dev->stats.rx_errors++;
2011*4882a593Smuzhiyun if (len < ETH_ZLEN)
2012*4882a593Smuzhiyun dev->stats.rx_length_errors++;
2013*4882a593Smuzhiyun if (len & (RXFLAG_OVERFLOW >> 16)) {
2014*4882a593Smuzhiyun dev->stats.rx_over_errors++;
2015*4882a593Smuzhiyun dev->stats.rx_fifo_errors++;
2016*4882a593Smuzhiyun }
2017*4882a593Smuzhiyun
2018*4882a593Smuzhiyun /* Return it to the Happy meal. */
2019*4882a593Smuzhiyun drop_it:
2020*4882a593Smuzhiyun dev->stats.rx_dropped++;
2021*4882a593Smuzhiyun hme_write_rxd(hp, this,
2022*4882a593Smuzhiyun (RXFLAG_OWN|((RX_BUF_ALLOC_SIZE-RX_OFFSET)<<16)),
2023*4882a593Smuzhiyun dma_addr);
2024*4882a593Smuzhiyun goto next;
2025*4882a593Smuzhiyun }
2026*4882a593Smuzhiyun skb = hp->rx_skbs[elem];
2027*4882a593Smuzhiyun if (len > RX_COPY_THRESHOLD) {
2028*4882a593Smuzhiyun struct sk_buff *new_skb;
2029*4882a593Smuzhiyun u32 mapping;
2030*4882a593Smuzhiyun
2031*4882a593Smuzhiyun /* Now refill the entry, if we can. */
2032*4882a593Smuzhiyun new_skb = happy_meal_alloc_skb(RX_BUF_ALLOC_SIZE, GFP_ATOMIC);
2033*4882a593Smuzhiyun if (new_skb == NULL) {
2034*4882a593Smuzhiyun drops++;
2035*4882a593Smuzhiyun goto drop_it;
2036*4882a593Smuzhiyun }
2037*4882a593Smuzhiyun skb_put(new_skb, (ETH_FRAME_LEN + RX_OFFSET + 4));
2038*4882a593Smuzhiyun mapping = dma_map_single(hp->dma_dev, new_skb->data,
2039*4882a593Smuzhiyun RX_BUF_ALLOC_SIZE,
2040*4882a593Smuzhiyun DMA_FROM_DEVICE);
2041*4882a593Smuzhiyun if (unlikely(dma_mapping_error(hp->dma_dev, mapping))) {
2042*4882a593Smuzhiyun dev_kfree_skb_any(new_skb);
2043*4882a593Smuzhiyun drops++;
2044*4882a593Smuzhiyun goto drop_it;
2045*4882a593Smuzhiyun }
2046*4882a593Smuzhiyun
2047*4882a593Smuzhiyun dma_unmap_single(hp->dma_dev, dma_addr, RX_BUF_ALLOC_SIZE, DMA_FROM_DEVICE);
2048*4882a593Smuzhiyun hp->rx_skbs[elem] = new_skb;
2049*4882a593Smuzhiyun hme_write_rxd(hp, this,
2050*4882a593Smuzhiyun (RXFLAG_OWN|((RX_BUF_ALLOC_SIZE-RX_OFFSET)<<16)),
2051*4882a593Smuzhiyun mapping);
2052*4882a593Smuzhiyun skb_reserve(new_skb, RX_OFFSET);
2053*4882a593Smuzhiyun
2054*4882a593Smuzhiyun /* Trim the original skb for the netif. */
2055*4882a593Smuzhiyun skb_trim(skb, len);
2056*4882a593Smuzhiyun } else {
2057*4882a593Smuzhiyun struct sk_buff *copy_skb = netdev_alloc_skb(dev, len + 2);
2058*4882a593Smuzhiyun
2059*4882a593Smuzhiyun if (copy_skb == NULL) {
2060*4882a593Smuzhiyun drops++;
2061*4882a593Smuzhiyun goto drop_it;
2062*4882a593Smuzhiyun }
2063*4882a593Smuzhiyun
2064*4882a593Smuzhiyun skb_reserve(copy_skb, 2);
2065*4882a593Smuzhiyun skb_put(copy_skb, len);
2066*4882a593Smuzhiyun dma_sync_single_for_cpu(hp->dma_dev, dma_addr, len + 2, DMA_FROM_DEVICE);
2067*4882a593Smuzhiyun skb_copy_from_linear_data(skb, copy_skb->data, len);
2068*4882a593Smuzhiyun dma_sync_single_for_device(hp->dma_dev, dma_addr, len + 2, DMA_FROM_DEVICE);
2069*4882a593Smuzhiyun /* Reuse original ring buffer. */
2070*4882a593Smuzhiyun hme_write_rxd(hp, this,
2071*4882a593Smuzhiyun (RXFLAG_OWN|((RX_BUF_ALLOC_SIZE-RX_OFFSET)<<16)),
2072*4882a593Smuzhiyun dma_addr);
2073*4882a593Smuzhiyun
2074*4882a593Smuzhiyun skb = copy_skb;
2075*4882a593Smuzhiyun }
2076*4882a593Smuzhiyun
2077*4882a593Smuzhiyun /* This card is _fucking_ hot... */
2078*4882a593Smuzhiyun skb->csum = csum_unfold(~(__force __sum16)htons(csum));
2079*4882a593Smuzhiyun skb->ip_summed = CHECKSUM_COMPLETE;
2080*4882a593Smuzhiyun
2081*4882a593Smuzhiyun RXD(("len=%d csum=%4x]", len, csum));
2082*4882a593Smuzhiyun skb->protocol = eth_type_trans(skb, dev);
2083*4882a593Smuzhiyun netif_rx(skb);
2084*4882a593Smuzhiyun
2085*4882a593Smuzhiyun dev->stats.rx_packets++;
2086*4882a593Smuzhiyun dev->stats.rx_bytes += len;
2087*4882a593Smuzhiyun next:
2088*4882a593Smuzhiyun elem = NEXT_RX(elem);
2089*4882a593Smuzhiyun this = &rxbase[elem];
2090*4882a593Smuzhiyun }
2091*4882a593Smuzhiyun hp->rx_new = elem;
2092*4882a593Smuzhiyun if (drops)
2093*4882a593Smuzhiyun printk(KERN_INFO "%s: Memory squeeze, deferring packet.\n", hp->dev->name);
2094*4882a593Smuzhiyun RXD((">"));
2095*4882a593Smuzhiyun }
2096*4882a593Smuzhiyun
happy_meal_interrupt(int irq,void * dev_id)2097*4882a593Smuzhiyun static irqreturn_t happy_meal_interrupt(int irq, void *dev_id)
2098*4882a593Smuzhiyun {
2099*4882a593Smuzhiyun struct net_device *dev = dev_id;
2100*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2101*4882a593Smuzhiyun u32 happy_status = hme_read32(hp, hp->gregs + GREG_STAT);
2102*4882a593Smuzhiyun
2103*4882a593Smuzhiyun HMD(("happy_meal_interrupt: status=%08x ", happy_status));
2104*4882a593Smuzhiyun
2105*4882a593Smuzhiyun spin_lock(&hp->happy_lock);
2106*4882a593Smuzhiyun
2107*4882a593Smuzhiyun if (happy_status & GREG_STAT_ERRORS) {
2108*4882a593Smuzhiyun HMD(("ERRORS "));
2109*4882a593Smuzhiyun if (happy_meal_is_not_so_happy(hp, /* un- */ happy_status))
2110*4882a593Smuzhiyun goto out;
2111*4882a593Smuzhiyun }
2112*4882a593Smuzhiyun
2113*4882a593Smuzhiyun if (happy_status & GREG_STAT_MIFIRQ) {
2114*4882a593Smuzhiyun HMD(("MIFIRQ "));
2115*4882a593Smuzhiyun happy_meal_mif_interrupt(hp);
2116*4882a593Smuzhiyun }
2117*4882a593Smuzhiyun
2118*4882a593Smuzhiyun if (happy_status & GREG_STAT_TXALL) {
2119*4882a593Smuzhiyun HMD(("TXALL "));
2120*4882a593Smuzhiyun happy_meal_tx(hp);
2121*4882a593Smuzhiyun }
2122*4882a593Smuzhiyun
2123*4882a593Smuzhiyun if (happy_status & GREG_STAT_RXTOHOST) {
2124*4882a593Smuzhiyun HMD(("RXTOHOST "));
2125*4882a593Smuzhiyun happy_meal_rx(hp, dev);
2126*4882a593Smuzhiyun }
2127*4882a593Smuzhiyun
2128*4882a593Smuzhiyun HMD(("done\n"));
2129*4882a593Smuzhiyun out:
2130*4882a593Smuzhiyun spin_unlock(&hp->happy_lock);
2131*4882a593Smuzhiyun
2132*4882a593Smuzhiyun return IRQ_HANDLED;
2133*4882a593Smuzhiyun }
2134*4882a593Smuzhiyun
2135*4882a593Smuzhiyun #ifdef CONFIG_SBUS
quattro_sbus_interrupt(int irq,void * cookie)2136*4882a593Smuzhiyun static irqreturn_t quattro_sbus_interrupt(int irq, void *cookie)
2137*4882a593Smuzhiyun {
2138*4882a593Smuzhiyun struct quattro *qp = (struct quattro *) cookie;
2139*4882a593Smuzhiyun int i;
2140*4882a593Smuzhiyun
2141*4882a593Smuzhiyun for (i = 0; i < 4; i++) {
2142*4882a593Smuzhiyun struct net_device *dev = qp->happy_meals[i];
2143*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2144*4882a593Smuzhiyun u32 happy_status = hme_read32(hp, hp->gregs + GREG_STAT);
2145*4882a593Smuzhiyun
2146*4882a593Smuzhiyun HMD(("quattro_interrupt: status=%08x ", happy_status));
2147*4882a593Smuzhiyun
2148*4882a593Smuzhiyun if (!(happy_status & (GREG_STAT_ERRORS |
2149*4882a593Smuzhiyun GREG_STAT_MIFIRQ |
2150*4882a593Smuzhiyun GREG_STAT_TXALL |
2151*4882a593Smuzhiyun GREG_STAT_RXTOHOST)))
2152*4882a593Smuzhiyun continue;
2153*4882a593Smuzhiyun
2154*4882a593Smuzhiyun spin_lock(&hp->happy_lock);
2155*4882a593Smuzhiyun
2156*4882a593Smuzhiyun if (happy_status & GREG_STAT_ERRORS) {
2157*4882a593Smuzhiyun HMD(("ERRORS "));
2158*4882a593Smuzhiyun if (happy_meal_is_not_so_happy(hp, happy_status))
2159*4882a593Smuzhiyun goto next;
2160*4882a593Smuzhiyun }
2161*4882a593Smuzhiyun
2162*4882a593Smuzhiyun if (happy_status & GREG_STAT_MIFIRQ) {
2163*4882a593Smuzhiyun HMD(("MIFIRQ "));
2164*4882a593Smuzhiyun happy_meal_mif_interrupt(hp);
2165*4882a593Smuzhiyun }
2166*4882a593Smuzhiyun
2167*4882a593Smuzhiyun if (happy_status & GREG_STAT_TXALL) {
2168*4882a593Smuzhiyun HMD(("TXALL "));
2169*4882a593Smuzhiyun happy_meal_tx(hp);
2170*4882a593Smuzhiyun }
2171*4882a593Smuzhiyun
2172*4882a593Smuzhiyun if (happy_status & GREG_STAT_RXTOHOST) {
2173*4882a593Smuzhiyun HMD(("RXTOHOST "));
2174*4882a593Smuzhiyun happy_meal_rx(hp, dev);
2175*4882a593Smuzhiyun }
2176*4882a593Smuzhiyun
2177*4882a593Smuzhiyun next:
2178*4882a593Smuzhiyun spin_unlock(&hp->happy_lock);
2179*4882a593Smuzhiyun }
2180*4882a593Smuzhiyun HMD(("done\n"));
2181*4882a593Smuzhiyun
2182*4882a593Smuzhiyun return IRQ_HANDLED;
2183*4882a593Smuzhiyun }
2184*4882a593Smuzhiyun #endif
2185*4882a593Smuzhiyun
happy_meal_open(struct net_device * dev)2186*4882a593Smuzhiyun static int happy_meal_open(struct net_device *dev)
2187*4882a593Smuzhiyun {
2188*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2189*4882a593Smuzhiyun int res;
2190*4882a593Smuzhiyun
2191*4882a593Smuzhiyun HMD(("happy_meal_open: "));
2192*4882a593Smuzhiyun
2193*4882a593Smuzhiyun /* On SBUS Quattro QFE cards, all hme interrupts are concentrated
2194*4882a593Smuzhiyun * into a single source which we register handling at probe time.
2195*4882a593Smuzhiyun */
2196*4882a593Smuzhiyun if ((hp->happy_flags & (HFLAG_QUATTRO|HFLAG_PCI)) != HFLAG_QUATTRO) {
2197*4882a593Smuzhiyun res = request_irq(hp->irq, happy_meal_interrupt, IRQF_SHARED,
2198*4882a593Smuzhiyun dev->name, dev);
2199*4882a593Smuzhiyun if (res) {
2200*4882a593Smuzhiyun HMD(("EAGAIN\n"));
2201*4882a593Smuzhiyun printk(KERN_ERR "happy_meal(SBUS): Can't order irq %d to go.\n",
2202*4882a593Smuzhiyun hp->irq);
2203*4882a593Smuzhiyun
2204*4882a593Smuzhiyun return -EAGAIN;
2205*4882a593Smuzhiyun }
2206*4882a593Smuzhiyun }
2207*4882a593Smuzhiyun
2208*4882a593Smuzhiyun HMD(("to happy_meal_init\n"));
2209*4882a593Smuzhiyun
2210*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
2211*4882a593Smuzhiyun res = happy_meal_init(hp);
2212*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2213*4882a593Smuzhiyun
2214*4882a593Smuzhiyun if (res && ((hp->happy_flags & (HFLAG_QUATTRO|HFLAG_PCI)) != HFLAG_QUATTRO))
2215*4882a593Smuzhiyun free_irq(hp->irq, dev);
2216*4882a593Smuzhiyun return res;
2217*4882a593Smuzhiyun }
2218*4882a593Smuzhiyun
happy_meal_close(struct net_device * dev)2219*4882a593Smuzhiyun static int happy_meal_close(struct net_device *dev)
2220*4882a593Smuzhiyun {
2221*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2222*4882a593Smuzhiyun
2223*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
2224*4882a593Smuzhiyun happy_meal_stop(hp, hp->gregs);
2225*4882a593Smuzhiyun happy_meal_clean_rings(hp);
2226*4882a593Smuzhiyun
2227*4882a593Smuzhiyun /* If auto-negotiation timer is running, kill it. */
2228*4882a593Smuzhiyun del_timer(&hp->happy_timer);
2229*4882a593Smuzhiyun
2230*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2231*4882a593Smuzhiyun
2232*4882a593Smuzhiyun /* On Quattro QFE cards, all hme interrupts are concentrated
2233*4882a593Smuzhiyun * into a single source which we register handling at probe
2234*4882a593Smuzhiyun * time and never unregister.
2235*4882a593Smuzhiyun */
2236*4882a593Smuzhiyun if ((hp->happy_flags & (HFLAG_QUATTRO|HFLAG_PCI)) != HFLAG_QUATTRO)
2237*4882a593Smuzhiyun free_irq(hp->irq, dev);
2238*4882a593Smuzhiyun
2239*4882a593Smuzhiyun return 0;
2240*4882a593Smuzhiyun }
2241*4882a593Smuzhiyun
2242*4882a593Smuzhiyun #ifdef SXDEBUG
2243*4882a593Smuzhiyun #define SXD(x) printk x
2244*4882a593Smuzhiyun #else
2245*4882a593Smuzhiyun #define SXD(x)
2246*4882a593Smuzhiyun #endif
2247*4882a593Smuzhiyun
happy_meal_tx_timeout(struct net_device * dev,unsigned int txqueue)2248*4882a593Smuzhiyun static void happy_meal_tx_timeout(struct net_device *dev, unsigned int txqueue)
2249*4882a593Smuzhiyun {
2250*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2251*4882a593Smuzhiyun
2252*4882a593Smuzhiyun printk (KERN_ERR "%s: transmit timed out, resetting\n", dev->name);
2253*4882a593Smuzhiyun tx_dump_log();
2254*4882a593Smuzhiyun printk (KERN_ERR "%s: Happy Status %08x TX[%08x:%08x]\n", dev->name,
2255*4882a593Smuzhiyun hme_read32(hp, hp->gregs + GREG_STAT),
2256*4882a593Smuzhiyun hme_read32(hp, hp->etxregs + ETX_CFG),
2257*4882a593Smuzhiyun hme_read32(hp, hp->bigmacregs + BMAC_TXCFG));
2258*4882a593Smuzhiyun
2259*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
2260*4882a593Smuzhiyun happy_meal_init(hp);
2261*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2262*4882a593Smuzhiyun
2263*4882a593Smuzhiyun netif_wake_queue(dev);
2264*4882a593Smuzhiyun }
2265*4882a593Smuzhiyun
unmap_partial_tx_skb(struct happy_meal * hp,u32 first_mapping,u32 first_len,u32 first_entry,u32 entry)2266*4882a593Smuzhiyun static void unmap_partial_tx_skb(struct happy_meal *hp, u32 first_mapping,
2267*4882a593Smuzhiyun u32 first_len, u32 first_entry, u32 entry)
2268*4882a593Smuzhiyun {
2269*4882a593Smuzhiyun struct happy_meal_txd *txbase = &hp->happy_block->happy_meal_txd[0];
2270*4882a593Smuzhiyun
2271*4882a593Smuzhiyun dma_unmap_single(hp->dma_dev, first_mapping, first_len, DMA_TO_DEVICE);
2272*4882a593Smuzhiyun
2273*4882a593Smuzhiyun first_entry = NEXT_TX(first_entry);
2274*4882a593Smuzhiyun while (first_entry != entry) {
2275*4882a593Smuzhiyun struct happy_meal_txd *this = &txbase[first_entry];
2276*4882a593Smuzhiyun u32 addr, len;
2277*4882a593Smuzhiyun
2278*4882a593Smuzhiyun addr = hme_read_desc32(hp, &this->tx_addr);
2279*4882a593Smuzhiyun len = hme_read_desc32(hp, &this->tx_flags);
2280*4882a593Smuzhiyun len &= TXFLAG_SIZE;
2281*4882a593Smuzhiyun dma_unmap_page(hp->dma_dev, addr, len, DMA_TO_DEVICE);
2282*4882a593Smuzhiyun }
2283*4882a593Smuzhiyun }
2284*4882a593Smuzhiyun
happy_meal_start_xmit(struct sk_buff * skb,struct net_device * dev)2285*4882a593Smuzhiyun static netdev_tx_t happy_meal_start_xmit(struct sk_buff *skb,
2286*4882a593Smuzhiyun struct net_device *dev)
2287*4882a593Smuzhiyun {
2288*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2289*4882a593Smuzhiyun int entry;
2290*4882a593Smuzhiyun u32 tx_flags;
2291*4882a593Smuzhiyun
2292*4882a593Smuzhiyun tx_flags = TXFLAG_OWN;
2293*4882a593Smuzhiyun if (skb->ip_summed == CHECKSUM_PARTIAL) {
2294*4882a593Smuzhiyun const u32 csum_start_off = skb_checksum_start_offset(skb);
2295*4882a593Smuzhiyun const u32 csum_stuff_off = csum_start_off + skb->csum_offset;
2296*4882a593Smuzhiyun
2297*4882a593Smuzhiyun tx_flags = (TXFLAG_OWN | TXFLAG_CSENABLE |
2298*4882a593Smuzhiyun ((csum_start_off << 14) & TXFLAG_CSBUFBEGIN) |
2299*4882a593Smuzhiyun ((csum_stuff_off << 20) & TXFLAG_CSLOCATION));
2300*4882a593Smuzhiyun }
2301*4882a593Smuzhiyun
2302*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
2303*4882a593Smuzhiyun
2304*4882a593Smuzhiyun if (TX_BUFFS_AVAIL(hp) <= (skb_shinfo(skb)->nr_frags + 1)) {
2305*4882a593Smuzhiyun netif_stop_queue(dev);
2306*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2307*4882a593Smuzhiyun printk(KERN_ERR "%s: BUG! Tx Ring full when queue awake!\n",
2308*4882a593Smuzhiyun dev->name);
2309*4882a593Smuzhiyun return NETDEV_TX_BUSY;
2310*4882a593Smuzhiyun }
2311*4882a593Smuzhiyun
2312*4882a593Smuzhiyun entry = hp->tx_new;
2313*4882a593Smuzhiyun SXD(("SX<l[%d]e[%d]>", len, entry));
2314*4882a593Smuzhiyun hp->tx_skbs[entry] = skb;
2315*4882a593Smuzhiyun
2316*4882a593Smuzhiyun if (skb_shinfo(skb)->nr_frags == 0) {
2317*4882a593Smuzhiyun u32 mapping, len;
2318*4882a593Smuzhiyun
2319*4882a593Smuzhiyun len = skb->len;
2320*4882a593Smuzhiyun mapping = dma_map_single(hp->dma_dev, skb->data, len, DMA_TO_DEVICE);
2321*4882a593Smuzhiyun if (unlikely(dma_mapping_error(hp->dma_dev, mapping)))
2322*4882a593Smuzhiyun goto out_dma_error;
2323*4882a593Smuzhiyun tx_flags |= (TXFLAG_SOP | TXFLAG_EOP);
2324*4882a593Smuzhiyun hme_write_txd(hp, &hp->happy_block->happy_meal_txd[entry],
2325*4882a593Smuzhiyun (tx_flags | (len & TXFLAG_SIZE)),
2326*4882a593Smuzhiyun mapping);
2327*4882a593Smuzhiyun entry = NEXT_TX(entry);
2328*4882a593Smuzhiyun } else {
2329*4882a593Smuzhiyun u32 first_len, first_mapping;
2330*4882a593Smuzhiyun int frag, first_entry = entry;
2331*4882a593Smuzhiyun
2332*4882a593Smuzhiyun /* We must give this initial chunk to the device last.
2333*4882a593Smuzhiyun * Otherwise we could race with the device.
2334*4882a593Smuzhiyun */
2335*4882a593Smuzhiyun first_len = skb_headlen(skb);
2336*4882a593Smuzhiyun first_mapping = dma_map_single(hp->dma_dev, skb->data, first_len,
2337*4882a593Smuzhiyun DMA_TO_DEVICE);
2338*4882a593Smuzhiyun if (unlikely(dma_mapping_error(hp->dma_dev, first_mapping)))
2339*4882a593Smuzhiyun goto out_dma_error;
2340*4882a593Smuzhiyun entry = NEXT_TX(entry);
2341*4882a593Smuzhiyun
2342*4882a593Smuzhiyun for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
2343*4882a593Smuzhiyun const skb_frag_t *this_frag = &skb_shinfo(skb)->frags[frag];
2344*4882a593Smuzhiyun u32 len, mapping, this_txflags;
2345*4882a593Smuzhiyun
2346*4882a593Smuzhiyun len = skb_frag_size(this_frag);
2347*4882a593Smuzhiyun mapping = skb_frag_dma_map(hp->dma_dev, this_frag,
2348*4882a593Smuzhiyun 0, len, DMA_TO_DEVICE);
2349*4882a593Smuzhiyun if (unlikely(dma_mapping_error(hp->dma_dev, mapping))) {
2350*4882a593Smuzhiyun unmap_partial_tx_skb(hp, first_mapping, first_len,
2351*4882a593Smuzhiyun first_entry, entry);
2352*4882a593Smuzhiyun goto out_dma_error;
2353*4882a593Smuzhiyun }
2354*4882a593Smuzhiyun this_txflags = tx_flags;
2355*4882a593Smuzhiyun if (frag == skb_shinfo(skb)->nr_frags - 1)
2356*4882a593Smuzhiyun this_txflags |= TXFLAG_EOP;
2357*4882a593Smuzhiyun hme_write_txd(hp, &hp->happy_block->happy_meal_txd[entry],
2358*4882a593Smuzhiyun (this_txflags | (len & TXFLAG_SIZE)),
2359*4882a593Smuzhiyun mapping);
2360*4882a593Smuzhiyun entry = NEXT_TX(entry);
2361*4882a593Smuzhiyun }
2362*4882a593Smuzhiyun hme_write_txd(hp, &hp->happy_block->happy_meal_txd[first_entry],
2363*4882a593Smuzhiyun (tx_flags | TXFLAG_SOP | (first_len & TXFLAG_SIZE)),
2364*4882a593Smuzhiyun first_mapping);
2365*4882a593Smuzhiyun }
2366*4882a593Smuzhiyun
2367*4882a593Smuzhiyun hp->tx_new = entry;
2368*4882a593Smuzhiyun
2369*4882a593Smuzhiyun if (TX_BUFFS_AVAIL(hp) <= (MAX_SKB_FRAGS + 1))
2370*4882a593Smuzhiyun netif_stop_queue(dev);
2371*4882a593Smuzhiyun
2372*4882a593Smuzhiyun /* Get it going. */
2373*4882a593Smuzhiyun hme_write32(hp, hp->etxregs + ETX_PENDING, ETX_TP_DMAWAKEUP);
2374*4882a593Smuzhiyun
2375*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2376*4882a593Smuzhiyun
2377*4882a593Smuzhiyun tx_add_log(hp, TXLOG_ACTION_TXMIT, 0);
2378*4882a593Smuzhiyun return NETDEV_TX_OK;
2379*4882a593Smuzhiyun
2380*4882a593Smuzhiyun out_dma_error:
2381*4882a593Smuzhiyun hp->tx_skbs[hp->tx_new] = NULL;
2382*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2383*4882a593Smuzhiyun
2384*4882a593Smuzhiyun dev_kfree_skb_any(skb);
2385*4882a593Smuzhiyun dev->stats.tx_dropped++;
2386*4882a593Smuzhiyun return NETDEV_TX_OK;
2387*4882a593Smuzhiyun }
2388*4882a593Smuzhiyun
happy_meal_get_stats(struct net_device * dev)2389*4882a593Smuzhiyun static struct net_device_stats *happy_meal_get_stats(struct net_device *dev)
2390*4882a593Smuzhiyun {
2391*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2392*4882a593Smuzhiyun
2393*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
2394*4882a593Smuzhiyun happy_meal_get_counters(hp, hp->bigmacregs);
2395*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2396*4882a593Smuzhiyun
2397*4882a593Smuzhiyun return &dev->stats;
2398*4882a593Smuzhiyun }
2399*4882a593Smuzhiyun
happy_meal_set_multicast(struct net_device * dev)2400*4882a593Smuzhiyun static void happy_meal_set_multicast(struct net_device *dev)
2401*4882a593Smuzhiyun {
2402*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2403*4882a593Smuzhiyun void __iomem *bregs = hp->bigmacregs;
2404*4882a593Smuzhiyun struct netdev_hw_addr *ha;
2405*4882a593Smuzhiyun u32 crc;
2406*4882a593Smuzhiyun
2407*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
2408*4882a593Smuzhiyun
2409*4882a593Smuzhiyun if ((dev->flags & IFF_ALLMULTI) || (netdev_mc_count(dev) > 64)) {
2410*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE0, 0xffff);
2411*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE1, 0xffff);
2412*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE2, 0xffff);
2413*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE3, 0xffff);
2414*4882a593Smuzhiyun } else if (dev->flags & IFF_PROMISC) {
2415*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_RXCFG,
2416*4882a593Smuzhiyun hme_read32(hp, bregs + BMAC_RXCFG) | BIGMAC_RXCFG_PMISC);
2417*4882a593Smuzhiyun } else {
2418*4882a593Smuzhiyun u16 hash_table[4];
2419*4882a593Smuzhiyun
2420*4882a593Smuzhiyun memset(hash_table, 0, sizeof(hash_table));
2421*4882a593Smuzhiyun netdev_for_each_mc_addr(ha, dev) {
2422*4882a593Smuzhiyun crc = ether_crc_le(6, ha->addr);
2423*4882a593Smuzhiyun crc >>= 26;
2424*4882a593Smuzhiyun hash_table[crc >> 4] |= 1 << (crc & 0xf);
2425*4882a593Smuzhiyun }
2426*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE0, hash_table[0]);
2427*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE1, hash_table[1]);
2428*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE2, hash_table[2]);
2429*4882a593Smuzhiyun hme_write32(hp, bregs + BMAC_HTABLE3, hash_table[3]);
2430*4882a593Smuzhiyun }
2431*4882a593Smuzhiyun
2432*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2433*4882a593Smuzhiyun }
2434*4882a593Smuzhiyun
2435*4882a593Smuzhiyun /* Ethtool support... */
hme_get_link_ksettings(struct net_device * dev,struct ethtool_link_ksettings * cmd)2436*4882a593Smuzhiyun static int hme_get_link_ksettings(struct net_device *dev,
2437*4882a593Smuzhiyun struct ethtool_link_ksettings *cmd)
2438*4882a593Smuzhiyun {
2439*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2440*4882a593Smuzhiyun u32 speed;
2441*4882a593Smuzhiyun u32 supported;
2442*4882a593Smuzhiyun
2443*4882a593Smuzhiyun supported =
2444*4882a593Smuzhiyun (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
2445*4882a593Smuzhiyun SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
2446*4882a593Smuzhiyun SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII);
2447*4882a593Smuzhiyun
2448*4882a593Smuzhiyun /* XXX hardcoded stuff for now */
2449*4882a593Smuzhiyun cmd->base.port = PORT_TP; /* XXX no MII support */
2450*4882a593Smuzhiyun cmd->base.phy_address = 0; /* XXX fixed PHYAD */
2451*4882a593Smuzhiyun
2452*4882a593Smuzhiyun /* Record PHY settings. */
2453*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
2454*4882a593Smuzhiyun hp->sw_bmcr = happy_meal_tcvr_read(hp, hp->tcvregs, MII_BMCR);
2455*4882a593Smuzhiyun hp->sw_lpa = happy_meal_tcvr_read(hp, hp->tcvregs, MII_LPA);
2456*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2457*4882a593Smuzhiyun
2458*4882a593Smuzhiyun if (hp->sw_bmcr & BMCR_ANENABLE) {
2459*4882a593Smuzhiyun cmd->base.autoneg = AUTONEG_ENABLE;
2460*4882a593Smuzhiyun speed = ((hp->sw_lpa & (LPA_100HALF | LPA_100FULL)) ?
2461*4882a593Smuzhiyun SPEED_100 : SPEED_10);
2462*4882a593Smuzhiyun if (speed == SPEED_100)
2463*4882a593Smuzhiyun cmd->base.duplex =
2464*4882a593Smuzhiyun (hp->sw_lpa & (LPA_100FULL)) ?
2465*4882a593Smuzhiyun DUPLEX_FULL : DUPLEX_HALF;
2466*4882a593Smuzhiyun else
2467*4882a593Smuzhiyun cmd->base.duplex =
2468*4882a593Smuzhiyun (hp->sw_lpa & (LPA_10FULL)) ?
2469*4882a593Smuzhiyun DUPLEX_FULL : DUPLEX_HALF;
2470*4882a593Smuzhiyun } else {
2471*4882a593Smuzhiyun cmd->base.autoneg = AUTONEG_DISABLE;
2472*4882a593Smuzhiyun speed = (hp->sw_bmcr & BMCR_SPEED100) ? SPEED_100 : SPEED_10;
2473*4882a593Smuzhiyun cmd->base.duplex =
2474*4882a593Smuzhiyun (hp->sw_bmcr & BMCR_FULLDPLX) ?
2475*4882a593Smuzhiyun DUPLEX_FULL : DUPLEX_HALF;
2476*4882a593Smuzhiyun }
2477*4882a593Smuzhiyun cmd->base.speed = speed;
2478*4882a593Smuzhiyun ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
2479*4882a593Smuzhiyun supported);
2480*4882a593Smuzhiyun
2481*4882a593Smuzhiyun return 0;
2482*4882a593Smuzhiyun }
2483*4882a593Smuzhiyun
hme_set_link_ksettings(struct net_device * dev,const struct ethtool_link_ksettings * cmd)2484*4882a593Smuzhiyun static int hme_set_link_ksettings(struct net_device *dev,
2485*4882a593Smuzhiyun const struct ethtool_link_ksettings *cmd)
2486*4882a593Smuzhiyun {
2487*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2488*4882a593Smuzhiyun
2489*4882a593Smuzhiyun /* Verify the settings we care about. */
2490*4882a593Smuzhiyun if (cmd->base.autoneg != AUTONEG_ENABLE &&
2491*4882a593Smuzhiyun cmd->base.autoneg != AUTONEG_DISABLE)
2492*4882a593Smuzhiyun return -EINVAL;
2493*4882a593Smuzhiyun if (cmd->base.autoneg == AUTONEG_DISABLE &&
2494*4882a593Smuzhiyun ((cmd->base.speed != SPEED_100 &&
2495*4882a593Smuzhiyun cmd->base.speed != SPEED_10) ||
2496*4882a593Smuzhiyun (cmd->base.duplex != DUPLEX_HALF &&
2497*4882a593Smuzhiyun cmd->base.duplex != DUPLEX_FULL)))
2498*4882a593Smuzhiyun return -EINVAL;
2499*4882a593Smuzhiyun
2500*4882a593Smuzhiyun /* Ok, do it to it. */
2501*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
2502*4882a593Smuzhiyun del_timer(&hp->happy_timer);
2503*4882a593Smuzhiyun happy_meal_begin_auto_negotiation(hp, hp->tcvregs, cmd);
2504*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2505*4882a593Smuzhiyun
2506*4882a593Smuzhiyun return 0;
2507*4882a593Smuzhiyun }
2508*4882a593Smuzhiyun
hme_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)2509*4882a593Smuzhiyun static void hme_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2510*4882a593Smuzhiyun {
2511*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2512*4882a593Smuzhiyun
2513*4882a593Smuzhiyun strlcpy(info->driver, "sunhme", sizeof(info->driver));
2514*4882a593Smuzhiyun strlcpy(info->version, "2.02", sizeof(info->version));
2515*4882a593Smuzhiyun if (hp->happy_flags & HFLAG_PCI) {
2516*4882a593Smuzhiyun struct pci_dev *pdev = hp->happy_dev;
2517*4882a593Smuzhiyun strlcpy(info->bus_info, pci_name(pdev), sizeof(info->bus_info));
2518*4882a593Smuzhiyun }
2519*4882a593Smuzhiyun #ifdef CONFIG_SBUS
2520*4882a593Smuzhiyun else {
2521*4882a593Smuzhiyun const struct linux_prom_registers *regs;
2522*4882a593Smuzhiyun struct platform_device *op = hp->happy_dev;
2523*4882a593Smuzhiyun regs = of_get_property(op->dev.of_node, "regs", NULL);
2524*4882a593Smuzhiyun if (regs)
2525*4882a593Smuzhiyun snprintf(info->bus_info, sizeof(info->bus_info),
2526*4882a593Smuzhiyun "SBUS:%d",
2527*4882a593Smuzhiyun regs->which_io);
2528*4882a593Smuzhiyun }
2529*4882a593Smuzhiyun #endif
2530*4882a593Smuzhiyun }
2531*4882a593Smuzhiyun
hme_get_link(struct net_device * dev)2532*4882a593Smuzhiyun static u32 hme_get_link(struct net_device *dev)
2533*4882a593Smuzhiyun {
2534*4882a593Smuzhiyun struct happy_meal *hp = netdev_priv(dev);
2535*4882a593Smuzhiyun
2536*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
2537*4882a593Smuzhiyun hp->sw_bmcr = happy_meal_tcvr_read(hp, hp->tcvregs, MII_BMCR);
2538*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2539*4882a593Smuzhiyun
2540*4882a593Smuzhiyun return hp->sw_bmsr & BMSR_LSTATUS;
2541*4882a593Smuzhiyun }
2542*4882a593Smuzhiyun
2543*4882a593Smuzhiyun static const struct ethtool_ops hme_ethtool_ops = {
2544*4882a593Smuzhiyun .get_drvinfo = hme_get_drvinfo,
2545*4882a593Smuzhiyun .get_link = hme_get_link,
2546*4882a593Smuzhiyun .get_link_ksettings = hme_get_link_ksettings,
2547*4882a593Smuzhiyun .set_link_ksettings = hme_set_link_ksettings,
2548*4882a593Smuzhiyun };
2549*4882a593Smuzhiyun
2550*4882a593Smuzhiyun static int hme_version_printed;
2551*4882a593Smuzhiyun
2552*4882a593Smuzhiyun #ifdef CONFIG_SBUS
2553*4882a593Smuzhiyun /* Given a happy meal sbus device, find it's quattro parent.
2554*4882a593Smuzhiyun * If none exist, allocate and return a new one.
2555*4882a593Smuzhiyun *
2556*4882a593Smuzhiyun * Return NULL on failure.
2557*4882a593Smuzhiyun */
quattro_sbus_find(struct platform_device * child)2558*4882a593Smuzhiyun static struct quattro *quattro_sbus_find(struct platform_device *child)
2559*4882a593Smuzhiyun {
2560*4882a593Smuzhiyun struct device *parent = child->dev.parent;
2561*4882a593Smuzhiyun struct platform_device *op;
2562*4882a593Smuzhiyun struct quattro *qp;
2563*4882a593Smuzhiyun
2564*4882a593Smuzhiyun op = to_platform_device(parent);
2565*4882a593Smuzhiyun qp = platform_get_drvdata(op);
2566*4882a593Smuzhiyun if (qp)
2567*4882a593Smuzhiyun return qp;
2568*4882a593Smuzhiyun
2569*4882a593Smuzhiyun qp = kmalloc(sizeof(struct quattro), GFP_KERNEL);
2570*4882a593Smuzhiyun if (qp != NULL) {
2571*4882a593Smuzhiyun int i;
2572*4882a593Smuzhiyun
2573*4882a593Smuzhiyun for (i = 0; i < 4; i++)
2574*4882a593Smuzhiyun qp->happy_meals[i] = NULL;
2575*4882a593Smuzhiyun
2576*4882a593Smuzhiyun qp->quattro_dev = child;
2577*4882a593Smuzhiyun qp->next = qfe_sbus_list;
2578*4882a593Smuzhiyun qfe_sbus_list = qp;
2579*4882a593Smuzhiyun
2580*4882a593Smuzhiyun platform_set_drvdata(op, qp);
2581*4882a593Smuzhiyun }
2582*4882a593Smuzhiyun return qp;
2583*4882a593Smuzhiyun }
2584*4882a593Smuzhiyun
2585*4882a593Smuzhiyun /* After all quattro cards have been probed, we call these functions
2586*4882a593Smuzhiyun * to register the IRQ handlers for the cards that have been
2587*4882a593Smuzhiyun * successfully probed and skip the cards that failed to initialize
2588*4882a593Smuzhiyun */
quattro_sbus_register_irqs(void)2589*4882a593Smuzhiyun static int __init quattro_sbus_register_irqs(void)
2590*4882a593Smuzhiyun {
2591*4882a593Smuzhiyun struct quattro *qp;
2592*4882a593Smuzhiyun
2593*4882a593Smuzhiyun for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) {
2594*4882a593Smuzhiyun struct platform_device *op = qp->quattro_dev;
2595*4882a593Smuzhiyun int err, qfe_slot, skip = 0;
2596*4882a593Smuzhiyun
2597*4882a593Smuzhiyun for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) {
2598*4882a593Smuzhiyun if (!qp->happy_meals[qfe_slot])
2599*4882a593Smuzhiyun skip = 1;
2600*4882a593Smuzhiyun }
2601*4882a593Smuzhiyun if (skip)
2602*4882a593Smuzhiyun continue;
2603*4882a593Smuzhiyun
2604*4882a593Smuzhiyun err = request_irq(op->archdata.irqs[0],
2605*4882a593Smuzhiyun quattro_sbus_interrupt,
2606*4882a593Smuzhiyun IRQF_SHARED, "Quattro",
2607*4882a593Smuzhiyun qp);
2608*4882a593Smuzhiyun if (err != 0) {
2609*4882a593Smuzhiyun printk(KERN_ERR "Quattro HME: IRQ registration "
2610*4882a593Smuzhiyun "error %d.\n", err);
2611*4882a593Smuzhiyun return err;
2612*4882a593Smuzhiyun }
2613*4882a593Smuzhiyun }
2614*4882a593Smuzhiyun
2615*4882a593Smuzhiyun return 0;
2616*4882a593Smuzhiyun }
2617*4882a593Smuzhiyun
quattro_sbus_free_irqs(void)2618*4882a593Smuzhiyun static void quattro_sbus_free_irqs(void)
2619*4882a593Smuzhiyun {
2620*4882a593Smuzhiyun struct quattro *qp;
2621*4882a593Smuzhiyun
2622*4882a593Smuzhiyun for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) {
2623*4882a593Smuzhiyun struct platform_device *op = qp->quattro_dev;
2624*4882a593Smuzhiyun int qfe_slot, skip = 0;
2625*4882a593Smuzhiyun
2626*4882a593Smuzhiyun for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) {
2627*4882a593Smuzhiyun if (!qp->happy_meals[qfe_slot])
2628*4882a593Smuzhiyun skip = 1;
2629*4882a593Smuzhiyun }
2630*4882a593Smuzhiyun if (skip)
2631*4882a593Smuzhiyun continue;
2632*4882a593Smuzhiyun
2633*4882a593Smuzhiyun free_irq(op->archdata.irqs[0], qp);
2634*4882a593Smuzhiyun }
2635*4882a593Smuzhiyun }
2636*4882a593Smuzhiyun #endif /* CONFIG_SBUS */
2637*4882a593Smuzhiyun
2638*4882a593Smuzhiyun #ifdef CONFIG_PCI
quattro_pci_find(struct pci_dev * pdev)2639*4882a593Smuzhiyun static struct quattro *quattro_pci_find(struct pci_dev *pdev)
2640*4882a593Smuzhiyun {
2641*4882a593Smuzhiyun struct pci_dev *bdev = pdev->bus->self;
2642*4882a593Smuzhiyun struct quattro *qp;
2643*4882a593Smuzhiyun
2644*4882a593Smuzhiyun if (!bdev) return NULL;
2645*4882a593Smuzhiyun for (qp = qfe_pci_list; qp != NULL; qp = qp->next) {
2646*4882a593Smuzhiyun struct pci_dev *qpdev = qp->quattro_dev;
2647*4882a593Smuzhiyun
2648*4882a593Smuzhiyun if (qpdev == bdev)
2649*4882a593Smuzhiyun return qp;
2650*4882a593Smuzhiyun }
2651*4882a593Smuzhiyun qp = kmalloc(sizeof(struct quattro), GFP_KERNEL);
2652*4882a593Smuzhiyun if (qp != NULL) {
2653*4882a593Smuzhiyun int i;
2654*4882a593Smuzhiyun
2655*4882a593Smuzhiyun for (i = 0; i < 4; i++)
2656*4882a593Smuzhiyun qp->happy_meals[i] = NULL;
2657*4882a593Smuzhiyun
2658*4882a593Smuzhiyun qp->quattro_dev = bdev;
2659*4882a593Smuzhiyun qp->next = qfe_pci_list;
2660*4882a593Smuzhiyun qfe_pci_list = qp;
2661*4882a593Smuzhiyun
2662*4882a593Smuzhiyun /* No range tricks necessary on PCI. */
2663*4882a593Smuzhiyun qp->nranges = 0;
2664*4882a593Smuzhiyun }
2665*4882a593Smuzhiyun return qp;
2666*4882a593Smuzhiyun }
2667*4882a593Smuzhiyun #endif /* CONFIG_PCI */
2668*4882a593Smuzhiyun
2669*4882a593Smuzhiyun static const struct net_device_ops hme_netdev_ops = {
2670*4882a593Smuzhiyun .ndo_open = happy_meal_open,
2671*4882a593Smuzhiyun .ndo_stop = happy_meal_close,
2672*4882a593Smuzhiyun .ndo_start_xmit = happy_meal_start_xmit,
2673*4882a593Smuzhiyun .ndo_tx_timeout = happy_meal_tx_timeout,
2674*4882a593Smuzhiyun .ndo_get_stats = happy_meal_get_stats,
2675*4882a593Smuzhiyun .ndo_set_rx_mode = happy_meal_set_multicast,
2676*4882a593Smuzhiyun .ndo_set_mac_address = eth_mac_addr,
2677*4882a593Smuzhiyun .ndo_validate_addr = eth_validate_addr,
2678*4882a593Smuzhiyun };
2679*4882a593Smuzhiyun
2680*4882a593Smuzhiyun #ifdef CONFIG_SBUS
happy_meal_sbus_probe_one(struct platform_device * op,int is_qfe)2681*4882a593Smuzhiyun static int happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe)
2682*4882a593Smuzhiyun {
2683*4882a593Smuzhiyun struct device_node *dp = op->dev.of_node, *sbus_dp;
2684*4882a593Smuzhiyun struct quattro *qp = NULL;
2685*4882a593Smuzhiyun struct happy_meal *hp;
2686*4882a593Smuzhiyun struct net_device *dev;
2687*4882a593Smuzhiyun int i, qfe_slot = -1;
2688*4882a593Smuzhiyun int err = -ENODEV;
2689*4882a593Smuzhiyun
2690*4882a593Smuzhiyun sbus_dp = op->dev.parent->of_node;
2691*4882a593Smuzhiyun
2692*4882a593Smuzhiyun /* We can match PCI devices too, do not accept those here. */
2693*4882a593Smuzhiyun if (!of_node_name_eq(sbus_dp, "sbus") && !of_node_name_eq(sbus_dp, "sbi"))
2694*4882a593Smuzhiyun return err;
2695*4882a593Smuzhiyun
2696*4882a593Smuzhiyun if (is_qfe) {
2697*4882a593Smuzhiyun qp = quattro_sbus_find(op);
2698*4882a593Smuzhiyun if (qp == NULL)
2699*4882a593Smuzhiyun goto err_out;
2700*4882a593Smuzhiyun for (qfe_slot = 0; qfe_slot < 4; qfe_slot++)
2701*4882a593Smuzhiyun if (qp->happy_meals[qfe_slot] == NULL)
2702*4882a593Smuzhiyun break;
2703*4882a593Smuzhiyun if (qfe_slot == 4)
2704*4882a593Smuzhiyun goto err_out;
2705*4882a593Smuzhiyun }
2706*4882a593Smuzhiyun
2707*4882a593Smuzhiyun err = -ENOMEM;
2708*4882a593Smuzhiyun dev = alloc_etherdev(sizeof(struct happy_meal));
2709*4882a593Smuzhiyun if (!dev)
2710*4882a593Smuzhiyun goto err_out;
2711*4882a593Smuzhiyun SET_NETDEV_DEV(dev, &op->dev);
2712*4882a593Smuzhiyun
2713*4882a593Smuzhiyun if (hme_version_printed++ == 0)
2714*4882a593Smuzhiyun printk(KERN_INFO "%s", version);
2715*4882a593Smuzhiyun
2716*4882a593Smuzhiyun /* If user did not specify a MAC address specifically, use
2717*4882a593Smuzhiyun * the Quattro local-mac-address property...
2718*4882a593Smuzhiyun */
2719*4882a593Smuzhiyun for (i = 0; i < 6; i++) {
2720*4882a593Smuzhiyun if (macaddr[i] != 0)
2721*4882a593Smuzhiyun break;
2722*4882a593Smuzhiyun }
2723*4882a593Smuzhiyun if (i < 6) { /* a mac address was given */
2724*4882a593Smuzhiyun for (i = 0; i < 6; i++)
2725*4882a593Smuzhiyun dev->dev_addr[i] = macaddr[i];
2726*4882a593Smuzhiyun macaddr[5]++;
2727*4882a593Smuzhiyun } else {
2728*4882a593Smuzhiyun const unsigned char *addr;
2729*4882a593Smuzhiyun int len;
2730*4882a593Smuzhiyun
2731*4882a593Smuzhiyun addr = of_get_property(dp, "local-mac-address", &len);
2732*4882a593Smuzhiyun
2733*4882a593Smuzhiyun if (qfe_slot != -1 && addr && len == ETH_ALEN)
2734*4882a593Smuzhiyun memcpy(dev->dev_addr, addr, ETH_ALEN);
2735*4882a593Smuzhiyun else
2736*4882a593Smuzhiyun memcpy(dev->dev_addr, idprom->id_ethaddr, ETH_ALEN);
2737*4882a593Smuzhiyun }
2738*4882a593Smuzhiyun
2739*4882a593Smuzhiyun hp = netdev_priv(dev);
2740*4882a593Smuzhiyun
2741*4882a593Smuzhiyun hp->happy_dev = op;
2742*4882a593Smuzhiyun hp->dma_dev = &op->dev;
2743*4882a593Smuzhiyun
2744*4882a593Smuzhiyun spin_lock_init(&hp->happy_lock);
2745*4882a593Smuzhiyun
2746*4882a593Smuzhiyun err = -ENODEV;
2747*4882a593Smuzhiyun if (qp != NULL) {
2748*4882a593Smuzhiyun hp->qfe_parent = qp;
2749*4882a593Smuzhiyun hp->qfe_ent = qfe_slot;
2750*4882a593Smuzhiyun qp->happy_meals[qfe_slot] = dev;
2751*4882a593Smuzhiyun }
2752*4882a593Smuzhiyun
2753*4882a593Smuzhiyun hp->gregs = of_ioremap(&op->resource[0], 0,
2754*4882a593Smuzhiyun GREG_REG_SIZE, "HME Global Regs");
2755*4882a593Smuzhiyun if (!hp->gregs) {
2756*4882a593Smuzhiyun printk(KERN_ERR "happymeal: Cannot map global registers.\n");
2757*4882a593Smuzhiyun goto err_out_free_netdev;
2758*4882a593Smuzhiyun }
2759*4882a593Smuzhiyun
2760*4882a593Smuzhiyun hp->etxregs = of_ioremap(&op->resource[1], 0,
2761*4882a593Smuzhiyun ETX_REG_SIZE, "HME TX Regs");
2762*4882a593Smuzhiyun if (!hp->etxregs) {
2763*4882a593Smuzhiyun printk(KERN_ERR "happymeal: Cannot map MAC TX registers.\n");
2764*4882a593Smuzhiyun goto err_out_iounmap;
2765*4882a593Smuzhiyun }
2766*4882a593Smuzhiyun
2767*4882a593Smuzhiyun hp->erxregs = of_ioremap(&op->resource[2], 0,
2768*4882a593Smuzhiyun ERX_REG_SIZE, "HME RX Regs");
2769*4882a593Smuzhiyun if (!hp->erxregs) {
2770*4882a593Smuzhiyun printk(KERN_ERR "happymeal: Cannot map MAC RX registers.\n");
2771*4882a593Smuzhiyun goto err_out_iounmap;
2772*4882a593Smuzhiyun }
2773*4882a593Smuzhiyun
2774*4882a593Smuzhiyun hp->bigmacregs = of_ioremap(&op->resource[3], 0,
2775*4882a593Smuzhiyun BMAC_REG_SIZE, "HME BIGMAC Regs");
2776*4882a593Smuzhiyun if (!hp->bigmacregs) {
2777*4882a593Smuzhiyun printk(KERN_ERR "happymeal: Cannot map BIGMAC registers.\n");
2778*4882a593Smuzhiyun goto err_out_iounmap;
2779*4882a593Smuzhiyun }
2780*4882a593Smuzhiyun
2781*4882a593Smuzhiyun hp->tcvregs = of_ioremap(&op->resource[4], 0,
2782*4882a593Smuzhiyun TCVR_REG_SIZE, "HME Tranceiver Regs");
2783*4882a593Smuzhiyun if (!hp->tcvregs) {
2784*4882a593Smuzhiyun printk(KERN_ERR "happymeal: Cannot map TCVR registers.\n");
2785*4882a593Smuzhiyun goto err_out_iounmap;
2786*4882a593Smuzhiyun }
2787*4882a593Smuzhiyun
2788*4882a593Smuzhiyun hp->hm_revision = of_getintprop_default(dp, "hm-rev", 0xff);
2789*4882a593Smuzhiyun if (hp->hm_revision == 0xff)
2790*4882a593Smuzhiyun hp->hm_revision = 0xa0;
2791*4882a593Smuzhiyun
2792*4882a593Smuzhiyun /* Now enable the feature flags we can. */
2793*4882a593Smuzhiyun if (hp->hm_revision == 0x20 || hp->hm_revision == 0x21)
2794*4882a593Smuzhiyun hp->happy_flags = HFLAG_20_21;
2795*4882a593Smuzhiyun else if (hp->hm_revision != 0xa0)
2796*4882a593Smuzhiyun hp->happy_flags = HFLAG_NOT_A0;
2797*4882a593Smuzhiyun
2798*4882a593Smuzhiyun if (qp != NULL)
2799*4882a593Smuzhiyun hp->happy_flags |= HFLAG_QUATTRO;
2800*4882a593Smuzhiyun
2801*4882a593Smuzhiyun /* Get the supported DVMA burst sizes from our Happy SBUS. */
2802*4882a593Smuzhiyun hp->happy_bursts = of_getintprop_default(sbus_dp,
2803*4882a593Smuzhiyun "burst-sizes", 0x00);
2804*4882a593Smuzhiyun
2805*4882a593Smuzhiyun hp->happy_block = dma_alloc_coherent(hp->dma_dev,
2806*4882a593Smuzhiyun PAGE_SIZE,
2807*4882a593Smuzhiyun &hp->hblock_dvma,
2808*4882a593Smuzhiyun GFP_ATOMIC);
2809*4882a593Smuzhiyun err = -ENOMEM;
2810*4882a593Smuzhiyun if (!hp->happy_block)
2811*4882a593Smuzhiyun goto err_out_iounmap;
2812*4882a593Smuzhiyun
2813*4882a593Smuzhiyun /* Force check of the link first time we are brought up. */
2814*4882a593Smuzhiyun hp->linkcheck = 0;
2815*4882a593Smuzhiyun
2816*4882a593Smuzhiyun /* Force timer state to 'asleep' with count of zero. */
2817*4882a593Smuzhiyun hp->timer_state = asleep;
2818*4882a593Smuzhiyun hp->timer_ticks = 0;
2819*4882a593Smuzhiyun
2820*4882a593Smuzhiyun timer_setup(&hp->happy_timer, happy_meal_timer, 0);
2821*4882a593Smuzhiyun
2822*4882a593Smuzhiyun hp->dev = dev;
2823*4882a593Smuzhiyun dev->netdev_ops = &hme_netdev_ops;
2824*4882a593Smuzhiyun dev->watchdog_timeo = 5*HZ;
2825*4882a593Smuzhiyun dev->ethtool_ops = &hme_ethtool_ops;
2826*4882a593Smuzhiyun
2827*4882a593Smuzhiyun /* Happy Meal can do it all... */
2828*4882a593Smuzhiyun dev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM;
2829*4882a593Smuzhiyun dev->features |= dev->hw_features | NETIF_F_RXCSUM;
2830*4882a593Smuzhiyun
2831*4882a593Smuzhiyun hp->irq = op->archdata.irqs[0];
2832*4882a593Smuzhiyun
2833*4882a593Smuzhiyun #if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
2834*4882a593Smuzhiyun /* Hook up SBUS register/descriptor accessors. */
2835*4882a593Smuzhiyun hp->read_desc32 = sbus_hme_read_desc32;
2836*4882a593Smuzhiyun hp->write_txd = sbus_hme_write_txd;
2837*4882a593Smuzhiyun hp->write_rxd = sbus_hme_write_rxd;
2838*4882a593Smuzhiyun hp->read32 = sbus_hme_read32;
2839*4882a593Smuzhiyun hp->write32 = sbus_hme_write32;
2840*4882a593Smuzhiyun #endif
2841*4882a593Smuzhiyun
2842*4882a593Smuzhiyun /* Grrr, Happy Meal comes up by default not advertising
2843*4882a593Smuzhiyun * full duplex 100baseT capabilities, fix this.
2844*4882a593Smuzhiyun */
2845*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
2846*4882a593Smuzhiyun happy_meal_set_initial_advertisement(hp);
2847*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
2848*4882a593Smuzhiyun
2849*4882a593Smuzhiyun err = register_netdev(hp->dev);
2850*4882a593Smuzhiyun if (err) {
2851*4882a593Smuzhiyun printk(KERN_ERR "happymeal: Cannot register net device, "
2852*4882a593Smuzhiyun "aborting.\n");
2853*4882a593Smuzhiyun goto err_out_free_coherent;
2854*4882a593Smuzhiyun }
2855*4882a593Smuzhiyun
2856*4882a593Smuzhiyun platform_set_drvdata(op, hp);
2857*4882a593Smuzhiyun
2858*4882a593Smuzhiyun if (qfe_slot != -1)
2859*4882a593Smuzhiyun printk(KERN_INFO "%s: Quattro HME slot %d (SBUS) 10/100baseT Ethernet ",
2860*4882a593Smuzhiyun dev->name, qfe_slot);
2861*4882a593Smuzhiyun else
2862*4882a593Smuzhiyun printk(KERN_INFO "%s: HAPPY MEAL (SBUS) 10/100baseT Ethernet ",
2863*4882a593Smuzhiyun dev->name);
2864*4882a593Smuzhiyun
2865*4882a593Smuzhiyun printk("%pM\n", dev->dev_addr);
2866*4882a593Smuzhiyun
2867*4882a593Smuzhiyun return 0;
2868*4882a593Smuzhiyun
2869*4882a593Smuzhiyun err_out_free_coherent:
2870*4882a593Smuzhiyun dma_free_coherent(hp->dma_dev,
2871*4882a593Smuzhiyun PAGE_SIZE,
2872*4882a593Smuzhiyun hp->happy_block,
2873*4882a593Smuzhiyun hp->hblock_dvma);
2874*4882a593Smuzhiyun
2875*4882a593Smuzhiyun err_out_iounmap:
2876*4882a593Smuzhiyun if (hp->gregs)
2877*4882a593Smuzhiyun of_iounmap(&op->resource[0], hp->gregs, GREG_REG_SIZE);
2878*4882a593Smuzhiyun if (hp->etxregs)
2879*4882a593Smuzhiyun of_iounmap(&op->resource[1], hp->etxregs, ETX_REG_SIZE);
2880*4882a593Smuzhiyun if (hp->erxregs)
2881*4882a593Smuzhiyun of_iounmap(&op->resource[2], hp->erxregs, ERX_REG_SIZE);
2882*4882a593Smuzhiyun if (hp->bigmacregs)
2883*4882a593Smuzhiyun of_iounmap(&op->resource[3], hp->bigmacregs, BMAC_REG_SIZE);
2884*4882a593Smuzhiyun if (hp->tcvregs)
2885*4882a593Smuzhiyun of_iounmap(&op->resource[4], hp->tcvregs, TCVR_REG_SIZE);
2886*4882a593Smuzhiyun
2887*4882a593Smuzhiyun if (qp)
2888*4882a593Smuzhiyun qp->happy_meals[qfe_slot] = NULL;
2889*4882a593Smuzhiyun
2890*4882a593Smuzhiyun err_out_free_netdev:
2891*4882a593Smuzhiyun free_netdev(dev);
2892*4882a593Smuzhiyun
2893*4882a593Smuzhiyun err_out:
2894*4882a593Smuzhiyun return err;
2895*4882a593Smuzhiyun }
2896*4882a593Smuzhiyun #endif
2897*4882a593Smuzhiyun
2898*4882a593Smuzhiyun #ifdef CONFIG_PCI
2899*4882a593Smuzhiyun #ifndef CONFIG_SPARC
is_quattro_p(struct pci_dev * pdev)2900*4882a593Smuzhiyun static int is_quattro_p(struct pci_dev *pdev)
2901*4882a593Smuzhiyun {
2902*4882a593Smuzhiyun struct pci_dev *busdev = pdev->bus->self;
2903*4882a593Smuzhiyun struct pci_dev *this_pdev;
2904*4882a593Smuzhiyun int n_hmes;
2905*4882a593Smuzhiyun
2906*4882a593Smuzhiyun if (busdev == NULL ||
2907*4882a593Smuzhiyun busdev->vendor != PCI_VENDOR_ID_DEC ||
2908*4882a593Smuzhiyun busdev->device != PCI_DEVICE_ID_DEC_21153)
2909*4882a593Smuzhiyun return 0;
2910*4882a593Smuzhiyun
2911*4882a593Smuzhiyun n_hmes = 0;
2912*4882a593Smuzhiyun list_for_each_entry(this_pdev, &pdev->bus->devices, bus_list) {
2913*4882a593Smuzhiyun if (this_pdev->vendor == PCI_VENDOR_ID_SUN &&
2914*4882a593Smuzhiyun this_pdev->device == PCI_DEVICE_ID_SUN_HAPPYMEAL)
2915*4882a593Smuzhiyun n_hmes++;
2916*4882a593Smuzhiyun }
2917*4882a593Smuzhiyun
2918*4882a593Smuzhiyun if (n_hmes != 4)
2919*4882a593Smuzhiyun return 0;
2920*4882a593Smuzhiyun
2921*4882a593Smuzhiyun return 1;
2922*4882a593Smuzhiyun }
2923*4882a593Smuzhiyun
2924*4882a593Smuzhiyun /* Fetch MAC address from vital product data of PCI ROM. */
find_eth_addr_in_vpd(void __iomem * rom_base,int len,int index,unsigned char * dev_addr)2925*4882a593Smuzhiyun static int find_eth_addr_in_vpd(void __iomem *rom_base, int len, int index, unsigned char *dev_addr)
2926*4882a593Smuzhiyun {
2927*4882a593Smuzhiyun int this_offset;
2928*4882a593Smuzhiyun
2929*4882a593Smuzhiyun for (this_offset = 0x20; this_offset < len; this_offset++) {
2930*4882a593Smuzhiyun void __iomem *p = rom_base + this_offset;
2931*4882a593Smuzhiyun
2932*4882a593Smuzhiyun if (readb(p + 0) != 0x90 ||
2933*4882a593Smuzhiyun readb(p + 1) != 0x00 ||
2934*4882a593Smuzhiyun readb(p + 2) != 0x09 ||
2935*4882a593Smuzhiyun readb(p + 3) != 0x4e ||
2936*4882a593Smuzhiyun readb(p + 4) != 0x41 ||
2937*4882a593Smuzhiyun readb(p + 5) != 0x06)
2938*4882a593Smuzhiyun continue;
2939*4882a593Smuzhiyun
2940*4882a593Smuzhiyun this_offset += 6;
2941*4882a593Smuzhiyun p += 6;
2942*4882a593Smuzhiyun
2943*4882a593Smuzhiyun if (index == 0) {
2944*4882a593Smuzhiyun int i;
2945*4882a593Smuzhiyun
2946*4882a593Smuzhiyun for (i = 0; i < 6; i++)
2947*4882a593Smuzhiyun dev_addr[i] = readb(p + i);
2948*4882a593Smuzhiyun return 1;
2949*4882a593Smuzhiyun }
2950*4882a593Smuzhiyun index--;
2951*4882a593Smuzhiyun }
2952*4882a593Smuzhiyun return 0;
2953*4882a593Smuzhiyun }
2954*4882a593Smuzhiyun
get_hme_mac_nonsparc(struct pci_dev * pdev,unsigned char * dev_addr)2955*4882a593Smuzhiyun static void get_hme_mac_nonsparc(struct pci_dev *pdev, unsigned char *dev_addr)
2956*4882a593Smuzhiyun {
2957*4882a593Smuzhiyun size_t size;
2958*4882a593Smuzhiyun void __iomem *p = pci_map_rom(pdev, &size);
2959*4882a593Smuzhiyun
2960*4882a593Smuzhiyun if (p) {
2961*4882a593Smuzhiyun int index = 0;
2962*4882a593Smuzhiyun int found;
2963*4882a593Smuzhiyun
2964*4882a593Smuzhiyun if (is_quattro_p(pdev))
2965*4882a593Smuzhiyun index = PCI_SLOT(pdev->devfn);
2966*4882a593Smuzhiyun
2967*4882a593Smuzhiyun found = readb(p) == 0x55 &&
2968*4882a593Smuzhiyun readb(p + 1) == 0xaa &&
2969*4882a593Smuzhiyun find_eth_addr_in_vpd(p, (64 * 1024), index, dev_addr);
2970*4882a593Smuzhiyun pci_unmap_rom(pdev, p);
2971*4882a593Smuzhiyun if (found)
2972*4882a593Smuzhiyun return;
2973*4882a593Smuzhiyun }
2974*4882a593Smuzhiyun
2975*4882a593Smuzhiyun /* Sun MAC prefix then 3 random bytes. */
2976*4882a593Smuzhiyun dev_addr[0] = 0x08;
2977*4882a593Smuzhiyun dev_addr[1] = 0x00;
2978*4882a593Smuzhiyun dev_addr[2] = 0x20;
2979*4882a593Smuzhiyun get_random_bytes(&dev_addr[3], 3);
2980*4882a593Smuzhiyun }
2981*4882a593Smuzhiyun #endif /* !(CONFIG_SPARC) */
2982*4882a593Smuzhiyun
happy_meal_pci_probe(struct pci_dev * pdev,const struct pci_device_id * ent)2983*4882a593Smuzhiyun static int happy_meal_pci_probe(struct pci_dev *pdev,
2984*4882a593Smuzhiyun const struct pci_device_id *ent)
2985*4882a593Smuzhiyun {
2986*4882a593Smuzhiyun struct quattro *qp = NULL;
2987*4882a593Smuzhiyun #ifdef CONFIG_SPARC
2988*4882a593Smuzhiyun struct device_node *dp;
2989*4882a593Smuzhiyun #endif
2990*4882a593Smuzhiyun struct happy_meal *hp;
2991*4882a593Smuzhiyun struct net_device *dev;
2992*4882a593Smuzhiyun void __iomem *hpreg_base;
2993*4882a593Smuzhiyun unsigned long hpreg_res;
2994*4882a593Smuzhiyun int i, qfe_slot = -1;
2995*4882a593Smuzhiyun char prom_name[64];
2996*4882a593Smuzhiyun int err;
2997*4882a593Smuzhiyun
2998*4882a593Smuzhiyun /* Now make sure pci_dev cookie is there. */
2999*4882a593Smuzhiyun #ifdef CONFIG_SPARC
3000*4882a593Smuzhiyun dp = pci_device_to_OF_node(pdev);
3001*4882a593Smuzhiyun snprintf(prom_name, sizeof(prom_name), "%pOFn", dp);
3002*4882a593Smuzhiyun #else
3003*4882a593Smuzhiyun if (is_quattro_p(pdev))
3004*4882a593Smuzhiyun strcpy(prom_name, "SUNW,qfe");
3005*4882a593Smuzhiyun else
3006*4882a593Smuzhiyun strcpy(prom_name, "SUNW,hme");
3007*4882a593Smuzhiyun #endif
3008*4882a593Smuzhiyun
3009*4882a593Smuzhiyun err = -ENODEV;
3010*4882a593Smuzhiyun
3011*4882a593Smuzhiyun if (pci_enable_device(pdev))
3012*4882a593Smuzhiyun goto err_out;
3013*4882a593Smuzhiyun pci_set_master(pdev);
3014*4882a593Smuzhiyun
3015*4882a593Smuzhiyun if (!strcmp(prom_name, "SUNW,qfe") || !strcmp(prom_name, "qfe")) {
3016*4882a593Smuzhiyun qp = quattro_pci_find(pdev);
3017*4882a593Smuzhiyun if (qp == NULL)
3018*4882a593Smuzhiyun goto err_out;
3019*4882a593Smuzhiyun for (qfe_slot = 0; qfe_slot < 4; qfe_slot++)
3020*4882a593Smuzhiyun if (qp->happy_meals[qfe_slot] == NULL)
3021*4882a593Smuzhiyun break;
3022*4882a593Smuzhiyun if (qfe_slot == 4)
3023*4882a593Smuzhiyun goto err_out;
3024*4882a593Smuzhiyun }
3025*4882a593Smuzhiyun
3026*4882a593Smuzhiyun dev = alloc_etherdev(sizeof(struct happy_meal));
3027*4882a593Smuzhiyun err = -ENOMEM;
3028*4882a593Smuzhiyun if (!dev)
3029*4882a593Smuzhiyun goto err_out;
3030*4882a593Smuzhiyun SET_NETDEV_DEV(dev, &pdev->dev);
3031*4882a593Smuzhiyun
3032*4882a593Smuzhiyun if (hme_version_printed++ == 0)
3033*4882a593Smuzhiyun printk(KERN_INFO "%s", version);
3034*4882a593Smuzhiyun
3035*4882a593Smuzhiyun hp = netdev_priv(dev);
3036*4882a593Smuzhiyun
3037*4882a593Smuzhiyun hp->happy_dev = pdev;
3038*4882a593Smuzhiyun hp->dma_dev = &pdev->dev;
3039*4882a593Smuzhiyun
3040*4882a593Smuzhiyun spin_lock_init(&hp->happy_lock);
3041*4882a593Smuzhiyun
3042*4882a593Smuzhiyun if (qp != NULL) {
3043*4882a593Smuzhiyun hp->qfe_parent = qp;
3044*4882a593Smuzhiyun hp->qfe_ent = qfe_slot;
3045*4882a593Smuzhiyun qp->happy_meals[qfe_slot] = dev;
3046*4882a593Smuzhiyun }
3047*4882a593Smuzhiyun
3048*4882a593Smuzhiyun hpreg_res = pci_resource_start(pdev, 0);
3049*4882a593Smuzhiyun err = -ENODEV;
3050*4882a593Smuzhiyun if ((pci_resource_flags(pdev, 0) & IORESOURCE_IO) != 0) {
3051*4882a593Smuzhiyun printk(KERN_ERR "happymeal(PCI): Cannot find proper PCI device base address.\n");
3052*4882a593Smuzhiyun goto err_out_clear_quattro;
3053*4882a593Smuzhiyun }
3054*4882a593Smuzhiyun if (pci_request_regions(pdev, DRV_NAME)) {
3055*4882a593Smuzhiyun printk(KERN_ERR "happymeal(PCI): Cannot obtain PCI resources, "
3056*4882a593Smuzhiyun "aborting.\n");
3057*4882a593Smuzhiyun goto err_out_clear_quattro;
3058*4882a593Smuzhiyun }
3059*4882a593Smuzhiyun
3060*4882a593Smuzhiyun if ((hpreg_base = ioremap(hpreg_res, 0x8000)) == NULL) {
3061*4882a593Smuzhiyun printk(KERN_ERR "happymeal(PCI): Unable to remap card memory.\n");
3062*4882a593Smuzhiyun goto err_out_free_res;
3063*4882a593Smuzhiyun }
3064*4882a593Smuzhiyun
3065*4882a593Smuzhiyun for (i = 0; i < 6; i++) {
3066*4882a593Smuzhiyun if (macaddr[i] != 0)
3067*4882a593Smuzhiyun break;
3068*4882a593Smuzhiyun }
3069*4882a593Smuzhiyun if (i < 6) { /* a mac address was given */
3070*4882a593Smuzhiyun for (i = 0; i < 6; i++)
3071*4882a593Smuzhiyun dev->dev_addr[i] = macaddr[i];
3072*4882a593Smuzhiyun macaddr[5]++;
3073*4882a593Smuzhiyun } else {
3074*4882a593Smuzhiyun #ifdef CONFIG_SPARC
3075*4882a593Smuzhiyun const unsigned char *addr;
3076*4882a593Smuzhiyun int len;
3077*4882a593Smuzhiyun
3078*4882a593Smuzhiyun if (qfe_slot != -1 &&
3079*4882a593Smuzhiyun (addr = of_get_property(dp, "local-mac-address", &len))
3080*4882a593Smuzhiyun != NULL &&
3081*4882a593Smuzhiyun len == 6) {
3082*4882a593Smuzhiyun memcpy(dev->dev_addr, addr, ETH_ALEN);
3083*4882a593Smuzhiyun } else {
3084*4882a593Smuzhiyun memcpy(dev->dev_addr, idprom->id_ethaddr, ETH_ALEN);
3085*4882a593Smuzhiyun }
3086*4882a593Smuzhiyun #else
3087*4882a593Smuzhiyun get_hme_mac_nonsparc(pdev, &dev->dev_addr[0]);
3088*4882a593Smuzhiyun #endif
3089*4882a593Smuzhiyun }
3090*4882a593Smuzhiyun
3091*4882a593Smuzhiyun /* Layout registers. */
3092*4882a593Smuzhiyun hp->gregs = (hpreg_base + 0x0000UL);
3093*4882a593Smuzhiyun hp->etxregs = (hpreg_base + 0x2000UL);
3094*4882a593Smuzhiyun hp->erxregs = (hpreg_base + 0x4000UL);
3095*4882a593Smuzhiyun hp->bigmacregs = (hpreg_base + 0x6000UL);
3096*4882a593Smuzhiyun hp->tcvregs = (hpreg_base + 0x7000UL);
3097*4882a593Smuzhiyun
3098*4882a593Smuzhiyun #ifdef CONFIG_SPARC
3099*4882a593Smuzhiyun hp->hm_revision = of_getintprop_default(dp, "hm-rev", 0xff);
3100*4882a593Smuzhiyun if (hp->hm_revision == 0xff)
3101*4882a593Smuzhiyun hp->hm_revision = 0xc0 | (pdev->revision & 0x0f);
3102*4882a593Smuzhiyun #else
3103*4882a593Smuzhiyun /* works with this on non-sparc hosts */
3104*4882a593Smuzhiyun hp->hm_revision = 0x20;
3105*4882a593Smuzhiyun #endif
3106*4882a593Smuzhiyun
3107*4882a593Smuzhiyun /* Now enable the feature flags we can. */
3108*4882a593Smuzhiyun if (hp->hm_revision == 0x20 || hp->hm_revision == 0x21)
3109*4882a593Smuzhiyun hp->happy_flags = HFLAG_20_21;
3110*4882a593Smuzhiyun else if (hp->hm_revision != 0xa0 && hp->hm_revision != 0xc0)
3111*4882a593Smuzhiyun hp->happy_flags = HFLAG_NOT_A0;
3112*4882a593Smuzhiyun
3113*4882a593Smuzhiyun if (qp != NULL)
3114*4882a593Smuzhiyun hp->happy_flags |= HFLAG_QUATTRO;
3115*4882a593Smuzhiyun
3116*4882a593Smuzhiyun /* And of course, indicate this is PCI. */
3117*4882a593Smuzhiyun hp->happy_flags |= HFLAG_PCI;
3118*4882a593Smuzhiyun
3119*4882a593Smuzhiyun #ifdef CONFIG_SPARC
3120*4882a593Smuzhiyun /* Assume PCI happy meals can handle all burst sizes. */
3121*4882a593Smuzhiyun hp->happy_bursts = DMA_BURSTBITS;
3122*4882a593Smuzhiyun #endif
3123*4882a593Smuzhiyun
3124*4882a593Smuzhiyun hp->happy_block = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
3125*4882a593Smuzhiyun &hp->hblock_dvma, GFP_KERNEL);
3126*4882a593Smuzhiyun err = -ENODEV;
3127*4882a593Smuzhiyun if (!hp->happy_block)
3128*4882a593Smuzhiyun goto err_out_iounmap;
3129*4882a593Smuzhiyun
3130*4882a593Smuzhiyun hp->linkcheck = 0;
3131*4882a593Smuzhiyun hp->timer_state = asleep;
3132*4882a593Smuzhiyun hp->timer_ticks = 0;
3133*4882a593Smuzhiyun
3134*4882a593Smuzhiyun timer_setup(&hp->happy_timer, happy_meal_timer, 0);
3135*4882a593Smuzhiyun
3136*4882a593Smuzhiyun hp->irq = pdev->irq;
3137*4882a593Smuzhiyun hp->dev = dev;
3138*4882a593Smuzhiyun dev->netdev_ops = &hme_netdev_ops;
3139*4882a593Smuzhiyun dev->watchdog_timeo = 5*HZ;
3140*4882a593Smuzhiyun dev->ethtool_ops = &hme_ethtool_ops;
3141*4882a593Smuzhiyun
3142*4882a593Smuzhiyun /* Happy Meal can do it all... */
3143*4882a593Smuzhiyun dev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM;
3144*4882a593Smuzhiyun dev->features |= dev->hw_features | NETIF_F_RXCSUM;
3145*4882a593Smuzhiyun
3146*4882a593Smuzhiyun #if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
3147*4882a593Smuzhiyun /* Hook up PCI register/descriptor accessors. */
3148*4882a593Smuzhiyun hp->read_desc32 = pci_hme_read_desc32;
3149*4882a593Smuzhiyun hp->write_txd = pci_hme_write_txd;
3150*4882a593Smuzhiyun hp->write_rxd = pci_hme_write_rxd;
3151*4882a593Smuzhiyun hp->read32 = pci_hme_read32;
3152*4882a593Smuzhiyun hp->write32 = pci_hme_write32;
3153*4882a593Smuzhiyun #endif
3154*4882a593Smuzhiyun
3155*4882a593Smuzhiyun /* Grrr, Happy Meal comes up by default not advertising
3156*4882a593Smuzhiyun * full duplex 100baseT capabilities, fix this.
3157*4882a593Smuzhiyun */
3158*4882a593Smuzhiyun spin_lock_irq(&hp->happy_lock);
3159*4882a593Smuzhiyun happy_meal_set_initial_advertisement(hp);
3160*4882a593Smuzhiyun spin_unlock_irq(&hp->happy_lock);
3161*4882a593Smuzhiyun
3162*4882a593Smuzhiyun err = register_netdev(hp->dev);
3163*4882a593Smuzhiyun if (err) {
3164*4882a593Smuzhiyun printk(KERN_ERR "happymeal(PCI): Cannot register net device, "
3165*4882a593Smuzhiyun "aborting.\n");
3166*4882a593Smuzhiyun goto err_out_free_coherent;
3167*4882a593Smuzhiyun }
3168*4882a593Smuzhiyun
3169*4882a593Smuzhiyun pci_set_drvdata(pdev, hp);
3170*4882a593Smuzhiyun
3171*4882a593Smuzhiyun if (!qfe_slot) {
3172*4882a593Smuzhiyun struct pci_dev *qpdev = qp->quattro_dev;
3173*4882a593Smuzhiyun
3174*4882a593Smuzhiyun prom_name[0] = 0;
3175*4882a593Smuzhiyun if (!strncmp(dev->name, "eth", 3)) {
3176*4882a593Smuzhiyun int i = simple_strtoul(dev->name + 3, NULL, 10);
3177*4882a593Smuzhiyun sprintf(prom_name, "-%d", i + 3);
3178*4882a593Smuzhiyun }
3179*4882a593Smuzhiyun printk(KERN_INFO "%s%s: Quattro HME (PCI/CheerIO) 10/100baseT Ethernet ", dev->name, prom_name);
3180*4882a593Smuzhiyun if (qpdev->vendor == PCI_VENDOR_ID_DEC &&
3181*4882a593Smuzhiyun qpdev->device == PCI_DEVICE_ID_DEC_21153)
3182*4882a593Smuzhiyun printk("DEC 21153 PCI Bridge\n");
3183*4882a593Smuzhiyun else
3184*4882a593Smuzhiyun printk("unknown bridge %04x.%04x\n",
3185*4882a593Smuzhiyun qpdev->vendor, qpdev->device);
3186*4882a593Smuzhiyun }
3187*4882a593Smuzhiyun
3188*4882a593Smuzhiyun if (qfe_slot != -1)
3189*4882a593Smuzhiyun printk(KERN_INFO "%s: Quattro HME slot %d (PCI/CheerIO) 10/100baseT Ethernet ",
3190*4882a593Smuzhiyun dev->name, qfe_slot);
3191*4882a593Smuzhiyun else
3192*4882a593Smuzhiyun printk(KERN_INFO "%s: HAPPY MEAL (PCI/CheerIO) 10/100BaseT Ethernet ",
3193*4882a593Smuzhiyun dev->name);
3194*4882a593Smuzhiyun
3195*4882a593Smuzhiyun printk("%pM\n", dev->dev_addr);
3196*4882a593Smuzhiyun
3197*4882a593Smuzhiyun return 0;
3198*4882a593Smuzhiyun
3199*4882a593Smuzhiyun err_out_free_coherent:
3200*4882a593Smuzhiyun dma_free_coherent(hp->dma_dev, PAGE_SIZE,
3201*4882a593Smuzhiyun hp->happy_block, hp->hblock_dvma);
3202*4882a593Smuzhiyun
3203*4882a593Smuzhiyun err_out_iounmap:
3204*4882a593Smuzhiyun iounmap(hp->gregs);
3205*4882a593Smuzhiyun
3206*4882a593Smuzhiyun err_out_free_res:
3207*4882a593Smuzhiyun pci_release_regions(pdev);
3208*4882a593Smuzhiyun
3209*4882a593Smuzhiyun err_out_clear_quattro:
3210*4882a593Smuzhiyun if (qp != NULL)
3211*4882a593Smuzhiyun qp->happy_meals[qfe_slot] = NULL;
3212*4882a593Smuzhiyun
3213*4882a593Smuzhiyun free_netdev(dev);
3214*4882a593Smuzhiyun
3215*4882a593Smuzhiyun err_out:
3216*4882a593Smuzhiyun return err;
3217*4882a593Smuzhiyun }
3218*4882a593Smuzhiyun
happy_meal_pci_remove(struct pci_dev * pdev)3219*4882a593Smuzhiyun static void happy_meal_pci_remove(struct pci_dev *pdev)
3220*4882a593Smuzhiyun {
3221*4882a593Smuzhiyun struct happy_meal *hp = pci_get_drvdata(pdev);
3222*4882a593Smuzhiyun struct net_device *net_dev = hp->dev;
3223*4882a593Smuzhiyun
3224*4882a593Smuzhiyun unregister_netdev(net_dev);
3225*4882a593Smuzhiyun
3226*4882a593Smuzhiyun dma_free_coherent(hp->dma_dev, PAGE_SIZE,
3227*4882a593Smuzhiyun hp->happy_block, hp->hblock_dvma);
3228*4882a593Smuzhiyun iounmap(hp->gregs);
3229*4882a593Smuzhiyun pci_release_regions(hp->happy_dev);
3230*4882a593Smuzhiyun
3231*4882a593Smuzhiyun free_netdev(net_dev);
3232*4882a593Smuzhiyun }
3233*4882a593Smuzhiyun
3234*4882a593Smuzhiyun static const struct pci_device_id happymeal_pci_ids[] = {
3235*4882a593Smuzhiyun { PCI_DEVICE(PCI_VENDOR_ID_SUN, PCI_DEVICE_ID_SUN_HAPPYMEAL) },
3236*4882a593Smuzhiyun { } /* Terminating entry */
3237*4882a593Smuzhiyun };
3238*4882a593Smuzhiyun
3239*4882a593Smuzhiyun MODULE_DEVICE_TABLE(pci, happymeal_pci_ids);
3240*4882a593Smuzhiyun
3241*4882a593Smuzhiyun static struct pci_driver hme_pci_driver = {
3242*4882a593Smuzhiyun .name = "hme",
3243*4882a593Smuzhiyun .id_table = happymeal_pci_ids,
3244*4882a593Smuzhiyun .probe = happy_meal_pci_probe,
3245*4882a593Smuzhiyun .remove = happy_meal_pci_remove,
3246*4882a593Smuzhiyun };
3247*4882a593Smuzhiyun
happy_meal_pci_init(void)3248*4882a593Smuzhiyun static int __init happy_meal_pci_init(void)
3249*4882a593Smuzhiyun {
3250*4882a593Smuzhiyun return pci_register_driver(&hme_pci_driver);
3251*4882a593Smuzhiyun }
3252*4882a593Smuzhiyun
happy_meal_pci_exit(void)3253*4882a593Smuzhiyun static void happy_meal_pci_exit(void)
3254*4882a593Smuzhiyun {
3255*4882a593Smuzhiyun pci_unregister_driver(&hme_pci_driver);
3256*4882a593Smuzhiyun
3257*4882a593Smuzhiyun while (qfe_pci_list) {
3258*4882a593Smuzhiyun struct quattro *qfe = qfe_pci_list;
3259*4882a593Smuzhiyun struct quattro *next = qfe->next;
3260*4882a593Smuzhiyun
3261*4882a593Smuzhiyun kfree(qfe);
3262*4882a593Smuzhiyun
3263*4882a593Smuzhiyun qfe_pci_list = next;
3264*4882a593Smuzhiyun }
3265*4882a593Smuzhiyun }
3266*4882a593Smuzhiyun
3267*4882a593Smuzhiyun #endif
3268*4882a593Smuzhiyun
3269*4882a593Smuzhiyun #ifdef CONFIG_SBUS
3270*4882a593Smuzhiyun static const struct of_device_id hme_sbus_match[];
hme_sbus_probe(struct platform_device * op)3271*4882a593Smuzhiyun static int hme_sbus_probe(struct platform_device *op)
3272*4882a593Smuzhiyun {
3273*4882a593Smuzhiyun const struct of_device_id *match;
3274*4882a593Smuzhiyun struct device_node *dp = op->dev.of_node;
3275*4882a593Smuzhiyun const char *model = of_get_property(dp, "model", NULL);
3276*4882a593Smuzhiyun int is_qfe;
3277*4882a593Smuzhiyun
3278*4882a593Smuzhiyun match = of_match_device(hme_sbus_match, &op->dev);
3279*4882a593Smuzhiyun if (!match)
3280*4882a593Smuzhiyun return -EINVAL;
3281*4882a593Smuzhiyun is_qfe = (match->data != NULL);
3282*4882a593Smuzhiyun
3283*4882a593Smuzhiyun if (!is_qfe && model && !strcmp(model, "SUNW,sbus-qfe"))
3284*4882a593Smuzhiyun is_qfe = 1;
3285*4882a593Smuzhiyun
3286*4882a593Smuzhiyun return happy_meal_sbus_probe_one(op, is_qfe);
3287*4882a593Smuzhiyun }
3288*4882a593Smuzhiyun
hme_sbus_remove(struct platform_device * op)3289*4882a593Smuzhiyun static int hme_sbus_remove(struct platform_device *op)
3290*4882a593Smuzhiyun {
3291*4882a593Smuzhiyun struct happy_meal *hp = platform_get_drvdata(op);
3292*4882a593Smuzhiyun struct net_device *net_dev = hp->dev;
3293*4882a593Smuzhiyun
3294*4882a593Smuzhiyun unregister_netdev(net_dev);
3295*4882a593Smuzhiyun
3296*4882a593Smuzhiyun /* XXX qfe parent interrupt... */
3297*4882a593Smuzhiyun
3298*4882a593Smuzhiyun of_iounmap(&op->resource[0], hp->gregs, GREG_REG_SIZE);
3299*4882a593Smuzhiyun of_iounmap(&op->resource[1], hp->etxregs, ETX_REG_SIZE);
3300*4882a593Smuzhiyun of_iounmap(&op->resource[2], hp->erxregs, ERX_REG_SIZE);
3301*4882a593Smuzhiyun of_iounmap(&op->resource[3], hp->bigmacregs, BMAC_REG_SIZE);
3302*4882a593Smuzhiyun of_iounmap(&op->resource[4], hp->tcvregs, TCVR_REG_SIZE);
3303*4882a593Smuzhiyun dma_free_coherent(hp->dma_dev,
3304*4882a593Smuzhiyun PAGE_SIZE,
3305*4882a593Smuzhiyun hp->happy_block,
3306*4882a593Smuzhiyun hp->hblock_dvma);
3307*4882a593Smuzhiyun
3308*4882a593Smuzhiyun free_netdev(net_dev);
3309*4882a593Smuzhiyun
3310*4882a593Smuzhiyun return 0;
3311*4882a593Smuzhiyun }
3312*4882a593Smuzhiyun
3313*4882a593Smuzhiyun static const struct of_device_id hme_sbus_match[] = {
3314*4882a593Smuzhiyun {
3315*4882a593Smuzhiyun .name = "SUNW,hme",
3316*4882a593Smuzhiyun },
3317*4882a593Smuzhiyun {
3318*4882a593Smuzhiyun .name = "SUNW,qfe",
3319*4882a593Smuzhiyun .data = (void *) 1,
3320*4882a593Smuzhiyun },
3321*4882a593Smuzhiyun {
3322*4882a593Smuzhiyun .name = "qfe",
3323*4882a593Smuzhiyun .data = (void *) 1,
3324*4882a593Smuzhiyun },
3325*4882a593Smuzhiyun {},
3326*4882a593Smuzhiyun };
3327*4882a593Smuzhiyun
3328*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, hme_sbus_match);
3329*4882a593Smuzhiyun
3330*4882a593Smuzhiyun static struct platform_driver hme_sbus_driver = {
3331*4882a593Smuzhiyun .driver = {
3332*4882a593Smuzhiyun .name = "hme",
3333*4882a593Smuzhiyun .of_match_table = hme_sbus_match,
3334*4882a593Smuzhiyun },
3335*4882a593Smuzhiyun .probe = hme_sbus_probe,
3336*4882a593Smuzhiyun .remove = hme_sbus_remove,
3337*4882a593Smuzhiyun };
3338*4882a593Smuzhiyun
happy_meal_sbus_init(void)3339*4882a593Smuzhiyun static int __init happy_meal_sbus_init(void)
3340*4882a593Smuzhiyun {
3341*4882a593Smuzhiyun int err;
3342*4882a593Smuzhiyun
3343*4882a593Smuzhiyun err = platform_driver_register(&hme_sbus_driver);
3344*4882a593Smuzhiyun if (!err)
3345*4882a593Smuzhiyun err = quattro_sbus_register_irqs();
3346*4882a593Smuzhiyun
3347*4882a593Smuzhiyun return err;
3348*4882a593Smuzhiyun }
3349*4882a593Smuzhiyun
happy_meal_sbus_exit(void)3350*4882a593Smuzhiyun static void happy_meal_sbus_exit(void)
3351*4882a593Smuzhiyun {
3352*4882a593Smuzhiyun platform_driver_unregister(&hme_sbus_driver);
3353*4882a593Smuzhiyun quattro_sbus_free_irqs();
3354*4882a593Smuzhiyun
3355*4882a593Smuzhiyun while (qfe_sbus_list) {
3356*4882a593Smuzhiyun struct quattro *qfe = qfe_sbus_list;
3357*4882a593Smuzhiyun struct quattro *next = qfe->next;
3358*4882a593Smuzhiyun
3359*4882a593Smuzhiyun kfree(qfe);
3360*4882a593Smuzhiyun
3361*4882a593Smuzhiyun qfe_sbus_list = next;
3362*4882a593Smuzhiyun }
3363*4882a593Smuzhiyun }
3364*4882a593Smuzhiyun #endif
3365*4882a593Smuzhiyun
happy_meal_probe(void)3366*4882a593Smuzhiyun static int __init happy_meal_probe(void)
3367*4882a593Smuzhiyun {
3368*4882a593Smuzhiyun int err = 0;
3369*4882a593Smuzhiyun
3370*4882a593Smuzhiyun #ifdef CONFIG_SBUS
3371*4882a593Smuzhiyun err = happy_meal_sbus_init();
3372*4882a593Smuzhiyun #endif
3373*4882a593Smuzhiyun #ifdef CONFIG_PCI
3374*4882a593Smuzhiyun if (!err) {
3375*4882a593Smuzhiyun err = happy_meal_pci_init();
3376*4882a593Smuzhiyun #ifdef CONFIG_SBUS
3377*4882a593Smuzhiyun if (err)
3378*4882a593Smuzhiyun happy_meal_sbus_exit();
3379*4882a593Smuzhiyun #endif
3380*4882a593Smuzhiyun }
3381*4882a593Smuzhiyun #endif
3382*4882a593Smuzhiyun
3383*4882a593Smuzhiyun return err;
3384*4882a593Smuzhiyun }
3385*4882a593Smuzhiyun
3386*4882a593Smuzhiyun
happy_meal_exit(void)3387*4882a593Smuzhiyun static void __exit happy_meal_exit(void)
3388*4882a593Smuzhiyun {
3389*4882a593Smuzhiyun #ifdef CONFIG_SBUS
3390*4882a593Smuzhiyun happy_meal_sbus_exit();
3391*4882a593Smuzhiyun #endif
3392*4882a593Smuzhiyun #ifdef CONFIG_PCI
3393*4882a593Smuzhiyun happy_meal_pci_exit();
3394*4882a593Smuzhiyun #endif
3395*4882a593Smuzhiyun }
3396*4882a593Smuzhiyun
3397*4882a593Smuzhiyun module_init(happy_meal_probe);
3398*4882a593Smuzhiyun module_exit(happy_meal_exit);
3399