Tom Rini | 10e4779 | 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 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 7 | #include <common.h> |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 8 | #include <asm/io.h> |
Marek Vasut | 7efcae4 | 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 | 2110c65 | 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 | 052a5ea | 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 | dbd7954 | 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 | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 17 | /* Ethernet chip registers. */ |
Marek Vasut | 447271b | 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 | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 31 | /* 82559 SCB status word defnitions */ |
Wolfgang Denk | 4dc1146 | 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 | 4dc1146 | 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 | 4dc1146 | 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 | dc83bfe | 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 | 4dc1146 | 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 | 4dc1146 | 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 | 4dc1146 | 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 | 4dc1146 | 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 | 4dc1146 | 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 | e4211ed | 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 | dc83bfe | 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 | dc83bfe | 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 | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 98 | /* The EEPROM commands include the alway-set leading bit. */ |
Marek Vasut | f9cc66a | 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 | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 104 | /* Receive frame descriptors. */ |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 105 | struct eepro100_rxfd { |
Marek Vasut | 7ad665f | 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 | 7ad665f | 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 | 4dc1146 | 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 | 4dc1146 | 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 | 4dc1146 | 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 | 4dc1146 | 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 | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 138 | /* Transmit frame descriptors */ |
Marek Vasut | 7ad665f | 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 | 7ad665f | 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 | 447271b | 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 | 447271b | 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 | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 162 | /* The Speedo3 Rx and Tx frame/buffer descriptors. */ |
Marek Vasut | 7ad665f | 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 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 171 | #define CFG_SYS_CMD_SUSPEND 0x4000 |
| 172 | #define CFG_SYS_CMD_IAS 0x0001 /* individual address setup */ |
| 173 | #define CFG_SYS_CMD_CONFIGURE 0x0002 /* configure */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 174 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 175 | #define CFG_SYS_STATUS_C 0x8000 |
| 176 | #define CFG_SYS_STATUS_OK 0x2000 |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 177 | |
Marek Vasut | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 178 | /* Misc. */ |
Wolfgang Denk | 4dc1146 | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 179 | #define NUM_RX_DESC PKTBUFSRX |
Marek Vasut | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 180 | #define NUM_TX_DESC 1 /* Number of TX descriptors */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 181 | |
| 182 | #define TOUT_LOOP 1000000 |
| 183 | |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 184 | /* |
| 185 | * The parameters for a CmdConfigure operation. |
| 186 | * There are so many options that it would be difficult to document |
| 187 | * each bit. We mostly use the default or recommended settings. |
| 188 | */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 189 | static const char i82558_config_cmd[] = { |
| 190 | 22, 0x08, 0, 1, 0, 0, 0x22, 0x03, 1, /* 1=Use MII 0=Use AUI */ |
| 191 | 0, 0x2E, 0, 0x60, 0x08, 0x88, |
| 192 | 0x68, 0, 0x40, 0xf2, 0x84, /* Disable FC */ |
| 193 | 0x31, 0x05, |
| 194 | }; |
| 195 | |
Marek Vasut | 13beaa8 | 2020-05-23 16:49:07 +0200 | [diff] [blame] | 196 | struct eepro100_priv { |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 197 | /* RX descriptor ring */ |
| 198 | struct eepro100_rxfd rx_ring[NUM_RX_DESC]; |
| 199 | /* TX descriptor ring */ |
| 200 | struct eepro100_txfd tx_ring[NUM_TX_DESC]; |
| 201 | /* RX descriptor ring pointer */ |
| 202 | int rx_next; |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 203 | u16 rx_stat; |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 204 | /* TX descriptor ring pointer */ |
| 205 | int tx_next; |
| 206 | int tx_threshold; |
Marek Vasut | cbc44b8 | 2020-05-23 16:26:20 +0200 | [diff] [blame] | 207 | struct udevice *devno; |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 208 | char *name; |
| 209 | void __iomem *iobase; |
| 210 | u8 *enetaddr; |
Marek Vasut | 13beaa8 | 2020-05-23 16:49:07 +0200 | [diff] [blame] | 211 | }; |
| 212 | |
Marek Vasut | cbc44b8 | 2020-05-23 16:26:20 +0200 | [diff] [blame] | 213 | #define bus_to_phys(dev, a) dm_pci_mem_to_phys((dev), (a)) |
| 214 | #define phys_to_bus(dev, a) dm_pci_phys_to_mem((dev), (a)) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 215 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 216 | static int INW(struct eepro100_priv *priv, u_long addr) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 217 | { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 218 | return le16_to_cpu(readw(addr + priv->iobase)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 221 | static void OUTW(struct eepro100_priv *priv, int command, u_long addr) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 222 | { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 223 | writew(cpu_to_le16(command), addr + priv->iobase); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 226 | static void OUTL(struct eepro100_priv *priv, int command, u_long addr) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 227 | { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 228 | writel(cpu_to_le32(command), addr + priv->iobase); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Jon Loeliger | b1d408a | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 231 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 232 | static int INL(struct eepro100_priv *priv, u_long addr) |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 233 | { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 234 | return le32_to_cpu(readl(addr + priv->iobase)); |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 235 | } |
| 236 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 237 | static int get_phyreg(struct eepro100_priv *priv, unsigned char addr, |
Marek Vasut | 60560d0 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 238 | unsigned char reg, unsigned short *value) |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 239 | { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 240 | int timeout = 50; |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 241 | int cmd; |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 242 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 243 | /* read requested data */ |
| 244 | cmd = (2 << 26) | ((addr & 0x1f) << 21) | ((reg & 0x1f) << 16); |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 245 | OUTL(priv, cmd, SCB_CTRL_MDI); |
Wolfgang Denk | 4dc1146 | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 246 | |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 247 | do { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 248 | udelay(1000); |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 249 | cmd = INL(priv, SCB_CTRL_MDI); |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 250 | } while (!(cmd & (1 << 28)) && (--timeout)); |
| 251 | |
| 252 | if (timeout == 0) |
| 253 | return -1; |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 254 | |
Marek Vasut | e4211ed | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 255 | *value = (unsigned short)(cmd & 0xffff); |
Wolfgang Denk | 4dc1146 | 2005-09-26 01:06:33 +0200 | [diff] [blame] | 256 | |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 260 | static int set_phyreg(struct eepro100_priv *priv, unsigned char addr, |
Marek Vasut | 60560d0 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 261 | unsigned char reg, unsigned short value) |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 262 | { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 263 | int timeout = 50; |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 264 | int cmd; |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 265 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 266 | /* write requested data */ |
| 267 | cmd = (1 << 26) | ((addr & 0x1f) << 21) | ((reg & 0x1f) << 16); |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 268 | OUTL(priv, cmd | value, SCB_CTRL_MDI); |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 269 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 270 | while (!(INL(priv, SCB_CTRL_MDI) & (1 << 28)) && (--timeout)) |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 271 | udelay(1000); |
| 272 | |
| 273 | if (timeout == 0) |
| 274 | return -1; |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 275 | |
| 276 | return 0; |
| 277 | } |
Wolfgang Denk | b8d1f51 | 2005-09-26 00:39:59 +0200 | [diff] [blame] | 278 | |
Marek Vasut | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 279 | /* |
| 280 | * Check if given phyaddr is valid, i.e. there is a PHY connected. |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 281 | * Do this by checking model value field from ID2 register. |
| 282 | */ |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 283 | static int verify_phyaddr(struct eepro100_priv *priv, unsigned char addr) |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 284 | { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 285 | unsigned short value, model; |
| 286 | int ret; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 287 | |
| 288 | /* read id2 register */ |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 289 | ret = get_phyreg(priv, addr, MII_PHYSID2, &value); |
| 290 | if (ret) { |
| 291 | printf("%s: mii read timeout!\n", priv->name); |
| 292 | return ret; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* get model */ |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 296 | model = (value >> 4) & 0x003f; |
| 297 | if (!model) { |
| 298 | printf("%s: no PHY at address %d\n", priv->name, addr); |
| 299 | return -EINVAL; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 300 | } |
| 301 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 302 | return 0; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 303 | } |
| 304 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 305 | static int eepro100_miiphy_read(struct mii_dev *bus, int addr, int devad, |
| 306 | int reg) |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 307 | { |
Marek Vasut | 4448e60 | 2020-05-23 17:55:50 +0200 | [diff] [blame] | 308 | struct eepro100_priv *priv = bus->priv; |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 309 | unsigned short value = 0; |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 310 | int ret; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 311 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 312 | ret = verify_phyaddr(priv, addr); |
| 313 | if (ret) |
| 314 | return ret; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 315 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 316 | ret = get_phyreg(priv, addr, reg, &value); |
| 317 | if (ret) { |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 318 | printf("%s: mii read timeout!\n", bus->name); |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 319 | return ret; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 320 | } |
| 321 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 322 | return value; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 325 | static int eepro100_miiphy_write(struct mii_dev *bus, int addr, int devad, |
| 326 | int reg, u16 value) |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 327 | { |
Marek Vasut | 4448e60 | 2020-05-23 17:55:50 +0200 | [diff] [blame] | 328 | struct eepro100_priv *priv = bus->priv; |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 329 | int ret; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 330 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 331 | ret = verify_phyaddr(priv, addr); |
| 332 | if (ret) |
| 333 | return ret; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 334 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 335 | ret = set_phyreg(priv, addr, reg, value); |
| 336 | if (ret) { |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 337 | printf("%s: mii write timeout!\n", bus->name); |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 338 | return ret; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | return 0; |
| 342 | } |
Jon Loeliger | b1d408a | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 343 | #endif |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 344 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 345 | static void init_rx_ring(struct eepro100_priv *priv) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 346 | { |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 347 | struct eepro100_rxfd *rx_ring = priv->rx_ring; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 348 | int i; |
| 349 | |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 350 | for (i = 0; i < NUM_RX_DESC; i++) { |
| 351 | rx_ring[i].status = 0; |
| 352 | rx_ring[i].control = (i == NUM_RX_DESC - 1) ? |
| 353 | cpu_to_le16 (RFD_CONTROL_S) : 0; |
| 354 | rx_ring[i].link = |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 355 | cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | c62e024 | 2020-05-23 16:38:41 +0200 | [diff] [blame] | 356 | (u32)&rx_ring[(i + 1) % |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 357 | NUM_RX_DESC])); |
| 358 | rx_ring[i].rx_buf_addr = 0xffffffff; |
| 359 | rx_ring[i].count = cpu_to_le32(PKTSIZE_ALIGN << 16); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 362 | flush_dcache_range((unsigned long)rx_ring, |
| 363 | (unsigned long)rx_ring + |
| 364 | (sizeof(*rx_ring) * NUM_RX_DESC)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 365 | |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 366 | priv->rx_next = 0; |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 367 | } |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 368 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 369 | static void purge_tx_ring(struct eepro100_priv *priv) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 370 | { |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 371 | struct eepro100_txfd *tx_ring = priv->tx_ring; |
| 372 | |
| 373 | priv->tx_next = 0; |
| 374 | priv->tx_threshold = 0x01208000; |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 375 | memset(tx_ring, 0, sizeof(*tx_ring) * NUM_TX_DESC); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 376 | |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 377 | flush_dcache_range((unsigned long)tx_ring, |
| 378 | (unsigned long)tx_ring + |
| 379 | (sizeof(*tx_ring) * NUM_TX_DESC)); |
| 380 | } |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 381 | |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 382 | /* Wait for the chip get the command. */ |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 383 | static int wait_for_eepro100(struct eepro100_priv *priv) |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 384 | { |
| 385 | int i; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 386 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 387 | for (i = 0; INW(priv, SCB_CMD) & (CU_CMD_MASK | RU_CMD_MASK); i++) { |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 388 | if (i >= TOUT_LOOP) |
| 389 | return 0; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 392 | return 1; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 395 | static int eepro100_txcmd_send(struct eepro100_priv *priv, |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 396 | struct eepro100_txfd *desc) |
| 397 | { |
| 398 | u16 rstat; |
| 399 | int i = 0; |
| 400 | |
Marek Vasut | 7efcae4 | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 401 | flush_dcache_range((unsigned long)desc, |
| 402 | (unsigned long)desc + sizeof(*desc)); |
| 403 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 404 | if (!wait_for_eepro100(priv)) |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 405 | return -ETIMEDOUT; |
| 406 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 407 | OUTL(priv, phys_to_bus(priv->devno, (u32)desc), SCB_POINTER); |
| 408 | OUTW(priv, SCB_M | CU_START, SCB_CMD); |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 409 | |
| 410 | while (true) { |
Marek Vasut | 7efcae4 | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 411 | invalidate_dcache_range((unsigned long)desc, |
| 412 | (unsigned long)desc + sizeof(*desc)); |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 413 | rstat = le16_to_cpu(desc->status); |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 414 | if (rstat & CFG_SYS_STATUS_C) |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 415 | break; |
| 416 | |
| 417 | if (i++ >= TOUT_LOOP) { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 418 | printf("%s: Tx error buffer not ready\n", priv->name); |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 419 | return -EINVAL; |
| 420 | } |
| 421 | } |
| 422 | |
Marek Vasut | 7efcae4 | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 423 | invalidate_dcache_range((unsigned long)desc, |
| 424 | (unsigned long)desc + sizeof(*desc)); |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 425 | rstat = le16_to_cpu(desc->status); |
| 426 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 427 | if (!(rstat & CFG_SYS_STATUS_OK)) { |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 428 | printf("TX error status = 0x%08X\n", rstat); |
| 429 | return -EIO; |
| 430 | } |
| 431 | |
| 432 | return 0; |
| 433 | } |
| 434 | |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 435 | /* SROM Read. */ |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 436 | static int read_eeprom(struct eepro100_priv *priv, int location, int addr_len) |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 437 | { |
| 438 | unsigned short retval = 0; |
Marek Vasut | f9cc66a | 2020-05-23 16:23:28 +0200 | [diff] [blame] | 439 | int read_cmd = location | EE_READ_CMD(addr_len); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 440 | int i; |
| 441 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 442 | OUTW(priv, EE_ENB & ~EE_CS, SCB_EEPROM); |
| 443 | OUTW(priv, EE_ENB, SCB_EEPROM); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 444 | |
| 445 | /* Shift the read command bits out. */ |
| 446 | for (i = 12; i >= 0; i--) { |
| 447 | short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; |
| 448 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 449 | OUTW(priv, EE_ENB | dataval, SCB_EEPROM); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 450 | udelay(1); |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 451 | OUTW(priv, EE_ENB | dataval | EE_SHIFT_CLK, SCB_EEPROM); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 452 | udelay(1); |
| 453 | } |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 454 | OUTW(priv, EE_ENB, SCB_EEPROM); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 455 | |
| 456 | for (i = 15; i >= 0; i--) { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 457 | OUTW(priv, EE_ENB | EE_SHIFT_CLK, SCB_EEPROM); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 458 | udelay(1); |
| 459 | retval = (retval << 1) | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 460 | !!(INW(priv, SCB_EEPROM) & EE_DATA_READ); |
| 461 | OUTW(priv, EE_ENB, SCB_EEPROM); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 462 | udelay(1); |
| 463 | } |
| 464 | |
| 465 | /* Terminate the EEPROM access. */ |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 466 | OUTW(priv, EE_ENB & ~EE_CS, SCB_EEPROM); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 467 | return retval; |
| 468 | } |
| 469 | |
Marek Vasut | d68d272 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 470 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 471 | static int eepro100_initialize_mii(struct eepro100_priv *priv) |
Marek Vasut | d68d272 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 472 | { |
| 473 | /* register mii command access routines */ |
| 474 | struct mii_dev *mdiodev; |
| 475 | int ret; |
| 476 | |
| 477 | mdiodev = mdio_alloc(); |
| 478 | if (!mdiodev) |
| 479 | return -ENOMEM; |
| 480 | |
Vladimir Oltean | c786b52 | 2021-09-27 14:21:46 +0300 | [diff] [blame] | 481 | strlcpy(mdiodev->name, priv->name, MDIO_NAME_LEN); |
Marek Vasut | d68d272 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 482 | mdiodev->read = eepro100_miiphy_read; |
| 483 | mdiodev->write = eepro100_miiphy_write; |
Marek Vasut | 4448e60 | 2020-05-23 17:55:50 +0200 | [diff] [blame] | 484 | mdiodev->priv = priv; |
Marek Vasut | d68d272 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 485 | |
| 486 | ret = mdio_register(mdiodev); |
| 487 | if (ret < 0) { |
| 488 | mdio_free(mdiodev); |
| 489 | return ret; |
| 490 | } |
| 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | #else |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 495 | static int eepro100_initialize_mii(struct eepro100_priv *priv) |
Marek Vasut | d68d272 | 2020-05-23 16:20:25 +0200 | [diff] [blame] | 496 | { |
| 497 | return 0; |
| 498 | } |
| 499 | #endif |
| 500 | |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 501 | static struct pci_device_id supported[] = { |
Marek Vasut | f7fee91 | 2020-05-23 15:11:30 +0200 | [diff] [blame] | 502 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82557) }, |
| 503 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82559) }, |
| 504 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82559ER) }, |
| 505 | { } |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 506 | }; |
| 507 | |
Marek Vasut | addde61 | 2020-05-23 17:20:39 +0200 | [diff] [blame] | 508 | static void eepro100_get_hwaddr(struct eepro100_priv *priv) |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 509 | { |
| 510 | u16 sum = 0; |
| 511 | int i, j; |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 512 | int addr_len = read_eeprom(priv, 0, 6) == 0xffff ? 8 : 6; |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 513 | |
| 514 | for (j = 0, i = 0; i < 0x40; i++) { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 515 | u16 value = read_eeprom(priv, i, addr_len); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 516 | |
| 517 | sum += value; |
| 518 | if (i < 3) { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 519 | priv->enetaddr[j++] = value; |
| 520 | priv->enetaddr[j++] = value >> 8; |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | |
| 524 | if (sum != 0xBABA) { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 525 | memset(priv->enetaddr, 0, ETH_ALEN); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 526 | debug("%s: Invalid EEPROM checksum %#4.4x, check settings before activating this device!\n", |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 527 | priv->name, sum); |
Marek Vasut | 2110c65 | 2020-05-23 15:07:30 +0200 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 531 | static int eepro100_init_common(struct eepro100_priv *priv) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 532 | { |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 533 | struct eepro100_rxfd *rx_ring = priv->rx_ring; |
| 534 | struct eepro100_txfd *tx_ring = priv->tx_ring; |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 535 | struct eepro100_txfd *ias_cmd, *cfg_cmd; |
| 536 | int ret, status = -1; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 537 | int tx_cur; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 538 | |
Marek Vasut | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 539 | /* Reset the ethernet controller */ |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 540 | OUTL(priv, I82559_SELECTIVE_RESET, SCB_PORT); |
Simon Glass | 0db4b94 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 541 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 542 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 543 | OUTL(priv, I82559_RESET, SCB_PORT); |
Simon Glass | 0db4b94 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 544 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 545 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 546 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | e4211ed | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 547 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 548 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 549 | } |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 550 | OUTL(priv, 0, SCB_POINTER); |
| 551 | OUTW(priv, SCB_M | RUC_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 552 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 553 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | e4211ed | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 554 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 555 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 556 | } |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 557 | OUTL(priv, 0, SCB_POINTER); |
| 558 | OUTW(priv, SCB_M | CU_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 559 | |
Marek Vasut | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 560 | /* Initialize Rx and Tx rings. */ |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 561 | init_rx_ring(priv); |
| 562 | purge_tx_ring(priv); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 563 | |
Marek Vasut | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 564 | /* Tell the adapter where the RX ring is located. */ |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 565 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | e4211ed | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 566 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 567 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Marek Vasut | 7efcae4 | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 570 | /* RX ring cache was already flushed in init_rx_ring() */ |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 571 | OUTL(priv, phys_to_bus(priv->devno, (u32)&rx_ring[priv->rx_next]), |
Marek Vasut | c62e024 | 2020-05-23 16:38:41 +0200 | [diff] [blame] | 572 | SCB_POINTER); |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 573 | OUTW(priv, SCB_M | RUC_START, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 574 | |
| 575 | /* Send the Configure frame */ |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 576 | tx_cur = priv->tx_next; |
| 577 | priv->tx_next = ((priv->tx_next + 1) % NUM_TX_DESC); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 578 | |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 579 | cfg_cmd = &tx_ring[tx_cur]; |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 580 | cfg_cmd->command = cpu_to_le16(CFG_SYS_CMD_SUSPEND | |
| 581 | CFG_SYS_CMD_CONFIGURE); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 582 | cfg_cmd->status = 0; |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 583 | cfg_cmd->link = cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 584 | (u32)&tx_ring[priv->tx_next])); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 585 | |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 586 | memcpy(((struct descriptor *)cfg_cmd)->params, i82558_config_cmd, |
Marek Vasut | 60560d0 | 2020-05-23 13:21:43 +0200 | [diff] [blame] | 587 | sizeof(i82558_config_cmd)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 588 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 589 | ret = eepro100_txcmd_send(priv, cfg_cmd); |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 590 | if (ret) { |
| 591 | if (ret == -ETIMEDOUT) |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 592 | printf("Error---CFG_SYS_CMD_CONFIGURE: Can not reset ethernet controller.\n"); |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 593 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Marek Vasut | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 596 | /* Send the Individual Address Setup frame */ |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 597 | tx_cur = priv->tx_next; |
| 598 | priv->tx_next = ((priv->tx_next + 1) % NUM_TX_DESC); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 599 | |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 600 | ias_cmd = &tx_ring[tx_cur]; |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 601 | ias_cmd->command = cpu_to_le16(CFG_SYS_CMD_SUSPEND | |
| 602 | CFG_SYS_CMD_IAS); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 603 | ias_cmd->status = 0; |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 604 | ias_cmd->link = cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 605 | (u32)&tx_ring[priv->tx_next])); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 606 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 607 | memcpy(((struct descriptor *)ias_cmd)->params, priv->enetaddr, 6); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 608 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 609 | ret = eepro100_txcmd_send(priv, ias_cmd); |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 610 | if (ret) { |
| 611 | if (ret == -ETIMEDOUT) |
| 612 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 613 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Ben Warren | de9fcb5 | 2008-01-09 18:15:53 -0500 | [diff] [blame] | 616 | status = 0; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 617 | |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 618 | done: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 619 | return status; |
| 620 | } |
| 621 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 622 | static int eepro100_send_common(struct eepro100_priv *priv, |
| 623 | void *packet, int length) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 624 | { |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 625 | struct eepro100_txfd *tx_ring = priv->tx_ring; |
Marek Vasut | 7efcae4 | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 626 | struct eepro100_txfd *desc; |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 627 | int ret, status = -1; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 628 | int tx_cur; |
| 629 | |
| 630 | if (length <= 0) { |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 631 | printf("%s: bad packet size: %d\n", priv->name, length); |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 632 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 635 | tx_cur = priv->tx_next; |
| 636 | priv->tx_next = (priv->tx_next + 1) % NUM_TX_DESC; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 637 | |
Marek Vasut | 7efcae4 | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 638 | desc = &tx_ring[tx_cur]; |
| 639 | desc->command = cpu_to_le16(TXCB_CMD_TRANSMIT | TXCB_CMD_SF | |
| 640 | TXCB_CMD_S | TXCB_CMD_EL); |
| 641 | desc->status = 0; |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 642 | desc->count = cpu_to_le32(priv->tx_threshold); |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 643 | desc->link = cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 644 | (u32)&tx_ring[priv->tx_next])); |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 645 | desc->tx_desc_addr = cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | c62e024 | 2020-05-23 16:38:41 +0200 | [diff] [blame] | 646 | (u32)&desc->tx_buf_addr0)); |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 647 | desc->tx_buf_addr0 = cpu_to_le32(phys_to_bus(priv->devno, |
Marek Vasut | c62e024 | 2020-05-23 16:38:41 +0200 | [diff] [blame] | 648 | (u_long)packet)); |
Marek Vasut | 7efcae4 | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 649 | desc->tx_buf_size0 = cpu_to_le32(length); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 650 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 651 | ret = eepro100_txcmd_send(priv, &tx_ring[tx_cur]); |
Marek Vasut | d2139bb | 2020-05-23 14:30:31 +0200 | [diff] [blame] | 652 | if (ret) { |
| 653 | if (ret == -ETIMEDOUT) |
| 654 | printf("%s: Tx error ethernet controller not ready.\n", |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 655 | priv->name); |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 656 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | status = length; |
| 660 | |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 661 | done: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 662 | return status; |
| 663 | } |
| 664 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 665 | static int eepro100_recv_common(struct eepro100_priv *priv, uchar **packetp) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 666 | { |
Marek Vasut | d443d2d | 2020-05-23 17:13:26 +0200 | [diff] [blame] | 667 | struct eepro100_rxfd *rx_ring = priv->rx_ring; |
Marek Vasut | 7efcae4 | 2020-05-23 14:55:26 +0200 | [diff] [blame] | 668 | struct eepro100_rxfd *desc; |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 669 | int length; |
| 670 | u16 status; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 671 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 672 | priv->rx_stat = INW(priv, SCB_STATUS); |
| 673 | OUTW(priv, priv->rx_stat & SCB_STATUS_RNR, SCB_STATUS); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 674 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 675 | desc = &rx_ring[priv->rx_next]; |
| 676 | invalidate_dcache_range((unsigned long)desc, |
| 677 | (unsigned long)desc + sizeof(*desc)); |
| 678 | status = le16_to_cpu(desc->status); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 679 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 680 | if (!(status & RFD_STATUS_C)) |
| 681 | return 0; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 682 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 683 | /* Valid frame status. */ |
| 684 | if (status & RFD_STATUS_OK) { |
| 685 | /* A valid frame received. */ |
| 686 | length = le32_to_cpu(desc->count) & 0x3fff; |
| 687 | /* Pass the packet up to the protocol layers. */ |
| 688 | *packetp = desc->data; |
| 689 | return length; |
| 690 | } |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 691 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 692 | /* There was an error. */ |
| 693 | printf("RX error status = 0x%08X\n", status); |
| 694 | return -EINVAL; |
| 695 | } |
| 696 | |
| 697 | static void eepro100_free_pkt_common(struct eepro100_priv *priv) |
| 698 | { |
| 699 | struct eepro100_rxfd *rx_ring = priv->rx_ring; |
| 700 | struct eepro100_rxfd *desc; |
| 701 | int rx_prev; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 702 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 703 | desc = &rx_ring[priv->rx_next]; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 704 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 705 | desc->control = cpu_to_le16(RFD_CONTROL_S); |
| 706 | desc->status = 0; |
| 707 | desc->count = cpu_to_le32(PKTSIZE_ALIGN << 16); |
| 708 | flush_dcache_range((unsigned long)desc, |
| 709 | (unsigned long)desc + sizeof(*desc)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 710 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 711 | rx_prev = (priv->rx_next + NUM_RX_DESC - 1) % NUM_RX_DESC; |
| 712 | desc = &rx_ring[rx_prev]; |
| 713 | desc->control = 0; |
| 714 | flush_dcache_range((unsigned long)desc, |
| 715 | (unsigned long)desc + sizeof(*desc)); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 716 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 717 | /* Update entry information. */ |
| 718 | priv->rx_next = (priv->rx_next + 1) % NUM_RX_DESC; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 719 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 720 | if (!(priv->rx_stat & SCB_STATUS_RNR)) |
| 721 | return; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 722 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 723 | printf("%s: Receiver is not ready, restart it !\n", priv->name); |
| 724 | |
| 725 | /* Reinitialize Rx ring. */ |
| 726 | init_rx_ring(priv); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 727 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 728 | if (!wait_for_eepro100(priv)) { |
| 729 | printf("Error: Can not restart ethernet controller.\n"); |
| 730 | return; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 731 | } |
| 732 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 733 | /* RX ring cache was already flushed in init_rx_ring() */ |
| 734 | OUTL(priv, phys_to_bus(priv->devno, (u32)&rx_ring[priv->rx_next]), |
| 735 | SCB_POINTER); |
| 736 | OUTW(priv, SCB_M | RUC_START, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 737 | } |
| 738 | |
Marek Vasut | 0ea22ba | 2020-05-23 17:28:20 +0200 | [diff] [blame] | 739 | static void eepro100_halt_common(struct eepro100_priv *priv) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 740 | { |
Marek Vasut | dc83bfe | 2020-05-23 12:49:16 +0200 | [diff] [blame] | 741 | /* Reset the ethernet controller */ |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 742 | OUTL(priv, I82559_SELECTIVE_RESET, SCB_PORT); |
Simon Glass | 0db4b94 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 743 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 744 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 745 | OUTL(priv, I82559_RESET, SCB_PORT); |
Simon Glass | 0db4b94 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 746 | udelay(20); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 747 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 748 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | e4211ed | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 749 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 750 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 751 | } |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 752 | OUTL(priv, 0, SCB_POINTER); |
| 753 | OUTW(priv, SCB_M | RUC_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 754 | |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 755 | if (!wait_for_eepro100(priv)) { |
Marek Vasut | e4211ed | 2020-05-23 13:17:03 +0200 | [diff] [blame] | 756 | printf("Error: Can not reset ethernet controller.\n"); |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 757 | goto done; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 758 | } |
Marek Vasut | 3334669 | 2020-05-23 17:10:03 +0200 | [diff] [blame] | 759 | OUTL(priv, 0, SCB_POINTER); |
| 760 | OUTW(priv, SCB_M | CU_ADDR_LOAD, SCB_CMD); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 761 | |
Marek Vasut | 447271b | 2020-05-23 13:52:50 +0200 | [diff] [blame] | 762 | done: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 763 | return; |
| 764 | } |
| 765 | |
Marek Vasut | cbc44b8 | 2020-05-23 16:26:20 +0200 | [diff] [blame] | 766 | static int eepro100_start(struct udevice *dev) |
| 767 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 768 | struct eth_pdata *plat = dev_get_plat(dev); |
Marek Vasut | cbc44b8 | 2020-05-23 16:26:20 +0200 | [diff] [blame] | 769 | struct eepro100_priv *priv = dev_get_priv(dev); |
| 770 | |
| 771 | memcpy(priv->enetaddr, plat->enetaddr, sizeof(plat->enetaddr)); |
| 772 | |
| 773 | return eepro100_init_common(priv); |
| 774 | } |
| 775 | |
| 776 | static void eepro100_stop(struct udevice *dev) |
| 777 | { |
| 778 | struct eepro100_priv *priv = dev_get_priv(dev); |
| 779 | |
| 780 | eepro100_halt_common(priv); |
| 781 | } |
| 782 | |
| 783 | static int eepro100_send(struct udevice *dev, void *packet, int length) |
| 784 | { |
| 785 | struct eepro100_priv *priv = dev_get_priv(dev); |
| 786 | int ret; |
| 787 | |
| 788 | ret = eepro100_send_common(priv, packet, length); |
| 789 | |
| 790 | return ret ? 0 : -ETIMEDOUT; |
| 791 | } |
| 792 | |
| 793 | static int eepro100_recv(struct udevice *dev, int flags, uchar **packetp) |
| 794 | { |
| 795 | struct eepro100_priv *priv = dev_get_priv(dev); |
| 796 | |
| 797 | return eepro100_recv_common(priv, packetp); |
| 798 | } |
| 799 | |
| 800 | static int eepro100_free_pkt(struct udevice *dev, uchar *packet, int length) |
| 801 | { |
| 802 | struct eepro100_priv *priv = dev_get_priv(dev); |
| 803 | |
| 804 | eepro100_free_pkt_common(priv); |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | static int eepro100_read_rom_hwaddr(struct udevice *dev) |
| 810 | { |
| 811 | struct eepro100_priv *priv = dev_get_priv(dev); |
| 812 | |
| 813 | eepro100_get_hwaddr(priv); |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | static int eepro100_bind(struct udevice *dev) |
| 819 | { |
| 820 | static int card_number; |
| 821 | char name[16]; |
| 822 | |
| 823 | sprintf(name, "eepro100#%u", card_number++); |
| 824 | |
| 825 | return device_set_name(dev, name); |
| 826 | } |
| 827 | |
| 828 | static int eepro100_probe(struct udevice *dev) |
| 829 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 830 | struct eth_pdata *plat = dev_get_plat(dev); |
Marek Vasut | cbc44b8 | 2020-05-23 16:26:20 +0200 | [diff] [blame] | 831 | struct eepro100_priv *priv = dev_get_priv(dev); |
| 832 | u16 command, status; |
| 833 | u32 iobase; |
| 834 | int ret; |
| 835 | |
| 836 | dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase); |
| 837 | iobase &= ~0xf; |
| 838 | |
| 839 | debug("eepro100: Intel i82559 PCI EtherExpressPro @0x%x\n", iobase); |
| 840 | |
| 841 | priv->devno = dev; |
| 842 | priv->enetaddr = plat->enetaddr; |
| 843 | priv->iobase = (void __iomem *)bus_to_phys(dev, iobase); |
| 844 | |
| 845 | command = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; |
| 846 | dm_pci_write_config16(dev, PCI_COMMAND, command); |
| 847 | dm_pci_read_config16(dev, PCI_COMMAND, &status); |
| 848 | if ((status & command) != command) { |
| 849 | printf("eepro100: Couldn't enable IO access or Bus Mastering\n"); |
| 850 | return -EINVAL; |
| 851 | } |
| 852 | |
| 853 | ret = eepro100_initialize_mii(priv); |
| 854 | if (ret) |
| 855 | return ret; |
| 856 | |
| 857 | dm_pci_write_config8(dev, PCI_LATENCY_TIMER, 0x20); |
| 858 | |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | static const struct eth_ops eepro100_ops = { |
| 863 | .start = eepro100_start, |
| 864 | .send = eepro100_send, |
| 865 | .recv = eepro100_recv, |
| 866 | .stop = eepro100_stop, |
| 867 | .free_pkt = eepro100_free_pkt, |
| 868 | .read_rom_hwaddr = eepro100_read_rom_hwaddr, |
| 869 | }; |
| 870 | |
| 871 | U_BOOT_DRIVER(eth_eepro100) = { |
| 872 | .name = "eth_eepro100", |
| 873 | .id = UCLASS_ETH, |
| 874 | .bind = eepro100_bind, |
| 875 | .probe = eepro100_probe, |
| 876 | .ops = &eepro100_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 877 | .priv_auto = sizeof(struct eepro100_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 878 | .plat_auto = sizeof(struct eth_pdata), |
Marek Vasut | cbc44b8 | 2020-05-23 16:26:20 +0200 | [diff] [blame] | 879 | }; |
| 880 | |
| 881 | U_BOOT_PCI_DEVICE(eth_eepro100, supported); |