VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/DevVirtioNet.cpp@ 33332

Last change on this file since 33332 was 33326, checked in by vboxsync, 14 years ago

virtio-net: 32-bit build fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 72.6 KB
Line 
1/* $Id: DevVirtioNet.cpp 33326 2010-10-21 21:11:08Z vboxsync $ */
2/** @file
3 * DevVirtioNet - Virtio Network Device
4 */
5
6/*
7 * Copyright (C) 2009-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19#define LOG_GROUP LOG_GROUP_DEV_VIRTIO_NET
20#define VNET_GC_SUPPORT
21#define VNET_WITH_GSO
22#define VNET_WITH_MERGEABLE_RX_BUFS
23
24#include <VBox/pdmdev.h>
25#include <VBox/pdmnetifs.h>
26#include <iprt/asm.h>
27#include <iprt/net.h>
28#include <iprt/semaphore.h>
29#ifdef IN_RING3
30# include <iprt/mem.h>
31# include <iprt/uuid.h>
32#endif /* IN_RING3 */
33#include "../Builtins.h"
34#include "../VirtIO/Virtio.h"
35
36
37#ifndef VBOX_DEVICE_STRUCT_TESTCASE
38
39#define INSTANCE(pState) pState->VPCI.szInstance
40#define STATUS pState->config.uStatus
41
42#ifdef IN_RING3
43
44#define VNET_PCI_SUBSYSTEM_ID 1 + VIRTIO_NET_ID
45#define VNET_PCI_CLASS 0x0200
46#define VNET_N_QUEUES 3
47#define VNET_NAME_FMT "VNet%d"
48
49#if 0
50/* Virtio Block Device */
51#define VNET_PCI_SUBSYSTEM_ID 1 + VIRTIO_BLK_ID
52#define VNET_PCI_CLASS 0x0180
53#define VNET_N_QUEUES 2
54#define VNET_NAME_FMT "VBlk%d"
55#endif
56
57#endif /* IN_RING3 */
58
59/* Forward declarations ******************************************************/
60RT_C_DECLS_BEGIN
61PDMBOTHCBDECL(int) vnetIOPortIn (PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t *pu32, unsigned cb);
62PDMBOTHCBDECL(int) vnetIOPortOut(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t u32, unsigned cb);
63RT_C_DECLS_END
64
65#endif /* VBOX_DEVICE_STRUCT_TESTCASE */
66
67
68#define VNET_TX_DELAY 150 /* 150 microseconds */
69#define VNET_MAX_FRAME_SIZE 65536 // TODO: Is it the right limit?
70#define VNET_MAC_FILTER_LEN 32
71#define VNET_MAX_VID (1 << 12)
72
73/* Virtio net features */
74#define VNET_F_CSUM 0x00000001 /* Host handles pkts w/ partial csum */
75#define VNET_F_GUEST_CSUM 0x00000002 /* Guest handles pkts w/ partial csum */
76#define VNET_F_MAC 0x00000020 /* Host has given MAC address. */
77#define VNET_F_GSO 0x00000040 /* Host handles pkts w/ any GSO type */
78#define VNET_F_GUEST_TSO4 0x00000080 /* Guest can handle TSOv4 in. */
79#define VNET_F_GUEST_TSO6 0x00000100 /* Guest can handle TSOv6 in. */
80#define VNET_F_GUEST_ECN 0x00000200 /* Guest can handle TSO[6] w/ ECN in. */
81#define VNET_F_GUEST_UFO 0x00000400 /* Guest can handle UFO in. */
82#define VNET_F_HOST_TSO4 0x00000800 /* Host can handle TSOv4 in. */
83#define VNET_F_HOST_TSO6 0x00001000 /* Host can handle TSOv6 in. */
84#define VNET_F_HOST_ECN 0x00002000 /* Host can handle TSO[6] w/ ECN in. */
85#define VNET_F_HOST_UFO 0x00004000 /* Host can handle UFO in. */
86#define VNET_F_MRG_RXBUF 0x00008000 /* Host can merge receive buffers. */
87#define VNET_F_STATUS 0x00010000 /* virtio_net_config.status available */
88#define VNET_F_CTRL_VQ 0x00020000 /* Control channel available */
89#define VNET_F_CTRL_RX 0x00040000 /* Control channel RX mode support */
90#define VNET_F_CTRL_VLAN 0x00080000 /* Control channel VLAN filtering */
91
92#define VNET_S_LINK_UP 1
93
94
95#ifdef _MSC_VER
96struct VNetPCIConfig
97#else /* !_MSC_VER */
98struct __attribute__ ((__packed__)) VNetPCIConfig
99#endif /* !_MSC_VER */
100{
101 RTMAC mac;
102 uint16_t uStatus;
103};
104AssertCompileMemberOffset(struct VNetPCIConfig, uStatus, 6);
105
106/**
107 * Device state structure. Holds the current state of device.
108 *
109 * @extends VPCISTATE
110 * @implements PDMINETWORKDOWN
111 * @implements PDMINETWORKCONFIG
112 */
113struct VNetState_st
114{
115 /* VPCISTATE must be the first member! */
116 VPCISTATE VPCI;
117
118// PDMCRITSECT csRx; /**< Protects RX queue. */
119
120 PDMINETWORKDOWN INetworkDown;
121 PDMINETWORKCONFIG INetworkConfig;
122 R3PTRTYPE(PPDMIBASE) pDrvBase; /**< Attached network driver. */
123 R3PTRTYPE(PPDMINETWORKUP) pDrv; /**< Connector of attached network driver. */
124
125 R3PTRTYPE(PPDMQUEUE) pCanRxQueueR3; /**< Rx wakeup signaller - R3. */
126 R0PTRTYPE(PPDMQUEUE) pCanRxQueueR0; /**< Rx wakeup signaller - R0. */
127 RCPTRTYPE(PPDMQUEUE) pCanRxQueueRC; /**< Rx wakeup signaller - RC. */
128# if HC_ARCH_BITS == 64
129 uint32_t padding;
130# endif
131
132 /**< Link Up(/Restore) Timer. */
133 PTMTIMERR3 pLinkUpTimer;
134
135#ifdef VNET_TX_DELAY
136 /**< Transmit Delay Timer - R3. */
137 PTMTIMERR3 pTxTimerR3;
138 /**< Transmit Delay Timer - R0. */
139 PTMTIMERR0 pTxTimerR0;
140 /**< Transmit Delay Timer - GC. */
141 PTMTIMERRC pTxTimerRC;
142
143# if HC_ARCH_BITS == 64
144 uint32_t padding2;
145# endif
146
147 uint32_t u32i;
148 uint32_t u32AvgDiff;
149 uint32_t u32MinDiff;
150 uint32_t u32MaxDiff;
151 uint64_t u64NanoTS;
152#endif /* VNET_TX_DELAY */
153
154 /** Indicates transmission in progress -- only one thread is allowed. */
155 uint32_t uIsTransmitting;
156
157 /** PCI config area holding MAC address as well as TBD. */
158 struct VNetPCIConfig config;
159 /** MAC address obtained from the configuration. */
160 RTMAC macConfigured;
161 /** True if physical cable is attached in configuration. */
162 bool fCableConnected;
163
164 /** Number of packet being sent/received to show in debug log. */
165 uint32_t u32PktNo;
166
167 /** N/A: */
168 bool volatile fMaybeOutOfSpace;
169
170 /** Promiscuous mode -- RX filter accepts all packets. */
171 bool fPromiscuous;
172 /** AllMulti mode -- RX filter accepts all multicast packets. */
173 bool fAllMulti;
174 /** The number of actually used slots in aMacTable. */
175 uint32_t nMacFilterEntries;
176 /** Array of MAC addresses accepted by RX filter. */
177 RTMAC aMacFilter[VNET_MAC_FILTER_LEN];
178 /** Bit array of VLAN filter, one bit per VLAN ID. */
179 uint8_t aVlanFilter[VNET_MAX_VID / sizeof(uint8_t)];
180
181 R3PTRTYPE(PVQUEUE) pRxQueue;
182 R3PTRTYPE(PVQUEUE) pTxQueue;
183 R3PTRTYPE(PVQUEUE) pCtlQueue;
184 /* Receive-blocking-related fields ***************************************/
185
186 /** EMT: Gets signalled when more RX descriptors become available. */
187 RTSEMEVENT hEventMoreRxDescAvail;
188
189 /* Statistic fields ******************************************************/
190
191 STAMCOUNTER StatReceiveBytes;
192 STAMCOUNTER StatTransmitBytes;
193 STAMCOUNTER StatReceiveGSO;
194 STAMCOUNTER StatTransmitPackets;
195 STAMCOUNTER StatTransmitGSO;
196 STAMCOUNTER StatTransmitCSum;
197#if defined(VBOX_WITH_STATISTICS)
198 STAMPROFILE StatReceive;
199 STAMPROFILE StatReceiveStore;
200 STAMPROFILEADV StatTransmit;
201 STAMPROFILE StatTransmitSend;
202 STAMPROFILE StatRxOverflow;
203 STAMCOUNTER StatRxOverflowWakeup;
204#endif /* VBOX_WITH_STATISTICS */
205
206};
207typedef struct VNetState_st VNETSTATE;
208typedef VNETSTATE *PVNETSTATE;
209
210#ifndef VBOX_DEVICE_STRUCT_TESTCASE
211
212#define VNETHDR_F_NEEDS_CSUM 1 // Use u16CSumStart, u16CSumOffset
213
214#define VNETHDR_GSO_NONE 0 // Not a GSO frame
215#define VNETHDR_GSO_TCPV4 1 // GSO frame, IPv4 TCP (TSO)
216#define VNETHDR_GSO_UDP 3 // GSO frame, IPv4 UDP (UFO)
217#define VNETHDR_GSO_TCPV6 4 // GSO frame, IPv6 TCP
218#define VNETHDR_GSO_ECN 0x80 // TCP has ECN set
219
220struct VNetHdr
221{
222 uint8_t u8Flags;
223 uint8_t u8GSOType;
224 uint16_t u16HdrLen;
225 uint16_t u16GSOSize;
226 uint16_t u16CSumStart;
227 uint16_t u16CSumOffset;
228};
229typedef struct VNetHdr VNETHDR;
230typedef VNETHDR *PVNETHDR;
231AssertCompileSize(VNETHDR, 10);
232
233struct VNetHdrMrx
234{
235 VNETHDR Hdr;
236 uint16_t u16NumBufs;
237};
238typedef struct VNetHdrMrx VNETHDRMRX;
239typedef VNETHDRMRX *PVNETHDRMRX;
240AssertCompileSize(VNETHDRMRX, 12);
241
242AssertCompileMemberOffset(VNETSTATE, VPCI, 0);
243
244#define VNET_OK 0
245#define VNET_ERROR 1
246typedef uint8_t VNETCTLACK;
247
248#define VNET_CTRL_CLS_RX_MODE 0
249#define VNET_CTRL_CMD_RX_MODE_PROMISC 0
250#define VNET_CTRL_CMD_RX_MODE_ALLMULTI 1
251
252#define VNET_CTRL_CLS_MAC 1
253#define VNET_CTRL_CMD_MAC_TABLE_SET 0
254
255#define VNET_CTRL_CLS_VLAN 2
256#define VNET_CTRL_CMD_VLAN_ADD 0
257#define VNET_CTRL_CMD_VLAN_DEL 1
258
259
260struct VNetCtlHdr
261{
262 uint8_t u8Class;
263 uint8_t u8Command;
264};
265typedef struct VNetCtlHdr VNETCTLHDR;
266typedef VNETCTLHDR *PVNETCTLHDR;
267AssertCompileSize(VNETCTLHDR, 2);
268
269/* Returns true if large packets are written into several RX buffers. */
270DECLINLINE(bool) vnetMergeableRxBuffers(PVNETSTATE pState)
271{
272 return !!(pState->VPCI.uGuestFeatures & VNET_F_MRG_RXBUF);
273}
274
275DECLINLINE(int) vnetCsEnter(PVNETSTATE pState, int rcBusy)
276{
277 return vpciCsEnter(&pState->VPCI, rcBusy);
278}
279
280DECLINLINE(void) vnetCsLeave(PVNETSTATE pState)
281{
282 vpciCsLeave(&pState->VPCI);
283}
284
285DECLINLINE(int) vnetCsRxEnter(PVNETSTATE pState, int rcBusy)
286{
287 // STAM_PROFILE_START(&pState->CTXSUFF(StatCsRx), a);
288 // int rc = PDMCritSectEnter(&pState->csRx, rcBusy);
289 // STAM_PROFILE_STOP(&pState->CTXSUFF(StatCsRx), a);
290 // return rc;
291 return VINF_SUCCESS;
292}
293
294DECLINLINE(void) vnetCsRxLeave(PVNETSTATE pState)
295{
296 // PDMCritSectLeave(&pState->csRx);
297}
298
299/**
300 * Dump a packet to debug log.
301 *
302 * @param pState The device state structure.
303 * @param cpPacket The packet.
304 * @param cb The size of the packet.
305 * @param cszText A string denoting direction of packet transfer.
306 */
307DECLINLINE(void) vnetPacketDump(PVNETSTATE pState, const uint8_t *cpPacket, size_t cb, const char *cszText)
308{
309#ifdef DEBUG
310 Log(("%s %s packet #%d (%d bytes):\n",
311 INSTANCE(pState), cszText, ++pState->u32PktNo, cb));
312 Log3(("%.*Rhxd\n", cb, cpPacket));
313#endif
314}
315
316
317
318PDMBOTHCBDECL(uint32_t) vnetGetHostFeatures(void *pvState)
319{
320 /* We support:
321 * - Host-provided MAC address
322 * - Link status reporting in config space
323 * - Control queue
324 * - RX mode setting
325 * - MAC filter table
326 * - VLAN filter
327 */
328 return VNET_F_MAC
329 | VNET_F_STATUS
330 | VNET_F_CTRL_VQ
331 | VNET_F_CTRL_RX
332 | VNET_F_CTRL_VLAN
333#ifdef VNET_WITH_GSO
334 | VNET_F_CSUM
335 | VNET_F_HOST_TSO4
336 | VNET_F_HOST_TSO6
337 | VNET_F_HOST_UFO
338#endif
339#ifdef VNET_WITH_MERGEABLE_RX_BUFS
340 | VNET_F_MRG_RXBUF
341#endif
342 ;
343}
344
345PDMBOTHCBDECL(uint32_t) vnetGetHostMinimalFeatures(void *pvState)
346{
347 return VNET_F_MAC;
348}
349
350PDMBOTHCBDECL(void) vnetSetHostFeatures(void *pvState, uint32_t uFeatures)
351{
352 // TODO: Nothing to do here yet
353 VNETSTATE *pState = (VNETSTATE *)pvState;
354 LogFlow(("%s vnetSetHostFeatures: uFeatures=%x\n", INSTANCE(pState), uFeatures));
355}
356
357PDMBOTHCBDECL(int) vnetGetConfig(void *pvState, uint32_t port, uint32_t cb, void *data)
358{
359 VNETSTATE *pState = (VNETSTATE *)pvState;
360 if (port + cb > sizeof(struct VNetPCIConfig))
361 {
362 Log(("%s vnetGetConfig: Read beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(pState), port, cb));
363 return VERR_IOM_IOPORT_UNUSED;
364 }
365 memcpy(data, ((uint8_t*)&pState->config) + port, cb);
366 return VINF_SUCCESS;
367}
368
369PDMBOTHCBDECL(int) vnetSetConfig(void *pvState, uint32_t port, uint32_t cb, void *data)
370{
371 VNETSTATE *pState = (VNETSTATE *)pvState;
372 if (port + cb > sizeof(struct VNetPCIConfig))
373 {
374 Log(("%s vnetGetConfig: Write beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(pState), port, cb));
375 if (port < sizeof(struct VNetPCIConfig))
376 memcpy(((uint8_t*)&pState->config) + port, data,
377 sizeof(struct VNetPCIConfig) - port);
378 return VINF_SUCCESS;
379 }
380 memcpy(((uint8_t*)&pState->config) + port, data, cb);
381 return VINF_SUCCESS;
382}
383
384/**
385 * Hardware reset. Revert all registers to initial values.
386 *
387 * @param pState The device state structure.
388 */
389PDMBOTHCBDECL(int) vnetReset(void *pvState)
390{
391 VNETSTATE *pState = (VNETSTATE*)pvState;
392 Log(("%s Reset triggered\n", INSTANCE(pState)));
393
394 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY);
395 if (RT_UNLIKELY(rc != VINF_SUCCESS))
396 {
397 LogRel(("vnetReset failed to enter RX critical section!\n"));
398 return rc;
399 }
400 vpciReset(&pState->VPCI);
401 vnetCsRxLeave(pState);
402
403 // TODO: Implement reset
404 if (pState->fCableConnected)
405 STATUS = VNET_S_LINK_UP;
406 else
407 STATUS = 0;
408
409 /*
410 * By default we pass all packets up since the older guests cannot control
411 * virtio mode.
412 */
413 pState->fPromiscuous = true;
414 pState->fAllMulti = false;
415 pState->nMacFilterEntries = 0;
416 memset(pState->aMacFilter, 0, VNET_MAC_FILTER_LEN * sizeof(RTMAC));
417 memset(pState->aVlanFilter, 0, sizeof(pState->aVlanFilter));
418 pState->uIsTransmitting = 0;
419#ifndef IN_RING3
420 return VINF_IOM_HC_IOPORT_WRITE;
421#else
422 if (pState->pDrv)
423 pState->pDrv->pfnSetPromiscuousMode(pState->pDrv, true);
424 return VINF_SUCCESS;
425#endif
426}
427
428#ifdef IN_RING3
429
430/**
431 * Wakeup the RX thread.
432 */
433static void vnetWakeupReceive(PPDMDEVINS pDevIns)
434{
435 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE *);
436 if ( pState->fMaybeOutOfSpace
437 && pState->hEventMoreRxDescAvail != NIL_RTSEMEVENT)
438 {
439 STAM_COUNTER_INC(&pState->StatRxOverflowWakeup);
440 Log(("%s Waking up Out-of-RX-space semaphore\n", INSTANCE(pState)));
441 RTSemEventSignal(pState->hEventMoreRxDescAvail);
442 }
443}
444
445/**
446 * Link Up Timer handler.
447 *
448 * @param pDevIns Pointer to device instance structure.
449 * @param pTimer Pointer to the timer.
450 * @param pvUser NULL.
451 * @thread EMT
452 */
453static DECLCALLBACK(void) vnetLinkUpTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
454{
455 VNETSTATE *pState = (VNETSTATE *)pvUser;
456
457 int rc = vnetCsEnter(pState, VERR_SEM_BUSY);
458 if (RT_UNLIKELY(rc != VINF_SUCCESS))
459 return;
460 STATUS |= VNET_S_LINK_UP;
461 vpciRaiseInterrupt(&pState->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
462 vnetWakeupReceive(pDevIns);
463 vnetCsLeave(pState);
464}
465
466
467
468
469/**
470 * Handler for the wakeup signaller queue.
471 */
472static DECLCALLBACK(bool) vnetCanRxQueueConsumer(PPDMDEVINS pDevIns, PPDMQUEUEITEMCORE pItem)
473{
474 vnetWakeupReceive(pDevIns);
475 return true;
476}
477
478#endif /* IN_RING3 */
479
480/**
481 * This function is called when the driver becomes ready.
482 *
483 * @param pState The device state structure.
484 */
485PDMBOTHCBDECL(void) vnetReady(void *pvState)
486{
487 VNETSTATE *pState = (VNETSTATE*)pvState;
488 Log(("%s Driver became ready, waking up RX thread...\n", INSTANCE(pState)));
489#ifdef IN_RING3
490 vnetWakeupReceive(pState->VPCI.CTX_SUFF(pDevIns));
491#else
492 PPDMQUEUEITEMCORE pItem = PDMQueueAlloc(pState->CTX_SUFF(pCanRxQueue));
493 if (pItem)
494 PDMQueueInsert(pState->CTX_SUFF(pCanRxQueue), pItem);
495#endif
496}
497
498/**
499 * Port I/O Handler for IN operations.
500 *
501 * @returns VBox status code.
502 *
503 * @param pDevIns The device instance.
504 * @param pvUser Pointer to the device state structure.
505 * @param port Port number used for the IN operation.
506 * @param pu32 Where to store the result.
507 * @param cb Number of bytes read.
508 * @thread EMT
509 */
510PDMBOTHCBDECL(int) vnetIOPortIn(PPDMDEVINS pDevIns, void *pvUser,
511 RTIOPORT port, uint32_t *pu32, unsigned cb)
512{
513 return vpciIOPortIn(pDevIns, pvUser, port, pu32, cb,
514 vnetGetHostFeatures,
515 vnetGetConfig);
516}
517
518
519/**
520 * Port I/O Handler for OUT operations.
521 *
522 * @returns VBox status code.
523 *
524 * @param pDevIns The device instance.
525 * @param pvUser User argument.
526 * @param Port Port number used for the IN operation.
527 * @param u32 The value to output.
528 * @param cb The value size in bytes.
529 * @thread EMT
530 */
531PDMBOTHCBDECL(int) vnetIOPortOut(PPDMDEVINS pDevIns, void *pvUser,
532 RTIOPORT port, uint32_t u32, unsigned cb)
533{
534 return vpciIOPortOut(pDevIns, pvUser, port, u32, cb,
535 vnetGetHostMinimalFeatures,
536 vnetGetHostFeatures,
537 vnetSetHostFeatures,
538 vnetReset,
539 vnetReady,
540 vnetSetConfig);
541}
542
543
544#ifdef IN_RING3
545
546/**
547 * Check if the device can receive data now.
548 * This must be called before the pfnRecieve() method is called.
549 *
550 * @remarks As a side effect this function enables queue notification
551 * if it cannot receive because the queue is empty.
552 * It disables notification if it can receive.
553 *
554 * @returns VERR_NET_NO_BUFFER_SPACE if it cannot.
555 * @param pInterface Pointer to the interface structure containing the called function pointer.
556 * @thread RX
557 */
558static int vnetCanReceive(VNETSTATE *pState)
559{
560 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY);
561 AssertRCReturn(rc, rc);
562
563 LogFlow(("%s vnetCanReceive\n", INSTANCE(pState)));
564 if (!(pState->VPCI.uStatus & VPCI_STATUS_DRV_OK))
565 rc = VERR_NET_NO_BUFFER_SPACE;
566 else if (!vqueueIsReady(&pState->VPCI, pState->pRxQueue))
567 rc = VERR_NET_NO_BUFFER_SPACE;
568 else if (vqueueIsEmpty(&pState->VPCI, pState->pRxQueue))
569 {
570 vringSetNotification(&pState->VPCI, &pState->pRxQueue->VRing, true);
571 rc = VERR_NET_NO_BUFFER_SPACE;
572 }
573 else
574 {
575 vringSetNotification(&pState->VPCI, &pState->pRxQueue->VRing, false);
576 rc = VINF_SUCCESS;
577 }
578
579 LogFlow(("%s vnetCanReceive -> %Rrc\n", INSTANCE(pState), rc));
580 vnetCsRxLeave(pState);
581 return rc;
582}
583
584/**
585 * @interface_method_impl{PDMINETWORKDOWN,pfnWaitReceiveAvail}
586 */
587static DECLCALLBACK(int) vnetNetworkDown_WaitReceiveAvail(PPDMINETWORKDOWN pInterface, RTMSINTERVAL cMillies)
588{
589 VNETSTATE *pState = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);
590 LogFlow(("%s vnetNetworkDown_WaitReceiveAvail(cMillies=%u)\n", INSTANCE(pState), cMillies));
591 int rc = vnetCanReceive(pState);
592
593 if (RT_SUCCESS(rc))
594 return VINF_SUCCESS;
595 if (RT_UNLIKELY(cMillies == 0))
596 return VERR_NET_NO_BUFFER_SPACE;
597
598 rc = VERR_INTERRUPTED;
599 ASMAtomicXchgBool(&pState->fMaybeOutOfSpace, true);
600 STAM_PROFILE_START(&pState->StatRxOverflow, a);
601
602 VMSTATE enmVMState;
603 while (RT_LIKELY( (enmVMState = PDMDevHlpVMState(pState->VPCI.CTX_SUFF(pDevIns))) == VMSTATE_RUNNING
604 || enmVMState == VMSTATE_RUNNING_LS))
605 {
606 int rc2 = vnetCanReceive(pState);
607 if (RT_SUCCESS(rc2))
608 {
609 rc = VINF_SUCCESS;
610 break;
611 }
612 Log(("%s vnetNetworkDown_WaitReceiveAvail: waiting cMillies=%u...\n",
613 INSTANCE(pState), cMillies));
614 RTSemEventWait(pState->hEventMoreRxDescAvail, cMillies);
615 }
616 STAM_PROFILE_STOP(&pState->StatRxOverflow, a);
617 ASMAtomicXchgBool(&pState->fMaybeOutOfSpace, false);
618
619 LogFlow(("%s vnetNetworkDown_WaitReceiveAvail -> %d\n", INSTANCE(pState), rc));
620 return rc;
621}
622
623
624/**
625 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
626 */
627static DECLCALLBACK(void *) vnetQueryInterface(struct PDMIBASE *pInterface, const char *pszIID)
628{
629 VNETSTATE *pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, VPCI.IBase);
630 Assert(&pThis->VPCI.IBase == pInterface);
631
632 PDMIBASE_RETURN_INTERFACE(pszIID, PDMINETWORKDOWN, &pThis->INetworkDown);
633 PDMIBASE_RETURN_INTERFACE(pszIID, PDMINETWORKCONFIG, &pThis->INetworkConfig);
634 return vpciQueryInterface(pInterface, pszIID);
635}
636
637/**
638 * Returns true if it is a broadcast packet.
639 *
640 * @returns true if destination address indicates broadcast.
641 * @param pvBuf The ethernet packet.
642 */
643DECLINLINE(bool) vnetIsBroadcast(const void *pvBuf)
644{
645 static const uint8_t s_abBcastAddr[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
646 return memcmp(pvBuf, s_abBcastAddr, sizeof(s_abBcastAddr)) == 0;
647}
648
649/**
650 * Returns true if it is a multicast packet.
651 *
652 * @remarks returns true for broadcast packets as well.
653 * @returns true if destination address indicates multicast.
654 * @param pvBuf The ethernet packet.
655 */
656DECLINLINE(bool) vnetIsMulticast(const void *pvBuf)
657{
658 return (*(char*)pvBuf) & 1;
659}
660
661/**
662 * Determines if the packet is to be delivered to upper layer.
663 *
664 * @returns true if packet is intended for this node.
665 * @param pState Pointer to the state structure.
666 * @param pvBuf The ethernet packet.
667 * @param cb Number of bytes available in the packet.
668 */
669static bool vnetAddressFilter(PVNETSTATE pState, const void *pvBuf, size_t cb)
670{
671 if (pState->fPromiscuous)
672 return true;
673
674 /* Ignore everything outside of our VLANs */
675 uint16_t *u16Ptr = (uint16_t*)pvBuf;
676 /* Compare TPID with VLAN Ether Type */
677 if ( u16Ptr[6] == RT_H2BE_U16(0x8100)
678 && !ASMBitTest(pState->aVlanFilter, RT_BE2H_U16(u16Ptr[7]) & 0xFFF))
679 {
680 Log4(("%s vnetAddressFilter: not our VLAN, returning false\n", INSTANCE(pState)));
681 return false;
682 }
683
684 if (vnetIsBroadcast(pvBuf))
685 return true;
686
687 if (pState->fAllMulti && vnetIsMulticast(pvBuf))
688 return true;
689
690 if (!memcmp(pState->config.mac.au8, pvBuf, sizeof(RTMAC)))
691 return true;
692 Log4(("%s vnetAddressFilter: %RTmac (conf) != %RTmac (dest)\n",
693 INSTANCE(pState), pState->config.mac.au8, pvBuf));
694
695 for (unsigned i = 0; i < pState->nMacFilterEntries; i++)
696 if (!memcmp(&pState->aMacFilter[i], pvBuf, sizeof(RTMAC)))
697 return true;
698
699 Log2(("%s vnetAddressFilter: failed all tests, returning false, packet dump follows:\n", INSTANCE(pState)));
700 vnetPacketDump(pState, (const uint8_t*)pvBuf, cb, "<-- Incoming");
701
702 return false;
703}
704
705/**
706 * Pad and store received packet.
707 *
708 * @remarks Make sure that the packet appears to upper layer as one coming
709 * from real Ethernet: pad it and insert FCS.
710 *
711 * @returns VBox status code.
712 * @param pState The device state structure.
713 * @param pvBuf The available data.
714 * @param cb Number of bytes available in the buffer.
715 * @thread RX
716 */
717static int vnetHandleRxPacket(PVNETSTATE pState, const void *pvBuf, size_t cb,
718 PCPDMNETWORKGSO pGso)
719{
720 VNETHDRMRX Hdr;
721 PVNETHDRMRX pHdr;
722 unsigned uHdrLen;
723 RTGCPHYS addrHdrMrx = 0;
724
725 if (pGso)
726 {
727 Log2(("%s vnetHandleRxPacket: gso type=%x cbHdr=%u mss=%u"
728 " off1=0x%x off2=0x%x\n", INSTANCE(pState), pGso->u8Type,
729 pGso->cbHdrs, pGso->cbMaxSeg, pGso->offHdr1, pGso->offHdr2));
730 Hdr.Hdr.u8Flags = VNETHDR_F_NEEDS_CSUM;
731 switch (pGso->u8Type)
732 {
733 case PDMNETWORKGSOTYPE_IPV4_TCP:
734 Hdr.Hdr.u8GSOType = VNETHDR_GSO_TCPV4;
735 Hdr.Hdr.u16CSumOffset = RT_OFFSETOF(RTNETTCP, th_sum);
736 break;
737 case PDMNETWORKGSOTYPE_IPV6_TCP:
738 Hdr.Hdr.u8GSOType = VNETHDR_GSO_TCPV6;
739 Hdr.Hdr.u16CSumOffset = RT_OFFSETOF(RTNETTCP, th_sum);
740 break;
741 case PDMNETWORKGSOTYPE_IPV4_UDP:
742 Hdr.Hdr.u8GSOType = VNETHDR_GSO_UDP;
743 Hdr.Hdr.u16CSumOffset = RT_OFFSETOF(RTNETUDP, uh_sum);
744 break;
745 default:
746 return VERR_INVALID_PARAMETER;
747 }
748 Hdr.Hdr.u16HdrLen = pGso->cbHdrs;
749 Hdr.Hdr.u16GSOSize = pGso->cbMaxSeg;
750 Hdr.Hdr.u16CSumStart = pGso->offHdr2;
751 STAM_REL_COUNTER_INC(&pState->StatReceiveGSO);
752 }
753 else
754 {
755 Hdr.Hdr.u8Flags = 0;
756 Hdr.Hdr.u8GSOType = VNETHDR_GSO_NONE;
757 }
758
759 if (vnetMergeableRxBuffers(pState))
760 uHdrLen = sizeof(VNETHDRMRX);
761 else
762 uHdrLen = sizeof(VNETHDR);
763
764 //vnetPacketDump(pState, (const uint8_t*)pvBuf, cb, "<-- Incoming");
765
766 unsigned int uOffset = 0;
767 unsigned int nElem;
768 for (nElem = 0; uOffset < cb; nElem++)
769 {
770 VQUEUEELEM elem;
771 unsigned int nSeg = 0, uElemSize = 0, cbReserved = 0;
772
773 if (!vqueueGet(&pState->VPCI, pState->pRxQueue, &elem))
774 {
775 /*
776 * @todo: It is possible to run out of RX buffers if only a few
777 * were added and we received a big packet.
778 */
779 Log(("%s vnetHandleRxPacket: Suddenly there is no space in receive queue!\n", INSTANCE(pState)));
780 return VERR_INTERNAL_ERROR;
781 }
782
783 if (elem.nIn < 1)
784 {
785 Log(("%s vnetHandleRxPacket: No writable descriptors in receive queue!\n", INSTANCE(pState)));
786 return VERR_INTERNAL_ERROR;
787 }
788
789 if (nElem == 0)
790 {
791 if (vnetMergeableRxBuffers(pState))
792 {
793 addrHdrMrx = elem.aSegsIn[nSeg].addr;
794 cbReserved = uHdrLen;
795 }
796 else
797 {
798 /* The very first segment of the very first element gets the header. */
799 if (elem.aSegsIn[nSeg].cb != sizeof(VNETHDR))
800 {
801 Log(("%s vnetHandleRxPacket: The first descriptor does match the header size!\n", INSTANCE(pState)));
802 return VERR_INTERNAL_ERROR;
803 }
804 elem.aSegsIn[nSeg++].pv = &Hdr;
805 }
806 uElemSize += uHdrLen;
807 }
808 while (nSeg < elem.nIn && uOffset < cb)
809 {
810 unsigned int uSize = (unsigned int)RT_MIN(elem.aSegsIn[nSeg].cb - (nSeg?0:cbReserved),
811 cb - uOffset);
812 elem.aSegsIn[nSeg++].pv = (uint8_t*)pvBuf + uOffset;
813 uOffset += uSize;
814 uElemSize += uSize;
815 }
816 STAM_PROFILE_START(&pState->StatReceiveStore, a);
817 vqueuePut(&pState->VPCI, pState->pRxQueue, &elem, uElemSize, cbReserved);
818 STAM_PROFILE_STOP(&pState->StatReceiveStore, a);
819 if (!vnetMergeableRxBuffers(pState))
820 break;
821 cbReserved = 0;
822 }
823 if (vnetMergeableRxBuffers(pState))
824 {
825 Hdr.u16NumBufs = nElem;
826 int rc = PDMDevHlpPhysWrite(pState->VPCI.CTX_SUFF(pDevIns), addrHdrMrx,
827 &Hdr, sizeof(Hdr));
828 if (RT_FAILURE(rc))
829 {
830 Log(("%s vnetHandleRxPacket: Failed to write merged RX buf header: %Rrc\n",
831 INSTANCE(pState), rc));
832 return rc;
833 }
834 }
835 vqueueSync(&pState->VPCI, pState->pRxQueue);
836 if (uOffset < cb)
837 {
838 Log(("%s vnetHandleRxPacket: Packet did not fit into RX queue (packet size=%u)!\n",
839 INSTANCE(pState), cb));
840 return VERR_TOO_MUCH_DATA;
841 }
842
843 return VINF_SUCCESS;
844}
845
846/**
847 * @interface_method_impl{PDMINETWORKDOWN,pfnReceiveGso}
848 */
849static DECLCALLBACK(int) vnetNetworkDown_ReceiveGso(PPDMINETWORKDOWN pInterface,
850 const void *pvBuf, size_t cb,
851 PCPDMNETWORKGSO pGso)
852{
853 VNETSTATE *pState = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);
854
855 Log2(("%s vnetNetworkDown_ReceiveGso: pvBuf=%p cb=%u pGso=%p\n",
856 INSTANCE(pState), pvBuf, cb, pGso));
857 int rc = vnetCanReceive(pState);
858 if (RT_FAILURE(rc))
859 return rc;
860
861 /* Drop packets if VM is not running or cable is disconnected. */
862 VMSTATE enmVMState = PDMDevHlpVMState(pState->VPCI.CTX_SUFF(pDevIns));
863 if (( enmVMState != VMSTATE_RUNNING
864 && enmVMState != VMSTATE_RUNNING_LS)
865 || !(STATUS & VNET_S_LINK_UP))
866 return VINF_SUCCESS;
867
868 STAM_PROFILE_START(&pState->StatReceive, a);
869 vpciSetReadLed(&pState->VPCI, true);
870 if (vnetAddressFilter(pState, pvBuf, cb))
871 {
872 rc = vnetCsRxEnter(pState, VERR_SEM_BUSY);
873 if (RT_SUCCESS(rc))
874 {
875 rc = vnetHandleRxPacket(pState, pvBuf, cb, pGso);
876 STAM_REL_COUNTER_ADD(&pState->StatReceiveBytes, cb);
877 vnetCsRxLeave(pState);
878 }
879 }
880 vpciSetReadLed(&pState->VPCI, false);
881 STAM_PROFILE_STOP(&pState->StatReceive, a);
882 return rc;
883}
884
885/**
886 * @interface_method_impl{PDMINETWORKDOWN,pfnReceive}
887 */
888static DECLCALLBACK(int) vnetNetworkDown_Receive(PPDMINETWORKDOWN pInterface, const void *pvBuf, size_t cb)
889{
890 return vnetNetworkDown_ReceiveGso(pInterface, pvBuf, cb, NULL);
891}
892
893/**
894 * Gets the current Media Access Control (MAC) address.
895 *
896 * @returns VBox status code.
897 * @param pInterface Pointer to the interface structure containing the called function pointer.
898 * @param pMac Where to store the MAC address.
899 * @thread EMT
900 */
901static DECLCALLBACK(int) vnetGetMac(PPDMINETWORKCONFIG pInterface, PRTMAC pMac)
902{
903 VNETSTATE *pState = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);
904 memcpy(pMac, pState->config.mac.au8, sizeof(RTMAC));
905 return VINF_SUCCESS;
906}
907
908/**
909 * Gets the new link state.
910 *
911 * @returns The current link state.
912 * @param pInterface Pointer to the interface structure containing the called function pointer.
913 * @thread EMT
914 */
915static DECLCALLBACK(PDMNETWORKLINKSTATE) vnetGetLinkState(PPDMINETWORKCONFIG pInterface)
916{
917 VNETSTATE *pState = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);
918 if (STATUS & VNET_S_LINK_UP)
919 return PDMNETWORKLINKSTATE_UP;
920 return PDMNETWORKLINKSTATE_DOWN;
921}
922
923
924/**
925 * Sets the new link state.
926 *
927 * @returns VBox status code.
928 * @param pInterface Pointer to the interface structure containing the called function pointer.
929 * @param enmState The new link state
930 */
931static DECLCALLBACK(int) vnetSetLinkState(PPDMINETWORKCONFIG pInterface, PDMNETWORKLINKSTATE enmState)
932{
933 VNETSTATE *pState = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);
934 bool fOldUp = !!(STATUS & VNET_S_LINK_UP);
935 bool fNewUp = enmState == PDMNETWORKLINKSTATE_UP;
936
937 if (fNewUp != fOldUp)
938 {
939 if (fNewUp)
940 {
941 Log(("%s Link is up\n", INSTANCE(pState)));
942 STATUS |= VNET_S_LINK_UP;
943 vpciRaiseInterrupt(&pState->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
944 }
945 else
946 {
947 Log(("%s Link is down\n", INSTANCE(pState)));
948 STATUS &= ~VNET_S_LINK_UP;
949 vpciRaiseInterrupt(&pState->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
950 }
951 if (pState->pDrv)
952 pState->pDrv->pfnNotifyLinkChanged(pState->pDrv, enmState);
953 }
954 return VINF_SUCCESS;
955}
956
957static DECLCALLBACK(void) vnetQueueReceive(void *pvState, PVQUEUE pQueue)
958{
959 VNETSTATE *pState = (VNETSTATE*)pvState;
960 Log(("%s Receive buffers has been added, waking up receive thread.\n", INSTANCE(pState)));
961 vnetWakeupReceive(pState->VPCI.CTX_SUFF(pDevIns));
962}
963
964/**
965 * Sets up the GSO context according to the Virtio header.
966 *
967 * @param pGso The GSO context to setup.
968 * @param pCtx The context descriptor.
969 */
970DECLINLINE(PPDMNETWORKGSO) vnetSetupGsoCtx(PPDMNETWORKGSO pGso, VNETHDR const *pHdr)
971{
972 pGso->u8Type = PDMNETWORKGSOTYPE_INVALID;
973
974 if (pHdr->u8GSOType & VNETHDR_GSO_ECN)
975 {
976 AssertMsgFailed(("Unsupported flag in virtio header: ECN\n"));
977 return NULL;
978 }
979 switch (pHdr->u8GSOType & ~VNETHDR_GSO_ECN)
980 {
981 case VNETHDR_GSO_TCPV4:
982 pGso->u8Type = PDMNETWORKGSOTYPE_IPV4_TCP;
983 break;
984 case VNETHDR_GSO_TCPV6:
985 pGso->u8Type = PDMNETWORKGSOTYPE_IPV6_TCP;
986 break;
987 case VNETHDR_GSO_UDP:
988 pGso->u8Type = PDMNETWORKGSOTYPE_IPV4_UDP;
989 break;
990 default:
991 return NULL;
992 }
993 if (pHdr->u8Flags & VNETHDR_F_NEEDS_CSUM)
994 pGso->offHdr2 = pHdr->u16CSumStart;
995 else
996 {
997 AssertMsgFailed(("GSO without checksum offloading!\n"));
998 return NULL;
999 }
1000 pGso->offHdr1 = sizeof(RTNETETHERHDR);
1001 pGso->cbHdrs = pHdr->u16HdrLen;
1002 pGso->cbMaxSeg = pHdr->u16GSOSize;
1003 return pGso;
1004}
1005
1006DECLINLINE(uint16_t) vnetCSum16(const void *pvBuf, size_t cb)
1007{
1008 uint32_t csum = 0;
1009 uint16_t *pu16 = (uint16_t *)pvBuf;
1010
1011 while (cb > 1)
1012 {
1013 csum += *pu16++;
1014 cb -= 2;
1015 }
1016 if (cb)
1017 csum += *(uint8_t*)pu16;
1018 while (csum >> 16)
1019 csum = (csum >> 16) + (csum & 0xFFFF);
1020 return ~csum;
1021}
1022
1023DECLINLINE(void) vnetCompleteChecksum(uint8_t *pBuf, unsigned cbSize, uint16_t uStart, uint16_t uOffset)
1024{
1025 *(uint16_t*)(pBuf + uStart + uOffset) = vnetCSum16(pBuf + uStart, cbSize - uStart);
1026}
1027
1028static void vnetTransmitPendingPackets(PVNETSTATE pState, PVQUEUE pQueue, bool fOnWorkerThread)
1029{
1030 /*
1031 * Only one thread is allowed to transmit at a time, others should skip
1032 * transmission as the packets will be picked up by the transmitting
1033 * thread.
1034 */
1035 if (!ASMAtomicCmpXchgU32(&pState->uIsTransmitting, 1, 0))
1036 return;
1037
1038 if ((pState->VPCI.uStatus & VPCI_STATUS_DRV_OK) == 0)
1039 {
1040 Log(("%s Ignoring transmit requests from non-existent driver (status=0x%x).\n",
1041 INSTANCE(pState), pState->VPCI.uStatus));
1042 return;
1043 }
1044
1045 PPDMINETWORKUP pDrv = pState->pDrv;
1046 if (pDrv)
1047 {
1048 int rc = pDrv->pfnBeginXmit(pDrv, fOnWorkerThread);
1049 Assert(rc == VINF_SUCCESS || rc == VERR_TRY_AGAIN);
1050 if (rc == VERR_TRY_AGAIN)
1051 {
1052 ASMAtomicWriteU32(&pState->uIsTransmitting, 0);
1053 return;
1054 }
1055 }
1056
1057 unsigned int uHdrLen;
1058 if (vnetMergeableRxBuffers(pState))
1059 uHdrLen = sizeof(VNETHDRMRX);
1060 else
1061 uHdrLen = sizeof(VNETHDR);
1062
1063 Log3(("%s vnetTransmitPendingPackets: About to trasmit %d pending packets\n", INSTANCE(pState),
1064 vringReadAvailIndex(&pState->VPCI, &pState->pTxQueue->VRing) - pState->pTxQueue->uNextAvailIndex));
1065
1066 vpciSetWriteLed(&pState->VPCI, true);
1067
1068 VQUEUEELEM elem;
1069 while (vqueueGet(&pState->VPCI, pQueue, &elem))
1070 {
1071 unsigned int uOffset = 0;
1072 if (elem.nOut < 2 || elem.aSegsOut[0].cb != uHdrLen)
1073 {
1074 Log(("%s vnetQueueTransmit: The first segment is not the header! (%u < 2 || %u != %u).\n",
1075 INSTANCE(pState), elem.nOut, elem.aSegsOut[0].cb, uHdrLen));
1076 break; /* For now we simply ignore the header, but it must be there anyway! */
1077 }
1078 else
1079 {
1080 unsigned int uSize = 0;
1081 STAM_PROFILE_ADV_START(&pState->StatTransmit, a);
1082 /* Compute total frame size. */
1083 for (unsigned int i = 1; i < elem.nOut; i++)
1084 uSize += elem.aSegsOut[i].cb;
1085 Assert(uSize <= VNET_MAX_FRAME_SIZE);
1086 if (pState->pDrv)
1087 {
1088 VNETHDR Hdr;
1089 PDMNETWORKGSO Gso, *pGso;
1090
1091 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[0].addr,
1092 &Hdr, sizeof(Hdr));
1093
1094 STAM_REL_COUNTER_INC(&pState->StatTransmitPackets);
1095
1096 STAM_PROFILE_START(&pState->StatTransmitSend, a);
1097
1098 pGso = vnetSetupGsoCtx(&Gso, &Hdr);
1099 /** @todo Optimize away the extra copying! (lazy bird) */
1100 PPDMSCATTERGATHER pSgBuf;
1101 int rc = pState->pDrv->pfnAllocBuf(pState->pDrv, uSize, pGso, &pSgBuf);
1102 if (RT_SUCCESS(rc))
1103 {
1104 Assert(pSgBuf->cSegs == 1);
1105 /* Assemble a complete frame. */
1106 for (unsigned int i = 1; i < elem.nOut; i++)
1107 {
1108 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[i].addr,
1109 ((uint8_t*)pSgBuf->aSegs[0].pvSeg) + uOffset,
1110 elem.aSegsOut[i].cb);
1111 uOffset += elem.aSegsOut[i].cb;
1112 }
1113 pSgBuf->cbUsed = uSize;
1114 //vnetPacketDump(pState, (uint8_t*)pSgBuf->aSegs[0].pvSeg, uSize, "--> Outgoing");
1115 if (pGso)
1116 STAM_REL_COUNTER_INC(&pState->StatTransmitGSO);
1117 else if (Hdr.u8Flags & VNETHDR_F_NEEDS_CSUM)
1118 {
1119 STAM_REL_COUNTER_INC(&pState->StatTransmitCSum);
1120 /*
1121 * This is not GSO frame but checksum offloading is requested.
1122 */
1123 vnetCompleteChecksum((uint8_t*)pSgBuf->aSegs[0].pvSeg, uSize,
1124 Hdr.u16CSumStart, Hdr.u16CSumOffset);
1125 }
1126
1127 rc = pState->pDrv->pfnSendBuf(pState->pDrv, pSgBuf, false);
1128 }
1129 else
1130 LogRel(("virtio-net: failed to allocate SG buffer: size=%u rc=%Rrc\n", uSize, rc));
1131
1132 STAM_PROFILE_STOP(&pState->StatTransmitSend, a);
1133 STAM_REL_COUNTER_ADD(&pState->StatTransmitBytes, uOffset);
1134 }
1135 }
1136 vqueuePut(&pState->VPCI, pQueue, &elem, sizeof(VNETHDR) + uOffset);
1137 vqueueSync(&pState->VPCI, pQueue);
1138 STAM_PROFILE_ADV_STOP(&pState->StatTransmit, a);
1139 }
1140 vpciSetWriteLed(&pState->VPCI, false);
1141
1142 if (pDrv)
1143 pDrv->pfnEndXmit(pDrv);
1144 ASMAtomicWriteU32(&pState->uIsTransmitting, 0);
1145}
1146
1147/**
1148 * @interface_method_impl{PDMINETWORKDOWN,pfnXmitPending}
1149 */
1150static DECLCALLBACK(void) vnetNetworkDown_XmitPending(PPDMINETWORKDOWN pInterface)
1151{
1152 VNETSTATE *pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);
1153 vnetTransmitPendingPackets(pThis, pThis->pTxQueue, false /*fOnWorkerThread*/);
1154}
1155
1156#ifdef VNET_TX_DELAY
1157
1158static DECLCALLBACK(void) vnetQueueTransmit(void *pvState, PVQUEUE pQueue)
1159{
1160 VNETSTATE *pState = (VNETSTATE*)pvState;
1161
1162 if (TMTimerIsActive(pState->CTX_SUFF(pTxTimer)))
1163 {
1164 int rc = TMTimerStop(pState->CTX_SUFF(pTxTimer));
1165 Log3(("%s vnetQueueTransmit: Got kicked with notification disabled, "
1166 "re-enable notification and flush TX queue\n", INSTANCE(pState)));
1167 vnetTransmitPendingPackets(pState, pQueue, false /*fOnWorkerThread*/);
1168 if (RT_FAILURE(vnetCsEnter(pState, VERR_SEM_BUSY)))
1169 LogRel(("vnetQueueTransmit: Failed to enter critical section!/n"));
1170 else
1171 {
1172 vringSetNotification(&pState->VPCI, &pState->pTxQueue->VRing, true);
1173 vnetCsLeave(pState);
1174 }
1175 }
1176 else
1177 {
1178 if (RT_FAILURE(vnetCsEnter(pState, VERR_SEM_BUSY)))
1179 LogRel(("vnetQueueTransmit: Failed to enter critical section!/n"));
1180 else
1181 {
1182 vringSetNotification(&pState->VPCI, &pState->pTxQueue->VRing, false);
1183 TMTimerSetMicro(pState->CTX_SUFF(pTxTimer), VNET_TX_DELAY);
1184 pState->u64NanoTS = RTTimeNanoTS();
1185 vnetCsLeave(pState);
1186 }
1187 }
1188}
1189
1190/**
1191 * Transmit Delay Timer handler.
1192 *
1193 * @remarks We only get here when the timer expires.
1194 *
1195 * @param pDevIns Pointer to device instance structure.
1196 * @param pTimer Pointer to the timer.
1197 * @param pvUser NULL.
1198 * @thread EMT
1199 */
1200static DECLCALLBACK(void) vnetTxTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
1201{
1202 VNETSTATE *pState = (VNETSTATE*)pvUser;
1203
1204 uint32_t u32MicroDiff = (uint32_t)((RTTimeNanoTS() - pState->u64NanoTS)/1000);
1205 if (u32MicroDiff < pState->u32MinDiff)
1206 pState->u32MinDiff = u32MicroDiff;
1207 if (u32MicroDiff > pState->u32MaxDiff)
1208 pState->u32MaxDiff = u32MicroDiff;
1209 pState->u32AvgDiff = (pState->u32AvgDiff * pState->u32i + u32MicroDiff) / (pState->u32i + 1);
1210 pState->u32i++;
1211 Log3(("vnetTxTimer: Expired, diff %9d usec, avg %9d usec, min %9d usec, max %9d usec\n",
1212 u32MicroDiff, pState->u32AvgDiff, pState->u32MinDiff, pState->u32MaxDiff));
1213
1214// Log3(("%s vnetTxTimer: Expired\n", INSTANCE(pState)));
1215 vnetTransmitPendingPackets(pState, pState->pTxQueue, false /*fOnWorkerThread*/);
1216 if (RT_FAILURE(vnetCsEnter(pState, VERR_SEM_BUSY)))
1217 {
1218 LogRel(("vnetTxTimer: Failed to enter critical section!/n"));
1219 return;
1220 }
1221 vringSetNotification(&pState->VPCI, &pState->pTxQueue->VRing, true);
1222 vnetCsLeave(pState);
1223}
1224
1225#else /* !VNET_TX_DELAY */
1226
1227static DECLCALLBACK(void) vnetQueueTransmit(void *pvState, PVQUEUE pQueue)
1228{
1229 VNETSTATE *pState = (VNETSTATE*)pvState;
1230
1231 vnetTransmitPendingPackets(pState, pQueue, false /*fOnWorkerThread*/);
1232}
1233
1234#endif /* !VNET_TX_DELAY */
1235
1236static uint8_t vnetControlRx(PVNETSTATE pState, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)
1237{
1238 uint8_t u8Ack = VNET_OK;
1239 uint8_t fOn, fDrvWasPromisc = pState->fPromiscuous | pState->fAllMulti;
1240 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
1241 pElem->aSegsOut[1].addr,
1242 &fOn, sizeof(fOn));
1243 Log(("%s vnetControlRx: uCommand=%u fOn=%u\n", INSTANCE(pState), pCtlHdr->u8Command, fOn));
1244 switch (pCtlHdr->u8Command)
1245 {
1246 case VNET_CTRL_CMD_RX_MODE_PROMISC:
1247 pState->fPromiscuous = !!fOn;
1248 break;
1249 case VNET_CTRL_CMD_RX_MODE_ALLMULTI:
1250 pState->fAllMulti = !!fOn;
1251 break;
1252 default:
1253 u8Ack = VNET_ERROR;
1254 }
1255 if (fDrvWasPromisc != (pState->fPromiscuous | pState->fAllMulti) && pState->pDrv)
1256 pState->pDrv->pfnSetPromiscuousMode(pState->pDrv,
1257 (pState->fPromiscuous | pState->fAllMulti));
1258
1259 return u8Ack;
1260}
1261
1262static uint8_t vnetControlMac(PVNETSTATE pState, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)
1263{
1264 uint32_t nMacs = 0;
1265
1266 if (pCtlHdr->u8Command != VNET_CTRL_CMD_MAC_TABLE_SET
1267 || pElem->nOut != 3
1268 || pElem->aSegsOut[1].cb < sizeof(nMacs)
1269 || pElem->aSegsOut[2].cb < sizeof(nMacs))
1270 {
1271 Log(("%s vnetControlMac: Segment layout is wrong "
1272 "(u8Command=%u nOut=%u cb1=%u cb2=%u)\n", INSTANCE(pState),
1273 pCtlHdr->u8Command, pElem->nOut,
1274 pElem->aSegsOut[1].cb, pElem->aSegsOut[2].cb));
1275 return VNET_ERROR;
1276 }
1277
1278 /* Load unicast addresses */
1279 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
1280 pElem->aSegsOut[1].addr,
1281 &nMacs, sizeof(nMacs));
1282
1283 if (pElem->aSegsOut[1].cb < nMacs * sizeof(RTMAC) + sizeof(nMacs))
1284 {
1285 Log(("%s vnetControlMac: The unicast mac segment is too small "
1286 "(nMacs=%u cb=%u)\n", INSTANCE(pState), pElem->aSegsOut[1].cb));
1287 return VNET_ERROR;
1288 }
1289
1290 if (nMacs > VNET_MAC_FILTER_LEN)
1291 {
1292 Log(("%s vnetControlMac: MAC table is too big, have to use promiscuous"
1293 " mode (nMacs=%u)\n", INSTANCE(pState), nMacs));
1294 pState->fPromiscuous = true;
1295 }
1296 else
1297 {
1298 if (nMacs)
1299 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
1300 pElem->aSegsOut[1].addr + sizeof(nMacs),
1301 pState->aMacFilter, nMacs * sizeof(RTMAC));
1302 pState->nMacFilterEntries = nMacs;
1303#ifdef DEBUG
1304 Log(("%s vnetControlMac: unicast macs:\n", INSTANCE(pState)));
1305 for(unsigned i = 0; i < nMacs; i++)
1306 Log((" %RTmac\n", &pState->aMacFilter[i]));
1307#endif /* DEBUG */
1308 }
1309
1310 /* Load multicast addresses */
1311 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
1312 pElem->aSegsOut[2].addr,
1313 &nMacs, sizeof(nMacs));
1314
1315 if (pElem->aSegsOut[2].cb < nMacs * sizeof(RTMAC) + sizeof(nMacs))
1316 {
1317 Log(("%s vnetControlMac: The multicast mac segment is too small "
1318 "(nMacs=%u cb=%u)\n", INSTANCE(pState), pElem->aSegsOut[2].cb));
1319 return VNET_ERROR;
1320 }
1321
1322 if (nMacs > VNET_MAC_FILTER_LEN - pState->nMacFilterEntries)
1323 {
1324 Log(("%s vnetControlMac: MAC table is too big, have to use allmulti"
1325 " mode (nMacs=%u)\n", INSTANCE(pState), nMacs));
1326 pState->fAllMulti = true;
1327 }
1328 else
1329 {
1330 if (nMacs)
1331 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
1332 pElem->aSegsOut[2].addr + sizeof(nMacs),
1333 &pState->aMacFilter[pState->nMacFilterEntries],
1334 nMacs * sizeof(RTMAC));
1335#ifdef DEBUG
1336 Log(("%s vnetControlMac: multicast macs:\n", INSTANCE(pState)));
1337 for(unsigned i = 0; i < nMacs; i++)
1338 Log((" %RTmac\n",
1339 &pState->aMacFilter[i+pState->nMacFilterEntries]));
1340#endif /* DEBUG */
1341 pState->nMacFilterEntries += nMacs;
1342 }
1343
1344 return VNET_OK;
1345}
1346
1347static uint8_t vnetControlVlan(PVNETSTATE pState, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)
1348{
1349 uint8_t u8Ack = VNET_OK;
1350 uint16_t u16Vid;
1351
1352 if (pElem->nOut != 2 || pElem->aSegsOut[1].cb != sizeof(u16Vid))
1353 {
1354 Log(("%s vnetControlVlan: Segment layout is wrong "
1355 "(u8Command=%u nOut=%u cb=%u)\n", INSTANCE(pState),
1356 pCtlHdr->u8Command, pElem->nOut, pElem->aSegsOut[1].cb));
1357 return VNET_ERROR;
1358 }
1359
1360 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
1361 pElem->aSegsOut[1].addr,
1362 &u16Vid, sizeof(u16Vid));
1363
1364 if (u16Vid >= VNET_MAX_VID)
1365 {
1366 Log(("%s vnetControlVlan: VLAN ID is out of range "
1367 "(VID=%u)\n", INSTANCE(pState), u16Vid));
1368 return VNET_ERROR;
1369 }
1370
1371 Log(("%s vnetControlVlan: uCommand=%u VID=%u\n", INSTANCE(pState),
1372 pCtlHdr->u8Command, u16Vid));
1373
1374 switch (pCtlHdr->u8Command)
1375 {
1376 case VNET_CTRL_CMD_VLAN_ADD:
1377 ASMBitSet(pState->aVlanFilter, u16Vid);
1378 break;
1379 case VNET_CTRL_CMD_VLAN_DEL:
1380 ASMBitClear(pState->aVlanFilter, u16Vid);
1381 break;
1382 default:
1383 u8Ack = VNET_ERROR;
1384 }
1385
1386 return u8Ack;
1387}
1388
1389
1390static DECLCALLBACK(void) vnetQueueControl(void *pvState, PVQUEUE pQueue)
1391{
1392 VNETSTATE *pState = (VNETSTATE*)pvState;
1393 uint8_t u8Ack;
1394 VQUEUEELEM elem;
1395 while (vqueueGet(&pState->VPCI, pQueue, &elem))
1396 {
1397 unsigned int uOffset = 0;
1398 if (elem.nOut < 1 || elem.aSegsOut[0].cb < sizeof(VNETCTLHDR))
1399 {
1400 Log(("%s vnetQueueControl: The first 'out' segment is not the "
1401 "header! (%u < 1 || %u < %u).\n", INSTANCE(pState), elem.nOut,
1402 elem.aSegsOut[0].cb,sizeof(VNETCTLHDR)));
1403 break; /* Skip the element and hope the next one is good. */
1404 }
1405 else if ( elem.nIn < 1
1406 || elem.aSegsIn[elem.nIn - 1].cb < sizeof(VNETCTLACK))
1407 {
1408 Log(("%s vnetQueueControl: The last 'in' segment is too small "
1409 "to hold the acknowledge! (%u < 1 || %u < %u).\n",
1410 INSTANCE(pState), elem.nIn, elem.aSegsIn[elem.nIn - 1].cb,
1411 sizeof(VNETCTLACK)));
1412 break; /* Skip the element and hope the next one is good. */
1413 }
1414 else
1415 {
1416 VNETCTLHDR CtlHdr;
1417 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
1418 elem.aSegsOut[0].addr,
1419 &CtlHdr, sizeof(CtlHdr));
1420 switch (CtlHdr.u8Class)
1421 {
1422 case VNET_CTRL_CLS_RX_MODE:
1423 u8Ack = vnetControlRx(pState, &CtlHdr, &elem);
1424 break;
1425 case VNET_CTRL_CLS_MAC:
1426 u8Ack = vnetControlMac(pState, &CtlHdr, &elem);
1427 break;
1428 case VNET_CTRL_CLS_VLAN:
1429 u8Ack = vnetControlVlan(pState, &CtlHdr, &elem);
1430 break;
1431 default:
1432 u8Ack = VNET_ERROR;
1433 }
1434 Log(("%s Processed control message %u, ack=%u.\n", INSTANCE(pState),
1435 CtlHdr.u8Class, u8Ack));
1436 PDMDevHlpPhysWrite(pState->VPCI.CTX_SUFF(pDevIns),
1437 elem.aSegsIn[elem.nIn - 1].addr,
1438 &u8Ack, sizeof(u8Ack));
1439 }
1440 vqueuePut(&pState->VPCI, pQueue, &elem, sizeof(u8Ack));
1441 vqueueSync(&pState->VPCI, pQueue);
1442 }
1443}
1444
1445/**
1446 * Saves the configuration.
1447 *
1448 * @param pState The VNET state.
1449 * @param pSSM The handle to the saved state.
1450 */
1451static void vnetSaveConfig(VNETSTATE *pState, PSSMHANDLE pSSM)
1452{
1453 SSMR3PutMem(pSSM, &pState->macConfigured, sizeof(pState->macConfigured));
1454}
1455
1456/**
1457 * Live save - save basic configuration.
1458 *
1459 * @returns VBox status code.
1460 * @param pDevIns The device instance.
1461 * @param pSSM The handle to the saved state.
1462 * @param uPass
1463 */
1464static DECLCALLBACK(int) vnetLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
1465{
1466 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1467 vnetSaveConfig(pState, pSSM);
1468 return VINF_SSM_DONT_CALL_AGAIN;
1469}
1470
1471/**
1472 * Prepares for state saving.
1473 *
1474 * @returns VBox status code.
1475 * @param pDevIns The device instance.
1476 * @param pSSM The handle to the saved state.
1477 */
1478static DECLCALLBACK(int) vnetSavePrep(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
1479{
1480 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1481
1482 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY);
1483 if (RT_UNLIKELY(rc != VINF_SUCCESS))
1484 return rc;
1485 vnetCsRxLeave(pState);
1486 return VINF_SUCCESS;
1487}
1488
1489/**
1490 * Saves the state of device.
1491 *
1492 * @returns VBox status code.
1493 * @param pDevIns The device instance.
1494 * @param pSSM The handle to the saved state.
1495 */
1496static DECLCALLBACK(int) vnetSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
1497{
1498 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1499
1500 /* Save config first */
1501 vnetSaveConfig(pState, pSSM);
1502
1503 /* Save the common part */
1504 int rc = vpciSaveExec(&pState->VPCI, pSSM);
1505 AssertRCReturn(rc, rc);
1506 /* Save device-specific part */
1507 rc = SSMR3PutMem( pSSM, pState->config.mac.au8, sizeof(pState->config.mac));
1508 AssertRCReturn(rc, rc);
1509 rc = SSMR3PutBool(pSSM, pState->fPromiscuous);
1510 AssertRCReturn(rc, rc);
1511 rc = SSMR3PutBool(pSSM, pState->fAllMulti);
1512 AssertRCReturn(rc, rc);
1513 rc = SSMR3PutU32( pSSM, pState->nMacFilterEntries);
1514 AssertRCReturn(rc, rc);
1515 rc = SSMR3PutMem( pSSM, pState->aMacFilter,
1516 pState->nMacFilterEntries * sizeof(RTMAC));
1517 AssertRCReturn(rc, rc);
1518 rc = SSMR3PutMem( pSSM, pState->aVlanFilter, sizeof(pState->aVlanFilter));
1519 AssertRCReturn(rc, rc);
1520 Log(("%s State has been saved\n", INSTANCE(pState)));
1521 return VINF_SUCCESS;
1522}
1523
1524
1525/**
1526 * Serializes the receive thread, it may be working inside the critsect.
1527 *
1528 * @returns VBox status code.
1529 * @param pDevIns The device instance.
1530 * @param pSSM The handle to the saved state.
1531 */
1532static DECLCALLBACK(int) vnetLoadPrep(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
1533{
1534 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1535
1536 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY);
1537 if (RT_UNLIKELY(rc != VINF_SUCCESS))
1538 return rc;
1539 vnetCsRxLeave(pState);
1540 return VINF_SUCCESS;
1541}
1542
1543/**
1544 * Takes down the link temporarily if it's current status is up.
1545 *
1546 * This is used during restore and when replumbing the network link.
1547 *
1548 * The temporary link outage is supposed to indicate to the OS that all network
1549 * connections have been lost and that it for instance is appropriate to
1550 * renegotiate any DHCP lease.
1551 *
1552 * @param pThis The PCNet instance data.
1553 */
1554static void vnetTempLinkDown(PVNETSTATE pState)
1555{
1556 if (STATUS & VNET_S_LINK_UP)
1557 {
1558 STATUS &= ~VNET_S_LINK_UP;
1559 vpciRaiseInterrupt(&pState->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
1560 /* Restore the link back in 5 seconds. */
1561 int rc = TMTimerSetMillies(pState->pLinkUpTimer, 5000);
1562 AssertRC(rc);
1563 }
1564}
1565
1566
1567/**
1568 * Restore previously saved state of device.
1569 *
1570 * @returns VBox status code.
1571 * @param pDevIns The device instance.
1572 * @param pSSM The handle to the saved state.
1573 * @param uVersion The data unit version number.
1574 * @param uPass The data pass.
1575 */
1576static DECLCALLBACK(int) vnetLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
1577{
1578 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1579 int rc;
1580
1581 /* config checks */
1582 RTMAC macConfigured;
1583 rc = SSMR3GetMem(pSSM, &macConfigured, sizeof(macConfigured));
1584 AssertRCReturn(rc, rc);
1585 if (memcmp(&macConfigured, &pState->macConfigured, sizeof(macConfigured))
1586 && (uPass == 0 || !PDMDevHlpVMTeleportedAndNotFullyResumedYet(pDevIns)))
1587 LogRel(("%s: The mac address differs: config=%RTmac saved=%RTmac\n", INSTANCE(pState), &pState->macConfigured, &macConfigured));
1588
1589 rc = vpciLoadExec(&pState->VPCI, pSSM, uVersion, uPass, VNET_N_QUEUES);
1590 AssertRCReturn(rc, rc);
1591
1592 if (uPass == SSM_PASS_FINAL)
1593 {
1594 rc = SSMR3GetMem( pSSM, pState->config.mac.au8,
1595 sizeof(pState->config.mac));
1596 AssertRCReturn(rc, rc);
1597
1598 if (uVersion > VIRTIO_SAVEDSTATE_VERSION_3_1_BETA1)
1599 {
1600 rc = SSMR3GetBool(pSSM, &pState->fPromiscuous);
1601 AssertRCReturn(rc, rc);
1602 rc = SSMR3GetBool(pSSM, &pState->fAllMulti);
1603 AssertRCReturn(rc, rc);
1604 rc = SSMR3GetU32(pSSM, &pState->nMacFilterEntries);
1605 AssertRCReturn(rc, rc);
1606 rc = SSMR3GetMem(pSSM, pState->aMacFilter,
1607 pState->nMacFilterEntries * sizeof(RTMAC));
1608 AssertRCReturn(rc, rc);
1609 /* Clear the rest. */
1610 if (pState->nMacFilterEntries < VNET_MAC_FILTER_LEN)
1611 memset(&pState->aMacFilter[pState->nMacFilterEntries],
1612 0,
1613 (VNET_MAC_FILTER_LEN - pState->nMacFilterEntries)
1614 * sizeof(RTMAC));
1615 rc = SSMR3GetMem(pSSM, pState->aVlanFilter,
1616 sizeof(pState->aVlanFilter));
1617 AssertRCReturn(rc, rc);
1618 }
1619 else
1620 {
1621 pState->fPromiscuous = true;
1622 pState->fAllMulti = false;
1623 pState->nMacFilterEntries = 0;
1624 memset(pState->aMacFilter, 0, VNET_MAC_FILTER_LEN * sizeof(RTMAC));
1625 memset(pState->aVlanFilter, 0, sizeof(pState->aVlanFilter));
1626 if (pState->pDrv)
1627 pState->pDrv->pfnSetPromiscuousMode(pState->pDrv, true);
1628 }
1629 }
1630
1631 return rc;
1632}
1633
1634/**
1635 * Link status adjustments after loading.
1636 *
1637 * @returns VBox status code.
1638 * @param pDevIns The device instance.
1639 * @param pSSM The handle to the saved state.
1640 */
1641static DECLCALLBACK(int) vnetLoadDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
1642{
1643 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1644
1645 if (pState->pDrv)
1646 pState->pDrv->pfnSetPromiscuousMode(pState->pDrv,
1647 (pState->fPromiscuous | pState->fAllMulti));
1648 /*
1649 * Indicate link down to the guest OS that all network connections have
1650 * been lost, unless we've been teleported here.
1651 */
1652 if (!PDMDevHlpVMTeleportedAndNotFullyResumedYet(pDevIns))
1653 vnetTempLinkDown(pState);
1654
1655 return VINF_SUCCESS;
1656}
1657
1658/**
1659 * Map PCI I/O region.
1660 *
1661 * @return VBox status code.
1662 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
1663 * @param iRegion The region number.
1664 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
1665 * I/O port, else it's a physical address.
1666 * This address is *NOT* relative to pci_mem_base like earlier!
1667 * @param cb Region size.
1668 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
1669 * @thread EMT
1670 */
1671static DECLCALLBACK(int) vnetMap(PPCIDEVICE pPciDev, int iRegion,
1672 RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
1673{
1674 int rc;
1675 VNETSTATE *pState = PDMINS_2_DATA(pPciDev->pDevIns, VNETSTATE*);
1676
1677 if (enmType != PCI_ADDRESS_SPACE_IO)
1678 {
1679 /* We should never get here */
1680 AssertMsgFailed(("Invalid PCI address space param in map callback"));
1681 return VERR_INTERNAL_ERROR;
1682 }
1683
1684 pState->VPCI.addrIOPort = (RTIOPORT)GCPhysAddress;
1685 rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns, pState->VPCI.addrIOPort,
1686 cb, 0, vnetIOPortOut, vnetIOPortIn,
1687 NULL, NULL, "VirtioNet");
1688#ifdef VNET_GC_SUPPORT
1689 AssertRCReturn(rc, rc);
1690 rc = PDMDevHlpIOPortRegisterR0(pPciDev->pDevIns, pState->VPCI.addrIOPort,
1691 cb, 0, "vnetIOPortOut", "vnetIOPortIn",
1692 NULL, NULL, "VirtioNet");
1693 AssertRCReturn(rc, rc);
1694 rc = PDMDevHlpIOPortRegisterRC(pPciDev->pDevIns, pState->VPCI.addrIOPort,
1695 cb, 0, "vnetIOPortOut", "vnetIOPortIn",
1696 NULL, NULL, "VirtioNet");
1697#endif
1698 AssertRC(rc);
1699 return rc;
1700}
1701
1702/* -=-=-=-=- PDMDEVREG -=-=-=-=- */
1703
1704#ifdef VBOX_DYNAMIC_NET_ATTACH
1705
1706/**
1707 * Detach notification.
1708 *
1709 * One port on the network card has been disconnected from the network.
1710 *
1711 * @param pDevIns The device instance.
1712 * @param iLUN The logical unit which is being detached.
1713 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
1714 */
1715static DECLCALLBACK(void) vnetDetach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
1716{
1717 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1718 Log(("%s vnetDetach:\n", INSTANCE(pState)));
1719
1720 AssertLogRelReturnVoid(iLUN == 0);
1721
1722 int rc = vnetCsEnter(pState, VERR_SEM_BUSY);
1723 if (RT_FAILURE(rc))
1724 {
1725 LogRel(("vnetDetach failed to enter critical section!\n"));
1726 return;
1727 }
1728
1729 /*
1730 * Zero some important members.
1731 */
1732 pState->pDrvBase = NULL;
1733 pState->pDrv = NULL;
1734
1735 vnetCsLeave(pState);
1736}
1737
1738
1739/**
1740 * Attach the Network attachment.
1741 *
1742 * One port on the network card has been connected to a network.
1743 *
1744 * @returns VBox status code.
1745 * @param pDevIns The device instance.
1746 * @param iLUN The logical unit which is being attached.
1747 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
1748 *
1749 * @remarks This code path is not used during construction.
1750 */
1751static DECLCALLBACK(int) vnetAttach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
1752{
1753 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1754 LogFlow(("%s vnetAttach:\n", INSTANCE(pState)));
1755
1756 AssertLogRelReturn(iLUN == 0, VERR_PDM_NO_SUCH_LUN);
1757
1758 int rc = vnetCsEnter(pState, VERR_SEM_BUSY);
1759 if (RT_FAILURE(rc))
1760 {
1761 LogRel(("vnetAttach failed to enter critical section!\n"));
1762 return rc;
1763 }
1764
1765 /*
1766 * Attach the driver.
1767 */
1768 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pState->VPCI.IBase, &pState->pDrvBase, "Network Port");
1769 if (RT_SUCCESS(rc))
1770 {
1771 if (rc == VINF_NAT_DNS)
1772 {
1773#ifdef RT_OS_LINUX
1774 PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "NoDNSforNAT",
1775 N_("A Domain Name Server (DNS) for NAT networking could not be determined. Please check your /etc/resolv.conf for <tt>nameserver</tt> entries. Either add one manually (<i>man resolv.conf</i>) or ensure that your host is correctly connected to an ISP. If you ignore this warning the guest will not be able to perform nameserver lookups and it will probably observe delays if trying so"));
1776#else
1777 PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "NoDNSforNAT",
1778 N_("A Domain Name Server (DNS) for NAT networking could not be determined. Ensure that your host is correctly connected to an ISP. If you ignore this warning the guest will not be able to perform nameserver lookups and it will probably observe delays if trying so"));
1779#endif
1780 }
1781 pState->pDrv = PDMIBASE_QUERY_INTERFACE(pState->pDrvBase, PDMINETWORKUP);
1782 AssertMsgStmt(pState->pDrv, ("Failed to obtain the PDMINETWORKUP interface!\n"),
1783 rc = VERR_PDM_MISSING_INTERFACE_BELOW);
1784 }
1785 else if ( rc == VERR_PDM_NO_ATTACHED_DRIVER
1786 || rc == VERR_PDM_CFG_MISSING_DRIVER_NAME)
1787 {
1788 /* This should never happen because this function is not called
1789 * if there is no driver to attach! */
1790 Log(("%s No attached driver!\n", INSTANCE(pState)));
1791 }
1792
1793 /*
1794 * Temporary set the link down if it was up so that the guest
1795 * will know that we have change the configuration of the
1796 * network card
1797 */
1798 if (RT_SUCCESS(rc))
1799 vnetTempLinkDown(pState);
1800
1801 vnetCsLeave(pState);
1802 return rc;
1803
1804}
1805
1806#endif /* VBOX_DYNAMIC_NET_ATTACH */
1807
1808/**
1809 * @copydoc FNPDMDEVSUSPEND
1810 */
1811static DECLCALLBACK(void) vnetSuspend(PPDMDEVINS pDevIns)
1812{
1813 /* Poke thread waiting for buffer space. */
1814 vnetWakeupReceive(pDevIns);
1815}
1816
1817/**
1818 * @copydoc FNPDMDEVPOWEROFF
1819 */
1820static DECLCALLBACK(void) vnetPowerOff(PPDMDEVINS pDevIns)
1821{
1822 /* Poke thread waiting for buffer space. */
1823 vnetWakeupReceive(pDevIns);
1824}
1825
1826/**
1827 * Device relocation callback.
1828 *
1829 * When this callback is called the device instance data, and if the
1830 * device have a GC component, is being relocated, or/and the selectors
1831 * have been changed. The device must use the chance to perform the
1832 * necessary pointer relocations and data updates.
1833 *
1834 * Before the GC code is executed the first time, this function will be
1835 * called with a 0 delta so GC pointer calculations can be one in one place.
1836 *
1837 * @param pDevIns Pointer to the device instance.
1838 * @param offDelta The relocation delta relative to the old location.
1839 *
1840 * @remark A relocation CANNOT fail.
1841 */
1842static DECLCALLBACK(void) vnetRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
1843{
1844 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1845 vpciRelocate(pDevIns, offDelta);
1846 pState->pCanRxQueueRC = PDMQueueRCPtr(pState->pCanRxQueueR3);
1847#ifdef VNET_TX_DELAY
1848 pState->pTxTimerRC = TMTimerRCPtr(pState->pTxTimerR3);
1849#endif /* VNET_TX_DELAY */
1850 // TBD
1851}
1852
1853/**
1854 * Destruct a device instance.
1855 *
1856 * We need to free non-VM resources only.
1857 *
1858 * @returns VBox status.
1859 * @param pDevIns The device instance data.
1860 * @thread EMT
1861 */
1862static DECLCALLBACK(int) vnetDestruct(PPDMDEVINS pDevIns)
1863{
1864 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1865 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
1866
1867 LogRel(("TxTimer stats (avg/min/max): %7d usec %7d usec %7d usec\n",
1868 pState->u32AvgDiff, pState->u32MinDiff, pState->u32MaxDiff));
1869 Log(("%s Destroying instance\n", INSTANCE(pState)));
1870 if (pState->hEventMoreRxDescAvail != NIL_RTSEMEVENT)
1871 {
1872 RTSemEventSignal(pState->hEventMoreRxDescAvail);
1873 RTSemEventDestroy(pState->hEventMoreRxDescAvail);
1874 pState->hEventMoreRxDescAvail = NIL_RTSEMEVENT;
1875 }
1876
1877 // if (PDMCritSectIsInitialized(&pState->csRx))
1878 // PDMR3CritSectDelete(&pState->csRx);
1879
1880 return vpciDestruct(&pState->VPCI);
1881}
1882
1883/**
1884 * @interface_method_impl{PDMDEVREG,pfnConstruct}
1885 */
1886static DECLCALLBACK(int) vnetConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
1887{
1888 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
1889 int rc;
1890 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
1891
1892 /* Initialize PCI part first. */
1893 pState->VPCI.IBase.pfnQueryInterface = vnetQueryInterface;
1894 rc = vpciConstruct(pDevIns, &pState->VPCI, iInstance,
1895 VNET_NAME_FMT, VNET_PCI_SUBSYSTEM_ID,
1896 VNET_PCI_CLASS, VNET_N_QUEUES);
1897 pState->pRxQueue = vpciAddQueue(&pState->VPCI, 256, vnetQueueReceive, "RX ");
1898 pState->pTxQueue = vpciAddQueue(&pState->VPCI, 256, vnetQueueTransmit, "TX ");
1899 pState->pCtlQueue = vpciAddQueue(&pState->VPCI, 16, vnetQueueControl, "CTL");
1900
1901 Log(("%s Constructing new instance\n", INSTANCE(pState)));
1902
1903 pState->hEventMoreRxDescAvail = NIL_RTSEMEVENT;
1904
1905 /*
1906 * Validate configuration.
1907 */
1908 if (!CFGMR3AreValuesValid(pCfg, "MAC\0" "CableConnected\0" "LineSpeed\0"))
1909 return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
1910 N_("Invalid configuration for VirtioNet device"));
1911
1912 /* Get config params */
1913 rc = CFGMR3QueryBytes(pCfg, "MAC", pState->macConfigured.au8,
1914 sizeof(pState->macConfigured));
1915 if (RT_FAILURE(rc))
1916 return PDMDEV_SET_ERROR(pDevIns, rc,
1917 N_("Configuration error: Failed to get MAC address"));
1918 rc = CFGMR3QueryBool(pCfg, "CableConnected", &pState->fCableConnected);
1919 if (RT_FAILURE(rc))
1920 return PDMDEV_SET_ERROR(pDevIns, rc,
1921 N_("Configuration error: Failed to get the value of 'CableConnected'"));
1922
1923 /* Initialize PCI config space */
1924 memcpy(pState->config.mac.au8, pState->macConfigured.au8, sizeof(pState->config.mac.au8));
1925 pState->config.uStatus = 0;
1926
1927 /* Initialize state structure */
1928 pState->u32PktNo = 1;
1929
1930 /* Interfaces */
1931 pState->INetworkDown.pfnWaitReceiveAvail = vnetNetworkDown_WaitReceiveAvail;
1932 pState->INetworkDown.pfnReceive = vnetNetworkDown_Receive;
1933 pState->INetworkDown.pfnReceiveGso = vnetNetworkDown_ReceiveGso;
1934 pState->INetworkDown.pfnXmitPending = vnetNetworkDown_XmitPending;
1935
1936 pState->INetworkConfig.pfnGetMac = vnetGetMac;
1937 pState->INetworkConfig.pfnGetLinkState = vnetGetLinkState;
1938 pState->INetworkConfig.pfnSetLinkState = vnetSetLinkState;
1939
1940 /* Initialize critical section. */
1941 // char szTmp[sizeof(pState->VPCI.szInstance) + 2];
1942 // RTStrPrintf(szTmp, sizeof(szTmp), "%sRX", pState->VPCI.szInstance);
1943 // rc = PDMDevHlpCritSectInit(pDevIns, &pState->csRx, szTmp);
1944 // if (RT_FAILURE(rc))
1945 // return rc;
1946
1947 /* Map our ports to IO space. */
1948 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0,
1949 VPCI_CONFIG + sizeof(VNetPCIConfig),
1950 PCI_ADDRESS_SPACE_IO, vnetMap);
1951 if (RT_FAILURE(rc))
1952 return rc;
1953
1954
1955 /* Register save/restore state handlers. */
1956 rc = PDMDevHlpSSMRegisterEx(pDevIns, VIRTIO_SAVEDSTATE_VERSION, sizeof(VNETSTATE), NULL,
1957 NULL, vnetLiveExec, NULL,
1958 vnetSavePrep, vnetSaveExec, NULL,
1959 vnetLoadPrep, vnetLoadExec, vnetLoadDone);
1960 if (RT_FAILURE(rc))
1961 return rc;
1962
1963 /* Create the RX notifier signaller. */
1964 rc = PDMDevHlpQueueCreate(pDevIns, sizeof(PDMQUEUEITEMCORE), 1, 0,
1965 vnetCanRxQueueConsumer, true, "VNet-Rcv", &pState->pCanRxQueueR3);
1966 if (RT_FAILURE(rc))
1967 return rc;
1968 pState->pCanRxQueueR0 = PDMQueueR0Ptr(pState->pCanRxQueueR3);
1969 pState->pCanRxQueueRC = PDMQueueRCPtr(pState->pCanRxQueueR3);
1970
1971 /* Create Link Up Timer */
1972 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vnetLinkUpTimer, pState,
1973 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, /** @todo check locking here. */
1974 "VirtioNet Link Up Timer", &pState->pLinkUpTimer);
1975 if (RT_FAILURE(rc))
1976 return rc;
1977
1978#ifdef VNET_TX_DELAY
1979 /* Create Transmit Delay Timer */
1980 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vnetTxTimer, pState,
1981 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, /** @todo check locking here. */
1982 "VirtioNet TX Delay Timer", &pState->pTxTimerR3);
1983 if (RT_FAILURE(rc))
1984 return rc;
1985 pState->pTxTimerR0 = TMTimerR0Ptr(pState->pTxTimerR3);
1986 pState->pTxTimerRC = TMTimerRCPtr(pState->pTxTimerR3);
1987
1988 pState->u32i = pState->u32AvgDiff = pState->u32MaxDiff = 0;
1989 pState->u32MinDiff = ~0;
1990#endif /* VNET_TX_DELAY */
1991
1992 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pState->VPCI.IBase, &pState->pDrvBase, "Network Port");
1993 if (RT_SUCCESS(rc))
1994 {
1995 if (rc == VINF_NAT_DNS)
1996 {
1997 PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "NoDNSforNAT",
1998 N_("A Domain Name Server (DNS) for NAT networking could not be determined. Ensure that your host is correctly connected to an ISP. If you ignore this warning the guest will not be able to perform nameserver lookups and it will probably observe delays if trying so"));
1999 }
2000 pState->pDrv = PDMIBASE_QUERY_INTERFACE(pState->pDrvBase, PDMINETWORKUP);
2001 AssertMsgReturn(pState->pDrv, ("Failed to obtain the PDMINETWORKUP interface!\n"),
2002 VERR_PDM_MISSING_INTERFACE_BELOW);
2003 }
2004 else if ( rc == VERR_PDM_NO_ATTACHED_DRIVER
2005 || rc == VERR_PDM_CFG_MISSING_DRIVER_NAME )
2006 {
2007 /* No error! */
2008 Log(("%s This adapter is not attached to any network!\n", INSTANCE(pState)));
2009 }
2010 else
2011 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to attach the network LUN"));
2012
2013 rc = RTSemEventCreate(&pState->hEventMoreRxDescAvail);
2014 if (RT_FAILURE(rc))
2015 return rc;
2016
2017 rc = vnetReset(pState);
2018 AssertRC(rc);
2019
2020 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatReceiveBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Amount of data received", "/Devices/VNet%d/Bytes/Receive", iInstance);
2021 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmitBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Amount of data transmitted", "/Devices/VNet%d/Bytes/Transmit", iInstance);
2022 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatReceiveGSO, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of received GSO packets", "/Devices/VNet%d/Packets/ReceiveGSO", iInstance);
2023 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmitPackets, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of sent packets", "/Devices/VNet%d/Packets/Transmit", iInstance);
2024 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmitGSO, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of sent GSO packets", "/Devices/VNet%d/Packets/Transmit-Gso", iInstance);
2025 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmitCSum, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of completed TX checksums", "/Devices/VNet%d/Packets/Transmit-Csum", iInstance);
2026#if defined(VBOX_WITH_STATISTICS)
2027 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatReceive, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling receive", "/Devices/VNet%d/Receive/Total", iInstance);
2028 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatReceiveStore, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling receive storing", "/Devices/VNet%d/Receive/Store", iInstance);
2029 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatRxOverflow, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, "Profiling RX overflows", "/Devices/VNet%d/RxOverflow", iInstance);
2030 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatRxOverflowWakeup, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of RX overflow wakeups", "/Devices/VNet%d/RxOverflowWakeup", iInstance);
2031 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmit, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling transmits in HC", "/Devices/VNet%d/Transmit/Total", iInstance);
2032 PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmitSend, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling send transmit in HC", "/Devices/VNet%d/Transmit/Send", iInstance);
2033#endif /* VBOX_WITH_STATISTICS */
2034
2035 return VINF_SUCCESS;
2036}
2037
2038/**
2039 * The device registration structure.
2040 */
2041const PDMDEVREG g_DeviceVirtioNet =
2042{
2043 /* Structure version. PDM_DEVREG_VERSION defines the current version. */
2044 PDM_DEVREG_VERSION,
2045 /* Device name. */
2046 "virtio-net",
2047 /* Name of guest context module (no path).
2048 * Only evalutated if PDM_DEVREG_FLAGS_RC is set. */
2049 "VBoxDDGC.gc",
2050 /* Name of ring-0 module (no path).
2051 * Only evalutated if PDM_DEVREG_FLAGS_RC is set. */
2052 "VBoxDDR0.r0",
2053 /* The description of the device. The UTF-8 string pointed to shall, like this structure,
2054 * remain unchanged from registration till VM destruction. */
2055 "Virtio Ethernet.\n",
2056
2057 /* Flags, combination of the PDM_DEVREG_FLAGS_* \#defines. */
2058#ifdef VNET_GC_SUPPORT
2059 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
2060#else
2061 PDM_DEVREG_FLAGS_DEFAULT_BITS,
2062#endif
2063 /* Device class(es), combination of the PDM_DEVREG_CLASS_* \#defines. */
2064 PDM_DEVREG_CLASS_NETWORK,
2065 /* Maximum number of instances (per VM). */
2066 8,
2067 /* Size of the instance data. */
2068 sizeof(VNETSTATE),
2069
2070 /* Construct instance - required. */
2071 vnetConstruct,
2072 /* Destruct instance - optional. */
2073 vnetDestruct,
2074 /* Relocation command - optional. */
2075 vnetRelocate,
2076 /* I/O Control interface - optional. */
2077 NULL,
2078 /* Power on notification - optional. */
2079 NULL,
2080 /* Reset notification - optional. */
2081 NULL,
2082 /* Suspend notification - optional. */
2083 vnetSuspend,
2084 /* Resume notification - optional. */
2085 NULL,
2086#ifdef VBOX_DYNAMIC_NET_ATTACH
2087 /* Attach command - optional. */
2088 vnetAttach,
2089 /* Detach notification - optional. */
2090 vnetDetach,
2091#else /* !VBOX_DYNAMIC_NET_ATTACH */
2092 /* Attach command - optional. */
2093 NULL,
2094 /* Detach notification - optional. */
2095 NULL,
2096#endif /* !VBOX_DYNAMIC_NET_ATTACH */
2097 /* Query a LUN base interface - optional. */
2098 NULL,
2099 /* Init complete notification - optional. */
2100 NULL,
2101 /* Power off notification - optional. */
2102 vnetPowerOff,
2103 /* pfnSoftReset */
2104 NULL,
2105 /* u32VersionEnd */
2106 PDM_DEVREG_VERSION
2107};
2108
2109#endif /* IN_RING3 */
2110#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette