1 // SPDX-License-Identifier: GPL-2.0+
15 #include <linux/delay.h>
17 /* Ethernet chip registers. */
18 #define SCB_STATUS 0 /* Rx/Command Unit Status *Word* */
19 #define SCB_INT_ACK_BYTE 1 /* Rx/Command Unit STAT/ACK byte */
20 #define SCB_CMD 2 /* Rx/Command Unit Command *Word* */
21 #define SCB_INTR_CTL_BYTE 3 /* Rx/Command Unit Intr.Control Byte */
22 #define SCB_POINTER 4 /* General purpose pointer. */
23 #define SCB_PORT 8 /* Misc. commands and operands. */
24 #define SCB_FLASH 12 /* Flash memory control. */
25 #define SCB_EEPROM 14 /* EEPROM memory control. */
26 #define SCB_CTRL_MDI 16 /* MDI interface control. */
27 #define SCB_EARLY_RX 20 /* Early receive byte count. */
28 #define SCB_GEN_CONTROL 28 /* 82559 General Control Register */
29 #define SCB_GEN_STATUS 29 /* 82559 General Status register */
31 /* 82559 SCB status word defnitions */
32 #define SCB_STATUS_CX 0x8000 /* CU finished command (transmit) */
33 #define SCB_STATUS_FR 0x4000 /* frame received */
34 #define SCB_STATUS_CNA 0x2000 /* CU left active state */
35 #define SCB_STATUS_RNR 0x1000 /* receiver left ready state */
36 #define SCB_STATUS_MDI 0x0800 /* MDI read/write cycle done */
37 #define SCB_STATUS_SWI 0x0400 /* software generated interrupt */
38 #define SCB_STATUS_FCP 0x0100 /* flow control pause interrupt */
40 #define SCB_INTACK_MASK 0xFD00 /* all the above */
42 #define SCB_INTACK_TX (SCB_STATUS_CX | SCB_STATUS_CNA)
43 #define SCB_INTACK_RX (SCB_STATUS_FR | SCB_STATUS_RNR)
45 /* System control block commands */
48 #define CU_START 0x0010
49 #define CU_RESUME 0x0020
50 #define CU_STATSADDR 0x0040 /* Load Dump Statistics ctrs addr */
51 #define CU_SHOWSTATS 0x0050 /* Dump statistics counters. */
52 #define CU_ADDR_LOAD 0x0060 /* Base address to add to CU commands */
53 #define CU_DUMPSTATS 0x0070 /* Dump then reset stats counters. */
56 #define RUC_NOP 0x0000
57 #define RUC_START 0x0001
58 #define RUC_RESUME 0x0002
59 #define RUC_ABORT 0x0004
60 #define RUC_ADDR_LOAD 0x0006 /* (seems not to clear on acceptance) */
61 #define RUC_RESUMENR 0x0007
63 #define CU_CMD_MASK 0x00f0
64 #define RU_CMD_MASK 0x0007
66 #define SCB_M 0x0100 /* 0 = enable interrupt, 1 = disable */
67 #define SCB_SWI 0x0200 /* 1 - cause device to interrupt */
69 #define CU_STATUS_MASK 0x00C0
70 #define RU_STATUS_MASK 0x003C
72 #define RU_STATUS_IDLE (0 << 2)
73 #define RU_STATUS_SUS (1 << 2)
74 #define RU_STATUS_NORES (2 << 2)
75 #define RU_STATUS_READY (4 << 2)
76 #define RU_STATUS_NO_RBDS_SUS ((1 << 2) | (8 << 2))
77 #define RU_STATUS_NO_RBDS_NORES ((2 << 2) | (8 << 2))
78 #define RU_STATUS_NO_RBDS_READY ((4 << 2) | (8 << 2))
80 /* 82559 Port interface commands. */
81 #define I82559_RESET 0x00000000 /* Software reset */
82 #define I82559_SELFTEST 0x00000001 /* 82559 Selftest command */
83 #define I82559_SELECTIVE_RESET 0x00000002
84 #define I82559_DUMP 0x00000003
85 #define I82559_DUMP_WAKEUP 0x00000007
87 /* 82559 Eeprom interface. */
88 #define EE_SHIFT_CLK 0x01 /* EEPROM shift clock. */
89 #define EE_CS 0x02 /* EEPROM chip select. */
90 #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
91 #define EE_WRITE_0 0x01
92 #define EE_WRITE_1 0x05
93 #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
94 #define EE_ENB (0x4800 | EE_CS)
96 #define EE_DATA_BITS 16
98 /* The EEPROM commands include the alway-set leading bit. */
99 #define EE_EWENB_CMD(addr_len) (4 << (addr_len))
100 #define EE_WRITE_CMD(addr_len) (5 << (addr_len))
101 #define EE_READ_CMD(addr_len) (6 << (addr_len))
102 #define EE_ERASE_CMD(addr_len) (7 << (addr_len))
104 /* Receive frame descriptors. */
105 struct eepro100_rxfd {
108 u32 link; /* struct eepro100_rxfd * */
109 u32 rx_buf_addr; /* void * */
112 u8 data[PKTSIZE_ALIGN];
115 #define RFD_STATUS_C 0x8000 /* completion of received frame */
116 #define RFD_STATUS_OK 0x2000 /* frame received with no errors */
118 #define RFD_CONTROL_EL 0x8000 /* 1=last RFD in RFA */
119 #define RFD_CONTROL_S 0x4000 /* 1=suspend RU after receiving frame */
120 #define RFD_CONTROL_H 0x0010 /* 1=RFD is a header RFD */
121 #define RFD_CONTROL_SF 0x0008 /* 0=simplified, 1=flexible mode */
123 #define RFD_COUNT_MASK 0x3fff
124 #define RFD_COUNT_F 0x4000
125 #define RFD_COUNT_EOF 0x8000
127 #define RFD_RX_CRC 0x0800 /* crc error */
128 #define RFD_RX_ALIGNMENT 0x0400 /* alignment error */
129 #define RFD_RX_RESOURCE 0x0200 /* out of space, no resources */
130 #define RFD_RX_DMA_OVER 0x0100 /* DMA overrun */
131 #define RFD_RX_SHORT 0x0080 /* short frame error */
132 #define RFD_RX_LENGTH 0x0020
133 #define RFD_RX_ERROR 0x0010 /* receive error */
134 #define RFD_RX_NO_ADR_MATCH 0x0004 /* no address match */
135 #define RFD_RX_IA_MATCH 0x0002 /* individual address does not match */
136 #define RFD_RX_TCO 0x0001 /* TCO indication */
138 /* Transmit frame descriptors */
139 struct eepro100_txfd { /* Transmit frame descriptor set. */
142 u32 link; /* void * */
143 u32 tx_desc_addr; /* Always points to the tx_buf_addr element. */
146 u32 tx_buf_addr0; /* void *, frame to be transmitted. */
147 s32 tx_buf_size0; /* Length of Tx frame. */
148 u32 tx_buf_addr1; /* void *, frame to be transmitted. */
149 s32 tx_buf_size1; /* Length of Tx frame. */
152 #define TXCB_CMD_TRANSMIT 0x0004 /* transmit command */
153 #define TXCB_CMD_SF 0x0008 /* 0=simplified, 1=flexible mode */
154 #define TXCB_CMD_NC 0x0010 /* 0=CRC insert by controller */
155 #define TXCB_CMD_I 0x2000 /* generate interrupt on completion */
156 #define TXCB_CMD_S 0x4000 /* suspend on completion */
157 #define TXCB_CMD_EL 0x8000 /* last command block in CBL */
159 #define TXCB_COUNT_MASK 0x3fff
160 #define TXCB_COUNT_EOF 0x8000
162 /* The Speedo3 Rx and Tx frame/buffer descriptors. */
163 struct descriptor { /* A generic descriptor. */
166 u32 link; /* struct descriptor * */
168 unsigned char params[0];
171 #define CONFIG_SYS_CMD_EL 0x8000
172 #define CONFIG_SYS_CMD_SUSPEND 0x4000
173 #define CONFIG_SYS_CMD_INT 0x2000
174 #define CONFIG_SYS_CMD_IAS 0x0001 /* individual address setup */
175 #define CONFIG_SYS_CMD_CONFIGURE 0x0002 /* configure */
177 #define CONFIG_SYS_STATUS_C 0x8000
178 #define CONFIG_SYS_STATUS_OK 0x2000
181 #define NUM_RX_DESC PKTBUFSRX
182 #define NUM_TX_DESC 1 /* Number of TX descriptors */
184 #define TOUT_LOOP 1000000
187 * The parameters for a CmdConfigure operation.
188 * There are so many options that it would be difficult to document
189 * each bit. We mostly use the default or recommended settings.
191 static const char i82558_config_cmd[] = {
192 22, 0x08, 0, 1, 0, 0, 0x22, 0x03, 1, /* 1=Use MII 0=Use AUI */
193 0, 0x2E, 0, 0x60, 0x08, 0x88,
194 0x68, 0, 0x40, 0xf2, 0x84, /* Disable FC */
198 struct eepro100_priv {
199 /* RX descriptor ring */
200 struct eepro100_rxfd rx_ring[NUM_RX_DESC];
201 /* TX descriptor ring */
202 struct eepro100_txfd tx_ring[NUM_TX_DESC];
203 /* RX descriptor ring pointer */
206 /* TX descriptor ring pointer */
210 struct udevice *devno;
212 struct eth_device dev;
216 void __iomem *iobase;
220 #if defined(CONFIG_DM_ETH)
221 #define bus_to_phys(dev, a) dm_pci_mem_to_phys((dev), (a))
222 #define phys_to_bus(dev, a) dm_pci_phys_to_mem((dev), (a))
223 #elif defined(CONFIG_E500)
224 #define bus_to_phys(dev, a) (a)
225 #define phys_to_bus(dev, a) (a)
227 #define bus_to_phys(dev, a) pci_mem_to_phys((dev), (a))
228 #define phys_to_bus(dev, a) pci_phys_to_mem((dev), (a))
231 static int INW(struct eepro100_priv *priv, u_long addr)
233 return le16_to_cpu(readw(addr + priv->iobase));
236 static void OUTW(struct eepro100_priv *priv, int command, u_long addr)
238 writew(cpu_to_le16(command), addr + priv->iobase);
241 static void OUTL(struct eepro100_priv *priv, int command, u_long addr)
243 writel(cpu_to_le32(command), addr + priv->iobase);
246 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
247 static int INL(struct eepro100_priv *priv, u_long addr)
249 return le32_to_cpu(readl(addr + priv->iobase));
252 static int get_phyreg(struct eepro100_priv *priv, unsigned char addr,
253 unsigned char reg, unsigned short *value)
258 /* read requested data */
259 cmd = (2 << 26) | ((addr & 0x1f) << 21) | ((reg & 0x1f) << 16);
260 OUTL(priv, cmd, SCB_CTRL_MDI);
264 cmd = INL(priv, SCB_CTRL_MDI);
265 } while (!(cmd & (1 << 28)) && (--timeout));
270 *value = (unsigned short)(cmd & 0xffff);
275 static int set_phyreg(struct eepro100_priv *priv, unsigned char addr,
276 unsigned char reg, unsigned short value)
281 /* write requested data */
282 cmd = (1 << 26) | ((addr & 0x1f) << 21) | ((reg & 0x1f) << 16);
283 OUTL(priv, cmd | value, SCB_CTRL_MDI);
285 while (!(INL(priv, SCB_CTRL_MDI) & (1 << 28)) && (--timeout))
295 * Check if given phyaddr is valid, i.e. there is a PHY connected.
296 * Do this by checking model value field from ID2 register.
298 static int verify_phyaddr(struct eepro100_priv *priv, unsigned char addr)
300 unsigned short value, model;
303 /* read id2 register */
304 ret = get_phyreg(priv, addr, MII_PHYSID2, &value);
306 printf("%s: mii read timeout!\n", priv->name);
311 model = (value >> 4) & 0x003f;
313 printf("%s: no PHY at address %d\n", priv->name, addr);
320 static int eepro100_miiphy_read(struct mii_dev *bus, int addr, int devad,
323 struct eepro100_priv *priv = bus->priv;
324 unsigned short value = 0;
327 ret = verify_phyaddr(priv, addr);
331 ret = get_phyreg(priv, addr, reg, &value);
333 printf("%s: mii read timeout!\n", bus->name);
340 static int eepro100_miiphy_write(struct mii_dev *bus, int addr, int devad,
343 struct eepro100_priv *priv = bus->priv;
346 ret = verify_phyaddr(priv, addr);
350 ret = set_phyreg(priv, addr, reg, value);
352 printf("%s: mii write timeout!\n", bus->name);
360 static void init_rx_ring(struct eepro100_priv *priv)
362 struct eepro100_rxfd *rx_ring = priv->rx_ring;
365 for (i = 0; i < NUM_RX_DESC; i++) {
366 rx_ring[i].status = 0;
367 rx_ring[i].control = (i == NUM_RX_DESC - 1) ?
368 cpu_to_le16 (RFD_CONTROL_S) : 0;
370 cpu_to_le32(phys_to_bus(priv->devno,
371 (u32)&rx_ring[(i + 1) %
373 rx_ring[i].rx_buf_addr = 0xffffffff;
374 rx_ring[i].count = cpu_to_le32(PKTSIZE_ALIGN << 16);
377 flush_dcache_range((unsigned long)rx_ring,
378 (unsigned long)rx_ring +
379 (sizeof(*rx_ring) * NUM_RX_DESC));
384 static void purge_tx_ring(struct eepro100_priv *priv)
386 struct eepro100_txfd *tx_ring = priv->tx_ring;
389 priv->tx_threshold = 0x01208000;
390 memset(tx_ring, 0, sizeof(*tx_ring) * NUM_TX_DESC);
392 flush_dcache_range((unsigned long)tx_ring,
393 (unsigned long)tx_ring +
394 (sizeof(*tx_ring) * NUM_TX_DESC));
397 /* Wait for the chip get the command. */
398 static int wait_for_eepro100(struct eepro100_priv *priv)
402 for (i = 0; INW(priv, SCB_CMD) & (CU_CMD_MASK | RU_CMD_MASK); i++) {
410 static int eepro100_txcmd_send(struct eepro100_priv *priv,
411 struct eepro100_txfd *desc)
416 flush_dcache_range((unsigned long)desc,
417 (unsigned long)desc + sizeof(*desc));
419 if (!wait_for_eepro100(priv))
422 OUTL(priv, phys_to_bus(priv->devno, (u32)desc), SCB_POINTER);
423 OUTW(priv, SCB_M | CU_START, SCB_CMD);
426 invalidate_dcache_range((unsigned long)desc,
427 (unsigned long)desc + sizeof(*desc));
428 rstat = le16_to_cpu(desc->status);
429 if (rstat & CONFIG_SYS_STATUS_C)
432 if (i++ >= TOUT_LOOP) {
433 printf("%s: Tx error buffer not ready\n", priv->name);
438 invalidate_dcache_range((unsigned long)desc,
439 (unsigned long)desc + sizeof(*desc));
440 rstat = le16_to_cpu(desc->status);
442 if (!(rstat & CONFIG_SYS_STATUS_OK)) {
443 printf("TX error status = 0x%08X\n", rstat);
451 static int read_eeprom(struct eepro100_priv *priv, int location, int addr_len)
453 unsigned short retval = 0;
454 int read_cmd = location | EE_READ_CMD(addr_len);
457 OUTW(priv, EE_ENB & ~EE_CS, SCB_EEPROM);
458 OUTW(priv, EE_ENB, SCB_EEPROM);
460 /* Shift the read command bits out. */
461 for (i = 12; i >= 0; i--) {
462 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
464 OUTW(priv, EE_ENB | dataval, SCB_EEPROM);
466 OUTW(priv, EE_ENB | dataval | EE_SHIFT_CLK, SCB_EEPROM);
469 OUTW(priv, EE_ENB, SCB_EEPROM);
471 for (i = 15; i >= 0; i--) {
472 OUTW(priv, EE_ENB | EE_SHIFT_CLK, SCB_EEPROM);
474 retval = (retval << 1) |
475 !!(INW(priv, SCB_EEPROM) & EE_DATA_READ);
476 OUTW(priv, EE_ENB, SCB_EEPROM);
480 /* Terminate the EEPROM access. */
481 OUTW(priv, EE_ENB & ~EE_CS, SCB_EEPROM);
485 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
486 static int eepro100_initialize_mii(struct eepro100_priv *priv)
488 /* register mii command access routines */
489 struct mii_dev *mdiodev;
492 mdiodev = mdio_alloc();
496 strncpy(mdiodev->name, priv->name, MDIO_NAME_LEN);
497 mdiodev->read = eepro100_miiphy_read;
498 mdiodev->write = eepro100_miiphy_write;
499 mdiodev->priv = priv;
501 ret = mdio_register(mdiodev);
510 static int eepro100_initialize_mii(struct eepro100_priv *priv)
516 static struct pci_device_id supported[] = {
517 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82557) },
518 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82559) },
519 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82559ER) },
523 static void eepro100_get_hwaddr(struct eepro100_priv *priv)
527 int addr_len = read_eeprom(priv, 0, 6) == 0xffff ? 8 : 6;
529 for (j = 0, i = 0; i < 0x40; i++) {
530 u16 value = read_eeprom(priv, i, addr_len);
534 priv->enetaddr[j++] = value;
535 priv->enetaddr[j++] = value >> 8;
540 memset(priv->enetaddr, 0, ETH_ALEN);
541 debug("%s: Invalid EEPROM checksum %#4.4x, check settings before activating this device!\n",
546 static int eepro100_init_common(struct eepro100_priv *priv)
548 struct eepro100_rxfd *rx_ring = priv->rx_ring;
549 struct eepro100_txfd *tx_ring = priv->tx_ring;
550 struct eepro100_txfd *ias_cmd, *cfg_cmd;
551 int ret, status = -1;
554 /* Reset the ethernet controller */
555 OUTL(priv, I82559_SELECTIVE_RESET, SCB_PORT);
558 OUTL(priv, I82559_RESET, SCB_PORT);
561 if (!wait_for_eepro100(priv)) {
562 printf("Error: Can not reset ethernet controller.\n");
565 OUTL(priv, 0, SCB_POINTER);
566 OUTW(priv, SCB_M | RUC_ADDR_LOAD, SCB_CMD);
568 if (!wait_for_eepro100(priv)) {
569 printf("Error: Can not reset ethernet controller.\n");
572 OUTL(priv, 0, SCB_POINTER);
573 OUTW(priv, SCB_M | CU_ADDR_LOAD, SCB_CMD);
575 /* Initialize Rx and Tx rings. */
579 /* Tell the adapter where the RX ring is located. */
580 if (!wait_for_eepro100(priv)) {
581 printf("Error: Can not reset ethernet controller.\n");
585 /* RX ring cache was already flushed in init_rx_ring() */
586 OUTL(priv, phys_to_bus(priv->devno, (u32)&rx_ring[priv->rx_next]),
588 OUTW(priv, SCB_M | RUC_START, SCB_CMD);
590 /* Send the Configure frame */
591 tx_cur = priv->tx_next;
592 priv->tx_next = ((priv->tx_next + 1) % NUM_TX_DESC);
594 cfg_cmd = &tx_ring[tx_cur];
595 cfg_cmd->command = cpu_to_le16(CONFIG_SYS_CMD_SUSPEND |
596 CONFIG_SYS_CMD_CONFIGURE);
598 cfg_cmd->link = cpu_to_le32(phys_to_bus(priv->devno,
599 (u32)&tx_ring[priv->tx_next]));
601 memcpy(((struct descriptor *)cfg_cmd)->params, i82558_config_cmd,
602 sizeof(i82558_config_cmd));
604 ret = eepro100_txcmd_send(priv, cfg_cmd);
606 if (ret == -ETIMEDOUT)
607 printf("Error---CONFIG_SYS_CMD_CONFIGURE: Can not reset ethernet controller.\n");
611 /* Send the Individual Address Setup frame */
612 tx_cur = priv->tx_next;
613 priv->tx_next = ((priv->tx_next + 1) % NUM_TX_DESC);
615 ias_cmd = &tx_ring[tx_cur];
616 ias_cmd->command = cpu_to_le16(CONFIG_SYS_CMD_SUSPEND |
619 ias_cmd->link = cpu_to_le32(phys_to_bus(priv->devno,
620 (u32)&tx_ring[priv->tx_next]));
622 memcpy(((struct descriptor *)ias_cmd)->params, priv->enetaddr, 6);
624 ret = eepro100_txcmd_send(priv, ias_cmd);
626 if (ret == -ETIMEDOUT)
627 printf("Error: Can not reset ethernet controller.\n");
637 static int eepro100_send_common(struct eepro100_priv *priv,
638 void *packet, int length)
640 struct eepro100_txfd *tx_ring = priv->tx_ring;
641 struct eepro100_txfd *desc;
642 int ret, status = -1;
646 printf("%s: bad packet size: %d\n", priv->name, length);
650 tx_cur = priv->tx_next;
651 priv->tx_next = (priv->tx_next + 1) % NUM_TX_DESC;
653 desc = &tx_ring[tx_cur];
654 desc->command = cpu_to_le16(TXCB_CMD_TRANSMIT | TXCB_CMD_SF |
655 TXCB_CMD_S | TXCB_CMD_EL);
657 desc->count = cpu_to_le32(priv->tx_threshold);
658 desc->link = cpu_to_le32(phys_to_bus(priv->devno,
659 (u32)&tx_ring[priv->tx_next]));
660 desc->tx_desc_addr = cpu_to_le32(phys_to_bus(priv->devno,
661 (u32)&desc->tx_buf_addr0));
662 desc->tx_buf_addr0 = cpu_to_le32(phys_to_bus(priv->devno,
664 desc->tx_buf_size0 = cpu_to_le32(length);
666 ret = eepro100_txcmd_send(priv, &tx_ring[tx_cur]);
668 if (ret == -ETIMEDOUT)
669 printf("%s: Tx error ethernet controller not ready.\n",
680 static int eepro100_recv_common(struct eepro100_priv *priv, uchar **packetp)
682 struct eepro100_rxfd *rx_ring = priv->rx_ring;
683 struct eepro100_rxfd *desc;
687 priv->rx_stat = INW(priv, SCB_STATUS);
688 OUTW(priv, priv->rx_stat & SCB_STATUS_RNR, SCB_STATUS);
690 desc = &rx_ring[priv->rx_next];
691 invalidate_dcache_range((unsigned long)desc,
692 (unsigned long)desc + sizeof(*desc));
693 status = le16_to_cpu(desc->status);
695 if (!(status & RFD_STATUS_C))
698 /* Valid frame status. */
699 if (status & RFD_STATUS_OK) {
700 /* A valid frame received. */
701 length = le32_to_cpu(desc->count) & 0x3fff;
702 /* Pass the packet up to the protocol layers. */
703 *packetp = desc->data;
707 /* There was an error. */
708 printf("RX error status = 0x%08X\n", status);
712 static void eepro100_free_pkt_common(struct eepro100_priv *priv)
714 struct eepro100_rxfd *rx_ring = priv->rx_ring;
715 struct eepro100_rxfd *desc;
718 desc = &rx_ring[priv->rx_next];
720 desc->control = cpu_to_le16(RFD_CONTROL_S);
722 desc->count = cpu_to_le32(PKTSIZE_ALIGN << 16);
723 flush_dcache_range((unsigned long)desc,
724 (unsigned long)desc + sizeof(*desc));
726 rx_prev = (priv->rx_next + NUM_RX_DESC - 1) % NUM_RX_DESC;
727 desc = &rx_ring[rx_prev];
729 flush_dcache_range((unsigned long)desc,
730 (unsigned long)desc + sizeof(*desc));
732 /* Update entry information. */
733 priv->rx_next = (priv->rx_next + 1) % NUM_RX_DESC;
735 if (!(priv->rx_stat & SCB_STATUS_RNR))
738 printf("%s: Receiver is not ready, restart it !\n", priv->name);
740 /* Reinitialize Rx ring. */
743 if (!wait_for_eepro100(priv)) {
744 printf("Error: Can not restart ethernet controller.\n");
748 /* RX ring cache was already flushed in init_rx_ring() */
749 OUTL(priv, phys_to_bus(priv->devno, (u32)&rx_ring[priv->rx_next]),
751 OUTW(priv, SCB_M | RUC_START, SCB_CMD);
754 static void eepro100_halt_common(struct eepro100_priv *priv)
756 /* Reset the ethernet controller */
757 OUTL(priv, I82559_SELECTIVE_RESET, SCB_PORT);
760 OUTL(priv, I82559_RESET, SCB_PORT);
763 if (!wait_for_eepro100(priv)) {
764 printf("Error: Can not reset ethernet controller.\n");
767 OUTL(priv, 0, SCB_POINTER);
768 OUTW(priv, SCB_M | RUC_ADDR_LOAD, SCB_CMD);
770 if (!wait_for_eepro100(priv)) {
771 printf("Error: Can not reset ethernet controller.\n");
774 OUTL(priv, 0, SCB_POINTER);
775 OUTW(priv, SCB_M | CU_ADDR_LOAD, SCB_CMD);
781 #ifndef CONFIG_DM_ETH
782 static int eepro100_init(struct eth_device *dev, bd_t *bis)
784 struct eepro100_priv *priv =
785 container_of(dev, struct eepro100_priv, dev);
787 return eepro100_init_common(priv);
790 static void eepro100_halt(struct eth_device *dev)
792 struct eepro100_priv *priv =
793 container_of(dev, struct eepro100_priv, dev);
795 eepro100_halt_common(priv);
798 static int eepro100_send(struct eth_device *dev, void *packet, int length)
800 struct eepro100_priv *priv =
801 container_of(dev, struct eepro100_priv, dev);
803 return eepro100_send_common(priv, packet, length);
806 static int eepro100_recv(struct eth_device *dev)
808 struct eepro100_priv *priv =
809 container_of(dev, struct eepro100_priv, dev);
813 ret = eepro100_recv_common(priv, &packet);
815 net_process_received_packet(packet, ret);
817 eepro100_free_pkt_common(priv);
822 int eepro100_initialize(bd_t *bis)
824 struct eepro100_priv *priv;
825 struct eth_device *dev;
833 /* Find PCI device */
834 devno = pci_find_devices(supported, idx++);
838 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &iobase);
841 debug("eepro100: Intel i82559 PCI EtherExpressPro @0x%x\n",
844 pci_write_config_dword(devno, PCI_COMMAND,
845 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
847 /* Check if I/O accesses and Bus Mastering are enabled. */
848 pci_read_config_dword(devno, PCI_COMMAND, &status);
849 if (!(status & PCI_COMMAND_MEMORY)) {
850 printf("Error: Can not enable MEM access.\n");
854 if (!(status & PCI_COMMAND_MASTER)) {
855 printf("Error: Can not enable Bus Mastering.\n");
859 priv = calloc(1, sizeof(*priv));
861 printf("eepro100: Can not allocate memory\n");
866 sprintf(dev->name, "i82559#%d", card_number);
867 priv->name = dev->name;
868 /* this have to come before bus_to_phys() */
870 priv->iobase = (void __iomem *)bus_to_phys(devno, iobase);
871 priv->enetaddr = dev->enetaddr;
873 dev->init = eepro100_init;
874 dev->halt = eepro100_halt;
875 dev->send = eepro100_send;
876 dev->recv = eepro100_recv;
880 ret = eepro100_initialize_mii(priv);
889 /* Set the latency timer for value. */
890 pci_write_config_byte(devno, PCI_LATENCY_TIMER, 0x20);
894 eepro100_get_hwaddr(priv);
901 static int eepro100_start(struct udevice *dev)
903 struct eth_pdata *plat = dev_get_platdata(dev);
904 struct eepro100_priv *priv = dev_get_priv(dev);
906 memcpy(priv->enetaddr, plat->enetaddr, sizeof(plat->enetaddr));
908 return eepro100_init_common(priv);
911 static void eepro100_stop(struct udevice *dev)
913 struct eepro100_priv *priv = dev_get_priv(dev);
915 eepro100_halt_common(priv);
918 static int eepro100_send(struct udevice *dev, void *packet, int length)
920 struct eepro100_priv *priv = dev_get_priv(dev);
923 ret = eepro100_send_common(priv, packet, length);
925 return ret ? 0 : -ETIMEDOUT;
928 static int eepro100_recv(struct udevice *dev, int flags, uchar **packetp)
930 struct eepro100_priv *priv = dev_get_priv(dev);
932 return eepro100_recv_common(priv, packetp);
935 static int eepro100_free_pkt(struct udevice *dev, uchar *packet, int length)
937 struct eepro100_priv *priv = dev_get_priv(dev);
939 eepro100_free_pkt_common(priv);
944 static int eepro100_read_rom_hwaddr(struct udevice *dev)
946 struct eepro100_priv *priv = dev_get_priv(dev);
948 eepro100_get_hwaddr(priv);
953 static int eepro100_bind(struct udevice *dev)
955 static int card_number;
958 sprintf(name, "eepro100#%u", card_number++);
960 return device_set_name(dev, name);
963 static int eepro100_probe(struct udevice *dev)
965 struct eth_pdata *plat = dev_get_platdata(dev);
966 struct eepro100_priv *priv = dev_get_priv(dev);
971 dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase);
974 debug("eepro100: Intel i82559 PCI EtherExpressPro @0x%x\n", iobase);
977 priv->enetaddr = plat->enetaddr;
978 priv->iobase = (void __iomem *)bus_to_phys(dev, iobase);
980 command = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
981 dm_pci_write_config16(dev, PCI_COMMAND, command);
982 dm_pci_read_config16(dev, PCI_COMMAND, &status);
983 if ((status & command) != command) {
984 printf("eepro100: Couldn't enable IO access or Bus Mastering\n");
988 ret = eepro100_initialize_mii(priv);
992 dm_pci_write_config8(dev, PCI_LATENCY_TIMER, 0x20);
997 static const struct eth_ops eepro100_ops = {
998 .start = eepro100_start,
999 .send = eepro100_send,
1000 .recv = eepro100_recv,
1001 .stop = eepro100_stop,
1002 .free_pkt = eepro100_free_pkt,
1003 .read_rom_hwaddr = eepro100_read_rom_hwaddr,
1006 U_BOOT_DRIVER(eth_eepro100) = {
1007 .name = "eth_eepro100",
1009 .bind = eepro100_bind,
1010 .probe = eepro100_probe,
1011 .ops = &eepro100_ops,
1012 .priv_auto_alloc_size = sizeof(struct eepro100_priv),
1013 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
1016 U_BOOT_PCI_DEVICE(eth_eepro100, supported);