ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU i8255x (PRO100) emulation |
| 3 | * |
Stefan Weil | 230a167 | 2010-03-02 22:37:47 +0100 | [diff] [blame] | 4 | * Copyright (C) 2006-2010 Stefan Weil |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 5 | * |
| 6 | * Portions of the code are copies from grub / etherboot eepro100.c |
| 7 | * and linux e100.c. |
| 8 | * |
Stefan Weil | 230a167 | 2010-03-02 22:37:47 +0100 | [diff] [blame] | 9 | * This program is free software: you can redistribute it and/or modify |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 10 | * it under the terms of the GNU General Public License as published by |
Stefan Weil | 230a167 | 2010-03-02 22:37:47 +0100 | [diff] [blame] | 11 | * the Free Software Foundation, either version 2 of the License, or |
| 12 | * (at your option) version 3 or any later version. |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
Stefan Weil | 230a167 | 2010-03-02 22:37:47 +0100 | [diff] [blame] | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 21 | * |
| 22 | * Tested features (i82559): |
Stefan Weil | 6cded3a | 2010-03-02 22:37:43 +0100 | [diff] [blame] | 23 | * PXE boot (i386) ok |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 24 | * Linux networking (i386) ok |
| 25 | * |
| 26 | * Untested: |
| 27 | * non-i386 platforms |
| 28 | * Windows networking |
| 29 | * |
| 30 | * References: |
| 31 | * |
| 32 | * Intel 8255x 10/100 Mbps Ethernet Controller Family |
| 33 | * Open Source Software Developer Manual |
Stefan Weil | ba19f2d | 2010-03-02 22:37:46 +0100 | [diff] [blame] | 34 | * |
| 35 | * TODO: |
| 36 | * * PHY emulation should be separated from nic emulation. |
| 37 | * Most nic emulations could share the same phy code. |
| 38 | * * i82550 is untested. It is programmed like the i82559. |
| 39 | * * i82562 is untested. It is programmed like the i82559. |
| 40 | * * Power management (i82558 and later) is not implemented. |
| 41 | * * Wake-on-LAN is not implemented. |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 42 | */ |
| 43 | |
Stefan Weil | 78728c9 | 2010-03-02 22:38:00 +0100 | [diff] [blame] | 44 | #include <stdbool.h> /* bool */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 45 | #include <stddef.h> /* offsetof */ |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 46 | #include "hw.h" |
| 47 | #include "pci.h" |
| 48 | #include "net.h" |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 49 | #include "eeprom93xx.h" |
| 50 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 51 | #define KiB 1024 |
| 52 | |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 53 | /* Debug EEPRO100 card. */ |
Stefan Weil | ce0e58b | 2010-03-02 22:37:41 +0100 | [diff] [blame] | 54 | #if 0 |
| 55 | # define DEBUG_EEPRO100 |
| 56 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 57 | |
| 58 | #ifdef DEBUG_EEPRO100 |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 59 | #define logout(fmt, ...) fprintf(stderr, "EE100\t%-24s" fmt, __func__, ## __VA_ARGS__) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 60 | #else |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 61 | #define logout(fmt, ...) ((void)0) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 62 | #endif |
| 63 | |
| 64 | /* Set flags to 0 to disable debug output. */ |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 65 | #define INT 1 /* interrupt related actions */ |
| 66 | #define MDI 1 /* mdi related actions */ |
| 67 | #define OTHER 1 |
| 68 | #define RXTX 1 |
| 69 | #define EEPROM 1 /* eeprom related actions */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 70 | |
| 71 | #define TRACE(flag, command) ((flag) ? (command) : (void)0) |
| 72 | |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 73 | #define missing(text) fprintf(stderr, "eepro100: feature is missing in this emulation: " text "\n") |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 74 | |
| 75 | #define MAX_ETH_FRAME_SIZE 1514 |
| 76 | |
| 77 | /* This driver supports several different devices which are declared here. */ |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 78 | #define i82550 0x82550 |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 79 | #define i82551 0x82551 |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 80 | #define i82557A 0x82557a |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 81 | #define i82557B 0x82557b |
| 82 | #define i82557C 0x82557c |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 83 | #define i82558A 0x82558a |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 84 | #define i82558B 0x82558b |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 85 | #define i82559A 0x82559a |
| 86 | #define i82559B 0x82559b |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 87 | #define i82559C 0x82559c |
| 88 | #define i82559ER 0x82559e |
| 89 | #define i82562 0x82562 |
| 90 | |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 91 | /* Use 64 word EEPROM. TODO: could be a runtime option. */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 92 | #define EEPROM_SIZE 64 |
| 93 | |
| 94 | #define PCI_MEM_SIZE (4 * KiB) |
| 95 | #define PCI_IO_SIZE 64 |
| 96 | #define PCI_FLASH_SIZE (128 * KiB) |
| 97 | |
| 98 | #define BIT(n) (1 << (n)) |
| 99 | #define BITS(n, m) (((0xffffffffU << (31 - n)) >> (31 - n + m)) << m) |
| 100 | |
| 101 | /* The SCB accepts the following controls for the Tx and Rx units: */ |
| 102 | #define CU_NOP 0x0000 /* No operation. */ |
| 103 | #define CU_START 0x0010 /* CU start. */ |
| 104 | #define CU_RESUME 0x0020 /* CU resume. */ |
| 105 | #define CU_STATSADDR 0x0040 /* Load dump counters address. */ |
| 106 | #define CU_SHOWSTATS 0x0050 /* Dump statistical counters. */ |
| 107 | #define CU_CMD_BASE 0x0060 /* Load CU base address. */ |
| 108 | #define CU_DUMPSTATS 0x0070 /* Dump and reset statistical counters. */ |
| 109 | #define CU_SRESUME 0x00a0 /* CU static resume. */ |
| 110 | |
| 111 | #define RU_NOP 0x0000 |
| 112 | #define RX_START 0x0001 |
| 113 | #define RX_RESUME 0x0002 |
Stefan Weil | e824012 | 2010-03-02 22:37:53 +0100 | [diff] [blame] | 114 | #define RU_ABORT 0x0004 |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 115 | #define RX_ADDR_LOAD 0x0006 |
| 116 | #define RX_RESUMENR 0x0007 |
| 117 | #define INT_MASK 0x0100 |
| 118 | #define DRVR_INT 0x0200 /* Driver generated interrupt. */ |
| 119 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 120 | /* Offsets to the various registers. |
| 121 | All accesses need not be longword aligned. */ |
| 122 | enum speedo_offsets { |
Stefan Weil | 0908bba | 2010-03-02 22:37:42 +0100 | [diff] [blame] | 123 | SCBStatus = 0, /* Status Word. */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 124 | SCBAck = 1, |
| 125 | SCBCmd = 2, /* Rx/Command Unit command and status. */ |
| 126 | SCBIntmask = 3, |
| 127 | SCBPointer = 4, /* General purpose pointer. */ |
| 128 | SCBPort = 8, /* Misc. commands and operands. */ |
Stefan Weil | 0908bba | 2010-03-02 22:37:42 +0100 | [diff] [blame] | 129 | SCBflash = 12, /* Flash memory control. */ |
| 130 | SCBeeprom = 14, /* EEPROM control. */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 131 | SCBCtrlMDI = 16, /* MDI interface control. */ |
| 132 | SCBEarlyRx = 20, /* Early receive byte count. */ |
Stefan Weil | 0908bba | 2010-03-02 22:37:42 +0100 | [diff] [blame] | 133 | SCBFlow = 24, /* Flow Control. */ |
| 134 | SCBpmdr = 27, /* Power Management Driver. */ |
| 135 | SCBgctrl = 28, /* General Control. */ |
| 136 | SCBgstat = 29, /* General Status. */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | /* A speedo3 transmit buffer descriptor with two buffers... */ |
| 140 | typedef struct { |
| 141 | uint16_t status; |
| 142 | uint16_t command; |
| 143 | uint32_t link; /* void * */ |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 144 | uint32_t tbd_array_addr; /* transmit buffer descriptor array address. */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 145 | uint16_t tcb_bytes; /* transmit command block byte count (in lower 14 bits */ |
| 146 | uint8_t tx_threshold; /* transmit threshold */ |
| 147 | uint8_t tbd_count; /* TBD number */ |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 148 | #if 0 |
| 149 | /* This constitutes two "TBD" entries: hdr and data */ |
| 150 | uint32_t tx_buf_addr0; /* void *, header of frame to be transmitted. */ |
| 151 | int32_t tx_buf_size0; /* Length of Tx hdr. */ |
| 152 | uint32_t tx_buf_addr1; /* void *, data to be transmitted. */ |
| 153 | int32_t tx_buf_size1; /* Length of Tx data. */ |
| 154 | #endif |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 155 | } eepro100_tx_t; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 156 | |
| 157 | /* Receive frame descriptor. */ |
| 158 | typedef struct { |
| 159 | int16_t status; |
| 160 | uint16_t command; |
| 161 | uint32_t link; /* struct RxFD * */ |
| 162 | uint32_t rx_buf_addr; /* void * */ |
| 163 | uint16_t count; |
| 164 | uint16_t size; |
| 165 | char packet[MAX_ETH_FRAME_SIZE + 4]; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 166 | } eepro100_rx_t; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 167 | |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 168 | typedef enum { |
| 169 | COMMAND_EL = BIT(15), |
| 170 | COMMAND_S = BIT(14), |
| 171 | COMMAND_I = BIT(13), |
| 172 | COMMAND_NC = BIT(4), |
| 173 | COMMAND_SF = BIT(3), |
| 174 | COMMAND_CMD = BITS(2, 0), |
| 175 | } scb_command_bit; |
| 176 | |
| 177 | typedef enum { |
| 178 | STATUS_C = BIT(15), |
| 179 | STATUS_OK = BIT(13), |
| 180 | } scb_status_bit; |
| 181 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 182 | typedef struct { |
| 183 | uint32_t tx_good_frames, tx_max_collisions, tx_late_collisions, |
Stefan Weil | cc02c66 | 2010-03-02 22:37:55 +0100 | [diff] [blame] | 184 | tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions, |
| 185 | tx_multiple_collisions, tx_total_collisions; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 186 | uint32_t rx_good_frames, rx_crc_errors, rx_alignment_errors, |
Stefan Weil | cc02c66 | 2010-03-02 22:37:55 +0100 | [diff] [blame] | 187 | rx_resource_errors, rx_overrun_errors, rx_cdt_errors, |
| 188 | rx_short_frame_errors; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 189 | uint32_t fc_xmt_pause, fc_rcv_pause, fc_rcv_unsupported; |
| 190 | uint16_t xmt_tco_frames, rcv_tco_frames; |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 191 | /* TODO: i82559 has six reserved statistics but a total of 24 dwords. */ |
| 192 | uint32_t reserved[4]; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 193 | } eepro100_stats_t; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 194 | |
| 195 | typedef enum { |
| 196 | cu_idle = 0, |
| 197 | cu_suspended = 1, |
| 198 | cu_active = 2, |
| 199 | cu_lpq_active = 2, |
| 200 | cu_hqp_active = 3 |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 201 | } cu_state_t; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 202 | |
| 203 | typedef enum { |
| 204 | ru_idle = 0, |
| 205 | ru_suspended = 1, |
| 206 | ru_no_resources = 2, |
| 207 | ru_ready = 4 |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 208 | } ru_state_t; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 209 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 210 | typedef struct { |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 211 | PCIDevice dev; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 212 | uint8_t mult[8]; /* multicast mask array */ |
| 213 | int mmio_index; |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 214 | NICState *nic; |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 215 | NICConf conf; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 216 | uint8_t scb_stat; /* SCB stat/ack byte */ |
| 217 | uint8_t int_stat; /* PCI interrupt status */ |
Stefan Weil | 3706c43 | 2009-10-09 19:49:58 +0200 | [diff] [blame] | 218 | /* region must not be saved by nic_save. */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 219 | uint32_t region[3]; /* PCI region addresses */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 220 | uint16_t mdimem[32]; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 221 | eeprom_t *eeprom; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 222 | uint32_t device; /* device variant */ |
| 223 | uint32_t pointer; |
| 224 | /* (cu_base + cu_offset) address the next command block in the command block list. */ |
| 225 | uint32_t cu_base; /* CU base address */ |
| 226 | uint32_t cu_offset; /* CU address offset */ |
| 227 | /* (ru_base + ru_offset) address the RFD in the Receive Frame Area. */ |
| 228 | uint32_t ru_base; /* RU base address */ |
| 229 | uint32_t ru_offset; /* RU address offset */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 230 | uint32_t statsaddr; /* pointer to eepro100_stats_t */ |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 231 | |
Stefan Weil | f3a52e5 | 2009-12-20 16:52:22 +0100 | [diff] [blame] | 232 | /* Temporary status information (no need to save these values), |
| 233 | * used while processing CU commands. */ |
| 234 | eepro100_tx_t tx; /* transmit buffer descriptor */ |
| 235 | uint32_t cb_address; /* = cu_base + cu_offset */ |
| 236 | |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 237 | /* Statistical counters. Also used for wake-up packet (i82559). */ |
| 238 | eepro100_stats_t statistics; |
| 239 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 240 | #if 0 |
| 241 | uint16_t status; |
| 242 | #endif |
| 243 | |
| 244 | /* Configuration bytes. */ |
| 245 | uint8_t configuration[22]; |
| 246 | |
| 247 | /* Data in mem is always in the byte order of the controller (le). */ |
| 248 | uint8_t mem[PCI_MEM_SIZE]; |
Juan Quintela | 151b298 | 2009-10-19 15:37:57 +0200 | [diff] [blame] | 249 | /* vmstate for each particular nic */ |
| 250 | VMStateDescription *vmstate; |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 251 | |
| 252 | /* Quasi static device properties (no need to save them). */ |
| 253 | uint16_t stats_size; |
| 254 | bool has_extended_tcb_support; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 255 | } EEPRO100State; |
| 256 | |
Stefan Weil | 6cded3a | 2010-03-02 22:37:43 +0100 | [diff] [blame] | 257 | /* Word indices in EEPROM. */ |
| 258 | typedef enum { |
| 259 | EEPROM_CNFG_MDIX = 0x03, |
| 260 | EEPROM_ID = 0x05, |
| 261 | EEPROM_PHY_ID = 0x06, |
| 262 | EEPROM_VENDOR_ID = 0x0c, |
| 263 | EEPROM_CONFIG_ASF = 0x0d, |
| 264 | EEPROM_DEVICE_ID = 0x23, |
| 265 | EEPROM_SMBUS_ADDR = 0x90, |
| 266 | } EEPROMOffset; |
| 267 | |
Stefan Weil | b1e8701 | 2010-03-02 22:37:51 +0100 | [diff] [blame] | 268 | /* Bit values for EEPROM ID word. */ |
| 269 | typedef enum { |
| 270 | EEPROM_ID_MDM = BIT(0), /* Modem */ |
| 271 | EEPROM_ID_STB = BIT(1), /* Standby Enable */ |
| 272 | EEPROM_ID_WMR = BIT(2), /* ??? */ |
| 273 | EEPROM_ID_WOL = BIT(5), /* Wake on LAN */ |
| 274 | EEPROM_ID_DPD = BIT(6), /* Deep Power Down */ |
| 275 | EEPROM_ID_ALT = BIT(7), /* */ |
| 276 | /* BITS(10, 8) device revision */ |
| 277 | EEPROM_ID_BD = BIT(11), /* boot disable */ |
| 278 | EEPROM_ID_ID = BIT(13), /* id bit */ |
| 279 | /* BITS(15, 14) signature */ |
| 280 | EEPROM_ID_VALID = BIT(14), /* signature for valid eeprom */ |
| 281 | } eeprom_id_bit; |
| 282 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 283 | /* Default values for MDI (PHY) registers */ |
| 284 | static const uint16_t eepro100_mdi_default[] = { |
| 285 | /* MDI Registers 0 - 6, 7 */ |
| 286 | 0x3000, 0x780d, 0x02a8, 0x0154, 0x05e1, 0x0000, 0x0000, 0x0000, |
| 287 | /* MDI Registers 8 - 15 */ |
| 288 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 289 | /* MDI Registers 16 - 31 */ |
| 290 | 0x0003, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 291 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 292 | }; |
| 293 | |
| 294 | /* Readonly mask for MDI (PHY) registers */ |
| 295 | static const uint16_t eepro100_mdi_mask[] = { |
| 296 | 0x0000, 0xffff, 0xffff, 0xffff, 0xc01f, 0xffff, 0xffff, 0x0000, |
| 297 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 298 | 0x0fff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, |
| 299 | 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 300 | }; |
| 301 | |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 302 | /* XXX: optimize */ |
| 303 | static void stl_le_phys(target_phys_addr_t addr, uint32_t val) |
| 304 | { |
| 305 | val = cpu_to_le32(val); |
| 306 | cpu_physical_memory_write(addr, (const uint8_t *)&val, sizeof(val)); |
| 307 | } |
| 308 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 309 | #define POLYNOMIAL 0x04c11db6 |
| 310 | |
| 311 | /* From FreeBSD */ |
| 312 | /* XXX: optimize */ |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 313 | static unsigned compute_mcast_idx(const uint8_t * ep) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 314 | { |
| 315 | uint32_t crc; |
| 316 | int carry, i, j; |
| 317 | uint8_t b; |
| 318 | |
| 319 | crc = 0xffffffff; |
| 320 | for (i = 0; i < 6; i++) { |
| 321 | b = *ep++; |
| 322 | for (j = 0; j < 8; j++) { |
| 323 | carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); |
| 324 | crc <<= 1; |
| 325 | b >>= 1; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 326 | if (carry) { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 327 | crc = ((crc ^ POLYNOMIAL) | carry); |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 328 | } |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 329 | } |
| 330 | } |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 331 | return (crc & BITS(7, 2)) >> 2; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | #if defined(DEBUG_EEPRO100) |
| 335 | static const char *nic_dump(const uint8_t * buf, unsigned size) |
| 336 | { |
| 337 | static char dump[3 * 16 + 1]; |
| 338 | char *p = &dump[0]; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 339 | if (size > 16) { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 340 | size = 16; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 341 | } |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 342 | while (size-- > 0) { |
| 343 | p += sprintf(p, " %02x", *buf++); |
| 344 | } |
| 345 | return dump; |
| 346 | } |
| 347 | #endif /* DEBUG_EEPRO100 */ |
| 348 | |
| 349 | enum scb_stat_ack { |
| 350 | stat_ack_not_ours = 0x00, |
| 351 | stat_ack_sw_gen = 0x04, |
| 352 | stat_ack_rnr = 0x10, |
| 353 | stat_ack_cu_idle = 0x20, |
| 354 | stat_ack_frame_rx = 0x40, |
| 355 | stat_ack_cu_cmd_done = 0x80, |
| 356 | stat_ack_not_present = 0xFF, |
| 357 | stat_ack_rx = (stat_ack_sw_gen | stat_ack_rnr | stat_ack_frame_rx), |
| 358 | stat_ack_tx = (stat_ack_cu_idle | stat_ack_cu_cmd_done), |
| 359 | }; |
| 360 | |
| 361 | static void disable_interrupt(EEPRO100State * s) |
| 362 | { |
| 363 | if (s->int_stat) { |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 364 | TRACE(INT, logout("interrupt disabled\n")); |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 365 | qemu_irq_lower(s->dev.irq[0]); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 366 | s->int_stat = 0; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | static void enable_interrupt(EEPRO100State * s) |
| 371 | { |
| 372 | if (!s->int_stat) { |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 373 | TRACE(INT, logout("interrupt enabled\n")); |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 374 | qemu_irq_raise(s->dev.irq[0]); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 375 | s->int_stat = 1; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | static void eepro100_acknowledge(EEPRO100State * s) |
| 380 | { |
| 381 | s->scb_stat &= ~s->mem[SCBAck]; |
| 382 | s->mem[SCBAck] = s->scb_stat; |
| 383 | if (s->scb_stat == 0) { |
| 384 | disable_interrupt(s); |
| 385 | } |
| 386 | } |
| 387 | |
Stefan Weil | e715c8e | 2010-03-02 22:37:52 +0100 | [diff] [blame] | 388 | static void eepro100_interrupt(EEPRO100State * s, uint8_t status) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 389 | { |
| 390 | uint8_t mask = ~s->mem[SCBIntmask]; |
Stefan Weil | e715c8e | 2010-03-02 22:37:52 +0100 | [diff] [blame] | 391 | s->mem[SCBAck] |= status; |
| 392 | status = s->scb_stat = s->mem[SCBAck]; |
| 393 | status &= (mask | 0x0f); |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 394 | #if 0 |
| 395 | status &= (~s->mem[SCBIntmask] | 0x0xf); |
| 396 | #endif |
Stefan Weil | e715c8e | 2010-03-02 22:37:52 +0100 | [diff] [blame] | 397 | if (status && (mask & 0x01)) { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 398 | /* SCB mask and SCB Bit M do not disable interrupt. */ |
| 399 | enable_interrupt(s); |
| 400 | } else if (s->int_stat) { |
| 401 | disable_interrupt(s); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | static void eepro100_cx_interrupt(EEPRO100State * s) |
| 406 | { |
| 407 | /* CU completed action command. */ |
| 408 | /* Transmit not ok (82557 only, not in emulation). */ |
| 409 | eepro100_interrupt(s, 0x80); |
| 410 | } |
| 411 | |
| 412 | static void eepro100_cna_interrupt(EEPRO100State * s) |
| 413 | { |
| 414 | /* CU left the active state. */ |
| 415 | eepro100_interrupt(s, 0x20); |
| 416 | } |
| 417 | |
| 418 | static void eepro100_fr_interrupt(EEPRO100State * s) |
| 419 | { |
| 420 | /* RU received a complete frame. */ |
| 421 | eepro100_interrupt(s, 0x40); |
| 422 | } |
| 423 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 424 | static void eepro100_rnr_interrupt(EEPRO100State * s) |
| 425 | { |
| 426 | /* RU is not ready. */ |
| 427 | eepro100_interrupt(s, 0x10); |
| 428 | } |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 429 | |
| 430 | static void eepro100_mdi_interrupt(EEPRO100State * s) |
| 431 | { |
| 432 | /* MDI completed read or write cycle. */ |
| 433 | eepro100_interrupt(s, 0x08); |
| 434 | } |
| 435 | |
| 436 | static void eepro100_swi_interrupt(EEPRO100State * s) |
| 437 | { |
| 438 | /* Software has requested an interrupt. */ |
| 439 | eepro100_interrupt(s, 0x04); |
| 440 | } |
| 441 | |
| 442 | #if 0 |
| 443 | static void eepro100_fcp_interrupt(EEPRO100State * s) |
| 444 | { |
| 445 | /* Flow control pause interrupt (82558 and later). */ |
| 446 | eepro100_interrupt(s, 0x01); |
| 447 | } |
| 448 | #endif |
| 449 | |
| 450 | static void pci_reset(EEPRO100State * s) |
| 451 | { |
| 452 | uint32_t device = s->device; |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 453 | uint8_t *pci_conf = s->dev.config; |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 454 | bool power_management = 1; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 455 | |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 456 | TRACE(OTHER, logout("%p\n", s)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 457 | |
| 458 | /* PCI Vendor ID */ |
aliguori | deb5439 | 2009-01-26 15:37:35 +0000 | [diff] [blame] | 459 | pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL); |
Stefan Weil | d6fd1e6 | 2009-09-01 22:16:10 +0200 | [diff] [blame] | 460 | /* PCI Device ID depends on device and is set below. */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 461 | /* PCI Status */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 462 | pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM | PCI_STATUS_FAST_BACK); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 463 | /* PCI Revision ID */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 464 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x08); |
blueswir1 | 173a543 | 2009-02-01 19:26:20 +0000 | [diff] [blame] | 465 | pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 466 | /* PCI Latency Timer */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 467 | pci_set_byte(pci_conf + PCI_LATENCY_TIMER, 0x20); /* latency timer = 32 clocks */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 468 | /* Capability Pointer */ |
Michael S. Tsirkin | 508cc6b | 2009-12-10 17:52:10 +0200 | [diff] [blame] | 469 | /* TODO: revisions with power_management 1 use this but |
| 470 | * do not set new capability list bit in status register. */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 471 | pci_set_byte(pci_conf + PCI_CAPABILITY_LIST, 0xdc); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 472 | /* Minimum Grant */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 473 | pci_set_byte(pci_conf + PCI_MIN_GNT, 0x08); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 474 | /* Maximum Latency */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 475 | pci_set_byte(pci_conf + PCI_MAX_LAT, 0x18); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 476 | |
| 477 | switch (device) { |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 478 | case i82550: |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 479 | /* TODO: check device id. */ |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 480 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT); |
| 481 | /* Revision ID: 0x0c, 0x0d, 0x0e. */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 482 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x0e); |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 483 | /* TODO: check size of statistical counters. */ |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 484 | s->stats_size = 80; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 485 | /* TODO: check extended tcb support. */ |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 486 | s->has_extended_tcb_support = 1; |
| 487 | break; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 488 | case i82551: |
Stefan Weil | d6fd1e6 | 2009-09-01 22:16:10 +0200 | [diff] [blame] | 489 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 490 | /* Revision ID: 0x0f, 0x10. */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 491 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x0f); |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 492 | /* TODO: check size of statistical counters. */ |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 493 | s->stats_size = 80; |
| 494 | s->has_extended_tcb_support = 1; |
| 495 | break; |
| 496 | case i82557A: |
| 497 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 498 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x01); |
| 499 | pci_set_byte(pci_conf + PCI_CAPABILITY_LIST, 0x00); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 500 | power_management = 0; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 501 | break; |
| 502 | case i82557B: |
Stefan Weil | d6fd1e6 | 2009-09-01 22:16:10 +0200 | [diff] [blame] | 503 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 504 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x02); |
| 505 | pci_set_byte(pci_conf + PCI_CAPABILITY_LIST, 0x00); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 506 | power_management = 0; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 507 | break; |
| 508 | case i82557C: |
Stefan Weil | d6fd1e6 | 2009-09-01 22:16:10 +0200 | [diff] [blame] | 509 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 510 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x03); |
| 511 | pci_set_byte(pci_conf + PCI_CAPABILITY_LIST, 0x00); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 512 | power_management = 0; |
| 513 | break; |
| 514 | case i82558A: |
| 515 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 516 | pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM | |
Michael S. Tsirkin | 508cc6b | 2009-12-10 17:52:10 +0200 | [diff] [blame] | 517 | PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 518 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x04); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 519 | s->stats_size = 76; |
| 520 | s->has_extended_tcb_support = 1; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 521 | break; |
| 522 | case i82558B: |
Stefan Weil | d6fd1e6 | 2009-09-01 22:16:10 +0200 | [diff] [blame] | 523 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 524 | pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM | |
Michael S. Tsirkin | 508cc6b | 2009-12-10 17:52:10 +0200 | [diff] [blame] | 525 | PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 526 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x05); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 527 | s->stats_size = 76; |
| 528 | s->has_extended_tcb_support = 1; |
| 529 | break; |
| 530 | case i82559A: |
| 531 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 532 | pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM | |
Michael S. Tsirkin | 508cc6b | 2009-12-10 17:52:10 +0200 | [diff] [blame] | 533 | PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 534 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x06); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 535 | s->stats_size = 80; |
| 536 | s->has_extended_tcb_support = 1; |
| 537 | break; |
| 538 | case i82559B: |
| 539 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 540 | pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM | |
Michael S. Tsirkin | 508cc6b | 2009-12-10 17:52:10 +0200 | [diff] [blame] | 541 | PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 542 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x07); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 543 | s->stats_size = 80; |
| 544 | s->has_extended_tcb_support = 1; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 545 | break; |
| 546 | case i82559C: |
Stefan Weil | d6fd1e6 | 2009-09-01 22:16:10 +0200 | [diff] [blame] | 547 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 548 | pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM | |
Michael S. Tsirkin | 508cc6b | 2009-12-10 17:52:10 +0200 | [diff] [blame] | 549 | PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 550 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x08); |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 551 | /* TODO: Windows wants revision id 0x0c. */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 552 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x0c); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 553 | #if EEPROM_SIZE > 0 |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 554 | pci_set_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID, 0x8086); |
| 555 | pci_set_word(pci_conf + PCI_SUBSYSTEM_ID, 0x0040); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 556 | #endif |
| 557 | s->stats_size = 80; |
| 558 | s->has_extended_tcb_support = 1; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 559 | break; |
| 560 | case i82559ER: |
Stefan Weil | d6fd1e6 | 2009-09-01 22:16:10 +0200 | [diff] [blame] | 561 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 562 | pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM | |
Michael S. Tsirkin | 508cc6b | 2009-12-10 17:52:10 +0200 | [diff] [blame] | 563 | PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST); |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 564 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x09); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 565 | s->stats_size = 80; |
| 566 | s->has_extended_tcb_support = 1; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 567 | break; |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 568 | case i82562: |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 569 | /* TODO: check device id. */ |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 570 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT); |
| 571 | /* TODO: wrong revision id. */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 572 | pci_set_byte(pci_conf + PCI_REVISION_ID, 0x0e); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 573 | s->stats_size = 80; |
| 574 | s->has_extended_tcb_support = 1; |
| 575 | break; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 576 | default: |
| 577 | logout("Device %X is undefined!\n", device); |
| 578 | } |
| 579 | |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 580 | s->configuration[6] |= BIT(5); |
| 581 | |
| 582 | if (s->stats_size == 80) { |
| 583 | /* TODO: check TCO Statistical Counters bit. Documentation not clear. */ |
| 584 | if (s->configuration[6] & BIT(2)) { |
| 585 | /* TCO statistical counters. */ |
| 586 | assert(s->configuration[6] & BIT(5)); |
| 587 | } else { |
| 588 | if (s->configuration[6] & BIT(5)) { |
| 589 | /* No extended statistical counters, i82557 compatible. */ |
| 590 | s->stats_size = 64; |
| 591 | } else { |
| 592 | /* i82558 compatible. */ |
| 593 | s->stats_size = 76; |
| 594 | } |
| 595 | } |
| 596 | } else { |
| 597 | if (s->configuration[6] & BIT(5)) { |
| 598 | /* No extended statistical counters. */ |
| 599 | s->stats_size = 64; |
| 600 | } |
| 601 | } |
| 602 | assert(s->stats_size > 0 && s->stats_size <= sizeof(s->statistics)); |
| 603 | |
| 604 | if (power_management) { |
| 605 | /* Power Management Capabilities */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 606 | pci_set_byte(pci_conf + 0xdc, 0x01); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 607 | /* Next Item Pointer */ |
| 608 | /* Capability ID */ |
Michael S. Tsirkin | 15e89f5 | 2010-03-03 14:00:21 +0200 | [diff] [blame] | 609 | pci_set_word(pci_conf + 0xde, 0x7e21); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 610 | /* TODO: Power Management Control / Status. */ |
| 611 | /* TODO: Ethernet Power Consumption Registers (i82559 and later). */ |
| 612 | } |
| 613 | |
| 614 | #if EEPROM_SIZE > 0 |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 615 | if (device == i82557C || device == i82558B || device == i82559C) { |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 616 | /* |
| 617 | TODO: get vendor id from EEPROM for i82557C or later. |
| 618 | TODO: get device id from EEPROM for i82557C or later. |
| 619 | TODO: status bit 4 can be disabled by EEPROM for i82558, i82559. |
| 620 | TODO: header type is determined by EEPROM for i82559. |
| 621 | TODO: get subsystem id from EEPROM for i82557C or later. |
| 622 | TODO: get subsystem vendor id from EEPROM for i82557C or later. |
| 623 | TODO: exp. rom baddr depends on a bit in EEPROM for i82558 or later. |
| 624 | TODO: capability pointer depends on EEPROM for i82558. |
| 625 | */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 626 | logout("Get device id and revision from EEPROM!!!\n"); |
| 627 | } |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 628 | #endif /* EEPROM_SIZE > 0 */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | static void nic_selective_reset(EEPRO100State * s) |
| 632 | { |
| 633 | size_t i; |
| 634 | uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom); |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 635 | #if 0 |
| 636 | eeprom93xx_reset(s->eeprom); |
| 637 | #endif |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 638 | memcpy(eeprom_contents, s->conf.macaddr.a, 6); |
Stefan Weil | b1e8701 | 2010-03-02 22:37:51 +0100 | [diff] [blame] | 639 | eeprom_contents[EEPROM_ID] = EEPROM_ID_VALID; |
=?UTF-8?q?Reimar=20D=C3=B6ffinger?= | f4e94df | 2009-09-12 15:42:01 +0200 | [diff] [blame] | 640 | if (s->device == i82557B || s->device == i82557C) |
| 641 | eeprom_contents[5] = 0x0100; |
Stefan Weil | 6cded3a | 2010-03-02 22:37:43 +0100 | [diff] [blame] | 642 | eeprom_contents[EEPROM_PHY_ID] = 1; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 643 | uint16_t sum = 0; |
| 644 | for (i = 0; i < EEPROM_SIZE - 1; i++) { |
| 645 | sum += eeprom_contents[i]; |
| 646 | } |
| 647 | eeprom_contents[EEPROM_SIZE - 1] = 0xbaba - sum; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 648 | TRACE(EEPROM, logout("checksum=0x%04x\n", eeprom_contents[EEPROM_SIZE - 1])); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 649 | |
| 650 | memset(s->mem, 0, sizeof(s->mem)); |
| 651 | uint32_t val = BIT(21); |
| 652 | memcpy(&s->mem[SCBCtrlMDI], &val, sizeof(val)); |
| 653 | |
| 654 | assert(sizeof(s->mdimem) == sizeof(eepro100_mdi_default)); |
| 655 | memcpy(&s->mdimem[0], &eepro100_mdi_default[0], sizeof(s->mdimem)); |
| 656 | } |
| 657 | |
| 658 | static void nic_reset(void *opaque) |
| 659 | { |
Juan Quintela | 769cf7a | 2009-08-24 18:42:36 +0200 | [diff] [blame] | 660 | EEPRO100State *s = opaque; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 661 | TRACE(OTHER, logout("%p\n", s)); |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 662 | /* TODO: Clearing of multicast table for selective reset, too? */ |
| 663 | memset(&s->mult[0], 0, sizeof(s->mult)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 664 | nic_selective_reset(s); |
| 665 | } |
| 666 | |
| 667 | #if defined(DEBUG_EEPRO100) |
Stefan Weil | b8f6ba0 | 2009-11-27 12:06:02 +0100 | [diff] [blame] | 668 | static const char * const e100_reg[PCI_IO_SIZE / 4] = { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 669 | "Command/Status", |
| 670 | "General Pointer", |
| 671 | "Port", |
| 672 | "EEPROM/Flash Control", |
| 673 | "MDI Control", |
| 674 | "Receive DMA Byte Count", |
Stefan Weil | b8f6ba0 | 2009-11-27 12:06:02 +0100 | [diff] [blame] | 675 | "Flow Control", |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 676 | "General Status/Control" |
| 677 | }; |
| 678 | |
| 679 | static char *regname(uint32_t addr) |
| 680 | { |
David Benjamin | ec16928 | 2009-11-25 21:20:10 -0500 | [diff] [blame] | 681 | static char buf[32]; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 682 | if (addr < PCI_IO_SIZE) { |
Stefan Weil | b8f6ba0 | 2009-11-27 12:06:02 +0100 | [diff] [blame] | 683 | const char *r = e100_reg[addr / 4]; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 684 | if (r != 0) { |
Stefan Weil | 41cbc23 | 2009-09-19 12:29:59 +0200 | [diff] [blame] | 685 | snprintf(buf, sizeof(buf), "%s+%u", r, addr % 4); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 686 | } else { |
Stefan Weil | 41cbc23 | 2009-09-19 12:29:59 +0200 | [diff] [blame] | 687 | snprintf(buf, sizeof(buf), "0x%02x", addr); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 688 | } |
| 689 | } else { |
Stefan Weil | 41cbc23 | 2009-09-19 12:29:59 +0200 | [diff] [blame] | 690 | snprintf(buf, sizeof(buf), "??? 0x%08x", addr); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 691 | } |
| 692 | return buf; |
| 693 | } |
| 694 | #endif /* DEBUG_EEPRO100 */ |
| 695 | |
| 696 | #if 0 |
| 697 | static uint16_t eepro100_read_status(EEPRO100State * s) |
| 698 | { |
| 699 | uint16_t val = s->status; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 700 | TRACE(OTHER, logout("val=0x%04x\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 701 | return val; |
| 702 | } |
| 703 | |
| 704 | static void eepro100_write_status(EEPRO100State * s, uint16_t val) |
| 705 | { |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 706 | TRACE(OTHER, logout("val=0x%04x\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 707 | s->status = val; |
| 708 | } |
| 709 | #endif |
| 710 | |
| 711 | /***************************************************************************** |
| 712 | * |
| 713 | * Command emulation. |
| 714 | * |
| 715 | ****************************************************************************/ |
| 716 | |
| 717 | #if 0 |
| 718 | static uint16_t eepro100_read_command(EEPRO100State * s) |
| 719 | { |
| 720 | uint16_t val = 0xffff; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 721 | TRACE(OTHER, logout("val=0x%04x\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 722 | return val; |
| 723 | } |
| 724 | #endif |
| 725 | |
| 726 | /* Commands that can be put in a command list entry. */ |
| 727 | enum commands { |
| 728 | CmdNOp = 0, |
| 729 | CmdIASetup = 1, |
| 730 | CmdConfigure = 2, |
| 731 | CmdMulticastList = 3, |
| 732 | CmdTx = 4, |
| 733 | CmdTDR = 5, /* load microcode */ |
| 734 | CmdDump = 6, |
| 735 | CmdDiagnose = 7, |
| 736 | |
| 737 | /* And some extra flags: */ |
| 738 | CmdSuspend = 0x4000, /* Suspend after completion. */ |
| 739 | CmdIntr = 0x2000, /* Interrupt after completion. */ |
| 740 | CmdTxFlex = 0x0008, /* Use "Flexible mode" for CmdTx command. */ |
| 741 | }; |
| 742 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 743 | static cu_state_t get_cu_state(EEPRO100State * s) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 744 | { |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 745 | return ((s->mem[SCBStatus] & BITS(7, 6)) >> 6); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 746 | } |
| 747 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 748 | static void set_cu_state(EEPRO100State * s, cu_state_t state) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 749 | { |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 750 | s->mem[SCBStatus] = (s->mem[SCBStatus] & ~BITS(7, 6)) + (state << 6); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 751 | } |
| 752 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 753 | static ru_state_t get_ru_state(EEPRO100State * s) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 754 | { |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 755 | return ((s->mem[SCBStatus] & BITS(5, 2)) >> 2); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 758 | static void set_ru_state(EEPRO100State * s, ru_state_t state) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 759 | { |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 760 | s->mem[SCBStatus] = (s->mem[SCBStatus] & ~BITS(5, 2)) + (state << 2); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | static void dump_statistics(EEPRO100State * s) |
| 764 | { |
| 765 | /* Dump statistical data. Most data is never changed by the emulation |
| 766 | * and always 0, so we first just copy the whole block and then those |
| 767 | * values which really matter. |
| 768 | * Number of data should check configuration!!! |
| 769 | */ |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 770 | cpu_physical_memory_write(s->statsaddr, |
| 771 | (uint8_t *) & s->statistics, s->stats_size); |
| 772 | stl_le_phys(s->statsaddr + 0, s->statistics.tx_good_frames); |
| 773 | stl_le_phys(s->statsaddr + 36, s->statistics.rx_good_frames); |
| 774 | stl_le_phys(s->statsaddr + 48, s->statistics.rx_resource_errors); |
| 775 | stl_le_phys(s->statsaddr + 60, s->statistics.rx_short_frame_errors); |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 776 | #if 0 |
| 777 | stw_le_phys(s->statsaddr + 76, s->statistics.xmt_tco_frames); |
| 778 | stw_le_phys(s->statsaddr + 78, s->statistics.rcv_tco_frames); |
| 779 | missing("CU dump statistical counters"); |
| 780 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Stefan Weil | 3d0f4b9 | 2010-03-02 22:37:57 +0100 | [diff] [blame] | 783 | static void read_cb(EEPRO100State *s) |
| 784 | { |
| 785 | cpu_physical_memory_read(s->cb_address, (uint8_t *) &s->tx, sizeof(s->tx)); |
| 786 | s->tx.status = le16_to_cpu(s->tx.status); |
| 787 | s->tx.command = le16_to_cpu(s->tx.command); |
| 788 | s->tx.link = le32_to_cpu(s->tx.link); |
| 789 | s->tx.tbd_array_addr = le32_to_cpu(s->tx.tbd_array_addr); |
| 790 | s->tx.tcb_bytes = le16_to_cpu(s->tx.tcb_bytes); |
| 791 | } |
| 792 | |
Stefan Weil | f3a52e5 | 2009-12-20 16:52:22 +0100 | [diff] [blame] | 793 | static void tx_command(EEPRO100State *s) |
| 794 | { |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 795 | uint32_t tbd_array = le32_to_cpu(s->tx.tbd_array_addr); |
Stefan Weil | f3a52e5 | 2009-12-20 16:52:22 +0100 | [diff] [blame] | 796 | uint16_t tcb_bytes = (le16_to_cpu(s->tx.tcb_bytes) & 0x3fff); |
| 797 | /* Sends larger than MAX_ETH_FRAME_SIZE are allowed, up to 2600 bytes. */ |
| 798 | uint8_t buf[2600]; |
| 799 | uint16_t size = 0; |
| 800 | uint32_t tbd_address = s->cb_address + 0x10; |
| 801 | TRACE(RXTX, logout |
| 802 | ("transmit, TBD array address 0x%08x, TCB byte count 0x%04x, TBD count %u\n", |
| 803 | tbd_array, tcb_bytes, s->tx.tbd_count)); |
| 804 | |
| 805 | if (tcb_bytes > 2600) { |
| 806 | logout("TCB byte count too large, using 2600\n"); |
| 807 | tcb_bytes = 2600; |
| 808 | } |
| 809 | if (!((tcb_bytes > 0) || (tbd_array != 0xffffffff))) { |
| 810 | logout |
| 811 | ("illegal values of TBD array address and TCB byte count!\n"); |
| 812 | } |
| 813 | assert(tcb_bytes <= sizeof(buf)); |
| 814 | while (size < tcb_bytes) { |
| 815 | uint32_t tx_buffer_address = ldl_phys(tbd_address); |
| 816 | uint16_t tx_buffer_size = lduw_phys(tbd_address + 4); |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 817 | #if 0 |
| 818 | uint16_t tx_buffer_el = lduw_phys(tbd_address + 6); |
| 819 | #endif |
Stefan Weil | f3a52e5 | 2009-12-20 16:52:22 +0100 | [diff] [blame] | 820 | tbd_address += 8; |
| 821 | TRACE(RXTX, logout |
| 822 | ("TBD (simplified mode): buffer address 0x%08x, size 0x%04x\n", |
| 823 | tx_buffer_address, tx_buffer_size)); |
| 824 | tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size); |
| 825 | cpu_physical_memory_read(tx_buffer_address, &buf[size], |
| 826 | tx_buffer_size); |
| 827 | size += tx_buffer_size; |
| 828 | } |
| 829 | if (tbd_array == 0xffffffff) { |
| 830 | /* Simplified mode. Was already handled by code above. */ |
| 831 | } else { |
| 832 | /* Flexible mode. */ |
| 833 | uint8_t tbd_count = 0; |
| 834 | if (s->has_extended_tcb_support && !(s->configuration[6] & BIT(4))) { |
| 835 | /* Extended Flexible TCB. */ |
| 836 | for (; tbd_count < 2; tbd_count++) { |
| 837 | uint32_t tx_buffer_address = ldl_phys(tbd_address); |
| 838 | uint16_t tx_buffer_size = lduw_phys(tbd_address + 4); |
| 839 | uint16_t tx_buffer_el = lduw_phys(tbd_address + 6); |
| 840 | tbd_address += 8; |
| 841 | TRACE(RXTX, logout |
| 842 | ("TBD (extended flexible mode): buffer address 0x%08x, size 0x%04x\n", |
| 843 | tx_buffer_address, tx_buffer_size)); |
| 844 | tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size); |
| 845 | cpu_physical_memory_read(tx_buffer_address, &buf[size], |
| 846 | tx_buffer_size); |
| 847 | size += tx_buffer_size; |
| 848 | if (tx_buffer_el & 1) { |
| 849 | break; |
| 850 | } |
| 851 | } |
| 852 | } |
| 853 | tbd_address = tbd_array; |
| 854 | for (; tbd_count < s->tx.tbd_count; tbd_count++) { |
| 855 | uint32_t tx_buffer_address = ldl_phys(tbd_address); |
| 856 | uint16_t tx_buffer_size = lduw_phys(tbd_address + 4); |
| 857 | uint16_t tx_buffer_el = lduw_phys(tbd_address + 6); |
| 858 | tbd_address += 8; |
| 859 | TRACE(RXTX, logout |
| 860 | ("TBD (flexible mode): buffer address 0x%08x, size 0x%04x\n", |
| 861 | tx_buffer_address, tx_buffer_size)); |
| 862 | tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size); |
| 863 | cpu_physical_memory_read(tx_buffer_address, &buf[size], |
| 864 | tx_buffer_size); |
| 865 | size += tx_buffer_size; |
| 866 | if (tx_buffer_el & 1) { |
| 867 | break; |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | TRACE(RXTX, logout("%p sending frame, len=%d,%s\n", s, size, nic_dump(buf, size))); |
| 872 | qemu_send_packet(&s->nic->nc, buf, size); |
| 873 | s->statistics.tx_good_frames++; |
| 874 | /* Transmit with bad status would raise an CX/TNO interrupt. |
| 875 | * (82557 only). Emulation never has bad status. */ |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 876 | #if 0 |
| 877 | eepro100_cx_interrupt(s); |
| 878 | #endif |
Stefan Weil | f3a52e5 | 2009-12-20 16:52:22 +0100 | [diff] [blame] | 879 | } |
| 880 | |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 881 | static void set_multicast_list(EEPRO100State *s) |
| 882 | { |
| 883 | uint16_t multicast_count = s->tx.tbd_array_addr & BITS(13, 0); |
| 884 | uint16_t i; |
| 885 | memset(&s->mult[0], 0, sizeof(s->mult)); |
| 886 | TRACE(OTHER, logout("multicast list, multicast count = %u\n", multicast_count)); |
| 887 | for (i = 0; i < multicast_count; i += 6) { |
| 888 | uint8_t multicast_addr[6]; |
| 889 | cpu_physical_memory_read(s->cb_address + 10 + i, multicast_addr, 6); |
| 890 | TRACE(OTHER, logout("multicast entry %s\n", nic_dump(multicast_addr, 6))); |
| 891 | unsigned mcast_idx = compute_mcast_idx(multicast_addr); |
| 892 | assert(mcast_idx < 64); |
| 893 | s->mult[mcast_idx >> 3] |= (1 << (mcast_idx & 7)); |
| 894 | } |
| 895 | } |
| 896 | |
Stefan Weil | 5fa9a0a | 2009-10-19 21:03:26 +0200 | [diff] [blame] | 897 | static void action_command(EEPRO100State *s) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 898 | { |
Stefan Weil | 5fa9a0a | 2009-10-19 21:03:26 +0200 | [diff] [blame] | 899 | for (;;) { |
Stefan Weil | 3d0f4b9 | 2010-03-02 22:37:57 +0100 | [diff] [blame] | 900 | bool bit_el; |
| 901 | bool bit_s; |
| 902 | bool bit_i; |
| 903 | bool bit_nc; |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 904 | bool success = true; |
Stefan Weil | 3d0f4b9 | 2010-03-02 22:37:57 +0100 | [diff] [blame] | 905 | s->cb_address = s->cu_base + s->cu_offset; |
| 906 | read_cb(s); |
| 907 | bit_el = ((s->tx.command & COMMAND_EL) != 0); |
| 908 | bit_s = ((s->tx.command & COMMAND_S) != 0); |
| 909 | bit_i = ((s->tx.command & COMMAND_I) != 0); |
| 910 | bit_nc = ((s->tx.command & COMMAND_NC) != 0); |
| 911 | #if 0 |
| 912 | bool bit_sf = ((s->tx.command & COMMAND_SF) != 0); |
| 913 | #endif |
| 914 | s->cu_offset = s->tx.link; |
| 915 | TRACE(OTHER, |
| 916 | logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n", |
| 917 | s->tx.status, s->tx.command, s->tx.link)); |
| 918 | switch (s->tx.command & COMMAND_CMD) { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 919 | case CmdNOp: |
| 920 | /* Do nothing. */ |
| 921 | break; |
| 922 | case CmdIASetup: |
Stefan Weil | f3a52e5 | 2009-12-20 16:52:22 +0100 | [diff] [blame] | 923 | cpu_physical_memory_read(s->cb_address + 8, &s->conf.macaddr.a[0], 6); |
Stefan Weil | ce0e58b | 2010-03-02 22:37:41 +0100 | [diff] [blame] | 924 | TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6))); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 925 | break; |
| 926 | case CmdConfigure: |
Stefan Weil | f3a52e5 | 2009-12-20 16:52:22 +0100 | [diff] [blame] | 927 | cpu_physical_memory_read(s->cb_address + 8, &s->configuration[0], |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 928 | sizeof(s->configuration)); |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 929 | TRACE(OTHER, logout("configuration: %s\n", nic_dump(&s->configuration[0], 16))); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 930 | break; |
| 931 | case CmdMulticastList: |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 932 | set_multicast_list(s); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 933 | break; |
| 934 | case CmdTx: |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 935 | if (bit_nc) { |
| 936 | missing("CmdTx: NC = 0"); |
| 937 | success = false; |
| 938 | break; |
| 939 | } |
Stefan Weil | f3a52e5 | 2009-12-20 16:52:22 +0100 | [diff] [blame] | 940 | tx_command(s); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 941 | break; |
| 942 | case CmdTDR: |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 943 | TRACE(OTHER, logout("load microcode\n")); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 944 | /* Starting with offset 8, the command contains |
| 945 | * 64 dwords microcode which we just ignore here. */ |
| 946 | break; |
Stefan Weil | f80a7fc | 2010-03-02 22:37:58 +0100 | [diff] [blame] | 947 | case CmdDiagnose: |
| 948 | TRACE(OTHER, logout("diagnose\n")); |
| 949 | /* Make sure error flag is not set. */ |
| 950 | s->tx.status = 0; |
| 951 | break; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 952 | default: |
| 953 | missing("undefined command"); |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 954 | success = false; |
| 955 | break; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 956 | } |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 957 | /* Write new status. */ |
Stefan Weil | ec1d02d | 2010-03-02 22:37:56 +0100 | [diff] [blame] | 958 | stw_phys(s->cb_address, s->tx.status | STATUS_C | (success ? STATUS_OK : 0)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 959 | if (bit_i) { |
| 960 | /* CU completed action. */ |
| 961 | eepro100_cx_interrupt(s); |
| 962 | } |
| 963 | if (bit_el) { |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 964 | /* CU becomes idle. Terminate command loop. */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 965 | set_cu_state(s, cu_idle); |
| 966 | eepro100_cna_interrupt(s); |
Stefan Weil | 5fa9a0a | 2009-10-19 21:03:26 +0200 | [diff] [blame] | 967 | break; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 968 | } else if (bit_s) { |
Stefan Weil | 5fa9a0a | 2009-10-19 21:03:26 +0200 | [diff] [blame] | 969 | /* CU becomes suspended. Terminate command loop. */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 970 | set_cu_state(s, cu_suspended); |
| 971 | eepro100_cna_interrupt(s); |
Stefan Weil | 5fa9a0a | 2009-10-19 21:03:26 +0200 | [diff] [blame] | 972 | break; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 973 | } else { |
| 974 | /* More entries in list. */ |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 975 | TRACE(OTHER, logout("CU list with at least one more entry\n")); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 976 | } |
Stefan Weil | 5fa9a0a | 2009-10-19 21:03:26 +0200 | [diff] [blame] | 977 | } |
| 978 | TRACE(OTHER, logout("CU list empty\n")); |
| 979 | /* List is empty. Now CU is idle or suspended. */ |
| 980 | } |
| 981 | |
| 982 | static void eepro100_cu_command(EEPRO100State * s, uint8_t val) |
| 983 | { |
Stefan Weil | cb25a3f | 2010-03-02 22:37:54 +0100 | [diff] [blame] | 984 | cu_state_t cu_state; |
Stefan Weil | 5fa9a0a | 2009-10-19 21:03:26 +0200 | [diff] [blame] | 985 | switch (val) { |
| 986 | case CU_NOP: |
| 987 | /* No operation. */ |
| 988 | break; |
| 989 | case CU_START: |
Stefan Weil | cb25a3f | 2010-03-02 22:37:54 +0100 | [diff] [blame] | 990 | cu_state = get_cu_state(s); |
| 991 | if (cu_state != cu_idle && cu_state != cu_suspended) { |
| 992 | /* Intel documentation says that CU must be idle or suspended |
| 993 | * for the CU start command. */ |
| 994 | logout("unexpected CU state is %u\n", cu_state); |
Stefan Weil | 5fa9a0a | 2009-10-19 21:03:26 +0200 | [diff] [blame] | 995 | } |
| 996 | set_cu_state(s, cu_active); |
| 997 | s->cu_offset = s->pointer; |
| 998 | action_command(s); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 999 | break; |
| 1000 | case CU_RESUME: |
| 1001 | if (get_cu_state(s) != cu_suspended) { |
| 1002 | logout("bad CU resume from CU state %u\n", get_cu_state(s)); |
| 1003 | /* Workaround for bad Linux eepro100 driver which resumes |
| 1004 | * from idle state. */ |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1005 | #if 0 |
| 1006 | missing("cu resume"); |
| 1007 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1008 | set_cu_state(s, cu_suspended); |
| 1009 | } |
| 1010 | if (get_cu_state(s) == cu_suspended) { |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1011 | TRACE(OTHER, logout("CU resuming\n")); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1012 | set_cu_state(s, cu_active); |
Stefan Weil | 5fa9a0a | 2009-10-19 21:03:26 +0200 | [diff] [blame] | 1013 | action_command(s); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1014 | } |
| 1015 | break; |
| 1016 | case CU_STATSADDR: |
| 1017 | /* Load dump counters address. */ |
| 1018 | s->statsaddr = s->pointer; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1019 | TRACE(OTHER, logout("val=0x%02x (status address)\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1020 | break; |
| 1021 | case CU_SHOWSTATS: |
| 1022 | /* Dump statistical counters. */ |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1023 | TRACE(OTHER, logout("val=0x%02x (dump stats)\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1024 | dump_statistics(s); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 1025 | stl_le_phys(s->statsaddr + s->stats_size, 0xa005); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1026 | break; |
| 1027 | case CU_CMD_BASE: |
| 1028 | /* Load CU base. */ |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1029 | TRACE(OTHER, logout("val=0x%02x (CU base address)\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1030 | s->cu_base = s->pointer; |
| 1031 | break; |
| 1032 | case CU_DUMPSTATS: |
| 1033 | /* Dump and reset statistical counters. */ |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1034 | TRACE(OTHER, logout("val=0x%02x (dump stats and reset)\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1035 | dump_statistics(s); |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 1036 | stl_le_phys(s->statsaddr + s->stats_size, 0xa007); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1037 | memset(&s->statistics, 0, sizeof(s->statistics)); |
| 1038 | break; |
| 1039 | case CU_SRESUME: |
| 1040 | /* CU static resume. */ |
| 1041 | missing("CU static resume"); |
| 1042 | break; |
| 1043 | default: |
| 1044 | missing("Undefined CU command"); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | static void eepro100_ru_command(EEPRO100State * s, uint8_t val) |
| 1049 | { |
| 1050 | switch (val) { |
| 1051 | case RU_NOP: |
| 1052 | /* No operation. */ |
| 1053 | break; |
| 1054 | case RX_START: |
| 1055 | /* RU start. */ |
| 1056 | if (get_ru_state(s) != ru_idle) { |
| 1057 | logout("RU state is %u, should be %u\n", get_ru_state(s), ru_idle); |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1058 | #if 0 |
| 1059 | assert(!"wrong RU state"); |
| 1060 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1061 | } |
| 1062 | set_ru_state(s, ru_ready); |
| 1063 | s->ru_offset = s->pointer; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1064 | TRACE(OTHER, logout("val=0x%02x (rx start)\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1065 | break; |
| 1066 | case RX_RESUME: |
| 1067 | /* Restart RU. */ |
| 1068 | if (get_ru_state(s) != ru_suspended) { |
| 1069 | logout("RU state is %u, should be %u\n", get_ru_state(s), |
| 1070 | ru_suspended); |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1071 | #if 0 |
| 1072 | assert(!"wrong RU state"); |
| 1073 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1074 | } |
| 1075 | set_ru_state(s, ru_ready); |
| 1076 | break; |
Stefan Weil | e824012 | 2010-03-02 22:37:53 +0100 | [diff] [blame] | 1077 | case RU_ABORT: |
| 1078 | /* RU abort. */ |
| 1079 | if (get_ru_state(s) == ru_ready) { |
| 1080 | eepro100_rnr_interrupt(s); |
| 1081 | } |
| 1082 | set_ru_state(s, ru_idle); |
| 1083 | break; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1084 | case RX_ADDR_LOAD: |
| 1085 | /* Load RU base. */ |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1086 | TRACE(OTHER, logout("val=0x%02x (RU base address)\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1087 | s->ru_base = s->pointer; |
| 1088 | break; |
| 1089 | default: |
| 1090 | logout("val=0x%02x (undefined RU command)\n", val); |
| 1091 | missing("Undefined SU command"); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | static void eepro100_write_command(EEPRO100State * s, uint8_t val) |
| 1096 | { |
| 1097 | eepro100_ru_command(s, val & 0x0f); |
| 1098 | eepro100_cu_command(s, val & 0xf0); |
| 1099 | if ((val) == 0) { |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1100 | TRACE(OTHER, logout("val=0x%02x\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1101 | } |
| 1102 | /* Clear command byte after command was accepted. */ |
| 1103 | s->mem[SCBCmd] = 0; |
| 1104 | } |
| 1105 | |
| 1106 | /***************************************************************************** |
| 1107 | * |
| 1108 | * EEPROM emulation. |
| 1109 | * |
| 1110 | ****************************************************************************/ |
| 1111 | |
| 1112 | #define EEPROM_CS 0x02 |
| 1113 | #define EEPROM_SK 0x01 |
| 1114 | #define EEPROM_DI 0x04 |
| 1115 | #define EEPROM_DO 0x08 |
| 1116 | |
| 1117 | static uint16_t eepro100_read_eeprom(EEPRO100State * s) |
| 1118 | { |
| 1119 | uint16_t val; |
| 1120 | memcpy(&val, &s->mem[SCBeeprom], sizeof(val)); |
| 1121 | if (eeprom93xx_read(s->eeprom)) { |
| 1122 | val |= EEPROM_DO; |
| 1123 | } else { |
| 1124 | val &= ~EEPROM_DO; |
| 1125 | } |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1126 | TRACE(EEPROM, logout("val=0x%04x\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1127 | return val; |
| 1128 | } |
| 1129 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1130 | static void eepro100_write_eeprom(eeprom_t * eeprom, uint8_t val) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1131 | { |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1132 | TRACE(EEPROM, logout("val=0x%02x\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1133 | |
| 1134 | /* mask unwriteable bits */ |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1135 | #if 0 |
| 1136 | val = SET_MASKED(val, 0x31, eeprom->value); |
| 1137 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1138 | |
| 1139 | int eecs = ((val & EEPROM_CS) != 0); |
| 1140 | int eesk = ((val & EEPROM_SK) != 0); |
| 1141 | int eedi = ((val & EEPROM_DI) != 0); |
| 1142 | eeprom93xx_write(eeprom, eecs, eesk, eedi); |
| 1143 | } |
| 1144 | |
| 1145 | static void eepro100_write_pointer(EEPRO100State * s, uint32_t val) |
| 1146 | { |
| 1147 | s->pointer = le32_to_cpu(val); |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1148 | TRACE(OTHER, logout("val=0x%08x\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /***************************************************************************** |
| 1152 | * |
| 1153 | * MDI emulation. |
| 1154 | * |
| 1155 | ****************************************************************************/ |
| 1156 | |
| 1157 | #if defined(DEBUG_EEPRO100) |
Reimar Döffinger | 6a0b9cc | 2009-09-12 15:20:24 +0000 | [diff] [blame] | 1158 | static const char * const mdi_op_name[] = { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1159 | "opcode 0", |
| 1160 | "write", |
| 1161 | "read", |
| 1162 | "opcode 3" |
| 1163 | }; |
| 1164 | |
Reimar Döffinger | 6a0b9cc | 2009-09-12 15:20:24 +0000 | [diff] [blame] | 1165 | static const char * const mdi_reg_name[] = { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1166 | "Control", |
| 1167 | "Status", |
| 1168 | "PHY Identification (Word 1)", |
| 1169 | "PHY Identification (Word 2)", |
| 1170 | "Auto-Negotiation Advertisement", |
| 1171 | "Auto-Negotiation Link Partner Ability", |
| 1172 | "Auto-Negotiation Expansion" |
| 1173 | }; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1174 | |
| 1175 | static const char *reg2name(uint8_t reg) |
| 1176 | { |
| 1177 | static char buffer[10]; |
| 1178 | const char *p = buffer; |
| 1179 | if (reg < ARRAY_SIZE(mdi_reg_name)) { |
| 1180 | p = mdi_reg_name[reg]; |
| 1181 | } else { |
| 1182 | snprintf(buffer, sizeof(buffer), "reg=0x%02x", reg); |
| 1183 | } |
| 1184 | return p; |
| 1185 | } |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1186 | #endif /* DEBUG_EEPRO100 */ |
| 1187 | |
| 1188 | static uint32_t eepro100_read_mdi(EEPRO100State * s) |
| 1189 | { |
| 1190 | uint32_t val; |
| 1191 | memcpy(&val, &s->mem[0x10], sizeof(val)); |
| 1192 | |
| 1193 | #ifdef DEBUG_EEPRO100 |
| 1194 | uint8_t raiseint = (val & BIT(29)) >> 29; |
| 1195 | uint8_t opcode = (val & BITS(27, 26)) >> 26; |
| 1196 | uint8_t phy = (val & BITS(25, 21)) >> 21; |
| 1197 | uint8_t reg = (val & BITS(20, 16)) >> 16; |
| 1198 | uint16_t data = (val & BITS(15, 0)); |
| 1199 | #endif |
| 1200 | /* Emulation takes no time to finish MDI transaction. */ |
| 1201 | val |= BIT(28); |
| 1202 | TRACE(MDI, logout("val=0x%08x (int=%u, %s, phy=%u, %s, data=0x%04x\n", |
| 1203 | val, raiseint, mdi_op_name[opcode], phy, |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1204 | reg2name(reg), data)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1205 | return val; |
| 1206 | } |
| 1207 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1208 | static void eepro100_write_mdi(EEPRO100State * s, uint32_t val) |
| 1209 | { |
| 1210 | uint8_t raiseint = (val & BIT(29)) >> 29; |
| 1211 | uint8_t opcode = (val & BITS(27, 26)) >> 26; |
| 1212 | uint8_t phy = (val & BITS(25, 21)) >> 21; |
| 1213 | uint8_t reg = (val & BITS(20, 16)) >> 16; |
| 1214 | uint16_t data = (val & BITS(15, 0)); |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1215 | TRACE(MDI, logout("val=0x%08x (int=%u, %s, phy=%u, %s, data=0x%04x\n", |
| 1216 | val, raiseint, mdi_op_name[opcode], phy, reg2name(reg), data)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1217 | if (phy != 1) { |
| 1218 | /* Unsupported PHY address. */ |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1219 | #if 0 |
| 1220 | logout("phy must be 1 but is %u\n", phy); |
| 1221 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1222 | data = 0; |
| 1223 | } else if (opcode != 1 && opcode != 2) { |
| 1224 | /* Unsupported opcode. */ |
| 1225 | logout("opcode must be 1 or 2 but is %u\n", opcode); |
| 1226 | data = 0; |
| 1227 | } else if (reg > 6) { |
| 1228 | /* Unsupported register. */ |
| 1229 | logout("register must be 0...6 but is %u\n", reg); |
| 1230 | data = 0; |
| 1231 | } else { |
| 1232 | TRACE(MDI, logout("val=0x%08x (int=%u, %s, phy=%u, %s, data=0x%04x\n", |
| 1233 | val, raiseint, mdi_op_name[opcode], phy, |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1234 | reg2name(reg), data)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1235 | if (opcode == 1) { |
| 1236 | /* MDI write */ |
| 1237 | switch (reg) { |
| 1238 | case 0: /* Control Register */ |
| 1239 | if (data & 0x8000) { |
| 1240 | /* Reset status and control registers to default. */ |
| 1241 | s->mdimem[0] = eepro100_mdi_default[0]; |
| 1242 | s->mdimem[1] = eepro100_mdi_default[1]; |
| 1243 | data = s->mdimem[reg]; |
| 1244 | } else { |
| 1245 | /* Restart Auto Configuration = Normal Operation */ |
| 1246 | data &= ~0x0200; |
| 1247 | } |
| 1248 | break; |
| 1249 | case 1: /* Status Register */ |
| 1250 | missing("not writable"); |
| 1251 | data = s->mdimem[reg]; |
| 1252 | break; |
| 1253 | case 2: /* PHY Identification Register (Word 1) */ |
| 1254 | case 3: /* PHY Identification Register (Word 2) */ |
| 1255 | missing("not implemented"); |
| 1256 | break; |
| 1257 | case 4: /* Auto-Negotiation Advertisement Register */ |
| 1258 | case 5: /* Auto-Negotiation Link Partner Ability Register */ |
| 1259 | break; |
| 1260 | case 6: /* Auto-Negotiation Expansion Register */ |
| 1261 | default: |
| 1262 | missing("not implemented"); |
| 1263 | } |
| 1264 | s->mdimem[reg] = data; |
| 1265 | } else if (opcode == 2) { |
| 1266 | /* MDI read */ |
| 1267 | switch (reg) { |
| 1268 | case 0: /* Control Register */ |
| 1269 | if (data & 0x8000) { |
| 1270 | /* Reset status and control registers to default. */ |
| 1271 | s->mdimem[0] = eepro100_mdi_default[0]; |
| 1272 | s->mdimem[1] = eepro100_mdi_default[1]; |
| 1273 | } |
| 1274 | break; |
| 1275 | case 1: /* Status Register */ |
| 1276 | s->mdimem[reg] |= 0x0020; |
| 1277 | break; |
| 1278 | case 2: /* PHY Identification Register (Word 1) */ |
| 1279 | case 3: /* PHY Identification Register (Word 2) */ |
| 1280 | case 4: /* Auto-Negotiation Advertisement Register */ |
| 1281 | break; |
| 1282 | case 5: /* Auto-Negotiation Link Partner Ability Register */ |
| 1283 | s->mdimem[reg] = 0x41fe; |
| 1284 | break; |
| 1285 | case 6: /* Auto-Negotiation Expansion Register */ |
| 1286 | s->mdimem[reg] = 0x0001; |
| 1287 | break; |
| 1288 | } |
| 1289 | data = s->mdimem[reg]; |
| 1290 | } |
| 1291 | /* Emulation takes no time to finish MDI transaction. |
| 1292 | * Set MDI bit in SCB status register. */ |
| 1293 | s->mem[SCBAck] |= 0x08; |
| 1294 | val |= BIT(28); |
| 1295 | if (raiseint) { |
| 1296 | eepro100_mdi_interrupt(s); |
| 1297 | } |
| 1298 | } |
| 1299 | val = (val & 0xffff0000) + data; |
| 1300 | memcpy(&s->mem[0x10], &val, sizeof(val)); |
| 1301 | } |
| 1302 | |
| 1303 | /***************************************************************************** |
| 1304 | * |
| 1305 | * Port emulation. |
| 1306 | * |
| 1307 | ****************************************************************************/ |
| 1308 | |
| 1309 | #define PORT_SOFTWARE_RESET 0 |
| 1310 | #define PORT_SELFTEST 1 |
| 1311 | #define PORT_SELECTIVE_RESET 2 |
| 1312 | #define PORT_DUMP 3 |
| 1313 | #define PORT_SELECTION_MASK 3 |
| 1314 | |
| 1315 | typedef struct { |
| 1316 | uint32_t st_sign; /* Self Test Signature */ |
| 1317 | uint32_t st_result; /* Self Test Results */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1318 | } eepro100_selftest_t; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1319 | |
| 1320 | static uint32_t eepro100_read_port(EEPRO100State * s) |
| 1321 | { |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | static void eepro100_write_port(EEPRO100State * s, uint32_t val) |
| 1326 | { |
| 1327 | val = le32_to_cpu(val); |
| 1328 | uint32_t address = (val & ~PORT_SELECTION_MASK); |
| 1329 | uint8_t selection = (val & PORT_SELECTION_MASK); |
| 1330 | switch (selection) { |
| 1331 | case PORT_SOFTWARE_RESET: |
| 1332 | nic_reset(s); |
| 1333 | break; |
| 1334 | case PORT_SELFTEST: |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1335 | TRACE(OTHER, logout("selftest address=0x%08x\n", address)); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1336 | eepro100_selftest_t data; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1337 | cpu_physical_memory_read(address, (uint8_t *) & data, sizeof(data)); |
| 1338 | data.st_sign = 0xffffffff; |
| 1339 | data.st_result = 0; |
| 1340 | cpu_physical_memory_write(address, (uint8_t *) & data, sizeof(data)); |
| 1341 | break; |
| 1342 | case PORT_SELECTIVE_RESET: |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1343 | TRACE(OTHER, logout("selective reset, selftest address=0x%08x\n", address)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1344 | nic_selective_reset(s); |
| 1345 | break; |
| 1346 | default: |
| 1347 | logout("val=0x%08x\n", val); |
| 1348 | missing("unknown port selection"); |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | /***************************************************************************** |
| 1353 | * |
| 1354 | * General hardware emulation. |
| 1355 | * |
| 1356 | ****************************************************************************/ |
| 1357 | |
| 1358 | static uint8_t eepro100_read1(EEPRO100State * s, uint32_t addr) |
| 1359 | { |
| 1360 | uint8_t val; |
| 1361 | if (addr <= sizeof(s->mem) - sizeof(val)) { |
| 1362 | memcpy(&val, &s->mem[addr], sizeof(val)); |
| 1363 | } |
| 1364 | |
| 1365 | switch (addr) { |
| 1366 | case SCBStatus: |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1367 | #if 0 |
| 1368 | val = eepro100_read_status(s); |
| 1369 | #endif |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1370 | TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1371 | break; |
| 1372 | case SCBAck: |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1373 | #if 0 |
| 1374 | val = eepro100_read_status(s); |
| 1375 | #endif |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1376 | TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1377 | break; |
| 1378 | case SCBCmd: |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1379 | TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val)); |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1380 | #if 0 |
| 1381 | val = eepro100_read_command(s); |
| 1382 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1383 | break; |
| 1384 | case SCBIntmask: |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1385 | TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1386 | break; |
| 1387 | case SCBPort + 3: |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1388 | TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1389 | break; |
| 1390 | case SCBeeprom: |
| 1391 | val = eepro100_read_eeprom(s); |
| 1392 | break; |
Stefan Weil | 0908bba | 2010-03-02 22:37:42 +0100 | [diff] [blame] | 1393 | case SCBpmdr: /* Power Management Driver Register */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1394 | val = 0; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1395 | TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1396 | break; |
Stefan Weil | 0908bba | 2010-03-02 22:37:42 +0100 | [diff] [blame] | 1397 | case SCBgstat: /* General Status Register */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1398 | /* 100 Mbps full duplex, valid link */ |
| 1399 | val = 0x07; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1400 | TRACE(OTHER, logout("addr=General Status val=%02x\n", val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1401 | break; |
| 1402 | default: |
| 1403 | logout("addr=%s val=0x%02x\n", regname(addr), val); |
| 1404 | missing("unknown byte read"); |
| 1405 | } |
| 1406 | return val; |
| 1407 | } |
| 1408 | |
| 1409 | static uint16_t eepro100_read2(EEPRO100State * s, uint32_t addr) |
| 1410 | { |
| 1411 | uint16_t val; |
| 1412 | if (addr <= sizeof(s->mem) - sizeof(val)) { |
| 1413 | memcpy(&val, &s->mem[addr], sizeof(val)); |
| 1414 | } |
| 1415 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1416 | switch (addr) { |
| 1417 | case SCBStatus: |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1418 | #if 0 |
| 1419 | val = eepro100_read_status(s); |
| 1420 | #endif |
=?UTF-8?q?Reimar=20D=C3=B6ffinger?= | dbbaaff | 2009-10-02 18:39:41 +0200 | [diff] [blame] | 1421 | case SCBCmd: |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1422 | TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1423 | break; |
| 1424 | case SCBeeprom: |
| 1425 | val = eepro100_read_eeprom(s); |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1426 | TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1427 | break; |
| 1428 | default: |
| 1429 | logout("addr=%s val=0x%04x\n", regname(addr), val); |
| 1430 | missing("unknown word read"); |
| 1431 | } |
| 1432 | return val; |
| 1433 | } |
| 1434 | |
| 1435 | static uint32_t eepro100_read4(EEPRO100State * s, uint32_t addr) |
| 1436 | { |
| 1437 | uint32_t val; |
| 1438 | if (addr <= sizeof(s->mem) - sizeof(val)) { |
| 1439 | memcpy(&val, &s->mem[addr], sizeof(val)); |
| 1440 | } |
| 1441 | |
| 1442 | switch (addr) { |
| 1443 | case SCBStatus: |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1444 | #if 0 |
| 1445 | val = eepro100_read_status(s); |
| 1446 | #endif |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1447 | TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1448 | break; |
| 1449 | case SCBPointer: |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1450 | #if 0 |
| 1451 | val = eepro100_read_pointer(s); |
| 1452 | #endif |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1453 | TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1454 | break; |
| 1455 | case SCBPort: |
| 1456 | val = eepro100_read_port(s); |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1457 | TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1458 | break; |
| 1459 | case SCBCtrlMDI: |
| 1460 | val = eepro100_read_mdi(s); |
| 1461 | break; |
| 1462 | default: |
| 1463 | logout("addr=%s val=0x%08x\n", regname(addr), val); |
| 1464 | missing("unknown longword read"); |
| 1465 | } |
| 1466 | return val; |
| 1467 | } |
| 1468 | |
| 1469 | static void eepro100_write1(EEPRO100State * s, uint32_t addr, uint8_t val) |
| 1470 | { |
| 1471 | if (addr <= sizeof(s->mem) - sizeof(val)) { |
| 1472 | memcpy(&s->mem[addr], &val, sizeof(val)); |
| 1473 | } |
| 1474 | |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1475 | TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1476 | |
| 1477 | switch (addr) { |
| 1478 | case SCBStatus: |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1479 | #if 0 |
| 1480 | eepro100_write_status(s, val); |
| 1481 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1482 | break; |
| 1483 | case SCBAck: |
| 1484 | eepro100_acknowledge(s); |
| 1485 | break; |
| 1486 | case SCBCmd: |
| 1487 | eepro100_write_command(s, val); |
| 1488 | break; |
| 1489 | case SCBIntmask: |
| 1490 | if (val & BIT(1)) { |
| 1491 | eepro100_swi_interrupt(s); |
| 1492 | } |
| 1493 | eepro100_interrupt(s, 0); |
| 1494 | break; |
| 1495 | case SCBPort + 3: |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1496 | case SCBFlow: /* does not exist on 82557 */ |
ths | 3257d2b | 2007-09-14 22:22:13 +0000 | [diff] [blame] | 1497 | case SCBFlow + 1: |
| 1498 | case SCBFlow + 2: |
Stefan Weil | 0908bba | 2010-03-02 22:37:42 +0100 | [diff] [blame] | 1499 | case SCBpmdr: /* does not exist on 82557 */ |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1500 | TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1501 | break; |
| 1502 | case SCBeeprom: |
| 1503 | eepro100_write_eeprom(s->eeprom, val); |
| 1504 | break; |
| 1505 | default: |
| 1506 | logout("addr=%s val=0x%02x\n", regname(addr), val); |
| 1507 | missing("unknown byte write"); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | static void eepro100_write2(EEPRO100State * s, uint32_t addr, uint16_t val) |
| 1512 | { |
| 1513 | if (addr <= sizeof(s->mem) - sizeof(val)) { |
| 1514 | memcpy(&s->mem[addr], &val, sizeof(val)); |
| 1515 | } |
| 1516 | |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1517 | TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1518 | |
| 1519 | switch (addr) { |
| 1520 | case SCBStatus: |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1521 | #if 0 |
| 1522 | eepro100_write_status(s, val); |
| 1523 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1524 | eepro100_acknowledge(s); |
| 1525 | break; |
| 1526 | case SCBCmd: |
| 1527 | eepro100_write_command(s, val); |
| 1528 | eepro100_write1(s, SCBIntmask, val >> 8); |
| 1529 | break; |
| 1530 | case SCBeeprom: |
| 1531 | eepro100_write_eeprom(s->eeprom, val); |
| 1532 | break; |
| 1533 | default: |
| 1534 | logout("addr=%s val=0x%04x\n", regname(addr), val); |
| 1535 | missing("unknown word write"); |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | static void eepro100_write4(EEPRO100State * s, uint32_t addr, uint32_t val) |
| 1540 | { |
| 1541 | if (addr <= sizeof(s->mem) - sizeof(val)) { |
| 1542 | memcpy(&s->mem[addr], &val, sizeof(val)); |
| 1543 | } |
| 1544 | |
| 1545 | switch (addr) { |
| 1546 | case SCBPointer: |
| 1547 | eepro100_write_pointer(s, val); |
| 1548 | break; |
| 1549 | case SCBPort: |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1550 | TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1551 | eepro100_write_port(s, val); |
| 1552 | break; |
| 1553 | case SCBCtrlMDI: |
| 1554 | eepro100_write_mdi(s, val); |
| 1555 | break; |
| 1556 | default: |
| 1557 | logout("addr=%s val=0x%08x\n", regname(addr), val); |
| 1558 | missing("unknown longword write"); |
| 1559 | } |
| 1560 | } |
| 1561 | |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1562 | /***************************************************************************** |
| 1563 | * |
| 1564 | * Port mapped I/O. |
| 1565 | * |
| 1566 | ****************************************************************************/ |
| 1567 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1568 | static uint32_t ioport_read1(void *opaque, uint32_t addr) |
| 1569 | { |
| 1570 | EEPRO100State *s = opaque; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1571 | #if 0 |
| 1572 | logout("addr=%s\n", regname(addr)); |
| 1573 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1574 | return eepro100_read1(s, addr - s->region[1]); |
| 1575 | } |
| 1576 | |
| 1577 | static uint32_t ioport_read2(void *opaque, uint32_t addr) |
| 1578 | { |
| 1579 | EEPRO100State *s = opaque; |
| 1580 | return eepro100_read2(s, addr - s->region[1]); |
| 1581 | } |
| 1582 | |
| 1583 | static uint32_t ioport_read4(void *opaque, uint32_t addr) |
| 1584 | { |
| 1585 | EEPRO100State *s = opaque; |
| 1586 | return eepro100_read4(s, addr - s->region[1]); |
| 1587 | } |
| 1588 | |
| 1589 | static void ioport_write1(void *opaque, uint32_t addr, uint32_t val) |
| 1590 | { |
| 1591 | EEPRO100State *s = opaque; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1592 | #if 0 |
| 1593 | logout("addr=%s val=0x%02x\n", regname(addr), val); |
| 1594 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1595 | eepro100_write1(s, addr - s->region[1], val); |
| 1596 | } |
| 1597 | |
| 1598 | static void ioport_write2(void *opaque, uint32_t addr, uint32_t val) |
| 1599 | { |
| 1600 | EEPRO100State *s = opaque; |
| 1601 | eepro100_write2(s, addr - s->region[1], val); |
| 1602 | } |
| 1603 | |
| 1604 | static void ioport_write4(void *opaque, uint32_t addr, uint32_t val) |
| 1605 | { |
| 1606 | EEPRO100State *s = opaque; |
| 1607 | eepro100_write4(s, addr - s->region[1], val); |
| 1608 | } |
| 1609 | |
| 1610 | /***********************************************************/ |
| 1611 | /* PCI EEPRO100 definitions */ |
| 1612 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1613 | static void pci_map(PCIDevice * pci_dev, int region_num, |
Isaku Yamahata | 6e355d9 | 2009-10-30 21:21:08 +0900 | [diff] [blame] | 1614 | pcibus_t addr, pcibus_t size, int type) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1615 | { |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 1616 | EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1617 | |
Isaku Yamahata | 89e8b13 | 2009-10-30 21:21:09 +0900 | [diff] [blame] | 1618 | TRACE(OTHER, logout("region %d, addr=0x%08"FMT_PCIBUS", " |
| 1619 | "size=0x%08"FMT_PCIBUS", type=%d\n", |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1620 | region_num, addr, size, type)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1621 | |
| 1622 | assert(region_num == 1); |
| 1623 | register_ioport_write(addr, size, 1, ioport_write1, s); |
| 1624 | register_ioport_read(addr, size, 1, ioport_read1, s); |
| 1625 | register_ioport_write(addr, size, 2, ioport_write2, s); |
| 1626 | register_ioport_read(addr, size, 2, ioport_read2, s); |
| 1627 | register_ioport_write(addr, size, 4, ioport_write4, s); |
| 1628 | register_ioport_read(addr, size, 4, ioport_read4, s); |
| 1629 | |
| 1630 | s->region[region_num] = addr; |
| 1631 | } |
| 1632 | |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1633 | /***************************************************************************** |
| 1634 | * |
| 1635 | * Memory mapped I/O. |
| 1636 | * |
| 1637 | ****************************************************************************/ |
| 1638 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1639 | static void pci_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1640 | { |
| 1641 | EEPRO100State *s = opaque; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1642 | #if 0 |
| 1643 | logout("addr=%s val=0x%02x\n", regname(addr), val); |
| 1644 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1645 | eepro100_write1(s, addr, val); |
| 1646 | } |
| 1647 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1648 | static void pci_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1649 | { |
| 1650 | EEPRO100State *s = opaque; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1651 | #if 0 |
| 1652 | logout("addr=%s val=0x%02x\n", regname(addr), val); |
| 1653 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1654 | eepro100_write2(s, addr, val); |
| 1655 | } |
| 1656 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1657 | static void pci_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1658 | { |
| 1659 | EEPRO100State *s = opaque; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1660 | #if 0 |
| 1661 | logout("addr=%s val=0x%02x\n", regname(addr), val); |
| 1662 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1663 | eepro100_write4(s, addr, val); |
| 1664 | } |
| 1665 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1666 | static uint32_t pci_mmio_readb(void *opaque, target_phys_addr_t addr) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1667 | { |
| 1668 | EEPRO100State *s = opaque; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1669 | #if 0 |
| 1670 | logout("addr=%s\n", regname(addr)); |
| 1671 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1672 | return eepro100_read1(s, addr); |
| 1673 | } |
| 1674 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1675 | static uint32_t pci_mmio_readw(void *opaque, target_phys_addr_t addr) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1676 | { |
| 1677 | EEPRO100State *s = opaque; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1678 | #if 0 |
| 1679 | logout("addr=%s\n", regname(addr)); |
| 1680 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1681 | return eepro100_read2(s, addr); |
| 1682 | } |
| 1683 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1684 | static uint32_t pci_mmio_readl(void *opaque, target_phys_addr_t addr) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1685 | { |
| 1686 | EEPRO100State *s = opaque; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1687 | #if 0 |
| 1688 | logout("addr=%s\n", regname(addr)); |
| 1689 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1690 | return eepro100_read4(s, addr); |
| 1691 | } |
| 1692 | |
Blue Swirl | d60efc6 | 2009-08-25 18:29:31 +0000 | [diff] [blame] | 1693 | static CPUWriteMemoryFunc * const pci_mmio_write[] = { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1694 | pci_mmio_writeb, |
| 1695 | pci_mmio_writew, |
| 1696 | pci_mmio_writel |
| 1697 | }; |
| 1698 | |
Blue Swirl | d60efc6 | 2009-08-25 18:29:31 +0000 | [diff] [blame] | 1699 | static CPUReadMemoryFunc * const pci_mmio_read[] = { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1700 | pci_mmio_readb, |
| 1701 | pci_mmio_readw, |
| 1702 | pci_mmio_readl |
| 1703 | }; |
| 1704 | |
| 1705 | static void pci_mmio_map(PCIDevice * pci_dev, int region_num, |
Isaku Yamahata | 6e355d9 | 2009-10-30 21:21:08 +0900 | [diff] [blame] | 1706 | pcibus_t addr, pcibus_t size, int type) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1707 | { |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 1708 | EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1709 | |
Isaku Yamahata | 89e8b13 | 2009-10-30 21:21:09 +0900 | [diff] [blame] | 1710 | TRACE(OTHER, logout("region %d, addr=0x%08"FMT_PCIBUS", " |
| 1711 | "size=0x%08"FMT_PCIBUS", type=%d\n", |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1712 | region_num, addr, size, type)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1713 | |
| 1714 | if (region_num == 0) { |
| 1715 | /* Map control / status registers. */ |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 1716 | cpu_register_physical_memory(addr, size, s->mmio_index); |
| 1717 | s->region[region_num] = addr; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1718 | } |
| 1719 | } |
| 1720 | |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1721 | static int nic_can_receive(VLANClientState *nc) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1722 | { |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1723 | EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque; |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1724 | TRACE(RXTX, logout("%p\n", s)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1725 | return get_ru_state(s) == ru_ready; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1726 | #if 0 |
| 1727 | return !eepro100_buffer_full(s); |
| 1728 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1731 | static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1732 | { |
| 1733 | /* TODO: |
| 1734 | * - Magic packets should set bit 30 in power management driver register. |
| 1735 | * - Interesting packets should set bit 29 in power management driver register. |
| 1736 | */ |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1737 | EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1738 | uint16_t rfd_status = 0xa000; |
| 1739 | static const uint8_t broadcast_macaddr[6] = |
| 1740 | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 1741 | |
| 1742 | /* TODO: check multiple IA bit. */ |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 1743 | if (s->configuration[20] & BIT(6)) { |
| 1744 | missing("Multiple IA bit"); |
| 1745 | return -1; |
| 1746 | } |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1747 | |
| 1748 | if (s->configuration[8] & 0x80) { |
| 1749 | /* CSMA is disabled. */ |
| 1750 | logout("%p received while CSMA is disabled\n", s); |
Mark McLoughlin | 4f1c942 | 2009-05-18 13:40:55 +0100 | [diff] [blame] | 1751 | return -1; |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 1752 | } else if (size < 64 && (s->configuration[7] & BIT(0))) { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1753 | /* Short frame and configuration byte 7/0 (discard short receive) set: |
| 1754 | * Short frame is discarded */ |
Stefan Weil | 067d01d | 2009-09-19 12:37:51 +0200 | [diff] [blame] | 1755 | logout("%p received short frame (%zu byte)\n", s, size); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1756 | s->statistics.rx_short_frame_errors++; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1757 | #if 0 |
| 1758 | return -1; |
| 1759 | #endif |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 1760 | } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & BIT(3))) { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1761 | /* Long frame and configuration byte 18/3 (long receive ok) not set: |
| 1762 | * Long frames are discarded. */ |
Stefan Weil | 067d01d | 2009-09-19 12:37:51 +0200 | [diff] [blame] | 1763 | logout("%p received long frame (%zu byte), ignored\n", s, size); |
Mark McLoughlin | 4f1c942 | 2009-05-18 13:40:55 +0100 | [diff] [blame] | 1764 | return -1; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1765 | } else if (memcmp(buf, s->conf.macaddr.a, 6) == 0) { /* !!! */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1766 | /* Frame matches individual address. */ |
| 1767 | /* TODO: check configuration byte 15/4 (ignore U/L). */ |
Stefan Weil | 067d01d | 2009-09-19 12:37:51 +0200 | [diff] [blame] | 1768 | TRACE(RXTX, logout("%p received frame for me, len=%zu\n", s, size)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1769 | } else if (memcmp(buf, broadcast_macaddr, 6) == 0) { |
| 1770 | /* Broadcast frame. */ |
Stefan Weil | 067d01d | 2009-09-19 12:37:51 +0200 | [diff] [blame] | 1771 | TRACE(RXTX, logout("%p received broadcast, len=%zu\n", s, size)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1772 | rfd_status |= 0x0002; |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 1773 | } else if (buf[0] & 0x01) { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1774 | /* Multicast frame. */ |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 1775 | TRACE(RXTX, logout("%p received multicast, len=%zu,%s\n", s, size, nic_dump(buf, size))); |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 1776 | if (s->configuration[21] & BIT(3)) { |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 1777 | /* Multicast all bit is set, receive all multicast frames. */ |
| 1778 | } else { |
| 1779 | unsigned mcast_idx = compute_mcast_idx(buf); |
| 1780 | assert(mcast_idx < 64); |
| 1781 | if (s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))) { |
| 1782 | /* Multicast frame is allowed in hash table. */ |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 1783 | } else if (s->configuration[15] & BIT(0)) { |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 1784 | /* Promiscuous: receive all. */ |
| 1785 | rfd_status |= 0x0004; |
| 1786 | } else { |
| 1787 | TRACE(RXTX, logout("%p multicast ignored\n", s)); |
| 1788 | return -1; |
| 1789 | } |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 1790 | } |
Stefan Weil | 7b8737d | 2009-12-20 16:52:24 +0100 | [diff] [blame] | 1791 | /* TODO: Next not for promiscuous mode? */ |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1792 | rfd_status |= 0x0002; |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 1793 | } else if (s->configuration[15] & BIT(0)) { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1794 | /* Promiscuous: receive all. */ |
Stefan Weil | 067d01d | 2009-09-19 12:37:51 +0200 | [diff] [blame] | 1795 | TRACE(RXTX, logout("%p received frame in promiscuous mode, len=%zu\n", s, size)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1796 | rfd_status |= 0x0004; |
| 1797 | } else { |
Stefan Weil | 067d01d | 2009-09-19 12:37:51 +0200 | [diff] [blame] | 1798 | TRACE(RXTX, logout("%p received frame, ignored, len=%zu,%s\n", s, size, |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1799 | nic_dump(buf, size))); |
Mark McLoughlin | 4f1c942 | 2009-05-18 13:40:55 +0100 | [diff] [blame] | 1800 | return size; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | if (get_ru_state(s) != ru_ready) { |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1804 | /* No resources available. */ |
| 1805 | logout("no resources, state=%u\n", get_ru_state(s)); |
Stefan Weil | e824012 | 2010-03-02 22:37:53 +0100 | [diff] [blame] | 1806 | /* TODO: RNR interrupt only at first failed frame? */ |
| 1807 | eepro100_rnr_interrupt(s); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1808 | s->statistics.rx_resource_errors++; |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1809 | #if 0 |
| 1810 | assert(!"no resources"); |
| 1811 | #endif |
Mark McLoughlin | 4f1c942 | 2009-05-18 13:40:55 +0100 | [diff] [blame] | 1812 | return -1; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1813 | } |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1814 | /* !!! */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1815 | eepro100_rx_t rx; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1816 | cpu_physical_memory_read(s->ru_base + s->ru_offset, (uint8_t *) & rx, |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1817 | offsetof(eepro100_rx_t, packet)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1818 | uint16_t rfd_command = le16_to_cpu(rx.command); |
| 1819 | uint16_t rfd_size = le16_to_cpu(rx.size); |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 1820 | |
| 1821 | if (size > rfd_size) { |
| 1822 | logout("Receive buffer (%" PRId16 " bytes) too small for data " |
| 1823 | "(%zu bytes); data truncated\n", rfd_size, size); |
| 1824 | size = rfd_size; |
| 1825 | } |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1826 | if (size < 64) { |
| 1827 | rfd_status |= 0x0080; |
| 1828 | } |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1829 | TRACE(OTHER, logout("command 0x%04x, link 0x%08x, addr 0x%08x, size %u\n", |
| 1830 | rfd_command, rx.link, rx.rx_buf_addr, rfd_size)); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1831 | stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, status), |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1832 | rfd_status); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1833 | stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, count), size); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1834 | /* Early receive interrupt not supported. */ |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1835 | #if 0 |
| 1836 | eepro100_er_interrupt(s); |
| 1837 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1838 | /* Receive CRC Transfer not supported. */ |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 1839 | if (s->configuration[18] & BIT(2)) { |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 1840 | missing("Receive CRC Transfer"); |
| 1841 | return -1; |
| 1842 | } |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1843 | /* TODO: check stripping enable bit. */ |
Stefan Weil | e7493b2 | 2010-03-02 22:37:59 +0100 | [diff] [blame] | 1844 | #if 0 |
| 1845 | assert(!(s->configuration[17] & BIT(0))); |
| 1846 | #endif |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1847 | cpu_physical_memory_write(s->ru_base + s->ru_offset + |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 1848 | offsetof(eepro100_rx_t, packet), buf, size); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1849 | s->statistics.rx_good_frames++; |
| 1850 | eepro100_fr_interrupt(s); |
| 1851 | s->ru_offset = le32_to_cpu(rx.link); |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 1852 | if (rfd_command & COMMAND_EL) { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1853 | /* EL bit is set, so this was the last frame. */ |
Kevin Wolf | 7f1e9d4 | 2009-09-23 17:42:42 +0200 | [diff] [blame] | 1854 | logout("receive: Running out of frames\n"); |
| 1855 | set_ru_state(s, ru_suspended); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1856 | } |
Stefan Weil | ced5296 | 2010-03-02 22:37:49 +0100 | [diff] [blame] | 1857 | if (rfd_command & COMMAND_S) { |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1858 | /* S bit is set. */ |
| 1859 | set_ru_state(s, ru_suspended); |
| 1860 | } |
Mark McLoughlin | 4f1c942 | 2009-05-18 13:40:55 +0100 | [diff] [blame] | 1861 | return size; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
Juan Quintela | 151b298 | 2009-10-19 15:37:57 +0200 | [diff] [blame] | 1864 | static const VMStateDescription vmstate_eepro100 = { |
| 1865 | .version_id = 3, |
| 1866 | .minimum_version_id = 2, |
| 1867 | .minimum_version_id_old = 2, |
| 1868 | .fields = (VMStateField []) { |
| 1869 | VMSTATE_PCI_DEVICE(dev, EEPRO100State), |
| 1870 | VMSTATE_UNUSED(32), |
| 1871 | VMSTATE_BUFFER(mult, EEPRO100State), |
| 1872 | VMSTATE_BUFFER(mem, EEPRO100State), |
| 1873 | /* Save all members of struct between scb_stat and mem. */ |
| 1874 | VMSTATE_UINT8(scb_stat, EEPRO100State), |
| 1875 | VMSTATE_UINT8(int_stat, EEPRO100State), |
| 1876 | VMSTATE_UNUSED(3*4), |
| 1877 | VMSTATE_MACADDR(conf.macaddr, EEPRO100State), |
| 1878 | VMSTATE_UNUSED(19*4), |
| 1879 | VMSTATE_UINT16_ARRAY(mdimem, EEPRO100State, 32), |
| 1880 | /* The eeprom should be saved and restored by its own routines. */ |
| 1881 | VMSTATE_UINT32(device, EEPRO100State), |
| 1882 | /* TODO check device. */ |
| 1883 | VMSTATE_UINT32(pointer, EEPRO100State), |
| 1884 | VMSTATE_UINT32(cu_base, EEPRO100State), |
| 1885 | VMSTATE_UINT32(cu_offset, EEPRO100State), |
| 1886 | VMSTATE_UINT32(ru_base, EEPRO100State), |
| 1887 | VMSTATE_UINT32(ru_offset, EEPRO100State), |
| 1888 | VMSTATE_UINT32(statsaddr, EEPRO100State), |
Stefan Weil | ba42b64 | 2009-10-30 13:36:21 +0100 | [diff] [blame] | 1889 | /* Save eepro100_stats_t statistics. */ |
Juan Quintela | 151b298 | 2009-10-19 15:37:57 +0200 | [diff] [blame] | 1890 | VMSTATE_UINT32(statistics.tx_good_frames, EEPRO100State), |
| 1891 | VMSTATE_UINT32(statistics.tx_max_collisions, EEPRO100State), |
| 1892 | VMSTATE_UINT32(statistics.tx_late_collisions, EEPRO100State), |
| 1893 | VMSTATE_UINT32(statistics.tx_underruns, EEPRO100State), |
| 1894 | VMSTATE_UINT32(statistics.tx_lost_crs, EEPRO100State), |
| 1895 | VMSTATE_UINT32(statistics.tx_deferred, EEPRO100State), |
| 1896 | VMSTATE_UINT32(statistics.tx_single_collisions, EEPRO100State), |
| 1897 | VMSTATE_UINT32(statistics.tx_multiple_collisions, EEPRO100State), |
| 1898 | VMSTATE_UINT32(statistics.tx_total_collisions, EEPRO100State), |
| 1899 | VMSTATE_UINT32(statistics.rx_good_frames, EEPRO100State), |
| 1900 | VMSTATE_UINT32(statistics.rx_crc_errors, EEPRO100State), |
| 1901 | VMSTATE_UINT32(statistics.rx_alignment_errors, EEPRO100State), |
| 1902 | VMSTATE_UINT32(statistics.rx_resource_errors, EEPRO100State), |
| 1903 | VMSTATE_UINT32(statistics.rx_overrun_errors, EEPRO100State), |
| 1904 | VMSTATE_UINT32(statistics.rx_cdt_errors, EEPRO100State), |
| 1905 | VMSTATE_UINT32(statistics.rx_short_frame_errors, EEPRO100State), |
| 1906 | VMSTATE_UINT32(statistics.fc_xmt_pause, EEPRO100State), |
| 1907 | VMSTATE_UINT32(statistics.fc_rcv_pause, EEPRO100State), |
| 1908 | VMSTATE_UINT32(statistics.fc_rcv_unsupported, EEPRO100State), |
| 1909 | VMSTATE_UINT16(statistics.xmt_tco_frames, EEPRO100State), |
| 1910 | VMSTATE_UINT16(statistics.rcv_tco_frames, EEPRO100State), |
balrog | 2657c66 | 2007-07-02 13:38:46 +0000 | [diff] [blame] | 1911 | #if 0 |
Juan Quintela | 151b298 | 2009-10-19 15:37:57 +0200 | [diff] [blame] | 1912 | VMSTATE_UINT16(status, EEPRO100State), |
balrog | 2657c66 | 2007-07-02 13:38:46 +0000 | [diff] [blame] | 1913 | #endif |
Juan Quintela | 151b298 | 2009-10-19 15:37:57 +0200 | [diff] [blame] | 1914 | /* Configuration bytes. */ |
| 1915 | VMSTATE_BUFFER(configuration, EEPRO100State), |
| 1916 | VMSTATE_END_OF_LIST() |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1917 | } |
Juan Quintela | 151b298 | 2009-10-19 15:37:57 +0200 | [diff] [blame] | 1918 | }; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1919 | |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1920 | static void nic_cleanup(VLANClientState *nc) |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 1921 | { |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1922 | EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque; |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 1923 | |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1924 | s->nic = NULL; |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 1927 | static int pci_nic_uninit(PCIDevice *pci_dev) |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 1928 | { |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 1929 | EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 1930 | |
| 1931 | cpu_unregister_io_memory(s->mmio_index); |
Juan Quintela | 151b298 | 2009-10-19 15:37:57 +0200 | [diff] [blame] | 1932 | vmstate_unregister(s->vmstate, s); |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 1933 | eeprom93xx_free(s->eeprom); |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1934 | qemu_del_vlan_client(&s->nic->nc); |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 1935 | return 0; |
| 1936 | } |
| 1937 | |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1938 | static NetClientInfo net_eepro100_info = { |
| 1939 | .type = NET_CLIENT_TYPE_NIC, |
| 1940 | .size = sizeof(NICState), |
| 1941 | .can_receive = nic_can_receive, |
| 1942 | .receive = nic_receive, |
| 1943 | .cleanup = nic_cleanup, |
| 1944 | }; |
| 1945 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 1946 | static int nic_init(PCIDevice *pci_dev, uint32_t device) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1947 | { |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 1948 | EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1949 | |
Stefan Weil | aac443e | 2009-09-19 12:11:36 +0200 | [diff] [blame] | 1950 | TRACE(OTHER, logout("\n")); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1951 | |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1952 | s->device = device; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1953 | |
| 1954 | pci_reset(s); |
| 1955 | |
| 1956 | /* Add 64 * 2 EEPROM. i82557 and i82558 support a 64 word EEPROM, |
| 1957 | * i82559 and later support 64 or 256 word EEPROM. */ |
| 1958 | s->eeprom = eeprom93xx_new(EEPROM_SIZE); |
| 1959 | |
| 1960 | /* Handler for memory-mapped I/O */ |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 1961 | s->mmio_index = |
Avi Kivity | 1eed09c | 2009-06-14 11:38:51 +0300 | [diff] [blame] | 1962 | cpu_register_io_memory(pci_mmio_read, pci_mmio_write, s); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1963 | |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 1964 | pci_register_bar(&s->dev, 0, PCI_MEM_SIZE, |
Isaku Yamahata | 0392a01 | 2009-10-30 21:21:03 +0900 | [diff] [blame] | 1965 | PCI_BASE_ADDRESS_SPACE_MEMORY | |
| 1966 | PCI_BASE_ADDRESS_MEM_PREFETCH, pci_mmio_map); |
| 1967 | pci_register_bar(&s->dev, 1, PCI_IO_SIZE, PCI_BASE_ADDRESS_SPACE_IO, |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1968 | pci_map); |
Isaku Yamahata | 0392a01 | 2009-10-30 21:21:03 +0900 | [diff] [blame] | 1969 | pci_register_bar(&s->dev, 2, PCI_FLASH_SIZE, PCI_BASE_ADDRESS_SPACE_MEMORY, |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1970 | pci_mmio_map); |
| 1971 | |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 1972 | qemu_macaddr_default_if_unset(&s->conf.macaddr); |
Stefan Weil | ce0e58b | 2010-03-02 22:37:41 +0100 | [diff] [blame] | 1973 | logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1974 | assert(s->region[1] == 0); |
| 1975 | |
| 1976 | nic_reset(s); |
| 1977 | |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1978 | s->nic = qemu_new_nic(&net_eepro100_info, &s->conf, |
| 1979 | pci_dev->qdev.info->name, pci_dev->qdev.id, s); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1980 | |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1981 | qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); |
| 1982 | TRACE(OTHER, logout("%s\n", s->nic->nc.info_str)); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1983 | |
Jan Kiszka | a08d436 | 2009-06-27 09:25:07 +0200 | [diff] [blame] | 1984 | qemu_register_reset(nic_reset, s); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1985 | |
Juan Quintela | 151b298 | 2009-10-19 15:37:57 +0200 | [diff] [blame] | 1986 | s->vmstate = qemu_malloc(sizeof(vmstate_eepro100)); |
| 1987 | memcpy(s->vmstate, &vmstate_eepro100, sizeof(vmstate_eepro100)); |
Mark McLoughlin | e00e365 | 2009-11-25 18:49:16 +0000 | [diff] [blame] | 1988 | s->vmstate->name = s->nic->nc.model; |
Juan Quintela | 151b298 | 2009-10-19 15:37:57 +0200 | [diff] [blame] | 1989 | vmstate_register(-1, s->vmstate, s); |
Stefan Weil | 4e9df06 | 2009-10-31 13:38:33 +0100 | [diff] [blame] | 1990 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 1991 | return 0; |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 1994 | static int pci_i82550_init(PCIDevice *pci_dev) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1995 | { |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 1996 | return nic_init(pci_dev, i82550); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 1999 | static int pci_i82551_init(PCIDevice *pci_dev) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 2000 | { |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2001 | return nic_init(pci_dev, i82551); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2004 | static int pci_i82557a_init(PCIDevice *pci_dev) |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 2005 | { |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2006 | return nic_init(pci_dev, i82557A); |
| 2007 | } |
| 2008 | |
| 2009 | static int pci_i82557b_init(PCIDevice *pci_dev) |
| 2010 | { |
| 2011 | return nic_init(pci_dev, i82557B); |
| 2012 | } |
| 2013 | |
| 2014 | static int pci_i82557c_init(PCIDevice *pci_dev) |
| 2015 | { |
| 2016 | return nic_init(pci_dev, i82557C); |
| 2017 | } |
| 2018 | |
| 2019 | static int pci_i82558a_init(PCIDevice *pci_dev) |
| 2020 | { |
| 2021 | return nic_init(pci_dev, i82558A); |
| 2022 | } |
| 2023 | |
| 2024 | static int pci_i82558b_init(PCIDevice *pci_dev) |
| 2025 | { |
| 2026 | return nic_init(pci_dev, i82558B); |
| 2027 | } |
| 2028 | |
| 2029 | static int pci_i82559a_init(PCIDevice *pci_dev) |
| 2030 | { |
| 2031 | return nic_init(pci_dev, i82559A); |
| 2032 | } |
| 2033 | |
| 2034 | static int pci_i82559b_init(PCIDevice *pci_dev) |
| 2035 | { |
| 2036 | return nic_init(pci_dev, i82559B); |
| 2037 | } |
| 2038 | |
| 2039 | static int pci_i82559c_init(PCIDevice *pci_dev) |
| 2040 | { |
| 2041 | return nic_init(pci_dev, i82559C); |
| 2042 | } |
| 2043 | |
| 2044 | static int pci_i82559er_init(PCIDevice *pci_dev) |
| 2045 | { |
| 2046 | return nic_init(pci_dev, i82559ER); |
| 2047 | } |
| 2048 | |
| 2049 | static int pci_i82562_init(PCIDevice *pci_dev) |
| 2050 | { |
| 2051 | return nic_init(pci_dev, i82562); |
ths | 663e8e5 | 2007-04-02 12:35:34 +0000 | [diff] [blame] | 2052 | } |
| 2053 | |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2054 | static PCIDeviceInfo eepro100_info[] = { |
| 2055 | { |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2056 | .qdev.name = "i82550", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2057 | .qdev.desc = "Intel i82550 Ethernet", |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2058 | .qdev.size = sizeof(EEPRO100State), |
| 2059 | .init = pci_i82550_init, |
Stefan Weil | 6a90e30 | 2009-11-02 17:34:53 +0100 | [diff] [blame] | 2060 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2061 | .romfile = "gpxe-eepro100-80861209.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2062 | .qdev.props = (Property[]) { |
| 2063 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2064 | DEFINE_PROP_END_OF_LIST(), |
| 2065 | }, |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2066 | },{ |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2067 | .qdev.name = "i82551", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2068 | .qdev.desc = "Intel i82551 Ethernet", |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 2069 | .qdev.size = sizeof(EEPRO100State), |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2070 | .init = pci_i82551_init, |
Gerd Hoffmann | e3936fa | 2009-09-25 21:42:38 +0200 | [diff] [blame] | 2071 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2072 | .romfile = "gpxe-eepro100-80861209.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2073 | .qdev.props = (Property[]) { |
| 2074 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2075 | DEFINE_PROP_END_OF_LIST(), |
| 2076 | }, |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2077 | },{ |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2078 | .qdev.name = "i82557a", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2079 | .qdev.desc = "Intel i82557A Ethernet", |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2080 | .qdev.size = sizeof(EEPRO100State), |
| 2081 | .init = pci_i82557a_init, |
Stefan Weil | 6a90e30 | 2009-11-02 17:34:53 +0100 | [diff] [blame] | 2082 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2083 | .romfile = "gpxe-eepro100-80861229.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2084 | .qdev.props = (Property[]) { |
| 2085 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2086 | DEFINE_PROP_END_OF_LIST(), |
| 2087 | }, |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2088 | },{ |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2089 | .qdev.name = "i82557b", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2090 | .qdev.desc = "Intel i82557B Ethernet", |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 2091 | .qdev.size = sizeof(EEPRO100State), |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2092 | .init = pci_i82557b_init, |
Gerd Hoffmann | e3936fa | 2009-09-25 21:42:38 +0200 | [diff] [blame] | 2093 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2094 | .romfile = "gpxe-eepro100-80861229.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2095 | .qdev.props = (Property[]) { |
| 2096 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2097 | DEFINE_PROP_END_OF_LIST(), |
| 2098 | }, |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2099 | },{ |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2100 | .qdev.name = "i82557c", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2101 | .qdev.desc = "Intel i82557C Ethernet", |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2102 | .qdev.size = sizeof(EEPRO100State), |
| 2103 | .init = pci_i82557c_init, |
Stefan Weil | 6a90e30 | 2009-11-02 17:34:53 +0100 | [diff] [blame] | 2104 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2105 | .romfile = "gpxe-eepro100-80861229.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2106 | .qdev.props = (Property[]) { |
| 2107 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2108 | DEFINE_PROP_END_OF_LIST(), |
| 2109 | }, |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2110 | },{ |
| 2111 | .qdev.name = "i82558a", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2112 | .qdev.desc = "Intel i82558A Ethernet", |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2113 | .qdev.size = sizeof(EEPRO100State), |
| 2114 | .init = pci_i82558a_init, |
Stefan Weil | 6a90e30 | 2009-11-02 17:34:53 +0100 | [diff] [blame] | 2115 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2116 | .romfile = "gpxe-eepro100-80861229.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2117 | .qdev.props = (Property[]) { |
| 2118 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2119 | DEFINE_PROP_END_OF_LIST(), |
| 2120 | }, |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2121 | },{ |
| 2122 | .qdev.name = "i82558b", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2123 | .qdev.desc = "Intel i82558B Ethernet", |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2124 | .qdev.size = sizeof(EEPRO100State), |
| 2125 | .init = pci_i82558b_init, |
Stefan Weil | 6a90e30 | 2009-11-02 17:34:53 +0100 | [diff] [blame] | 2126 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2127 | .romfile = "gpxe-eepro100-80861229.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2128 | .qdev.props = (Property[]) { |
| 2129 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2130 | DEFINE_PROP_END_OF_LIST(), |
| 2131 | }, |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2132 | },{ |
| 2133 | .qdev.name = "i82559a", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2134 | .qdev.desc = "Intel i82559A Ethernet", |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2135 | .qdev.size = sizeof(EEPRO100State), |
| 2136 | .init = pci_i82559a_init, |
Stefan Weil | 6a90e30 | 2009-11-02 17:34:53 +0100 | [diff] [blame] | 2137 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2138 | .romfile = "gpxe-eepro100-80861229.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2139 | .qdev.props = (Property[]) { |
| 2140 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2141 | DEFINE_PROP_END_OF_LIST(), |
| 2142 | }, |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2143 | },{ |
| 2144 | .qdev.name = "i82559b", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2145 | .qdev.desc = "Intel i82559B Ethernet", |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2146 | .qdev.size = sizeof(EEPRO100State), |
| 2147 | .init = pci_i82559b_init, |
Stefan Weil | 6a90e30 | 2009-11-02 17:34:53 +0100 | [diff] [blame] | 2148 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2149 | .romfile = "gpxe-eepro100-80861229.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2150 | .qdev.props = (Property[]) { |
| 2151 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2152 | DEFINE_PROP_END_OF_LIST(), |
| 2153 | }, |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2154 | },{ |
| 2155 | .qdev.name = "i82559c", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2156 | .qdev.desc = "Intel i82559C Ethernet", |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2157 | .qdev.size = sizeof(EEPRO100State), |
| 2158 | .init = pci_i82559c_init, |
Stefan Weil | 6a90e30 | 2009-11-02 17:34:53 +0100 | [diff] [blame] | 2159 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2160 | .romfile = "gpxe-eepro100-80861229.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2161 | .qdev.props = (Property[]) { |
| 2162 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2163 | DEFINE_PROP_END_OF_LIST(), |
| 2164 | }, |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2165 | },{ |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2166 | .qdev.name = "i82559er", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2167 | .qdev.desc = "Intel i82559ER Ethernet", |
Juan Quintela | 273a214 | 2009-08-24 18:42:37 +0200 | [diff] [blame] | 2168 | .qdev.size = sizeof(EEPRO100State), |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2169 | .init = pci_i82559er_init, |
Gerd Hoffmann | e3936fa | 2009-09-25 21:42:38 +0200 | [diff] [blame] | 2170 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2171 | .romfile = "gpxe-eepro100-80861209.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2172 | .qdev.props = (Property[]) { |
| 2173 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2174 | DEFINE_PROP_END_OF_LIST(), |
| 2175 | }, |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2176 | },{ |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2177 | .qdev.name = "i82562", |
Stefan Weil | 762401e | 2010-03-02 22:37:48 +0100 | [diff] [blame] | 2178 | .qdev.desc = "Intel i82562 Ethernet", |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2179 | .qdev.size = sizeof(EEPRO100State), |
| 2180 | .init = pci_i82562_init, |
Stefan Weil | 6a90e30 | 2009-11-02 17:34:53 +0100 | [diff] [blame] | 2181 | .exit = pci_nic_uninit, |
Stefan Weil | da51e79 | 2010-03-02 22:37:44 +0100 | [diff] [blame] | 2182 | .romfile = "gpxe-eepro100-80861209.rom", |
Gerd Hoffmann | 508ef93 | 2009-10-21 15:25:36 +0200 | [diff] [blame] | 2183 | .qdev.props = (Property[]) { |
| 2184 | DEFINE_NIC_PROPERTIES(EEPRO100State, conf), |
| 2185 | DEFINE_PROP_END_OF_LIST(), |
| 2186 | }, |
Stefan Weil | c4c270e | 2009-09-19 13:02:09 +0200 | [diff] [blame] | 2187 | },{ |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2188 | /* end of list */ |
| 2189 | } |
| 2190 | }; |
| 2191 | |
Paul Brook | 9d07d75 | 2009-05-14 22:35:07 +0100 | [diff] [blame] | 2192 | static void eepro100_register_devices(void) |
| 2193 | { |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 2194 | pci_qdev_register_many(eepro100_info); |
Paul Brook | 9d07d75 | 2009-05-14 22:35:07 +0100 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | device_init(eepro100_register_devices) |