xref: /linux/drivers/net/ethernet/cirrus/cs89x0.c (revision 878492af7d503f4b093ea903173500be00e9cbe7)
1 /* cs89x0.c: A Crystal Semiconductor (Now Cirrus Logic) CS89[02]0
2  *           driver for linux.
3  * Written 1996 by Russell Nelson, with reference to skeleton.c
4  * written 1993-1994 by Donald Becker.
5  *
6  * This software may be used and distributed according to the terms
7  * of the GNU General Public License, incorporated herein by reference.
8  *
9  * The author may be reached at nelson@crynwr.com, Crynwr
10  * Software, 521 Pleasant Valley Rd., Potsdam, NY 13676
11  *
12  * Other contributors:
13  * Mike Cruse        : mcruse@cti-ltd.com
14  * Russ Nelson
15  * Melody Lee        : ethernet@crystal.cirrus.com
16  * Alan Cox
17  * Andrew Morton
18  * Oskar Schirmer    : oskar@scara.com
19  * Deepak Saxena     : dsaxena@plexity.net
20  * Dmitry Pervushin  : dpervushin@ru.mvista.com
21  * Deepak Saxena     : dsaxena@plexity.net
22  * Domenico Andreoli : cavokz@gmail.com
23  */
24 
25 /*
26  * Set this to zero to remove all the debug statements via
27  * dead code elimination
28  */
29 #define DEBUGGING	1
30 
31 /* Sources:
32  *	Crynwr packet driver epktisa.
33  *	Crystal Semiconductor data sheets.
34  */
35 
36 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37 
38 #include <linux/module.h>
39 #include <linux/printk.h>
40 #include <linux/errno.h>
41 #include <linux/netdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/of.h>
44 #include <linux/platform_device.h>
45 #include <linux/kernel.h>
46 #include <linux/types.h>
47 #include <linux/fcntl.h>
48 #include <linux/interrupt.h>
49 #include <linux/ioport.h>
50 #include <linux/in.h>
51 #include <linux/jiffies.h>
52 #include <linux/skbuff.h>
53 #include <linux/spinlock.h>
54 #include <linux/string.h>
55 #include <linux/init.h>
56 #include <linux/bitops.h>
57 #include <linux/delay.h>
58 #include <linux/gfp.h>
59 #include <linux/io.h>
60 
61 #include <asm/irq.h>
62 #include <linux/atomic.h>
63 
64 #include "cs89x0.h"
65 
66 #define cs89_dbg(val, level, fmt, ...)				\
67 do {								\
68 	if (val <= net_debug)					\
69 		pr_##level(fmt, ##__VA_ARGS__);			\
70 } while (0)
71 
72 static char version[] __initdata =
73 	"v2.4.3-pre1 Russell Nelson <nelson@crynwr.com>, Andrew Morton";
74 
75 #define DRV_NAME "cs89x0"
76 #if DEBUGGING
77 static unsigned int net_debug = DEBUGGING;
78 #else
79 #define net_debug 0	/* gcc will remove all the debug code for us */
80 #endif
81 
82 /* The number of low I/O ports used by the ethercard. */
83 #define NETCARD_IO_EXTENT	16
84 
85 /* we allow the user to override various values normally set in the EEPROM */
86 #define FORCE_RJ45	0x0001    /* pick one of these three */
87 #define FORCE_AUI	0x0002
88 #define FORCE_BNC	0x0004
89 
90 #define FORCE_AUTO	0x0010    /* pick one of these three */
91 #define FORCE_HALF	0x0020
92 #define FORCE_FULL	0x0030
93 
94 /* Information that need to be kept for each board. */
95 struct net_local {
96 	int chip_type;		/* one of: CS8900, CS8920, CS8920M */
97 	char chip_revision;	/* revision letter of the chip ('A'...) */
98 	int send_cmd;		/* the proper send command: TX_NOW, TX_AFTER_381, or TX_AFTER_ALL */
99 	int auto_neg_cnf;	/* auto-negotiation word from EEPROM */
100 	int adapter_cnf;	/* adapter configuration from EEPROM */
101 	int isa_config;		/* ISA configuration from EEPROM */
102 	int irq_map;		/* IRQ map from EEPROM */
103 	int rx_mode;		/* what mode are we in? 0, RX_MULTCAST_ACCEPT, or RX_ALL_ACCEPT */
104 	int curr_rx_cfg;	/* a copy of PP_RxCFG */
105 	int linectl;		/* either 0 or LOW_RX_SQUELCH, depending on configuration. */
106 	int send_underrun;	/* keep track of how many underruns in a row we get */
107 	int force;		/* force various values; see FORCE* above. */
108 	spinlock_t lock;
109 	void __iomem *virt_addr;/* CS89x0 virtual address. */
110 };
111 
112 /* Example routines you must write ;->. */
113 #define tx_done(dev) 1
114 
115 /*
116  * Permit 'cs89x0_dma=N' in the kernel boot environment
117  */
118 #if !defined(MODULE)
119 static int g_cs89x0_media__force;
120 
121 static int __init media_fn(char *str)
122 {
123 	if (!strcmp(str, "rj45"))
124 		g_cs89x0_media__force = FORCE_RJ45;
125 	else if (!strcmp(str, "aui"))
126 		g_cs89x0_media__force = FORCE_AUI;
127 	else if (!strcmp(str, "bnc"))
128 		g_cs89x0_media__force = FORCE_BNC;
129 
130 	return 1;
131 }
132 
133 __setup("cs89x0_media=", media_fn);
134 #endif
135 
136 static void readwords(struct net_local *lp, int portno, void *buf, int length)
137 {
138 	u8 *buf8 = (u8 *)buf;
139 
140 	do {
141 		u16 tmp16;
142 
143 		tmp16 = ioread16(lp->virt_addr + portno);
144 		*buf8++ = (u8)tmp16;
145 		*buf8++ = (u8)(tmp16 >> 8);
146 	} while (--length);
147 }
148 
149 static void writewords(struct net_local *lp, int portno, void *buf, int length)
150 {
151 	u8 *buf8 = (u8 *)buf;
152 
153 	do {
154 		u16 tmp16;
155 
156 		tmp16 = *buf8++;
157 		tmp16 |= (*buf8++) << 8;
158 		iowrite16(tmp16, lp->virt_addr + portno);
159 	} while (--length);
160 }
161 
162 static u16
163 readreg(struct net_device *dev, u16 regno)
164 {
165 	struct net_local *lp = netdev_priv(dev);
166 
167 	iowrite16(regno, lp->virt_addr + ADD_PORT);
168 	return ioread16(lp->virt_addr + DATA_PORT);
169 }
170 
171 static void
172 writereg(struct net_device *dev, u16 regno, u16 value)
173 {
174 	struct net_local *lp = netdev_priv(dev);
175 
176 	iowrite16(regno, lp->virt_addr + ADD_PORT);
177 	iowrite16(value, lp->virt_addr + DATA_PORT);
178 }
179 
180 static int __init
181 wait_eeprom_ready(struct net_device *dev)
182 {
183 	unsigned long timeout = jiffies;
184 	/* check to see if the EEPROM is ready,
185 	 * a timeout is used just in case EEPROM is ready when
186 	 * SI_BUSY in the PP_SelfST is clear
187 	 */
188 	while (readreg(dev, PP_SelfST) & SI_BUSY)
189 		if (time_after_eq(jiffies, timeout + 40))
190 			return -1;
191 	return 0;
192 }
193 
194 static int __init
195 get_eeprom_data(struct net_device *dev, int off, int len, int *buffer)
196 {
197 	int i;
198 
199 	cs89_dbg(3, info, "EEPROM data from %x for %x:", off, len);
200 	for (i = 0; i < len; i++) {
201 		if (wait_eeprom_ready(dev) < 0)
202 			return -1;
203 		/* Now send the EEPROM read command and EEPROM location to read */
204 		writereg(dev, PP_EECMD, (off + i) | EEPROM_READ_CMD);
205 		if (wait_eeprom_ready(dev) < 0)
206 			return -1;
207 		buffer[i] = readreg(dev, PP_EEData);
208 		cs89_dbg(3, cont, " %04x", buffer[i]);
209 	}
210 	cs89_dbg(3, cont, "\n");
211 	return 0;
212 }
213 
214 static int  __init
215 get_eeprom_cksum(int off, int len, int *buffer)
216 {
217 	int i, cksum;
218 
219 	cksum = 0;
220 	for (i = 0; i < len; i++)
221 		cksum += buffer[i];
222 	cksum &= 0xffff;
223 	if (cksum == 0)
224 		return 0;
225 	return -1;
226 }
227 
228 static void
229 write_irq(struct net_device *dev, int chip_type, int irq)
230 {
231 	if (chip_type == CS8900) {
232 		/* INTRQ0 pin is used for interrupt generation. */
233 		writereg(dev, PP_CS8900_ISAINT, 0);
234 	} else {
235 		writereg(dev, PP_CS8920_ISAINT, irq);
236 	}
237 }
238 
239 static void
240 count_rx_errors(int status, struct net_device *dev)
241 {
242 	dev->stats.rx_errors++;
243 	if (status & RX_RUNT)
244 		dev->stats.rx_length_errors++;
245 	if (status & RX_EXTRA_DATA)
246 		dev->stats.rx_length_errors++;
247 	if ((status & RX_CRC_ERROR) && !(status & (RX_EXTRA_DATA | RX_RUNT)))
248 		/* per str 172 */
249 		dev->stats.rx_crc_errors++;
250 	if (status & RX_DRIBBLE)
251 		dev->stats.rx_frame_errors++;
252 }
253 
254 static void
255 control_dc_dc(struct net_device *dev, int on_not_off)
256 {
257 	struct net_local *lp = netdev_priv(dev);
258 	unsigned int selfcontrol;
259 	unsigned long timenow = jiffies;
260 	/* control the DC to DC convertor in the SelfControl register.
261 	 * Note: This is hooked up to a general purpose pin, might not
262 	 * always be a DC to DC convertor.
263 	 */
264 
265 	selfcontrol = HCB1_ENBL; /* Enable the HCB1 bit as an output */
266 	if (((lp->adapter_cnf & A_CNF_DC_DC_POLARITY) != 0) ^ on_not_off)
267 		selfcontrol |= HCB1;
268 	else
269 		selfcontrol &= ~HCB1;
270 	writereg(dev, PP_SelfCTL, selfcontrol);
271 
272 	/* Wait for the DC/DC converter to power up - 500ms */
273 	while (time_before(jiffies, timenow + HZ))
274 		;
275 }
276 
277 /* send a test packet - return true if carrier bits are ok */
278 static int
279 send_test_pkt(struct net_device *dev)
280 {
281 	struct net_local *lp = netdev_priv(dev);
282 	char test_packet[] = {
283 		0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0,
284 		0, 46,		/* A 46 in network order */
285 		0, 0,		/* DSAP=0 & SSAP=0 fields */
286 		0xf3, 0		/* Control (Test Req + P bit set) */
287 	};
288 	unsigned long timenow = jiffies;
289 
290 	writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_TX_ON);
291 
292 	memcpy(test_packet,            dev->dev_addr, ETH_ALEN);
293 	memcpy(test_packet + ETH_ALEN, dev->dev_addr, ETH_ALEN);
294 
295 	iowrite16(TX_AFTER_ALL, lp->virt_addr + TX_CMD_PORT);
296 	iowrite16(ETH_ZLEN, lp->virt_addr + TX_LEN_PORT);
297 
298 	/* Test to see if the chip has allocated memory for the packet */
299 	while (time_before(jiffies, timenow + 5))
300 		if (readreg(dev, PP_BusST) & READY_FOR_TX_NOW)
301 			break;
302 	if (time_after_eq(jiffies, timenow + 5))
303 		return 0;	/* this shouldn't happen */
304 
305 	/* Write the contents of the packet */
306 	writewords(lp, TX_FRAME_PORT, test_packet, (ETH_ZLEN + 1) >> 1);
307 
308 	cs89_dbg(1, debug, "Sending test packet ");
309 	/* wait a couple of jiffies for packet to be received */
310 	for (timenow = jiffies; time_before(jiffies, timenow + 3);)
311 		;
312 	if ((readreg(dev, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) {
313 		cs89_dbg(1, cont, "succeeded\n");
314 		return 1;
315 	}
316 	cs89_dbg(1, cont, "failed\n");
317 	return 0;
318 }
319 
320 #define DETECTED_NONE  0
321 #define DETECTED_RJ45H 1
322 #define DETECTED_RJ45F 2
323 #define DETECTED_AUI   3
324 #define DETECTED_BNC   4
325 
326 static int
327 detect_tp(struct net_device *dev)
328 {
329 	struct net_local *lp = netdev_priv(dev);
330 	unsigned long timenow = jiffies;
331 	int fdx;
332 
333 	cs89_dbg(1, debug, "%s: Attempting TP\n", dev->name);
334 
335 	/* If connected to another full duplex capable 10-Base-T card
336 	 * the link pulses seem to be lost when the auto detect bit in
337 	 * the LineCTL is set.  To overcome this the auto detect bit will
338 	 * be cleared whilst testing the 10-Base-T interface.  This would
339 	 * not be necessary for the sparrow chip but is simpler to do it
340 	 * anyway.
341 	 */
342 	writereg(dev, PP_LineCTL, lp->linectl & ~AUI_ONLY);
343 	control_dc_dc(dev, 0);
344 
345 	/* Delay for the hardware to work out if the TP cable is present
346 	 * - 150ms
347 	 */
348 	for (timenow = jiffies; time_before(jiffies, timenow + 15);)
349 		;
350 	if ((readreg(dev, PP_LineST) & LINK_OK) == 0)
351 		return DETECTED_NONE;
352 
353 	if (lp->chip_type == CS8900) {
354 		switch (lp->force & 0xf0) {
355 #if 0
356 		case FORCE_AUTO:
357 			pr_info("%s: cs8900 doesn't autonegotiate\n",
358 				dev->name);
359 			return DETECTED_NONE;
360 #endif
361 			/* CS8900 doesn't support AUTO, change to HALF*/
362 		case FORCE_AUTO:
363 			lp->force &= ~FORCE_AUTO;
364 			lp->force |= FORCE_HALF;
365 			break;
366 		case FORCE_HALF:
367 			break;
368 		case FORCE_FULL:
369 			writereg(dev, PP_TestCTL,
370 				 readreg(dev, PP_TestCTL) | FDX_8900);
371 			break;
372 		}
373 		fdx = readreg(dev, PP_TestCTL) & FDX_8900;
374 	} else {
375 		switch (lp->force & 0xf0) {
376 		case FORCE_AUTO:
377 			lp->auto_neg_cnf = AUTO_NEG_ENABLE;
378 			break;
379 		case FORCE_HALF:
380 			lp->auto_neg_cnf = 0;
381 			break;
382 		case FORCE_FULL:
383 			lp->auto_neg_cnf = RE_NEG_NOW | ALLOW_FDX;
384 			break;
385 		}
386 
387 		writereg(dev, PP_AutoNegCTL, lp->auto_neg_cnf & AUTO_NEG_MASK);
388 
389 		if ((lp->auto_neg_cnf & AUTO_NEG_BITS) == AUTO_NEG_ENABLE) {
390 			pr_info("%s: negotiating duplex...\n", dev->name);
391 			while (readreg(dev, PP_AutoNegST) & AUTO_NEG_BUSY) {
392 				if (time_after(jiffies, timenow + 4000)) {
393 					pr_err("**** Full / half duplex auto-negotiation timed out ****\n");
394 					break;
395 				}
396 			}
397 		}
398 		fdx = readreg(dev, PP_AutoNegST) & FDX_ACTIVE;
399 	}
400 	if (fdx)
401 		return DETECTED_RJ45F;
402 	else
403 		return DETECTED_RJ45H;
404 }
405 
406 static int
407 detect_bnc(struct net_device *dev)
408 {
409 	struct net_local *lp = netdev_priv(dev);
410 
411 	cs89_dbg(1, debug, "%s: Attempting BNC\n", dev->name);
412 	control_dc_dc(dev, 1);
413 
414 	writereg(dev, PP_LineCTL, (lp->linectl & ~AUTO_AUI_10BASET) | AUI_ONLY);
415 
416 	if (send_test_pkt(dev))
417 		return DETECTED_BNC;
418 	else
419 		return DETECTED_NONE;
420 }
421 
422 static int
423 detect_aui(struct net_device *dev)
424 {
425 	struct net_local *lp = netdev_priv(dev);
426 
427 	cs89_dbg(1, debug, "%s: Attempting AUI\n", dev->name);
428 	control_dc_dc(dev, 0);
429 
430 	writereg(dev, PP_LineCTL, (lp->linectl & ~AUTO_AUI_10BASET) | AUI_ONLY);
431 
432 	if (send_test_pkt(dev))
433 		return DETECTED_AUI;
434 	else
435 		return DETECTED_NONE;
436 }
437 
438 /* We have a good packet(s), get it/them out of the buffers. */
439 static void
440 net_rx(struct net_device *dev)
441 {
442 	struct net_local *lp = netdev_priv(dev);
443 	struct sk_buff *skb;
444 	int status, length;
445 
446 	status = ioread16(lp->virt_addr + RX_FRAME_PORT);
447 	length = ioread16(lp->virt_addr + RX_FRAME_PORT);
448 
449 	if ((status & RX_OK) == 0) {
450 		count_rx_errors(status, dev);
451 		return;
452 	}
453 
454 	/* Malloc up new buffer. */
455 	skb = netdev_alloc_skb(dev, length + 2);
456 	if (skb == NULL) {
457 		dev->stats.rx_dropped++;
458 		return;
459 	}
460 	skb_reserve(skb, 2);	/* longword align L3 header */
461 
462 	readwords(lp, RX_FRAME_PORT, skb_put(skb, length), length >> 1);
463 	if (length & 1)
464 		skb->data[length-1] = ioread16(lp->virt_addr + RX_FRAME_PORT);
465 
466 	cs89_dbg(3, debug, "%s: received %d byte packet of type %x\n",
467 		 dev->name, length,
468 		 (skb->data[ETH_ALEN + ETH_ALEN] << 8) |
469 		 skb->data[ETH_ALEN + ETH_ALEN + 1]);
470 
471 	skb->protocol = eth_type_trans(skb, dev);
472 	netif_rx(skb);
473 	dev->stats.rx_packets++;
474 	dev->stats.rx_bytes += length;
475 }
476 
477 /* The typical workload of the driver:
478  * Handle the network interface interrupts.
479  */
480 
481 static irqreturn_t net_interrupt(int irq, void *dev_id)
482 {
483 	struct net_device *dev = dev_id;
484 	struct net_local *lp;
485 	int status;
486 	int handled = 0;
487 
488 	lp = netdev_priv(dev);
489 
490 	/* we MUST read all the events out of the ISQ, otherwise we'll never
491 	 * get interrupted again.  As a consequence, we can't have any limit
492 	 * on the number of times we loop in the interrupt handler.  The
493 	 * hardware guarantees that eventually we'll run out of events.  Of
494 	 * course, if you're on a slow machine, and packets are arriving
495 	 * faster than you can read them off, you're screwed.  Hasta la
496 	 * vista, baby!
497 	 */
498 	while ((status = ioread16(lp->virt_addr + ISQ_PORT))) {
499 		cs89_dbg(4, debug, "%s: event=%04x\n", dev->name, status);
500 		handled = 1;
501 		switch (status & ISQ_EVENT_MASK) {
502 		case ISQ_RECEIVER_EVENT:
503 			/* Got a packet(s). */
504 			net_rx(dev);
505 			break;
506 		case ISQ_TRANSMITTER_EVENT:
507 			dev->stats.tx_packets++;
508 			netif_wake_queue(dev);	/* Inform upper layers. */
509 			if ((status & (TX_OK |
510 				       TX_LOST_CRS |
511 				       TX_SQE_ERROR |
512 				       TX_LATE_COL |
513 				       TX_16_COL)) != TX_OK) {
514 				if ((status & TX_OK) == 0)
515 					dev->stats.tx_errors++;
516 				if (status & TX_LOST_CRS)
517 					dev->stats.tx_carrier_errors++;
518 				if (status & TX_SQE_ERROR)
519 					dev->stats.tx_heartbeat_errors++;
520 				if (status & TX_LATE_COL)
521 					dev->stats.tx_window_errors++;
522 				if (status & TX_16_COL)
523 					dev->stats.tx_aborted_errors++;
524 			}
525 			break;
526 		case ISQ_BUFFER_EVENT:
527 			if (status & READY_FOR_TX) {
528 				/* we tried to transmit a packet earlier,
529 				 * but inexplicably ran out of buffers.
530 				 * That shouldn't happen since we only ever
531 				 * load one packet.  Shrug.  Do the right
532 				 * thing anyway.
533 				 */
534 				netif_wake_queue(dev);	/* Inform upper layers. */
535 			}
536 			if (status & TX_UNDERRUN) {
537 				cs89_dbg(0, err, "%s: transmit underrun\n",
538 					 dev->name);
539 				lp->send_underrun++;
540 				if (lp->send_underrun == 3)
541 					lp->send_cmd = TX_AFTER_381;
542 				else if (lp->send_underrun == 6)
543 					lp->send_cmd = TX_AFTER_ALL;
544 				/* transmit cycle is done, although
545 				 * frame wasn't transmitted - this
546 				 * avoids having to wait for the upper
547 				 * layers to timeout on us, in the
548 				 * event of a tx underrun
549 				 */
550 				netif_wake_queue(dev);	/* Inform upper layers. */
551 			}
552 			break;
553 		case ISQ_RX_MISS_EVENT:
554 			dev->stats.rx_missed_errors += (status >> 6);
555 			break;
556 		case ISQ_TX_COL_EVENT:
557 			dev->stats.collisions += (status >> 6);
558 			break;
559 		}
560 	}
561 	return IRQ_RETVAL(handled);
562 }
563 
564 /* Open/initialize the board.  This is called (in the current kernel)
565    sometime after booting when the 'ifconfig' program is run.
566 
567    This routine should set everything up anew at each open, even
568    registers that "should" only need to be set once at boot, so that
569    there is non-reboot way to recover if something goes wrong.
570 */
571 
572 /* AKPM: do we need to do any locking here? */
573 
574 static int
575 net_open(struct net_device *dev)
576 {
577 	struct net_local *lp = netdev_priv(dev);
578 	int result = 0;
579 	int i;
580 	int ret;
581 
582 	if (dev->irq < 2) {
583 		/* Allow interrupts to be generated by the chip */
584 /* Cirrus' release had this: */
585 #if 0
586 		writereg(dev, PP_BusCTL, readreg(dev, PP_BusCTL) | ENABLE_IRQ);
587 #endif
588 /* And 2.3.47 had this: */
589 		writereg(dev, PP_BusCTL, ENABLE_IRQ | MEMORY_ON);
590 
591 		for (i = 2; i < CS8920_NO_INTS; i++) {
592 			if ((1 << i) & lp->irq_map) {
593 				if (request_irq(i, net_interrupt, 0, dev->name,
594 						dev) == 0) {
595 					dev->irq = i;
596 					write_irq(dev, lp->chip_type, i);
597 					/* writereg(dev, PP_BufCFG, GENERATE_SW_INTERRUPT); */
598 					break;
599 				}
600 			}
601 		}
602 
603 		if (i >= CS8920_NO_INTS) {
604 			writereg(dev, PP_BusCTL, 0);	/* disable interrupts. */
605 			pr_err("can't get an interrupt\n");
606 			ret = -EAGAIN;
607 			goto bad_out;
608 		}
609 	} else {
610 /* FIXME: Cirrus' release had this: */
611 		writereg(dev, PP_BusCTL, readreg(dev, PP_BusCTL)|ENABLE_IRQ);
612 /* And 2.3.47 had this: */
613 #if 0
614 		writereg(dev, PP_BusCTL, ENABLE_IRQ | MEMORY_ON);
615 #endif
616 		write_irq(dev, lp->chip_type, dev->irq);
617 		ret = request_irq(dev->irq, net_interrupt, 0, dev->name, dev);
618 		if (ret) {
619 			pr_err("request_irq(%d) failed\n", dev->irq);
620 			goto bad_out;
621 		}
622 	}
623 
624 	/* set the Ethernet address */
625 	for (i = 0; i < ETH_ALEN / 2; i++)
626 		writereg(dev, PP_IA + i * 2,
627 			 (dev->dev_addr[i * 2] |
628 			  (dev->dev_addr[i * 2 + 1] << 8)));
629 
630 	/* while we're testing the interface, leave interrupts disabled */
631 	writereg(dev, PP_BusCTL, MEMORY_ON);
632 
633 	/* Set the LineCTL quintuplet based on adapter configuration read from EEPROM */
634 	if ((lp->adapter_cnf & A_CNF_EXTND_10B_2) &&
635 	    (lp->adapter_cnf & A_CNF_LOW_RX_SQUELCH))
636 		lp->linectl = LOW_RX_SQUELCH;
637 	else
638 		lp->linectl = 0;
639 
640 	/* check to make sure that they have the "right" hardware available */
641 	switch (lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
642 	case A_CNF_MEDIA_10B_T:
643 		result = lp->adapter_cnf & A_CNF_10B_T;
644 		break;
645 	case A_CNF_MEDIA_AUI:
646 		result = lp->adapter_cnf & A_CNF_AUI;
647 		break;
648 	case A_CNF_MEDIA_10B_2:
649 		result = lp->adapter_cnf & A_CNF_10B_2;
650 		break;
651 	default:
652 		result = lp->adapter_cnf & (A_CNF_10B_T |
653 					    A_CNF_AUI |
654 					    A_CNF_10B_2);
655 	}
656 	if (!result) {
657 		pr_err("%s: EEPROM is configured for unavailable media\n",
658 		       dev->name);
659 release_dma:
660 		writereg(dev, PP_LineCTL,
661 			 readreg(dev, PP_LineCTL) & ~(SERIAL_TX_ON | SERIAL_RX_ON));
662 		free_irq(dev->irq, dev);
663 		ret = -EAGAIN;
664 		goto bad_out;
665 	}
666 
667 	/* set the hardware to the configured choice */
668 	switch (lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
669 	case A_CNF_MEDIA_10B_T:
670 		result = detect_tp(dev);
671 		if (result == DETECTED_NONE) {
672 			pr_warn("%s: 10Base-T (RJ-45) has no cable\n",
673 				dev->name);
674 			if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
675 				result = DETECTED_RJ45H; /* Yes! I don't care if I see a link pulse */
676 		}
677 		break;
678 	case A_CNF_MEDIA_AUI:
679 		result = detect_aui(dev);
680 		if (result == DETECTED_NONE) {
681 			pr_warn("%s: 10Base-5 (AUI) has no cable\n", dev->name);
682 			if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
683 				result = DETECTED_AUI; /* Yes! I don't care if I see a carrier */
684 		}
685 		break;
686 	case A_CNF_MEDIA_10B_2:
687 		result = detect_bnc(dev);
688 		if (result == DETECTED_NONE) {
689 			pr_warn("%s: 10Base-2 (BNC) has no cable\n", dev->name);
690 			if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
691 				result = DETECTED_BNC; /* Yes! I don't care if I can xmit a packet */
692 		}
693 		break;
694 	case A_CNF_MEDIA_AUTO:
695 		writereg(dev, PP_LineCTL, lp->linectl | AUTO_AUI_10BASET);
696 		if (lp->adapter_cnf & A_CNF_10B_T) {
697 			result = detect_tp(dev);
698 			if (result != DETECTED_NONE)
699 				break;
700 		}
701 		if (lp->adapter_cnf & A_CNF_AUI) {
702 			result = detect_aui(dev);
703 			if (result != DETECTED_NONE)
704 				break;
705 		}
706 		if (lp->adapter_cnf & A_CNF_10B_2) {
707 			result = detect_bnc(dev);
708 			if (result != DETECTED_NONE)
709 				break;
710 		}
711 		pr_err("%s: no media detected\n", dev->name);
712 		goto release_dma;
713 	}
714 	switch (result) {
715 	case DETECTED_NONE:
716 		pr_err("%s: no network cable attached to configured media\n",
717 		       dev->name);
718 		goto release_dma;
719 	case DETECTED_RJ45H:
720 		pr_info("%s: using half-duplex 10Base-T (RJ-45)\n", dev->name);
721 		break;
722 	case DETECTED_RJ45F:
723 		pr_info("%s: using full-duplex 10Base-T (RJ-45)\n", dev->name);
724 		break;
725 	case DETECTED_AUI:
726 		pr_info("%s: using 10Base-5 (AUI)\n", dev->name);
727 		break;
728 	case DETECTED_BNC:
729 		pr_info("%s: using 10Base-2 (BNC)\n", dev->name);
730 		break;
731 	}
732 
733 	/* Turn on both receive and transmit operations */
734 	writereg(dev, PP_LineCTL,
735 		 readreg(dev, PP_LineCTL) | SERIAL_RX_ON | SERIAL_TX_ON);
736 
737 	/* Receive only error free packets addressed to this card */
738 	lp->rx_mode = 0;
739 	writereg(dev, PP_RxCTL, DEF_RX_ACCEPT);
740 
741 	lp->curr_rx_cfg = RX_OK_ENBL | RX_CRC_ERROR_ENBL;
742 
743 	if (lp->isa_config & STREAM_TRANSFER)
744 		lp->curr_rx_cfg |= RX_STREAM_ENBL;
745 	writereg(dev, PP_RxCFG, lp->curr_rx_cfg);
746 
747 	writereg(dev, PP_TxCFG, (TX_LOST_CRS_ENBL |
748 				 TX_SQE_ERROR_ENBL |
749 				 TX_OK_ENBL |
750 				 TX_LATE_COL_ENBL |
751 				 TX_JBR_ENBL |
752 				 TX_ANY_COL_ENBL |
753 				 TX_16_COL_ENBL));
754 
755 	writereg(dev, PP_BufCFG, (READY_FOR_TX_ENBL |
756 				  RX_MISS_COUNT_OVRFLOW_ENBL |
757 				  TX_COL_COUNT_OVRFLOW_ENBL |
758 				  TX_UNDERRUN_ENBL));
759 
760 	/* now that we've got our act together, enable everything */
761 	writereg(dev, PP_BusCTL,
762 		 (ENABLE_IRQ | (dev->mem_start ? MEMORY_ON : 0))); /* turn memory on */
763 	netif_start_queue(dev);
764 	cs89_dbg(1, debug, "net_open() succeeded\n");
765 	return 0;
766 bad_out:
767 	return ret;
768 }
769 
770 /* The inverse routine to net_open(). */
771 static int
772 net_close(struct net_device *dev)
773 {
774 	netif_stop_queue(dev);
775 
776 	writereg(dev, PP_RxCFG, 0);
777 	writereg(dev, PP_TxCFG, 0);
778 	writereg(dev, PP_BufCFG, 0);
779 	writereg(dev, PP_BusCTL, 0);
780 
781 	free_irq(dev->irq, dev);
782 
783 	/* Update the statistics here. */
784 	return 0;
785 }
786 
787 /* Get the current statistics.
788  * This may be called with the card open or closed.
789  */
790 static struct net_device_stats *
791 net_get_stats(struct net_device *dev)
792 {
793 	struct net_local *lp = netdev_priv(dev);
794 	unsigned long flags;
795 
796 	spin_lock_irqsave(&lp->lock, flags);
797 	/* Update the statistics from the device registers. */
798 	dev->stats.rx_missed_errors += (readreg(dev, PP_RxMiss) >> 6);
799 	dev->stats.collisions += (readreg(dev, PP_TxCol) >> 6);
800 	spin_unlock_irqrestore(&lp->lock, flags);
801 
802 	return &dev->stats;
803 }
804 
805 static void net_timeout(struct net_device *dev, unsigned int txqueue)
806 {
807 	/* If we get here, some higher level has decided we are broken.
808 	   There should really be a "kick me" function call instead. */
809 	cs89_dbg(0, err, "%s: transmit timed out, %s?\n",
810 		 dev->name,
811 		 tx_done(dev) ? "IRQ conflict" : "network cable problem");
812 	/* Try to restart the adaptor. */
813 	netif_wake_queue(dev);
814 }
815 
816 static netdev_tx_t net_send_packet(struct sk_buff *skb, struct net_device *dev)
817 {
818 	struct net_local *lp = netdev_priv(dev);
819 	unsigned long flags;
820 
821 	cs89_dbg(3, debug, "%s: sent %d byte packet of type %x\n",
822 		 dev->name, skb->len,
823 		 ((skb->data[ETH_ALEN + ETH_ALEN] << 8) |
824 		  skb->data[ETH_ALEN + ETH_ALEN + 1]));
825 
826 	/* keep the upload from being interrupted, since we
827 	 * ask the chip to start transmitting before the
828 	 * whole packet has been completely uploaded.
829 	 */
830 
831 	spin_lock_irqsave(&lp->lock, flags);
832 	netif_stop_queue(dev);
833 
834 	/* initiate a transmit sequence */
835 	iowrite16(lp->send_cmd, lp->virt_addr + TX_CMD_PORT);
836 	iowrite16(skb->len, lp->virt_addr + TX_LEN_PORT);
837 
838 	/* Test to see if the chip has allocated memory for the packet */
839 	if ((readreg(dev, PP_BusST) & READY_FOR_TX_NOW) == 0) {
840 		/* Gasp!  It hasn't.  But that shouldn't happen since
841 		 * we're waiting for TxOk, so return 1 and requeue this packet.
842 		 */
843 
844 		spin_unlock_irqrestore(&lp->lock, flags);
845 		cs89_dbg(0, err, "Tx buffer not free!\n");
846 		return NETDEV_TX_BUSY;
847 	}
848 	/* Write the contents of the packet */
849 	writewords(lp, TX_FRAME_PORT, skb->data, (skb->len + 1) >> 1);
850 	spin_unlock_irqrestore(&lp->lock, flags);
851 	dev->stats.tx_bytes += skb->len;
852 	dev_consume_skb_any(skb);
853 
854 	/* We DO NOT call netif_wake_queue() here.
855 	 * We also DO NOT call netif_start_queue().
856 	 *
857 	 * Either of these would cause another bottom half run through
858 	 * net_send_packet() before this packet has fully gone out.
859 	 * That causes us to hit the "Gasp!" above and the send is rescheduled.
860 	 * it runs like a dog.  We just return and wait for the Tx completion
861 	 * interrupt handler to restart the netdevice layer
862 	 */
863 
864 	return NETDEV_TX_OK;
865 }
866 
867 static void set_multicast_list(struct net_device *dev)
868 {
869 	struct net_local *lp = netdev_priv(dev);
870 	unsigned long flags;
871 	u16 cfg;
872 
873 	spin_lock_irqsave(&lp->lock, flags);
874 	if (dev->flags & IFF_PROMISC)
875 		lp->rx_mode = RX_ALL_ACCEPT;
876 	else if ((dev->flags & IFF_ALLMULTI) || !netdev_mc_empty(dev))
877 		/* The multicast-accept list is initialized to accept-all,
878 		 * and we rely on higher-level filtering for now.
879 		 */
880 		lp->rx_mode = RX_MULTCAST_ACCEPT;
881 	else
882 		lp->rx_mode = 0;
883 
884 	writereg(dev, PP_RxCTL, DEF_RX_ACCEPT | lp->rx_mode);
885 
886 	/* in promiscuous mode, we accept errored packets,
887 	 * so we have to enable interrupts on them also
888 	 */
889 	cfg = lp->curr_rx_cfg;
890 	if (lp->rx_mode == RX_ALL_ACCEPT)
891 		cfg |= RX_CRC_ERROR_ENBL | RX_RUNT_ENBL | RX_EXTRA_DATA_ENBL;
892 	writereg(dev, PP_RxCFG, cfg);
893 	spin_unlock_irqrestore(&lp->lock, flags);
894 }
895 
896 static int set_mac_address(struct net_device *dev, void *p)
897 {
898 	int i;
899 	struct sockaddr *addr = p;
900 
901 	if (netif_running(dev))
902 		return -EBUSY;
903 
904 	eth_hw_addr_set(dev, addr->sa_data);
905 
906 	cs89_dbg(0, debug, "%s: Setting MAC address to %pM\n",
907 		 dev->name, dev->dev_addr);
908 
909 	/* set the Ethernet address */
910 	for (i = 0; i < ETH_ALEN / 2; i++)
911 		writereg(dev, PP_IA + i * 2,
912 			 (dev->dev_addr[i * 2] |
913 			  (dev->dev_addr[i * 2 + 1] << 8)));
914 
915 	return 0;
916 }
917 
918 #ifdef CONFIG_NET_POLL_CONTROLLER
919 /*
920  * Polling receive - used by netconsole and other diagnostic tools
921  * to allow network i/o with interrupts disabled.
922  */
923 static void net_poll_controller(struct net_device *dev)
924 {
925 	disable_irq(dev->irq);
926 	net_interrupt(dev->irq, dev);
927 	enable_irq(dev->irq);
928 }
929 #endif
930 
931 static const struct net_device_ops net_ops = {
932 	.ndo_open		= net_open,
933 	.ndo_stop		= net_close,
934 	.ndo_tx_timeout		= net_timeout,
935 	.ndo_start_xmit		= net_send_packet,
936 	.ndo_get_stats		= net_get_stats,
937 	.ndo_set_rx_mode	= set_multicast_list,
938 	.ndo_set_mac_address	= set_mac_address,
939 #ifdef CONFIG_NET_POLL_CONTROLLER
940 	.ndo_poll_controller	= net_poll_controller,
941 #endif
942 	.ndo_validate_addr	= eth_validate_addr,
943 };
944 
945 static void __init reset_chip(struct net_device *dev)
946 {
947 	struct net_local *lp = netdev_priv(dev);
948 	unsigned long reset_start_time;
949 
950 	writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);
951 
952 	/* wait 30 ms */
953 	msleep(30);
954 
955 	if (lp->chip_type != CS8900) {
956 		/* Hardware problem requires PNP registers to be reconfigured after a reset */
957 		iowrite16(PP_CS8920_ISAINT, lp->virt_addr + ADD_PORT);
958 		iowrite8(dev->irq, lp->virt_addr + DATA_PORT);
959 		iowrite8(0, lp->virt_addr + DATA_PORT + 1);
960 
961 		iowrite16(PP_CS8920_ISAMemB, lp->virt_addr + ADD_PORT);
962 		iowrite8((dev->mem_start >> 16) & 0xff,
963 			 lp->virt_addr + DATA_PORT);
964 		iowrite8((dev->mem_start >> 8) & 0xff,
965 			 lp->virt_addr + DATA_PORT + 1);
966 	}
967 
968 	/* Wait until the chip is reset */
969 	reset_start_time = jiffies;
970 	while ((readreg(dev, PP_SelfST) & INIT_DONE) == 0 &&
971 	       time_before(jiffies, reset_start_time + 2))
972 		;
973 }
974 
975 /* This is the real probe routine.
976  * Linux has a history of friendly device probes on the ISA bus.
977  * A good device probes avoids doing writes, and
978  * verifies that the correct device exists and functions.
979  * Return 0 on success.
980  */
981 static int __init
982 cs89x0_probe1(struct net_device *dev, void __iomem *ioaddr, int modular)
983 {
984 	struct net_local *lp = netdev_priv(dev);
985 	int i;
986 	int tmp;
987 	unsigned rev_type = 0;
988 	int eeprom_buff[CHKSUM_LEN];
989 	u8 addr[ETH_ALEN];
990 	int retval;
991 
992 	/* Initialize the device structure. */
993 	if (!modular) {
994 		memset(lp, 0, sizeof(*lp));
995 		spin_lock_init(&lp->lock);
996 #ifndef MODULE
997 		lp->force = g_cs89x0_media__force;
998 #endif
999 	}
1000 
1001 	pr_debug("PP_addr at %p[%x]: 0x%x\n",
1002 		 ioaddr, ADD_PORT, ioread16(ioaddr + ADD_PORT));
1003 	iowrite16(PP_ChipID, ioaddr + ADD_PORT);
1004 
1005 	tmp = ioread16(ioaddr + DATA_PORT);
1006 	if (tmp != CHIP_EISA_ID_SIG) {
1007 		pr_debug("%s: incorrect signature at %p[%x]: 0x%x!="
1008 			 CHIP_EISA_ID_SIG_STR "\n",
1009 			 dev->name, ioaddr, DATA_PORT, tmp);
1010 		retval = -ENODEV;
1011 		goto out1;
1012 	}
1013 
1014 	lp->virt_addr = ioaddr;
1015 
1016 	/* get the chip type */
1017 	rev_type = readreg(dev, PRODUCT_ID_ADD);
1018 	lp->chip_type = rev_type & ~REVISON_BITS;
1019 	lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A';
1020 
1021 	/* Check the chip type and revision in order to set the correct
1022 	 * send command.  CS8920 revision C and CS8900 revision F can use
1023 	 * the faster send.
1024 	 */
1025 	lp->send_cmd = TX_AFTER_381;
1026 	if (lp->chip_type == CS8900 && lp->chip_revision >= 'F')
1027 		lp->send_cmd = TX_NOW;
1028 	if (lp->chip_type != CS8900 && lp->chip_revision >= 'C')
1029 		lp->send_cmd = TX_NOW;
1030 
1031 	pr_info_once("%s\n", version);
1032 
1033 	pr_info("%s: cs89%c0%s rev %c found at %p ",
1034 		dev->name,
1035 		lp->chip_type == CS8900  ? '0' : '2',
1036 		lp->chip_type == CS8920M ? "M" : "",
1037 		lp->chip_revision,
1038 		lp->virt_addr);
1039 
1040 	reset_chip(dev);
1041 
1042 	/* Here we read the current configuration of the chip.
1043 	 * If there is no Extended EEPROM then the idea is to not disturb
1044 	 * the chip configuration, it should have been correctly setup by
1045 	 * automatic EEPROM read on reset. So, if the chip says it read
1046 	 * the EEPROM the driver will always do *something* instead of
1047 	 * complain that adapter_cnf is 0.
1048 	 */
1049 
1050 	if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) ==
1051 	    (EEPROM_OK | EEPROM_PRESENT)) {
1052 		/* Load the MAC. */
1053 		for (i = 0; i < ETH_ALEN / 2; i++) {
1054 			unsigned int Addr;
1055 			Addr = readreg(dev, PP_IA + i * 2);
1056 			addr[i * 2] = Addr & 0xFF;
1057 			addr[i * 2 + 1] = Addr >> 8;
1058 		}
1059 		eth_hw_addr_set(dev, addr);
1060 
1061 		/* Load the Adapter Configuration.
1062 		 * Note:  Barring any more specific information from some
1063 		 * other source (ie EEPROM+Schematics), we would not know
1064 		 * how to operate a 10Base2 interface on the AUI port.
1065 		 * However, since we  do read the status of HCB1 and use
1066 		 * settings that always result in calls to control_dc_dc(dev,0)
1067 		 * a BNC interface should work if the enable pin
1068 		 * (dc/dc converter) is on HCB1.
1069 		 * It will be called AUI however.
1070 		 */
1071 
1072 		lp->adapter_cnf = 0;
1073 		i = readreg(dev, PP_LineCTL);
1074 		/* Preserve the setting of the HCB1 pin. */
1075 		if ((i & (HCB1 | HCB1_ENBL)) == (HCB1 | HCB1_ENBL))
1076 			lp->adapter_cnf |= A_CNF_DC_DC_POLARITY;
1077 		/* Save the sqelch bit */
1078 		if ((i & LOW_RX_SQUELCH) == LOW_RX_SQUELCH)
1079 			lp->adapter_cnf |= A_CNF_EXTND_10B_2 | A_CNF_LOW_RX_SQUELCH;
1080 		/* Check if the card is in 10Base-t only mode */
1081 		if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == 0)
1082 			lp->adapter_cnf |=  A_CNF_10B_T | A_CNF_MEDIA_10B_T;
1083 		/* Check if the card is in AUI only mode */
1084 		if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUI_ONLY)
1085 			lp->adapter_cnf |=  A_CNF_AUI | A_CNF_MEDIA_AUI;
1086 		/* Check if the card is in Auto mode. */
1087 		if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUTO_AUI_10BASET)
1088 			lp->adapter_cnf |=  A_CNF_AUI | A_CNF_10B_T |
1089 				A_CNF_MEDIA_AUI | A_CNF_MEDIA_10B_T | A_CNF_MEDIA_AUTO;
1090 
1091 		cs89_dbg(1, info, "%s: PP_LineCTL=0x%x, adapter_cnf=0x%x\n",
1092 			 dev->name, i, lp->adapter_cnf);
1093 
1094 		/* IRQ. Other chips already probe, see below. */
1095 		if (lp->chip_type == CS8900)
1096 			lp->isa_config = readreg(dev, PP_CS8900_ISAINT) & INT_NO_MASK;
1097 
1098 		pr_cont("[Cirrus EEPROM] ");
1099 	}
1100 
1101 	pr_cont("\n");
1102 
1103 	/* First check to see if an EEPROM is attached. */
1104 
1105 	if ((readreg(dev, PP_SelfST) & EEPROM_PRESENT) == 0)
1106 		pr_warn("No EEPROM, relying on command line....\n");
1107 	else if (get_eeprom_data(dev, START_EEPROM_DATA, CHKSUM_LEN, eeprom_buff) < 0) {
1108 		pr_warn("EEPROM read failed, relying on command line\n");
1109 	} else if (get_eeprom_cksum(START_EEPROM_DATA, CHKSUM_LEN, eeprom_buff) < 0) {
1110 		/* Check if the chip was able to read its own configuration starting
1111 		   at 0 in the EEPROM*/
1112 		if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) !=
1113 		    (EEPROM_OK | EEPROM_PRESENT))
1114 			pr_warn("Extended EEPROM checksum bad and no Cirrus EEPROM, relying on command line\n");
1115 
1116 	} else {
1117 		/* This reads an extended EEPROM that is not documented
1118 		 * in the CS8900 datasheet.
1119 		 */
1120 
1121 		/* get transmission control word  but keep the autonegotiation bits */
1122 		if (!lp->auto_neg_cnf)
1123 			lp->auto_neg_cnf = eeprom_buff[AUTO_NEG_CNF_OFFSET / 2];
1124 		/* Store adapter configuration */
1125 		if (!lp->adapter_cnf)
1126 			lp->adapter_cnf = eeprom_buff[ADAPTER_CNF_OFFSET / 2];
1127 		/* Store ISA configuration */
1128 		lp->isa_config = eeprom_buff[ISA_CNF_OFFSET / 2];
1129 		dev->mem_start = eeprom_buff[PACKET_PAGE_OFFSET / 2] << 8;
1130 
1131 		/* eeprom_buff has 32-bit ints, so we can't just memcpy it */
1132 		/* store the initial memory base address */
1133 		for (i = 0; i < ETH_ALEN / 2; i++) {
1134 			addr[i * 2] = eeprom_buff[i];
1135 			addr[i * 2 + 1] = eeprom_buff[i] >> 8;
1136 		}
1137 		eth_hw_addr_set(dev, addr);
1138 		cs89_dbg(1, debug, "%s: new adapter_cnf: 0x%x\n",
1139 			 dev->name, lp->adapter_cnf);
1140 	}
1141 
1142 	/* allow them to force multiple transceivers.  If they force multiple, autosense */
1143 	{
1144 		int count = 0;
1145 		if (lp->force & FORCE_RJ45) {
1146 			lp->adapter_cnf |= A_CNF_10B_T;
1147 			count++;
1148 		}
1149 		if (lp->force & FORCE_AUI) {
1150 			lp->adapter_cnf |= A_CNF_AUI;
1151 			count++;
1152 		}
1153 		if (lp->force & FORCE_BNC) {
1154 			lp->adapter_cnf |= A_CNF_10B_2;
1155 			count++;
1156 		}
1157 		if (count > 1)
1158 			lp->adapter_cnf |= A_CNF_MEDIA_AUTO;
1159 		else if (lp->force & FORCE_RJ45)
1160 			lp->adapter_cnf |= A_CNF_MEDIA_10B_T;
1161 		else if (lp->force & FORCE_AUI)
1162 			lp->adapter_cnf |= A_CNF_MEDIA_AUI;
1163 		else if (lp->force & FORCE_BNC)
1164 			lp->adapter_cnf |= A_CNF_MEDIA_10B_2;
1165 	}
1166 
1167 	cs89_dbg(1, debug, "%s: after force 0x%x, adapter_cnf=0x%x\n",
1168 		 dev->name, lp->force, lp->adapter_cnf);
1169 
1170 	/* FIXME: We don't let you set dc-dc polarity or low RX squelch from the command line: add it here */
1171 
1172 	/* FIXME: We don't let you set the IMM bit from the command line: add it to lp->auto_neg_cnf here */
1173 
1174 	/* FIXME: we don't set the Ethernet address on the command line.  Use
1175 	 * ifconfig IFACE hw ether AABBCCDDEEFF
1176 	 */
1177 
1178 	pr_info("media %s%s%s",
1179 		(lp->adapter_cnf & A_CNF_10B_T) ? "RJ-45," : "",
1180 		(lp->adapter_cnf & A_CNF_AUI) ? "AUI," : "",
1181 		(lp->adapter_cnf & A_CNF_10B_2) ? "BNC," : "");
1182 
1183 	lp->irq_map = 0xffff;
1184 
1185 	/* If this is a CS8900 then no pnp soft */
1186 	if (lp->chip_type != CS8900 &&
1187 	    /* Check if the ISA IRQ has been set  */
1188 	    (i = readreg(dev, PP_CS8920_ISAINT) & 0xff,
1189 	     (i != 0 && i < CS8920_NO_INTS))) {
1190 		if (!dev->irq)
1191 			dev->irq = i;
1192 	} else {
1193 		i = lp->isa_config & INT_NO_MASK;
1194 		if (!dev->irq)
1195 			dev->irq = i;
1196 	}
1197 
1198 	pr_cont(" IRQ %d", dev->irq);
1199 	pr_cont(", programmed I/O");
1200 
1201 	/* print the ethernet address. */
1202 	pr_cont(", MAC %pM\n", dev->dev_addr);
1203 
1204 	dev->netdev_ops	= &net_ops;
1205 	dev->watchdog_timeo = HZ;
1206 
1207 	cs89_dbg(0, info, "cs89x0_probe1() successful\n");
1208 
1209 	retval = register_netdev(dev);
1210 	if (retval)
1211 		goto out2;
1212 	return 0;
1213 out2:
1214 	iowrite16(PP_ChipID, lp->virt_addr + ADD_PORT);
1215 out1:
1216 	return retval;
1217 }
1218 
1219 static int __init cs89x0_platform_probe(struct platform_device *pdev)
1220 {
1221 	struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
1222 	void __iomem *virt_addr;
1223 	int err;
1224 
1225 	if (!dev)
1226 		return -ENOMEM;
1227 
1228 	dev->irq = platform_get_irq(pdev, 0);
1229 	if (dev->irq < 0) {
1230 		err = dev->irq;
1231 		goto free;
1232 	}
1233 
1234 	virt_addr = devm_platform_ioremap_resource(pdev, 0);
1235 	if (IS_ERR(virt_addr)) {
1236 		err = PTR_ERR(virt_addr);
1237 		goto free;
1238 	}
1239 
1240 	err = cs89x0_probe1(dev, virt_addr, 0);
1241 	if (err) {
1242 		dev_warn(&dev->dev, "no cs8900 or cs8920 detected\n");
1243 		goto free;
1244 	}
1245 
1246 	platform_set_drvdata(pdev, dev);
1247 	return 0;
1248 
1249 free:
1250 	free_netdev(dev);
1251 	return err;
1252 }
1253 
1254 static void cs89x0_platform_remove(struct platform_device *pdev)
1255 {
1256 	struct net_device *dev = platform_get_drvdata(pdev);
1257 
1258 	/* This platform_get_resource() call will not return NULL, because
1259 	 * the same call in cs89x0_platform_probe() has returned a non NULL
1260 	 * value.
1261 	 */
1262 	unregister_netdev(dev);
1263 	free_netdev(dev);
1264 }
1265 
1266 static const struct of_device_id __maybe_unused cs89x0_match[] = {
1267 	{ .compatible = "cirrus,cs8900", },
1268 	{ .compatible = "cirrus,cs8920", },
1269 	{ },
1270 };
1271 MODULE_DEVICE_TABLE(of, cs89x0_match);
1272 
1273 static struct platform_driver cs89x0_driver = {
1274 	.driver	= {
1275 		.name		= DRV_NAME,
1276 		.of_match_table	= of_match_ptr(cs89x0_match),
1277 	},
1278 	.remove = cs89x0_platform_remove,
1279 };
1280 
1281 module_platform_driver_probe(cs89x0_driver, cs89x0_platform_probe);
1282 
1283 MODULE_LICENSE("GPL");
1284 MODULE_DESCRIPTION("Crystal Semiconductor (Now Cirrus Logic) CS89[02]0 network driver");
1285 MODULE_AUTHOR("Russell Nelson <nelson@crynwr.com>");
1286