2 * QEMU model of Xilinx AXI-Ethernet.
4 * Copyright (c) 2011 Edgar E. Iglesias.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
27 #include "hw/sysbus.h"
28 #include "qapi/error.h"
30 #include "qemu/module.h"
32 #include "net/checksum.h"
36 #include "hw/qdev-properties.h"
37 #include "hw/stream.h"
38 #include "qom/object.h"
42 #define TYPE_XILINX_AXI_ENET "xlnx.axi-ethernet"
43 #define TYPE_XILINX_AXI_ENET_DATA_STREAM "xilinx-axienet-data-stream"
44 #define TYPE_XILINX_AXI_ENET_CONTROL_STREAM "xilinx-axienet-control-stream"
46 typedef struct XilinxAXIEnet XilinxAXIEnet
;
47 #define XILINX_AXI_ENET(obj) \
48 OBJECT_CHECK(XilinxAXIEnet, (obj), TYPE_XILINX_AXI_ENET)
50 typedef struct XilinxAXIEnetStreamSlave XilinxAXIEnetStreamSlave
;
51 #define XILINX_AXI_ENET_DATA_STREAM(obj) \
52 OBJECT_CHECK(XilinxAXIEnetStreamSlave, (obj),\
53 TYPE_XILINX_AXI_ENET_DATA_STREAM)
55 #define XILINX_AXI_ENET_CONTROL_STREAM(obj) \
56 OBJECT_CHECK(XilinxAXIEnetStreamSlave, (obj),\
57 TYPE_XILINX_AXI_ENET_CONTROL_STREAM)
59 /* Advertisement control register. */
60 #define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
61 #define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
62 #define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
64 #define CONTROL_PAYLOAD_WORDS 5
65 #define CONTROL_PAYLOAD_SIZE (CONTROL_PAYLOAD_WORDS * (sizeof(uint32_t)))
72 unsigned int (*read
)(struct PHY
*phy
, unsigned int req
);
73 void (*write
)(struct PHY
*phy
, unsigned int req
,
77 static unsigned int tdk_read(struct PHY
*phy
, unsigned int req
)
90 /* Speeds and modes. */
91 r
|= (1 << 13) | (1 << 14);
92 r
|= (1 << 11) | (1 << 12);
93 r
|= (1 << 5); /* Autoneg complete. */
94 r
|= (1 << 3); /* Autoneg able. */
95 r
|= (1 << 2); /* link. */
96 r
|= (1 << 1); /* link. */
99 /* Link partner ability.
100 We are kind; always agree with whatever best mode
101 the guest advertises. */
102 r
= 1 << 14; /* Success. */
103 /* Copy advertised modes. */
104 r
|= phy
->regs
[4] & (15 << 5);
105 /* Autoneg support. */
109 /* Marvell PHY on many xilinx boards. */
110 r
= 0x8000; /* 1000Mb */
114 /* Diagnostics reg. */
122 /* Are we advertising 100 half or 100 duplex ? */
123 speed_100
= !!(phy
->regs
[4] & ADVERTISE_100HALF
);
124 speed_100
|= !!(phy
->regs
[4] & ADVERTISE_100FULL
);
126 /* Are we advertising 10 duplex or 100 duplex ? */
127 duplex
= !!(phy
->regs
[4] & ADVERTISE_100FULL
);
128 duplex
|= !!(phy
->regs
[4] & ADVERTISE_10FULL
);
129 r
= (speed_100
<< 10) | (duplex
<< 11);
134 r
= phy
->regs
[regnum
];
137 DPHY(qemu_log("\n%s %x = reg[%d]\n", __func__
, r
, regnum
));
142 tdk_write(struct PHY
*phy
, unsigned int req
, unsigned int data
)
147 DPHY(qemu_log("%s reg[%d] = %x\n", __func__
, regnum
, data
));
150 phy
->regs
[regnum
] = data
;
154 /* Unconditionally clear regs[BMCR][BMCR_RESET] and auto-neg */
155 phy
->regs
[0] &= ~0x8200;
159 tdk_init(struct PHY
*phy
)
161 phy
->regs
[0] = 0x3100;
163 phy
->regs
[2] = 0x0300;
164 phy
->regs
[3] = 0xe400;
165 /* Autonegotiation advertisement reg. */
166 phy
->regs
[4] = 0x01E1;
169 phy
->read
= tdk_read
;
170 phy
->write
= tdk_write
;
174 struct PHY
*devs
[32];
178 mdio_attach(struct MDIOBus
*bus
, struct PHY
*phy
, unsigned int addr
)
180 bus
->devs
[addr
& 0x1f] = phy
;
183 #ifdef USE_THIS_DEAD_CODE
185 mdio_detach(struct MDIOBus
*bus
, struct PHY
*phy
, unsigned int addr
)
187 bus
->devs
[addr
& 0x1f] = NULL
;
191 static uint16_t mdio_read_req(struct MDIOBus
*bus
, unsigned int addr
,
197 phy
= bus
->devs
[addr
];
198 if (phy
&& phy
->read
) {
199 data
= phy
->read(phy
, reg
);
203 DPHY(qemu_log("%s addr=%d reg=%d data=%x\n", __func__
, addr
, reg
, data
));
207 static void mdio_write_req(struct MDIOBus
*bus
, unsigned int addr
,
208 unsigned int reg
, uint16_t data
)
212 DPHY(qemu_log("%s addr=%d reg=%d data=%x\n", __func__
, addr
, reg
, data
));
213 phy
= bus
->devs
[addr
];
214 if (phy
&& phy
->write
) {
215 phy
->write(phy
, reg
, data
);
221 #define R_RAF (0x000 / 4)
223 RAF_MCAST_REJ
= (1 << 1),
224 RAF_BCAST_REJ
= (1 << 2),
225 RAF_EMCF_EN
= (1 << 12),
226 RAF_NEWFUNC_EN
= (1 << 11)
229 #define R_IS (0x00C / 4)
231 IS_HARD_ACCESS_COMPLETE
= 1,
232 IS_AUTONEG
= (1 << 1),
233 IS_RX_COMPLETE
= (1 << 2),
234 IS_RX_REJECT
= (1 << 3),
235 IS_TX_COMPLETE
= (1 << 5),
236 IS_RX_DCM_LOCK
= (1 << 6),
237 IS_MGM_RDY
= (1 << 7),
238 IS_PHY_RST_DONE
= (1 << 8),
241 #define R_IP (0x010 / 4)
242 #define R_IE (0x014 / 4)
243 #define R_UAWL (0x020 / 4)
244 #define R_UAWU (0x024 / 4)
245 #define R_PPST (0x030 / 4)
247 PPST_LINKSTATUS
= (1 << 0),
248 PPST_PHY_LINKSTATUS
= (1 << 7),
251 #define R_STATS_RX_BYTESL (0x200 / 4)
252 #define R_STATS_RX_BYTESH (0x204 / 4)
253 #define R_STATS_TX_BYTESL (0x208 / 4)
254 #define R_STATS_TX_BYTESH (0x20C / 4)
255 #define R_STATS_RXL (0x290 / 4)
256 #define R_STATS_RXH (0x294 / 4)
257 #define R_STATS_RX_BCASTL (0x2a0 / 4)
258 #define R_STATS_RX_BCASTH (0x2a4 / 4)
259 #define R_STATS_RX_MCASTL (0x2a8 / 4)
260 #define R_STATS_RX_MCASTH (0x2ac / 4)
262 #define R_RCW0 (0x400 / 4)
263 #define R_RCW1 (0x404 / 4)
265 RCW1_VLAN
= (1 << 27),
267 RCW1_FCS
= (1 << 29),
268 RCW1_JUM
= (1 << 30),
269 RCW1_RST
= (1 << 31),
272 #define R_TC (0x408 / 4)
281 #define R_EMMC (0x410 / 4)
283 EMMC_LINKSPEED_10MB
= (0 << 30),
284 EMMC_LINKSPEED_100MB
= (1 << 30),
285 EMMC_LINKSPEED_1000MB
= (2 << 30),
288 #define R_PHYC (0x414 / 4)
290 #define R_MC (0x500 / 4)
291 #define MC_EN (1 << 6)
293 #define R_MCR (0x504 / 4)
294 #define R_MWD (0x508 / 4)
295 #define R_MRD (0x50c / 4)
296 #define R_MIS (0x600 / 4)
297 #define R_MIP (0x620 / 4)
298 #define R_MIE (0x640 / 4)
299 #define R_MIC (0x640 / 4)
301 #define R_UAW0 (0x700 / 4)
302 #define R_UAW1 (0x704 / 4)
303 #define R_FMI (0x708 / 4)
304 #define R_AF0 (0x710 / 4)
305 #define R_AF1 (0x714 / 4)
306 #define R_MAX (0x34 / 4)
308 /* Indirect registers. */
310 struct MDIOBus mdio_bus
;
317 struct XilinxAXIEnetStreamSlave
{
320 struct XilinxAXIEnet
*enet
;
323 struct XilinxAXIEnet
{
327 StreamSlave
*tx_data_dev
;
328 StreamSlave
*tx_control_dev
;
329 XilinxAXIEnetStreamSlave rx_data_dev
;
330 XilinxAXIEnetStreamSlave rx_control_dev
;
361 /* Receive configuration words. */
363 /* Transmit config. */
368 /* Unicast Address Word. */
370 /* Unicast address filter used with extended mcast. */
374 uint32_t regs
[R_MAX
];
376 /* Multicast filter addrs. */
377 uint32_t maddr
[4][2];
378 /* 32K x 1 lookup filter. */
379 uint32_t ext_mtable
[1024];
381 uint32_t hdr
[CONTROL_PAYLOAD_WORDS
];
390 uint8_t rxapp
[CONTROL_PAYLOAD_SIZE
];
393 /* Whether axienet_eth_rx_notify should flush incoming queue. */
397 static void axienet_rx_reset(XilinxAXIEnet
*s
)
399 s
->rcw
[1] = RCW1_JUM
| RCW1_FCS
| RCW1_RX
| RCW1_VLAN
;
402 static void axienet_tx_reset(XilinxAXIEnet
*s
)
404 s
->tc
= TC_JUM
| TC_TX
| TC_VLAN
;
408 static inline int axienet_rx_resetting(XilinxAXIEnet
*s
)
410 return s
->rcw
[1] & RCW1_RST
;
413 static inline int axienet_rx_enabled(XilinxAXIEnet
*s
)
415 return s
->rcw
[1] & RCW1_RX
;
418 static inline int axienet_extmcf_enabled(XilinxAXIEnet
*s
)
420 return !!(s
->regs
[R_RAF
] & RAF_EMCF_EN
);
423 static inline int axienet_newfunc_enabled(XilinxAXIEnet
*s
)
425 return !!(s
->regs
[R_RAF
] & RAF_NEWFUNC_EN
);
428 static void xilinx_axienet_reset(DeviceState
*d
)
430 XilinxAXIEnet
*s
= XILINX_AXI_ENET(d
);
435 s
->regs
[R_PPST
] = PPST_LINKSTATUS
| PPST_PHY_LINKSTATUS
;
436 s
->regs
[R_IS
] = IS_AUTONEG
| IS_RX_DCM_LOCK
| IS_MGM_RDY
| IS_PHY_RST_DONE
;
438 s
->emmc
= EMMC_LINKSPEED_100MB
;
441 static void enet_update_irq(XilinxAXIEnet
*s
)
443 s
->regs
[R_IP
] = s
->regs
[R_IS
] & s
->regs
[R_IE
];
444 qemu_set_irq(s
->irq
, !!s
->regs
[R_IP
]);
447 static uint64_t enet_read(void *opaque
, hwaddr addr
, unsigned size
)
449 XilinxAXIEnet
*s
= opaque
;
456 r
= s
->rcw
[addr
& 1];
472 r
= s
->mii
.regs
[addr
& 3] | (1 << 7); /* Always ready. */
475 case R_STATS_RX_BYTESL
:
476 case R_STATS_RX_BYTESH
:
477 r
= s
->stats
.rx_bytes
>> (32 * (addr
& 1));
480 case R_STATS_TX_BYTESL
:
481 case R_STATS_TX_BYTESH
:
482 r
= s
->stats
.tx_bytes
>> (32 * (addr
& 1));
487 r
= s
->stats
.rx
>> (32 * (addr
& 1));
489 case R_STATS_RX_BCASTL
:
490 case R_STATS_RX_BCASTH
:
491 r
= s
->stats
.rx_bcast
>> (32 * (addr
& 1));
493 case R_STATS_RX_MCASTL
:
494 case R_STATS_RX_MCASTH
:
495 r
= s
->stats
.rx_mcast
>> (32 * (addr
& 1));
501 r
= s
->mii
.regs
[addr
& 3];
506 r
= s
->uaw
[addr
& 1];
511 r
= s
->ext_uaw
[addr
& 1];
520 r
= s
->maddr
[s
->fmi
& 3][addr
& 1];
523 case 0x8000 ... 0x83ff:
524 r
= s
->ext_mtable
[addr
- 0x8000];
528 if (addr
< ARRAY_SIZE(s
->regs
)) {
531 DENET(qemu_log("%s addr=" TARGET_FMT_plx
" v=%x\n",
532 __func__
, addr
* 4, r
));
538 static void enet_write(void *opaque
, hwaddr addr
,
539 uint64_t value
, unsigned size
)
541 XilinxAXIEnet
*s
= opaque
;
542 struct TEMAC
*t
= &s
->TEMAC
;
548 s
->rcw
[addr
& 1] = value
;
549 if ((addr
& 1) && value
& RCW1_RST
) {
552 qemu_flush_queued_packets(qemu_get_queue(s
->nic
));
558 if (value
& TC_RST
) {
572 value
&= ((1 << 7) - 1);
574 /* Enable the MII. */
576 unsigned int miiclkdiv
= value
& ((1 << 6) - 1);
578 qemu_log("AXIENET: MDIO enabled but MDIOCLK is zero!\n");
585 unsigned int phyaddr
= (value
>> 24) & 0x1f;
586 unsigned int regaddr
= (value
>> 16) & 0x1f;
587 unsigned int op
= (value
>> 14) & 3;
588 unsigned int initiate
= (value
>> 11) & 1;
592 mdio_write_req(&t
->mdio_bus
, phyaddr
, regaddr
, s
->mii
.mwd
);
593 } else if (op
== 2) {
594 s
->mii
.mrd
= mdio_read_req(&t
->mdio_bus
, phyaddr
, regaddr
);
596 qemu_log("AXIENET: invalid MDIOBus OP=%d\n", op
);
605 s
->mii
.regs
[addr
& 3] = value
;
611 s
->uaw
[addr
& 1] = value
;
616 s
->ext_uaw
[addr
& 1] = value
;
625 s
->maddr
[s
->fmi
& 3][addr
& 1] = value
;
629 s
->regs
[addr
] &= ~value
;
632 case 0x8000 ... 0x83ff:
633 s
->ext_mtable
[addr
- 0x8000] = value
;
637 DENET(qemu_log("%s addr=" TARGET_FMT_plx
" v=%x\n",
638 __func__
, addr
* 4, (unsigned)value
));
639 if (addr
< ARRAY_SIZE(s
->regs
)) {
640 s
->regs
[addr
] = value
;
647 static const MemoryRegionOps enet_ops
= {
650 .endianness
= DEVICE_LITTLE_ENDIAN
,
653 static int eth_can_rx(XilinxAXIEnet
*s
)
656 return !s
->rxsize
&& !axienet_rx_resetting(s
) && axienet_rx_enabled(s
);
659 static int enet_match_addr(const uint8_t *buf
, uint32_t f0
, uint32_t f1
)
663 if (memcmp(buf
, &f0
, 4)) {
667 if (buf
[4] != (f1
& 0xff) || buf
[5] != ((f1
>> 8) & 0xff)) {
674 static void axienet_eth_rx_notify(void *opaque
)
676 XilinxAXIEnet
*s
= XILINX_AXI_ENET(opaque
);
678 while (s
->rxappsize
&& stream_can_push(s
->tx_control_dev
,
679 axienet_eth_rx_notify
, s
)) {
680 size_t ret
= stream_push(s
->tx_control_dev
,
681 (void *)s
->rxapp
+ CONTROL_PAYLOAD_SIZE
682 - s
->rxappsize
, s
->rxappsize
, true);
686 while (s
->rxsize
&& stream_can_push(s
->tx_data_dev
,
687 axienet_eth_rx_notify
, s
)) {
688 size_t ret
= stream_push(s
->tx_data_dev
, (void *)s
->rxmem
+ s
->rxpos
,
693 s
->regs
[R_IS
] |= IS_RX_COMPLETE
;
695 s
->need_flush
= false;
696 qemu_flush_queued_packets(qemu_get_queue(s
->nic
));
703 static ssize_t
eth_rx(NetClientState
*nc
, const uint8_t *buf
, size_t size
)
705 XilinxAXIEnet
*s
= qemu_get_nic_opaque(nc
);
706 static const unsigned char sa_bcast
[6] = {0xff, 0xff, 0xff,
708 static const unsigned char sa_ipmcast
[3] = {0x01, 0x00, 0x52};
709 uint32_t app
[CONTROL_PAYLOAD_WORDS
] = {0};
710 int promisc
= s
->fmi
& (1 << 31);
711 int unicast
, broadcast
, multicast
, ip_multicast
= 0;
716 DENET(qemu_log("%s: %zd bytes\n", __func__
, size
));
718 if (!eth_can_rx(s
)) {
719 s
->need_flush
= true;
723 unicast
= ~buf
[0] & 0x1;
724 broadcast
= memcmp(buf
, sa_bcast
, 6) == 0;
725 multicast
= !unicast
&& !broadcast
;
726 if (multicast
&& (memcmp(sa_ipmcast
, buf
, sizeof sa_ipmcast
) == 0)) {
730 /* Jumbo or vlan sizes ? */
731 if (!(s
->rcw
[1] & RCW1_JUM
)) {
732 if (size
> 1518 && size
<= 1522 && !(s
->rcw
[1] & RCW1_VLAN
)) {
737 /* Basic Address filters. If you want to use the extended filters
738 you'll generally have to place the ethernet mac into promiscuous mode
739 to avoid the basic filtering from dropping most frames. */
742 if (!enet_match_addr(buf
, s
->uaw
[0], s
->uaw
[1])) {
748 if (s
->regs
[R_RAF
] & RAF_BCAST_REJ
) {
755 if (s
->regs
[R_RAF
] & RAF_MCAST_REJ
) {
759 for (i
= 0; i
< 4; i
++) {
760 if (enet_match_addr(buf
, s
->maddr
[i
][0], s
->maddr
[i
][1])) {
773 /* Extended mcast filtering enabled? */
774 if (axienet_newfunc_enabled(s
) && axienet_extmcf_enabled(s
)) {
776 if (!enet_match_addr(buf
, s
->ext_uaw
[0], s
->ext_uaw
[1])) {
782 if (s
->regs
[R_RAF
] & RAF_BCAST_REJ
) {
789 if (!memcmp(buf
, sa_ipmcast
, 3)) {
793 idx
= (buf
[4] & 0x7f) << 8;
796 bit
= 1 << (idx
& 0x1f);
799 if (!(s
->ext_mtable
[idx
] & bit
)) {
807 s
->regs
[R_IS
] |= IS_RX_REJECT
;
812 if (size
> (s
->c_rxmem
- 4)) {
813 size
= s
->c_rxmem
- 4;
816 memcpy(s
->rxmem
, buf
, size
);
817 memset(s
->rxmem
+ size
, 0, 4); /* Clear the FCS. */
819 if (s
->rcw
[1] & RCW1_FCS
) {
820 size
+= 4; /* fcs is inband. */
824 csum32
= net_checksum_add(size
- 14, (uint8_t *)s
->rxmem
+ 14);
826 csum32
= (csum32
& 0xffff) + (csum32
>> 16);
827 /* And twice to get rid of possible carries. */
828 csum16
= (csum32
& 0xffff) + (csum32
>> 16);
830 app
[4] = size
& 0xffff;
832 s
->stats
.rx_bytes
+= size
;
836 app
[2] |= 1 | (ip_multicast
<< 1);
837 } else if (broadcast
) {
847 for (i
= 0; i
< ARRAY_SIZE(app
); ++i
) {
848 app
[i
] = cpu_to_le32(app
[i
]);
850 s
->rxappsize
= CONTROL_PAYLOAD_SIZE
;
851 memcpy(s
->rxapp
, app
, s
->rxappsize
);
852 axienet_eth_rx_notify(s
);
859 xilinx_axienet_control_stream_push(StreamSlave
*obj
, uint8_t *buf
, size_t len
,
863 XilinxAXIEnetStreamSlave
*cs
= XILINX_AXI_ENET_CONTROL_STREAM(obj
);
864 XilinxAXIEnet
*s
= cs
->enet
;
867 if (len
!= CONTROL_PAYLOAD_SIZE
) {
868 hw_error("AXI Enet requires %d byte control stream payload\n",
869 (int)CONTROL_PAYLOAD_SIZE
);
872 memcpy(s
->hdr
, buf
, len
);
874 for (i
= 0; i
< ARRAY_SIZE(s
->hdr
); ++i
) {
875 s
->hdr
[i
] = le32_to_cpu(s
->hdr
[i
]);
881 xilinx_axienet_data_stream_push(StreamSlave
*obj
, uint8_t *buf
, size_t size
,
884 XilinxAXIEnetStreamSlave
*ds
= XILINX_AXI_ENET_DATA_STREAM(obj
);
885 XilinxAXIEnet
*s
= ds
->enet
;
888 if (!(s
->tc
& TC_TX
)) {
892 if (s
->txpos
+ size
> s
->c_txmem
) {
893 qemu_log_mask(LOG_GUEST_ERROR
, "%s: Packet larger than txmem\n",
894 TYPE_XILINX_AXI_ENET
);
899 if (s
->txpos
== 0 && eop
) {
900 /* Fast path single fragment. */
903 memcpy(s
->txmem
+ s
->txpos
, buf
, size
);
912 /* Jumbo or vlan sizes ? */
913 if (!(s
->tc
& TC_JUM
)) {
914 if (s
->txpos
> 1518 && s
->txpos
<= 1522 && !(s
->tc
& TC_VLAN
)) {
921 unsigned int start_off
= s
->hdr
[1] >> 16;
922 unsigned int write_off
= s
->hdr
[1] & 0xffff;
926 tmp_csum
= net_checksum_add(s
->txpos
- start_off
,
928 /* Accumulate the seed. */
929 tmp_csum
+= s
->hdr
[2] & 0xffff;
931 /* Fold the 32bit partial checksum. */
932 csum
= net_checksum_finish(tmp_csum
);
935 buf
[write_off
] = csum
>> 8;
936 buf
[write_off
+ 1] = csum
& 0xff;
939 qemu_send_packet(qemu_get_queue(s
->nic
), buf
, s
->txpos
);
941 s
->stats
.tx_bytes
+= s
->txpos
;
942 s
->regs
[R_IS
] |= IS_TX_COMPLETE
;
949 static NetClientInfo net_xilinx_enet_info
= {
950 .type
= NET_CLIENT_DRIVER_NIC
,
951 .size
= sizeof(NICState
),
955 static void xilinx_enet_realize(DeviceState
*dev
, Error
**errp
)
957 XilinxAXIEnet
*s
= XILINX_AXI_ENET(dev
);
958 XilinxAXIEnetStreamSlave
*ds
= XILINX_AXI_ENET_DATA_STREAM(&s
->rx_data_dev
);
959 XilinxAXIEnetStreamSlave
*cs
= XILINX_AXI_ENET_CONTROL_STREAM(
962 object_property_add_link(OBJECT(ds
), "enet", "xlnx.axi-ethernet",
963 (Object
**) &ds
->enet
,
964 object_property_allow_set_link
,
965 OBJ_PROP_LINK_STRONG
);
966 object_property_add_link(OBJECT(cs
), "enet", "xlnx.axi-ethernet",
967 (Object
**) &cs
->enet
,
968 object_property_allow_set_link
,
969 OBJ_PROP_LINK_STRONG
);
970 object_property_set_link(OBJECT(ds
), "enet", OBJECT(s
), &error_abort
);
971 object_property_set_link(OBJECT(cs
), "enet", OBJECT(s
), &error_abort
);
973 qemu_macaddr_default_if_unset(&s
->conf
.macaddr
);
974 s
->nic
= qemu_new_nic(&net_xilinx_enet_info
, &s
->conf
,
975 object_get_typename(OBJECT(dev
)), dev
->id
, s
);
976 qemu_format_nic_info_str(qemu_get_queue(s
->nic
), s
->conf
.macaddr
.a
);
978 tdk_init(&s
->TEMAC
.phy
);
979 mdio_attach(&s
->TEMAC
.mdio_bus
, &s
->TEMAC
.phy
, s
->c_phyaddr
);
983 s
->rxmem
= g_malloc(s
->c_rxmem
);
984 s
->txmem
= g_malloc(s
->c_txmem
);
987 static void xilinx_enet_init(Object
*obj
)
989 XilinxAXIEnet
*s
= XILINX_AXI_ENET(obj
);
990 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
992 object_initialize_child(OBJECT(s
), "axistream-connected-target",
993 &s
->rx_data_dev
, TYPE_XILINX_AXI_ENET_DATA_STREAM
);
994 object_initialize_child(OBJECT(s
), "axistream-control-connected-target",
996 TYPE_XILINX_AXI_ENET_CONTROL_STREAM
);
997 sysbus_init_irq(sbd
, &s
->irq
);
999 memory_region_init_io(&s
->iomem
, OBJECT(s
), &enet_ops
, s
, "enet", 0x40000);
1000 sysbus_init_mmio(sbd
, &s
->iomem
);
1003 static Property xilinx_enet_properties
[] = {
1004 DEFINE_PROP_UINT32("phyaddr", XilinxAXIEnet
, c_phyaddr
, 7),
1005 DEFINE_PROP_UINT32("rxmem", XilinxAXIEnet
, c_rxmem
, 0x1000),
1006 DEFINE_PROP_UINT32("txmem", XilinxAXIEnet
, c_txmem
, 0x1000),
1007 DEFINE_NIC_PROPERTIES(XilinxAXIEnet
, conf
),
1008 DEFINE_PROP_LINK("axistream-connected", XilinxAXIEnet
,
1009 tx_data_dev
, TYPE_STREAM_SLAVE
, StreamSlave
*),
1010 DEFINE_PROP_LINK("axistream-control-connected", XilinxAXIEnet
,
1011 tx_control_dev
, TYPE_STREAM_SLAVE
, StreamSlave
*),
1012 DEFINE_PROP_END_OF_LIST(),
1015 static void xilinx_enet_class_init(ObjectClass
*klass
, void *data
)
1017 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1019 dc
->realize
= xilinx_enet_realize
;
1020 device_class_set_props(dc
, xilinx_enet_properties
);
1021 dc
->reset
= xilinx_axienet_reset
;
1024 static void xilinx_enet_control_stream_class_init(ObjectClass
*klass
,
1027 StreamSlaveClass
*ssc
= STREAM_SLAVE_CLASS(klass
);
1029 ssc
->push
= xilinx_axienet_control_stream_push
;
1032 static void xilinx_enet_data_stream_class_init(ObjectClass
*klass
, void *data
)
1034 StreamSlaveClass
*ssc
= STREAM_SLAVE_CLASS(klass
);
1036 ssc
->push
= xilinx_axienet_data_stream_push
;
1039 static const TypeInfo xilinx_enet_info
= {
1040 .name
= TYPE_XILINX_AXI_ENET
,
1041 .parent
= TYPE_SYS_BUS_DEVICE
,
1042 .instance_size
= sizeof(XilinxAXIEnet
),
1043 .class_init
= xilinx_enet_class_init
,
1044 .instance_init
= xilinx_enet_init
,
1047 static const TypeInfo xilinx_enet_data_stream_info
= {
1048 .name
= TYPE_XILINX_AXI_ENET_DATA_STREAM
,
1049 .parent
= TYPE_OBJECT
,
1050 .instance_size
= sizeof(struct XilinxAXIEnetStreamSlave
),
1051 .class_init
= xilinx_enet_data_stream_class_init
,
1052 .interfaces
= (InterfaceInfo
[]) {
1053 { TYPE_STREAM_SLAVE
},
1058 static const TypeInfo xilinx_enet_control_stream_info
= {
1059 .name
= TYPE_XILINX_AXI_ENET_CONTROL_STREAM
,
1060 .parent
= TYPE_OBJECT
,
1061 .instance_size
= sizeof(struct XilinxAXIEnetStreamSlave
),
1062 .class_init
= xilinx_enet_control_stream_class_init
,
1063 .interfaces
= (InterfaceInfo
[]) {
1064 { TYPE_STREAM_SLAVE
},
1069 static void xilinx_enet_register_types(void)
1071 type_register_static(&xilinx_enet_info
);
1072 type_register_static(&xilinx_enet_data_stream_info
);
1073 type_register_static(&xilinx_enet_control_stream_info
);
1076 type_init(xilinx_enet_register_types
)