2 * Copyright (c) 2000-04 ICP vortex GmbH
3 * Copyright (c) 2002-04 Intel Corporation
4 * Copyright (c) 2003-04 Adaptec Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * iir.c: SCSI dependant code for the Intel Integrated RAID Controller driver
35 * Written by: Achim Leubner <achim_leubner@adaptec.com>
36 * Fixes/Additions: Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com>
38 * credits: Niklas Hallqvist; OpenBSD driver for the ICP Controllers.
39 * Mike Smith; Some driver source code.
40 * FreeBSD.ORG; Great O/S to work on and for.
42 * $Id: iir.c 1.5 2004/03/30 10:17:53 achim Exp $"
45 #include <sys/cdefs.h>
46 __FBSDID("$FreeBSD$");
50 /* #include "opt_iir.h" */
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/endian.h>
54 #include <sys/eventhandler.h>
55 #include <sys/malloc.h>
56 #include <sys/kernel.h>
59 #include <machine/bus.h>
60 #include <machine/stdarg.h>
63 #include <cam/cam_ccb.h>
64 #include <cam/cam_sim.h>
65 #include <cam/cam_xpt_sim.h>
66 #include <cam/cam_debug.h>
67 #include <cam/scsi/scsi_all.h>
68 #include <cam/scsi/scsi_message.h>
73 #include <dev/iir/iir.h>
75 MALLOC_DEFINE(M_GDTBUF, "iirbuf", "iir driver buffer");
77 struct gdt_softc *gdt_wait_gdt;
81 int gdt_debug = GDT_DEBUG;
83 #define MAX_SERBUF 160
84 static void ser_init(void);
85 static void ser_puts(char *str);
86 static void ser_putc(int c);
87 static char strbuf[MAX_SERBUF+1];
89 #define COM_BASE 0x2f8
91 #define COM_BASE 0x3f8
93 static void ser_init()
95 unsigned port=COM_BASE;
99 /* 19200 Baud, if 9600: outb(12,port) */
105 static void ser_puts(char *str)
110 for (ptr=str;*ptr;++ptr)
111 ser_putc((int)(*ptr));
114 static void ser_putc(int c)
116 unsigned port=COM_BASE;
118 while ((inb(port+5) & 0x20)==0);
122 while ((inb(port+5) & 0x20)==0);
127 int ser_printf(const char *fmt, ...)
133 i = vsprintf(strbuf,fmt,args);
141 /* The linked list of softc structures */
142 struct gdt_softc_list gdt_softcs = TAILQ_HEAD_INITIALIZER(gdt_softcs);
143 /* controller cnt. */
146 static gdt_evt_str ebuffer[GDT_MAX_EVENTS];
147 static int elastidx, eoldidx;
149 gdt_statist_t gdt_stat;
151 /* Definitions for our use of the SIM private CCB area */
152 #define ccb_sim_ptr spriv_ptr0
153 #define ccb_priority spriv_field1
155 static void iir_action(struct cam_sim *sim, union ccb *ccb);
156 static void iir_poll(struct cam_sim *sim);
157 static void iir_shutdown(void *arg, int howto);
158 static void iir_timeout(void *arg);
159 static void iir_watchdog(void *arg);
161 static void gdt_eval_mapping(u_int32_t size, int *cyls, int *heads,
163 static int gdt_internal_cmd(struct gdt_softc *gdt, struct gdt_ccb *gccb,
164 u_int8_t service, u_int16_t opcode,
165 u_int32_t arg1, u_int32_t arg2, u_int32_t arg3);
166 static int gdt_wait(struct gdt_softc *gdt, struct gdt_ccb *ccb,
169 static struct gdt_ccb *gdt_get_ccb(struct gdt_softc *gdt);
171 static int gdt_sync_event(struct gdt_softc *gdt, int service,
172 u_int8_t index, struct gdt_ccb *gccb);
173 static int gdt_async_event(struct gdt_softc *gdt, int service);
174 static struct gdt_ccb *gdt_raw_cmd(struct gdt_softc *gdt,
175 union ccb *ccb, int *lock);
176 static struct gdt_ccb *gdt_cache_cmd(struct gdt_softc *gdt,
177 union ccb *ccb, int *lock);
178 static struct gdt_ccb *gdt_ioctl_cmd(struct gdt_softc *gdt,
179 gdt_ucmd_t *ucmd, int *lock);
180 static void gdt_internal_cache_cmd(struct gdt_softc *gdt,union ccb *ccb);
182 static void gdtmapmem(void *arg, bus_dma_segment_t *dm_segs,
183 int nseg, int error);
184 static void gdtexecuteccb(void *arg, bus_dma_segment_t *dm_segs,
185 int nseg, int error);
188 iir_init(struct gdt_softc *gdt)
191 int i, id, drv_cyls, drv_hds, drv_secs;
192 struct gdt_ccb *gccb;
194 GDT_DPRINTF(GDT_D_DEBUG, ("iir_init()\n"));
196 gdt->sc_state = GDT_POLLING;
198 bzero(&gdt_stat, sizeof(gdt_statist_t));
200 SLIST_INIT(&gdt->sc_free_gccb);
201 SLIST_INIT(&gdt->sc_pending_gccb);
202 TAILQ_INIT(&gdt->sc_ccb_queue);
203 TAILQ_INIT(&gdt->sc_ucmd_queue);
204 TAILQ_INSERT_TAIL(&gdt_softcs, gdt, links);
206 /* DMA tag for mapping buffers into device visible space. */
207 if (bus_dma_tag_create(gdt->sc_parent_dmat, /*alignment*/1, /*boundary*/0,
208 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
209 /*highaddr*/BUS_SPACE_MAXADDR,
210 /*filter*/NULL, /*filterarg*/NULL,
211 /*maxsize*/MAXBSIZE, /*nsegments*/GDT_MAXSG,
212 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
213 /*flags*/BUS_DMA_ALLOCNOW,
214 /*lockfunc*/busdma_lock_mutex, /*lockarg*/&Giant,
215 &gdt->sc_buffer_dmat) != 0) {
216 printf("iir%d: bus_dma_tag_create(...,gdt->sc_buffer_dmat) failed\n",
220 gdt->sc_init_level++;
222 /* DMA tag for our ccb structures */
223 if (bus_dma_tag_create(gdt->sc_parent_dmat,
226 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
227 /*highaddr*/BUS_SPACE_MAXADDR,
230 GDT_MAXCMDS * GDT_SCRATCH_SZ, /* maxsize */
232 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
233 /*flags*/0, /*lockfunc*/busdma_lock_mutex,
234 /*lockarg*/&Giant, &gdt->sc_gcscratch_dmat) != 0) {
235 printf("iir%d: bus_dma_tag_create(...,gdt->sc_gcscratch_dmat) failed\n",
239 gdt->sc_init_level++;
241 /* Allocation for our ccb scratch area */
242 if (bus_dmamem_alloc(gdt->sc_gcscratch_dmat, (void **)&gdt->sc_gcscratch,
243 BUS_DMA_NOWAIT, &gdt->sc_gcscratch_dmamap) != 0) {
244 printf("iir%d: bus_dmamem_alloc(...,&gdt->sc_gccbs,...) failed\n",
248 gdt->sc_init_level++;
250 /* And permanently map them */
251 bus_dmamap_load(gdt->sc_gcscratch_dmat, gdt->sc_gcscratch_dmamap,
252 gdt->sc_gcscratch, GDT_MAXCMDS * GDT_SCRATCH_SZ,
253 gdtmapmem, &gdt->sc_gcscratch_busbase, /*flags*/0);
254 gdt->sc_init_level++;
256 /* Clear them out. */
257 bzero(gdt->sc_gcscratch, GDT_MAXCMDS * GDT_SCRATCH_SZ);
259 /* Initialize the ccbs */
260 gdt->sc_gccbs = malloc(sizeof(struct gdt_ccb) * GDT_MAXCMDS, M_GDTBUF,
262 if (gdt->sc_gccbs == NULL) {
263 printf("iir%d: no memory for gccbs.\n", gdt->sc_hanum);
266 for (i = GDT_MAXCMDS-1; i >= 0; i--) {
267 gccb = &gdt->sc_gccbs[i];
268 gccb->gc_cmd_index = i + 2;
269 gccb->gc_flags = GDT_GCF_UNUSED;
270 gccb->gc_map_flag = FALSE;
271 if (bus_dmamap_create(gdt->sc_buffer_dmat, /*flags*/0,
272 &gccb->gc_dmamap) != 0)
274 gccb->gc_map_flag = TRUE;
275 gccb->gc_scratch = &gdt->sc_gcscratch[GDT_SCRATCH_SZ * i];
276 gccb->gc_scratch_busbase = gdt->sc_gcscratch_busbase + GDT_SCRATCH_SZ * i;
277 SLIST_INSERT_HEAD(&gdt->sc_free_gccb, gccb, sle);
279 gdt->sc_init_level++;
281 /* create the control device */
282 gdt->sc_dev = gdt_make_dev(gdt->sc_hanum);
284 /* allocate ccb for gdt_internal_cmd() */
285 gccb = gdt_get_ccb(gdt);
287 printf("iir%d: No free command index found\n",
291 bzero(gccb->gc_cmd, GDT_CMD_SZ);
293 if (!gdt_internal_cmd(gdt, gccb, GDT_SCREENSERVICE, GDT_INIT,
295 printf("iir%d: Screen service initialization error %d\n",
296 gdt->sc_hanum, gdt->sc_status);
297 gdt_free_ccb(gdt, gccb);
301 gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_UNFREEZE_IO,
304 if (!gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_INIT,
305 GDT_LINUX_OS, 0, 0)) {
306 printf("iir%d: Cache service initialization error %d\n",
307 gdt->sc_hanum, gdt->sc_status);
308 gdt_free_ccb(gdt, gccb);
311 cdev_cnt = (u_int16_t)gdt->sc_info;
312 gdt->sc_fw_vers = gdt->sc_service;
314 /* Detect number of buses */
315 gdt_enc32(gccb->gc_scratch + GDT_IOC_VERSION, GDT_IOC_NEWEST);
316 gccb->gc_scratch[GDT_IOC_LIST_ENTRIES] = GDT_MAXBUS;
317 gccb->gc_scratch[GDT_IOC_FIRST_CHAN] = 0;
318 gccb->gc_scratch[GDT_IOC_LAST_CHAN] = GDT_MAXBUS - 1;
319 gdt_enc32(gccb->gc_scratch + GDT_IOC_LIST_OFFSET, GDT_IOC_HDR_SZ);
320 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_IOCTL,
321 GDT_IOCHAN_RAW_DESC, GDT_INVALID_CHANNEL,
322 GDT_IOC_HDR_SZ + GDT_MAXBUS * GDT_RAWIOC_SZ)) {
323 gdt->sc_bus_cnt = gccb->gc_scratch[GDT_IOC_CHAN_COUNT];
324 for (i = 0; i < gdt->sc_bus_cnt; i++) {
325 id = gccb->gc_scratch[GDT_IOC_HDR_SZ +
326 i * GDT_RAWIOC_SZ + GDT_RAWIOC_PROC_ID];
327 gdt->sc_bus_id[i] = id < GDT_MAXID_FC ? id : 0xff;
330 /* New method failed, use fallback. */
331 for (i = 0; i < GDT_MAXBUS; i++) {
332 gdt_enc32(gccb->gc_scratch + GDT_GETCH_CHANNEL_NO, i);
333 if (!gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_IOCTL,
334 GDT_SCSI_CHAN_CNT | GDT_L_CTRL_PATTERN,
335 GDT_IO_CHANNEL | GDT_INVALID_CHANNEL,
338 printf("iir%d: Cannot get channel count, "
339 "error %d\n", gdt->sc_hanum, gdt->sc_status);
340 gdt_free_ccb(gdt, gccb);
346 (gccb->gc_scratch[GDT_GETCH_SIOP_ID] < GDT_MAXID_FC) ?
347 gccb->gc_scratch[GDT_GETCH_SIOP_ID] : 0xff;
351 /* add one "virtual" channel for the host drives */
352 gdt->sc_virt_bus = gdt->sc_bus_cnt;
355 if (!gdt_internal_cmd(gdt, gccb, GDT_SCSIRAWSERVICE, GDT_INIT,
357 printf("iir%d: Raw service initialization error %d\n",
358 gdt->sc_hanum, gdt->sc_status);
359 gdt_free_ccb(gdt, gccb);
363 /* Set/get features raw service (scatter/gather) */
364 gdt->sc_raw_feat = 0;
365 if (gdt_internal_cmd(gdt, gccb, GDT_SCSIRAWSERVICE, GDT_SET_FEAT,
366 GDT_SCATTER_GATHER, 0, 0)) {
367 if (gdt_internal_cmd(gdt, gccb, GDT_SCSIRAWSERVICE, GDT_GET_FEAT,
369 gdt->sc_raw_feat = gdt->sc_info;
370 if (!(gdt->sc_info & GDT_SCATTER_GATHER)) {
371 panic("iir%d: Scatter/Gather Raw Service "
372 "required but not supported!\n", gdt->sc_hanum);
373 gdt_free_ccb(gdt, gccb);
379 /* Set/get features cache service (scatter/gather) */
380 gdt->sc_cache_feat = 0;
381 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_SET_FEAT,
382 0, GDT_SCATTER_GATHER, 0)) {
383 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_GET_FEAT,
385 gdt->sc_cache_feat = gdt->sc_info;
386 if (!(gdt->sc_info & GDT_SCATTER_GATHER)) {
387 panic("iir%d: Scatter/Gather Cache Service "
388 "required but not supported!\n", gdt->sc_hanum);
389 gdt_free_ccb(gdt, gccb);
396 gdt_enc32(gccb->gc_scratch + GDT_OEM_VERSION, 0x01);
397 gdt_enc32(gccb->gc_scratch + GDT_OEM_BUFSIZE, sizeof(gdt_oem_record_t));
398 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_IOCTL,
399 GDT_OEM_STR_RECORD, GDT_INVALID_CHANNEL,
400 sizeof(gdt_oem_str_record_t))) {
401 strncpy(gdt->oem_name, ((gdt_oem_str_record_t *)
402 gccb->gc_scratch)->text.scsi_host_drive_inquiry_vendor_id, 7);
403 gdt->oem_name[7]='\0';
405 /* Old method, based on PCI ID */
406 if (gdt->sc_vendor == INTEL_VENDOR_ID)
407 strcpy(gdt->oem_name,"Intel ");
409 strcpy(gdt->oem_name,"ICP ");
412 /* Scan for cache devices */
413 for (i = 0; i < cdev_cnt && i < GDT_MAX_HDRIVES; i++) {
414 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_INFO,
416 gdt->sc_hdr[i].hd_present = 1;
417 gdt->sc_hdr[i].hd_size = gdt->sc_info;
420 * Evaluate mapping (sectors per head, heads per cyl)
422 gdt->sc_hdr[i].hd_size &= ~GDT_SECS32;
423 if (gdt->sc_info2 == 0)
424 gdt_eval_mapping(gdt->sc_hdr[i].hd_size,
425 &drv_cyls, &drv_hds, &drv_secs);
427 drv_hds = gdt->sc_info2 & 0xff;
428 drv_secs = (gdt->sc_info2 >> 8) & 0xff;
429 drv_cyls = gdt->sc_hdr[i].hd_size / drv_hds /
432 gdt->sc_hdr[i].hd_heads = drv_hds;
433 gdt->sc_hdr[i].hd_secs = drv_secs;
435 gdt->sc_hdr[i].hd_size = drv_cyls * drv_hds * drv_secs;
437 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE,
438 GDT_DEVTYPE, i, 0, 0))
439 gdt->sc_hdr[i].hd_devtype = gdt->sc_info;
443 GDT_DPRINTF(GDT_D_INIT, ("dpmem %x %d-bus %d cache device%s\n",
445 gdt->sc_bus_cnt, cdev_cnt,
446 cdev_cnt == 1 ? "" : "s"));
447 gdt_free_ccb(gdt, gccb);
454 iir_free(struct gdt_softc *gdt)
458 GDT_DPRINTF(GDT_D_INIT, ("iir_free()\n"));
460 switch (gdt->sc_init_level) {
462 gdt_destroy_dev(gdt->sc_dev);
464 for (i = GDT_MAXCMDS-1; i >= 0; i--)
465 if (gdt->sc_gccbs[i].gc_map_flag)
466 bus_dmamap_destroy(gdt->sc_buffer_dmat,
467 gdt->sc_gccbs[i].gc_dmamap);
468 bus_dmamap_unload(gdt->sc_gcscratch_dmat, gdt->sc_gcscratch_dmamap);
469 free(gdt->sc_gccbs, M_GDTBUF);
471 bus_dmamem_free(gdt->sc_gcscratch_dmat, gdt->sc_gcscratch, gdt->sc_gcscratch_dmamap);
473 bus_dma_tag_destroy(gdt->sc_gcscratch_dmat);
475 bus_dma_tag_destroy(gdt->sc_buffer_dmat);
477 bus_dma_tag_destroy(gdt->sc_parent_dmat);
481 TAILQ_REMOVE(&gdt_softcs, gdt, links);
485 iir_attach(struct gdt_softc *gdt)
487 struct cam_devq *devq;
490 GDT_DPRINTF(GDT_D_INIT, ("iir_attach()\n"));
493 * Create the device queue for our SIM.
494 * XXX Throttle this down since the card has problems under load.
496 devq = cam_simq_alloc(32);
500 for (i = 0; i < gdt->sc_bus_cnt; i++) {
502 * Construct our SIM entry
504 gdt->sims[i] = cam_sim_alloc(iir_action, iir_poll, "iir",
505 gdt, gdt->sc_hanum, /*untagged*/1,
506 /*tagged*/GDT_MAXCMDS, devq);
507 if (xpt_bus_register(gdt->sims[i], i) != CAM_SUCCESS) {
508 cam_sim_free(gdt->sims[i], /*free_devq*/i == 0);
512 if (xpt_create_path(&gdt->paths[i], /*periph*/NULL,
513 cam_sim_path(gdt->sims[i]),
515 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
516 xpt_bus_deregister(cam_sim_path(gdt->sims[i]));
517 cam_sim_free(gdt->sims[i], /*free_devq*/i == 0);
522 EVENTHANDLER_REGISTER(shutdown_final, iir_shutdown,
523 gdt, SHUTDOWN_PRI_DEFAULT);
524 /* iir_watchdog(gdt); */
525 gdt->sc_state = GDT_NORMAL;
529 gdt_eval_mapping(u_int32_t size, int *cyls, int *heads, int *secs)
531 *cyls = size / GDT_HEADS / GDT_SECS;
532 if (*cyls < GDT_MAXCYLS) {
536 /* Too high for 64 * 32 */
537 *cyls = size / GDT_MEDHEADS / GDT_MEDSECS;
538 if (*cyls < GDT_MAXCYLS) {
539 *heads = GDT_MEDHEADS;
542 /* Too high for 127 * 63 */
543 *cyls = size / GDT_BIGHEADS / GDT_BIGSECS;
544 *heads = GDT_BIGHEADS;
551 gdt_wait(struct gdt_softc *gdt, struct gdt_ccb *gccb,
556 GDT_DPRINTF(GDT_D_INIT,
557 ("gdt_wait(%p, %p, %d)\n", gdt, gccb, timeout));
559 gdt->sc_state |= GDT_POLL_WAIT;
562 if (gdt == gdt_wait_gdt &&
563 gccb->gc_cmd_index == gdt_wait_index) {
569 gdt->sc_state &= ~GDT_POLL_WAIT;
571 while (gdt->sc_test_busy(gdt))
572 DELAY(1); /* XXX correct? */
578 gdt_internal_cmd(struct gdt_softc *gdt, struct gdt_ccb *gccb,
579 u_int8_t service, u_int16_t opcode,
580 u_int32_t arg1, u_int32_t arg2, u_int32_t arg3)
584 GDT_DPRINTF(GDT_D_CMD, ("gdt_internal_cmd(%p, %d, %d, %d, %d, %d)\n",
585 gdt, service, opcode, arg1, arg2, arg3));
587 bzero(gccb->gc_cmd, GDT_CMD_SZ);
589 for (retries = GDT_RETRIES; ; ) {
590 gccb->gc_service = service;
591 gccb->gc_flags = GDT_GCF_INTERNAL;
593 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
595 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, opcode);
598 case GDT_CACHESERVICE:
599 if (opcode == GDT_IOCTL) {
600 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION +
601 GDT_IOCTL_SUBFUNC, arg1);
602 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION +
603 GDT_IOCTL_CHANNEL, arg2);
604 gdt_enc16(gccb->gc_cmd + GDT_CMD_UNION +
605 GDT_IOCTL_PARAM_SIZE, (u_int16_t)arg3);
606 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_IOCTL_P_PARAM,
607 gccb->gc_scratch_busbase);
609 gdt_enc16(gccb->gc_cmd + GDT_CMD_UNION +
610 GDT_CACHE_DEVICENO, (u_int16_t)arg1);
611 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION +
612 GDT_CACHE_BLOCKNO, arg2);
616 case GDT_SCSIRAWSERVICE:
617 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION +
618 GDT_RAW_DIRECTION, arg1);
619 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_BUS] =
621 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_TARGET] =
623 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_LUN] =
624 (u_int8_t)(arg3 >> 8);
627 gdt->sc_set_sema0(gdt);
628 gccb->gc_cmd_len = GDT_CMD_SZ;
631 gdt->sc_copy_cmd(gdt, gccb);
632 gdt->sc_release_event(gdt);
634 if (!gdt_wait(gdt, gccb, GDT_POLL_TIMEOUT))
636 if (gdt->sc_status != GDT_S_BSY || --retries == 0)
640 return (gdt->sc_status == GDT_S_OK);
643 static struct gdt_ccb *
644 gdt_get_ccb(struct gdt_softc *gdt)
646 struct gdt_ccb *gccb;
649 GDT_DPRINTF(GDT_D_QUEUE, ("gdt_get_ccb(%p)\n", gdt));
652 gccb = SLIST_FIRST(&gdt->sc_free_gccb);
654 SLIST_REMOVE_HEAD(&gdt->sc_free_gccb, sle);
655 SLIST_INSERT_HEAD(&gdt->sc_pending_gccb, gccb, sle);
656 ++gdt_stat.cmd_index_act;
657 if (gdt_stat.cmd_index_act > gdt_stat.cmd_index_max)
658 gdt_stat.cmd_index_max = gdt_stat.cmd_index_act;
665 gdt_free_ccb(struct gdt_softc *gdt, struct gdt_ccb *gccb)
669 GDT_DPRINTF(GDT_D_QUEUE, ("gdt_free_ccb(%p, %p)\n", gdt, gccb));
672 gccb->gc_flags = GDT_GCF_UNUSED;
673 SLIST_REMOVE(&gdt->sc_pending_gccb, gccb, gdt_ccb, sle);
674 SLIST_INSERT_HEAD(&gdt->sc_free_gccb, gccb, sle);
675 --gdt_stat.cmd_index_act;
677 if (gdt->sc_state & GDT_SHUTDOWN)
682 gdt_next(struct gdt_softc *gdt)
688 int bus, target, lun;
691 struct ccb_scsiio *csio;
692 struct ccb_hdr *ccbh;
693 struct gdt_ccb *gccb = NULL;
696 GDT_DPRINTF(GDT_D_QUEUE, ("gdt_next(%p)\n", gdt));
699 if (gdt->sc_test_busy(gdt)) {
700 if (!(gdt->sc_state & GDT_POLLING)) {
704 while (gdt->sc_test_busy(gdt))
708 gdt->sc_cmd_cnt = gdt->sc_cmd_off = 0;
711 /* I/Os in queue? controller ready? */
712 if (!TAILQ_FIRST(&gdt->sc_ucmd_queue) &&
713 !TAILQ_FIRST(&gdt->sc_ccb_queue))
716 /* 1.: I/Os without ccb (IOCTLs) */
717 ucmd = TAILQ_FIRST(&gdt->sc_ucmd_queue);
719 TAILQ_REMOVE(&gdt->sc_ucmd_queue, ucmd, links);
720 if ((gccb = gdt_ioctl_cmd(gdt, ucmd, &lock)) == NULL) {
721 TAILQ_INSERT_HEAD(&gdt->sc_ucmd_queue, ucmd, links);
725 /* wenn mehrere Kdos. zulassen: if (!gdt_polling) continue; */
728 /* 2.: I/Os with ccb */
729 ccb = (union ccb *)TAILQ_FIRST(&gdt->sc_ccb_queue);
730 /* ist dann immer != NULL, da oben getestet */
731 sim = (struct cam_sim *)ccb->ccb_h.ccb_sim_ptr;
732 bus = cam_sim_bus(sim);
733 target = ccb->ccb_h.target_id;
734 lun = ccb->ccb_h.target_lun;
736 TAILQ_REMOVE(&gdt->sc_ccb_queue, &ccb->ccb_h, sim_links.tqe);
737 --gdt_stat.req_queue_act;
738 /* ccb->ccb_h.func_code is XPT_SCSI_IO */
739 GDT_DPRINTF(GDT_D_QUEUE, ("XPT_SCSI_IO flags 0x%x)\n",
743 cmd = csio->cdb_io.cdb_bytes[0];
744 /* Max CDB length is 12 bytes */
745 if (csio->cdb_len > 12) {
746 ccbh->status = CAM_REQ_INVALID;
747 --gdt_stat.io_count_act;
749 } else if (bus != gdt->sc_virt_bus) {
750 /* raw service command */
751 if ((gccb = gdt_raw_cmd(gdt, ccb, &lock)) == NULL) {
752 TAILQ_INSERT_HEAD(&gdt->sc_ccb_queue, &ccb->ccb_h,
754 ++gdt_stat.req_queue_act;
755 if (gdt_stat.req_queue_act > gdt_stat.req_queue_max)
756 gdt_stat.req_queue_max = gdt_stat.req_queue_act;
759 } else if (target >= GDT_MAX_HDRIVES ||
760 !gdt->sc_hdr[target].hd_present || lun != 0) {
761 ccbh->status = CAM_DEV_NOT_THERE;
762 --gdt_stat.io_count_act;
765 /* cache service command */
766 if (cmd == READ_6 || cmd == WRITE_6 ||
767 cmd == READ_10 || cmd == WRITE_10) {
768 if ((gccb = gdt_cache_cmd(gdt, ccb, &lock)) == NULL) {
769 TAILQ_INSERT_HEAD(&gdt->sc_ccb_queue, &ccb->ccb_h,
771 ++gdt_stat.req_queue_act;
772 if (gdt_stat.req_queue_act > gdt_stat.req_queue_max)
773 gdt_stat.req_queue_max = gdt_stat.req_queue_act;
778 gdt_internal_cache_cmd(gdt, ccb);
782 if ((gdt->sc_state & GDT_POLLING) || !next_cmd)
785 if (gdt->sc_cmd_cnt > 0)
786 gdt->sc_release_event(gdt);
790 if ((gdt->sc_state & GDT_POLLING) && gdt->sc_cmd_cnt > 0) {
791 gdt_wait(gdt, gccb, GDT_POLL_TIMEOUT);
795 static struct gdt_ccb *
796 gdt_raw_cmd(struct gdt_softc *gdt, union ccb *ccb, int *lock)
798 struct gdt_ccb *gccb;
801 GDT_DPRINTF(GDT_D_CMD, ("gdt_raw_cmd(%p, %p)\n", gdt, ccb));
803 if (roundup(GDT_CMD_UNION + GDT_RAW_SZ, sizeof(u_int32_t)) +
804 gdt->sc_cmd_off + GDT_DPMEM_COMMAND_OFFSET >
805 gdt->sc_ic_all_size) {
806 GDT_DPRINTF(GDT_D_INVALID, ("iir%d: gdt_raw_cmd(): DPMEM overflow\n",
811 gccb = gdt_get_ccb(gdt);
813 GDT_DPRINTF(GDT_D_INVALID, ("iir%d: No free command index found\n",
817 bzero(gccb->gc_cmd, GDT_CMD_SZ);
818 sim = (struct cam_sim *)ccb->ccb_h.ccb_sim_ptr;
820 gccb->gc_service = GDT_SCSIRAWSERVICE;
821 gccb->gc_flags = GDT_GCF_SCSI;
823 if (gdt->sc_cmd_cnt == 0)
824 gdt->sc_set_sema0(gdt);
826 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
828 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, GDT_WRITE);
830 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_DIRECTION,
831 (ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN ?
832 GDT_DATA_IN : GDT_DATA_OUT);
833 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SDLEN,
834 ccb->csio.dxfer_len);
835 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_CLEN,
837 bcopy(ccb->csio.cdb_io.cdb_bytes, gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_CMD,
839 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_TARGET] =
840 ccb->ccb_h.target_id;
841 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_LUN] =
842 ccb->ccb_h.target_lun;
843 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_BUS] =
845 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SENSE_LEN,
846 sizeof(struct scsi_sense_data));
847 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SENSE_DATA,
848 gccb->gc_scratch_busbase);
851 * If we have any data to send with this command,
852 * map it into bus space.
854 /* Only use S/G if there is a transfer */
855 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
856 if ((ccb->ccb_h.flags & CAM_SCATTER_VALID) == 0) {
857 if ((ccb->ccb_h.flags & CAM_DATA_PHYS) == 0) {
861 /* vorher unlock von splcam() ??? */
864 bus_dmamap_load(gdt->sc_buffer_dmat,
870 if (error == EINPROGRESS) {
871 xpt_freeze_simq(sim, 1);
872 gccb->gc_ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
876 panic("iir: CAM_DATA_PHYS not supported");
879 struct bus_dma_segment *segs;
881 if ((ccb->ccb_h.flags & CAM_DATA_PHYS) != 0)
882 panic("iir%d: iir_action - Physical "
883 "segment pointers unsupported", gdt->sc_hanum);
885 if ((ccb->ccb_h.flags & CAM_SG_LIST_PHYS)==0)
886 panic("iir%d: iir_action - Virtual "
887 "segment addresses unsupported", gdt->sc_hanum);
889 /* Just use the segments provided */
890 segs = (struct bus_dma_segment *)ccb->csio.data_ptr;
891 gdtexecuteccb(gccb, segs, ccb->csio.sglist_cnt, 0);
894 gdtexecuteccb(gccb, NULL, 0, 0);
901 static struct gdt_ccb *
902 gdt_cache_cmd(struct gdt_softc *gdt, union ccb *ccb, int *lock)
904 struct gdt_ccb *gccb;
908 u_int32_t blockno, blockcnt;
910 GDT_DPRINTF(GDT_D_CMD, ("gdt_cache_cmd(%p, %p)\n", gdt, ccb));
912 if (roundup(GDT_CMD_UNION + GDT_CACHE_SZ, sizeof(u_int32_t)) +
913 gdt->sc_cmd_off + GDT_DPMEM_COMMAND_OFFSET >
914 gdt->sc_ic_all_size) {
915 GDT_DPRINTF(GDT_D_INVALID, ("iir%d: gdt_cache_cmd(): DPMEM overflow\n",
920 gccb = gdt_get_ccb(gdt);
922 GDT_DPRINTF(GDT_D_DEBUG, ("iir%d: No free command index found\n",
926 bzero(gccb->gc_cmd, GDT_CMD_SZ);
927 sim = (struct cam_sim *)ccb->ccb_h.ccb_sim_ptr;
929 gccb->gc_service = GDT_CACHESERVICE;
930 gccb->gc_flags = GDT_GCF_SCSI;
932 if (gdt->sc_cmd_cnt == 0)
933 gdt->sc_set_sema0(gdt);
935 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
937 cmdp = ccb->csio.cdb_io.cdb_bytes;
938 opcode = (*cmdp == WRITE_6 || *cmdp == WRITE_10) ? GDT_WRITE : GDT_READ;
939 if ((gdt->sc_state & GDT_SHUTDOWN) && opcode == GDT_WRITE)
940 opcode = GDT_WRITE_THR;
941 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, opcode);
943 gdt_enc16(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_DEVICENO,
944 ccb->ccb_h.target_id);
945 if (ccb->csio.cdb_len == 6) {
946 struct scsi_rw_6 *rw = (struct scsi_rw_6 *)cmdp;
947 blockno = scsi_3btoul(rw->addr) & ((SRW_TOPADDR<<16) | 0xffff);
948 blockcnt = rw->length ? rw->length : 0x100;
950 struct scsi_rw_10 *rw = (struct scsi_rw_10 *)cmdp;
951 blockno = scsi_4btoul(rw->addr);
952 blockcnt = scsi_2btoul(rw->length);
954 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_BLOCKNO,
956 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_BLOCKCNT,
960 * If we have any data to send with this command,
961 * map it into bus space.
963 /* Only use S/G if there is a transfer */
964 if ((ccb->ccb_h.flags & CAM_SCATTER_VALID) == 0) {
965 if ((ccb->ccb_h.flags & CAM_DATA_PHYS) == 0) {
969 /* vorher unlock von splcam() ??? */
972 bus_dmamap_load(gdt->sc_buffer_dmat,
978 if (error == EINPROGRESS) {
979 xpt_freeze_simq(sim, 1);
980 gccb->gc_ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
984 panic("iir: CAM_DATA_PHYS not supported");
987 struct bus_dma_segment *segs;
989 if ((ccb->ccb_h.flags & CAM_DATA_PHYS) != 0)
990 panic("iir%d: iir_action - Physical "
991 "segment pointers unsupported", gdt->sc_hanum);
993 if ((ccb->ccb_h.flags & CAM_SG_LIST_PHYS)==0)
994 panic("iir%d: iir_action - Virtual "
995 "segment addresses unsupported", gdt->sc_hanum);
997 /* Just use the segments provided */
998 segs = (struct bus_dma_segment *)ccb->csio.data_ptr;
999 gdtexecuteccb(gccb, segs, ccb->csio.sglist_cnt, 0);
1006 static struct gdt_ccb *
1007 gdt_ioctl_cmd(struct gdt_softc *gdt, gdt_ucmd_t *ucmd, int *lock)
1009 struct gdt_ccb *gccb;
1012 GDT_DPRINTF(GDT_D_DEBUG, ("gdt_ioctl_cmd(%p, %p)\n", gdt, ucmd));
1014 gccb = gdt_get_ccb(gdt);
1016 GDT_DPRINTF(GDT_D_DEBUG, ("iir%d: No free command index found\n",
1020 bzero(gccb->gc_cmd, GDT_CMD_SZ);
1021 gccb->gc_ucmd = ucmd;
1022 gccb->gc_service = ucmd->service;
1023 gccb->gc_flags = GDT_GCF_IOCTL;
1025 /* check DPMEM space, copy data buffer from user space */
1026 if (ucmd->service == GDT_CACHESERVICE) {
1027 if (ucmd->OpCode == GDT_IOCTL) {
1028 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_IOCTL_SZ,
1030 cnt = ucmd->u.ioctl.param_size;
1031 if (cnt > GDT_SCRATCH_SZ) {
1032 printf("iir%d: Scratch buffer too small (%d/%d)\n",
1033 gdt->sc_hanum, GDT_SCRATCH_SZ, cnt);
1034 gdt_free_ccb(gdt, gccb);
1038 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_CACHE_SG_LST +
1039 GDT_SG_SZ, sizeof(u_int32_t));
1040 cnt = ucmd->u.cache.BlockCnt * GDT_SECTOR_SIZE;
1041 if (cnt > GDT_SCRATCH_SZ) {
1042 printf("iir%d: Scratch buffer too small (%d/%d)\n",
1043 gdt->sc_hanum, GDT_SCRATCH_SZ, cnt);
1044 gdt_free_ccb(gdt, gccb);
1049 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_RAW_SG_LST +
1050 GDT_SG_SZ, sizeof(u_int32_t));
1051 cnt = ucmd->u.raw.sdlen;
1052 if (cnt + ucmd->u.raw.sense_len > GDT_SCRATCH_SZ) {
1053 printf("iir%d: Scratch buffer too small (%d/%d)\n",
1054 gdt->sc_hanum, GDT_SCRATCH_SZ, cnt + ucmd->u.raw.sense_len);
1055 gdt_free_ccb(gdt, gccb);
1060 bcopy(ucmd->data, gccb->gc_scratch, cnt);
1062 if (gdt->sc_cmd_off + gccb->gc_cmd_len + GDT_DPMEM_COMMAND_OFFSET >
1063 gdt->sc_ic_all_size) {
1064 GDT_DPRINTF(GDT_D_INVALID, ("iir%d: gdt_ioctl_cmd(): DPMEM overflow\n",
1066 gdt_free_ccb(gdt, gccb);
1070 if (gdt->sc_cmd_cnt == 0)
1071 gdt->sc_set_sema0(gdt);
1074 /* fill cmd structure */
1075 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
1076 gccb->gc_cmd_index);
1077 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE,
1080 if (ucmd->service == GDT_CACHESERVICE) {
1081 if (ucmd->OpCode == GDT_IOCTL) {
1083 gdt_enc16(gccb->gc_cmd + GDT_CMD_UNION + GDT_IOCTL_PARAM_SIZE,
1084 ucmd->u.ioctl.param_size);
1085 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_IOCTL_SUBFUNC,
1086 ucmd->u.ioctl.subfunc);
1087 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_IOCTL_CHANNEL,
1088 ucmd->u.ioctl.channel);
1089 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_IOCTL_P_PARAM,
1090 gccb->gc_scratch_busbase);
1092 /* cache service command */
1093 gdt_enc16(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_DEVICENO,
1094 ucmd->u.cache.DeviceNo);
1095 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_BLOCKNO,
1096 ucmd->u.cache.BlockNo);
1097 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_BLOCKCNT,
1098 ucmd->u.cache.BlockCnt);
1099 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_DESTADDR,
1101 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_CANZ,
1103 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_LST +
1104 GDT_SG_PTR, gccb->gc_scratch_busbase);
1105 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_LST +
1106 GDT_SG_LEN, ucmd->u.cache.BlockCnt * GDT_SECTOR_SIZE);
1109 /* raw service command */
1110 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_DIRECTION,
1111 ucmd->u.raw.direction);
1112 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SDATA,
1114 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SDLEN,
1116 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_CLEN,
1118 bcopy(ucmd->u.raw.cmd, gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_CMD,
1120 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_TARGET] =
1122 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_LUN] =
1124 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_BUS] =
1126 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SENSE_LEN,
1127 ucmd->u.raw.sense_len);
1128 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SENSE_DATA,
1129 gccb->gc_scratch_busbase + ucmd->u.raw.sdlen);
1130 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_RANZ,
1132 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_LST +
1133 GDT_SG_PTR, gccb->gc_scratch_busbase);
1134 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_LST +
1135 GDT_SG_LEN, ucmd->u.raw.sdlen);
1139 gdt_stat.sg_count_act = 1;
1140 gdt->sc_copy_cmd(gdt, gccb);
1145 gdt_internal_cache_cmd(struct gdt_softc *gdt,union ccb *ccb)
1149 t = ccb->ccb_h.target_id;
1150 GDT_DPRINTF(GDT_D_CMD, ("gdt_internal_cache_cmd(%p, %p, 0x%x, %d)\n",
1151 gdt, ccb, ccb->csio.cdb_io.cdb_bytes[0], t));
1153 switch (ccb->csio.cdb_io.cdb_bytes[0]) {
1154 case TEST_UNIT_READY:
1158 GDT_DPRINTF(GDT_D_MISC, ("REQUEST_SENSE\n"));
1162 struct scsi_inquiry_data *inq;
1164 inq = (struct scsi_inquiry_data *)ccb->csio.data_ptr;
1165 bzero(inq, sizeof(struct scsi_inquiry_data));
1166 inq->device = (gdt->sc_hdr[t].hd_devtype & 4) ?
1168 inq->dev_qual2 = (gdt->sc_hdr[t].hd_devtype & 1) ? 0x80 : 0;
1169 inq->version = SCSI_REV_2;
1170 inq->response_format = 2;
1171 inq->additional_length = 32;
1172 inq->flags = SID_CmdQue | SID_Sync;
1173 strcpy(inq->vendor, gdt->oem_name);
1174 sprintf(inq->product, "Host Drive #%02d", t);
1175 strcpy(inq->revision, " ");
1181 struct scsi_mode_hdr_6 hd;
1182 struct scsi_mode_block_descr bd;
1183 struct scsi_control_page cp;
1187 mpd = (struct mpd_data *)ccb->csio.data_ptr;
1188 bzero(mpd, sizeof(struct mpd_data));
1189 mpd->hd.datalen = sizeof(struct scsi_mode_hdr_6) +
1190 sizeof(struct scsi_mode_block_descr);
1191 mpd->hd.dev_specific = (gdt->sc_hdr[t].hd_devtype & 2) ? 0x80 : 0;
1192 mpd->hd.block_descr_len = sizeof(struct scsi_mode_block_descr);
1193 mpd->bd.block_len[0] = (GDT_SECTOR_SIZE & 0x00ff0000) >> 16;
1194 mpd->bd.block_len[1] = (GDT_SECTOR_SIZE & 0x0000ff00) >> 8;
1195 mpd->bd.block_len[2] = (GDT_SECTOR_SIZE & 0x000000ff);
1196 page=((struct scsi_mode_sense_6 *)ccb->csio.cdb_io.cdb_bytes)->page;
1199 GDT_DPRINTF(GDT_D_MISC, ("MODE_SENSE_6: page 0x%x\n", page));
1206 struct scsi_read_capacity_data *rcd;
1208 rcd = (struct scsi_read_capacity_data *)ccb->csio.data_ptr;
1209 bzero(rcd, sizeof(struct scsi_read_capacity_data));
1210 scsi_ulto4b(gdt->sc_hdr[t].hd_size - 1, rcd->addr);
1211 scsi_ulto4b(GDT_SECTOR_SIZE, rcd->length);
1215 GDT_DPRINTF(GDT_D_MISC, ("gdt_internal_cache_cmd(%d) unknown\n",
1216 ccb->csio.cdb_io.cdb_bytes[0]));
1219 ccb->ccb_h.status |= CAM_REQ_CMP;
1220 --gdt_stat.io_count_act;
1225 gdtmapmem(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1227 bus_addr_t *busaddrp;
1229 busaddrp = (bus_addr_t *)arg;
1230 *busaddrp = dm_segs->ds_addr;
1234 gdtexecuteccb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1236 struct gdt_ccb *gccb;
1238 struct gdt_softc *gdt;
1243 gccb = (struct gdt_ccb *)arg;
1245 gdt = cam_sim_softc((struct cam_sim *)ccb->ccb_h.ccb_sim_ptr);
1247 GDT_DPRINTF(GDT_D_CMD, ("gdtexecuteccb(%p, %p, %p, %d, %d)\n",
1248 gdt, gccb, dm_segs, nseg, error));
1249 gdt_stat.sg_count_act = nseg;
1250 if (nseg > gdt_stat.sg_count_max)
1251 gdt_stat.sg_count_max = nseg;
1253 /* Copy the segments into our SG list */
1254 if (gccb->gc_service == GDT_CACHESERVICE) {
1255 for (i = 0; i < nseg; ++i) {
1256 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_LST +
1257 i * GDT_SG_SZ + GDT_SG_PTR, dm_segs->ds_addr);
1258 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_LST +
1259 i * GDT_SG_SZ + GDT_SG_LEN, dm_segs->ds_len);
1262 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_CANZ,
1264 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_DESTADDR,
1267 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_CACHE_SG_LST +
1268 nseg * GDT_SG_SZ, sizeof(u_int32_t));
1270 for (i = 0; i < nseg; ++i) {
1271 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_LST +
1272 i * GDT_SG_SZ + GDT_SG_PTR, dm_segs->ds_addr);
1273 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_LST +
1274 i * GDT_SG_SZ + GDT_SG_LEN, dm_segs->ds_len);
1277 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_RANZ,
1279 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SDATA,
1282 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_RAW_SG_LST +
1283 nseg * GDT_SG_SZ, sizeof(u_int32_t));
1287 bus_dmamap_sync(gdt->sc_buffer_dmat, gccb->gc_dmamap,
1288 (ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN ?
1289 BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
1292 /* We must NOT abort the command here if CAM_REQ_INPROG is not set,
1293 * because command semaphore is already set!
1296 ccb->ccb_h.status |= CAM_SIM_QUEUED;
1297 /* timeout handling */
1298 ccb->ccb_h.timeout_ch =
1299 timeout(iir_timeout, (caddr_t)gccb,
1300 (ccb->ccb_h.timeout * hz) / 1000);
1302 gdt->sc_copy_cmd(gdt, gccb);
1308 iir_action( struct cam_sim *sim, union ccb *ccb )
1310 struct gdt_softc *gdt;
1311 int lock, bus, target, lun;
1313 gdt = (struct gdt_softc *)cam_sim_softc( sim );
1314 ccb->ccb_h.ccb_sim_ptr = sim;
1315 bus = cam_sim_bus(sim);
1316 target = ccb->ccb_h.target_id;
1317 lun = ccb->ccb_h.target_lun;
1318 GDT_DPRINTF(GDT_D_CMD,
1319 ("iir_action(%p) func 0x%x cmd 0x%x bus %d target %d lun %d\n",
1320 gdt, ccb->ccb_h.func_code, ccb->csio.cdb_io.cdb_bytes[0],
1322 ++gdt_stat.io_count_act;
1323 if (gdt_stat.io_count_act > gdt_stat.io_count_max)
1324 gdt_stat.io_count_max = gdt_stat.io_count_act;
1326 switch (ccb->ccb_h.func_code) {
1329 TAILQ_INSERT_TAIL(&gdt->sc_ccb_queue, &ccb->ccb_h, sim_links.tqe);
1330 ++gdt_stat.req_queue_act;
1331 if (gdt_stat.req_queue_act > gdt_stat.req_queue_max)
1332 gdt_stat.req_queue_max = gdt_stat.req_queue_act;
1336 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
1337 case XPT_ABORT: /* Abort the specified CCB */
1339 ccb->ccb_h.status = CAM_REQ_INVALID;
1340 --gdt_stat.io_count_act;
1343 case XPT_SET_TRAN_SETTINGS:
1344 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1345 --gdt_stat.io_count_act;
1348 case XPT_GET_TRAN_SETTINGS:
1349 /* Get default/user set transfer settings for the target */
1351 struct ccb_trans_settings *cts = &ccb->cts;
1352 struct ccb_trans_settings_scsi *scsi = &cts->proto_specific.scsi;
1353 struct ccb_trans_settings_spi *spi = &cts->xport_specific.spi;
1355 cts->protocol = PROTO_SCSI;
1356 cts->protocol_version = SCSI_REV_2;
1357 cts->transport = XPORT_SPI;
1358 cts->transport_version = 2;
1360 if (cts->type == CTS_TYPE_USER_SETTINGS) {
1361 spi->flags = CTS_SPI_FLAGS_DISC_ENB;
1362 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
1363 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
1364 spi->sync_period = 25; /* 10MHz */
1365 if (spi->sync_period != 0)
1366 spi->sync_offset = 15;
1368 spi->valid = CTS_SPI_VALID_SYNC_RATE
1369 | CTS_SPI_VALID_SYNC_OFFSET
1370 | CTS_SPI_VALID_BUS_WIDTH
1371 | CTS_SPI_VALID_DISC;
1372 scsi->valid = CTS_SCSI_VALID_TQ;
1373 ccb->ccb_h.status = CAM_REQ_CMP;
1375 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1377 --gdt_stat.io_count_act;
1381 case XPT_CALC_GEOMETRY:
1383 struct ccb_calc_geometry *ccg;
1384 u_int32_t secs_per_cylinder;
1387 ccg->heads = gdt->sc_hdr[target].hd_heads;
1388 ccg->secs_per_track = gdt->sc_hdr[target].hd_secs;
1389 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
1390 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
1391 ccb->ccb_h.status = CAM_REQ_CMP;
1392 --gdt_stat.io_count_act;
1396 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
1399 ccb->ccb_h.status = CAM_REQ_CMP;
1400 --gdt_stat.io_count_act;
1404 case XPT_TERM_IO: /* Terminate the I/O process */
1406 ccb->ccb_h.status = CAM_REQ_INVALID;
1407 --gdt_stat.io_count_act;
1410 case XPT_PATH_INQ: /* Path routing inquiry */
1412 struct ccb_pathinq *cpi = &ccb->cpi;
1414 cpi->version_num = 1;
1415 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE;
1416 cpi->hba_inquiry |= PI_WIDE_16;
1417 cpi->target_sprt = 1;
1419 cpi->hba_eng_cnt = 0;
1420 if (bus == gdt->sc_virt_bus)
1421 cpi->max_target = GDT_MAX_HDRIVES - 1;
1422 else if (gdt->sc_class & GDT_FC)
1423 cpi->max_target = GDT_MAXID_FC - 1;
1425 cpi->max_target = GDT_MAXID - 1;
1427 cpi->unit_number = cam_sim_unit(sim);
1430 (bus == gdt->sc_virt_bus ? 127 : gdt->sc_bus_id[bus]);
1431 cpi->base_transfer_speed = 3300;
1432 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
1433 if (gdt->sc_vendor == INTEL_VENDOR_ID)
1434 strncpy(cpi->hba_vid, "Intel Corp.", HBA_IDLEN);
1436 strncpy(cpi->hba_vid, "ICP vortex ", HBA_IDLEN);
1437 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
1438 cpi->transport = XPORT_SPI;
1439 cpi->transport_version = 2;
1440 cpi->protocol = PROTO_SCSI;
1441 cpi->protocol_version = SCSI_REV_2;
1442 cpi->ccb_h.status = CAM_REQ_CMP;
1443 --gdt_stat.io_count_act;
1448 GDT_DPRINTF(GDT_D_INVALID, ("gdt_next(%p) cmd 0x%x invalid\n",
1449 gdt, ccb->ccb_h.func_code));
1450 ccb->ccb_h.status = CAM_REQ_INVALID;
1451 --gdt_stat.io_count_act;
1458 iir_poll( struct cam_sim *sim )
1460 struct gdt_softc *gdt;
1462 gdt = (struct gdt_softc *)cam_sim_softc( sim );
1463 GDT_DPRINTF(GDT_D_CMD, ("iir_poll sim %p gdt %p\n", sim, gdt));
1468 iir_timeout(void *arg)
1470 GDT_DPRINTF(GDT_D_TIMEOUT, ("iir_timeout(%p)\n", gccb));
1474 iir_watchdog(void *arg)
1476 struct gdt_softc *gdt;
1478 gdt = (struct gdt_softc *)arg;
1479 GDT_DPRINTF(GDT_D_DEBUG, ("iir_watchdog(%p)\n", gdt));
1482 int ccbs = 0, ucmds = 0, frees = 0, pends = 0;
1487 for (h = TAILQ_FIRST(&gdt->sc_ccb_queue); h != NULL;
1488 h = TAILQ_NEXT(h, sim_links.tqe))
1490 for (u = TAILQ_FIRST(&gdt->sc_ucmd_queue); u != NULL;
1491 u = TAILQ_NEXT(u, links))
1493 for (p = SLIST_FIRST(&gdt->sc_free_gccb); p != NULL;
1494 p = SLIST_NEXT(p, sle))
1496 for (p = SLIST_FIRST(&gdt->sc_pending_gccb); p != NULL;
1497 p = SLIST_NEXT(p, sle))
1500 GDT_DPRINTF(GDT_D_TIMEOUT, ("ccbs %d ucmds %d frees %d pends %d\n",
1501 ccbs, ucmds, frees, pends));
1504 timeout(iir_watchdog, (caddr_t)gdt, hz * 15);
1508 iir_shutdown( void *arg, int howto )
1510 struct gdt_softc *gdt;
1511 struct gdt_ccb *gccb;
1515 gdt = (struct gdt_softc *)arg;
1516 GDT_DPRINTF(GDT_D_CMD, ("iir_shutdown(%p, %d)\n", gdt, howto));
1518 printf("iir%d: Flushing all Host Drives. Please wait ... ",
1521 /* allocate ucmd buffer */
1522 ucmd = malloc(sizeof(gdt_ucmd_t), M_GDTBUF, M_NOWAIT);
1524 printf("iir%d: iir_shutdown(): Cannot allocate resource\n",
1528 bzero(ucmd, sizeof(gdt_ucmd_t));
1530 /* wait for pending IOs */
1532 gdt->sc_state = GDT_SHUTDOWN;
1534 if ((gccb = SLIST_FIRST(&gdt->sc_pending_gccb)) != NULL)
1535 (void) tsleep((void *)gccb, PCATCH | PRIBIO, "iirshw", 100 * hz);
1538 for (i = 0; i < GDT_MAX_HDRIVES; ++i) {
1539 if (gdt->sc_hdr[i].hd_present) {
1540 ucmd->service = GDT_CACHESERVICE;
1541 ucmd->OpCode = GDT_FLUSH;
1542 ucmd->u.cache.DeviceNo = i;
1544 TAILQ_INSERT_TAIL(&gdt->sc_ucmd_queue, ucmd, links);
1545 ucmd->complete_flag = FALSE;
1548 if (!ucmd->complete_flag)
1549 (void) tsleep((void *)ucmd, PCATCH|PRIBIO, "iirshw", 10*hz);
1553 free(ucmd, M_DEVBUF);
1560 struct gdt_softc *gdt = arg;
1561 struct gdt_intr_ctx ctx;
1563 struct gdt_ccb *gccb;
1567 GDT_DPRINTF(GDT_D_INTR, ("gdt_intr(%p)\n", gdt));
1569 /* If polling and we were not called from gdt_wait, just return */
1570 if ((gdt->sc_state & GDT_POLLING) &&
1571 !(gdt->sc_state & GDT_POLL_WAIT))
1574 if (!(gdt->sc_state & GDT_POLLING))
1578 ctx.istatus = gdt->sc_get_status(gdt);
1579 if (ctx.istatus == 0x00) {
1580 if (!(gdt->sc_state & GDT_POLLING))
1582 gdt->sc_status = GDT_S_NO_STATUS;
1586 gdt->sc_intr(gdt, &ctx);
1588 gdt->sc_status = ctx.cmd_status;
1589 gdt->sc_service = ctx.service;
1590 gdt->sc_info = ctx.info;
1591 gdt->sc_info2 = ctx.info2;
1593 if (gdt->sc_state & GDT_POLL_WAIT) {
1595 gdt_wait_index = ctx.istatus;
1598 if (ctx.istatus == GDT_ASYNCINDEX) {
1599 gdt_async_event(gdt, ctx.service);
1600 if (!(gdt->sc_state & GDT_POLLING))
1604 if (ctx.istatus == GDT_SPEZINDEX) {
1605 GDT_DPRINTF(GDT_D_INVALID,
1606 ("iir%d: Service unknown or not initialized!\n",
1608 gdt->sc_dvr.size = sizeof(gdt->sc_dvr.eu.driver);
1609 gdt->sc_dvr.eu.driver.ionode = gdt->sc_hanum;
1610 gdt_store_event(GDT_ES_DRIVER, 4, &gdt->sc_dvr);
1611 if (!(gdt->sc_state & GDT_POLLING))
1616 gccb = &gdt->sc_gccbs[ctx.istatus - 2];
1617 ctx.service = gccb->gc_service;
1619 switch (gccb->gc_flags) {
1620 case GDT_GCF_UNUSED:
1621 GDT_DPRINTF(GDT_D_INVALID, ("iir%d: Index (%d) to unused command!\n",
1622 gdt->sc_hanum, ctx.istatus));
1623 gdt->sc_dvr.size = sizeof(gdt->sc_dvr.eu.driver);
1624 gdt->sc_dvr.eu.driver.ionode = gdt->sc_hanum;
1625 gdt->sc_dvr.eu.driver.index = ctx.istatus;
1626 gdt_store_event(GDT_ES_DRIVER, 1, &gdt->sc_dvr);
1627 gdt_free_ccb(gdt, gccb);
1630 case GDT_GCF_INTERNAL:
1631 if (!(gdt->sc_state & GDT_POLLING))
1636 ucmd = gccb->gc_ucmd;
1637 if (gdt->sc_status == GDT_S_BSY) {
1638 GDT_DPRINTF(GDT_D_DEBUG, ("iir_intr(%p) ioctl: gccb %p busy\n",
1640 TAILQ_INSERT_HEAD(&gdt->sc_ucmd_queue, ucmd, links);
1641 if (!(gdt->sc_state & GDT_POLLING))
1644 ucmd->status = gdt->sc_status;
1645 ucmd->info = gdt->sc_info;
1646 ucmd->complete_flag = TRUE;
1647 if (ucmd->service == GDT_CACHESERVICE) {
1648 if (ucmd->OpCode == GDT_IOCTL) {
1649 cnt = ucmd->u.ioctl.param_size;
1651 bcopy(gccb->gc_scratch, ucmd->data, cnt);
1653 cnt = ucmd->u.cache.BlockCnt * GDT_SECTOR_SIZE;
1655 bcopy(gccb->gc_scratch, ucmd->data, cnt);
1658 cnt = ucmd->u.raw.sdlen;
1660 bcopy(gccb->gc_scratch, ucmd->data, cnt);
1661 if (ucmd->u.raw.sense_len != 0)
1662 bcopy(gccb->gc_scratch, ucmd->data, cnt);
1664 gdt_free_ccb(gdt, gccb);
1665 if (!(gdt->sc_state & GDT_POLLING))
1674 gdt_free_ccb(gdt, gccb);
1675 gdt_sync_event(gdt, ctx.service, ctx.istatus, gccb);
1676 if (!(gdt->sc_state & GDT_POLLING))
1684 gdt_async_event(struct gdt_softc *gdt, int service)
1686 struct gdt_ccb *gccb;
1688 GDT_DPRINTF(GDT_D_INTR, ("gdt_async_event(%p, %d)\n", gdt, service));
1690 if (service == GDT_SCREENSERVICE) {
1691 if (gdt->sc_status == GDT_MSG_REQUEST) {
1692 while (gdt->sc_test_busy(gdt))
1694 gccb = gdt_get_ccb(gdt);
1696 printf("iir%d: No free command index found\n",
1700 bzero(gccb->gc_cmd, GDT_CMD_SZ);
1701 gccb->gc_service = service;
1702 gccb->gc_flags = GDT_GCF_SCREEN;
1703 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
1704 gccb->gc_cmd_index);
1705 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, GDT_READ);
1706 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_HANDLE,
1707 GDT_MSG_INV_HANDLE);
1708 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_ADDR,
1709 gccb->gc_scratch_busbase);
1710 gdt->sc_set_sema0(gdt);
1711 gdt->sc_cmd_off = 0;
1712 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_SCREEN_SZ,
1714 gdt->sc_cmd_cnt = 0;
1715 gdt->sc_copy_cmd(gdt, gccb);
1716 printf("iir%d: [PCI %d/%d] ",
1717 gdt->sc_hanum,gdt->sc_bus,gdt->sc_slot);
1718 gdt->sc_release_event(gdt);
1722 if ((gdt->sc_fw_vers & 0xff) >= 0x1a) {
1723 gdt->sc_dvr.size = 0;
1724 gdt->sc_dvr.eu.async.ionode = gdt->sc_hanum;
1725 gdt->sc_dvr.eu.async.status = gdt->sc_status;
1726 /* severity and event_string already set! */
1728 gdt->sc_dvr.size = sizeof(gdt->sc_dvr.eu.async);
1729 gdt->sc_dvr.eu.async.ionode = gdt->sc_hanum;
1730 gdt->sc_dvr.eu.async.service = service;
1731 gdt->sc_dvr.eu.async.status = gdt->sc_status;
1732 gdt->sc_dvr.eu.async.info = gdt->sc_info;
1733 *(u_int32_t *)gdt->sc_dvr.eu.async.scsi_coord = gdt->sc_info2;
1735 gdt_store_event(GDT_ES_ASYNC, service, &gdt->sc_dvr);
1736 printf("iir%d: %s\n", gdt->sc_hanum, gdt->sc_dvr.event_string);
1743 gdt_sync_event(struct gdt_softc *gdt, int service,
1744 u_int8_t index, struct gdt_ccb *gccb)
1748 GDT_DPRINTF(GDT_D_INTR,
1749 ("gdt_sync_event(%p, %d, %d, %p)\n", gdt,service,index,gccb));
1753 if (service == GDT_SCREENSERVICE) {
1756 msg_len = gdt_dec32(gccb->gc_scratch + GDT_SCR_MSG_LEN);
1758 if (!(gccb->gc_scratch[GDT_SCR_MSG_ANSWER] &&
1759 gccb->gc_scratch[GDT_SCR_MSG_EXT])) {
1760 gccb->gc_scratch[GDT_SCR_MSG_TEXT + msg_len] = '\0';
1761 printf("%s",&gccb->gc_scratch[GDT_SCR_MSG_TEXT]);
1764 if (gccb->gc_scratch[GDT_SCR_MSG_EXT] &&
1765 !gccb->gc_scratch[GDT_SCR_MSG_ANSWER]) {
1766 while (gdt->sc_test_busy(gdt))
1768 bzero(gccb->gc_cmd, GDT_CMD_SZ);
1769 gccb = gdt_get_ccb(gdt);
1771 printf("iir%d: No free command index found\n",
1775 gccb->gc_service = service;
1776 gccb->gc_flags = GDT_GCF_SCREEN;
1777 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
1778 gccb->gc_cmd_index);
1779 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, GDT_READ);
1780 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_HANDLE,
1781 gccb->gc_scratch[GDT_SCR_MSG_HANDLE]);
1782 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_ADDR,
1783 gccb->gc_scratch_busbase);
1784 gdt->sc_set_sema0(gdt);
1785 gdt->sc_cmd_off = 0;
1786 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_SCREEN_SZ,
1788 gdt->sc_cmd_cnt = 0;
1789 gdt->sc_copy_cmd(gdt, gccb);
1790 gdt->sc_release_event(gdt);
1794 if (gccb->gc_scratch[GDT_SCR_MSG_ANSWER] &&
1795 gdt_dec32(gccb->gc_scratch + GDT_SCR_MSG_ALEN)) {
1796 /* default answers (getchar() not possible) */
1797 if (gdt_dec32(gccb->gc_scratch + GDT_SCR_MSG_ALEN) == 1) {
1798 gdt_enc32(gccb->gc_scratch + GDT_SCR_MSG_ALEN, 0);
1799 gdt_enc32(gccb->gc_scratch + GDT_SCR_MSG_LEN, 1);
1800 gccb->gc_scratch[GDT_SCR_MSG_TEXT] = 0;
1802 gdt_enc32(gccb->gc_scratch + GDT_SCR_MSG_ALEN,
1803 gdt_dec32(gccb->gc_scratch + GDT_SCR_MSG_ALEN) - 2);
1804 gdt_enc32(gccb->gc_scratch + GDT_SCR_MSG_LEN, 2);
1805 gccb->gc_scratch[GDT_SCR_MSG_TEXT] = 1;
1806 gccb->gc_scratch[GDT_SCR_MSG_TEXT + 1] = 0;
1808 gccb->gc_scratch[GDT_SCR_MSG_EXT] = 0;
1809 gccb->gc_scratch[GDT_SCR_MSG_ANSWER] = 0;
1810 while (gdt->sc_test_busy(gdt))
1812 bzero(gccb->gc_cmd, GDT_CMD_SZ);
1813 gccb = gdt_get_ccb(gdt);
1815 printf("iir%d: No free command index found\n",
1819 gccb->gc_service = service;
1820 gccb->gc_flags = GDT_GCF_SCREEN;
1821 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
1822 gccb->gc_cmd_index);
1823 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, GDT_WRITE);
1824 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_HANDLE,
1825 gccb->gc_scratch[GDT_SCR_MSG_HANDLE]);
1826 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_ADDR,
1827 gccb->gc_scratch_busbase);
1828 gdt->sc_set_sema0(gdt);
1829 gdt->sc_cmd_off = 0;
1830 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_SCREEN_SZ,
1832 gdt->sc_cmd_cnt = 0;
1833 gdt->sc_copy_cmd(gdt, gccb);
1834 gdt->sc_release_event(gdt);
1840 untimeout(iir_timeout, gccb, ccb->ccb_h.timeout_ch);
1841 if (gdt->sc_status == GDT_S_BSY) {
1842 GDT_DPRINTF(GDT_D_DEBUG, ("gdt_sync_event(%p) gccb %p busy\n",
1844 TAILQ_INSERT_HEAD(&gdt->sc_ccb_queue, &ccb->ccb_h, sim_links.tqe);
1845 ++gdt_stat.req_queue_act;
1846 if (gdt_stat.req_queue_act > gdt_stat.req_queue_max)
1847 gdt_stat.req_queue_max = gdt_stat.req_queue_act;
1851 bus_dmamap_sync(gdt->sc_buffer_dmat, gccb->gc_dmamap,
1852 (ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN ?
1853 BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
1854 bus_dmamap_unload(gdt->sc_buffer_dmat, gccb->gc_dmamap);
1856 ccb->csio.resid = 0;
1857 if (gdt->sc_status == GDT_S_OK) {
1858 ccb->ccb_h.status |= CAM_REQ_CMP;
1859 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1862 if (gccb->gc_service == GDT_CACHESERVICE) {
1863 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID;
1864 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1865 ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
1866 bzero(&ccb->csio.sense_data, ccb->csio.sense_len);
1867 ccb->csio.sense_data.error_code =
1868 SSD_CURRENT_ERROR | SSD_ERRCODE_VALID;
1869 ccb->csio.sense_data.flags = SSD_KEY_NOT_READY;
1871 gdt->sc_dvr.size = sizeof(gdt->sc_dvr.eu.sync);
1872 gdt->sc_dvr.eu.sync.ionode = gdt->sc_hanum;
1873 gdt->sc_dvr.eu.sync.service = service;
1874 gdt->sc_dvr.eu.sync.status = gdt->sc_status;
1875 gdt->sc_dvr.eu.sync.info = gdt->sc_info;
1876 gdt->sc_dvr.eu.sync.hostdrive = ccb->ccb_h.target_id;
1877 if (gdt->sc_status >= 0x8000)
1878 gdt_store_event(GDT_ES_SYNC, 0, &gdt->sc_dvr);
1880 gdt_store_event(GDT_ES_SYNC, service, &gdt->sc_dvr);
1883 if (gdt->sc_status != GDT_S_RAW_SCSI || gdt->sc_info >= 0x100) {
1884 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
1886 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR|CAM_AUTOSNS_VALID;
1887 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1888 ccb->csio.scsi_status = gdt->sc_info;
1889 bcopy(gccb->gc_scratch, &ccb->csio.sense_data,
1890 ccb->csio.sense_len);
1894 --gdt_stat.io_count_act;
1900 /* Controller event handling functions */
1901 gdt_evt_str *gdt_store_event(u_int16_t source, u_int16_t idx,
1907 GDT_DPRINTF(GDT_D_MISC, ("gdt_store_event(%d, %d)\n", source, idx));
1908 if (source == 0) /* no source -> no event */
1911 if (ebuffer[elastidx].event_source == source &&
1912 ebuffer[elastidx].event_idx == idx &&
1913 ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 &&
1914 !memcmp((char *)&ebuffer[elastidx].event_data.eu,
1915 (char *)&evt->eu, evt->size)) ||
1916 (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 &&
1917 !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
1918 (char *)&evt->event_string)))) {
1919 e = &ebuffer[elastidx];
1921 e->last_stamp = tv.tv_sec;
1924 if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */
1926 if (elastidx == GDT_MAX_EVENTS)
1928 if (elastidx == eoldidx) { /* reached mark ? */
1930 if (eoldidx == GDT_MAX_EVENTS)
1934 e = &ebuffer[elastidx];
1935 e->event_source = source;
1938 e->first_stamp = e->last_stamp = tv.tv_sec;
1940 e->event_data = *evt;
1946 int gdt_read_event(int handle, gdt_evt_str *estr)
1951 GDT_DPRINTF(GDT_D_MISC, ("gdt_read_event(%d)\n", handle));
1957 estr->event_source = 0;
1959 if (eindex >= GDT_MAX_EVENTS) {
1963 e = &ebuffer[eindex];
1964 if (e->event_source != 0) {
1965 if (eindex != elastidx) {
1966 if (++eindex == GDT_MAX_EVENTS)
1971 memcpy(estr, e, sizeof(gdt_evt_str));
1977 void gdt_readapp_event(u_int8_t application, gdt_evt_str *estr)
1983 GDT_DPRINTF(GDT_D_MISC, ("gdt_readapp_event(%d)\n", application));
1987 e = &ebuffer[eindex];
1988 if (e->event_source == 0)
1990 if ((e->application & application) == 0) {
1991 e->application |= application;
1995 if (eindex == elastidx)
1997 if (++eindex == GDT_MAX_EVENTS)
2001 memcpy(estr, e, sizeof(gdt_evt_str));
2003 estr->event_source = 0;
2007 void gdt_clear_events()
2009 GDT_DPRINTF(GDT_D_MISC, ("gdt_clear_events\n"));
2011 eoldidx = elastidx = 0;
2012 ebuffer[0].event_source = 0;