浏览代码

Updated to general ISA bus API.

tags/v0.9.3
Michael Brown 19 年前
父节点
当前提交
8165c14e71
共有 1 个文件被更改,包括 108 次插入122 次删除
  1. 108
    122
      src/drivers/net/eepro.c

+ 108
- 122
src/drivers/net/eepro.c 查看文件

@@ -33,8 +33,6 @@ has 34 pins, the top row of 2 are not used.
33 33
 /* we use timer2 for microsecond waits */
34 34
 #include "timer.h"
35 35
 
36
-#undef	DEBUG		/* only after include files */
37
-
38 36
 /* Different 82595 chips */
39 37
 #define LAN595		0
40 38
 #define LAN595TX	1
@@ -287,7 +285,6 @@ static unsigned int	rx_start, tx_start;
287 285
 static int		tx_last;
288 286
 static unsigned	int	tx_end;
289 287
 static int		eepro = 0;
290
-static unsigned short	ioaddr = 0;
291 288
 static unsigned int	mem_start, mem_end = RCV_DEFAULT_RAM / 1024;
292 289
 
293 290
 /**************************************************************************
@@ -298,42 +295,40 @@ static void eepro_reset(struct nic *nic)
298 295
 	int		temp_reg, i;
299 296
 
300 297
 	/* put the card in its initial state */
301
-	eepro_sw2bank2(ioaddr);	/* be careful, bank2 now */
302
-	temp_reg = inb(ioaddr + eeprom_reg);
303
-#ifdef	DEBUG
304
-	printf("Stepping %d\n", temp_reg >> 5);
305
-#endif
298
+	eepro_sw2bank2(nic->ioaddr);	/* be careful, bank2 now */
299
+	temp_reg = inb(nic->ioaddr + eeprom_reg);
300
+	DBG("Stepping %d\n", temp_reg >> 5);
306 301
 	if (temp_reg & 0x10)	/* check the TurnOff Enable bit */
307
-		outb(temp_reg & 0xEF, ioaddr + eeprom_reg);
302
+		outb(temp_reg & 0xEF, nic->ioaddr + eeprom_reg);
308 303
 	for (i = 0; i < ETH_ALEN; i++)	/* fill the MAC address */
309
-		outb(nic->node_addr[i], ioaddr + I_ADD_REG0 + i);
310
-	temp_reg = inb(ioaddr + REG1);
304
+		outb(nic->node_addr[i], nic->ioaddr + I_ADD_REG0 + i);
305
+	temp_reg = inb(nic->ioaddr + REG1);
311 306
 	/* setup Transmit Chaining and discard bad RCV frames */
312 307
 	outb(temp_reg | XMT_Chain_Int | XMT_Chain_ErrStop
313
-		| RCV_Discard_BadFrame, ioaddr + REG1);
314
-	temp_reg = inb(ioaddr + REG2);		/* match broadcast */
315
-	outb(temp_reg | 0x14, ioaddr + REG2);
316
-	temp_reg = inb(ioaddr + REG3);
317
-	outb(temp_reg & 0x3F, ioaddr + REG3);	/* clear test mode */
308
+		| RCV_Discard_BadFrame, nic->ioaddr + REG1);
309
+	temp_reg = inb(nic->ioaddr + REG2);		/* match broadcast */
310
+	outb(temp_reg | 0x14, nic->ioaddr + REG2);
311
+	temp_reg = inb(nic->ioaddr + REG3);
312
+	outb(temp_reg & 0x3F, nic->ioaddr + REG3);	/* clear test mode */
318 313
 	/* set the receiving mode */
319
-	eepro_sw2bank1(ioaddr);	/* be careful, bank1 now */
314
+	eepro_sw2bank1(nic->ioaddr);	/* be careful, bank1 now */
320 315
 	/* initialise the RCV and XMT upper and lower limits */
321
-	outb(RCV_LOWER_LIMIT, ioaddr + RCV_LOWER_LIMIT_REG);
322
-	outb(RCV_UPPER_LIMIT, ioaddr + RCV_UPPER_LIMIT_REG);
323
-	outb(XMT_LOWER_LIMIT, ioaddr + xmt_lower_limit_reg);
324
-	outb(XMT_UPPER_LIMIT, ioaddr + xmt_upper_limit_reg);
325
-	eepro_sw2bank0(ioaddr);	/* Switch back to bank 0 */
326
-	eepro_clear_int(ioaddr);
316
+	outb(RCV_LOWER_LIMIT, nic->ioaddr + RCV_LOWER_LIMIT_REG);
317
+	outb(RCV_UPPER_LIMIT, nic->ioaddr + RCV_UPPER_LIMIT_REG);
318
+	outb(XMT_LOWER_LIMIT, nic->ioaddr + xmt_lower_limit_reg);
319
+	outb(XMT_UPPER_LIMIT, nic->ioaddr + xmt_upper_limit_reg);
320
+	eepro_sw2bank0(nic->ioaddr);	/* Switch back to bank 0 */
321
+	eepro_clear_int(nic->ioaddr);
327 322
 	/* Initialise RCV */
328 323
 	rx_start = (unsigned int)bus_to_virt(RCV_LOWER_LIMIT << 8);
329
-	outw(RCV_LOWER_LIMIT << 8, ioaddr + RCV_BAR);
330
-	outw(((RCV_UPPER_LIMIT << 8) | 0xFE), ioaddr + RCV_STOP);
324
+	outw(RCV_LOWER_LIMIT << 8, nic->ioaddr + RCV_BAR);
325
+	outw(((RCV_UPPER_LIMIT << 8) | 0xFE), nic->ioaddr + RCV_STOP);
331 326
 	/* Intialise XMT */
332
-	outw((XMT_LOWER_LIMIT << 8), ioaddr + xmt_bar);
333
-	eepro_sel_reset(ioaddr);
327
+	outw((XMT_LOWER_LIMIT << 8), nic->ioaddr + xmt_bar);
328
+	eepro_sel_reset(nic->ioaddr);
334 329
 	tx_start = tx_end = (unsigned int)bus_to_virt(XMT_LOWER_LIMIT << 8);
335 330
 	tx_last = 0;
336
-	eepro_en_rx(ioaddr);
331
+	eepro_en_rx(nic->ioaddr);
337 332
 }
338 333
 
339 334
 /**************************************************************************
@@ -348,12 +343,12 @@ static int eepro_poll(struct nic *nic, int retrieve)
348 343
 	/* nic->packet should contain data on return */
349 344
 	/* nic->packetlen should contain length of data */
350 345
 #if	0
351
-	if ((inb(ioaddr + STATUS_REG) & 0x40) == 0)
346
+	if ((inb(nic->ioaddr + STATUS_REG) & 0x40) == 0)
352 347
 		return (0);
353
-	outb(0x40, ioaddr + STATUS_REG);
348
+	outb(0x40, nic->ioaddr + STATUS_REG);
354 349
 #endif
355
-	outw(rcv_car, ioaddr + HOST_ADDRESS_REG);
356
-	rcv_event = inw(ioaddr + IO_PORT);
350
+	outw(rcv_car, nic->ioaddr + HOST_ADDRESS_REG);
351
+	rcv_event = inw(nic->ioaddr + IO_PORT);
357 352
 	if (rcv_event != RCV_DONE)
358 353
 		return (0);
359 354
 
@@ -362,19 +357,19 @@ static int eepro_poll(struct nic *nic, int retrieve)
362 357
 	   maybe there's another way. */
363 358
 	if ( ! retrieve ) return 1;
364 359
 
365
-	rcv_status = inw(ioaddr + IO_PORT);
366
-	rcv_next_frame = inw(ioaddr + IO_PORT);
367
-	rcv_size = inw(ioaddr + IO_PORT);
360
+	rcv_status = inw(nic->ioaddr + IO_PORT);
361
+	rcv_next_frame = inw(nic->ioaddr + IO_PORT);
362
+	rcv_size = inw(nic->ioaddr + IO_PORT);
368 363
 #if	0
369 364
 	printf("%hX %hX %d %hhX\n", rcv_status, rcv_next_frame, rcv_size,
370
-		inb(ioaddr + STATUS_REG));
365
+		inb(nic->ioaddr + STATUS_REG));
371 366
 #endif
372 367
 	if ((rcv_status & (RX_OK|RX_ERROR)) != RX_OK) {
373 368
 		printf("Receive error %hX\n", rcv_status);
374 369
 		return (0);
375 370
 	}
376 371
 	rcv_size &= 0x3FFF;
377
-	insw(ioaddr + IO_PORT, nic->packet, ((rcv_size + 3) >> 1));
372
+	insw(nic->ioaddr + IO_PORT, nic->packet, ((rcv_size + 3) >> 1));
378 373
 #if	0
379 374
 {
380 375
 	int i;
@@ -389,7 +384,7 @@ static int eepro_poll(struct nic *nic, int retrieve)
389 384
 	rx_start = (unsigned int)bus_to_virt(rcv_next_frame << 8);
390 385
 	if (rcv_car == 0)
391 386
 		rcv_car = ((RCV_UPPER_LIMIT << 8) | 0xff);
392
-	outw(rcv_car - 1, ioaddr + RCV_STOP);
387
+	outw(rcv_car - 1, nic->ioaddr + RCV_STOP);
393 388
 	return (1);
394 389
 }
395 390
 
@@ -420,20 +415,20 @@ static void eepro_transmit(
420 415
 		last = (XMT_LOWER_LIMIT << 8);
421 416
 		end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
422 417
 	}
423
-	outw(last, ioaddr + HOST_ADDRESS_REG);
424
-	outw(XMT_CMD, ioaddr + IO_PORT);
425
-	outw(0, ioaddr + IO_PORT);
426
-	outw(end, ioaddr + IO_PORT);
427
-	outw(length, ioaddr + IO_PORT);
428
-	outsw(ioaddr + IO_PORT, d, ETH_ALEN / 2);
429
-	outsw(ioaddr + IO_PORT, nic->node_addr, ETH_ALEN / 2);
418
+	outw(last, nic->ioaddr + HOST_ADDRESS_REG);
419
+	outw(XMT_CMD, nic->ioaddr + IO_PORT);
420
+	outw(0, nic->ioaddr + IO_PORT);
421
+	outw(end, nic->ioaddr + IO_PORT);
422
+	outw(length, nic->ioaddr + IO_PORT);
423
+	outsw(nic->ioaddr + IO_PORT, d, ETH_ALEN / 2);
424
+	outsw(nic->ioaddr + IO_PORT, nic->node_addr, ETH_ALEN / 2);
430 425
 	type = htons(t);
431
-	outsw(ioaddr + IO_PORT, &type, sizeof(type) / 2);
432
-	outsw(ioaddr + IO_PORT, p, (s + 3) >> 1);
426
+	outsw(nic->ioaddr + IO_PORT, &type, sizeof(type) / 2);
427
+	outsw(nic->ioaddr + IO_PORT, p, (s + 3) >> 1);
433 428
 	/* A dummy read to flush the DRAM write pipeline */
434
-	status = inw(ioaddr + IO_PORT);
435
-	outw(last, ioaddr + xmt_bar);
436
-	outb(XMT_CMD, ioaddr);
429
+	status = inw(nic->ioaddr + IO_PORT);
430
+	outw(last, nic->ioaddr + xmt_bar);
431
+	outb(XMT_CMD, nic->ioaddr);
437 432
 	tx_start = last;
438 433
 	tx_last = last;
439 434
 	tx_end = end;
@@ -441,29 +436,28 @@ static void eepro_transmit(
441 436
 	printf("%d %d\n", tx_start, tx_end);
442 437
 #endif
443 438
 	while (boguscount > 0) {
444
-		if (((status = inw(ioaddr + IO_PORT)) & TX_DONE_BIT) == 0) {
439
+		if (((status = inw(nic->ioaddr + IO_PORT)) & TX_DONE_BIT) == 0) {
445 440
 			udelay(40);
446 441
 			boguscount--;
447 442
 			continue;
448 443
 		}
449
-#if	DEBUG
450
-		if ((status & 0x2000) == 0)
451
-			printf("Transmit status %hX\n", status);
452
-#endif
444
+		if ((status & 0x2000) == 0) {
445
+			DBG("Transmit status %hX\n", status);
446
+		}
453 447
 	}
454 448
 }
455 449
 
456 450
 /**************************************************************************
457 451
 DISABLE - Turn off ethernet interface
458 452
 ***************************************************************************/
459
-static void eepro_disable ( struct nic *nic __unused ) {
460
-	eepro_sw2bank0(ioaddr);	/* Switch to bank 0 */
453
+static void eepro_disable ( struct nic *nic ) {
454
+	eepro_sw2bank0(nic->ioaddr);	/* Switch to bank 0 */
461 455
 	/* Flush the Tx and disable Rx */
462
-	outb(STOP_RCV_CMD, ioaddr);
456
+	outb(STOP_RCV_CMD, nic->ioaddr);
463 457
 	tx_start = tx_end = (unsigned int) (bus_to_virt(XMT_LOWER_LIMIT << 8));
464 458
 	tx_last = 0;
465 459
 	/* Reset the 82595 */
466
-	eepro_full_reset(ioaddr);
460
+	eepro_full_reset(nic->ioaddr);
467 461
 }
468 462
 
469 463
 /**************************************************************************
@@ -481,7 +475,7 @@ static void eepro_irq(struct nic *nic __unused, irq_action_t action __unused)
481 475
   }
482 476
 }
483 477
 
484
-static int read_eeprom(int location)
478
+static int read_eeprom(uint16_t ioaddr, int location)
485 479
 {
486 480
 	int		i;
487 481
 	unsigned short	retval = 0;
@@ -522,14 +516,8 @@ static int read_eeprom(int location)
522 516
 	return (retval);
523 517
 }
524 518
 
525
-static int eepro_probe1(struct nic *nic)
526
-{
527
-	int		i, id, counter, l_eepro = 0;
528
-	union {
529
-		unsigned char	caddr[ETH_ALEN];
530
-		unsigned short	saddr[ETH_ALEN/2];
531
-	} station_addr;
532
-	char		*name;
519
+static int eepro_probe1 ( uint16_t ioaddr ) {
520
+	int		id, counter;
533 521
 
534 522
 	id = inb(ioaddr + ID_REG);
535 523
 	if ((id & ID_REG_MASK) != ID_REG_SIG)
@@ -538,29 +526,55 @@ static int eepro_probe1(struct nic *nic)
538 526
 	if (((id = inb(ioaddr + ID_REG)) & R_ROBIN_BITS) != (counter + 0x40))
539 527
 		return (0);
540 528
 	/* yes the 82595 has been found */
541
-	station_addr.saddr[2] = read_eeprom(2);
542
-	if (station_addr.saddr[2] == 0x0000 || station_addr.saddr[2] == 0xFFFF) {
529
+	return (1);
530
+}
531
+
532
+static struct nic_operations eepro_operations = {
533
+	.connect	= dummy_connect,
534
+	.poll		= eepro_poll,
535
+	.transmit	= eepro_transmit,
536
+	.irq		= eepro_irq,
537
+	.disable	= eepro_disable,
538
+};
539
+
540
+/**************************************************************************
541
+PROBE - Look for an adapter, this routine's visible to the outside
542
+***************************************************************************/
543
+static int eepro_probe ( struct dev *dev, struct isa_device *isa ) {
544
+	struct nic *nic = nic_device ( dev );
545
+	int		i, l_eepro = 0;
546
+	union {
547
+		unsigned char	caddr[ETH_ALEN];
548
+		unsigned short	saddr[ETH_ALEN/2];
549
+	} station_addr;
550
+
551
+	nic->irqno  = 0;
552
+	nic->ioaddr = isa->ioaddr;
553
+
554
+	station_addr.saddr[2] = read_eeprom(nic->ioaddr,2);
555
+	if ( ( station_addr.saddr[2] == 0x0000 ) ||
556
+	     ( station_addr.saddr[2] == 0xFFFF ) ) {
543 557
 		l_eepro = 3;
544 558
 		eepro = LAN595FX_10ISA;
545 559
 		eeprom_reg= EEPROM_REG_10;
546 560
 		rcv_start = RCV_START_10;
547 561
 		xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_10;
548 562
 		xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_10;
549
-		station_addr.saddr[2] = read_eeprom(2);
563
+		station_addr.saddr[2] = read_eeprom(nic->ioaddr,2);
550 564
 	}
551
-	station_addr.saddr[1] = read_eeprom(3);
552
-	station_addr.saddr[0] = read_eeprom(4);
565
+	station_addr.saddr[1] = read_eeprom(nic->ioaddr,3);
566
+	station_addr.saddr[0] = read_eeprom(nic->ioaddr,4);
553 567
 	if (l_eepro)
554
-		name = "Intel EtherExpress 10 ISA";
555
-	else if (read_eeprom(7) == ee_FX_INT2IRQ) {
556
-		name = "Intel EtherExpress Pro/10+ ISA";
568
+		dev->name = "Intel EtherExpress 10 ISA";
569
+	else if (read_eeprom(nic->ioaddr,7) == ee_FX_INT2IRQ) {
570
+		dev->name = "Intel EtherExpress Pro/10+ ISA";
557 571
 		l_eepro = 2;
558 572
 	} else if (station_addr.saddr[0] == SA_ADDR1) {
559
-		name = "Intel EtherExpress Pro/10 ISA";
573
+		dev->name = "Intel EtherExpress Pro/10 ISA";
560 574
 		l_eepro = 1;
561 575
 	} else {
562 576
 		l_eepro = 0;
563
-		name = "Intel 82595-based LAN card";
577
+		dev->name = "Intel 82595-based LAN card";
564 578
 	}
565 579
 	station_addr.saddr[0] = swap16(station_addr.saddr[0]);
566 580
 	station_addr.saddr[1] = swap16(station_addr.saddr[1]);
@@ -568,7 +582,7 @@ static int eepro_probe1(struct nic *nic)
568 582
 	for (i = 0; i < ETH_ALEN; i++) {
569 583
 		nic->node_addr[i] = station_addr.caddr[i];
570 584
 	}
571
-	printf("\n%s ioaddr %#hX, addr %!", name, ioaddr, nic->node_addr);
585
+	DBG("%s ioaddr %#hX, addr %!", dev->name, nic->ioaddr, nic->node_addr);
572 586
 	mem_start = RCV_LOWER_LIMIT << 8;
573 587
 	if ((mem_end & 0x3F) < 3 || (mem_end & 0x3F) > 29)
574 588
 		mem_end = RCV_UPPER_LIMIT << 8;
@@ -577,53 +591,25 @@ static int eepro_probe1(struct nic *nic)
577 591
 		rcv_ram = mem_end - (RCV_LOWER_LIMIT << 8);
578 592
 	}
579 593
 	printf(", Rx mem %dK, if %s\n", (mem_end - mem_start) >> 10,
580
-		GetBit(read_eeprom(5), ee_BNC_TPE) ? "BNC" : "TP");
581
-	return (1);
582
-}
583
-
584
-/**************************************************************************
585
-PROBE - Look for an adapter, this routine's visible to the outside
586
-***************************************************************************/
587
-static int eepro_probe(struct dev *dev, unsigned short *probe_addrs)
588
-{
589
-	struct nic *nic = (struct nic *)dev;
590
-	unsigned short		*p;
591
-	/* same probe list as the Linux driver */
592
-	static unsigned short	ioaddrs[] = {
593
-		0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360, 0};
594
-
595
-	if (probe_addrs == 0 || probe_addrs[0] == 0)
596
-		probe_addrs = ioaddrs;
597
-	for (p = probe_addrs; (ioaddr = *p) != 0; p++) {
598
-		if (eepro_probe1(nic))
599
-			break;
600
-	}
601
-	if (*p == 0)
602
-		return (0);
603
-
604
-	nic->irqno  = 0;
605
-	nic->ioaddr = *p;
594
+		GetBit(read_eeprom(nic->ioaddr,5), ee_BNC_TPE) ? "BNC" : "TP");
606 595
 
607 596
 	eepro_reset(nic);
597
+
608 598
 	/* point to NIC specific routines */
609
-static struct nic_operations eepro_operations;
610
-static struct nic_operations eepro_operations = {
611
-	.connect	= dummy_connect,
612
-	.poll		= eepro_poll,
613
-	.transmit	= eepro_transmit,
614
-	.irq		= eepro_irq,
615
-	.disable	= eepro_disable,
616
-};	nic->nic_op	= &eepro_operations;
617
-	/* Based on PnP ISA map */
618
-	dev->devid.vendor_id = htons(GENERIC_ISAPNP_VENDOR);
619
-	dev->devid.device_id = htons(0x828a);
599
+	nic->nic_op	= &eepro_operations;
620 600
 	return 1;
621 601
 }
622 602
 
623
-static struct isa_driver eepro_driver __isa_driver = {
624
-	.type    = NIC_DRIVER,
625
-	.name    = "EEPRO",
626
-	.probe   = eepro_probe,
627
-	.ioaddrs = 0,
603
+static struct isa_probe_addr eepro_probe_addrs[] = {
604
+	{ 0x300 },
605
+	{ 0x210 }, { 0x240 }, { 0x280 }, { 0x2C0 }, { 0x200 },
606
+	{ 0x320 }, { 0x340 }, { 0x360 },
628 607
 };
629
-ISA_ROM("eepro","Intel Etherexpress Pro/10");
608
+
609
+static struct isa_driver eepro_driver =
610
+	ISA_DRIVER ( "eepro", eepro_probe_addrs, eepro_probe1,
611
+		     GENERIC_ISAPNP_VENDOR, 0x828a );
612
+
613
+BOOT_DRIVER ( "eepro", find_isa_boot_device, eepro_driver, eepro_probe );
614
+
615
+ISA_ROM ( "eepro", "Intel Etherexpress Pro/10" );

正在加载...
取消
保存