VirtualBox

Ignore:
Timestamp:
Oct 17, 2023 10:22:01 AM (15 months ago)
Author:
vboxsync
Message:

Main/ConsoleImpl: Move the network controller configuration out of the x86 config constructor into a separate method in order to be able to use it from the Armv8 variant later on, bugref:10528

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImplConfigCommon.cpp

    r101465 r101469  
    46304630
    46314631
     4632int Console::i_configNetworkCtrls(ComPtr<IMachine> pMachine, ComPtr<IPlatformProperties> pPlatformProperties,
     4633                                  ChipsetType_T enmChipset, BusAssignmentManager *pBusMgr, PCVMMR3VTABLE pVMM, PUVM pUVM,
     4634                                  PCFGMNODE pDevices, std::list<BootNic> &llBootNics)
     4635{
     4636/* Comment out the following line to remove VMWare compatibility hack. */
     4637#define VMWARE_NET_IN_SLOT_11
     4638
     4639    PCFGMNODE pDev = NULL;          /* /Devices/Dev/ */
     4640    PCFGMNODE pInst = NULL;         /* /Devices/Dev/0/ */
     4641    PCFGMNODE pCfg = NULL;          /* /Devices/Dev/.../Config/ */
     4642    PCFGMNODE pLunL0 = NULL;        /* /Devices/Dev/0/LUN#0/ */
     4643
     4644    ULONG maxNetworkAdapters;
     4645    HRESULT hrc = pPlatformProperties->GetMaxNetworkAdapters(enmChipset, &maxNetworkAdapters); H();
     4646
     4647#ifdef VMWARE_NET_IN_SLOT_11
     4648    bool fSwapSlots3and11 = false;
     4649#endif
     4650    PCFGMNODE pDevPCNet = NULL;          /* PCNet-type devices */
     4651    InsertConfigNode(pDevices, "pcnet", &pDevPCNet);
     4652#ifdef VBOX_WITH_E1000
     4653    PCFGMNODE pDevE1000 = NULL;          /* E1000-type devices */
     4654    InsertConfigNode(pDevices, "e1000", &pDevE1000);
     4655#endif
     4656#ifdef VBOX_WITH_VIRTIO
     4657    PCFGMNODE pDevVirtioNet = NULL;          /* Virtio network devices */
     4658    InsertConfigNode(pDevices, "virtio-net", &pDevVirtioNet);
     4659#endif /* VBOX_WITH_VIRTIO */
     4660    PCFGMNODE pDevDP8390 = NULL;         /* DP8390-type devices */
     4661    InsertConfigNode(pDevices, "dp8390", &pDevDP8390);
     4662    PCFGMNODE pDev3C501 = NULL;          /* EtherLink-type devices */
     4663    InsertConfigNode(pDevices, "3c501",  &pDev3C501);
     4664
     4665    for (ULONG uInstance = 0; uInstance < maxNetworkAdapters; ++uInstance)
     4666    {
     4667        ComPtr<INetworkAdapter> networkAdapter;
     4668         hrc = pMachine->GetNetworkAdapter(uInstance, networkAdapter.asOutParam());     H();
     4669        BOOL fEnabledNetAdapter = FALSE;
     4670        hrc = networkAdapter->COMGETTER(Enabled)(&fEnabledNetAdapter);                  H();
     4671        if (!fEnabledNetAdapter)
     4672            continue;
     4673
     4674        /*
     4675         * The virtual hardware type. Create appropriate device first.
     4676         */
     4677        const char *pszAdapterName = "pcnet";
     4678        NetworkAdapterType_T adapterType;
     4679        hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType);                     H();
     4680        switch (adapterType)
     4681        {
     4682            case NetworkAdapterType_Am79C970A:
     4683            case NetworkAdapterType_Am79C973:
     4684            case NetworkAdapterType_Am79C960:
     4685                pDev = pDevPCNet;
     4686                break;
     4687#ifdef VBOX_WITH_E1000
     4688            case NetworkAdapterType_I82540EM:
     4689            case NetworkAdapterType_I82543GC:
     4690            case NetworkAdapterType_I82545EM:
     4691                pDev = pDevE1000;
     4692                pszAdapterName = "e1000";
     4693                break;
     4694#endif
     4695#ifdef VBOX_WITH_VIRTIO
     4696            case NetworkAdapterType_Virtio:
     4697                pDev = pDevVirtioNet;
     4698                pszAdapterName = "virtio-net";
     4699                break;
     4700#endif /* VBOX_WITH_VIRTIO */
     4701            case NetworkAdapterType_NE1000:
     4702            case NetworkAdapterType_NE2000:
     4703            case NetworkAdapterType_WD8003:
     4704            case NetworkAdapterType_WD8013:
     4705            case NetworkAdapterType_ELNK2:
     4706                pDev = pDevDP8390;
     4707                break;
     4708            case NetworkAdapterType_ELNK1:
     4709                pDev = pDev3C501;
     4710                break;
     4711            default:
     4712                AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'", adapterType, uInstance));
     4713                return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
     4714                                             N_("Invalid network adapter type '%d' for slot '%d'"), adapterType, uInstance);
     4715        }
     4716
     4717        InsertConfigNode(pDev, Utf8StrFmt("%u", uInstance).c_str(), &pInst);
     4718        InsertConfigInteger(pInst, "Trusted",              1); /* boolean */
     4719        /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
     4720         * next 4 get 16..19. */
     4721        int iPCIDeviceNo;
     4722        switch (uInstance)
     4723        {
     4724            case 0:
     4725                iPCIDeviceNo = 3;
     4726                break;
     4727            case 1: case 2: case 3:
     4728                iPCIDeviceNo = uInstance - 1 + 8;
     4729                break;
     4730            case 4: case 5: case 6: case 7:
     4731                iPCIDeviceNo = uInstance - 4 + 16;
     4732                break;
     4733            default:
     4734                /* auto assignment */
     4735                iPCIDeviceNo = -1;
     4736                break;
     4737        }
     4738#ifdef VMWARE_NET_IN_SLOT_11
     4739        /*
     4740         * Dirty hack for PCI slot compatibility with VMWare,
     4741         * it assigns slot 0x11 to the first network controller.
     4742         */
     4743        if (iPCIDeviceNo == 3 && adapterType == NetworkAdapterType_I82545EM)
     4744        {
     4745            iPCIDeviceNo = 0x11;
     4746            fSwapSlots3and11 = true;
     4747        }
     4748        else if (iPCIDeviceNo == 0x11 && fSwapSlots3and11)
     4749            iPCIDeviceNo = 3;
     4750#endif
     4751        PCIBusAddress PCIAddr = PCIBusAddress(0, iPCIDeviceNo, 0);
     4752        hrc = pBusMgr->assignPCIDevice(pszAdapterName, pInst, PCIAddr);                 H();
     4753
     4754        InsertConfigNode(pInst, "Config", &pCfg);
     4755#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE   /* not safe here yet. */ /** @todo Make PCNet ring-0 safe on 32-bit mac kernels! */
     4756        if (pDev == pDevPCNet)
     4757            InsertConfigInteger(pCfg, "R0Enabled",    false);
     4758#endif
     4759        /*
     4760         * Collect information needed for network booting and add it to the list.
     4761         */
     4762        BootNic     nic;
     4763
     4764        nic.mInstance    = uInstance;
     4765        /* Could be updated by reference, if auto assigned */
     4766        nic.mPCIAddress  = PCIAddr;
     4767
     4768        hrc = networkAdapter->COMGETTER(BootPriority)(&nic.mBootPrio);                  H();
     4769
     4770        llBootNics.push_back(nic);
     4771
     4772        /*
     4773         * The virtual hardware type. PCNet supports three types, E1000 three,
     4774         * but VirtIO only one.
     4775         */
     4776        switch (adapterType)
     4777        {
     4778            case NetworkAdapterType_Am79C970A:
     4779                InsertConfigString(pCfg, "ChipType", "Am79C970A");
     4780                break;
     4781            case NetworkAdapterType_Am79C973:
     4782                InsertConfigString(pCfg, "ChipType", "Am79C973");
     4783                break;
     4784            case NetworkAdapterType_Am79C960:
     4785                InsertConfigString(pCfg, "ChipType", "Am79C960");
     4786                break;
     4787            case NetworkAdapterType_I82540EM:
     4788                InsertConfigInteger(pCfg, "AdapterType", 0);
     4789                break;
     4790            case NetworkAdapterType_I82543GC:
     4791                InsertConfigInteger(pCfg, "AdapterType", 1);
     4792                break;
     4793            case NetworkAdapterType_I82545EM:
     4794                InsertConfigInteger(pCfg, "AdapterType", 2);
     4795                break;
     4796            case NetworkAdapterType_Virtio:
     4797                break;
     4798            case NetworkAdapterType_NE1000:
     4799                InsertConfigString(pCfg, "DeviceType", "NE1000");
     4800                break;
     4801            case NetworkAdapterType_NE2000:
     4802                InsertConfigString(pCfg, "DeviceType", "NE2000");
     4803                break;
     4804            case NetworkAdapterType_WD8003:
     4805                InsertConfigString(pCfg, "DeviceType", "WD8003");
     4806                break;
     4807            case NetworkAdapterType_WD8013:
     4808                InsertConfigString(pCfg, "DeviceType", "WD8013");
     4809                break;
     4810            case NetworkAdapterType_ELNK2:
     4811                InsertConfigString(pCfg, "DeviceType", "3C503");
     4812                break;
     4813            case NetworkAdapterType_ELNK1:
     4814                break;
     4815            case NetworkAdapterType_Null:      AssertFailedBreak(); /* (compiler warnings) */
     4816#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
     4817            case NetworkAdapterType_32BitHack: AssertFailedBreak(); /* (compiler warnings) */
     4818#endif
     4819        }
     4820
     4821        /*
     4822         * Get the MAC address and convert it to binary representation
     4823         */
     4824        Bstr macAddr;
     4825        hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam());              H();
     4826        Assert(!macAddr.isEmpty());
     4827        Utf8Str macAddrUtf8 = macAddr;
     4828#ifdef VBOX_WITH_CLOUD_NET
     4829        NetworkAttachmentType_T eAttachmentType;
     4830        hrc = networkAdapter->COMGETTER(AttachmentType)(&eAttachmentType);                 H();
     4831        if (eAttachmentType == NetworkAttachmentType_Cloud)
     4832        {
     4833            mGateway.setLocalMacAddress(macAddrUtf8);
     4834            /* We'll insert cloud MAC later, when it becomes known. */
     4835        }
     4836        else
     4837        {
     4838#endif
     4839        char *macStr = (char*)macAddrUtf8.c_str();
     4840        Assert(strlen(macStr) == 12);
     4841        RTMAC Mac;
     4842        RT_ZERO(Mac);
     4843        char *pMac = (char*)&Mac;
     4844        for (uint32_t i = 0; i < 6; ++i)
     4845        {
     4846            int c1 = *macStr++ - '0';
     4847            if (c1 > 9)
     4848                c1 -= 7;
     4849            int c2 = *macStr++ - '0';
     4850            if (c2 > 9)
     4851                c2 -= 7;
     4852            *pMac++ = (char)(((c1 & 0x0f) << 4) | (c2 & 0x0f));
     4853        }
     4854        InsertConfigBytes(pCfg, "MAC", &Mac, sizeof(Mac));
     4855#ifdef VBOX_WITH_CLOUD_NET
     4856        }
     4857#endif
     4858        /*
     4859         * Check if the cable is supposed to be unplugged
     4860         */
     4861        BOOL fCableConnected;
     4862        hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected);              H();
     4863        InsertConfigInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0);
     4864
     4865        /*
     4866         * Line speed to report from custom drivers
     4867         */
     4868        ULONG ulLineSpeed;
     4869        hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed);                       H();
     4870        InsertConfigInteger(pCfg, "LineSpeed", ulLineSpeed);
     4871
     4872        /*
     4873         * Attach the status driver.
     4874         */
     4875        i_attachStatusDriver(pInst, DeviceType_Network);
     4876
     4877        /*
     4878         * Configure the network card now
     4879         */
     4880        bool fIgnoreConnectFailure = mMachineState == MachineState_Restoring;
     4881        int vrc = i_configNetwork(pszAdapterName,
     4882                                  uInstance,
     4883                                  0,
     4884                                  networkAdapter,
     4885                                  pCfg,
     4886                                  pLunL0,
     4887                                  pInst,
     4888                                  false /*fAttachDetach*/,
     4889                                  fIgnoreConnectFailure,
     4890                                  pUVM,
     4891                                  pVMM);
     4892        if (RT_FAILURE(vrc))
     4893            return vrc;
     4894    }
     4895
     4896    return VINF_SUCCESS;
     4897}
     4898
     4899
    46324900int Console::i_configGuestDbg(ComPtr<IVirtualBox> pVBox, ComPtr<IMachine> pMachine, PCFGMNODE pRoot)
    46334901{
Note: See TracChangeset for help on using the changeset viewer.

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