Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /*====================================================================== |
2 | ||
3 | A PCMCIA ethernet driver for SMC91c92-based cards. | |
4 | ||
5 | This driver supports Megahertz PCMCIA ethernet cards; and | |
6 | Megahertz, Motorola, Ositech, and Psion Dacom ethernet/modem | |
7 | multifunction cards. | |
8 | ||
9 | Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net | |
10 | ||
11 | smc91c92_cs.c 1.122 2002/10/25 06:26:39 | |
12 | ||
13 | This driver contains code written by Donald Becker | |
14 | (becker@scyld.com), Rowan Hughes (x-csrdh@jcu.edu.au), | |
15 | David Hinds (dahinds@users.sourceforge.net), and Erik Stahlman | |
16 | (erik@vt.edu). Donald wrote the SMC 91c92 code using parts of | |
17 | Erik's SMC 91c94 driver. Rowan wrote a similar driver, and I've | |
18 | incorporated some parts of his driver here. I (Dave) wrote most | |
19 | of the PCMCIA glue code, and the Ositech support code. Kelly | |
20 | Stephens (kstephen@holli.com) added support for the Motorola | |
21 | Mariner, with help from Allen Brost. | |
22 | ||
23 | This software may be used and distributed according to the terms of | |
24 | the GNU General Public License, incorporated herein by reference. | |
25 | ||
26 | ======================================================================*/ | |
27 | ||
28 | #include <linux/module.h> | |
29 | #include <linux/kernel.h> | |
30 | #include <linux/init.h> | |
31 | #include <linux/slab.h> | |
32 | #include <linux/string.h> | |
33 | #include <linux/timer.h> | |
34 | #include <linux/interrupt.h> | |
35 | #include <linux/delay.h> | |
36 | #include <linux/crc32.h> | |
37 | #include <linux/netdevice.h> | |
38 | #include <linux/etherdevice.h> | |
39 | #include <linux/skbuff.h> | |
40 | #include <linux/if_arp.h> | |
41 | #include <linux/ioport.h> | |
42 | #include <linux/ethtool.h> | |
43 | #include <linux/mii.h> | |
44 | ||
1da177e4 LT |
45 | #include <pcmcia/cs_types.h> |
46 | #include <pcmcia/cs.h> | |
47 | #include <pcmcia/cistpl.h> | |
48 | #include <pcmcia/cisreg.h> | |
49 | #include <pcmcia/ciscode.h> | |
50 | #include <pcmcia/ds.h> | |
51 | ||
52 | #include <asm/io.h> | |
53 | #include <asm/system.h> | |
54 | #include <asm/uaccess.h> | |
55 | ||
56 | /* Ositech Seven of Diamonds firmware */ | |
57 | #include "ositech.h" | |
58 | ||
59 | /*====================================================================*/ | |
60 | ||
61 | static char *if_names[] = { "auto", "10baseT", "10base2"}; | |
62 | ||
63 | /* Module parameters */ | |
64 | ||
65 | MODULE_DESCRIPTION("SMC 91c92 series PCMCIA ethernet driver"); | |
66 | MODULE_LICENSE("GPL"); | |
67 | ||
68 | #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0) | |
69 | ||
70 | /* | |
71 | Transceiver/media type. | |
72 | 0 = auto | |
73 | 1 = 10baseT (and autoselect if #define AUTOSELECT), | |
74 | 2 = AUI/10base2, | |
75 | */ | |
76 | INT_MODULE_PARM(if_port, 0); | |
77 | ||
78 | #ifdef PCMCIA_DEBUG | |
79 | INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG); | |
80 | static const char *version = | |
81 | "smc91c92_cs.c 0.09 1996/8/4 Donald Becker, becker@scyld.com.\n"; | |
82 | #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) | |
83 | #else | |
84 | #define DEBUG(n, args...) | |
85 | #endif | |
86 | ||
87 | #define DRV_NAME "smc91c92_cs" | |
88 | #define DRV_VERSION "1.122" | |
89 | ||
90 | /*====================================================================*/ | |
91 | ||
92 | /* Operational parameter that usually are not changed. */ | |
93 | ||
94 | /* Time in jiffies before concluding Tx hung */ | |
95 | #define TX_TIMEOUT ((400*HZ)/1000) | |
96 | ||
97 | /* Maximum events (Rx packets, etc.) to handle at each interrupt. */ | |
98 | #define INTR_WORK 4 | |
99 | ||
100 | /* Times to check the check the chip before concluding that it doesn't | |
101 | currently have room for another Tx packet. */ | |
102 | #define MEMORY_WAIT_TIME 8 | |
103 | ||
104 | static dev_info_t dev_info = "smc91c92_cs"; | |
105 | ||
106 | static dev_link_t *dev_list; | |
107 | ||
108 | struct smc_private { | |
109 | dev_link_t link; | |
110 | spinlock_t lock; | |
111 | u_short manfid; | |
112 | u_short cardid; | |
113 | struct net_device_stats stats; | |
114 | dev_node_t node; | |
115 | struct sk_buff *saved_skb; | |
116 | int packets_waiting; | |
117 | void __iomem *base; | |
118 | u_short cfg; | |
119 | struct timer_list media; | |
120 | int watchdog, tx_err; | |
121 | u_short media_status; | |
122 | u_short fast_poll; | |
123 | u_short link_status; | |
124 | struct mii_if_info mii_if; | |
125 | int duplex; | |
126 | int rx_ovrn; | |
127 | }; | |
128 | ||
4638aef4 YR |
129 | struct smc_cfg_mem { |
130 | tuple_t tuple; | |
131 | cisparse_t parse; | |
132 | u_char buf[255]; | |
133 | }; | |
134 | ||
1da177e4 LT |
135 | /* Special definitions for Megahertz multifunction cards */ |
136 | #define MEGAHERTZ_ISR 0x0380 | |
137 | ||
138 | /* Special function registers for Motorola Mariner */ | |
139 | #define MOT_LAN 0x0000 | |
140 | #define MOT_UART 0x0020 | |
141 | #define MOT_EEPROM 0x20 | |
142 | ||
143 | #define MOT_NORMAL \ | |
144 | (COR_LEVEL_REQ | COR_FUNC_ENA | COR_ADDR_DECODE | COR_IREQ_ENA) | |
145 | ||
146 | /* Special function registers for Ositech cards */ | |
147 | #define OSITECH_AUI_CTL 0x0c | |
148 | #define OSITECH_PWRDOWN 0x0d | |
149 | #define OSITECH_RESET 0x0e | |
150 | #define OSITECH_ISR 0x0f | |
151 | #define OSITECH_AUI_PWR 0x0c | |
152 | #define OSITECH_RESET_ISR 0x0e | |
153 | ||
154 | #define OSI_AUI_PWR 0x40 | |
155 | #define OSI_LAN_PWRDOWN 0x02 | |
156 | #define OSI_MODEM_PWRDOWN 0x01 | |
157 | #define OSI_LAN_RESET 0x02 | |
158 | #define OSI_MODEM_RESET 0x01 | |
159 | ||
160 | /* Symbolic constants for the SMC91c9* series chips, from Erik Stahlman. */ | |
161 | #define BANK_SELECT 14 /* Window select register. */ | |
162 | #define SMC_SELECT_BANK(x) { outw(x, ioaddr + BANK_SELECT); } | |
163 | ||
164 | /* Bank 0 registers. */ | |
165 | #define TCR 0 /* transmit control register */ | |
166 | #define TCR_CLEAR 0 /* do NOTHING */ | |
167 | #define TCR_ENABLE 0x0001 /* if this is 1, we can transmit */ | |
168 | #define TCR_PAD_EN 0x0080 /* pads short packets to 64 bytes */ | |
169 | #define TCR_MONCSN 0x0400 /* Monitor Carrier. */ | |
170 | #define TCR_FDUPLX 0x0800 /* Full duplex mode. */ | |
171 | #define TCR_NORMAL TCR_ENABLE | TCR_PAD_EN | |
172 | ||
173 | #define EPH 2 /* Ethernet Protocol Handler report. */ | |
174 | #define EPH_TX_SUC 0x0001 | |
175 | #define EPH_SNGLCOL 0x0002 | |
176 | #define EPH_MULCOL 0x0004 | |
177 | #define EPH_LTX_MULT 0x0008 | |
178 | #define EPH_16COL 0x0010 | |
179 | #define EPH_SQET 0x0020 | |
180 | #define EPH_LTX_BRD 0x0040 | |
181 | #define EPH_TX_DEFR 0x0080 | |
182 | #define EPH_LAT_COL 0x0200 | |
183 | #define EPH_LOST_CAR 0x0400 | |
184 | #define EPH_EXC_DEF 0x0800 | |
185 | #define EPH_CTR_ROL 0x1000 | |
186 | #define EPH_RX_OVRN 0x2000 | |
187 | #define EPH_LINK_OK 0x4000 | |
188 | #define EPH_TX_UNRN 0x8000 | |
189 | #define MEMINFO 8 /* Memory Information Register */ | |
190 | #define MEMCFG 10 /* Memory Configuration Register */ | |
191 | ||
192 | /* Bank 1 registers. */ | |
193 | #define CONFIG 0 | |
194 | #define CFG_MII_SELECT 0x8000 /* 91C100 only */ | |
195 | #define CFG_NO_WAIT 0x1000 | |
196 | #define CFG_FULL_STEP 0x0400 | |
197 | #define CFG_SET_SQLCH 0x0200 | |
198 | #define CFG_AUI_SELECT 0x0100 | |
199 | #define CFG_16BIT 0x0080 | |
200 | #define CFG_DIS_LINK 0x0040 | |
201 | #define CFG_STATIC 0x0030 | |
202 | #define CFG_IRQ_SEL_1 0x0004 | |
203 | #define CFG_IRQ_SEL_0 0x0002 | |
204 | #define BASE_ADDR 2 | |
205 | #define ADDR0 4 | |
206 | #define GENERAL 10 | |
207 | #define CONTROL 12 | |
208 | #define CTL_STORE 0x0001 | |
209 | #define CTL_RELOAD 0x0002 | |
210 | #define CTL_EE_SELECT 0x0004 | |
211 | #define CTL_TE_ENABLE 0x0020 | |
212 | #define CTL_CR_ENABLE 0x0040 | |
213 | #define CTL_LE_ENABLE 0x0080 | |
214 | #define CTL_AUTO_RELEASE 0x0800 | |
215 | #define CTL_POWERDOWN 0x2000 | |
216 | ||
217 | /* Bank 2 registers. */ | |
218 | #define MMU_CMD 0 | |
219 | #define MC_ALLOC 0x20 /* or with number of 256 byte packets */ | |
220 | #define MC_RESET 0x40 | |
221 | #define MC_RELEASE 0x80 /* remove and release the current rx packet */ | |
222 | #define MC_FREEPKT 0xA0 /* Release packet in PNR register */ | |
223 | #define MC_ENQUEUE 0xC0 /* Enqueue the packet for transmit */ | |
224 | #define PNR_ARR 2 | |
225 | #define FIFO_PORTS 4 | |
226 | #define FP_RXEMPTY 0x8000 | |
227 | #define POINTER 6 | |
228 | #define PTR_AUTO_INC 0x0040 | |
229 | #define PTR_READ 0x2000 | |
230 | #define PTR_AUTOINC 0x4000 | |
231 | #define PTR_RCV 0x8000 | |
232 | #define DATA_1 8 | |
233 | #define INTERRUPT 12 | |
234 | #define IM_RCV_INT 0x1 | |
235 | #define IM_TX_INT 0x2 | |
236 | #define IM_TX_EMPTY_INT 0x4 | |
237 | #define IM_ALLOC_INT 0x8 | |
238 | #define IM_RX_OVRN_INT 0x10 | |
239 | #define IM_EPH_INT 0x20 | |
240 | ||
241 | #define RCR 4 | |
242 | enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002, | |
243 | RxEnable = 0x0100, RxStripCRC = 0x0200}; | |
244 | #define RCR_SOFTRESET 0x8000 /* resets the chip */ | |
245 | #define RCR_STRIP_CRC 0x200 /* strips CRC */ | |
246 | #define RCR_ENABLE 0x100 /* IFF this is set, we can receive packets */ | |
247 | #define RCR_ALMUL 0x4 /* receive all multicast packets */ | |
248 | #define RCR_PROMISC 0x2 /* enable promiscuous mode */ | |
249 | ||
250 | /* the normal settings for the RCR register : */ | |
251 | #define RCR_NORMAL (RCR_STRIP_CRC | RCR_ENABLE) | |
252 | #define RCR_CLEAR 0x0 /* set it to a base state */ | |
253 | #define COUNTER 6 | |
254 | ||
255 | /* BANK 3 -- not the same values as in smc9194! */ | |
256 | #define MULTICAST0 0 | |
257 | #define MULTICAST2 2 | |
258 | #define MULTICAST4 4 | |
259 | #define MULTICAST6 6 | |
260 | #define MGMT 8 | |
261 | #define REVISION 0x0a | |
262 | ||
263 | /* Transmit status bits. */ | |
264 | #define TS_SUCCESS 0x0001 | |
265 | #define TS_16COL 0x0010 | |
266 | #define TS_LATCOL 0x0200 | |
267 | #define TS_LOSTCAR 0x0400 | |
268 | ||
269 | /* Receive status bits. */ | |
270 | #define RS_ALGNERR 0x8000 | |
271 | #define RS_BADCRC 0x2000 | |
272 | #define RS_ODDFRAME 0x1000 | |
273 | #define RS_TOOLONG 0x0800 | |
274 | #define RS_TOOSHORT 0x0400 | |
275 | #define RS_MULTICAST 0x0001 | |
276 | #define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT) | |
277 | ||
278 | #define set_bits(v, p) outw(inw(p)|(v), (p)) | |
279 | #define mask_bits(v, p) outw(inw(p)&(v), (p)) | |
280 | ||
281 | /*====================================================================*/ | |
282 | ||
283 | static dev_link_t *smc91c92_attach(void); | |
284 | static void smc91c92_detach(dev_link_t *); | |
285 | static void smc91c92_config(dev_link_t *link); | |
286 | static void smc91c92_release(dev_link_t *link); | |
287 | static int smc91c92_event(event_t event, int priority, | |
288 | event_callback_args_t *args); | |
289 | ||
290 | static int smc_open(struct net_device *dev); | |
291 | static int smc_close(struct net_device *dev); | |
292 | static int smc_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); | |
293 | static void smc_tx_timeout(struct net_device *dev); | |
294 | static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev); | |
295 | static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs); | |
296 | static void smc_rx(struct net_device *dev); | |
297 | static struct net_device_stats *smc_get_stats(struct net_device *dev); | |
298 | static void set_rx_mode(struct net_device *dev); | |
299 | static int s9k_config(struct net_device *dev, struct ifmap *map); | |
300 | static void smc_set_xcvr(struct net_device *dev, int if_port); | |
301 | static void smc_reset(struct net_device *dev); | |
302 | static void media_check(u_long arg); | |
303 | static void mdio_sync(kio_addr_t addr); | |
304 | static int mdio_read(struct net_device *dev, int phy_id, int loc); | |
305 | static void mdio_write(struct net_device *dev, int phy_id, int loc, int value); | |
306 | static int smc_link_ok(struct net_device *dev); | |
307 | static struct ethtool_ops ethtool_ops; | |
308 | ||
309 | /*====================================================================== | |
310 | ||
311 | smc91c92_attach() creates an "instance" of the driver, allocating | |
312 | local data structures for one device. The device is registered | |
313 | with Card Services. | |
314 | ||
315 | ======================================================================*/ | |
316 | ||
317 | static dev_link_t *smc91c92_attach(void) | |
318 | { | |
319 | client_reg_t client_reg; | |
320 | struct smc_private *smc; | |
321 | dev_link_t *link; | |
322 | struct net_device *dev; | |
323 | int ret; | |
324 | ||
325 | DEBUG(0, "smc91c92_attach()\n"); | |
326 | ||
327 | /* Create new ethernet device */ | |
328 | dev = alloc_etherdev(sizeof(struct smc_private)); | |
329 | if (!dev) | |
330 | return NULL; | |
331 | smc = netdev_priv(dev); | |
332 | link = &smc->link; | |
333 | link->priv = dev; | |
334 | ||
335 | spin_lock_init(&smc->lock); | |
336 | link->io.NumPorts1 = 16; | |
337 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; | |
338 | link->io.IOAddrLines = 4; | |
339 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; | |
340 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; | |
341 | link->irq.Handler = &smc_interrupt; | |
342 | link->irq.Instance = dev; | |
343 | link->conf.Attributes = CONF_ENABLE_IRQ; | |
344 | link->conf.Vcc = 50; | |
345 | link->conf.IntType = INT_MEMORY_AND_IO; | |
346 | ||
347 | /* The SMC91c92-specific entries in the device structure. */ | |
348 | SET_MODULE_OWNER(dev); | |
349 | dev->hard_start_xmit = &smc_start_xmit; | |
350 | dev->get_stats = &smc_get_stats; | |
351 | dev->set_config = &s9k_config; | |
352 | dev->set_multicast_list = &set_rx_mode; | |
353 | dev->open = &smc_open; | |
354 | dev->stop = &smc_close; | |
355 | dev->do_ioctl = &smc_ioctl; | |
356 | SET_ETHTOOL_OPS(dev, ðtool_ops); | |
357 | #ifdef HAVE_TX_TIMEOUT | |
358 | dev->tx_timeout = smc_tx_timeout; | |
359 | dev->watchdog_timeo = TX_TIMEOUT; | |
360 | #endif | |
361 | ||
362 | smc->mii_if.dev = dev; | |
363 | smc->mii_if.mdio_read = mdio_read; | |
364 | smc->mii_if.mdio_write = mdio_write; | |
365 | smc->mii_if.phy_id_mask = 0x1f; | |
366 | smc->mii_if.reg_num_mask = 0x1f; | |
367 | ||
368 | /* Register with Card Services */ | |
369 | link->next = dev_list; | |
370 | dev_list = link; | |
371 | client_reg.dev_info = &dev_info; | |
1da177e4 LT |
372 | client_reg.Version = 0x0210; |
373 | client_reg.event_callback_args.client_data = link; | |
374 | ret = pcmcia_register_client(&link->handle, &client_reg); | |
375 | if (ret != 0) { | |
376 | cs_error(link->handle, RegisterClient, ret); | |
377 | smc91c92_detach(link); | |
378 | return NULL; | |
379 | } | |
380 | ||
381 | return link; | |
382 | } /* smc91c92_attach */ | |
383 | ||
384 | /*====================================================================== | |
385 | ||
386 | This deletes a driver "instance". The device is de-registered | |
387 | with Card Services. If it has been released, all local data | |
388 | structures are freed. Otherwise, the structures will be freed | |
389 | when the device is released. | |
390 | ||
391 | ======================================================================*/ | |
392 | ||
393 | static void smc91c92_detach(dev_link_t *link) | |
394 | { | |
395 | struct net_device *dev = link->priv; | |
396 | dev_link_t **linkp; | |
397 | ||
398 | DEBUG(0, "smc91c92_detach(0x%p)\n", link); | |
399 | ||
400 | /* Locate device structure */ | |
401 | for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) | |
402 | if (*linkp == link) break; | |
403 | if (*linkp == NULL) | |
404 | return; | |
405 | ||
406 | if (link->dev) | |
407 | unregister_netdev(dev); | |
408 | ||
409 | if (link->state & DEV_CONFIG) | |
410 | smc91c92_release(link); | |
411 | ||
412 | if (link->handle) | |
413 | pcmcia_deregister_client(link->handle); | |
414 | ||
415 | /* Unlink device structure, free bits */ | |
416 | *linkp = link->next; | |
417 | free_netdev(dev); | |
418 | } /* smc91c92_detach */ | |
419 | ||
420 | /*====================================================================*/ | |
421 | ||
422 | static int cvt_ascii_address(struct net_device *dev, char *s) | |
423 | { | |
424 | int i, j, da, c; | |
425 | ||
426 | if (strlen(s) != 12) | |
427 | return -1; | |
428 | for (i = 0; i < 6; i++) { | |
429 | da = 0; | |
430 | for (j = 0; j < 2; j++) { | |
431 | c = *s++; | |
432 | da <<= 4; | |
433 | da += ((c >= '0') && (c <= '9')) ? | |
434 | (c - '0') : ((c & 0x0f) + 9); | |
435 | } | |
436 | dev->dev_addr[i] = da; | |
437 | } | |
438 | return 0; | |
439 | } | |
440 | ||
441 | /*====================================================================*/ | |
442 | ||
443 | static int first_tuple(client_handle_t handle, tuple_t *tuple, | |
444 | cisparse_t *parse) | |
445 | { | |
446 | int i; | |
447 | ||
448 | if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS || | |
449 | (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS) | |
450 | return i; | |
451 | return pcmcia_parse_tuple(handle, tuple, parse); | |
452 | } | |
453 | ||
454 | static int next_tuple(client_handle_t handle, tuple_t *tuple, | |
455 | cisparse_t *parse) | |
456 | { | |
457 | int i; | |
458 | ||
459 | if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS || | |
460 | (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS) | |
461 | return i; | |
462 | return pcmcia_parse_tuple(handle, tuple, parse); | |
463 | } | |
464 | ||
465 | /*====================================================================== | |
466 | ||
467 | Configuration stuff for Megahertz cards | |
468 | ||
469 | mhz_3288_power() is used to power up a 3288's ethernet chip. | |
470 | mhz_mfc_config() handles socket setup for multifunction (1144 | |
471 | and 3288) cards. mhz_setup() gets a card's hardware ethernet | |
472 | address. | |
473 | ||
474 | ======================================================================*/ | |
475 | ||
476 | static int mhz_3288_power(dev_link_t *link) | |
477 | { | |
478 | struct net_device *dev = link->priv; | |
479 | struct smc_private *smc = netdev_priv(dev); | |
480 | u_char tmp; | |
481 | ||
482 | /* Read the ISR twice... */ | |
483 | readb(smc->base+MEGAHERTZ_ISR); | |
484 | udelay(5); | |
485 | readb(smc->base+MEGAHERTZ_ISR); | |
486 | ||
487 | /* Pause 200ms... */ | |
488 | mdelay(200); | |
489 | ||
490 | /* Now read and write the COR... */ | |
491 | tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR); | |
492 | udelay(5); | |
493 | writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR); | |
494 | ||
495 | return 0; | |
496 | } | |
497 | ||
498 | static int mhz_mfc_config(dev_link_t *link) | |
499 | { | |
500 | struct net_device *dev = link->priv; | |
501 | struct smc_private *smc = netdev_priv(dev); | |
4638aef4 YR |
502 | struct smc_cfg_mem *cfg_mem; |
503 | tuple_t *tuple; | |
504 | cisparse_t *parse; | |
505 | cistpl_cftable_entry_t *cf; | |
506 | u_char *buf; | |
1da177e4 LT |
507 | win_req_t req; |
508 | memreq_t mem; | |
509 | int i, k; | |
510 | ||
4638aef4 YR |
511 | cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); |
512 | if (!cfg_mem) | |
513 | return CS_OUT_OF_RESOURCE; | |
514 | ||
515 | tuple = &cfg_mem->tuple; | |
516 | parse = &cfg_mem->parse; | |
517 | cf = &parse->cftable_entry; | |
518 | buf = cfg_mem->buf; | |
519 | ||
1da177e4 LT |
520 | link->conf.Attributes |= CONF_ENABLE_SPKR; |
521 | link->conf.Status = CCSR_AUDIO_ENA; | |
522 | link->irq.Attributes = | |
523 | IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT; | |
524 | link->io.IOAddrLines = 16; | |
525 | link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; | |
526 | link->io.NumPorts2 = 8; | |
527 | ||
4638aef4 YR |
528 | tuple->Attributes = tuple->TupleOffset = 0; |
529 | tuple->TupleData = (cisdata_t *)buf; | |
530 | tuple->TupleDataMax = 255; | |
531 | tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; | |
1da177e4 | 532 | |
4638aef4 | 533 | i = first_tuple(link->handle, tuple, parse); |
1da177e4 LT |
534 | /* The Megahertz combo cards have modem-like CIS entries, so |
535 | we have to explicitly try a bunch of port combinations. */ | |
536 | while (i == CS_SUCCESS) { | |
537 | link->conf.ConfigIndex = cf->index; | |
538 | link->io.BasePort2 = cf->io.win[0].base; | |
539 | for (k = 0; k < 0x400; k += 0x10) { | |
540 | if (k & 0x80) continue; | |
541 | link->io.BasePort1 = k ^ 0x300; | |
542 | i = pcmcia_request_io(link->handle, &link->io); | |
543 | if (i == CS_SUCCESS) break; | |
544 | } | |
545 | if (i == CS_SUCCESS) break; | |
4638aef4 | 546 | i = next_tuple(link->handle, tuple, parse); |
1da177e4 LT |
547 | } |
548 | if (i != CS_SUCCESS) | |
4638aef4 | 549 | goto free_cfg_mem; |
1da177e4 LT |
550 | dev->base_addr = link->io.BasePort1; |
551 | ||
552 | /* Allocate a memory window, for accessing the ISR */ | |
553 | req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; | |
554 | req.Base = req.Size = 0; | |
555 | req.AccessSpeed = 0; | |
556 | i = pcmcia_request_window(&link->handle, &req, &link->win); | |
557 | if (i != CS_SUCCESS) | |
4638aef4 | 558 | goto free_cfg_mem; |
1da177e4 LT |
559 | smc->base = ioremap(req.Base, req.Size); |
560 | mem.CardOffset = mem.Page = 0; | |
561 | if (smc->manfid == MANFID_MOTOROLA) | |
562 | mem.CardOffset = link->conf.ConfigBase; | |
563 | i = pcmcia_map_mem_page(link->win, &mem); | |
564 | ||
565 | if ((i == CS_SUCCESS) | |
566 | && (smc->manfid == MANFID_MEGAHERTZ) | |
567 | && (smc->cardid == PRODID_MEGAHERTZ_EM3288)) | |
568 | mhz_3288_power(link); | |
569 | ||
4638aef4 YR |
570 | free_cfg_mem: |
571 | kfree(cfg_mem); | |
1da177e4 LT |
572 | return i; |
573 | } | |
574 | ||
575 | static int mhz_setup(dev_link_t *link) | |
576 | { | |
577 | client_handle_t handle = link->handle; | |
578 | struct net_device *dev = link->priv; | |
4638aef4 YR |
579 | struct smc_cfg_mem *cfg_mem; |
580 | tuple_t *tuple; | |
581 | cisparse_t *parse; | |
582 | u_char *buf, *station_addr; | |
583 | int rc; | |
584 | ||
585 | cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); | |
586 | if (!cfg_mem) | |
587 | return -1; | |
1da177e4 | 588 | |
4638aef4 YR |
589 | tuple = &cfg_mem->tuple; |
590 | parse = &cfg_mem->parse; | |
591 | buf = cfg_mem->buf; | |
592 | ||
593 | tuple->Attributes = tuple->TupleOffset = 0; | |
594 | tuple->TupleData = (cisdata_t *)buf; | |
595 | tuple->TupleDataMax = 255; | |
1da177e4 LT |
596 | |
597 | /* Read the station address from the CIS. It is stored as the last | |
598 | (fourth) string in the Version 1 Version/ID tuple. */ | |
4638aef4 YR |
599 | tuple->DesiredTuple = CISTPL_VERS_1; |
600 | if (first_tuple(handle, tuple, parse) != CS_SUCCESS) { | |
601 | rc = -1; | |
602 | goto free_cfg_mem; | |
603 | } | |
1da177e4 | 604 | /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */ |
4638aef4 YR |
605 | if (next_tuple(handle, tuple, parse) != CS_SUCCESS) |
606 | first_tuple(handle, tuple, parse); | |
607 | if (parse->version_1.ns > 3) { | |
608 | station_addr = parse->version_1.str + parse->version_1.ofs[3]; | |
609 | if (cvt_ascii_address(dev, station_addr) == 0) { | |
610 | rc = 0; | |
611 | goto free_cfg_mem; | |
612 | } | |
1da177e4 LT |
613 | } |
614 | ||
615 | /* Another possibility: for the EM3288, in a special tuple */ | |
4638aef4 YR |
616 | tuple->DesiredTuple = 0x81; |
617 | if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) { | |
618 | rc = -1; | |
619 | goto free_cfg_mem; | |
620 | } | |
621 | if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) { | |
622 | rc = -1; | |
623 | goto free_cfg_mem; | |
624 | } | |
1da177e4 | 625 | buf[12] = '\0'; |
4638aef4 YR |
626 | if (cvt_ascii_address(dev, buf) == 0) { |
627 | rc = 0; | |
628 | goto free_cfg_mem; | |
629 | } | |
630 | rc = -1; | |
631 | free_cfg_mem: | |
632 | kfree(cfg_mem); | |
633 | return rc; | |
1da177e4 LT |
634 | } |
635 | ||
636 | /*====================================================================== | |
637 | ||
638 | Configuration stuff for the Motorola Mariner | |
639 | ||
640 | mot_config() writes directly to the Mariner configuration | |
641 | registers because the CIS is just bogus. | |
642 | ||
643 | ======================================================================*/ | |
644 | ||
645 | static void mot_config(dev_link_t *link) | |
646 | { | |
647 | struct net_device *dev = link->priv; | |
648 | struct smc_private *smc = netdev_priv(dev); | |
649 | kio_addr_t ioaddr = dev->base_addr; | |
650 | kio_addr_t iouart = link->io.BasePort2; | |
651 | ||
652 | /* Set UART base address and force map with COR bit 1 */ | |
653 | writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0); | |
654 | writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1); | |
655 | writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR); | |
656 | ||
657 | /* Set SMC base address and force map with COR bit 1 */ | |
658 | writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0); | |
659 | writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1); | |
660 | writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR); | |
661 | ||
662 | /* Wait for things to settle down */ | |
663 | mdelay(100); | |
664 | } | |
665 | ||
666 | static int mot_setup(dev_link_t *link) | |
667 | { | |
668 | struct net_device *dev = link->priv; | |
669 | kio_addr_t ioaddr = dev->base_addr; | |
670 | int i, wait, loop; | |
671 | u_int addr; | |
672 | ||
673 | /* Read Ethernet address from Serial EEPROM */ | |
674 | ||
675 | for (i = 0; i < 3; i++) { | |
676 | SMC_SELECT_BANK(2); | |
677 | outw(MOT_EEPROM + i, ioaddr + POINTER); | |
678 | SMC_SELECT_BANK(1); | |
679 | outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL); | |
680 | ||
681 | for (loop = wait = 0; loop < 200; loop++) { | |
682 | udelay(10); | |
683 | wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL)); | |
684 | if (wait == 0) break; | |
685 | } | |
686 | ||
687 | if (wait) | |
688 | return -1; | |
689 | ||
690 | addr = inw(ioaddr + GENERAL); | |
691 | dev->dev_addr[2*i] = addr & 0xff; | |
692 | dev->dev_addr[2*i+1] = (addr >> 8) & 0xff; | |
693 | } | |
694 | ||
695 | return 0; | |
696 | } | |
697 | ||
698 | /*====================================================================*/ | |
699 | ||
700 | static int smc_config(dev_link_t *link) | |
701 | { | |
702 | struct net_device *dev = link->priv; | |
4638aef4 YR |
703 | struct smc_cfg_mem *cfg_mem; |
704 | tuple_t *tuple; | |
705 | cisparse_t *parse; | |
706 | cistpl_cftable_entry_t *cf; | |
707 | u_char *buf; | |
1da177e4 LT |
708 | int i; |
709 | ||
4638aef4 YR |
710 | cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); |
711 | if (!cfg_mem) | |
712 | return CS_OUT_OF_RESOURCE; | |
713 | ||
714 | tuple = &cfg_mem->tuple; | |
715 | parse = &cfg_mem->parse; | |
716 | cf = &parse->cftable_entry; | |
717 | buf = cfg_mem->buf; | |
718 | ||
719 | tuple->Attributes = tuple->TupleOffset = 0; | |
720 | tuple->TupleData = (cisdata_t *)buf; | |
721 | tuple->TupleDataMax = 255; | |
722 | tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; | |
1da177e4 LT |
723 | |
724 | link->io.NumPorts1 = 16; | |
4638aef4 | 725 | i = first_tuple(link->handle, tuple, parse); |
1da177e4 LT |
726 | while (i != CS_NO_MORE_ITEMS) { |
727 | if (i == CS_SUCCESS) { | |
728 | link->conf.ConfigIndex = cf->index; | |
729 | link->io.BasePort1 = cf->io.win[0].base; | |
730 | link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; | |
731 | i = pcmcia_request_io(link->handle, &link->io); | |
732 | if (i == CS_SUCCESS) break; | |
733 | } | |
4638aef4 | 734 | i = next_tuple(link->handle, tuple, parse); |
1da177e4 LT |
735 | } |
736 | if (i == CS_SUCCESS) | |
737 | dev->base_addr = link->io.BasePort1; | |
4638aef4 YR |
738 | |
739 | kfree(cfg_mem); | |
1da177e4 LT |
740 | return i; |
741 | } | |
742 | ||
743 | static int smc_setup(dev_link_t *link) | |
744 | { | |
745 | client_handle_t handle = link->handle; | |
746 | struct net_device *dev = link->priv; | |
4638aef4 YR |
747 | struct smc_cfg_mem *cfg_mem; |
748 | tuple_t *tuple; | |
749 | cisparse_t *parse; | |
1da177e4 | 750 | cistpl_lan_node_id_t *node_id; |
4638aef4 YR |
751 | u_char *buf, *station_addr; |
752 | int i, rc; | |
753 | ||
754 | cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); | |
755 | if (!cfg_mem) | |
756 | return CS_OUT_OF_RESOURCE; | |
757 | ||
758 | tuple = &cfg_mem->tuple; | |
759 | parse = &cfg_mem->parse; | |
760 | buf = cfg_mem->buf; | |
1da177e4 | 761 | |
4638aef4 YR |
762 | tuple->Attributes = tuple->TupleOffset = 0; |
763 | tuple->TupleData = (cisdata_t *)buf; | |
764 | tuple->TupleDataMax = 255; | |
1da177e4 LT |
765 | |
766 | /* Check for a LAN function extension tuple */ | |
4638aef4 YR |
767 | tuple->DesiredTuple = CISTPL_FUNCE; |
768 | i = first_tuple(handle, tuple, parse); | |
1da177e4 | 769 | while (i == CS_SUCCESS) { |
4638aef4 | 770 | if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID) |
1da177e4 | 771 | break; |
4638aef4 | 772 | i = next_tuple(handle, tuple, parse); |
1da177e4 LT |
773 | } |
774 | if (i == CS_SUCCESS) { | |
4638aef4 | 775 | node_id = (cistpl_lan_node_id_t *)parse->funce.data; |
1da177e4 LT |
776 | if (node_id->nb == 6) { |
777 | for (i = 0; i < 6; i++) | |
778 | dev->dev_addr[i] = node_id->id[i]; | |
4638aef4 YR |
779 | rc = 0; |
780 | goto free_cfg_mem; | |
1da177e4 LT |
781 | } |
782 | } | |
783 | /* Try the third string in the Version 1 Version/ID tuple. */ | |
4638aef4 YR |
784 | tuple->DesiredTuple = CISTPL_VERS_1; |
785 | if (first_tuple(handle, tuple, parse) != CS_SUCCESS) { | |
786 | rc = -1; | |
787 | goto free_cfg_mem; | |
788 | } | |
789 | station_addr = parse->version_1.str + parse->version_1.ofs[2]; | |
790 | if (cvt_ascii_address(dev, station_addr) == 0) { | |
791 | rc = 0; | |
792 | goto free_cfg_mem; | |
793 | } | |
1da177e4 | 794 | |
4638aef4 YR |
795 | rc = -1; |
796 | free_cfg_mem: | |
797 | kfree(cfg_mem); | |
798 | return rc; | |
1da177e4 LT |
799 | } |
800 | ||
801 | /*====================================================================*/ | |
802 | ||
803 | static int osi_config(dev_link_t *link) | |
804 | { | |
805 | struct net_device *dev = link->priv; | |
806 | static kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; | |
807 | int i, j; | |
808 | ||
809 | link->conf.Attributes |= CONF_ENABLE_SPKR; | |
810 | link->conf.Status = CCSR_AUDIO_ENA; | |
811 | link->irq.Attributes = | |
812 | IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT; | |
813 | link->io.NumPorts1 = 64; | |
814 | link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; | |
815 | link->io.NumPorts2 = 8; | |
816 | link->io.IOAddrLines = 16; | |
817 | ||
818 | /* Enable Hard Decode, LAN, Modem */ | |
819 | link->conf.ConfigIndex = 0x23; | |
820 | ||
821 | for (i = j = 0; j < 4; j++) { | |
822 | link->io.BasePort2 = com[j]; | |
823 | i = pcmcia_request_io(link->handle, &link->io); | |
824 | if (i == CS_SUCCESS) break; | |
825 | } | |
826 | if (i != CS_SUCCESS) { | |
827 | /* Fallback: turn off hard decode */ | |
828 | link->conf.ConfigIndex = 0x03; | |
829 | link->io.NumPorts2 = 0; | |
830 | i = pcmcia_request_io(link->handle, &link->io); | |
831 | } | |
832 | dev->base_addr = link->io.BasePort1 + 0x10; | |
833 | return i; | |
834 | } | |
835 | ||
836 | static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid) | |
837 | { | |
838 | client_handle_t handle = link->handle; | |
839 | struct net_device *dev = link->priv; | |
4638aef4 YR |
840 | struct smc_cfg_mem *cfg_mem; |
841 | tuple_t *tuple; | |
842 | u_char *buf; | |
843 | int i, rc; | |
1da177e4 | 844 | |
4638aef4 YR |
845 | cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); |
846 | if (!cfg_mem) | |
847 | return -1; | |
848 | ||
849 | tuple = &cfg_mem->tuple; | |
850 | buf = cfg_mem->buf; | |
851 | ||
852 | tuple->Attributes = TUPLE_RETURN_COMMON; | |
853 | tuple->TupleData = (cisdata_t *)buf; | |
854 | tuple->TupleDataMax = 255; | |
855 | tuple->TupleOffset = 0; | |
1da177e4 LT |
856 | |
857 | /* Read the station address from tuple 0x90, subtuple 0x04 */ | |
4638aef4 YR |
858 | tuple->DesiredTuple = 0x90; |
859 | i = pcmcia_get_first_tuple(handle, tuple); | |
1da177e4 | 860 | while (i == CS_SUCCESS) { |
4638aef4 | 861 | i = pcmcia_get_tuple_data(handle, tuple); |
1da177e4 LT |
862 | if ((i != CS_SUCCESS) || (buf[0] == 0x04)) |
863 | break; | |
4638aef4 YR |
864 | i = pcmcia_get_next_tuple(handle, tuple); |
865 | } | |
866 | if (i != CS_SUCCESS) { | |
867 | rc = -1; | |
868 | goto free_cfg_mem; | |
1da177e4 | 869 | } |
1da177e4 LT |
870 | for (i = 0; i < 6; i++) |
871 | dev->dev_addr[i] = buf[i+2]; | |
872 | ||
873 | if (((manfid == MANFID_OSITECH) && | |
874 | (cardid == PRODID_OSITECH_SEVEN)) || | |
875 | ((manfid == MANFID_PSION) && | |
876 | (cardid == PRODID_PSION_NET100))) { | |
877 | /* Download the Seven of Diamonds firmware */ | |
878 | for (i = 0; i < sizeof(__Xilinx7OD); i++) { | |
879 | outb(__Xilinx7OD[i], link->io.BasePort1+2); | |
880 | udelay(50); | |
881 | } | |
882 | } else if (manfid == MANFID_OSITECH) { | |
883 | /* Make sure both functions are powered up */ | |
884 | set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR); | |
885 | /* Now, turn on the interrupt for both card functions */ | |
886 | set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR); | |
887 | DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n", | |
888 | inw(link->io.BasePort1 + OSITECH_AUI_PWR), | |
889 | inw(link->io.BasePort1 + OSITECH_RESET_ISR)); | |
890 | } | |
4638aef4 YR |
891 | rc = 0; |
892 | free_cfg_mem: | |
893 | kfree(cfg_mem); | |
894 | return rc; | |
1da177e4 LT |
895 | } |
896 | ||
897 | /*====================================================================== | |
898 | ||
899 | This verifies that the chip is some SMC91cXX variant, and returns | |
900 | the revision code if successful. Otherwise, it returns -ENODEV. | |
901 | ||
902 | ======================================================================*/ | |
903 | ||
904 | static int check_sig(dev_link_t *link) | |
905 | { | |
906 | struct net_device *dev = link->priv; | |
907 | kio_addr_t ioaddr = dev->base_addr; | |
908 | int width; | |
909 | u_short s; | |
910 | ||
911 | SMC_SELECT_BANK(1); | |
912 | if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) { | |
913 | /* Try powering up the chip */ | |
914 | outw(0, ioaddr + CONTROL); | |
915 | mdelay(55); | |
916 | } | |
917 | ||
918 | /* Try setting bus width */ | |
919 | width = (link->io.Attributes1 == IO_DATA_PATH_WIDTH_AUTO); | |
920 | s = inb(ioaddr + CONFIG); | |
921 | if (width) | |
922 | s |= CFG_16BIT; | |
923 | else | |
924 | s &= ~CFG_16BIT; | |
925 | outb(s, ioaddr + CONFIG); | |
926 | ||
927 | /* Check Base Address Register to make sure bus width is OK */ | |
928 | s = inw(ioaddr + BASE_ADDR); | |
929 | if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) && | |
930 | ((s >> 8) != (s & 0xff))) { | |
931 | SMC_SELECT_BANK(3); | |
932 | s = inw(ioaddr + REVISION); | |
933 | return (s & 0xff); | |
934 | } | |
935 | ||
936 | if (width) { | |
937 | event_callback_args_t args; | |
938 | printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n"); | |
939 | args.client_data = link; | |
940 | smc91c92_event(CS_EVENT_RESET_PHYSICAL, 0, &args); | |
941 | pcmcia_release_io(link->handle, &link->io); | |
942 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; | |
943 | pcmcia_request_io(link->handle, &link->io); | |
944 | smc91c92_event(CS_EVENT_CARD_RESET, 0, &args); | |
945 | return check_sig(link); | |
946 | } | |
947 | return -ENODEV; | |
948 | } | |
949 | ||
950 | /*====================================================================== | |
951 | ||
952 | smc91c92_config() is scheduled to run after a CARD_INSERTION event | |
953 | is received, to configure the PCMCIA socket, and to make the | |
954 | ethernet device available to the system. | |
955 | ||
956 | ======================================================================*/ | |
957 | ||
958 | #define CS_EXIT_TEST(ret, svc, label) \ | |
959 | if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; } | |
960 | ||
961 | static void smc91c92_config(dev_link_t *link) | |
962 | { | |
963 | client_handle_t handle = link->handle; | |
964 | struct net_device *dev = link->priv; | |
965 | struct smc_private *smc = netdev_priv(dev); | |
4638aef4 YR |
966 | struct smc_cfg_mem *cfg_mem; |
967 | tuple_t *tuple; | |
968 | cisparse_t *parse; | |
969 | u_char *buf; | |
1da177e4 LT |
970 | char *name; |
971 | int i, j, rev; | |
972 | kio_addr_t ioaddr; | |
973 | u_long mir; | |
974 | ||
975 | DEBUG(0, "smc91c92_config(0x%p)\n", link); | |
976 | ||
4638aef4 YR |
977 | cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); |
978 | if (!cfg_mem) | |
979 | goto config_failed; | |
1da177e4 | 980 | |
4638aef4 YR |
981 | tuple = &cfg_mem->tuple; |
982 | parse = &cfg_mem->parse; | |
983 | buf = cfg_mem->buf; | |
984 | ||
985 | tuple->Attributes = tuple->TupleOffset = 0; | |
986 | tuple->TupleData = (cisdata_t *)buf; | |
987 | tuple->TupleDataMax = 64; | |
988 | ||
989 | tuple->DesiredTuple = CISTPL_CONFIG; | |
990 | i = first_tuple(handle, tuple, parse); | |
1da177e4 | 991 | CS_EXIT_TEST(i, ParseTuple, config_failed); |
4638aef4 YR |
992 | link->conf.ConfigBase = parse->config.base; |
993 | link->conf.Present = parse->config.rmask[0]; | |
994 | ||
995 | tuple->DesiredTuple = CISTPL_MANFID; | |
996 | tuple->Attributes = TUPLE_RETURN_COMMON; | |
997 | if (first_tuple(handle, tuple, parse) == CS_SUCCESS) { | |
998 | smc->manfid = parse->manfid.manf; | |
999 | smc->cardid = parse->manfid.card; | |
1da177e4 LT |
1000 | } |
1001 | ||
1002 | /* Configure card */ | |
1003 | link->state |= DEV_CONFIG; | |
1004 | ||
1005 | if ((smc->manfid == MANFID_OSITECH) && | |
1006 | (smc->cardid != PRODID_OSITECH_SEVEN)) { | |
1007 | i = osi_config(link); | |
1008 | } else if ((smc->manfid == MANFID_MOTOROLA) || | |
1009 | ((smc->manfid == MANFID_MEGAHERTZ) && | |
1010 | ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) || | |
1011 | (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) { | |
1012 | i = mhz_mfc_config(link); | |
1013 | } else { | |
1014 | i = smc_config(link); | |
1015 | } | |
1016 | CS_EXIT_TEST(i, RequestIO, config_failed); | |
1017 | ||
1018 | i = pcmcia_request_irq(link->handle, &link->irq); | |
1019 | CS_EXIT_TEST(i, RequestIRQ, config_failed); | |
1020 | i = pcmcia_request_configuration(link->handle, &link->conf); | |
1021 | CS_EXIT_TEST(i, RequestConfiguration, config_failed); | |
1022 | ||
1023 | if (smc->manfid == MANFID_MOTOROLA) | |
1024 | mot_config(link); | |
1025 | ||
1026 | dev->irq = link->irq.AssignedIRQ; | |
1027 | ||
1028 | if ((if_port >= 0) && (if_port <= 2)) | |
1029 | dev->if_port = if_port; | |
1030 | else | |
1031 | printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n"); | |
1032 | ||
1033 | switch (smc->manfid) { | |
1034 | case MANFID_OSITECH: | |
1035 | case MANFID_PSION: | |
1036 | i = osi_setup(link, smc->manfid, smc->cardid); break; | |
1037 | case MANFID_SMC: | |
1038 | case MANFID_NEW_MEDIA: | |
1039 | i = smc_setup(link); break; | |
1040 | case 0x128: /* For broken Megahertz cards */ | |
1041 | case MANFID_MEGAHERTZ: | |
1042 | i = mhz_setup(link); break; | |
1043 | case MANFID_MOTOROLA: | |
1044 | default: /* get the hw address from EEPROM */ | |
1045 | i = mot_setup(link); break; | |
1046 | } | |
1047 | ||
1048 | if (i != 0) { | |
1049 | printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n"); | |
1050 | goto config_undo; | |
1051 | } | |
1052 | ||
1053 | smc->duplex = 0; | |
1054 | smc->rx_ovrn = 0; | |
1055 | ||
1056 | rev = check_sig(link); | |
1057 | name = "???"; | |
1058 | if (rev > 0) | |
1059 | switch (rev >> 4) { | |
1060 | case 3: name = "92"; break; | |
1061 | case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break; | |
1062 | case 5: name = "95"; break; | |
1063 | case 7: name = "100"; break; | |
1064 | case 8: name = "100-FD"; break; | |
1065 | case 9: name = "110"; break; | |
1066 | } | |
1067 | ||
1068 | ioaddr = dev->base_addr; | |
1069 | if (rev > 0) { | |
1070 | u_long mcr; | |
1071 | SMC_SELECT_BANK(0); | |
1072 | mir = inw(ioaddr + MEMINFO) & 0xff; | |
1073 | if (mir == 0xff) mir++; | |
1074 | /* Get scale factor for memory size */ | |
1075 | mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200; | |
1076 | mir *= 128 * (1<<((mcr >> 9) & 7)); | |
1077 | SMC_SELECT_BANK(1); | |
1078 | smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT; | |
1079 | smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC; | |
1080 | if (smc->manfid == MANFID_OSITECH) | |
1081 | smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0; | |
1082 | if ((rev >> 4) >= 7) | |
1083 | smc->cfg |= CFG_MII_SELECT; | |
1084 | } else | |
1085 | mir = 0; | |
1086 | ||
1087 | if (smc->cfg & CFG_MII_SELECT) { | |
1088 | SMC_SELECT_BANK(3); | |
1089 | ||
1090 | for (i = 0; i < 32; i++) { | |
1091 | j = mdio_read(dev, i, 1); | |
1092 | if ((j != 0) && (j != 0xffff)) break; | |
1093 | } | |
1094 | smc->mii_if.phy_id = (i < 32) ? i : -1; | |
1095 | ||
1096 | SMC_SELECT_BANK(0); | |
1097 | } | |
1098 | ||
1099 | link->dev = &smc->node; | |
1100 | link->state &= ~DEV_CONFIG_PENDING; | |
1101 | SET_NETDEV_DEV(dev, &handle_to_dev(handle)); | |
1102 | ||
1103 | if (register_netdev(dev) != 0) { | |
1104 | printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n"); | |
1105 | link->dev = NULL; | |
1106 | goto config_undo; | |
1107 | } | |
1108 | ||
1109 | strcpy(smc->node.dev_name, dev->name); | |
1110 | ||
1111 | printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, " | |
1112 | "hw_addr ", dev->name, name, (rev & 0x0f), dev->base_addr, | |
1113 | dev->irq); | |
1114 | for (i = 0; i < 6; i++) | |
1115 | printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); | |
1116 | ||
1117 | if (rev > 0) { | |
1118 | if (mir & 0x3ff) | |
1119 | printk(KERN_INFO " %lu byte", mir); | |
1120 | else | |
1121 | printk(KERN_INFO " %lu kb", mir>>10); | |
1122 | printk(" buffer, %s xcvr\n", (smc->cfg & CFG_MII_SELECT) ? | |
1123 | "MII" : if_names[dev->if_port]); | |
1124 | } | |
1125 | ||
1126 | if (smc->cfg & CFG_MII_SELECT) { | |
1127 | if (smc->mii_if.phy_id != -1) { | |
1128 | DEBUG(0, " MII transceiver at index %d, status %x.\n", | |
1129 | smc->mii_if.phy_id, j); | |
1130 | } else { | |
1131 | printk(KERN_NOTICE " No MII transceivers found!\n"); | |
1132 | } | |
1133 | } | |
4638aef4 | 1134 | kfree(cfg_mem); |
1da177e4 LT |
1135 | return; |
1136 | ||
1137 | config_undo: | |
1138 | unregister_netdev(dev); | |
1139 | config_failed: /* CS_EXIT_TEST() calls jump to here... */ | |
1140 | smc91c92_release(link); | |
1141 | link->state &= ~DEV_CONFIG_PENDING; | |
4638aef4 | 1142 | kfree(cfg_mem); |
1da177e4 LT |
1143 | |
1144 | } /* smc91c92_config */ | |
1145 | ||
1146 | /*====================================================================== | |
1147 | ||
1148 | After a card is removed, smc91c92_release() will unregister the net | |
1149 | device, and release the PCMCIA configuration. If the device is | |
1150 | still open, this will be postponed until it is closed. | |
1151 | ||
1152 | ======================================================================*/ | |
1153 | ||
1154 | static void smc91c92_release(dev_link_t *link) | |
1155 | { | |
1156 | ||
1157 | DEBUG(0, "smc91c92_release(0x%p)\n", link); | |
1158 | ||
1159 | pcmcia_release_configuration(link->handle); | |
1160 | pcmcia_release_io(link->handle, &link->io); | |
1161 | pcmcia_release_irq(link->handle, &link->irq); | |
1162 | if (link->win) { | |
1163 | struct net_device *dev = link->priv; | |
1164 | struct smc_private *smc = netdev_priv(dev); | |
1165 | iounmap(smc->base); | |
1166 | pcmcia_release_window(link->win); | |
1167 | } | |
1168 | ||
1169 | link->state &= ~DEV_CONFIG; | |
1170 | } | |
1171 | ||
1172 | /*====================================================================== | |
1173 | ||
1174 | The card status event handler. Mostly, this schedules other | |
1175 | stuff to run after an event is received. A CARD_REMOVAL event | |
1176 | also sets some flags to discourage the net drivers from trying | |
1177 | to talk to the card any more. | |
1178 | ||
1179 | ======================================================================*/ | |
1180 | ||
1181 | static int smc91c92_event(event_t event, int priority, | |
1182 | event_callback_args_t *args) | |
1183 | { | |
1184 | dev_link_t *link = args->client_data; | |
1185 | struct net_device *dev = link->priv; | |
1186 | struct smc_private *smc = netdev_priv(dev); | |
1187 | int i; | |
1188 | ||
1189 | DEBUG(1, "smc91c92_event(0x%06x)\n", event); | |
1190 | ||
1191 | switch (event) { | |
1192 | case CS_EVENT_CARD_REMOVAL: | |
1193 | link->state &= ~DEV_PRESENT; | |
1194 | if (link->state & DEV_CONFIG) | |
1195 | netif_device_detach(dev); | |
1196 | break; | |
1197 | case CS_EVENT_CARD_INSERTION: | |
1198 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; | |
1199 | smc91c92_config(link); | |
1200 | break; | |
1201 | case CS_EVENT_PM_SUSPEND: | |
1202 | link->state |= DEV_SUSPEND; | |
1203 | /* Fall through... */ | |
1204 | case CS_EVENT_RESET_PHYSICAL: | |
1205 | if (link->state & DEV_CONFIG) { | |
1206 | if (link->open) | |
1207 | netif_device_detach(dev); | |
1208 | pcmcia_release_configuration(link->handle); | |
1209 | } | |
1210 | break; | |
1211 | case CS_EVENT_PM_RESUME: | |
1212 | link->state &= ~DEV_SUSPEND; | |
1213 | /* Fall through... */ | |
1214 | case CS_EVENT_CARD_RESET: | |
1215 | if (link->state & DEV_CONFIG) { | |
1216 | if ((smc->manfid == MANFID_MEGAHERTZ) && | |
1217 | (smc->cardid == PRODID_MEGAHERTZ_EM3288)) | |
1218 | mhz_3288_power(link); | |
1219 | pcmcia_request_configuration(link->handle, &link->conf); | |
1220 | if (smc->manfid == MANFID_MOTOROLA) | |
1221 | mot_config(link); | |
1222 | if ((smc->manfid == MANFID_OSITECH) && | |
1223 | (smc->cardid != PRODID_OSITECH_SEVEN)) { | |
1224 | /* Power up the card and enable interrupts */ | |
1225 | set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR); | |
1226 | set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR); | |
1227 | } | |
1228 | if (((smc->manfid == MANFID_OSITECH) && | |
1229 | (smc->cardid == PRODID_OSITECH_SEVEN)) || | |
1230 | ((smc->manfid == MANFID_PSION) && | |
1231 | (smc->cardid == PRODID_PSION_NET100))) { | |
1232 | /* Download the Seven of Diamonds firmware */ | |
1233 | for (i = 0; i < sizeof(__Xilinx7OD); i++) { | |
1234 | outb(__Xilinx7OD[i], link->io.BasePort1+2); | |
1235 | udelay(50); | |
1236 | } | |
1237 | } | |
1238 | if (link->open) { | |
1239 | smc_reset(dev); | |
1240 | netif_device_attach(dev); | |
1241 | } | |
1242 | } | |
1243 | break; | |
1244 | } | |
1245 | return 0; | |
1246 | } /* smc91c92_event */ | |
1247 | ||
1248 | /*====================================================================== | |
1249 | ||
1250 | MII interface support for SMC91cXX based cards | |
1251 | ======================================================================*/ | |
1252 | ||
1253 | #define MDIO_SHIFT_CLK 0x04 | |
1254 | #define MDIO_DATA_OUT 0x01 | |
1255 | #define MDIO_DIR_WRITE 0x08 | |
1256 | #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE) | |
1257 | #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT) | |
1258 | #define MDIO_DATA_READ 0x02 | |
1259 | ||
1260 | static void mdio_sync(kio_addr_t addr) | |
1261 | { | |
1262 | int bits; | |
1263 | for (bits = 0; bits < 32; bits++) { | |
1264 | outb(MDIO_DATA_WRITE1, addr); | |
1265 | outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr); | |
1266 | } | |
1267 | } | |
1268 | ||
1269 | static int mdio_read(struct net_device *dev, int phy_id, int loc) | |
1270 | { | |
1271 | kio_addr_t addr = dev->base_addr + MGMT; | |
1272 | u_int cmd = (0x06<<10)|(phy_id<<5)|loc; | |
1273 | int i, retval = 0; | |
1274 | ||
1275 | mdio_sync(addr); | |
1276 | for (i = 13; i >= 0; i--) { | |
1277 | int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0; | |
1278 | outb(dat, addr); | |
1279 | outb(dat | MDIO_SHIFT_CLK, addr); | |
1280 | } | |
1281 | for (i = 19; i > 0; i--) { | |
1282 | outb(0, addr); | |
1283 | retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0); | |
1284 | outb(MDIO_SHIFT_CLK, addr); | |
1285 | } | |
1286 | return (retval>>1) & 0xffff; | |
1287 | } | |
1288 | ||
1289 | static void mdio_write(struct net_device *dev, int phy_id, int loc, int value) | |
1290 | { | |
1291 | kio_addr_t addr = dev->base_addr + MGMT; | |
1292 | u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value; | |
1293 | int i; | |
1294 | ||
1295 | mdio_sync(addr); | |
1296 | for (i = 31; i >= 0; i--) { | |
1297 | int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0; | |
1298 | outb(dat, addr); | |
1299 | outb(dat | MDIO_SHIFT_CLK, addr); | |
1300 | } | |
1301 | for (i = 1; i >= 0; i--) { | |
1302 | outb(0, addr); | |
1303 | outb(MDIO_SHIFT_CLK, addr); | |
1304 | } | |
1305 | } | |
1306 | ||
1307 | /*====================================================================== | |
1308 | ||
1309 | The driver core code, most of which should be common with a | |
1310 | non-PCMCIA implementation. | |
1311 | ||
1312 | ======================================================================*/ | |
1313 | ||
1314 | #ifdef PCMCIA_DEBUG | |
1315 | static void smc_dump(struct net_device *dev) | |
1316 | { | |
1317 | kio_addr_t ioaddr = dev->base_addr; | |
1318 | u_short i, w, save; | |
1319 | save = inw(ioaddr + BANK_SELECT); | |
1320 | for (w = 0; w < 4; w++) { | |
1321 | SMC_SELECT_BANK(w); | |
1322 | printk(KERN_DEBUG "bank %d: ", w); | |
1323 | for (i = 0; i < 14; i += 2) | |
1324 | printk(" %04x", inw(ioaddr + i)); | |
1325 | printk("\n"); | |
1326 | } | |
1327 | outw(save, ioaddr + BANK_SELECT); | |
1328 | } | |
1329 | #endif | |
1330 | ||
1331 | static int smc_open(struct net_device *dev) | |
1332 | { | |
1333 | struct smc_private *smc = netdev_priv(dev); | |
1334 | dev_link_t *link = &smc->link; | |
1335 | ||
1336 | #ifdef PCMCIA_DEBUG | |
1337 | DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n", | |
1338 | dev->name, dev, inw(dev->base_addr + BANK_SELECT)); | |
1339 | if (pc_debug > 1) smc_dump(dev); | |
1340 | #endif | |
1341 | ||
1342 | /* Check that the PCMCIA card is still here. */ | |
1343 | if (!DEV_OK(link)) | |
1344 | return -ENODEV; | |
1345 | /* Physical device present signature. */ | |
1346 | if (check_sig(link) < 0) { | |
1347 | printk("smc91c92_cs: Yikes! Bad chip signature!\n"); | |
1348 | return -ENODEV; | |
1349 | } | |
1350 | link->open++; | |
1351 | ||
1352 | netif_start_queue(dev); | |
1353 | smc->saved_skb = NULL; | |
1354 | smc->packets_waiting = 0; | |
1355 | ||
1356 | smc_reset(dev); | |
1357 | init_timer(&smc->media); | |
1358 | smc->media.function = &media_check; | |
1359 | smc->media.data = (u_long) dev; | |
1360 | smc->media.expires = jiffies + HZ; | |
1361 | add_timer(&smc->media); | |
1362 | ||
1363 | return 0; | |
1364 | } /* smc_open */ | |
1365 | ||
1366 | /*====================================================================*/ | |
1367 | ||
1368 | static int smc_close(struct net_device *dev) | |
1369 | { | |
1370 | struct smc_private *smc = netdev_priv(dev); | |
1371 | dev_link_t *link = &smc->link; | |
1372 | kio_addr_t ioaddr = dev->base_addr; | |
1373 | ||
1374 | DEBUG(0, "%s: smc_close(), status %4.4x.\n", | |
1375 | dev->name, inw(ioaddr + BANK_SELECT)); | |
1376 | ||
1377 | netif_stop_queue(dev); | |
1378 | ||
1379 | /* Shut off all interrupts, and turn off the Tx and Rx sections. | |
1380 | Don't bother to check for chip present. */ | |
1381 | SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */ | |
1382 | outw(0, ioaddr + INTERRUPT); | |
1383 | SMC_SELECT_BANK(0); | |
1384 | mask_bits(0xff00, ioaddr + RCR); | |
1385 | mask_bits(0xff00, ioaddr + TCR); | |
1386 | ||
1387 | /* Put the chip into power-down mode. */ | |
1388 | SMC_SELECT_BANK(1); | |
1389 | outw(CTL_POWERDOWN, ioaddr + CONTROL ); | |
1390 | ||
1391 | link->open--; | |
1392 | del_timer_sync(&smc->media); | |
1393 | ||
1394 | return 0; | |
1395 | } /* smc_close */ | |
1396 | ||
1397 | /*====================================================================== | |
1398 | ||
1399 | Transfer a packet to the hardware and trigger the packet send. | |
1400 | This may be called at either from either the Tx queue code | |
1401 | or the interrupt handler. | |
1402 | ||
1403 | ======================================================================*/ | |
1404 | ||
1405 | static void smc_hardware_send_packet(struct net_device * dev) | |
1406 | { | |
1407 | struct smc_private *smc = netdev_priv(dev); | |
1408 | struct sk_buff *skb = smc->saved_skb; | |
1409 | kio_addr_t ioaddr = dev->base_addr; | |
1410 | u_char packet_no; | |
1411 | ||
1412 | if (!skb) { | |
1413 | printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name); | |
1414 | return; | |
1415 | } | |
1416 | ||
1417 | /* There should be a packet slot waiting. */ | |
1418 | packet_no = inw(ioaddr + PNR_ARR) >> 8; | |
1419 | if (packet_no & 0x80) { | |
1420 | /* If not, there is a hardware problem! Likely an ejected card. */ | |
1421 | printk(KERN_WARNING "%s: 91c92 hardware Tx buffer allocation" | |
1422 | " failed, status %#2.2x.\n", dev->name, packet_no); | |
1423 | dev_kfree_skb_irq(skb); | |
1424 | smc->saved_skb = NULL; | |
1425 | netif_start_queue(dev); | |
1426 | return; | |
1427 | } | |
1428 | ||
1429 | smc->stats.tx_bytes += skb->len; | |
1430 | /* The card should use the just-allocated buffer. */ | |
1431 | outw(packet_no, ioaddr + PNR_ARR); | |
1432 | /* point to the beginning of the packet */ | |
1433 | outw(PTR_AUTOINC , ioaddr + POINTER); | |
1434 | ||
1435 | /* Send the packet length (+6 for status, length and ctl byte) | |
1436 | and the status word (set to zeros). */ | |
1437 | { | |
1438 | u_char *buf = skb->data; | |
1439 | u_int length = skb->len; /* The chip will pad to ethernet min. */ | |
1440 | ||
1441 | DEBUG(2, "%s: Trying to xmit packet of length %d.\n", | |
1442 | dev->name, length); | |
1443 | ||
1444 | /* send the packet length: +6 for status word, length, and ctl */ | |
1445 | outw(0, ioaddr + DATA_1); | |
1446 | outw(length + 6, ioaddr + DATA_1); | |
1447 | outsw(ioaddr + DATA_1, buf, length >> 1); | |
1448 | ||
1449 | /* The odd last byte, if there is one, goes in the control word. */ | |
1450 | outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1); | |
1451 | } | |
1452 | ||
1453 | /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */ | |
1454 | outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) | | |
1455 | (inw(ioaddr + INTERRUPT) & 0xff00), | |
1456 | ioaddr + INTERRUPT); | |
1457 | ||
1458 | /* The chip does the rest of the work. */ | |
1459 | outw(MC_ENQUEUE , ioaddr + MMU_CMD); | |
1460 | ||
1461 | smc->saved_skb = NULL; | |
1462 | dev_kfree_skb_irq(skb); | |
1463 | dev->trans_start = jiffies; | |
1464 | netif_start_queue(dev); | |
1465 | return; | |
1466 | } | |
1467 | ||
1468 | /*====================================================================*/ | |
1469 | ||
1470 | static void smc_tx_timeout(struct net_device *dev) | |
1471 | { | |
1472 | struct smc_private *smc = netdev_priv(dev); | |
1473 | kio_addr_t ioaddr = dev->base_addr; | |
1474 | ||
1475 | printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, " | |
1476 | "Tx_status %2.2x status %4.4x.\n", | |
1477 | dev->name, inw(ioaddr)&0xff, inw(ioaddr + 2)); | |
1478 | smc->stats.tx_errors++; | |
1479 | smc_reset(dev); | |
1480 | dev->trans_start = jiffies; | |
1481 | smc->saved_skb = NULL; | |
1482 | netif_wake_queue(dev); | |
1483 | } | |
1484 | ||
1485 | static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
1486 | { | |
1487 | struct smc_private *smc = netdev_priv(dev); | |
1488 | kio_addr_t ioaddr = dev->base_addr; | |
1489 | u_short num_pages; | |
1490 | short time_out, ir; | |
1491 | ||
1492 | netif_stop_queue(dev); | |
1493 | ||
1494 | DEBUG(2, "%s: smc_start_xmit(length = %d) called," | |
1495 | " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2)); | |
1496 | ||
1497 | if (smc->saved_skb) { | |
1498 | /* THIS SHOULD NEVER HAPPEN. */ | |
1499 | smc->stats.tx_aborted_errors++; | |
1500 | printk(KERN_DEBUG "%s: Internal error -- sent packet while busy.\n", | |
1501 | dev->name); | |
1502 | return 1; | |
1503 | } | |
1504 | smc->saved_skb = skb; | |
1505 | ||
1506 | num_pages = skb->len >> 8; | |
1507 | ||
1508 | if (num_pages > 7) { | |
1509 | printk(KERN_ERR "%s: Far too big packet error.\n", dev->name); | |
1510 | dev_kfree_skb (skb); | |
1511 | smc->saved_skb = NULL; | |
1512 | smc->stats.tx_dropped++; | |
1513 | return 0; /* Do not re-queue this packet. */ | |
1514 | } | |
1515 | /* A packet is now waiting. */ | |
1516 | smc->packets_waiting++; | |
1517 | ||
1518 | SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */ | |
1519 | ||
1520 | /* need MC_RESET to keep the memory consistent. errata? */ | |
1521 | if (smc->rx_ovrn) { | |
1522 | outw(MC_RESET, ioaddr + MMU_CMD); | |
1523 | smc->rx_ovrn = 0; | |
1524 | } | |
1525 | ||
1526 | /* Allocate the memory; send the packet now if we win. */ | |
1527 | outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD); | |
1528 | for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) { | |
1529 | ir = inw(ioaddr+INTERRUPT); | |
1530 | if (ir & IM_ALLOC_INT) { | |
1531 | /* Acknowledge the interrupt, send the packet. */ | |
1532 | outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT); | |
1533 | smc_hardware_send_packet(dev); /* Send the packet now.. */ | |
1534 | return 0; | |
1535 | } | |
1536 | } | |
1537 | ||
1538 | /* Otherwise defer until the Tx-space-allocated interrupt. */ | |
1539 | DEBUG(2, "%s: memory allocation deferred.\n", dev->name); | |
1540 | outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT); | |
1541 | ||
1542 | return 0; | |
1543 | } | |
1544 | ||
1545 | /*====================================================================== | |
1546 | ||
1547 | Handle a Tx anomolous event. Entered while in Window 2. | |
1548 | ||
1549 | ======================================================================*/ | |
1550 | ||
1551 | static void smc_tx_err(struct net_device * dev) | |
1552 | { | |
1553 | struct smc_private *smc = netdev_priv(dev); | |
1554 | kio_addr_t ioaddr = dev->base_addr; | |
1555 | int saved_packet = inw(ioaddr + PNR_ARR) & 0xff; | |
1556 | int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f; | |
1557 | int tx_status; | |
1558 | ||
1559 | /* select this as the packet to read from */ | |
1560 | outw(packet_no, ioaddr + PNR_ARR); | |
1561 | ||
1562 | /* read the first word from this packet */ | |
1563 | outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER); | |
1564 | ||
1565 | tx_status = inw(ioaddr + DATA_1); | |
1566 | ||
1567 | smc->stats.tx_errors++; | |
1568 | if (tx_status & TS_LOSTCAR) smc->stats.tx_carrier_errors++; | |
1569 | if (tx_status & TS_LATCOL) smc->stats.tx_window_errors++; | |
1570 | if (tx_status & TS_16COL) { | |
1571 | smc->stats.tx_aborted_errors++; | |
1572 | smc->tx_err++; | |
1573 | } | |
1574 | ||
1575 | if (tx_status & TS_SUCCESS) { | |
1576 | printk(KERN_NOTICE "%s: Successful packet caused error " | |
1577 | "interrupt?\n", dev->name); | |
1578 | } | |
1579 | /* re-enable transmit */ | |
1580 | SMC_SELECT_BANK(0); | |
1581 | outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR); | |
1582 | SMC_SELECT_BANK(2); | |
1583 | ||
1584 | outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */ | |
1585 | ||
1586 | /* one less packet waiting for me */ | |
1587 | smc->packets_waiting--; | |
1588 | ||
1589 | outw(saved_packet, ioaddr + PNR_ARR); | |
1590 | return; | |
1591 | } | |
1592 | ||
1593 | /*====================================================================*/ | |
1594 | ||
1595 | static void smc_eph_irq(struct net_device *dev) | |
1596 | { | |
1597 | struct smc_private *smc = netdev_priv(dev); | |
1598 | kio_addr_t ioaddr = dev->base_addr; | |
1599 | u_short card_stats, ephs; | |
1600 | ||
1601 | SMC_SELECT_BANK(0); | |
1602 | ephs = inw(ioaddr + EPH); | |
1603 | DEBUG(2, "%s: Ethernet protocol handler interrupt, status" | |
1604 | " %4.4x.\n", dev->name, ephs); | |
1605 | /* Could be a counter roll-over warning: update stats. */ | |
1606 | card_stats = inw(ioaddr + COUNTER); | |
1607 | /* single collisions */ | |
1608 | smc->stats.collisions += card_stats & 0xF; | |
1609 | card_stats >>= 4; | |
1610 | /* multiple collisions */ | |
1611 | smc->stats.collisions += card_stats & 0xF; | |
1612 | #if 0 /* These are for when linux supports these statistics */ | |
1613 | card_stats >>= 4; /* deferred */ | |
1614 | card_stats >>= 4; /* excess deferred */ | |
1615 | #endif | |
1616 | /* If we had a transmit error we must re-enable the transmitter. */ | |
1617 | outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR); | |
1618 | ||
1619 | /* Clear a link error interrupt. */ | |
1620 | SMC_SELECT_BANK(1); | |
1621 | outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL); | |
1622 | outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE, | |
1623 | ioaddr + CONTROL); | |
1624 | SMC_SELECT_BANK(2); | |
1625 | } | |
1626 | ||
1627 | /*====================================================================*/ | |
1628 | ||
1629 | static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs) | |
1630 | { | |
1631 | struct net_device *dev = dev_id; | |
1632 | struct smc_private *smc = netdev_priv(dev); | |
1633 | kio_addr_t ioaddr; | |
1634 | u_short saved_bank, saved_pointer, mask, status; | |
1635 | unsigned int handled = 1; | |
1636 | char bogus_cnt = INTR_WORK; /* Work we are willing to do. */ | |
1637 | ||
1638 | if (!netif_device_present(dev)) | |
1639 | return IRQ_NONE; | |
1640 | ||
1641 | ioaddr = dev->base_addr; | |
1642 | ||
1643 | DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name, | |
1644 | irq, ioaddr); | |
1645 | ||
1646 | smc->watchdog = 0; | |
1647 | saved_bank = inw(ioaddr + BANK_SELECT); | |
1648 | if ((saved_bank & 0xff00) != 0x3300) { | |
1649 | /* The device does not exist -- the card could be off-line, or | |
1650 | maybe it has been ejected. */ | |
1651 | DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent" | |
1652 | "/ejected device.\n", dev->name, irq); | |
1653 | handled = 0; | |
1654 | goto irq_done; | |
1655 | } | |
1656 | ||
1657 | SMC_SELECT_BANK(2); | |
1658 | saved_pointer = inw(ioaddr + POINTER); | |
1659 | mask = inw(ioaddr + INTERRUPT) >> 8; | |
1660 | /* clear all interrupts */ | |
1661 | outw(0, ioaddr + INTERRUPT); | |
1662 | ||
1663 | do { /* read the status flag, and mask it */ | |
1664 | status = inw(ioaddr + INTERRUPT) & 0xff; | |
1665 | DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev->name, | |
1666 | status, mask); | |
1667 | if ((status & mask) == 0) { | |
1668 | if (bogus_cnt == INTR_WORK) | |
1669 | handled = 0; | |
1670 | break; | |
1671 | } | |
1672 | if (status & IM_RCV_INT) { | |
1673 | /* Got a packet(s). */ | |
1674 | smc_rx(dev); | |
1675 | } | |
1676 | if (status & IM_TX_INT) { | |
1677 | smc_tx_err(dev); | |
1678 | outw(IM_TX_INT, ioaddr + INTERRUPT); | |
1679 | } | |
1680 | status &= mask; | |
1681 | if (status & IM_TX_EMPTY_INT) { | |
1682 | outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT); | |
1683 | mask &= ~IM_TX_EMPTY_INT; | |
1684 | smc->stats.tx_packets += smc->packets_waiting; | |
1685 | smc->packets_waiting = 0; | |
1686 | } | |
1687 | if (status & IM_ALLOC_INT) { | |
1688 | /* Clear this interrupt so it doesn't happen again */ | |
1689 | mask &= ~IM_ALLOC_INT; | |
1690 | ||
1691 | smc_hardware_send_packet(dev); | |
1692 | ||
1693 | /* enable xmit interrupts based on this */ | |
1694 | mask |= (IM_TX_EMPTY_INT | IM_TX_INT); | |
1695 | ||
1696 | /* and let the card send more packets to me */ | |
1697 | netif_wake_queue(dev); | |
1698 | } | |
1699 | if (status & IM_RX_OVRN_INT) { | |
1700 | smc->stats.rx_errors++; | |
1701 | smc->stats.rx_fifo_errors++; | |
1702 | if (smc->duplex) | |
1703 | smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */ | |
1704 | outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT); | |
1705 | } | |
1706 | if (status & IM_EPH_INT) | |
1707 | smc_eph_irq(dev); | |
1708 | } while (--bogus_cnt); | |
1709 | ||
1710 | DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x" | |
1711 | " pointer %4.4x.\n", mask, saved_bank, saved_pointer); | |
1712 | ||
1713 | /* restore state register */ | |
1714 | outw((mask<<8), ioaddr + INTERRUPT); | |
1715 | outw(saved_pointer, ioaddr + POINTER); | |
1716 | SMC_SELECT_BANK(saved_bank); | |
1717 | ||
1718 | DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq); | |
1719 | ||
1720 | irq_done: | |
1721 | ||
1722 | if ((smc->manfid == MANFID_OSITECH) && | |
1723 | (smc->cardid != PRODID_OSITECH_SEVEN)) { | |
1724 | /* Retrigger interrupt if needed */ | |
1725 | mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR); | |
1726 | set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR); | |
1727 | } | |
1728 | if (smc->manfid == MANFID_MOTOROLA) { | |
1729 | u_char cor; | |
1730 | cor = readb(smc->base + MOT_UART + CISREG_COR); | |
1731 | writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR); | |
1732 | writeb(cor, smc->base + MOT_UART + CISREG_COR); | |
1733 | cor = readb(smc->base + MOT_LAN + CISREG_COR); | |
1734 | writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR); | |
1735 | writeb(cor, smc->base + MOT_LAN + CISREG_COR); | |
1736 | } | |
1737 | #ifdef DOES_NOT_WORK | |
1738 | if (smc->base != NULL) { /* Megahertz MFC's */ | |
1739 | readb(smc->base+MEGAHERTZ_ISR); | |
1740 | readb(smc->base+MEGAHERTZ_ISR); | |
1741 | } | |
1742 | #endif | |
1743 | return IRQ_RETVAL(handled); | |
1744 | } | |
1745 | ||
1746 | /*====================================================================*/ | |
1747 | ||
1748 | static void smc_rx(struct net_device *dev) | |
1749 | { | |
1750 | struct smc_private *smc = netdev_priv(dev); | |
1751 | kio_addr_t ioaddr = dev->base_addr; | |
1752 | int rx_status; | |
1753 | int packet_length; /* Caution: not frame length, rather words | |
1754 | to transfer from the chip. */ | |
1755 | ||
1756 | /* Assertion: we are in Window 2. */ | |
1757 | ||
1758 | if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) { | |
1759 | printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n", | |
1760 | dev->name); | |
1761 | return; | |
1762 | } | |
1763 | ||
1764 | /* Reset the read pointer, and read the status and packet length. */ | |
1765 | outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER); | |
1766 | rx_status = inw(ioaddr + DATA_1); | |
1767 | packet_length = inw(ioaddr + DATA_1) & 0x07ff; | |
1768 | ||
1769 | DEBUG(2, "%s: Receive status %4.4x length %d.\n", | |
1770 | dev->name, rx_status, packet_length); | |
1771 | ||
1772 | if (!(rx_status & RS_ERRORS)) { | |
1773 | /* do stuff to make a new packet */ | |
1774 | struct sk_buff *skb; | |
1775 | ||
1776 | /* Note: packet_length adds 5 or 6 extra bytes here! */ | |
1777 | skb = dev_alloc_skb(packet_length+2); | |
1778 | ||
1779 | if (skb == NULL) { | |
1780 | DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name); | |
1781 | smc->stats.rx_dropped++; | |
1782 | outw(MC_RELEASE, ioaddr + MMU_CMD); | |
1783 | return; | |
1784 | } | |
1785 | ||
1786 | packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6); | |
1787 | skb_reserve(skb, 2); | |
1788 | insw(ioaddr+DATA_1, skb_put(skb, packet_length), | |
1789 | (packet_length+1)>>1); | |
1790 | skb->protocol = eth_type_trans(skb, dev); | |
1791 | ||
1792 | skb->dev = dev; | |
1793 | netif_rx(skb); | |
1794 | dev->last_rx = jiffies; | |
1795 | smc->stats.rx_packets++; | |
1796 | smc->stats.rx_bytes += packet_length; | |
1797 | if (rx_status & RS_MULTICAST) | |
1798 | smc->stats.multicast++; | |
1799 | } else { | |
1800 | /* error ... */ | |
1801 | smc->stats.rx_errors++; | |
1802 | ||
1803 | if (rx_status & RS_ALGNERR) smc->stats.rx_frame_errors++; | |
1804 | if (rx_status & (RS_TOOSHORT | RS_TOOLONG)) | |
1805 | smc->stats.rx_length_errors++; | |
1806 | if (rx_status & RS_BADCRC) smc->stats.rx_crc_errors++; | |
1807 | } | |
1808 | /* Let the MMU free the memory of this packet. */ | |
1809 | outw(MC_RELEASE, ioaddr + MMU_CMD); | |
1810 | ||
1811 | return; | |
1812 | } | |
1813 | ||
1814 | /*====================================================================*/ | |
1815 | ||
1816 | static struct net_device_stats *smc_get_stats(struct net_device *dev) | |
1817 | { | |
1818 | struct smc_private *smc = netdev_priv(dev); | |
1819 | /* Nothing to update - the 91c92 is a pretty primative chip. */ | |
1820 | return &smc->stats; | |
1821 | } | |
1822 | ||
1823 | /*====================================================================== | |
1824 | ||
1825 | Calculate values for the hardware multicast filter hash table. | |
1826 | ||
1827 | ======================================================================*/ | |
1828 | ||
1829 | static void fill_multicast_tbl(int count, struct dev_mc_list *addrs, | |
1830 | u_char *multicast_table) | |
1831 | { | |
1832 | struct dev_mc_list *mc_addr; | |
1833 | ||
1834 | for (mc_addr = addrs; mc_addr && --count > 0; mc_addr = mc_addr->next) { | |
1835 | u_int position = ether_crc(6, mc_addr->dmi_addr); | |
1836 | #ifndef final_version /* Verify multicast address. */ | |
1837 | if ((mc_addr->dmi_addr[0] & 1) == 0) | |
1838 | continue; | |
1839 | #endif | |
1840 | multicast_table[position >> 29] |= 1 << ((position >> 26) & 7); | |
1841 | } | |
1842 | } | |
1843 | ||
1844 | /*====================================================================== | |
1845 | ||
1846 | Set the receive mode. | |
1847 | ||
1848 | This routine is used by both the protocol level to notify us of | |
1849 | promiscuous/multicast mode changes, and by the open/reset code to | |
1850 | initialize the Rx registers. We always set the multicast list and | |
1851 | leave the receiver running. | |
1852 | ||
1853 | ======================================================================*/ | |
1854 | ||
1855 | static void set_rx_mode(struct net_device *dev) | |
1856 | { | |
1857 | kio_addr_t ioaddr = dev->base_addr; | |
1858 | struct smc_private *smc = netdev_priv(dev); | |
1859 | u_int multicast_table[ 2 ] = { 0, }; | |
1860 | unsigned long flags; | |
1861 | u_short rx_cfg_setting; | |
1862 | ||
1863 | if (dev->flags & IFF_PROMISC) { | |
1864 | printk(KERN_NOTICE "%s: setting Rx mode to promiscuous.\n", dev->name); | |
1865 | rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti; | |
1866 | } else if (dev->flags & IFF_ALLMULTI) | |
1867 | rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti; | |
1868 | else { | |
1869 | if (dev->mc_count) { | |
1870 | fill_multicast_tbl(dev->mc_count, dev->mc_list, | |
1871 | (u_char *)multicast_table); | |
1872 | } | |
1873 | rx_cfg_setting = RxStripCRC | RxEnable; | |
1874 | } | |
1875 | ||
1876 | /* Load MC table and Rx setting into the chip without interrupts. */ | |
1877 | spin_lock_irqsave(&smc->lock, flags); | |
1878 | SMC_SELECT_BANK(3); | |
1879 | outl(multicast_table[0], ioaddr + MULTICAST0); | |
1880 | outl(multicast_table[1], ioaddr + MULTICAST4); | |
1881 | SMC_SELECT_BANK(0); | |
1882 | outw(rx_cfg_setting, ioaddr + RCR); | |
1883 | SMC_SELECT_BANK(2); | |
1884 | spin_unlock_irqrestore(&smc->lock, flags); | |
1885 | ||
1886 | return; | |
1887 | } | |
1888 | ||
1889 | /*====================================================================== | |
1890 | ||
1891 | Senses when a card's config changes. Here, it's coax or TP. | |
1892 | ||
1893 | ======================================================================*/ | |
1894 | ||
1895 | static int s9k_config(struct net_device *dev, struct ifmap *map) | |
1896 | { | |
1897 | struct smc_private *smc = netdev_priv(dev); | |
1898 | if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) { | |
1899 | if (smc->cfg & CFG_MII_SELECT) | |
1900 | return -EOPNOTSUPP; | |
1901 | else if (map->port > 2) | |
1902 | return -EINVAL; | |
1903 | dev->if_port = map->port; | |
1904 | printk(KERN_INFO "%s: switched to %s port\n", | |
1905 | dev->name, if_names[dev->if_port]); | |
1906 | smc_reset(dev); | |
1907 | } | |
1908 | return 0; | |
1909 | } | |
1910 | ||
1911 | /*====================================================================== | |
1912 | ||
1913 | Reset the chip, reloading every register that might be corrupted. | |
1914 | ||
1915 | ======================================================================*/ | |
1916 | ||
1917 | /* | |
1918 | Set transceiver type, perhaps to something other than what the user | |
1919 | specified in dev->if_port. | |
1920 | */ | |
1921 | static void smc_set_xcvr(struct net_device *dev, int if_port) | |
1922 | { | |
1923 | struct smc_private *smc = netdev_priv(dev); | |
1924 | kio_addr_t ioaddr = dev->base_addr; | |
1925 | u_short saved_bank; | |
1926 | ||
1927 | saved_bank = inw(ioaddr + BANK_SELECT); | |
1928 | SMC_SELECT_BANK(1); | |
1929 | if (if_port == 2) { | |
1930 | outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG); | |
1931 | if ((smc->manfid == MANFID_OSITECH) && | |
1932 | (smc->cardid != PRODID_OSITECH_SEVEN)) | |
1933 | set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR); | |
1934 | smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002); | |
1935 | } else { | |
1936 | outw(smc->cfg, ioaddr + CONFIG); | |
1937 | if ((smc->manfid == MANFID_OSITECH) && | |
1938 | (smc->cardid != PRODID_OSITECH_SEVEN)) | |
1939 | mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR); | |
1940 | smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001); | |
1941 | } | |
1942 | SMC_SELECT_BANK(saved_bank); | |
1943 | } | |
1944 | ||
1945 | static void smc_reset(struct net_device *dev) | |
1946 | { | |
1947 | kio_addr_t ioaddr = dev->base_addr; | |
1948 | struct smc_private *smc = netdev_priv(dev); | |
1949 | int i; | |
1950 | ||
1951 | DEBUG(0, "%s: smc91c92 reset called.\n", dev->name); | |
1952 | ||
1953 | /* The first interaction must be a write to bring the chip out | |
1954 | of sleep mode. */ | |
1955 | SMC_SELECT_BANK(0); | |
1956 | /* Reset the chip. */ | |
1957 | outw(RCR_SOFTRESET, ioaddr + RCR); | |
1958 | udelay(10); | |
1959 | ||
1960 | /* Clear the transmit and receive configuration registers. */ | |
1961 | outw(RCR_CLEAR, ioaddr + RCR); | |
1962 | outw(TCR_CLEAR, ioaddr + TCR); | |
1963 | ||
1964 | /* Set the Window 1 control, configuration and station addr registers. | |
1965 | No point in writing the I/O base register ;-> */ | |
1966 | SMC_SELECT_BANK(1); | |
1967 | /* Automatically release succesfully transmitted packets, | |
1968 | Accept link errors, counter and Tx error interrupts. */ | |
1969 | outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE, | |
1970 | ioaddr + CONTROL); | |
1971 | smc_set_xcvr(dev, dev->if_port); | |
1972 | if ((smc->manfid == MANFID_OSITECH) && | |
1973 | (smc->cardid != PRODID_OSITECH_SEVEN)) | |
1974 | outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) | | |
1975 | (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00), | |
1976 | ioaddr - 0x10 + OSITECH_AUI_PWR); | |
1977 | ||
1978 | /* Fill in the physical address. The databook is wrong about the order! */ | |
1979 | for (i = 0; i < 6; i += 2) | |
1980 | outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i], | |
1981 | ioaddr + ADDR0 + i); | |
1982 | ||
1983 | /* Reset the MMU */ | |
1984 | SMC_SELECT_BANK(2); | |
1985 | outw(MC_RESET, ioaddr + MMU_CMD); | |
1986 | outw(0, ioaddr + INTERRUPT); | |
1987 | ||
1988 | /* Re-enable the chip. */ | |
1989 | SMC_SELECT_BANK(0); | |
1990 | outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) | | |
1991 | TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR); | |
1992 | set_rx_mode(dev); | |
1993 | ||
1994 | if (smc->cfg & CFG_MII_SELECT) { | |
1995 | SMC_SELECT_BANK(3); | |
1996 | ||
1997 | /* Reset MII */ | |
1998 | mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000); | |
1999 | ||
2000 | /* Advertise 100F, 100H, 10F, 10H */ | |
2001 | mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1); | |
2002 | ||
2003 | /* Restart MII autonegotiation */ | |
2004 | mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000); | |
2005 | mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200); | |
2006 | } | |
2007 | ||
2008 | /* Enable interrupts. */ | |
2009 | SMC_SELECT_BANK(2); | |
2010 | outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8, | |
2011 | ioaddr + INTERRUPT); | |
2012 | } | |
2013 | ||
2014 | /*====================================================================== | |
2015 | ||
2016 | Media selection timer routine | |
2017 | ||
2018 | ======================================================================*/ | |
2019 | ||
2020 | static void media_check(u_long arg) | |
2021 | { | |
2022 | struct net_device *dev = (struct net_device *) arg; | |
2023 | struct smc_private *smc = netdev_priv(dev); | |
2024 | kio_addr_t ioaddr = dev->base_addr; | |
2025 | u_short i, media, saved_bank; | |
2026 | u_short link; | |
2027 | ||
2028 | saved_bank = inw(ioaddr + BANK_SELECT); | |
2029 | ||
2030 | if (!netif_device_present(dev)) | |
2031 | goto reschedule; | |
2032 | ||
2033 | SMC_SELECT_BANK(2); | |
2034 | ||
2035 | /* need MC_RESET to keep the memory consistent. errata? */ | |
2036 | if (smc->rx_ovrn) { | |
2037 | outw(MC_RESET, ioaddr + MMU_CMD); | |
2038 | smc->rx_ovrn = 0; | |
2039 | } | |
2040 | i = inw(ioaddr + INTERRUPT); | |
2041 | SMC_SELECT_BANK(0); | |
2042 | media = inw(ioaddr + EPH) & EPH_LINK_OK; | |
2043 | SMC_SELECT_BANK(1); | |
2044 | media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1; | |
2045 | ||
2046 | /* Check for pending interrupt with watchdog flag set: with | |
2047 | this, we can limp along even if the interrupt is blocked */ | |
2048 | if (smc->watchdog++ && ((i>>8) & i)) { | |
2049 | if (!smc->fast_poll) | |
2050 | printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name); | |
2051 | smc_interrupt(dev->irq, smc, NULL); | |
2052 | smc->fast_poll = HZ; | |
2053 | } | |
2054 | if (smc->fast_poll) { | |
2055 | smc->fast_poll--; | |
2056 | smc->media.expires = jiffies + HZ/100; | |
2057 | add_timer(&smc->media); | |
2058 | SMC_SELECT_BANK(saved_bank); | |
2059 | return; | |
2060 | } | |
2061 | ||
2062 | if (smc->cfg & CFG_MII_SELECT) { | |
2063 | if (smc->mii_if.phy_id < 0) | |
2064 | goto reschedule; | |
2065 | ||
2066 | SMC_SELECT_BANK(3); | |
2067 | link = mdio_read(dev, smc->mii_if.phy_id, 1); | |
2068 | if (!link || (link == 0xffff)) { | |
2069 | printk(KERN_INFO "%s: MII is missing!\n", dev->name); | |
2070 | smc->mii_if.phy_id = -1; | |
2071 | goto reschedule; | |
2072 | } | |
2073 | ||
2074 | link &= 0x0004; | |
2075 | if (link != smc->link_status) { | |
2076 | u_short p = mdio_read(dev, smc->mii_if.phy_id, 5); | |
2077 | printk(KERN_INFO "%s: %s link beat\n", dev->name, | |
2078 | (link) ? "found" : "lost"); | |
2079 | smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40)) | |
2080 | ? TCR_FDUPLX : 0); | |
2081 | if (link) { | |
2082 | printk(KERN_INFO "%s: autonegotiation complete: " | |
2083 | "%sbaseT-%cD selected\n", dev->name, | |
2084 | ((p & 0x0180) ? "100" : "10"), | |
2085 | (smc->duplex ? 'F' : 'H')); | |
2086 | } | |
2087 | SMC_SELECT_BANK(0); | |
2088 | outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR); | |
2089 | smc->link_status = link; | |
2090 | } | |
2091 | goto reschedule; | |
2092 | } | |
2093 | ||
2094 | /* Ignore collisions unless we've had no rx's recently */ | |
2095 | if (jiffies - dev->last_rx > HZ) { | |
2096 | if (smc->tx_err || (smc->media_status & EPH_16COL)) | |
2097 | media |= EPH_16COL; | |
2098 | } | |
2099 | smc->tx_err = 0; | |
2100 | ||
2101 | if (media != smc->media_status) { | |
2102 | if ((media & smc->media_status & 1) && | |
2103 | ((smc->media_status ^ media) & EPH_LINK_OK)) | |
2104 | printk(KERN_INFO "%s: %s link beat\n", dev->name, | |
2105 | (smc->media_status & EPH_LINK_OK ? "lost" : "found")); | |
2106 | else if ((media & smc->media_status & 2) && | |
2107 | ((smc->media_status ^ media) & EPH_16COL)) | |
2108 | printk(KERN_INFO "%s: coax cable %s\n", dev->name, | |
2109 | (media & EPH_16COL ? "problem" : "ok")); | |
2110 | if (dev->if_port == 0) { | |
2111 | if (media & 1) { | |
2112 | if (media & EPH_LINK_OK) | |
2113 | printk(KERN_INFO "%s: flipped to 10baseT\n", | |
2114 | dev->name); | |
2115 | else | |
2116 | smc_set_xcvr(dev, 2); | |
2117 | } else { | |
2118 | if (media & EPH_16COL) | |
2119 | smc_set_xcvr(dev, 1); | |
2120 | else | |
2121 | printk(KERN_INFO "%s: flipped to 10base2\n", | |
2122 | dev->name); | |
2123 | } | |
2124 | } | |
2125 | smc->media_status = media; | |
2126 | } | |
2127 | ||
2128 | reschedule: | |
2129 | smc->media.expires = jiffies + HZ; | |
2130 | add_timer(&smc->media); | |
2131 | SMC_SELECT_BANK(saved_bank); | |
2132 | } | |
2133 | ||
2134 | static int smc_link_ok(struct net_device *dev) | |
2135 | { | |
2136 | kio_addr_t ioaddr = dev->base_addr; | |
2137 | struct smc_private *smc = netdev_priv(dev); | |
2138 | ||
2139 | if (smc->cfg & CFG_MII_SELECT) { | |
2140 | return mii_link_ok(&smc->mii_if); | |
2141 | } else { | |
2142 | SMC_SELECT_BANK(0); | |
2143 | return inw(ioaddr + EPH) & EPH_LINK_OK; | |
2144 | } | |
2145 | } | |
2146 | ||
2147 | static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd) | |
2148 | { | |
2149 | u16 tmp; | |
2150 | kio_addr_t ioaddr = dev->base_addr; | |
2151 | ||
2152 | ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI | | |
2153 | SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full); | |
2154 | ||
2155 | SMC_SELECT_BANK(1); | |
2156 | tmp = inw(ioaddr + CONFIG); | |
2157 | ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP; | |
2158 | ecmd->transceiver = XCVR_INTERNAL; | |
2159 | ecmd->speed = SPEED_10; | |
2160 | ecmd->phy_address = ioaddr + MGMT; | |
2161 | ||
2162 | SMC_SELECT_BANK(0); | |
2163 | tmp = inw(ioaddr + TCR); | |
2164 | ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF; | |
2165 | ||
2166 | return 0; | |
2167 | } | |
2168 | ||
2169 | static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd) | |
2170 | { | |
2171 | u16 tmp; | |
2172 | kio_addr_t ioaddr = dev->base_addr; | |
2173 | ||
2174 | if (ecmd->speed != SPEED_10) | |
2175 | return -EINVAL; | |
2176 | if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL) | |
2177 | return -EINVAL; | |
2178 | if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI) | |
2179 | return -EINVAL; | |
2180 | if (ecmd->transceiver != XCVR_INTERNAL) | |
2181 | return -EINVAL; | |
2182 | ||
2183 | if (ecmd->port == PORT_AUI) | |
2184 | smc_set_xcvr(dev, 1); | |
2185 | else | |
2186 | smc_set_xcvr(dev, 0); | |
2187 | ||
2188 | SMC_SELECT_BANK(0); | |
2189 | tmp = inw(ioaddr + TCR); | |
2190 | if (ecmd->duplex == DUPLEX_FULL) | |
2191 | tmp |= TCR_FDUPLX; | |
2192 | else | |
2193 | tmp &= ~TCR_FDUPLX; | |
2194 | outw(tmp, ioaddr + TCR); | |
2195 | ||
2196 | return 0; | |
2197 | } | |
2198 | ||
2199 | static int check_if_running(struct net_device *dev) | |
2200 | { | |
2201 | if (!netif_running(dev)) | |
2202 | return -EINVAL; | |
2203 | return 0; | |
2204 | } | |
2205 | ||
2206 | static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) | |
2207 | { | |
2208 | strcpy(info->driver, DRV_NAME); | |
2209 | strcpy(info->version, DRV_VERSION); | |
2210 | } | |
2211 | ||
2212 | static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | |
2213 | { | |
2214 | struct smc_private *smc = netdev_priv(dev); | |
2215 | kio_addr_t ioaddr = dev->base_addr; | |
2216 | u16 saved_bank = inw(ioaddr + BANK_SELECT); | |
2217 | int ret; | |
2218 | ||
2219 | SMC_SELECT_BANK(3); | |
2220 | spin_lock_irq(&smc->lock); | |
2221 | if (smc->cfg & CFG_MII_SELECT) | |
2222 | ret = mii_ethtool_gset(&smc->mii_if, ecmd); | |
2223 | else | |
2224 | ret = smc_netdev_get_ecmd(dev, ecmd); | |
2225 | spin_unlock_irq(&smc->lock); | |
2226 | SMC_SELECT_BANK(saved_bank); | |
2227 | return ret; | |
2228 | } | |
2229 | ||
2230 | static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | |
2231 | { | |
2232 | struct smc_private *smc = netdev_priv(dev); | |
2233 | kio_addr_t ioaddr = dev->base_addr; | |
2234 | u16 saved_bank = inw(ioaddr + BANK_SELECT); | |
2235 | int ret; | |
2236 | ||
2237 | SMC_SELECT_BANK(3); | |
2238 | spin_lock_irq(&smc->lock); | |
2239 | if (smc->cfg & CFG_MII_SELECT) | |
2240 | ret = mii_ethtool_sset(&smc->mii_if, ecmd); | |
2241 | else | |
2242 | ret = smc_netdev_set_ecmd(dev, ecmd); | |
2243 | spin_unlock_irq(&smc->lock); | |
2244 | SMC_SELECT_BANK(saved_bank); | |
2245 | return ret; | |
2246 | } | |
2247 | ||
2248 | static u32 smc_get_link(struct net_device *dev) | |
2249 | { | |
2250 | struct smc_private *smc = netdev_priv(dev); | |
2251 | kio_addr_t ioaddr = dev->base_addr; | |
2252 | u16 saved_bank = inw(ioaddr + BANK_SELECT); | |
2253 | u32 ret; | |
2254 | ||
2255 | SMC_SELECT_BANK(3); | |
2256 | spin_lock_irq(&smc->lock); | |
2257 | ret = smc_link_ok(dev); | |
2258 | spin_unlock_irq(&smc->lock); | |
2259 | SMC_SELECT_BANK(saved_bank); | |
2260 | return ret; | |
2261 | } | |
2262 | ||
2263 | #ifdef PCMCIA_DEBUG | |
2264 | static u32 smc_get_msglevel(struct net_device *dev) | |
2265 | { | |
2266 | return pc_debug; | |
2267 | } | |
2268 | ||
2269 | static void smc_set_msglevel(struct net_device *dev, u32 val) | |
2270 | { | |
2271 | pc_debug = val; | |
2272 | } | |
2273 | #endif | |
2274 | ||
2275 | static int smc_nway_reset(struct net_device *dev) | |
2276 | { | |
2277 | struct smc_private *smc = netdev_priv(dev); | |
2278 | if (smc->cfg & CFG_MII_SELECT) { | |
2279 | kio_addr_t ioaddr = dev->base_addr; | |
2280 | u16 saved_bank = inw(ioaddr + BANK_SELECT); | |
2281 | int res; | |
2282 | ||
2283 | SMC_SELECT_BANK(3); | |
2284 | res = mii_nway_restart(&smc->mii_if); | |
2285 | SMC_SELECT_BANK(saved_bank); | |
2286 | ||
2287 | return res; | |
2288 | } else | |
2289 | return -EOPNOTSUPP; | |
2290 | } | |
2291 | ||
2292 | static struct ethtool_ops ethtool_ops = { | |
2293 | .begin = check_if_running, | |
2294 | .get_drvinfo = smc_get_drvinfo, | |
2295 | .get_settings = smc_get_settings, | |
2296 | .set_settings = smc_set_settings, | |
2297 | .get_link = smc_get_link, | |
2298 | #ifdef PCMCIA_DEBUG | |
2299 | .get_msglevel = smc_get_msglevel, | |
2300 | .set_msglevel = smc_set_msglevel, | |
2301 | #endif | |
2302 | .nway_reset = smc_nway_reset, | |
2303 | }; | |
2304 | ||
2305 | static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd) | |
2306 | { | |
2307 | struct smc_private *smc = netdev_priv(dev); | |
2308 | struct mii_ioctl_data *mii = if_mii(rq); | |
2309 | int rc = 0; | |
2310 | u16 saved_bank; | |
2311 | kio_addr_t ioaddr = dev->base_addr; | |
2312 | ||
2313 | if (!netif_running(dev)) | |
2314 | return -EINVAL; | |
2315 | ||
2316 | spin_lock_irq(&smc->lock); | |
2317 | saved_bank = inw(ioaddr + BANK_SELECT); | |
2318 | SMC_SELECT_BANK(3); | |
2319 | rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL); | |
2320 | SMC_SELECT_BANK(saved_bank); | |
2321 | spin_unlock_irq(&smc->lock); | |
2322 | return rc; | |
2323 | } | |
2324 | ||
5c672220 DB |
2325 | static struct pcmcia_device_id smc91c92_ids[] = { |
2326 | PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501), | |
2327 | PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a), | |
2328 | PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63), | |
2329 | PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63), | |
2330 | PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef), | |
2331 | PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef), | |
2332 | PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c), | |
2333 | PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e), | |
2334 | PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f), | |
2335 | PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f), | |
2336 | PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020), | |
2337 | PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023), | |
2338 | PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb), | |
2339 | PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc), | |
2340 | PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1), | |
2341 | PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5), | |
2342 | PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9), | |
2343 | PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953), | |
2344 | PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a), | |
2345 | PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f), | |
2346 | PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f), | |
2347 | PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc), | |
2348 | PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9), | |
2349 | PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d), | |
2350 | /* These conflict with other cards! */ | |
2351 | /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */ | |
2352 | /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */ | |
2353 | PCMCIA_DEVICE_NULL, | |
2354 | }; | |
2355 | MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids); | |
2356 | ||
1da177e4 LT |
2357 | static struct pcmcia_driver smc91c92_cs_driver = { |
2358 | .owner = THIS_MODULE, | |
2359 | .drv = { | |
2360 | .name = "smc91c92_cs", | |
2361 | }, | |
2362 | .attach = smc91c92_attach, | |
1e212f36 | 2363 | .event = smc91c92_event, |
1da177e4 | 2364 | .detach = smc91c92_detach, |
5c672220 | 2365 | .id_table = smc91c92_ids, |
1da177e4 LT |
2366 | }; |
2367 | ||
2368 | static int __init init_smc91c92_cs(void) | |
2369 | { | |
2370 | return pcmcia_register_driver(&smc91c92_cs_driver); | |
2371 | } | |
2372 | ||
2373 | static void __exit exit_smc91c92_cs(void) | |
2374 | { | |
2375 | pcmcia_unregister_driver(&smc91c92_cs_driver); | |
2376 | BUG_ON(dev_list != NULL); | |
2377 | } | |
2378 | ||
2379 | module_init(init_smc91c92_cs); | |
2380 | module_exit(exit_smc91c92_cs); |