2 * 3c90x.c -- This file implements a gPXE API 3c90x driver
4 * Originally written for etherboot by:
5 * Greg Beeley, Greg.Beeley@LightSys.org
6 * Modified by Steve Smith,
7 * Steve.Smith@Juno.Com. Alignment bug fix Neil Newell (nn@icenoir.net).
8 * Almost totally Rewritten to use gPXE API, implementation of tx/rx ring support
9 * by Thomas Miletich, thomas.miletich@gmail.com
10 * Thanks to Marty Connor and Stefan Hajnoczi for their help and feedback,
11 * and to Daniel Verkamp for his help with testing.
13 * Copyright (c) 2009 Thomas Miletich
15 * Copyright (c) 1999 LightSys Technology Services, Inc.
16 * Portions Copyright (c) 1999 Steve Smith
18 * This program may be re-distributed in source or binary form, modified,
19 * sold, or copied for any purpose, provided that the above copyright message
20 * and this text are included with all source copies or derivative works, and
21 * provided that the above copyright message and this text are included in the
22 * documentation of any binary-only distributions. This program is distributed
23 * WITHOUT ANY WARRANTY, without even the warranty of FITNESS FOR A PARTICULAR
24 * PURPOSE or MERCHANTABILITY. Please read the associated documentation
25 * "3c90x.txt" before compiling and using this driver.
27 * [ --mdc 20090313 The 3c90x.txt file is now at:
28 * http://etherboot.org/wiki/appnotes/3c90x_issues ]
30 * This program was written with the assistance of the 3com documentation for
31 * the 3c905B-TX card, as well as with some assistance from the 3c59x
32 * driver Donald Becker wrote for the Linux kernel, and with some assistance
33 * from the remainder of the Etherboot distribution.
35 * Indented with unix 'indent' command:
36 * $ indent -kr -i8 3c90x.c
48 #include <gpxe/ethernet.h>
49 #include <gpxe/if_ether.h>
51 #include <gpxe/iobuf.h>
52 #include <gpxe/malloc.h>
53 #include <gpxe/netdevice.h>
55 #include <gpxe/timer.h>
61 * a3c90x_internal_IssueCommand: sends a command to the 3c90x card
62 * and waits for it's completion
64 * @v ioaddr IOAddress of the NIC
65 * @v cmd Command to be issued
66 * @v param Command parameter
68 static void a3c90x_internal_IssueCommand(int ioaddr, int cmd, int param)
70 unsigned int val = (cmd << 11) | param;
73 DBGP("a3c90x_internal_IssueCommand\n");
75 /* Send the cmd to the cmd register */
76 outw(val, ioaddr + regCommandIntStatus_w);
78 /* Wait for the cmd to complete */
79 for (cnt = 0; cnt < 100000; cnt++) {
80 if (inw(ioaddr + regCommandIntStatus_w) & INT_CMDINPROGRESS) {
83 DBG2("Command 0x%04X finished in time. cnt = %d.\n", cmd, cnt);
88 DBG("Command 0x%04X DID NOT finish in time. cnt = %d.\n", cmd, cnt);
92 * a3c90x_internal_SetWindow: selects a register window set.
94 * @v inf_3c90x private NIC data
95 * @v window window to be selected
97 static void a3c90x_internal_SetWindow(struct INF_3C90X *inf_3c90x, int window)
99 DBGP("a3c90x_internal_SetWindow\n");
100 /* Window already as set? */
101 if (inf_3c90x->CurrentWindow == window)
104 /* Issue the window command. */
105 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr,
106 cmdSelectRegisterWindow, window);
107 inf_3c90x->CurrentWindow = window;
112 static void a3c90x_internal_WaitForEeprom(struct INF_3C90X *inf_3c90x)
116 DBGP("a3c90x_internal_WaitForEeprom\n");
118 while (eepromBusy & inw(inf_3c90x->IOAddr + regEepromCommand_0_w)) {
119 if (cnt == EEPROM_TIMEOUT) {
120 DBG("Read from eeprom failed: timeout\n");
129 * a3c90x_internal_ReadEeprom - nvs routine to read eeprom data
130 * We only support reading one word(2 byte). The nvs subsystem will make sure
131 * that the routine will never be called with len != 2.
134 * @v address eeprom address to read data from.
135 * @v data data is put here.
136 * @v len number of bytes to read.
139 a3c90x_internal_ReadEeprom(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
141 unsigned short *dest = (unsigned short *) data;
142 struct INF_3C90X *inf_3c90x =
143 container_of(nvs, struct INF_3C90X, nvs);
145 DBGP("a3c90x_internal_ReadEeprom\n");
147 /* we support reading 2 bytes only */
150 /* Select correct window */
151 a3c90x_internal_SetWindow(inf_3c90x, winEepromBios0);
153 /* set eepromRead bits in command sent to NIC */
154 address += (inf_3c90x->is3c556 ? eepromRead_556 : eepromRead);
156 a3c90x_internal_WaitForEeprom(inf_3c90x);
157 /* send address to NIC */
158 outw(address, inf_3c90x->IOAddr + regEepromCommand_0_w);
159 a3c90x_internal_WaitForEeprom(inf_3c90x);
162 *dest = inw(inf_3c90x->IOAddr + regEepromData_0_w);
168 * a3c90x_internal_WriteEeprom - nvs routine to write eeprom data
169 * currently not implemented
172 * @v address eeprom address to read data from.
173 * @v data data is put here.
174 * @v len number of bytes to read.
177 a3c90x_internal_WriteEeprom(struct nvs_device *nvs __unused,
178 unsigned int address __unused,
179 const void *data __unused, size_t len __unused)
184 static void a3c90x_internal_ReadEepromContents(struct INF_3C90X *inf_3c90x)
186 int eeprom_size = (inf_3c90x->isBrev ? 0x20 : 0x17) * 2;
188 DBGP("a3c90x_internal_ReadEepromContents\n");
190 nvs_read(&inf_3c90x->nvs, 0, inf_3c90x->eeprom, eeprom_size);
194 * a3c90x_reset: exported function that resets the card to its default
195 * state. This is so the Linux driver can re-set the card up the way
196 * it wants to. If CFG_3C90X_PRESERVE_XCVR is defined, then the reset will
197 * not alter the selected transceiver that we used to download the boot
200 * @v inf_3c90x Private NIC data
202 static void a3c90x_reset(struct INF_3C90X *inf_3c90x)
204 DBGP("a3c90x_reset\n");
205 /* Send the reset command to the card */
206 DBG("3c90x: Issuing RESET\n");
207 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdGlobalReset, 0);
209 /* global reset command resets station mask, non-B revision cards
210 * require explicit reset of values
212 a3c90x_internal_SetWindow(inf_3c90x, winAddressing2);
213 outw(0, inf_3c90x->IOAddr + regStationMask_2_3w + 0);
214 outw(0, inf_3c90x->IOAddr + regStationMask_2_3w + 2);
215 outw(0, inf_3c90x->IOAddr + regStationMask_2_3w + 4);
217 /* Issue transmit reset, wait for command completion */
218 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdTxReset, 0);
220 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdTxEnable, 0);
223 * reset of the receiver on B-revision cards re-negotiates the link
224 * takes several seconds (a computer eternity)
226 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdRxReset,
227 inf_3c90x->isBrev ? 0x04 : 0x00);
229 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdRxEnable, 0);
231 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr,
232 cmdSetInterruptEnable, 0);
233 /* enable rxComplete and txComplete */
234 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr,
235 cmdSetIndicationEnable,
236 INT_TXCOMPLETE | INT_UPCOMPLETE);
237 /* acknowledge any pending status flags */
238 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr,
239 cmdAcknowledgeInterrupt, 0x661);
245 * a3c90x_setup_tx_ring - Allocates TX ring, initialize tx_desc values
247 * @v p Private NIC data
249 * @ret Returns 0 on success, negative on failure
251 static int a3c90x_setup_tx_ring(struct INF_3C90X *p)
253 DBGP("a3c90x_setup_tx_ring\n");
255 malloc_dma(TX_RING_SIZE * sizeof(struct TXD), TX_RING_ALIGN);
258 DBG("Could not allocate TX-ring\n");
262 memset(p->tx_ring, 0, TX_RING_SIZE * sizeof(struct TXD));
271 * a3c90x_process_tx_packets - Checks for successfully sent packets,
272 * reports them to gPXE with netdev_tx_complete();
274 * @v netdev Network device info
276 static void a3c90x_process_tx_packets(struct net_device *netdev)
278 struct INF_3C90X *p = netdev_priv(netdev);
279 unsigned int downlist_ptr;
281 DBGP("a3c90x_process_tx_packets\n");
283 DBG(" tx_cnt: %d\n", p->tx_cnt);
285 while (p->tx_tail != p->tx_cur) {
287 downlist_ptr = inl(p->IOAddr + regDnListPtr_l);
289 DBG(" downlist_ptr: %#08x\n", downlist_ptr);
290 DBG(" tx_tail: %d tx_cur: %d\n", p->tx_tail, p->tx_cur);
292 /* NIC is currently working on this tx desc */
293 if(downlist_ptr == virt_to_bus(p->tx_ring + p->tx_tail))
296 netdev_tx_complete(netdev, p->tx_iobuf[p->tx_tail]);
298 DBG("transmitted packet\n");
299 DBG(" size: %d\n", iob_len(p->tx_iobuf[p->tx_tail]));
301 p->tx_tail = (p->tx_tail + 1) % TX_RING_SIZE;
306 static void a3c90x_free_tx_ring(struct INF_3C90X *p)
308 DBGP("a3c90x_free_tx_ring\n");
310 free_dma(p->tx_ring, TX_RING_SIZE * sizeof(struct TXD));
312 /* io_buffers are free()ed by netdev_tx_complete[,_err]() */
316 * a3c90x_transmit - Transmits a packet.
318 * @v netdev Network device info
319 * @v iob io_buffer containing the data to be send
321 * @ret Returns 0 on success, negative on failure
323 static int a3c90x_transmit(struct net_device *netdev,
324 struct io_buffer *iob)
326 struct INF_3C90X *inf_3c90x = netdev_priv(netdev);
327 struct TXD *tx_cur_desc;
328 struct TXD *tx_prev_desc;
331 unsigned int downlist_ptr;
333 DBGP("a3c90x_transmit\n");
335 if (inf_3c90x->tx_cnt == TX_RING_SIZE) {
336 DBG("TX-Ring overflow\n");
340 inf_3c90x->tx_iobuf[inf_3c90x->tx_cur] = iob;
341 tx_cur_desc = inf_3c90x->tx_ring + inf_3c90x->tx_cur;
343 tx_prev_desc = inf_3c90x->tx_ring +
344 (((inf_3c90x->tx_cur + TX_RING_SIZE) - 1) % TX_RING_SIZE);
348 /* Setup the DPD (download descriptor) */
349 tx_cur_desc->DnNextPtr = 0;
351 /* FrameStartHeader differs in 90x and >= 90xB
352 * It contains length in 90x and a round up boundary and packet ID for
353 * 90xB and 90xC. We can leave this to 0 for 90xB and 90xC.
355 tx_cur_desc->FrameStartHeader =
356 fshTxIndicate | (inf_3c90x->isBrev ? 0x00 : len);
358 tx_cur_desc->DataAddr = virt_to_bus(iob->data);
359 tx_cur_desc->DataLength = len | downLastFrag;
361 /* We have to stall the download engine, so the NIC won't access the
362 * tx descriptor while we modify it. There is a way around this
363 * from revision B and upwards. To stay compatible with older revisions
364 * we don't use it here.
366 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdStallCtl,
369 tx_prev_desc->DnNextPtr = virt_to_bus(tx_cur_desc);
371 downlist_ptr = inl(inf_3c90x->IOAddr + regDnListPtr_l);
372 if (downlist_ptr == 0) {
373 /* currently no DownList, sending a new one */
374 outl(virt_to_bus(tx_cur_desc),
375 inf_3c90x->IOAddr + regDnListPtr_l);
379 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdStallCtl,
382 inf_3c90x->tx_cur = (inf_3c90x->tx_cur + 1) % TX_RING_SIZE;
389 * a3c90x_prepare_rx_desc - fills the rx desc with initial data
391 * @v p NIC private data
392 * @v index Index for rx_iobuf and rx_ring array
395 static void a3c90x_prepare_rx_desc(struct INF_3C90X *p, unsigned int index)
397 DBGP("a3c90x_prepare_rx_desc\n");
398 DBG("Populating rx_desc %d\n", index);
400 /* We have to stall the upload engine, so the NIC won't access the
401 * rx descriptor while we modify it. There is a way around this
402 * from revision B and upwards. To stay compatible with older revisions
403 * we don't use it here.
405 a3c90x_internal_IssueCommand(p->IOAddr, cmdStallCtl, upStall);
407 p->rx_ring[index].DataAddr = virt_to_bus(p->rx_iobuf[index]->data);
408 p->rx_ring[index].DataLength = RX_BUF_SIZE | upLastFrag;
409 p->rx_ring[index].UpPktStatus = 0;
411 /* unstall upload engine */
412 a3c90x_internal_IssueCommand(p->IOAddr, cmdStallCtl, upUnStall);
416 * a3c90x_refill_rx_ring -checks every entry in the rx ring and reallocates
417 * them as necessary. Then it calls a3c90x_prepare_rx_desc to fill the rx desc
420 * @v p NIC private data
422 static void a3c90x_refill_rx_ring(struct INF_3C90X *p)
426 struct RXD *rx_cur_desc;
428 DBGP("a3c90x_refill_rx_ring\n");
430 for (i = 0; i < RX_RING_SIZE; i++) {
431 rx_cur_desc = p->rx_ring + i;
432 status = rx_cur_desc->UpPktStatus;
434 /* only refill used descriptor */
435 if (!(status & upComplete))
438 /* we still need to process this descriptor */
439 if (p->rx_iobuf[i] != NULL)
442 p->rx_iobuf[i] = alloc_iob(RX_BUF_SIZE);
443 if (p->rx_iobuf[i] == NULL) {
444 DBG("alloc_iob() failed\n");
448 a3c90x_prepare_rx_desc(p, i);
453 * a3c90x_setup_rx_ring - Allocates RX ring, initialize rx_desc values
455 * @v p Private NIC data
457 * @ret Returns 0 on success, negative on failure
459 static int a3c90x_setup_rx_ring(struct INF_3C90X *p)
463 DBGP("a3c90x_setup_rx_ring\n");
466 malloc_dma(RX_RING_SIZE * sizeof(struct RXD), RX_RING_ALIGN);
469 DBG("Could not allocate RX-ring\n");
475 for (i = 0; i < RX_RING_SIZE; i++) {
476 p->rx_ring[i].UpNextPtr =
477 virt_to_bus(p->rx_ring + (i + 1));
479 /* these are needed so refill_rx_ring initializes the ring */
480 p->rx_ring[i].UpPktStatus = upComplete;
481 p->rx_iobuf[i] = NULL;
485 p->rx_ring[i - 1].UpNextPtr = virt_to_bus(p->rx_ring);
487 a3c90x_refill_rx_ring(p);
492 static void a3c90x_free_rx_ring(struct INF_3C90X *p)
494 DBGP("a3c90x_free_rx_ring\n");
496 free_dma(p->rx_ring, RX_RING_SIZE * sizeof(struct RXD));
500 static void a3c90x_free_rx_iobuf(struct INF_3C90X *p)
504 DBGP("a3c90x_free_rx_iobuf\n");
506 for (i = 0; i < RX_RING_SIZE; i++) {
507 free_iob(p->rx_iobuf[i]);
508 p->rx_iobuf[i] = NULL;
513 * a3c90x_process_rx_packets - Checks for received packets,
514 * reports them to gPXE with netdev_rx() or netdev_rx_err() if there was an
515 * error while receiving the packet
517 * @v netdev Network device info
519 static void a3c90x_process_rx_packets(struct net_device *netdev)
522 unsigned int rx_status;
523 struct INF_3C90X *p = netdev_priv(netdev);
524 struct RXD *rx_cur_desc;
526 DBGP("a3c90x_process_rx_packets\n");
528 for (i = 0; i < RX_RING_SIZE; i++) {
529 rx_cur_desc = p->rx_ring + p->rx_cur;
530 rx_status = rx_cur_desc->UpPktStatus;
532 if (!(rx_status & upComplete) && !(rx_status & upError))
535 if (p->rx_iobuf[p->rx_cur] == NULL)
538 if (rx_status & upError) {
539 DBG("Corrupted packet received\n");
540 netdev_rx_err(netdev, p->rx_iobuf[p->rx_cur],
543 /* if we're here, we've got good packet */
546 packet_len = rx_status & 0x1FFF;
547 iob_put(p->rx_iobuf[p->rx_cur], packet_len);
549 DBG("received packet\n");
550 DBG(" size: %d\n", packet_len);
552 netdev_rx(netdev, p->rx_iobuf[p->rx_cur]);
555 p->rx_iobuf[p->rx_cur] = NULL; /* invalidate rx desc */
556 p->rx_cur = (p->rx_cur + 1) % RX_RING_SIZE;
558 a3c90x_refill_rx_ring(p);
563 * a3c90x_poll - Routine that gets called periodically.
564 * Here we hanle transmitted and received packets.
565 * We could also check the link status from time to time, which we
566 * currently don't do.
568 * @v netdev Network device info
570 static void a3c90x_poll(struct net_device *netdev)
572 struct INF_3C90X *p = netdev_priv(netdev);
573 uint16_t raw_status, int_status;
575 DBGP("a3c90x_poll\n");
577 raw_status = inw(p->IOAddr + regCommandIntStatus_w);
578 int_status = (raw_status & 0x0FFF);
580 if ( int_status == 0 )
583 a3c90x_internal_IssueCommand(p->IOAddr, cmdAcknowledgeInterrupt,
586 if (int_status & INT_TXCOMPLETE)
587 outb(0x00, p->IOAddr + regTxStatus_b);
589 DBG("poll: status = %#04x\n", raw_status);
591 a3c90x_process_tx_packets(netdev);
593 a3c90x_process_rx_packets(netdev);
598 static void a3c90x_free_resources(struct INF_3C90X *p)
600 DBGP("a3c90x_free_resources\n");
602 a3c90x_free_tx_ring(p);
603 a3c90x_free_rx_ring(p);
604 a3c90x_free_rx_iobuf(p);
608 * a3c90x_remove - Routine to remove the card. Unregisters
609 * the NIC from gPXE, disables RX/TX and resets the card.
611 * @v pci PCI device info
613 static void a3c90x_remove(struct pci_device *pci)
615 struct net_device *netdev = pci_get_drvdata(pci);
616 struct INF_3C90X *inf_3c90x = netdev_priv(netdev);
618 DBGP("a3c90x_remove\n");
620 unregister_netdev(netdev);
622 /* Disable the receiver and transmitter. */
623 outw(cmdRxDisable, inf_3c90x->IOAddr + regCommandIntStatus_w);
624 outw(cmdTxDisable, inf_3c90x->IOAddr + regCommandIntStatus_w);
626 a3c90x_reset(inf_3c90x);
627 netdev_nullify(netdev);
631 static void a3c90x_irq(struct net_device *netdev, int enable)
633 struct INF_3C90X *p = netdev_priv(netdev);
635 DBGP("a3c90x_irq\n");
638 /* disable interrupts */
639 a3c90x_internal_IssueCommand(p->IOAddr,
640 cmdSetInterruptEnable, 0);
642 a3c90x_internal_IssueCommand(p->IOAddr,
643 cmdSetInterruptEnable,
646 a3c90x_internal_IssueCommand(p->IOAddr,
647 cmdAcknowledgeInterrupt,
653 * a3c90x_hw_start - Initialize hardware, copy MAC address
654 * to NIC registers, set default receiver
656 static void a3c90x_hw_start(struct net_device *netdev)
661 unsigned short linktype;
662 struct INF_3C90X *inf_3c90x = netdev_priv(netdev);
664 DBGP("a3c90x_hw_start\n");
666 /* 3C556: Invert MII power */
667 if (inf_3c90x->is3c556) {
669 a3c90x_internal_SetWindow(inf_3c90x, winAddressing2);
670 tmp = inw(inf_3c90x->IOAddr + regResetOptions_2_w);
672 outw(tmp, inf_3c90x->IOAddr + regResetOptions_2_w);
675 /* Copy MAC address into the NIC registers */
676 a3c90x_internal_SetWindow(inf_3c90x, winAddressing2);
677 for (i = 0; i < ETH_ALEN; i++)
678 outb(netdev->ll_addr[i],
679 inf_3c90x->IOAddr + regStationAddress_2_3w + i);
680 for (i = 0; i < ETH_ALEN; i++)
681 outb(0, inf_3c90x->IOAddr + regStationMask_2_3w + i);
683 /* Read the media options register, print a message and set default
686 * Uses Media Option command on B revision, Reset Option on non-B
687 * revision cards -- same register address
689 a3c90x_internal_SetWindow(inf_3c90x, winTxRxOptions3);
690 mopt = inw(inf_3c90x->IOAddr + regResetMediaOptions_3_w);
692 /* mask out VCO bit that is defined as 10baseFL bit on B-rev cards */
693 if (!inf_3c90x->isBrev) {
697 DBG("Connectors present: ");
701 DBG("%s100Base-T4", (c++) ? ", " : "");
705 DBG("%s100Base-FX", (c++) ? ", " : "");
706 linktype = link100BaseFX;
709 DBG("%s10Base-2", (c++) ? ", " : "");
710 linktype = link10Base2;
713 DBG("%sAUI", (c++) ? ", " : "");
717 DBG("%sMII", (c++) ? ", " : "");
720 if ((mopt & 0xA) == 0xA) {
721 DBG("%s10Base-T / 100Base-TX", (c++) ? ", " : "");
722 linktype = linkAutoneg;
723 } else if ((mopt & 0xA) == 0x2) {
724 DBG("%s100Base-TX", (c++) ? ", " : "");
725 linktype = linkAutoneg;
726 } else if ((mopt & 0xA) == 0x8) {
727 DBG("%s10Base-T", (c++) ? ", " : "");
728 linktype = linkAutoneg;
732 /* Determine transceiver type to use, depending on value stored in
735 if (inf_3c90x->isBrev) {
736 if ((inf_3c90x->eeprom[0x16] & 0xFF00) == XCVR_MAGIC) {
738 linktype = inf_3c90x->eeprom[0x16] & 0x000F;
741 /* I don't know what MII MAC only mode is!!! */
742 if (linktype == linkExternalMII) {
743 if (inf_3c90x->isBrev)
744 DBG("WARNING: MII External MAC Mode only supported on B-revision " "cards!!!!\nFalling Back to MII Mode\n");
749 /* enable DC converter for 10-Base-T */
750 if (linktype == link10Base2) {
751 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr,
752 cmdEnableDcConverter, 0);
755 /* Set the link to the type we just determined. */
756 a3c90x_internal_SetWindow(inf_3c90x, winTxRxOptions3);
757 cfg = inl(inf_3c90x->IOAddr + regInternalConfig_3_l);
759 cfg |= (linktype << 20);
761 DBG("Setting internal cfg register: 0x%08X (linktype: 0x%02X)\n",
764 outl(cfg, inf_3c90x->IOAddr + regInternalConfig_3_l);
766 /* Now that we set the xcvr type, reset the Tx and Rx */
767 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdTxReset, 0x00);
769 if (!inf_3c90x->isBrev)
770 outb(0x01, inf_3c90x->IOAddr + regTxFreeThresh_b);
772 /* Set the RX filter = receive only individual pkts & multicast & bcast. */
773 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdSetRxFilter,
778 * set Indication and Interrupt flags , acknowledge any IRQ's
780 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr,
781 cmdSetInterruptEnable,
782 INT_TXCOMPLETE | INT_UPCOMPLETE);
783 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr,
784 cmdSetIndicationEnable,
785 INT_TXCOMPLETE | INT_UPCOMPLETE);
786 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr,
787 cmdAcknowledgeInterrupt, 0x661);
791 * a3c90x_open - Routine to initialize the card. Initialize hardware,
792 * allocate TX and RX ring, send RX ring address to the NIC.
794 * @v netdev Network device info
796 * @ret Returns 0 on success, negative on failure
798 static int a3c90x_open(struct net_device *netdev)
801 struct INF_3C90X *inf_3c90x = netdev_priv(netdev);
803 DBGP("a3c90x_open\n");
805 a3c90x_hw_start(netdev);
807 rc = a3c90x_setup_tx_ring(inf_3c90x);
809 DBG("Error setting up TX Ring\n");
813 rc = a3c90x_setup_rx_ring(inf_3c90x);
815 DBG("Error setting up RX Ring\n");
819 /* send rx_ring address to NIC */
820 outl(virt_to_bus(inf_3c90x->rx_ring),
821 inf_3c90x->IOAddr + regUpListPtr_l);
823 /* enable packet transmission and reception */
824 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdTxEnable, 0);
825 a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdRxEnable, 0);
830 a3c90x_free_resources(inf_3c90x);
831 a3c90x_reset(inf_3c90x);
836 * a3c90x_close - free()s TX and RX ring, disablex RX/TX, resets NIC
838 * @v netdev Network device info
840 static void a3c90x_close(struct net_device *netdev)
842 struct INF_3C90X *inf_3c90x = netdev_priv(netdev);
844 DBGP("a3c90x_close\n");
846 outw(cmdRxDisable, inf_3c90x->IOAddr + regCommandIntStatus_w);
847 outw(cmdTxDisable, inf_3c90x->IOAddr + regCommandIntStatus_w);
848 a3c90x_reset(inf_3c90x);
849 a3c90x_free_resources(inf_3c90x);
852 static struct net_device_operations a3c90x_operations = {
854 .close = a3c90x_close,
856 .transmit = a3c90x_transmit,
861 * a3c90x_probe: exported routine to probe for the 3c905 card.
862 * If this routine is called, the pci functions did find the
863 * card. We read the eeprom here and get the MAC address.
864 * Initialization is done in a3c90x_open().
866 * @v pci PCI device info
867 * @ pci_id PCI device IDs
869 * @ret rc Returns 0 on success, negative on failure
871 static int a3c90x_probe(struct pci_device *pci,
872 const struct pci_device_id *pci_id __unused)
875 struct net_device *netdev;
876 struct INF_3C90X *inf_3c90x;
877 unsigned char *HWAddr;
880 DBGP("a3c90x_probe\n");
882 if (pci->ioaddr == 0)
885 netdev = alloc_etherdev(sizeof(*inf_3c90x));
889 netdev_init(netdev, &a3c90x_operations);
890 pci_set_drvdata(pci, netdev);
891 netdev->dev = &pci->dev;
893 inf_3c90x = netdev_priv(netdev);
894 memset(inf_3c90x, 0, sizeof(*inf_3c90x));
896 adjust_pci_device(pci);
898 inf_3c90x->is3c556 = (pci->device == 0x6055);
899 inf_3c90x->IOAddr = pci->ioaddr;
900 inf_3c90x->CurrentWindow = winNone;
902 inf_3c90x->isBrev = 1;
903 switch (pci->device) {
904 case 0x9000: /* 10 Base TPO */
905 case 0x9001: /* 10/100 T4 */
906 case 0x9050: /* 10/100 TPO */
907 case 0x9051: /* 10 Base Combo */
908 inf_3c90x->isBrev = 0;
912 DBG("[3c90x]: found NIC(0x%04X, 0x%04X), isBrev=%d, is3c556=%d\n",
913 pci->vendor, pci->device, inf_3c90x->isBrev,
916 /* initialize nvs device */
917 inf_3c90x->nvs.word_len_log2 = 1; /* word */
918 inf_3c90x->nvs.size = (inf_3c90x->isBrev ? 0x20 : 0x17);
919 inf_3c90x->nvs.block_size = 1;
920 inf_3c90x->nvs.read = a3c90x_internal_ReadEeprom;
921 inf_3c90x->nvs.write = a3c90x_internal_WriteEeprom;
923 /* reset NIC before accessing any data from it */
924 a3c90x_reset(inf_3c90x);
926 /* load eeprom contents to inf_3c90x->eeprom */
927 a3c90x_internal_ReadEepromContents(inf_3c90x);
929 HWAddr = netdev->ll_addr;
931 /* Retrieve the Hardware address */
932 HWAddr[0] = inf_3c90x->eeprom[eepromHwAddrOffset + 0] >> 8;
933 HWAddr[1] = inf_3c90x->eeprom[eepromHwAddrOffset + 0] & 0xFF;
934 HWAddr[2] = inf_3c90x->eeprom[eepromHwAddrOffset + 1] >> 8;
935 HWAddr[3] = inf_3c90x->eeprom[eepromHwAddrOffset + 1] & 0xFF;
936 HWAddr[4] = inf_3c90x->eeprom[eepromHwAddrOffset + 2] >> 8;
937 HWAddr[5] = inf_3c90x->eeprom[eepromHwAddrOffset + 2] & 0xFF;
939 /* we don't handle linkstates yet, so we're always up */
940 netdev_link_up(netdev);
942 if ((rc = register_netdev(netdev)) != 0) {
943 DBG("3c90x: register_netdev() failed\n");
951 static struct pci_device_id a3c90x_nics[] = {
952 /* Original 90x revisions: */
953 PCI_ROM(0x10b7, 0x6055, "3c556", "3C556"), /* Huricane */
954 PCI_ROM(0x10b7, 0x9000, "3c905-tpo", "3Com900-TPO"), /* 10 Base TPO */
955 PCI_ROM(0x10b7, 0x9001, "3c905-t4", "3Com900-Combo"), /* 10/100 T4 */
956 PCI_ROM(0x10b7, 0x9050, "3c905-tpo100", "3Com905-TX"), /* 100 Base TX / 10/100 TPO */
957 PCI_ROM(0x10b7, 0x9051, "3c905-combo", "3Com905-T4"), /* 100 Base T4 / 10 Base Combo */
958 /* Newer 90xB revisions: */
959 PCI_ROM(0x10b7, 0x9004, "3c905b-tpo", "3Com900B-TPO"), /* 10 Base TPO */
960 PCI_ROM(0x10b7, 0x9005, "3c905b-combo", "3Com900B-Combo"), /* 10 Base Combo */
961 PCI_ROM(0x10b7, 0x9006, "3c905b-tpb2", "3Com900B-2/T"), /* 10 Base TP and Base2 */
962 PCI_ROM(0x10b7, 0x900a, "3c905b-fl", "3Com900B-FL"), /* 10 Base FL */
963 PCI_ROM(0x10b7, 0x9055, "3c905b-tpo100", "3Com905B-TX"), /* 10/100 TPO */
964 PCI_ROM(0x10b7, 0x9056, "3c905b-t4", "3Com905B-T4"), /* 10/100 T4 */
965 PCI_ROM(0x10b7, 0x9058, "3c905b-9058", "3Com905B-9058"), /* Cyclone 10/100/BNC */
966 PCI_ROM(0x10b7, 0x905a, "3c905b-fx", "3Com905B-FL"), /* 100 Base FX / 10 Base FX */
967 /* Newer 90xC revision: */
968 PCI_ROM(0x10b7, 0x9200, "3c905c-tpo", "3Com905C-TXM"), /* 10/100 TPO (3C905C-TXM) */
969 PCI_ROM(0x10b7, 0x9202, "3c920b-emb-ati", "3c920B-EMB-WNM (ATI Radeon 9100 IGP)"), /* 3c920B-EMB-WNM (ATI Radeon 9100 IGP) */
970 PCI_ROM(0x10b7, 0x9210, "3c920b-emb-wnm", "3Com20B-EMB WNM"),
971 PCI_ROM(0x10b7, 0x9800, "3c980", "3Com980-Cyclone"), /* Cyclone */
972 PCI_ROM(0x10b7, 0x9805, "3c9805", "3Com9805"), /* Dual Port Server Cyclone */
973 PCI_ROM(0x10b7, 0x7646, "3csoho100-tx", "3CSOHO100-TX"), /* Hurricane */
974 PCI_ROM(0x10b7, 0x4500, "3c450", "3Com450 HomePNA Tornado"),
975 PCI_ROM(0x10b7, 0x1201, "3c982a", "3Com982A"),
976 PCI_ROM(0x10b7, 0x1202, "3c982b", "3Com982B"),
979 struct pci_driver a3c90x_driver __pci_driver = {
981 .id_count = (sizeof(a3c90x_nics) / sizeof(a3c90x_nics[0])),
982 .probe = a3c90x_probe,
983 .remove = a3c90x_remove,