2007-11-24 04:13:04 +01:00
|
|
|
/*
|
|
|
|
* Luminary Micro Stellaris Ethernet Controller
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 CodeSourcery.
|
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
2011-06-26 04:21:35 +02:00
|
|
|
* This code is licensed under the GPL.
|
2007-11-24 04:13:04 +01:00
|
|
|
*/
|
2019-05-23 16:35:07 +02:00
|
|
|
|
2016-01-26 19:17:05 +01:00
|
|
|
#include "qemu/osdep.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2012-10-24 08:43:34 +02:00
|
|
|
#include "net/net.h"
|
2018-06-26 18:50:41 +02:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2007-11-24 04:13:04 +01:00
|
|
|
#include <zlib.h>
|
|
|
|
|
|
|
|
//#define DEBUG_STELLARIS_ENET 1
|
|
|
|
|
|
|
|
#ifdef DEBUG_STELLARIS_ENET
|
2009-05-13 19:53:17 +02:00
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
do { printf("stellaris_enet: " fmt , ## __VA_ARGS__); } while (0)
|
|
|
|
#define BADF(fmt, ...) \
|
|
|
|
do { fprintf(stderr, "stellaris_enet: error: " fmt , ## __VA_ARGS__); exit(1);} while (0)
|
2007-11-24 04:13:04 +01:00
|
|
|
#else
|
2009-05-13 19:53:17 +02:00
|
|
|
#define DPRINTF(fmt, ...) do {} while(0)
|
|
|
|
#define BADF(fmt, ...) \
|
|
|
|
do { fprintf(stderr, "stellaris_enet: error: " fmt , ## __VA_ARGS__);} while (0)
|
2007-11-24 04:13:04 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define SE_INT_RX 0x01
|
|
|
|
#define SE_INT_TXER 0x02
|
|
|
|
#define SE_INT_TXEMP 0x04
|
|
|
|
#define SE_INT_FOV 0x08
|
|
|
|
#define SE_INT_RXER 0x10
|
|
|
|
#define SE_INT_MD 0x20
|
|
|
|
#define SE_INT_PHY 0x40
|
|
|
|
|
|
|
|
#define SE_RCTL_RXEN 0x01
|
|
|
|
#define SE_RCTL_AMUL 0x02
|
|
|
|
#define SE_RCTL_PRMS 0x04
|
|
|
|
#define SE_RCTL_BADCRC 0x08
|
|
|
|
#define SE_RCTL_RSTFIFO 0x10
|
|
|
|
|
|
|
|
#define SE_TCTL_TXEN 0x01
|
|
|
|
#define SE_TCTL_PADEN 0x02
|
|
|
|
#define SE_TCTL_CRC 0x04
|
|
|
|
#define SE_TCTL_DUPLEX 0x08
|
|
|
|
|
2013-07-27 12:23:22 +02:00
|
|
|
#define TYPE_STELLARIS_ENET "stellaris_enet"
|
|
|
|
#define STELLARIS_ENET(obj) \
|
|
|
|
OBJECT_CHECK(stellaris_enet_state, (obj), TYPE_STELLARIS_ENET)
|
|
|
|
|
2014-05-13 17:09:38 +02:00
|
|
|
typedef struct {
|
|
|
|
uint8_t data[2048];
|
|
|
|
uint32_t len;
|
|
|
|
} StellarisEnetRxFrame;
|
|
|
|
|
2007-11-24 04:13:04 +01:00
|
|
|
typedef struct {
|
2013-07-27 12:23:22 +02:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2007-11-24 04:13:04 +01:00
|
|
|
uint32_t ris;
|
|
|
|
uint32_t im;
|
|
|
|
uint32_t rctl;
|
|
|
|
uint32_t tctl;
|
|
|
|
uint32_t thr;
|
|
|
|
uint32_t mctl;
|
|
|
|
uint32_t mdv;
|
|
|
|
uint32_t mtxd;
|
|
|
|
uint32_t mrxd;
|
|
|
|
uint32_t np;
|
2014-05-13 17:09:38 +02:00
|
|
|
uint32_t tx_fifo_len;
|
2007-11-24 04:13:04 +01:00
|
|
|
uint8_t tx_fifo[2048];
|
|
|
|
/* Real hardware has a 2k fifo, which works out to be at most 31 packets.
|
|
|
|
We implement a full 31 packet fifo. */
|
2014-05-13 17:09:38 +02:00
|
|
|
StellarisEnetRxFrame rx[31];
|
|
|
|
uint32_t rx_fifo_offset;
|
|
|
|
uint32_t next_packet;
|
2009-11-25 19:49:24 +01:00
|
|
|
NICState *nic;
|
2009-10-21 15:25:39 +02:00
|
|
|
NICConf conf;
|
2007-11-24 04:13:04 +01:00
|
|
|
qemu_irq irq;
|
2011-07-18 10:58:50 +02:00
|
|
|
MemoryRegion mmio;
|
2007-11-24 04:13:04 +01:00
|
|
|
} stellaris_enet_state;
|
|
|
|
|
2014-05-13 17:09:38 +02:00
|
|
|
static const VMStateDescription vmstate_rx_frame = {
|
|
|
|
.name = "stellaris_enet/rx_frame",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8_ARRAY(data, StellarisEnetRxFrame, 2048),
|
|
|
|
VMSTATE_UINT32(len, StellarisEnetRxFrame),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int stellaris_enet_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
stellaris_enet_state *s = opaque;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Sanitize inbound state. Note that next_packet is an index but
|
|
|
|
* np is a size; hence their valid upper bounds differ.
|
|
|
|
*/
|
|
|
|
if (s->next_packet >= ARRAY_SIZE(s->rx)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->np > ARRAY_SIZE(s->rx)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(s->rx); i++) {
|
|
|
|
if (s->rx[i].len > ARRAY_SIZE(s->rx[i].data)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->rx_fifo_offset > ARRAY_SIZE(s->rx[0].data) - 4) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->tx_fifo_len > ARRAY_SIZE(s->tx_fifo)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_stellaris_enet = {
|
|
|
|
.name = "stellaris_enet",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
|
|
|
.post_load = stellaris_enet_post_load,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(ris, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(im, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(rctl, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(tctl, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(thr, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(mctl, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(mdv, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(mtxd, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(mrxd, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(np, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(tx_fifo_len, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT8_ARRAY(tx_fifo, stellaris_enet_state, 2048),
|
|
|
|
VMSTATE_STRUCT_ARRAY(rx, stellaris_enet_state, 31, 1,
|
|
|
|
vmstate_rx_frame, StellarisEnetRxFrame),
|
|
|
|
VMSTATE_UINT32(rx_fifo_offset, stellaris_enet_state),
|
|
|
|
VMSTATE_UINT32(next_packet, stellaris_enet_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-11-24 04:13:04 +01:00
|
|
|
static void stellaris_enet_update(stellaris_enet_state *s)
|
|
|
|
{
|
|
|
|
qemu_set_irq(s->irq, (s->ris & s->im) != 0);
|
|
|
|
}
|
|
|
|
|
2014-05-13 17:09:36 +02:00
|
|
|
/* Return the data length of the packet currently being assembled
|
|
|
|
* in the TX fifo.
|
|
|
|
*/
|
|
|
|
static inline int stellaris_txpacket_datalen(stellaris_enet_state *s)
|
|
|
|
{
|
|
|
|
return s->tx_fifo[0] | (s->tx_fifo[1] << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return true if the packet currently in the TX FIFO is complete,
|
|
|
|
* ie the FIFO holds enough bytes for the data length, ethernet header,
|
|
|
|
* payload and optionally CRC.
|
|
|
|
*/
|
|
|
|
static inline bool stellaris_txpacket_complete(stellaris_enet_state *s)
|
|
|
|
{
|
|
|
|
int framelen = stellaris_txpacket_datalen(s);
|
|
|
|
framelen += 16;
|
|
|
|
if (!(s->tctl & SE_TCTL_CRC)) {
|
|
|
|
framelen += 4;
|
|
|
|
}
|
|
|
|
/* Cover the corner case of a 2032 byte payload with auto-CRC disabled:
|
|
|
|
* this requires more bytes than will fit in the FIFO. It's not totally
|
|
|
|
* clear how the h/w handles this, but if using threshold-based TX
|
|
|
|
* it will definitely try to transmit something.
|
|
|
|
*/
|
|
|
|
framelen = MIN(framelen, ARRAY_SIZE(s->tx_fifo));
|
|
|
|
return s->tx_fifo_len >= framelen;
|
|
|
|
}
|
|
|
|
|
2014-05-13 17:09:37 +02:00
|
|
|
/* Return true if the TX FIFO threshold is enabled and the FIFO
|
|
|
|
* has filled enough to reach it.
|
|
|
|
*/
|
|
|
|
static inline bool stellaris_tx_thr_reached(stellaris_enet_state *s)
|
|
|
|
{
|
|
|
|
return (s->thr < 0x3f &&
|
|
|
|
(s->tx_fifo_len >= 4 * (s->thr * 8 + 1)));
|
|
|
|
}
|
|
|
|
|
2014-05-13 17:09:36 +02:00
|
|
|
/* Send the packet currently in the TX FIFO */
|
|
|
|
static void stellaris_enet_send(stellaris_enet_state *s)
|
|
|
|
{
|
|
|
|
int framelen = stellaris_txpacket_datalen(s);
|
|
|
|
|
|
|
|
/* Ethernet header is in the FIFO but not in the datacount.
|
|
|
|
* We don't implement explicit CRC, so just ignore any
|
|
|
|
* CRC value in the FIFO.
|
|
|
|
*/
|
|
|
|
framelen += 14;
|
|
|
|
if ((s->tctl & SE_TCTL_PADEN) && framelen < 60) {
|
|
|
|
memset(&s->tx_fifo[framelen + 2], 0, 60 - framelen);
|
|
|
|
framelen = 60;
|
|
|
|
}
|
|
|
|
/* This MIN will have no effect unless the FIFO data is corrupt
|
|
|
|
* (eg bad data from an incoming migration); otherwise the check
|
|
|
|
* on the datalen at the start of writing the data into the FIFO
|
|
|
|
* will have caught this. Silently write a corrupt half-packet,
|
|
|
|
* which is what the hardware does in FIFO underrun situations.
|
|
|
|
*/
|
|
|
|
framelen = MIN(framelen, ARRAY_SIZE(s->tx_fifo) - 2);
|
|
|
|
qemu_send_packet(qemu_get_queue(s->nic), s->tx_fifo + 2, framelen);
|
|
|
|
s->tx_fifo_len = 0;
|
|
|
|
s->ris |= SE_INT_TXEMP;
|
|
|
|
stellaris_enet_update(s);
|
|
|
|
DPRINTF("Done TX\n");
|
|
|
|
}
|
|
|
|
|
2007-11-24 04:13:04 +01:00
|
|
|
/* TODO: Implement MAC address filtering. */
|
2012-07-24 17:35:13 +02:00
|
|
|
static ssize_t stellaris_enet_receive(NetClientState *nc, const uint8_t *buf, size_t size)
|
2007-11-24 04:13:04 +01:00
|
|
|
{
|
2013-01-30 12:12:23 +01:00
|
|
|
stellaris_enet_state *s = qemu_get_nic_opaque(nc);
|
2007-11-24 04:13:04 +01:00
|
|
|
int n;
|
|
|
|
uint8_t *p;
|
|
|
|
uint32_t crc;
|
|
|
|
|
|
|
|
if ((s->rctl & SE_RCTL_RXEN) == 0)
|
2009-05-18 14:40:55 +02:00
|
|
|
return -1;
|
2007-11-24 04:13:04 +01:00
|
|
|
if (s->np >= 31) {
|
2015-07-15 12:19:11 +02:00
|
|
|
return 0;
|
2007-11-24 04:13:04 +01:00
|
|
|
}
|
|
|
|
|
2014-05-13 17:09:37 +02:00
|
|
|
DPRINTF("Received packet len=%zu\n", size);
|
2007-11-24 04:13:04 +01:00
|
|
|
n = s->next_packet + s->np;
|
|
|
|
if (n >= 31)
|
|
|
|
n -= 31;
|
|
|
|
|
2016-04-08 08:03:48 +02:00
|
|
|
if (size >= sizeof(s->rx[n].data) - 6) {
|
|
|
|
/* If the packet won't fit into the
|
|
|
|
* emulated 2K RAM, this is reported
|
|
|
|
* as a FIFO overrun error.
|
|
|
|
*/
|
|
|
|
s->ris |= SE_INT_FOV;
|
|
|
|
stellaris_enet_update(s);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->np++;
|
2007-11-24 04:13:04 +01:00
|
|
|
s->rx[n].len = size + 6;
|
|
|
|
p = s->rx[n].data;
|
|
|
|
*(p++) = (size + 6);
|
|
|
|
*(p++) = (size + 6) >> 8;
|
|
|
|
memcpy (p, buf, size);
|
|
|
|
p += size;
|
|
|
|
crc = crc32(~0, buf, size);
|
|
|
|
*(p++) = crc;
|
|
|
|
*(p++) = crc >> 8;
|
|
|
|
*(p++) = crc >> 16;
|
|
|
|
*(p++) = crc >> 24;
|
|
|
|
/* Clear the remaining bytes in the last word. */
|
|
|
|
if ((size & 3) != 2) {
|
|
|
|
memset(p, 0, (6 - size) & 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->ris |= SE_INT_RX;
|
|
|
|
stellaris_enet_update(s);
|
2009-05-18 14:40:55 +02:00
|
|
|
|
|
|
|
return size;
|
2007-11-24 04:13:04 +01:00
|
|
|
}
|
|
|
|
|
2015-07-15 12:19:11 +02:00
|
|
|
static int stellaris_enet_can_receive(stellaris_enet_state *s)
|
2007-11-24 04:13:04 +01:00
|
|
|
{
|
|
|
|
return (s->np < 31);
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t stellaris_enet_read(void *opaque, hwaddr offset,
|
2011-07-18 10:58:50 +02:00
|
|
|
unsigned size)
|
2007-11-24 04:13:04 +01:00
|
|
|
{
|
2009-06-11 14:22:27 +02:00
|
|
|
stellaris_enet_state *s = (stellaris_enet_state *)opaque;
|
2007-11-24 04:13:04 +01:00
|
|
|
uint32_t val;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case 0x00: /* RIS */
|
|
|
|
DPRINTF("IRQ status %02x\n", s->ris);
|
|
|
|
return s->ris;
|
|
|
|
case 0x04: /* IM */
|
|
|
|
return s->im;
|
|
|
|
case 0x08: /* RCTL */
|
|
|
|
return s->rctl;
|
|
|
|
case 0x0c: /* TCTL */
|
|
|
|
return s->tctl;
|
|
|
|
case 0x10: /* DATA */
|
2014-05-13 17:09:37 +02:00
|
|
|
{
|
|
|
|
uint8_t *rx_fifo;
|
|
|
|
|
|
|
|
if (s->np == 0) {
|
|
|
|
BADF("RX underflow\n");
|
|
|
|
return 0;
|
2007-11-24 04:13:04 +01:00
|
|
|
}
|
2014-05-13 17:09:37 +02:00
|
|
|
|
|
|
|
rx_fifo = s->rx[s->next_packet].data + s->rx_fifo_offset;
|
|
|
|
|
|
|
|
val = rx_fifo[0] | (rx_fifo[1] << 8) | (rx_fifo[2] << 16)
|
|
|
|
| (rx_fifo[3] << 24);
|
|
|
|
s->rx_fifo_offset += 4;
|
|
|
|
if (s->rx_fifo_offset >= s->rx[s->next_packet].len) {
|
|
|
|
s->rx_fifo_offset = 0;
|
2007-11-24 04:13:04 +01:00
|
|
|
s->next_packet++;
|
|
|
|
if (s->next_packet >= 31)
|
|
|
|
s->next_packet = 0;
|
|
|
|
s->np--;
|
|
|
|
DPRINTF("RX done np=%d\n", s->np);
|
2015-07-15 12:19:11 +02:00
|
|
|
if (!s->np && stellaris_enet_can_receive(s)) {
|
|
|
|
qemu_flush_queued_packets(qemu_get_queue(s->nic));
|
|
|
|
}
|
2007-11-24 04:13:04 +01:00
|
|
|
}
|
|
|
|
return val;
|
2014-05-13 17:09:37 +02:00
|
|
|
}
|
2007-11-24 04:13:04 +01:00
|
|
|
case 0x14: /* IA0 */
|
2009-10-21 15:25:39 +02:00
|
|
|
return s->conf.macaddr.a[0] | (s->conf.macaddr.a[1] << 8)
|
2014-02-26 18:19:58 +01:00
|
|
|
| (s->conf.macaddr.a[2] << 16)
|
|
|
|
| ((uint32_t)s->conf.macaddr.a[3] << 24);
|
2007-11-24 04:13:04 +01:00
|
|
|
case 0x18: /* IA1 */
|
2009-10-21 15:25:39 +02:00
|
|
|
return s->conf.macaddr.a[4] | (s->conf.macaddr.a[5] << 8);
|
2007-11-24 04:13:04 +01:00
|
|
|
case 0x1c: /* THR */
|
|
|
|
return s->thr;
|
|
|
|
case 0x20: /* MCTL */
|
|
|
|
return s->mctl;
|
|
|
|
case 0x24: /* MDV */
|
|
|
|
return s->mdv;
|
|
|
|
case 0x28: /* MADD */
|
|
|
|
return 0;
|
|
|
|
case 0x2c: /* MTXD */
|
|
|
|
return s->mtxd;
|
|
|
|
case 0x30: /* MRXD */
|
|
|
|
return s->mrxd;
|
|
|
|
case 0x34: /* NP */
|
|
|
|
return s->np;
|
|
|
|
case 0x38: /* TR */
|
|
|
|
return 0;
|
2018-06-26 18:50:41 +02:00
|
|
|
case 0x3c: /* Undocumented: Timestamp? */
|
2007-11-24 04:13:04 +01:00
|
|
|
return 0;
|
|
|
|
default:
|
2018-06-26 18:50:41 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "stellaris_enet_rd%d: Illegal register"
|
|
|
|
" 0x02%" HWADDR_PRIx "\n",
|
|
|
|
size * 8, offset);
|
2007-11-24 04:13:04 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void stellaris_enet_write(void *opaque, hwaddr offset,
|
2011-07-18 10:58:50 +02:00
|
|
|
uint64_t value, unsigned size)
|
2007-11-24 04:13:04 +01:00
|
|
|
{
|
|
|
|
stellaris_enet_state *s = (stellaris_enet_state *)opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case 0x00: /* IACK */
|
|
|
|
s->ris &= ~value;
|
2014-05-13 17:09:37 +02:00
|
|
|
DPRINTF("IRQ ack %02" PRIx64 "/%02x\n", value, s->ris);
|
2007-11-24 04:13:04 +01:00
|
|
|
stellaris_enet_update(s);
|
|
|
|
/* Clearing TXER also resets the TX fifo. */
|
2014-05-13 17:09:36 +02:00
|
|
|
if (value & SE_INT_TXER) {
|
|
|
|
s->tx_fifo_len = 0;
|
|
|
|
}
|
2007-11-24 04:13:04 +01:00
|
|
|
break;
|
|
|
|
case 0x04: /* IM */
|
2014-05-13 17:09:37 +02:00
|
|
|
DPRINTF("IRQ mask %02" PRIx64 "/%02x\n", value, s->ris);
|
2007-11-24 04:13:04 +01:00
|
|
|
s->im = value;
|
|
|
|
stellaris_enet_update(s);
|
|
|
|
break;
|
|
|
|
case 0x08: /* RCTL */
|
|
|
|
s->rctl = value;
|
|
|
|
if (value & SE_RCTL_RSTFIFO) {
|
|
|
|
s->np = 0;
|
2014-05-13 17:09:37 +02:00
|
|
|
s->rx_fifo_offset = 0;
|
2007-11-24 04:13:04 +01:00
|
|
|
stellaris_enet_update(s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x0c: /* TCTL */
|
|
|
|
s->tctl = value;
|
|
|
|
break;
|
|
|
|
case 0x10: /* DATA */
|
2014-05-13 17:09:36 +02:00
|
|
|
if (s->tx_fifo_len == 0) {
|
|
|
|
/* The first word is special, it contains the data length */
|
|
|
|
int framelen = value & 0xffff;
|
|
|
|
if (framelen > 2032) {
|
|
|
|
DPRINTF("TX frame too long (%d)\n", framelen);
|
2007-11-24 04:13:04 +01:00
|
|
|
s->ris |= SE_INT_TXER;
|
|
|
|
stellaris_enet_update(s);
|
2014-05-13 17:09:36 +02:00
|
|
|
break;
|
2007-11-24 04:13:04 +01:00
|
|
|
}
|
|
|
|
}
|
2014-05-13 17:09:36 +02:00
|
|
|
|
|
|
|
if (s->tx_fifo_len + 4 <= ARRAY_SIZE(s->tx_fifo)) {
|
|
|
|
s->tx_fifo[s->tx_fifo_len++] = value;
|
|
|
|
s->tx_fifo[s->tx_fifo_len++] = value >> 8;
|
|
|
|
s->tx_fifo[s->tx_fifo_len++] = value >> 16;
|
|
|
|
s->tx_fifo[s->tx_fifo_len++] = value >> 24;
|
|
|
|
}
|
|
|
|
|
2014-05-13 17:09:37 +02:00
|
|
|
if (stellaris_tx_thr_reached(s) && stellaris_txpacket_complete(s)) {
|
2014-05-13 17:09:36 +02:00
|
|
|
stellaris_enet_send(s);
|
|
|
|
}
|
2007-11-24 04:13:04 +01:00
|
|
|
break;
|
|
|
|
case 0x14: /* IA0 */
|
2009-10-21 15:25:39 +02:00
|
|
|
s->conf.macaddr.a[0] = value;
|
|
|
|
s->conf.macaddr.a[1] = value >> 8;
|
|
|
|
s->conf.macaddr.a[2] = value >> 16;
|
|
|
|
s->conf.macaddr.a[3] = value >> 24;
|
2007-11-24 04:13:04 +01:00
|
|
|
break;
|
|
|
|
case 0x18: /* IA1 */
|
2009-10-21 15:25:39 +02:00
|
|
|
s->conf.macaddr.a[4] = value;
|
|
|
|
s->conf.macaddr.a[5] = value >> 8;
|
2007-11-24 04:13:04 +01:00
|
|
|
break;
|
|
|
|
case 0x1c: /* THR */
|
|
|
|
s->thr = value;
|
|
|
|
break;
|
|
|
|
case 0x20: /* MCTL */
|
2017-01-27 16:20:25 +01:00
|
|
|
/* TODO: MII registers aren't modelled.
|
|
|
|
* Clear START, indicating that the operation completes immediately.
|
|
|
|
*/
|
|
|
|
s->mctl = value & ~1;
|
2007-11-24 04:13:04 +01:00
|
|
|
break;
|
|
|
|
case 0x24: /* MDV */
|
|
|
|
s->mdv = value;
|
|
|
|
break;
|
|
|
|
case 0x28: /* MADD */
|
|
|
|
/* ignored. */
|
|
|
|
break;
|
|
|
|
case 0x2c: /* MTXD */
|
|
|
|
s->mtxd = value & 0xff;
|
|
|
|
break;
|
2014-05-13 17:09:37 +02:00
|
|
|
case 0x38: /* TR */
|
|
|
|
if (value & 1) {
|
|
|
|
stellaris_enet_send(s);
|
|
|
|
}
|
|
|
|
break;
|
2007-11-24 04:13:04 +01:00
|
|
|
case 0x30: /* MRXD */
|
|
|
|
case 0x34: /* NP */
|
|
|
|
/* Ignored. */
|
|
|
|
case 0x3c: /* Undocuented: Timestamp? */
|
|
|
|
/* Ignored. */
|
|
|
|
break;
|
|
|
|
default:
|
2018-06-26 18:50:41 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "stellaris_enet_wr%d: Illegal register "
|
|
|
|
"0x02%" HWADDR_PRIx " = 0x%" PRIx64 "\n",
|
|
|
|
size * 8, offset, value);
|
2007-11-24 04:13:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-18 10:58:50 +02:00
|
|
|
static const MemoryRegionOps stellaris_enet_ops = {
|
|
|
|
.read = stellaris_enet_read,
|
|
|
|
.write = stellaris_enet_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-11-24 04:13:04 +01:00
|
|
|
};
|
|
|
|
|
2018-10-01 08:38:02 +02:00
|
|
|
static void stellaris_enet_reset(DeviceState *dev)
|
2007-11-24 04:13:04 +01:00
|
|
|
{
|
2018-10-01 08:38:02 +02:00
|
|
|
stellaris_enet_state *s = STELLARIS_ENET(dev);
|
|
|
|
|
2007-11-24 04:13:04 +01:00
|
|
|
s->mdv = 0x80;
|
|
|
|
s->rctl = SE_RCTL_BADCRC;
|
|
|
|
s->im = SE_INT_PHY | SE_INT_MD | SE_INT_RXER | SE_INT_FOV | SE_INT_TXEMP
|
|
|
|
| SE_INT_TXER | SE_INT_RX;
|
|
|
|
s->thr = 0x3f;
|
2014-05-13 17:09:36 +02:00
|
|
|
s->tx_fifo_len = 0;
|
2007-11-24 04:13:04 +01:00
|
|
|
}
|
|
|
|
|
2009-11-25 19:49:24 +01:00
|
|
|
static NetClientInfo net_stellaris_enet_info = {
|
qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union. The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.
While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place. Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two. Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.
Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-14 05:50:23 +02:00
|
|
|
.type = NET_CLIENT_DRIVER_NIC,
|
2009-11-25 19:49:24 +01:00
|
|
|
.size = sizeof(NICState),
|
|
|
|
.receive = stellaris_enet_receive,
|
|
|
|
};
|
|
|
|
|
2018-10-01 08:38:01 +02:00
|
|
|
static void stellaris_enet_realize(DeviceState *dev, Error **errp)
|
2007-11-24 04:13:04 +01:00
|
|
|
{
|
2018-10-01 08:38:01 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
2013-07-27 12:23:22 +02:00
|
|
|
stellaris_enet_state *s = STELLARIS_ENET(dev);
|
2007-11-24 04:13:04 +01:00
|
|
|
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&s->mmio, OBJECT(s), &stellaris_enet_ops, s,
|
|
|
|
"stellaris_enet", 0x1000);
|
2013-07-27 12:23:22 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->mmio);
|
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
2009-10-21 15:25:39 +02:00
|
|
|
qemu_macaddr_default_if_unset(&s->conf.macaddr);
|
2009-05-14 23:35:07 +02:00
|
|
|
|
2009-11-25 19:49:24 +01:00
|
|
|
s->nic = qemu_new_nic(&net_stellaris_enet_info, &s->conf,
|
2013-07-27 12:23:22 +02:00
|
|
|
object_get_typename(OBJECT(dev)), dev->id, s);
|
2013-01-30 12:12:22 +01:00
|
|
|
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
|
2007-11-24 04:13:04 +01:00
|
|
|
}
|
2009-05-14 23:35:07 +02:00
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static Property stellaris_enet_properties[] = {
|
|
|
|
DEFINE_NIC_PROPERTIES(stellaris_enet_state, conf),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void stellaris_enet_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2018-10-01 08:38:01 +02:00
|
|
|
dc->realize = stellaris_enet_realize;
|
2018-10-01 08:38:02 +02:00
|
|
|
dc->reset = stellaris_enet_reset;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, stellaris_enet_properties);
|
2014-05-13 17:09:38 +02:00
|
|
|
dc->vmsd = &vmstate_stellaris_enet;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo stellaris_enet_info = {
|
2013-07-27 12:23:22 +02:00
|
|
|
.name = TYPE_STELLARIS_ENET,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(stellaris_enet_state),
|
|
|
|
.class_init = stellaris_enet_class_init,
|
2009-10-21 15:25:39 +02:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void stellaris_enet_register_types(void)
|
2009-05-14 23:35:07 +02:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&stellaris_enet_info);
|
2009-05-14 23:35:07 +02:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(stellaris_enet_register_types)
|