|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Register definitions and base classes for Ethernet Virtio. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __QEMUETHERNET_ |
|
19 #define __QEMUETHERNET_ |
|
20 |
|
21 #include <ethernet.h> |
|
22 #include <system.h> |
|
23 |
|
24 #define SVPDBG |
|
25 #ifdef SVPDBG |
|
26 #define DP(format...) Kern::Printf(format) |
|
27 #else |
|
28 #define DP(format...) |
|
29 #endif |
|
30 |
|
31 #define ETHERNET_PAYLOAD_SIZE 1500 |
|
32 |
|
33 #define VIRTIO_CONFIG_S_ACKNOWLEDGE 1 |
|
34 #define VIRTIO_CONFIG_S_DRIVER 2 |
|
35 #define VIRTIO_CONFIG_S_DRIVER_OK 4 |
|
36 #define VIRTIO_CONFIG_S_FAILED 0x80 |
|
37 |
|
38 /* This marks a buffer as continuing via the next field. */ |
|
39 #define VRING_DESC_F_NEXT 1 |
|
40 /* This marks a buffer as write-only (otherwise read-only). */ |
|
41 #define VRING_DESC_F_WRITE 2 |
|
42 |
|
43 #define TX_QUEUE 1 |
|
44 #define RX_QUEUE 0 |
|
45 |
|
46 #define VNET_MAC ((volatile TUint8 *)(0xc600c000 + 0x100)) |
|
47 #define VNET ((volatile TUint32 *)0xc600c000) |
|
48 |
|
49 enum { |
|
50 VIRTIO_ID = 0, |
|
51 VIRTIO_DEVTYPE = 1, |
|
52 VIRTIO_HOST_FEATURES = 2, |
|
53 VIRTIO_GUEST_FEATURES = 3, |
|
54 VIRTIO_QUEUE_BASE = 4, |
|
55 VIRTIO_QUEUE_NUM = 5, |
|
56 VIRTIO_QUEUE_SEL = 6, |
|
57 VIRTIO_QUEUE_NOTIFY = 7, |
|
58 VIRTIO_STATUS = 8, |
|
59 VIRTIO_INT_ENABLE = 9, |
|
60 VIRTIO_INT_STATUS = 10 |
|
61 }; |
|
62 |
|
63 typedef struct |
|
64 { |
|
65 #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 // Use csum_start, csum_offset |
|
66 TUint8 flags; |
|
67 #define VIRTIO_NET_HDR_GSO_NONE 0 // Not a GSO frame |
|
68 #define VIRTIO_NET_HDR_GSO_TCPV4 1 // GSO frame, IPv4 TCP (TSO) |
|
69 #define VIRTIO_NET_HDR_GSO_UDP 3 // GSO frame, IPv4 UDP (UFO) |
|
70 #define VIRTIO_NET_HDR_GSO_TCPV6 4 // GSO frame, IPv6 TCP |
|
71 #define VIRTIO_NET_HDR_GSO_ECN 0x80 // TCP has ECN set |
|
72 TUint8 gso_type; |
|
73 TUint16 hdr_len; |
|
74 TUint16 gso_size; |
|
75 TUint16 csum_start; |
|
76 TUint16 csum_offset; |
|
77 } virtio_net_hdr; |
|
78 |
|
79 typedef struct |
|
80 { |
|
81 TUint64 addr; |
|
82 TUint32 len; |
|
83 TUint16 flags; |
|
84 TUint16 next; |
|
85 } vring_desc; |
|
86 |
|
87 typedef struct |
|
88 { |
|
89 TUint16 flags; |
|
90 TUint16 idx; |
|
91 TUint16 ring[16]; |
|
92 |
|
93 } vring_avail; |
|
94 |
|
95 typedef struct |
|
96 { |
|
97 TUint16 flags; |
|
98 TUint16 idx; |
|
99 struct { |
|
100 TUint32 id; |
|
101 TUint32 len; |
|
102 } ring[16]; |
|
103 } vring_used; |
|
104 |
|
105 |
|
106 // |
|
107 // Class to identify the device as ethernet device for Symbian |
|
108 // |
|
109 class EthernetDevice : public DEthernet |
|
110 { |
|
111 public: |
|
112 EthernetDevice(); |
|
113 ~EthernetDevice(); |
|
114 TInt DoCreate(TInt aUnit, const TDesC8* anInfo); |
|
115 static void Isr(TAny* aPtr); |
|
116 |
|
117 // |
|
118 // Functions that we must implement as we are inheriting from abstract base class |
|
119 // |
|
120 virtual TInt Start(); |
|
121 virtual void Stop(TStopMode aMode); |
|
122 virtual void GetConfig(TEthernetConfigV01 &aConfig) const; |
|
123 virtual TInt ValidateConfig(const TEthernetConfigV01 &aConfig) const; |
|
124 virtual void CheckConfig(TEthernetConfigV01 &aConfig); |
|
125 virtual TInt Configure(TEthernetConfigV01 &aConfig); |
|
126 virtual void MacConfigure(TEthernetConfigV01 &aConfig); |
|
127 virtual void Caps(TDes8 &aCaps) const; |
|
128 virtual TInt DisableIrqs(); |
|
129 virtual void RestoreIrqs(TInt aIrq); |
|
130 virtual TDfcQue* DfcQ(TInt aUnit); |
|
131 virtual TInt Send(TBuf8<KMaxEthernetPacket+32> &aBuffer); |
|
132 virtual TInt ReceiveFrame(TBuf8<KMaxEthernetPacket+32> &aBuffer, TBool okToUse); |
|
133 |
|
134 private: |
|
135 |
|
136 TEthernetConfigV01 iDefaultConfig; |
|
137 TInt iInterruptId; |
|
138 TDfc iRxDfc; |
|
139 TUint32 iCreated; |
|
140 TUint32 iStarted; |
|
141 |
|
142 //Virtio structs for transmitting data to QEMU. |
|
143 volatile vring_desc *iTxDesc; |
|
144 volatile vring_avail *iTxAvail; |
|
145 volatile vring_used *iTxUsed; |
|
146 //Ring size hardcoded in QEMU. |
|
147 TUint tx_ring_size; |
|
148 |
|
149 //Virtio structs for receiving data from QEMU. |
|
150 volatile vring_desc *iRxDesc; |
|
151 volatile vring_avail *iRxAvail; |
|
152 volatile vring_used *iRxUsed; |
|
153 |
|
154 TUint rx_ring_size; |
|
155 TUint rx_last_used; |
|
156 |
|
157 //Virtio packet header definitions. |
|
158 virtio_net_hdr rx_header; |
|
159 virtio_net_hdr tx_header; |
|
160 |
|
161 //Buffers for Rx/Tx transmission. |
|
162 TBuf8<KMaxEthernetPacket+32> iTxBuffer; |
|
163 TBuf8<KMaxEthernetPacket+32> iRxBuffer; |
|
164 |
|
165 static void RxDfc(TAny* aPtr); |
|
166 |
|
167 //QEMU specific member functions |
|
168 void AllocRings(); |
|
169 void* AllocAligned(TUint16 size); |
|
170 void AddRx(); |
|
171 void SetMacAddress(void); |
|
172 }; |
|
173 |
|
174 #endif // __QEMUETHERNET_ |