freebsd-skq/sys/pci/simos.c

351 lines
7.4 KiB
C
Raw Normal View History

/*-
* Copyright (c) 1998 Doug Rabson
* 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.
*
1999-08-28 01:08:13 +00:00
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/bio.h>
#include <sys/buf.h>
#include <sys/proc.h>
1998-09-26 14:49:26 +00:00
#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_sim.h>
#include <cam/cam_xpt_sim.h>
#include <cam/cam_debug.h>
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_message.h>
#include <machine/clock.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <sys/kernel.h>
#include <pci/simos.h>
#include <pci/pcireg.h>
#include <pci/pcivar.h>
#ifndef COMPAT_OLDPCI
#error "The simos device requires the old pci compatibility shims"
#endif
#include <machine/alpha_cpu.h>
struct simos_softc {
int sc_unit;
SimOS_SCSI* sc_regs;
1998-09-26 14:49:26 +00:00
/*
* SimOS only supports one pending command.
*/
struct cam_sim *sc_sim;
struct cam_path *sc_path;
struct ccb_scsiio *sc_pending;
};
struct simos_softc* simosp[10];
static u_long simos_unit;
static const char *simos_probe __P((pcici_t tag, pcidi_t type));
static void simos_attach __P((pcici_t config_d, int unit));
1998-09-26 14:49:26 +00:00
static void simos_action __P((struct cam_sim *sim, union ccb *ccb));
static void simos_poll __P((struct cam_sim *sim));
struct pci_device simos_driver = {
"simos",
simos_probe,
simos_attach,
&simos_unit,
NULL
};
COMPAT_PCI_DRIVER (simos, simos_driver);
static const char *
simos_probe(pcici_t tag, pcidi_t type)
{
switch (type) {
case 0x1291|(0x1291<<16):
return "SimOS SCSI";
default:
return NULL;
}
}
static void
simos_attach(pcici_t config_id, int unit)
{
struct simos_softc* sc;
1998-09-26 14:49:26 +00:00
struct cam_devq *devq;
sc = malloc(sizeof(struct simos_softc), M_DEVBUF, M_WAITOK | M_ZERO);
simosp[unit] = sc;
sc->sc_unit = unit;
sc->sc_regs = (SimOS_SCSI*) SIMOS_SCSI_ADDR;
1998-09-26 14:49:26 +00:00
sc->sc_pending = 0;
1998-09-26 14:49:26 +00:00
devq = cam_simq_alloc(/*maxopenings*/1);
if (devq == NULL)
return;
sc->sc_sim = cam_sim_alloc(simos_action, simos_poll, "simos", sc, unit,
/*untagged*/1, /*tagged*/0, devq);
if (sc->sc_sim == NULL) {
cam_simq_free(devq);
return;
}
1998-09-26 14:49:26 +00:00
if (xpt_bus_register(sc->sc_sim, /*bus*/0) != CAM_SUCCESS) {
cam_sim_free(sc->sc_sim, /*free_devq*/TRUE);
return;
}
if (xpt_create_path(&sc->sc_path, /*periph*/NULL,
cam_sim_path(sc->sc_sim), CAM_TARGET_WILDCARD,
CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
xpt_bus_deregister(cam_sim_path(sc->sc_sim));
cam_sim_free(sc->sc_sim, /*free_devq*/TRUE);
return;
}
alpha_register_pci_scsi(config_id->bus, config_id->slot, sc->sc_sim);
return;
}
static void
1998-09-26 14:49:26 +00:00
simos_start(struct simos_softc* sc, struct ccb_scsiio *csio)
{
1998-09-26 14:49:26 +00:00
struct scsi_generic *cmd;
int cmdlen;
caddr_t data;
int datalen;
int s;
u_int8_t* p;
int i, count, target;
vm_offset_t va;
vm_size_t size;
1998-09-26 14:49:26 +00:00
cmd = (struct scsi_generic *) &csio->cdb_io.cdb_bytes;
cmdlen = csio->cdb_len;
data = csio->data_ptr;
datalen = csio->dxfer_len;
/*
* Simos doesn't understand some commands
*/
if (cmd->opcode == START_STOP || cmd->opcode == PREVENT_ALLOW
|| cmd->opcode == SYNCHRONIZE_CACHE) {
csio->ccb_h.status = CAM_REQ_CMP;
xpt_done((union ccb *) csio);
return;
1998-09-26 14:49:26 +00:00
}
1998-09-26 14:49:26 +00:00
if (sc->sc_pending) {
/*
* Don't think this can happen.
*/
printf("simos_start: can't start command while one is pending\n");
csio->ccb_h.status = CAM_BUSY;
xpt_done((union ccb *) csio);
return;
}
s = splcam();
csio->ccb_h.status |= CAM_SIM_QUEUED;
sc->sc_pending = csio;
1998-09-26 14:49:26 +00:00
target = csio->ccb_h.target_id;
/*
* Copy the command into SimOS' buffer
*/
1998-09-26 14:49:26 +00:00
p = (u_int8_t*) cmd;
count = cmdlen;
for (i = 0; i < count; i++)
sc->sc_regs->cmd[i] = *p++;
sc->sc_regs->length = count;
sc->sc_regs->target = target;
1998-09-26 14:49:26 +00:00
sc->sc_regs->lun = csio->ccb_h.target_lun;
/*
* Setup the segment descriptors.
*/
1998-09-26 14:49:26 +00:00
va = (vm_offset_t) data;
size = datalen;
i = 0;
while (size > 0) {
vm_size_t len = PAGE_SIZE - (va & PAGE_MASK);
if (len > size)
len = size;
sc->sc_regs->sgMap[i].pAddr = vtophys(va);
sc->sc_regs->sgMap[i].len = len;
size -= len;
va += len;
i++;
}
sc->sc_regs->sgLen = i;
/*
* Start the i/o.
*/
alpha_wmb();
sc->sc_regs->startIO = 1;
alpha_wmb();
1998-09-26 14:49:26 +00:00
splx(s);
}
static void
simos_done(struct simos_softc* sc)
{
1998-09-26 14:49:26 +00:00
struct ccb_scsiio* csio = sc->sc_pending;
int s, done;
/*
* Spurious interrupt caused by my bogus interrupt broadcasting.
*/
1998-09-26 14:49:26 +00:00
if (!csio)
return;
1998-09-26 14:49:26 +00:00
sc->sc_pending = 0;
1998-09-26 14:49:26 +00:00
done = sc->sc_regs->done[csio->ccb_h.target_id];
if (!done)
return;
1998-09-26 14:49:26 +00:00
s = splcam();
1998-09-26 14:49:26 +00:00
if (done >> 16)
/* Error detected */
csio->ccb_h.status = CAM_CMD_TIMEOUT;
else
csio->ccb_h.status = CAM_REQ_CMP;
/*
* Ack the interrupt to clear it.
*/
sc->sc_regs->done[csio->ccb_h.target_id] = 1;
alpha_wmb();
1998-09-26 14:49:26 +00:00
xpt_done((union ccb *) csio);
1998-09-26 14:49:26 +00:00
splx(s);
}
1998-09-26 14:49:26 +00:00
static void
simos_action(struct cam_sim *sim, union ccb *ccb)
{
1998-09-26 14:49:26 +00:00
struct simos_softc* sc = (struct simos_softc *)sim->softc;
1998-09-26 14:49:26 +00:00
switch (ccb->ccb_h.func_code) {
case XPT_SCSI_IO:
{
struct ccb_scsiio *csio;
1998-09-26 14:49:26 +00:00
csio = &ccb->csio;
simos_start(sc, csio);
break;
}
1998-09-26 14:49:26 +00:00
case XPT_CALC_GEOMETRY:
{
struct ccb_calc_geometry *ccg;
u_int32_t size_mb;
u_int32_t secs_per_cylinder;
1998-09-26 14:49:26 +00:00
ccg = &ccb->ccg;
size_mb = ccg->volume_size
/ ((1024L * 1024L) / ccg->block_size);
1998-09-26 14:49:26 +00:00
ccg->heads = 64;
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;
xpt_done(ccb);
break;
}
case XPT_RESET_BUS:
{
ccb->ccb_h.status = CAM_REQ_CMP;
xpt_done(ccb);
break;
}
1998-09-26 14:49:26 +00:00
case XPT_PATH_INQ:
{
struct ccb_pathinq *cpi = &ccb->cpi;
1998-09-26 14:49:26 +00:00
cpi->version_num = 1; /* XXX??? */
cpi->max_target = 2;
cpi->max_lun = 0;
cpi->initiator_id = 7;
cpi->bus_id = sim->bus_id;
Add a number of interrelated CAM feature enhancements and bug fixes. NOTE: These changes will require recompilation of any userland applications, like cdrecord, xmcd, etc., that use the CAM passthrough interface. A make world is recommended. camcontrol.[c8]: - We now support two new commands, "tags" and "negotiate". - The tags commands allows users to view the number of tagged openings for a device as well as a number of other related parameters, and it allows users to set tagged openings for a device. - The negotiate command allows users to enable and disable disconnection and tagged queueing, set sync rates, offsets and bus width. Note that not all of those features are available for all controllers. Only the adv, ahc, and ncr drivers fully support all of the features at this point. Some cards do not allow the setting of sync rates, offsets and the like, and some of the drivers don't have any facilities to do so. Some drivers, like the adw driver, only support enabling or disabling sync negotiation, but do not support setting sync rates. - new description in the camcontrol man page of how to format a disk - cleanup of the camcontrol inquiry command - add support in the 'devlist' command for skipping unconfigured devices if -v was not specified on the command line. - make use of the new base_transfer_speed in the path inquiry CCB. - fix CCB bzero cases cam_xpt.c, cam_sim.[ch], cam_ccb.h: - new flags on many CCB function codes to designate whether they're non-immediate, use a user-supplied CCB, and can only be passed from userland programs via the xpt device. Use these flags in the transport layer and pass driver to categorize CCBs. - new flag in the transport layer device matching code for device nodes that indicates whether a device is unconfigured - bump the CAM version from 0x10 to 0x11 - Change the CAM ioctls to use the version as their group code, so we can force users to recompile code even when the CCB size doesn't change. - add + fill in a new value in the path inquiry CCB, base_transfer_speed. Remove a corresponding field from the cam_sim structure, and add code to every SIM to set this field to the proper value. - Fix the set transfer settings code in the transport layer. scsi_cd.c: - make some variables volatile instead of just casting them in various places - fix a race condition in the changer code - attach unless we get a "logical unit not supported" error. This should fix all of the cases where people have devices that return weird errors when they don't have media in the drive. scsi_da.c: - attach unless we get a "logical unit not supported" error scsi_pass.c: - for immediate CCBs, just malloc a CCB to send the user request in. This gets rid of the 'held' count problem in camcontrol tags. scsi_pass.h: - change the CAM ioctls to use the CAM version as their group code. adv driver: - Allow changing the sync rate and offset separately. adw driver - Allow changing the sync rate and offset separately. aha driver: - Don't return CAM_REQ_CMP for SET_TRAN_SETTINGS CCBs. ahc driver: - Allow setting offset and sync rate separately bt driver: - Don't return CAM_REQ_CMP for SET_TRAN_SETTINGS CCBs. NCR driver: - Fix the ultra/ultra 2 negotiation bug - allow setting both the sync rate and offset separately Other HBA drivers: - Put code in to set the base_transfer_speed field for XPT_GET_TRAN_SETTINGS CCBs. Reviewed by: gibbs, mjacob (isp), imp (aha)
1999-05-06 20:16:39 +00:00
cpi->base_transfer_speed = 3300;
1998-09-26 14:49:26 +00:00
strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
strncpy(cpi->hba_vid, "SimOS", HBA_IDLEN);
strncpy(cpi->dev_name, sim->sim_name, DEV_IDLEN);
cpi->unit_number = sim->unit_number;
cpi->ccb_h.status = CAM_REQ_CMP;
xpt_done(ccb);
break;
}
1998-09-26 14:49:26 +00:00
default:
ccb->ccb_h.status = CAM_REQ_INVALID;
xpt_done(ccb);
break;
}
}
static void
1998-09-26 14:49:26 +00:00
simos_poll(struct cam_sim *sim)
{
simos_done(cam_sim_softc(sim));
}
void
simos_intr(int unit)
{
/* XXX bogus */
struct simos_softc* sc = simosp[unit];
simos_done(sc);
}