2 * QEMU model of SUN GEM ethernet controller
4 * As found in Apple ASICs among others
6 * Copyright 2016 Ben Herrenschmidt
7 * Copyright 2017 Mark Cave-Ayland
10 #include "qemu/osdep.h"
11 #include "hw/pci/pci_device.h"
12 #include "hw/qdev-properties.h"
13 #include "migration/vmstate.h"
15 #include "qemu/module.h"
18 #include "net/checksum.h"
19 #include "hw/net/mii.h"
20 #include "sysemu/sysemu.h"
22 #include "qom/object.h"
24 #define TYPE_SUNGEM "sungem"
26 OBJECT_DECLARE_SIMPLE_TYPE(SunGEMState
, SUNGEM
)
28 #define MAX_PACKET_SIZE 9016
30 #define SUNGEM_MMIO_SIZE 0x200000
32 /* Global registers */
33 #define SUNGEM_MMIO_GREG_SIZE 0x2000
35 #define GREG_SEBSTATE 0x0000UL /* SEB State Register */
37 #define GREG_STAT 0x000CUL /* Status Register */
38 #define GREG_STAT_TXINTME 0x00000001 /* TX INTME frame transferred */
39 #define GREG_STAT_TXALL 0x00000002 /* All TX frames transferred */
40 #define GREG_STAT_TXDONE 0x00000004 /* One TX frame transferred */
41 #define GREG_STAT_RXDONE 0x00000010 /* One RX frame arrived */
42 #define GREG_STAT_RXNOBUF 0x00000020 /* No free RX buffers available */
43 #define GREG_STAT_RXTAGERR 0x00000040 /* RX tag framing is corrupt */
44 #define GREG_STAT_TXMAC 0x00004000 /* TX MAC signalled interrupt */
45 #define GREG_STAT_RXMAC 0x00008000 /* RX MAC signalled interrupt */
46 #define GREG_STAT_MAC 0x00010000 /* MAC Control signalled irq */
47 #define GREG_STAT_TXNR 0xfff80000 /* == TXDMA_TXDONE reg val */
48 #define GREG_STAT_TXNR_SHIFT 19
50 /* These interrupts are edge latches in the status register,
51 * reading it (or writing the corresponding bit in IACK) will
54 #define GREG_STAT_LATCH (GREG_STAT_TXALL | GREG_STAT_TXINTME | \
55 GREG_STAT_RXDONE | GREG_STAT_RXDONE | \
56 GREG_STAT_RXNOBUF | GREG_STAT_RXTAGERR)
58 #define GREG_IMASK 0x0010UL /* Interrupt Mask Register */
59 #define GREG_IACK 0x0014UL /* Interrupt ACK Register */
60 #define GREG_STAT2 0x001CUL /* Alias of GREG_STAT */
61 #define GREG_PCIESTAT 0x1000UL /* PCI Error Status Register */
62 #define GREG_PCIEMASK 0x1004UL /* PCI Error Mask Register */
64 #define GREG_SWRST 0x1010UL /* Software Reset Register */
65 #define GREG_SWRST_TXRST 0x00000001 /* TX Software Reset */
66 #define GREG_SWRST_RXRST 0x00000002 /* RX Software Reset */
67 #define GREG_SWRST_RSTOUT 0x00000004 /* Force RST# pin active */
69 /* TX DMA Registers */
70 #define SUNGEM_MMIO_TXDMA_SIZE 0x1000
72 #define TXDMA_KICK 0x0000UL /* TX Kick Register */
74 #define TXDMA_CFG 0x0004UL /* TX Configuration Register */
75 #define TXDMA_CFG_ENABLE 0x00000001 /* Enable TX DMA channel */
76 #define TXDMA_CFG_RINGSZ 0x0000001e /* TX descriptor ring size */
78 #define TXDMA_DBLOW 0x0008UL /* TX Desc. Base Low */
79 #define TXDMA_DBHI 0x000CUL /* TX Desc. Base High */
80 #define TXDMA_PCNT 0x0024UL /* TX FIFO Packet Counter */
81 #define TXDMA_SMACHINE 0x0028UL /* TX State Machine Register */
82 #define TXDMA_DPLOW 0x0030UL /* TX Data Pointer Low */
83 #define TXDMA_DPHI 0x0034UL /* TX Data Pointer High */
84 #define TXDMA_TXDONE 0x0100UL /* TX Completion Register */
85 #define TXDMA_FTAG 0x0108UL /* TX FIFO Tag */
86 #define TXDMA_FSZ 0x0118UL /* TX FIFO Size */
88 /* Receive DMA Registers */
89 #define SUNGEM_MMIO_RXDMA_SIZE 0x2000
91 #define RXDMA_CFG 0x0000UL /* RX Configuration Register */
92 #define RXDMA_CFG_ENABLE 0x00000001 /* Enable RX DMA channel */
93 #define RXDMA_CFG_RINGSZ 0x0000001e /* RX descriptor ring size */
94 #define RXDMA_CFG_FBOFF 0x00001c00 /* Offset of first data byte */
95 #define RXDMA_CFG_CSUMOFF 0x000fe000 /* Skip bytes before csum calc */
97 #define RXDMA_DBLOW 0x0004UL /* RX Descriptor Base Low */
98 #define RXDMA_DBHI 0x0008UL /* RX Descriptor Base High */
99 #define RXDMA_PCNT 0x0018UL /* RX FIFO Packet Counter */
100 #define RXDMA_SMACHINE 0x001CUL /* RX State Machine Register */
101 #define RXDMA_PTHRESH 0x0020UL /* Pause Thresholds */
102 #define RXDMA_DPLOW 0x0024UL /* RX Data Pointer Low */
103 #define RXDMA_DPHI 0x0028UL /* RX Data Pointer High */
104 #define RXDMA_KICK 0x0100UL /* RX Kick Register */
105 #define RXDMA_DONE 0x0104UL /* RX Completion Register */
106 #define RXDMA_BLANK 0x0108UL /* RX Blanking Register */
107 #define RXDMA_FTAG 0x0110UL /* RX FIFO Tag */
108 #define RXDMA_FSZ 0x0120UL /* RX FIFO Size */
111 #define SUNGEM_MMIO_WOL_SIZE 0x14
113 #define WOL_MATCH0 0x0000UL
114 #define WOL_MATCH1 0x0004UL
115 #define WOL_MATCH2 0x0008UL
116 #define WOL_MCOUNT 0x000CUL
117 #define WOL_WAKECSR 0x0010UL
120 #define SUNGEM_MMIO_MAC_SIZE 0x200
122 #define MAC_TXRST 0x0000UL /* TX MAC Software Reset Command */
123 #define MAC_RXRST 0x0004UL /* RX MAC Software Reset Command */
124 #define MAC_TXSTAT 0x0010UL /* TX MAC Status Register */
125 #define MAC_RXSTAT 0x0014UL /* RX MAC Status Register */
127 #define MAC_CSTAT 0x0018UL /* MAC Control Status Register */
128 #define MAC_CSTAT_PTR 0xffff0000 /* Pause Time Received */
130 #define MAC_TXMASK 0x0020UL /* TX MAC Mask Register */
131 #define MAC_RXMASK 0x0024UL /* RX MAC Mask Register */
132 #define MAC_MCMASK 0x0028UL /* MAC Control Mask Register */
134 #define MAC_TXCFG 0x0030UL /* TX MAC Configuration Register */
135 #define MAC_TXCFG_ENAB 0x00000001 /* TX MAC Enable */
137 #define MAC_RXCFG 0x0034UL /* RX MAC Configuration Register */
138 #define MAC_RXCFG_ENAB 0x00000001 /* RX MAC Enable */
139 #define MAC_RXCFG_SFCS 0x00000004 /* Strip FCS */
140 #define MAC_RXCFG_PROM 0x00000008 /* Promiscuous Mode */
141 #define MAC_RXCFG_PGRP 0x00000010 /* Promiscuous Group */
142 #define MAC_RXCFG_HFE 0x00000020 /* Hash Filter Enable */
144 #define MAC_XIFCFG 0x003CUL /* XIF Configuration Register */
145 #define MAC_XIFCFG_LBCK 0x00000002 /* Loopback TX to RX */
147 #define MAC_MINFSZ 0x0050UL /* MinFrameSize Register */
148 #define MAC_MAXFSZ 0x0054UL /* MaxFrameSize Register */
149 #define MAC_ADDR0 0x0080UL /* MAC Address 0 Register */
150 #define MAC_ADDR1 0x0084UL /* MAC Address 1 Register */
151 #define MAC_ADDR2 0x0088UL /* MAC Address 2 Register */
152 #define MAC_ADDR3 0x008CUL /* MAC Address 3 Register */
153 #define MAC_ADDR4 0x0090UL /* MAC Address 4 Register */
154 #define MAC_ADDR5 0x0094UL /* MAC Address 5 Register */
155 #define MAC_HASH0 0x00C0UL /* Hash Table 0 Register */
156 #define MAC_PATMPS 0x0114UL /* Peak Attempts Register */
157 #define MAC_SMACHINE 0x0134UL /* State Machine Register */
160 #define SUNGEM_MMIO_MIF_SIZE 0x20
162 #define MIF_FRAME 0x000CUL /* MIF Frame/Output Register */
163 #define MIF_FRAME_OP 0x30000000 /* OPcode */
164 #define MIF_FRAME_PHYAD 0x0f800000 /* PHY ADdress */
165 #define MIF_FRAME_REGAD 0x007c0000 /* REGister ADdress */
166 #define MIF_FRAME_TALSB 0x00010000 /* Turn Around LSB */
167 #define MIF_FRAME_DATA 0x0000ffff /* Instruction Payload */
169 #define MIF_CFG 0x0010UL /* MIF Configuration Register */
170 #define MIF_CFG_MDI0 0x00000100 /* MDIO_0 present or read-bit */
171 #define MIF_CFG_MDI1 0x00000200 /* MDIO_1 present or read-bit */
173 #define MIF_STATUS 0x0018UL /* MIF Status Register */
174 #define MIF_SMACHINE 0x001CUL /* MIF State Machine Register */
176 /* PCS/Serialink Registers */
177 #define SUNGEM_MMIO_PCS_SIZE 0x60
178 #define PCS_MIISTAT 0x0004UL /* PCS MII Status Register */
179 #define PCS_ISTAT 0x0018UL /* PCS Interrupt Status Reg */
181 #define PCS_SSTATE 0x005CUL /* Serialink State Register */
185 uint64_t control_word
;
189 #define TXDCTRL_BUFSZ 0x0000000000007fffULL /* Buffer Size */
190 #define TXDCTRL_CSTART 0x00000000001f8000ULL /* CSUM Start Offset */
191 #define TXDCTRL_COFF 0x000000001fe00000ULL /* CSUM Stuff Offset */
192 #define TXDCTRL_CENAB 0x0000000020000000ULL /* CSUM Enable */
193 #define TXDCTRL_EOF 0x0000000040000000ULL /* End of Frame */
194 #define TXDCTRL_SOF 0x0000000080000000ULL /* Start of Frame */
195 #define TXDCTRL_INTME 0x0000000100000000ULL /* "Interrupt Me" */
198 uint64_t status_word
;
202 #define RXDCTRL_HPASS 0x1000000000000000ULL /* Passed Hash Filter */
203 #define RXDCTRL_ALTMAC 0x2000000000000000ULL /* Matched ALT MAC */
221 uint32_t gregs
[SUNGEM_MMIO_GREG_SIZE
>> 2];
222 uint32_t txdmaregs
[SUNGEM_MMIO_TXDMA_SIZE
>> 2];
223 uint32_t rxdmaregs
[SUNGEM_MMIO_RXDMA_SIZE
>> 2];
224 uint32_t macregs
[SUNGEM_MMIO_MAC_SIZE
>> 2];
225 uint32_t mifregs
[SUNGEM_MMIO_MIF_SIZE
>> 2];
226 uint32_t pcsregs
[SUNGEM_MMIO_PCS_SIZE
>> 2];
228 /* Cache some useful things */
232 /* Current tx packet */
233 uint8_t tx_data
[MAX_PACKET_SIZE
];
235 uint64_t tx_first_ctl
;
239 static void sungem_eval_irq(SunGEMState
*s
)
243 mask
= s
->gregs
[GREG_IMASK
>> 2];
244 stat
= s
->gregs
[GREG_STAT
>> 2] & ~GREG_STAT_TXNR
;
246 pci_set_irq(PCI_DEVICE(s
), 1);
248 pci_set_irq(PCI_DEVICE(s
), 0);
252 static void sungem_update_status(SunGEMState
*s
, uint32_t bits
, bool val
)
256 stat
= s
->gregs
[GREG_STAT
>> 2];
262 s
->gregs
[GREG_STAT
>> 2] = stat
;
266 static void sungem_eval_cascade_irq(SunGEMState
*s
)
270 mask
= s
->macregs
[MAC_TXSTAT
>> 2];
271 stat
= s
->macregs
[MAC_TXMASK
>> 2];
273 sungem_update_status(s
, GREG_STAT_TXMAC
, true);
275 sungem_update_status(s
, GREG_STAT_TXMAC
, false);
278 mask
= s
->macregs
[MAC_RXSTAT
>> 2];
279 stat
= s
->macregs
[MAC_RXMASK
>> 2];
281 sungem_update_status(s
, GREG_STAT_RXMAC
, true);
283 sungem_update_status(s
, GREG_STAT_RXMAC
, false);
286 mask
= s
->macregs
[MAC_CSTAT
>> 2];
287 stat
= s
->macregs
[MAC_MCMASK
>> 2] & ~MAC_CSTAT_PTR
;
289 sungem_update_status(s
, GREG_STAT_MAC
, true);
291 sungem_update_status(s
, GREG_STAT_MAC
, false);
295 static void sungem_do_tx_csum(SunGEMState
*s
)
300 start
= (s
->tx_first_ctl
& TXDCTRL_CSTART
) >> 15;
301 off
= (s
->tx_first_ctl
& TXDCTRL_COFF
) >> 21;
303 trace_sungem_tx_checksum(start
, off
);
305 if (start
> (s
->tx_size
- 2) || off
> (s
->tx_size
- 2)) {
306 trace_sungem_tx_checksum_oob();
310 csum
= net_raw_checksum(s
->tx_data
+ start
, s
->tx_size
- start
);
311 stw_be_p(s
->tx_data
+ off
, csum
);
314 static void sungem_send_packet(SunGEMState
*s
, const uint8_t *buf
,
317 NetClientState
*nc
= qemu_get_queue(s
->nic
);
319 if (s
->macregs
[MAC_XIFCFG
>> 2] & MAC_XIFCFG_LBCK
) {
320 qemu_receive_packet(nc
, buf
, size
);
322 qemu_send_packet(nc
, buf
, size
);
326 static void sungem_process_tx_desc(SunGEMState
*s
, struct gem_txd
*desc
)
328 PCIDevice
*d
= PCI_DEVICE(s
);
331 /* If it's a start of frame, discard anything we had in the
332 * buffer and start again. This should be an error condition
333 * if we had something ... for now we ignore it
335 if (desc
->control_word
& TXDCTRL_SOF
) {
336 if (s
->tx_first_ctl
) {
337 trace_sungem_tx_unfinished();
340 s
->tx_first_ctl
= desc
->control_word
;
344 len
= desc
->control_word
& TXDCTRL_BUFSZ
;
346 /* Clamp it to our max size */
347 if ((s
->tx_size
+ len
) > MAX_PACKET_SIZE
) {
348 trace_sungem_tx_overflow();
349 len
= MAX_PACKET_SIZE
- s
->tx_size
;
353 pci_dma_read(d
, desc
->buffer
, &s
->tx_data
[s
->tx_size
], len
);
356 /* If end of frame, send packet */
357 if (desc
->control_word
& TXDCTRL_EOF
) {
358 trace_sungem_tx_finished(s
->tx_size
);
361 if (s
->tx_first_ctl
& TXDCTRL_CENAB
) {
362 sungem_do_tx_csum(s
);
366 sungem_send_packet(s
, s
->tx_data
, s
->tx_size
);
368 /* No more pending packet */
374 static void sungem_tx_kick(SunGEMState
*s
)
376 PCIDevice
*d
= PCI_DEVICE(s
);
378 uint32_t txdma_cfg
, txmac_cfg
, ints
;
381 trace_sungem_tx_kick();
383 /* Check that both TX MAC and TX DMA are enabled. We don't
384 * handle DMA-less direct FIFO operations (we don't emulate
387 * A write to TXDMA_KICK while DMA isn't enabled can happen
388 * when the driver is resetting the pointer.
390 txdma_cfg
= s
->txdmaregs
[TXDMA_CFG
>> 2];
391 txmac_cfg
= s
->macregs
[MAC_TXCFG
>> 2];
392 if (!(txdma_cfg
& TXDMA_CFG_ENABLE
) ||
393 !(txmac_cfg
& MAC_TXCFG_ENAB
)) {
394 trace_sungem_tx_disabled();
398 /* XXX Test min frame size register ? */
399 /* XXX Test max frame size register ? */
401 dbase
= s
->txdmaregs
[TXDMA_DBHI
>> 2];
402 dbase
= (dbase
<< 32) | s
->txdmaregs
[TXDMA_DBLOW
>> 2];
404 comp
= s
->txdmaregs
[TXDMA_TXDONE
>> 2] & s
->tx_mask
;
405 kick
= s
->txdmaregs
[TXDMA_KICK
>> 2] & s
->tx_mask
;
407 trace_sungem_tx_process(comp
, kick
, s
->tx_mask
+ 1);
409 /* This is rather primitive for now, we just send everything we
410 * can in one go, like e1000. Ideally we should do the sending
411 * from some kind of background task
413 while (comp
!= kick
) {
416 /* Read the next descriptor */
417 pci_dma_read(d
, dbase
+ comp
* sizeof(desc
), &desc
, sizeof(desc
));
419 /* Byteswap descriptor */
420 desc
.control_word
= le64_to_cpu(desc
.control_word
);
421 desc
.buffer
= le64_to_cpu(desc
.buffer
);
422 trace_sungem_tx_desc(comp
, desc
.control_word
, desc
.buffer
);
424 /* Send it for processing */
425 sungem_process_tx_desc(s
, &desc
);
428 ints
= GREG_STAT_TXDONE
;
429 if (desc
.control_word
& TXDCTRL_INTME
) {
430 ints
|= GREG_STAT_TXINTME
;
432 sungem_update_status(s
, ints
, true);
435 comp
= (comp
+ 1) & s
->tx_mask
;
436 s
->txdmaregs
[TXDMA_TXDONE
>> 2] = comp
;
439 /* We sent everything, set status/irq bit */
440 sungem_update_status(s
, GREG_STAT_TXALL
, true);
443 static bool sungem_rx_full(SunGEMState
*s
, uint32_t kick
, uint32_t done
)
445 return kick
== ((done
+ 1) & s
->rx_mask
);
448 static bool sungem_can_receive(NetClientState
*nc
)
450 SunGEMState
*s
= qemu_get_nic_opaque(nc
);
451 uint32_t kick
, done
, rxdma_cfg
, rxmac_cfg
;
454 rxmac_cfg
= s
->macregs
[MAC_RXCFG
>> 2];
455 rxdma_cfg
= s
->rxdmaregs
[RXDMA_CFG
>> 2];
457 /* If MAC disabled, can't receive */
458 if ((rxmac_cfg
& MAC_RXCFG_ENAB
) == 0) {
459 trace_sungem_rx_mac_disabled();
462 if ((rxdma_cfg
& RXDMA_CFG_ENABLE
) == 0) {
463 trace_sungem_rx_txdma_disabled();
467 /* Check RX availability */
468 kick
= s
->rxdmaregs
[RXDMA_KICK
>> 2];
469 done
= s
->rxdmaregs
[RXDMA_DONE
>> 2];
470 full
= sungem_rx_full(s
, kick
, done
);
472 trace_sungem_rx_check(!full
, kick
, done
);
487 static int sungem_check_rx_mac(SunGEMState
*s
, const uint8_t *mac
, uint32_t crc
)
489 uint32_t rxcfg
= s
->macregs
[MAC_RXCFG
>> 2];
490 uint32_t mac0
, mac1
, mac2
;
492 /* Promisc enabled ? */
493 if (rxcfg
& MAC_RXCFG_PROM
) {
494 return rx_match_promisc
;
497 /* Format MAC address into dwords */
498 mac0
= (mac
[4] << 8) | mac
[5];
499 mac1
= (mac
[2] << 8) | mac
[3];
500 mac2
= (mac
[0] << 8) | mac
[1];
502 trace_sungem_rx_mac_check(mac0
, mac1
, mac2
);
504 /* Is this a broadcast frame ? */
505 if (mac0
== 0xffff && mac1
== 0xffff && mac2
== 0xffff) {
506 return rx_match_bcast
;
509 /* TODO: Implement address filter registers (or we don't care ?) */
511 /* Is this a multicast frame ? */
513 trace_sungem_rx_mac_multicast();
515 /* Promisc group enabled ? */
516 if (rxcfg
& MAC_RXCFG_PGRP
) {
517 return rx_match_allmcast
;
520 /* TODO: Check MAC control frames (or we don't care) ? */
522 /* Check hash filter (somebody check that's correct ?) */
523 if (rxcfg
& MAC_RXCFG_HFE
) {
527 idx
= (crc
>> 2) & 0x3c;
528 hash
= s
->macregs
[(MAC_HASH0
+ idx
) >> 2];
529 if (hash
& (1 << (15 - (crc
& 0xf)))) {
530 return rx_match_mcast
;
537 trace_sungem_rx_mac_compare(s
->macregs
[MAC_ADDR0
>> 2],
538 s
->macregs
[MAC_ADDR1
>> 2],
539 s
->macregs
[MAC_ADDR2
>> 2]);
541 if (mac0
== s
->macregs
[MAC_ADDR0
>> 2] &&
542 mac1
== s
->macregs
[MAC_ADDR1
>> 2] &&
543 mac2
== s
->macregs
[MAC_ADDR2
>> 2]) {
548 if (mac0
== s
->macregs
[MAC_ADDR3
>> 2] &&
549 mac1
== s
->macregs
[MAC_ADDR4
>> 2] &&
550 mac2
== s
->macregs
[MAC_ADDR5
>> 2]) {
551 return rx_match_altmac
;
557 static ssize_t
sungem_receive(NetClientState
*nc
, const uint8_t *buf
,
560 SunGEMState
*s
= qemu_get_nic_opaque(nc
);
561 PCIDevice
*d
= PCI_DEVICE(s
);
562 uint32_t mac_crc
, done
, kick
, max_fsize
;
563 uint32_t fcs_size
, ints
, rxdma_cfg
, rxmac_cfg
, csum
, coff
;
565 uint64_t dbase
, baddr
;
566 unsigned int rx_cond
;
568 trace_sungem_rx_packet(size
);
570 rxmac_cfg
= s
->macregs
[MAC_RXCFG
>> 2];
571 rxdma_cfg
= s
->rxdmaregs
[RXDMA_CFG
>> 2];
572 max_fsize
= s
->macregs
[MAC_MAXFSZ
>> 2] & 0x7fff;
574 /* If MAC or DMA disabled, can't receive */
575 if (!(rxdma_cfg
& RXDMA_CFG_ENABLE
) ||
576 !(rxmac_cfg
& MAC_RXCFG_ENAB
)) {
577 trace_sungem_rx_disabled();
581 /* Size adjustment for FCS */
582 if (rxmac_cfg
& MAC_RXCFG_SFCS
) {
588 /* Discard frame smaller than a MAC or larger than max frame size
589 * (when accounting for FCS)
591 if (size
< 6 || (size
+ 4) > max_fsize
) {
592 trace_sungem_rx_bad_frame_size(size
);
593 /* XXX Increment error statistics ? */
598 mac_crc
= net_crc32_le(buf
, ETH_ALEN
);
600 /* Packet isn't for me ? */
601 rx_cond
= sungem_check_rx_mac(s
, buf
, mac_crc
);
602 if (rx_cond
== rx_no_match
) {
604 trace_sungem_rx_unmatched();
608 /* Get ring pointers */
609 kick
= s
->rxdmaregs
[RXDMA_KICK
>> 2] & s
->rx_mask
;
610 done
= s
->rxdmaregs
[RXDMA_DONE
>> 2] & s
->rx_mask
;
612 trace_sungem_rx_process(done
, kick
, s
->rx_mask
+ 1);
614 /* Ring full ? Can't receive */
615 if (sungem_rx_full(s
, kick
, done
)) {
616 trace_sungem_rx_ringfull();
620 /* Note: The real GEM will fetch descriptors in blocks of 4,
621 * for now we handle them one at a time, I think the driver will
625 dbase
= s
->rxdmaregs
[RXDMA_DBHI
>> 2];
626 dbase
= (dbase
<< 32) | s
->rxdmaregs
[RXDMA_DBLOW
>> 2];
628 /* Read the next descriptor */
629 pci_dma_read(d
, dbase
+ done
* sizeof(desc
), &desc
, sizeof(desc
));
631 trace_sungem_rx_desc(le64_to_cpu(desc
.status_word
),
632 le64_to_cpu(desc
.buffer
));
634 /* Effective buffer address */
635 baddr
= le64_to_cpu(desc
.buffer
) & ~7ull;
636 baddr
|= (rxdma_cfg
& RXDMA_CFG_FBOFF
) >> 10;
638 /* Write buffer out */
639 pci_dma_write(d
, baddr
, buf
, size
);
642 /* Should we add an FCS ? Linux doesn't ask us to strip it,
643 * however I believe nothing checks it... For now we just
644 * do nothing. It's faster this way.
648 /* Calculate the checksum */
649 coff
= (rxdma_cfg
& RXDMA_CFG_CSUMOFF
) >> 13;
650 csum
= net_raw_checksum((uint8_t *)buf
+ coff
, size
- coff
);
652 /* Build the updated descriptor */
653 desc
.status_word
= (size
+ fcs_size
) << 16;
654 desc
.status_word
|= ((uint64_t)(mac_crc
>> 16)) << 44;
655 desc
.status_word
|= csum
;
656 if (rx_cond
== rx_match_mcast
) {
657 desc
.status_word
|= RXDCTRL_HPASS
;
659 if (rx_cond
== rx_match_altmac
) {
660 desc
.status_word
|= RXDCTRL_ALTMAC
;
662 desc
.status_word
= cpu_to_le64(desc
.status_word
);
664 pci_dma_write(d
, dbase
+ done
* sizeof(desc
), &desc
, sizeof(desc
));
666 done
= (done
+ 1) & s
->rx_mask
;
667 s
->rxdmaregs
[RXDMA_DONE
>> 2] = done
;
669 /* XXX Unconditionally set RX interrupt for now. The interrupt
670 * mitigation timer might well end up adding more overhead than
673 ints
= GREG_STAT_RXDONE
;
674 if (sungem_rx_full(s
, kick
, done
)) {
675 ints
|= GREG_STAT_RXNOBUF
;
677 sungem_update_status(s
, ints
, true);
682 static void sungem_set_link_status(NetClientState
*nc
)
684 /* We don't do anything for now as I believe none of the OSes
685 * drivers use the MIF autopoll feature nor the PHY interrupt
689 static void sungem_update_masks(SunGEMState
*s
)
693 sz
= 1 << (((s
->rxdmaregs
[RXDMA_CFG
>> 2] & RXDMA_CFG_RINGSZ
) >> 1) + 5);
696 sz
= 1 << (((s
->txdmaregs
[TXDMA_CFG
>> 2] & TXDMA_CFG_RINGSZ
) >> 1) + 5);
700 static void sungem_reset_rx(SunGEMState
*s
)
702 trace_sungem_rx_reset();
705 /* XXX Check value */
706 s
->rxdmaregs
[RXDMA_FSZ
>> 2] = 0x140;
707 s
->rxdmaregs
[RXDMA_DONE
>> 2] = 0;
708 s
->rxdmaregs
[RXDMA_KICK
>> 2] = 0;
709 s
->rxdmaregs
[RXDMA_CFG
>> 2] = 0x1000010;
710 s
->rxdmaregs
[RXDMA_PTHRESH
>> 2] = 0xf8;
711 s
->rxdmaregs
[RXDMA_BLANK
>> 2] = 0;
713 sungem_update_masks(s
);
716 static void sungem_reset_tx(SunGEMState
*s
)
718 trace_sungem_tx_reset();
721 /* XXX Check value */
722 s
->txdmaregs
[TXDMA_FSZ
>> 2] = 0x90;
723 s
->txdmaregs
[TXDMA_TXDONE
>> 2] = 0;
724 s
->txdmaregs
[TXDMA_KICK
>> 2] = 0;
725 s
->txdmaregs
[TXDMA_CFG
>> 2] = 0x118010;
727 sungem_update_masks(s
);
733 static void sungem_reset_all(SunGEMState
*s
, bool pci_reset
)
735 trace_sungem_reset(pci_reset
);
740 s
->gregs
[GREG_IMASK
>> 2] = 0xFFFFFFF;
741 s
->gregs
[GREG_STAT
>> 2] = 0;
743 uint8_t *ma
= s
->conf
.macaddr
.a
;
745 s
->gregs
[GREG_SWRST
>> 2] = 0;
746 s
->macregs
[MAC_ADDR0
>> 2] = (ma
[4] << 8) | ma
[5];
747 s
->macregs
[MAC_ADDR1
>> 2] = (ma
[2] << 8) | ma
[3];
748 s
->macregs
[MAC_ADDR2
>> 2] = (ma
[0] << 8) | ma
[1];
750 s
->gregs
[GREG_SWRST
>> 2] &= GREG_SWRST_RSTOUT
;
752 s
->mifregs
[MIF_CFG
>> 2] = MIF_CFG_MDI0
;
755 static void sungem_mii_write(SunGEMState
*s
, uint8_t phy_addr
,
756 uint8_t reg_addr
, uint16_t val
)
758 trace_sungem_mii_write(phy_addr
, reg_addr
, val
);
763 static uint16_t __sungem_mii_read(SunGEMState
*s
, uint8_t phy_addr
,
766 if (phy_addr
!= s
->phy_addr
) {
769 /* Primitive emulation of a BCM5201 to please the driver,
770 * ID is 0x00406210. TODO: Do a gigabit PHY like BCM5400
780 if (qemu_get_queue(s
->nic
)->link_down
) {
781 return MII_BMSR_100TX_FD
| MII_BMSR_AUTONEG
;
783 return MII_BMSR_100TX_FD
| MII_BMSR_AN_COMP
|
784 MII_BMSR_AUTONEG
| MII_BMSR_LINK_ST
;
788 return MII_ANLPAR_TXFD
;
789 case 0x18: /* 5201 AUX status */
790 return 3; /* 100FD */
795 static uint16_t sungem_mii_read(SunGEMState
*s
, uint8_t phy_addr
,
800 val
= __sungem_mii_read(s
, phy_addr
, reg_addr
);
802 trace_sungem_mii_read(phy_addr
, reg_addr
, val
);
807 static uint32_t sungem_mii_op(SunGEMState
*s
, uint32_t val
)
809 uint8_t phy_addr
, reg_addr
, op
;
811 /* Ignore not start of frame */
812 if ((val
>> 30) != 1) {
813 trace_sungem_mii_invalid_sof(val
>> 30);
816 phy_addr
= (val
& MIF_FRAME_PHYAD
) >> 23;
817 reg_addr
= (val
& MIF_FRAME_REGAD
) >> 18;
818 op
= (val
& MIF_FRAME_OP
) >> 28;
821 sungem_mii_write(s
, phy_addr
, reg_addr
, val
& MIF_FRAME_DATA
);
822 return val
| MIF_FRAME_TALSB
;
824 return sungem_mii_read(s
, phy_addr
, reg_addr
) | MIF_FRAME_TALSB
;
826 trace_sungem_mii_invalid_op(op
);
828 return 0xffff | MIF_FRAME_TALSB
;
831 static void sungem_mmio_greg_write(void *opaque
, hwaddr addr
, uint64_t val
,
834 SunGEMState
*s
= opaque
;
836 if (!(addr
< 0x20) && !(addr
>= 0x1000 && addr
<= 0x1010)) {
837 qemu_log_mask(LOG_GUEST_ERROR
,
838 "Write to unknown GREG register 0x%"HWADDR_PRIx
"\n",
843 trace_sungem_mmio_greg_write(addr
, val
);
845 /* Pre-write filter */
847 /* Read only registers */
852 return; /* No actual write */
854 val
&= GREG_STAT_LATCH
;
855 s
->gregs
[GREG_STAT
>> 2] &= ~val
;
857 return; /* No actual write */
863 s
->gregs
[addr
>> 2] = val
;
865 /* Post write action */
868 /* Re-evaluate interrupt */
872 switch (val
& (GREG_SWRST_TXRST
| GREG_SWRST_RXRST
)) {
873 case GREG_SWRST_RXRST
:
876 case GREG_SWRST_TXRST
:
879 case GREG_SWRST_RXRST
| GREG_SWRST_TXRST
:
880 sungem_reset_all(s
, false);
886 static uint64_t sungem_mmio_greg_read(void *opaque
, hwaddr addr
, unsigned size
)
888 SunGEMState
*s
= opaque
;
891 if (!(addr
< 0x20) && !(addr
>= 0x1000 && addr
<= 0x1010)) {
892 qemu_log_mask(LOG_GUEST_ERROR
,
893 "Read from unknown GREG register 0x%"HWADDR_PRIx
"\n",
898 val
= s
->gregs
[addr
>> 2];
900 trace_sungem_mmio_greg_read(addr
, val
);
904 /* Side effect, clear bottom 7 bits */
905 s
->gregs
[GREG_STAT
>> 2] &= ~GREG_STAT_LATCH
;
908 /* Inject TX completion in returned value */
909 val
= (val
& ~GREG_STAT_TXNR
) |
910 (s
->txdmaregs
[TXDMA_TXDONE
>> 2] << GREG_STAT_TXNR_SHIFT
);
913 /* Return the status reg without side effect
914 * (and inject TX completion in returned value)
916 val
= (s
->gregs
[GREG_STAT
>> 2] & ~GREG_STAT_TXNR
) |
917 (s
->txdmaregs
[TXDMA_TXDONE
>> 2] << GREG_STAT_TXNR_SHIFT
);
924 static const MemoryRegionOps sungem_mmio_greg_ops
= {
925 .read
= sungem_mmio_greg_read
,
926 .write
= sungem_mmio_greg_write
,
927 .endianness
= DEVICE_LITTLE_ENDIAN
,
929 .min_access_size
= 4,
930 .max_access_size
= 4,
934 static void sungem_mmio_txdma_write(void *opaque
, hwaddr addr
, uint64_t val
,
937 SunGEMState
*s
= opaque
;
939 if (!(addr
< 0x38) && !(addr
>= 0x100 && addr
<= 0x118)) {
940 qemu_log_mask(LOG_GUEST_ERROR
,
941 "Write to unknown TXDMA register 0x%"HWADDR_PRIx
"\n",
946 trace_sungem_mmio_txdma_write(addr
, val
);
948 /* Pre-write filter */
950 /* Read only registers */
958 return; /* No actual write */
961 s
->txdmaregs
[addr
>> 2] = val
;
963 /* Post write action */
969 sungem_update_masks(s
);
974 static uint64_t sungem_mmio_txdma_read(void *opaque
, hwaddr addr
, unsigned size
)
976 SunGEMState
*s
= opaque
;
979 if (!(addr
< 0x38) && !(addr
>= 0x100 && addr
<= 0x118)) {
980 qemu_log_mask(LOG_GUEST_ERROR
,
981 "Read from unknown TXDMA register 0x%"HWADDR_PRIx
"\n",
986 val
= s
->txdmaregs
[addr
>> 2];
988 trace_sungem_mmio_txdma_read(addr
, val
);
993 static const MemoryRegionOps sungem_mmio_txdma_ops
= {
994 .read
= sungem_mmio_txdma_read
,
995 .write
= sungem_mmio_txdma_write
,
996 .endianness
= DEVICE_LITTLE_ENDIAN
,
998 .min_access_size
= 4,
999 .max_access_size
= 4,
1003 static void sungem_mmio_rxdma_write(void *opaque
, hwaddr addr
, uint64_t val
,
1006 SunGEMState
*s
= opaque
;
1008 if (!(addr
<= 0x28) && !(addr
>= 0x100 && addr
<= 0x120)) {
1009 qemu_log_mask(LOG_GUEST_ERROR
,
1010 "Write to unknown RXDMA register 0x%"HWADDR_PRIx
"\n",
1015 trace_sungem_mmio_rxdma_write(addr
, val
);
1017 /* Pre-write filter */
1019 /* Read only registers */
1022 case RXDMA_SMACHINE
:
1027 return; /* No actual write */
1030 s
->rxdmaregs
[addr
>> 2] = val
;
1032 /* Post write action */
1035 trace_sungem_rx_kick(val
);
1038 sungem_update_masks(s
);
1039 if ((s
->macregs
[MAC_RXCFG
>> 2] & MAC_RXCFG_ENAB
) != 0 &&
1040 (s
->rxdmaregs
[RXDMA_CFG
>> 2] & RXDMA_CFG_ENABLE
) != 0) {
1041 qemu_flush_queued_packets(qemu_get_queue(s
->nic
));
1047 static uint64_t sungem_mmio_rxdma_read(void *opaque
, hwaddr addr
, unsigned size
)
1049 SunGEMState
*s
= opaque
;
1052 if (!(addr
<= 0x28) && !(addr
>= 0x100 && addr
<= 0x120)) {
1053 qemu_log_mask(LOG_GUEST_ERROR
,
1054 "Read from unknown RXDMA register 0x%"HWADDR_PRIx
"\n",
1059 val
= s
->rxdmaregs
[addr
>> 2];
1061 trace_sungem_mmio_rxdma_read(addr
, val
);
1066 static const MemoryRegionOps sungem_mmio_rxdma_ops
= {
1067 .read
= sungem_mmio_rxdma_read
,
1068 .write
= sungem_mmio_rxdma_write
,
1069 .endianness
= DEVICE_LITTLE_ENDIAN
,
1071 .min_access_size
= 4,
1072 .max_access_size
= 4,
1076 static void sungem_mmio_wol_write(void *opaque
, hwaddr addr
, uint64_t val
,
1079 trace_sungem_mmio_wol_write(addr
, val
);
1084 qemu_log_mask(LOG_UNIMP
, "sungem: WOL not supported\n");
1088 qemu_log_mask(LOG_UNIMP
, "sungem: WOL not supported\n");
1092 static uint64_t sungem_mmio_wol_read(void *opaque
, hwaddr addr
, unsigned size
)
1096 qemu_log_mask(LOG_UNIMP
, "sungem: WOL not supported\n");
1098 trace_sungem_mmio_wol_read(addr
, val
);
1103 static const MemoryRegionOps sungem_mmio_wol_ops
= {
1104 .read
= sungem_mmio_wol_read
,
1105 .write
= sungem_mmio_wol_write
,
1106 .endianness
= DEVICE_LITTLE_ENDIAN
,
1108 .min_access_size
= 4,
1109 .max_access_size
= 4,
1113 static void sungem_mmio_mac_write(void *opaque
, hwaddr addr
, uint64_t val
,
1116 SunGEMState
*s
= opaque
;
1118 if (!(addr
<= 0x134)) {
1119 qemu_log_mask(LOG_GUEST_ERROR
,
1120 "Write to unknown MAC register 0x%"HWADDR_PRIx
"\n",
1125 trace_sungem_mmio_mac_write(addr
, val
);
1127 /* Pre-write filter */
1129 /* Read only registers */
1130 case MAC_TXRST
: /* Not technically read-only but will do for now */
1131 case MAC_RXRST
: /* Not technically read-only but will do for now */
1137 return; /* No actual write */
1139 /* 10-bits implemented */
1144 s
->macregs
[addr
>> 2] = val
;
1146 /* Post write action */
1151 sungem_eval_cascade_irq(s
);
1154 sungem_update_masks(s
);
1155 if ((s
->macregs
[MAC_RXCFG
>> 2] & MAC_RXCFG_ENAB
) != 0 &&
1156 (s
->rxdmaregs
[RXDMA_CFG
>> 2] & RXDMA_CFG_ENABLE
) != 0) {
1157 qemu_flush_queued_packets(qemu_get_queue(s
->nic
));
1163 static uint64_t sungem_mmio_mac_read(void *opaque
, hwaddr addr
, unsigned size
)
1165 SunGEMState
*s
= opaque
;
1168 if (!(addr
<= 0x134)) {
1169 qemu_log_mask(LOG_GUEST_ERROR
,
1170 "Read from unknown MAC register 0x%"HWADDR_PRIx
"\n",
1175 val
= s
->macregs
[addr
>> 2];
1177 trace_sungem_mmio_mac_read(addr
, val
);
1181 /* Side effect, clear all */
1182 s
->macregs
[addr
>> 2] = 0;
1183 sungem_update_status(s
, GREG_STAT_TXMAC
, false);
1186 /* Side effect, clear all */
1187 s
->macregs
[addr
>> 2] = 0;
1188 sungem_update_status(s
, GREG_STAT_RXMAC
, false);
1191 /* Side effect, interrupt bits */
1192 s
->macregs
[addr
>> 2] &= MAC_CSTAT_PTR
;
1193 sungem_update_status(s
, GREG_STAT_MAC
, false);
1200 static const MemoryRegionOps sungem_mmio_mac_ops
= {
1201 .read
= sungem_mmio_mac_read
,
1202 .write
= sungem_mmio_mac_write
,
1203 .endianness
= DEVICE_LITTLE_ENDIAN
,
1205 .min_access_size
= 4,
1206 .max_access_size
= 4,
1210 static void sungem_mmio_mif_write(void *opaque
, hwaddr addr
, uint64_t val
,
1213 SunGEMState
*s
= opaque
;
1215 if (!(addr
<= 0x1c)) {
1216 qemu_log_mask(LOG_GUEST_ERROR
,
1217 "Write to unknown MIF register 0x%"HWADDR_PRIx
"\n",
1222 trace_sungem_mmio_mif_write(addr
, val
);
1224 /* Pre-write filter */
1226 /* Read only registers */
1229 return; /* No actual write */
1231 /* Maintain the RO MDI bits to advertise an MDIO PHY on MDI0 */
1232 val
&= ~MIF_CFG_MDI1
;
1233 val
|= MIF_CFG_MDI0
;
1237 s
->mifregs
[addr
>> 2] = val
;
1239 /* Post write action */
1242 s
->mifregs
[addr
>> 2] = sungem_mii_op(s
, val
);
1247 static uint64_t sungem_mmio_mif_read(void *opaque
, hwaddr addr
, unsigned size
)
1249 SunGEMState
*s
= opaque
;
1252 if (!(addr
<= 0x1c)) {
1253 qemu_log_mask(LOG_GUEST_ERROR
,
1254 "Read from unknown MIF register 0x%"HWADDR_PRIx
"\n",
1259 val
= s
->mifregs
[addr
>> 2];
1261 trace_sungem_mmio_mif_read(addr
, val
);
1266 static const MemoryRegionOps sungem_mmio_mif_ops
= {
1267 .read
= sungem_mmio_mif_read
,
1268 .write
= sungem_mmio_mif_write
,
1269 .endianness
= DEVICE_LITTLE_ENDIAN
,
1271 .min_access_size
= 4,
1272 .max_access_size
= 4,
1276 static void sungem_mmio_pcs_write(void *opaque
, hwaddr addr
, uint64_t val
,
1279 SunGEMState
*s
= opaque
;
1281 if (!(addr
<= 0x18) && !(addr
>= 0x50 && addr
<= 0x5c)) {
1282 qemu_log_mask(LOG_GUEST_ERROR
,
1283 "Write to unknown PCS register 0x%"HWADDR_PRIx
"\n",
1288 trace_sungem_mmio_pcs_write(addr
, val
);
1290 /* Pre-write filter */
1292 /* Read only registers */
1296 return; /* No actual write */
1299 s
->pcsregs
[addr
>> 2] = val
;
1302 static uint64_t sungem_mmio_pcs_read(void *opaque
, hwaddr addr
, unsigned size
)
1304 SunGEMState
*s
= opaque
;
1307 if (!(addr
<= 0x18) && !(addr
>= 0x50 && addr
<= 0x5c)) {
1308 qemu_log_mask(LOG_GUEST_ERROR
,
1309 "Read from unknown PCS register 0x%"HWADDR_PRIx
"\n",
1314 val
= s
->pcsregs
[addr
>> 2];
1316 trace_sungem_mmio_pcs_read(addr
, val
);
1321 static const MemoryRegionOps sungem_mmio_pcs_ops
= {
1322 .read
= sungem_mmio_pcs_read
,
1323 .write
= sungem_mmio_pcs_write
,
1324 .endianness
= DEVICE_LITTLE_ENDIAN
,
1326 .min_access_size
= 4,
1327 .max_access_size
= 4,
1331 static void sungem_uninit(PCIDevice
*dev
)
1333 SunGEMState
*s
= SUNGEM(dev
);
1335 qemu_del_nic(s
->nic
);
1338 static NetClientInfo net_sungem_info
= {
1339 .type
= NET_CLIENT_DRIVER_NIC
,
1340 .size
= sizeof(NICState
),
1341 .can_receive
= sungem_can_receive
,
1342 .receive
= sungem_receive
,
1343 .link_status_changed
= sungem_set_link_status
,
1346 static void sungem_realize(PCIDevice
*pci_dev
, Error
**errp
)
1348 DeviceState
*dev
= DEVICE(pci_dev
);
1349 SunGEMState
*s
= SUNGEM(pci_dev
);
1352 pci_conf
= pci_dev
->config
;
1354 pci_set_word(pci_conf
+ PCI_STATUS
,
1355 PCI_STATUS_FAST_BACK
|
1356 PCI_STATUS_DEVSEL_MEDIUM
|
1359 pci_set_word(pci_conf
+ PCI_SUBSYSTEM_VENDOR_ID
, 0x0);
1360 pci_set_word(pci_conf
+ PCI_SUBSYSTEM_ID
, 0x0);
1362 pci_conf
[PCI_INTERRUPT_PIN
] = 1; /* interrupt pin A */
1363 pci_conf
[PCI_MIN_GNT
] = 0x40;
1364 pci_conf
[PCI_MAX_LAT
] = 0x40;
1366 sungem_reset_all(s
, true);
1367 memory_region_init(&s
->sungem
, OBJECT(s
), "sungem", SUNGEM_MMIO_SIZE
);
1369 memory_region_init_io(&s
->greg
, OBJECT(s
), &sungem_mmio_greg_ops
, s
,
1370 "sungem.greg", SUNGEM_MMIO_GREG_SIZE
);
1371 memory_region_add_subregion(&s
->sungem
, 0, &s
->greg
);
1373 memory_region_init_io(&s
->txdma
, OBJECT(s
), &sungem_mmio_txdma_ops
, s
,
1374 "sungem.txdma", SUNGEM_MMIO_TXDMA_SIZE
);
1375 memory_region_add_subregion(&s
->sungem
, 0x2000, &s
->txdma
);
1377 memory_region_init_io(&s
->rxdma
, OBJECT(s
), &sungem_mmio_rxdma_ops
, s
,
1378 "sungem.rxdma", SUNGEM_MMIO_RXDMA_SIZE
);
1379 memory_region_add_subregion(&s
->sungem
, 0x4000, &s
->rxdma
);
1381 memory_region_init_io(&s
->wol
, OBJECT(s
), &sungem_mmio_wol_ops
, s
,
1382 "sungem.wol", SUNGEM_MMIO_WOL_SIZE
);
1383 memory_region_add_subregion(&s
->sungem
, 0x3000, &s
->wol
);
1385 memory_region_init_io(&s
->mac
, OBJECT(s
), &sungem_mmio_mac_ops
, s
,
1386 "sungem.mac", SUNGEM_MMIO_MAC_SIZE
);
1387 memory_region_add_subregion(&s
->sungem
, 0x6000, &s
->mac
);
1389 memory_region_init_io(&s
->mif
, OBJECT(s
), &sungem_mmio_mif_ops
, s
,
1390 "sungem.mif", SUNGEM_MMIO_MIF_SIZE
);
1391 memory_region_add_subregion(&s
->sungem
, 0x6200, &s
->mif
);
1393 memory_region_init_io(&s
->pcs
, OBJECT(s
), &sungem_mmio_pcs_ops
, s
,
1394 "sungem.pcs", SUNGEM_MMIO_PCS_SIZE
);
1395 memory_region_add_subregion(&s
->sungem
, 0x9000, &s
->pcs
);
1397 pci_register_bar(pci_dev
, 0, PCI_BASE_ADDRESS_SPACE_MEMORY
, &s
->sungem
);
1399 qemu_macaddr_default_if_unset(&s
->conf
.macaddr
);
1400 s
->nic
= qemu_new_nic(&net_sungem_info
, &s
->conf
,
1401 object_get_typename(OBJECT(dev
)),
1402 dev
->id
, &dev
->mem_reentrancy_guard
, s
);
1403 qemu_format_nic_info_str(qemu_get_queue(s
->nic
),
1407 static void sungem_reset(DeviceState
*dev
)
1409 SunGEMState
*s
= SUNGEM(dev
);
1411 sungem_reset_all(s
, true);
1414 static void sungem_instance_init(Object
*obj
)
1416 SunGEMState
*s
= SUNGEM(obj
);
1418 device_add_bootindex_property(obj
, &s
->conf
.bootindex
,
1419 "bootindex", "/ethernet-phy@0",
1423 static Property sungem_properties
[] = {
1424 DEFINE_NIC_PROPERTIES(SunGEMState
, conf
),
1425 /* Phy address should be 0 for most Apple machines except
1426 * for K2 in which case it's 1. Will be set by a machine
1429 DEFINE_PROP_UINT32("phy_addr", SunGEMState
, phy_addr
, 0),
1430 DEFINE_PROP_END_OF_LIST(),
1433 static const VMStateDescription vmstate_sungem
= {
1436 .minimum_version_id
= 0,
1437 .fields
= (const VMStateField
[]) {
1438 VMSTATE_PCI_DEVICE(pdev
, SunGEMState
),
1439 VMSTATE_MACADDR(conf
.macaddr
, SunGEMState
),
1440 VMSTATE_UINT32(phy_addr
, SunGEMState
),
1441 VMSTATE_UINT32_ARRAY(gregs
, SunGEMState
, (SUNGEM_MMIO_GREG_SIZE
>> 2)),
1442 VMSTATE_UINT32_ARRAY(txdmaregs
, SunGEMState
,
1443 (SUNGEM_MMIO_TXDMA_SIZE
>> 2)),
1444 VMSTATE_UINT32_ARRAY(rxdmaregs
, SunGEMState
,
1445 (SUNGEM_MMIO_RXDMA_SIZE
>> 2)),
1446 VMSTATE_UINT32_ARRAY(macregs
, SunGEMState
, (SUNGEM_MMIO_MAC_SIZE
>> 2)),
1447 VMSTATE_UINT32_ARRAY(mifregs
, SunGEMState
, (SUNGEM_MMIO_MIF_SIZE
>> 2)),
1448 VMSTATE_UINT32_ARRAY(pcsregs
, SunGEMState
, (SUNGEM_MMIO_PCS_SIZE
>> 2)),
1449 VMSTATE_UINT32(rx_mask
, SunGEMState
),
1450 VMSTATE_UINT32(tx_mask
, SunGEMState
),
1451 VMSTATE_UINT8_ARRAY(tx_data
, SunGEMState
, MAX_PACKET_SIZE
),
1452 VMSTATE_UINT32(tx_size
, SunGEMState
),
1453 VMSTATE_UINT64(tx_first_ctl
, SunGEMState
),
1454 VMSTATE_END_OF_LIST()
1458 static void sungem_class_init(ObjectClass
*klass
, void *data
)
1460 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1461 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
1463 k
->realize
= sungem_realize
;
1464 k
->exit
= sungem_uninit
;
1465 k
->vendor_id
= PCI_VENDOR_ID_APPLE
;
1466 k
->device_id
= PCI_DEVICE_ID_APPLE_UNI_N_GMAC
;
1468 k
->class_id
= PCI_CLASS_NETWORK_ETHERNET
;
1469 dc
->vmsd
= &vmstate_sungem
;
1470 dc
->reset
= sungem_reset
;
1471 device_class_set_props(dc
, sungem_properties
);
1472 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
1475 static const TypeInfo sungem_info
= {
1476 .name
= TYPE_SUNGEM
,
1477 .parent
= TYPE_PCI_DEVICE
,
1478 .instance_size
= sizeof(SunGEMState
),
1479 .class_init
= sungem_class_init
,
1480 .instance_init
= sungem_instance_init
,
1481 .interfaces
= (InterfaceInfo
[]) {
1482 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
1487 static void sungem_register_types(void)
1489 type_register_static(&sungem_info
);
1492 type_init(sungem_register_types
)