/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <io/xdf_shell.h>
/*
* We're emulating (and possibly layering on top of) cmdk devices, so xdf
* disk unit mappings must match up with cmdk disk unit mappings'.
*/
#if !defined(XDF_PSHIFT)
#error "can't find definition for xdf unit mappings - XDF_PSHIFT"
#endif /* XDF_PSHIFT */
#if !defined(CMDK_UNITSHF)
#error "can't find definition for cmdk unit mappings - CMDK_UNITSHF"
#endif /* CMDK_UNITSHF */
#if ((XDF_PSHIFT - CMDK_UNITSHF) != 0)
#error "cmdk and xdf unit mappings don't match."
#endif /* ((XDF_PSHIFT - CMDK_UNITSHF) != 0) */
extern void *cmdk_state;
/*
* Globals required by xdf_shell.c
*/
/*
* The paths mapping here are very specific to xen and qemu. When a
* domU is booted under xen in HVM mode, qemu is normally used to
* emulate up to four ide disks. These disks always have the four
* path listed below. To configure an emulated ide device, the
* xen domain configuration file normally has an entry that looks
* like this:
* disk = [ 'file:/foo.img,hda,w' ]
*
* The part we're interested in is the 'hda', which we'll call the
* xen disk device name here. The xen management tools (which parse
* the xen domain configuration file and launch qemu) makes the
* following assumptions about this value:
* hda == emulated ide disk 0 (ide bus 0, master)
* hdb == emulated ide disk 1 (ide bus 0, slave)
* hdc == emulated ide disk 2 (ide bus 1, master)
* hdd == emulated ide disk 3 (ide bus 1, slave)
*
* (Uncoincidentally, these xen disk device names actually map to
* the /dev filesystem names of ide disk devices in Linux. So in
* our mapping we've just hardcoded the cmdk paths that we know
* qemu will use.
*
* To understand the second half of the mapping (ie, the xdf device
* that each emulated cmdk device should be mapped two) we need to
* know the solaris device node address that will be assigned to
* each xdf device. (The device node address is the decimal
* number that comes after the "xdf@" in the device path.)
*
* So the question becomes, how do we know what the xenstore device
* id for emulated disk will be? Well, it turns out that since the
* xen management tools expect the disk device names to be Linux
* device names, those same management tools assign each disk a
* device id that matches the dev_t of the corresponding device
* under Linux. (Big shocker.) This xen device name-to-id mapping
* is currently all hard coded here:
*
* So looking at the code above we can see the following xen disk
* device name to xenstore device id mappings:
* 'hda' == 0t768 == ((3 * 256) + (0 * 64))
* 'hdb' == 0t832 == ((3 * 256) + (1 * 64))
* 'hdc' == 0t5632 == ((22 * 256) + (0 * 64))
* 'hdd' == 0t5696 == ((22 * 256) + (1 * 64))
*/
{ NULL, 0 }
};
/*
* Private functions
*/
/*
* xdfs_get_modser() is basically a local copy of
* cmdk_get_modser() modified to work without the dadk layer.
* (which the non-pv version of the cmdk driver uses.)
*/
static int
{
char *s;
char ch;
int i;
int tb;
return (0);
/*
*/
s = buf;
ch = *s++;
tb = i + 1;
}
return (0);
return (tb);
}
/*
* xdfs_devid_modser() is basically a copy of cmdk_devid_modser()
* that has been modified to use local pv cmdk driver functions.
*
* Build a devid from the model and serial number
* Return DDI_SUCCESS or DDI_FAILURE.
*/
static int
{
char *hwid;
int modlen;
int serlen;
/*
* device ID is a concatenation of model number, '=', serial number.
*/
if (modlen == 0)
goto err;
if (serlen == 0)
goto err;
/* Initialize the device ID, trailing NULL not included */
if (rc != DDI_SUCCESS)
goto err;
return (DDI_SUCCESS);
err:
return (DDI_FAILURE);
}
/*
* xdfs_devid_read() is basically a local copy of
* cmdk_devid_read() modified to work without the dadk layer.
* (which the non-pv version of the cmdk driver uses.)
*
* Read a devid from on the first block of the last track of
* the last cylinder. Make sure what we read is a valid devid.
* Return DDI_SUCCESS or DDI_FAILURE.
*/
static int
{
int i;
return (DDI_FAILURE);
goto err;
/* Validate the revision */
goto err;
/* Calculate the checksum */
chksum = 0;
for (i = 0; i < ((NBPSCTR - sizeof (int))/sizeof (int)); i++)
goto err;
/* Validate the device id */
goto err;
/* keep a copy of the device id */
return (DDI_SUCCESS);
err:
return (DDI_FAILURE);
}
/*
* xdfs_devid_fabricate() is basically a local copy of
* cmdk_devid_fabricate() modified to work without the dadk layer.
* (which the non-pv version of the cmdk driver uses.)
*
* Create a devid and write it on the first block of the last track of
* the last cylinder.
* Return DDI_SUCCESS or DDI_FAILURE.
*/
static int
{
int i;
return (DDI_FAILURE);
return (DDI_FAILURE);
/* allocate a buffer */
/* Fill in the revision */
/* Copy in the device id */
i = ddi_devid_sizeof(devid);
if (i > DK_DEVID_SIZE)
goto err;
/* Calculate the chksum */
chksum = 0;
for (i = 0; i < ((NBPSCTR - sizeof (int))/sizeof (int)); i++)
/* Fill in the checksum */
goto err;
return (DDI_SUCCESS);
err:
return (DDI_FAILURE);
}
/*
* xdfs_rwcmd_copyin() is a duplicate of rwcmd_copyin().
*/
static int
{
switch (ddi_model_convert_from(flag)) {
case DDI_MODEL_ILP32: {
sizeof (struct dadkio_rwcmd32), flag)) {
return (EFAULT);
}
/*
* Note: we do not convert the 'status' field,
* as it should not contain valid data at this
* point.
*/
break;
}
case DDI_MODEL_NONE: {
sizeof (struct dadkio_rwcmd), flag)) {
return (EFAULT);
}
}
}
return (0);
}
/*
* xdfs_rwcmd_copyout() is a duplicate of rwcmd_copyout().
*/
static int
{
switch (ddi_model_convert_from(flag)) {
case DDI_MODEL_ILP32: {
sizeof (struct dadkio_rwcmd32), flag))
return (EFAULT);
break;
}
case DDI_MODEL_NONE: {
sizeof (struct dadkio_rwcmd), flag))
return (EFAULT);
}
}
return (0);
}
static int
{
if (status != 0)
goto out;
case DADKIO_RWCMD_READ:
case DADKIO_RWCMD_WRITE:
break;
default:
goto out;
}
/*
* Tell the xdf driver that this I/O request is using an absolute
* offset.
*/
if (status == 0)
out:
return (status);
}
/*
* xdf_shell callback functions
*/
/*ARGSUSED*/
int
{
switch (cmd) {
default:
return (0);
case DKIOCLOCK:
case DKIOCUNLOCK:
case FDEJECT:
case DKIOCEJECT:
case CDROMEJECT: {
/* we don't support ejectable devices */
return (ENOTTY);
}
case DKIOCGETWCE:
case DKIOCSETWCE: {
return (EIO);
}
case DKIOCADDBAD: {
/*
* to cause the driver to re-read the bad block list and
* alternate map after it has been updated. Our driver
* will refuse to attach to any disk which has a bad blocks
* list defined, so there really isn't much to do here.
*/
return (0);
}
case DKIOCGETDEF: {
/*
* I can't actually find any code that utilizes this ioctl,
* hence we're leaving it explicitly unimplemented.
*/
ASSERT("ioctl cmd unsupported by xdf shell: DKIOCGETDEF");
return (EIO);
}
case DIOCTL_RWCMD: {
/*
* This just seems to just be an alternate interface for
* reading and writing the disk. Great, another way to
* do the same thing...
*/
}
case DKIOCINFO: {
int rv;
/* Pass on the ioctl request, save the response */
return (rv);
/* Update controller info */
/* Update unit info. */
return (EFAULT);
return (0);
}
} /* switch (cmd) */
/*NOTREACHED*/
}
/*
* xdfs_c_devid_setup() is a slightly modified copy of cmdk_devid_setup().
*
* Create and register the devid.
* There are 4 different ways we can get a device id:
* 1. Already have one - nothing to do
* 2. Build one from the drive's model and serial numbers
* 3. Read one from the disk (first sector of last track)
* 4. Fabricate one and write it on the disk.
* If any of these succeeds, register the deviceid
*/
void
{
int rc;
/* Try options until one succeeds, or all have failed */
/* 1. All done if already registered */
return;
/* 2. Build a devid from the model and serial number */
if (rc != DDI_SUCCESS) {
/* 3. Read devid from the disk, if present */
/* 4. otherwise make one up and write it on the disk */
if (rc != DDI_SUCCESS)
}
/* If we managed to get a devid any of the above ways, register it */
if (rc == DDI_SUCCESS)
}
int
{
int err;
return (err);
/* This driver won't work if this isn't true */
return (0);
}
{
int alts;
/* find slice with V_ALTSCTR tag */
/* no partition table exists */
return (B_FALSE);
}
break;
}
return (B_FALSE); /* no V_ALTSCTR slice defined */
/* read in ALTS label block */
goto err;
goto err;
/* we found bad block mappins */
return (B_TRUE);
err:
return (B_FALSE);
}
char *
{
}
/*ARGSUSED*/
int
{
return (xsp->xdfss_tgt_is_cd ?
}
/*ARGSUSED*/
void
{
}