Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2 | |
| 3 | #include <common.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 4 | #include <env.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 5 | #include <malloc.h> |
| 6 | #include <net.h> |
Ben Warren | 840f8a5 | 2008-08-31 10:45:44 -0700 | [diff] [blame] | 7 | #include <netdev.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 8 | #include <pci.h> |
| 9 | |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 10 | #define SROM_DLEVEL 0 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 11 | |
| 12 | #undef UPDATE_SROM |
| 13 | |
Marek Vasut | 81d10f7 | 2020-04-19 03:09:26 +0200 | [diff] [blame] | 14 | /* PCI Registers. */ |
| 15 | #define PCI_CFDA_PSM 0x43 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 16 | |
| 17 | #define CFRV_RN 0x000000f0 /* Revision Number */ |
| 18 | |
| 19 | #define WAKEUP 0x00 /* Power Saving Wakeup */ |
| 20 | #define SLEEP 0x80 /* Power Saving Sleep Mode */ |
| 21 | |
Marek Vasut | 81d10f7 | 2020-04-19 03:09:26 +0200 | [diff] [blame] | 22 | #define DC2114x_BRK 0x0020 /* CFRV break between DC21142 & DC21143 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 23 | |
Marek Vasut | 81d10f7 | 2020-04-19 03:09:26 +0200 | [diff] [blame] | 24 | /* Ethernet chip registers. */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 25 | #define DE4X5_BMR 0x000 /* Bus Mode Register */ |
| 26 | #define DE4X5_TPD 0x008 /* Transmit Poll Demand Reg */ |
| 27 | #define DE4X5_RRBA 0x018 /* RX Ring Base Address Reg */ |
| 28 | #define DE4X5_TRBA 0x020 /* TX Ring Base Address Reg */ |
| 29 | #define DE4X5_STS 0x028 /* Status Register */ |
| 30 | #define DE4X5_OMR 0x030 /* Operation Mode Register */ |
| 31 | #define DE4X5_SICR 0x068 /* SIA Connectivity Register */ |
| 32 | #define DE4X5_APROM 0x048 /* Ethernet Address PROM */ |
| 33 | |
Marek Vasut | 81d10f7 | 2020-04-19 03:09:26 +0200 | [diff] [blame] | 34 | /* Register bits. */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 35 | #define BMR_SWR 0x00000001 /* Software Reset */ |
| 36 | #define STS_TS 0x00700000 /* Transmit Process State */ |
| 37 | #define STS_RS 0x000e0000 /* Receive Process State */ |
| 38 | #define OMR_ST 0x00002000 /* Start/Stop Transmission Command */ |
| 39 | #define OMR_SR 0x00000002 /* Start/Stop Receive */ |
| 40 | #define OMR_PS 0x00040000 /* Port Select */ |
| 41 | #define OMR_SDP 0x02000000 /* SD Polarity - MUST BE ASSERTED */ |
| 42 | #define OMR_PM 0x00000080 /* Pass All Multicast */ |
| 43 | |
Marek Vasut | 81d10f7 | 2020-04-19 03:09:26 +0200 | [diff] [blame] | 44 | /* Descriptor bits. */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 45 | #define R_OWN 0x80000000 /* Own Bit */ |
| 46 | #define RD_RER 0x02000000 /* Receive End Of Ring */ |
| 47 | #define RD_LS 0x00000100 /* Last Descriptor */ |
| 48 | #define RD_ES 0x00008000 /* Error Summary */ |
| 49 | #define TD_TER 0x02000000 /* Transmit End Of Ring */ |
| 50 | #define T_OWN 0x80000000 /* Own Bit */ |
| 51 | #define TD_LS 0x40000000 /* Last Segment */ |
| 52 | #define TD_FS 0x20000000 /* First Segment */ |
| 53 | #define TD_ES 0x00008000 /* Error Summary */ |
| 54 | #define TD_SET 0x08000000 /* Setup Packet */ |
| 55 | |
| 56 | /* The EEPROM commands include the alway-set leading bit. */ |
| 57 | #define SROM_WRITE_CMD 5 |
| 58 | #define SROM_READ_CMD 6 |
| 59 | #define SROM_ERASE_CMD 7 |
| 60 | |
Marek Vasut | 81d10f7 | 2020-04-19 03:09:26 +0200 | [diff] [blame] | 61 | #define SROM_HWADD 0x0014 /* Hardware Address offset in SROM */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 62 | #define SROM_RD 0x00004000 /* Read from Boot ROM */ |
Marek Vasut | 81d10f7 | 2020-04-19 03:09:26 +0200 | [diff] [blame] | 63 | #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */ |
| 64 | #define EE_WRITE_0 0x4801 |
| 65 | #define EE_WRITE_1 0x4805 |
| 66 | #define EE_DATA_READ 0x08 /* EEPROM chip data out. */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 67 | #define SROM_SR 0x00000800 /* Select Serial ROM when set */ |
| 68 | |
| 69 | #define DT_IN 0x00000004 /* Serial Data In */ |
| 70 | #define DT_CLK 0x00000002 /* Serial ROM Clock */ |
| 71 | #define DT_CS 0x00000001 /* Serial ROM Chip Select */ |
| 72 | |
| 73 | #define POLL_DEMAND 1 |
| 74 | |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 75 | #if defined(CONFIG_E500) |
| 76 | #define phys_to_bus(a) (a) |
| 77 | #else |
| 78 | #define phys_to_bus(a) pci_phys_to_mem((pci_dev_t)dev->priv, a) |
| 79 | #endif |
| 80 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 81 | #define NUM_RX_DESC PKTBUFSRX |
| 82 | #define NUM_TX_DESC 1 /* Number of TX descriptors */ |
| 83 | #define RX_BUFF_SZ PKTSIZE_ALIGN |
| 84 | |
| 85 | #define TOUT_LOOP 1000000 |
| 86 | |
| 87 | #define SETUP_FRAME_LEN 192 |
| 88 | |
| 89 | struct de4x5_desc { |
| 90 | volatile s32 status; |
| 91 | u32 des1; |
| 92 | u32 buf; |
| 93 | u32 next; |
| 94 | }; |
| 95 | |
| 96 | /* RX and TX descriptor ring */ |
| 97 | static struct de4x5_desc rx_ring[NUM_RX_DESC] __aligned(32); |
| 98 | static struct de4x5_desc tx_ring[NUM_TX_DESC] __aligned(32); |
| 99 | static int rx_new; /* RX descriptor ring pointer */ |
| 100 | static int tx_new; /* TX descriptor ring pointer */ |
| 101 | |
| 102 | static char rx_ring_size; |
| 103 | static char tx_ring_size; |
| 104 | |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 105 | static u32 dc2114x_inl(struct eth_device *dev, u32 addr) |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 106 | { |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 107 | return le32_to_cpu(*(volatile u32 *)(addr + dev->iobase)); |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 110 | static void dc2114x_outl(struct eth_device *dev, u32 command, u32 addr) |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 111 | { |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 112 | *(volatile u32 *)(addr + dev->iobase) = cpu_to_le32(command); |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static void reset_de4x5(struct eth_device *dev) |
| 116 | { |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 117 | u32 i; |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 118 | |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 119 | i = dc2114x_inl(dev, DE4X5_BMR); |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 120 | mdelay(1); |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 121 | dc2114x_outl(dev, i | BMR_SWR, DE4X5_BMR); |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 122 | mdelay(1); |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 123 | dc2114x_outl(dev, i, DE4X5_BMR); |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 124 | mdelay(1); |
| 125 | |
| 126 | for (i = 0; i < 5; i++) { |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 127 | dc2114x_inl(dev, DE4X5_BMR); |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 128 | mdelay(10); |
| 129 | } |
| 130 | |
| 131 | mdelay(1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 134 | static void start_de4x5(struct eth_device *dev) |
| 135 | { |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 136 | u32 omr; |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 137 | |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 138 | omr = dc2114x_inl(dev, DE4X5_OMR); |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 139 | omr |= OMR_ST | OMR_SR; |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 140 | dc2114x_outl(dev, omr, DE4X5_OMR); /* Enable the TX and/or RX */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 143 | static void stop_de4x5(struct eth_device *dev) |
| 144 | { |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 145 | u32 omr; |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 146 | |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 147 | omr = dc2114x_inl(dev, DE4X5_OMR); |
Marek Vasut | 75244fb | 2020-04-19 03:36:46 +0200 | [diff] [blame] | 148 | omr &= ~(OMR_ST | OMR_SR); |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 149 | dc2114x_outl(dev, omr, DE4X5_OMR); /* Disable the TX and/or RX */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 152 | /* SROM Read and write routines. */ |
| 153 | static void sendto_srom(struct eth_device *dev, u_int command, u_long addr) |
| 154 | { |
| 155 | dc2114x_outl(dev, command, addr); |
| 156 | udelay(1); |
| 157 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 158 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 159 | static int getfrom_srom(struct eth_device *dev, u_long addr) |
| 160 | { |
| 161 | u32 tmp = dc2114x_inl(dev, addr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 162 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 163 | udelay(1); |
| 164 | return tmp; |
| 165 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 166 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 167 | /* Note: this routine returns extra data bits for size detection. */ |
| 168 | static int do_read_eeprom(struct eth_device *dev, u_long ioaddr, int location, |
| 169 | int addr_len) |
| 170 | { |
| 171 | int read_cmd = location | (SROM_READ_CMD << addr_len); |
| 172 | unsigned int retval = 0; |
| 173 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 174 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 175 | sendto_srom(dev, SROM_RD | SROM_SR, ioaddr); |
| 176 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 177 | |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 178 | debug_cond(SROM_DLEVEL >= 1, " EEPROM read at %d ", location); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 179 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 180 | /* Shift the read command bits out. */ |
| 181 | for (i = 4 + addr_len; i >= 0; i--) { |
| 182 | short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 183 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 184 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS | dataval, |
| 185 | ioaddr); |
| 186 | udelay(10); |
| 187 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS | dataval | DT_CLK, |
| 188 | ioaddr); |
| 189 | udelay(10); |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 190 | debug_cond(SROM_DLEVEL >= 2, "%X", |
| 191 | getfrom_srom(dev, ioaddr) & 15); |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 192 | retval = (retval << 1) | |
| 193 | !!(getfrom_srom(dev, ioaddr) & EE_DATA_READ); |
| 194 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 195 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 196 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 197 | |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 198 | debug_cond(SROM_DLEVEL >= 2, " :%X:", getfrom_srom(dev, ioaddr) & 15); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 199 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 200 | for (i = 16; i > 0; i--) { |
| 201 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS | DT_CLK, ioaddr); |
| 202 | udelay(10); |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 203 | debug_cond(SROM_DLEVEL >= 2, "%X", |
| 204 | getfrom_srom(dev, ioaddr) & 15); |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 205 | retval = (retval << 1) | |
| 206 | !!(getfrom_srom(dev, ioaddr) & EE_DATA_READ); |
| 207 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr); |
| 208 | udelay(10); |
| 209 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 210 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 211 | /* Terminate the EEPROM access. */ |
| 212 | sendto_srom(dev, SROM_RD | SROM_SR, ioaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 213 | |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 214 | debug_cond(SROM_DLEVEL >= 2, " EEPROM value at %d is %5.5x.\n", |
| 215 | location, retval); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 216 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 217 | return retval; |
| 218 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 219 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 220 | /* |
| 221 | * This executes a generic EEPROM command, typically a write or write |
| 222 | * enable. It returns the data output from the EEPROM, and thus may |
| 223 | * also be used for reads. |
| 224 | */ |
| 225 | static int do_eeprom_cmd(struct eth_device *dev, u_long ioaddr, int cmd, |
| 226 | int cmd_len) |
| 227 | { |
| 228 | unsigned int retval = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 229 | |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 230 | debug_cond(SROM_DLEVEL >= 1, " EEPROM op 0x%x: ", cmd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 231 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 232 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS | DT_CLK, ioaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 233 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 234 | /* Shift the command bits out. */ |
| 235 | do { |
| 236 | short dataval = (cmd & BIT(cmd_len)) ? EE_WRITE_1 : EE_WRITE_0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 237 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 238 | sendto_srom(dev, dataval, ioaddr); |
| 239 | udelay(10); |
Marek Vasut | 268cc5b | 2020-04-19 03:09:47 +0200 | [diff] [blame] | 240 | |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 241 | debug_cond(SROM_DLEVEL >= 2, "%X", |
| 242 | getfrom_srom(dev, ioaddr) & 15); |
Nobuhiro Iwamatsu | d45fa74 | 2010-10-19 14:03:40 +0900 | [diff] [blame] | 243 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 244 | sendto_srom(dev, dataval | DT_CLK, ioaddr); |
| 245 | udelay(10); |
| 246 | retval = (retval << 1) | |
| 247 | !!(getfrom_srom(dev, ioaddr) & EE_DATA_READ); |
| 248 | } while (--cmd_len >= 0); |
wdenk | 0260cd6 | 2004-01-02 15:01:32 +0000 | [diff] [blame] | 249 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 250 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 251 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 252 | /* Terminate the EEPROM access. */ |
| 253 | sendto_srom(dev, SROM_RD | SROM_SR, ioaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 254 | |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 255 | debug_cond(SROM_DLEVEL >= 1, " EEPROM result is 0x%5.5x.\n", retval); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 256 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 257 | return retval; |
| 258 | } |
Marek Vasut | 331e4ec | 2020-04-18 01:56:51 +0200 | [diff] [blame] | 259 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 260 | static int read_srom(struct eth_device *dev, u_long ioaddr, int index) |
| 261 | { |
| 262 | int ee_addr_size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 263 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 264 | ee_addr_size = (do_read_eeprom(dev, ioaddr, 0xff, 8) & BIT(18)) ? 8 : 6; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 265 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 266 | return do_eeprom_cmd(dev, ioaddr, 0xffff | |
| 267 | (((SROM_READ_CMD << ee_addr_size) | index) << 16), |
| 268 | 3 + ee_addr_size + 16); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 271 | #ifdef UPDATE_SROM |
| 272 | static int write_srom(struct eth_device *dev, u_long ioaddr, int index, |
| 273 | int new_value) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 274 | { |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 275 | unsigned short newval; |
| 276 | int ee_addr_size; |
Marek Vasut | 268cc5b | 2020-04-19 03:09:47 +0200 | [diff] [blame] | 277 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 278 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 279 | ee_addr_size = (do_read_eeprom(dev, ioaddr, 0xff, 8) & BIT(18)) ? 8 : 6; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 280 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 281 | udelay(10 * 1000); /* test-only */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 282 | |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 283 | debug_cond(SROM_DLEVEL >= 1, "ee_addr_size=%d.\n", ee_addr_size); |
| 284 | debug_cond(SROM_DLEVEL >= 1, |
| 285 | "Writing new entry 0x%4.4x to offset %d.\n", |
| 286 | new_value, index); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 287 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 288 | /* Enable programming modes. */ |
| 289 | do_eeprom_cmd(dev, ioaddr, 0x4f << (ee_addr_size - 4), |
| 290 | 3 + ee_addr_size); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 291 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 292 | /* Do the actual write. */ |
| 293 | do_eeprom_cmd(dev, ioaddr, new_value | |
| 294 | (((SROM_WRITE_CMD << ee_addr_size) | index) << 16), |
| 295 | 3 + ee_addr_size + 16); |
| 296 | |
| 297 | /* Poll for write finished. */ |
| 298 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr); |
| 299 | for (i = 0; i < 10000; i++) { /* Typical 2000 ticks */ |
| 300 | if (getfrom_srom(dev, ioaddr) & EE_DATA_READ) |
| 301 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 304 | debug_cond(SROM_DLEVEL >= 1, " Write finished after %d ticks.\n", i); |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 305 | |
| 306 | /* Disable programming. */ |
| 307 | do_eeprom_cmd(dev, ioaddr, (0x40 << (ee_addr_size - 4)), |
| 308 | 3 + ee_addr_size); |
| 309 | |
| 310 | /* And read the result. */ |
| 311 | newval = do_eeprom_cmd(dev, ioaddr, |
| 312 | (((SROM_READ_CMD << ee_addr_size) | index) << 16) |
| 313 | | 0xffff, 3 + ee_addr_size + 16); |
Marek Vasut | 091eea8 | 2020-04-19 04:05:44 +0200 | [diff] [blame^] | 314 | |
| 315 | debug_cond(SROM_DLEVEL >= 1, " New value at offset %d is %4.4x.\n", |
| 316 | index, newval); |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 317 | |
| 318 | return 1; |
| 319 | } |
| 320 | |
| 321 | static void update_srom(struct eth_device *dev, bd_t *bis) |
| 322 | { |
| 323 | static unsigned short eeprom[0x40] = { |
| 324 | 0x140b, 0x6610, 0x0000, 0x0000, /* 00 */ |
| 325 | 0x0000, 0x0000, 0x0000, 0x0000, /* 04 */ |
| 326 | 0x00a3, 0x0103, 0x0000, 0x0000, /* 08 */ |
| 327 | 0x0000, 0x1f00, 0x0000, 0x0000, /* 0c */ |
| 328 | 0x0108, 0x038d, 0x0000, 0x0000, /* 10 */ |
| 329 | 0xe078, 0x0001, 0x0040, 0x0018, /* 14 */ |
| 330 | 0x0000, 0x0000, 0x0000, 0x0000, /* 18 */ |
| 331 | 0x0000, 0x0000, 0x0000, 0x0000, /* 1c */ |
| 332 | 0x0000, 0x0000, 0x0000, 0x0000, /* 20 */ |
| 333 | 0x0000, 0x0000, 0x0000, 0x0000, /* 24 */ |
| 334 | 0x0000, 0x0000, 0x0000, 0x0000, /* 28 */ |
| 335 | 0x0000, 0x0000, 0x0000, 0x0000, /* 2c */ |
| 336 | 0x0000, 0x0000, 0x0000, 0x0000, /* 30 */ |
| 337 | 0x0000, 0x0000, 0x0000, 0x0000, /* 34 */ |
| 338 | 0x0000, 0x0000, 0x0000, 0x0000, /* 38 */ |
| 339 | 0x0000, 0x0000, 0x0000, 0x4e07, /* 3c */ |
| 340 | }; |
| 341 | uchar enetaddr[6]; |
| 342 | int i; |
| 343 | |
| 344 | /* Ethernet Addr... */ |
| 345 | if (!eth_env_get_enetaddr("ethaddr", enetaddr)) |
| 346 | return; |
| 347 | |
| 348 | eeprom[0x0a] = (enetaddr[1] << 8) | enetaddr[0]; |
| 349 | eeprom[0x0b] = (enetaddr[3] << 8) | enetaddr[2]; |
| 350 | eeprom[0x0c] = (enetaddr[5] << 8) | enetaddr[4]; |
| 351 | |
| 352 | for (i = 0; i < 0x40; i++) |
| 353 | write_srom(dev, DE4X5_APROM, i, eeprom[i]); |
| 354 | } |
| 355 | #endif /* UPDATE_SROM */ |
| 356 | |
| 357 | static void send_setup_frame(struct eth_device *dev, bd_t *bis) |
| 358 | { |
| 359 | char setup_frame[SETUP_FRAME_LEN]; |
| 360 | char *pa = &setup_frame[0]; |
| 361 | int i; |
| 362 | |
| 363 | memset(pa, 0xff, SETUP_FRAME_LEN); |
| 364 | |
| 365 | for (i = 0; i < ETH_ALEN; i++) { |
| 366 | *(pa + (i & 1)) = dev->enetaddr[i]; |
| 367 | if (i & 0x01) |
| 368 | pa += 4; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 371 | for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) { |
| 372 | if (i < TOUT_LOOP) |
| 373 | continue; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 374 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 375 | printf("%s: tx error buffer not ready\n", dev->name); |
| 376 | return; |
| 377 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 378 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 379 | tx_ring[tx_new].buf = cpu_to_le32(phys_to_bus((u32)&setup_frame[0])); |
| 380 | tx_ring[tx_new].des1 = cpu_to_le32(TD_TER | TD_SET | SETUP_FRAME_LEN); |
| 381 | tx_ring[tx_new].status = cpu_to_le32(T_OWN); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 382 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 383 | dc2114x_outl(dev, POLL_DEMAND, DE4X5_TPD); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 384 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 385 | for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) { |
| 386 | if (i < TOUT_LOOP) |
| 387 | continue; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 388 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 389 | printf("%s: tx buffer not ready\n", dev->name); |
| 390 | return; |
| 391 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 392 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 393 | if (le32_to_cpu(tx_ring[tx_new].status) != 0x7FFFFFFF) { |
| 394 | printf("TX error status2 = 0x%08X\n", |
| 395 | le32_to_cpu(tx_ring[tx_new].status)); |
| 396 | } |
| 397 | |
| 398 | tx_new = (tx_new + 1) % NUM_TX_DESC; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Joe Hershberger | cfb0cee | 2012-05-21 14:45:22 +0000 | [diff] [blame] | 401 | static int dc21x4x_send(struct eth_device *dev, void *packet, int length) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 402 | { |
Marek Vasut | e3ffef3 | 2020-04-19 03:10:14 +0200 | [diff] [blame] | 403 | int status = -1; |
| 404 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 405 | |
| 406 | if (length <= 0) { |
| 407 | printf("%s: bad packet size: %d\n", dev->name, length); |
Marek Vasut | e3ffef3 | 2020-04-19 03:10:14 +0200 | [diff] [blame] | 408 | goto done; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Marek Vasut | e3ffef3 | 2020-04-19 03:10:14 +0200 | [diff] [blame] | 411 | for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) { |
| 412 | if (i < TOUT_LOOP) |
| 413 | continue; |
| 414 | |
| 415 | printf("%s: tx error buffer not ready\n", dev->name); |
| 416 | goto done; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Marek Vasut | e3ffef3 | 2020-04-19 03:10:14 +0200 | [diff] [blame] | 419 | tx_ring[tx_new].buf = cpu_to_le32(phys_to_bus((u32)packet)); |
| 420 | tx_ring[tx_new].des1 = cpu_to_le32(TD_TER | TD_LS | TD_FS | length); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 421 | tx_ring[tx_new].status = cpu_to_le32(T_OWN); |
| 422 | |
Marek Vasut | f02b701 | 2020-04-19 03:40:03 +0200 | [diff] [blame] | 423 | dc2114x_outl(dev, POLL_DEMAND, DE4X5_TPD); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 424 | |
Marek Vasut | e3ffef3 | 2020-04-19 03:10:14 +0200 | [diff] [blame] | 425 | for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) { |
| 426 | if (i < TOUT_LOOP) |
| 427 | continue; |
| 428 | |
| 429 | printf(".%s: tx buffer not ready\n", dev->name); |
| 430 | goto done; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | if (le32_to_cpu(tx_ring[tx_new].status) & TD_ES) { |
wdenk | 0260cd6 | 2004-01-02 15:01:32 +0000 | [diff] [blame] | 434 | tx_ring[tx_new].status = 0x0; |
Marek Vasut | e3ffef3 | 2020-04-19 03:10:14 +0200 | [diff] [blame] | 435 | goto done; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | status = length; |
| 439 | |
Marek Vasut | e3ffef3 | 2020-04-19 03:10:14 +0200 | [diff] [blame] | 440 | done: |
| 441 | tx_new = (tx_new + 1) % NUM_TX_DESC; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 442 | return status; |
| 443 | } |
| 444 | |
Marek Vasut | f30abb7 | 2020-04-19 03:10:25 +0200 | [diff] [blame] | 445 | static int dc21x4x_recv(struct eth_device *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 446 | { |
Marek Vasut | f30abb7 | 2020-04-19 03:10:25 +0200 | [diff] [blame] | 447 | int length = 0; |
| 448 | u32 status; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 449 | |
Marek Vasut | f30abb7 | 2020-04-19 03:10:25 +0200 | [diff] [blame] | 450 | while (true) { |
| 451 | status = le32_to_cpu(rx_ring[rx_new].status); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 452 | |
Marek Vasut | f30abb7 | 2020-04-19 03:10:25 +0200 | [diff] [blame] | 453 | if (status & R_OWN) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 454 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 455 | |
| 456 | if (status & RD_LS) { |
Marek Vasut | f30abb7 | 2020-04-19 03:10:25 +0200 | [diff] [blame] | 457 | /* Valid frame status. */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 458 | if (status & RD_ES) { |
Marek Vasut | f30abb7 | 2020-04-19 03:10:25 +0200 | [diff] [blame] | 459 | /* There was an error. */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 460 | printf("RX error status = 0x%08X\n", status); |
| 461 | } else { |
Marek Vasut | f30abb7 | 2020-04-19 03:10:25 +0200 | [diff] [blame] | 462 | /* A valid frame received. */ |
| 463 | length = (le32_to_cpu(rx_ring[rx_new].status) |
| 464 | >> 16); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 465 | |
Marek Vasut | f30abb7 | 2020-04-19 03:10:25 +0200 | [diff] [blame] | 466 | /* Pass the packet up to the protocol layers */ |
| 467 | net_process_received_packet |
| 468 | (net_rx_packets[rx_new], length - 4); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Marek Vasut | f30abb7 | 2020-04-19 03:10:25 +0200 | [diff] [blame] | 471 | /* |
| 472 | * Change buffer ownership for this frame, |
| 473 | * back to the adapter. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 474 | */ |
| 475 | rx_ring[rx_new].status = cpu_to_le32(R_OWN); |
| 476 | } |
| 477 | |
Marek Vasut | f30abb7 | 2020-04-19 03:10:25 +0200 | [diff] [blame] | 478 | /* Update entry information. */ |
Marek Vasut | 81d10f7 | 2020-04-19 03:09:26 +0200 | [diff] [blame] | 479 | rx_new = (rx_new + 1) % rx_ring_size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | return length; |
| 483 | } |
| 484 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 485 | static int dc21x4x_init(struct eth_device *dev, bd_t *bis) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 486 | { |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 487 | int i; |
Marek Vasut | 1f34678 | 2020-04-19 03:10:30 +0200 | [diff] [blame] | 488 | int devbusfn = (int)dev->priv; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 489 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 490 | /* Ensure we're not sleeping. */ |
| 491 | pci_write_config_byte(devbusfn, PCI_CFDA_PSM, WAKEUP); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 492 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 493 | reset_de4x5(dev); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 494 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 495 | if (dc2114x_inl(dev, DE4X5_STS) & (STS_TS | STS_RS)) { |
| 496 | printf("Error: Cannot reset ethernet controller.\n"); |
| 497 | return -1; |
| 498 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 499 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 500 | dc2114x_outl(dev, OMR_SDP | OMR_PS | OMR_PM, DE4X5_OMR); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 501 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 502 | for (i = 0; i < NUM_RX_DESC; i++) { |
| 503 | rx_ring[i].status = cpu_to_le32(R_OWN); |
| 504 | rx_ring[i].des1 = cpu_to_le32(RX_BUFF_SZ); |
| 505 | rx_ring[i].buf = |
| 506 | cpu_to_le32(phys_to_bus((u32)net_rx_packets[i])); |
| 507 | rx_ring[i].next = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 510 | for (i = 0; i < NUM_TX_DESC; i++) { |
| 511 | tx_ring[i].status = 0; |
| 512 | tx_ring[i].des1 = 0; |
| 513 | tx_ring[i].buf = 0; |
| 514 | tx_ring[i].next = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 517 | rx_ring_size = NUM_RX_DESC; |
| 518 | tx_ring_size = NUM_TX_DESC; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 519 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 520 | /* Write the end of list marker to the descriptor lists. */ |
| 521 | rx_ring[rx_ring_size - 1].des1 |= cpu_to_le32(RD_RER); |
| 522 | tx_ring[tx_ring_size - 1].des1 |= cpu_to_le32(TD_TER); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 523 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 524 | /* Tell the adapter where the TX/RX rings are located. */ |
| 525 | dc2114x_outl(dev, phys_to_bus((u32)&rx_ring), DE4X5_RRBA); |
| 526 | dc2114x_outl(dev, phys_to_bus((u32)&tx_ring), DE4X5_TRBA); |
Marek Vasut | e13635a | 2020-04-19 03:10:50 +0200 | [diff] [blame] | 527 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 528 | start_de4x5(dev); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 529 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 530 | tx_new = 0; |
| 531 | rx_new = 0; |
wdenk | 0260cd6 | 2004-01-02 15:01:32 +0000 | [diff] [blame] | 532 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 533 | send_setup_frame(dev, bis); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 534 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 535 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 538 | static void dc21x4x_halt(struct eth_device *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 539 | { |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 540 | int devbusfn = (int)dev->priv; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 541 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 542 | stop_de4x5(dev); |
| 543 | dc2114x_outl(dev, 0, DE4X5_SICR); |
| 544 | |
| 545 | pci_write_config_byte(devbusfn, PCI_CFDA_PSM, SLEEP); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 548 | static void read_hw_addr(struct eth_device *dev, bd_t *bis) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 549 | { |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 550 | u_short tmp, *p = (u_short *)(&dev->enetaddr[0]); |
| 551 | int i, j = 0; |
Marek Vasut | b46c7a0 | 2020-04-19 03:11:06 +0200 | [diff] [blame] | 552 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 553 | for (i = 0; i < (ETH_ALEN >> 1); i++) { |
| 554 | tmp = read_srom(dev, DE4X5_APROM, (SROM_HWADD >> 1) + i); |
| 555 | *p = le16_to_cpu(tmp); |
| 556 | j += *p++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 559 | if (!j || j == 0x2fffd) { |
| 560 | memset(dev->enetaddr, 0, ETH_ALEN); |
| 561 | debug("Warning: can't read HW address from SROM.\n"); |
| 562 | #ifdef UPDATE_SROM |
| 563 | update_srom(dev, bis); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 564 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 565 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 568 | static struct pci_device_id supported[] = { |
| 569 | { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST }, |
| 570 | { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21142 }, |
| 571 | { } |
| 572 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 573 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 574 | int dc21x4x_initialize(bd_t *bis) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 575 | { |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 576 | struct eth_device *dev; |
| 577 | unsigned short status; |
| 578 | unsigned char timer; |
| 579 | unsigned int iobase; |
| 580 | int card_number = 0; |
| 581 | pci_dev_t devbusfn; |
| 582 | unsigned int cfrv; |
| 583 | int idx = 0; |
Marek Vasut | b46c7a0 | 2020-04-19 03:11:06 +0200 | [diff] [blame] | 584 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 585 | while (1) { |
| 586 | devbusfn = pci_find_devices(supported, idx++); |
| 587 | if (devbusfn == -1) |
| 588 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 589 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 590 | /* Get the chip configuration revision register. */ |
| 591 | pci_read_config_dword(devbusfn, PCI_REVISION_ID, &cfrv); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 592 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 593 | if ((cfrv & CFRV_RN) < DC2114x_BRK) { |
| 594 | printf("Error: The chip is not DC21143.\n"); |
| 595 | continue; |
| 596 | } |
Marek Vasut | b46c7a0 | 2020-04-19 03:11:06 +0200 | [diff] [blame] | 597 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 598 | pci_read_config_word(devbusfn, PCI_COMMAND, &status); |
| 599 | status |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; |
| 600 | pci_write_config_word(devbusfn, PCI_COMMAND, status); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 601 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 602 | pci_read_config_word(devbusfn, PCI_COMMAND, &status); |
| 603 | if (!(status & PCI_COMMAND_MEMORY)) { |
| 604 | printf("Error: Can not enable MEMORY access.\n"); |
| 605 | continue; |
| 606 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 607 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 608 | if (!(status & PCI_COMMAND_MASTER)) { |
| 609 | printf("Error: Can not enable Bus Mastering.\n"); |
| 610 | continue; |
| 611 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 612 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 613 | /* Check the latency timer for values >= 0x60. */ |
| 614 | pci_read_config_byte(devbusfn, PCI_LATENCY_TIMER, &timer); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 615 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 616 | if (timer < 0x60) { |
| 617 | pci_write_config_byte(devbusfn, PCI_LATENCY_TIMER, |
| 618 | 0x60); |
| 619 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 620 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 621 | /* read BAR for memory space access */ |
| 622 | pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_1, &iobase); |
| 623 | iobase &= PCI_BASE_ADDRESS_MEM_MASK; |
| 624 | debug("dc21x4x: DEC 21142 PCI Device @0x%x\n", iobase); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 625 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 626 | dev = (struct eth_device *)malloc(sizeof(*dev)); |
| 627 | if (!dev) { |
| 628 | printf("Can not allocalte memory of dc21x4x\n"); |
| 629 | break; |
| 630 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 631 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 632 | memset(dev, 0, sizeof(*dev)); |
Marek Vasut | b46c7a0 | 2020-04-19 03:11:06 +0200 | [diff] [blame] | 633 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 634 | sprintf(dev->name, "dc21x4x#%d", card_number); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 635 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 636 | dev->iobase = pci_mem_to_phys(devbusfn, iobase); |
| 637 | dev->priv = (void *)devbusfn; |
| 638 | dev->init = dc21x4x_init; |
| 639 | dev->halt = dc21x4x_halt; |
| 640 | dev->send = dc21x4x_send; |
| 641 | dev->recv = dc21x4x_recv; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 642 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 643 | /* Ensure we're not sleeping. */ |
| 644 | pci_write_config_byte(devbusfn, PCI_CFDA_PSM, WAKEUP); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 645 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 646 | udelay(10 * 1000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 647 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 648 | read_hw_addr(dev, bis); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 649 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 650 | eth_register(dev); |
Marek Vasut | b46c7a0 | 2020-04-19 03:11:06 +0200 | [diff] [blame] | 651 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 652 | card_number++; |
| 653 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 654 | |
Marek Vasut | 5e2ad05 | 2020-04-19 04:00:49 +0200 | [diff] [blame] | 655 | return card_number; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 656 | } |