2 * Copyright (c) 1998 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/pci/simos.c,v 1.7 1999/08/28 00:51:06 peter Exp $
27 * $DragonFly: src/sys/dev/disk/simos/Attic/simos.c,v 1.5 2004/03/15 01:10:44 dillon Exp $
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/malloc.h>
36 #include <bus/cam/cam.h>
37 #include <bus/cam/cam_ccb.h>
38 #include <bus/cam/cam_sim.h>
39 #include <bus/cam/cam_xpt_sim.h>
40 #include <bus/cam/cam_debug.h>
42 #include <bus/cam/scsi/scsi_all.h>
43 #include <bus/cam/scsi/scsi_message.h>
45 #include <machine/clock.h>
47 #include <vm/vm_param.h>
49 #include <sys/kernel.h>
53 #include <bus/pci/pcireg.h>
54 #include <bus/pci/pcivar.h>
56 #include <machine/alpha_cpu.h>
63 * SimOS only supports one pending command.
65 struct cam_sim *sc_sim;
66 struct cam_path *sc_path;
67 struct ccb_scsiio *sc_pending;
70 struct simos_softc* simosp[10];
72 static u_long simos_unit;
74 static const char *simos_probe (pcici_t tag, pcidi_t type);
75 static void simos_attach (pcici_t config_d, int unit);
76 static void simos_action (struct cam_sim *sim, union ccb *ccb);
77 static void simos_poll (struct cam_sim *sim);
79 struct pci_device simos_driver = {
86 COMPAT_PCI_DRIVER (simos, simos_driver);
89 simos_probe(pcici_t tag, pcidi_t type)
92 case 0x1291|(0x1291<<16):
101 simos_attach(pcici_t config_id, int unit)
103 struct simos_softc* sc;
104 struct cam_devq *devq;
106 sc = malloc(sizeof(struct simos_softc), M_DEVBUF, M_WAITOK);
108 bzero(sc, sizeof *sc);
111 sc->sc_regs = (SimOS_SCSI*) SIMOS_SCSI_ADDR;
114 devq = cam_simq_alloc(/*maxopenings*/1);
118 sc->sc_sim = cam_sim_alloc(simos_action, simos_poll, "simos", sc, unit,
119 /*untagged*/1, /*tagged*/0, devq);
120 cam_simq_release(devq);
121 if (sc->sc_sim == NULL) {
125 if (xpt_bus_register(sc->sc_sim, /*bus*/0) != CAM_SUCCESS) {
126 cam_sim_free(sc->sc_sim);
130 if (xpt_create_path(&sc->sc_path, /*periph*/NULL,
131 cam_sim_path(sc->sc_sim), CAM_TARGET_WILDCARD,
132 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
133 xpt_bus_deregister(cam_sim_path(sc->sc_sim));
134 cam_sim_free(sc->sc_sim);
138 alpha_register_pci_scsi(config_id->bus, config_id->slot, sc->sc_sim);
144 simos_start(struct simos_softc* sc, struct ccb_scsiio *csio)
146 struct scsi_generic *cmd;
152 int i, count, target;
156 cmd = (struct scsi_generic *) &csio->cdb_io.cdb_bytes;
157 cmdlen = csio->cdb_len;
158 data = csio->data_ptr;
159 datalen = csio->dxfer_len;
162 * Simos doesn't understand some commands
164 if (cmd->opcode == START_STOP || cmd->opcode == PREVENT_ALLOW
165 || cmd->opcode == SYNCHRONIZE_CACHE) {
166 csio->ccb_h.status = CAM_REQ_CMP;
167 xpt_done((union ccb *) csio);
171 if (sc->sc_pending) {
173 * Don't think this can happen.
175 printf("simos_start: can't start command while one is pending\n");
176 csio->ccb_h.status = CAM_BUSY;
177 xpt_done((union ccb *) csio);
183 csio->ccb_h.status |= CAM_SIM_QUEUED;
184 sc->sc_pending = csio;
186 target = csio->ccb_h.target_id;
189 * Copy the command into SimOS' buffer
193 for (i = 0; i < count; i++)
194 sc->sc_regs->cmd[i] = *p++;
195 sc->sc_regs->length = count;
196 sc->sc_regs->target = target;
197 sc->sc_regs->lun = csio->ccb_h.target_lun;
200 * Setup the segment descriptors.
202 va = (vm_offset_t) data;
206 vm_size_t len = PAGE_SIZE - (va & PAGE_MASK);
209 sc->sc_regs->sgMap[i].pAddr = vtophys(va);
210 sc->sc_regs->sgMap[i].len = len;
215 sc->sc_regs->sgLen = i;
221 sc->sc_regs->startIO = 1;
228 simos_done(struct simos_softc* sc)
230 struct ccb_scsiio* csio = sc->sc_pending;
234 * Spurious interrupt caused by my bogus interrupt broadcasting.
241 done = sc->sc_regs->done[csio->ccb_h.target_id];
249 csio->ccb_h.status = CAM_CMD_TIMEOUT;
251 csio->ccb_h.status = CAM_REQ_CMP;
254 * Ack the interrupt to clear it.
256 sc->sc_regs->done[csio->ccb_h.target_id] = 1;
259 xpt_done((union ccb *) csio);
265 simos_action(struct cam_sim *sim, union ccb *ccb)
267 struct simos_softc* sc = (struct simos_softc *)sim->softc;
269 switch (ccb->ccb_h.func_code) {
272 struct ccb_scsiio *csio;
275 simos_start(sc, csio);
279 case XPT_CALC_GEOMETRY:
281 struct ccb_calc_geometry *ccg;
283 u_int32_t secs_per_cylinder;
286 size_mb = ccg->volume_size
287 / ((1024L * 1024L) / ccg->block_size);
290 ccg->secs_per_track = 32;
292 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
293 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
295 ccb->ccb_h.status = CAM_REQ_CMP;
302 ccb->ccb_h.status = CAM_REQ_CMP;
309 struct ccb_pathinq *cpi = &ccb->cpi;
311 cpi->version_num = 1; /* XXX??? */
314 cpi->initiator_id = 7;
315 cpi->bus_id = sim->bus_id;
316 cpi->base_transfer_speed = 3300;
317 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
318 strncpy(cpi->hba_vid, "SimOS", HBA_IDLEN);
319 strncpy(cpi->dev_name, sim->sim_name, DEV_IDLEN);
320 cpi->unit_number = sim->unit_number;
322 cpi->ccb_h.status = CAM_REQ_CMP;
328 ccb->ccb_h.status = CAM_REQ_INVALID;
335 simos_poll(struct cam_sim *sim)
337 simos_done(cam_sim_softc(sim));
344 struct simos_softc* sc = simosp[unit];