New functionality for arcmsr(4) native management via bioctl(8):

Added support to create/remove hot-spare, pass-through disks.
Added support to create/remove volume sets.
Added support to show information about physical disks, even if they
are marked unused, hot-spares or pass-through.

sd(4) devices are attached/detached automagically when a pass-through
disk or volume set is created/removed... thanks scsipi(9) and cube@
for hints.
This commit is contained in:
xtraeme 2008-01-02 23:48:05 +00:00
parent 481db08b0a
commit 68d02b93e3
2 changed files with 637 additions and 101 deletions

View File

@ -1,7 +1,8 @@
/* $NetBSD: arcmsr.c,v 1.8 2007/12/07 11:51:21 xtraeme Exp $ */
/* $NetBSD: arcmsr.c,v 1.9 2008/01/02 23:48:05 xtraeme Exp $ */
/* $OpenBSD: arc.c,v 1.68 2007/10/27 03:28:27 dlg Exp $ */
/*
* Copyright (c) 2007 Juan Romero Pardines <xtraeme@netbsd.org>
* Copyright (c) 2006 David Gwynne <dlg@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@ -20,7 +21,7 @@
#include "bio.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: arcmsr.c,v 1.8 2007/12/07 11:51:21 xtraeme Exp $");
__KERNEL_RCSID(0, "$NetBSD: arcmsr.c,v 1.9 2008/01/02 23:48:05 xtraeme Exp $");
#include <sys/param.h>
#include <sys/buf.h>
@ -95,13 +96,19 @@ CFATTACH_DECL(arcmsr, sizeof(struct arc_softc),
static int arc_bioctl(struct device *, u_long, void *);
static int arc_bio_inq(struct arc_softc *, struct bioc_inq *);
static int arc_bio_vol(struct arc_softc *, struct bioc_vol *);
static int arc_bio_disk(struct arc_softc *, struct bioc_disk *);
static int arc_bio_disk_volume(struct arc_softc *, struct bioc_disk *);
static int arc_bio_disk_novol(struct arc_softc *, struct bioc_disk *);
static void arc_bio_disk_filldata(struct arc_softc *, struct bioc_disk *,
struct arc_fw_diskinfo *, int);
static int arc_bio_alarm(struct arc_softc *, struct bioc_alarm *);
static int arc_bio_alarm_state(struct arc_softc *, struct bioc_alarm *);
static int arc_bio_getvol(struct arc_softc *, int,
struct arc_fw_volinfo *);
static int arc_bio_setstate(struct arc_softc *, struct bioc_setstate *);
static int arc_bio_volops(struct arc_softc *, struct bioc_volops *);
static void arc_create_sensors(void *);
static void arc_refresh_sensors(struct sysmon_envsys *, envsys_data_t *);
static int arc_fw_parse_status_code(struct arc_softc *, uint8_t *);
#endif
static int
@ -186,7 +193,11 @@ arc_attach(device_t parent, device_t self, void *aux)
chan->chan_channel = 0;
chan->chan_flags = SCSIPI_CHAN_NOSETTLE;
(void)config_found(self, &sc->sc_chan, scsiprint);
/*
* Save the device_t returned, because we could to attach
* devices via the management interface.
*/
sc->sc_scsibus_dv = config_found(self, &sc->sc_chan, scsiprint);
/* enable interrupts */
arc_write(sc, ARC_REG_INTRMASK,
@ -277,7 +288,6 @@ arc_intr(void *arg)
if (intrstat & ARC_REG_INTRSTAT_DOORBELL) {
if (sc->sc_talking) {
/* if an ioctl is talking, wake it up */
arc_write(sc, ARC_REG_INTRMASK,
~ARC_REG_INTRMASK_POSTQUEUE);
cv_broadcast(&sc->sc_condvar);
@ -305,6 +315,7 @@ arc_intr(void *arg)
arc_scsi_cmd_done(sc, ccb, reg);
}
return 1;
}
@ -635,7 +646,6 @@ arc_query_firmware(struct arc_softc *sc)
device_xname(&sc->sc_dev), string);
scsipi_strvis(string, 17, fwinfo.model, sizeof(fwinfo.model));
aprint_normal("%s: Areca %s Host Adapter RAID controller\n",
device_xname(&sc->sc_dev), string);
@ -643,6 +653,13 @@ arc_query_firmware(struct arc_softc *sc)
DNPRINTF(ARC_D_INIT, "%s: version: \"%s\"\n",
device_xname(&sc->sc_dev), string);
aprint_normal("%s: %d ports, %dMB SDRAM, firmware <%s>\n",
device_xname(&sc->sc_dev), htole32(fwinfo.sata_ports),
htole32(fwinfo.sdram_size), string);
/* save the number of max disks for future use */
sc->sc_maxdisks = htole32(fwinfo.sata_ports);
if (htole32(fwinfo.request_len) != ARC_MAX_IOCMDLEN) {
aprint_error("%s: unexpected request frame size (%d != %d)\n",
device_xname(&sc->sc_dev),
@ -652,10 +669,6 @@ arc_query_firmware(struct arc_softc *sc)
sc->sc_req_count = htole32(fwinfo.queue_len);
aprint_normal("%s: %d ports, %dMB SDRAM, firmware <%s>\n",
device_xname(&sc->sc_dev), htole32(fwinfo.sata_ports),
htole32(fwinfo.sdram_size), string);
return 0;
}
@ -676,13 +689,25 @@ arc_bioctl(struct device *self, u_long cmd, void *addr)
break;
case BIOCDISK:
error = arc_bio_disk(sc, (struct bioc_disk *)addr);
error = arc_bio_disk_volume(sc, (struct bioc_disk *)addr);
break;
case BIOCDISK_NOVOL:
error = arc_bio_disk_novol(sc, (struct bioc_disk *)addr);
break;
case BIOCALARM:
error = arc_bio_alarm(sc, (struct bioc_alarm *)addr);
break;
case BIOCSETSTATE:
error = arc_bio_setstate(sc, (struct bioc_setstate *)addr);
break;
case BIOCVOLOPS:
error = arc_bio_volops(sc, (struct bioc_volops *)addr);
break;
default:
error = ENOTTY;
break;
@ -691,6 +716,64 @@ arc_bioctl(struct device *self, u_long cmd, void *addr)
return error;
}
static int
arc_fw_parse_status_code(struct arc_softc *sc, uint8_t *reply)
{
switch (*reply) {
case ARC_FW_CMD_RAIDINVAL:
printf("%s: firmware error (invalid raid set)\n",
device_xname(&sc->sc_dev));
return EINVAL;
case ARC_FW_CMD_VOLINVAL:
printf("%s: firmware error (invalid volume set)\n",
device_xname(&sc->sc_dev));
return EINVAL;
case ARC_FW_CMD_NORAID:
printf("%s: firmware error (unexistent raid set)\n",
device_xname(&sc->sc_dev));
return ENODEV;
case ARC_FW_CMD_NOVOLUME:
printf("%s: firmware error (unexistent volume set)\n",
device_xname(&sc->sc_dev));
return ENODEV;
case ARC_FW_CMD_NOPHYSDRV:
printf("%s: firmware error (unexistent physical drive)\n",
device_xname(&sc->sc_dev));
return ENODEV;
case ARC_FW_CMD_PARAM_ERR:
printf("%s: firmware error (parameter error)\n",
device_xname(&sc->sc_dev));
return EINVAL;
case ARC_FW_CMD_UNSUPPORTED:
printf("%s: firmware error (unsupported command)\n",
device_xname(&sc->sc_dev));
return EOPNOTSUPP;
case ARC_FW_CMD_DISKCFG_CHGD:
printf("%s: firmware error (disk configuration changed)\n",
device_xname(&sc->sc_dev));
return EINVAL;
case ARC_FW_CMD_PASS_INVAL:
printf("%s: firmware error (invalid password)\n",
device_xname(&sc->sc_dev));
return EINVAL;
case ARC_FW_CMD_NODISKSPACE:
printf("%s: firmware error (no disk space available)\n",
device_xname(&sc->sc_dev));
return EOPNOTSUPP;
case ARC_FW_CMD_CHECKSUM_ERR:
printf("%s: firmware error (checksum error)\n",
device_xname(&sc->sc_dev));
return EINVAL;
case ARC_FW_CMD_PASS_REQD:
printf("%s: firmware error (password required)\n",
device_xname(&sc->sc_dev));
return EPERM;
case ARC_FW_CMD_OK:
default:
return 0;
}
}
static int
arc_bio_alarm(struct arc_softc *sc, struct bioc_alarm *ba)
{
@ -726,21 +809,14 @@ arc_bio_alarm(struct arc_softc *sc, struct bioc_alarm *ba)
if (error != 0)
return error;
switch (reply[0]) {
case ARC_FW_CMD_OK:
return 0;
case ARC_FW_CMD_PASS_REQD:
return EPERM;
default:
return EIO;
}
return arc_fw_parse_status_code(sc, &reply[0]);
}
static int
arc_bio_alarm_state(struct arc_softc *sc, struct bioc_alarm *ba)
{
uint8_t request = ARC_FW_SYSINFO;
struct arc_fw_sysinfo *sysinfo;
uint8_t request;
int error = 0;
sysinfo = kmem_zalloc(sizeof(struct arc_fw_sysinfo), KM_SLEEP);
@ -759,18 +835,343 @@ out:
return error;
}
static int
arc_bio_volops(struct arc_softc *sc, struct bioc_volops *bc)
{
/* to create a raid set */
struct req_craidset {
uint8_t cmdcode;
uint32_t devmask;
uint8_t raidset_name[16];
} __packed;
/* to create a volume set */
struct req_cvolset {
uint8_t cmdcode;
uint8_t raidset;
uint8_t volset_name[16];
uint64_t capacity;
uint8_t raidlevel;
uint8_t stripe;
uint8_t scsi_chan;
uint8_t scsi_target;
uint8_t scsi_lun;
uint8_t tagqueue;
uint8_t cache;
uint8_t speed;
uint8_t quick_init;
} __packed;
struct scsibus_softc *scsibus_sc = NULL;
struct req_craidset req_craidset;
struct req_cvolset req_cvolset;
uint8_t request[2];
uint8_t reply[1];
int error = 0;
switch (bc->bc_opcode) {
case BIOC_VCREATE_VOLUME:
{
/*
* Zero out the structs so that we use some defaults
* in raid and volume sets.
*/
memset(&req_craidset, 0, sizeof(req_craidset));
memset(&req_cvolset, 0, sizeof(req_cvolset));
/*
* Firstly we have to create the raid set and
* use the default name for all them.
*/
req_craidset.cmdcode = ARC_FW_CREATE_RAIDSET;
req_craidset.devmask = bc->bc_devmask;
error = arc_msgbuf(sc, &req_craidset, sizeof(req_craidset),
reply, sizeof(reply));
if (error != 0)
return error;
error = arc_fw_parse_status_code(sc, &reply[0]);
if (error) {
printf("%s: create raidset%d failed\n",
device_xname(&sc->sc_dev), bc->bc_volid);
return error;
}
/*
* At this point the raid set was created, so it's
* time to create the volume set.
*/
req_cvolset.cmdcode = ARC_FW_CREATE_VOLUME;
req_cvolset.raidset = bc->bc_volid;
req_cvolset.capacity = bc->bc_size * ARC_BLOCKSIZE;
/*
* Set the RAID level.
*/
switch (bc->bc_level) {
case 0:
case 1:
req_cvolset.raidlevel = bc->bc_level;
break;
case 3:
req_cvolset.raidlevel = ARC_FW_VOL_RAIDLEVEL_3;
break;
case 5:
req_cvolset.raidlevel = ARC_FW_VOL_RAIDLEVEL_5;
break;
case 6:
req_cvolset.raidlevel = ARC_FW_VOL_RAIDLEVEL_6;
break;
default:
return EOPNOTSUPP;
}
/*
* Set the stripe size.
*/
switch (bc->bc_stripe) {
case 4:
req_cvolset.stripe = 0;
break;
case 8:
req_cvolset.stripe = 1;
break;
case 16:
req_cvolset.stripe = 2;
break;
case 32:
req_cvolset.stripe = 3;
break;
case 64:
req_cvolset.stripe = 4;
break;
case 128:
req_cvolset.stripe = 5;
break;
default:
req_cvolset.stripe = 4; /* by default 64K */
break;
}
req_cvolset.scsi_chan = bc->bc_channel;
req_cvolset.scsi_target = bc->bc_target;
req_cvolset.scsi_lun = bc->bc_lun;
req_cvolset.tagqueue = 1; /* always enabled */
req_cvolset.cache = 1; /* always enabled */
req_cvolset.speed = 4; /* always max speed */
error = arc_msgbuf(sc, &req_cvolset, sizeof(req_cvolset),
reply, sizeof(reply));
if (error != 0)
return error;
error = arc_fw_parse_status_code(sc, &reply[0]);
if (error) {
printf("%s: create volumeset%d failed\n",
device_xname(&sc->sc_dev), bc->bc_volid);
return error;
}
/*
* Do a rescan on the bus to attach the device associated
* with the new volume.
*/
scsibus_sc = device_private(sc->sc_scsibus_dv);
(void)scsi_probe_bus(scsibus_sc, bc->bc_target, bc->bc_lun);
break;
}
case BIOC_VREMOVE_VOLUME:
{
/*
* Remove the volume set specified in bc_volid.
*/
request[0] = ARC_FW_DELETE_VOLUME;
request[1] = bc->bc_volid;
error = arc_msgbuf(sc, request, sizeof(request),
reply, sizeof(reply));
if (error != 0)
return error;
error = arc_fw_parse_status_code(sc, &reply[0]);
if (error) {
printf("%s: delete volumeset%d failed\n",
device_xname(&sc->sc_dev), bc->bc_volid);
return error;
}
/*
* Detach the sd(4) device associated with the volume,
* but if there's an error don't make it a priority.
*/
error = scsipi_target_detach(&sc->sc_chan, bc->bc_target,
bc->bc_lun, 0);
if (error)
printf("%s: couldn't detach sd device for volume %d "
"at %u:%u.%u (error=%d)\n",
device_xname(&sc->sc_dev), bc->bc_volid,
bc->bc_channel, bc->bc_target, bc->bc_lun, error);
/*
* and remove the raid set specified in bc_volid,
* we only care about volumes.
*/
request[0] = ARC_FW_DELETE_RAIDSET;
request[1] = bc->bc_volid;
error = arc_msgbuf(sc, request, sizeof(request),
reply, sizeof(reply));
if (error != 0)
return error;
error = arc_fw_parse_status_code(sc, &reply[0]);
if (error) {
printf("%s: delete raidset%d failed\n",
device_xname(&sc->sc_dev), bc->bc_volid);
return error;
}
break;
}
default:
return EOPNOTSUPP;
}
return error;
}
static int
arc_bio_setstate(struct arc_softc *sc, struct bioc_setstate *bs)
{
/* for a hotspare disk */
struct request_hs {
uint8_t cmdcode;
uint32_t devmask;
} __packed;
/* for a pass-through disk */
struct request_pt {
uint8_t cmdcode;
uint8_t devid;
uint8_t scsi_chan;
uint8_t scsi_id;
uint8_t scsi_lun;
uint8_t tagged_queue;
uint8_t cache_mode;
uint8_t max_speed;
} __packed;
struct scsibus_softc *scsibus_sc = NULL;
struct request_hs req_hs; /* to add/remove hotspare */
struct request_pt req_pt; /* to add a pass-through */
uint8_t req_gen[2];
uint8_t reply[1];
int error = 0;
switch (bs->bs_status) {
case BIOC_SSHOTSPARE:
{
req_hs.cmdcode = ARC_FW_CREATE_HOTSPARE;
req_hs.devmask = (1 << bs->bs_target);
goto hotspare;
}
case BIOC_SSDELHOTSPARE:
{
req_hs.cmdcode = ARC_FW_DELETE_HOTSPARE;
req_hs.devmask = (1 << bs->bs_target);
goto hotspare;
}
case BIOC_SSPASSTHRU:
{
req_pt.cmdcode = ARC_FW_CREATE_PASSTHRU;
req_pt.devid = bs->bs_other_id; /* this wants device# */
req_pt.scsi_chan = bs->bs_channel;
req_pt.scsi_id = bs->bs_target;
req_pt.scsi_lun = bs->bs_lun;
req_pt.tagged_queue = 1; /* always enabled */
req_pt.cache_mode = 1; /* always enabled */
req_pt.max_speed = 4; /* always max speed */
error = arc_msgbuf(sc, &req_pt, sizeof(req_pt),
reply, sizeof(reply));
if (error != 0)
return error;
/*
* Do a rescan on the bus to attach the new device
* associated with the pass-through disk.
*/
scsibus_sc = device_private(sc->sc_scsibus_dv);
(void)scsi_probe_bus(scsibus_sc, bs->bs_target, bs->bs_lun);
goto out;
}
case BIOC_SSDELPASSTHRU:
{
req_gen[0] = ARC_FW_DELETE_PASSTHRU;
req_gen[1] = bs->bs_target;
error = arc_msgbuf(sc, &req_gen, sizeof(req_gen),
reply, sizeof(reply));
if (error != 0)
return error;
/*
* Detach the sd device associated with this pass-through disk.
*/
error = scsipi_target_detach(&sc->sc_chan, bs->bs_target,
bs->bs_lun, 0);
if (error)
printf("%s: couldn't detach sd device for the "
"pass-through disk at %u:%u.%u (error=%d)\n",
device_xname(&sc->sc_dev),
bs->bs_channel, bs->bs_target, bs->bs_lun, error);
goto out;
}
case BIOC_SSCHECKSTART_VOL:
{
req_gen[0] = ARC_FW_START_CHECKVOL;
req_gen[1] = bs->bs_volid;
error = arc_msgbuf(sc, &req_gen, sizeof(req_gen),
reply, sizeof(reply));
if (error != 0)
return error;
goto out;
}
case BIOC_SSCHECKSTOP_VOL:
{
uint8_t req = ARC_FW_STOP_CHECKVOL;
error = arc_msgbuf(sc, &req, 1, reply, sizeof(reply));
if (error != 0)
return error;
goto out;
}
default:
return EOPNOTSUPP;
}
hotspare:
error = arc_msgbuf(sc, &req_hs, sizeof(req_hs),
reply, sizeof(reply));
if (error != 0)
return error;
out:
return arc_fw_parse_status_code(sc, &reply[0]);
}
static int
arc_bio_inq(struct arc_softc *sc, struct bioc_inq *bi)
{
uint8_t request[2];
struct arc_fw_sysinfo *sysinfo;
struct arc_fw_volinfo *volinfo;
int maxvols, nvols = 0, i;
struct arc_fw_raidinfo *raidinfo;
int maxraidset, nvols = 0, i;
int error = 0;
sysinfo = kmem_zalloc(sizeof(struct arc_fw_sysinfo), KM_SLEEP);
volinfo = kmem_zalloc(sizeof(struct arc_fw_volinfo), KM_SLEEP);
raidinfo = kmem_zalloc(sizeof(struct arc_fw_raidinfo), KM_SLEEP);
request[0] = ARC_FW_SYSINFO;
error = arc_msgbuf(sc, request, 1, sysinfo,
@ -778,30 +1179,26 @@ arc_bio_inq(struct arc_softc *sc, struct bioc_inq *bi)
if (error != 0)
goto out;
maxvols = sysinfo->max_volume_set;
maxraidset = sysinfo->max_raid_set;
request[0] = ARC_FW_VOLINFO;
for (i = 0; i < maxvols; i++) {
request[0] = ARC_FW_RAIDINFO;
for (i = 0; i < maxraidset; i++) {
request[1] = i;
error = arc_msgbuf(sc, request, sizeof(request), volinfo,
sizeof(struct arc_fw_volinfo));
error = arc_msgbuf(sc, request, sizeof(request), raidinfo,
sizeof(struct arc_fw_raidinfo));
if (error != 0)
goto out;
/*
* I can't find an easy way to see if the volume exists or not
* except to say that if it has no capacity then it isn't there.
* Ignore passthru volumes, bioc_vol doesn't understand them.
*/
if ((volinfo->capacity != 0 || volinfo->capacity2 != 0) &&
volinfo->raid_level != ARC_FW_VOL_RAIDLEVEL_PASSTHRU)
if (raidinfo->volumes)
nvols++;
}
strlcpy(bi->bi_dev, device_xname(&sc->sc_dev), sizeof(bi->bi_dev));
bi->bi_novol = nvols;
bi->bi_nodisk = sc->sc_maxdisks;
out:
kmem_free(volinfo, sizeof(*volinfo));
kmem_free(raidinfo, sizeof(*raidinfo));
kmem_free(sysinfo, sizeof(*sysinfo));
return error;
}
@ -817,7 +1214,6 @@ arc_bio_getvol(struct arc_softc *sc, int vol, struct arc_fw_volinfo *volinfo)
sysinfo = kmem_zalloc(sizeof(struct arc_fw_sysinfo), KM_SLEEP);
request[0] = ARC_FW_SYSINFO;
error = arc_msgbuf(sc, request, 1, sysinfo,
sizeof(struct arc_fw_sysinfo));
if (error != 0)
@ -833,8 +1229,7 @@ arc_bio_getvol(struct arc_softc *sc, int vol, struct arc_fw_volinfo *volinfo)
if (error != 0)
goto out;
if ((volinfo->capacity == 0 && volinfo->capacity2 == 0) ||
volinfo->raid_level == ARC_FW_VOL_RAIDLEVEL_PASSTHRU)
if (volinfo->capacity == 0 && volinfo->capacity2 == 0)
continue;
if (nvols == vol)
@ -844,8 +1239,7 @@ arc_bio_getvol(struct arc_softc *sc, int vol, struct arc_fw_volinfo *volinfo)
}
if (nvols != vol ||
(volinfo->capacity == 0 && volinfo->capacity2 == 0) ||
volinfo->raid_level == ARC_FW_VOL_RAIDLEVEL_PASSTHRU) {
(volinfo->capacity == 0 && volinfo->capacity2 == 0)) {
error = ENODEV;
goto out;
}
@ -884,13 +1278,16 @@ arc_bio_vol(struct arc_softc *sc, struct bioc_vol *bv)
bv->bv_status = BIOC_SVOFFLINE;
} else if (status & ARC_FW_VOL_STATUS_INITTING) {
bv->bv_status = BIOC_SVBUILDING;
bv->bv_percent = htole32(volinfo->progress) / 10;
bv->bv_percent = htole32(volinfo->progress);
} else if (status & ARC_FW_VOL_STATUS_REBUILDING) {
bv->bv_status = BIOC_SVREBUILD;
bv->bv_percent = htole32(volinfo->progress) / 10;
bv->bv_percent = htole32(volinfo->progress);
} else if (status & ARC_FW_VOL_STATUS_MIGRATING) {
bv->bv_status = BIOC_SVMIGRATING;
bv->bv_percent = htole32(volinfo->progress) / 10;
bv->bv_percent = htole32(volinfo->progress);
} else if (status & ARC_FW_VOL_STATUS_CHECKING) {
bv->bv_status = BIOC_SVCHECKING;
bv->bv_percent = htole32(volinfo->progress);
}
blocks = (uint64_t)htole32(volinfo->capacity2) << 32;
@ -914,13 +1311,18 @@ arc_bio_vol(struct arc_softc *sc, struct bioc_vol *bv)
bv->bv_level = 6;
break;
case ARC_FW_VOL_RAIDLEVEL_PASSTHRU:
bv->bv_level = BIOC_SVOL_PASSTHRU;
break;
default:
bv->bv_level = -1;
break;
}
bv->bv_nodisk = volinfo->member_disks;
strlcpy(bv->bv_dev, volinfo->set_name, sizeof(bv->bv_dev));
bv->bv_stripe_size = volinfo->stripe_size / 2;
snprintf(bv->bv_dev, sizeof(bv->bv_dev), "sd%d", bv->bv_volid);
scsipi_strvis(bv->bv_vendor, sizeof(bv->bv_vendor), volinfo->set_name,
sizeof(volinfo->set_name));
out:
kmem_free(volinfo, sizeof(*volinfo));
@ -928,18 +1330,104 @@ out:
}
static int
arc_bio_disk(struct arc_softc *sc, struct bioc_disk *bd)
arc_bio_disk_novol(struct arc_softc *sc, struct bioc_disk *bd)
{
uint8_t request[2];
struct arc_fw_volinfo *volinfo;
struct arc_fw_raidinfo *raidinfo;
struct arc_fw_diskinfo *diskinfo;
uint8_t request[2];
int error = 0;
diskinfo = kmem_zalloc(sizeof(struct arc_fw_diskinfo), KM_SLEEP);
if (bd->bd_diskid > sc->sc_maxdisks) {
error = ENODEV;
goto out;
}
request[0] = ARC_FW_DISKINFO;
request[1] = bd->bd_diskid;
error = arc_msgbuf(sc, request, sizeof(request),
diskinfo, sizeof(struct arc_fw_diskinfo));
if (error != 0)
return error;
/* skip disks with no capacity */
if (htole32(diskinfo->capacity) == 0 &&
htole32(diskinfo->capacity2) == 0)
goto out;
bd->bd_disknovol = true;
arc_bio_disk_filldata(sc, bd, diskinfo, bd->bd_diskid);
out:
kmem_free(diskinfo, sizeof(*diskinfo));
return error;
}
static void
arc_bio_disk_filldata(struct arc_softc *sc, struct bioc_disk *bd,
struct arc_fw_diskinfo *diskinfo, int diskid)
{
uint64_t blocks;
char model[81];
char serial[41];
char rev[17];
switch (htole32(diskinfo->device_state)) {
case ARC_FW_DISK_PASSTHRU:
bd->bd_status = BIOC_SDPASSTHRU;
break;
case ARC_FW_DISK_RAIDMEMBER:
bd->bd_status = BIOC_SDONLINE;
break;
case ARC_FW_DISK_HOTSPARE:
bd->bd_status = BIOC_SDHOTSPARE;
break;
case ARC_FW_DISK_UNUSED:
bd->bd_status = BIOC_SDUNUSED;
break;
default:
printf("%s: unknown disk device_state: 0x%x\n", __func__,
htole32(diskinfo->device_state));
bd->bd_status = BIOC_SDINVALID;
return;
}
blocks = (uint64_t)htole32(diskinfo->capacity2) << 32;
blocks += (uint64_t)htole32(diskinfo->capacity);
bd->bd_size = blocks * ARC_BLOCKSIZE; /* XXX */
scsipi_strvis(model, 81, diskinfo->model, sizeof(diskinfo->model));
scsipi_strvis(serial, 41, diskinfo->serial, sizeof(diskinfo->serial));
scsipi_strvis(rev, 17, diskinfo->firmware_rev,
sizeof(diskinfo->firmware_rev));
snprintf(bd->bd_vendor, sizeof(bd->bd_vendor), "%s %s", model, rev);
strlcpy(bd->bd_serial, serial, sizeof(bd->bd_serial));
#if 0
bd->bd_channel = diskinfo->scsi_attr.channel;
bd->bd_target = diskinfo->scsi_attr.target;
bd->bd_lun = diskinfo->scsi_attr.lun;
#endif
/*
* the firwmare doesnt seem to fill scsi_attr in, so fake it with
* the diskid.
*/
bd->bd_channel = 0;
bd->bd_target = diskid;
bd->bd_lun = 0;
}
static int
arc_bio_disk_volume(struct arc_softc *sc, struct bioc_disk *bd)
{
uint8_t request[2];
struct arc_fw_raidinfo *raidinfo;
struct arc_fw_volinfo *volinfo;
struct arc_fw_diskinfo *diskinfo;
int error = 0;
volinfo = kmem_zalloc(sizeof(struct arc_fw_volinfo), KM_SLEEP);
raidinfo = kmem_zalloc(sizeof(struct arc_fw_raidinfo), KM_SLEEP);
diskinfo = kmem_zalloc(sizeof(struct arc_fw_diskinfo), KM_SLEEP);
@ -961,19 +1449,6 @@ arc_bio_disk(struct arc_softc *sc, struct bioc_disk *bd)
goto out;
}
if (raidinfo->device_array[bd->bd_diskid] == 0xff) {
/*
* the disk doesn't exist anymore. bio is too dumb to be
* able to display that, so put it on another bus
*/
bd->bd_channel = 1;
bd->bd_target = 0;
bd->bd_lun = 0;
bd->bd_status = BIOC_SDOFFLINE;
strlcpy(bd->bd_vendor, "disk missing", sizeof(bd->bd_vendor));
goto out;
}
request[0] = ARC_FW_DISKINFO;
request[1] = raidinfo->device_array[bd->bd_diskid];
error = arc_msgbuf(sc, request, sizeof(request), diskinfo,
@ -981,36 +1456,14 @@ arc_bio_disk(struct arc_softc *sc, struct bioc_disk *bd)
if (error != 0)
goto out;
#if 0
bd->bd_channel = diskinfo->scsi_attr.channel;
bd->bd_target = diskinfo->scsi_attr.target;
bd->bd_lun = diskinfo->scsi_attr.lun;
#endif
/*
* the firwmare doesnt seem to fill scsi_attr in, so fake it with
* the diskid.
*/
bd->bd_channel = 0;
bd->bd_target = raidinfo->device_array[bd->bd_diskid];
bd->bd_lun = 0;
bd->bd_status = BIOC_SDONLINE;
blocks = (uint64_t)htole32(diskinfo->capacity2) << 32;
blocks += (uint64_t)htole32(diskinfo->capacity);
bd->bd_size = blocks * ARC_BLOCKSIZE; /* XXX */
scsipi_strvis(model, 81, diskinfo->model, sizeof(diskinfo->model));
scsipi_strvis(serial, 41, diskinfo->serial, sizeof(diskinfo->serial));
scsipi_strvis(rev, 17, diskinfo->firmware_rev,
sizeof(diskinfo->firmware_rev));
snprintf(bd->bd_vendor, sizeof(bd->bd_vendor), "%s %s", model, rev);
strlcpy(bd->bd_serial, serial, sizeof(bd->bd_serial));
/* now fill our bio disk with data from the firmware */
arc_bio_disk_filldata(sc, bd, diskinfo,
raidinfo->device_array[bd->bd_diskid]);
out:
kmem_free(diskinfo, sizeof(*diskinfo));
kmem_free(raidinfo, sizeof(*raidinfo));
kmem_free(volinfo, sizeof(*volinfo));
kmem_free(diskinfo, sizeof(*diskinfo));
return error;
}
#endif /* NBIO > 0 */
@ -1102,6 +1555,7 @@ arc_msgbuf(struct arc_softc *sc, void *wptr, size_t wbuflen, void *rptr,
while ((reg = arc_read(sc, ARC_REG_OUTB_DOORBELL)) == 0)
arc_wait(sc);
arc_write(sc, ARC_REG_OUTB_DOORBELL, reg);
DNPRINTF(ARC_D_DB, "%s: reg: 0x%08x\n",
@ -1187,9 +1641,9 @@ arc_unlock(struct arc_softc *sc)
{
KASSERT(mutex_owned(&sc->sc_mutex));
sc->sc_talking = 0;
arc_write(sc, ARC_REG_INTRMASK,
~(ARC_REG_INTRMASK_POSTQUEUE|ARC_REG_INTRMASK_DOORBELL));
sc->sc_talking = 0;
mutex_spin_exit(&sc->sc_mutex);
rw_exit(&sc->sc_rwlock);
}
@ -1201,8 +1655,7 @@ arc_wait(struct arc_softc *sc)
arc_write(sc, ARC_REG_INTRMASK,
~(ARC_REG_INTRMASK_POSTQUEUE|ARC_REG_INTRMASK_DOORBELL));
if (cv_timedwait_sig(&sc->sc_condvar, &sc->sc_mutex, hz) ==
EWOULDBLOCK)
if (cv_timedwait(&sc->sc_condvar, &sc->sc_mutex, hz) == EWOULDBLOCK)
arc_write(sc, ARC_REG_INTRMASK, ~ARC_REG_INTRMASK_POSTQUEUE);
}
@ -1243,8 +1696,8 @@ arc_create_sensors(void *arg)
sc->sc_sensors[i].units = ENVSYS_DRIVE;
sc->sc_sensors[i].monitor = true;
sc->sc_sensors[i].flags = ENVSYS_FMONSTCHANGED;
strlcpy(sc->sc_sensors[i].desc, bv.bv_dev,
sizeof(sc->sc_sensors[i].desc));
snprintf(sc->sc_sensors[i].desc, sizeof(sc->sc_sensors[i].desc),
"RAID volume %s", bv.bv_dev);
if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensors[i]))
goto bad;
}

View File

@ -1,7 +1,8 @@
/* $NetBSD: arcmsrvar.h,v 1.6 2007/12/09 00:24:46 xtraeme Exp $ */
/* $NetBSD: arcmsrvar.h,v 1.7 2008/01/02 23:48:05 xtraeme Exp $ */
/* Derived from $OpenBSD: arc.c,v 1.68 2007/10/27 03:28:27 dlg Exp $ */
/*
* Copyright (c) 2007 Juan Romero Pardines <xtraeme@netbsd.org>
* Copyright (c) 2006 David Gwynne <dlg@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@ -163,6 +164,7 @@ struct arc_fw_bufhdr {
/* Firmware command codes */
#define ARC_FW_CHECK_PASS 0x14 /* opcode + 1 byte length + password */
#define ARC_FW_GETEVENTS 0x1a /* opcode + 1 byte for page 0/1/2/3 */
#define ARC_FW_GETHWMON 0x1b /* opcode + arc_fw_hwmon */
#define ARC_FW_RAIDINFO 0x20 /* opcode + raid# */
#define ARC_FW_VOLINFO 0x21 /* opcode + vol# */
#define ARC_FW_DISKINFO 0x22 /* opcode + physdisk# */
@ -184,6 +186,55 @@ struct arc_fw_bufhdr {
#define ARC_FW_SET_MAXATA_MODE_66 (1<<2)
#define ARC_FW_SET_MAXATA_MODE_33 (1<<3)
#define ARC_FW_NOP 0x38 /* opcode only */
/*
* Structure for ARC_FW_CREATE_PASSTHRU:
*
* byte 2 command code 0x40
* byte 3 device #
* byte 4 scsi channel (0/1)
* byte 5 scsi id (0/15)
* byte 6 scsi lun (0/7)
* byte 7 tagged queue (1 enabled)
* byte 8 cache mode (1 enabled)
* byte 9 max speed ((0/1/2/3/4 -> 33/66/100/133/150)
*/
#define ARC_FW_CREATE_PASSTHRU 0x40
#define ARC_FW_DELETE_PASSTHRU 0x42 /* opcode + device# */
/*
* Structure for ARC_FW_CREATE_RAIDSET:
*
* byte 2 command code 0x50
* byte 3-6 device mask
* byte 7-22 raidset name (byte 7 == 0 use default)
*/
#define ARC_FW_CREATE_RAIDSET 0x50
#define ARC_FW_DELETE_RAIDSET 0x51 /* opcode + raidset# */
#define ARC_FW_CREATE_HOTSPARE 0x54 /* opcode + 4 bytes device mask */
#define ARC_FW_DELETE_HOTSPARE 0x55 /* opcode + 4 bytes device mask */
/*
* Structure for ARC_FW_CREATE_VOLUME/ARC_FW_MODIFY_VOLUME:
*
* byte 2 command code 0x60
* byte 3 raidset#
* byte 4-19 volume set name (byte 4 == 0 use default)
* byte 20-27 volume capacity in blocks
* byte 28 raid level
* byte 29 stripe size
* byte 30 channel
* byte 31 ID
* byte 32 LUN
* byte 33 1 enable tag queuing
* byte 33 1 enable cache
* byte 35 speed 0/1/2/3/4 -> 33/66/100/133/150
* byte 36 1 for quick init (only for CREATE_VOLUME)
*/
#define ARC_FW_CREATE_VOLUME 0x60
#define ARC_FW_MODIFY_VOLUME 0x61
#define ARC_FW_DELETE_VOLUME 0x62 /* opcode + vol# */
#define ARC_FW_START_CHECKVOL 0x63 /* opcode + vol# */
#define ARC_FW_STOP_CHECKVOL 0x64 /* opcode only */
/* Status codes for the firmware command codes */
#define ARC_FW_CMD_OK 0x41
@ -197,8 +248,27 @@ struct arc_fw_bufhdr {
#define ARC_FW_CMD_DISKCFG_CHGD 0x49
#define ARC_FW_CMD_PASS_INVAL 0x4a
#define ARC_FW_CMD_NODISKSPACE 0x4b
#define ARC_FW_CMD_PASS_REQD 0x4d
#define ARC_FW_CMD_CHECKSUM_ERR 0x4c
#define ARC_FW_CMD_PASS_REQD 0x4d
struct arc_fw_hwmon {
uint8_t nfans;
uint8_t nvoltages;
uint8_t ntemps;
uint8_t npower;
uint16_t fan0; /* RPM */
uint16_t fan1; /* RPM */
uint16_t voltage_orig0; /* original value * 1000 */
uint16_t voltage_val0; /* value */
uint16_t voltage_orig1; /* original value * 1000 */
uint16_t voltage_val1; /* value */
uint16_t voltage_orig2;
uint16_t voltage_val2;
uint8_t temp0;
uint8_t temp1;
uint8_t pwr_indicator; /* (bit0 : power#0, bit1 : power#1) */
uint8_t ups_indicator;
} __packed;
struct arc_fw_comminfo {
uint8_t baud_rate;
@ -277,6 +347,10 @@ struct arc_fw_diskinfo {
uint32_t capacity;
uint32_t capacity2;
uint8_t device_state;
#define ARC_FW_DISK_RAIDMEMBER 0x89 /* disk is member of a raid set */
#define ARC_FW_DISK_PASSTHRU 0x8b /* pass through disk */
#define ARC_FW_DISK_HOTSPARE 0xa9 /* hotspare disk */
#define ARC_FW_DISK_UNUSED 0xc9 /* free/unused disk */
uint8_t pio_mode;
uint8_t current_udma_mode;
uint8_t udma_mode;
@ -350,6 +424,7 @@ struct arc_softc {
void *sc_shutdownhook;
int sc_req_count;
u_int sc_maxdisks;
struct arc_dmamem *sc_requests;
struct arc_ccb *sc_ccbs;
@ -364,6 +439,8 @@ struct arc_softc {
struct sysmon_envsys *sc_sme;
envsys_data_t *sc_sensors;
int sc_nsensors;
struct device *sc_scsibus_dv;
};
/*
@ -375,11 +452,15 @@ void arc_scsi_cmd(struct scsipi_channel *, scsipi_adapter_req_t, void *);
* code to deal with getting bits in and out of the bus space.
*/
uint32_t arc_read(struct arc_softc *, bus_size_t);
void arc_read_region(struct arc_softc *, bus_size_t, void *, size_t);
void arc_read_region(struct arc_softc *, bus_size_t, void *,
size_t);
void arc_write(struct arc_softc *, bus_size_t, uint32_t);
void arc_write_region(struct arc_softc *, bus_size_t, void *, size_t);
int arc_wait_eq(struct arc_softc *, bus_size_t, uint32_t, uint32_t);
int arc_wait_ne(struct arc_softc *, bus_size_t, uint32_t, uint32_t);
void arc_write_region(struct arc_softc *, bus_size_t, void *,
size_t);
int arc_wait_eq(struct arc_softc *, bus_size_t, uint32_t,
uint32_t);
int arc_wait_ne(struct arc_softc *, bus_size_t, uint32_t,
uint32_t);
int arc_msg0(struct arc_softc *, uint32_t);
#define arc_push(_s, _r) arc_write((_s), ARC_REG_POST_QUEUE, (_r))
@ -399,7 +480,8 @@ struct arc_dmamem {
#define ARC_DMA_KVA(_adm) ((void *)(_adm)->adm_kva)
struct arc_dmamem *arc_dmamem_alloc(struct arc_softc *, size_t);
void arc_dmamem_free(struct arc_softc *, struct arc_dmamem *);
void arc_dmamem_free(struct arc_softc *,
struct arc_dmamem *);
/*
* stuff to manage a scsi command.
@ -423,7 +505,8 @@ struct arc_ccb *arc_get_ccb(struct arc_softc *);
void arc_put_ccb(struct arc_softc *, struct arc_ccb *);
int arc_load_xs(struct arc_ccb *);
int arc_complete(struct arc_softc *, struct arc_ccb *, int);
void arc_scsi_cmd_done(struct arc_softc *, struct arc_ccb *, uint32_t);
void arc_scsi_cmd_done(struct arc_softc *, struct arc_ccb *,
uint32_t);
/*
* real stuff for dealing with the hardware.