VBoxNetAdp-solaris.c revision 3fa78bc85ec3388c0600fb4470002b1b45deda11
/* $Id$ */
/** @file
* VBoxNetAdapter - Network Adapter Driver (Host), Solaris Specific Code.
*/
/*
* Copyright (C) 2009-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_NET_ADP_DRV
#ifdef DEBUG_ramshankar
# define LOG_ENABLED
# define LOG_INSTANCE RTLogRelDefaultInstance()
#endif
#include <iprt/semaphore.h>
#include <iprt/initterm.h>
#include "../VBoxNetAdpInternal.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#define DEVICE_NAME "vboxnet"
/** The module descriptions as seen in 'modinfo'. */
#define DEVICE_DESC_DRV "VirtualBox NetAdp"
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
/**
* Streams: module info.
*/
static struct module_info g_VBoxNetAdpSolarisModInfo =
{
0x0dd, /* module id */
0, /* min. packet size */
INFPSZ, /* max. packet size */
0, /* hi-water mark */
0 /* lo-water mark */
};
/**
* Streams: read queue hooks.
*/
static struct qinit g_VBoxNetAdpSolarisReadQ =
{
NULL, /* read */
NULL, /* admin (reserved) */
NULL /* module stats */
};
/**
* Streams: write queue hooks.
*/
static struct qinit g_VBoxNetAdpSolarisWriteQ =
{
NULL, /* open */
NULL, /* close */
NULL, /* admin (reserved) */
NULL /* module stats */
};
/**
* Streams: IO stream tab.
*/
static struct streamtab g_VBoxNetAdpSolarisStreamTab =
{
NULL, /* muxread init */
NULL /* muxwrite init */
};
/**
*/
static struct cb_ops g_VBoxNetAdpSolarisCbOps =
{
nulldev, /* cb open */
nulldev, /* cb close */
nodev, /* b strategy */
nodev, /* b dump */
nodev, /* b print */
nodev, /* cb read */
nodev, /* cb write */
nodev, /* cb ioctl */
nodev, /* c devmap */
nodev, /* c mmap */
nodev, /* c segmap */
nochpoll, /* c poll */
ddi_prop_op, /* property ops */
D_MP, /* compat. flag */
CB_REV /* revision */
};
/**
*/
static struct dev_ops g_VBoxNetAdpSolarisDevOps =
{
DEVO_REV, /* driver build revision */
0, /* ref count */
nulldev, /* identify */
nulldev, /* probe */
nodev, /* reset */
(struct bus_ops *)0,
nodev, /* power */
};
/**
* modldrv: export driver specifics to kernel
*/
static struct modldrv g_VBoxNetAdpSolarisDriver =
{
&mod_driverops, /* extern from kernel */
};
/**
*/
static struct modlinkage g_VBoxNetAdpSolarisModLinkage =
{
MODREV_1, /* loadable module system revision */
{
&g_VBoxNetAdpSolarisDriver, /* adapter streams driver framework */
NULL /* terminate array of linkage structures */
}
};
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The default ethernet broadcast address */
/**
* vboxnetadp_state_t: per-instance data
*/
typedef struct vboxnetadp_state_t
{
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static int vboxNetAdpSolarisSetMulticast(gld_mac_info_t *pMacInfo, unsigned char *pMulticastAddr, int fMulticast);
/**
* Kernel entry points
*/
int _init(void)
{
/*
* Prevent module autounloading.
*/
if (pModCtl)
else
/*
* Initialize IPRT.
*/
if (RT_SUCCESS(rc))
{
if (!rc)
return rc;
RTR0Term();
}
else
return RTErrConvertToErrno(rc);
}
int _fini(void)
{
/*
* Undo the work done during start (in reverse order).
*/
RTR0Term();
return mod_remove(&g_VBoxNetAdpSolarisModLinkage);
}
{
return rc;
}
/**
* Attach entry point, to attach a device to the system or resume it.
*
* @param pDip The module structure instance.
*
* @returns corresponding solaris error code.
*/
{
int rc = -1;
switch (enmCmd)
{
case DDI_ATTACH:
{
if (pMacInfo)
{
if (pState)
{
/*
* Setup GLD MAC layer registration info.
*/
pMacInfo->gldm_minpkt = 0;
/*
* We use a semi-random MAC addresses similar to a guest NIC's MAC address
* as the default factory address of the interface.
*/
if (RT_SUCCESS(rc))
{
/*
* Now try registering our GLD with the MAC layer.
* Registration can fail on some S10 versions when the MTU size is more than 1500.
* When we implement jumbo frames we should probably retry with MTU 1500 for S10.
*/
if (rc == DDI_SUCCESS)
{
return DDI_SUCCESS;
}
else
}
else
}
else
}
else
return DDI_FAILURE;
}
case DDI_RESUME:
{
/* Nothing to do here... */
return DDI_SUCCESS;
}
/* case DDI_PM_RESUME: */
default:
return DDI_FAILURE;
}
}
/**
* Detach entry point, to detach a device to the system or suspend it.
*
* @param pDip The module structure instance.
*
* @returns corresponding solaris error code.
*/
{
switch (enmCmd)
{
case DDI_DETACH:
{
/*
* Unregister and clean up.
*/
if (pMacInfo)
{
if (pState)
{
if (rc == DDI_SUCCESS)
{
return DDI_SUCCESS;
}
else
LogRel((DEVICE_NAME ":VBoxNetAdpSolarisDetach failed to unregister GLD from MAC layer.rc=%d\n", rc));
}
else
}
else
return DDI_FAILURE;
}
case DDI_RESUME:
{
/* Nothing to do here... */
return DDI_SUCCESS;
}
/* case DDI_SUSPEND: */
/* case DDI_HOTPLUG_DETACH: */
default:
return DDI_FAILURE;
}
}
{
return VINF_SUCCESS;
}
{
if (pState)
{
Log((DEVICE_NAME ":vboxNetAdpSolarisSetMacAddress updated MAC %.*Rhxs\n", sizeof(RTMAC), &pState->CurrentMac));
return GLD_SUCCESS;
}
else
return GLD_FAILURE;
}
{
while (pMsg)
{
}
return GLD_SUCCESS;
}
{
return GLD_SUCCESS;
}
static int vboxNetAdpSolarisSetMulticast(gld_mac_info_t *pMacInfo, unsigned char *pMulticastAddr, int fMulticast)
{
return GLD_SUCCESS;
}
{
/* Host requesting promiscuous intnet connection... */
return GLD_SUCCESS;
}
{
/*
* For now fake up stats. Stats like duplex and speed are better set as they
* are used in utilities like dladm. Link state capabilities are critical
* as they are used by ipadm while trying to restore persistent interface configs.
*/
if (pState)
{
/* Ether */
return GLD_SUCCESS;
}
else
return GLD_FAILURE;
}