Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <malloc.h> |
| 9 | #include <net.h> |
Ben Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 10 | #include <netdev.h> |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <pci.h> |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 13 | #include <miiphy.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 14 | #include <linux/delay.h> |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 15 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 16 | /* Ethernet chip registers. */ |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 17 | #define SCB_STATUS 0 /* Rx/Command Unit Status *Word* */ |
| 18 | #define SCB_INT_ACK_BYTE 1 /* Rx/Command Unit STAT/ACK byte */ |
| 19 | #define SCB_CMD 2 /* Rx/Command Unit Command *Word* */ |
| 20 | #define SCB_INTR_CTL_BYTE 3 /* Rx/Command Unit Intr.Control Byte */ |
| 21 | #define SCB_POINTER 4 /* General purpose pointer. */ |
| 22 | #define SCB_PORT 8 /* Misc. commands and operands. */ |
| 23 | #define SCB_FLASH 12 /* Flash memory control. */ |
| 24 | #define SCB_EEPROM 14 /* EEPROM memory control. */ |
| 25 | #define SCB_CTRL_MDI 16 /* MDI interface control. */ |
| 26 | #define SCB_EARLY_RX 20 /* Early receive byte count. */ |
| 27 | #define SCB_GEN_CONTROL 28 /* 82559 General Control Register */ |
| 28 | #define SCB_GEN_STATUS 29 /* 82559 General Status register */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 29 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 30 | /* 82559 SCB status word defnitions */ |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 31 | #define SCB_STATUS_CX 0x8000 /* CU finished command (transmit) */ |
| 32 | #define SCB_STATUS_FR 0x4000 /* frame received */ |
| 33 | #define SCB_STATUS_CNA 0x2000 /* CU left active state */ |
| 34 | #define SCB_STATUS_RNR 0x1000 /* receiver left ready state */ |
| 35 | #define SCB_STATUS_MDI 0x0800 /* MDI read/write cycle done */ |
| 36 | #define SCB_STATUS_SWI 0x0400 /* software generated interrupt */ |
| 37 | #define SCB_STATUS_FCP 0x0100 /* flow control pause interrupt */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 38 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 39 | #define SCB_INTACK_MASK 0xFD00 /* all the above */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 40 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 41 | #define SCB_INTACK_TX (SCB_STATUS_CX | SCB_STATUS_CNA) |
| 42 | #define SCB_INTACK_RX (SCB_STATUS_FR | SCB_STATUS_RNR) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 43 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 44 | /* System control block commands */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 45 | /* CU Commands */ |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 46 | #define CU_NOP 0x0000 |
| 47 | #define CU_START 0x0010 |
| 48 | #define CU_RESUME 0x0020 |
| 49 | #define CU_STATSADDR 0x0040 /* Load Dump Statistics ctrs addr */ |
| 50 | #define CU_SHOWSTATS 0x0050 /* Dump statistics counters. */ |
| 51 | #define CU_ADDR_LOAD 0x0060 /* Base address to add to CU commands */ |
| 52 | #define CU_DUMPSTATS 0x0070 /* Dump then reset stats counters. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 53 | |
| 54 | /* RUC Commands */ |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 55 | #define RUC_NOP 0x0000 |
| 56 | #define RUC_START 0x0001 |
| 57 | #define RUC_RESUME 0x0002 |
| 58 | #define RUC_ABORT 0x0004 |
| 59 | #define RUC_ADDR_LOAD 0x0006 /* (seems not to clear on acceptance) */ |
| 60 | #define RUC_RESUMENR 0x0007 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 61 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 62 | #define CU_CMD_MASK 0x00f0 |
| 63 | #define RU_CMD_MASK 0x0007 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 64 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 65 | #define SCB_M 0x0100 /* 0 = enable interrupt, 1 = disable */ |
| 66 | #define SCB_SWI 0x0200 /* 1 - cause device to interrupt */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 67 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 68 | #define CU_STATUS_MASK 0x00C0 |
| 69 | #define RU_STATUS_MASK 0x003C |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 70 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 71 | #define RU_STATUS_IDLE (0 << 2) |
| 72 | #define RU_STATUS_SUS (1 << 2) |
| 73 | #define RU_STATUS_NORES (2 << 2) |
| 74 | #define RU_STATUS_READY (4 << 2) |
| 75 | #define RU_STATUS_NO_RBDS_SUS ((1 << 2) | (8 << 2)) |
| 76 | #define RU_STATUS_NO_RBDS_NORES ((2 << 2) | (8 << 2)) |
| 77 | #define RU_STATUS_NO_RBDS_READY ((4 << 2) | (8 << 2)) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 78 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 79 | /* 82559 Port interface commands. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 80 | #define I82559_RESET 0x00000000 /* Software reset */ |
| 81 | #define I82559_SELFTEST 0x00000001 /* 82559 Selftest command */ |
| 82 | #define I82559_SELECTIVE_RESET 0x00000002 |
| 83 | #define I82559_DUMP 0x00000003 |
| 84 | #define I82559_DUMP_WAKEUP 0x00000007 |
| 85 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 86 | /* 82559 Eeprom interface. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 87 | #define EE_SHIFT_CLK 0x01 /* EEPROM shift clock. */ |
| 88 | #define EE_CS 0x02 /* EEPROM chip select. */ |
| 89 | #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */ |
| 90 | #define EE_WRITE_0 0x01 |
| 91 | #define EE_WRITE_1 0x05 |
| 92 | #define EE_DATA_READ 0x08 /* EEPROM chip data out. */ |
| 93 | #define EE_ENB (0x4800 | EE_CS) |
| 94 | #define EE_CMD_BITS 3 |
| 95 | #define EE_DATA_BITS 16 |
| 96 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 97 | /* The EEPROM commands include the alway-set leading bit. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 98 | #define EE_EWENB_CMD (4 << addr_len) |
| 99 | #define EE_WRITE_CMD (5 << addr_len) |
| 100 | #define EE_READ_CMD (6 << addr_len) |
| 101 | #define EE_ERASE_CMD (7 << addr_len) |
| 102 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 103 | /* Receive frame descriptors. */ |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 104 | struct eepro100_rxfd { |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 105 | volatile u16 status; |
| 106 | volatile u16 control; |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 107 | volatile u32 link; /* struct eepro100_rxfd * */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 108 | volatile u32 rx_buf_addr; /* void * */ |
| 109 | volatile u32 count; |
| 110 | |
| 111 | volatile u8 data[PKTSIZE_ALIGN]; |
| 112 | }; |
| 113 | |
| 114 | #define RFD_STATUS_C 0x8000 /* completion of received frame */ |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 115 | #define RFD_STATUS_OK 0x2000 /* frame received with no errors */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 116 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 117 | #define RFD_CONTROL_EL 0x8000 /* 1=last RFD in RFA */ |
| 118 | #define RFD_CONTROL_S 0x4000 /* 1=suspend RU after receiving frame */ |
| 119 | #define RFD_CONTROL_H 0x0010 /* 1=RFD is a header RFD */ |
| 120 | #define RFD_CONTROL_SF 0x0008 /* 0=simplified, 1=flexible mode */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 121 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 122 | #define RFD_COUNT_MASK 0x3fff |
| 123 | #define RFD_COUNT_F 0x4000 |
| 124 | #define RFD_COUNT_EOF 0x8000 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 125 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 126 | #define RFD_RX_CRC 0x0800 /* crc error */ |
| 127 | #define RFD_RX_ALIGNMENT 0x0400 /* alignment error */ |
| 128 | #define RFD_RX_RESOURCE 0x0200 /* out of space, no resources */ |
| 129 | #define RFD_RX_DMA_OVER 0x0100 /* DMA overrun */ |
| 130 | #define RFD_RX_SHORT 0x0080 /* short frame error */ |
| 131 | #define RFD_RX_LENGTH 0x0020 |
| 132 | #define RFD_RX_ERROR 0x0010 /* receive error */ |
| 133 | #define RFD_RX_NO_ADR_MATCH 0x0004 /* no address match */ |
| 134 | #define RFD_RX_IA_MATCH 0x0002 /* individual address does not match */ |
| 135 | #define RFD_RX_TCO 0x0001 /* TCO indication */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 136 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 137 | /* Transmit frame descriptors */ |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 138 | struct eepro100_txfd { /* Transmit frame descriptor set. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 139 | volatile u16 status; |
| 140 | volatile u16 command; |
| 141 | volatile u32 link; /* void * */ |
| 142 | volatile u32 tx_desc_addr; /* Always points to the tx_buf_addr element. */ |
| 143 | volatile s32 count; |
| 144 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 145 | volatile u32 tx_buf_addr0; /* void *, frame to be transmitted. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 146 | volatile s32 tx_buf_size0; /* Length of Tx frame. */ |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 147 | volatile u32 tx_buf_addr1; /* void *, frame to be transmitted. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 148 | volatile s32 tx_buf_size1; /* Length of Tx frame. */ |
| 149 | }; |
| 150 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 151 | #define TXCB_CMD_TRANSMIT 0x0004 /* transmit command */ |
| 152 | #define TXCB_CMD_SF 0x0008 /* 0=simplified, 1=flexible mode */ |
| 153 | #define TXCB_CMD_NC 0x0010 /* 0=CRC insert by controller */ |
| 154 | #define TXCB_CMD_I 0x2000 /* generate interrupt on completion */ |
| 155 | #define TXCB_CMD_S 0x4000 /* suspend on completion */ |
| 156 | #define TXCB_CMD_EL 0x8000 /* last command block in CBL */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 157 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 158 | #define TXCB_COUNT_MASK 0x3fff |
| 159 | #define TXCB_COUNT_EOF 0x8000 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 160 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 161 | /* The Speedo3 Rx and Tx frame/buffer descriptors. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 162 | struct descriptor { /* A generic descriptor. */ |
| 163 | volatile u16 status; |
| 164 | volatile u16 command; |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 165 | volatile u32 link; /* struct descriptor * */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 166 | |
| 167 | unsigned char params[0]; |
| 168 | }; |
| 169 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 170 | #define CONFIG_SYS_CMD_EL 0x8000 |
| 171 | #define CONFIG_SYS_CMD_SUSPEND 0x4000 |
| 172 | #define CONFIG_SYS_CMD_INT 0x2000 |
| 173 | #define CONFIG_SYS_CMD_IAS 0x0001 /* individual address setup */ |
| 174 | #define CONFIG_SYS_CMD_CONFIGURE 0x0002 /* configure */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 175 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 176 | #define CONFIG_SYS_STATUS_C 0x8000 |
| 177 | #define CONFIG_SYS_STATUS_OK 0x2000 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 178 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 179 | /* Misc. */ |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 180 | #define NUM_RX_DESC PKTBUFSRX |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 181 | #define NUM_TX_DESC 1 /* Number of TX descriptors */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 182 | |
| 183 | #define TOUT_LOOP 1000000 |
| 184 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 185 | static struct eepro100_rxfd rx_ring[NUM_RX_DESC]; /* RX descriptor ring */ |
| 186 | static struct eepro100_txfd tx_ring[NUM_TX_DESC]; /* TX descriptor ring */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 187 | static int rx_next; /* RX descriptor ring pointer */ |
| 188 | static int tx_next; /* TX descriptor ring pointer */ |
| 189 | static int tx_threshold; |
| 190 | |
| 191 | /* |
| 192 | * The parameters for a CmdConfigure operation. |
| 193 | * There are so many options that it would be difficult to document |
| 194 | * each bit. We mostly use the default or recommended settings. |
| 195 | */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 196 | static const char i82558_config_cmd[] = { |
| 197 | 22, 0x08, 0, 1, 0, 0, 0x22, 0x03, 1, /* 1=Use MII 0=Use AUI */ |
| 198 | 0, 0x2E, 0, 0x60, 0x08, 0x88, |
| 199 | 0x68, 0, 0x40, 0xf2, 0x84, /* Disable FC */ |
| 200 | 0x31, 0x05, |
| 201 | }; |
| 202 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 203 | static void init_rx_ring(struct eth_device *dev); |
| 204 | static void purge_tx_ring(struct eth_device *dev); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 205 | |
Marek Vasut | 7a30873 | 2020-05-23 13:23:13 +0200 | [diff] [blame] | 206 | static void read_hw_addr(struct eth_device *dev, bd_t *bis); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 207 | |
Marek Vasut | 7a30873 | 2020-05-23 13:23:13 +0200 | [diff] [blame] | 208 | static int eepro100_init(struct eth_device *dev, bd_t *bis); |
Joe Hershberger | bccbe61 | 2012-05-21 14:45:25 +0000 | [diff] [blame] | 209 | static int eepro100_send(struct eth_device *dev, void *packet, int length); |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 210 | static int eepro100_recv(struct eth_device *dev); |
| 211 | static void eepro100_halt(struct eth_device *dev); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 212 | |
Wolfgang Denk | 03b0040 | 2014-10-21 15:23:32 +0200 | [diff] [blame] | 213 | #if defined(CONFIG_E500) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 214 | #define bus_to_phys(a) (a) |
| 215 | #define phys_to_bus(a) (a) |
| 216 | #else |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 217 | #define bus_to_phys(a) pci_mem_to_phys((pci_dev_t)dev->priv, a) |
| 218 | #define phys_to_bus(a) pci_phys_to_mem((pci_dev_t)dev->priv, a) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 219 | #endif |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 220 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 221 | static inline int INW(struct eth_device *dev, u_long addr) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 222 | { |
Marek Vasut | 81bdeea | 2020-05-23 14:14:45 +0200 | [diff] [blame] | 223 | return le16_to_cpu(readw(addr + (void *)dev->iobase)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 226 | static inline void OUTW(struct eth_device *dev, int command, u_long addr) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 227 | { |
Marek Vasut | 81bdeea | 2020-05-23 14:14:45 +0200 | [diff] [blame] | 228 | writew(cpu_to_le16(command), addr + (void *)dev->iobase); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 231 | static inline void OUTL(struct eth_device *dev, int command, u_long addr) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 232 | { |
Marek Vasut | 81bdeea | 2020-05-23 14:14:45 +0200 | [diff] [blame] | 233 | writel(cpu_to_le32(command), addr + (void *)dev->iobase); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Jon Loeliger | 07d38a1 | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 236 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 237 | static inline int INL(struct eth_device *dev, u_long addr) |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 238 | { |
Marek Vasut | 81bdeea | 2020-05-23 14:14:45 +0200 | [diff] [blame] | 239 | return le32_to_cpu(readl(addr + (void *)dev->iobase)); |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 240 | } |
| 241 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 242 | static int get_phyreg(struct eth_device *dev, unsigned char addr, |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 243 | unsigned char reg, unsigned short *value) |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 244 | { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 245 | int cmd; |
| 246 | int timeout = 50; |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 247 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 248 | /* read requested data */ |
| 249 | cmd = (2 << 26) | ((addr & 0x1f) << 21) | ((reg & 0x1f) << 16); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 250 | OUTL(dev, cmd, SCB_CTRL_MDI); |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 251 | |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 252 | do { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 253 | udelay(1000); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 254 | cmd = INL(dev, SCB_CTRL_MDI); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 255 | } while (!(cmd & (1 << 28)) && (--timeout)); |
| 256 | |
| 257 | if (timeout == 0) |
| 258 | return -1; |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 259 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 260 | *value = (unsigned short)(cmd & 0xffff); |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 261 | |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 265 | static int set_phyreg(struct eth_device *dev, unsigned char addr, |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 266 | unsigned char reg, unsigned short value) |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 267 | { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 268 | int cmd; |
| 269 | int timeout = 50; |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 270 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 271 | /* write requested data */ |
| 272 | cmd = (1 << 26) | ((addr & 0x1f) << 21) | ((reg & 0x1f) << 16); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 273 | OUTL(dev, cmd | value, SCB_CTRL_MDI); |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 274 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 275 | while (!(INL(dev, SCB_CTRL_MDI) & (1 << 28)) && (--timeout)) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 276 | udelay(1000); |
| 277 | |
| 278 | if (timeout == 0) |
| 279 | return -1; |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 280 | |
| 281 | return 0; |
| 282 | } |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 283 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 284 | /* |
| 285 | * Check if given phyaddr is valid, i.e. there is a PHY connected. |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 286 | * Do this by checking model value field from ID2 register. |
| 287 | */ |
Marek Vasut | 7a30873 | 2020-05-23 13:23:13 +0200 | [diff] [blame] | 288 | static struct eth_device *verify_phyaddr(const char *devname, |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 289 | unsigned char addr) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 290 | { |
| 291 | struct eth_device *dev; |
| 292 | unsigned short value; |
| 293 | unsigned char model; |
| 294 | |
| 295 | dev = eth_get_dev_by_name(devname); |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 296 | if (!dev) { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 297 | printf("%s: no such device\n", devname); |
| 298 | return NULL; |
| 299 | } |
| 300 | |
| 301 | /* read id2 register */ |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 302 | if (get_phyreg(dev, addr, MII_PHYSID2, &value) != 0) { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 303 | printf("%s: mii read timeout!\n", devname); |
| 304 | return NULL; |
| 305 | } |
| 306 | |
| 307 | /* get model */ |
| 308 | model = (unsigned char)((value >> 4) & 0x003f); |
| 309 | |
| 310 | if (model == 0) { |
| 311 | printf("%s: no PHY at address %d\n", devname, addr); |
| 312 | return NULL; |
| 313 | } |
| 314 | |
| 315 | return dev; |
| 316 | } |
| 317 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 318 | static int eepro100_miiphy_read(struct mii_dev *bus, int addr, int devad, |
| 319 | int reg) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 320 | { |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 321 | unsigned short value = 0; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 322 | struct eth_device *dev; |
| 323 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 324 | dev = verify_phyaddr(bus->name, addr); |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 325 | if (!dev) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 326 | return -1; |
| 327 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 328 | if (get_phyreg(dev, addr, reg, &value) != 0) { |
| 329 | printf("%s: mii read timeout!\n", bus->name); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 330 | return -1; |
| 331 | } |
| 332 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 333 | return value; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 334 | } |
| 335 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 336 | static int eepro100_miiphy_write(struct mii_dev *bus, int addr, int devad, |
| 337 | int reg, u16 value) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 338 | { |
| 339 | struct eth_device *dev; |
| 340 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 341 | dev = verify_phyaddr(bus->name, addr); |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 342 | if (!dev) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 343 | return -1; |
| 344 | |
| 345 | if (set_phyreg(dev, addr, reg, value) != 0) { |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 346 | printf("%s: mii write timeout!\n", bus->name); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 347 | return -1; |
| 348 | } |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
Jon Loeliger | 07d38a1 | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 353 | #endif |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 354 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 355 | /* Wait for the chip get the command. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 356 | static int wait_for_eepro100(struct eth_device *dev) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 357 | { |
| 358 | int i; |
| 359 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 360 | for (i = 0; INW(dev, SCB_CMD) & (CU_CMD_MASK | RU_CMD_MASK); i++) { |
Marek Vasut | 9b12ff9 | 2020-05-23 13:20:14 +0200 | [diff] [blame] | 361 | if (i >= TOUT_LOOP) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 362 | return 0; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | return 1; |
| 366 | } |
| 367 | |
| 368 | static struct pci_device_id supported[] = { |
| 369 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82557}, |
| 370 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82559}, |
| 371 | {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82559ER}, |
| 372 | {} |
| 373 | }; |
| 374 | |
Marek Vasut | 7a30873 | 2020-05-23 13:23:13 +0200 | [diff] [blame] | 375 | int eepro100_initialize(bd_t *bis) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 376 | { |
| 377 | pci_dev_t devno; |
| 378 | int card_number = 0; |
| 379 | struct eth_device *dev; |
| 380 | u32 iobase, status; |
| 381 | int idx = 0; |
| 382 | |
| 383 | while (1) { |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 384 | /* Find PCI device */ |
Marek Vasut | 9b12ff9 | 2020-05-23 13:20:14 +0200 | [diff] [blame] | 385 | devno = pci_find_devices(supported, idx++); |
| 386 | if (devno < 0) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 387 | break; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 388 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 389 | pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &iobase); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 390 | iobase &= ~0xf; |
| 391 | |
Marek Vasut | e5352c6 | 2020-05-23 13:11:48 +0200 | [diff] [blame] | 392 | debug("eepro100: Intel i82559 PCI EtherExpressPro @0x%x\n", |
| 393 | iobase); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 394 | |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 395 | pci_write_config_dword(devno, PCI_COMMAND, |
| 396 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 397 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 398 | /* Check if I/O accesses and Bus Mastering are enabled. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 399 | pci_read_config_dword(devno, PCI_COMMAND, &status); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 400 | if (!(status & PCI_COMMAND_MEMORY)) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 401 | printf("Error: Can not enable MEM access.\n"); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 402 | continue; |
| 403 | } |
| 404 | |
| 405 | if (!(status & PCI_COMMAND_MASTER)) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 406 | printf("Error: Can not enable Bus Mastering.\n"); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 407 | continue; |
| 408 | } |
| 409 | |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 410 | dev = (struct eth_device *)malloc(sizeof(*dev)); |
Nobuhiro Iwamatsu | 72c4c33 | 2010-10-19 14:03:41 +0900 | [diff] [blame] | 411 | if (!dev) { |
| 412 | printf("eepro100: Can not allocate memory\n"); |
| 413 | break; |
| 414 | } |
| 415 | memset(dev, 0, sizeof(*dev)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 416 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 417 | sprintf(dev->name, "i82559#%d", card_number); |
| 418 | dev->priv = (void *)devno; /* this have to come before bus_to_phys() */ |
| 419 | dev->iobase = bus_to_phys(iobase); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 420 | dev->init = eepro100_init; |
| 421 | dev->halt = eepro100_halt; |
| 422 | dev->send = eepro100_send; |
| 423 | dev->recv = eepro100_recv; |
| 424 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 425 | eth_register(dev); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 426 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 427 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 428 | /* register mii command access routines */ |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 429 | int retval; |
| 430 | struct mii_dev *mdiodev = mdio_alloc(); |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 431 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 432 | if (!mdiodev) |
| 433 | return -ENOMEM; |
| 434 | strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN); |
| 435 | mdiodev->read = eepro100_miiphy_read; |
| 436 | mdiodev->write = eepro100_miiphy_write; |
| 437 | |
| 438 | retval = mdio_register(mdiodev); |
| 439 | if (retval < 0) |
| 440 | return retval; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 441 | #endif |
| 442 | |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 443 | card_number++; |
| 444 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 445 | /* Set the latency timer for value. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 446 | pci_write_config_byte(devno, PCI_LATENCY_TIMER, 0x20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 447 | |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 448 | udelay(10 * 1000); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 449 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 450 | read_hw_addr(dev, bis); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | return card_number; |
| 454 | } |
| 455 | |
Marek Vasut | 7a30873 | 2020-05-23 13:23:13 +0200 | [diff] [blame] | 456 | static int eepro100_init(struct eth_device *dev, bd_t *bis) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 457 | { |
Ben Warren | 422b1a0 | 2008-01-09 18:15:53 -0500 | [diff] [blame] | 458 | int i, status = -1; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 459 | int tx_cur; |
| 460 | struct descriptor *ias_cmd, *cfg_cmd; |
| 461 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 462 | /* Reset the ethernet controller */ |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 463 | OUTL(dev, I82559_SELECTIVE_RESET, SCB_PORT); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 464 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 465 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 466 | OUTL(dev, I82559_RESET, SCB_PORT); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 467 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 468 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 469 | if (!wait_for_eepro100(dev)) { |
| 470 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 471 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 472 | } |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 473 | OUTL(dev, 0, SCB_POINTER); |
| 474 | OUTW(dev, SCB_M | RUC_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 475 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 476 | if (!wait_for_eepro100(dev)) { |
| 477 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 478 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 479 | } |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 480 | OUTL(dev, 0, SCB_POINTER); |
| 481 | OUTW(dev, SCB_M | CU_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 482 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 483 | /* Initialize Rx and Tx rings. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 484 | init_rx_ring(dev); |
| 485 | purge_tx_ring(dev); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 486 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 487 | /* Tell the adapter where the RX ring is located. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 488 | if (!wait_for_eepro100(dev)) { |
| 489 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 490 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 493 | OUTL(dev, phys_to_bus((u32)&rx_ring[rx_next]), SCB_POINTER); |
| 494 | OUTW(dev, SCB_M | RUC_START, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 495 | |
| 496 | /* Send the Configure frame */ |
| 497 | tx_cur = tx_next; |
| 498 | tx_next = ((tx_next + 1) % NUM_TX_DESC); |
| 499 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 500 | cfg_cmd = (struct descriptor *)&tx_ring[tx_cur]; |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 501 | cfg_cmd->command = cpu_to_le16(CONFIG_SYS_CMD_SUSPEND | |
| 502 | CONFIG_SYS_CMD_CONFIGURE); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 503 | cfg_cmd->status = 0; |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 504 | cfg_cmd->link = cpu_to_le32(phys_to_bus((u32)&tx_ring[tx_next])); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 505 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 506 | memcpy(cfg_cmd->params, i82558_config_cmd, |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 507 | sizeof(i82558_config_cmd)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 508 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 509 | if (!wait_for_eepro100(dev)) { |
| 510 | printf("Error---CONFIG_SYS_CMD_CONFIGURE: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 511 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 514 | OUTL(dev, phys_to_bus((u32)&tx_ring[tx_cur]), SCB_POINTER); |
| 515 | OUTW(dev, SCB_M | CU_START, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 516 | |
| 517 | for (i = 0; |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 518 | !(le16_to_cpu(tx_ring[tx_cur].status) & CONFIG_SYS_STATUS_C); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 519 | i++) { |
| 520 | if (i >= TOUT_LOOP) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 521 | printf("%s: Tx error buffer not ready\n", dev->name); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 522 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 526 | if (!(le16_to_cpu(tx_ring[tx_cur].status) & CONFIG_SYS_STATUS_OK)) { |
| 527 | printf("TX error status = 0x%08X\n", |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 528 | le16_to_cpu(tx_ring[tx_cur].status)); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 529 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 532 | /* Send the Individual Address Setup frame */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 533 | tx_cur = tx_next; |
| 534 | tx_next = ((tx_next + 1) % NUM_TX_DESC); |
| 535 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 536 | ias_cmd = (struct descriptor *)&tx_ring[tx_cur]; |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 537 | ias_cmd->command = cpu_to_le16(CONFIG_SYS_CMD_SUSPEND | |
| 538 | CONFIG_SYS_CMD_IAS); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 539 | ias_cmd->status = 0; |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 540 | ias_cmd->link = cpu_to_le32(phys_to_bus((u32)&tx_ring[tx_next])); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 541 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 542 | memcpy(ias_cmd->params, dev->enetaddr, 6); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 543 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 544 | /* Tell the adapter where the TX ring is located. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 545 | if (!wait_for_eepro100(dev)) { |
| 546 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 547 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 550 | OUTL(dev, phys_to_bus((u32)&tx_ring[tx_cur]), SCB_POINTER); |
| 551 | OUTW(dev, SCB_M | CU_START, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 552 | |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 553 | for (i = 0; |
| 554 | !(le16_to_cpu(tx_ring[tx_cur].status) & CONFIG_SYS_STATUS_C); |
| 555 | i++) { |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 556 | if (i >= TOUT_LOOP) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 557 | printf("%s: Tx error buffer not ready\n", |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 558 | dev->name); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 559 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 563 | if (!(le16_to_cpu(tx_ring[tx_cur].status) & CONFIG_SYS_STATUS_OK)) { |
| 564 | printf("TX error status = 0x%08X\n", |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 565 | le16_to_cpu(tx_ring[tx_cur].status)); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 566 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Ben Warren | 422b1a0 | 2008-01-09 18:15:53 -0500 | [diff] [blame] | 569 | status = 0; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 570 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 571 | done: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 572 | return status; |
| 573 | } |
| 574 | |
Joe Hershberger | bccbe61 | 2012-05-21 14:45:25 +0000 | [diff] [blame] | 575 | static int eepro100_send(struct eth_device *dev, void *packet, int length) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 576 | { |
| 577 | int i, status = -1; |
| 578 | int tx_cur; |
| 579 | |
| 580 | if (length <= 0) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 581 | printf("%s: bad packet size: %d\n", dev->name, length); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 582 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | tx_cur = tx_next; |
| 586 | tx_next = (tx_next + 1) % NUM_TX_DESC; |
| 587 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 588 | tx_ring[tx_cur].command = cpu_to_le16(TXCB_CMD_TRANSMIT | TXCB_CMD_SF | |
| 589 | TXCB_CMD_S | TXCB_CMD_EL); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 590 | tx_ring[tx_cur].status = 0; |
| 591 | tx_ring[tx_cur].count = cpu_to_le32 (tx_threshold); |
| 592 | tx_ring[tx_cur].link = |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 593 | cpu_to_le32 (phys_to_bus((u32)&tx_ring[tx_next])); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 594 | tx_ring[tx_cur].tx_desc_addr = |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 595 | cpu_to_le32 (phys_to_bus((u32)&tx_ring[tx_cur].tx_buf_addr0)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 596 | tx_ring[tx_cur].tx_buf_addr0 = |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 597 | cpu_to_le32 (phys_to_bus((u_long)packet)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 598 | tx_ring[tx_cur].tx_buf_size0 = cpu_to_le32 (length); |
| 599 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 600 | if (!wait_for_eepro100(dev)) { |
| 601 | printf("%s: Tx error ethernet controller not ready.\n", |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 602 | dev->name); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 603 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 606 | /* Send the packet. */ |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 607 | OUTL(dev, phys_to_bus((u32)&tx_ring[tx_cur]), SCB_POINTER); |
| 608 | OUTW(dev, SCB_M | CU_START, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 609 | |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 610 | for (i = 0; |
| 611 | !(le16_to_cpu(tx_ring[tx_cur].status) & CONFIG_SYS_STATUS_C); |
| 612 | i++) { |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 613 | if (i >= TOUT_LOOP) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 614 | printf("%s: Tx error buffer not ready\n", dev->name); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 615 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 619 | if (!(le16_to_cpu(tx_ring[tx_cur].status) & CONFIG_SYS_STATUS_OK)) { |
| 620 | printf("TX error status = 0x%08X\n", |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 621 | le16_to_cpu(tx_ring[tx_cur].status)); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 622 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | status = length; |
| 626 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 627 | done: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 628 | return status; |
| 629 | } |
| 630 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 631 | static int eepro100_recv(struct eth_device *dev) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 632 | { |
| 633 | u16 status, stat; |
| 634 | int rx_prev, length = 0; |
| 635 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 636 | stat = INW(dev, SCB_STATUS); |
| 637 | OUTW(dev, stat & SCB_STATUS_RNR, SCB_STATUS); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 638 | |
| 639 | for (;;) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 640 | status = le16_to_cpu(rx_ring[rx_next].status); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 641 | |
Marek Vasut | 9b12ff9 | 2020-05-23 13:20:14 +0200 | [diff] [blame] | 642 | if (!(status & RFD_STATUS_C)) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 643 | break; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 644 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 645 | /* Valid frame status. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 646 | if ((status & RFD_STATUS_OK)) { |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 647 | /* A valid frame received. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 648 | length = le32_to_cpu(rx_ring[rx_next].count) & 0x3fff; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 649 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 650 | /* Pass the packet up to the protocol layers. */ |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 651 | net_process_received_packet((u8 *)rx_ring[rx_next].data, |
| 652 | length); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 653 | } else { |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 654 | /* There was an error. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 655 | printf("RX error status = 0x%08X\n", status); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | rx_ring[rx_next].control = cpu_to_le16 (RFD_CONTROL_S); |
| 659 | rx_ring[rx_next].status = 0; |
| 660 | rx_ring[rx_next].count = cpu_to_le32 (PKTSIZE_ALIGN << 16); |
| 661 | |
| 662 | rx_prev = (rx_next + NUM_RX_DESC - 1) % NUM_RX_DESC; |
| 663 | rx_ring[rx_prev].control = 0; |
| 664 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 665 | /* Update entry information. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 666 | rx_next = (rx_next + 1) % NUM_RX_DESC; |
| 667 | } |
| 668 | |
| 669 | if (stat & SCB_STATUS_RNR) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 670 | printf("%s: Receiver is not ready, restart it !\n", dev->name); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 671 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 672 | /* Reinitialize Rx ring. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 673 | init_rx_ring(dev); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 674 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 675 | if (!wait_for_eepro100(dev)) { |
| 676 | printf("Error: Can not restart ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 677 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 680 | OUTL(dev, phys_to_bus((u32)&rx_ring[rx_next]), SCB_POINTER); |
| 681 | OUTW(dev, SCB_M | RUC_START, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 684 | done: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 685 | return length; |
| 686 | } |
| 687 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 688 | static void eepro100_halt(struct eth_device *dev) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 689 | { |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 690 | /* Reset the ethernet controller */ |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 691 | OUTL(dev, I82559_SELECTIVE_RESET, SCB_PORT); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 692 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 693 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 694 | OUTL(dev, I82559_RESET, SCB_PORT); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 695 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 696 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 697 | if (!wait_for_eepro100(dev)) { |
| 698 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 699 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 700 | } |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 701 | OUTL(dev, 0, SCB_POINTER); |
| 702 | OUTW(dev, SCB_M | RUC_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 703 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 704 | if (!wait_for_eepro100(dev)) { |
| 705 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 706 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 707 | } |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 708 | OUTL(dev, 0, SCB_POINTER); |
| 709 | OUTW(dev, SCB_M | CU_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 710 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 711 | done: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 715 | /* SROM Read. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 716 | static int read_eeprom(struct eth_device *dev, int location, int addr_len) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 717 | { |
| 718 | unsigned short retval = 0; |
| 719 | int read_cmd = location | EE_READ_CMD; |
| 720 | int i; |
| 721 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 722 | OUTW(dev, EE_ENB & ~EE_CS, SCB_EEPROM); |
| 723 | OUTW(dev, EE_ENB, SCB_EEPROM); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 724 | |
| 725 | /* Shift the read command bits out. */ |
| 726 | for (i = 12; i >= 0; i--) { |
| 727 | short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; |
| 728 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 729 | OUTW(dev, EE_ENB | dataval, SCB_EEPROM); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 730 | udelay(1); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 731 | OUTW(dev, EE_ENB | dataval | EE_SHIFT_CLK, SCB_EEPROM); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 732 | udelay(1); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 733 | } |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 734 | OUTW(dev, EE_ENB, SCB_EEPROM); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 735 | |
| 736 | for (i = 15; i >= 0; i--) { |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 737 | OUTW(dev, EE_ENB | EE_SHIFT_CLK, SCB_EEPROM); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 738 | udelay(1); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 739 | retval = (retval << 1) | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 740 | ((INW(dev, SCB_EEPROM) & EE_DATA_READ) ? 1 : 0); |
| 741 | OUTW(dev, EE_ENB, SCB_EEPROM); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 742 | udelay(1); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /* Terminate the EEPROM access. */ |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 746 | OUTW(dev, EE_ENB & ~EE_CS, SCB_EEPROM); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 747 | return retval; |
| 748 | } |
| 749 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 750 | static void init_rx_ring(struct eth_device *dev) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 751 | { |
| 752 | int i; |
| 753 | |
| 754 | for (i = 0; i < NUM_RX_DESC; i++) { |
| 755 | rx_ring[i].status = 0; |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 756 | rx_ring[i].control = (i == NUM_RX_DESC - 1) ? |
| 757 | cpu_to_le16 (RFD_CONTROL_S) : 0; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 758 | rx_ring[i].link = |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 759 | cpu_to_le32(phys_to_bus((u32)&rx_ring[(i + 1) % |
| 760 | NUM_RX_DESC])); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 761 | rx_ring[i].rx_buf_addr = 0xffffffff; |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 762 | rx_ring[i].count = cpu_to_le32(PKTSIZE_ALIGN << 16); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | rx_next = 0; |
| 766 | } |
| 767 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 768 | static void purge_tx_ring(struct eth_device *dev) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 769 | { |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 770 | tx_next = 0; |
| 771 | tx_threshold = 0x01208000; |
Marek Vasut | 46df32e | 2020-05-23 14:26:16 +0200 | [diff] [blame^] | 772 | memset(tx_ring, 0, sizeof(*tx_ring) * NUM_TX_DESC); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 773 | } |
| 774 | |
Marek Vasut | 7a30873 | 2020-05-23 13:23:13 +0200 | [diff] [blame] | 775 | static void read_hw_addr(struct eth_device *dev, bd_t *bis) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 776 | { |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 777 | u16 sum = 0; |
| 778 | int i, j; |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 779 | int addr_len = read_eeprom(dev, 0, 6) == 0xffff ? 8 : 6; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 780 | |
| 781 | for (j = 0, i = 0; i < 0x40; i++) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 782 | u16 value = read_eeprom(dev, i, addr_len); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 783 | |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 784 | sum += value; |
| 785 | if (i < 3) { |
| 786 | dev->enetaddr[j++] = value; |
| 787 | dev->enetaddr[j++] = value >> 8; |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | if (sum != 0xBABA) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 792 | memset(dev->enetaddr, 0, ETH_ALEN); |
Marek Vasut | e5352c6 | 2020-05-23 13:11:48 +0200 | [diff] [blame] | 793 | debug("%s: Invalid EEPROM checksum %#4.4x, check settings before activating this device!\n", |
| 794 | dev->name, sum); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 795 | } |
| 796 | } |