Merge with latest version of the Mylex 6+ driver.

- All sources are built in a single object, reducing namespace pollution.
 - Kill the ready queue, and handle a busy response to mly_start in callers
   rather than deferring the command.
 - Improve our interaction with CAM:
   - Don't advertise physical channels as SCSI busses by default.
   - use the SIM queue freeze capability rather than queueing CDBs internally.
   - force bus reprobe at module load time.
 - Clean up more resources in mly_free.
 - Tidy up debugging levels.
 - Tidy up handling of events (mostly just code cleanliness).
 - Use explanatory macros for operations on bus/target/channel numbers.
This commit is contained in:
Mike Smith 2001-07-14 00:12:23 +00:00
parent ef1cb1959c
commit 822c2e6a94
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=79695
8 changed files with 1320 additions and 1423 deletions

View File

@ -408,8 +408,6 @@ dev/mlx/mlx.c optional mlx
dev/mlx/mlx_disk.c optional mlx
dev/mlx/mlx_pci.c optional mlx
dev/mly/mly.c optional mly
dev/mly/mly_cam.c optional mly
dev/mly/mly_pci.c optional mly
dev/musycc/musycc.c optional musycc
dev/nge/if_nge.c optional nge
dev/null/null.c standard

File diff suppressed because it is too large Load Diff

View File

@ -1,598 +0,0 @@
/*-
* Copyright (c) 2000, 2001 Michael Smith
* Copyright (c) 2000 BSDi
* 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.
*
* $FreeBSD$
*/
/*
* CAM interface for FreeBSD
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/devicestat.h>
#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_periph.h>
#include <cam/cam_sim.h>
#include <cam/cam_xpt_sim.h>
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_message.h>
#include <machine/resource.h>
#include <machine/bus.h>
#include <dev/mly/mlyreg.h>
#include <dev/mly/mlyio.h>
#include <dev/mly/mlyvar.h>
#include <dev/mly/mly_tables.h>
static void mly_cam_poll(struct cam_sim *sim);
static void mly_cam_action(struct cam_sim *sim, union ccb *ccb);
static void mly_cam_complete(struct mly_command *mc);
static struct cam_periph *mly_find_periph(struct mly_softc *sc, int bus, int target);
/********************************************************************************
* CAM-specific queue primitives
*/
static __inline void
mly_initq_ccb(struct mly_softc *sc)
{
TAILQ_INIT(&sc->mly_cam_ccbq);
MLYQ_INIT(sc, MLYQ_CCB);
}
static __inline void
mly_enqueue_ccb(struct mly_softc *sc, union ccb *ccb)
{
int s;
s = splcam();
TAILQ_INSERT_TAIL(&sc->mly_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
MLYQ_ADD(sc, MLYQ_CCB);
splx(s);
}
static __inline void
mly_requeue_ccb(struct mly_softc *sc, union ccb *ccb)
{
int s;
s = splcam();
TAILQ_INSERT_HEAD(&sc->mly_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
MLYQ_ADD(sc, MLYQ_CCB);
splx(s);
}
static __inline union ccb *
mly_dequeue_ccb(struct mly_softc *sc)
{
union ccb *ccb;
int s;
s = splcam();
if ((ccb = (union ccb *)TAILQ_FIRST(&sc->mly_cam_ccbq)) != NULL) {
TAILQ_REMOVE(&sc->mly_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
MLYQ_REMOVE(sc, MLYQ_CCB);
}
splx(s);
return(ccb);
}
/********************************************************************************
* space-fill a character string
*/
static __inline void
padstr(char *targ, char *src, int len)
{
while (len-- > 0) {
if (*src != 0) {
*targ++ = *src++;
} else {
*targ++ = ' ';
}
}
}
/********************************************************************************
* Attach the real and virtual SCSI busses to CAM
*/
int
mly_cam_attach(struct mly_softc *sc)
{
struct cam_devq *devq;
int chn, i;
debug_called(1);
/* initialise the CCB queue */
mly_initq_ccb(sc);
/*
* Allocate a devq for all our channels combined.
*/
if ((devq = cam_simq_alloc(sc->mly_controllerinfo->maximum_parallel_commands)) == NULL) {
mly_printf(sc, "can't allocate CAM SIM\n");
return(ENOMEM);
}
/*
* Iterate over channels, registering them with CAM.
*
* Physical channels are set up to support tagged commands and only a single
* untagged command. Virtual channels do not support tags, and don't need them.
*/
for (i = 0, chn = 0; i < sc->mly_controllerinfo->physical_channels_present; i++, chn++) {
/* allocate a sim */
if ((sc->mly_cam_sim[chn] = cam_sim_alloc(mly_cam_action,
mly_cam_poll,
"mly",
sc,
device_get_unit(sc->mly_dev),
1,
sc->mly_controllerinfo->maximum_parallel_commands,
devq)) == NULL) {
cam_simq_free(devq);
mly_printf(sc, "CAM SIM attach failed\n");
return(ENOMEM);
}
}
for (i = 0; i < sc->mly_controllerinfo->virtual_channels_present; i++, chn++) {
/* allocate a sim */
if ((sc->mly_cam_sim[chn] = cam_sim_alloc(mly_cam_action,
mly_cam_poll,
"mly",
sc,
device_get_unit(sc->mly_dev),
sc->mly_controllerinfo->maximum_parallel_commands,
0,
devq)) == NULL) {
cam_simq_free(devq);
mly_printf(sc, "CAM SIM attach failed\n");
return(ENOMEM);
}
}
for (i = 0; i < chn; i++) {
/* register the bus IDs so we can get them later */
if (xpt_bus_register(sc->mly_cam_sim[i], i)) {
mly_printf(sc, "CAM XPT bus registration failed\n");
return(ENXIO);
}
debug(1, "registered sim %p bus %d", sc->mly_cam_sim[i], i);
}
return(0);
}
/********************************************************************************
* Detach from CAM
*/
void
mly_cam_detach(struct mly_softc *sc)
{
int chn, nchn, first;
debug_called(1);
nchn = sc->mly_controllerinfo->physical_channels_present +
sc->mly_controllerinfo->virtual_channels_present;
/*
* Iterate over channels, deregistering as we go.
*/
nchn = sc->mly_controllerinfo->physical_channels_present +
sc->mly_controllerinfo->virtual_channels_present;
for (chn = 0, first = 1; chn < nchn; chn++) {
/*
* If a sim was registered for this channel, free it.
*/
if (sc->mly_cam_sim[chn] != NULL) {
debug(1, "deregister bus %d", chn);
xpt_bus_deregister(cam_sim_path(sc->mly_cam_sim[chn]));
debug(1, "free sim for channel %d (%sfree queue)", chn, first ? "" : "don't ");
cam_sim_free(sc->mly_cam_sim[chn], first ? TRUE : FALSE);
first = 0;
}
}
}
/********************************************************************************
* Handle an action requested by CAM
*/
static void
mly_cam_action(struct cam_sim *sim, union ccb *ccb)
{
struct mly_softc *sc = cam_sim_softc(sim);
debug_called(2);
switch (ccb->ccb_h.func_code) {
/* perform SCSI I/O */
case XPT_SCSI_IO:
{
struct ccb_scsiio *csio = &ccb->csio;
int bus, target;
bus = cam_sim_bus(sim);
target = csio->ccb_h.target_id;
debug(2, "XPT_SCSI_IO %d:%d:%d", bus, target, ccb->ccb_h.target_lun);
/* check for I/O attempt to a protected device */
if (sc->mly_btl[bus][target].mb_flags & MLY_BTL_PROTECTED) {
debug(2, " device protected");
csio->ccb_h.status = CAM_REQ_CMP_ERR;
}
/* check for I/O attempt to nonexistent device */
if (!(sc->mly_btl[bus][target].mb_flags & (MLY_BTL_LOGICAL | MLY_BTL_PHYSICAL))) {
debug(2, " device does not exist");
csio->ccb_h.status = CAM_REQ_CMP_ERR;
}
/* XXX increase if/when we support large SCSI commands */
if (csio->cdb_len > MLY_CMD_SCSI_SMALL_CDB) {
debug(2, " command too large (%d > %d)", csio->cdb_len, MLY_CMD_SCSI_SMALL_CDB);
csio->ccb_h.status = CAM_REQ_CMP_ERR;
}
/* check that the CDB pointer is not to a physical address */
if ((csio->ccb_h.flags & CAM_CDB_POINTER) && (csio->ccb_h.flags & CAM_CDB_PHYS)) {
debug(2, " CDB pointer is to physical address");
csio->ccb_h.status = CAM_REQ_CMP_ERR;
}
/* if there is data transfer, it must be to/from a virtual address */
if ((csio->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
if (csio->ccb_h.flags & CAM_DATA_PHYS) { /* we can't map it */
debug(2, " data pointer is to physical address");
csio->ccb_h.status = CAM_REQ_CMP_ERR;
}
if (csio->ccb_h.flags & CAM_SCATTER_VALID) { /* we want to do the s/g setup */
debug(2, " data has premature s/g setup");
csio->ccb_h.status = CAM_REQ_CMP_ERR;
}
}
/* abandon aborted ccbs or those that have failed validation */
if ((csio->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) {
debug(2, "abandoning CCB due to abort/validation failure");
break;
}
/* save the channel number in the ccb */
csio->ccb_h.sim_priv.entries[0].field = bus;
/* enqueue the ccb and start I/O */
mly_enqueue_ccb(sc, ccb);
mly_startio(sc);
return;
}
/* perform geometry calculations */
case XPT_CALC_GEOMETRY:
{
struct ccb_calc_geometry *ccg = &ccb->ccg;
u_int32_t secs_per_cylinder;
debug(2, "XPT_CALC_GEOMETRY %d:%d:%d", cam_sim_bus(sim), ccb->ccb_h.target_id, ccb->ccb_h.target_lun);
if (sc->mly_controllerparam->bios_geometry == MLY_BIOSGEOM_8G) {
ccg->heads = 255;
ccg->secs_per_track = 63;
} else { /* MLY_BIOSGEOM_2G */
ccg->heads = 128;
ccg->secs_per_track = 32;
}
secs_per_cylinder = ccg->heads * ccg->secs_per_track;
ccg->cylinders = ccg->volume_size / secs_per_cylinder;
ccb->ccb_h.status = CAM_REQ_CMP;
break;
}
/* handle path attribute inquiry */
case XPT_PATH_INQ:
{
struct ccb_pathinq *cpi = &ccb->cpi;
debug(2, "XPT_PATH_INQ %d:%d:%d", cam_sim_bus(sim), ccb->ccb_h.target_id, ccb->ccb_h.target_lun);
cpi->version_num = 1;
cpi->hba_inquiry = PI_TAG_ABLE; /* XXX extra flags for physical channels? */
cpi->target_sprt = 0;
cpi->hba_misc = 0;
cpi->max_target = MLY_MAX_TARGETS - 1;
cpi->max_lun = MLY_MAX_LUNS - 1;
cpi->initiator_id = sc->mly_controllerparam->initiator_id;
strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
strncpy(cpi->hba_vid, "BSDi", HBA_IDLEN);
strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
cpi->unit_number = cam_sim_unit(sim);
cpi->bus_id = cam_sim_bus(sim);
cpi->base_transfer_speed = 132 * 1024; /* XXX what to set this to? */
ccb->ccb_h.status = CAM_REQ_CMP;
break;
}
case XPT_GET_TRAN_SETTINGS:
{
struct ccb_trans_settings *cts = &ccb->cts;
int bus, target;
bus = cam_sim_bus(sim);
target = cts->ccb_h.target_id;
debug(2, "XPT_GET_TRAN_SETTINGS %d:%d", bus, target);
cts->valid = 0;
/* logical device? */
if (sc->mly_btl[bus][target].mb_flags & MLY_BTL_LOGICAL) {
/* nothing special for these */
/* physical device? */
} else if (sc->mly_btl[bus][target].mb_flags & MLY_BTL_PHYSICAL) {
/* allow CAM to try tagged transactions */
cts->flags |= CCB_TRANS_TAG_ENB;
cts->valid |= CCB_TRANS_TQ_VALID;
/* convert speed (MHz) to usec */
if (sc->mly_btl[bus][target].mb_speed == 0) {
cts->sync_period = 1000000 / 5;
} else {
cts->sync_period = 1000000 / sc->mly_btl[bus][target].mb_speed;
}
/* convert bus width to CAM internal encoding */
switch (sc->mly_btl[bus][target].mb_width) {
case 32:
cts->bus_width = MSG_EXT_WDTR_BUS_32_BIT;
break;
case 16:
cts->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
break;
case 8:
default:
cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
break;
}
cts->valid |= CCB_TRANS_SYNC_RATE_VALID | CCB_TRANS_BUS_WIDTH_VALID;
/* not a device, bail out */
} else {
cts->ccb_h.status = CAM_REQ_CMP_ERR;
break;
}
/* disconnect always OK */
cts->flags |= CCB_TRANS_DISC_ENB;
cts->valid |= CCB_TRANS_DISC_VALID;
cts->ccb_h.status = CAM_REQ_CMP;
break;
}
default: /* we can't do this */
debug(2, "unspported func_code = 0x%x", ccb->ccb_h.func_code);
ccb->ccb_h.status = CAM_REQ_INVALID;
break;
}
xpt_done(ccb);
}
/********************************************************************************
* Check for possibly-completed commands.
*/
static void
mly_cam_poll(struct cam_sim *sim)
{
struct mly_softc *sc = cam_sim_softc(sim);
debug_called(2);
mly_done(sc);
}
/********************************************************************************
* Pull a CCB off the work queue and turn it into a command.
*/
int
mly_cam_command(struct mly_softc *sc, struct mly_command **mcp)
{
struct mly_command *mc;
struct mly_command_scsi_small *ss;
struct ccb_scsiio *csio;
int error;
debug_called(2);
error = 0;
mc = NULL;
csio = NULL;
/* check for a CCB */
if (!(csio = (struct ccb_scsiio *)mly_dequeue_ccb(sc)))
goto out;
/* get a command to back it */
if (mly_alloc_command(sc, &mc)) {
error = ENOMEM;
goto out;
}
/* build the command */
mc->mc_data = csio->data_ptr;
mc->mc_length = csio->dxfer_len;
mc->mc_complete = mly_cam_complete;
mc->mc_private = csio;
/* build the packet for the controller */
ss = &mc->mc_packet->scsi_small;
ss->opcode = MDACMD_SCSI;
if (csio->ccb_h.flags * CAM_DIS_DISCONNECT)
ss->command_control.disable_disconnect = 1;
if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT)
ss->command_control.data_direction = MLY_CCB_WRITE;
ss->data_size = csio->dxfer_len;
ss->addr.phys.lun = csio->ccb_h.target_lun;
ss->addr.phys.target = csio->ccb_h.target_id;
ss->addr.phys.channel = csio->ccb_h.sim_priv.entries[0].field;
if (csio->ccb_h.timeout < (60 * 1000)) {
ss->timeout.value = csio->ccb_h.timeout / 1000;
ss->timeout.scale = MLY_TIMEOUT_SECONDS;
} else if (csio->ccb_h.timeout < (60 * 60 * 1000)) {
ss->timeout.value = csio->ccb_h.timeout / (60 * 1000);
ss->timeout.scale = MLY_TIMEOUT_MINUTES;
} else {
ss->timeout.value = csio->ccb_h.timeout / (60 * 60 * 1000); /* overflow? */
ss->timeout.scale = MLY_TIMEOUT_HOURS;
}
ss->maximum_sense_size = csio->sense_len;
ss->cdb_length = csio->cdb_len;
if (csio->ccb_h.flags & CAM_CDB_POINTER) {
bcopy(csio->cdb_io.cdb_ptr, ss->cdb, csio->cdb_len);
} else {
bcopy(csio->cdb_io.cdb_bytes, ss->cdb, csio->cdb_len);
}
out:
if (error != 0) {
if (mc != NULL) {
mly_release_command(mc);
mc = NULL;
}
if (csio != NULL)
mly_requeue_ccb(sc, (union ccb *)csio);
}
*mcp = mc;
return(error);
}
/********************************************************************************
* Handle completion of a command - pass results back through the CCB
*/
static void
mly_cam_complete(struct mly_command *mc)
{
struct mly_softc *sc = mc->mc_sc;
struct ccb_scsiio *csio = (struct ccb_scsiio *)mc->mc_private;
struct scsi_inquiry_data *inq = (struct scsi_inquiry_data *)csio->data_ptr;
struct mly_btl *btl;
u_int8_t cmd;
int bus, target;
debug_called(2);
csio->scsi_status = mc->mc_status;
switch(mc->mc_status) {
case SCSI_STATUS_OK:
/*
* In order to report logical device type and status, we overwrite
* the result of the INQUIRY command to logical devices.
*/
bus = csio->ccb_h.sim_priv.entries[0].field;
if (bus >= sc->mly_controllerinfo->physical_channels_present) {
if (csio->ccb_h.flags & CAM_CDB_POINTER) {
cmd = *csio->cdb_io.cdb_ptr;
} else {
cmd = csio->cdb_io.cdb_bytes[0];
}
if (cmd == INQUIRY) {
target = csio->ccb_h.target_id;
btl = &sc->mly_btl[bus][target];
padstr(inq->vendor, mly_describe_code(mly_table_device_type, btl->mb_type), 8);
padstr(inq->product, mly_describe_code(mly_table_device_state, btl->mb_state), 16);
padstr(inq->revision, "", 4);
}
}
debug(2, "SCSI_STATUS_OK");
csio->ccb_h.status = CAM_REQ_CMP;
break;
case SCSI_STATUS_CHECK_COND:
debug(2, "SCSI_STATUS_CHECK_COND sense %d resid %d", mc->mc_sense, mc->mc_resid);
csio->ccb_h.status = CAM_SCSI_STATUS_ERROR;
bzero(&csio->sense_data, SSD_FULL_SIZE);
bcopy(mc->mc_packet, &csio->sense_data, mc->mc_sense);
csio->sense_len = mc->mc_sense;
csio->ccb_h.status |= CAM_AUTOSNS_VALID;
csio->resid = mc->mc_resid; /* XXX this is a signed value... */
break;
case SCSI_STATUS_BUSY:
debug(2, "SCSI_STATUS_BUSY");
csio->ccb_h.status = CAM_SCSI_BUSY;
break;
default:
debug(2, "unknown status 0x%x", csio->scsi_status);
csio->ccb_h.status = CAM_REQ_CMP_ERR;
break;
}
xpt_done((union ccb *)csio);
mly_release_command(mc);
}
/********************************************************************************
* Find a peripheral attahed at (bus),(target)
*/
static struct cam_periph *
mly_find_periph(struct mly_softc *sc, int bus, int target)
{
struct cam_periph *periph;
struct cam_path *path;
int status;
status = xpt_create_path(&path, NULL, cam_sim_path(sc->mly_cam_sim[bus]), target, 0);
if (status == CAM_REQ_CMP) {
periph = cam_periph_find(path, NULL);
xpt_free_path(path);
} else {
periph = NULL;
}
return(periph);
}
/********************************************************************************
* Name the device at (bus)(target)
*/
int
mly_name_device(struct mly_softc *sc, int bus, int target)
{
struct cam_periph *periph;
if ((periph = mly_find_periph(sc, bus, target)) != NULL) {
sprintf(sc->mly_btl[bus][target].mb_name, "%s%d", periph->periph_name, periph->unit_number);
return(0);
}
sc->mly_btl[bus][target].mb_name[0] = 0;
return(ENOENT);
}

View File

@ -1,577 +0,0 @@
/*-
* Copyright (c) 2000, 2001 Michael Smith
* Copyright (c) 2000 BSDi
* 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.
*
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/devicestat.h>
#include <sys/disk.h>
#include <machine/bus_memio.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>
#include <pci/pcireg.h>
#include <pci/pcivar.h>
#include <dev/mly/mlyreg.h>
#include <dev/mly/mlyio.h>
#include <dev/mly/mlyvar.h>
static int mly_pci_probe(device_t dev);
static int mly_pci_attach(device_t dev);
static int mly_pci_detach(device_t dev);
static int mly_pci_shutdown(device_t dev);
static int mly_pci_suspend(device_t dev);
static int mly_pci_resume(device_t dev);
static void mly_pci_intr(void *arg);
static int mly_sg_map(struct mly_softc *sc);
static void mly_sg_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error);
static int mly_mmbox_map(struct mly_softc *sc);
static void mly_mmbox_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error);
static device_method_t mly_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, mly_pci_probe),
DEVMETHOD(device_attach, mly_pci_attach),
DEVMETHOD(device_detach, mly_pci_detach),
DEVMETHOD(device_shutdown, mly_pci_shutdown),
DEVMETHOD(device_suspend, mly_pci_suspend),
DEVMETHOD(device_resume, mly_pci_resume),
{ 0, 0 }
};
static driver_t mly_pci_driver = {
"mly",
mly_methods,
sizeof(struct mly_softc)
};
static devclass_t mly_devclass;
DRIVER_MODULE(mly, pci, mly_pci_driver, mly_devclass, 0, 0);
struct mly_ident
{
u_int16_t vendor;
u_int16_t device;
u_int16_t subvendor;
u_int16_t subdevice;
int hwif;
char *desc;
} mly_identifiers[] = {
{0x1069, 0xba56, 0x1069, 0x0040, MLY_HWIF_STRONGARM, "Mylex eXtremeRAID 2000"},
{0x1069, 0xba56, 0x1069, 0x0030, MLY_HWIF_STRONGARM, "Mylex eXtremeRAID 3000"},
{0x1069, 0x0050, 0x1069, 0x0050, MLY_HWIF_I960RX, "Mylex AcceleRAID 352"},
{0x1069, 0x0050, 0x1069, 0x0052, MLY_HWIF_I960RX, "Mylex AcceleRAID 170"},
{0x1069, 0x0050, 0x1069, 0x0054, MLY_HWIF_I960RX, "Mylex AcceleRAID 160"},
{0, 0, 0, 0, 0, 0}
};
/********************************************************************************
********************************************************************************
Bus Interface
********************************************************************************
********************************************************************************/
static int
mly_pci_probe(device_t dev)
{
struct mly_ident *m;
debug_called(1);
for (m = mly_identifiers; m->vendor != 0; m++) {
if ((m->vendor == pci_get_vendor(dev)) &&
(m->device == pci_get_device(dev)) &&
((m->subvendor == 0) || ((m->subvendor == pci_get_subvendor(dev)) &&
(m->subdevice == pci_get_subdevice(dev))))) {
device_set_desc(dev, m->desc);
return(-10); /* allow room to be overridden */
}
}
return(ENXIO);
}
static int
mly_pci_attach(device_t dev)
{
struct mly_softc *sc;
int i, error;
u_int32_t command;
debug_called(1);
/*
* Initialise softc.
*/
sc = device_get_softc(dev);
bzero(sc, sizeof(*sc));
sc->mly_dev = dev;
#ifdef MLY_DEBUG
if (device_get_unit(sc->mly_dev) == 0)
mly_softc0 = sc;
#endif
/* assume failure is 'not configured' */
error = ENXIO;
/*
* Verify that the adapter is correctly set up in PCI space.
*/
command = pci_read_config(sc->mly_dev, PCIR_COMMAND, 2);
command |= PCIM_CMD_BUSMASTEREN;
pci_write_config(dev, PCIR_COMMAND, command, 2);
command = pci_read_config(sc->mly_dev, PCIR_COMMAND, 2);
if (!(command & PCIM_CMD_BUSMASTEREN)) {
mly_printf(sc, "can't enable busmaster feature\n");
goto fail;
}
if ((command & PCIM_CMD_MEMEN) == 0) {
mly_printf(sc, "memory window not available\n");
goto fail;
}
/*
* Allocate the PCI register window.
*/
sc->mly_regs_rid = PCIR_MAPS; /* first base address register */
if ((sc->mly_regs_resource = bus_alloc_resource(sc->mly_dev, SYS_RES_MEMORY, &sc->mly_regs_rid,
0, ~0, 1, RF_ACTIVE)) == NULL) {
mly_printf(sc, "can't allocate register window\n");
goto fail;
}
sc->mly_btag = rman_get_bustag(sc->mly_regs_resource);
sc->mly_bhandle = rman_get_bushandle(sc->mly_regs_resource);
/*
* Allocate and connect our interrupt.
*/
sc->mly_irq_rid = 0;
if ((sc->mly_irq = bus_alloc_resource(sc->mly_dev, SYS_RES_IRQ, &sc->mly_irq_rid,
0, ~0, 1, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
mly_printf(sc, "can't allocate interrupt\n");
goto fail;
}
if (bus_setup_intr(sc->mly_dev, sc->mly_irq, INTR_TYPE_CAM | INTR_ENTROPY, mly_pci_intr, sc, &sc->mly_intr)) {
mly_printf(sc, "can't set up interrupt\n");
goto fail;
}
/* assume failure is 'out of memory' */
error = ENOMEM;
/*
* Allocate the parent bus DMA tag appropriate for our PCI interface.
*
* Note that all of these controllers are 64-bit capable.
*/
if (bus_dma_tag_create(NULL, /* parent */
1, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
MAXBSIZE, MLY_MAXSGENTRIES, /* maxsize, nsegments */
BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
BUS_DMA_ALLOCNOW, /* flags */
&sc->mly_parent_dmat)) {
mly_printf(sc, "can't allocate parent DMA tag\n");
goto fail;
}
/*
* Create DMA tag for mapping buffers into controller-addressable space.
*/
if (bus_dma_tag_create(sc->mly_parent_dmat, /* parent */
1, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
MAXBSIZE, MLY_MAXSGENTRIES, /* maxsize, nsegments */
BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
0, /* flags */
&sc->mly_buffer_dmat)) {
mly_printf(sc, "can't allocate buffer DMA tag\n");
goto fail;
}
/*
* Initialise the DMA tag for command packets.
*/
if (bus_dma_tag_create(sc->mly_parent_dmat, /* parent */
1, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
sizeof(union mly_command_packet) * MLY_MAXCOMMANDS, 1, /* maxsize, nsegments */
BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
0, /* flags */
&sc->mly_packet_dmat)) {
mly_printf(sc, "can't allocate command packet DMA tag\n");
goto fail;
}
/*
* Detect the hardware interface version
*/
for (i = 0; mly_identifiers[i].vendor != 0; i++) {
if ((mly_identifiers[i].vendor == pci_get_vendor(dev)) &&
(mly_identifiers[i].device == pci_get_device(dev))) {
sc->mly_hwif = mly_identifiers[i].hwif;
switch(sc->mly_hwif) {
case MLY_HWIF_I960RX:
debug(2, "set hardware up for i960RX");
sc->mly_doorbell_true = 0x00;
sc->mly_command_mailbox = MLY_I960RX_COMMAND_MAILBOX;
sc->mly_status_mailbox = MLY_I960RX_STATUS_MAILBOX;
sc->mly_idbr = MLY_I960RX_IDBR;
sc->mly_odbr = MLY_I960RX_ODBR;
sc->mly_error_status = MLY_I960RX_ERROR_STATUS;
sc->mly_interrupt_status = MLY_I960RX_INTERRUPT_STATUS;
sc->mly_interrupt_mask = MLY_I960RX_INTERRUPT_MASK;
break;
case MLY_HWIF_STRONGARM:
debug(2, "set hardware up for StrongARM");
sc->mly_doorbell_true = 0xff; /* doorbell 'true' is 0 */
sc->mly_command_mailbox = MLY_STRONGARM_COMMAND_MAILBOX;
sc->mly_status_mailbox = MLY_STRONGARM_STATUS_MAILBOX;
sc->mly_idbr = MLY_STRONGARM_IDBR;
sc->mly_odbr = MLY_STRONGARM_ODBR;
sc->mly_error_status = MLY_STRONGARM_ERROR_STATUS;
sc->mly_interrupt_status = MLY_STRONGARM_INTERRUPT_STATUS;
sc->mly_interrupt_mask = MLY_STRONGARM_INTERRUPT_MASK;
break;
}
break;
}
}
/*
* Create the scatter/gather mappings.
*/
if ((error = mly_sg_map(sc)))
goto fail;
/*
* Allocate and map the memory mailbox
*/
if ((error = mly_mmbox_map(sc)))
goto fail;
/*
* Do bus-independent initialisation.
*/
if ((error = mly_attach(sc)))
goto fail;
return(0);
fail:
mly_free(sc);
return(error);
}
/********************************************************************************
* Disconnect from the controller completely, in preparation for unload.
*/
static int
mly_pci_detach(device_t dev)
{
struct mly_softc *sc = device_get_softc(dev);
int error;
debug_called(1);
if (sc->mly_state & MLY_STATE_OPEN)
return(EBUSY);
if ((error = mly_pci_shutdown(dev)))
return(error);
mly_free(sc);
return(0);
}
/********************************************************************************
* Bring the controller down to a dormant state and detach all child devices.
*
* This function is called before detach or system shutdown.
*
* Note that we can assume that the camq on the controller is empty, as we won't
* allow shutdown if any device is open.
*/
static int
mly_pci_shutdown(device_t dev)
{
struct mly_softc *sc = device_get_softc(dev);
debug_called(1);
mly_detach(sc);
return(0);
}
/********************************************************************************
* Bring the controller to a quiescent state, ready for system suspend.
*
* We can't assume that the controller is not active at this point, so we need
* to mask interrupts.
*/
static int
mly_pci_suspend(device_t dev)
{
struct mly_softc *sc = device_get_softc(dev);
int s;
debug_called(1);
s = splcam();
mly_detach(sc);
splx(s);
return(0);
}
/********************************************************************************
* Bring the controller back to a state ready for operation.
*/
static int
mly_pci_resume(device_t dev)
{
struct mly_softc *sc = device_get_softc(dev);
debug_called(1);
sc->mly_state &= ~MLY_STATE_SUSPEND;
MLY_UNMASK_INTERRUPTS(sc);
return(0);
}
/*******************************************************************************
* Take an interrupt, or be poked by other code to look for interrupt-worthy
* status.
*/
static void
mly_pci_intr(void *arg)
{
struct mly_softc *sc = (struct mly_softc *)arg;
debug_called(3);
/* collect finished commands, queue anything waiting */
mly_done(sc);
};
/********************************************************************************
********************************************************************************
Bus-dependant Resource Management
********************************************************************************
********************************************************************************/
/********************************************************************************
* Allocate memory for the scatter/gather tables
*/
static int
mly_sg_map(struct mly_softc *sc)
{
size_t segsize;
debug_called(1);
/*
* Create a single tag describing a region large enough to hold all of
* the s/g lists we will need.
*/
segsize = sizeof(struct mly_sg_entry) * MLY_MAXCOMMANDS * MLY_MAXSGENTRIES;
if (bus_dma_tag_create(sc->mly_parent_dmat, /* parent */
1, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
segsize, 1, /* maxsize, nsegments */
BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
0, /* flags */
&sc->mly_sg_dmat)) {
mly_printf(sc, "can't allocate scatter/gather DMA tag\n");
return(ENOMEM);
}
/*
* Allocate enough s/g maps for all commands and permanently map them into
* controller-visible space.
*
* XXX this assumes we can get enough space for all the s/g maps in one
* contiguous slab.
*/
if (bus_dmamem_alloc(sc->mly_sg_dmat, (void **)&sc->mly_sg_table, BUS_DMA_NOWAIT, &sc->mly_sg_dmamap)) {
mly_printf(sc, "can't allocate s/g table\n");
return(ENOMEM);
}
bus_dmamap_load(sc->mly_sg_dmat, sc->mly_sg_dmamap, sc->mly_sg_table, segsize, mly_sg_map_helper, sc, 0);
return(0);
}
/********************************************************************************
* Save the physical address of the base of the s/g table.
*/
static void
mly_sg_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error)
{
struct mly_softc *sc = (struct mly_softc *)arg;
debug_called(2);
/* save base of s/g table's address in bus space */
sc->mly_sg_busaddr = segs->ds_addr;
}
/********************************************************************************
* Allocate memory for the memory-mailbox interface
*/
static int
mly_mmbox_map(struct mly_softc *sc)
{
/*
* Create a DMA tag for a single contiguous region large enough for the
* memory mailbox structure.
*/
if (bus_dma_tag_create(sc->mly_parent_dmat, /* parent */
1, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
sizeof(struct mly_mmbox), 1, /* maxsize, nsegments */
BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
0, /* flags */
&sc->mly_mmbox_dmat)) {
mly_printf(sc, "can't allocate memory mailbox DMA tag\n");
return(ENOMEM);
}
/*
* Allocate the buffer
*/
if (bus_dmamem_alloc(sc->mly_mmbox_dmat, (void **)&sc->mly_mmbox, BUS_DMA_NOWAIT, &sc->mly_mmbox_dmamap)) {
mly_printf(sc, "can't allocate memory mailbox\n");
return(ENOMEM);
}
bus_dmamap_load(sc->mly_mmbox_dmat, sc->mly_mmbox_dmamap, sc->mly_mmbox, sizeof(struct mly_mmbox),
mly_mmbox_map_helper, sc, 0);
bzero(sc->mly_mmbox, sizeof(*sc->mly_mmbox));
return(0);
}
/********************************************************************************
* Save the physical address of the memory mailbox
*/
static void
mly_mmbox_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error)
{
struct mly_softc *sc = (struct mly_softc *)arg;
debug_called(2);
sc->mly_mmbox_busaddr = segs->ds_addr;
}
/********************************************************************************
* Free all of the resources associated with (sc)
*
* Should not be called if the controller is active.
*/
void
mly_free(struct mly_softc *sc)
{
struct mly_command *mc;
debug_called(1);
/* detach from CAM */
mly_cam_detach(sc);
/* throw away command buffer DMA maps */
while (mly_alloc_command(sc, &mc) == 0)
bus_dmamap_destroy(sc->mly_buffer_dmat, mc->mc_datamap);
/* release the packet storage */
if (sc->mly_packet != NULL) {
bus_dmamap_unload(sc->mly_packet_dmat, sc->mly_packetmap);
bus_dmamem_free(sc->mly_packet_dmat, sc->mly_packet, sc->mly_packetmap);
}
/* throw away the controllerinfo structure */
if (sc->mly_controllerinfo != NULL)
free(sc->mly_controllerinfo, M_DEVBUF);
/* throw away the controllerparam structure */
if (sc->mly_controllerparam != NULL)
free(sc->mly_controllerparam, M_DEVBUF);
/* destroy data-transfer DMA tag */
if (sc->mly_buffer_dmat)
bus_dma_tag_destroy(sc->mly_buffer_dmat);
/* free and destroy DMA memory and tag for s/g lists */
if (sc->mly_sg_table) {
bus_dmamap_unload(sc->mly_sg_dmat, sc->mly_sg_dmamap);
bus_dmamem_free(sc->mly_sg_dmat, sc->mly_sg_table, sc->mly_sg_dmamap);
}
if (sc->mly_sg_dmat)
bus_dma_tag_destroy(sc->mly_sg_dmat);
/* free and destroy DMA memory and tag for memory mailbox */
if (sc->mly_mmbox) {
bus_dmamap_unload(sc->mly_mmbox_dmat, sc->mly_mmbox_dmamap);
bus_dmamem_free(sc->mly_mmbox_dmat, sc->mly_mmbox, sc->mly_mmbox_dmamap);
}
if (sc->mly_mmbox_dmat)
bus_dma_tag_destroy(sc->mly_mmbox_dmat);
/* disconnect the interrupt handler */
if (sc->mly_intr)
bus_teardown_intr(sc->mly_dev, sc->mly_irq, sc->mly_intr);
if (sc->mly_irq != NULL)
bus_release_resource(sc->mly_dev, SYS_RES_IRQ, sc->mly_irq_rid, sc->mly_irq);
/* destroy the parent DMA tag */
if (sc->mly_parent_dmat)
bus_dma_tag_destroy(sc->mly_parent_dmat);
/* release the register window mapping */
if (sc->mly_regs_resource != NULL)
bus_release_resource(sc->mly_dev, SYS_RES_MEMORY, sc->mly_regs_rid, sc->mly_regs_resource);
}

View File

@ -35,26 +35,12 @@ struct mly_code_lookup {
u_int32_t code;
};
extern char *mly_describe_code(struct mly_code_lookup *table, u_int32_t code);
#ifndef MLY_DEFINE_TABLES
extern struct mly_code_lookup mly_table_bustype[];
extern struct mly_code_lookup mly_table_controllertype[];
extern struct mly_code_lookup mly_table_oemname[];
extern struct mly_code_lookup mly_table_memorytype[];
extern struct mly_code_lookup mly_table_cputype[];
extern struct mly_code_lookup mly_table_event[];
extern struct mly_code_lookup mly_table_device_state[];
extern struct mly_code_lookup mly_table_device_type[];
extern struct mly_code_lookup mly_table_stripe_size[];
extern struct mly_code_lookup mly_table_cacheline_size[];
#else /* MLY_DEFINE_TABLES */
static char *mly_describe_code(struct mly_code_lookup *table, u_int32_t code);
/********************************************************************************
* Look up a text description of a numeric code and return a pointer to same.
*/
char *
static char *
mly_describe_code(struct mly_code_lookup *table, u_int32_t code)
{
int i;
@ -65,7 +51,7 @@ mly_describe_code(struct mly_code_lookup *table, u_int32_t code)
return(table[i+1].string);
}
struct mly_code_lookup mly_table_bustype[] = {
static struct mly_code_lookup mly_table_bustype[] = {
{"SCSI", 0x00},
{"FC-AL", 0x01},
{"PCI", 0x03},
@ -73,7 +59,7 @@ struct mly_code_lookup mly_table_bustype[] = {
{"unknown bus", 0}
};
struct mly_code_lookup mly_table_controllertype[] = {
static struct mly_code_lookup mly_table_controllertype[] = {
#if 0 /* not supported by this driver */
{"DAC960E", 0x01}, /* EISA */
{"DAC960M", 0x08}, /* MCA */
@ -99,7 +85,7 @@ struct mly_code_lookup mly_table_controllertype[] = {
{"unknown adapter", 0}
};
struct mly_code_lookup mly_table_oemname[] = {
static struct mly_code_lookup mly_table_oemname[] = {
{"Mylex", MLY_OEM_MYLEX},
{"IBM", MLY_OEM_IBM},
{"Hewlett-Packard", MLY_OEM_HP},
@ -110,7 +96,7 @@ struct mly_code_lookup mly_table_oemname[] = {
{"unknown OEM", 0}
};
struct mly_code_lookup mly_table_memorytype[] = {
static struct mly_code_lookup mly_table_memorytype[] = {
{"DRAM", 0x01},
{"EDRAM", 0x02},
{"EDO RAM", 0x03},
@ -119,7 +105,7 @@ struct mly_code_lookup mly_table_memorytype[] = {
{"unknown memory", 0}
};
struct mly_code_lookup mly_table_cputype[] = {
static struct mly_code_lookup mly_table_cputype[] = {
{"i960CA", 0x01},
{"i960RD", 0x02},
{"i960RN", 0x03},
@ -153,7 +139,7 @@ struct mly_code_lookup mly_table_cputype[] = {
* r rescan the device for possible state change
*
*/
struct mly_code_lookup mly_table_event[] = {
static struct mly_code_lookup mly_table_event[] = {
/* physical device events (0x0000 - 0x007f) */
{"pr online", 0x0001},
{"pr standby", 0x0002},
@ -266,7 +252,7 @@ struct mly_code_lookup mly_table_event[] = {
* Values here must be 16 characters or less, as they are packed into
* the 'product' field in the SCSI inquiry data.
*/
struct mly_code_lookup mly_table_device_state[] = {
static struct mly_code_lookup mly_table_device_state[] = {
{"offline", MLY_DEVICE_STATE_OFFLINE},
{"unconfigured", MLY_DEVICE_STATE_UNCONFIGURED},
{"online", MLY_DEVICE_STATE_ONLINE},
@ -282,7 +268,7 @@ struct mly_code_lookup mly_table_device_state[] = {
* Values here must be 8 characters or less, as they are packed into
* the 'vendor' field in the SCSI inquiry data.
*/
struct mly_code_lookup mly_table_device_type[] = {
static struct mly_code_lookup mly_table_device_type[] = {
{"RAID 0", MLY_DEVICE_TYPE_RAID0},
{"RAID 1", MLY_DEVICE_TYPE_RAID1},
{"RAID 3", MLY_DEVICE_TYPE_RAID3}, /* right asymmetric parity */
@ -300,7 +286,7 @@ struct mly_code_lookup mly_table_device_type[] = {
{"UNKNOWN", 0}
};
struct mly_code_lookup mly_table_stripe_size[] = {
static struct mly_code_lookup mly_table_stripe_size[] = {
{"NONE", MLY_STRIPE_ZERO},
{"512B", MLY_STRIPE_512b},
{"1k", MLY_STRIPE_1k},
@ -318,7 +304,7 @@ struct mly_code_lookup mly_table_stripe_size[] = {
{"unknown", 0}
};
struct mly_code_lookup mly_table_cacheline_size[] = {
static struct mly_code_lookup mly_table_cacheline_size[] = {
{"NONE", MLY_CACHELINE_ZERO},
{"512B", MLY_CACHELINE_512b},
{"1k", MLY_CACHELINE_1k},
@ -331,5 +317,3 @@ struct mly_code_lookup mly_table_cacheline_size[] = {
{NULL, 0},
{"unknown", 0}
};
#endif /* MLY_DEFINE_TABLES */

View File

@ -59,11 +59,9 @@ struct mly_user_health
*/
#define MLYQ_FREE 0
#define MLYQ_CCB 1
#define MLYQ_READY 2
#define MLYQ_BUSY 3
#define MLYQ_COMPLETE 4
#define MLYQ_COUNT 5
#define MLYQ_BUSY 1
#define MLYQ_COMPLETE 2
#define MLYQ_COUNT 3
struct mly_qstat
{

View File

@ -38,13 +38,18 @@
* table this size (256k) would be too expensive, so we cap ourselves at a
* reasonable limit.
*/
#define MLY_MAXCOMMANDS 256 /* max commands per controller */
#define MLY_MAX_COMMANDS 256 /* max commands per controller */
/*
* The firmware interface allows for a 16-bit s/g list length. We limit
* ourselves to a reasonable maximum and ensure alignment.
*/
#define MLY_MAXSGENTRIES 64 /* max S/G entries, limit 65535 */
#define MLY_MAX_SGENTRIES 64 /* max S/G entries, limit 65535 */
/*
* The interval at which we poke the controller for status updates (in seconds).
*/
#define MLY_PERIODIC_INTERVAL 1
/********************************************************************************
********************************************************************************
@ -62,6 +67,10 @@
# define offsetof(type, field) ((size_t)(&((type *)0)->field))
#endif
#ifndef INTR_ENTROPY
# define INTR_ENTROPY 0
#endif
/********************************************************************************
********************************************************************************
Driver Variable Definitions
@ -147,7 +156,7 @@ struct mly_command {
* We can't use slot 0 due to the memory mailbox implementation.
*/
#define MLY_SLOT_START 1
#define MLY_SLOT_MAX (MLY_SLOT_START + MLY_MAXCOMMANDS)
#define MLY_SLOT_MAX (MLY_SLOT_START + MLY_MAX_COMMANDS)
/*
* Per-controller structure.
@ -193,22 +202,21 @@ struct mly_softc {
/* controller features, limits and status */
int mly_state;
#define MLY_STATE_SUSPEND (1<<0)
#define MLY_STATE_OPEN (1<<1)
#define MLY_STATE_INTERRUPTS_ON (1<<2)
#define MLY_STATE_MMBOX_ACTIVE (1<<3)
#define MLY_STATE_CAM_FROZEN (1<<4)
struct mly_ioctl_getcontrollerinfo *mly_controllerinfo;
struct mly_param_controller *mly_controllerparam;
struct mly_btl mly_btl[MLY_MAX_CHANNELS][MLY_MAX_TARGETS];
/* command management */
struct mly_command mly_command[MLY_MAXCOMMANDS]; /* commands */
struct mly_command mly_command[MLY_MAX_COMMANDS]; /* commands */
union mly_command_packet *mly_packet; /* command packets */
bus_dma_tag_t mly_packet_dmat; /* packet DMA tag */
bus_dmamap_t mly_packetmap; /* packet DMA map */
u_int64_t mly_packetphys; /* packet array base address */
TAILQ_HEAD(,mly_command) mly_free; /* commands available for reuse */
TAILQ_HEAD(,mly_command) mly_ready; /* commands ready to be submitted */
TAILQ_HEAD(,mly_command) mly_busy;
TAILQ_HEAD(,mly_command) mly_complete; /* commands which have been returned by the controller */
struct mly_qstat mly_qstat[MLYQ_COUNT]; /* queue statistics */
@ -220,9 +228,10 @@ struct mly_softc {
struct callout_handle mly_periodic; /* periodic event handling */
/* CAM connection */
TAILQ_HEAD(,ccb_hdr) mly_cam_ccbq; /* outstanding I/O from CAM */
struct cam_sim *mly_cam_sim[MLY_MAX_CHANNELS];
int mly_cam_lowbus;
struct cam_devq *mly_cam_devq; /* CAM device queue */
struct cam_sim *mly_cam_sim[MLY_MAX_CHANNELS]; /* CAM SIMs */
struct cam_path *mly_cam_path; /* rescan path */
int mly_cam_channels; /* total channel count */
#if __FreeBSD_version >= 500005
/* command-completion task */
@ -272,28 +281,15 @@ struct mly_softc {
} while(0);
/*
* Logical device number -> bus/target translation
* Bus/target/logical ID-related macros.
*/
#define MLY_LOGDEV_BUS(sc, x) (((x) / MLY_MAX_TARGETS) + (sc)->mly_controllerinfo->physical_channels_present)
#define MLY_LOGDEV_TARGET(x) ((x) % MLY_MAX_TARGETS)
/*
* Public functions/variables
*/
/* mly.c */
extern int mly_attach(struct mly_softc *sc);
extern void mly_detach(struct mly_softc *sc);
extern void mly_free(struct mly_softc *sc);
extern void mly_startio(struct mly_softc *sc);
extern void mly_done(struct mly_softc *sc);
extern int mly_alloc_command(struct mly_softc *sc, struct mly_command **mcp);
extern void mly_release_command(struct mly_command *mc);
/* mly_cam.c */
extern int mly_cam_attach(struct mly_softc *sc);
extern void mly_cam_detach(struct mly_softc *sc);
extern int mly_cam_command(struct mly_softc *sc, struct mly_command **mcp);
extern int mly_name_device(struct mly_softc *sc, int bus, int target);
#define MLY_LOGDEV_ID(sc, bus, target) (((bus) - (sc)->mly_controllerinfo->physical_channels_present) * \
MLY_MAX_TARGETS + (target))
#define MLY_LOGDEV_BUS(sc, logdev) (((logdev) / MLY_MAX_TARGETS) + \
(sc)->mly_controllerinfo->physical_channels_present)
#define MLY_LOGDEV_TARGET(sc, logdev) ((logdev) % MLY_MAX_TARGETS)
#define MLY_BUS_IS_VIRTUAL(sc, bus) ((bus) >= (sc)->mly_controllerinfo->physical_channels_present)
#define MLY_BUS_IS_VALID(sc, bus) (((bus) < (sc)->mly_cam_channels) && ((sc)->mly_cam_sim[(bus)] != NULL))
/********************************************************************************
* Queue primitives
@ -370,7 +366,20 @@ mly_remove_ ## name (struct mly_command *mc) \
struct hack
MLYQ_COMMAND_QUEUE(free, MLYQ_FREE);
MLYQ_COMMAND_QUEUE(ready, MLYQ_READY);
MLYQ_COMMAND_QUEUE(busy, MLYQ_BUSY);
MLYQ_COMMAND_QUEUE(complete, MLYQ_COMPLETE);
/********************************************************************************
* space-fill a character string
*/
static __inline void
padstr(char *targ, char *src, int len)
{
while (len-- > 0) {
if (*src != 0) {
*targ++ = *src++;
} else {
*targ++ = ' ';
}
}
}

View File

@ -3,10 +3,11 @@
.PATH: ${.CURDIR}/../../dev/mly
KMOD= mly
SRCS= mly.c mly_pci.c mly_cam.c
SRCS= mly.c
SRCS+= opt_scsi.h opt_cam.h
SRCS+= device_if.h bus_if.h pci_if.h
#CFLAGS+= -DMLY_DEBUG=1
CFLAGS+= -DMLY_MODULE
.include <bsd.kmod.mk>