1 | The following changes since commit 32c7e0ab755745e961f1772e95cac381cc68769d: | 1 | The following changes since commit fff3159900d2b95613a9cb75fc3703e67a674729: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/juanquintela/tags/migration/20170421' into staging (2017-04-21 15:59:27 +0100) | 3 | Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20190726' into staging (2019-07-26 16:23:07 +0100) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the git repository at: |
6 | 6 | ||
7 | https://github.com/jasowang/qemu.git tags/net-pull-request | 7 | https://github.com/jasowang/qemu.git tags/net-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 049f6d8237dd0b14dee02e4c22b20114c43cecff: | 9 | for you to fetch changes up to f77bed14f01557596727c4eea042e9818c242049: |
10 | 10 | ||
11 | COLO-compare: Optimize tcp compare trace event (2017-04-24 11:30:36 +0800) | 11 | net/colo-compare.c: Fix memory leak and code style issue. (2019-07-29 16:29:30 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | 14 | ||
15 | ---------------------------------------------------------------- | 15 | ---------------------------------------------------------------- |
16 | Cédric Le Goater (5): | 16 | Jason Wang (1): |
17 | hw/net: add MII definitions | 17 | e1000: don't raise interrupt in pre_save() |
18 | net: add FTGMAC100 support | ||
19 | net/ftgmac100: add a 'aspeed' property | ||
20 | aspeed: add a FTGMAC100 nic | ||
21 | slirp: add a fake NC-SI backend | ||
22 | 18 | ||
23 | Zhang Chen (3): | 19 | Prasad J Pandit (3): |
24 | colo-compare: Fix old packet check bug. | 20 | qemu-bridge-helper: restrict interface name to IFNAMSIZ |
25 | COLO-compare: Optimize tcp compare for option field | 21 | qemu-bridge-helper: move repeating code in parse_acl_file |
26 | COLO-compare: Optimize tcp compare trace event | 22 | net: tap: replace snprintf with g_strdup_printf calls |
27 | 23 | ||
28 | default-configs/arm-softmmu.mak | 1 + | 24 | Zhang Chen (1): |
29 | hw/arm/aspeed_soc.c | 21 + | 25 | net/colo-compare.c: Fix memory leak and code style issue. |
30 | hw/net/Makefile.objs | 1 + | ||
31 | hw/net/ftgmac100.c | 1016 +++++++++++++++++++++++++++++++++++++++ | ||
32 | include/hw/arm/aspeed_soc.h | 2 + | ||
33 | include/hw/net/ftgmac100.h | 64 +++ | ||
34 | include/hw/net/mii.h | 71 ++- | ||
35 | include/net/eth.h | 1 + | ||
36 | net/colo-compare.c | 69 ++- | ||
37 | net/trace-events | 3 +- | ||
38 | slirp/Makefile.objs | 2 +- | ||
39 | slirp/ncsi-pkt.h | 419 ++++++++++++++++ | ||
40 | slirp/ncsi.c | 130 +++++ | ||
41 | slirp/slirp.c | 4 + | ||
42 | slirp/slirp.h | 3 + | ||
43 | 15 files changed, 1770 insertions(+), 37 deletions(-) | ||
44 | create mode 100644 hw/net/ftgmac100.c | ||
45 | create mode 100644 include/hw/net/ftgmac100.h | ||
46 | create mode 100644 slirp/ncsi-pkt.h | ||
47 | create mode 100644 slirp/ncsi.c | ||
48 | 26 | ||
27 | hw/net/e1000.c | 8 ++------ | ||
28 | net/colo-compare.c | 27 ++++++++++++++++++++------- | ||
29 | net/tap.c | 19 +++++++++++-------- | ||
30 | qemu-bridge-helper.c | 24 +++++++++++++++++------- | ||
31 | 4 files changed, 50 insertions(+), 28 deletions(-) | ||
32 | |||
33 | diff view generated by jsdifflib |
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 1 | We should not raise any interrupt after VM has been stopped but this |
---|---|---|---|
2 | is what e1000 currently did when mit timer is active in | ||
3 | pre_save(). Fixing this by scheduling a timer in post_load() which can | ||
4 | make sure the interrupt was raised when VM is running. | ||
2 | 5 | ||
3 | Optimize two trace events as one, adjust print format make | 6 | Reported-and-tested-by: Longpeng <longpeng2@huawei.com> |
4 | it easy to read. rename trace_colo_compare_pkt_info_src/dst | ||
5 | to trace_colo_compare_tcp_info. | ||
6 | |||
7 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
8 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 7 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
9 | --- | 8 | --- |
10 | net/colo-compare.c | 29 +++++++++++++++++------------ | 9 | hw/net/e1000.c | 8 ++------ |
11 | net/trace-events | 3 +-- | 10 | 1 file changed, 2 insertions(+), 6 deletions(-) |
12 | 2 files changed, 18 insertions(+), 14 deletions(-) | ||
13 | 11 | ||
14 | diff --git a/net/colo-compare.c b/net/colo-compare.c | 12 | diff --git a/hw/net/e1000.c b/hw/net/e1000.c |
15 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/net/colo-compare.c | 14 | --- a/hw/net/e1000.c |
17 | +++ b/net/colo-compare.c | 15 | +++ b/hw/net/e1000.c |
18 | @@ -XXX,XX +XXX,XX @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) | 16 | @@ -XXX,XX +XXX,XX @@ static int e1000_pre_save(void *opaque) |
19 | res = -1; | 17 | E1000State *s = opaque; |
18 | NetClientState *nc = qemu_get_queue(s->nic); | ||
19 | |||
20 | - /* If the mitigation timer is active, emulate a timeout now. */ | ||
21 | - if (s->mit_timer_on) { | ||
22 | - e1000_mit_timer(s); | ||
23 | - } | ||
24 | - | ||
25 | /* | ||
26 | * If link is down and auto-negotiation is supported and ongoing, | ||
27 | * complete auto-negotiation immediately. This allows us to look | ||
28 | @@ -XXX,XX +XXX,XX @@ static int e1000_post_load(void *opaque, int version_id) | ||
29 | s->mit_irq_level = false; | ||
20 | } | 30 | } |
21 | 31 | s->mit_ide = 0; | |
22 | - if (res != 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { | 32 | - s->mit_timer_on = false; |
23 | - trace_colo_compare_pkt_info_src(inet_ntoa(ppkt->ip->ip_src), | 33 | + s->mit_timer_on = true; |
24 | - ntohl(stcp->th_seq), | 34 | + timer_mod(s->mit_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1); |
25 | - ntohl(stcp->th_ack), | 35 | |
26 | - res, stcp->th_flags, | 36 | /* nc.link_down can't be migrated, so infer link_down according |
27 | - spkt->size); | 37 | * to link status bit in mac_reg[STATUS]. |
28 | - | ||
29 | - trace_colo_compare_pkt_info_dst(inet_ntoa(ppkt->ip->ip_dst), | ||
30 | - ntohl(ptcp->th_seq), | ||
31 | - ntohl(ptcp->th_ack), | ||
32 | - res, ptcp->th_flags, | ||
33 | - ppkt->size); | ||
34 | + if (res && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { | ||
35 | + char ip_src[20], ip_dst[20]; | ||
36 | + | ||
37 | + strcpy(ip_src, inet_ntoa(ppkt->ip->ip_src)); | ||
38 | + strcpy(ip_dst, inet_ntoa(ppkt->ip->ip_dst)); | ||
39 | + | ||
40 | + trace_colo_compare_tcp_info(ip_src, | ||
41 | + ip_dst, | ||
42 | + ntohl(ptcp->th_seq), | ||
43 | + ntohl(stcp->th_seq), | ||
44 | + ntohl(ptcp->th_ack), | ||
45 | + ntohl(stcp->th_ack), | ||
46 | + res, | ||
47 | + ptcp->th_flags, | ||
48 | + stcp->th_flags, | ||
49 | + ppkt->size, | ||
50 | + spkt->size); | ||
51 | |||
52 | qemu_hexdump((char *)ppkt->data, stderr, | ||
53 | "colo-compare ppkt", ppkt->size); | ||
54 | diff --git a/net/trace-events b/net/trace-events | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/net/trace-events | ||
57 | +++ b/net/trace-events | ||
58 | @@ -XXX,XX +XXX,XX @@ colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d" | ||
59 | colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s" | ||
60 | colo_old_packet_check_found(int64_t old_time) "%" PRId64 | ||
61 | colo_compare_miscompare(void) "" | ||
62 | -colo_compare_pkt_info_src(const char *src, uint32_t sseq, uint32_t sack, int res, uint32_t sflag, int ssize) "src/dst: %s s: seq/ack=%u/%u res=%d flags=%x spkt_size: %d\n" | ||
63 | -colo_compare_pkt_info_dst(const char *dst, uint32_t dseq, uint32_t dack, int res, uint32_t dflag, int dsize) "src/dst: %s d: seq/ack=%u/%u res=%d flags=%x dpkt_size: %d\n" | ||
64 | +colo_compare_tcp_info(const char *src, const char *dst, uint32_t pseq, uint32_t sseq, uint32_t pack, uint32_t sack, int res, uint32_t pflag, uint32_t sflag, int psize, int ssize) "src/dst: %s/%s pseq/sseq:%u/%u pack/sack:%u/%u res=%d pflags/sflag:%x/%x psize/ssize:%d/%d \n" | ||
65 | |||
66 | # net/filter-rewriter.c | ||
67 | colo_filter_rewriter_debug(void) "" | ||
68 | -- | 38 | -- |
69 | 2.7.4 | 39 | 2.5.0 |
70 | 40 | ||
71 | 41 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | From: Prasad J Pandit <pjp@fedoraproject.org> |
---|---|---|---|
2 | 2 | ||
3 | The FTGMAC100 device is an Ethernet controller with DMA function that | 3 | The network interface name in Linux is defined to be of size |
4 | can be found on Aspeed SoCs (which include NCSI). | 4 | IFNAMSIZ(=16), including the terminating null('\0') byte. |
5 | The same is applied to interface names read from 'bridge.conf' | ||
6 | file to form ACL rules. If user supplied '--br=bridge' name | ||
7 | is not restricted to the same length, it could lead to ACL bypass | ||
8 | issue. Restrict interface name to IFNAMSIZ, including null byte. | ||
5 | 9 | ||
6 | It is fully compliant with IEEE 802.3 specification for 10/100 Mbps | 10 | Reported-by: Riccardo Schirone <rschiron@redhat.com> |
7 | Ethernet and IEEE 802.3z specification for 1000 Mbps Ethernet and | 11 | Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org> |
8 | includes Reduced Media Independent Interface (RMII) and Reduced | 12 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | Gigabit Media Independent Interface (RGMII) interfaces. It adopts an | 13 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> |
10 | AHB bus interface and integrates a link list DMA engine with direct | 14 | Reviewed-by: Li Qiang <liq3ea@gmail.com> |
11 | M-Bus accesses for transmitting and receiving packets. It has | ||
12 | independent TX/RX fifos, supports half and full duplex (1000 Mbps mode | ||
13 | only supports full duplex), flow control for full duplex and | ||
14 | backpressure for half duplex. | ||
15 | |||
16 | The FTGMAC100 also implements IP, TCP, UDP checksum offloads and | ||
17 | supports IEEE 802.1Q VLAN tag insertion and removal. It offers | ||
18 | high-priority transmit queue for QoS and CoS applications | ||
19 | |||
20 | This model is backed with a RealTek 8211E PHY which is the chip found | ||
21 | on the AST2500 EVB. It is complete enough to satisfy two different | ||
22 | Linux drivers and a U-Boot driver. Not supported features are : | ||
23 | |||
24 | - IEEE 802.1Q VLAN | ||
25 | - High Priority Transmit Queue | ||
26 | - Wake-On-LAN functions | ||
27 | |||
28 | The code is based on the Coldfire Fast Ethernet Controller model. | ||
29 | |||
30 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
31 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 15 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
32 | --- | 16 | --- |
33 | default-configs/arm-softmmu.mak | 1 + | 17 | qemu-bridge-helper.c | 11 +++++++++++ |
34 | hw/net/Makefile.objs | 1 + | 18 | 1 file changed, 11 insertions(+) |
35 | hw/net/ftgmac100.c | 1003 +++++++++++++++++++++++++++++++++++++++ | ||
36 | include/hw/net/ftgmac100.h | 60 +++ | ||
37 | 4 files changed, 1065 insertions(+) | ||
38 | create mode 100644 hw/net/ftgmac100.c | ||
39 | create mode 100644 include/hw/net/ftgmac100.h | ||
40 | 19 | ||
41 | diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak | 20 | diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c |
42 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
43 | --- a/default-configs/arm-softmmu.mak | 22 | --- a/qemu-bridge-helper.c |
44 | +++ b/default-configs/arm-softmmu.mak | 23 | +++ b/qemu-bridge-helper.c |
45 | @@ -XXX,XX +XXX,XX @@ CONFIG_LAN9118=y | 24 | @@ -XXX,XX +XXX,XX @@ static int parse_acl_file(const char *filename, ACLList *acl_list) |
46 | CONFIG_SMC91C111=y | 25 | } |
47 | CONFIG_ALLWINNER_EMAC=y | 26 | *argend = 0; |
48 | CONFIG_IMX_FEC=y | 27 | |
49 | +CONFIG_FTGMAC100=y | 28 | + if (!g_str_equal(cmd, "include") && strlen(arg) >= IFNAMSIZ) { |
50 | CONFIG_DS1338=y | 29 | + fprintf(stderr, "name `%s' too long: %zu\n", arg, strlen(arg)); |
51 | CONFIG_PFLASH_CFI01=y | 30 | + fclose(f); |
52 | CONFIG_PFLASH_CFI02=y | 31 | + errno = EINVAL; |
53 | diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/hw/net/Makefile.objs | ||
56 | +++ b/hw/net/Makefile.objs | ||
57 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_IMX_FEC) += imx_fec.o | ||
58 | common-obj-$(CONFIG_CADENCE) += cadence_gem.o | ||
59 | common-obj-$(CONFIG_STELLARIS_ENET) += stellaris_enet.o | ||
60 | common-obj-$(CONFIG_LANCE) += lance.o | ||
61 | +common-obj-$(CONFIG_FTGMAC100) += ftgmac100.o | ||
62 | |||
63 | obj-$(CONFIG_ETRAXFS) += etraxfs_eth.o | ||
64 | obj-$(CONFIG_COLDFIRE) += mcf_fec.o | ||
65 | diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c | ||
66 | new file mode 100644 | ||
67 | index XXXXXXX..XXXXXXX | ||
68 | --- /dev/null | ||
69 | +++ b/hw/net/ftgmac100.c | ||
70 | @@ -XXX,XX +XXX,XX @@ | ||
71 | +/* | ||
72 | + * Faraday FTGMAC100 Gigabit Ethernet | ||
73 | + * | ||
74 | + * Copyright (C) 2016-2017, IBM Corporation. | ||
75 | + * | ||
76 | + * Based on Coldfire Fast Ethernet Controller emulation. | ||
77 | + * | ||
78 | + * Copyright (c) 2007 CodeSourcery. | ||
79 | + * | ||
80 | + * This code is licensed under the GPL version 2 or later. See the | ||
81 | + * COPYING file in the top-level directory. | ||
82 | + */ | ||
83 | + | ||
84 | +#include "qemu/osdep.h" | ||
85 | +#include "hw/net/ftgmac100.h" | ||
86 | +#include "sysemu/dma.h" | ||
87 | +#include "qemu/log.h" | ||
88 | +#include "net/checksum.h" | ||
89 | +#include "net/eth.h" | ||
90 | +#include "hw/net/mii.h" | ||
91 | + | ||
92 | +/* For crc32 */ | ||
93 | +#include <zlib.h> | ||
94 | + | ||
95 | +/* | ||
96 | + * FTGMAC100 registers | ||
97 | + */ | ||
98 | +#define FTGMAC100_ISR 0x00 | ||
99 | +#define FTGMAC100_IER 0x04 | ||
100 | +#define FTGMAC100_MAC_MADR 0x08 | ||
101 | +#define FTGMAC100_MAC_LADR 0x0c | ||
102 | +#define FTGMAC100_MATH0 0x10 | ||
103 | +#define FTGMAC100_MATH1 0x14 | ||
104 | +#define FTGMAC100_NPTXPD 0x18 | ||
105 | +#define FTGMAC100_RXPD 0x1C | ||
106 | +#define FTGMAC100_NPTXR_BADR 0x20 | ||
107 | +#define FTGMAC100_RXR_BADR 0x24 | ||
108 | +#define FTGMAC100_HPTXPD 0x28 | ||
109 | +#define FTGMAC100_HPTXR_BADR 0x2c | ||
110 | +#define FTGMAC100_ITC 0x30 | ||
111 | +#define FTGMAC100_APTC 0x34 | ||
112 | +#define FTGMAC100_DBLAC 0x38 | ||
113 | +#define FTGMAC100_REVR 0x40 | ||
114 | +#define FTGMAC100_FEAR1 0x44 | ||
115 | +#define FTGMAC100_RBSR 0x4c | ||
116 | +#define FTGMAC100_TPAFCR 0x48 | ||
117 | + | ||
118 | +#define FTGMAC100_MACCR 0x50 | ||
119 | +#define FTGMAC100_MACSR 0x54 | ||
120 | +#define FTGMAC100_PHYCR 0x60 | ||
121 | +#define FTGMAC100_PHYDATA 0x64 | ||
122 | +#define FTGMAC100_FCR 0x68 | ||
123 | + | ||
124 | +/* | ||
125 | + * Interrupt status register & interrupt enable register | ||
126 | + */ | ||
127 | +#define FTGMAC100_INT_RPKT_BUF (1 << 0) | ||
128 | +#define FTGMAC100_INT_RPKT_FIFO (1 << 1) | ||
129 | +#define FTGMAC100_INT_NO_RXBUF (1 << 2) | ||
130 | +#define FTGMAC100_INT_RPKT_LOST (1 << 3) | ||
131 | +#define FTGMAC100_INT_XPKT_ETH (1 << 4) | ||
132 | +#define FTGMAC100_INT_XPKT_FIFO (1 << 5) | ||
133 | +#define FTGMAC100_INT_NO_NPTXBUF (1 << 6) | ||
134 | +#define FTGMAC100_INT_XPKT_LOST (1 << 7) | ||
135 | +#define FTGMAC100_INT_AHB_ERR (1 << 8) | ||
136 | +#define FTGMAC100_INT_PHYSTS_CHG (1 << 9) | ||
137 | +#define FTGMAC100_INT_NO_HPTXBUF (1 << 10) | ||
138 | + | ||
139 | +/* | ||
140 | + * Automatic polling timer control register | ||
141 | + */ | ||
142 | +#define FTGMAC100_APTC_RXPOLL_CNT(x) ((x) & 0xf) | ||
143 | +#define FTGMAC100_APTC_RXPOLL_TIME_SEL (1 << 4) | ||
144 | +#define FTGMAC100_APTC_TXPOLL_CNT(x) (((x) >> 8) & 0xf) | ||
145 | +#define FTGMAC100_APTC_TXPOLL_TIME_SEL (1 << 12) | ||
146 | + | ||
147 | +/* | ||
148 | + * PHY control register | ||
149 | + */ | ||
150 | +#define FTGMAC100_PHYCR_MIIRD (1 << 26) | ||
151 | +#define FTGMAC100_PHYCR_MIIWR (1 << 27) | ||
152 | + | ||
153 | +#define FTGMAC100_PHYCR_DEV(x) (((x) >> 16) & 0x1f) | ||
154 | +#define FTGMAC100_PHYCR_REG(x) (((x) >> 21) & 0x1f) | ||
155 | + | ||
156 | +/* | ||
157 | + * PHY data register | ||
158 | + */ | ||
159 | +#define FTGMAC100_PHYDATA_MIIWDATA(x) ((x) & 0xffff) | ||
160 | +#define FTGMAC100_PHYDATA_MIIRDATA(x) (((x) >> 16) & 0xffff) | ||
161 | + | ||
162 | +/* | ||
163 | + * Feature Register | ||
164 | + */ | ||
165 | +#define FTGMAC100_REVR_NEW_MDIO_INTERFACE (1 << 31) | ||
166 | + | ||
167 | +/* | ||
168 | + * MAC control register | ||
169 | + */ | ||
170 | +#define FTGMAC100_MACCR_TXDMA_EN (1 << 0) | ||
171 | +#define FTGMAC100_MACCR_RXDMA_EN (1 << 1) | ||
172 | +#define FTGMAC100_MACCR_TXMAC_EN (1 << 2) | ||
173 | +#define FTGMAC100_MACCR_RXMAC_EN (1 << 3) | ||
174 | +#define FTGMAC100_MACCR_RM_VLAN (1 << 4) | ||
175 | +#define FTGMAC100_MACCR_HPTXR_EN (1 << 5) | ||
176 | +#define FTGMAC100_MACCR_LOOP_EN (1 << 6) | ||
177 | +#define FTGMAC100_MACCR_ENRX_IN_HALFTX (1 << 7) | ||
178 | +#define FTGMAC100_MACCR_FULLDUP (1 << 8) | ||
179 | +#define FTGMAC100_MACCR_GIGA_MODE (1 << 9) | ||
180 | +#define FTGMAC100_MACCR_CRC_APD (1 << 10) /* not needed */ | ||
181 | +#define FTGMAC100_MACCR_RX_RUNT (1 << 12) | ||
182 | +#define FTGMAC100_MACCR_JUMBO_LF (1 << 13) | ||
183 | +#define FTGMAC100_MACCR_RX_ALL (1 << 14) | ||
184 | +#define FTGMAC100_MACCR_HT_MULTI_EN (1 << 15) | ||
185 | +#define FTGMAC100_MACCR_RX_MULTIPKT (1 << 16) | ||
186 | +#define FTGMAC100_MACCR_RX_BROADPKT (1 << 17) | ||
187 | +#define FTGMAC100_MACCR_DISCARD_CRCERR (1 << 18) | ||
188 | +#define FTGMAC100_MACCR_FAST_MODE (1 << 19) | ||
189 | +#define FTGMAC100_MACCR_SW_RST (1 << 31) | ||
190 | + | ||
191 | +/* | ||
192 | + * Transmit descriptor | ||
193 | + */ | ||
194 | +#define FTGMAC100_TXDES0_TXBUF_SIZE(x) ((x) & 0x3fff) | ||
195 | +#define FTGMAC100_TXDES0_EDOTR (1 << 15) | ||
196 | +#define FTGMAC100_TXDES0_CRC_ERR (1 << 19) | ||
197 | +#define FTGMAC100_TXDES0_LTS (1 << 28) | ||
198 | +#define FTGMAC100_TXDES0_FTS (1 << 29) | ||
199 | +#define FTGMAC100_TXDES0_TXDMA_OWN (1 << 31) | ||
200 | + | ||
201 | +#define FTGMAC100_TXDES1_VLANTAG_CI(x) ((x) & 0xffff) | ||
202 | +#define FTGMAC100_TXDES1_INS_VLANTAG (1 << 16) | ||
203 | +#define FTGMAC100_TXDES1_TCP_CHKSUM (1 << 17) | ||
204 | +#define FTGMAC100_TXDES1_UDP_CHKSUM (1 << 18) | ||
205 | +#define FTGMAC100_TXDES1_IP_CHKSUM (1 << 19) | ||
206 | +#define FTGMAC100_TXDES1_LLC (1 << 22) | ||
207 | +#define FTGMAC100_TXDES1_TX2FIC (1 << 30) | ||
208 | +#define FTGMAC100_TXDES1_TXIC (1 << 31) | ||
209 | + | ||
210 | +/* | ||
211 | + * Receive descriptor | ||
212 | + */ | ||
213 | +#define FTGMAC100_RXDES0_VDBC 0x3fff | ||
214 | +#define FTGMAC100_RXDES0_EDORR (1 << 15) | ||
215 | +#define FTGMAC100_RXDES0_MULTICAST (1 << 16) | ||
216 | +#define FTGMAC100_RXDES0_BROADCAST (1 << 17) | ||
217 | +#define FTGMAC100_RXDES0_RX_ERR (1 << 18) | ||
218 | +#define FTGMAC100_RXDES0_CRC_ERR (1 << 19) | ||
219 | +#define FTGMAC100_RXDES0_FTL (1 << 20) | ||
220 | +#define FTGMAC100_RXDES0_RUNT (1 << 21) | ||
221 | +#define FTGMAC100_RXDES0_RX_ODD_NB (1 << 22) | ||
222 | +#define FTGMAC100_RXDES0_FIFO_FULL (1 << 23) | ||
223 | +#define FTGMAC100_RXDES0_PAUSE_OPCODE (1 << 24) | ||
224 | +#define FTGMAC100_RXDES0_PAUSE_FRAME (1 << 25) | ||
225 | +#define FTGMAC100_RXDES0_LRS (1 << 28) | ||
226 | +#define FTGMAC100_RXDES0_FRS (1 << 29) | ||
227 | +#define FTGMAC100_RXDES0_RXPKT_RDY (1 << 31) | ||
228 | + | ||
229 | +#define FTGMAC100_RXDES1_VLANTAG_CI 0xffff | ||
230 | +#define FTGMAC100_RXDES1_PROT_MASK (0x3 << 20) | ||
231 | +#define FTGMAC100_RXDES1_PROT_NONIP (0x0 << 20) | ||
232 | +#define FTGMAC100_RXDES1_PROT_IP (0x1 << 20) | ||
233 | +#define FTGMAC100_RXDES1_PROT_TCPIP (0x2 << 20) | ||
234 | +#define FTGMAC100_RXDES1_PROT_UDPIP (0x3 << 20) | ||
235 | +#define FTGMAC100_RXDES1_LLC (1 << 22) | ||
236 | +#define FTGMAC100_RXDES1_DF (1 << 23) | ||
237 | +#define FTGMAC100_RXDES1_VLANTAG_AVAIL (1 << 24) | ||
238 | +#define FTGMAC100_RXDES1_TCP_CHKSUM_ERR (1 << 25) | ||
239 | +#define FTGMAC100_RXDES1_UDP_CHKSUM_ERR (1 << 26) | ||
240 | +#define FTGMAC100_RXDES1_IP_CHKSUM_ERR (1 << 27) | ||
241 | + | ||
242 | +/* | ||
243 | + * Receive and transmit Buffer Descriptor | ||
244 | + */ | ||
245 | +typedef struct { | ||
246 | + uint32_t des0; | ||
247 | + uint32_t des1; | ||
248 | + uint32_t des2; /* not used by HW */ | ||
249 | + uint32_t des3; | ||
250 | +} FTGMAC100Desc; | ||
251 | + | ||
252 | +/* | ||
253 | + * Specific RTL8211E MII Registers | ||
254 | + */ | ||
255 | +#define RTL8211E_MII_PHYCR 16 /* PHY Specific Control */ | ||
256 | +#define RTL8211E_MII_PHYSR 17 /* PHY Specific Status */ | ||
257 | +#define RTL8211E_MII_INER 18 /* Interrupt Enable */ | ||
258 | +#define RTL8211E_MII_INSR 19 /* Interrupt Status */ | ||
259 | +#define RTL8211E_MII_RXERC 24 /* Receive Error Counter */ | ||
260 | +#define RTL8211E_MII_LDPSR 27 /* Link Down Power Saving */ | ||
261 | +#define RTL8211E_MII_EPAGSR 30 /* Extension Page Select */ | ||
262 | +#define RTL8211E_MII_PAGSEL 31 /* Page Select */ | ||
263 | + | ||
264 | +/* | ||
265 | + * RTL8211E Interrupt Status | ||
266 | + */ | ||
267 | +#define PHY_INT_AUTONEG_ERROR (1 << 15) | ||
268 | +#define PHY_INT_PAGE_RECV (1 << 12) | ||
269 | +#define PHY_INT_AUTONEG_COMPLETE (1 << 11) | ||
270 | +#define PHY_INT_LINK_STATUS (1 << 10) | ||
271 | +#define PHY_INT_ERROR (1 << 9) | ||
272 | +#define PHY_INT_DOWN (1 << 8) | ||
273 | +#define PHY_INT_JABBER (1 << 0) | ||
274 | + | ||
275 | +/* | ||
276 | + * Max frame size for the receiving buffer | ||
277 | + */ | ||
278 | +#define FTGMAC100_MAX_FRAME_SIZE 10240 | ||
279 | + | ||
280 | +/* Limits depending on the type of the frame | ||
281 | + * | ||
282 | + * 9216 for Jumbo frames (+ 4 for VLAN) | ||
283 | + * 1518 for other frames (+ 4 for VLAN) | ||
284 | + */ | ||
285 | +static int ftgmac100_max_frame_size(FTGMAC100State *s) | ||
286 | +{ | ||
287 | + return (s->maccr & FTGMAC100_MACCR_JUMBO_LF ? 9216 : 1518) + 4; | ||
288 | +} | ||
289 | + | ||
290 | +static void ftgmac100_update_irq(FTGMAC100State *s) | ||
291 | +{ | ||
292 | + qemu_set_irq(s->irq, s->isr & s->ier); | ||
293 | +} | ||
294 | + | ||
295 | +/* | ||
296 | + * The MII phy could raise a GPIO to the processor which in turn | ||
297 | + * could be handled as an interrpt by the OS. | ||
298 | + * For now we don't handle any GPIO/interrupt line, so the OS will | ||
299 | + * have to poll for the PHY status. | ||
300 | + */ | ||
301 | +static void phy_update_irq(FTGMAC100State *s) | ||
302 | +{ | ||
303 | + ftgmac100_update_irq(s); | ||
304 | +} | ||
305 | + | ||
306 | +static void phy_update_link(FTGMAC100State *s) | ||
307 | +{ | ||
308 | + /* Autonegotiation status mirrors link status. */ | ||
309 | + if (qemu_get_queue(s->nic)->link_down) { | ||
310 | + s->phy_status &= ~(MII_BMSR_LINK_ST | MII_BMSR_AN_COMP); | ||
311 | + s->phy_int |= PHY_INT_DOWN; | ||
312 | + } else { | ||
313 | + s->phy_status |= (MII_BMSR_LINK_ST | MII_BMSR_AN_COMP); | ||
314 | + s->phy_int |= PHY_INT_AUTONEG_COMPLETE; | ||
315 | + } | ||
316 | + phy_update_irq(s); | ||
317 | +} | ||
318 | + | ||
319 | +static void ftgmac100_set_link(NetClientState *nc) | ||
320 | +{ | ||
321 | + phy_update_link(FTGMAC100(qemu_get_nic_opaque(nc))); | ||
322 | +} | ||
323 | + | ||
324 | +static void phy_reset(FTGMAC100State *s) | ||
325 | +{ | ||
326 | + s->phy_status = (MII_BMSR_100TX_FD | MII_BMSR_100TX_HD | MII_BMSR_10T_FD | | ||
327 | + MII_BMSR_10T_HD | MII_BMSR_EXTSTAT | MII_BMSR_MFPS | | ||
328 | + MII_BMSR_AN_COMP | MII_BMSR_AUTONEG | MII_BMSR_LINK_ST | | ||
329 | + MII_BMSR_EXTCAP); | ||
330 | + s->phy_control = (MII_BMCR_AUTOEN | MII_BMCR_FD | MII_BMCR_SPEED1000); | ||
331 | + s->phy_advertise = (MII_ANAR_PAUSE_ASYM | MII_ANAR_PAUSE | MII_ANAR_TXFD | | ||
332 | + MII_ANAR_TX | MII_ANAR_10FD | MII_ANAR_10 | | ||
333 | + MII_ANAR_CSMACD); | ||
334 | + s->phy_int_mask = 0; | ||
335 | + s->phy_int = 0; | ||
336 | +} | ||
337 | + | ||
338 | +static uint32_t do_phy_read(FTGMAC100State *s, int reg) | ||
339 | +{ | ||
340 | + uint32_t val; | ||
341 | + | ||
342 | + switch (reg) { | ||
343 | + case MII_BMCR: /* Basic Control */ | ||
344 | + val = s->phy_control; | ||
345 | + break; | ||
346 | + case MII_BMSR: /* Basic Status */ | ||
347 | + val = s->phy_status; | ||
348 | + break; | ||
349 | + case MII_PHYID1: /* ID1 */ | ||
350 | + val = RTL8211E_PHYID1; | ||
351 | + break; | ||
352 | + case MII_PHYID2: /* ID2 */ | ||
353 | + val = RTL8211E_PHYID2; | ||
354 | + break; | ||
355 | + case MII_ANAR: /* Auto-neg advertisement */ | ||
356 | + val = s->phy_advertise; | ||
357 | + break; | ||
358 | + case MII_ANLPAR: /* Auto-neg Link Partner Ability */ | ||
359 | + val = (MII_ANLPAR_ACK | MII_ANLPAR_PAUSE | MII_ANLPAR_TXFD | | ||
360 | + MII_ANLPAR_TX | MII_ANLPAR_10FD | MII_ANLPAR_10 | | ||
361 | + MII_ANLPAR_CSMACD); | ||
362 | + break; | ||
363 | + case MII_ANER: /* Auto-neg Expansion */ | ||
364 | + val = MII_ANER_NWAY; | ||
365 | + break; | ||
366 | + case MII_CTRL1000: /* 1000BASE-T control */ | ||
367 | + val = (MII_CTRL1000_HALF | MII_CTRL1000_FULL); | ||
368 | + break; | ||
369 | + case MII_STAT1000: /* 1000BASE-T status */ | ||
370 | + val = MII_STAT1000_FULL; | ||
371 | + break; | ||
372 | + case RTL8211E_MII_INSR: /* Interrupt status. */ | ||
373 | + val = s->phy_int; | ||
374 | + s->phy_int = 0; | ||
375 | + phy_update_irq(s); | ||
376 | + break; | ||
377 | + case RTL8211E_MII_INER: /* Interrupt enable */ | ||
378 | + val = s->phy_int_mask; | ||
379 | + break; | ||
380 | + case RTL8211E_MII_PHYCR: | ||
381 | + case RTL8211E_MII_PHYSR: | ||
382 | + case RTL8211E_MII_RXERC: | ||
383 | + case RTL8211E_MII_LDPSR: | ||
384 | + case RTL8211E_MII_EPAGSR: | ||
385 | + case RTL8211E_MII_PAGSEL: | ||
386 | + qemu_log_mask(LOG_UNIMP, "%s: reg %d not implemented\n", | ||
387 | + __func__, reg); | ||
388 | + val = 0; | ||
389 | + break; | ||
390 | + default: | ||
391 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset %d\n", | ||
392 | + __func__, reg); | ||
393 | + val = 0; | ||
394 | + break; | ||
395 | + } | ||
396 | + | ||
397 | + return val; | ||
398 | +} | ||
399 | + | ||
400 | +#define MII_BMCR_MASK (MII_BMCR_LOOPBACK | MII_BMCR_SPEED100 | \ | ||
401 | + MII_BMCR_SPEED | MII_BMCR_AUTOEN | MII_BMCR_PDOWN | \ | ||
402 | + MII_BMCR_FD | MII_BMCR_CTST) | ||
403 | +#define MII_ANAR_MASK 0x2d7f | ||
404 | + | ||
405 | +static void do_phy_write(FTGMAC100State *s, int reg, uint32_t val) | ||
406 | +{ | ||
407 | + switch (reg) { | ||
408 | + case MII_BMCR: /* Basic Control */ | ||
409 | + if (val & MII_BMCR_RESET) { | ||
410 | + phy_reset(s); | ||
411 | + } else { | ||
412 | + s->phy_control = val & MII_BMCR_MASK; | ||
413 | + /* Complete autonegotiation immediately. */ | ||
414 | + if (val & MII_BMCR_AUTOEN) { | ||
415 | + s->phy_status |= MII_BMSR_AN_COMP; | ||
416 | + } | ||
417 | + } | ||
418 | + break; | ||
419 | + case MII_ANAR: /* Auto-neg advertisement */ | ||
420 | + s->phy_advertise = (val & MII_ANAR_MASK) | MII_ANAR_TX; | ||
421 | + break; | ||
422 | + case RTL8211E_MII_INER: /* Interrupt enable */ | ||
423 | + s->phy_int_mask = val & 0xff; | ||
424 | + phy_update_irq(s); | ||
425 | + break; | ||
426 | + case RTL8211E_MII_PHYCR: | ||
427 | + case RTL8211E_MII_PHYSR: | ||
428 | + case RTL8211E_MII_RXERC: | ||
429 | + case RTL8211E_MII_LDPSR: | ||
430 | + case RTL8211E_MII_EPAGSR: | ||
431 | + case RTL8211E_MII_PAGSEL: | ||
432 | + qemu_log_mask(LOG_UNIMP, "%s: reg %d not implemented\n", | ||
433 | + __func__, reg); | ||
434 | + break; | ||
435 | + default: | ||
436 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset %d\n", | ||
437 | + __func__, reg); | ||
438 | + break; | ||
439 | + } | ||
440 | +} | ||
441 | + | ||
442 | +static int ftgmac100_read_bd(FTGMAC100Desc *bd, dma_addr_t addr) | ||
443 | +{ | ||
444 | + if (dma_memory_read(&address_space_memory, addr, bd, sizeof(*bd))) { | ||
445 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to read descriptor @ 0x%" | ||
446 | + HWADDR_PRIx "\n", __func__, addr); | ||
447 | + return -1; | ||
448 | + } | ||
449 | + bd->des0 = le32_to_cpu(bd->des0); | ||
450 | + bd->des1 = le32_to_cpu(bd->des1); | ||
451 | + bd->des2 = le32_to_cpu(bd->des2); | ||
452 | + bd->des3 = le32_to_cpu(bd->des3); | ||
453 | + return 0; | ||
454 | +} | ||
455 | + | ||
456 | +static int ftgmac100_write_bd(FTGMAC100Desc *bd, dma_addr_t addr) | ||
457 | +{ | ||
458 | + FTGMAC100Desc lebd; | ||
459 | + | ||
460 | + lebd.des0 = cpu_to_le32(bd->des0); | ||
461 | + lebd.des1 = cpu_to_le32(bd->des1); | ||
462 | + lebd.des2 = cpu_to_le32(bd->des2); | ||
463 | + lebd.des3 = cpu_to_le32(bd->des3); | ||
464 | + if (dma_memory_write(&address_space_memory, addr, &lebd, sizeof(lebd))) { | ||
465 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to write descriptor @ 0x%" | ||
466 | + HWADDR_PRIx "\n", __func__, addr); | ||
467 | + return -1; | ||
468 | + } | ||
469 | + return 0; | ||
470 | +} | ||
471 | + | ||
472 | +static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring, | ||
473 | + uint32_t tx_descriptor) | ||
474 | +{ | ||
475 | + int frame_size = 0; | ||
476 | + uint8_t *ptr = s->frame; | ||
477 | + uint32_t addr = tx_descriptor; | ||
478 | + uint32_t flags = 0; | ||
479 | + int max_frame_size = ftgmac100_max_frame_size(s); | ||
480 | + | ||
481 | + while (1) { | ||
482 | + FTGMAC100Desc bd; | ||
483 | + int len; | ||
484 | + | ||
485 | + if (ftgmac100_read_bd(&bd, addr) || | ||
486 | + ((bd.des0 & FTGMAC100_TXDES0_TXDMA_OWN) == 0)) { | ||
487 | + /* Run out of descriptors to transmit. */ | ||
488 | + s->isr |= FTGMAC100_INT_NO_NPTXBUF; | ||
489 | + break; | ||
490 | + } | ||
491 | + | ||
492 | + /* record transmit flags as they are valid only on the first | ||
493 | + * segment */ | ||
494 | + if (bd.des0 & FTGMAC100_TXDES0_FTS) { | ||
495 | + flags = bd.des1; | ||
496 | + } | ||
497 | + | ||
498 | + len = bd.des0 & 0x3FFF; | ||
499 | + if (frame_size + len > max_frame_size) { | ||
500 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: frame too big : %d bytes\n", | ||
501 | + __func__, len); | ||
502 | + len = max_frame_size - frame_size; | ||
503 | + } | ||
504 | + | ||
505 | + if (dma_memory_read(&address_space_memory, bd.des3, ptr, len)) { | ||
506 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to read packet @ 0x%x\n", | ||
507 | + __func__, bd.des3); | ||
508 | + s->isr |= FTGMAC100_INT_NO_NPTXBUF; | ||
509 | + break; | ||
510 | + } | ||
511 | + | ||
512 | + ptr += len; | ||
513 | + frame_size += len; | ||
514 | + if (bd.des0 & FTGMAC100_TXDES0_LTS) { | ||
515 | + if (flags & FTGMAC100_TXDES1_IP_CHKSUM) { | ||
516 | + net_checksum_calculate(s->frame, frame_size); | ||
517 | + } | ||
518 | + /* Last buffer in frame. */ | ||
519 | + qemu_send_packet(qemu_get_queue(s->nic), s->frame, frame_size); | ||
520 | + ptr = s->frame; | ||
521 | + frame_size = 0; | ||
522 | + if (flags & FTGMAC100_TXDES1_TXIC) { | ||
523 | + s->isr |= FTGMAC100_INT_XPKT_ETH; | ||
524 | + } | ||
525 | + } | ||
526 | + | ||
527 | + if (flags & FTGMAC100_TXDES1_TX2FIC) { | ||
528 | + s->isr |= FTGMAC100_INT_XPKT_FIFO; | ||
529 | + } | ||
530 | + bd.des0 &= ~FTGMAC100_TXDES0_TXDMA_OWN; | ||
531 | + | ||
532 | + /* Write back the modified descriptor. */ | ||
533 | + ftgmac100_write_bd(&bd, addr); | ||
534 | + /* Advance to the next descriptor. */ | ||
535 | + if (bd.des0 & FTGMAC100_TXDES0_EDOTR) { | ||
536 | + addr = tx_ring; | ||
537 | + } else { | ||
538 | + addr += sizeof(FTGMAC100Desc); | ||
539 | + } | ||
540 | + } | ||
541 | + | ||
542 | + s->tx_descriptor = addr; | ||
543 | + | ||
544 | + ftgmac100_update_irq(s); | ||
545 | +} | ||
546 | + | ||
547 | +static int ftgmac100_can_receive(NetClientState *nc) | ||
548 | +{ | ||
549 | + FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc)); | ||
550 | + FTGMAC100Desc bd; | ||
551 | + | ||
552 | + if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN)) | ||
553 | + != (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN)) { | ||
554 | + return 0; | ||
555 | + } | ||
556 | + | ||
557 | + if (ftgmac100_read_bd(&bd, s->rx_descriptor)) { | ||
558 | + return 0; | ||
559 | + } | ||
560 | + return !(bd.des0 & FTGMAC100_RXDES0_RXPKT_RDY); | ||
561 | +} | ||
562 | + | ||
563 | +/* | ||
564 | + * This is purely informative. The HW can poll the RW (and RX) ring | ||
565 | + * buffers for available descriptors but we don't need to trigger a | ||
566 | + * timer for that in qemu. | ||
567 | + */ | ||
568 | +static uint32_t ftgmac100_rxpoll(FTGMAC100State *s) | ||
569 | +{ | ||
570 | + /* Polling times : | ||
571 | + * | ||
572 | + * Speed TIME_SEL=0 TIME_SEL=1 | ||
573 | + * | ||
574 | + * 10 51.2 ms 819.2 ms | ||
575 | + * 100 5.12 ms 81.92 ms | ||
576 | + * 1000 1.024 ms 16.384 ms | ||
577 | + */ | ||
578 | + static const int div[] = { 20, 200, 1000 }; | ||
579 | + | ||
580 | + uint32_t cnt = 1024 * FTGMAC100_APTC_RXPOLL_CNT(s->aptcr); | ||
581 | + uint32_t speed = (s->maccr & FTGMAC100_MACCR_FAST_MODE) ? 1 : 0; | ||
582 | + uint32_t period; | ||
583 | + | ||
584 | + if (s->aptcr & FTGMAC100_APTC_RXPOLL_TIME_SEL) { | ||
585 | + cnt <<= 4; | ||
586 | + } | ||
587 | + | ||
588 | + if (s->maccr & FTGMAC100_MACCR_GIGA_MODE) { | ||
589 | + speed = 2; | ||
590 | + } | ||
591 | + | ||
592 | + period = cnt / div[speed]; | ||
593 | + | ||
594 | + return period; | ||
595 | +} | ||
596 | + | ||
597 | +static void ftgmac100_reset(DeviceState *d) | ||
598 | +{ | ||
599 | + FTGMAC100State *s = FTGMAC100(d); | ||
600 | + | ||
601 | + /* Reset the FTGMAC100 */ | ||
602 | + s->isr = 0; | ||
603 | + s->ier = 0; | ||
604 | + s->rx_enabled = 0; | ||
605 | + s->rx_ring = 0; | ||
606 | + s->rbsr = 0x640; | ||
607 | + s->rx_descriptor = 0; | ||
608 | + s->tx_ring = 0; | ||
609 | + s->tx_descriptor = 0; | ||
610 | + s->math[0] = 0; | ||
611 | + s->math[1] = 0; | ||
612 | + s->itc = 0; | ||
613 | + s->aptcr = 1; | ||
614 | + s->dblac = 0x00022f00; | ||
615 | + s->revr = 0; | ||
616 | + s->fear1 = 0; | ||
617 | + s->tpafcr = 0xf1; | ||
618 | + | ||
619 | + s->maccr = 0; | ||
620 | + s->phycr = 0; | ||
621 | + s->phydata = 0; | ||
622 | + s->fcr = 0x400; | ||
623 | + | ||
624 | + /* and the PHY */ | ||
625 | + phy_reset(s); | ||
626 | +} | ||
627 | + | ||
628 | +static uint64_t ftgmac100_read(void *opaque, hwaddr addr, unsigned size) | ||
629 | +{ | ||
630 | + FTGMAC100State *s = FTGMAC100(opaque); | ||
631 | + | ||
632 | + switch (addr & 0xff) { | ||
633 | + case FTGMAC100_ISR: | ||
634 | + return s->isr; | ||
635 | + case FTGMAC100_IER: | ||
636 | + return s->ier; | ||
637 | + case FTGMAC100_MAC_MADR: | ||
638 | + return (s->conf.macaddr.a[0] << 8) | s->conf.macaddr.a[1]; | ||
639 | + case FTGMAC100_MAC_LADR: | ||
640 | + return ((uint32_t) s->conf.macaddr.a[2] << 24) | | ||
641 | + (s->conf.macaddr.a[3] << 16) | (s->conf.macaddr.a[4] << 8) | | ||
642 | + s->conf.macaddr.a[5]; | ||
643 | + case FTGMAC100_MATH0: | ||
644 | + return s->math[0]; | ||
645 | + case FTGMAC100_MATH1: | ||
646 | + return s->math[1]; | ||
647 | + case FTGMAC100_ITC: | ||
648 | + return s->itc; | ||
649 | + case FTGMAC100_DBLAC: | ||
650 | + return s->dblac; | ||
651 | + case FTGMAC100_REVR: | ||
652 | + return s->revr; | ||
653 | + case FTGMAC100_FEAR1: | ||
654 | + return s->fear1; | ||
655 | + case FTGMAC100_TPAFCR: | ||
656 | + return s->tpafcr; | ||
657 | + case FTGMAC100_FCR: | ||
658 | + return s->fcr; | ||
659 | + case FTGMAC100_MACCR: | ||
660 | + return s->maccr; | ||
661 | + case FTGMAC100_PHYCR: | ||
662 | + return s->phycr; | ||
663 | + case FTGMAC100_PHYDATA: | ||
664 | + return s->phydata; | ||
665 | + | ||
666 | + /* We might want to support these one day */ | ||
667 | + case FTGMAC100_HPTXPD: /* High Priority Transmit Poll Demand */ | ||
668 | + case FTGMAC100_HPTXR_BADR: /* High Priority Transmit Ring Base Address */ | ||
669 | + case FTGMAC100_MACSR: /* MAC Status Register (MACSR) */ | ||
670 | + qemu_log_mask(LOG_UNIMP, "%s: read to unimplemented register 0x%" | ||
671 | + HWADDR_PRIx "\n", __func__, addr); | ||
672 | + return 0; | ||
673 | + default: | ||
674 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset 0x%" | ||
675 | + HWADDR_PRIx "\n", __func__, addr); | ||
676 | + return 0; | ||
677 | + } | ||
678 | +} | ||
679 | + | ||
680 | +static void ftgmac100_write(void *opaque, hwaddr addr, | ||
681 | + uint64_t value, unsigned size) | ||
682 | +{ | ||
683 | + FTGMAC100State *s = FTGMAC100(opaque); | ||
684 | + int reg; | ||
685 | + | ||
686 | + switch (addr & 0xff) { | ||
687 | + case FTGMAC100_ISR: /* Interrupt status */ | ||
688 | + s->isr &= ~value; | ||
689 | + break; | ||
690 | + case FTGMAC100_IER: /* Interrupt control */ | ||
691 | + s->ier = value; | ||
692 | + break; | ||
693 | + case FTGMAC100_MAC_MADR: /* MAC */ | ||
694 | + s->conf.macaddr.a[0] = value >> 8; | ||
695 | + s->conf.macaddr.a[1] = value; | ||
696 | + break; | ||
697 | + case FTGMAC100_MAC_LADR: | ||
698 | + s->conf.macaddr.a[2] = value >> 24; | ||
699 | + s->conf.macaddr.a[3] = value >> 16; | ||
700 | + s->conf.macaddr.a[4] = value >> 8; | ||
701 | + s->conf.macaddr.a[5] = value; | ||
702 | + break; | ||
703 | + case FTGMAC100_MATH0: /* Multicast Address Hash Table 0 */ | ||
704 | + s->math[0] = value; | ||
705 | + break; | ||
706 | + case FTGMAC100_MATH1: /* Multicast Address Hash Table 1 */ | ||
707 | + s->math[1] = value; | ||
708 | + break; | ||
709 | + case FTGMAC100_ITC: /* TODO: Interrupt Timer Control */ | ||
710 | + s->itc = value; | ||
711 | + break; | ||
712 | + case FTGMAC100_RXR_BADR: /* Ring buffer address */ | ||
713 | + s->rx_ring = value; | ||
714 | + s->rx_descriptor = s->rx_ring; | ||
715 | + break; | ||
716 | + | ||
717 | + case FTGMAC100_RBSR: /* DMA buffer size */ | ||
718 | + s->rbsr = value; | ||
719 | + break; | ||
720 | + | ||
721 | + case FTGMAC100_NPTXR_BADR: /* Transmit buffer address */ | ||
722 | + s->tx_ring = value; | ||
723 | + s->tx_descriptor = s->tx_ring; | ||
724 | + break; | ||
725 | + | ||
726 | + case FTGMAC100_NPTXPD: /* Trigger transmit */ | ||
727 | + if ((s->maccr & (FTGMAC100_MACCR_TXDMA_EN | FTGMAC100_MACCR_TXMAC_EN)) | ||
728 | + == (FTGMAC100_MACCR_TXDMA_EN | FTGMAC100_MACCR_TXMAC_EN)) { | ||
729 | + /* TODO: high priority tx ring */ | ||
730 | + ftgmac100_do_tx(s, s->tx_ring, s->tx_descriptor); | ||
731 | + } | ||
732 | + if (ftgmac100_can_receive(qemu_get_queue(s->nic))) { | ||
733 | + qemu_flush_queued_packets(qemu_get_queue(s->nic)); | ||
734 | + } | ||
735 | + break; | ||
736 | + | ||
737 | + case FTGMAC100_RXPD: /* Receive Poll Demand Register */ | ||
738 | + if (ftgmac100_can_receive(qemu_get_queue(s->nic))) { | ||
739 | + qemu_flush_queued_packets(qemu_get_queue(s->nic)); | ||
740 | + } | ||
741 | + break; | ||
742 | + | ||
743 | + case FTGMAC100_APTC: /* Automatic polling */ | ||
744 | + s->aptcr = value; | ||
745 | + | ||
746 | + if (FTGMAC100_APTC_RXPOLL_CNT(s->aptcr)) { | ||
747 | + ftgmac100_rxpoll(s); | ||
748 | + } | ||
749 | + | ||
750 | + if (FTGMAC100_APTC_TXPOLL_CNT(s->aptcr)) { | ||
751 | + qemu_log_mask(LOG_UNIMP, "%s: no transmit polling\n", __func__); | ||
752 | + } | ||
753 | + break; | ||
754 | + | ||
755 | + case FTGMAC100_MACCR: /* MAC Device control */ | ||
756 | + s->maccr = value; | ||
757 | + if (value & FTGMAC100_MACCR_SW_RST) { | ||
758 | + ftgmac100_reset(DEVICE(s)); | ||
759 | + } | ||
760 | + | ||
761 | + if (ftgmac100_can_receive(qemu_get_queue(s->nic))) { | ||
762 | + qemu_flush_queued_packets(qemu_get_queue(s->nic)); | ||
763 | + } | ||
764 | + break; | ||
765 | + | ||
766 | + case FTGMAC100_PHYCR: /* PHY Device control */ | ||
767 | + reg = FTGMAC100_PHYCR_REG(value); | ||
768 | + s->phycr = value; | ||
769 | + if (value & FTGMAC100_PHYCR_MIIWR) { | ||
770 | + do_phy_write(s, reg, s->phydata & 0xffff); | ||
771 | + s->phycr &= ~FTGMAC100_PHYCR_MIIWR; | ||
772 | + } else { | ||
773 | + s->phydata = do_phy_read(s, reg) << 16; | ||
774 | + s->phycr &= ~FTGMAC100_PHYCR_MIIRD; | ||
775 | + } | ||
776 | + break; | ||
777 | + case FTGMAC100_PHYDATA: | ||
778 | + s->phydata = value & 0xffff; | ||
779 | + break; | ||
780 | + case FTGMAC100_DBLAC: /* DMA Burst Length and Arbitration Control */ | ||
781 | + s->dblac = value; | ||
782 | + break; | ||
783 | + case FTGMAC100_REVR: /* Feature Register */ | ||
784 | + /* TODO: Only Old MDIO interface is supported */ | ||
785 | + s->revr = value & ~FTGMAC100_REVR_NEW_MDIO_INTERFACE; | ||
786 | + break; | ||
787 | + case FTGMAC100_FEAR1: /* Feature Register 1 */ | ||
788 | + s->fear1 = value; | ||
789 | + break; | ||
790 | + case FTGMAC100_TPAFCR: /* Transmit Priority Arbitration and FIFO Control */ | ||
791 | + s->tpafcr = value; | ||
792 | + break; | ||
793 | + case FTGMAC100_FCR: /* Flow Control */ | ||
794 | + s->fcr = value; | ||
795 | + break; | ||
796 | + | ||
797 | + case FTGMAC100_HPTXPD: /* High Priority Transmit Poll Demand */ | ||
798 | + case FTGMAC100_HPTXR_BADR: /* High Priority Transmit Ring Base Address */ | ||
799 | + case FTGMAC100_MACSR: /* MAC Status Register (MACSR) */ | ||
800 | + qemu_log_mask(LOG_UNIMP, "%s: write to unimplemented register 0x%" | ||
801 | + HWADDR_PRIx "\n", __func__, addr); | ||
802 | + break; | ||
803 | + default: | ||
804 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset 0x%" | ||
805 | + HWADDR_PRIx "\n", __func__, addr); | ||
806 | + break; | ||
807 | + } | ||
808 | + | ||
809 | + ftgmac100_update_irq(s); | ||
810 | +} | ||
811 | + | ||
812 | +static int ftgmac100_filter(FTGMAC100State *s, const uint8_t *buf, size_t len) | ||
813 | +{ | ||
814 | + unsigned mcast_idx; | ||
815 | + | ||
816 | + if (s->maccr & FTGMAC100_MACCR_RX_ALL) { | ||
817 | + return 1; | ||
818 | + } | ||
819 | + | ||
820 | + switch (get_eth_packet_type(PKT_GET_ETH_HDR(buf))) { | ||
821 | + case ETH_PKT_BCAST: | ||
822 | + if (!(s->maccr & FTGMAC100_MACCR_RX_BROADPKT)) { | ||
823 | + return 0; | ||
824 | + } | ||
825 | + break; | ||
826 | + case ETH_PKT_MCAST: | ||
827 | + if (!(s->maccr & FTGMAC100_MACCR_RX_MULTIPKT)) { | ||
828 | + if (!(s->maccr & FTGMAC100_MACCR_HT_MULTI_EN)) { | ||
829 | + return 0; | ||
830 | + } | ||
831 | + | ||
832 | + /* TODO: this does not seem to work for ftgmac100 */ | ||
833 | + mcast_idx = compute_mcast_idx(buf); | ||
834 | + if (!(s->math[mcast_idx / 32] & (1 << (mcast_idx % 32)))) { | ||
835 | + return 0; | ||
836 | + } | ||
837 | + } | ||
838 | + break; | ||
839 | + case ETH_PKT_UCAST: | ||
840 | + if (memcmp(s->conf.macaddr.a, buf, 6)) { | ||
841 | + return 0; | ||
842 | + } | ||
843 | + break; | ||
844 | + } | ||
845 | + | ||
846 | + return 1; | ||
847 | +} | ||
848 | + | ||
849 | +static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf, | ||
850 | + size_t len) | ||
851 | +{ | ||
852 | + FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc)); | ||
853 | + FTGMAC100Desc bd; | ||
854 | + uint32_t flags = 0; | ||
855 | + uint32_t addr; | ||
856 | + uint32_t crc; | ||
857 | + uint32_t buf_addr; | ||
858 | + uint8_t *crc_ptr; | ||
859 | + uint32_t buf_len; | ||
860 | + size_t size = len; | ||
861 | + uint32_t first = FTGMAC100_RXDES0_FRS; | ||
862 | + int max_frame_size = ftgmac100_max_frame_size(s); | ||
863 | + | ||
864 | + if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN)) | ||
865 | + != (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN)) { | ||
866 | + return -1; | ||
867 | + } | ||
868 | + | ||
869 | + /* TODO : Pad to minimum Ethernet frame length */ | ||
870 | + /* handle small packets. */ | ||
871 | + if (size < 10) { | ||
872 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: dropped frame of %zd bytes\n", | ||
873 | + __func__, size); | ||
874 | + return size; | ||
875 | + } | ||
876 | + | ||
877 | + if (size < 64 && !(s->maccr && FTGMAC100_MACCR_RX_RUNT)) { | ||
878 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: dropped runt frame of %zd bytes\n", | ||
879 | + __func__, size); | ||
880 | + return size; | ||
881 | + } | ||
882 | + | ||
883 | + if (!ftgmac100_filter(s, buf, size)) { | ||
884 | + return size; | ||
885 | + } | ||
886 | + | ||
887 | + /* 4 bytes for the CRC. */ | ||
888 | + size += 4; | ||
889 | + crc = cpu_to_be32(crc32(~0, buf, size)); | ||
890 | + crc_ptr = (uint8_t *) &crc; | ||
891 | + | ||
892 | + /* Huge frames are truncated. */ | ||
893 | + if (size > max_frame_size) { | ||
894 | + size = max_frame_size; | ||
895 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: frame too big : %zd bytes\n", | ||
896 | + __func__, size); | ||
897 | + flags |= FTGMAC100_RXDES0_FTL; | ||
898 | + } | ||
899 | + | ||
900 | + switch (get_eth_packet_type(PKT_GET_ETH_HDR(buf))) { | ||
901 | + case ETH_PKT_BCAST: | ||
902 | + flags |= FTGMAC100_RXDES0_BROADCAST; | ||
903 | + break; | ||
904 | + case ETH_PKT_MCAST: | ||
905 | + flags |= FTGMAC100_RXDES0_MULTICAST; | ||
906 | + break; | ||
907 | + case ETH_PKT_UCAST: | ||
908 | + break; | ||
909 | + } | ||
910 | + | ||
911 | + addr = s->rx_descriptor; | ||
912 | + while (size > 0) { | ||
913 | + if (!ftgmac100_can_receive(nc)) { | ||
914 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Unexpected packet\n", __func__); | ||
915 | + return -1; | 32 | + return -1; |
916 | + } | 33 | + } |
917 | + | 34 | + |
918 | + if (ftgmac100_read_bd(&bd, addr) || | 35 | if (strcmp(cmd, "deny") == 0) { |
919 | + (bd.des0 & FTGMAC100_RXDES0_RXPKT_RDY)) { | 36 | acl_rule = g_malloc(sizeof(*acl_rule)); |
920 | + /* No descriptors available. Bail out. */ | 37 | if (strcmp(arg, "all") == 0) { |
921 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Lost end of frame\n", | 38 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) |
922 | + __func__); | 39 | usage(); |
923 | + s->isr |= FTGMAC100_INT_NO_RXBUF; | 40 | return EXIT_FAILURE; |
924 | + break; | 41 | } |
925 | + } | 42 | + if (strlen(bridge) >= IFNAMSIZ) { |
926 | + buf_len = (size <= s->rbsr) ? size : s->rbsr; | 43 | + fprintf(stderr, "name `%s' too long: %zu\n", bridge, strlen(bridge)); |
927 | + bd.des0 |= buf_len & 0x3fff; | 44 | + return EXIT_FAILURE; |
928 | + size -= buf_len; | ||
929 | + | ||
930 | + /* The last 4 bytes are the CRC. */ | ||
931 | + if (size < 4) { | ||
932 | + buf_len += size - 4; | ||
933 | + } | ||
934 | + buf_addr = bd.des3; | ||
935 | + dma_memory_write(&address_space_memory, buf_addr, buf, buf_len); | ||
936 | + buf += buf_len; | ||
937 | + if (size < 4) { | ||
938 | + dma_memory_write(&address_space_memory, buf_addr + buf_len, | ||
939 | + crc_ptr, 4 - size); | ||
940 | + crc_ptr += 4 - size; | ||
941 | + } | ||
942 | + | ||
943 | + bd.des0 |= first | FTGMAC100_RXDES0_RXPKT_RDY; | ||
944 | + first = 0; | ||
945 | + if (size == 0) { | ||
946 | + /* Last buffer in frame. */ | ||
947 | + bd.des0 |= flags | FTGMAC100_RXDES0_LRS; | ||
948 | + s->isr |= FTGMAC100_INT_RPKT_BUF; | ||
949 | + } else { | ||
950 | + s->isr |= FTGMAC100_INT_RPKT_FIFO; | ||
951 | + } | ||
952 | + ftgmac100_write_bd(&bd, addr); | ||
953 | + if (bd.des0 & FTGMAC100_RXDES0_EDORR) { | ||
954 | + addr = s->rx_ring; | ||
955 | + } else { | ||
956 | + addr += sizeof(FTGMAC100Desc); | ||
957 | + } | ||
958 | + } | 45 | + } |
959 | + s->rx_descriptor = addr; | 46 | |
960 | + | 47 | /* parse default acl file */ |
961 | + ftgmac100_update_irq(s); | 48 | QSIMPLEQ_INIT(&acl_list); |
962 | + return len; | ||
963 | +} | ||
964 | + | ||
965 | +static const MemoryRegionOps ftgmac100_ops = { | ||
966 | + .read = ftgmac100_read, | ||
967 | + .write = ftgmac100_write, | ||
968 | + .valid.min_access_size = 4, | ||
969 | + .valid.max_access_size = 4, | ||
970 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
971 | +}; | ||
972 | + | ||
973 | +static void ftgmac100_cleanup(NetClientState *nc) | ||
974 | +{ | ||
975 | + FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc)); | ||
976 | + | ||
977 | + s->nic = NULL; | ||
978 | +} | ||
979 | + | ||
980 | +static NetClientInfo net_ftgmac100_info = { | ||
981 | + .type = NET_CLIENT_DRIVER_NIC, | ||
982 | + .size = sizeof(NICState), | ||
983 | + .can_receive = ftgmac100_can_receive, | ||
984 | + .receive = ftgmac100_receive, | ||
985 | + .cleanup = ftgmac100_cleanup, | ||
986 | + .link_status_changed = ftgmac100_set_link, | ||
987 | +}; | ||
988 | + | ||
989 | +static void ftgmac100_realize(DeviceState *dev, Error **errp) | ||
990 | +{ | ||
991 | + FTGMAC100State *s = FTGMAC100(dev); | ||
992 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
993 | + | ||
994 | + memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s, | ||
995 | + TYPE_FTGMAC100, 0x2000); | ||
996 | + sysbus_init_mmio(sbd, &s->iomem); | ||
997 | + sysbus_init_irq(sbd, &s->irq); | ||
998 | + qemu_macaddr_default_if_unset(&s->conf.macaddr); | ||
999 | + | ||
1000 | + s->conf.peers.ncs[0] = nd_table[0].netdev; | ||
1001 | + | ||
1002 | + s->nic = qemu_new_nic(&net_ftgmac100_info, &s->conf, | ||
1003 | + object_get_typename(OBJECT(dev)), DEVICE(dev)->id, | ||
1004 | + s); | ||
1005 | + qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); | ||
1006 | + | ||
1007 | + s->frame = g_malloc(FTGMAC100_MAX_FRAME_SIZE); | ||
1008 | +} | ||
1009 | + | ||
1010 | +static const VMStateDescription vmstate_ftgmac100 = { | ||
1011 | + .name = TYPE_FTGMAC100, | ||
1012 | + .version_id = 1, | ||
1013 | + .minimum_version_id = 1, | ||
1014 | + .fields = (VMStateField[]) { | ||
1015 | + VMSTATE_UINT32(irq_state, FTGMAC100State), | ||
1016 | + VMSTATE_UINT32(isr, FTGMAC100State), | ||
1017 | + VMSTATE_UINT32(ier, FTGMAC100State), | ||
1018 | + VMSTATE_UINT32(rx_enabled, FTGMAC100State), | ||
1019 | + VMSTATE_UINT32(rx_ring, FTGMAC100State), | ||
1020 | + VMSTATE_UINT32(rbsr, FTGMAC100State), | ||
1021 | + VMSTATE_UINT32(tx_ring, FTGMAC100State), | ||
1022 | + VMSTATE_UINT32(rx_descriptor, FTGMAC100State), | ||
1023 | + VMSTATE_UINT32(tx_descriptor, FTGMAC100State), | ||
1024 | + VMSTATE_UINT32_ARRAY(math, FTGMAC100State, 2), | ||
1025 | + VMSTATE_UINT32(itc, FTGMAC100State), | ||
1026 | + VMSTATE_UINT32(aptcr, FTGMAC100State), | ||
1027 | + VMSTATE_UINT32(dblac, FTGMAC100State), | ||
1028 | + VMSTATE_UINT32(revr, FTGMAC100State), | ||
1029 | + VMSTATE_UINT32(fear1, FTGMAC100State), | ||
1030 | + VMSTATE_UINT32(tpafcr, FTGMAC100State), | ||
1031 | + VMSTATE_UINT32(maccr, FTGMAC100State), | ||
1032 | + VMSTATE_UINT32(phycr, FTGMAC100State), | ||
1033 | + VMSTATE_UINT32(phydata, FTGMAC100State), | ||
1034 | + VMSTATE_UINT32(fcr, FTGMAC100State), | ||
1035 | + VMSTATE_UINT32(phy_status, FTGMAC100State), | ||
1036 | + VMSTATE_UINT32(phy_control, FTGMAC100State), | ||
1037 | + VMSTATE_UINT32(phy_advertise, FTGMAC100State), | ||
1038 | + VMSTATE_UINT32(phy_int, FTGMAC100State), | ||
1039 | + VMSTATE_UINT32(phy_int_mask, FTGMAC100State), | ||
1040 | + VMSTATE_END_OF_LIST() | ||
1041 | + } | ||
1042 | +}; | ||
1043 | + | ||
1044 | +static Property ftgmac100_properties[] = { | ||
1045 | + DEFINE_NIC_PROPERTIES(FTGMAC100State, conf), | ||
1046 | + DEFINE_PROP_END_OF_LIST(), | ||
1047 | +}; | ||
1048 | + | ||
1049 | +static void ftgmac100_class_init(ObjectClass *klass, void *data) | ||
1050 | +{ | ||
1051 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
1052 | + | ||
1053 | + dc->vmsd = &vmstate_ftgmac100; | ||
1054 | + dc->reset = ftgmac100_reset; | ||
1055 | + dc->props = ftgmac100_properties; | ||
1056 | + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); | ||
1057 | + dc->realize = ftgmac100_realize; | ||
1058 | + dc->desc = "Faraday FTGMAC100 Gigabit Ethernet emulation"; | ||
1059 | +} | ||
1060 | + | ||
1061 | +static const TypeInfo ftgmac100_info = { | ||
1062 | + .name = TYPE_FTGMAC100, | ||
1063 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
1064 | + .instance_size = sizeof(FTGMAC100State), | ||
1065 | + .class_init = ftgmac100_class_init, | ||
1066 | +}; | ||
1067 | + | ||
1068 | +static void ftgmac100_register_types(void) | ||
1069 | +{ | ||
1070 | + type_register_static(&ftgmac100_info); | ||
1071 | +} | ||
1072 | + | ||
1073 | +type_init(ftgmac100_register_types) | ||
1074 | diff --git a/include/hw/net/ftgmac100.h b/include/hw/net/ftgmac100.h | ||
1075 | new file mode 100644 | ||
1076 | index XXXXXXX..XXXXXXX | ||
1077 | --- /dev/null | ||
1078 | +++ b/include/hw/net/ftgmac100.h | ||
1079 | @@ -XXX,XX +XXX,XX @@ | ||
1080 | +/* | ||
1081 | + * Faraday FTGMAC100 Gigabit Ethernet | ||
1082 | + * | ||
1083 | + * Copyright (C) 2016-2017, IBM Corporation. | ||
1084 | + * | ||
1085 | + * This code is licensed under the GPL version 2 or later. See the | ||
1086 | + * COPYING file in the top-level directory. | ||
1087 | + */ | ||
1088 | + | ||
1089 | +#ifndef FTGMAC100_H | ||
1090 | +#define FTGMAC100_H | ||
1091 | + | ||
1092 | +#define TYPE_FTGMAC100 "ftgmac100" | ||
1093 | +#define FTGMAC100(obj) OBJECT_CHECK(FTGMAC100State, (obj), TYPE_FTGMAC100) | ||
1094 | + | ||
1095 | +#include "hw/sysbus.h" | ||
1096 | +#include "net/net.h" | ||
1097 | + | ||
1098 | +typedef struct FTGMAC100State { | ||
1099 | + /*< private >*/ | ||
1100 | + SysBusDevice parent_obj; | ||
1101 | + | ||
1102 | + /*< public >*/ | ||
1103 | + NICState *nic; | ||
1104 | + NICConf conf; | ||
1105 | + qemu_irq irq; | ||
1106 | + MemoryRegion iomem; | ||
1107 | + | ||
1108 | + uint8_t *frame; | ||
1109 | + | ||
1110 | + uint32_t irq_state; | ||
1111 | + uint32_t isr; | ||
1112 | + uint32_t ier; | ||
1113 | + uint32_t rx_enabled; | ||
1114 | + uint32_t rx_ring; | ||
1115 | + uint32_t rx_descriptor; | ||
1116 | + uint32_t tx_ring; | ||
1117 | + uint32_t tx_descriptor; | ||
1118 | + uint32_t math[2]; | ||
1119 | + uint32_t rbsr; | ||
1120 | + uint32_t itc; | ||
1121 | + uint32_t aptcr; | ||
1122 | + uint32_t dblac; | ||
1123 | + uint32_t revr; | ||
1124 | + uint32_t fear1; | ||
1125 | + uint32_t tpafcr; | ||
1126 | + uint32_t maccr; | ||
1127 | + uint32_t phycr; | ||
1128 | + uint32_t phydata; | ||
1129 | + uint32_t fcr; | ||
1130 | + | ||
1131 | + | ||
1132 | + uint32_t phy_status; | ||
1133 | + uint32_t phy_control; | ||
1134 | + uint32_t phy_advertise; | ||
1135 | + uint32_t phy_int; | ||
1136 | + uint32_t phy_int_mask; | ||
1137 | +} FTGMAC100State; | ||
1138 | + | ||
1139 | +#endif | ||
1140 | -- | 49 | -- |
1141 | 2.7.4 | 50 | 2.5.0 |
1142 | 51 | ||
1143 | 52 | diff view generated by jsdifflib |
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 1 | From: Prasad J Pandit <pjp@fedoraproject.org> |
---|---|---|---|
2 | 2 | ||
3 | In this patch we support packet that have tcp options field. | 3 | Move repeating error handling sequence in parse_acl_file routine |
4 | Add tcp options field check, If the packet have options | 4 | to an 'err' label. |
5 | field we just skip it and compare tcp payload, | ||
6 | Avoid unnecessary checkpoint, optimize performance. | ||
7 | 5 | ||
8 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 6 | Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org> |
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
9 | Reviewed-by: Li Qiang <liq3ea@gmail.com> | ||
9 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 10 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
10 | --- | 11 | --- |
11 | net/colo-compare.c | 27 ++++++++++++++++++++++++++- | 12 | qemu-bridge-helper.c | 19 +++++++++---------- |
12 | 1 file changed, 26 insertions(+), 1 deletion(-) | 13 | 1 file changed, 9 insertions(+), 10 deletions(-) |
13 | 14 | ||
14 | diff --git a/net/colo-compare.c b/net/colo-compare.c | 15 | diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/net/colo-compare.c | 17 | --- a/qemu-bridge-helper.c |
17 | +++ b/net/colo-compare.c | 18 | +++ b/qemu-bridge-helper.c |
18 | @@ -XXX,XX +XXX,XX @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) | 19 | @@ -XXX,XX +XXX,XX @@ static int parse_acl_file(const char *filename, ACLList *acl_list) |
19 | spkt->ip->ip_sum = ppkt->ip->ip_sum; | 20 | |
21 | if (arg == NULL) { | ||
22 | fprintf(stderr, "Invalid config line:\n %s\n", line); | ||
23 | - fclose(f); | ||
24 | - errno = EINVAL; | ||
25 | - return -1; | ||
26 | + goto err; | ||
27 | } | ||
28 | |||
29 | *arg = 0; | ||
30 | @@ -XXX,XX +XXX,XX @@ static int parse_acl_file(const char *filename, ACLList *acl_list) | ||
31 | |||
32 | if (!g_str_equal(cmd, "include") && strlen(arg) >= IFNAMSIZ) { | ||
33 | fprintf(stderr, "name `%s' too long: %zu\n", arg, strlen(arg)); | ||
34 | - fclose(f); | ||
35 | - errno = EINVAL; | ||
36 | - return -1; | ||
37 | + goto err; | ||
38 | } | ||
39 | |||
40 | if (strcmp(cmd, "deny") == 0) { | ||
41 | @@ -XXX,XX +XXX,XX @@ static int parse_acl_file(const char *filename, ACLList *acl_list) | ||
42 | parse_acl_file(arg, acl_list); | ||
43 | } else { | ||
44 | fprintf(stderr, "Unknown command `%s'\n", cmd); | ||
45 | - fclose(f); | ||
46 | - errno = EINVAL; | ||
47 | - return -1; | ||
48 | + goto err; | ||
49 | } | ||
20 | } | 50 | } |
21 | 51 | ||
22 | - if (ptcp->th_sum == stcp->th_sum) { | 52 | fclose(f); |
23 | + /* | 53 | - |
24 | + * Check tcp header length for tcp option field. | 54 | return 0; |
25 | + * th_off > 5 means this tcp packet have options field. | 55 | + |
26 | + * The tcp options maybe always different. | 56 | +err: |
27 | + * for example: | 57 | + fclose(f); |
28 | + * From RFC 7323. | 58 | + errno = EINVAL; |
29 | + * TCP Timestamps option (TSopt): | 59 | + return -1; |
30 | + * Kind: 8 | 60 | + |
31 | + * | 61 | } |
32 | + * Length: 10 bytes | 62 | |
33 | + * | 63 | static bool has_vnet_hdr(int fd) |
34 | + * +-------+-------+---------------------+---------------------+ | ||
35 | + * |Kind=8 | 10 | TS Value (TSval) |TS Echo Reply (TSecr)| | ||
36 | + * +-------+-------+---------------------+---------------------+ | ||
37 | + * 1 1 4 4 | ||
38 | + * | ||
39 | + * In this case the primary guest's timestamp always different with | ||
40 | + * the secondary guest's timestamp. COLO just focus on payload, | ||
41 | + * so we just need skip this field. | ||
42 | + */ | ||
43 | + if (ptcp->th_off > 5) { | ||
44 | + ptrdiff_t tcp_offset; | ||
45 | + tcp_offset = ppkt->transport_header - (uint8_t *)ppkt->data | ||
46 | + + (ptcp->th_off * 4); | ||
47 | + res = colo_packet_compare_common(ppkt, spkt, tcp_offset); | ||
48 | + } else if (ptcp->th_sum == stcp->th_sum) { | ||
49 | res = colo_packet_compare_common(ppkt, spkt, ETH_HLEN); | ||
50 | } else { | ||
51 | res = -1; | ||
52 | -- | 64 | -- |
53 | 2.7.4 | 65 | 2.5.0 |
54 | 66 | ||
55 | 67 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | From: Prasad J Pandit <pjp@fedoraproject.org> |
---|---|---|---|
2 | 2 | ||
3 | There is a second NIC but we do not use it for the moment. We use the | 3 | When invoking qemu-bridge-helper in 'net_bridge_run_helper', |
4 | 'aspeed' property to tune the definition of the end of ring buffer bit | 4 | instead of using fixed sized buffers, use dynamically allocated |
5 | for the Aspeed SoCs. | 5 | ones initialised and returned by g_strdup_printf(). |
6 | 6 | ||
7 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | 7 | Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org> |
8 | Reviewed-by: Li Qiang <liq3ea@gmail.com> | ||
9 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
8 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 10 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
9 | --- | 11 | --- |
10 | hw/arm/aspeed_soc.c | 21 +++++++++++++++++++++ | 12 | net/tap.c | 19 +++++++++++-------- |
11 | include/hw/arm/aspeed_soc.h | 2 ++ | 13 | 1 file changed, 11 insertions(+), 8 deletions(-) |
12 | 2 files changed, 23 insertions(+) | ||
13 | 14 | ||
14 | diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c | 15 | diff --git a/net/tap.c b/net/tap.c |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/aspeed_soc.c | 17 | --- a/net/tap.c |
17 | +++ b/hw/arm/aspeed_soc.c | 18 | +++ b/net/tap.c |
18 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static int net_bridge_run_helper(const char *helper, const char *bridge, |
19 | #include "hw/char/serial.h" | ||
20 | #include "qemu/log.h" | ||
21 | #include "hw/i2c/aspeed_i2c.h" | ||
22 | +#include "net/net.h" | ||
23 | |||
24 | #define ASPEED_SOC_UART_5_BASE 0x00184000 | ||
25 | #define ASPEED_SOC_IOMEM_SIZE 0x00200000 | ||
26 | @@ -XXX,XX +XXX,XX @@ | ||
27 | #define ASPEED_SOC_TIMER_BASE 0x1E782000 | ||
28 | #define ASPEED_SOC_WDT_BASE 0x1E785000 | ||
29 | #define ASPEED_SOC_I2C_BASE 0x1E78A000 | ||
30 | +#define ASPEED_SOC_ETH1_BASE 0x1E660000 | ||
31 | +#define ASPEED_SOC_ETH2_BASE 0x1E680000 | ||
32 | |||
33 | static const int uart_irqs[] = { 9, 32, 33, 34, 10 }; | ||
34 | static const int timer_irqs[] = { 16, 17, 18, 35, 36, 37, 38, 39, }; | ||
35 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj) | ||
36 | object_initialize(&s->wdt, sizeof(s->wdt), TYPE_ASPEED_WDT); | ||
37 | object_property_add_child(obj, "wdt", OBJECT(&s->wdt), NULL); | ||
38 | qdev_set_parent_bus(DEVICE(&s->wdt), sysbus_get_default()); | ||
39 | + | ||
40 | + object_initialize(&s->ftgmac100, sizeof(s->ftgmac100), TYPE_FTGMAC100); | ||
41 | + object_property_add_child(obj, "ftgmac100", OBJECT(&s->ftgmac100), NULL); | ||
42 | + qdev_set_parent_bus(DEVICE(&s->ftgmac100), sysbus_get_default()); | ||
43 | } | ||
44 | |||
45 | static void aspeed_soc_realize(DeviceState *dev, Error **errp) | ||
46 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) | ||
47 | return; | ||
48 | } | 20 | } |
49 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt), 0, ASPEED_SOC_WDT_BASE); | 21 | if (pid == 0) { |
50 | + | 22 | int open_max = sysconf(_SC_OPEN_MAX), i; |
51 | + /* Net */ | 23 | - char fd_buf[6+10]; |
52 | + qdev_set_nic_properties(DEVICE(&s->ftgmac100), &nd_table[0]); | 24 | - char br_buf[6+IFNAMSIZ] = {0}; |
53 | + object_property_set_bool(OBJECT(&s->ftgmac100), true, "aspeed", &err); | 25 | - char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + 15]; |
54 | + object_property_set_bool(OBJECT(&s->ftgmac100), true, "realized", | 26 | + char *fd_buf = NULL; |
55 | + &local_err); | 27 | + char *br_buf = NULL; |
56 | + error_propagate(&err, local_err); | 28 | + char *helper_cmd = NULL; |
57 | + if (err) { | 29 | |
58 | + error_propagate(errp, err); | 30 | for (i = 3; i < open_max; i++) { |
59 | + return; | 31 | if (i != sv[1]) { |
60 | + } | 32 | @@ -XXX,XX +XXX,XX @@ static int net_bridge_run_helper(const char *helper, const char *bridge, |
61 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ftgmac100), 0, ASPEED_SOC_ETH1_BASE); | 33 | } |
62 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100), 0, | 34 | } |
63 | + qdev_get_gpio_in(DEVICE(&s->vic), 2)); | 35 | |
64 | } | 36 | - snprintf(fd_buf, sizeof(fd_buf), "%s%d", "--fd=", sv[1]); |
65 | 37 | + fd_buf = g_strdup_printf("%s%d", "--fd=", sv[1]); | |
66 | static void aspeed_soc_class_init(ObjectClass *oc, void *data) | 38 | |
67 | diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h | 39 | if (strrchr(helper, ' ') || strrchr(helper, '\t')) { |
68 | index XXXXXXX..XXXXXXX 100644 | 40 | /* assume helper is a command */ |
69 | --- a/include/hw/arm/aspeed_soc.h | 41 | |
70 | +++ b/include/hw/arm/aspeed_soc.h | 42 | if (strstr(helper, "--br=") == NULL) { |
71 | @@ -XXX,XX +XXX,XX @@ | 43 | - snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=", bridge); |
72 | #include "hw/i2c/aspeed_i2c.h" | 44 | + br_buf = g_strdup_printf("%s%s", "--br=", bridge); |
73 | #include "hw/ssi/aspeed_smc.h" | 45 | } |
74 | #include "hw/watchdog/wdt_aspeed.h" | 46 | |
75 | +#include "hw/net/ftgmac100.h" | 47 | - snprintf(helper_cmd, sizeof(helper_cmd), "%s %s %s %s", |
76 | 48 | - helper, "--use-vnet", fd_buf, br_buf); | |
77 | #define ASPEED_SPIS_NUM 2 | 49 | + helper_cmd = g_strdup_printf("%s %s %s %s", helper, |
78 | 50 | + "--use-vnet", fd_buf, br_buf ? br_buf : ""); | |
79 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState { | 51 | |
80 | AspeedSMCState spi[ASPEED_SPIS_NUM]; | 52 | parg = args; |
81 | AspeedSDMCState sdmc; | 53 | *parg++ = (char *)"sh"; |
82 | AspeedWDTState wdt; | 54 | @@ -XXX,XX +XXX,XX @@ static int net_bridge_run_helper(const char *helper, const char *bridge, |
83 | + FTGMAC100State ftgmac100; | 55 | *parg++ = NULL; |
84 | } AspeedSoCState; | 56 | |
85 | 57 | execv("/bin/sh", args); | |
86 | #define TYPE_ASPEED_SOC "aspeed-soc" | 58 | + g_free(helper_cmd); |
59 | } else { | ||
60 | /* assume helper is just the executable path name */ | ||
61 | |||
62 | - snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=", bridge); | ||
63 | + br_buf = g_strdup_printf("%s%s", "--br=", bridge); | ||
64 | |||
65 | parg = args; | ||
66 | *parg++ = (char *)helper; | ||
67 | @@ -XXX,XX +XXX,XX @@ static int net_bridge_run_helper(const char *helper, const char *bridge, | ||
68 | |||
69 | execv(helper, args); | ||
70 | } | ||
71 | + g_free(fd_buf); | ||
72 | + g_free(br_buf); | ||
73 | _exit(1); | ||
74 | |||
75 | } else { | ||
87 | -- | 76 | -- |
88 | 2.7.4 | 77 | 2.5.0 |
89 | 78 | ||
90 | 79 | diff view generated by jsdifflib |
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 1 | From: Zhang Chen <chen.zhang@intel.com> |
---|---|---|---|
2 | 2 | ||
3 | If colo-compare find one old packet,we can notify colo-frame | 3 | This patch to fix the origin "char *data" memory leak, code style issue |
4 | do checkpoint, no need continue find more old packet here. | 4 | and add necessary check here. |
5 | Reported-by: Coverity (CID 1402785) | ||
5 | 6 | ||
6 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 7 | Signed-off-by: Zhang Chen <chen.zhang@intel.com> |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 9 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 10 | --- |
9 | net/colo-compare.c | 15 +++++++++++---- | 11 | net/colo-compare.c | 27 ++++++++++++++++++++------- |
10 | 1 file changed, 11 insertions(+), 4 deletions(-) | 12 | 1 file changed, 20 insertions(+), 7 deletions(-) |
11 | 13 | ||
12 | diff --git a/net/colo-compare.c b/net/colo-compare.c | 14 | diff --git a/net/colo-compare.c b/net/colo-compare.c |
13 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/net/colo-compare.c | 16 | --- a/net/colo-compare.c |
15 | +++ b/net/colo-compare.c | 17 | +++ b/net/colo-compare.c |
16 | @@ -XXX,XX +XXX,XX @@ static int colo_old_packet_check_one(Packet *pkt, int64_t *check_time) | 18 | @@ -XXX,XX +XXX,XX @@ static int compare_chr_send(CompareState *s, |
19 | uint32_t vnet_hdr_len, | ||
20 | bool notify_remote_frame); | ||
21 | |||
22 | +static bool packet_matches_str(const char *str, | ||
23 | + const uint8_t *buf, | ||
24 | + uint32_t packet_len) | ||
25 | +{ | ||
26 | + if (packet_len != strlen(str)) { | ||
27 | + return false; | ||
28 | + } | ||
29 | + | ||
30 | + return !memcmp(str, buf, strlen(str)); | ||
31 | +} | ||
32 | + | ||
33 | static void notify_remote_frame(CompareState *s) | ||
34 | { | ||
35 | char msg[] = "DO_CHECKPOINT"; | ||
36 | @@ -XXX,XX +XXX,XX @@ static void compare_notify_rs_finalize(SocketReadState *notify_rs) | ||
37 | { | ||
38 | CompareState *s = container_of(notify_rs, CompareState, notify_rs); | ||
39 | |||
40 | - /* Get Xen colo-frame's notify and handle the message */ | ||
41 | - char *data = g_memdup(notify_rs->buf, notify_rs->packet_len); | ||
42 | - char msg[] = "COLO_COMPARE_GET_XEN_INIT"; | ||
43 | + const char msg[] = "COLO_COMPARE_GET_XEN_INIT"; | ||
44 | int ret; | ||
45 | |||
46 | - if (!strcmp(data, "COLO_USERSPACE_PROXY_INIT")) { | ||
47 | + if (packet_matches_str("COLO_USERSPACE_PROXY_INIT", | ||
48 | + notify_rs->buf, | ||
49 | + notify_rs->packet_len)) { | ||
50 | ret = compare_chr_send(s, (uint8_t *)msg, strlen(msg), 0, true); | ||
51 | if (ret < 0) { | ||
52 | error_report("Notify Xen COLO-frame INIT failed"); | ||
53 | } | ||
54 | - } | ||
55 | - | ||
56 | - if (!strcmp(data, "COLO_CHECKPOINT")) { | ||
57 | + } else if (packet_matches_str("COLO_CHECKPOINT", | ||
58 | + notify_rs->buf, | ||
59 | + notify_rs->packet_len)) { | ||
60 | /* colo-compare do checkpoint, flush pri packet and remove sec packet */ | ||
61 | g_queue_foreach(&s->conn_list, colo_flush_packets, s); | ||
62 | + } else { | ||
63 | + error_report("COLO compare got unsupported instruction"); | ||
17 | } | 64 | } |
18 | } | 65 | } |
19 | 66 | ||
20 | -static void colo_old_packet_check_one_conn(void *opaque, | ||
21 | - void *user_data) | ||
22 | +static int colo_old_packet_check_one_conn(Connection *conn, | ||
23 | + void *user_data) | ||
24 | { | ||
25 | - Connection *conn = opaque; | ||
26 | GList *result = NULL; | ||
27 | int64_t check_time = REGULAR_PACKET_CHECK_MS; | ||
28 | |||
29 | @@ -XXX,XX +XXX,XX @@ static void colo_old_packet_check_one_conn(void *opaque, | ||
30 | if (result) { | ||
31 | /* do checkpoint will flush old packet */ | ||
32 | /* TODO: colo_notify_checkpoint();*/ | ||
33 | + return 0; | ||
34 | } | ||
35 | + | ||
36 | + return 1; | ||
37 | } | ||
38 | |||
39 | /* | ||
40 | @@ -XXX,XX +XXX,XX @@ static void colo_old_packet_check(void *opaque) | ||
41 | { | ||
42 | CompareState *s = opaque; | ||
43 | |||
44 | - g_queue_foreach(&s->conn_list, colo_old_packet_check_one_conn, NULL); | ||
45 | + /* | ||
46 | + * If we find one old packet, stop finding job and notify | ||
47 | + * COLO frame do checkpoint. | ||
48 | + */ | ||
49 | + g_queue_find_custom(&s->conn_list, NULL, | ||
50 | + (GCompareFunc)colo_old_packet_check_one_conn); | ||
51 | } | ||
52 | |||
53 | /* | ||
54 | -- | 67 | -- |
55 | 2.7.4 | 68 | 2.5.0 |
56 | 69 | ||
57 | 70 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Cédric Le Goater <clg@kaod.org> | ||
2 | 1 | ||
3 | This adds comments on the Basic mode control and status registers bit | ||
4 | definitions. It also adds a couple of bits for 1000BASE-T and the | ||
5 | RealTek 8211E PHY for the FTGMAC100 model to use. | ||
6 | |||
7 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
10 | --- | ||
11 | include/hw/net/mii.h | 71 +++++++++++++++++++++++++++++++++++++++------------- | ||
12 | 1 file changed, 53 insertions(+), 18 deletions(-) | ||
13 | |||
14 | diff --git a/include/hw/net/mii.h b/include/hw/net/mii.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/hw/net/mii.h | ||
17 | +++ b/include/hw/net/mii.h | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | #define MII_H | ||
20 | |||
21 | /* PHY registers */ | ||
22 | -#define MII_BMCR 0 | ||
23 | -#define MII_BMSR 1 | ||
24 | -#define MII_PHYID1 2 | ||
25 | -#define MII_PHYID2 3 | ||
26 | -#define MII_ANAR 4 | ||
27 | -#define MII_ANLPAR 5 | ||
28 | -#define MII_ANER 6 | ||
29 | +#define MII_BMCR 0 /* Basic mode control register */ | ||
30 | +#define MII_BMSR 1 /* Basic mode status register */ | ||
31 | +#define MII_PHYID1 2 /* ID register 1 */ | ||
32 | +#define MII_PHYID2 3 /* ID register 2 */ | ||
33 | +#define MII_ANAR 4 /* Autonegotiation advertisement */ | ||
34 | +#define MII_ANLPAR 5 /* Autonegotiation lnk partner abilities */ | ||
35 | +#define MII_ANER 6 /* Autonegotiation expansion */ | ||
36 | +#define MII_ANNP 7 /* Autonegotiation next page */ | ||
37 | +#define MII_ANLPRNP 8 /* Autonegotiation link partner rx next page */ | ||
38 | +#define MII_CTRL1000 9 /* 1000BASE-T control */ | ||
39 | +#define MII_STAT1000 10 /* 1000BASE-T status */ | ||
40 | +#define MII_MDDACR 13 /* MMD access control */ | ||
41 | +#define MII_MDDAADR 14 /* MMD access address data */ | ||
42 | +#define MII_EXTSTAT 15 /* Extended Status */ | ||
43 | #define MII_NSR 16 | ||
44 | #define MII_LBREMR 17 | ||
45 | #define MII_REC 18 | ||
46 | @@ -XXX,XX +XXX,XX @@ | ||
47 | /* PHY registers fields */ | ||
48 | #define MII_BMCR_RESET (1 << 15) | ||
49 | #define MII_BMCR_LOOPBACK (1 << 14) | ||
50 | -#define MII_BMCR_SPEED (1 << 13) | ||
51 | -#define MII_BMCR_AUTOEN (1 << 12) | ||
52 | -#define MII_BMCR_FD (1 << 8) | ||
53 | +#define MII_BMCR_SPEED100 (1 << 13) /* LSB of Speed (100) */ | ||
54 | +#define MII_BMCR_SPEED MII_BMCR_SPEED100 | ||
55 | +#define MII_BMCR_AUTOEN (1 << 12) /* Autonegotiation enable */ | ||
56 | +#define MII_BMCR_PDOWN (1 << 11) /* Enable low power state */ | ||
57 | +#define MII_BMCR_ISOLATE (1 << 10) /* Isolate data paths from MII */ | ||
58 | +#define MII_BMCR_ANRESTART (1 << 9) /* Auto negotiation restart */ | ||
59 | +#define MII_BMCR_FD (1 << 8) /* Set duplex mode */ | ||
60 | +#define MII_BMCR_CTST (1 << 7) /* Collision test */ | ||
61 | +#define MII_BMCR_SPEED1000 (1 << 6) /* MSB of Speed (1000) */ | ||
62 | |||
63 | -#define MII_BMSR_100TX_FD (1 << 14) | ||
64 | -#define MII_BMSR_100TX_HD (1 << 13) | ||
65 | -#define MII_BMSR_10T_FD (1 << 12) | ||
66 | -#define MII_BMSR_10T_HD (1 << 11) | ||
67 | -#define MII_BMSR_MFPS (1 << 6) | ||
68 | -#define MII_BMSR_AN_COMP (1 << 5) | ||
69 | -#define MII_BMSR_AUTONEG (1 << 3) | ||
70 | -#define MII_BMSR_LINK_ST (1 << 2) | ||
71 | +#define MII_BMSR_100TX_FD (1 << 14) /* Can do 100mbps, full-duplex */ | ||
72 | +#define MII_BMSR_100TX_HD (1 << 13) /* Can do 100mbps, half-duplex */ | ||
73 | +#define MII_BMSR_10T_FD (1 << 12) /* Can do 10mbps, full-duplex */ | ||
74 | +#define MII_BMSR_10T_HD (1 << 11) /* Can do 10mbps, half-duplex */ | ||
75 | +#define MII_BMSR_100T2_FD (1 << 10) /* Can do 100mbps T2, full-duplex */ | ||
76 | +#define MII_BMSR_100T2_HD (1 << 9) /* Can do 100mbps T2, half-duplex */ | ||
77 | +#define MII_BMSR_EXTSTAT (1 << 8) /* Extended status in register 15 */ | ||
78 | +#define MII_BMSR_MFPS (1 << 6) /* MII Frame Preamble Suppression */ | ||
79 | +#define MII_BMSR_AN_COMP (1 << 5) /* Auto-negotiation complete */ | ||
80 | +#define MII_BMSR_RFAULT (1 << 4) /* Remote fault */ | ||
81 | +#define MII_BMSR_AUTONEG (1 << 3) /* Able to do auto-negotiation */ | ||
82 | +#define MII_BMSR_LINK_ST (1 << 2) /* Link status */ | ||
83 | +#define MII_BMSR_JABBER (1 << 1) /* Jabber detected */ | ||
84 | +#define MII_BMSR_EXTCAP (1 << 0) /* Ext-reg capability */ | ||
85 | |||
86 | +#define MII_ANAR_PAUSE_ASYM (1 << 11) /* Try for asymetric pause */ | ||
87 | +#define MII_ANAR_PAUSE (1 << 10) /* Try for pause */ | ||
88 | #define MII_ANAR_TXFD (1 << 8) | ||
89 | #define MII_ANAR_TX (1 << 7) | ||
90 | #define MII_ANAR_10FD (1 << 6) | ||
91 | @@ -XXX,XX +XXX,XX @@ | ||
92 | #define MII_ANAR_CSMACD (1 << 0) | ||
93 | |||
94 | #define MII_ANLPAR_ACK (1 << 14) | ||
95 | +#define MII_ANLPAR_PAUSEASY (1 << 11) /* can pause asymmetrically */ | ||
96 | +#define MII_ANLPAR_PAUSE (1 << 10) /* can pause */ | ||
97 | #define MII_ANLPAR_TXFD (1 << 8) | ||
98 | #define MII_ANLPAR_TX (1 << 7) | ||
99 | #define MII_ANLPAR_10FD (1 << 6) | ||
100 | #define MII_ANLPAR_10 (1 << 5) | ||
101 | #define MII_ANLPAR_CSMACD (1 << 0) | ||
102 | |||
103 | +#define MII_ANER_NWAY (1 << 0) /* Can do N-way auto-nego */ | ||
104 | + | ||
105 | +#define MII_CTRL1000_FULL (1 << 9) /* 1000BASE-T full duplex */ | ||
106 | +#define MII_CTRL1000_HALF (1 << 8) /* 1000BASE-T half duplex */ | ||
107 | + | ||
108 | +#define MII_STAT1000_FULL (1 << 11) /* 1000BASE-T full duplex */ | ||
109 | +#define MII_STAT1000_HALF (1 << 10) /* 1000BASE-T half duplex */ | ||
110 | + | ||
111 | /* List of vendor identifiers */ | ||
112 | /* RealTek 8201 */ | ||
113 | #define RTL8201CP_PHYID1 0x0000 | ||
114 | #define RTL8201CP_PHYID2 0x8201 | ||
115 | |||
116 | +/* RealTek 8211E */ | ||
117 | +#define RTL8211E_PHYID1 0x001c | ||
118 | +#define RTL8211E_PHYID2 0xc915 | ||
119 | + | ||
120 | /* National Semiconductor DP83848 */ | ||
121 | #define DP83848_PHYID1 0x2000 | ||
122 | #define DP83848_PHYID2 0x5c90 | ||
123 | -- | ||
124 | 2.7.4 | ||
125 | |||
126 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Cédric Le Goater <clg@kaod.org> | ||
2 | 1 | ||
3 | The Aspeed SoCs have a different definition of the end of the ring | ||
4 | buffer bit. Add a property to specify which set of bits should be used | ||
5 | by the NIC. | ||
6 | |||
7 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
8 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
9 | --- | ||
10 | hw/net/ftgmac100.c | 17 +++++++++++++++-- | ||
11 | include/hw/net/ftgmac100.h | 4 ++++ | ||
12 | 2 files changed, 19 insertions(+), 2 deletions(-) | ||
13 | |||
14 | diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/net/ftgmac100.c | ||
17 | +++ b/hw/net/ftgmac100.c | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | #define FTGMAC100_TXDES0_CRC_ERR (1 << 19) | ||
20 | #define FTGMAC100_TXDES0_LTS (1 << 28) | ||
21 | #define FTGMAC100_TXDES0_FTS (1 << 29) | ||
22 | +#define FTGMAC100_TXDES0_EDOTR_ASPEED (1 << 30) | ||
23 | #define FTGMAC100_TXDES0_TXDMA_OWN (1 << 31) | ||
24 | |||
25 | #define FTGMAC100_TXDES1_VLANTAG_CI(x) ((x) & 0xffff) | ||
26 | @@ -XXX,XX +XXX,XX @@ | ||
27 | #define FTGMAC100_RXDES0_PAUSE_FRAME (1 << 25) | ||
28 | #define FTGMAC100_RXDES0_LRS (1 << 28) | ||
29 | #define FTGMAC100_RXDES0_FRS (1 << 29) | ||
30 | +#define FTGMAC100_RXDES0_EDORR_ASPEED (1 << 30) | ||
31 | #define FTGMAC100_RXDES0_RXPKT_RDY (1 << 31) | ||
32 | |||
33 | #define FTGMAC100_RXDES1_VLANTAG_CI 0xffff | ||
34 | @@ -XXX,XX +XXX,XX @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring, | ||
35 | /* Write back the modified descriptor. */ | ||
36 | ftgmac100_write_bd(&bd, addr); | ||
37 | /* Advance to the next descriptor. */ | ||
38 | - if (bd.des0 & FTGMAC100_TXDES0_EDOTR) { | ||
39 | + if (bd.des0 & s->txdes0_edotr) { | ||
40 | addr = tx_ring; | ||
41 | } else { | ||
42 | addr += sizeof(FTGMAC100Desc); | ||
43 | @@ -XXX,XX +XXX,XX @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf, | ||
44 | s->isr |= FTGMAC100_INT_RPKT_FIFO; | ||
45 | } | ||
46 | ftgmac100_write_bd(&bd, addr); | ||
47 | - if (bd.des0 & FTGMAC100_RXDES0_EDORR) { | ||
48 | + if (bd.des0 & s->rxdes0_edorr) { | ||
49 | addr = s->rx_ring; | ||
50 | } else { | ||
51 | addr += sizeof(FTGMAC100Desc); | ||
52 | @@ -XXX,XX +XXX,XX @@ static void ftgmac100_realize(DeviceState *dev, Error **errp) | ||
53 | FTGMAC100State *s = FTGMAC100(dev); | ||
54 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
55 | |||
56 | + if (s->aspeed) { | ||
57 | + s->txdes0_edotr = FTGMAC100_TXDES0_EDOTR_ASPEED; | ||
58 | + s->rxdes0_edorr = FTGMAC100_RXDES0_EDORR_ASPEED; | ||
59 | + } else { | ||
60 | + s->txdes0_edotr = FTGMAC100_TXDES0_EDOTR; | ||
61 | + s->rxdes0_edorr = FTGMAC100_RXDES0_EDORR; | ||
62 | + } | ||
63 | + | ||
64 | memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s, | ||
65 | TYPE_FTGMAC100, 0x2000); | ||
66 | sysbus_init_mmio(sbd, &s->iomem); | ||
67 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_ftgmac100 = { | ||
68 | VMSTATE_UINT32(phy_advertise, FTGMAC100State), | ||
69 | VMSTATE_UINT32(phy_int, FTGMAC100State), | ||
70 | VMSTATE_UINT32(phy_int_mask, FTGMAC100State), | ||
71 | + VMSTATE_UINT32(txdes0_edotr, FTGMAC100State), | ||
72 | + VMSTATE_UINT32(rxdes0_edorr, FTGMAC100State), | ||
73 | VMSTATE_END_OF_LIST() | ||
74 | } | ||
75 | }; | ||
76 | |||
77 | static Property ftgmac100_properties[] = { | ||
78 | + DEFINE_PROP_BOOL("aspeed", FTGMAC100State, aspeed, false), | ||
79 | DEFINE_NIC_PROPERTIES(FTGMAC100State, conf), | ||
80 | DEFINE_PROP_END_OF_LIST(), | ||
81 | }; | ||
82 | diff --git a/include/hw/net/ftgmac100.h b/include/hw/net/ftgmac100.h | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/include/hw/net/ftgmac100.h | ||
85 | +++ b/include/hw/net/ftgmac100.h | ||
86 | @@ -XXX,XX +XXX,XX @@ typedef struct FTGMAC100State { | ||
87 | uint32_t phy_advertise; | ||
88 | uint32_t phy_int; | ||
89 | uint32_t phy_int_mask; | ||
90 | + | ||
91 | + bool aspeed; | ||
92 | + uint32_t txdes0_edotr; | ||
93 | + uint32_t rxdes0_edorr; | ||
94 | } FTGMAC100State; | ||
95 | |||
96 | #endif | ||
97 | -- | ||
98 | 2.7.4 | ||
99 | |||
100 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Cédric Le Goater <clg@kaod.org> | ||
2 | 1 | ||
3 | NC-SI (Network Controller Sideband Interface) enables a BMC to manage | ||
4 | a set of NICs on a system. This model takes the simplest approach and | ||
5 | reverses the NC-SI packets to pretend a NIC is present and exercise | ||
6 | the Linux driver. | ||
7 | |||
8 | The NCSI header file <ncsi-pkt.h> comes from mainline Linux and was | ||
9 | untabified. | ||
10 | |||
11 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org> | ||
14 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
15 | --- | ||
16 | include/net/eth.h | 1 + | ||
17 | slirp/Makefile.objs | 2 +- | ||
18 | slirp/ncsi-pkt.h | 419 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
19 | slirp/ncsi.c | 130 ++++++++++++++++ | ||
20 | slirp/slirp.c | 4 + | ||
21 | slirp/slirp.h | 3 + | ||
22 | 6 files changed, 558 insertions(+), 1 deletion(-) | ||
23 | create mode 100644 slirp/ncsi-pkt.h | ||
24 | create mode 100644 slirp/ncsi.c | ||
25 | |||
26 | diff --git a/include/net/eth.h b/include/net/eth.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/include/net/eth.h | ||
29 | +++ b/include/net/eth.h | ||
30 | @@ -XXX,XX +XXX,XX @@ struct tcp_hdr { | ||
31 | #define ETH_P_IPV6 (0x86dd) | ||
32 | #define ETH_P_VLAN (0x8100) | ||
33 | #define ETH_P_DVLAN (0x88a8) | ||
34 | +#define ETH_P_NCSI (0x88f8) | ||
35 | #define ETH_P_UNKNOWN (0xffff) | ||
36 | #define VLAN_VID_MASK 0x0fff | ||
37 | #define IP_HEADER_VERSION_4 (4) | ||
38 | diff --git a/slirp/Makefile.objs b/slirp/Makefile.objs | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/slirp/Makefile.objs | ||
41 | +++ b/slirp/Makefile.objs | ||
42 | @@ -XXX,XX +XXX,XX @@ common-obj-y = cksum.o if.o ip_icmp.o ip6_icmp.o ip6_input.o ip6_output.o \ | ||
43 | ip_input.o ip_output.o dnssearch.o dhcpv6.o | ||
44 | common-obj-y += slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o | ||
45 | common-obj-y += tcp_subr.o tcp_timer.o udp.o udp6.o bootp.o tftp.o arp_table.o \ | ||
46 | - ndp_table.o | ||
47 | + ndp_table.o ncsi.o | ||
48 | diff --git a/slirp/ncsi-pkt.h b/slirp/ncsi-pkt.h | ||
49 | new file mode 100644 | ||
50 | index XXXXXXX..XXXXXXX | ||
51 | --- /dev/null | ||
52 | +++ b/slirp/ncsi-pkt.h | ||
53 | @@ -XXX,XX +XXX,XX @@ | ||
54 | +/* | ||
55 | + * Copyright Gavin Shan, IBM Corporation 2016. | ||
56 | + * | ||
57 | + * This program is free software; you can redistribute it and/or modify | ||
58 | + * it under the terms of the GNU General Public License as published by | ||
59 | + * the Free Software Foundation; either version 2 of the License, or | ||
60 | + * (at your option) any later version. | ||
61 | + */ | ||
62 | + | ||
63 | +#ifndef NCSI_PKT_H | ||
64 | +#define NCSI_PKT_H | ||
65 | + | ||
66 | +/* from linux/net/ncsi/ncsi-pkt.h */ | ||
67 | +#define __be32 uint32_t | ||
68 | +#define __be16 uint16_t | ||
69 | + | ||
70 | +struct ncsi_pkt_hdr { | ||
71 | + unsigned char mc_id; /* Management controller ID */ | ||
72 | + unsigned char revision; /* NCSI version - 0x01 */ | ||
73 | + unsigned char reserved; /* Reserved */ | ||
74 | + unsigned char id; /* Packet sequence number */ | ||
75 | + unsigned char type; /* Packet type */ | ||
76 | + unsigned char channel; /* Network controller ID */ | ||
77 | + __be16 length; /* Payload length */ | ||
78 | + __be32 reserved1[2]; /* Reserved */ | ||
79 | +}; | ||
80 | + | ||
81 | +struct ncsi_cmd_pkt_hdr { | ||
82 | + struct ncsi_pkt_hdr common; /* Common NCSI packet header */ | ||
83 | +}; | ||
84 | + | ||
85 | +struct ncsi_rsp_pkt_hdr { | ||
86 | + struct ncsi_pkt_hdr common; /* Common NCSI packet header */ | ||
87 | + __be16 code; /* Response code */ | ||
88 | + __be16 reason; /* Response reason */ | ||
89 | +}; | ||
90 | + | ||
91 | +struct ncsi_aen_pkt_hdr { | ||
92 | + struct ncsi_pkt_hdr common; /* Common NCSI packet header */ | ||
93 | + unsigned char reserved2[3]; /* Reserved */ | ||
94 | + unsigned char type; /* AEN packet type */ | ||
95 | +}; | ||
96 | + | ||
97 | +/* NCSI common command packet */ | ||
98 | +struct ncsi_cmd_pkt { | ||
99 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
100 | + __be32 checksum; /* Checksum */ | ||
101 | + unsigned char pad[26]; | ||
102 | +}; | ||
103 | + | ||
104 | +struct ncsi_rsp_pkt { | ||
105 | + struct ncsi_rsp_pkt_hdr rsp; /* Response header */ | ||
106 | + __be32 checksum; /* Checksum */ | ||
107 | + unsigned char pad[22]; | ||
108 | +}; | ||
109 | + | ||
110 | +/* Select Package */ | ||
111 | +struct ncsi_cmd_sp_pkt { | ||
112 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
113 | + unsigned char reserved[3]; /* Reserved */ | ||
114 | + unsigned char hw_arbitration; /* HW arbitration */ | ||
115 | + __be32 checksum; /* Checksum */ | ||
116 | + unsigned char pad[22]; | ||
117 | +}; | ||
118 | + | ||
119 | +/* Disable Channel */ | ||
120 | +struct ncsi_cmd_dc_pkt { | ||
121 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
122 | + unsigned char reserved[3]; /* Reserved */ | ||
123 | + unsigned char ald; /* Allow link down */ | ||
124 | + __be32 checksum; /* Checksum */ | ||
125 | + unsigned char pad[22]; | ||
126 | +}; | ||
127 | + | ||
128 | +/* Reset Channel */ | ||
129 | +struct ncsi_cmd_rc_pkt { | ||
130 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
131 | + __be32 reserved; /* Reserved */ | ||
132 | + __be32 checksum; /* Checksum */ | ||
133 | + unsigned char pad[22]; | ||
134 | +}; | ||
135 | + | ||
136 | +/* AEN Enable */ | ||
137 | +struct ncsi_cmd_ae_pkt { | ||
138 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
139 | + unsigned char reserved[3]; /* Reserved */ | ||
140 | + unsigned char mc_id; /* MC ID */ | ||
141 | + __be32 mode; /* AEN working mode */ | ||
142 | + __be32 checksum; /* Checksum */ | ||
143 | + unsigned char pad[18]; | ||
144 | +}; | ||
145 | + | ||
146 | +/* Set Link */ | ||
147 | +struct ncsi_cmd_sl_pkt { | ||
148 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
149 | + __be32 mode; /* Link working mode */ | ||
150 | + __be32 oem_mode; /* OEM link mode */ | ||
151 | + __be32 checksum; /* Checksum */ | ||
152 | + unsigned char pad[18]; | ||
153 | +}; | ||
154 | + | ||
155 | +/* Set VLAN Filter */ | ||
156 | +struct ncsi_cmd_svf_pkt { | ||
157 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
158 | + __be16 reserved; /* Reserved */ | ||
159 | + __be16 vlan; /* VLAN ID */ | ||
160 | + __be16 reserved1; /* Reserved */ | ||
161 | + unsigned char index; /* VLAN table index */ | ||
162 | + unsigned char enable; /* Enable or disable */ | ||
163 | + __be32 checksum; /* Checksum */ | ||
164 | + unsigned char pad[14]; | ||
165 | +}; | ||
166 | + | ||
167 | +/* Enable VLAN */ | ||
168 | +struct ncsi_cmd_ev_pkt { | ||
169 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
170 | + unsigned char reserved[3]; /* Reserved */ | ||
171 | + unsigned char mode; /* VLAN filter mode */ | ||
172 | + __be32 checksum; /* Checksum */ | ||
173 | + unsigned char pad[22]; | ||
174 | +}; | ||
175 | + | ||
176 | +/* Set MAC Address */ | ||
177 | +struct ncsi_cmd_sma_pkt { | ||
178 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
179 | + unsigned char mac[6]; /* MAC address */ | ||
180 | + unsigned char index; /* MAC table index */ | ||
181 | + unsigned char at_e; /* Addr type and operation */ | ||
182 | + __be32 checksum; /* Checksum */ | ||
183 | + unsigned char pad[18]; | ||
184 | +}; | ||
185 | + | ||
186 | +/* Enable Broadcast Filter */ | ||
187 | +struct ncsi_cmd_ebf_pkt { | ||
188 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
189 | + __be32 mode; /* Filter mode */ | ||
190 | + __be32 checksum; /* Checksum */ | ||
191 | + unsigned char pad[22]; | ||
192 | +}; | ||
193 | + | ||
194 | +/* Enable Global Multicast Filter */ | ||
195 | +struct ncsi_cmd_egmf_pkt { | ||
196 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
197 | + __be32 mode; /* Global MC mode */ | ||
198 | + __be32 checksum; /* Checksum */ | ||
199 | + unsigned char pad[22]; | ||
200 | +}; | ||
201 | + | ||
202 | +/* Set NCSI Flow Control */ | ||
203 | +struct ncsi_cmd_snfc_pkt { | ||
204 | + struct ncsi_cmd_pkt_hdr cmd; /* Command header */ | ||
205 | + unsigned char reserved[3]; /* Reserved */ | ||
206 | + unsigned char mode; /* Flow control mode */ | ||
207 | + __be32 checksum; /* Checksum */ | ||
208 | + unsigned char pad[22]; | ||
209 | +}; | ||
210 | + | ||
211 | +/* Get Link Status */ | ||
212 | +struct ncsi_rsp_gls_pkt { | ||
213 | + struct ncsi_rsp_pkt_hdr rsp; /* Response header */ | ||
214 | + __be32 status; /* Link status */ | ||
215 | + __be32 other; /* Other indications */ | ||
216 | + __be32 oem_status; /* OEM link status */ | ||
217 | + __be32 checksum; | ||
218 | + unsigned char pad[10]; | ||
219 | +}; | ||
220 | + | ||
221 | +/* Get Version ID */ | ||
222 | +struct ncsi_rsp_gvi_pkt { | ||
223 | + struct ncsi_rsp_pkt_hdr rsp; /* Response header */ | ||
224 | + __be32 ncsi_version; /* NCSI version */ | ||
225 | + unsigned char reserved[3]; /* Reserved */ | ||
226 | + unsigned char alpha2; /* NCSI version */ | ||
227 | + unsigned char fw_name[12]; /* f/w name string */ | ||
228 | + __be32 fw_version; /* f/w version */ | ||
229 | + __be16 pci_ids[4]; /* PCI IDs */ | ||
230 | + __be32 mf_id; /* Manufacture ID */ | ||
231 | + __be32 checksum; | ||
232 | +}; | ||
233 | + | ||
234 | +/* Get Capabilities */ | ||
235 | +struct ncsi_rsp_gc_pkt { | ||
236 | + struct ncsi_rsp_pkt_hdr rsp; /* Response header */ | ||
237 | + __be32 cap; /* Capabilities */ | ||
238 | + __be32 bc_cap; /* Broadcast cap */ | ||
239 | + __be32 mc_cap; /* Multicast cap */ | ||
240 | + __be32 buf_cap; /* Buffering cap */ | ||
241 | + __be32 aen_cap; /* AEN cap */ | ||
242 | + unsigned char vlan_cnt; /* VLAN filter count */ | ||
243 | + unsigned char mixed_cnt; /* Mix filter count */ | ||
244 | + unsigned char mc_cnt; /* MC filter count */ | ||
245 | + unsigned char uc_cnt; /* UC filter count */ | ||
246 | + unsigned char reserved[2]; /* Reserved */ | ||
247 | + unsigned char vlan_mode; /* VLAN mode */ | ||
248 | + unsigned char channel_cnt; /* Channel count */ | ||
249 | + __be32 checksum; /* Checksum */ | ||
250 | +}; | ||
251 | + | ||
252 | +/* Get Parameters */ | ||
253 | +struct ncsi_rsp_gp_pkt { | ||
254 | + struct ncsi_rsp_pkt_hdr rsp; /* Response header */ | ||
255 | + unsigned char mac_cnt; /* Number of MAC addr */ | ||
256 | + unsigned char reserved[2]; /* Reserved */ | ||
257 | + unsigned char mac_enable; /* MAC addr enable flags */ | ||
258 | + unsigned char vlan_cnt; /* VLAN tag count */ | ||
259 | + unsigned char reserved1; /* Reserved */ | ||
260 | + __be16 vlan_enable; /* VLAN tag enable flags */ | ||
261 | + __be32 link_mode; /* Link setting */ | ||
262 | + __be32 bc_mode; /* BC filter mode */ | ||
263 | + __be32 valid_modes; /* Valid mode parameters */ | ||
264 | + unsigned char vlan_mode; /* VLAN mode */ | ||
265 | + unsigned char fc_mode; /* Flow control mode */ | ||
266 | + unsigned char reserved2[2]; /* Reserved */ | ||
267 | + __be32 aen_mode; /* AEN mode */ | ||
268 | + unsigned char mac[6]; /* Supported MAC addr */ | ||
269 | + __be16 vlan; /* Supported VLAN tags */ | ||
270 | + __be32 checksum; /* Checksum */ | ||
271 | +}; | ||
272 | + | ||
273 | +/* Get Controller Packet Statistics */ | ||
274 | +struct ncsi_rsp_gcps_pkt { | ||
275 | + struct ncsi_rsp_pkt_hdr rsp; /* Response header */ | ||
276 | + __be32 cnt_hi; /* Counter cleared */ | ||
277 | + __be32 cnt_lo; /* Counter cleared */ | ||
278 | + __be32 rx_bytes; /* Rx bytes */ | ||
279 | + __be32 tx_bytes; /* Tx bytes */ | ||
280 | + __be32 rx_uc_pkts; /* Rx UC packets */ | ||
281 | + __be32 rx_mc_pkts; /* Rx MC packets */ | ||
282 | + __be32 rx_bc_pkts; /* Rx BC packets */ | ||
283 | + __be32 tx_uc_pkts; /* Tx UC packets */ | ||
284 | + __be32 tx_mc_pkts; /* Tx MC packets */ | ||
285 | + __be32 tx_bc_pkts; /* Tx BC packets */ | ||
286 | + __be32 fcs_err; /* FCS errors */ | ||
287 | + __be32 align_err; /* Alignment errors */ | ||
288 | + __be32 false_carrier; /* False carrier detection */ | ||
289 | + __be32 runt_pkts; /* Rx runt packets */ | ||
290 | + __be32 jabber_pkts; /* Rx jabber packets */ | ||
291 | + __be32 rx_pause_xon; /* Rx pause XON frames */ | ||
292 | + __be32 rx_pause_xoff; /* Rx XOFF frames */ | ||
293 | + __be32 tx_pause_xon; /* Tx XON frames */ | ||
294 | + __be32 tx_pause_xoff; /* Tx XOFF frames */ | ||
295 | + __be32 tx_s_collision; /* Single collision frames */ | ||
296 | + __be32 tx_m_collision; /* Multiple collision frames */ | ||
297 | + __be32 l_collision; /* Late collision frames */ | ||
298 | + __be32 e_collision; /* Excessive collision frames */ | ||
299 | + __be32 rx_ctl_frames; /* Rx control frames */ | ||
300 | + __be32 rx_64_frames; /* Rx 64-bytes frames */ | ||
301 | + __be32 rx_127_frames; /* Rx 65-127 bytes frames */ | ||
302 | + __be32 rx_255_frames; /* Rx 128-255 bytes frames */ | ||
303 | + __be32 rx_511_frames; /* Rx 256-511 bytes frames */ | ||
304 | + __be32 rx_1023_frames; /* Rx 512-1023 bytes frames */ | ||
305 | + __be32 rx_1522_frames; /* Rx 1024-1522 bytes frames */ | ||
306 | + __be32 rx_9022_frames; /* Rx 1523-9022 bytes frames */ | ||
307 | + __be32 tx_64_frames; /* Tx 64-bytes frames */ | ||
308 | + __be32 tx_127_frames; /* Tx 65-127 bytes frames */ | ||
309 | + __be32 tx_255_frames; /* Tx 128-255 bytes frames */ | ||
310 | + __be32 tx_511_frames; /* Tx 256-511 bytes frames */ | ||
311 | + __be32 tx_1023_frames; /* Tx 512-1023 bytes frames */ | ||
312 | + __be32 tx_1522_frames; /* Tx 1024-1522 bytes frames */ | ||
313 | + __be32 tx_9022_frames; /* Tx 1523-9022 bytes frames */ | ||
314 | + __be32 rx_valid_bytes; /* Rx valid bytes */ | ||
315 | + __be32 rx_runt_pkts; /* Rx error runt packets */ | ||
316 | + __be32 rx_jabber_pkts; /* Rx error jabber packets */ | ||
317 | + __be32 checksum; /* Checksum */ | ||
318 | +}; | ||
319 | + | ||
320 | +/* Get NCSI Statistics */ | ||
321 | +struct ncsi_rsp_gns_pkt { | ||
322 | + struct ncsi_rsp_pkt_hdr rsp; /* Response header */ | ||
323 | + __be32 rx_cmds; /* Rx NCSI commands */ | ||
324 | + __be32 dropped_cmds; /* Dropped commands */ | ||
325 | + __be32 cmd_type_errs; /* Command type errors */ | ||
326 | + __be32 cmd_csum_errs; /* Command checksum errors */ | ||
327 | + __be32 rx_pkts; /* Rx NCSI packets */ | ||
328 | + __be32 tx_pkts; /* Tx NCSI packets */ | ||
329 | + __be32 tx_aen_pkts; /* Tx AEN packets */ | ||
330 | + __be32 checksum; /* Checksum */ | ||
331 | +}; | ||
332 | + | ||
333 | +/* Get NCSI Pass-through Statistics */ | ||
334 | +struct ncsi_rsp_gnpts_pkt { | ||
335 | + struct ncsi_rsp_pkt_hdr rsp; /* Response header */ | ||
336 | + __be32 tx_pkts; /* Tx packets */ | ||
337 | + __be32 tx_dropped; /* Tx dropped packets */ | ||
338 | + __be32 tx_channel_err; /* Tx channel errors */ | ||
339 | + __be32 tx_us_err; /* Tx undersize errors */ | ||
340 | + __be32 rx_pkts; /* Rx packets */ | ||
341 | + __be32 rx_dropped; /* Rx dropped packets */ | ||
342 | + __be32 rx_channel_err; /* Rx channel errors */ | ||
343 | + __be32 rx_us_err; /* Rx undersize errors */ | ||
344 | + __be32 rx_os_err; /* Rx oversize errors */ | ||
345 | + __be32 checksum; /* Checksum */ | ||
346 | +}; | ||
347 | + | ||
348 | +/* Get package status */ | ||
349 | +struct ncsi_rsp_gps_pkt { | ||
350 | + struct ncsi_rsp_pkt_hdr rsp; /* Response header */ | ||
351 | + __be32 status; /* Hardware arbitration status */ | ||
352 | + __be32 checksum; | ||
353 | +}; | ||
354 | + | ||
355 | +/* Get package UUID */ | ||
356 | +struct ncsi_rsp_gpuuid_pkt { | ||
357 | + struct ncsi_rsp_pkt_hdr rsp; /* Response header */ | ||
358 | + unsigned char uuid[16]; /* UUID */ | ||
359 | + __be32 checksum; | ||
360 | +}; | ||
361 | + | ||
362 | +/* AEN: Link State Change */ | ||
363 | +struct ncsi_aen_lsc_pkt { | ||
364 | + struct ncsi_aen_pkt_hdr aen; /* AEN header */ | ||
365 | + __be32 status; /* Link status */ | ||
366 | + __be32 oem_status; /* OEM link status */ | ||
367 | + __be32 checksum; /* Checksum */ | ||
368 | + unsigned char pad[14]; | ||
369 | +}; | ||
370 | + | ||
371 | +/* AEN: Configuration Required */ | ||
372 | +struct ncsi_aen_cr_pkt { | ||
373 | + struct ncsi_aen_pkt_hdr aen; /* AEN header */ | ||
374 | + __be32 checksum; /* Checksum */ | ||
375 | + unsigned char pad[22]; | ||
376 | +}; | ||
377 | + | ||
378 | +/* AEN: Host Network Controller Driver Status Change */ | ||
379 | +struct ncsi_aen_hncdsc_pkt { | ||
380 | + struct ncsi_aen_pkt_hdr aen; /* AEN header */ | ||
381 | + __be32 status; /* Status */ | ||
382 | + __be32 checksum; /* Checksum */ | ||
383 | + unsigned char pad[18]; | ||
384 | +}; | ||
385 | + | ||
386 | +/* NCSI packet revision */ | ||
387 | +#define NCSI_PKT_REVISION 0x01 | ||
388 | + | ||
389 | +/* NCSI packet commands */ | ||
390 | +#define NCSI_PKT_CMD_CIS 0x00 /* Clear Initial State */ | ||
391 | +#define NCSI_PKT_CMD_SP 0x01 /* Select Package */ | ||
392 | +#define NCSI_PKT_CMD_DP 0x02 /* Deselect Package */ | ||
393 | +#define NCSI_PKT_CMD_EC 0x03 /* Enable Channel */ | ||
394 | +#define NCSI_PKT_CMD_DC 0x04 /* Disable Channel */ | ||
395 | +#define NCSI_PKT_CMD_RC 0x05 /* Reset Channel */ | ||
396 | +#define NCSI_PKT_CMD_ECNT 0x06 /* Enable Channel Network Tx */ | ||
397 | +#define NCSI_PKT_CMD_DCNT 0x07 /* Disable Channel Network Tx */ | ||
398 | +#define NCSI_PKT_CMD_AE 0x08 /* AEN Enable */ | ||
399 | +#define NCSI_PKT_CMD_SL 0x09 /* Set Link */ | ||
400 | +#define NCSI_PKT_CMD_GLS 0x0a /* Get Link */ | ||
401 | +#define NCSI_PKT_CMD_SVF 0x0b /* Set VLAN Filter */ | ||
402 | +#define NCSI_PKT_CMD_EV 0x0c /* Enable VLAN */ | ||
403 | +#define NCSI_PKT_CMD_DV 0x0d /* Disable VLAN */ | ||
404 | +#define NCSI_PKT_CMD_SMA 0x0e /* Set MAC address */ | ||
405 | +#define NCSI_PKT_CMD_EBF 0x10 /* Enable Broadcast Filter */ | ||
406 | +#define NCSI_PKT_CMD_DBF 0x11 /* Disable Broadcast Filter */ | ||
407 | +#define NCSI_PKT_CMD_EGMF 0x12 /* Enable Global Multicast Filter */ | ||
408 | +#define NCSI_PKT_CMD_DGMF 0x13 /* Disable Global Multicast Filter */ | ||
409 | +#define NCSI_PKT_CMD_SNFC 0x14 /* Set NCSI Flow Control */ | ||
410 | +#define NCSI_PKT_CMD_GVI 0x15 /* Get Version ID */ | ||
411 | +#define NCSI_PKT_CMD_GC 0x16 /* Get Capabilities */ | ||
412 | +#define NCSI_PKT_CMD_GP 0x17 /* Get Parameters */ | ||
413 | +#define NCSI_PKT_CMD_GCPS 0x18 /* Get Controller Packet Statistics */ | ||
414 | +#define NCSI_PKT_CMD_GNS 0x19 /* Get NCSI Statistics */ | ||
415 | +#define NCSI_PKT_CMD_GNPTS 0x1a /* Get NCSI Pass-throu Statistics */ | ||
416 | +#define NCSI_PKT_CMD_GPS 0x1b /* Get package status */ | ||
417 | +#define NCSI_PKT_CMD_OEM 0x50 /* OEM */ | ||
418 | +#define NCSI_PKT_CMD_PLDM 0x51 /* PLDM request over NCSI over RBT */ | ||
419 | +#define NCSI_PKT_CMD_GPUUID 0x52 /* Get package UUID */ | ||
420 | + | ||
421 | +/* NCSI packet responses */ | ||
422 | +#define NCSI_PKT_RSP_CIS (NCSI_PKT_CMD_CIS + 0x80) | ||
423 | +#define NCSI_PKT_RSP_SP (NCSI_PKT_CMD_SP + 0x80) | ||
424 | +#define NCSI_PKT_RSP_DP (NCSI_PKT_CMD_DP + 0x80) | ||
425 | +#define NCSI_PKT_RSP_EC (NCSI_PKT_CMD_EC + 0x80) | ||
426 | +#define NCSI_PKT_RSP_DC (NCSI_PKT_CMD_DC + 0x80) | ||
427 | +#define NCSI_PKT_RSP_RC (NCSI_PKT_CMD_RC + 0x80) | ||
428 | +#define NCSI_PKT_RSP_ECNT (NCSI_PKT_CMD_ECNT + 0x80) | ||
429 | +#define NCSI_PKT_RSP_DCNT (NCSI_PKT_CMD_DCNT + 0x80) | ||
430 | +#define NCSI_PKT_RSP_AE (NCSI_PKT_CMD_AE + 0x80) | ||
431 | +#define NCSI_PKT_RSP_SL (NCSI_PKT_CMD_SL + 0x80) | ||
432 | +#define NCSI_PKT_RSP_GLS (NCSI_PKT_CMD_GLS + 0x80) | ||
433 | +#define NCSI_PKT_RSP_SVF (NCSI_PKT_CMD_SVF + 0x80) | ||
434 | +#define NCSI_PKT_RSP_EV (NCSI_PKT_CMD_EV + 0x80) | ||
435 | +#define NCSI_PKT_RSP_DV (NCSI_PKT_CMD_DV + 0x80) | ||
436 | +#define NCSI_PKT_RSP_SMA (NCSI_PKT_CMD_SMA + 0x80) | ||
437 | +#define NCSI_PKT_RSP_EBF (NCSI_PKT_CMD_EBF + 0x80) | ||
438 | +#define NCSI_PKT_RSP_DBF (NCSI_PKT_CMD_DBF + 0x80) | ||
439 | +#define NCSI_PKT_RSP_EGMF (NCSI_PKT_CMD_EGMF + 0x80) | ||
440 | +#define NCSI_PKT_RSP_DGMF (NCSI_PKT_CMD_DGMF + 0x80) | ||
441 | +#define NCSI_PKT_RSP_SNFC (NCSI_PKT_CMD_SNFC + 0x80) | ||
442 | +#define NCSI_PKT_RSP_GVI (NCSI_PKT_CMD_GVI + 0x80) | ||
443 | +#define NCSI_PKT_RSP_GC (NCSI_PKT_CMD_GC + 0x80) | ||
444 | +#define NCSI_PKT_RSP_GP (NCSI_PKT_CMD_GP + 0x80) | ||
445 | +#define NCSI_PKT_RSP_GCPS (NCSI_PKT_CMD_GCPS + 0x80) | ||
446 | +#define NCSI_PKT_RSP_GNS (NCSI_PKT_CMD_GNS + 0x80) | ||
447 | +#define NCSI_PKT_RSP_GNPTS (NCSI_PKT_CMD_GNPTS + 0x80) | ||
448 | +#define NCSI_PKT_RSP_GPS (NCSI_PKT_CMD_GPS + 0x80) | ||
449 | +#define NCSI_PKT_RSP_OEM (NCSI_PKT_CMD_OEM + 0x80) | ||
450 | +#define NCSI_PKT_RSP_PLDM (NCSI_PKT_CMD_PLDM + 0x80) | ||
451 | +#define NCSI_PKT_RSP_GPUUID (NCSI_PKT_CMD_GPUUID + 0x80) | ||
452 | + | ||
453 | +/* NCSI response code/reason */ | ||
454 | +#define NCSI_PKT_RSP_C_COMPLETED 0x0000 /* Command Completed */ | ||
455 | +#define NCSI_PKT_RSP_C_FAILED 0x0001 /* Command Failed */ | ||
456 | +#define NCSI_PKT_RSP_C_UNAVAILABLE 0x0002 /* Command Unavailable */ | ||
457 | +#define NCSI_PKT_RSP_C_UNSUPPORTED 0x0003 /* Command Unsupported */ | ||
458 | +#define NCSI_PKT_RSP_R_NO_ERROR 0x0000 /* No Error */ | ||
459 | +#define NCSI_PKT_RSP_R_INTERFACE 0x0001 /* Interface not ready */ | ||
460 | +#define NCSI_PKT_RSP_R_PARAM 0x0002 /* Invalid Parameter */ | ||
461 | +#define NCSI_PKT_RSP_R_CHANNEL 0x0003 /* Channel not Ready */ | ||
462 | +#define NCSI_PKT_RSP_R_PACKAGE 0x0004 /* Package not Ready */ | ||
463 | +#define NCSI_PKT_RSP_R_LENGTH 0x0005 /* Invalid payload length */ | ||
464 | +#define NCSI_PKT_RSP_R_UNKNOWN 0x7fff /* Command type unsupported */ | ||
465 | + | ||
466 | +/* NCSI AEN packet type */ | ||
467 | +#define NCSI_PKT_AEN 0xFF /* AEN Packet */ | ||
468 | +#define NCSI_PKT_AEN_LSC 0x00 /* Link status change */ | ||
469 | +#define NCSI_PKT_AEN_CR 0x01 /* Configuration required */ | ||
470 | +#define NCSI_PKT_AEN_HNCDSC 0x02 /* HNC driver status change */ | ||
471 | + | ||
472 | +#endif /* NCSI_PKT_H */ | ||
473 | diff --git a/slirp/ncsi.c b/slirp/ncsi.c | ||
474 | new file mode 100644 | ||
475 | index XXXXXXX..XXXXXXX | ||
476 | --- /dev/null | ||
477 | +++ b/slirp/ncsi.c | ||
478 | @@ -XXX,XX +XXX,XX @@ | ||
479 | +/* | ||
480 | + * NC-SI (Network Controller Sideband Interface) "echo" model | ||
481 | + * | ||
482 | + * Copyright (C) 2016 IBM Corp. | ||
483 | + * | ||
484 | + * This code is licensed under the GPL version 2 or later. See the | ||
485 | + * COPYING file in the top-level directory. | ||
486 | + */ | ||
487 | +#include "qemu/osdep.h" | ||
488 | +#include "slirp.h" | ||
489 | + | ||
490 | +#include "ncsi-pkt.h" | ||
491 | + | ||
492 | +/* Get Capabilities */ | ||
493 | +static int ncsi_rsp_handler_gc(struct ncsi_rsp_pkt_hdr *rnh) | ||
494 | +{ | ||
495 | + struct ncsi_rsp_gc_pkt *rsp = (struct ncsi_rsp_gc_pkt *) rnh; | ||
496 | + | ||
497 | + rsp->cap = htonl(~0); | ||
498 | + rsp->bc_cap = htonl(~0); | ||
499 | + rsp->mc_cap = htonl(~0); | ||
500 | + rsp->buf_cap = htonl(~0); | ||
501 | + rsp->aen_cap = htonl(~0); | ||
502 | + rsp->vlan_mode = 0xff; | ||
503 | + rsp->uc_cnt = 2; | ||
504 | + return 0; | ||
505 | +} | ||
506 | + | ||
507 | +/* Get Link status */ | ||
508 | +static int ncsi_rsp_handler_gls(struct ncsi_rsp_pkt_hdr *rnh) | ||
509 | +{ | ||
510 | + struct ncsi_rsp_gls_pkt *rsp = (struct ncsi_rsp_gls_pkt *) rnh; | ||
511 | + | ||
512 | + rsp->status = htonl(0x1); | ||
513 | + return 0; | ||
514 | +} | ||
515 | + | ||
516 | +static const struct ncsi_rsp_handler { | ||
517 | + unsigned char type; | ||
518 | + int payload; | ||
519 | + int (*handler)(struct ncsi_rsp_pkt_hdr *rnh); | ||
520 | +} ncsi_rsp_handlers[] = { | ||
521 | + { NCSI_PKT_RSP_CIS, 4, NULL }, | ||
522 | + { NCSI_PKT_RSP_SP, 4, NULL }, | ||
523 | + { NCSI_PKT_RSP_DP, 4, NULL }, | ||
524 | + { NCSI_PKT_RSP_EC, 4, NULL }, | ||
525 | + { NCSI_PKT_RSP_DC, 4, NULL }, | ||
526 | + { NCSI_PKT_RSP_RC, 4, NULL }, | ||
527 | + { NCSI_PKT_RSP_ECNT, 4, NULL }, | ||
528 | + { NCSI_PKT_RSP_DCNT, 4, NULL }, | ||
529 | + { NCSI_PKT_RSP_AE, 4, NULL }, | ||
530 | + { NCSI_PKT_RSP_SL, 4, NULL }, | ||
531 | + { NCSI_PKT_RSP_GLS, 16, ncsi_rsp_handler_gls }, | ||
532 | + { NCSI_PKT_RSP_SVF, 4, NULL }, | ||
533 | + { NCSI_PKT_RSP_EV, 4, NULL }, | ||
534 | + { NCSI_PKT_RSP_DV, 4, NULL }, | ||
535 | + { NCSI_PKT_RSP_SMA, 4, NULL }, | ||
536 | + { NCSI_PKT_RSP_EBF, 4, NULL }, | ||
537 | + { NCSI_PKT_RSP_DBF, 4, NULL }, | ||
538 | + { NCSI_PKT_RSP_EGMF, 4, NULL }, | ||
539 | + { NCSI_PKT_RSP_DGMF, 4, NULL }, | ||
540 | + { NCSI_PKT_RSP_SNFC, 4, NULL }, | ||
541 | + { NCSI_PKT_RSP_GVI, 36, NULL }, | ||
542 | + { NCSI_PKT_RSP_GC, 32, ncsi_rsp_handler_gc }, | ||
543 | + { NCSI_PKT_RSP_GP, -1, NULL }, | ||
544 | + { NCSI_PKT_RSP_GCPS, 172, NULL }, | ||
545 | + { NCSI_PKT_RSP_GNS, 172, NULL }, | ||
546 | + { NCSI_PKT_RSP_GNPTS, 172, NULL }, | ||
547 | + { NCSI_PKT_RSP_GPS, 8, NULL }, | ||
548 | + { NCSI_PKT_RSP_OEM, 0, NULL }, | ||
549 | + { NCSI_PKT_RSP_PLDM, 0, NULL }, | ||
550 | + { NCSI_PKT_RSP_GPUUID, 20, NULL } | ||
551 | +}; | ||
552 | + | ||
553 | +/* | ||
554 | + * packet format : ncsi header + payload + checksum | ||
555 | + */ | ||
556 | +#define NCSI_MAX_PAYLOAD 172 | ||
557 | +#define NCSI_MAX_LEN (sizeof(struct ncsi_pkt_hdr) + NCSI_MAX_PAYLOAD + 4) | ||
558 | + | ||
559 | +void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) | ||
560 | +{ | ||
561 | + struct ncsi_pkt_hdr *nh = (struct ncsi_pkt_hdr *)(pkt + ETH_HLEN); | ||
562 | + uint8_t ncsi_reply[ETH_HLEN + NCSI_MAX_LEN]; | ||
563 | + struct ethhdr *reh = (struct ethhdr *)ncsi_reply; | ||
564 | + struct ncsi_rsp_pkt_hdr *rnh = (struct ncsi_rsp_pkt_hdr *) | ||
565 | + (ncsi_reply + ETH_HLEN); | ||
566 | + const struct ncsi_rsp_handler *handler = NULL; | ||
567 | + int i; | ||
568 | + | ||
569 | + memset(ncsi_reply, 0, sizeof(ncsi_reply)); | ||
570 | + | ||
571 | + memset(reh->h_dest, 0xff, ETH_ALEN); | ||
572 | + memset(reh->h_source, 0xff, ETH_ALEN); | ||
573 | + reh->h_proto = htons(ETH_P_NCSI); | ||
574 | + | ||
575 | + for (i = 0; i < ARRAY_SIZE(ncsi_rsp_handlers); i++) { | ||
576 | + if (ncsi_rsp_handlers[i].type == nh->type + 0x80) { | ||
577 | + handler = &ncsi_rsp_handlers[i]; | ||
578 | + break; | ||
579 | + } | ||
580 | + } | ||
581 | + | ||
582 | + rnh->common.mc_id = nh->mc_id; | ||
583 | + rnh->common.revision = NCSI_PKT_REVISION; | ||
584 | + rnh->common.id = nh->id; | ||
585 | + rnh->common.type = nh->type + 0x80; | ||
586 | + rnh->common.channel = nh->channel; | ||
587 | + | ||
588 | + if (handler) { | ||
589 | + rnh->common.length = htons(handler->payload); | ||
590 | + rnh->code = htons(NCSI_PKT_RSP_C_COMPLETED); | ||
591 | + rnh->reason = htons(NCSI_PKT_RSP_R_NO_ERROR); | ||
592 | + | ||
593 | + if (handler->handler) { | ||
594 | + /* TODO: handle errors */ | ||
595 | + handler->handler(rnh); | ||
596 | + } | ||
597 | + } else { | ||
598 | + rnh->common.length = 0; | ||
599 | + rnh->code = htons(NCSI_PKT_RSP_C_UNAVAILABLE); | ||
600 | + rnh->reason = htons(NCSI_PKT_RSP_R_UNKNOWN); | ||
601 | + } | ||
602 | + | ||
603 | + /* TODO: add a checksum at the end of the frame but the specs | ||
604 | + * allows it to be zero */ | ||
605 | + | ||
606 | + slirp_output(slirp->opaque, ncsi_reply, ETH_HLEN + sizeof(*nh) + | ||
607 | + (handler ? handler->payload : 0) + 4); | ||
608 | +} | ||
609 | diff --git a/slirp/slirp.c b/slirp/slirp.c | ||
610 | index XXXXXXX..XXXXXXX 100644 | ||
611 | --- a/slirp/slirp.c | ||
612 | +++ b/slirp/slirp.c | ||
613 | @@ -XXX,XX +XXX,XX @@ void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) | ||
614 | } | ||
615 | break; | ||
616 | |||
617 | + case ETH_P_NCSI: | ||
618 | + ncsi_input(slirp, pkt, pkt_len); | ||
619 | + break; | ||
620 | + | ||
621 | default: | ||
622 | break; | ||
623 | } | ||
624 | diff --git a/slirp/slirp.h b/slirp/slirp.h | ||
625 | index XXXXXXX..XXXXXXX 100644 | ||
626 | --- a/slirp/slirp.h | ||
627 | +++ b/slirp/slirp.h | ||
628 | @@ -XXX,XX +XXX,XX @@ extern Slirp *slirp_instance; | ||
629 | |||
630 | void if_start(Slirp *); | ||
631 | |||
632 | +/* ncsi.c */ | ||
633 | +void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); | ||
634 | + | ||
635 | #ifndef _WIN32 | ||
636 | #include <netdb.h> | ||
637 | #endif | ||
638 | -- | ||
639 | 2.7.4 | ||
640 | |||
641 | diff view generated by jsdifflib |