1 /**************************************************************************
3 * sundance.c -- Etherboot device driver for the Sundance ST201 "Alta".
4 * Written 2002-2002 by Timothy Legge <tlegge@rogers.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * Portions of this code based on:
21 * sundance.c: A Linux device driver for the Sundance ST201 "Alta"
22 * Written 1999-2002 by Donald Becker
24 * tulip.c: Tulip and Clone Etherboot Driver
26 * Copyright (C) 2001 Entity Cyber, Inc.
28 * Linux Driver Version LK1.09a, 10-Jul-2003 (2.4.25)
32 * v1.1 01-01-2003 timlegge Initial implementation
33 * v1.7 04-10-2003 timlegge Transfers Linux Kernel (30 sec)
34 * v1.8 04-13-2003 timlegge Fix multiple transmission bug
35 * v1.9 08-19-2003 timlegge Support Multicast
36 * v1.10 01-17-2004 timlegge Initial driver output cleanup
37 * v1.11 03-21-2004 timlegge Remove unused variables
38 * v1.12 03-21-2004 timlegge Remove excess MII defines
39 * v1.13 03-24-2004 timlegge Update to Linux 2.4.25 driver
41 ****************************************************************************/
43 /* to get some global routines like printf */
44 #include "etherboot.h"
45 /* to get the interface to the body of the program */
47 /* to get the PCI support functions, if this is a PCI NIC */
51 #define drv_version "v1.12"
52 #define drv_date "2004-03-21"
56 /* Condensed operations for readability. */
57 #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
58 #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
60 /* May need to be moved to mii.h */
64 unsigned int full_duplex:1; /* is full duplex? */
68 static int mtu = 1514;
70 /* Maximum number of multicast addresses to filter (vs. rx-all-multicast).
71 The sundance uses a 64 element hash table based on the Ethernet CRC. */
72 // static int multicast_filter_limit = 32;
74 /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
75 Setting to > 1518 effectively disables this feature.
76 This chip can receive into any byte alignment buffers, so word-oriented
77 archs do not need a copy-align of the IP header. */
78 static int rx_copybreak = 0;
79 static int flowctrl = 1;
81 /* Allow forcing the media type */
82 /* media[] specifies the media type the NIC operates at.
83 autosense Autosensing active media.
84 10mbps_hd 10Mbps half duplex.
85 10mbps_fd 10Mbps full duplex.
86 100mbps_hd 100Mbps half duplex.
87 100mbps_fd 100Mbps full duplex.
89 static char media[] = "autosense";
91 /* Operational parameters that are set at compile time. */
93 /* As Etherboot uses a Polling driver we can keep the number of rings
94 to the minimum number required. In general that is 1 transmit and 4 receive receive rings. However some cards require that
95 there be a minimum of 2 rings */
96 #define TX_RING_SIZE 2
97 #define TX_QUEUE_LEN 10 /* Limit ring entries actually used. */
98 #define RX_RING_SIZE 4
101 /* Operational parameters that usually are not changed. */
102 /* Time in jiffies before concluding the transmitter is hung. */
103 #define TX_TIME_OUT (4*HZ)
104 #define PKT_BUF_SZ 1536
106 /* Offsets to the device registers.
107 Unlike software-only systems, device drivers interact with complex hardware.
108 It's not useful to define symbolic names for every register bit in the
109 device. The name can only partially document the semantics and make
110 the driver longer and more difficult to read.
111 In general, only the important configuration values or bits changed
112 multiple times should be defined symbolically.
117 TxDMABurstThresh = 0x08,
118 TxDMAUrgentThresh = 0x09,
119 TxDMAPollPeriod = 0x0a,
124 RxDMABurstThresh = 0x14,
125 RxDMAUrgentThresh = 0x15,
126 RxDMAPollPeriod = 0x16,
131 TxStartThresh = 0x3c,
132 RxEarlyThresh = 0x3e,
147 MulticastFilter0 = 0x60,
148 MulticastFilter1 = 0x64,
155 StatsCarrierError = 0x74,
156 StatsLateColl = 0x75,
157 StatsMultiColl = 0x76,
161 StatsTxXSDefer = 0x7a,
167 /* Aliased and bogus values! */
170 enum ASICCtrl_HiWord_bit {
171 GlobalReset = 0x0001,
176 NetworkReset = 0x0020,
181 /* Bits in the interrupt status/mask registers. */
182 enum intr_status_bits {
183 IntrSummary = 0x0001, IntrPCIErr = 0x0002, IntrMACCtrl = 0x0008,
184 IntrTxDone = 0x0004, IntrRxDone = 0x0010, IntrRxStart = 0x0020,
185 IntrDrvRqst = 0x0040,
186 StatsMax = 0x0080, LinkChange = 0x0100,
187 IntrTxDMADone = 0x0200, IntrRxDMADone = 0x0400,
190 /* Bits in the RxMode register. */
192 AcceptAllIPMulti = 0x20, AcceptMultiHash = 0x10, AcceptAll = 0x08,
193 AcceptBroadcast = 0x04, AcceptMulticast = 0x02, AcceptMyPhys =
196 /* Bits in MACCtrl. */
197 enum mac_ctrl0_bits {
198 EnbFullDuplex = 0x20, EnbRcvLargeFrame = 0x40,
199 EnbFlowCtrl = 0x100, EnbPassRxCRC = 0x200,
201 enum mac_ctrl1_bits {
202 StatsEnable = 0x0020, StatsDisable = 0x0040, StatsEnabled = 0x0080,
203 TxEnable = 0x0100, TxDisable = 0x0200, TxEnabled = 0x0400,
204 RxEnable = 0x0800, RxDisable = 0x1000, RxEnabled = 0x2000,
207 /* The Rx and Tx buffer descriptors.
208 Using only 32 bit fields simplifies software endian correction.
209 This structure must be aligned, and should avoid spanning cache lines.
218 /* Bits in netdev_desc.status */
219 enum desc_status_bits {
221 DescEndPacket = 0x4000,
222 DescEndRing = 0x2000,
223 LastFrag = 0x80000000,
224 DescIntrOnTx = 0x8000,
225 DescIntrOnDMADone = 0x80000000,
226 DisableAlign = 0x00000001,
229 /**********************************************
230 * Descriptor Ring and Buffer defination
231 ***********************************************/
232 /* Define the TX Descriptor */
233 static struct netdev_desc tx_ring[TX_RING_SIZE];
235 /* Define the RX Descriptor */
236 static struct netdev_desc rx_ring[RX_RING_SIZE];
238 /* Create a static buffer of size PKT_BUF_SZ for each RX and TX descriptor.
239 All descriptors point to a part of this buffer */
241 unsigned char txb[PKT_BUF_SZ * TX_RING_SIZE];
242 unsigned char rxb[RX_RING_SIZE * PKT_BUF_SZ];
243 } rx_tx_buf __shared;
244 #define rxb rx_tx_buf.rxb
245 #define txb rx_tx_buf.txb
247 /* FIXME: Move BASE to the private structure */
249 #define EEPROM_SIZE 128
251 enum pci_id_flags_bits {
252 PCI_USES_IO = 1, PCI_USES_MEM = 2, PCI_USES_MASTER = 4,
253 PCI_ADDR0 = 0 << 4, PCI_ADDR1 = 1 << 4, PCI_ADDR2 =
254 2 << 4, PCI_ADDR3 = 3 << 4,
257 enum chip_capability_flags { CanHaveMII = 1, KendinPktDropBug = 2, };
258 #define PCI_IOTYPE (PCI_USES_MASTER | PCI_USES_IO | PCI_ADDR0)
261 static struct sundance_private {
262 const char *nic_name;
263 /* Frequently used values */
265 unsigned int cur_rx; /* Producer/consumer ring indicies */
268 /* These values keep track of the tranceiver/media in use */
269 unsigned int flowctrl:1;
270 unsigned int an_enable:1;
274 /* MII tranceiver section */
275 struct mii_if_info mii_if;
276 int mii_preamble_required;
277 unsigned char phys[MII_CNT];
278 unsigned char pci_rev_id;
281 static struct sundance_private *sdc;
283 /* Station Address location within the EEPROM */
284 #define EEPROM_SA_OFFSET 0x10
285 #define DEFAULT_INTR (IntrRxDMADone | IntrPCIErr | \
286 IntrDrvRqst | IntrTxDone | StatsMax | \
289 static int eeprom_read(long ioaddr, int location);
290 static int mdio_read(struct nic *nic, int phy_id, unsigned int location);
291 static void mdio_write(struct nic *nic, int phy_id, unsigned int location,
293 static void set_rx_mode(struct nic *nic);
295 static void check_duplex(struct nic *nic)
297 int mii_lpa = mdio_read(nic, sdc->phys[0], MII_LPA);
298 int negotiated = mii_lpa & sdc->mii_if.advertising;
302 if (!sdc->an_enable || mii_lpa == 0xffff) {
303 if (sdc->mii_if.full_duplex)
304 outw(inw(BASE + MACCtrl0) | EnbFullDuplex,
309 /* Autonegotiation */
310 duplex = (negotiated & 0x0100) || (negotiated & 0x01C0) == 0x0040;
311 if (sdc->mii_if.full_duplex != duplex) {
312 sdc->mii_if.full_duplex = duplex;
313 DBG ("%s: Setting %s-duplex based on MII #%d "
314 "negotiated capability %4.4x.\n", sdc->nic_name,
315 duplex ? "full" : "half", sdc->phys[0],
317 outw(inw(BASE + MACCtrl0) | duplex ? 0x20 : 0,
323 /**************************************************************************
324 * init_ring - setup the tx and rx descriptors
325 *************************************************************************/
326 static void init_ring(struct nic *nic __unused)
332 /* Initialize all the Rx descriptors */
333 for (i = 0; i < RX_RING_SIZE; i++) {
334 rx_ring[i].next_desc = virt_to_le32desc(&rx_ring[i + 1]);
335 rx_ring[i].status = 0;
336 rx_ring[i].length = 0;
340 /* Mark the last entry as wrapping the ring */
341 rx_ring[i - 1].next_desc = virt_to_le32desc(&rx_ring[0]);
343 for (i = 0; i < RX_RING_SIZE; i++) {
344 rx_ring[i].addr = virt_to_le32desc(&rxb[i * PKT_BUF_SZ]);
345 rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ | LastFrag);
348 /* We only use one transmit buffer, but two
349 * descriptors so transmit engines have somewhere
350 * to point should they feel the need */
351 tx_ring[0].status = 0x00000000;
352 tx_ring[0].addr = virt_to_bus(&txb[0]);
353 tx_ring[0].next_desc = 0; /* virt_to_bus(&tx_ring[1]); */
355 /* This descriptor is never used */
356 tx_ring[1].status = 0x00000000;
357 tx_ring[1].addr = 0; /*virt_to_bus(&txb[0]); */
358 tx_ring[1].next_desc = 0;
360 /* Mark the last entry as wrapping the ring,
361 * though this should never happen */
362 tx_ring[1].length = cpu_to_le32(LastFrag | PKT_BUF_SZ);
365 /**************************************************************************
366 * RESET - Reset Adapter
367 * ***********************************************************************/
368 static void sundance_reset(struct nic *nic)
374 outl(virt_to_le32desc(&rx_ring[0]), BASE + RxListPtr);
375 /* The Tx List Pointer is written as packets are queued */
377 /* Initialize other registers. */
378 /* __set_mac_addr(dev); */
382 addr16 = (nic->node_addr[0] | (nic->node_addr[1] << 8));
383 outw(addr16, BASE + StationAddr);
384 addr16 = (nic->node_addr[2] | (nic->node_addr[3] << 8));
385 outw(addr16, BASE + StationAddr + 2);
386 addr16 = (nic->node_addr[4] | (nic->node_addr[5] << 8));
387 outw(addr16, BASE + StationAddr + 4);
390 outw(sdc->mtu + 14, BASE + MaxFrameSize);
391 if (sdc->mtu > 2047) /* this will never happen with default options */
392 outl(inl(BASE + ASICCtrl) | 0x0c, BASE + ASICCtrl);
396 outw(0, BASE + DownCounter);
397 /* Set the chip to poll every N*30nsec */
398 outb(100, BASE + RxDMAPollPeriod);
400 /* Fix DFE-580TX packet drop issue */
401 if (sdc->pci_rev_id >= 0x14)
402 writeb(0x01, BASE + DebugCtrl1);
404 outw(RxEnable | TxEnable, BASE + MACCtrl1);
406 /* Construct a perfect filter frame with the mac address as first match
407 * and broadcast for all others */
408 for (i = 0; i < 192; i++)
411 txb[0] = nic->node_addr[0];
412 txb[1] = nic->node_addr[1];
413 txb[2] = nic->node_addr[2];
414 txb[3] = nic->node_addr[3];
415 txb[4] = nic->node_addr[4];
416 txb[5] = nic->node_addr[5];
418 DBG ( "%s: Done sundance_reset, status: Rx %hX Tx %hX "
419 "MAC Control %hX, %hX %hX\n",
420 sdc->nic_name, (int) inl(BASE + RxStatus),
421 (int) inw(BASE + TxStatus), (int) inl(BASE + MACCtrl0),
422 (int) inw(BASE + MACCtrl1), (int) inw(BASE + MACCtrl0) );
425 /**************************************************************************
426 IRQ - Wait for a frame
427 ***************************************************************************/
428 static void sundance_irq ( struct nic *nic, irq_action_t action ) {
429 unsigned int intr_status;
434 intr_status = inw(nic->ioaddr + IntrStatus);
435 intr_status = intr_status & ~DEFAULT_INTR;
436 if ( action == ENABLE )
437 intr_status = intr_status | DEFAULT_INTR;
438 outw(intr_status, nic->ioaddr + IntrEnable);
441 outw(0x0200, BASE + ASICCtrl);
445 /**************************************************************************
446 POLL - Wait for a frame
447 ***************************************************************************/
448 static int sundance_poll(struct nic *nic, int retreive)
450 /* return true if there's an ethernet packet ready to read */
451 /* nic->packet should contain data on return */
452 /* nic->packetlen should contain length of data */
453 int entry = sdc->cur_rx % RX_RING_SIZE;
454 u32 frame_status = le32_to_cpu(rx_ring[entry].status);
458 if (!(frame_status & DescOwn))
461 /* There is a packet ready */
465 intr_status = inw(nic->ioaddr + IntrStatus);
466 outw(intr_status, nic->ioaddr + IntrStatus);
468 pkt_len = frame_status & 0x1fff;
470 if (frame_status & 0x001f4000) {
471 DBG ( "Polling frame_status error\n" ); /* Do we really care about this */
473 if (pkt_len < rx_copybreak) {
474 /* FIXME: What should happen Will this ever occur */
475 printf("Poll Error: pkt_len < rx_copybreak");
477 nic->packetlen = pkt_len;
478 memcpy(nic->packet, rxb +
479 (sdc->cur_rx * PKT_BUF_SZ), nic->packetlen);
483 rx_ring[entry].length = cpu_to_le32(PKT_BUF_SZ | LastFrag);
484 rx_ring[entry].status = 0;
486 sdc->cur_rx = entry % RX_RING_SIZE;
487 outw(DEFAULT_INTR & ~(IntrRxDone|IntrRxDMADone),
488 nic->ioaddr + IntrStatus);
492 /**************************************************************************
493 TRANSMIT - Transmit a frame
494 ***************************************************************************/
495 static void sundance_transmit(struct nic *nic, const char *d, /* Destination */
496 unsigned int t, /* Type */
497 unsigned int s, /* size */
504 outw(TxDisable, BASE + MACCtrl1);
506 memcpy(txb, d, ETH_ALEN);
507 memcpy(txb + ETH_ALEN, nic->node_addr, ETH_ALEN);
508 nstype = htons((u16) t);
509 memcpy(txb + 2 * ETH_ALEN, (u8 *) & nstype, 2);
510 memcpy(txb + ETH_HLEN, p, s);
517 /* Setup the transmit descriptor */
518 tx_ring[0].length = cpu_to_le32(s | LastFrag);
519 tx_ring[0].status = cpu_to_le32(0x00000001);
521 /* Point to transmit descriptor */
522 outl(virt_to_le32desc(&tx_ring[0]), BASE + TxListPtr);
525 outw(TxEnable, BASE + MACCtrl1);
526 /* Trigger an immediate send */
527 outw(0, BASE + TxStatus);
529 to = currticks() + TX_TIME_OUT;
530 while (!(tx_ring[0].status & 0x00010000) && (currticks() < to)); /* wait */
532 if (currticks() >= to) {
533 printf("TX Time Out");
536 outw(TxDisable, BASE + MACCtrl1);
540 /**************************************************************************
541 DISABLE - Turn off ethernet interface
542 ***************************************************************************/
543 static void sundance_disable ( struct nic *nic __unused ) {
544 /* put the card in its initial state */
545 /* This function serves 3 purposes.
546 * This disables DMA and interrupts so we don't receive
547 * unexpected packets or interrupts from the card after
548 * etherboot has finished.
549 * This frees resources so etherboot may use
550 * this driver on another interface
551 * This allows etherboot to reinitialize the interface
552 * if something is something goes wrong.
554 outw(0x0000, BASE + IntrEnable);
555 /* Stop the Chipchips Tx and Rx Status */
556 outw(TxDisable | RxDisable | StatsDisable, BASE + MACCtrl1);
559 static struct nic_operations sundance_operations = {
560 .connect = dummy_connect,
561 .poll = sundance_poll,
562 .transmit = sundance_transmit,
567 /**************************************************************************
568 PROBE - Look for an adapter, this routine's visible to the outside
569 ***************************************************************************/
570 static int sundance_probe ( struct nic *nic, struct pci_device *pci ) {
572 u8 ee_data[EEPROM_SIZE];
577 if (pci->ioaddr == 0)
580 /* BASE is used throughout to address the card */
582 printf(" sundance.c: Found %s Vendor=0x%hX Device=0x%hX\n",
583 pci->driver_name, pci->vendor, pci->device);
585 /* Get the MAC Address by reading the EEPROM */
586 for (i = 0; i < 3; i++) {
587 ((u16 *) ee_data)[i] =
588 le16_to_cpu(eeprom_read(BASE, i + EEPROM_SA_OFFSET));
590 /* Update the nic structure with the MAC Address */
591 for (i = 0; i < ETH_ALEN; i++) {
592 nic->node_addr[i] = ee_data[i];
595 /* Set the card as PCI Bus Master */
596 adjust_pci_device(pci);
598 // sdc->mii_if.dev = pci;
599 // sdc->mii_if.phy_id_mask = 0x1f;
600 // sdc->mii_if.reg_num_mask = 0x1f;
602 /* point to private storage */
605 sdc->nic_name = pci->driver_name;
608 pci_read_config_byte(pci, PCI_REVISION_ID, &sdc->pci_rev_id);
610 DBG ( "Device revision id: %hx\n", sdc->pci_rev_id );
612 /* Print out some hardware info */
613 DBG ( "%s: %s at ioaddr %hX, ", pci->driver_name, nic->node_addr, (unsigned int) BASE);
615 sdc->mii_preamble_required = 0;
617 int phy, phy_idx = 0;
618 sdc->phys[0] = 1; /* Default Setting */
619 sdc->mii_preamble_required++;
620 for (phy = 1; phy < 32 && phy_idx < MII_CNT; phy++) {
621 int mii_status = mdio_read(nic, phy, MII_BMSR);
622 if (mii_status != 0xffff && mii_status != 0x0000) {
623 sdc->phys[phy_idx++] = phy;
624 sdc->mii_if.advertising =
625 mdio_read(nic, phy, MII_ADVERTISE);
626 if ((mii_status & 0x0040) == 0)
627 sdc->mii_preamble_required++;
629 ( "%s: MII PHY found at address %d, status " "%hX advertising %hX\n", sdc->nic_name, phy, mii_status, sdc->mii_if.advertising );
632 sdc->mii_preamble_required--;
634 printf("%s: No MII transceiver found!\n",
636 sdc->mii_if.phy_id = sdc->phys[0];
639 /* Parse override configuration */
641 if (strcasecmp(media, "autosense") != 0) {
643 if (strcasecmp(media, "100mbps_fd") == 0 ||
644 strcasecmp(media, "4") == 0) {
646 sdc->mii_if.full_duplex = 1;
647 } else if (strcasecmp(media, "100mbps_hd") == 0
648 || strcasecmp(media, "3") == 0) {
650 sdc->mii_if.full_duplex = 0;
651 } else if (strcasecmp(media, "10mbps_fd") == 0 ||
652 strcasecmp(media, "2") == 0) {
654 sdc->mii_if.full_duplex = 1;
655 } else if (strcasecmp(media, "10mbps_hd") == 0 ||
656 strcasecmp(media, "1") == 0) {
658 sdc->mii_if.full_duplex = 0;
667 if (inl(BASE + ASICCtrl) & 0x80) {
668 /* Default 100Mbps Full */
669 if (sdc->an_enable) {
671 sdc->mii_if.full_duplex = 1;
676 /* The Linux driver uses flow control and resets the link here. This means the
677 mii section from above would need to be re done I believe. Since it serves
678 no real purpose leave it out. */
680 /* Force media type */
681 if (!sdc->an_enable) {
683 mii_ctl |= (sdc->speed == 100) ? BMCR_SPEED100 : 0;
684 mii_ctl |= (sdc->mii_if.full_duplex) ? BMCR_FULLDPLX : 0;
685 mdio_write(nic, sdc->phys[0], MII_BMCR, mii_ctl);
686 printf("Override speed=%d, %s duplex\n",
688 sdc->mii_if.full_duplex ? "Full" : "Half");
691 /* Reset the chip to erase previous misconfiguration */
692 DBG ( "ASIC Control is %#x\n", inl(BASE + ASICCtrl) );
693 outw(0x007f, BASE + ASICCtrl + 2);
696 * wait for reset to complete
697 * this is heavily inspired by the linux sundance driver
698 * according to the linux driver it can take up to 1ms for the reset
702 while(inl(BASE + ASICCtrl) & (ResetBusy << 16)) {
704 DBG("sundance: NIC reset did not complete.\n");
710 DBG ( "ASIC Control is now %#x.\n", inl(BASE + ASICCtrl) );
713 if (sdc->an_enable) {
714 u16 mii_advertise, mii_lpa;
716 mdio_read(nic, sdc->phys[0], MII_ADVERTISE);
717 mii_lpa = mdio_read(nic, sdc->phys[0], MII_LPA);
718 mii_advertise &= mii_lpa;
719 if (mii_advertise & ADVERTISE_100FULL)
721 else if (mii_advertise & ADVERTISE_100HALF)
723 else if (mii_advertise & ADVERTISE_10FULL)
725 else if (mii_advertise & ADVERTISE_10HALF)
728 mii_ctl = mdio_read(nic, sdc->phys[0], MII_BMCR);
729 speed = (mii_ctl & BMCR_SPEED100) ? 100 : 10;
731 printf("%s: Link changed: %dMbps ,", sdc->nic_name, speed);
732 printf("%s duplex.\n", (mii_ctl & BMCR_FULLDPLX) ?
736 if (sdc->flowctrl && sdc->mii_if.full_duplex) {
737 outw(inw(BASE + MulticastFilter1 + 2) | 0x0200,
738 BASE + MulticastFilter1 + 2);
739 outw(inw(BASE + MACCtrl0) | EnbFlowCtrl, BASE + MACCtrl0);
741 printf("%dMbps, %s-Duplex\n", sdc->speed,
742 sdc->mii_if.full_duplex ? "Full" : "Half");
744 /* point to NIC specific routines */
745 nic->nic_op = &sundance_operations;
747 nic->irqno = pci->irq;
754 /* Read the EEPROM and MII Management Data I/O (MDIO) interfaces. */
755 static int eeprom_read(long ioaddr, int location)
757 int boguscnt = 10000; /* Typical 1900 ticks */
758 outw(0x0200 | (location & 0xff), ioaddr + EECtrl);
760 if (!(inw(ioaddr + EECtrl) & 0x8000)) {
761 return inw(ioaddr + EEData);
764 while (--boguscnt > 0);
768 /* MII transceiver control section.
769 Read and write the MII registers using software-generated serial
770 MDIO protocol. See the MII specifications or DP83840A data sheet
773 The maximum data clock rate is 2.5 Mhz.
774 The timing is decoupled from the processor clock by flushing the write
775 from the CPU write buffer with a following read, and using PCI
778 #define mdio_in(mdio_addr) inb(mdio_addr)
779 #define mdio_out(value, mdio_addr) outb(value, mdio_addr)
780 #define mdio_delay(mdio_addr) inb(mdio_addr)
783 MDIO_ShiftClk = 0x0001, MDIO_Data = 0x0002, MDIO_EnbOutput =
786 #define MDIO_EnbIn (0)
787 #define MDIO_WRITE0 (MDIO_EnbOutput)
788 #define MDIO_WRITE1 (MDIO_Data | MDIO_EnbOutput)
790 /* Generate the preamble required for initial synchronization and
791 a few older transceivers. */
792 static void mdio_sync(long mdio_addr)
796 /* Establish sync by sending at least 32 logic ones. */
797 while (--bits >= 0) {
798 mdio_out(MDIO_WRITE1, mdio_addr);
799 mdio_delay(mdio_addr);
800 mdio_out(MDIO_WRITE1 | MDIO_ShiftClk, mdio_addr);
801 mdio_delay(mdio_addr);
806 mdio_read(struct nic *nic __unused, int phy_id, unsigned int location)
808 long mdio_addr = BASE + MIICtrl;
809 int mii_cmd = (0xf6 << 10) | (phy_id << 5) | location;
812 if (sdc->mii_preamble_required)
813 mdio_sync(mdio_addr);
815 /* Shift the read command bits out. */
816 for (i = 15; i >= 0; i--) {
818 (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
820 mdio_out(dataval, mdio_addr);
821 mdio_delay(mdio_addr);
822 mdio_out(dataval | MDIO_ShiftClk, mdio_addr);
823 mdio_delay(mdio_addr);
825 /* Read the two transition, 16 data, and wire-idle bits. */
826 for (i = 19; i > 0; i--) {
827 mdio_out(MDIO_EnbIn, mdio_addr);
828 mdio_delay(mdio_addr);
829 retval = (retval << 1) | ((mdio_in(mdio_addr) & MDIO_Data)
831 mdio_out(MDIO_EnbIn | MDIO_ShiftClk, mdio_addr);
832 mdio_delay(mdio_addr);
834 return (retval >> 1) & 0xffff;
838 mdio_write(struct nic *nic __unused, int phy_id,
839 unsigned int location, int value)
841 long mdio_addr = BASE + MIICtrl;
843 (0x5002 << 16) | (phy_id << 23) | (location << 18) | value;
846 if (sdc->mii_preamble_required)
847 mdio_sync(mdio_addr);
849 /* Shift the command bits out. */
850 for (i = 31; i >= 0; i--) {
852 (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
853 mdio_out(dataval, mdio_addr);
854 mdio_delay(mdio_addr);
855 mdio_out(dataval | MDIO_ShiftClk, mdio_addr);
856 mdio_delay(mdio_addr);
858 /* Clear out extra bits. */
859 for (i = 2; i > 0; i--) {
860 mdio_out(MDIO_EnbIn, mdio_addr);
861 mdio_delay(mdio_addr);
862 mdio_out(MDIO_EnbIn | MDIO_ShiftClk, mdio_addr);
863 mdio_delay(mdio_addr);
868 static void set_rx_mode(struct nic *nic __unused)
871 u16 mc_filter[4]; /* Multicast hash filter */
874 memset(mc_filter, 0xff, sizeof(mc_filter));
875 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
877 if (sdc->mii_if.full_duplex && sdc->flowctrl)
878 mc_filter[3] |= 0x0200;
879 for (i = 0; i < 4; i++)
880 outw(mc_filter[i], BASE + MulticastFilter0 + i * 2);
881 outb(rx_mode, BASE + RxMode);
885 static struct pci_device_id sundance_nics[] = {
886 PCI_ROM(0x13f0, 0x0201, "sundance", "ST201 Sundance 'Alta' based Adaptor"),
887 PCI_ROM(0x1186, 0x1002, "dfe530txs", "D-Link DFE530TXS (Sundance ST201 Alta)"),
888 PCI_ROM(0x13f0, 0x0200, "ip100a", "IC+ IP100A"),
891 PCI_DRIVER ( sundance_driver, sundance_nics, PCI_NO_CLASS );
893 DRIVER ( "SUNDANCE/PCI", nic_driver, pci_driver, sundance_driver,
894 sundance_probe, sundance_disable );