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>
70 #include <dev/iir/iir.h>
72 MALLOC_DEFINE(M_GDTBUF, "iirbuf", "iir driver buffer");
74 struct gdt_softc *gdt_wait_gdt;
78 int gdt_debug = GDT_DEBUG;
80 #define MAX_SERBUF 160
81 static void ser_init(void);
82 static void ser_puts(char *str);
83 static void ser_putc(int c);
84 static char strbuf[MAX_SERBUF+1];
86 #define COM_BASE 0x2f8
88 #define COM_BASE 0x3f8
90 static void ser_init()
92 unsigned port=COM_BASE;
96 /* 19200 Baud, if 9600: outb(12,port) */
102 static void ser_puts(char *str)
107 for (ptr=str;*ptr;++ptr)
108 ser_putc((int)(*ptr));
111 static void ser_putc(int c)
113 unsigned port=COM_BASE;
115 while ((inb(port+5) & 0x20)==0);
119 while ((inb(port+5) & 0x20)==0);
124 int ser_printf(const char *fmt, ...)
130 i = vsprintf(strbuf,fmt,args);
138 /* The linked list of softc structures */
139 struct gdt_softc_list gdt_softcs = TAILQ_HEAD_INITIALIZER(gdt_softcs);
140 /* controller cnt. */
143 static gdt_evt_str ebuffer[GDT_MAX_EVENTS];
144 static int elastidx, eoldidx;
146 gdt_statist_t gdt_stat;
148 /* Definitions for our use of the SIM private CCB area */
149 #define ccb_sim_ptr spriv_ptr0
150 #define ccb_priority spriv_field1
152 static void iir_action(struct cam_sim *sim, union ccb *ccb);
153 static void iir_poll(struct cam_sim *sim);
154 static void iir_shutdown(void *arg, int howto);
155 static void iir_timeout(void *arg);
156 static void iir_watchdog(void *arg);
158 static void gdt_eval_mapping(u_int32_t size, int *cyls, int *heads,
160 static int gdt_internal_cmd(struct gdt_softc *gdt, struct gdt_ccb *gccb,
161 u_int8_t service, u_int16_t opcode,
162 u_int32_t arg1, u_int32_t arg2, u_int32_t arg3);
163 static int gdt_wait(struct gdt_softc *gdt, struct gdt_ccb *ccb,
166 static struct gdt_ccb *gdt_get_ccb(struct gdt_softc *gdt);
168 static int gdt_sync_event(struct gdt_softc *gdt, int service,
169 u_int8_t index, struct gdt_ccb *gccb);
170 static int gdt_async_event(struct gdt_softc *gdt, int service);
171 static struct gdt_ccb *gdt_raw_cmd(struct gdt_softc *gdt,
172 union ccb *ccb, int *lock);
173 static struct gdt_ccb *gdt_cache_cmd(struct gdt_softc *gdt,
174 union ccb *ccb, int *lock);
175 static struct gdt_ccb *gdt_ioctl_cmd(struct gdt_softc *gdt,
176 gdt_ucmd_t *ucmd, int *lock);
177 static void gdt_internal_cache_cmd(struct gdt_softc *gdt,union ccb *ccb);
179 static void gdtmapmem(void *arg, bus_dma_segment_t *dm_segs,
180 int nseg, int error);
181 static void gdtexecuteccb(void *arg, bus_dma_segment_t *dm_segs,
182 int nseg, int error);
185 iir_init(struct gdt_softc *gdt)
188 int i, id, drv_cyls, drv_hds, drv_secs;
189 struct gdt_ccb *gccb;
191 GDT_DPRINTF(GDT_D_DEBUG, ("iir_init()\n"));
193 gdt->sc_state = GDT_POLLING;
195 bzero(&gdt_stat, sizeof(gdt_statist_t));
197 SLIST_INIT(&gdt->sc_free_gccb);
198 SLIST_INIT(&gdt->sc_pending_gccb);
199 TAILQ_INIT(&gdt->sc_ccb_queue);
200 TAILQ_INIT(&gdt->sc_ucmd_queue);
201 TAILQ_INSERT_TAIL(&gdt_softcs, gdt, links);
203 /* DMA tag for mapping buffers into device visible space. */
204 if (bus_dma_tag_create(gdt->sc_parent_dmat, /*alignment*/1, /*boundary*/0,
205 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
206 /*highaddr*/BUS_SPACE_MAXADDR,
207 /*filter*/NULL, /*filterarg*/NULL,
208 /*maxsize*/MAXBSIZE, /*nsegments*/GDT_MAXSG,
209 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
210 /*flags*/BUS_DMA_ALLOCNOW,
211 /*lockfunc*/busdma_lock_mutex, /*lockarg*/&Giant,
212 &gdt->sc_buffer_dmat) != 0) {
213 printf("iir%d: bus_dma_tag_create(...,gdt->sc_buffer_dmat) failed\n",
217 gdt->sc_init_level++;
219 /* DMA tag for our ccb structures */
220 if (bus_dma_tag_create(gdt->sc_parent_dmat,
223 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
224 /*highaddr*/BUS_SPACE_MAXADDR,
227 GDT_MAXCMDS * GDT_SCRATCH_SZ, /* maxsize */
229 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
230 /*flags*/0, /*lockfunc*/busdma_lock_mutex,
231 /*lockarg*/&Giant, &gdt->sc_gcscratch_dmat) != 0) {
232 printf("iir%d: bus_dma_tag_create(...,gdt->sc_gcscratch_dmat) failed\n",
236 gdt->sc_init_level++;
238 /* Allocation for our ccb scratch area */
239 if (bus_dmamem_alloc(gdt->sc_gcscratch_dmat, (void **)&gdt->sc_gcscratch,
240 BUS_DMA_NOWAIT, &gdt->sc_gcscratch_dmamap) != 0) {
241 printf("iir%d: bus_dmamem_alloc(...,&gdt->sc_gccbs,...) failed\n",
245 gdt->sc_init_level++;
247 /* And permanently map them */
248 bus_dmamap_load(gdt->sc_gcscratch_dmat, gdt->sc_gcscratch_dmamap,
249 gdt->sc_gcscratch, GDT_MAXCMDS * GDT_SCRATCH_SZ,
250 gdtmapmem, &gdt->sc_gcscratch_busbase, /*flags*/0);
251 gdt->sc_init_level++;
253 /* Clear them out. */
254 bzero(gdt->sc_gcscratch, GDT_MAXCMDS * GDT_SCRATCH_SZ);
256 /* Initialize the ccbs */
257 gdt->sc_gccbs = malloc(sizeof(struct gdt_ccb) * GDT_MAXCMDS, M_GDTBUF,
259 if (gdt->sc_gccbs == NULL) {
260 printf("iir%d: no memory for gccbs.\n", gdt->sc_hanum);
263 for (i = GDT_MAXCMDS-1; i >= 0; i--) {
264 gccb = &gdt->sc_gccbs[i];
265 gccb->gc_cmd_index = i + 2;
266 gccb->gc_flags = GDT_GCF_UNUSED;
267 gccb->gc_map_flag = FALSE;
268 if (bus_dmamap_create(gdt->sc_buffer_dmat, /*flags*/0,
269 &gccb->gc_dmamap) != 0)
271 gccb->gc_map_flag = TRUE;
272 gccb->gc_scratch = &gdt->sc_gcscratch[GDT_SCRATCH_SZ * i];
273 gccb->gc_scratch_busbase = gdt->sc_gcscratch_busbase + GDT_SCRATCH_SZ * i;
274 SLIST_INSERT_HEAD(&gdt->sc_free_gccb, gccb, sle);
276 gdt->sc_init_level++;
278 /* create the control device */
279 gdt->sc_dev = gdt_make_dev(gdt->sc_hanum);
281 /* allocate ccb for gdt_internal_cmd() */
282 gccb = gdt_get_ccb(gdt);
284 printf("iir%d: No free command index found\n",
288 bzero(gccb->gc_cmd, GDT_CMD_SZ);
290 if (!gdt_internal_cmd(gdt, gccb, GDT_SCREENSERVICE, GDT_INIT,
292 printf("iir%d: Screen service initialization error %d\n",
293 gdt->sc_hanum, gdt->sc_status);
294 gdt_free_ccb(gdt, gccb);
298 gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_UNFREEZE_IO,
301 if (!gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_INIT,
302 GDT_LINUX_OS, 0, 0)) {
303 printf("iir%d: Cache service initialization error %d\n",
304 gdt->sc_hanum, gdt->sc_status);
305 gdt_free_ccb(gdt, gccb);
308 cdev_cnt = (u_int16_t)gdt->sc_info;
309 gdt->sc_fw_vers = gdt->sc_service;
311 /* Detect number of buses */
312 gdt_enc32(gccb->gc_scratch + GDT_IOC_VERSION, GDT_IOC_NEWEST);
313 gccb->gc_scratch[GDT_IOC_LIST_ENTRIES] = GDT_MAXBUS;
314 gccb->gc_scratch[GDT_IOC_FIRST_CHAN] = 0;
315 gccb->gc_scratch[GDT_IOC_LAST_CHAN] = GDT_MAXBUS - 1;
316 gdt_enc32(gccb->gc_scratch + GDT_IOC_LIST_OFFSET, GDT_IOC_HDR_SZ);
317 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_IOCTL,
318 GDT_IOCHAN_RAW_DESC, GDT_INVALID_CHANNEL,
319 GDT_IOC_HDR_SZ + GDT_MAXBUS * GDT_RAWIOC_SZ)) {
320 gdt->sc_bus_cnt = gccb->gc_scratch[GDT_IOC_CHAN_COUNT];
321 for (i = 0; i < gdt->sc_bus_cnt; i++) {
322 id = gccb->gc_scratch[GDT_IOC_HDR_SZ +
323 i * GDT_RAWIOC_SZ + GDT_RAWIOC_PROC_ID];
324 gdt->sc_bus_id[i] = id < GDT_MAXID_FC ? id : 0xff;
327 /* New method failed, use fallback. */
328 for (i = 0; i < GDT_MAXBUS; i++) {
329 gdt_enc32(gccb->gc_scratch + GDT_GETCH_CHANNEL_NO, i);
330 if (!gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_IOCTL,
331 GDT_SCSI_CHAN_CNT | GDT_L_CTRL_PATTERN,
332 GDT_IO_CHANNEL | GDT_INVALID_CHANNEL,
335 printf("iir%d: Cannot get channel count, "
336 "error %d\n", gdt->sc_hanum, gdt->sc_status);
337 gdt_free_ccb(gdt, gccb);
343 (gccb->gc_scratch[GDT_GETCH_SIOP_ID] < GDT_MAXID_FC) ?
344 gccb->gc_scratch[GDT_GETCH_SIOP_ID] : 0xff;
348 /* add one "virtual" channel for the host drives */
349 gdt->sc_virt_bus = gdt->sc_bus_cnt;
352 if (!gdt_internal_cmd(gdt, gccb, GDT_SCSIRAWSERVICE, GDT_INIT,
354 printf("iir%d: Raw service initialization error %d\n",
355 gdt->sc_hanum, gdt->sc_status);
356 gdt_free_ccb(gdt, gccb);
360 /* Set/get features raw service (scatter/gather) */
361 gdt->sc_raw_feat = 0;
362 if (gdt_internal_cmd(gdt, gccb, GDT_SCSIRAWSERVICE, GDT_SET_FEAT,
363 GDT_SCATTER_GATHER, 0, 0)) {
364 if (gdt_internal_cmd(gdt, gccb, GDT_SCSIRAWSERVICE, GDT_GET_FEAT,
366 gdt->sc_raw_feat = gdt->sc_info;
367 if (!(gdt->sc_info & GDT_SCATTER_GATHER)) {
368 panic("iir%d: Scatter/Gather Raw Service "
369 "required but not supported!\n", gdt->sc_hanum);
370 gdt_free_ccb(gdt, gccb);
376 /* Set/get features cache service (scatter/gather) */
377 gdt->sc_cache_feat = 0;
378 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_SET_FEAT,
379 0, GDT_SCATTER_GATHER, 0)) {
380 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_GET_FEAT,
382 gdt->sc_cache_feat = gdt->sc_info;
383 if (!(gdt->sc_info & GDT_SCATTER_GATHER)) {
384 panic("iir%d: Scatter/Gather Cache Service "
385 "required but not supported!\n", gdt->sc_hanum);
386 gdt_free_ccb(gdt, gccb);
393 gdt_enc32(gccb->gc_scratch + GDT_OEM_VERSION, 0x01);
394 gdt_enc32(gccb->gc_scratch + GDT_OEM_BUFSIZE, sizeof(gdt_oem_record_t));
395 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_IOCTL,
396 GDT_OEM_STR_RECORD, GDT_INVALID_CHANNEL,
397 sizeof(gdt_oem_str_record_t))) {
398 strncpy(gdt->oem_name, ((gdt_oem_str_record_t *)
399 gccb->gc_scratch)->text.scsi_host_drive_inquiry_vendor_id, 7);
400 gdt->oem_name[7]='\0';
402 /* Old method, based on PCI ID */
403 if (gdt->sc_vendor == INTEL_VENDOR_ID)
404 strcpy(gdt->oem_name,"Intel ");
406 strcpy(gdt->oem_name,"ICP ");
409 /* Scan for cache devices */
410 for (i = 0; i < cdev_cnt && i < GDT_MAX_HDRIVES; i++) {
411 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE, GDT_INFO,
413 gdt->sc_hdr[i].hd_present = 1;
414 gdt->sc_hdr[i].hd_size = gdt->sc_info;
417 * Evaluate mapping (sectors per head, heads per cyl)
419 gdt->sc_hdr[i].hd_size &= ~GDT_SECS32;
420 if (gdt->sc_info2 == 0)
421 gdt_eval_mapping(gdt->sc_hdr[i].hd_size,
422 &drv_cyls, &drv_hds, &drv_secs);
424 drv_hds = gdt->sc_info2 & 0xff;
425 drv_secs = (gdt->sc_info2 >> 8) & 0xff;
426 drv_cyls = gdt->sc_hdr[i].hd_size / drv_hds /
429 gdt->sc_hdr[i].hd_heads = drv_hds;
430 gdt->sc_hdr[i].hd_secs = drv_secs;
432 gdt->sc_hdr[i].hd_size = drv_cyls * drv_hds * drv_secs;
434 if (gdt_internal_cmd(gdt, gccb, GDT_CACHESERVICE,
435 GDT_DEVTYPE, i, 0, 0))
436 gdt->sc_hdr[i].hd_devtype = gdt->sc_info;
440 GDT_DPRINTF(GDT_D_INIT, ("dpmem %x %d-bus %d cache device%s\n",
442 gdt->sc_bus_cnt, cdev_cnt,
443 cdev_cnt == 1 ? "" : "s"));
444 gdt_free_ccb(gdt, gccb);
451 iir_free(struct gdt_softc *gdt)
455 GDT_DPRINTF(GDT_D_INIT, ("iir_free()\n"));
457 switch (gdt->sc_init_level) {
459 gdt_destroy_dev(gdt->sc_dev);
461 for (i = GDT_MAXCMDS-1; i >= 0; i--)
462 if (gdt->sc_gccbs[i].gc_map_flag)
463 bus_dmamap_destroy(gdt->sc_buffer_dmat,
464 gdt->sc_gccbs[i].gc_dmamap);
465 bus_dmamap_unload(gdt->sc_gcscratch_dmat, gdt->sc_gcscratch_dmamap);
466 free(gdt->sc_gccbs, M_GDTBUF);
468 bus_dmamem_free(gdt->sc_gcscratch_dmat, gdt->sc_gcscratch, gdt->sc_gcscratch_dmamap);
470 bus_dma_tag_destroy(gdt->sc_gcscratch_dmat);
472 bus_dma_tag_destroy(gdt->sc_buffer_dmat);
474 bus_dma_tag_destroy(gdt->sc_parent_dmat);
478 TAILQ_REMOVE(&gdt_softcs, gdt, links);
482 iir_attach(struct gdt_softc *gdt)
484 struct cam_devq *devq;
487 GDT_DPRINTF(GDT_D_INIT, ("iir_attach()\n"));
490 * Create the device queue for our SIM.
491 * XXX Throttle this down since the card has problems under load.
493 devq = cam_simq_alloc(32);
497 for (i = 0; i < gdt->sc_bus_cnt; i++) {
499 * Construct our SIM entry
501 gdt->sims[i] = cam_sim_alloc(iir_action, iir_poll, "iir",
502 gdt, gdt->sc_hanum, &Giant,
504 /*tagged*/GDT_MAXCMDS, devq);
505 if (xpt_bus_register(gdt->sims[i], gdt->sc_devnode, i) != CAM_SUCCESS) {
506 cam_sim_free(gdt->sims[i], /*free_devq*/i == 0);
510 if (xpt_create_path(&gdt->paths[i], /*periph*/NULL,
511 cam_sim_path(gdt->sims[i]),
513 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
514 xpt_bus_deregister(cam_sim_path(gdt->sims[i]));
515 cam_sim_free(gdt->sims[i], /*free_devq*/i == 0);
520 EVENTHANDLER_REGISTER(shutdown_final, iir_shutdown,
521 gdt, SHUTDOWN_PRI_DEFAULT);
522 /* iir_watchdog(gdt); */
523 gdt->sc_state = GDT_NORMAL;
527 gdt_eval_mapping(u_int32_t size, int *cyls, int *heads, int *secs)
529 *cyls = size / GDT_HEADS / GDT_SECS;
530 if (*cyls < GDT_MAXCYLS) {
534 /* Too high for 64 * 32 */
535 *cyls = size / GDT_MEDHEADS / GDT_MEDSECS;
536 if (*cyls < GDT_MAXCYLS) {
537 *heads = GDT_MEDHEADS;
540 /* Too high for 127 * 63 */
541 *cyls = size / GDT_BIGHEADS / GDT_BIGSECS;
542 *heads = GDT_BIGHEADS;
549 gdt_wait(struct gdt_softc *gdt, struct gdt_ccb *gccb,
554 GDT_DPRINTF(GDT_D_INIT,
555 ("gdt_wait(%p, %p, %d)\n", gdt, gccb, timeout));
557 gdt->sc_state |= GDT_POLL_WAIT;
560 if (gdt == gdt_wait_gdt &&
561 gccb->gc_cmd_index == gdt_wait_index) {
567 gdt->sc_state &= ~GDT_POLL_WAIT;
569 while (gdt->sc_test_busy(gdt))
570 DELAY(1); /* XXX correct? */
576 gdt_internal_cmd(struct gdt_softc *gdt, struct gdt_ccb *gccb,
577 u_int8_t service, u_int16_t opcode,
578 u_int32_t arg1, u_int32_t arg2, u_int32_t arg3)
582 GDT_DPRINTF(GDT_D_CMD, ("gdt_internal_cmd(%p, %d, %d, %d, %d, %d)\n",
583 gdt, service, opcode, arg1, arg2, arg3));
585 bzero(gccb->gc_cmd, GDT_CMD_SZ);
587 for (retries = GDT_RETRIES; ; ) {
588 gccb->gc_service = service;
589 gccb->gc_flags = GDT_GCF_INTERNAL;
591 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
593 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, opcode);
596 case GDT_CACHESERVICE:
597 if (opcode == GDT_IOCTL) {
598 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION +
599 GDT_IOCTL_SUBFUNC, arg1);
600 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION +
601 GDT_IOCTL_CHANNEL, arg2);
602 gdt_enc16(gccb->gc_cmd + GDT_CMD_UNION +
603 GDT_IOCTL_PARAM_SIZE, (u_int16_t)arg3);
604 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_IOCTL_P_PARAM,
605 gccb->gc_scratch_busbase);
607 gdt_enc16(gccb->gc_cmd + GDT_CMD_UNION +
608 GDT_CACHE_DEVICENO, (u_int16_t)arg1);
609 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION +
610 GDT_CACHE_BLOCKNO, arg2);
614 case GDT_SCSIRAWSERVICE:
615 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION +
616 GDT_RAW_DIRECTION, arg1);
617 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_BUS] =
619 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_TARGET] =
621 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_LUN] =
622 (u_int8_t)(arg3 >> 8);
625 gdt->sc_set_sema0(gdt);
626 gccb->gc_cmd_len = GDT_CMD_SZ;
629 gdt->sc_copy_cmd(gdt, gccb);
630 gdt->sc_release_event(gdt);
632 if (!gdt_wait(gdt, gccb, GDT_POLL_TIMEOUT))
634 if (gdt->sc_status != GDT_S_BSY || --retries == 0)
638 return (gdt->sc_status == GDT_S_OK);
641 static struct gdt_ccb *
642 gdt_get_ccb(struct gdt_softc *gdt)
644 struct gdt_ccb *gccb;
647 GDT_DPRINTF(GDT_D_QUEUE, ("gdt_get_ccb(%p)\n", gdt));
650 gccb = SLIST_FIRST(&gdt->sc_free_gccb);
652 SLIST_REMOVE_HEAD(&gdt->sc_free_gccb, sle);
653 SLIST_INSERT_HEAD(&gdt->sc_pending_gccb, gccb, sle);
654 ++gdt_stat.cmd_index_act;
655 if (gdt_stat.cmd_index_act > gdt_stat.cmd_index_max)
656 gdt_stat.cmd_index_max = gdt_stat.cmd_index_act;
663 gdt_free_ccb(struct gdt_softc *gdt, struct gdt_ccb *gccb)
667 GDT_DPRINTF(GDT_D_QUEUE, ("gdt_free_ccb(%p, %p)\n", gdt, gccb));
670 gccb->gc_flags = GDT_GCF_UNUSED;
671 SLIST_REMOVE(&gdt->sc_pending_gccb, gccb, gdt_ccb, sle);
672 SLIST_INSERT_HEAD(&gdt->sc_free_gccb, gccb, sle);
673 --gdt_stat.cmd_index_act;
675 if (gdt->sc_state & GDT_SHUTDOWN)
680 gdt_next(struct gdt_softc *gdt)
686 int bus, target, lun;
689 struct ccb_scsiio *csio;
690 struct ccb_hdr *ccbh;
691 struct gdt_ccb *gccb = NULL;
694 GDT_DPRINTF(GDT_D_QUEUE, ("gdt_next(%p)\n", gdt));
697 if (gdt->sc_test_busy(gdt)) {
698 if (!(gdt->sc_state & GDT_POLLING)) {
702 while (gdt->sc_test_busy(gdt))
706 gdt->sc_cmd_cnt = gdt->sc_cmd_off = 0;
709 /* I/Os in queue? controller ready? */
710 if (!TAILQ_FIRST(&gdt->sc_ucmd_queue) &&
711 !TAILQ_FIRST(&gdt->sc_ccb_queue))
714 /* 1.: I/Os without ccb (IOCTLs) */
715 ucmd = TAILQ_FIRST(&gdt->sc_ucmd_queue);
717 TAILQ_REMOVE(&gdt->sc_ucmd_queue, ucmd, links);
718 if ((gccb = gdt_ioctl_cmd(gdt, ucmd, &lock)) == NULL) {
719 TAILQ_INSERT_HEAD(&gdt->sc_ucmd_queue, ucmd, links);
723 /* wenn mehrere Kdos. zulassen: if (!gdt_polling) continue; */
726 /* 2.: I/Os with ccb */
727 ccb = (union ccb *)TAILQ_FIRST(&gdt->sc_ccb_queue);
728 /* ist dann immer != NULL, da oben getestet */
729 sim = (struct cam_sim *)ccb->ccb_h.ccb_sim_ptr;
730 bus = cam_sim_bus(sim);
731 target = ccb->ccb_h.target_id;
732 lun = ccb->ccb_h.target_lun;
734 TAILQ_REMOVE(&gdt->sc_ccb_queue, &ccb->ccb_h, sim_links.tqe);
735 --gdt_stat.req_queue_act;
736 /* ccb->ccb_h.func_code is XPT_SCSI_IO */
737 GDT_DPRINTF(GDT_D_QUEUE, ("XPT_SCSI_IO flags 0x%x)\n",
741 cmd = csio->cdb_io.cdb_bytes[0];
742 /* Max CDB length is 12 bytes */
743 if (csio->cdb_len > 12) {
744 ccbh->status = CAM_REQ_INVALID;
745 --gdt_stat.io_count_act;
747 } else if (bus != gdt->sc_virt_bus) {
748 /* raw service command */
749 if ((gccb = gdt_raw_cmd(gdt, ccb, &lock)) == NULL) {
750 TAILQ_INSERT_HEAD(&gdt->sc_ccb_queue, &ccb->ccb_h,
752 ++gdt_stat.req_queue_act;
753 if (gdt_stat.req_queue_act > gdt_stat.req_queue_max)
754 gdt_stat.req_queue_max = gdt_stat.req_queue_act;
757 } else if (target >= GDT_MAX_HDRIVES ||
758 !gdt->sc_hdr[target].hd_present || lun != 0) {
759 ccbh->status = CAM_DEV_NOT_THERE;
760 --gdt_stat.io_count_act;
763 /* cache service command */
764 if (cmd == READ_6 || cmd == WRITE_6 ||
765 cmd == READ_10 || cmd == WRITE_10) {
766 if ((gccb = gdt_cache_cmd(gdt, ccb, &lock)) == NULL) {
767 TAILQ_INSERT_HEAD(&gdt->sc_ccb_queue, &ccb->ccb_h,
769 ++gdt_stat.req_queue_act;
770 if (gdt_stat.req_queue_act > gdt_stat.req_queue_max)
771 gdt_stat.req_queue_max = gdt_stat.req_queue_act;
776 gdt_internal_cache_cmd(gdt, ccb);
780 if ((gdt->sc_state & GDT_POLLING) || !next_cmd)
783 if (gdt->sc_cmd_cnt > 0)
784 gdt->sc_release_event(gdt);
788 if ((gdt->sc_state & GDT_POLLING) && gdt->sc_cmd_cnt > 0) {
789 gdt_wait(gdt, gccb, GDT_POLL_TIMEOUT);
793 static struct gdt_ccb *
794 gdt_raw_cmd(struct gdt_softc *gdt, union ccb *ccb, int *lock)
796 struct gdt_ccb *gccb;
799 GDT_DPRINTF(GDT_D_CMD, ("gdt_raw_cmd(%p, %p)\n", gdt, ccb));
801 if (roundup(GDT_CMD_UNION + GDT_RAW_SZ, sizeof(u_int32_t)) +
802 gdt->sc_cmd_off + GDT_DPMEM_COMMAND_OFFSET >
803 gdt->sc_ic_all_size) {
804 GDT_DPRINTF(GDT_D_INVALID, ("iir%d: gdt_raw_cmd(): DPMEM overflow\n",
809 gccb = gdt_get_ccb(gdt);
811 GDT_DPRINTF(GDT_D_INVALID, ("iir%d: No free command index found\n",
815 bzero(gccb->gc_cmd, GDT_CMD_SZ);
816 sim = (struct cam_sim *)ccb->ccb_h.ccb_sim_ptr;
818 gccb->gc_service = GDT_SCSIRAWSERVICE;
819 gccb->gc_flags = GDT_GCF_SCSI;
821 if (gdt->sc_cmd_cnt == 0)
822 gdt->sc_set_sema0(gdt);
824 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
826 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, GDT_WRITE);
828 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_DIRECTION,
829 (ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN ?
830 GDT_DATA_IN : GDT_DATA_OUT);
831 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SDLEN,
832 ccb->csio.dxfer_len);
833 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_CLEN,
835 bcopy(ccb->csio.cdb_io.cdb_bytes, gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_CMD,
837 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_TARGET] =
838 ccb->ccb_h.target_id;
839 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_LUN] =
840 ccb->ccb_h.target_lun;
841 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_BUS] =
843 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SENSE_LEN,
844 sizeof(struct scsi_sense_data));
845 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SENSE_DATA,
846 gccb->gc_scratch_busbase);
849 * If we have any data to send with this command,
850 * map it into bus space.
852 /* Only use S/G if there is a transfer */
853 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
854 if ((ccb->ccb_h.flags & CAM_SCATTER_VALID) == 0) {
855 if ((ccb->ccb_h.flags & CAM_DATA_PHYS) == 0) {
859 /* vorher unlock von splcam() ??? */
862 bus_dmamap_load(gdt->sc_buffer_dmat,
868 if (error == EINPROGRESS) {
869 xpt_freeze_simq(sim, 1);
870 gccb->gc_ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
874 panic("iir: CAM_DATA_PHYS not supported");
877 struct bus_dma_segment *segs;
879 if ((ccb->ccb_h.flags & CAM_DATA_PHYS) != 0)
880 panic("iir%d: iir_action - Physical "
881 "segment pointers unsupported", gdt->sc_hanum);
883 if ((ccb->ccb_h.flags & CAM_SG_LIST_PHYS)==0)
884 panic("iir%d: iir_action - Virtual "
885 "segment addresses unsupported", gdt->sc_hanum);
887 /* Just use the segments provided */
888 segs = (struct bus_dma_segment *)ccb->csio.data_ptr;
889 gdtexecuteccb(gccb, segs, ccb->csio.sglist_cnt, 0);
892 gdtexecuteccb(gccb, NULL, 0, 0);
899 static struct gdt_ccb *
900 gdt_cache_cmd(struct gdt_softc *gdt, union ccb *ccb, int *lock)
902 struct gdt_ccb *gccb;
906 u_int32_t blockno, blockcnt;
908 GDT_DPRINTF(GDT_D_CMD, ("gdt_cache_cmd(%p, %p)\n", gdt, ccb));
910 if (roundup(GDT_CMD_UNION + GDT_CACHE_SZ, sizeof(u_int32_t)) +
911 gdt->sc_cmd_off + GDT_DPMEM_COMMAND_OFFSET >
912 gdt->sc_ic_all_size) {
913 GDT_DPRINTF(GDT_D_INVALID, ("iir%d: gdt_cache_cmd(): DPMEM overflow\n",
918 gccb = gdt_get_ccb(gdt);
920 GDT_DPRINTF(GDT_D_DEBUG, ("iir%d: No free command index found\n",
924 bzero(gccb->gc_cmd, GDT_CMD_SZ);
925 sim = (struct cam_sim *)ccb->ccb_h.ccb_sim_ptr;
927 gccb->gc_service = GDT_CACHESERVICE;
928 gccb->gc_flags = GDT_GCF_SCSI;
930 if (gdt->sc_cmd_cnt == 0)
931 gdt->sc_set_sema0(gdt);
933 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
935 cmdp = ccb->csio.cdb_io.cdb_bytes;
936 opcode = (*cmdp == WRITE_6 || *cmdp == WRITE_10) ? GDT_WRITE : GDT_READ;
937 if ((gdt->sc_state & GDT_SHUTDOWN) && opcode == GDT_WRITE)
938 opcode = GDT_WRITE_THR;
939 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, opcode);
941 gdt_enc16(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_DEVICENO,
942 ccb->ccb_h.target_id);
943 if (ccb->csio.cdb_len == 6) {
944 struct scsi_rw_6 *rw = (struct scsi_rw_6 *)cmdp;
945 blockno = scsi_3btoul(rw->addr) & ((SRW_TOPADDR<<16) | 0xffff);
946 blockcnt = rw->length ? rw->length : 0x100;
948 struct scsi_rw_10 *rw = (struct scsi_rw_10 *)cmdp;
949 blockno = scsi_4btoul(rw->addr);
950 blockcnt = scsi_2btoul(rw->length);
952 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_BLOCKNO,
954 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_BLOCKCNT,
958 * If we have any data to send with this command,
959 * map it into bus space.
961 /* Only use S/G if there is a transfer */
962 if ((ccb->ccb_h.flags & CAM_SCATTER_VALID) == 0) {
963 if ((ccb->ccb_h.flags & CAM_DATA_PHYS) == 0) {
967 /* vorher unlock von splcam() ??? */
970 bus_dmamap_load(gdt->sc_buffer_dmat,
976 if (error == EINPROGRESS) {
977 xpt_freeze_simq(sim, 1);
978 gccb->gc_ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
982 panic("iir: CAM_DATA_PHYS not supported");
985 struct bus_dma_segment *segs;
987 if ((ccb->ccb_h.flags & CAM_DATA_PHYS) != 0)
988 panic("iir%d: iir_action - Physical "
989 "segment pointers unsupported", gdt->sc_hanum);
991 if ((ccb->ccb_h.flags & CAM_SG_LIST_PHYS)==0)
992 panic("iir%d: iir_action - Virtual "
993 "segment addresses unsupported", gdt->sc_hanum);
995 /* Just use the segments provided */
996 segs = (struct bus_dma_segment *)ccb->csio.data_ptr;
997 gdtexecuteccb(gccb, segs, ccb->csio.sglist_cnt, 0);
1004 static struct gdt_ccb *
1005 gdt_ioctl_cmd(struct gdt_softc *gdt, gdt_ucmd_t *ucmd, int *lock)
1007 struct gdt_ccb *gccb;
1010 GDT_DPRINTF(GDT_D_DEBUG, ("gdt_ioctl_cmd(%p, %p)\n", gdt, ucmd));
1012 gccb = gdt_get_ccb(gdt);
1014 GDT_DPRINTF(GDT_D_DEBUG, ("iir%d: No free command index found\n",
1018 bzero(gccb->gc_cmd, GDT_CMD_SZ);
1019 gccb->gc_ucmd = ucmd;
1020 gccb->gc_service = ucmd->service;
1021 gccb->gc_flags = GDT_GCF_IOCTL;
1023 /* check DPMEM space, copy data buffer from user space */
1024 if (ucmd->service == GDT_CACHESERVICE) {
1025 if (ucmd->OpCode == GDT_IOCTL) {
1026 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_IOCTL_SZ,
1028 cnt = ucmd->u.ioctl.param_size;
1029 if (cnt > GDT_SCRATCH_SZ) {
1030 printf("iir%d: Scratch buffer too small (%d/%d)\n",
1031 gdt->sc_hanum, GDT_SCRATCH_SZ, cnt);
1032 gdt_free_ccb(gdt, gccb);
1036 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_CACHE_SG_LST +
1037 GDT_SG_SZ, sizeof(u_int32_t));
1038 cnt = ucmd->u.cache.BlockCnt * GDT_SECTOR_SIZE;
1039 if (cnt > GDT_SCRATCH_SZ) {
1040 printf("iir%d: Scratch buffer too small (%d/%d)\n",
1041 gdt->sc_hanum, GDT_SCRATCH_SZ, cnt);
1042 gdt_free_ccb(gdt, gccb);
1047 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_RAW_SG_LST +
1048 GDT_SG_SZ, sizeof(u_int32_t));
1049 cnt = ucmd->u.raw.sdlen;
1050 if (cnt + ucmd->u.raw.sense_len > GDT_SCRATCH_SZ) {
1051 printf("iir%d: Scratch buffer too small (%d/%d)\n",
1052 gdt->sc_hanum, GDT_SCRATCH_SZ, cnt + ucmd->u.raw.sense_len);
1053 gdt_free_ccb(gdt, gccb);
1058 bcopy(ucmd->data, gccb->gc_scratch, cnt);
1060 if (gdt->sc_cmd_off + gccb->gc_cmd_len + GDT_DPMEM_COMMAND_OFFSET >
1061 gdt->sc_ic_all_size) {
1062 GDT_DPRINTF(GDT_D_INVALID, ("iir%d: gdt_ioctl_cmd(): DPMEM overflow\n",
1064 gdt_free_ccb(gdt, gccb);
1068 if (gdt->sc_cmd_cnt == 0)
1069 gdt->sc_set_sema0(gdt);
1072 /* fill cmd structure */
1073 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
1074 gccb->gc_cmd_index);
1075 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE,
1078 if (ucmd->service == GDT_CACHESERVICE) {
1079 if (ucmd->OpCode == GDT_IOCTL) {
1081 gdt_enc16(gccb->gc_cmd + GDT_CMD_UNION + GDT_IOCTL_PARAM_SIZE,
1082 ucmd->u.ioctl.param_size);
1083 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_IOCTL_SUBFUNC,
1084 ucmd->u.ioctl.subfunc);
1085 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_IOCTL_CHANNEL,
1086 ucmd->u.ioctl.channel);
1087 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_IOCTL_P_PARAM,
1088 gccb->gc_scratch_busbase);
1090 /* cache service command */
1091 gdt_enc16(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_DEVICENO,
1092 ucmd->u.cache.DeviceNo);
1093 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_BLOCKNO,
1094 ucmd->u.cache.BlockNo);
1095 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_BLOCKCNT,
1096 ucmd->u.cache.BlockCnt);
1097 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_DESTADDR,
1099 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_CANZ,
1101 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_LST +
1102 GDT_SG_PTR, gccb->gc_scratch_busbase);
1103 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_LST +
1104 GDT_SG_LEN, ucmd->u.cache.BlockCnt * GDT_SECTOR_SIZE);
1107 /* raw service command */
1108 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_DIRECTION,
1109 ucmd->u.raw.direction);
1110 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SDATA,
1112 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SDLEN,
1114 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_CLEN,
1116 bcopy(ucmd->u.raw.cmd, gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_CMD,
1118 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_TARGET] =
1120 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_LUN] =
1122 gccb->gc_cmd[GDT_CMD_UNION + GDT_RAW_BUS] =
1124 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SENSE_LEN,
1125 ucmd->u.raw.sense_len);
1126 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SENSE_DATA,
1127 gccb->gc_scratch_busbase + ucmd->u.raw.sdlen);
1128 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_RANZ,
1130 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_LST +
1131 GDT_SG_PTR, gccb->gc_scratch_busbase);
1132 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_LST +
1133 GDT_SG_LEN, ucmd->u.raw.sdlen);
1137 gdt_stat.sg_count_act = 1;
1138 gdt->sc_copy_cmd(gdt, gccb);
1143 gdt_internal_cache_cmd(struct gdt_softc *gdt,union ccb *ccb)
1147 t = ccb->ccb_h.target_id;
1148 GDT_DPRINTF(GDT_D_CMD, ("gdt_internal_cache_cmd(%p, %p, 0x%x, %d)\n",
1149 gdt, ccb, ccb->csio.cdb_io.cdb_bytes[0], t));
1151 switch (ccb->csio.cdb_io.cdb_bytes[0]) {
1152 case TEST_UNIT_READY:
1156 GDT_DPRINTF(GDT_D_MISC, ("REQUEST_SENSE\n"));
1160 struct scsi_inquiry_data inq;
1161 size_t copylen = MIN(sizeof(inq), ccb->csio.dxfer_len);
1163 bzero(&inq, sizeof(inq));
1164 inq.device = (gdt->sc_hdr[t].hd_devtype & 4) ?
1166 inq.dev_qual2 = (gdt->sc_hdr[t].hd_devtype & 1) ? 0x80 : 0;
1167 inq.version = SCSI_REV_2;
1168 inq.response_format = 2;
1169 inq.additional_length = 32;
1170 inq.flags = SID_CmdQue | SID_Sync;
1171 strncpy(inq.vendor, gdt->oem_name, sizeof(inq.vendor));
1172 snprintf(inq.product, sizeof(inq.product),
1173 "Host Drive #%02d", t);
1174 strncpy(inq.revision, " ", sizeof(inq.revision));
1175 bcopy(&inq, ccb->csio.data_ptr, copylen );
1176 if( ccb->csio.dxfer_len > copylen )
1177 bzero( ccb->csio.data_ptr+copylen,
1178 ccb->csio.dxfer_len - copylen );
1184 struct scsi_mode_hdr_6 hd;
1185 struct scsi_mode_block_descr bd;
1186 struct scsi_control_page cp;
1188 size_t copylen = MIN(sizeof(mpd), ccb->csio.dxfer_len);
1191 /*mpd = (struct mpd_data *)ccb->csio.data_ptr;*/
1192 bzero(&mpd, sizeof(mpd));
1193 mpd.hd.datalen = sizeof(struct scsi_mode_hdr_6) +
1194 sizeof(struct scsi_mode_block_descr);
1195 mpd.hd.dev_specific = (gdt->sc_hdr[t].hd_devtype & 2) ? 0x80 : 0;
1196 mpd.hd.block_descr_len = sizeof(struct scsi_mode_block_descr);
1197 mpd.bd.block_len[0] = (GDT_SECTOR_SIZE & 0x00ff0000) >> 16;
1198 mpd.bd.block_len[1] = (GDT_SECTOR_SIZE & 0x0000ff00) >> 8;
1199 mpd.bd.block_len[2] = (GDT_SECTOR_SIZE & 0x000000ff);
1201 bcopy(&mpd, ccb->csio.data_ptr, copylen );
1202 if( ccb->csio.dxfer_len > copylen )
1203 bzero( ccb->csio.data_ptr+copylen,
1204 ccb->csio.dxfer_len - copylen );
1205 page=((struct scsi_mode_sense_6 *)ccb->csio.cdb_io.cdb_bytes)->page;
1208 GDT_DPRINTF(GDT_D_MISC, ("MODE_SENSE_6: page 0x%x\n", page));
1215 struct scsi_read_capacity_data rcd;
1216 size_t copylen = MIN(sizeof(rcd), ccb->csio.dxfer_len);
1218 /*rcd = (struct scsi_read_capacity_data *)ccb->csio.data_ptr;*/
1219 bzero(&rcd, sizeof(rcd));
1220 scsi_ulto4b(gdt->sc_hdr[t].hd_size - 1, rcd.addr);
1221 scsi_ulto4b(GDT_SECTOR_SIZE, rcd.length);
1222 bcopy(&rcd, ccb->csio.data_ptr, copylen );
1223 if( ccb->csio.dxfer_len > copylen )
1224 bzero( ccb->csio.data_ptr+copylen,
1225 ccb->csio.dxfer_len - copylen );
1229 GDT_DPRINTF(GDT_D_MISC, ("gdt_internal_cache_cmd(%d) unknown\n",
1230 ccb->csio.cdb_io.cdb_bytes[0]));
1233 ccb->ccb_h.status |= CAM_REQ_CMP;
1234 --gdt_stat.io_count_act;
1239 gdtmapmem(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1241 bus_addr_t *busaddrp;
1243 busaddrp = (bus_addr_t *)arg;
1244 *busaddrp = dm_segs->ds_addr;
1248 gdtexecuteccb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1250 struct gdt_ccb *gccb;
1252 struct gdt_softc *gdt;
1257 gccb = (struct gdt_ccb *)arg;
1259 gdt = cam_sim_softc((struct cam_sim *)ccb->ccb_h.ccb_sim_ptr);
1261 GDT_DPRINTF(GDT_D_CMD, ("gdtexecuteccb(%p, %p, %p, %d, %d)\n",
1262 gdt, gccb, dm_segs, nseg, error));
1263 gdt_stat.sg_count_act = nseg;
1264 if (nseg > gdt_stat.sg_count_max)
1265 gdt_stat.sg_count_max = nseg;
1267 /* Copy the segments into our SG list */
1268 if (gccb->gc_service == GDT_CACHESERVICE) {
1269 for (i = 0; i < nseg; ++i) {
1270 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_LST +
1271 i * GDT_SG_SZ + GDT_SG_PTR, dm_segs->ds_addr);
1272 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_LST +
1273 i * GDT_SG_SZ + GDT_SG_LEN, dm_segs->ds_len);
1276 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_SG_CANZ,
1278 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_CACHE_DESTADDR,
1281 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_CACHE_SG_LST +
1282 nseg * GDT_SG_SZ, sizeof(u_int32_t));
1284 for (i = 0; i < nseg; ++i) {
1285 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_LST +
1286 i * GDT_SG_SZ + GDT_SG_PTR, dm_segs->ds_addr);
1287 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_LST +
1288 i * GDT_SG_SZ + GDT_SG_LEN, dm_segs->ds_len);
1291 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SG_RANZ,
1293 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_RAW_SDATA,
1296 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_RAW_SG_LST +
1297 nseg * GDT_SG_SZ, sizeof(u_int32_t));
1301 bus_dmamap_sync(gdt->sc_buffer_dmat, gccb->gc_dmamap,
1302 (ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN ?
1303 BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
1306 /* We must NOT abort the command here if CAM_REQ_INPROG is not set,
1307 * because command semaphore is already set!
1310 ccb->ccb_h.status |= CAM_SIM_QUEUED;
1311 /* timeout handling */
1312 ccb->ccb_h.timeout_ch =
1313 timeout(iir_timeout, (caddr_t)gccb,
1314 (ccb->ccb_h.timeout * hz) / 1000);
1316 gdt->sc_copy_cmd(gdt, gccb);
1322 iir_action( struct cam_sim *sim, union ccb *ccb )
1324 struct gdt_softc *gdt;
1325 int lock, bus, target, lun;
1327 gdt = (struct gdt_softc *)cam_sim_softc( sim );
1328 ccb->ccb_h.ccb_sim_ptr = sim;
1329 bus = cam_sim_bus(sim);
1330 target = ccb->ccb_h.target_id;
1331 lun = ccb->ccb_h.target_lun;
1332 GDT_DPRINTF(GDT_D_CMD,
1333 ("iir_action(%p) func 0x%x cmd 0x%x bus %d target %d lun %d\n",
1334 gdt, ccb->ccb_h.func_code, ccb->csio.cdb_io.cdb_bytes[0],
1336 ++gdt_stat.io_count_act;
1337 if (gdt_stat.io_count_act > gdt_stat.io_count_max)
1338 gdt_stat.io_count_max = gdt_stat.io_count_act;
1340 switch (ccb->ccb_h.func_code) {
1343 TAILQ_INSERT_TAIL(&gdt->sc_ccb_queue, &ccb->ccb_h, sim_links.tqe);
1344 ++gdt_stat.req_queue_act;
1345 if (gdt_stat.req_queue_act > gdt_stat.req_queue_max)
1346 gdt_stat.req_queue_max = gdt_stat.req_queue_act;
1350 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
1351 case XPT_ABORT: /* Abort the specified CCB */
1353 ccb->ccb_h.status = CAM_REQ_INVALID;
1354 --gdt_stat.io_count_act;
1357 case XPT_SET_TRAN_SETTINGS:
1358 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1359 --gdt_stat.io_count_act;
1362 case XPT_GET_TRAN_SETTINGS:
1363 /* Get default/user set transfer settings for the target */
1365 struct ccb_trans_settings *cts = &ccb->cts;
1366 struct ccb_trans_settings_scsi *scsi = &cts->proto_specific.scsi;
1367 struct ccb_trans_settings_spi *spi = &cts->xport_specific.spi;
1369 cts->protocol = PROTO_SCSI;
1370 cts->protocol_version = SCSI_REV_2;
1371 cts->transport = XPORT_SPI;
1372 cts->transport_version = 2;
1374 if (cts->type == CTS_TYPE_USER_SETTINGS) {
1375 spi->flags = CTS_SPI_FLAGS_DISC_ENB;
1376 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
1377 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
1378 spi->sync_period = 25; /* 10MHz */
1379 if (spi->sync_period != 0)
1380 spi->sync_offset = 15;
1382 spi->valid = CTS_SPI_VALID_SYNC_RATE
1383 | CTS_SPI_VALID_SYNC_OFFSET
1384 | CTS_SPI_VALID_BUS_WIDTH
1385 | CTS_SPI_VALID_DISC;
1386 scsi->valid = CTS_SCSI_VALID_TQ;
1387 ccb->ccb_h.status = CAM_REQ_CMP;
1389 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1391 --gdt_stat.io_count_act;
1395 case XPT_CALC_GEOMETRY:
1397 struct ccb_calc_geometry *ccg;
1398 u_int32_t secs_per_cylinder;
1401 ccg->heads = gdt->sc_hdr[target].hd_heads;
1402 ccg->secs_per_track = gdt->sc_hdr[target].hd_secs;
1403 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
1404 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
1405 ccb->ccb_h.status = CAM_REQ_CMP;
1406 --gdt_stat.io_count_act;
1410 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
1413 ccb->ccb_h.status = CAM_REQ_CMP;
1414 --gdt_stat.io_count_act;
1418 case XPT_TERM_IO: /* Terminate the I/O process */
1420 ccb->ccb_h.status = CAM_REQ_INVALID;
1421 --gdt_stat.io_count_act;
1424 case XPT_PATH_INQ: /* Path routing inquiry */
1426 struct ccb_pathinq *cpi = &ccb->cpi;
1428 cpi->version_num = 1;
1429 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE;
1430 cpi->hba_inquiry |= PI_WIDE_16;
1431 cpi->target_sprt = 1;
1433 cpi->hba_eng_cnt = 0;
1434 if (bus == gdt->sc_virt_bus)
1435 cpi->max_target = GDT_MAX_HDRIVES - 1;
1436 else if (gdt->sc_class & GDT_FC)
1437 cpi->max_target = GDT_MAXID_FC - 1;
1439 cpi->max_target = GDT_MAXID - 1;
1441 cpi->unit_number = cam_sim_unit(sim);
1444 (bus == gdt->sc_virt_bus ? 127 : gdt->sc_bus_id[bus]);
1445 cpi->base_transfer_speed = 3300;
1446 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
1447 if (gdt->sc_vendor == INTEL_VENDOR_ID)
1448 strncpy(cpi->hba_vid, "Intel Corp.", HBA_IDLEN);
1450 strncpy(cpi->hba_vid, "ICP vortex ", HBA_IDLEN);
1451 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
1452 cpi->transport = XPORT_SPI;
1453 cpi->transport_version = 2;
1454 cpi->protocol = PROTO_SCSI;
1455 cpi->protocol_version = SCSI_REV_2;
1456 cpi->ccb_h.status = CAM_REQ_CMP;
1457 --gdt_stat.io_count_act;
1462 GDT_DPRINTF(GDT_D_INVALID, ("gdt_next(%p) cmd 0x%x invalid\n",
1463 gdt, ccb->ccb_h.func_code));
1464 ccb->ccb_h.status = CAM_REQ_INVALID;
1465 --gdt_stat.io_count_act;
1472 iir_poll( struct cam_sim *sim )
1474 struct gdt_softc *gdt;
1476 gdt = (struct gdt_softc *)cam_sim_softc( sim );
1477 GDT_DPRINTF(GDT_D_CMD, ("iir_poll sim %p gdt %p\n", sim, gdt));
1482 iir_timeout(void *arg)
1484 GDT_DPRINTF(GDT_D_TIMEOUT, ("iir_timeout(%p)\n", gccb));
1488 iir_watchdog(void *arg)
1490 struct gdt_softc *gdt;
1492 gdt = (struct gdt_softc *)arg;
1493 GDT_DPRINTF(GDT_D_DEBUG, ("iir_watchdog(%p)\n", gdt));
1496 int ccbs = 0, ucmds = 0, frees = 0, pends = 0;
1501 for (h = TAILQ_FIRST(&gdt->sc_ccb_queue); h != NULL;
1502 h = TAILQ_NEXT(h, sim_links.tqe))
1504 for (u = TAILQ_FIRST(&gdt->sc_ucmd_queue); u != NULL;
1505 u = TAILQ_NEXT(u, links))
1507 for (p = SLIST_FIRST(&gdt->sc_free_gccb); p != NULL;
1508 p = SLIST_NEXT(p, sle))
1510 for (p = SLIST_FIRST(&gdt->sc_pending_gccb); p != NULL;
1511 p = SLIST_NEXT(p, sle))
1514 GDT_DPRINTF(GDT_D_TIMEOUT, ("ccbs %d ucmds %d frees %d pends %d\n",
1515 ccbs, ucmds, frees, pends));
1518 timeout(iir_watchdog, (caddr_t)gdt, hz * 15);
1522 iir_shutdown( void *arg, int howto )
1524 struct gdt_softc *gdt;
1525 struct gdt_ccb *gccb;
1529 gdt = (struct gdt_softc *)arg;
1530 GDT_DPRINTF(GDT_D_CMD, ("iir_shutdown(%p, %d)\n", gdt, howto));
1532 printf("iir%d: Flushing all Host Drives. Please wait ... ",
1535 /* allocate ucmd buffer */
1536 ucmd = malloc(sizeof(gdt_ucmd_t), M_GDTBUF, M_NOWAIT);
1538 printf("iir%d: iir_shutdown(): Cannot allocate resource\n",
1542 bzero(ucmd, sizeof(gdt_ucmd_t));
1544 /* wait for pending IOs */
1546 gdt->sc_state = GDT_SHUTDOWN;
1548 if ((gccb = SLIST_FIRST(&gdt->sc_pending_gccb)) != NULL)
1549 (void) tsleep((void *)gccb, PCATCH | PRIBIO, "iirshw", 100 * hz);
1552 for (i = 0; i < GDT_MAX_HDRIVES; ++i) {
1553 if (gdt->sc_hdr[i].hd_present) {
1554 ucmd->service = GDT_CACHESERVICE;
1555 ucmd->OpCode = GDT_FLUSH;
1556 ucmd->u.cache.DeviceNo = i;
1558 TAILQ_INSERT_TAIL(&gdt->sc_ucmd_queue, ucmd, links);
1559 ucmd->complete_flag = FALSE;
1562 if (!ucmd->complete_flag)
1563 (void) tsleep((void *)ucmd, PCATCH|PRIBIO, "iirshw", 10*hz);
1567 free(ucmd, M_DEVBUF);
1574 struct gdt_softc *gdt = arg;
1575 struct gdt_intr_ctx ctx;
1577 struct gdt_ccb *gccb;
1581 GDT_DPRINTF(GDT_D_INTR, ("gdt_intr(%p)\n", gdt));
1583 /* If polling and we were not called from gdt_wait, just return */
1584 if ((gdt->sc_state & GDT_POLLING) &&
1585 !(gdt->sc_state & GDT_POLL_WAIT))
1588 if (!(gdt->sc_state & GDT_POLLING))
1592 ctx.istatus = gdt->sc_get_status(gdt);
1593 if (ctx.istatus == 0x00) {
1594 if (!(gdt->sc_state & GDT_POLLING))
1596 gdt->sc_status = GDT_S_NO_STATUS;
1600 gdt->sc_intr(gdt, &ctx);
1602 gdt->sc_status = ctx.cmd_status;
1603 gdt->sc_service = ctx.service;
1604 gdt->sc_info = ctx.info;
1605 gdt->sc_info2 = ctx.info2;
1607 if (gdt->sc_state & GDT_POLL_WAIT) {
1609 gdt_wait_index = ctx.istatus;
1612 if (ctx.istatus == GDT_ASYNCINDEX) {
1613 gdt_async_event(gdt, ctx.service);
1614 if (!(gdt->sc_state & GDT_POLLING))
1618 if (ctx.istatus == GDT_SPEZINDEX) {
1619 GDT_DPRINTF(GDT_D_INVALID,
1620 ("iir%d: Service unknown or not initialized!\n",
1622 gdt->sc_dvr.size = sizeof(gdt->sc_dvr.eu.driver);
1623 gdt->sc_dvr.eu.driver.ionode = gdt->sc_hanum;
1624 gdt_store_event(GDT_ES_DRIVER, 4, &gdt->sc_dvr);
1625 if (!(gdt->sc_state & GDT_POLLING))
1630 gccb = &gdt->sc_gccbs[ctx.istatus - 2];
1631 ctx.service = gccb->gc_service;
1633 switch (gccb->gc_flags) {
1634 case GDT_GCF_UNUSED:
1635 GDT_DPRINTF(GDT_D_INVALID, ("iir%d: Index (%d) to unused command!\n",
1636 gdt->sc_hanum, ctx.istatus));
1637 gdt->sc_dvr.size = sizeof(gdt->sc_dvr.eu.driver);
1638 gdt->sc_dvr.eu.driver.ionode = gdt->sc_hanum;
1639 gdt->sc_dvr.eu.driver.index = ctx.istatus;
1640 gdt_store_event(GDT_ES_DRIVER, 1, &gdt->sc_dvr);
1641 gdt_free_ccb(gdt, gccb);
1644 case GDT_GCF_INTERNAL:
1645 if (!(gdt->sc_state & GDT_POLLING))
1650 ucmd = gccb->gc_ucmd;
1651 if (gdt->sc_status == GDT_S_BSY) {
1652 GDT_DPRINTF(GDT_D_DEBUG, ("iir_intr(%p) ioctl: gccb %p busy\n",
1654 TAILQ_INSERT_HEAD(&gdt->sc_ucmd_queue, ucmd, links);
1655 if (!(gdt->sc_state & GDT_POLLING))
1658 ucmd->status = gdt->sc_status;
1659 ucmd->info = gdt->sc_info;
1660 ucmd->complete_flag = TRUE;
1661 if (ucmd->service == GDT_CACHESERVICE) {
1662 if (ucmd->OpCode == GDT_IOCTL) {
1663 cnt = ucmd->u.ioctl.param_size;
1665 bcopy(gccb->gc_scratch, ucmd->data, cnt);
1667 cnt = ucmd->u.cache.BlockCnt * GDT_SECTOR_SIZE;
1669 bcopy(gccb->gc_scratch, ucmd->data, cnt);
1672 cnt = ucmd->u.raw.sdlen;
1674 bcopy(gccb->gc_scratch, ucmd->data, cnt);
1675 if (ucmd->u.raw.sense_len != 0)
1676 bcopy(gccb->gc_scratch, ucmd->data, cnt);
1678 gdt_free_ccb(gdt, gccb);
1679 if (!(gdt->sc_state & GDT_POLLING))
1688 gdt_free_ccb(gdt, gccb);
1689 gdt_sync_event(gdt, ctx.service, ctx.istatus, gccb);
1690 if (!(gdt->sc_state & GDT_POLLING))
1698 gdt_async_event(struct gdt_softc *gdt, int service)
1700 struct gdt_ccb *gccb;
1702 GDT_DPRINTF(GDT_D_INTR, ("gdt_async_event(%p, %d)\n", gdt, service));
1704 if (service == GDT_SCREENSERVICE) {
1705 if (gdt->sc_status == GDT_MSG_REQUEST) {
1706 while (gdt->sc_test_busy(gdt))
1708 gccb = gdt_get_ccb(gdt);
1710 printf("iir%d: No free command index found\n",
1714 bzero(gccb->gc_cmd, GDT_CMD_SZ);
1715 gccb->gc_service = service;
1716 gccb->gc_flags = GDT_GCF_SCREEN;
1717 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
1718 gccb->gc_cmd_index);
1719 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, GDT_READ);
1720 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_HANDLE,
1721 GDT_MSG_INV_HANDLE);
1722 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_ADDR,
1723 gccb->gc_scratch_busbase);
1724 gdt->sc_set_sema0(gdt);
1725 gdt->sc_cmd_off = 0;
1726 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_SCREEN_SZ,
1728 gdt->sc_cmd_cnt = 0;
1729 gdt->sc_copy_cmd(gdt, gccb);
1730 printf("iir%d: [PCI %d/%d] ",
1731 gdt->sc_hanum,gdt->sc_bus,gdt->sc_slot);
1732 gdt->sc_release_event(gdt);
1736 if ((gdt->sc_fw_vers & 0xff) >= 0x1a) {
1737 gdt->sc_dvr.size = 0;
1738 gdt->sc_dvr.eu.async.ionode = gdt->sc_hanum;
1739 gdt->sc_dvr.eu.async.status = gdt->sc_status;
1740 /* severity and event_string already set! */
1742 gdt->sc_dvr.size = sizeof(gdt->sc_dvr.eu.async);
1743 gdt->sc_dvr.eu.async.ionode = gdt->sc_hanum;
1744 gdt->sc_dvr.eu.async.service = service;
1745 gdt->sc_dvr.eu.async.status = gdt->sc_status;
1746 gdt->sc_dvr.eu.async.info = gdt->sc_info;
1747 *(u_int32_t *)gdt->sc_dvr.eu.async.scsi_coord = gdt->sc_info2;
1749 gdt_store_event(GDT_ES_ASYNC, service, &gdt->sc_dvr);
1750 printf("iir%d: %s\n", gdt->sc_hanum, gdt->sc_dvr.event_string);
1757 gdt_sync_event(struct gdt_softc *gdt, int service,
1758 u_int8_t index, struct gdt_ccb *gccb)
1762 GDT_DPRINTF(GDT_D_INTR,
1763 ("gdt_sync_event(%p, %d, %d, %p)\n", gdt,service,index,gccb));
1767 if (service == GDT_SCREENSERVICE) {
1770 msg_len = gdt_dec32(gccb->gc_scratch + GDT_SCR_MSG_LEN);
1772 if (!(gccb->gc_scratch[GDT_SCR_MSG_ANSWER] &&
1773 gccb->gc_scratch[GDT_SCR_MSG_EXT])) {
1774 gccb->gc_scratch[GDT_SCR_MSG_TEXT + msg_len] = '\0';
1775 printf("%s",&gccb->gc_scratch[GDT_SCR_MSG_TEXT]);
1778 if (gccb->gc_scratch[GDT_SCR_MSG_EXT] &&
1779 !gccb->gc_scratch[GDT_SCR_MSG_ANSWER]) {
1780 while (gdt->sc_test_busy(gdt))
1782 bzero(gccb->gc_cmd, GDT_CMD_SZ);
1783 gccb = gdt_get_ccb(gdt);
1785 printf("iir%d: No free command index found\n",
1789 gccb->gc_service = service;
1790 gccb->gc_flags = GDT_GCF_SCREEN;
1791 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
1792 gccb->gc_cmd_index);
1793 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, GDT_READ);
1794 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_HANDLE,
1795 gccb->gc_scratch[GDT_SCR_MSG_HANDLE]);
1796 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_ADDR,
1797 gccb->gc_scratch_busbase);
1798 gdt->sc_set_sema0(gdt);
1799 gdt->sc_cmd_off = 0;
1800 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_SCREEN_SZ,
1802 gdt->sc_cmd_cnt = 0;
1803 gdt->sc_copy_cmd(gdt, gccb);
1804 gdt->sc_release_event(gdt);
1808 if (gccb->gc_scratch[GDT_SCR_MSG_ANSWER] &&
1809 gdt_dec32(gccb->gc_scratch + GDT_SCR_MSG_ALEN)) {
1810 /* default answers (getchar() not possible) */
1811 if (gdt_dec32(gccb->gc_scratch + GDT_SCR_MSG_ALEN) == 1) {
1812 gdt_enc32(gccb->gc_scratch + GDT_SCR_MSG_ALEN, 0);
1813 gdt_enc32(gccb->gc_scratch + GDT_SCR_MSG_LEN, 1);
1814 gccb->gc_scratch[GDT_SCR_MSG_TEXT] = 0;
1816 gdt_enc32(gccb->gc_scratch + GDT_SCR_MSG_ALEN,
1817 gdt_dec32(gccb->gc_scratch + GDT_SCR_MSG_ALEN) - 2);
1818 gdt_enc32(gccb->gc_scratch + GDT_SCR_MSG_LEN, 2);
1819 gccb->gc_scratch[GDT_SCR_MSG_TEXT] = 1;
1820 gccb->gc_scratch[GDT_SCR_MSG_TEXT + 1] = 0;
1822 gccb->gc_scratch[GDT_SCR_MSG_EXT] = 0;
1823 gccb->gc_scratch[GDT_SCR_MSG_ANSWER] = 0;
1824 while (gdt->sc_test_busy(gdt))
1826 bzero(gccb->gc_cmd, GDT_CMD_SZ);
1827 gccb = gdt_get_ccb(gdt);
1829 printf("iir%d: No free command index found\n",
1833 gccb->gc_service = service;
1834 gccb->gc_flags = GDT_GCF_SCREEN;
1835 gdt_enc32(gccb->gc_cmd + GDT_CMD_COMMANDINDEX,
1836 gccb->gc_cmd_index);
1837 gdt_enc16(gccb->gc_cmd + GDT_CMD_OPCODE, GDT_WRITE);
1838 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_HANDLE,
1839 gccb->gc_scratch[GDT_SCR_MSG_HANDLE]);
1840 gdt_enc32(gccb->gc_cmd + GDT_CMD_UNION + GDT_SCREEN_MSG_ADDR,
1841 gccb->gc_scratch_busbase);
1842 gdt->sc_set_sema0(gdt);
1843 gdt->sc_cmd_off = 0;
1844 gccb->gc_cmd_len = roundup(GDT_CMD_UNION + GDT_SCREEN_SZ,
1846 gdt->sc_cmd_cnt = 0;
1847 gdt->sc_copy_cmd(gdt, gccb);
1848 gdt->sc_release_event(gdt);
1854 untimeout(iir_timeout, gccb, ccb->ccb_h.timeout_ch);
1855 if (gdt->sc_status == GDT_S_BSY) {
1856 GDT_DPRINTF(GDT_D_DEBUG, ("gdt_sync_event(%p) gccb %p busy\n",
1858 TAILQ_INSERT_HEAD(&gdt->sc_ccb_queue, &ccb->ccb_h, sim_links.tqe);
1859 ++gdt_stat.req_queue_act;
1860 if (gdt_stat.req_queue_act > gdt_stat.req_queue_max)
1861 gdt_stat.req_queue_max = gdt_stat.req_queue_act;
1865 bus_dmamap_sync(gdt->sc_buffer_dmat, gccb->gc_dmamap,
1866 (ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN ?
1867 BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
1868 bus_dmamap_unload(gdt->sc_buffer_dmat, gccb->gc_dmamap);
1870 ccb->csio.resid = 0;
1871 if (gdt->sc_status == GDT_S_OK) {
1872 ccb->ccb_h.status |= CAM_REQ_CMP;
1873 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1876 if (gccb->gc_service == GDT_CACHESERVICE) {
1877 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID;
1878 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1879 ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
1880 bzero(&ccb->csio.sense_data, ccb->csio.sense_len);
1881 ccb->csio.sense_data.error_code =
1882 SSD_CURRENT_ERROR | SSD_ERRCODE_VALID;
1883 ccb->csio.sense_data.flags = SSD_KEY_NOT_READY;
1885 gdt->sc_dvr.size = sizeof(gdt->sc_dvr.eu.sync);
1886 gdt->sc_dvr.eu.sync.ionode = gdt->sc_hanum;
1887 gdt->sc_dvr.eu.sync.service = service;
1888 gdt->sc_dvr.eu.sync.status = gdt->sc_status;
1889 gdt->sc_dvr.eu.sync.info = gdt->sc_info;
1890 gdt->sc_dvr.eu.sync.hostdrive = ccb->ccb_h.target_id;
1891 if (gdt->sc_status >= 0x8000)
1892 gdt_store_event(GDT_ES_SYNC, 0, &gdt->sc_dvr);
1894 gdt_store_event(GDT_ES_SYNC, service, &gdt->sc_dvr);
1897 if (gdt->sc_status != GDT_S_RAW_SCSI || gdt->sc_info >= 0x100) {
1898 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
1900 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR|CAM_AUTOSNS_VALID;
1901 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1902 ccb->csio.scsi_status = gdt->sc_info;
1903 bcopy(gccb->gc_scratch, &ccb->csio.sense_data,
1904 ccb->csio.sense_len);
1908 --gdt_stat.io_count_act;
1914 /* Controller event handling functions */
1915 gdt_evt_str *gdt_store_event(u_int16_t source, u_int16_t idx,
1921 GDT_DPRINTF(GDT_D_MISC, ("gdt_store_event(%d, %d)\n", source, idx));
1922 if (source == 0) /* no source -> no event */
1925 if (ebuffer[elastidx].event_source == source &&
1926 ebuffer[elastidx].event_idx == idx &&
1927 ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 &&
1928 !memcmp((char *)&ebuffer[elastidx].event_data.eu,
1929 (char *)&evt->eu, evt->size)) ||
1930 (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 &&
1931 !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
1932 (char *)&evt->event_string)))) {
1933 e = &ebuffer[elastidx];
1935 e->last_stamp = tv.tv_sec;
1938 if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */
1940 if (elastidx == GDT_MAX_EVENTS)
1942 if (elastidx == eoldidx) { /* reached mark ? */
1944 if (eoldidx == GDT_MAX_EVENTS)
1948 e = &ebuffer[elastidx];
1949 e->event_source = source;
1952 e->first_stamp = e->last_stamp = tv.tv_sec;
1954 e->event_data = *evt;
1960 int gdt_read_event(int handle, gdt_evt_str *estr)
1965 GDT_DPRINTF(GDT_D_MISC, ("gdt_read_event(%d)\n", handle));
1971 estr->event_source = 0;
1973 if (eindex >= GDT_MAX_EVENTS) {
1977 e = &ebuffer[eindex];
1978 if (e->event_source != 0) {
1979 if (eindex != elastidx) {
1980 if (++eindex == GDT_MAX_EVENTS)
1985 memcpy(estr, e, sizeof(gdt_evt_str));
1991 void gdt_readapp_event(u_int8_t application, gdt_evt_str *estr)
1997 GDT_DPRINTF(GDT_D_MISC, ("gdt_readapp_event(%d)\n", application));
2001 e = &ebuffer[eindex];
2002 if (e->event_source == 0)
2004 if ((e->application & application) == 0) {
2005 e->application |= application;
2009 if (eindex == elastidx)
2011 if (++eindex == GDT_MAX_EVENTS)
2015 memcpy(estr, e, sizeof(gdt_evt_str));
2017 estr->event_source = 0;
2021 void gdt_clear_events()
2023 GDT_DPRINTF(GDT_D_MISC, ("gdt_clear_events\n"));
2025 eoldidx = elastidx = 0;
2026 ebuffer[0].event_source = 0;