1 /* $FreeBSD: src/sys/dev/iir/iir.c,v 1.2.2.3 2002/05/05 08:18:12 asmodai Exp $ */
2 /* $DragonFly: src/sys/dev/raid/iir/iir.c,v 1.15 2006/12/20 18:14:40 dillon Exp $ */
4 * Copyright (c) 2000-01 Intel Corporation
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@intel.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.
45 #ident "$Id: iir.c 1.2 2001/06/21 20:28:32 achim Exp $"
49 /* #include "opt_iir.h" */
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/types.h>
53 #include <sys/eventhandler.h>
54 #include <sys/malloc.h>
55 #include <sys/kernel.h>
57 #include <sys/thread2.h>
59 #include <machine/clock.h>
60 #include <machine/stdarg.h>
62 #include <bus/cam/cam.h>
63 #include <bus/cam/cam_ccb.h>
64 #include <bus/cam/cam_sim.h>
65 #include <bus/cam/cam_xpt_sim.h>
66 #include <bus/cam/cam_debug.h>
67 #include <bus/cam/scsi/scsi_all.h>
68 #include <bus/cam/scsi/scsi_message.h>
75 struct gdt_softc
*gdt_wait_gdt
;
79 int gdt_debug
= GDT_DEBUG
;
81 #define MAX_SERBUF 160
82 static void ser_init(void);
83 static void ser_puts(char *str
);
84 static void ser_putc(int c
);
85 static char strbuf
[MAX_SERBUF
+1];
87 #define COM_BASE 0x2f8
89 #define COM_BASE 0x3f8
91 static void ser_init()
93 unsigned port
=COM_BASE
;
97 /* 19200 Baud, if 9600: outb(12,port) */
103 static void ser_puts(char *str
)
108 for (ptr
=str
;*ptr
;++ptr
)
109 ser_putc((int)(*ptr
));
112 static void ser_putc(int c
)
114 unsigned port
=COM_BASE
;
116 while ((inb(port
+5) & 0x20)==0);
120 while ((inb(port
+5) & 0x20)==0);
126 ser_printf(const char *fmt
, ...)
131 __va_start(args
,fmt
);
132 i
= kvsprintf(strbuf
,fmt
,args
);
140 /* The linked list of softc structures */
141 struct gdt_softc_list gdt_softcs
= TAILQ_HEAD_INITIALIZER(gdt_softcs
);
142 /* controller cnt. */
145 static gdt_evt_str ebuffer
[GDT_MAX_EVENTS
];
146 static int elastidx
, eoldidx
;
148 gdt_statist_t gdt_stat
;
150 /* Definitions for our use of the SIM private CCB area */
151 #define ccb_sim_ptr spriv_ptr0
152 #define ccb_priority spriv_field1
154 static void iir_action(struct cam_sim
*sim
, union ccb
*ccb
);
155 static void iir_poll(struct cam_sim
*sim
);
156 static void iir_shutdown(void *arg
, int howto
);
157 static void iir_timeout(void *arg
);
158 static void iir_watchdog(void *arg
);
160 static void gdt_eval_mapping(u_int32_t size
, int *cyls
, int *heads
,
162 static int gdt_internal_cmd(struct gdt_softc
*gdt
, struct gdt_ccb
*gccb
,
163 u_int8_t service
, u_int16_t opcode
,
164 u_int32_t arg1
, u_int32_t arg2
, u_int32_t arg3
);
165 static int gdt_wait(struct gdt_softc
*gdt
, struct gdt_ccb
*ccb
,
168 static struct gdt_ccb
*gdt_get_ccb(struct gdt_softc
*gdt
);
169 static u_int32_t
gdt_ccb_vtop(struct gdt_softc
*gdt
,
170 struct gdt_ccb
*gccb
);
172 static int gdt_sync_event(struct gdt_softc
*gdt
, int service
,
173 u_int8_t index
, struct gdt_ccb
*gccb
);
174 static int gdt_async_event(struct gdt_softc
*gdt
, int service
);
175 static struct gdt_ccb
*gdt_raw_cmd(struct gdt_softc
*gdt
, union ccb
*ccb
);
176 static struct gdt_ccb
*gdt_cache_cmd(struct gdt_softc
*gdt
, union ccb
*ccb
);
177 static struct gdt_ccb
*gdt_ioctl_cmd(struct gdt_softc
*gdt
, gdt_ucmd_t
*ucmd
);
178 static void gdt_internal_cache_cmd(struct gdt_softc
*gdt
,union ccb
*ccb
);
180 static void gdtmapmem(void *arg
, bus_dma_segment_t
*dm_segs
,
181 int nseg
, int error
);
182 static void gdtexecuteccb(void *arg
, bus_dma_segment_t
*dm_segs
,
183 int nseg
, int error
);
186 iir_init(struct gdt_softc
*gdt
)
189 int i
, id
, drv_cyls
, drv_hds
, drv_secs
;
190 struct gdt_ccb
*gccb
;
192 GDT_DPRINTF(GDT_D_DEBUG
, ("iir_init()\n"));
194 gdt
->sc_state
= GDT_POLLING
;
196 bzero(&gdt_stat
, sizeof(gdt_statist_t
));
198 SLIST_INIT(&gdt
->sc_free_gccb
);
199 SLIST_INIT(&gdt
->sc_pending_gccb
);
200 TAILQ_INIT(&gdt
->sc_ccb_queue
);
201 TAILQ_INIT(&gdt
->sc_ucmd_queue
);
202 TAILQ_INSERT_TAIL(&gdt_softcs
, gdt
, links
);
204 /* DMA tag for mapping buffers into device visible space. */
205 if (bus_dma_tag_create(gdt
->sc_parent_dmat
, /*alignment*/1, /*boundary*/0,
206 /*lowaddr*/BUS_SPACE_MAXADDR
,
207 /*highaddr*/BUS_SPACE_MAXADDR
,
208 /*filter*/NULL
, /*filterarg*/NULL
,
209 /*maxsize*/MAXBSIZE
, /*nsegments*/GDT_MAXSG
,
210 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
211 /*flags*/BUS_DMA_ALLOCNOW
,
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
, /*alignment*/1, /*boundary*/0,
221 /*lowaddr*/BUS_SPACE_MAXADDR
,
222 /*highaddr*/BUS_SPACE_MAXADDR
,
223 /*filter*/NULL
, /*filterarg*/NULL
,
224 GDT_MAXCMDS
* sizeof(struct gdt_ccb
),
226 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
227 /*flags*/0, &gdt
->sc_gccb_dmat
) != 0) {
228 printf("iir%d: bus_dma_tag_create(...,gdt->sc_gccb_dmat) failed\n",
232 gdt
->sc_init_level
++;
234 /* Allocation for our ccbs */
235 if (bus_dmamem_alloc(gdt
->sc_gccb_dmat
, (void **)&gdt
->sc_gccbs
,
236 BUS_DMA_NOWAIT
, &gdt
->sc_gccb_dmamap
) != 0) {
237 printf("iir%d: bus_dmamem_alloc(...,&gdt->sc_gccbs,...) failed\n",
241 gdt
->sc_init_level
++;
243 /* And permanently map them */
244 bus_dmamap_load(gdt
->sc_gccb_dmat
, gdt
->sc_gccb_dmamap
,
245 gdt
->sc_gccbs
, GDT_MAXCMDS
* sizeof(struct gdt_ccb
),
246 gdtmapmem
, &gdt
->sc_gccb_busbase
, /*flags*/0);
247 gdt
->sc_init_level
++;
249 /* Clear them out. */
250 bzero(gdt
->sc_gccbs
, GDT_MAXCMDS
* sizeof(struct gdt_ccb
));
252 /* Initialize the ccbs */
253 for (i
= GDT_MAXCMDS
-1; i
>= 0; i
--) {
254 gdt
->sc_gccbs
[i
].gc_cmd_index
= i
+ 2;
255 gdt
->sc_gccbs
[i
].gc_flags
= GDT_GCF_UNUSED
;
256 gdt
->sc_gccbs
[i
].gc_map_flag
= FALSE
;
257 if (bus_dmamap_create(gdt
->sc_buffer_dmat
, /*flags*/0,
258 &gdt
->sc_gccbs
[i
].gc_dmamap
) != 0)
260 gdt
->sc_gccbs
[i
].gc_map_flag
= TRUE
;
261 SLIST_INSERT_HEAD(&gdt
->sc_free_gccb
, &gdt
->sc_gccbs
[i
], sle
);
263 gdt
->sc_init_level
++;
265 /* create the control device */
266 gdt
->sc_dev
= gdt_make_dev(gdt
->sc_hanum
);
268 /* allocate ccb for gdt_internal_cmd() */
269 gccb
= gdt_get_ccb(gdt
);
271 printf("iir%d: No free command index found\n",
276 if (!gdt_internal_cmd(gdt
, gccb
, GDT_SCREENSERVICE
, GDT_INIT
,
278 printf("iir%d: Screen service initialization error %d\n",
279 gdt
->sc_hanum
, gdt
->sc_status
);
280 gdt_free_ccb(gdt
, gccb
);
284 if (!gdt_internal_cmd(gdt
, gccb
, GDT_CACHESERVICE
, GDT_INIT
,
285 GDT_LINUX_OS
, 0, 0)) {
286 printf("iir%d: Cache service initialization error %d\n",
287 gdt
->sc_hanum
, gdt
->sc_status
);
288 gdt_free_ccb(gdt
, gccb
);
291 gdt_internal_cmd(gdt
, gccb
, GDT_CACHESERVICE
, GDT_UNFREEZE_IO
,
294 if (!gdt_internal_cmd(gdt
, gccb
, GDT_CACHESERVICE
, GDT_MOUNT
,
296 printf("iir%d: Cache service mount error %d\n",
297 gdt
->sc_hanum
, gdt
->sc_status
);
298 gdt_free_ccb(gdt
, gccb
);
302 if (!gdt_internal_cmd(gdt
, gccb
, GDT_CACHESERVICE
, GDT_INIT
,
303 GDT_LINUX_OS
, 0, 0)) {
304 printf("iir%d: Cache service post-mount initialization error %d\n",
305 gdt
->sc_hanum
, gdt
->sc_status
);
306 gdt_free_ccb(gdt
, gccb
);
309 cdev_cnt
= (u_int16_t
)gdt
->sc_info
;
310 gdt
->sc_fw_vers
= gdt
->sc_service
;
312 /* Detect number of buses */
313 gdt_enc32(gccb
->gc_scratch
+ GDT_IOC_VERSION
, GDT_IOC_NEWEST
);
314 gccb
->gc_scratch
[GDT_IOC_LIST_ENTRIES
] = GDT_MAXBUS
;
315 gccb
->gc_scratch
[GDT_IOC_FIRST_CHAN
] = 0;
316 gccb
->gc_scratch
[GDT_IOC_LAST_CHAN
] = GDT_MAXBUS
- 1;
317 gdt_enc32(gccb
->gc_scratch
+ GDT_IOC_LIST_OFFSET
, GDT_IOC_HDR_SZ
);
318 if (gdt_internal_cmd(gdt
, gccb
, GDT_CACHESERVICE
, GDT_IOCTL
,
319 GDT_IOCHAN_RAW_DESC
, GDT_INVALID_CHANNEL
,
320 GDT_IOC_HDR_SZ
+ GDT_MAXBUS
* GDT_RAWIOC_SZ
)) {
321 gdt
->sc_bus_cnt
= gccb
->gc_scratch
[GDT_IOC_CHAN_COUNT
];
322 for (i
= 0; i
< gdt
->sc_bus_cnt
; i
++) {
323 id
= gccb
->gc_scratch
[GDT_IOC_HDR_SZ
+
324 i
* GDT_RAWIOC_SZ
+ GDT_RAWIOC_PROC_ID
];
325 gdt
->sc_bus_id
[i
] = id
< GDT_MAXID_FC
? id
: 0xff;
328 /* New method failed, use fallback. */
329 for (i
= 0; i
< GDT_MAXBUS
; i
++) {
330 gdt_enc32(gccb
->gc_scratch
+ GDT_GETCH_CHANNEL_NO
, i
);
331 if (!gdt_internal_cmd(gdt
, gccb
, GDT_CACHESERVICE
, GDT_IOCTL
,
332 GDT_SCSI_CHAN_CNT
| GDT_L_CTRL_PATTERN
,
333 GDT_IO_CHANNEL
| GDT_INVALID_CHANNEL
,
336 printf("iir%d: Cannot get channel count, "
337 "error %d\n", gdt
->sc_hanum
, gdt
->sc_status
);
338 gdt_free_ccb(gdt
, gccb
);
344 (gccb
->gc_scratch
[GDT_GETCH_SIOP_ID
] < GDT_MAXID_FC
) ?
345 gccb
->gc_scratch
[GDT_GETCH_SIOP_ID
] : 0xff;
349 /* add one "virtual" channel for the host drives */
350 gdt
->sc_virt_bus
= gdt
->sc_bus_cnt
;
353 if (!gdt_internal_cmd(gdt
, gccb
, GDT_SCSIRAWSERVICE
, GDT_INIT
,
355 printf("iir%d: Raw service initialization error %d\n",
356 gdt
->sc_hanum
, gdt
->sc_status
);
357 gdt_free_ccb(gdt
, gccb
);
361 /* Set/get features raw service (scatter/gather) */
362 gdt
->sc_raw_feat
= 0;
363 if (gdt_internal_cmd(gdt
, gccb
, GDT_SCSIRAWSERVICE
, GDT_SET_FEAT
,
364 GDT_SCATTER_GATHER
, 0, 0)) {
365 if (gdt_internal_cmd(gdt
, gccb
, GDT_SCSIRAWSERVICE
, GDT_GET_FEAT
,
367 gdt
->sc_raw_feat
= gdt
->sc_info
;
368 if (!(gdt
->sc_info
& GDT_SCATTER_GATHER
)) {
369 panic("iir%d: Scatter/Gather Raw Service "
370 "required but not supported!\n", gdt
->sc_hanum
);
371 gdt_free_ccb(gdt
, gccb
);
377 /* Set/get features cache service (scatter/gather) */
378 gdt
->sc_cache_feat
= 0;
379 if (gdt_internal_cmd(gdt
, gccb
, GDT_CACHESERVICE
, GDT_SET_FEAT
,
380 0, GDT_SCATTER_GATHER
, 0)) {
381 if (gdt_internal_cmd(gdt
, gccb
, GDT_CACHESERVICE
, GDT_GET_FEAT
,
383 gdt
->sc_cache_feat
= gdt
->sc_info
;
384 if (!(gdt
->sc_info
& GDT_SCATTER_GATHER
)) {
385 panic("iir%d: Scatter/Gather Cache Service "
386 "required but not supported!\n", gdt
->sc_hanum
);
387 gdt_free_ccb(gdt
, gccb
);
393 /* Scan for cache devices */
394 for (i
= 0; i
< cdev_cnt
&& i
< GDT_MAX_HDRIVES
; i
++) {
395 if (gdt_internal_cmd(gdt
, gccb
, GDT_CACHESERVICE
, GDT_INFO
,
397 gdt
->sc_hdr
[i
].hd_present
= 1;
398 gdt
->sc_hdr
[i
].hd_size
= gdt
->sc_info
;
401 * Evaluate mapping (sectors per head, heads per cyl)
403 gdt
->sc_hdr
[i
].hd_size
&= ~GDT_SECS32
;
404 if (gdt
->sc_info2
== 0)
405 gdt_eval_mapping(gdt
->sc_hdr
[i
].hd_size
,
406 &drv_cyls
, &drv_hds
, &drv_secs
);
408 drv_hds
= gdt
->sc_info2
& 0xff;
409 drv_secs
= (gdt
->sc_info2
>> 8) & 0xff;
410 drv_cyls
= gdt
->sc_hdr
[i
].hd_size
/ drv_hds
/
413 gdt
->sc_hdr
[i
].hd_heads
= drv_hds
;
414 gdt
->sc_hdr
[i
].hd_secs
= drv_secs
;
416 gdt
->sc_hdr
[i
].hd_size
= drv_cyls
* drv_hds
* drv_secs
;
418 if (gdt_internal_cmd(gdt
, gccb
, GDT_CACHESERVICE
,
419 GDT_DEVTYPE
, i
, 0, 0))
420 gdt
->sc_hdr
[i
].hd_devtype
= gdt
->sc_info
;
424 GDT_DPRINTF(GDT_D_INIT
, ("dpmem %x %d-bus %d cache device%s\n",
426 gdt
->sc_bus_cnt
, cdev_cnt
,
427 cdev_cnt
== 1 ? "" : "s"));
428 gdt_free_ccb(gdt
, gccb
);
435 iir_free(struct gdt_softc
*gdt
)
439 GDT_DPRINTF(GDT_D_INIT
, ("iir_free()\n"));
441 switch (gdt
->sc_init_level
) {
443 gdt_destroy_dev(gdt
->sc_dev
);
445 for (i
= GDT_MAXCMDS
-1; i
>= 0; i
--)
446 if (gdt
->sc_gccbs
[i
].gc_map_flag
)
447 bus_dmamap_destroy(gdt
->sc_buffer_dmat
,
448 gdt
->sc_gccbs
[i
].gc_dmamap
);
449 bus_dmamap_unload(gdt
->sc_gccb_dmat
, gdt
->sc_gccb_dmamap
);
451 bus_dmamem_free(gdt
->sc_gccb_dmat
, gdt
->sc_gccbs
, gdt
->sc_gccb_dmamap
);
453 bus_dma_tag_destroy(gdt
->sc_gccb_dmat
);
455 bus_dma_tag_destroy(gdt
->sc_buffer_dmat
);
457 bus_dma_tag_destroy(gdt
->sc_parent_dmat
);
461 TAILQ_REMOVE(&gdt_softcs
, gdt
, links
);
465 iir_attach(struct gdt_softc
*gdt
)
467 struct cam_devq
*devq
;
470 GDT_DPRINTF(GDT_D_INIT
, ("iir_attach()\n"));
472 callout_init(&gdt
->watchdog_timer
);
474 * Create the device queue for our SIM.
476 devq
= cam_simq_alloc(GDT_MAXCMDS
);
480 for (i
= 0; i
< gdt
->sc_bus_cnt
; i
++) {
482 * Construct our SIM entry
484 gdt
->sims
[i
] = cam_sim_alloc(iir_action
, iir_poll
, "iir",
485 gdt
, gdt
->sc_hanum
, /*untagged*/2,
486 /*tagged*/GDT_MAXCMDS
, devq
);
487 if (xpt_bus_register(gdt
->sims
[i
], i
) != CAM_SUCCESS
) {
488 cam_sim_free(gdt
->sims
[i
]);
492 if (xpt_create_path(&gdt
->paths
[i
], /*periph*/NULL
,
493 cam_sim_path(gdt
->sims
[i
]),
495 CAM_LUN_WILDCARD
) != CAM_REQ_CMP
) {
496 xpt_bus_deregister(cam_sim_path(gdt
->sims
[i
]));
497 cam_sim_free(gdt
->sims
[i
]);
501 cam_simq_release(devq
);
503 EVENTHANDLER_REGISTER(shutdown_final
, iir_shutdown
,
504 gdt
, SHUTDOWN_PRI_DEFAULT
);
505 /* iir_watchdog(gdt); */
506 gdt
->sc_state
= GDT_NORMAL
;
510 gdt_eval_mapping(u_int32_t size
, int *cyls
, int *heads
, int *secs
)
512 *cyls
= size
/ GDT_HEADS
/ GDT_SECS
;
513 if (*cyls
< GDT_MAXCYLS
) {
517 /* Too high for 64 * 32 */
518 *cyls
= size
/ GDT_MEDHEADS
/ GDT_MEDSECS
;
519 if (*cyls
< GDT_MAXCYLS
) {
520 *heads
= GDT_MEDHEADS
;
523 /* Too high for 127 * 63 */
524 *cyls
= size
/ GDT_BIGHEADS
/ GDT_BIGSECS
;
525 *heads
= GDT_BIGHEADS
;
532 gdt_wait(struct gdt_softc
*gdt
, struct gdt_ccb
*gccb
,
537 GDT_DPRINTF(GDT_D_INIT
,
538 ("gdt_wait(%p, %p, %d)\n", gdt
, gccb
, timeout
));
540 gdt
->sc_state
|= GDT_POLL_WAIT
;
543 if (gdt
== gdt_wait_gdt
&&
544 gccb
->gc_cmd_index
== gdt_wait_index
) {
550 gdt
->sc_state
&= ~GDT_POLL_WAIT
;
552 while (gdt
->sc_test_busy(gdt
))
553 DELAY(1); /* XXX correct? */
559 gdt_internal_cmd(struct gdt_softc
*gdt
, struct gdt_ccb
*gccb
,
560 u_int8_t service
, u_int16_t opcode
,
561 u_int32_t arg1
, u_int32_t arg2
, u_int32_t arg3
)
565 GDT_DPRINTF(GDT_D_CMD
, ("gdt_internal_cmd(%p, %d, %d, %d, %d, %d)\n",
566 gdt
, service
, opcode
, arg1
, arg2
, arg3
));
568 bzero(gdt
->sc_cmd
, GDT_CMD_SZ
);
570 for (retries
= GDT_RETRIES
; ; ) {
571 gccb
->gc_service
= service
;
572 gccb
->gc_flags
= GDT_GCF_INTERNAL
;
574 gdt
->sc_set_sema0(gdt
);
575 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_COMMANDINDEX
,
577 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_OPCODE
, opcode
);
580 case GDT_CACHESERVICE
:
581 if (opcode
== GDT_IOCTL
) {
582 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+
583 GDT_IOCTL_SUBFUNC
, arg1
);
584 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+
585 GDT_IOCTL_CHANNEL
, arg2
);
586 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_UNION
+
587 GDT_IOCTL_PARAM_SIZE
, (u_int16_t
)arg3
);
588 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_IOCTL_P_PARAM
,
589 gdt_ccb_vtop(gdt
, gccb
) +
590 offsetof(struct gdt_ccb
, gc_scratch
[0]));
592 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_UNION
+
593 GDT_CACHE_DEVICENO
, (u_int16_t
)arg1
);
594 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+
595 GDT_CACHE_BLOCKNO
, arg2
);
599 case GDT_SCSIRAWSERVICE
:
600 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+
601 GDT_RAW_DIRECTION
, arg1
);
602 gdt
->sc_cmd
[GDT_CMD_UNION
+ GDT_RAW_BUS
] =
604 gdt
->sc_cmd
[GDT_CMD_UNION
+ GDT_RAW_TARGET
] =
606 gdt
->sc_cmd
[GDT_CMD_UNION
+ GDT_RAW_LUN
] =
607 (u_int8_t
)(arg3
>> 8);
610 gdt
->sc_cmd_len
= GDT_CMD_SZ
;
613 gdt
->sc_copy_cmd(gdt
, gccb
);
614 gdt
->sc_release_event(gdt
);
616 if (!gdt_wait(gdt
, gccb
, GDT_POLL_TIMEOUT
))
618 if (gdt
->sc_status
!= GDT_S_BSY
|| --retries
== 0)
622 return (gdt
->sc_status
== GDT_S_OK
);
625 static struct gdt_ccb
*
626 gdt_get_ccb(struct gdt_softc
*gdt
)
628 struct gdt_ccb
*gccb
;
630 GDT_DPRINTF(GDT_D_QUEUE
, ("gdt_get_ccb(%p)\n", gdt
));
633 gccb
= SLIST_FIRST(&gdt
->sc_free_gccb
);
635 SLIST_REMOVE_HEAD(&gdt
->sc_free_gccb
, sle
);
636 SLIST_INSERT_HEAD(&gdt
->sc_pending_gccb
, gccb
, sle
);
637 ++gdt_stat
.cmd_index_act
;
638 if (gdt_stat
.cmd_index_act
> gdt_stat
.cmd_index_max
)
639 gdt_stat
.cmd_index_max
= gdt_stat
.cmd_index_act
;
646 gdt_free_ccb(struct gdt_softc
*gdt
, struct gdt_ccb
*gccb
)
648 GDT_DPRINTF(GDT_D_QUEUE
, ("gdt_free_ccb(%p, %p)\n", gdt
, gccb
));
651 gccb
->gc_flags
= GDT_GCF_UNUSED
;
652 SLIST_REMOVE(&gdt
->sc_pending_gccb
, gccb
, gdt_ccb
, sle
);
653 SLIST_INSERT_HEAD(&gdt
->sc_free_gccb
, gccb
, sle
);
654 --gdt_stat
.cmd_index_act
;
656 if (gdt
->sc_state
& GDT_SHUTDOWN
)
661 gdt_ccb_vtop(struct gdt_softc
*gdt
, struct gdt_ccb
*gccb
)
663 return (gdt
->sc_gccb_busbase
664 + (u_int32_t
)((caddr_t
)gccb
- (caddr_t
)gdt
->sc_gccbs
));
668 gdt_next(struct gdt_softc
*gdt
)
673 int bus
, target
, lun
;
676 struct ccb_scsiio
*csio
;
677 struct ccb_hdr
*ccbh
;
678 struct gdt_ccb
*gccb
= NULL
;
681 GDT_DPRINTF(GDT_D_QUEUE
, ("gdt_next(%p)\n", gdt
));
684 if (gdt
->sc_test_busy(gdt
)) {
685 if (!(gdt
->sc_state
& GDT_POLLING
)) {
689 while (gdt
->sc_test_busy(gdt
))
693 gdt
->sc_cmd_cnt
= gdt
->sc_cmd_off
= 0;
696 /* I/Os in queue? controller ready? */
697 if (!TAILQ_FIRST(&gdt
->sc_ucmd_queue
) &&
698 !TAILQ_FIRST(&gdt
->sc_ccb_queue
))
701 /* 1.: I/Os without ccb (IOCTLs) */
702 ucmd
= TAILQ_FIRST(&gdt
->sc_ucmd_queue
);
704 TAILQ_REMOVE(&gdt
->sc_ucmd_queue
, ucmd
, links
);
705 if ((gccb
= gdt_ioctl_cmd(gdt
, ucmd
)) == NULL
) {
706 TAILQ_INSERT_HEAD(&gdt
->sc_ucmd_queue
, ucmd
, links
);
710 /* wenn mehrere Kdos. zulassen: if (!gdt_polling) continue; */
713 /* 2.: I/Os with ccb */
714 ccb
= (union ccb
*)TAILQ_FIRST(&gdt
->sc_ccb_queue
);
715 /* ist dann immer != NULL, da oben getestet */
716 sim
= (struct cam_sim
*)ccb
->ccb_h
.ccb_sim_ptr
;
717 bus
= cam_sim_bus(sim
);
718 target
= ccb
->ccb_h
.target_id
;
719 lun
= ccb
->ccb_h
.target_lun
;
721 TAILQ_REMOVE(&gdt
->sc_ccb_queue
, &ccb
->ccb_h
, sim_links
.tqe
);
722 --gdt_stat
.req_queue_act
;
723 /* ccb->ccb_h.func_code is XPT_SCSI_IO */
724 GDT_DPRINTF(GDT_D_QUEUE
, ("XPT_SCSI_IO flags 0x%x)\n",
728 cmd
= csio
->cdb_io
.cdb_bytes
[0];
729 /* Max CDB length is 12 bytes */
730 if (csio
->cdb_len
> 12) {
731 ccbh
->status
= CAM_REQ_INVALID
;
732 --gdt_stat
.io_count_act
;
734 } else if (bus
!= gdt
->sc_virt_bus
) {
735 /* raw service command */
736 if ((gccb
= gdt_raw_cmd(gdt
, ccb
)) == NULL
) {
737 TAILQ_INSERT_HEAD(&gdt
->sc_ccb_queue
, &ccb
->ccb_h
,
739 ++gdt_stat
.req_queue_act
;
740 if (gdt_stat
.req_queue_act
> gdt_stat
.req_queue_max
)
741 gdt_stat
.req_queue_max
= gdt_stat
.req_queue_act
;
744 } else if (target
>= GDT_MAX_HDRIVES
||
745 !gdt
->sc_hdr
[target
].hd_present
|| lun
!= 0) {
746 ccbh
->status
= CAM_SEL_TIMEOUT
;
747 --gdt_stat
.io_count_act
;
750 /* cache service command */
751 if (cmd
== READ_6
|| cmd
== WRITE_6
||
752 cmd
== READ_10
|| cmd
== WRITE_10
) {
753 if ((gccb
= gdt_cache_cmd(gdt
, ccb
)) == NULL
) {
754 TAILQ_INSERT_HEAD(&gdt
->sc_ccb_queue
, &ccb
->ccb_h
,
756 ++gdt_stat
.req_queue_act
;
757 if (gdt_stat
.req_queue_act
> gdt_stat
.req_queue_max
)
758 gdt_stat
.req_queue_max
= gdt_stat
.req_queue_act
;
763 gdt_internal_cache_cmd(gdt
, ccb
);
767 if ((gdt
->sc_state
& GDT_POLLING
) || !next_cmd
)
770 if (gdt
->sc_cmd_cnt
> 0)
771 gdt
->sc_release_event(gdt
);
775 if ((gdt
->sc_state
& GDT_POLLING
) && gdt
->sc_cmd_cnt
> 0) {
776 gdt_wait(gdt
, gccb
, GDT_POLL_TIMEOUT
);
780 static struct gdt_ccb
*
781 gdt_raw_cmd(struct gdt_softc
*gdt
, union ccb
*ccb
)
783 struct gdt_ccb
*gccb
;
786 GDT_DPRINTF(GDT_D_CMD
, ("gdt_raw_cmd(%p, %p)\n", gdt
, ccb
));
788 if (roundup(GDT_CMD_UNION
+ GDT_RAW_SZ
, sizeof(u_int32_t
)) +
789 gdt
->sc_cmd_off
+ GDT_DPMEM_COMMAND_OFFSET
>
790 gdt
->sc_ic_all_size
) {
791 GDT_DPRINTF(GDT_D_INVALID
, ("iir%d: gdt_raw_cmd(): DPMEM overflow\n",
796 bzero(gdt
->sc_cmd
, GDT_CMD_SZ
);
798 gccb
= gdt_get_ccb(gdt
);
800 GDT_DPRINTF(GDT_D_INVALID
, ("iir%d: No free command index found\n",
804 sim
= (struct cam_sim
*)ccb
->ccb_h
.ccb_sim_ptr
;
806 gccb
->gc_service
= GDT_SCSIRAWSERVICE
;
807 gccb
->gc_flags
= GDT_GCF_SCSI
;
809 if (gdt
->sc_cmd_cnt
== 0)
810 gdt
->sc_set_sema0(gdt
);
812 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_COMMANDINDEX
,
814 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_OPCODE
, GDT_WRITE
);
816 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_DIRECTION
,
817 (ccb
->ccb_h
.flags
& CAM_DIR_MASK
) == CAM_DIR_IN
?
818 GDT_DATA_IN
: GDT_DATA_OUT
);
819 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SDLEN
,
820 ccb
->csio
.dxfer_len
);
821 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_CLEN
,
823 bcopy(ccb
->csio
.cdb_io
.cdb_bytes
, gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_CMD
,
825 gdt
->sc_cmd
[GDT_CMD_UNION
+ GDT_RAW_TARGET
] =
826 ccb
->ccb_h
.target_id
;
827 gdt
->sc_cmd
[GDT_CMD_UNION
+ GDT_RAW_LUN
] =
828 ccb
->ccb_h
.target_lun
;
829 gdt
->sc_cmd
[GDT_CMD_UNION
+ GDT_RAW_BUS
] =
831 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SENSE_LEN
,
832 sizeof(struct scsi_sense_data
));
833 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SENSE_DATA
,
834 gdt_ccb_vtop(gdt
, gccb
) +
835 offsetof(struct gdt_ccb
, gc_scratch
[0]));
838 * If we have any data to send with this command,
839 * map it into bus space.
841 /* Only use S/G if there is a transfer */
842 if ((ccb
->ccb_h
.flags
& CAM_DIR_MASK
) != CAM_DIR_NONE
) {
843 if ((ccb
->ccb_h
.flags
& CAM_SCATTER_VALID
) == 0) {
844 if ((ccb
->ccb_h
.flags
& CAM_DATA_PHYS
) == 0) {
847 /* vorher unlock von splcam() ??? */
850 bus_dmamap_load(gdt
->sc_buffer_dmat
,
856 if (error
== EINPROGRESS
) {
857 xpt_freeze_simq(sim
, 1);
858 gccb
->gc_state
|= CAM_RELEASE_SIMQ
;
862 struct bus_dma_segment seg
;
864 /* Pointer to physical buffer */
866 (bus_addr_t
)ccb
->csio
.data_ptr
;
867 seg
.ds_len
= ccb
->csio
.dxfer_len
;
868 gdtexecuteccb(gccb
, &seg
, 1, 0);
871 struct bus_dma_segment
*segs
;
873 if ((ccb
->ccb_h
.flags
& CAM_DATA_PHYS
) != 0)
874 panic("iir%d: iir_action - Physical "
875 "segment pointers unsupported", gdt
->sc_hanum
);
877 if ((ccb
->ccb_h
.flags
& CAM_SG_LIST_PHYS
)==0)
878 panic("iir%d: iir_action - Virtual "
879 "segment addresses unsupported", gdt
->sc_hanum
);
881 /* Just use the segments provided */
882 segs
= (struct bus_dma_segment
*)ccb
->csio
.data_ptr
;
883 gdtexecuteccb(gccb
, segs
, ccb
->csio
.sglist_cnt
, 0);
886 gdtexecuteccb(gccb
, NULL
, 0, 0);
893 static struct gdt_ccb
*
894 gdt_cache_cmd(struct gdt_softc
*gdt
, union ccb
*ccb
)
896 struct gdt_ccb
*gccb
;
900 u_int32_t blockno
, blockcnt
;
902 GDT_DPRINTF(GDT_D_CMD
, ("gdt_cache_cmd(%p, %p)\n", gdt
, ccb
));
904 if (roundup(GDT_CMD_UNION
+ GDT_CACHE_SZ
, sizeof(u_int32_t
)) +
905 gdt
->sc_cmd_off
+ GDT_DPMEM_COMMAND_OFFSET
>
906 gdt
->sc_ic_all_size
) {
907 GDT_DPRINTF(GDT_D_INVALID
, ("iir%d: gdt_cache_cmd(): DPMEM overflow\n",
912 bzero(gdt
->sc_cmd
, GDT_CMD_SZ
);
914 gccb
= gdt_get_ccb(gdt
);
916 GDT_DPRINTF(GDT_D_DEBUG
, ("iir%d: No free command index found\n",
920 sim
= (struct cam_sim
*)ccb
->ccb_h
.ccb_sim_ptr
;
922 gccb
->gc_service
= GDT_CACHESERVICE
;
923 gccb
->gc_flags
= GDT_GCF_SCSI
;
925 if (gdt
->sc_cmd_cnt
== 0)
926 gdt
->sc_set_sema0(gdt
);
928 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_COMMANDINDEX
,
930 cmdp
= ccb
->csio
.cdb_io
.cdb_bytes
;
931 opcode
= (*cmdp
== WRITE_6
|| *cmdp
== WRITE_10
) ? GDT_WRITE
: GDT_READ
;
932 if ((gdt
->sc_state
& GDT_SHUTDOWN
) && opcode
== GDT_WRITE
)
933 opcode
= GDT_WRITE_THR
;
934 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_OPCODE
, opcode
);
936 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_DEVICENO
,
937 ccb
->ccb_h
.target_id
);
938 if (ccb
->csio
.cdb_len
== 6) {
939 struct scsi_rw_6
*rw
= (struct scsi_rw_6
*)cmdp
;
940 blockno
= scsi_3btoul(rw
->addr
) & ((SRW_TOPADDR
<<16) | 0xffff);
941 blockcnt
= rw
->length
? rw
->length
: 0x100;
943 struct scsi_rw_10
*rw
= (struct scsi_rw_10
*)cmdp
;
944 blockno
= scsi_4btoul(rw
->addr
);
945 blockcnt
= scsi_2btoul(rw
->length
);
947 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_BLOCKNO
,
949 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_BLOCKCNT
,
953 * If we have any data to send with this command,
954 * map it into bus space.
956 /* Only use S/G if there is a transfer */
957 if ((ccb
->ccb_h
.flags
& CAM_SCATTER_VALID
) == 0) {
958 if ((ccb
->ccb_h
.flags
& CAM_DATA_PHYS
) == 0) {
961 /* vorher unlock von splcam() ??? */
964 bus_dmamap_load(gdt
->sc_buffer_dmat
,
970 if (error
== EINPROGRESS
) {
971 xpt_freeze_simq(sim
, 1);
972 gccb
->gc_state
|= CAM_RELEASE_SIMQ
;
976 struct bus_dma_segment seg
;
978 /* Pointer to physical buffer */
980 (bus_addr_t
)ccb
->csio
.data_ptr
;
981 seg
.ds_len
= ccb
->csio
.dxfer_len
;
982 gdtexecuteccb(gccb
, &seg
, 1, 0);
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
)
1007 struct gdt_ccb
*gccb
;
1010 GDT_DPRINTF(GDT_D_DEBUG
, ("gdt_ioctl_cmd(%p, %p)\n", gdt
, ucmd
));
1012 bzero(gdt
->sc_cmd
, GDT_CMD_SZ
);
1014 gccb
= gdt_get_ccb(gdt
);
1016 GDT_DPRINTF(GDT_D_DEBUG
, ("iir%d: No free command index found\n",
1020 gccb
->gc_ucmd
= ucmd
;
1021 gccb
->gc_service
= ucmd
->service
;
1022 gccb
->gc_flags
= GDT_GCF_IOCTL
;
1024 /* check DPMEM space, copy data buffer from user space */
1025 if (ucmd
->service
== GDT_CACHESERVICE
) {
1026 if (ucmd
->OpCode
== GDT_IOCTL
) {
1027 gdt
->sc_cmd_len
= roundup(GDT_CMD_UNION
+ GDT_IOCTL_SZ
,
1029 cnt
= ucmd
->u
.ioctl
.param_size
;
1030 if (cnt
> GDT_SCRATCH_SZ
) {
1031 printf("iir%d: Scratch buffer too small (%d/%d)\n",
1032 gdt
->sc_hanum
, GDT_SCRATCH_SZ
, cnt
);
1033 gdt_free_ccb(gdt
, gccb
);
1037 gdt
->sc_cmd_len
= roundup(GDT_CMD_UNION
+ GDT_CACHE_SG_LST
+
1038 GDT_SG_SZ
, sizeof(u_int32_t
));
1039 cnt
= ucmd
->u
.cache
.BlockCnt
* GDT_SECTOR_SIZE
;
1040 if (cnt
> GDT_SCRATCH_SZ
) {
1041 printf("iir%d: Scratch buffer too small (%d/%d)\n",
1042 gdt
->sc_hanum
, GDT_SCRATCH_SZ
, cnt
);
1043 gdt_free_ccb(gdt
, gccb
);
1048 gdt
->sc_cmd_len
= roundup(GDT_CMD_UNION
+ GDT_RAW_SG_LST
+
1049 GDT_SG_SZ
, sizeof(u_int32_t
));
1050 cnt
= ucmd
->u
.raw
.sdlen
;
1051 if (cnt
+ ucmd
->u
.raw
.sense_len
> GDT_SCRATCH_SZ
) {
1052 printf("iir%d: Scratch buffer too small (%d/%d)\n",
1053 gdt
->sc_hanum
, GDT_SCRATCH_SZ
, cnt
+ ucmd
->u
.raw
.sense_len
);
1054 gdt_free_ccb(gdt
, gccb
);
1059 bcopy(ucmd
->data
, gccb
->gc_scratch
, cnt
);
1061 if (gdt
->sc_cmd_off
+ gdt
->sc_cmd_len
+ GDT_DPMEM_COMMAND_OFFSET
>
1062 gdt
->sc_ic_all_size
) {
1063 GDT_DPRINTF(GDT_D_INVALID
, ("iir%d: gdt_ioctl_cmd(): DPMEM overflow\n",
1065 gdt_free_ccb(gdt
, gccb
);
1069 if (gdt
->sc_cmd_cnt
== 0)
1070 gdt
->sc_set_sema0(gdt
);
1073 /* fill cmd structure */
1074 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_COMMANDINDEX
,
1075 gccb
->gc_cmd_index
);
1076 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_OPCODE
,
1079 if (ucmd
->service
== GDT_CACHESERVICE
) {
1080 if (ucmd
->OpCode
== GDT_IOCTL
) {
1082 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_IOCTL_PARAM_SIZE
,
1083 ucmd
->u
.ioctl
.param_size
);
1084 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_IOCTL_SUBFUNC
,
1085 ucmd
->u
.ioctl
.subfunc
);
1086 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_IOCTL_CHANNEL
,
1087 ucmd
->u
.ioctl
.channel
);
1088 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_IOCTL_P_PARAM
,
1089 gdt_ccb_vtop(gdt
, gccb
) +
1090 offsetof(struct gdt_ccb
, gc_scratch
[0]));
1092 /* cache service command */
1093 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_DEVICENO
,
1094 ucmd
->u
.cache
.DeviceNo
);
1095 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_BLOCKNO
,
1096 ucmd
->u
.cache
.BlockNo
);
1097 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_BLOCKCNT
,
1098 ucmd
->u
.cache
.BlockCnt
);
1099 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_DESTADDR
,
1101 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_SG_CANZ
,
1103 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_SG_LST
+
1104 GDT_SG_PTR
, gdt_ccb_vtop(gdt
, gccb
) +
1105 offsetof(struct gdt_ccb
, gc_scratch
[0]));
1106 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_SG_LST
+
1107 GDT_SG_LEN
, ucmd
->u
.cache
.BlockCnt
* GDT_SECTOR_SIZE
);
1110 /* raw service command */
1111 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_DIRECTION
,
1112 ucmd
->u
.raw
.direction
);
1113 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SDATA
,
1115 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SDLEN
,
1117 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_CLEN
,
1119 bcopy(ucmd
->u
.raw
.cmd
, gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_CMD
,
1121 gdt
->sc_cmd
[GDT_CMD_UNION
+ GDT_RAW_TARGET
] =
1123 gdt
->sc_cmd
[GDT_CMD_UNION
+ GDT_RAW_LUN
] =
1125 gdt
->sc_cmd
[GDT_CMD_UNION
+ GDT_RAW_BUS
] =
1127 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SENSE_LEN
,
1128 ucmd
->u
.raw
.sense_len
);
1129 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SENSE_DATA
,
1130 gdt_ccb_vtop(gdt
, gccb
) +
1131 offsetof(struct gdt_ccb
, gc_scratch
[ucmd
->u
.raw
.sdlen
]));
1132 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SG_RANZ
,
1134 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SG_LST
+
1135 GDT_SG_PTR
, gdt_ccb_vtop(gdt
, gccb
) +
1136 offsetof(struct gdt_ccb
, gc_scratch
[0]));
1137 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SG_LST
+
1138 GDT_SG_LEN
, ucmd
->u
.raw
.sdlen
);
1142 gdt_stat
.sg_count_act
= 1;
1143 gdt
->sc_copy_cmd(gdt
, gccb
);
1148 gdt_internal_cache_cmd(struct gdt_softc
*gdt
,union ccb
*ccb
)
1152 t
= ccb
->ccb_h
.target_id
;
1153 GDT_DPRINTF(GDT_D_CMD
, ("gdt_internal_cache_cmd(%p, %p, 0x%x, %d)\n",
1154 gdt
, ccb
, ccb
->csio
.cdb_io
.cdb_bytes
[0], t
));
1156 switch (ccb
->csio
.cdb_io
.cdb_bytes
[0]) {
1157 case TEST_UNIT_READY
:
1161 GDT_DPRINTF(GDT_D_MISC
, ("REQUEST_SENSE\n"));
1165 struct scsi_inquiry_data
*inq
;
1167 inq
= (struct scsi_inquiry_data
*)ccb
->csio
.data_ptr
;
1168 bzero(inq
, sizeof(struct scsi_inquiry_data
));
1169 inq
->device
= (gdt
->sc_hdr
[t
].hd_devtype
& 4) ?
1171 inq
->dev_qual2
= (gdt
->sc_hdr
[t
].hd_devtype
& 1) ? 0x80 : 0;
1172 inq
->version
= SCSI_REV_2
;
1173 inq
->response_format
= 2;
1174 inq
->additional_length
= 32;
1175 inq
->flags
= SID_CmdQue
| SID_Sync
;
1176 strcpy(inq
->vendor
, "IIR ");
1177 ksprintf(inq
->product
, "Host Drive #%02d", t
);
1178 strcpy(inq
->revision
, " ");
1184 struct scsi_mode_hdr_6 hd
;
1185 struct scsi_mode_block_descr bd
;
1186 struct scsi_control_page cp
;
1190 mpd
= (struct mpd_data
*)ccb
->csio
.data_ptr
;
1191 bzero(mpd
, sizeof(struct mpd_data
));
1192 mpd
->hd
.datalen
= sizeof(struct scsi_mode_hdr_6
) +
1193 sizeof(struct scsi_mode_block_descr
);
1194 mpd
->hd
.dev_specific
= (gdt
->sc_hdr
[t
].hd_devtype
& 2) ? 0x80 : 0;
1195 mpd
->hd
.block_descr_len
= sizeof(struct scsi_mode_block_descr
);
1196 mpd
->bd
.block_len
[0] = (GDT_SECTOR_SIZE
& 0x00ff0000) >> 16;
1197 mpd
->bd
.block_len
[1] = (GDT_SECTOR_SIZE
& 0x0000ff00) >> 8;
1198 mpd
->bd
.block_len
[2] = (GDT_SECTOR_SIZE
& 0x000000ff);
1199 page
=((struct scsi_mode_sense_6
*)ccb
->csio
.cdb_io
.cdb_bytes
)->page
;
1202 GDT_DPRINTF(GDT_D_MISC
, ("MODE_SENSE_6: page 0x%x\n", page
));
1209 struct scsi_read_capacity_data
*rcd
;
1211 rcd
= (struct scsi_read_capacity_data
*)ccb
->csio
.data_ptr
;
1212 bzero(rcd
, sizeof(struct scsi_read_capacity_data
));
1213 scsi_ulto4b(gdt
->sc_hdr
[t
].hd_size
- 1, rcd
->addr
);
1214 scsi_ulto4b(GDT_SECTOR_SIZE
, rcd
->length
);
1218 GDT_DPRINTF(GDT_D_MISC
, ("gdt_internal_cache_cmd(%d) unknown\n",
1219 ccb
->csio
.cdb_io
.cdb_bytes
[0]));
1222 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
1223 --gdt_stat
.io_count_act
;
1228 gdtmapmem(void *arg
, bus_dma_segment_t
*dm_segs
, int nseg
, int error
)
1230 bus_addr_t
*busaddrp
;
1232 busaddrp
= (bus_addr_t
*)arg
;
1233 *busaddrp
= dm_segs
->ds_addr
;
1237 gdtexecuteccb(void *arg
, bus_dma_segment_t
*dm_segs
, int nseg
, int error
)
1239 struct gdt_ccb
*gccb
;
1241 struct gdt_softc
*gdt
;
1246 gccb
= (struct gdt_ccb
*)arg
;
1248 gdt
= cam_sim_softc((struct cam_sim
*)ccb
->ccb_h
.ccb_sim_ptr
);
1250 GDT_DPRINTF(GDT_D_CMD
, ("gdtexecuteccb(%p, %p, %p, %d, %d)\n",
1251 gdt
, gccb
, dm_segs
, nseg
, error
));
1252 gdt_stat
.sg_count_act
= nseg
;
1253 if (nseg
> gdt_stat
.sg_count_max
)
1254 gdt_stat
.sg_count_max
= nseg
;
1256 /* Copy the segments into our SG list */
1257 if (gccb
->gc_service
== GDT_CACHESERVICE
) {
1258 for (i
= 0; i
< nseg
; ++i
) {
1259 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_SG_LST
+
1260 i
* GDT_SG_SZ
+ GDT_SG_PTR
, dm_segs
->ds_addr
);
1261 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_SG_LST
+
1262 i
* GDT_SG_SZ
+ GDT_SG_LEN
, dm_segs
->ds_len
);
1265 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_SG_CANZ
,
1267 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_CACHE_DESTADDR
,
1270 gdt
->sc_cmd_len
= roundup(GDT_CMD_UNION
+ GDT_CACHE_SG_LST
+
1271 nseg
* GDT_SG_SZ
, sizeof(u_int32_t
));
1273 for (i
= 0; i
< nseg
; ++i
) {
1274 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SG_LST
+
1275 i
* GDT_SG_SZ
+ GDT_SG_PTR
, dm_segs
->ds_addr
);
1276 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SG_LST
+
1277 i
* GDT_SG_SZ
+ GDT_SG_LEN
, dm_segs
->ds_len
);
1280 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SG_RANZ
,
1282 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_RAW_SDATA
,
1285 gdt
->sc_cmd_len
= roundup(GDT_CMD_UNION
+ GDT_RAW_SG_LST
+
1286 nseg
* GDT_SG_SZ
, sizeof(u_int32_t
));
1290 bus_dmasync_op_t op
;
1292 if ((ccb
->ccb_h
.flags
& CAM_DIR_MASK
) == CAM_DIR_IN
)
1293 op
= BUS_DMASYNC_PREREAD
;
1295 op
= BUS_DMASYNC_PREWRITE
;
1296 bus_dmamap_sync(gdt
->sc_buffer_dmat
, gccb
->gc_dmamap
, op
);
1299 /* We must NOT abort the command here if CAM_REQ_INPROG is not set,
1300 * because command semaphore is already set!
1303 ccb
->ccb_h
.status
|= CAM_SIM_QUEUED
;
1304 /* timeout handling */
1305 callout_reset(&ccb
->ccb_h
.timeout_ch
, (ccb
->ccb_h
.timeout
* hz
) / 1000,
1308 gdt
->sc_copy_cmd(gdt
, gccb
);
1314 iir_action( struct cam_sim
*sim
, union ccb
*ccb
)
1316 struct gdt_softc
*gdt
;
1317 int bus
, target
, lun
;
1319 gdt
= (struct gdt_softc
*)cam_sim_softc( sim
);
1320 ccb
->ccb_h
.ccb_sim_ptr
= sim
;
1321 bus
= cam_sim_bus(sim
);
1322 target
= ccb
->ccb_h
.target_id
;
1323 lun
= ccb
->ccb_h
.target_lun
;
1324 GDT_DPRINTF(GDT_D_CMD
,
1325 ("iir_action(%p) func 0x%x cmd 0x%x bus %d target %d lun %d\n",
1326 gdt
, ccb
->ccb_h
.func_code
, ccb
->csio
.cdb_io
.cdb_bytes
[0],
1328 ++gdt_stat
.io_count_act
;
1329 if (gdt_stat
.io_count_act
> gdt_stat
.io_count_max
)
1330 gdt_stat
.io_count_max
= gdt_stat
.io_count_act
;
1332 switch (ccb
->ccb_h
.func_code
) {
1335 TAILQ_INSERT_TAIL(&gdt
->sc_ccb_queue
, &ccb
->ccb_h
, sim_links
.tqe
);
1336 ++gdt_stat
.req_queue_act
;
1337 if (gdt_stat
.req_queue_act
> gdt_stat
.req_queue_max
)
1338 gdt_stat
.req_queue_max
= gdt_stat
.req_queue_act
;
1342 case XPT_RESET_DEV
: /* Bus Device Reset the specified SCSI device */
1343 case XPT_ABORT
: /* Abort the specified CCB */
1345 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
1346 --gdt_stat
.io_count_act
;
1349 case XPT_SET_TRAN_SETTINGS
:
1350 ccb
->ccb_h
.status
= CAM_FUNC_NOTAVAIL
;
1351 --gdt_stat
.io_count_act
;
1354 case XPT_GET_TRAN_SETTINGS
:
1355 /* Get default/user set transfer settings for the target */
1357 struct ccb_trans_settings
*cts
;
1361 target_mask
= 0x01 << target
;
1362 if ((cts
->flags
& CCB_TRANS_USER_SETTINGS
) != 0) {
1363 cts
->flags
= CCB_TRANS_DISC_ENB
|CCB_TRANS_TAG_ENB
;
1364 cts
->bus_width
= MSG_EXT_WDTR_BUS_16_BIT
;
1365 cts
->sync_period
= 25; /* 10MHz */
1366 if (cts
->sync_period
!= 0)
1367 cts
->sync_offset
= 15;
1369 cts
->valid
= CCB_TRANS_SYNC_RATE_VALID
1370 | CCB_TRANS_SYNC_OFFSET_VALID
1371 | CCB_TRANS_BUS_WIDTH_VALID
1372 | CCB_TRANS_DISC_VALID
1373 | CCB_TRANS_TQ_VALID
;
1374 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
1376 ccb
->ccb_h
.status
= CAM_FUNC_NOTAVAIL
;
1378 --gdt_stat
.io_count_act
;
1382 case XPT_CALC_GEOMETRY
:
1384 struct ccb_calc_geometry
*ccg
;
1385 u_int32_t secs_per_cylinder
;
1388 ccg
->heads
= gdt
->sc_hdr
[target
].hd_heads
;
1389 ccg
->secs_per_track
= gdt
->sc_hdr
[target
].hd_secs
;
1390 secs_per_cylinder
= ccg
->heads
* ccg
->secs_per_track
;
1391 ccg
->cylinders
= ccg
->volume_size
/ secs_per_cylinder
;
1392 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
1393 --gdt_stat
.io_count_act
;
1397 case XPT_RESET_BUS
: /* Reset the specified SCSI bus */
1400 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
1401 --gdt_stat
.io_count_act
;
1405 case XPT_TERM_IO
: /* Terminate the I/O process */
1407 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
1408 --gdt_stat
.io_count_act
;
1411 case XPT_PATH_INQ
: /* Path routing inquiry */
1413 struct ccb_pathinq
*cpi
= &ccb
->cpi
;
1415 cpi
->version_num
= 1;
1416 cpi
->hba_inquiry
= PI_SDTR_ABLE
|PI_TAG_ABLE
;
1417 cpi
->hba_inquiry
|= PI_WIDE_16
;
1418 cpi
->target_sprt
= 1;
1420 cpi
->hba_eng_cnt
= 0;
1421 if (bus
== gdt
->sc_virt_bus
)
1422 cpi
->max_target
= GDT_MAX_HDRIVES
- 1;
1423 else if (gdt
->sc_class
& GDT_FC
)
1424 cpi
->max_target
= GDT_MAXID_FC
- 1;
1426 cpi
->max_target
= GDT_MAXID
- 1;
1428 cpi
->unit_number
= cam_sim_unit(sim
);
1431 (bus
== gdt
->sc_virt_bus
? 127 : gdt
->sc_bus_id
[bus
]);
1432 cpi
->base_transfer_speed
= 3300;
1433 strncpy(cpi
->sim_vid
, "FreeBSD", SIM_IDLEN
);
1434 strncpy(cpi
->hba_vid
, "Intel Corp.", HBA_IDLEN
);
1435 strncpy(cpi
->dev_name
, cam_sim_name(sim
), DEV_IDLEN
);
1436 cpi
->ccb_h
.status
= CAM_REQ_CMP
;
1437 --gdt_stat
.io_count_act
;
1442 GDT_DPRINTF(GDT_D_INVALID
, ("gdt_next(%p) cmd 0x%x invalid\n",
1443 gdt
, ccb
->ccb_h
.func_code
));
1444 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
1445 --gdt_stat
.io_count_act
;
1452 iir_poll( struct cam_sim
*sim
)
1454 struct gdt_softc
*gdt
;
1456 gdt
= (struct gdt_softc
*)cam_sim_softc( sim
);
1457 GDT_DPRINTF(GDT_D_CMD
, ("iir_poll sim %p gdt %p\n", sim
, gdt
));
1462 iir_timeout(void *arg
)
1464 GDT_DPRINTF(GDT_D_TIMEOUT
, ("iir_timeout(%p)\n", arg
));
1468 iir_watchdog(void *arg
)
1470 struct gdt_softc
*gdt
;
1472 gdt
= (struct gdt_softc
*)arg
;
1473 GDT_DPRINTF(GDT_D_DEBUG
, ("iir_watchdog(%p)\n", gdt
));
1476 int ccbs
= 0, ucmds
= 0, frees
= 0, pends
= 0;
1481 for (h
= TAILQ_FIRST(&gdt
->sc_ccb_queue
); h
!= NULL
;
1482 h
= TAILQ_NEXT(h
, sim_links
.tqe
))
1484 for (u
= TAILQ_FIRST(&gdt
->sc_ucmd_queue
); u
!= NULL
;
1485 u
= TAILQ_NEXT(u
, links
))
1487 for (p
= SLIST_FIRST(&gdt
->sc_free_gccb
); p
!= NULL
;
1488 p
= SLIST_NEXT(p
, sle
))
1490 for (p
= SLIST_FIRST(&gdt
->sc_pending_gccb
); p
!= NULL
;
1491 p
= SLIST_NEXT(p
, sle
))
1494 GDT_DPRINTF(GDT_D_TIMEOUT
, ("ccbs %d ucmds %d frees %d pends %d\n",
1495 ccbs
, ucmds
, frees
, pends
));
1498 callout_reset(&gdt
->watchdog_timer
, hz
* 15, iir_watchdog
, gdt
);
1502 iir_shutdown( void *arg
, int howto
)
1504 struct gdt_softc
*gdt
;
1505 struct gdt_ccb
*gccb
;
1509 gdt
= (struct gdt_softc
*)arg
;
1510 GDT_DPRINTF(GDT_D_CMD
, ("iir_shutdown(%p, %d)\n", gdt
, howto
));
1512 printf("iir%d: Flushing all Host Drives. Please wait ... ",
1515 /* allocate ucmd buffer */
1516 ucmd
= kmalloc(sizeof(gdt_ucmd_t
), M_DEVBUF
, M_INTWAIT
| M_ZERO
);
1518 /* wait for pending IOs */
1520 gdt
->sc_state
= GDT_SHUTDOWN
;
1522 if ((gccb
= SLIST_FIRST(&gdt
->sc_pending_gccb
)) != NULL
)
1523 (void) tsleep((void *)gccb
, PCATCH
, "iirshw", 100 * hz
);
1526 for (i
= 0; i
< GDT_MAX_HDRIVES
; ++i
) {
1527 if (gdt
->sc_hdr
[i
].hd_present
) {
1528 ucmd
->service
= GDT_CACHESERVICE
;
1529 ucmd
->OpCode
= GDT_FLUSH
;
1530 ucmd
->u
.cache
.DeviceNo
= i
;
1532 TAILQ_INSERT_TAIL(&gdt
->sc_ucmd_queue
, ucmd
, links
);
1533 ucmd
->complete_flag
= FALSE
;
1536 if (!ucmd
->complete_flag
)
1537 (void) tsleep((void *)ucmd
, PCATCH
, "iirshw", 10*hz
);
1541 kfree(ucmd
, M_DEVBUF
);
1548 struct gdt_softc
*gdt
= arg
;
1549 struct gdt_intr_ctx ctx
;
1550 struct gdt_ccb
*gccb
;
1554 GDT_DPRINTF(GDT_D_INTR
, ("gdt_intr(%p)\n", gdt
));
1556 /* If polling and we were not called from gdt_wait, just return */
1557 if ((gdt
->sc_state
& GDT_POLLING
) &&
1558 !(gdt
->sc_state
& GDT_POLL_WAIT
))
1561 if (!(gdt
->sc_state
& GDT_POLLING
))
1565 ctx
.istatus
= gdt
->sc_get_status(gdt
);
1567 if (!(gdt
->sc_state
& GDT_POLLING
))
1569 gdt
->sc_status
= GDT_S_NO_STATUS
;
1573 gdt
->sc_intr(gdt
, &ctx
);
1575 gdt
->sc_status
= ctx
.cmd_status
;
1576 gdt
->sc_service
= ctx
.service
;
1577 gdt
->sc_info
= ctx
.info
;
1578 gdt
->sc_info2
= ctx
.info2
;
1580 if (gdt
->sc_state
& GDT_POLL_WAIT
) {
1582 gdt_wait_index
= ctx
.istatus
;
1585 if (ctx
.istatus
== GDT_ASYNCINDEX
) {
1586 gdt_async_event(gdt
, ctx
.service
);
1587 if (!(gdt
->sc_state
& GDT_POLLING
))
1591 if (ctx
.istatus
== GDT_SPEZINDEX
) {
1592 GDT_DPRINTF(GDT_D_INVALID
,
1593 ("iir%d: Service unknown or not initialized!\n",
1595 gdt
->sc_dvr
.size
= sizeof(gdt
->sc_dvr
.eu
.driver
);
1596 gdt
->sc_dvr
.eu
.driver
.ionode
= gdt
->sc_hanum
;
1597 gdt_store_event(GDT_ES_DRIVER
, 4, &gdt
->sc_dvr
);
1598 if (!(gdt
->sc_state
& GDT_POLLING
))
1603 gccb
= &gdt
->sc_gccbs
[ctx
.istatus
- 2];
1604 ctx
.service
= gccb
->gc_service
;
1606 switch (gccb
->gc_flags
) {
1607 case GDT_GCF_UNUSED
:
1608 GDT_DPRINTF(GDT_D_INVALID
, ("iir%d: Index (%d) to unused command!\n",
1609 gdt
->sc_hanum
, ctx
.istatus
));
1610 gdt
->sc_dvr
.size
= sizeof(gdt
->sc_dvr
.eu
.driver
);
1611 gdt
->sc_dvr
.eu
.driver
.ionode
= gdt
->sc_hanum
;
1612 gdt
->sc_dvr
.eu
.driver
.index
= ctx
.istatus
;
1613 gdt_store_event(GDT_ES_DRIVER
, 1, &gdt
->sc_dvr
);
1614 gdt_free_ccb(gdt
, gccb
);
1617 case GDT_GCF_INTERNAL
:
1618 if (!(gdt
->sc_state
& GDT_POLLING
))
1623 ucmd
= gccb
->gc_ucmd
;
1624 if (gdt
->sc_status
== GDT_S_BSY
) {
1625 GDT_DPRINTF(GDT_D_DEBUG
, ("iir_intr(%p) ioctl: gccb %p busy\n",
1627 TAILQ_INSERT_HEAD(&gdt
->sc_ucmd_queue
, ucmd
, links
);
1628 if (!(gdt
->sc_state
& GDT_POLLING
))
1631 ucmd
->status
= gdt
->sc_status
;
1632 ucmd
->info
= gdt
->sc_info
;
1633 ucmd
->complete_flag
= TRUE
;
1634 if (ucmd
->service
== GDT_CACHESERVICE
) {
1635 if (ucmd
->OpCode
== GDT_IOCTL
) {
1636 cnt
= ucmd
->u
.ioctl
.param_size
;
1638 bcopy(gccb
->gc_scratch
, ucmd
->data
, cnt
);
1640 cnt
= ucmd
->u
.cache
.BlockCnt
* GDT_SECTOR_SIZE
;
1642 bcopy(gccb
->gc_scratch
, ucmd
->data
, cnt
);
1645 cnt
= ucmd
->u
.raw
.sdlen
;
1647 bcopy(gccb
->gc_scratch
, ucmd
->data
, cnt
);
1648 if (ucmd
->u
.raw
.sense_len
!= 0)
1649 bcopy(gccb
->gc_scratch
, ucmd
->data
, cnt
);
1651 gdt_free_ccb(gdt
, gccb
);
1652 if (!(gdt
->sc_state
& GDT_POLLING
))
1661 gdt_free_ccb(gdt
, gccb
);
1662 gdt_sync_event(gdt
, ctx
.service
, ctx
.istatus
, gccb
);
1663 if (!(gdt
->sc_state
& GDT_POLLING
))
1671 gdt_async_event(struct gdt_softc
*gdt
, int service
)
1673 struct gdt_ccb
*gccb
;
1675 GDT_DPRINTF(GDT_D_INTR
, ("gdt_async_event(%p, %d)\n", gdt
, service
));
1677 if (service
== GDT_SCREENSERVICE
) {
1678 if (gdt
->sc_status
== GDT_MSG_REQUEST
) {
1679 while (gdt
->sc_test_busy(gdt
))
1681 bzero(gdt
->sc_cmd
, GDT_CMD_SZ
);
1682 gccb
= gdt_get_ccb(gdt
);
1684 printf("iir%d: No free command index found\n",
1688 gccb
->gc_service
= service
;
1689 gccb
->gc_flags
= GDT_GCF_SCREEN
;
1690 gdt
->sc_set_sema0(gdt
);
1691 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_COMMANDINDEX
,
1692 gccb
->gc_cmd_index
);
1693 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_OPCODE
, GDT_READ
);
1694 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_SCREEN_MSG_HANDLE
,
1695 GDT_MSG_INV_HANDLE
);
1696 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_SCREEN_MSG_ADDR
,
1697 gdt_ccb_vtop(gdt
, gccb
) +
1698 offsetof(struct gdt_ccb
, gc_scratch
[0]));
1699 gdt
->sc_cmd_off
= 0;
1700 gdt
->sc_cmd_len
= roundup(GDT_CMD_UNION
+ GDT_SCREEN_SZ
,
1702 gdt
->sc_cmd_cnt
= 0;
1703 gdt
->sc_copy_cmd(gdt
, gccb
);
1704 printf("iir%d: [PCI %d/%d] ",
1705 gdt
->sc_hanum
,gdt
->sc_bus
,gdt
->sc_slot
);
1706 gdt
->sc_release_event(gdt
);
1710 if ((gdt
->sc_fw_vers
& 0xff) >= 0x1a) {
1711 gdt
->sc_dvr
.size
= 0;
1712 gdt
->sc_dvr
.eu
.async
.ionode
= gdt
->sc_hanum
;
1713 gdt
->sc_dvr
.eu
.async
.status
= gdt
->sc_status
;
1714 /* severity and event_string already set! */
1716 gdt
->sc_dvr
.size
= sizeof(gdt
->sc_dvr
.eu
.async
);
1717 gdt
->sc_dvr
.eu
.async
.ionode
= gdt
->sc_hanum
;
1718 gdt
->sc_dvr
.eu
.async
.service
= service
;
1719 gdt
->sc_dvr
.eu
.async
.status
= gdt
->sc_status
;
1720 gdt
->sc_dvr
.eu
.async
.info
= gdt
->sc_info
;
1721 *(u_int32_t
*)gdt
->sc_dvr
.eu
.async
.scsi_coord
= gdt
->sc_info2
;
1723 gdt_store_event(GDT_ES_ASYNC
, service
, &gdt
->sc_dvr
);
1724 printf("iir%d: %s\n", gdt
->sc_hanum
, gdt
->sc_dvr
.event_string
);
1731 gdt_sync_event(struct gdt_softc
*gdt
, int service
,
1732 u_int8_t index
, struct gdt_ccb
*gccb
)
1735 bus_dmasync_op_t op
;
1737 GDT_DPRINTF(GDT_D_INTR
,
1738 ("gdt_sync_event(%p, %d, %d, %p)\n", gdt
,service
,index
,gccb
));
1742 if (service
== GDT_SCREENSERVICE
) {
1745 msg_len
= gdt_dec32(gccb
->gc_scratch
+ GDT_SCR_MSG_LEN
);
1747 if (!(gccb
->gc_scratch
[GDT_SCR_MSG_ANSWER
] &&
1748 gccb
->gc_scratch
[GDT_SCR_MSG_EXT
])) {
1749 gccb
->gc_scratch
[GDT_SCR_MSG_TEXT
+ msg_len
] = '\0';
1750 printf("%s",&gccb
->gc_scratch
[GDT_SCR_MSG_TEXT
]);
1753 if (gccb
->gc_scratch
[GDT_SCR_MSG_EXT
] &&
1754 !gccb
->gc_scratch
[GDT_SCR_MSG_ANSWER
]) {
1755 while (gdt
->sc_test_busy(gdt
))
1757 bzero(gdt
->sc_cmd
, GDT_CMD_SZ
);
1758 gccb
= gdt_get_ccb(gdt
);
1760 printf("iir%d: No free command index found\n",
1764 gccb
->gc_service
= service
;
1765 gccb
->gc_flags
= GDT_GCF_SCREEN
;
1766 gdt
->sc_set_sema0(gdt
);
1767 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_COMMANDINDEX
,
1768 gccb
->gc_cmd_index
);
1769 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_OPCODE
, GDT_READ
);
1770 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_SCREEN_MSG_HANDLE
,
1771 gccb
->gc_scratch
[GDT_SCR_MSG_HANDLE
]);
1772 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_SCREEN_MSG_ADDR
,
1773 gdt_ccb_vtop(gdt
, gccb
) +
1774 offsetof(struct gdt_ccb
, gc_scratch
[0]));
1775 gdt
->sc_cmd_off
= 0;
1776 gdt
->sc_cmd_len
= roundup(GDT_CMD_UNION
+ GDT_SCREEN_SZ
,
1778 gdt
->sc_cmd_cnt
= 0;
1779 gdt
->sc_copy_cmd(gdt
, gccb
);
1780 gdt
->sc_release_event(gdt
);
1784 if (gccb
->gc_scratch
[GDT_SCR_MSG_ANSWER
] &&
1785 gdt_dec32(gccb
->gc_scratch
+ GDT_SCR_MSG_ALEN
)) {
1786 /* default answers (getchar() not possible) */
1787 if (gdt_dec32(gccb
->gc_scratch
+ GDT_SCR_MSG_ALEN
) == 1) {
1788 gdt_enc32(gccb
->gc_scratch
+ GDT_SCR_MSG_ALEN
, 0);
1789 gdt_enc32(gccb
->gc_scratch
+ GDT_SCR_MSG_LEN
, 1);
1790 gccb
->gc_scratch
[GDT_SCR_MSG_TEXT
] = 0;
1792 gdt_enc32(gccb
->gc_scratch
+ GDT_SCR_MSG_ALEN
,
1793 gdt_dec32(gccb
->gc_scratch
+ GDT_SCR_MSG_ALEN
) - 2);
1794 gdt_enc32(gccb
->gc_scratch
+ GDT_SCR_MSG_LEN
, 2);
1795 gccb
->gc_scratch
[GDT_SCR_MSG_TEXT
] = 1;
1796 gccb
->gc_scratch
[GDT_SCR_MSG_TEXT
+ 1] = 0;
1798 gccb
->gc_scratch
[GDT_SCR_MSG_EXT
] = 0;
1799 gccb
->gc_scratch
[GDT_SCR_MSG_ANSWER
] = 0;
1800 while (gdt
->sc_test_busy(gdt
))
1802 bzero(gdt
->sc_cmd
, GDT_CMD_SZ
);
1803 gccb
= gdt_get_ccb(gdt
);
1805 printf("iir%d: No free command index found\n",
1809 gccb
->gc_service
= service
;
1810 gccb
->gc_flags
= GDT_GCF_SCREEN
;
1811 gdt
->sc_set_sema0(gdt
);
1812 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_COMMANDINDEX
,
1813 gccb
->gc_cmd_index
);
1814 gdt_enc16(gdt
->sc_cmd
+ GDT_CMD_OPCODE
, GDT_WRITE
);
1815 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_SCREEN_MSG_HANDLE
,
1816 gccb
->gc_scratch
[GDT_SCR_MSG_HANDLE
]);
1817 gdt_enc32(gdt
->sc_cmd
+ GDT_CMD_UNION
+ GDT_SCREEN_MSG_ADDR
,
1818 gdt_ccb_vtop(gdt
, gccb
) +
1819 offsetof(struct gdt_ccb
, gc_scratch
[0]));
1820 gdt
->sc_cmd_off
= 0;
1821 gdt
->sc_cmd_len
= roundup(GDT_CMD_UNION
+ GDT_SCREEN_SZ
,
1823 gdt
->sc_cmd_cnt
= 0;
1824 gdt
->sc_copy_cmd(gdt
, gccb
);
1825 gdt
->sc_release_event(gdt
);
1831 callout_stop(&ccb
->ccb_h
.timeout_ch
);
1832 if (gdt
->sc_status
== GDT_S_BSY
) {
1833 GDT_DPRINTF(GDT_D_DEBUG
, ("gdt_sync_event(%p) gccb %p busy\n",
1835 TAILQ_INSERT_HEAD(&gdt
->sc_ccb_queue
, &ccb
->ccb_h
, sim_links
.tqe
);
1836 ++gdt_stat
.req_queue_act
;
1837 if (gdt_stat
.req_queue_act
> gdt_stat
.req_queue_max
)
1838 gdt_stat
.req_queue_max
= gdt_stat
.req_queue_act
;
1842 if ((ccb
->ccb_h
.flags
& CAM_DIR_MASK
) == CAM_DIR_IN
)
1843 op
= BUS_DMASYNC_POSTREAD
;
1845 op
= BUS_DMASYNC_POSTWRITE
;
1846 bus_dmamap_sync(gdt
->sc_buffer_dmat
, gccb
->gc_dmamap
, op
);
1848 ccb
->csio
.resid
= 0;
1849 if (gdt
->sc_status
== GDT_S_OK
) {
1850 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
1853 if (gccb
->gc_service
== GDT_CACHESERVICE
) {
1854 ccb
->ccb_h
.status
= CAM_SCSI_STATUS_ERROR
| CAM_AUTOSNS_VALID
;
1855 ccb
->csio
.scsi_status
= SCSI_STATUS_CHECK_COND
;
1856 bzero(&ccb
->csio
.sense_data
, ccb
->csio
.sense_len
);
1857 ccb
->csio
.sense_data
.error_code
=
1858 SSD_CURRENT_ERROR
| SSD_ERRCODE_VALID
;
1859 ccb
->csio
.sense_data
.flags
= SSD_KEY_NOT_READY
;
1861 gdt
->sc_dvr
.size
= sizeof(gdt
->sc_dvr
.eu
.sync
);
1862 gdt
->sc_dvr
.eu
.sync
.ionode
= gdt
->sc_hanum
;
1863 gdt
->sc_dvr
.eu
.sync
.service
= service
;
1864 gdt
->sc_dvr
.eu
.sync
.status
= gdt
->sc_status
;
1865 gdt
->sc_dvr
.eu
.sync
.info
= gdt
->sc_info
;
1866 gdt
->sc_dvr
.eu
.sync
.hostdrive
= ccb
->ccb_h
.target_id
;
1867 if (gdt
->sc_status
>= 0x8000)
1868 gdt_store_event(GDT_ES_SYNC
, 0, &gdt
->sc_dvr
);
1870 gdt_store_event(GDT_ES_SYNC
, service
, &gdt
->sc_dvr
);
1873 if (gdt
->sc_status
!= GDT_S_RAW_SCSI
|| gdt
->sc_info
>= 0x100) {
1874 ccb
->ccb_h
.status
= CAM_SEL_TIMEOUT
;
1876 ccb
->ccb_h
.status
= CAM_SCSI_STATUS_ERROR
|CAM_AUTOSNS_VALID
;
1877 ccb
->csio
.scsi_status
= gdt
->sc_info
;
1878 bcopy(gccb
->gc_scratch
, &ccb
->csio
.sense_data
,
1879 ccb
->csio
.sense_len
);
1883 --gdt_stat
.io_count_act
;
1889 /* Controller event handling functions */
1891 gdt_store_event(u_int16_t source
, u_int16_t idx
, gdt_evt_data
*evt
)
1896 GDT_DPRINTF(GDT_D_MISC
, ("gdt_store_event(%d, %d)\n", source
, idx
));
1897 if (source
== 0) /* no source -> no event */
1900 if (ebuffer
[elastidx
].event_source
== source
&&
1901 ebuffer
[elastidx
].event_idx
== idx
&&
1902 ((evt
->size
!= 0 && ebuffer
[elastidx
].event_data
.size
!= 0 &&
1903 !memcmp((char *)&ebuffer
[elastidx
].event_data
.eu
,
1904 (char *)&evt
->eu
, evt
->size
)) ||
1905 (evt
->size
== 0 && ebuffer
[elastidx
].event_data
.size
== 0 &&
1906 !strcmp((char *)&ebuffer
[elastidx
].event_data
.event_string
,
1907 (char *)&evt
->event_string
)))) {
1908 e
= &ebuffer
[elastidx
];
1910 e
->last_stamp
= tv
.tv_sec
;
1913 if (ebuffer
[elastidx
].event_source
!= 0) { /* entry not free ? */
1915 if (elastidx
== GDT_MAX_EVENTS
)
1917 if (elastidx
== eoldidx
) { /* reached mark ? */
1919 if (eoldidx
== GDT_MAX_EVENTS
)
1923 e
= &ebuffer
[elastidx
];
1924 e
->event_source
= source
;
1927 e
->first_stamp
= e
->last_stamp
= tv
.tv_sec
;
1929 e
->event_data
= *evt
;
1936 gdt_read_event(int handle
, gdt_evt_str
*estr
)
1941 GDT_DPRINTF(GDT_D_MISC
, ("gdt_read_event(%d)\n", handle
));
1947 estr
->event_source
= 0;
1949 if (eindex
>= GDT_MAX_EVENTS
) {
1953 e
= &ebuffer
[eindex
];
1954 if (e
->event_source
!= 0) {
1955 if (eindex
!= elastidx
) {
1956 if (++eindex
== GDT_MAX_EVENTS
)
1961 memcpy(estr
, e
, sizeof(gdt_evt_str
));
1968 gdt_readapp_event(u_int8_t application
, gdt_evt_str
*estr
)
1974 GDT_DPRINTF(GDT_D_MISC
, ("gdt_readapp_event(%d)\n", application
));
1978 e
= &ebuffer
[eindex
];
1979 if (e
->event_source
== 0)
1981 if ((e
->application
& application
) == 0) {
1982 e
->application
|= application
;
1986 if (eindex
== elastidx
)
1988 if (++eindex
== GDT_MAX_EVENTS
)
1992 memcpy(estr
, e
, sizeof(gdt_evt_str
));
1994 estr
->event_source
= 0;
1999 gdt_clear_events(void)
2001 GDT_DPRINTF(GDT_D_MISC
, ("gdt_clear_events\n"));
2003 eoldidx
= elastidx
= 0;
2004 ebuffer
[0].event_source
= 0;