VBoxNetAdp-solaris.c revision e8360046bf56d03d114dcd9c8e273d00e1985f43
/* $Id$ */
/** @file
* VBoxNetAdapter - Network Adapter Driver (Host), Solaris Specific Code.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#if defined(DEBUG_ramshankar) && !defined(LOG_ENABLED)
# define LOG_ENABLED
#endif
#define LOG_GROUP LOG_GROUP_NET_TAP_DRV
#include <iprt/semaphore.h>
#include <iprt/initterm.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#define VBOXSOLQUOTE2(x) #x
#define VBOXSOLQUOTE(x) VBOXSOLQUOTE2(x)
#define DEVICE_NAME "vboxnet"
/** The module descriptions as seen in 'modinfo'. */
#define DEVICE_DESC_DRV "VirtualBox NetAdp"
#define DEVICE_DESC_MOD "VirtualBox AdpMod"
#define VBOXNETADP_MTU 1500
static int VBoxNetAdpSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pArg, void **ppResult);
static int VBoxNetAdpSolarisModOpen(queue_t *pQueue, dev_t *pDev, int fFile, int fStream, cred_t *pCred);
/**
* Streams: module info.
*/
static struct module_info g_VBoxNetAdpSolarisModInfo =
{
0x0dd, /* module id */
0, /* min. packet size */
INFPSZ, /* max. packet size */
0, /* hi-water mask */
0 /* lo-water mask */
};
/**
* 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 *
*******************************************************************************/
/** Global device info handle. */
/** The default ethernet broadcast address */
/** GCC C++ hack. */
unsigned __gxx_personality_v0 = 0xbadb100d;
/**
* 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)
{
int rc;
/*
* 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 registeration 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.
* Registeration 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;
}
}
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;
}
}
return DDI_FAILURE;
}
/**
* Info entry point, called by solaris kernel for obtaining driver info.
*
* @param pDip The module structure instance (do not use).
* @param enmCmd Information request type.
* @param pvArg Type specific argument.
* @param ppvResult Where to store the requested info.
*
* @returns corresponding solaris error code.
*/
static int VBoxNetAdpSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg, void **ppResult)
{
LogFlow((DEVICE_NAME ":VBoxNetAdpSolarisGetInfo pDip=%p enmCmd=%d pArg=%p instance=%d\n", pDip, enmCmd,
switch (enmCmd)
{
case DDI_INFO_DEVT2DEVINFO:
{
return DDI_SUCCESS;
}
case DDI_INFO_DEVT2INSTANCE:
{
return DDI_SUCCESS;
}
}
return DDI_FAILURE;
}
{
return VINF_SUCCESS;
}
{
}
{
}
{
return GLD_SUCCESS;
}
static int vboxNetAdpSolarisSetMulticast(gld_mac_info_t *pMacInfo, unsigned char *pMulticastAddr, int fMulticast)
{
}
{
}