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> |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 8 | #include <asm/io.h> |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 9 | #include <cpu_func.h> |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 10 | #include <malloc.h> |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 11 | #include <miiphy.h> |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 12 | #include <net.h> |
Ben Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 13 | #include <netdev.h> |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 14 | #include <pci.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 15 | #include <linux/delay.h> |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 16 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 17 | /* Ethernet chip registers. */ |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 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 */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 30 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 31 | /* 82559 SCB status word defnitions */ |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 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 */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 39 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 40 | #define SCB_INTACK_MASK 0xFD00 /* all the above */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 41 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 42 | #define SCB_INTACK_TX (SCB_STATUS_CX | SCB_STATUS_CNA) |
| 43 | #define SCB_INTACK_RX (SCB_STATUS_FR | SCB_STATUS_RNR) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 44 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 45 | /* System control block commands */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 46 | /* CU Commands */ |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 47 | #define CU_NOP 0x0000 |
| 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. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 54 | |
| 55 | /* RUC Commands */ |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 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 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 62 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 63 | #define CU_CMD_MASK 0x00f0 |
| 64 | #define RU_CMD_MASK 0x0007 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 65 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 66 | #define SCB_M 0x0100 /* 0 = enable interrupt, 1 = disable */ |
| 67 | #define SCB_SWI 0x0200 /* 1 - cause device to interrupt */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 68 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 69 | #define CU_STATUS_MASK 0x00C0 |
| 70 | #define RU_STATUS_MASK 0x003C |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 71 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 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)) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 79 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 80 | /* 82559 Port interface commands. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 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 |
| 86 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 87 | /* 82559 Eeprom interface. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 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) |
| 95 | #define EE_CMD_BITS 3 |
| 96 | #define EE_DATA_BITS 16 |
| 97 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 98 | /* The EEPROM commands include the alway-set leading bit. */ |
Marek Vasut | a6c06ec | 2020-05-23 16:23:28 +0200 | [diff] [blame] | 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)) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 103 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 104 | /* Receive frame descriptors. */ |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 105 | struct eepro100_rxfd { |
Marek Vasut | d47cf87 | 2020-05-23 15:02:47 +0200 | [diff] [blame] | 106 | u16 status; |
| 107 | u16 control; |
| 108 | u32 link; /* struct eepro100_rxfd * */ |
| 109 | u32 rx_buf_addr; /* void * */ |
| 110 | u32 count; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 111 | |
Marek Vasut | d47cf87 | 2020-05-23 15:02:47 +0200 | [diff] [blame] | 112 | u8 data[PKTSIZE_ALIGN]; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | #define RFD_STATUS_C 0x8000 /* completion of received frame */ |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 116 | #define RFD_STATUS_OK 0x2000 /* frame received with no errors */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 117 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 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 */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 122 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 123 | #define RFD_COUNT_MASK 0x3fff |
| 124 | #define RFD_COUNT_F 0x4000 |
| 125 | #define RFD_COUNT_EOF 0x8000 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 126 | |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 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 */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 137 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 138 | /* Transmit frame descriptors */ |
Marek Vasut | d47cf87 | 2020-05-23 15:02:47 +0200 | [diff] [blame] | 139 | struct eepro100_txfd { /* Transmit frame descriptor set. */ |
| 140 | u16 status; |
| 141 | u16 command; |
| 142 | u32 link; /* void * */ |
| 143 | u32 tx_desc_addr; /* Always points to the tx_buf_addr element. */ |
| 144 | s32 count; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 145 | |
Marek Vasut | d47cf87 | 2020-05-23 15:02:47 +0200 | [diff] [blame] | 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. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 150 | }; |
| 151 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 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 */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 158 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 159 | #define TXCB_COUNT_MASK 0x3fff |
| 160 | #define TXCB_COUNT_EOF 0x8000 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 161 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 162 | /* The Speedo3 Rx and Tx frame/buffer descriptors. */ |
Marek Vasut | d47cf87 | 2020-05-23 15:02:47 +0200 | [diff] [blame] | 163 | struct descriptor { /* A generic descriptor. */ |
| 164 | u16 status; |
| 165 | u16 command; |
| 166 | u32 link; /* struct descriptor * */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 167 | |
| 168 | unsigned char params[0]; |
| 169 | }; |
| 170 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 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 */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 176 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 177 | #define CONFIG_SYS_STATUS_C 0x8000 |
| 178 | #define CONFIG_SYS_STATUS_OK 0x2000 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 179 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 180 | /* Misc. */ |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 181 | #define NUM_RX_DESC PKTBUFSRX |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 182 | #define NUM_TX_DESC 1 /* Number of TX descriptors */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 183 | |
| 184 | #define TOUT_LOOP 1000000 |
| 185 | |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 186 | /* |
| 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. |
| 190 | */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 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 */ |
| 195 | 0x31, 0x05, |
| 196 | }; |
| 197 | |
Marek Vasut | bd159c6 | 2020-05-23 16:49:07 +0200 | [diff] [blame] | 198 | struct eepro100_priv { |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 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 */ |
| 204 | int rx_next; |
| 205 | /* TX descriptor ring pointer */ |
| 206 | int tx_next; |
| 207 | int tx_threshold; |
Marek Vasut | bd159c6 | 2020-05-23 16:49:07 +0200 | [diff] [blame] | 208 | struct eth_device dev; |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 209 | pci_dev_t devno; |
| 210 | char *name; |
| 211 | void __iomem *iobase; |
| 212 | u8 *enetaddr; |
Marek Vasut | bd159c6 | 2020-05-23 16:49:07 +0200 | [diff] [blame] | 213 | }; |
| 214 | |
Wolfgang Denk | 03b0040 | 2014-10-21 15:23:32 +0200 | [diff] [blame] | 215 | #if defined(CONFIG_E500) |
Marek Vasut | fa9e121 | 2020-05-23 16:38:41 +0200 | [diff] [blame] | 216 | #define bus_to_phys(dev, a) (a) |
| 217 | #define phys_to_bus(dev, a) (a) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 218 | #else |
Marek Vasut | fa9e121 | 2020-05-23 16:38:41 +0200 | [diff] [blame] | 219 | #define bus_to_phys(dev, a) pci_mem_to_phys((dev), (a)) |
| 220 | #define phys_to_bus(dev, a) pci_phys_to_mem((dev), (a)) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 221 | #endif |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 222 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 223 | static int INW(struct eepro100_priv *priv, u_long addr) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 224 | { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 225 | return le16_to_cpu(readw(addr + priv->iobase)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 228 | static void OUTW(struct eepro100_priv *priv, int command, u_long addr) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 229 | { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 230 | writew(cpu_to_le16(command), addr + priv->iobase); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 233 | static void OUTL(struct eepro100_priv *priv, int command, u_long addr) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 234 | { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 235 | writel(cpu_to_le32(command), addr + priv->iobase); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Jon Loeliger | 07d38a1 | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 238 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 239 | static int INL(struct eepro100_priv *priv, u_long addr) |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 240 | { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 241 | return le32_to_cpu(readl(addr + priv->iobase)); |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 242 | } |
| 243 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 244 | static int get_phyreg(struct eepro100_priv *priv, unsigned char addr, |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 245 | unsigned char reg, unsigned short *value) |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 246 | { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 247 | int timeout = 50; |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 248 | int cmd; |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 249 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 250 | /* read requested data */ |
| 251 | cmd = (2 << 26) | ((addr & 0x1f) << 21) | ((reg & 0x1f) << 16); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 252 | OUTL(priv, cmd, SCB_CTRL_MDI); |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 253 | |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 254 | do { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 255 | udelay(1000); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 256 | cmd = INL(priv, SCB_CTRL_MDI); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 257 | } while (!(cmd & (1 << 28)) && (--timeout)); |
| 258 | |
| 259 | if (timeout == 0) |
| 260 | return -1; |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 261 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 262 | *value = (unsigned short)(cmd & 0xffff); |
Wolfgang Denk | c570b2f | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 263 | |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 267 | static int set_phyreg(struct eepro100_priv *priv, unsigned char addr, |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 268 | unsigned char reg, unsigned short value) |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 269 | { |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 270 | int timeout = 50; |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 271 | int cmd; |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 272 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 273 | /* write requested data */ |
| 274 | cmd = (1 << 26) | ((addr & 0x1f) << 21) | ((reg & 0x1f) << 16); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 275 | OUTL(priv, cmd | value, SCB_CTRL_MDI); |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 276 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 277 | while (!(INL(priv, SCB_CTRL_MDI) & (1 << 28)) && (--timeout)) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 278 | udelay(1000); |
| 279 | |
| 280 | if (timeout == 0) |
| 281 | return -1; |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 282 | |
| 283 | return 0; |
| 284 | } |
Wolfgang Denk | a912733 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 285 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 286 | /* |
| 287 | * 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] | 288 | * Do this by checking model value field from ID2 register. |
| 289 | */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 290 | static int verify_phyaddr(struct eepro100_priv *priv, unsigned char addr) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 291 | { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 292 | unsigned short value, model; |
| 293 | int ret; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 294 | |
| 295 | /* read id2 register */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 296 | ret = get_phyreg(priv, addr, MII_PHYSID2, &value); |
| 297 | if (ret) { |
| 298 | printf("%s: mii read timeout!\n", priv->name); |
| 299 | return ret; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /* get model */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 303 | model = (value >> 4) & 0x003f; |
| 304 | if (!model) { |
| 305 | printf("%s: no PHY at address %d\n", priv->name, addr); |
| 306 | return -EINVAL; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 307 | } |
| 308 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 309 | return 0; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 312 | static int eepro100_miiphy_read(struct mii_dev *bus, int addr, int devad, |
| 313 | int reg) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 314 | { |
Marek Vasut | 39daab2 | 2020-05-23 17:55:50 +0200 | [diff] [blame] | 315 | struct eepro100_priv *priv = bus->priv; |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 316 | unsigned short value = 0; |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 317 | int ret; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 318 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 319 | ret = verify_phyaddr(priv, addr); |
| 320 | if (ret) |
| 321 | return ret; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 322 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 323 | ret = get_phyreg(priv, addr, reg, &value); |
| 324 | if (ret) { |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 325 | printf("%s: mii read timeout!\n", bus->name); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 326 | return ret; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 327 | } |
| 328 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 329 | return value; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 330 | } |
| 331 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 332 | static int eepro100_miiphy_write(struct mii_dev *bus, int addr, int devad, |
| 333 | int reg, u16 value) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 334 | { |
Marek Vasut | 39daab2 | 2020-05-23 17:55:50 +0200 | [diff] [blame] | 335 | struct eepro100_priv *priv = bus->priv; |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 336 | int ret; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 337 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 338 | ret = verify_phyaddr(priv, addr); |
| 339 | if (ret) |
| 340 | return ret; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 341 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 342 | ret = set_phyreg(priv, addr, reg, value); |
| 343 | if (ret) { |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 344 | printf("%s: mii write timeout!\n", bus->name); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 345 | return ret; |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | return 0; |
| 349 | } |
Jon Loeliger | 07d38a1 | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 350 | #endif |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 351 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 352 | static void init_rx_ring(struct eepro100_priv *priv) |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 353 | { |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 354 | struct eepro100_rxfd *rx_ring = priv->rx_ring; |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 355 | int i; |
| 356 | |
| 357 | for (i = 0; i < NUM_RX_DESC; i++) { |
| 358 | rx_ring[i].status = 0; |
| 359 | rx_ring[i].control = (i == NUM_RX_DESC - 1) ? |
| 360 | cpu_to_le16 (RFD_CONTROL_S) : 0; |
| 361 | rx_ring[i].link = |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 362 | cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | fa9e121 | 2020-05-23 16:38:41 +0200 | [diff] [blame] | 363 | (u32)&rx_ring[(i + 1) % |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 364 | NUM_RX_DESC])); |
| 365 | rx_ring[i].rx_buf_addr = 0xffffffff; |
| 366 | rx_ring[i].count = cpu_to_le32(PKTSIZE_ALIGN << 16); |
| 367 | } |
| 368 | |
| 369 | flush_dcache_range((unsigned long)rx_ring, |
| 370 | (unsigned long)rx_ring + |
| 371 | (sizeof(*rx_ring) * NUM_RX_DESC)); |
| 372 | |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 373 | priv->rx_next = 0; |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 374 | } |
| 375 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 376 | static void purge_tx_ring(struct eepro100_priv *priv) |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 377 | { |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 378 | struct eepro100_txfd *tx_ring = priv->tx_ring; |
| 379 | |
| 380 | priv->tx_next = 0; |
| 381 | priv->tx_threshold = 0x01208000; |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 382 | memset(tx_ring, 0, sizeof(*tx_ring) * NUM_TX_DESC); |
| 383 | |
| 384 | flush_dcache_range((unsigned long)tx_ring, |
| 385 | (unsigned long)tx_ring + |
| 386 | (sizeof(*tx_ring) * NUM_TX_DESC)); |
| 387 | } |
| 388 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 389 | /* Wait for the chip get the command. */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 390 | static int wait_for_eepro100(struct eepro100_priv *priv) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 391 | { |
| 392 | int i; |
| 393 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 394 | for (i = 0; INW(priv, SCB_CMD) & (CU_CMD_MASK | RU_CMD_MASK); i++) { |
Marek Vasut | 9b12ff9 | 2020-05-23 13:20:14 +0200 | [diff] [blame] | 395 | if (i >= TOUT_LOOP) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 396 | return 0; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | return 1; |
| 400 | } |
| 401 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 402 | static int eepro100_txcmd_send(struct eepro100_priv *priv, |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 403 | struct eepro100_txfd *desc) |
| 404 | { |
| 405 | u16 rstat; |
| 406 | int i = 0; |
| 407 | |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 408 | flush_dcache_range((unsigned long)desc, |
| 409 | (unsigned long)desc + sizeof(*desc)); |
| 410 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 411 | if (!wait_for_eepro100(priv)) |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 412 | return -ETIMEDOUT; |
| 413 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 414 | OUTL(priv, phys_to_bus(priv->devno, (u32)desc), SCB_POINTER); |
| 415 | OUTW(priv, SCB_M | CU_START, SCB_CMD); |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 416 | |
| 417 | while (true) { |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 418 | invalidate_dcache_range((unsigned long)desc, |
| 419 | (unsigned long)desc + sizeof(*desc)); |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 420 | rstat = le16_to_cpu(desc->status); |
| 421 | if (rstat & CONFIG_SYS_STATUS_C) |
| 422 | break; |
| 423 | |
| 424 | if (i++ >= TOUT_LOOP) { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 425 | printf("%s: Tx error buffer not ready\n", priv->name); |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 426 | return -EINVAL; |
| 427 | } |
| 428 | } |
| 429 | |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 430 | invalidate_dcache_range((unsigned long)desc, |
| 431 | (unsigned long)desc + sizeof(*desc)); |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 432 | rstat = le16_to_cpu(desc->status); |
| 433 | |
| 434 | if (!(rstat & CONFIG_SYS_STATUS_OK)) { |
| 435 | printf("TX error status = 0x%08X\n", rstat); |
| 436 | return -EIO; |
| 437 | } |
| 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 442 | /* SROM Read. */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 443 | static int read_eeprom(struct eepro100_priv *priv, int location, int addr_len) |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 444 | { |
| 445 | unsigned short retval = 0; |
Marek Vasut | a6c06ec | 2020-05-23 16:23:28 +0200 | [diff] [blame] | 446 | int read_cmd = location | EE_READ_CMD(addr_len); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 447 | int i; |
| 448 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 449 | OUTW(priv, EE_ENB & ~EE_CS, SCB_EEPROM); |
| 450 | OUTW(priv, EE_ENB, SCB_EEPROM); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 451 | |
| 452 | /* Shift the read command bits out. */ |
| 453 | for (i = 12; i >= 0; i--) { |
| 454 | short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; |
| 455 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 456 | OUTW(priv, EE_ENB | dataval, SCB_EEPROM); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 457 | udelay(1); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 458 | OUTW(priv, EE_ENB | dataval | EE_SHIFT_CLK, SCB_EEPROM); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 459 | udelay(1); |
| 460 | } |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 461 | OUTW(priv, EE_ENB, SCB_EEPROM); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 462 | |
| 463 | for (i = 15; i >= 0; i--) { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 464 | OUTW(priv, EE_ENB | EE_SHIFT_CLK, SCB_EEPROM); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 465 | udelay(1); |
| 466 | retval = (retval << 1) | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 467 | !!(INW(priv, SCB_EEPROM) & EE_DATA_READ); |
| 468 | OUTW(priv, EE_ENB, SCB_EEPROM); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 469 | udelay(1); |
| 470 | } |
| 471 | |
| 472 | /* Terminate the EEPROM access. */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 473 | OUTW(priv, EE_ENB & ~EE_CS, SCB_EEPROM); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 474 | return retval; |
| 475 | } |
| 476 | |
Marek Vasut | 66fed73 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 477 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 478 | static int eepro100_initialize_mii(struct eepro100_priv *priv) |
Marek Vasut | 66fed73 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 479 | { |
| 480 | /* register mii command access routines */ |
| 481 | struct mii_dev *mdiodev; |
| 482 | int ret; |
| 483 | |
| 484 | mdiodev = mdio_alloc(); |
| 485 | if (!mdiodev) |
| 486 | return -ENOMEM; |
| 487 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 488 | strncpy(mdiodev->name, priv->name, MDIO_NAME_LEN); |
Marek Vasut | 66fed73 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 489 | mdiodev->read = eepro100_miiphy_read; |
| 490 | mdiodev->write = eepro100_miiphy_write; |
Marek Vasut | 39daab2 | 2020-05-23 17:55:50 +0200 | [diff] [blame] | 491 | mdiodev->priv = priv; |
Marek Vasut | 66fed73 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 492 | |
| 493 | ret = mdio_register(mdiodev); |
| 494 | if (ret < 0) { |
| 495 | mdio_free(mdiodev); |
| 496 | return ret; |
| 497 | } |
| 498 | |
| 499 | return 0; |
| 500 | } |
| 501 | #else |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 502 | static int eepro100_initialize_mii(struct eepro100_priv *priv) |
Marek Vasut | 66fed73 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 503 | { |
| 504 | return 0; |
| 505 | } |
| 506 | #endif |
| 507 | |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 508 | static struct pci_device_id supported[] = { |
Marek Vasut | 3a15684 | 2020-05-23 15:11:30 +0200 | [diff] [blame] | 509 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82557) }, |
| 510 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82559) }, |
| 511 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82559ER) }, |
| 512 | { } |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 513 | }; |
| 514 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 515 | static void read_hw_addr(struct eepro100_priv *priv, bd_t *bis) |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 516 | { |
| 517 | u16 sum = 0; |
| 518 | int i, j; |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 519 | int addr_len = read_eeprom(priv, 0, 6) == 0xffff ? 8 : 6; |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 520 | |
| 521 | for (j = 0, i = 0; i < 0x40; i++) { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 522 | u16 value = read_eeprom(priv, i, addr_len); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 523 | |
| 524 | sum += value; |
| 525 | if (i < 3) { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 526 | priv->enetaddr[j++] = value; |
| 527 | priv->enetaddr[j++] = value >> 8; |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | if (sum != 0xBABA) { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 532 | memset(priv->enetaddr, 0, ETH_ALEN); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 533 | debug("%s: Invalid EEPROM checksum %#4.4x, check settings before activating this device!\n", |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 534 | priv->name, sum); |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
Marek Vasut | 7a30873 | 2020-05-23 13:23:13 +0200 | [diff] [blame] | 538 | static int eepro100_init(struct eth_device *dev, bd_t *bis) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 539 | { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 540 | struct eepro100_priv *priv = |
| 541 | container_of(dev, struct eepro100_priv, dev); |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 542 | struct eepro100_rxfd *rx_ring = priv->rx_ring; |
| 543 | struct eepro100_txfd *tx_ring = priv->tx_ring; |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 544 | struct eepro100_txfd *ias_cmd, *cfg_cmd; |
| 545 | int ret, status = -1; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 546 | int tx_cur; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 547 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 548 | /* Reset the ethernet controller */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 549 | OUTL(priv, I82559_SELECTIVE_RESET, SCB_PORT); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 550 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 551 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 552 | OUTL(priv, I82559_RESET, SCB_PORT); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 553 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 554 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 555 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 556 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 557 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 558 | } |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 559 | OUTL(priv, 0, SCB_POINTER); |
| 560 | OUTW(priv, SCB_M | RUC_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 561 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 562 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 563 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 564 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 565 | } |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 566 | OUTL(priv, 0, SCB_POINTER); |
| 567 | OUTW(priv, SCB_M | CU_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 568 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 569 | /* Initialize Rx and Tx rings. */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 570 | init_rx_ring(priv); |
| 571 | purge_tx_ring(priv); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 572 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 573 | /* Tell the adapter where the RX ring is located. */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 574 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 575 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 576 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 579 | /* RX ring cache was already flushed in init_rx_ring() */ |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 580 | OUTL(priv, phys_to_bus(priv->devno, (u32)&rx_ring[priv->rx_next]), |
Marek Vasut | fa9e121 | 2020-05-23 16:38:41 +0200 | [diff] [blame] | 581 | SCB_POINTER); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 582 | OUTW(priv, SCB_M | RUC_START, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 583 | |
| 584 | /* Send the Configure frame */ |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 585 | tx_cur = priv->tx_next; |
| 586 | priv->tx_next = ((priv->tx_next + 1) % NUM_TX_DESC); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 587 | |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 588 | cfg_cmd = &tx_ring[tx_cur]; |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 589 | cfg_cmd->command = cpu_to_le16(CONFIG_SYS_CMD_SUSPEND | |
| 590 | CONFIG_SYS_CMD_CONFIGURE); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 591 | cfg_cmd->status = 0; |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 592 | cfg_cmd->link = cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 593 | (u32)&tx_ring[priv->tx_next])); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 594 | |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 595 | memcpy(((struct descriptor *)cfg_cmd)->params, i82558_config_cmd, |
Marek Vasut | 773af83 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 596 | sizeof(i82558_config_cmd)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 597 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 598 | ret = eepro100_txcmd_send(priv, cfg_cmd); |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 599 | if (ret) { |
| 600 | if (ret == -ETIMEDOUT) |
| 601 | printf("Error---CONFIG_SYS_CMD_CONFIGURE: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 602 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 605 | /* Send the Individual Address Setup frame */ |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 606 | tx_cur = priv->tx_next; |
| 607 | priv->tx_next = ((priv->tx_next + 1) % NUM_TX_DESC); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 608 | |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 609 | ias_cmd = &tx_ring[tx_cur]; |
Marek Vasut | b013173 | 2020-05-23 13:45:41 +0200 | [diff] [blame] | 610 | ias_cmd->command = cpu_to_le16(CONFIG_SYS_CMD_SUSPEND | |
| 611 | CONFIG_SYS_CMD_IAS); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 612 | ias_cmd->status = 0; |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 613 | ias_cmd->link = cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 614 | (u32)&tx_ring[priv->tx_next])); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 615 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 616 | memcpy(((struct descriptor *)ias_cmd)->params, priv->enetaddr, 6); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 617 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 618 | ret = eepro100_txcmd_send(priv, ias_cmd); |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 619 | if (ret) { |
| 620 | if (ret == -ETIMEDOUT) |
| 621 | printf("Error: Can not reset ethernet controller.\n"); |
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 | |
Ben Warren | 422b1a0 | 2008-01-09 18:15:53 -0500 | [diff] [blame] | 625 | status = 0; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 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 | |
Joe Hershberger | bccbe61 | 2012-05-21 14:45:25 +0000 | [diff] [blame] | 631 | static int eepro100_send(struct eth_device *dev, void *packet, int length) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 632 | { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 633 | struct eepro100_priv *priv = |
| 634 | container_of(dev, struct eepro100_priv, dev); |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 635 | struct eepro100_txfd *tx_ring = priv->tx_ring; |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 636 | struct eepro100_txfd *desc; |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 637 | int ret, status = -1; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 638 | int tx_cur; |
| 639 | |
| 640 | if (length <= 0) { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 641 | printf("%s: bad packet size: %d\n", priv->name, length); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 642 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 645 | tx_cur = priv->tx_next; |
| 646 | priv->tx_next = (priv->tx_next + 1) % NUM_TX_DESC; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 647 | |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 648 | desc = &tx_ring[tx_cur]; |
| 649 | desc->command = cpu_to_le16(TXCB_CMD_TRANSMIT | TXCB_CMD_SF | |
| 650 | TXCB_CMD_S | TXCB_CMD_EL); |
| 651 | desc->status = 0; |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 652 | desc->count = cpu_to_le32(priv->tx_threshold); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 653 | desc->link = cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 654 | (u32)&tx_ring[priv->tx_next])); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 655 | desc->tx_desc_addr = cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | fa9e121 | 2020-05-23 16:38:41 +0200 | [diff] [blame] | 656 | (u32)&desc->tx_buf_addr0)); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 657 | desc->tx_buf_addr0 = cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | fa9e121 | 2020-05-23 16:38:41 +0200 | [diff] [blame] | 658 | (u_long)packet)); |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 659 | desc->tx_buf_size0 = cpu_to_le32(length); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 660 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 661 | ret = eepro100_txcmd_send(priv, &tx_ring[tx_cur]); |
Marek Vasut | 95655b9 | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 662 | if (ret) { |
| 663 | if (ret == -ETIMEDOUT) |
| 664 | printf("%s: Tx error ethernet controller not ready.\n", |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 665 | priv->name); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 666 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | status = length; |
| 670 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 671 | done: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 672 | return status; |
| 673 | } |
| 674 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 675 | static int eepro100_recv(struct eth_device *dev) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 676 | { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 677 | struct eepro100_priv *priv = |
| 678 | container_of(dev, struct eepro100_priv, dev); |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 679 | struct eepro100_rxfd *rx_ring = priv->rx_ring; |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 680 | struct eepro100_rxfd *desc; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 681 | int rx_prev, length = 0; |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 682 | u16 status, stat; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 683 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 684 | stat = INW(priv, SCB_STATUS); |
| 685 | OUTW(priv, stat & SCB_STATUS_RNR, SCB_STATUS); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 686 | |
| 687 | for (;;) { |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 688 | desc = &rx_ring[priv->rx_next]; |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 689 | invalidate_dcache_range((unsigned long)desc, |
| 690 | (unsigned long)desc + sizeof(*desc)); |
| 691 | status = le16_to_cpu(desc->status); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 692 | |
Marek Vasut | 9b12ff9 | 2020-05-23 13:20:14 +0200 | [diff] [blame] | 693 | if (!(status & RFD_STATUS_C)) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 694 | break; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 695 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 696 | /* Valid frame status. */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 697 | if ((status & RFD_STATUS_OK)) { |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 698 | /* A valid frame received. */ |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 699 | length = le32_to_cpu(desc->count) & 0x3fff; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 700 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 701 | /* Pass the packet up to the protocol layers. */ |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 702 | net_process_received_packet((u8 *)desc->data, length); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 703 | } else { |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 704 | /* There was an error. */ |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 705 | printf("RX error status = 0x%08X\n", status); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 708 | desc->control = cpu_to_le16(RFD_CONTROL_S); |
| 709 | desc->status = 0; |
| 710 | desc->count = cpu_to_le32(PKTSIZE_ALIGN << 16); |
| 711 | flush_dcache_range((unsigned long)desc, |
| 712 | (unsigned long)desc + sizeof(*desc)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 713 | |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 714 | rx_prev = (priv->rx_next + NUM_RX_DESC - 1) % NUM_RX_DESC; |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 715 | desc = &rx_ring[rx_prev]; |
| 716 | desc->control = 0; |
| 717 | flush_dcache_range((unsigned long)desc, |
| 718 | (unsigned long)desc + sizeof(*desc)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 719 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 720 | /* Update entry information. */ |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 721 | priv->rx_next = (priv->rx_next + 1) % NUM_RX_DESC; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | if (stat & SCB_STATUS_RNR) { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 725 | printf("%s: Receiver is not ready, restart it !\n", priv->name); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 726 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 727 | /* Reinitialize Rx ring. */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 728 | init_rx_ring(priv); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 729 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 730 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 731 | printf("Error: Can not restart ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 732 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Marek Vasut | 5116aae | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 735 | /* RX ring cache was already flushed in init_rx_ring() */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 736 | OUTL(priv, phys_to_bus(priv->devno, |
Marek Vasut | fb8307e | 2020-05-23 17:13:26 +0200 | [diff] [blame^] | 737 | (u32)&rx_ring[priv->rx_next]), |
| 738 | SCB_POINTER); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 739 | OUTW(priv, SCB_M | RUC_START, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 742 | done: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 743 | return length; |
| 744 | } |
| 745 | |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 746 | static void eepro100_halt(struct eth_device *dev) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 747 | { |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 748 | struct eepro100_priv *priv = |
| 749 | container_of(dev, struct eepro100_priv, dev); |
| 750 | |
Marek Vasut | aba283d | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 751 | /* Reset the ethernet controller */ |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 752 | OUTL(priv, I82559_SELECTIVE_RESET, SCB_PORT); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 753 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 754 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 755 | OUTL(priv, I82559_RESET, SCB_PORT); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 756 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 757 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 758 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 759 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 760 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 761 | } |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 762 | OUTL(priv, 0, SCB_POINTER); |
| 763 | OUTW(priv, SCB_M | RUC_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 764 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 765 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | db9f181 | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 766 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 767 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 768 | } |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 769 | OUTL(priv, 0, SCB_POINTER); |
| 770 | OUTW(priv, SCB_M | CU_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 771 | |
Marek Vasut | f3878f5 | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 772 | done: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 773 | return; |
| 774 | } |
| 775 | |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 776 | int eepro100_initialize(bd_t *bis) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 777 | { |
Marek Vasut | bd159c6 | 2020-05-23 16:49:07 +0200 | [diff] [blame] | 778 | struct eepro100_priv *priv; |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 779 | struct eth_device *dev; |
Marek Vasut | 66fed73 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 780 | int card_number = 0; |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 781 | u32 iobase, status; |
Marek Vasut | 66fed73 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 782 | pci_dev_t devno; |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 783 | int idx = 0; |
Marek Vasut | 66fed73 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 784 | int ret; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 785 | |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 786 | while (1) { |
| 787 | /* Find PCI device */ |
| 788 | devno = pci_find_devices(supported, idx++); |
| 789 | if (devno < 0) |
| 790 | break; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 791 | |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 792 | pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &iobase); |
| 793 | iobase &= ~0xf; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 794 | |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 795 | debug("eepro100: Intel i82559 PCI EtherExpressPro @0x%x\n", |
| 796 | iobase); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 797 | |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 798 | pci_write_config_dword(devno, PCI_COMMAND, |
| 799 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 800 | |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 801 | /* Check if I/O accesses and Bus Mastering are enabled. */ |
| 802 | pci_read_config_dword(devno, PCI_COMMAND, &status); |
| 803 | if (!(status & PCI_COMMAND_MEMORY)) { |
| 804 | printf("Error: Can not enable MEM access.\n"); |
| 805 | continue; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 806 | } |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 807 | |
| 808 | if (!(status & PCI_COMMAND_MASTER)) { |
| 809 | printf("Error: Can not enable Bus Mastering.\n"); |
| 810 | continue; |
| 811 | } |
| 812 | |
Marek Vasut | bd159c6 | 2020-05-23 16:49:07 +0200 | [diff] [blame] | 813 | priv = calloc(1, sizeof(*priv)); |
| 814 | if (!priv) { |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 815 | printf("eepro100: Can not allocate memory\n"); |
| 816 | break; |
| 817 | } |
Marek Vasut | bd159c6 | 2020-05-23 16:49:07 +0200 | [diff] [blame] | 818 | dev = &priv->dev; |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 819 | |
| 820 | sprintf(dev->name, "i82559#%d", card_number); |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 821 | priv->name = dev->name; |
| 822 | /* this have to come before bus_to_phys() */ |
| 823 | priv->devno = devno; |
| 824 | priv->iobase = (void __iomem *)bus_to_phys(devno, iobase); |
| 825 | priv->enetaddr = dev->enetaddr; |
| 826 | |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 827 | dev->init = eepro100_init; |
| 828 | dev->halt = eepro100_halt; |
| 829 | dev->send = eepro100_send; |
| 830 | dev->recv = eepro100_recv; |
| 831 | |
| 832 | eth_register(dev); |
| 833 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 834 | ret = eepro100_initialize_mii(priv); |
Marek Vasut | 66fed73 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 835 | if (ret) { |
| 836 | eth_unregister(dev); |
Marek Vasut | bd159c6 | 2020-05-23 16:49:07 +0200 | [diff] [blame] | 837 | free(priv); |
Marek Vasut | 66fed73 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 838 | return ret; |
| 839 | } |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 840 | |
| 841 | card_number++; |
| 842 | |
| 843 | /* Set the latency timer for value. */ |
| 844 | pci_write_config_byte(devno, PCI_LATENCY_TIMER, 0x20); |
| 845 | |
| 846 | udelay(10 * 1000); |
| 847 | |
Marek Vasut | 389da97 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 848 | read_hw_addr(priv, bis); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Marek Vasut | 047a800 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 851 | return card_number; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 852 | } |