Revision 658788c5
b/hw/xen_nic.c | ||
---|---|---|
41 | 41 |
#include "hw.h" |
42 | 42 |
#include "net.h" |
43 | 43 |
#include "net/checksum.h" |
44 |
#include "net/util.h" |
|
44 | 45 |
#include "qemu-char.h" |
45 | 46 |
#include "xen_backend.h" |
46 | 47 |
|
... | ... | |
56 | 57 |
struct netif_rx_sring *rxs; |
57 | 58 |
netif_tx_back_ring_t tx_ring; |
58 | 59 |
netif_rx_back_ring_t rx_ring; |
59 |
VLANClientState *vs; |
|
60 |
NICConf conf; |
|
61 |
NICState *nic; |
|
60 | 62 |
}; |
61 | 63 |
|
62 | 64 |
/* ------------------------------------------------------------- */ |
... | ... | |
179 | 181 |
tmpbuf = qemu_malloc(XC_PAGE_SIZE); |
180 | 182 |
memcpy(tmpbuf, page + txreq.offset, txreq.size); |
181 | 183 |
net_checksum_calculate(tmpbuf, txreq.size); |
182 |
qemu_send_packet(netdev->vs, tmpbuf, txreq.size);
|
|
184 |
qemu_send_packet(&netdev->nic->nc, tmpbuf, txreq.size);
|
|
183 | 185 |
} else { |
184 |
qemu_send_packet(netdev->vs, page + txreq.offset, txreq.size);
|
|
186 |
qemu_send_packet(&netdev->nic->nc, page + txreq.offset, txreq.size);
|
|
185 | 187 |
} |
186 | 188 |
xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1); |
187 | 189 |
net_tx_response(netdev, &txreq, NETIF_RSP_OKAY); |
... | ... | |
223 | 225 |
|
224 | 226 |
#define NET_IP_ALIGN 2 |
225 | 227 |
|
226 |
static int net_rx_ok(VLANClientState *vc)
|
|
228 |
static int net_rx_ok(VLANClientState *nc)
|
|
227 | 229 |
{ |
228 |
struct XenNetDev *netdev = vc->opaque;
|
|
230 |
struct XenNetDev *netdev = DO_UPCAST(NICState, nc, nc)->opaque;
|
|
229 | 231 |
RING_IDX rc, rp; |
230 | 232 |
|
231 | 233 |
if (netdev->xendev.be_state != XenbusStateConnected) |
... | ... | |
243 | 245 |
return 1; |
244 | 246 |
} |
245 | 247 |
|
246 |
static ssize_t net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size)
|
|
248 |
static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t size)
|
|
247 | 249 |
{ |
248 |
struct XenNetDev *netdev = vc->opaque;
|
|
250 |
struct XenNetDev *netdev = DO_UPCAST(NICState, nc, nc)->opaque;
|
|
249 | 251 |
netif_rx_request_t rxreq; |
250 | 252 |
RING_IDX rc, rp; |
251 | 253 |
void *page; |
... | ... | |
288 | 290 |
|
289 | 291 |
/* ------------------------------------------------------------- */ |
290 | 292 |
|
293 |
static NetClientInfo net_xen_info = { |
|
294 |
.type = NET_CLIENT_TYPE_NIC, |
|
295 |
.size = sizeof(NICState), |
|
296 |
.can_receive = net_rx_ok, |
|
297 |
.receive = net_rx_packet, |
|
298 |
}; |
|
299 |
|
|
291 | 300 |
static int net_init(struct XenDevice *xendev) |
292 | 301 |
{ |
293 | 302 |
struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev); |
294 |
VLANState *vlan; |
|
295 | 303 |
|
296 | 304 |
/* read xenstore entries */ |
297 | 305 |
if (netdev->mac == NULL) |
... | ... | |
301 | 309 |
if (netdev->mac == NULL) |
302 | 310 |
return -1; |
303 | 311 |
|
304 |
vlan = qemu_find_vlan(netdev->xendev.dev, 1); |
|
305 |
netdev->vs = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, |
|
306 |
vlan, NULL, "xen", NULL, |
|
307 |
net_rx_ok, net_rx_packet, NULL, NULL, |
|
308 |
NULL, netdev); |
|
309 |
snprintf(netdev->vs->info_str, sizeof(netdev->vs->info_str), |
|
312 |
if (net_parse_macaddr(netdev->conf.macaddr.a, netdev->mac) < 0) |
|
313 |
return -1; |
|
314 |
|
|
315 |
netdev->conf.vlan = qemu_find_vlan(netdev->xendev.dev, 1); |
|
316 |
netdev->conf.peer = NULL; |
|
317 |
|
|
318 |
netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf, |
|
319 |
"xen", NULL, netdev); |
|
320 |
|
|
321 |
snprintf(netdev->nic->nc.info_str, sizeof(netdev->nic->nc.info_str), |
|
310 | 322 |
"nic: xenbus vif macaddr=%s", netdev->mac); |
311 | 323 |
|
312 | 324 |
/* fill info */ |
... | ... | |
376 | 388 |
xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1); |
377 | 389 |
netdev->rxs = NULL; |
378 | 390 |
} |
379 |
if (netdev->vs) {
|
|
380 |
qemu_del_vlan_client(netdev->vs);
|
|
381 |
netdev->vs = NULL;
|
|
391 |
if (netdev->nic) {
|
|
392 |
qemu_del_vlan_client(&netdev->nic->nc);
|
|
393 |
netdev->nic = NULL;
|
|
382 | 394 |
} |
383 | 395 |
} |
384 | 396 |
|
Also available in: Unified diff