2004-10-24 05:37:23 +00:00
|
|
|
/*
|
2005-09-07 23:33:26 +00:00
|
|
|
* Copyright (c) 2004-2005 HighPoint Technologies, Inc.
|
2004-10-24 05:37:23 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2005-03-02 05:14:28 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
2004-10-24 05:37:23 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* gui_lib.c
|
|
|
|
* Copyright (c) 2002-2004 HighPoint Technologies, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Platform independent ioctl interface implementation.
|
|
|
|
* The platform dependent part may reuse this function and/or use it own
|
|
|
|
* implementation for each ioctl function.
|
|
|
|
*
|
|
|
|
* This implementation doesn't use any synchronization; the caller must
|
|
|
|
* assure the proper context when calling these functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
#ifndef __KERNEL__
|
|
|
|
#define __KERNEL__
|
|
|
|
#endif
|
|
|
|
|
2004-10-24 05:37:23 +00:00
|
|
|
#include <dev/hptmv/global.h>
|
|
|
|
#include <dev/hptmv/hptintf.h>
|
|
|
|
#include <dev/hptmv/osbsd.h>
|
2005-03-02 15:13:37 +00:00
|
|
|
#include <dev/hptmv/access601.h>
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
static int hpt_get_driver_capabilities(PDRIVER_CAPABILITIES cap);
|
|
|
|
static int hpt_get_controller_count(void);
|
|
|
|
static int hpt_get_controller_info(int id, PCONTROLLER_INFO pInfo);
|
|
|
|
static int hpt_get_channel_info(int id, int bus, PCHANNEL_INFO pInfo);
|
|
|
|
static int hpt_get_logical_devices(DEVICEID * pIds, int nMaxCount);
|
|
|
|
static int hpt_get_device_info(DEVICEID id, PLOGICAL_DEVICE_INFO pInfo);
|
2009-04-07 16:38:25 +00:00
|
|
|
static int hpt_get_device_info_v2(DEVICEID id, PLOGICAL_DEVICE_INFO_V2 pInfo);
|
2004-10-24 05:37:23 +00:00
|
|
|
static DEVICEID hpt_create_array(_VBUS_ARG PCREATE_ARRAY_PARAMS pParam);
|
2009-04-07 16:38:25 +00:00
|
|
|
static DEVICEID hpt_create_array_v2(_VBUS_ARG PCREATE_ARRAY_PARAMS_V2 pParam);
|
2004-10-24 05:37:23 +00:00
|
|
|
static int hpt_add_spare_disk(_VBUS_ARG DEVICEID idDisk);
|
|
|
|
static int hpt_remove_spare_disk(_VBUS_ARG DEVICEID idDisk);
|
|
|
|
static int hpt_set_array_info(_VBUS_ARG DEVICEID idArray, PALTERABLE_ARRAY_INFO pInfo);
|
|
|
|
static int hpt_set_device_info(_VBUS_ARG DEVICEID idDisk, PALTERABLE_DEVICE_INFO pInfo);
|
2009-04-07 16:38:25 +00:00
|
|
|
static int hpt_set_device_info_v2(_VBUS_ARG DEVICEID idDisk, PALTERABLE_DEVICE_INFO_V2 pInfo);
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
int
|
|
|
|
check_VDevice_valid(PVDevice p)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
PVDevice pVDevice;
|
|
|
|
PVBus _vbus_p;
|
|
|
|
IAL_ADAPTER_T *pAdapter = gIal_Adapter;
|
|
|
|
|
|
|
|
while(pAdapter != 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < MV_SATA_CHANNELS_NUM; i++)
|
|
|
|
if(&(pAdapter->VDevices[i]) == p) return 0;
|
|
|
|
pAdapter = pAdapter->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SUPPORT_ARRAY
|
|
|
|
pAdapter = gIal_Adapter;
|
|
|
|
while(pAdapter != 0)
|
|
|
|
{
|
|
|
|
_vbus_p = &pAdapter->VBus;
|
|
|
|
for (i=0;i<MAX_ARRAY_PER_VBUS;i++)
|
|
|
|
{
|
|
|
|
pVDevice=ArrayTables(i);
|
|
|
|
if ((pVDevice->u.array.dArStamp != 0) && (pVDevice == p))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pAdapter = pAdapter->next;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SUPPORT_ARRAY
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
static UCHAR get_vdev_type(PVDevice pVDevice)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
2009-04-07 16:38:25 +00:00
|
|
|
switch (pVDevice->VDeviceType) {
|
|
|
|
case VD_RAID_0: return AT_RAID0;
|
|
|
|
case VD_RAID_1: return AT_RAID1;
|
|
|
|
case VD_JBOD: return AT_JBOD;
|
|
|
|
case VD_RAID_5: return AT_RAID5;
|
|
|
|
default: return AT_UNKNOWN;
|
|
|
|
}
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
static DWORD get_array_flag(PVDevice pVDevice)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
DWORD f = 0;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* The array is disabled */
|
|
|
|
if(!pVDevice->vf_online) {
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_DISABLED;
|
|
|
|
/* Ignore other info */
|
|
|
|
return f;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* array need synchronizing */
|
|
|
|
if(pVDevice->u.array.rf_need_rebuild && !pVDevice->u.array.rf_duplicate_and_create)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_NEEDBUILDING;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* array is in rebuilding process */
|
|
|
|
if(pVDevice->u.array.rf_rebuilding)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_REBUILDING;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* array is being verified */
|
|
|
|
if(pVDevice->u.array.rf_verifying)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_VERIFYING;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* array is being initialized */
|
|
|
|
if(pVDevice->u.array.rf_initializing)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_INITIALIZING;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* broken but may still working */
|
|
|
|
if(pVDevice->u.array.rf_broken)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_BROKEN;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* array has a active partition */
|
|
|
|
if(pVDevice->vf_bootable)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_BOOTDISK;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* a newly created array */
|
|
|
|
if(pVDevice->u.array.rf_newly_created)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_NEWLY_CREATED;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* array has boot mark set */
|
|
|
|
if(pVDevice->vf_bootmark)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_BOOTMARK;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* auto-rebuild should start */
|
|
|
|
if(pVDevice->u.array.rf_auto_rebuild)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_NEED_AUTOREBUILD;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
for(i = 0; i < pVDevice->u.array.bArnMember; i++)
|
|
|
|
{
|
|
|
|
PVDevice pMember = pVDevice->u.array.pMember[i];
|
|
|
|
if (!pMember || !pMember->vf_online || (pMember->VDeviceType==VD_SINGLE_DISK))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* array need synchronizing */
|
|
|
|
if(pMember->u.array.rf_need_rebuild &&
|
|
|
|
!pMember->u.array.rf_duplicate_and_create)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_NEEDBUILDING;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* array is in rebuilding process */
|
|
|
|
if(pMember->u.array.rf_rebuilding)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_REBUILDING;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* array is being verified */
|
|
|
|
if(pMember->u.array.rf_verifying)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_VERIFYING;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* array is being initialized */
|
|
|
|
if(pMember->u.array.rf_initializing)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_INITIALIZING;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* broken but may still working */
|
|
|
|
if(pMember->u.array.rf_broken)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_BROKEN;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* a newly created array */
|
|
|
|
if(pMember->u.array.rf_newly_created)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_NEWLY_CREATED;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* auto-rebuild should start */
|
|
|
|
if(pMember->u.array.rf_auto_rebuild)
|
2009-04-07 16:38:25 +00:00
|
|
|
f |= ARRAY_FLAG_NEED_AUTOREBUILD;
|
|
|
|
}
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD calc_rebuild_progress(PVDevice pVDevice)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
DWORD result = ((ULONG)(pVDevice->u.array.RebuildSectors>>11)*1000 /
|
|
|
|
(ULONG)(pVDevice->VDeviceCapacity>>11) * (pVDevice->u.array.bArnMember-1)) * 10;
|
|
|
|
|
|
|
|
for(i = 0; i < pVDevice->u.array.bArnMember; i++)
|
|
|
|
{
|
|
|
|
PVDevice pMember = pVDevice->u.array.pMember[i];
|
|
|
|
if (!pMember || !pMember->vf_online || (pMember->VDeviceType==VD_SINGLE_DISK))
|
|
|
|
continue;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* for RAID1/0 case */
|
|
|
|
if (pMember->u.array.rf_rebuilding ||
|
|
|
|
pMember->u.array.rf_verifying ||
|
|
|
|
pMember->u.array.rf_initializing)
|
|
|
|
{
|
2009-04-07 16:38:25 +00:00
|
|
|
DWORD percent = ((ULONG)(pMember->u.array.RebuildSectors>>11)*1000 /
|
|
|
|
(ULONG)(pMember->VDeviceCapacity>>11) * (pMember->u.array.bArnMember-1)) * 10;
|
|
|
|
if (result==0 || result>percent)
|
|
|
|
result = percent;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
2009-04-07 16:38:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (result>10000) result = 10000;
|
|
|
|
return result;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
static void get_array_info(PVDevice pVDevice, PHPT_ARRAY_INFO pArrayInfo)
|
|
|
|
{
|
|
|
|
int i;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
memcpy(pArrayInfo->Name, pVDevice->u.array.ArrayName, MAX_ARRAY_NAME);
|
|
|
|
pArrayInfo->ArrayType = get_vdev_type(pVDevice);
|
|
|
|
pArrayInfo->BlockSizeShift = pVDevice->u.array.bArBlockSizeShift;
|
|
|
|
pArrayInfo->RebuiltSectors = pVDevice->u.array.RebuildSectors;
|
|
|
|
pArrayInfo->Flags = get_array_flag(pVDevice);
|
|
|
|
pArrayInfo->RebuildingProgress = calc_rebuild_progress(pVDevice);
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
pArrayInfo->nDisk = 0;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
for(i = 0; i < pVDevice->u.array.bArnMember; i++)
|
2009-04-07 16:38:25 +00:00
|
|
|
if(pVDevice->u.array.pMember[i] != NULL)
|
|
|
|
pArrayInfo->Members[pArrayInfo->nDisk++] = VDEV_TO_ID(pVDevice->u.array.pMember[i]);
|
|
|
|
|
|
|
|
for(i=pArrayInfo->nDisk; i<MAX_ARRAY_MEMBERS; i++)
|
|
|
|
pArrayInfo->Members[i] = INVALID_DEVICEID;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
2009-04-07 16:38:25 +00:00
|
|
|
|
|
|
|
static void get_array_info_v2(PVDevice pVDevice, PHPT_ARRAY_INFO_V2 pArrayInfo)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memcpy(pArrayInfo->Name, pVDevice->u.array.ArrayName, MAX_ARRAYNAME_LEN);
|
|
|
|
pArrayInfo->ArrayType = get_vdev_type(pVDevice);
|
|
|
|
pArrayInfo->BlockSizeShift = pVDevice->u.array.bArBlockSizeShift;
|
|
|
|
pArrayInfo->RebuiltSectors.lo32 = pVDevice->u.array.RebuildSectors;
|
|
|
|
pArrayInfo->RebuiltSectors.hi32 = sizeof(LBA_T)>4? (pVDevice->u.array.RebuildSectors>>32) : 0;
|
|
|
|
pArrayInfo->Flags = get_array_flag(pVDevice);
|
|
|
|
pArrayInfo->RebuildingProgress = calc_rebuild_progress(pVDevice);
|
|
|
|
|
|
|
|
pArrayInfo->nDisk = 0;
|
|
|
|
|
|
|
|
for(i = 0; i < pVDevice->u.array.bArnMember; i++)
|
|
|
|
if(pVDevice->u.array.pMember[i] != NULL)
|
|
|
|
pArrayInfo->Members[pArrayInfo->nDisk++] = VDEV_TO_ID(pVDevice->u.array.pMember[i]);
|
|
|
|
|
|
|
|
for(i=pArrayInfo->nDisk; i<MAX_ARRAY_MEMBERS_V2; i++)
|
|
|
|
pArrayInfo->Members[i] = INVALID_DEVICEID;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
static int get_disk_info(PVDevice pVDevice, PDEVICE_INFO pDiskInfo)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
MV_SATA_ADAPTER *pSataAdapter;
|
|
|
|
MV_SATA_CHANNEL *pSataChannel;
|
|
|
|
IAL_ADAPTER_T *pAdapter;
|
2009-04-07 16:38:25 +00:00
|
|
|
MV_CHANNEL *channelInfo;
|
2004-10-24 05:37:23 +00:00
|
|
|
char *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* device location */
|
|
|
|
pSataChannel = pVDevice->u.disk.mv;
|
|
|
|
if(pSataChannel == NULL) return -1;
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->TargetId = 0;
|
2004-10-24 05:37:23 +00:00
|
|
|
pSataAdapter = pSataChannel->mvSataAdapter;
|
|
|
|
if(pSataAdapter == NULL) return -1;
|
|
|
|
|
|
|
|
pAdapter = pSataAdapter->IALData;
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->PathId = pSataChannel->channelNumber;
|
|
|
|
pDiskInfo->ControllerId = (UCHAR)pSataAdapter->adapterId;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/*GUI uses DeviceModeSetting to display to users
|
|
|
|
(1) if users select a mode, GUI/BIOS should display that mode.
|
|
|
|
(2) if SATA/150, GUI/BIOS should display 150 if case (1) isn't satisfied.
|
|
|
|
(3) display real mode if case (1)&&(2) not satisfied.
|
|
|
|
*/
|
|
|
|
if (pVDevice->u.disk.df_user_mode_set)
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->DeviceModeSetting = pVDevice->u.disk.bDeUserSelectMode;
|
|
|
|
else if (((((PIDENTIFY_DATA)pVDevice->u.disk.mv->identifyDevice)->SataCapability) & 3)==2)
|
|
|
|
pDiskInfo->DeviceModeSetting = 15;
|
2004-10-24 05:37:23 +00:00
|
|
|
else {
|
|
|
|
p = (char *)&((PIDENTIFY_DATA)pVDevice->u.disk.mv->identifyDevice)->ModelNumber;
|
2009-04-07 16:38:25 +00:00
|
|
|
if (*(WORD*)p==(0x5354) /*'ST'*/ &&
|
|
|
|
(*(WORD*)(p+8)==(0x4153)/*'AS'*/ || (p[8]=='A' && p[11]=='S')))
|
|
|
|
pDiskInfo->DeviceModeSetting = 15;
|
2004-10-24 05:37:23 +00:00
|
|
|
else
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->DeviceModeSetting = pVDevice->u.disk.bDeModeSetting;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->UsableMode = pVDevice->u.disk.bDeUsable_Mode;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->DeviceType = PDT_HARDDISK;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->Flags = 0x0;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* device is disabled */
|
|
|
|
if(!pVDevice->u.disk.df_on_line)
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->Flags |= DEVICE_FLAG_DISABLED;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* disk has a active partition */
|
|
|
|
if(pVDevice->vf_bootable)
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->Flags |= DEVICE_FLAG_BOOTDISK;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* disk has boot mark set */
|
|
|
|
if(pVDevice->vf_bootmark)
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->Flags |= DEVICE_FLAG_BOOTMARK;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->Flags |= DEVICE_FLAG_SATA;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
/* is a spare disk */
|
|
|
|
if(pVDevice->VDeviceType == VD_SPARE)
|
2009-04-07 16:38:25 +00:00
|
|
|
pDiskInfo->Flags |= DEVICE_FLAG_IS_SPARE;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
memcpy(&(pDiskInfo->IdentifyData), (pSataChannel->identifyDevice), sizeof(IDENTIFY_DATA2));
|
|
|
|
p = (char *)&pDiskInfo->IdentifyData.ModelNumber;
|
2004-10-24 05:37:23 +00:00
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
((WORD*)p)[i] = shortswap(pSataChannel->identifyDevice[IDEN_MODEL_OFFSET+i]);
|
|
|
|
p[39] = '\0';
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
channelInfo = &pAdapter->mvChannel[pSataChannel->channelNumber];
|
|
|
|
pDiskInfo->ReadAheadSupported = channelInfo->readAheadSupported;
|
|
|
|
pDiskInfo->ReadAheadEnabled = channelInfo->readAheadEnabled;
|
|
|
|
pDiskInfo->WriteCacheSupported = channelInfo->writeCacheSupported;
|
|
|
|
pDiskInfo->WriteCacheEnabled = channelInfo->writeCacheEnabled;
|
|
|
|
pDiskInfo->TCQSupported = (pSataChannel->identifyDevice[IDEN_SUPPORTED_COMMANDS2] & (0x2))!=0;
|
|
|
|
pDiskInfo->TCQEnabled = pSataChannel->queuedDMA==MV_EDMA_MODE_QUEUED;
|
|
|
|
pDiskInfo->NCQSupported = MV_SATA_GEN_2(pSataAdapter) &&
|
|
|
|
(pSataChannel->identifyDevice[IDEN_SATA_CAPABILITIES] & (0x0100));
|
|
|
|
pDiskInfo->NCQEnabled = pSataChannel->queuedDMA==MV_EDMA_MODE_NATIVE_QUEUING;
|
2004-10-24 05:37:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
int hpt_get_driver_capabilities(PDRIVER_CAPABILITIES cap)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
ZeroMemory(cap, sizeof(DRIVER_CAPABILITIES));
|
|
|
|
cap->dwSize = sizeof(DRIVER_CAPABILITIES);
|
|
|
|
cap->MaximumControllers = MAX_VBUS;
|
|
|
|
|
|
|
|
/* cap->SupportCrossControllerRAID = 0; */
|
|
|
|
/* take care for various OSes! */
|
|
|
|
cap->SupportCrossControllerRAID = 0;
|
|
|
|
|
|
|
|
|
|
|
|
cap->MinimumBlockSizeShift = MinBlockSizeShift;
|
|
|
|
cap->MaximumBlockSizeShift = MaxBlockSizeShift;
|
|
|
|
cap->SupportDiskModeSetting = 0;
|
|
|
|
cap->SupportSparePool = 1;
|
|
|
|
cap->MaximumArrayNameLength = MAX_ARRAY_NAME - 1;
|
|
|
|
cap->SupportDedicatedSpare = 0;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SUPPORT_ARRAY
|
|
|
|
/* Stripe */
|
|
|
|
cap->SupportedRAIDTypes[0] = AT_RAID0;
|
|
|
|
cap->MaximumArrayMembers[0] = MAX_MEMBERS;
|
|
|
|
/* Mirror */
|
|
|
|
cap->SupportedRAIDTypes[1] = AT_RAID1;
|
|
|
|
cap->MaximumArrayMembers[1] = 2;
|
|
|
|
/* Mirror + Stripe */
|
|
|
|
#ifdef ARRAY_V2_ONLY
|
|
|
|
cap->SupportedRAIDTypes[2] = (AT_RAID1<<4)|AT_RAID0; /* RAID0/1 */
|
2005-09-07 23:33:26 +00:00
|
|
|
#else
|
2004-10-24 05:37:23 +00:00
|
|
|
cap->SupportedRAIDTypes[2] = (AT_RAID0<<4)|AT_RAID1; /* RAID1/0 */
|
|
|
|
#endif
|
|
|
|
cap->MaximumArrayMembers[2] = MAX_MEMBERS;
|
|
|
|
/* Jbod */
|
|
|
|
cap->SupportedRAIDTypes[3] = AT_JBOD;
|
|
|
|
cap->MaximumArrayMembers[3] = MAX_MEMBERS;
|
|
|
|
/* RAID5 */
|
|
|
|
#if SUPPORT_RAID5
|
|
|
|
cap->SupportedRAIDTypes[4] = AT_RAID5;
|
|
|
|
cap->MaximumArrayMembers[4] = MAX_MEMBERS;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
int hpt_get_controller_count(void)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
IAL_ADAPTER_T *pAdapTemp = gIal_Adapter;
|
|
|
|
int iControllerCount = 0;
|
|
|
|
|
|
|
|
while(pAdapTemp != 0)
|
|
|
|
{
|
|
|
|
iControllerCount++;
|
|
|
|
pAdapTemp = pAdapTemp->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iControllerCount;
|
|
|
|
}
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
int hpt_get_controller_info(int id, PCONTROLLER_INFO pInfo)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
IAL_ADAPTER_T *pAdapTemp;
|
|
|
|
int iControllerCount = 0;
|
|
|
|
|
|
|
|
for (pAdapTemp = gIal_Adapter; pAdapTemp; pAdapTemp = pAdapTemp->next) {
|
|
|
|
if (iControllerCount++==id) {
|
|
|
|
pInfo->InterruptLevel = 0;
|
|
|
|
pInfo->ChipType = 0;
|
|
|
|
pInfo->ChipFlags = CHIP_SUPPORT_ULTRA_100;
|
|
|
|
strcpy( pInfo->szVendorID, "HighPoint Technologies, Inc.");
|
|
|
|
#ifdef GUI_CONTROLLER_NAME
|
|
|
|
#ifdef FORCE_ATA150_DISPLAY
|
|
|
|
/* show "Bus Type: ATA/150" in GUI for SATA controllers */
|
|
|
|
pInfo->ChipFlags = CHIP_SUPPORT_ULTRA_150;
|
|
|
|
#endif
|
|
|
|
strcpy(pInfo->szProductID, GUI_CONTROLLER_NAME);
|
|
|
|
#define _set_product_id(x)
|
2005-09-07 23:33:26 +00:00
|
|
|
#else
|
2004-10-24 05:37:23 +00:00
|
|
|
#define _set_product_id(x) strcpy(pInfo->szProductID, x)
|
|
|
|
#endif
|
2009-04-07 16:38:25 +00:00
|
|
|
_set_product_id("RocketRAID 18xx SATA Controller");
|
2004-10-24 05:37:23 +00:00
|
|
|
pInfo->NumBuses = 8;
|
|
|
|
pInfo->ChipFlags |= CHIP_SUPPORT_ULTRA_133|CHIP_SUPPORT_ULTRA_150;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
int hpt_get_channel_info(int id, int bus, PCHANNEL_INFO pInfo)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
IAL_ADAPTER_T *pAdapTemp = gIal_Adapter;
|
|
|
|
int i,iControllerCount = 0;
|
|
|
|
|
|
|
|
while(pAdapTemp != 0)
|
|
|
|
{
|
|
|
|
if (iControllerCount++==id)
|
|
|
|
goto found;
|
|
|
|
pAdapTemp = pAdapTemp->next;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
found:
|
|
|
|
|
|
|
|
pInfo->IoPort = 0;
|
|
|
|
pInfo->ControlPort = 0;
|
|
|
|
|
|
|
|
for (i=0; i<2 ;i++)
|
|
|
|
{
|
|
|
|
pInfo->Devices[i] = (DEVICEID)INVALID_DEVICEID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pAdapTemp->mvChannel[bus].online == MV_TRUE)
|
|
|
|
pInfo->Devices[0] = VDEV_TO_ID(&pAdapTemp->VDevices[bus]);
|
|
|
|
else
|
|
|
|
pInfo->Devices[0] = (DEVICEID)INVALID_DEVICEID;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
int hpt_get_logical_devices(DEVICEID * pIds, int nMaxCount)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
int i,j;
|
|
|
|
PVDevice pPhysical, pLogical;
|
|
|
|
IAL_ADAPTER_T *pAdapTemp;
|
|
|
|
|
|
|
|
for(i = 0; i < nMaxCount; i++)
|
|
|
|
pIds[i] = INVALID_DEVICEID;
|
|
|
|
|
|
|
|
/* append the arrays not registered on VBus */
|
|
|
|
for (pAdapTemp = gIal_Adapter; pAdapTemp; pAdapTemp = pAdapTemp->next) {
|
|
|
|
for(i = 0; i < MV_SATA_CHANNELS_NUM; i++)
|
|
|
|
{
|
|
|
|
pPhysical = &pAdapTemp->VDevices[i];
|
|
|
|
pLogical = pPhysical;
|
|
|
|
|
|
|
|
while (pLogical->pParent) pLogical = pLogical->pParent;
|
|
|
|
if (pLogical->VDeviceType==VD_SPARE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j=0; j<count; j++)
|
|
|
|
if (pIds[j]==VDEV_TO_ID(pLogical)) goto next;
|
|
|
|
pIds[count++] = VDEV_TO_ID(pLogical);
|
|
|
|
if (count>=nMaxCount) goto done;
|
|
|
|
next:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
int hpt_get_device_info(DEVICEID id, PLOGICAL_DEVICE_INFO pInfo)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
PVDevice pVDevice = ID_TO_VDEV(id);
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
if((id == 0) || check_VDevice_valid(pVDevice))
|
2004-10-24 05:37:23 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
#ifdef SUPPORT_ARRAY
|
2009-04-07 16:38:25 +00:00
|
|
|
if (mIsArray(pVDevice)) {
|
|
|
|
pInfo->Type = LDT_ARRAY;
|
|
|
|
pInfo->Capacity = pVDevice->VDeviceCapacity;
|
|
|
|
pInfo->ParentArray = VDEV_TO_ID(pVDevice->pParent);
|
|
|
|
get_array_info(pVDevice, &pInfo->u.array);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-10-24 05:37:23 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
pInfo->Type = LDT_DEVICE;
|
|
|
|
pInfo->ParentArray = pVDevice->pParent? VDEV_TO_ID(pVDevice->pParent) : INVALID_DEVICEID;
|
|
|
|
/* report real capacity to be compatible with old arrays */
|
|
|
|
pInfo->Capacity = pVDevice->u.disk.dDeRealCapacity;
|
|
|
|
return get_disk_info(pVDevice, &pInfo->u.device);
|
|
|
|
}
|
|
|
|
|
|
|
|
int hpt_get_device_info_v2(DEVICEID id, PLOGICAL_DEVICE_INFO_V2 pInfo)
|
|
|
|
{
|
|
|
|
PVDevice pVDevice = ID_TO_VDEV(id);
|
|
|
|
|
|
|
|
if((id == 0) || check_VDevice_valid(pVDevice))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
#ifdef SUPPORT_ARRAY
|
|
|
|
if (mIsArray(pVDevice)) {
|
|
|
|
pInfo->Type = LDT_ARRAY;
|
|
|
|
pInfo->Capacity.lo32 = pVDevice->VDeviceCapacity;
|
|
|
|
pInfo->Capacity.hi32 = sizeof(LBA_T)>4? (pVDevice->VDeviceCapacity>>32) : 0;
|
|
|
|
pInfo->ParentArray = VDEV_TO_ID(pVDevice->pParent);
|
|
|
|
get_array_info_v2(pVDevice, &pInfo->u.array);
|
2004-10-24 05:37:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-04-07 16:38:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
pInfo->Type = LDT_DEVICE;
|
|
|
|
pInfo->ParentArray = pVDevice->pParent? VDEV_TO_ID(pVDevice->pParent) : INVALID_DEVICEID;
|
|
|
|
/* report real capacity to be compatible with old arrays */
|
|
|
|
pInfo->Capacity.lo32 = pVDevice->u.disk.dDeRealCapacity;
|
|
|
|
pInfo->Capacity.hi32 = 0;
|
|
|
|
return get_disk_info(pVDevice, &pInfo->u.device);
|
|
|
|
}
|
2004-10-24 05:37:23 +00:00
|
|
|
|
|
|
|
#ifdef SUPPORT_ARRAY
|
2009-04-07 16:38:25 +00:00
|
|
|
DEVICEID hpt_create_array_v2(_VBUS_ARG PCREATE_ARRAY_PARAMS_V2 pParam)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
ULONG Stamp = GetStamp();
|
|
|
|
int i,j;
|
2009-04-07 16:38:25 +00:00
|
|
|
LBA_T capacity = MAX_LBA_T;
|
2004-10-24 05:37:23 +00:00
|
|
|
PVDevice pArray,pChild;
|
|
|
|
int Loca = -1;
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if (pParam->nDisk > MAX_MEMBERS)
|
|
|
|
return INVALID_DEVICEID;
|
|
|
|
/* check in verify_vd
|
2004-10-24 05:37:23 +00:00
|
|
|
for(i = 0; i < pParam->nDisk; i++)
|
|
|
|
{
|
|
|
|
PVDevice pVDev = ID_TO_VDEV(pParam->Members[i]);
|
|
|
|
if (check_VDevice_valid(pVDev)) return INVALID_DEVICEID;
|
|
|
|
if (mIsArray(pVDev)) return INVALID_DEVICEID;
|
|
|
|
if (!pVDev->vf_online) return INVALID_DEVICEID;
|
|
|
|
if (!_vbus_p)
|
|
|
|
_vbus_p = pVDev->u.disk.pVBus;
|
|
|
|
else if (_vbus_p != pVDev->u.disk.pVBus)
|
|
|
|
return INVALID_DEVICEID;
|
|
|
|
}
|
2009-04-07 16:38:25 +00:00
|
|
|
*/
|
|
|
|
_vbus_p = (ID_TO_VDEV(pParam->Members[0]))->u.disk.pVBus;
|
2004-10-24 05:37:23 +00:00
|
|
|
if (!_vbus_p) return INVALID_DEVICEID;
|
|
|
|
|
|
|
|
mArGetArrayTable(pArray);
|
|
|
|
if(!pArray) return INVALID_DEVICEID;
|
|
|
|
|
|
|
|
switch (pParam->ArrayType)
|
|
|
|
{
|
|
|
|
case AT_JBOD:
|
|
|
|
pArray->VDeviceType = VD_JBOD;
|
|
|
|
goto simple;
|
|
|
|
|
|
|
|
case AT_RAID0:
|
|
|
|
if((pParam->BlockSizeShift < MinBlockSizeShift) || (pParam->BlockSizeShift > MaxBlockSizeShift))
|
|
|
|
goto error;
|
|
|
|
pArray->VDeviceType = VD_RAID_0;
|
|
|
|
goto simple;
|
|
|
|
|
|
|
|
case AT_RAID5:
|
|
|
|
if((pParam->BlockSizeShift < MinBlockSizeShift) || (pParam->BlockSizeShift > MaxBlockSizeShift))
|
|
|
|
goto error;
|
|
|
|
pArray->VDeviceType = VD_RAID_5;
|
|
|
|
/* only "no build" R5 is not critical after creation. */
|
|
|
|
if ((pParam->CreateFlags & CAF_CREATE_R5_NO_BUILD)==0)
|
|
|
|
pArray->u.array.rf_need_rebuild = 1;
|
|
|
|
goto simple;
|
|
|
|
|
|
|
|
case AT_RAID1:
|
|
|
|
if(pParam->nDisk <= 2)
|
|
|
|
{
|
|
|
|
pArray->VDeviceType = VD_RAID_1;
|
|
|
|
simple:
|
|
|
|
pArray->u.array.bArnMember = pParam->nDisk;
|
|
|
|
pArray->u.array.bArRealnMember = pParam->nDisk;
|
|
|
|
pArray->u.array.bArBlockSizeShift = pParam->BlockSizeShift;
|
|
|
|
pArray->u.array.bStripeWitch = (1 << pParam->BlockSizeShift);
|
|
|
|
pArray->u.array.dArStamp = Stamp;
|
|
|
|
|
|
|
|
pArray->u.array.rf_need_sync = 1;
|
|
|
|
pArray->u.array.rf_newly_created = 1;
|
|
|
|
|
|
|
|
if ((pParam->CreateFlags & CAF_CREATE_AND_DUPLICATE) &&
|
|
|
|
(pArray->VDeviceType == VD_RAID_1))
|
|
|
|
{
|
|
|
|
pArray->u.array.rf_newly_created = 0; /* R1 shall still be accessible */
|
|
|
|
pArray->u.array.rf_need_rebuild = 1;
|
|
|
|
pArray->u.array.rf_auto_rebuild = 1;
|
|
|
|
pArray->u.array.rf_duplicate_and_create = 1;
|
|
|
|
|
|
|
|
for(i = 0; i < MAX_VDEVICE_PER_VBUS; i++)
|
|
|
|
if (_vbus_p->pVDevice[i] == ID_TO_VDEV(pParam->Members[0]))
|
|
|
|
Loca = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
pArray->u.array.RebuildSectors = pArray->u.array.rf_need_rebuild? 0 : MAX_LBA_T;
|
|
|
|
|
|
|
|
memcpy(pArray->u.array.ArrayName, pParam->ArrayName, MAX_ARRAY_NAME);
|
|
|
|
|
|
|
|
for(i = 0; i < pParam->nDisk; i++)
|
|
|
|
{
|
|
|
|
pArray->u.array.pMember[i] = ID_TO_VDEV(pParam->Members[i]);
|
|
|
|
pArray->u.array.pMember[i]->bSerialNumber = i;
|
|
|
|
pArray->u.array.pMember[i]->pParent = pArray;
|
|
|
|
|
|
|
|
/* don't unregister source disk for duplicate RAID1 */
|
|
|
|
if (i ||
|
|
|
|
pArray->VDeviceType!=VD_RAID_1 ||
|
|
|
|
(pParam->CreateFlags & CAF_CREATE_AND_DUPLICATE)==0)
|
|
|
|
UnregisterVDevice(pArray->u.array.pMember[i]);
|
|
|
|
|
|
|
|
if(pArray->VDeviceType == VD_RAID_5)
|
|
|
|
pArray->u.array.pMember[i]->vf_cache_disk = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(i = 0; i < (pParam->nDisk / 2); i++)
|
|
|
|
{
|
|
|
|
mArGetArrayTable(pChild);
|
|
|
|
pChild->VDeviceType = VD_RAID_1;
|
|
|
|
|
|
|
|
pChild->u.array.bArnMember = 2;
|
|
|
|
pChild->u.array.bArRealnMember = 2;
|
|
|
|
pChild->u.array.bArBlockSizeShift = pParam->BlockSizeShift;
|
|
|
|
pChild->u.array.bStripeWitch = (1 << pParam->BlockSizeShift);
|
|
|
|
pChild->u.array.dArStamp = Stamp;
|
|
|
|
|
|
|
|
pChild->u.array.rf_need_sync = 1;
|
|
|
|
pChild->u.array.rf_newly_created = 1;
|
|
|
|
|
|
|
|
pChild->u.array.RebuildSectors = MAX_LBA_T;
|
|
|
|
|
|
|
|
memcpy(pChild->u.array.ArrayName, pParam->ArrayName, MAX_ARRAY_NAME);
|
|
|
|
|
|
|
|
for(j = 0; j < 2; j++)
|
|
|
|
{
|
|
|
|
pChild->u.array.pMember[j] = ID_TO_VDEV(pParam->Members[i*2 + j]);
|
|
|
|
pChild->u.array.pMember[j]->bSerialNumber = j;
|
|
|
|
pChild->u.array.pMember[j]->pParent = pChild;
|
|
|
|
pChild->u.array.pMember[j]->pfnDeviceFailed = pfnDeviceFailed[pChild->VDeviceType];
|
|
|
|
UnregisterVDevice(pChild->u.array.pMember[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pArray->u.array.pMember[i] = pChild;
|
|
|
|
|
|
|
|
pChild->vf_online = 1;
|
|
|
|
pChild->bSerialNumber = i;
|
|
|
|
pChild->pParent = pArray;
|
|
|
|
pChild->VDeviceCapacity = MIN(pChild->u.array.pMember[0]->VDeviceCapacity,
|
|
|
|
pChild->u.array.pMember[1]->VDeviceCapacity);
|
|
|
|
|
|
|
|
pChild->pfnSendCommand = pfnSendCommand[pChild->VDeviceType];
|
|
|
|
pChild->pfnDeviceFailed = pfnDeviceFailed[VD_RAID_0];
|
|
|
|
}
|
|
|
|
|
|
|
|
pArray->VDeviceType = VD_RAID_0;
|
|
|
|
|
|
|
|
pArray->u.array.bArnMember = pParam->nDisk / 2;
|
|
|
|
pArray->u.array.bArRealnMember = pParam->nDisk / 2;
|
|
|
|
pArray->u.array.bArBlockSizeShift = pParam->BlockSizeShift;
|
|
|
|
pArray->u.array.bStripeWitch = (1 << pParam->BlockSizeShift);
|
|
|
|
pArray->u.array.dArStamp = Stamp;
|
|
|
|
|
|
|
|
pArray->u.array.rf_need_sync = 1;
|
|
|
|
pArray->u.array.rf_newly_created = 1;
|
|
|
|
|
|
|
|
memcpy(pArray->u.array.ArrayName, pParam->ArrayName, MAX_ARRAY_NAME);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < pArray->u.array.bArnMember; i++)
|
|
|
|
pArray->u.array.pMember[i]->pfnDeviceFailed = pfnDeviceFailed[pArray->VDeviceType];
|
|
|
|
|
|
|
|
if ((pParam->CreateFlags & CAF_CREATE_AND_DUPLICATE) &&
|
|
|
|
(pArray->VDeviceType == VD_RAID_1))
|
|
|
|
{
|
|
|
|
pArray->vf_bootmark = pArray->u.array.pMember[0]->vf_bootmark;
|
|
|
|
pArray->vf_bootable = pArray->u.array.pMember[0]->vf_bootable;
|
|
|
|
pArray->u.array.pMember[0]->vf_bootable = 0;
|
|
|
|
pArray->u.array.pMember[0]->vf_bootmark = 0;
|
|
|
|
if (Loca>=0) {
|
|
|
|
_vbus_p->pVDevice[Loca] = pArray;
|
|
|
|
/* to comfort OS */
|
|
|
|
pArray->u.array.rf_duplicate_and_created = 1;
|
|
|
|
pArray->pVBus = _vbus_p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UCHAR TempBuffer[512];
|
|
|
|
ZeroMemory(TempBuffer, 512);
|
|
|
|
for(i = 0; i < pParam->nDisk; i++)
|
|
|
|
{
|
|
|
|
PVDevice pDisk = ID_TO_VDEV(pParam->Members[i]);
|
|
|
|
pDisk->vf_bootmark = pDisk->vf_bootable = 0;
|
|
|
|
fDeReadWrite(&pDisk->u.disk, 0, IDE_COMMAND_WRITE, TempBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pArray->vf_online = 1;
|
|
|
|
pArray->pParent = NULL;
|
|
|
|
|
|
|
|
switch(pArray->VDeviceType)
|
|
|
|
{
|
|
|
|
case VD_RAID_0:
|
|
|
|
for(i = 0; i < pArray->u.array.bArnMember; i++)
|
|
|
|
if(pArray->u.array.pMember[i]->VDeviceCapacity < capacity)
|
|
|
|
capacity = pArray->u.array.pMember[i]->VDeviceCapacity;
|
|
|
|
#ifdef ARRAY_V2_ONLY
|
|
|
|
capacity -= 10;
|
|
|
|
#endif
|
|
|
|
capacity &= ~(pArray->u.array.bStripeWitch - 1);
|
|
|
|
/* shrink member capacity for RAID 1/0 */
|
|
|
|
for(i = 0; i < pArray->u.array.bArnMember; i++)
|
|
|
|
if (mIsArray(pArray->u.array.pMember[i]))
|
|
|
|
pArray->u.array.pMember[i]->VDeviceCapacity = capacity;
|
|
|
|
pArray->VDeviceCapacity = capacity * pArray->u.array.bArnMember;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VD_RAID_1:
|
|
|
|
pArray->VDeviceCapacity = MIN(pArray->u.array.pMember[0]->VDeviceCapacity,
|
|
|
|
pArray->u.array.pMember[1]->VDeviceCapacity);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VD_JBOD:
|
|
|
|
for(i = 0; i < pArray->u.array.bArnMember; i++)
|
|
|
|
pArray->VDeviceCapacity += pArray->u.array.pMember[i]->VDeviceCapacity
|
|
|
|
#ifdef ARRAY_V2_ONLY
|
|
|
|
-10
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VD_RAID_5:
|
|
|
|
for(i = 0; i < pArray->u.array.bArnMember; i++)
|
|
|
|
if(pArray->u.array.pMember[i]->VDeviceCapacity < capacity)
|
|
|
|
capacity = pArray->u.array.pMember[i]->VDeviceCapacity;
|
|
|
|
pArray->VDeviceCapacity = (capacity & ~(pArray->u.array.bStripeWitch - 1))
|
|
|
|
* (pArray->u.array.bArnMember - 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
pArray->pfnSendCommand = pfnSendCommand[pArray->VDeviceType];
|
|
|
|
pArray->pfnDeviceFailed = fOsDiskFailed;
|
|
|
|
SyncArrayInfo(pArray);
|
|
|
|
|
|
|
|
if (!pArray->u.array.rf_duplicate_and_created)
|
|
|
|
RegisterVDevice(pArray);
|
|
|
|
return VDEV_TO_ID(pArray);
|
|
|
|
|
|
|
|
error:
|
|
|
|
for(i = 0; i < pArray->u.array.bArnMember; i++)
|
|
|
|
{
|
|
|
|
pChild = pArray->u.array.pMember[i];
|
|
|
|
if((pChild != NULL) && (pChild->VDeviceType != VD_SINGLE_DISK))
|
|
|
|
mArFreeArrayTable(pChild);
|
|
|
|
}
|
|
|
|
mArFreeArrayTable(pArray);
|
|
|
|
return INVALID_DEVICEID;
|
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
DEVICEID hpt_create_array(_VBUS_ARG PCREATE_ARRAY_PARAMS pParam)
|
|
|
|
{
|
|
|
|
CREATE_ARRAY_PARAMS_V2 param2;
|
|
|
|
param2.ArrayType = pParam->ArrayType;
|
|
|
|
param2.nDisk = pParam->nDisk;
|
|
|
|
param2.BlockSizeShift = pParam->BlockSizeShift;
|
|
|
|
param2.CreateFlags = pParam->CreateFlags;
|
|
|
|
param2.CreateTime = pParam->CreateTime;
|
|
|
|
memcpy(param2.ArrayName, pParam->ArrayName, sizeof(param2.ArrayName));
|
|
|
|
memcpy(param2.Description, pParam->Description, sizeof(param2.Description));
|
|
|
|
memcpy(param2.CreateManager, pParam->CreateManager, sizeof(param2.CreateManager));
|
|
|
|
param2.Capacity.lo32 = param2.Capacity.hi32 = 0;
|
|
|
|
memcpy(param2.Members, pParam->Members, sizeof(pParam->Members));
|
|
|
|
return hpt_create_array_v2(_VBUS_P ¶m2);
|
|
|
|
}
|
|
|
|
|
2004-10-24 05:37:23 +00:00
|
|
|
#ifdef SUPPORT_OLD_ARRAY
|
|
|
|
/* this is only for old RAID 0/1 */
|
|
|
|
int old_add_disk_to_raid01(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk)
|
|
|
|
{
|
|
|
|
PVDevice pArray1 = ID_TO_VDEV(idArray);
|
|
|
|
PVDevice pArray2 = 0;
|
|
|
|
PVDevice pDisk = ID_TO_VDEV(idDisk);
|
|
|
|
int i;
|
|
|
|
IAL_ADAPTER_T *pAdapter = gIal_Adapter;
|
|
|
|
|
|
|
|
if (pArray1->pVBus!=_vbus_p) { HPT_ASSERT(0); return -1;}
|
|
|
|
|
|
|
|
if(pDisk->u.disk.dDeRealCapacity < (pArray1->VDeviceCapacity / 2))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
pArray2 = pArray1->u.array.pMember[1];
|
|
|
|
if(pArray2 == NULL) {
|
|
|
|
/* create a Stripe */
|
|
|
|
mArGetArrayTable(pArray2);
|
|
|
|
pArray2->VDeviceType = VD_RAID_0;
|
|
|
|
pArray2->u.array.dArStamp = GetStamp();
|
|
|
|
pArray2->vf_format_v2 = 1;
|
|
|
|
pArray2->u.array.rf_broken = 1;
|
|
|
|
pArray2->u.array.bArBlockSizeShift = pArray1->u.array.bArBlockSizeShift;
|
|
|
|
pArray2->u.array.bStripeWitch = (1 << pArray2->u.array.bArBlockSizeShift);
|
|
|
|
pArray2->u.array.bArnMember = 2;
|
|
|
|
pArray2->VDeviceCapacity = pArray1->VDeviceCapacity;
|
|
|
|
pArray2->pfnSendCommand = pfnSendCommand[pArray2->VDeviceType];
|
|
|
|
pArray2->pfnDeviceFailed = pfnDeviceFailed[pArray1->VDeviceType];
|
|
|
|
memcpy(pArray2->u.array.ArrayName, pArray1->u.array.ArrayName, MAX_ARRAY_NAME);
|
|
|
|
pArray2->pParent = pArray1;
|
|
|
|
pArray2->bSerialNumber = 1;
|
|
|
|
pArray1->u.array.pMember[1] = pArray2;
|
|
|
|
pArray1->u.array.bArRealnMember++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < pArray2->u.array.bArnMember; i++)
|
|
|
|
if((pArray2->u.array.pMember[i] == NULL) || !pArray2->u.array.pMember[i]->vf_online)
|
|
|
|
{
|
|
|
|
if(pArray2->u.array.pMember[i] != NULL)
|
|
|
|
pArray2->u.array.pMember[i]->pParent = NULL;
|
|
|
|
pArray2->u.array.pMember[i] = pDisk;
|
|
|
|
goto find;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
find:
|
|
|
|
UnregisterVDevice(pDisk);
|
|
|
|
pDisk->VDeviceType = VD_SINGLE_DISK;
|
|
|
|
pDisk->bSerialNumber = i;
|
|
|
|
pDisk->pParent = pArray2;
|
|
|
|
pDisk->vf_format_v2 = 1;
|
|
|
|
pDisk->u.disk.dDeHiddenLba = i? 10 : 0;
|
|
|
|
pDisk->VDeviceCapacity = pDisk->u.disk.dDeRealCapacity;
|
|
|
|
pDisk->pfnDeviceFailed = pfnDeviceFailed[pArray2->VDeviceType];
|
|
|
|
|
|
|
|
pArray2->u.array.bArRealnMember++;
|
|
|
|
if(pArray2->u.array.bArnMember == pArray2->u.array.bArRealnMember){
|
|
|
|
pArray2->vf_online = 1;
|
|
|
|
pArray2->u.array.rf_broken = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pArray1->u.array.pMember[0]->vf_online && pArray1->u.array.pMember[1]->vf_online){
|
|
|
|
pArray1->u.array.bArRealnMember = pArray1->u.array.bArnMember;
|
|
|
|
pArray1->u.array.rf_broken = 0;
|
|
|
|
pArray1->u.array.rf_need_rebuild = 1;
|
|
|
|
pArray1->u.array.rf_auto_rebuild = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
pArray1->u.array.RebuildSectors = 0;
|
|
|
|
pArray1->u.array.dArStamp = GetStamp();
|
|
|
|
SyncArrayInfo(pArray1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int hpt_add_disk_to_array(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
LBA_T Capacity;
|
2004-10-24 05:37:23 +00:00
|
|
|
PVDevice pArray = ID_TO_VDEV(idArray);
|
|
|
|
PVDevice pDisk = ID_TO_VDEV(idDisk);
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
if((idArray == 0) || (idDisk == 0)) return -1;
|
2004-10-24 05:37:23 +00:00
|
|
|
if(check_VDevice_valid(pArray) || check_VDevice_valid(pDisk)) return -1;
|
|
|
|
if(!pArray->u.array.rf_broken) return -1;
|
|
|
|
|
|
|
|
if(pArray->VDeviceType != VD_RAID_1 && pArray->VDeviceType != VD_RAID_5)
|
|
|
|
return -1;
|
|
|
|
if((pDisk->VDeviceType != VD_SINGLE_DISK) && (pDisk->VDeviceType != VD_SPARE))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
#ifdef SUPPORT_OLD_ARRAY
|
|
|
|
/* RAID 0 + 1 */
|
|
|
|
if (pArray->vf_format_v2 && pArray->VDeviceType==VD_RAID_1 &&
|
|
|
|
pArray->u.array.pMember[0] &&
|
|
|
|
mIsArray(pArray->u.array.pMember[0]))
|
|
|
|
{
|
|
|
|
if(old_add_disk_to_raid01(_VBUS_P idArray, idDisk))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Capacity = pArray->VDeviceCapacity / (pArray->u.array.bArnMember - 1);
|
|
|
|
|
|
|
|
if (pArray->vf_format_v2) {
|
|
|
|
if(pDisk->u.disk.dDeRealCapacity < Capacity) return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if(pDisk->VDeviceCapacity < Capacity) return -1;
|
|
|
|
|
|
|
|
if (pArray->pVBus!=_vbus_p) { HPT_ASSERT(0); return -1;}
|
|
|
|
|
|
|
|
for(i = 0; i < pArray->u.array.bArnMember; i++)
|
2009-04-07 16:38:25 +00:00
|
|
|
if((pArray->u.array.pMember[i] == 0) || !pArray->u.array.pMember[i]->vf_online)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
if(pArray->u.array.pMember[i] != NULL)
|
|
|
|
pArray->u.array.pMember[i]->pParent = NULL;
|
|
|
|
pArray->u.array.pMember[i] = pDisk;
|
|
|
|
goto find;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
find:
|
|
|
|
UnregisterVDevice(pDisk);
|
|
|
|
pDisk->VDeviceType = VD_SINGLE_DISK;
|
|
|
|
pDisk->bSerialNumber = i;
|
|
|
|
pDisk->pParent = pArray;
|
|
|
|
if (pArray->VDeviceType==VD_RAID_5) pDisk->vf_cache_disk = 1;
|
|
|
|
pDisk->pfnDeviceFailed = pfnDeviceFailed[pArray->VDeviceType];
|
|
|
|
if (pArray->vf_format_v2) {
|
|
|
|
pDisk->vf_format_v2 = 1;
|
|
|
|
pDisk->VDeviceCapacity = pDisk->u.disk.dDeRealCapacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
pArray->u.array.bArRealnMember++;
|
|
|
|
if(pArray->u.array.bArnMember == pArray->u.array.bArRealnMember)
|
|
|
|
{
|
|
|
|
pArray->u.array.rf_need_rebuild = 1;
|
|
|
|
pArray->u.array.RebuildSectors = 0;
|
|
|
|
pArray->u.array.rf_auto_rebuild = 1;
|
|
|
|
pArray->u.array.rf_broken = 0;
|
|
|
|
}
|
|
|
|
pArray->u.array.RebuildSectors = 0;
|
|
|
|
|
|
|
|
/* sync the whole array */
|
|
|
|
while (pArray->pParent) pArray = pArray->pParent;
|
|
|
|
pArray->u.array.dArStamp = GetStamp();
|
|
|
|
SyncArrayInfo(pArray);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
int hpt_add_spare_disk(_VBUS_ARG DEVICEID idDisk)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
PVDevice pVDevice = ID_TO_VDEV(idDisk);
|
|
|
|
DECLARE_BUFFER(PUCHAR, pbuffer);
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
if(idDisk == 0 || check_VDevice_valid(pVDevice)) return -1;
|
2004-10-24 05:37:23 +00:00
|
|
|
if (pVDevice->VDeviceType != VD_SINGLE_DISK || pVDevice->pParent)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (pVDevice->u.disk.pVBus!=_vbus_p) return -1;
|
|
|
|
|
|
|
|
UnregisterVDevice(pVDevice);
|
|
|
|
pVDevice->VDeviceType = VD_SPARE;
|
|
|
|
pVDevice->vf_bootmark = 0;
|
|
|
|
|
|
|
|
ZeroMemory((char *)pbuffer, 512);
|
|
|
|
fDeReadWrite(&pVDevice->u.disk, 0, IDE_COMMAND_WRITE, pbuffer);
|
|
|
|
SyncArrayInfo(pVDevice);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
int hpt_remove_spare_disk(_VBUS_ARG DEVICEID idDisk)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
PVDevice pVDevice = ID_TO_VDEV(idDisk);
|
|
|
|
|
|
|
|
if(idDisk == 0 || check_VDevice_valid(pVDevice)) return -1;
|
|
|
|
|
|
|
|
if (pVDevice->u.disk.pVBus!=_vbus_p) return -1;
|
|
|
|
|
|
|
|
pVDevice->VDeviceType = VD_SINGLE_DISK;
|
|
|
|
|
|
|
|
SyncArrayInfo(pVDevice);
|
|
|
|
RegisterVDevice(pVDevice);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
int hpt_set_array_info(_VBUS_ARG DEVICEID idArray, PALTERABLE_ARRAY_INFO pInfo)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
PVDevice pVDevice = ID_TO_VDEV(idArray);
|
|
|
|
|
2005-09-07 23:33:26 +00:00
|
|
|
if(idArray == 0 || check_VDevice_valid(pVDevice)) return -1;
|
2004-10-24 05:37:23 +00:00
|
|
|
if (!mIsArray(pVDevice)) return -1;
|
|
|
|
|
|
|
|
/* if the pVDevice isn't a top level, return -1; */
|
|
|
|
if(pVDevice->pParent != NULL) return -1;
|
|
|
|
|
|
|
|
if (pVDevice->pVBus!=_vbus_p) { HPT_ASSERT(0); return -1;}
|
|
|
|
|
|
|
|
if (pInfo->ValidFields & AAIF_NAME) {
|
|
|
|
memset(pVDevice->u.array.ArrayName, 0, MAX_ARRAY_NAME);
|
|
|
|
memcpy(pVDevice->u.array.ArrayName, pInfo->Name, sizeof(pInfo->Name));
|
|
|
|
pVDevice->u.array.rf_need_sync = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pInfo->ValidFields & AAIF_DESCRIPTION) {
|
|
|
|
memcpy(pVDevice->u.array.Description, pInfo->Description, sizeof(pInfo->Description));
|
|
|
|
pVDevice->u.array.rf_need_sync = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pVDevice->u.array.rf_need_sync)
|
|
|
|
SyncArrayInfo(pVDevice);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
static int hpt_set_device_info(_VBUS_ARG DEVICEID idDisk, PALTERABLE_DEVICE_INFO pInfo)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
PVDevice pVDevice = ID_TO_VDEV(idDisk);
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if(idDisk == 0 || check_VDevice_valid(pVDevice)) return -1;
|
|
|
|
if (mIsArray(pVDevice))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (pVDevice->u.disk.pVBus!=_vbus_p) return -1;
|
|
|
|
|
|
|
|
/* TODO */
|
2004-10-24 05:37:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
static int hpt_set_device_info_v2(_VBUS_ARG DEVICEID idDisk, PALTERABLE_DEVICE_INFO_V2 pInfo)
|
|
|
|
{
|
|
|
|
PVDevice pVDevice = ID_TO_VDEV(idDisk);
|
|
|
|
int sync = 0;
|
|
|
|
|
|
|
|
if(idDisk==0 || check_VDevice_valid(pVDevice)) return -1;
|
2004-10-24 05:37:23 +00:00
|
|
|
if (mIsArray(pVDevice))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (pVDevice->u.disk.pVBus!=_vbus_p) return -1;
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if (pInfo->ValidFields & ADIF_MODE) {
|
2004-10-24 05:37:23 +00:00
|
|
|
pVDevice->u.disk.bDeModeSetting = pInfo->DeviceModeSetting;
|
|
|
|
pVDevice->u.disk.bDeUserSelectMode = pInfo->DeviceModeSetting;
|
|
|
|
pVDevice->u.disk.df_user_mode_set = 1;
|
|
|
|
fDeSelectMode((PDevice)&(pVDevice->u.disk), (UCHAR)pInfo->DeviceModeSetting);
|
2009-04-07 16:38:25 +00:00
|
|
|
sync = 1;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if (pInfo->ValidFields & ADIF_TCQ) {
|
|
|
|
if (fDeSetTCQ(&pVDevice->u.disk, pInfo->TCQEnabled, 0)) {
|
|
|
|
pVDevice->u.disk.df_tcq_set = 1;
|
|
|
|
pVDevice->u.disk.df_tcq = pInfo->TCQEnabled!=0;
|
|
|
|
sync = 1;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if (pInfo->ValidFields & ADIF_NCQ) {
|
|
|
|
if (fDeSetNCQ(&pVDevice->u.disk, pInfo->NCQEnabled, 0)) {
|
|
|
|
pVDevice->u.disk.df_ncq_set = 1;
|
|
|
|
pVDevice->u.disk.df_ncq = pInfo->NCQEnabled!=0;
|
|
|
|
sync = 1;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if (pInfo->ValidFields & ADIF_WRITE_CACHE) {
|
|
|
|
if (fDeSetWriteCache(&pVDevice->u.disk, pInfo->WriteCacheEnabled)) {
|
|
|
|
pVDevice->u.disk.df_write_cache_set = 1;
|
|
|
|
pVDevice->u.disk.df_write_cache = pInfo->WriteCacheEnabled!=0;
|
|
|
|
sync = 1;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if (pInfo->ValidFields & ADIF_READ_AHEAD) {
|
|
|
|
if (fDeSetReadAhead(&pVDevice->u.disk, pInfo->ReadAheadEnabled)) {
|
|
|
|
pVDevice->u.disk.df_read_ahead_set = 1;
|
|
|
|
pVDevice->u.disk.df_read_ahead = pInfo->ReadAheadEnabled!=0;
|
|
|
|
sync = 1;
|
|
|
|
}
|
|
|
|
}
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if (sync)
|
|
|
|
SyncArrayInfo(pVDevice);
|
2004-10-24 05:37:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-04-07 16:38:25 +00:00
|
|
|
|
2004-10-24 05:37:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* hpt_default_ioctl()
|
|
|
|
* This is a default implementation. The platform dependent part
|
|
|
|
* may reuse this function and/or use it own implementation for
|
|
|
|
* each ioctl function.
|
|
|
|
*/
|
|
|
|
int hpt_default_ioctl(_VBUS_ARG
|
|
|
|
DWORD dwIoControlCode, /* operation control code */
|
|
|
|
PVOID lpInBuffer, /* input data buffer */
|
|
|
|
DWORD nInBufferSize, /* size of input data buffer */
|
|
|
|
PVOID lpOutBuffer, /* output data buffer */
|
|
|
|
DWORD nOutBufferSize, /* size of output data buffer */
|
|
|
|
PDWORD lpBytesReturned /* byte count */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
switch(dwIoControlCode) {
|
|
|
|
|
|
|
|
case HPT_IOCTL_GET_VERSION:
|
|
|
|
|
|
|
|
if (nInBufferSize != 0) return -1;
|
|
|
|
if (nOutBufferSize != sizeof(DWORD)) return -1;
|
|
|
|
*((DWORD*)lpOutBuffer) = HPT_INTERFACE_VERSION;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_GET_CONTROLLER_COUNT:
|
|
|
|
|
|
|
|
if (nOutBufferSize!=sizeof(DWORD)) return -1;
|
|
|
|
*(PDWORD)lpOutBuffer = hpt_get_controller_count();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_GET_CONTROLLER_INFO:
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
PCONTROLLER_INFO pInfo;
|
|
|
|
|
|
|
|
if (nInBufferSize!=sizeof(DWORD)) return -1;
|
|
|
|
if (nOutBufferSize!=sizeof(CONTROLLER_INFO)) return -1;
|
|
|
|
|
|
|
|
id = *(DWORD *)lpInBuffer;
|
|
|
|
pInfo = (PCONTROLLER_INFO)lpOutBuffer;
|
|
|
|
if (hpt_get_controller_info(id, pInfo)!=0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_GET_CHANNEL_INFO:
|
|
|
|
{
|
|
|
|
int id, bus;
|
|
|
|
PCHANNEL_INFO pInfo;
|
|
|
|
|
|
|
|
if (nInBufferSize!=8) return -1;
|
|
|
|
if (nOutBufferSize!=sizeof(CHANNEL_INFO)) return -1;
|
|
|
|
|
|
|
|
id = *(DWORD *)lpInBuffer;
|
|
|
|
bus = ((DWORD *)lpInBuffer)[1];
|
|
|
|
pInfo = (PCHANNEL_INFO)lpOutBuffer;
|
|
|
|
|
|
|
|
if (hpt_get_channel_info(id, bus, pInfo)!=0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_GET_LOGICAL_DEVICES:
|
|
|
|
{
|
|
|
|
DWORD nMax;
|
|
|
|
DEVICEID *pIds;
|
|
|
|
|
|
|
|
if (nInBufferSize!=sizeof(DWORD)) return -1;
|
|
|
|
nMax = *(DWORD *)lpInBuffer;
|
|
|
|
if (nOutBufferSize < sizeof(DWORD)+sizeof(DWORD)*nMax) return -1;
|
|
|
|
|
|
|
|
pIds = ((DEVICEID *)lpOutBuffer)+1;
|
|
|
|
*(DWORD*)lpOutBuffer = hpt_get_logical_devices(pIds, nMax);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_GET_DEVICE_INFO:
|
|
|
|
{
|
|
|
|
DEVICEID id;
|
|
|
|
PLOGICAL_DEVICE_INFO pInfo;
|
|
|
|
|
|
|
|
if (nInBufferSize!=sizeof(DEVICEID)) return -1;
|
|
|
|
if (nOutBufferSize!=sizeof(LOGICAL_DEVICE_INFO)) return -1;
|
|
|
|
|
|
|
|
id = *(DWORD *)lpInBuffer;
|
|
|
|
if (id == INVALID_DEVICEID) return -1;
|
|
|
|
|
|
|
|
pInfo = (PLOGICAL_DEVICE_INFO)lpOutBuffer;
|
|
|
|
memset(pInfo, 0, sizeof(LOGICAL_DEVICE_INFO));
|
|
|
|
|
|
|
|
if (hpt_get_device_info(id, pInfo)!=0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
case HPT_IOCTL_GET_DEVICE_INFO_V2:
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
DEVICEID id;
|
2009-04-07 16:38:25 +00:00
|
|
|
PLOGICAL_DEVICE_INFO_V2 pInfo;
|
|
|
|
|
|
|
|
if (nInBufferSize!=sizeof(DEVICEID)) return -1;
|
|
|
|
if (nOutBufferSize!=sizeof(LOGICAL_DEVICE_INFO_V2)) return -1;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
id = *(DWORD *)lpInBuffer;
|
|
|
|
if (id == INVALID_DEVICEID) return -1;
|
|
|
|
|
|
|
|
pInfo = (PLOGICAL_DEVICE_INFO_V2)lpOutBuffer;
|
|
|
|
memset(pInfo, 0, sizeof(LOGICAL_DEVICE_INFO_V2));
|
|
|
|
|
|
|
|
if (hpt_get_device_info_v2(id, pInfo)!=0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef SUPPORT_ARRAY
|
|
|
|
case HPT_IOCTL_CREATE_ARRAY:
|
|
|
|
{
|
2004-10-24 05:37:23 +00:00
|
|
|
if (nInBufferSize!=sizeof(CREATE_ARRAY_PARAMS)) return -1;
|
|
|
|
if (nOutBufferSize!=sizeof(DEVICEID)) return -1;
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
*(DEVICEID *)lpOutBuffer = hpt_create_array(_VBUS_P (PCREATE_ARRAY_PARAMS)lpInBuffer);
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if(*(DEVICEID *)lpOutBuffer == INVALID_DEVICEID)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_CREATE_ARRAY_V2:
|
|
|
|
{
|
|
|
|
if (nInBufferSize!=sizeof(CREATE_ARRAY_PARAMS_V2)) return -1;
|
|
|
|
if (nOutBufferSize!=sizeof(DEVICEID)) return -1;
|
|
|
|
|
|
|
|
*(DEVICEID *)lpOutBuffer = hpt_create_array_v2(_VBUS_P (PCREATE_ARRAY_PARAMS_V2)lpInBuffer);
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if (*(DEVICEID *)lpOutBuffer == INVALID_DEVICEID)
|
2004-10-24 05:37:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_SET_ARRAY_INFO:
|
|
|
|
{
|
|
|
|
DEVICEID idArray;
|
|
|
|
PALTERABLE_ARRAY_INFO pInfo;
|
|
|
|
|
|
|
|
if (nInBufferSize!=sizeof(HPT_SET_ARRAY_INFO)) return -1;
|
|
|
|
if (nOutBufferSize!=0) return -1;
|
|
|
|
|
|
|
|
idArray = ((PHPT_SET_ARRAY_INFO)lpInBuffer)->idArray;
|
|
|
|
pInfo = &((PHPT_SET_ARRAY_INFO)lpInBuffer)->Info;
|
|
|
|
|
|
|
|
if(hpt_set_array_info(_VBUS_P idArray, pInfo))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_SET_DEVICE_INFO:
|
|
|
|
{
|
|
|
|
DEVICEID idDisk;
|
|
|
|
PALTERABLE_DEVICE_INFO pInfo;
|
|
|
|
|
|
|
|
if (nInBufferSize!=sizeof(HPT_SET_DEVICE_INFO)) return -1;
|
|
|
|
if (nOutBufferSize!=0) return -1;
|
|
|
|
|
|
|
|
idDisk = ((PHPT_SET_DEVICE_INFO)lpInBuffer)->idDisk;
|
|
|
|
pInfo = &((PHPT_SET_DEVICE_INFO)lpInBuffer)->Info;
|
|
|
|
if(hpt_set_device_info(_VBUS_P idDisk, pInfo) != 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
case HPT_IOCTL_SET_DEVICE_INFO_V2:
|
|
|
|
{
|
|
|
|
DEVICEID idDisk;
|
|
|
|
PALTERABLE_DEVICE_INFO_V2 pInfo;
|
|
|
|
|
|
|
|
if (nInBufferSize < sizeof(HPT_SET_DEVICE_INFO_V2)) return -1;
|
|
|
|
if (nOutBufferSize!=0) return -1;
|
|
|
|
|
|
|
|
idDisk = ((PHPT_SET_DEVICE_INFO_V2)lpInBuffer)->idDisk;
|
|
|
|
pInfo = &((PHPT_SET_DEVICE_INFO_V2)lpInBuffer)->Info;
|
|
|
|
if(hpt_set_device_info_v2(_VBUS_P idDisk, pInfo) != 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-10-24 05:37:23 +00:00
|
|
|
case HPT_IOCTL_SET_BOOT_MARK:
|
|
|
|
{
|
|
|
|
DEVICEID id;
|
|
|
|
PVDevice pTop;
|
|
|
|
int i;
|
|
|
|
IAL_ADAPTER_T *pAdapter = gIal_Adapter;
|
|
|
|
PVBus pVBus;
|
|
|
|
|
|
|
|
if (nInBufferSize!=sizeof(DEVICEID)) return -1;
|
|
|
|
id = *(DEVICEID *)lpInBuffer;
|
|
|
|
while(pAdapter != 0)
|
|
|
|
{
|
|
|
|
pVBus = &pAdapter->VBus;
|
2009-04-07 16:38:25 +00:00
|
|
|
for(i = 0; i < MAX_VDEVICE_PER_VBUS; i++)
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
|
|
|
if(!(pTop = pVBus->pVDevice[i])) continue;
|
|
|
|
if (pTop->pVBus!=_vbus_p) return -1;
|
|
|
|
while (pTop->pParent) pTop = pTop->pParent;
|
|
|
|
if (id==0 && pTop->vf_bootmark)
|
|
|
|
pTop->vf_bootmark = 0;
|
|
|
|
else if (pTop==ID_TO_VDEV(id) && !pTop->vf_bootmark)
|
|
|
|
pTop->vf_bootmark = 1;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
SyncArrayInfo(pTop);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pAdapter = pAdapter->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_ADD_SPARE_DISK:
|
|
|
|
{
|
|
|
|
DEVICEID id;
|
|
|
|
|
|
|
|
if (nInBufferSize!=sizeof(DEVICEID)) return -1;
|
|
|
|
if (nOutBufferSize!=0) return -1;
|
|
|
|
|
|
|
|
id = *(DEVICEID *)lpInBuffer;
|
|
|
|
|
|
|
|
if(hpt_add_spare_disk(_VBUS_P id))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_REMOVE_SPARE_DISK:
|
|
|
|
{
|
|
|
|
DEVICEID id;
|
|
|
|
|
|
|
|
if (nInBufferSize!=sizeof(DEVICEID)) return -1;
|
|
|
|
if (nOutBufferSize!=0) return -1;
|
|
|
|
|
|
|
|
id = *(DEVICEID *)lpInBuffer;
|
|
|
|
|
|
|
|
if(hpt_remove_spare_disk(_VBUS_P id))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPT_IOCTL_ADD_DISK_TO_ARRAY:
|
|
|
|
{
|
|
|
|
DEVICEID id1,id2;
|
|
|
|
id1 = ((PHPT_ADD_DISK_TO_ARRAY)lpInBuffer)->idArray;
|
|
|
|
id2 = ((PHPT_ADD_DISK_TO_ARRAY)lpInBuffer)->idDisk;
|
|
|
|
|
|
|
|
if (nInBufferSize != sizeof(HPT_ADD_DISK_TO_ARRAY)) return -1;
|
|
|
|
if (nOutBufferSize != 0) return -1;
|
|
|
|
|
|
|
|
if(hpt_add_disk_to_array(_VBUS_P id1, id2))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case HPT_IOCTL_GET_DRIVER_CAPABILITIES:
|
|
|
|
{
|
|
|
|
PDRIVER_CAPABILITIES cap;
|
|
|
|
if (nOutBufferSize<sizeof(DRIVER_CAPABILITIES)) return -1;
|
|
|
|
cap = (PDRIVER_CAPABILITIES)lpOutBuffer;
|
|
|
|
|
|
|
|
if(hpt_get_driver_capabilities(cap))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
case HPT_IOCTL_GET_CONTROLLER_VENID:
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
2009-04-07 16:38:25 +00:00
|
|
|
DWORD id = ((DWORD*)lpInBuffer)[0];
|
|
|
|
IAL_ADAPTER_T *pAdapTemp;
|
|
|
|
int iControllerCount = 0;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
for (pAdapTemp = gIal_Adapter; pAdapTemp; pAdapTemp = pAdapTemp->next)
|
|
|
|
if (iControllerCount++==id)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!pAdapTemp)
|
2004-10-24 05:37:23 +00:00
|
|
|
return -1;
|
2009-04-07 16:38:25 +00:00
|
|
|
|
|
|
|
if (nOutBufferSize < 4)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*(DWORD*)lpOutBuffer = ((DWORD)pAdapTemp->mvSataAdapter.pciConfigDeviceId << 16) | 0x11AB;
|
|
|
|
return 0;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
case HPT_IOCTL_EPROM_IO:
|
2004-10-24 05:37:23 +00:00
|
|
|
{
|
2009-04-07 16:38:25 +00:00
|
|
|
DWORD id = ((DWORD*)lpInBuffer)[0];
|
|
|
|
DWORD offset = ((DWORD*)lpInBuffer)[1];
|
|
|
|
DWORD direction = ((DWORD*)lpInBuffer)[2];
|
|
|
|
DWORD length = ((DWORD*)lpInBuffer)[3];
|
|
|
|
IAL_ADAPTER_T *pAdapTemp;
|
|
|
|
int iControllerCount = 0;
|
|
|
|
|
|
|
|
for (pAdapTemp = gIal_Adapter; pAdapTemp; pAdapTemp = pAdapTemp->next)
|
|
|
|
if (iControllerCount++==id)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!pAdapTemp)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (nInBufferSize < sizeof(DWORD) * 4 + (direction? length : 0) ||
|
|
|
|
nOutBufferSize < (direction? 0 : length))
|
|
|
|
return -1;
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
if (direction == 0) /* read */
|
|
|
|
sx508x_flash_access(&pAdapTemp->mvSataAdapter,
|
|
|
|
offset, lpOutBuffer, length, 1);
|
|
|
|
else
|
|
|
|
sx508x_flash_access(&pAdapTemp->mvSataAdapter,
|
|
|
|
offset, (char *)lpInBuffer + 16, length, 0);
|
2004-10-24 05:37:23 +00:00
|
|
|
|
2009-04-07 16:38:25 +00:00
|
|
|
return 0;
|
2004-10-24 05:37:23 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-04-07 16:38:25 +00:00
|
|
|
|
2004-10-24 05:37:23 +00:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpBytesReturned)
|
|
|
|
*lpBytesReturned = nOutBufferSize;
|
|
|
|
return 0;
|
|
|
|
}
|