2 * Implementation of SCSI Direct Access Peripheral driver for CAM.
4 * Copyright (c) 1997 Justin T. Gibbs.
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. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
38 #include <sys/sysctl.h>
39 #include <sys/taskqueue.h>
41 #include <sys/mutex.h>
43 #include <sys/devicestat.h>
44 #include <sys/eventhandler.h>
45 #include <sys/malloc.h>
47 #include <geom/geom_disk.h>
56 #include <cam/cam_ccb.h>
57 #include <cam/cam_periph.h>
58 #include <cam/cam_xpt_periph.h>
59 #include <cam/cam_sim.h>
61 #include <cam/scsi/scsi_message.h>
64 #include <cam/scsi/scsi_da.h>
75 DA_FLAG_PACK_INVALID = 0x001,
76 DA_FLAG_NEW_PACK = 0x002,
77 DA_FLAG_PACK_LOCKED = 0x004,
78 DA_FLAG_PACK_REMOVABLE = 0x008,
79 DA_FLAG_TAGGED_QUEUING = 0x010,
80 DA_FLAG_NEED_OTAG = 0x020,
81 DA_FLAG_WENT_IDLE = 0x040,
82 DA_FLAG_RETRY_UA = 0x080,
84 DA_FLAG_SCTX_INIT = 0x200
89 DA_Q_NO_SYNC_CACHE = 0x01,
90 DA_Q_NO_6_BYTE = 0x02,
91 DA_Q_NO_PREVENT = 0x04,
98 DA_CCB_BUFFER_IO = 0x03,
99 DA_CCB_WAITING = 0x04,
101 DA_CCB_TYPE_MASK = 0x0F,
102 DA_CCB_RETRY_UA = 0x10
105 /* Offsets into our private area for storing information */
106 #define ccb_state ppriv_field0
107 #define ccb_bp ppriv_ptr1
112 u_int8_t secs_per_track;
113 u_int32_t secsize; /* Number of bytes/sector */
114 u_int64_t sectors; /* total number sectors */
120 struct bio_queue_head bio_queue;
121 SLIST_ENTRY(da_softc) links;
122 LIST_HEAD(, ccb_hdr) pending_ccbs;
126 int minimum_cmd_size;
128 int ordered_tag_count;
129 int outstanding_cmds;
130 struct disk_params params;
133 struct task sysctl_task;
134 struct sysctl_ctx_list sysctl_ctx;
135 struct sysctl_oid *sysctl_tree;
136 struct callout sendordered_c;
139 struct da_quirk_entry {
140 struct scsi_inquiry_pattern inq_pat;
144 static const char quantum[] = "QUANTUM";
145 static const char microp[] = "MICROP";
147 static struct da_quirk_entry da_quirk_table[] =
149 /* SPI, FC devices */
152 * Fujitsu M2513A MO drives.
153 * Tested devices: M2513A2 firmware versions 1200 & 1300.
154 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
155 * Reported by: W.Scholten <whs@xs4all.nl>
157 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
158 /*quirks*/ DA_Q_NO_SYNC_CACHE
162 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
163 /*quirks*/ DA_Q_NO_SYNC_CACHE
167 * This particular Fujitsu drive doesn't like the
168 * synchronize cache command.
169 * Reported by: Tom Jackson <toj@gorilla.net>
171 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
172 /*quirks*/ DA_Q_NO_SYNC_CACHE
176 * This drive doesn't like the synchronize cache command
177 * either. Reported by: Matthew Jacob <mjacob@feral.com>
178 * in NetBSD PR kern/6027, August 24, 1998.
180 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
181 /*quirks*/ DA_Q_NO_SYNC_CACHE
185 * This drive doesn't like the synchronize cache command
186 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
189 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
190 /*quirks*/ DA_Q_NO_SYNC_CACHE
194 * Doesn't like the synchronize cache command.
195 * Reported by: Blaz Zupan <blaz@gold.amis.net>
197 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
198 /*quirks*/ DA_Q_NO_SYNC_CACHE
202 * Doesn't like the synchronize cache command.
203 * Reported by: Blaz Zupan <blaz@gold.amis.net>
205 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
206 /*quirks*/ DA_Q_NO_SYNC_CACHE
210 * Doesn't like the synchronize cache command.
212 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
213 /*quirks*/ DA_Q_NO_SYNC_CACHE
217 * Doesn't like the synchronize cache command.
218 * Reported by: walter@pelissero.de
220 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
221 /*quirks*/ DA_Q_NO_SYNC_CACHE
225 * Doesn't work correctly with 6 byte reads/writes.
226 * Returns illegal request, and points to byte 9 of the
228 * Reported by: Adam McDougall <bsdx@spawnet.com>
230 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
231 /*quirks*/ DA_Q_NO_6_BYTE
235 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
236 /*quirks*/ DA_Q_NO_6_BYTE
240 * Doesn't like the synchronize cache command.
241 * Reported by: walter@pelissero.de
243 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
244 /*quirks*/ DA_Q_NO_SYNC_CACHE
248 * The CISS RAID controllers do not support SYNC_CACHE
250 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
251 /*quirks*/ DA_Q_NO_SYNC_CACHE
253 /* USB mass storage devices supported by umass(4) */
256 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
259 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
260 /*quirks*/ DA_Q_NO_SYNC_CACHE
264 * Power Quotient Int. (PQI) USB flash key
267 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
268 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
272 * Creative Nomad MUVO mp3 player (USB)
275 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
276 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
280 * Jungsoft NEXDISK USB flash key
283 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
284 /*quirks*/ DA_Q_NO_SYNC_CACHE
288 * FreeDik USB Mini Data Drive
291 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
292 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
296 * Sigmatel USB Flash MP3 Player
299 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
300 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
304 * Neuros USB Digital Audio Computer
307 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
308 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
312 * SEAGRAND NP-900 MP3 Player
315 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
316 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
320 * iRiver iFP MP3 player (with UMS Firmware)
321 * PR: kern/54881, i386/63941, kern/66124
323 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
324 /*quirks*/ DA_Q_NO_SYNC_CACHE
328 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
331 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
332 /*quirks*/ DA_Q_NO_SYNC_CACHE
336 * ZICPlay USB MP3 Player with FM
339 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
340 /*quirks*/ DA_Q_NO_SYNC_CACHE
344 * TEAC USB floppy mechanisms
346 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
347 /*quirks*/ DA_Q_NO_SYNC_CACHE
351 * Kingston DataTraveler II+ USB Pen-Drive.
352 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
354 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
355 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
359 * Motorola E398 Mobile Phone (TransFlash memory card).
360 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
363 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
364 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
368 * Qware BeatZkey! Pro
371 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
372 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
376 * Time DPA20B 1GB MP3 Player
379 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
380 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
384 * Samsung USB key 128Mb
387 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
388 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
392 * Kingston DataTraveler 2.0 USB Flash memory.
395 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
396 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
400 * Creative MUVO Slim mp3 player (USB)
403 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
404 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
408 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
411 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
412 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
416 * SanDisk Micro Cruzer 128MB
419 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
420 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
424 * TOSHIBA TransMemory USB sticks
427 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
428 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
433 * PR: usb/75578, usb/72344, usb/65436
435 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
436 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
440 * Genesys 6-in-1 Card Reader
443 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
444 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
448 * Rekam Digital CAMERA
451 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
452 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
456 * iRiver H10 MP3 player
459 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
460 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
464 * iRiver U10 MP3 player
467 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
468 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
475 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
476 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
480 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
483 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
484 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
491 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
492 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
496 * Philips USB Key Audio KEY013
499 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
500 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
507 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
508 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
515 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
516 /*quirks*/ DA_Q_NO_SYNC_CACHE
520 * I/O Magic USB flash - Giga Bank
523 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
524 /*quirks*/ DA_Q_NO_SYNC_CACHE
528 * JoyFly 128mb USB Flash Drive
531 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
532 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
539 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
540 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
544 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
547 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
548 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
552 * Samsung YP-U3 mp3-player
555 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
556 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
559 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
560 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
564 * Sony Cyber-Shot DSC cameras
567 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
568 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
570 /* ATA/SATA devices over SAS/USB/... */
572 /* Hitachi Advanced Format (4k) drives */
573 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
577 /* Samsung Advanced Format (4k) drives */
578 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
582 /* Samsung Advanced Format (4k) drives */
583 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
587 /* Samsung Advanced Format (4k) drives */
588 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
592 /* Samsung Advanced Format (4k) drives */
593 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
597 /* Seagate Barracuda Green Advanced Format (4k) drives */
598 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
602 /* Seagate Barracuda Green Advanced Format (4k) drives */
603 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
607 /* Seagate Barracuda Green Advanced Format (4k) drives */
608 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
612 /* Seagate Barracuda Green Advanced Format (4k) drives */
613 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
617 /* Seagate Barracuda Green Advanced Format (4k) drives */
618 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
622 /* Seagate Barracuda Green Advanced Format (4k) drives */
623 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
627 /* Seagate Momentus Advanced Format (4k) drives */
628 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
632 /* Seagate Momentus Advanced Format (4k) drives */
633 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
637 /* Seagate Momentus Advanced Format (4k) drives */
638 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
642 /* Seagate Momentus Advanced Format (4k) drives */
643 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
647 /* Seagate Momentus Advanced Format (4k) drives */
648 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
652 /* Seagate Momentus Advanced Format (4k) drives */
653 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
657 /* Seagate Momentus Advanced Format (4k) drives */
658 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
662 /* Seagate Momentus Advanced Format (4k) drives */
663 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
667 /* Seagate Momentus Advanced Format (4k) drives */
668 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
672 /* Seagate Momentus Advanced Format (4k) drives */
673 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
677 /* Seagate Momentus Advanced Format (4k) drives */
678 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
682 /* Seagate Momentus Advanced Format (4k) drives */
683 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
687 /* Seagate Momentus Advanced Format (4k) drives */
688 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
692 /* Seagate Momentus Advanced Format (4k) drives */
693 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
697 /* Seagate Momentus Thin Advanced Format (4k) drives */
698 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
702 /* Seagate Momentus Thin Advanced Format (4k) drives */
703 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
707 /* WDC Caviar Green Advanced Format (4k) drives */
708 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
712 /* WDC Caviar Green Advanced Format (4k) drives */
713 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
717 /* WDC Caviar Green Advanced Format (4k) drives */
718 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
722 /* WDC Caviar Green Advanced Format (4k) drives */
723 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
727 /* WDC Caviar Green Advanced Format (4k) drives */
728 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
732 /* WDC Caviar Green Advanced Format (4k) drives */
733 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
737 /* WDC Caviar Green Advanced Format (4k) drives */
738 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
742 /* WDC Caviar Green Advanced Format (4k) drives */
743 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
747 /* WDC Scorpio Black Advanced Format (4k) drives */
748 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
752 /* WDC Scorpio Black Advanced Format (4k) drives */
753 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
757 /* WDC Scorpio Black Advanced Format (4k) drives */
758 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
762 /* WDC Scorpio Black Advanced Format (4k) drives */
763 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
767 /* WDC Scorpio Blue Advanced Format (4k) drives */
768 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
772 /* WDC Scorpio Blue Advanced Format (4k) drives */
773 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
777 /* WDC Scorpio Blue Advanced Format (4k) drives */
778 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
782 /* WDC Scorpio Blue Advanced Format (4k) drives */
783 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
788 static disk_strategy_t dastrategy;
789 static dumper_t dadump;
790 static periph_init_t dainit;
791 static void daasync(void *callback_arg, u_int32_t code,
792 struct cam_path *path, void *arg);
793 static void dasysctlinit(void *context, int pending);
794 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
795 static periph_ctor_t daregister;
796 static periph_dtor_t dacleanup;
797 static periph_start_t dastart;
798 static periph_oninv_t daoninvalidate;
799 static void dadone(struct cam_periph *periph,
800 union ccb *done_ccb);
801 static int daerror(union ccb *ccb, u_int32_t cam_flags,
802 u_int32_t sense_flags);
803 static void daprevent(struct cam_periph *periph, int action);
804 static int dagetcapacity(struct cam_periph *periph);
805 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
806 uint64_t maxsector, u_int lbppbe, u_int lalba);
807 static timeout_t dasendorderedtag;
808 static void dashutdown(void *arg, int howto);
810 #ifndef DA_DEFAULT_TIMEOUT
811 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
814 #ifndef DA_DEFAULT_RETRY
815 #define DA_DEFAULT_RETRY 4
818 #ifndef DA_DEFAULT_SEND_ORDERED
819 #define DA_DEFAULT_SEND_ORDERED 1
823 static int da_retry_count = DA_DEFAULT_RETRY;
824 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
825 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
827 SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
828 "CAM Direct Access Disk driver");
829 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RW,
830 &da_retry_count, 0, "Normal I/O retry count");
831 TUNABLE_INT("kern.cam.da.retry_count", &da_retry_count);
832 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RW,
833 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
834 TUNABLE_INT("kern.cam.da.default_timeout", &da_default_timeout);
835 SYSCTL_INT(_kern_cam_da, OID_AUTO, da_send_ordered, CTLFLAG_RW,
836 &da_send_ordered, 0, "Send Ordered Tags");
837 TUNABLE_INT("kern.cam.da.da_send_ordered", &da_send_ordered);
840 * DA_ORDEREDTAG_INTERVAL determines how often, relative
841 * to the default timeout, we check to see whether an ordered
842 * tagged transaction is appropriate to prevent simple tag
843 * starvation. Since we'd like to ensure that there is at least
844 * 1/2 of the timeout length left for a starved transaction to
845 * complete after we've sent an ordered tag, we must poll at least
846 * four times in every timeout period. This takes care of the worst
847 * case where a starved transaction starts during an interval that
848 * meets the requirement "don't send an ordered tag" test so it takes
849 * us two intervals to determine that a tag must be sent.
851 #ifndef DA_ORDEREDTAG_INTERVAL
852 #define DA_ORDEREDTAG_INTERVAL 4
855 static struct periph_driver dadriver =
858 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
861 PERIPHDRIVER_DECLARE(da, dadriver);
863 MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
866 daopen(struct disk *dp)
868 struct cam_periph *periph;
869 struct da_softc *softc;
873 periph = (struct cam_periph *)dp->d_drv1;
874 if (periph == NULL) {
878 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
882 cam_periph_lock(periph);
883 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
884 cam_periph_unlock(periph);
885 cam_periph_release(periph);
889 unit = periph->unit_number;
890 softc = (struct da_softc *)periph->softc;
891 softc->flags |= DA_FLAG_OPEN;
893 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
894 ("daopen: disk=%s%d (unit %d)\n", dp->d_name, dp->d_unit,
897 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
898 /* Invalidate our pack information. */
899 softc->flags &= ~DA_FLAG_PACK_INVALID;
902 error = dagetcapacity(periph);
906 softc->disk->d_sectorsize = softc->params.secsize;
907 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
908 softc->disk->d_stripesize = softc->params.stripesize;
909 softc->disk->d_stripeoffset = softc->params.stripeoffset;
910 /* XXX: these are not actually "firmware" values, so they may be wrong */
911 softc->disk->d_fwsectors = softc->params.secs_per_track;
912 softc->disk->d_fwheads = softc->params.heads;
913 softc->disk->d_devstat->block_size = softc->params.secsize;
914 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
916 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
917 (softc->quirks & DA_Q_NO_PREVENT) == 0)
918 daprevent(periph, PR_PREVENT);
920 softc->flags &= ~DA_FLAG_OPEN;
922 cam_periph_unhold(periph);
923 cam_periph_unlock(periph);
926 cam_periph_release(periph);
932 daclose(struct disk *dp)
934 struct cam_periph *periph;
935 struct da_softc *softc;
938 periph = (struct cam_periph *)dp->d_drv1;
942 cam_periph_lock(periph);
943 if ((error = cam_periph_hold(periph, PRIBIO)) != 0) {
944 cam_periph_unlock(periph);
945 cam_periph_release(periph);
949 softc = (struct da_softc *)periph->softc;
951 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
954 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
956 scsi_synchronize_cache(&ccb->csio,
960 /*begin_lba*/0,/* Cover the whole disk */
965 cam_periph_runccb(ccb, /*error_routine*/NULL, /*cam_flags*/0,
966 /*sense_flags*/SF_RETRY_UA,
967 softc->disk->d_devstat);
969 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
970 if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
971 CAM_SCSI_STATUS_ERROR) {
973 int sense_key, error_code;
975 scsi_extract_sense(&ccb->csio.sense_data,
979 if (sense_key != SSD_KEY_ILLEGAL_REQUEST)
980 scsi_sense_print(&ccb->csio);
982 xpt_print(periph->path, "Synchronize cache "
983 "failed, status == 0x%x, scsi status == "
984 "0x%x\n", ccb->csio.ccb_h.status,
985 ccb->csio.scsi_status);
989 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
990 cam_release_devq(ccb->ccb_h.path,
996 xpt_release_ccb(ccb);
1000 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0) {
1001 if ((softc->quirks & DA_Q_NO_PREVENT) == 0)
1002 daprevent(periph, PR_ALLOW);
1004 * If we've got removeable media, mark the blocksize as
1005 * unavailable, since it could change when new media is
1008 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1011 softc->flags &= ~DA_FLAG_OPEN;
1012 cam_periph_unhold(periph);
1013 cam_periph_unlock(periph);
1014 cam_periph_release(periph);
1019 * Actually translate the requested transfer into one the physical driver
1020 * can understand. The transfer is described by a buf and will include
1021 * only one physical transfer.
1024 dastrategy(struct bio *bp)
1026 struct cam_periph *periph;
1027 struct da_softc *softc;
1029 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1030 if (periph == NULL) {
1031 biofinish(bp, NULL, ENXIO);
1034 softc = (struct da_softc *)periph->softc;
1036 cam_periph_lock(periph);
1039 * If the device has been made invalid, error out
1041 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1042 cam_periph_unlock(periph);
1043 biofinish(bp, NULL, ENXIO);
1048 * Place it in the queue of disk activities for this disk
1050 bioq_disksort(&softc->bio_queue, bp);
1053 * Schedule ourselves for performing the work.
1055 xpt_schedule(periph, CAM_PRIORITY_NORMAL);
1056 cam_periph_unlock(periph);
1062 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1064 struct cam_periph *periph;
1065 struct da_softc *softc;
1067 struct ccb_scsiio csio;
1071 periph = dp->d_drv1;
1074 softc = (struct da_softc *)periph->softc;
1075 cam_periph_lock(periph);
1076 secsize = softc->params.secsize;
1078 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1079 cam_periph_unlock(periph);
1084 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1085 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1086 scsi_read_write(&csio,
1092 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1095 /*data_ptr*/(u_int8_t *) virtual,
1096 /*dxfer_len*/length,
1097 /*sense_len*/SSD_FULL_SIZE,
1098 DA_DEFAULT_TIMEOUT * 1000);
1099 xpt_polled_action((union ccb *)&csio);
1101 if ((csio.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1102 printf("Aborting dump due to I/O error.\n");
1103 if ((csio.ccb_h.status & CAM_STATUS_MASK) ==
1104 CAM_SCSI_STATUS_ERROR)
1105 scsi_sense_print(&csio);
1107 printf("status == 0x%x, scsi status == 0x%x\n",
1108 csio.ccb_h.status, csio.scsi_status);
1111 cam_periph_unlock(periph);
1116 * Sync the disk cache contents to the physical media.
1118 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1120 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1121 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1122 scsi_synchronize_cache(&csio,
1126 /*begin_lba*/0,/* Cover the whole disk */
1130 xpt_polled_action((union ccb *)&csio);
1132 if ((csio.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1133 if ((csio.ccb_h.status & CAM_STATUS_MASK) ==
1134 CAM_SCSI_STATUS_ERROR) {
1136 int sense_key, error_code;
1138 scsi_extract_sense(&csio.sense_data,
1142 if (sense_key != SSD_KEY_ILLEGAL_REQUEST)
1143 scsi_sense_print(&csio);
1145 xpt_print(periph->path, "Synchronize cache "
1146 "failed, status == 0x%x, scsi status == "
1147 "0x%x\n", csio.ccb_h.status,
1152 cam_periph_unlock(periph);
1162 * Install a global async callback. This callback will
1163 * receive async callbacks like "new device found".
1165 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1167 if (status != CAM_REQ_CMP) {
1168 printf("da: Failed to attach master async callback "
1169 "due to status 0x%x!\n", status);
1170 } else if (da_send_ordered) {
1172 /* Register our shutdown event handler */
1173 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1174 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1175 printf("dainit: shutdown event registration failed!\n");
1180 daoninvalidate(struct cam_periph *periph)
1182 struct da_softc *softc;
1184 softc = (struct da_softc *)periph->softc;
1187 * De-register any async callbacks.
1189 xpt_register_async(0, daasync, periph, periph->path);
1191 softc->flags |= DA_FLAG_PACK_INVALID;
1194 * Return all queued I/O with ENXIO.
1195 * XXX Handle any transactions queued to the card
1196 * with XPT_ABORT_CCB.
1198 bioq_flush(&softc->bio_queue, NULL, ENXIO);
1200 disk_gone(softc->disk);
1201 xpt_print(periph->path, "lost device - %d outstanding, %d refs\n",
1202 softc->outstanding_cmds, periph->refcount);
1206 dacleanup(struct cam_periph *periph)
1208 struct da_softc *softc;
1210 softc = (struct da_softc *)periph->softc;
1212 xpt_print(periph->path, "removing device entry\n");
1213 cam_periph_unlock(periph);
1216 * If we can't free the sysctl tree, oh well...
1218 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0
1219 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
1220 xpt_print(periph->path, "can't remove sysctl context\n");
1223 disk_destroy(softc->disk);
1224 callout_drain(&softc->sendordered_c);
1225 free(softc, M_DEVBUF);
1226 cam_periph_lock(periph);
1230 daasync(void *callback_arg, u_int32_t code,
1231 struct cam_path *path, void *arg)
1233 struct cam_periph *periph;
1235 periph = (struct cam_periph *)callback_arg;
1237 case AC_FOUND_DEVICE:
1239 struct ccb_getdev *cgd;
1242 cgd = (struct ccb_getdev *)arg;
1246 if (cgd->protocol != PROTO_SCSI)
1249 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1250 && SID_TYPE(&cgd->inq_data) != T_RBC
1251 && SID_TYPE(&cgd->inq_data) != T_OPTICAL)
1255 * Allocate a peripheral instance for
1256 * this device and start the probe
1259 status = cam_periph_alloc(daregister, daoninvalidate,
1261 "da", CAM_PERIPH_BIO,
1262 cgd->ccb_h.path, daasync,
1263 AC_FOUND_DEVICE, cgd);
1265 if (status != CAM_REQ_CMP
1266 && status != CAM_REQ_INPROG)
1267 printf("daasync: Unable to attach to new device "
1268 "due to status 0x%x\n", status);
1274 struct da_softc *softc;
1275 struct ccb_hdr *ccbh;
1277 softc = (struct da_softc *)periph->softc;
1279 * Don't fail on the expected unit attention
1282 softc->flags |= DA_FLAG_RETRY_UA;
1283 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1284 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1288 cam_periph_async(periph, code, path, arg);
1294 dasysctlinit(void *context, int pending)
1296 struct cam_periph *periph;
1297 struct da_softc *softc;
1298 char tmpstr[80], tmpstr2[80];
1300 periph = (struct cam_periph *)context;
1302 * periph was held for us when this task was enqueued
1304 if (periph->flags & CAM_PERIPH_INVALID) {
1305 cam_periph_release(periph);
1309 softc = (struct da_softc *)periph->softc;
1310 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1311 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1313 sysctl_ctx_init(&softc->sysctl_ctx);
1314 softc->flags |= DA_FLAG_SCTX_INIT;
1315 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
1316 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1317 CTLFLAG_RD, 0, tmpstr);
1318 if (softc->sysctl_tree == NULL) {
1319 printf("dasysctlinit: unable to allocate sysctl tree\n");
1320 cam_periph_release(periph);
1325 * Now register the sysctl handler, so the user can the value on
1328 SYSCTL_ADD_PROC(&softc->sysctl_ctx,SYSCTL_CHILDREN(softc->sysctl_tree),
1329 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1330 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1331 "Minimum CDB size");
1333 cam_periph_release(periph);
1337 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
1341 value = *(int *)arg1;
1343 error = sysctl_handle_int(oidp, &value, 0, req);
1346 || (req->newptr == NULL))
1350 * Acceptable values here are 6, 10, 12 or 16.
1354 else if ((value > 6)
1357 else if ((value > 10)
1360 else if (value > 12)
1363 *(int *)arg1 = value;
1369 daregister(struct cam_periph *periph, void *arg)
1371 struct da_softc *softc;
1372 struct ccb_pathinq cpi;
1373 struct ccb_getdev *cgd;
1377 cgd = (struct ccb_getdev *)arg;
1378 if (periph == NULL) {
1379 printf("daregister: periph was NULL!!\n");
1380 return(CAM_REQ_CMP_ERR);
1384 printf("daregister: no getdev CCB, can't register device\n");
1385 return(CAM_REQ_CMP_ERR);
1388 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
1391 if (softc == NULL) {
1392 printf("daregister: Unable to probe new device. "
1393 "Unable to allocate softc\n");
1394 return(CAM_REQ_CMP_ERR);
1397 LIST_INIT(&softc->pending_ccbs);
1398 softc->state = DA_STATE_PROBE;
1399 bioq_init(&softc->bio_queue);
1400 if (SID_IS_REMOVABLE(&cgd->inq_data))
1401 softc->flags |= DA_FLAG_PACK_REMOVABLE;
1402 if ((cgd->inq_data.flags & SID_CmdQue) != 0)
1403 softc->flags |= DA_FLAG_TAGGED_QUEUING;
1405 periph->softc = softc;
1408 * See if this device has any quirks.
1410 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
1411 (caddr_t)da_quirk_table,
1412 sizeof(da_quirk_table)/sizeof(*da_quirk_table),
1413 sizeof(*da_quirk_table), scsi_inquiry_match);
1416 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
1418 softc->quirks = DA_Q_NONE;
1420 /* Check if the SIM does not want 6 byte commands */
1421 bzero(&cpi, sizeof(cpi));
1422 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1423 cpi.ccb_h.func_code = XPT_PATH_INQ;
1424 xpt_action((union ccb *)&cpi);
1425 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
1426 softc->quirks |= DA_Q_NO_6_BYTE;
1428 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
1431 * Add async callbacks for bus reset and
1432 * bus device reset calls. I don't bother
1433 * checking if this fails as, in most cases,
1434 * the system will function just fine without
1435 * them and the only alternative would be to
1436 * not attach the device on failure.
1438 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE,
1439 daasync, periph, periph->path);
1442 * Take an exclusive refcount on the periph while dastart is called
1443 * to finish the probe. The reference will be dropped in dadone at
1446 (void)cam_periph_hold(periph, PRIBIO);
1449 * Schedule a periodic event to occasionally send an
1450 * ordered tag to a device.
1452 callout_init_mtx(&softc->sendordered_c, periph->sim->mtx, 0);
1453 callout_reset(&softc->sendordered_c,
1454 (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL,
1455 dasendorderedtag, softc);
1457 mtx_unlock(periph->sim->mtx);
1459 * RBC devices don't have to support READ(6), only READ(10).
1461 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
1462 softc->minimum_cmd_size = 10;
1464 softc->minimum_cmd_size = 6;
1467 * Load the user's default, if any.
1469 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
1470 periph->unit_number);
1471 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
1474 * 6, 10, 12 and 16 are the currently permissible values.
1476 if (softc->minimum_cmd_size < 6)
1477 softc->minimum_cmd_size = 6;
1478 else if ((softc->minimum_cmd_size > 6)
1479 && (softc->minimum_cmd_size <= 10))
1480 softc->minimum_cmd_size = 10;
1481 else if ((softc->minimum_cmd_size > 10)
1482 && (softc->minimum_cmd_size <= 12))
1483 softc->minimum_cmd_size = 12;
1484 else if (softc->minimum_cmd_size > 12)
1485 softc->minimum_cmd_size = 16;
1488 * Register this media as a disk.
1490 softc->disk = disk_alloc();
1491 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
1492 periph->unit_number, 0,
1493 DEVSTAT_BS_UNAVAILABLE,
1494 SID_TYPE(&cgd->inq_data) |
1495 XPORT_DEVSTAT_TYPE(cpi.transport),
1496 DEVSTAT_PRIORITY_DISK);
1497 softc->disk->d_open = daopen;
1498 softc->disk->d_close = daclose;
1499 softc->disk->d_strategy = dastrategy;
1500 softc->disk->d_dump = dadump;
1501 softc->disk->d_name = "da";
1502 softc->disk->d_drv1 = periph;
1504 softc->disk->d_maxsize = DFLTPHYS; /* traditional default */
1505 else if (cpi.maxio > MAXPHYS)
1506 softc->disk->d_maxsize = MAXPHYS; /* for safety */
1508 softc->disk->d_maxsize = cpi.maxio;
1509 softc->disk->d_unit = periph->unit_number;
1510 softc->disk->d_flags = 0;
1511 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
1512 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
1513 strlcpy(softc->disk->d_ident, cgd->serial_num,
1514 MIN(sizeof(softc->disk->d_ident), cgd->serial_num_len + 1));
1515 disk_create(softc->disk, DISK_VERSION);
1516 mtx_lock(periph->sim->mtx);
1518 xpt_schedule(periph, CAM_PRIORITY_DEV);
1520 return(CAM_REQ_CMP);
1524 dastart(struct cam_periph *periph, union ccb *start_ccb)
1526 struct da_softc *softc;
1528 softc = (struct da_softc *)periph->softc;
1530 switch (softc->state) {
1531 case DA_STATE_NORMAL:
1533 /* Pull a buffer from the queue and get going on it */
1537 * See if there is a buf with work for us to do..
1539 bp = bioq_first(&softc->bio_queue);
1540 if (periph->immediate_priority <= periph->pinfo.priority) {
1541 CAM_DEBUG_PRINT(CAM_DEBUG_SUBTRACE,
1542 ("queuing for immediate ccb\n"));
1543 start_ccb->ccb_h.ccb_state = DA_CCB_WAITING;
1544 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
1546 periph->immediate_priority = CAM_PRIORITY_NONE;
1547 wakeup(&periph->ccb_list);
1548 } else if (bp == NULL) {
1549 xpt_release_ccb(start_ccb);
1553 bioq_remove(&softc->bio_queue, bp);
1555 if ((bp->bio_flags & BIO_ORDERED) != 0
1556 || (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
1557 softc->flags &= ~DA_FLAG_NEED_OTAG;
1558 softc->ordered_tag_count++;
1559 tag_code = MSG_ORDERED_Q_TAG;
1561 tag_code = MSG_SIMPLE_Q_TAG;
1563 switch (bp->bio_cmd) {
1566 scsi_read_write(&start_ccb->csio,
1567 /*retries*/da_retry_count,
1569 /*tag_action*/tag_code,
1570 /*read_op*/bp->bio_cmd
1573 softc->minimum_cmd_size,
1574 /*lba*/bp->bio_pblkno,
1575 /*block_count*/bp->bio_bcount /
1576 softc->params.secsize,
1577 /*data_ptr*/ bp->bio_data,
1578 /*dxfer_len*/ bp->bio_bcount,
1579 /*sense_len*/SSD_FULL_SIZE,
1580 da_default_timeout * 1000);
1584 * BIO_FLUSH doesn't currently communicate
1585 * range data, so we synchronize the cache
1586 * over the whole disk. We also force
1587 * ordered tag semantics the flush applies
1588 * to all previously queued I/O.
1590 scsi_synchronize_cache(&start_ccb->csio,
1597 da_default_timeout*1000);
1600 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
1603 * Block out any asyncronous callbacks
1604 * while we touch the pending ccb list.
1606 LIST_INSERT_HEAD(&softc->pending_ccbs,
1607 &start_ccb->ccb_h, periph_links.le);
1608 softc->outstanding_cmds++;
1610 /* We expect a unit attention from this device */
1611 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
1612 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
1613 softc->flags &= ~DA_FLAG_RETRY_UA;
1616 start_ccb->ccb_h.ccb_bp = bp;
1617 bp = bioq_first(&softc->bio_queue);
1619 xpt_action(start_ccb);
1623 /* Have more work to do, so ensure we stay scheduled */
1624 xpt_schedule(periph, CAM_PRIORITY_NORMAL);
1628 case DA_STATE_PROBE:
1630 struct ccb_scsiio *csio;
1631 struct scsi_read_capacity_data *rcap;
1633 rcap = (struct scsi_read_capacity_data *)
1634 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
1636 printf("dastart: Couldn't malloc read_capacity data\n");
1637 /* da_free_periph??? */
1640 csio = &start_ccb->csio;
1641 scsi_read_capacity(csio,
1648 start_ccb->ccb_h.ccb_bp = NULL;
1649 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE;
1650 xpt_action(start_ccb);
1653 case DA_STATE_PROBE2:
1655 struct ccb_scsiio *csio;
1656 struct scsi_read_capacity_data_long *rcaplong;
1658 rcaplong = (struct scsi_read_capacity_data_long *)
1659 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
1660 if (rcaplong == NULL) {
1661 printf("dastart: Couldn't malloc read_capacity data\n");
1662 /* da_free_periph??? */
1665 csio = &start_ccb->csio;
1666 scsi_read_capacity_16(csio,
1669 /*tag_action*/ MSG_SIMPLE_Q_TAG,
1674 /*sense_len*/ SSD_FULL_SIZE,
1676 start_ccb->ccb_h.ccb_bp = NULL;
1677 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE2;
1678 xpt_action(start_ccb);
1685 cmd6workaround(union ccb *ccb)
1687 struct scsi_rw_6 cmd6;
1688 struct scsi_rw_10 *cmd10;
1689 struct da_softc *softc;
1693 cdb = ccb->csio.cdb_io.cdb_bytes;
1695 /* Translation only possible if CDB is an array and cmd is R/W6 */
1696 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
1697 (*cdb != READ_6 && *cdb != WRITE_6))
1700 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
1701 "increasing minimum_cmd_size to 10.\n");
1702 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
1703 softc->minimum_cmd_size = 10;
1705 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
1706 cmd10 = (struct scsi_rw_10 *)cdb;
1707 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
1709 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
1710 cmd10->reserved = 0;
1711 scsi_ulto2b(cmd6.length, cmd10->length);
1712 cmd10->control = cmd6.control;
1713 ccb->csio.cdb_len = sizeof(*cmd10);
1715 /* Requeue request, unfreezing queue if necessary */
1716 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
1717 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1720 cam_release_devq(ccb->ccb_h.path,
1724 /*getcount_only*/0);
1730 dadone(struct cam_periph *periph, union ccb *done_ccb)
1732 struct da_softc *softc;
1733 struct ccb_scsiio *csio;
1736 softc = (struct da_softc *)periph->softc;
1737 priority = done_ccb->ccb_h.pinfo.priority;
1738 csio = &done_ccb->csio;
1739 switch (csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK) {
1740 case DA_CCB_BUFFER_IO:
1744 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
1745 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1749 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
1754 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
1755 if (error == ERESTART) {
1757 * A retry was scheuled, so
1764 if (error == ENXIO) {
1766 * Catastrophic error. Mark our pack as
1770 * XXX See if this is really a media
1773 xpt_print(periph->path,
1774 "Invalidating pack\n");
1775 softc->flags |= DA_FLAG_PACK_INVALID;
1779 * return all queued I/O with EIO, so that
1780 * the client can retry these I/Os in the
1781 * proper order should it attempt to recover.
1783 bioq_flush(&softc->bio_queue, NULL, EIO);
1784 bp->bio_error = error;
1785 bp->bio_resid = bp->bio_bcount;
1786 bp->bio_flags |= BIO_ERROR;
1788 bp->bio_resid = csio->resid;
1790 if (bp->bio_resid != 0)
1791 bp->bio_flags |= BIO_ERROR;
1793 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1794 cam_release_devq(done_ccb->ccb_h.path,
1798 /*getcount_only*/0);
1800 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1801 panic("REQ_CMP with QFRZN");
1802 bp->bio_resid = csio->resid;
1803 if (csio->resid > 0)
1804 bp->bio_flags |= BIO_ERROR;
1805 if (softc->error_inject != 0) {
1806 bp->bio_error = softc->error_inject;
1807 bp->bio_resid = bp->bio_bcount;
1808 bp->bio_flags |= BIO_ERROR;
1809 softc->error_inject = 0;
1815 * Block out any asyncronous callbacks
1816 * while we touch the pending ccb list.
1818 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
1819 softc->outstanding_cmds--;
1820 if (softc->outstanding_cmds == 0)
1821 softc->flags |= DA_FLAG_WENT_IDLE;
1829 struct scsi_read_capacity_data *rdcap;
1830 struct scsi_read_capacity_data_long *rcaplong;
1831 char announce_buf[80];
1835 if (softc->state == DA_STATE_PROBE)
1836 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
1838 rcaplong = (struct scsi_read_capacity_data_long *)
1841 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1842 struct disk_params *dp;
1843 uint32_t block_size;
1846 if (softc->state == DA_STATE_PROBE) {
1847 block_size = scsi_4btoul(rdcap->length);
1848 maxsector = scsi_4btoul(rdcap->addr);
1851 * According to SBC-2, if the standard 10
1852 * byte READ CAPACITY command returns 2^32,
1853 * we should issue the 16 byte version of
1854 * the command, since the device in question
1855 * has more sectors than can be represented
1856 * with the short version of the command.
1858 if (maxsector == 0xffffffff) {
1859 softc->state = DA_STATE_PROBE2;
1860 free(rdcap, M_SCSIDA);
1861 xpt_release_ccb(done_ccb);
1862 xpt_schedule(periph, priority);
1866 block_size = scsi_4btoul(rcaplong->length);
1867 maxsector = scsi_8btou64(rcaplong->addr);
1871 * Because GEOM code just will panic us if we
1872 * give them an 'illegal' value we'll avoid that
1875 if (block_size == 0 && maxsector == 0) {
1876 snprintf(announce_buf, sizeof(announce_buf),
1878 } else if (block_size >= MAXPHYS || block_size == 0) {
1879 xpt_print(periph->path,
1880 "unsupportable block size %ju\n",
1881 (uintmax_t) block_size);
1882 announce_buf[0] = '\0';
1883 cam_periph_invalidate(periph);
1885 dasetgeom(periph, block_size, maxsector, 0, 0);
1886 dp = &softc->params;
1887 snprintf(announce_buf, sizeof(announce_buf),
1888 "%juMB (%ju %u byte sectors: %dH %dS/T "
1890 (((uintmax_t)dp->secsize *
1891 dp->sectors) / (1024*1024)),
1892 (uintmax_t)dp->sectors,
1893 dp->secsize, dp->heads,
1894 dp->secs_per_track, dp->cylinders);
1899 announce_buf[0] = '\0';
1902 * Retry any UNIT ATTENTION type errors. They
1903 * are expected at boot.
1905 error = daerror(done_ccb, CAM_RETRY_SELTO,
1906 SF_RETRY_UA|SF_NO_PRINT);
1907 if (error == ERESTART) {
1909 * A retry was scheuled, so
1913 } else if (error != 0) {
1914 struct scsi_sense_data *sense;
1916 int sense_key, error_code;
1919 struct ccb_getdev cgd;
1921 /* Don't wedge this device's queue */
1922 status = done_ccb->ccb_h.status;
1923 if ((status & CAM_DEV_QFRZN) != 0)
1924 cam_release_devq(done_ccb->ccb_h.path,
1928 /*getcount_only*/0);
1931 xpt_setup_ccb(&cgd.ccb_h,
1932 done_ccb->ccb_h.path,
1933 CAM_PRIORITY_NORMAL);
1934 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
1935 xpt_action((union ccb *)&cgd);
1937 if (((csio->ccb_h.flags & CAM_SENSE_PHYS) != 0)
1938 || ((csio->ccb_h.flags & CAM_SENSE_PTR) != 0)
1939 || ((status & CAM_AUTOSNS_VALID) == 0))
1945 sense = &csio->sense_data;
1946 scsi_extract_sense(sense, &error_code,
1951 * Attach to anything that claims to be a
1952 * direct access or optical disk device,
1953 * as long as it doesn't return a "Logical
1954 * unit not supported" (0x25) error.
1956 if ((have_sense) && (asc != 0x25)
1957 && (error_code == SSD_CURRENT_ERROR)) {
1958 const char *sense_key_desc;
1959 const char *asc_desc;
1961 scsi_sense_desc(sense_key, asc, ascq,
1965 snprintf(announce_buf,
1966 sizeof(announce_buf),
1967 "Attempt to query device "
1968 "size failed: %s, %s",
1976 xpt_print(periph->path,
1977 "got CAM status %#x\n",
1978 done_ccb->ccb_h.status);
1981 xpt_print(periph->path, "fatal error, "
1982 "failed to attach to device\n");
1985 * Free up resources.
1987 cam_periph_invalidate(periph);
1991 free(csio->data_ptr, M_SCSIDA);
1992 if (announce_buf[0] != '\0') {
1994 * Create our sysctl variables, now that we know
1995 * we have successfully attached.
1997 /* increase the refcount */
1998 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1999 taskqueue_enqueue(taskqueue_thread,
2000 &softc->sysctl_task);
2001 xpt_announce_periph(periph, announce_buf);
2003 xpt_print(periph->path, "fatal error, "
2004 "could not acquire reference count\n");
2008 softc->state = DA_STATE_NORMAL;
2010 * Since our peripheral may be invalidated by an error
2011 * above or an external event, we must release our CCB
2012 * before releasing the probe lock on the peripheral.
2013 * The peripheral will only go away once the last lock
2014 * is removed, and we need it around for the CCB release
2017 xpt_release_ccb(done_ccb);
2018 cam_periph_unhold(periph);
2021 case DA_CCB_WAITING:
2023 /* Caller will release the CCB */
2024 wakeup(&done_ccb->ccb_h.cbfcnp);
2028 /* No-op. We're polling */
2033 xpt_release_ccb(done_ccb);
2037 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
2039 struct da_softc *softc;
2040 struct cam_periph *periph;
2043 periph = xpt_path_periph(ccb->ccb_h.path);
2044 softc = (struct da_softc *)periph->softc;
2047 * Automatically detect devices that do not support
2048 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
2051 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
2052 error = cmd6workaround(ccb);
2053 } else if (((ccb->ccb_h.status & CAM_STATUS_MASK) ==
2054 CAM_SCSI_STATUS_ERROR)
2055 && (ccb->ccb_h.status & CAM_AUTOSNS_VALID)
2056 && (ccb->csio.scsi_status == SCSI_STATUS_CHECK_COND)
2057 && ((ccb->ccb_h.flags & CAM_SENSE_PHYS) == 0)
2058 && ((ccb->ccb_h.flags & CAM_SENSE_PTR) == 0)) {
2059 int sense_key, error_code, asc, ascq;
2061 scsi_extract_sense(&ccb->csio.sense_data,
2062 &error_code, &sense_key, &asc, &ascq);
2063 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
2064 error = cmd6workaround(ccb);
2066 if (error == ERESTART)
2071 * Until we have a better way of doing pack validation,
2072 * don't treat UAs as errors.
2074 sense_flags |= SF_RETRY_UA;
2075 return(cam_periph_error(ccb, cam_flags, sense_flags,
2076 &softc->saved_ccb));
2080 daprevent(struct cam_periph *periph, int action)
2082 struct da_softc *softc;
2086 softc = (struct da_softc *)periph->softc;
2088 if (((action == PR_ALLOW)
2089 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
2090 || ((action == PR_PREVENT)
2091 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
2095 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
2097 scsi_prevent(&ccb->csio,
2105 error = cam_periph_runccb(ccb, /*error_routine*/NULL, CAM_RETRY_SELTO,
2106 SF_RETRY_UA, softc->disk->d_devstat);
2109 if (action == PR_ALLOW)
2110 softc->flags &= ~DA_FLAG_PACK_LOCKED;
2112 softc->flags |= DA_FLAG_PACK_LOCKED;
2115 xpt_release_ccb(ccb);
2119 dagetcapacity(struct cam_periph *periph)
2121 struct da_softc *softc;
2123 struct scsi_read_capacity_data *rcap;
2124 struct scsi_read_capacity_data_long *rcaplong;
2128 u_int32_t sense_flags;
2130 softc = (struct da_softc *)periph->softc;
2134 sense_flags = SF_RETRY_UA;
2135 if (softc->flags & DA_FLAG_PACK_REMOVABLE)
2136 sense_flags |= SF_NO_PRINT;
2138 /* Do a read capacity */
2139 rcap = (struct scsi_read_capacity_data *)malloc(sizeof(*rcaplong),
2145 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
2146 scsi_read_capacity(&ccb->csio,
2153 ccb->ccb_h.ccb_bp = NULL;
2155 error = cam_periph_runccb(ccb, daerror,
2156 /*cam_flags*/CAM_RETRY_SELTO,
2158 softc->disk->d_devstat);
2160 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2161 cam_release_devq(ccb->ccb_h.path,
2165 /*getcount_only*/0);
2168 block_len = scsi_4btoul(rcap->length);
2169 maxsector = scsi_4btoul(rcap->addr);
2171 if (maxsector != 0xffffffff)
2176 rcaplong = (struct scsi_read_capacity_data_long *)rcap;
2178 scsi_read_capacity_16(&ccb->csio,
2181 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2186 /*sense_len*/ SSD_FULL_SIZE,
2188 ccb->ccb_h.ccb_bp = NULL;
2190 error = cam_periph_runccb(ccb, daerror,
2191 /*cam_flags*/CAM_RETRY_SELTO,
2193 softc->disk->d_devstat);
2195 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2196 cam_release_devq(ccb->ccb_h.path,
2200 /*getcount_only*/0);
2203 block_len = scsi_4btoul(rcaplong->length);
2204 maxsector = scsi_8btou64(rcaplong->addr);
2210 if (block_len >= MAXPHYS || block_len == 0) {
2211 xpt_print(periph->path,
2212 "unsupportable block size %ju\n",
2213 (uintmax_t) block_len);
2216 dasetgeom(periph, block_len, maxsector, 0, 0);
2219 xpt_release_ccb(ccb);
2221 free(rcap, M_SCSIDA);
2227 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
2228 u_int lbppbe, u_int lalba)
2230 struct ccb_calc_geometry ccg;
2231 struct da_softc *softc;
2232 struct disk_params *dp;
2234 softc = (struct da_softc *)periph->softc;
2236 dp = &softc->params;
2237 dp->secsize = block_len;
2238 dp->sectors = maxsector + 1;
2240 dp->stripesize = block_len << lbppbe;
2241 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
2243 } else if (softc->quirks & DA_Q_4K) {
2244 dp->stripesize = 4096;
2245 dp->stripeoffset = 0;
2248 dp->stripeoffset = 0;
2251 * Have the controller provide us with a geometry
2252 * for this disk. The only time the geometry
2253 * matters is when we boot and the controller
2254 * is the only one knowledgeable enough to come
2255 * up with something that will make this a bootable
2258 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2259 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
2260 ccg.block_size = dp->secsize;
2261 ccg.volume_size = dp->sectors;
2263 ccg.secs_per_track = 0;
2265 xpt_action((union ccb*)&ccg);
2266 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2268 * We don't know what went wrong here- but just pick
2269 * a geometry so we don't have nasty things like divide
2273 dp->secs_per_track = 255;
2274 dp->cylinders = dp->sectors / (255 * 255);
2275 if (dp->cylinders == 0) {
2279 dp->heads = ccg.heads;
2280 dp->secs_per_track = ccg.secs_per_track;
2281 dp->cylinders = ccg.cylinders;
2286 dasendorderedtag(void *arg)
2288 struct da_softc *softc = arg;
2290 if (da_send_ordered) {
2291 if ((softc->ordered_tag_count == 0)
2292 && ((softc->flags & DA_FLAG_WENT_IDLE) == 0)) {
2293 softc->flags |= DA_FLAG_NEED_OTAG;
2295 if (softc->outstanding_cmds > 0)
2296 softc->flags &= ~DA_FLAG_WENT_IDLE;
2298 softc->ordered_tag_count = 0;
2300 /* Queue us up again */
2301 callout_reset(&softc->sendordered_c,
2302 (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL,
2303 dasendorderedtag, softc);
2307 * Step through all DA peripheral drivers, and if the device is still open,
2308 * sync the disk cache to physical media.
2311 dashutdown(void * arg, int howto)
2313 struct cam_periph *periph;
2314 struct da_softc *softc;
2316 TAILQ_FOREACH(periph, &dadriver.units, unit_links) {
2319 cam_periph_lock(periph);
2320 softc = (struct da_softc *)periph->softc;
2323 * We only sync the cache if the drive is still open, and
2324 * if the drive is capable of it..
2326 if (((softc->flags & DA_FLAG_OPEN) == 0)
2327 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
2328 cam_periph_unlock(periph);
2332 xpt_setup_ccb(&ccb.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2334 ccb.ccb_h.ccb_state = DA_CCB_DUMP;
2335 scsi_synchronize_cache(&ccb.csio,
2339 /*begin_lba*/0, /* whole disk */
2344 xpt_polled_action(&ccb);
2346 if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2347 if (((ccb.ccb_h.status & CAM_STATUS_MASK) ==
2348 CAM_SCSI_STATUS_ERROR)
2349 && (ccb.csio.scsi_status == SCSI_STATUS_CHECK_COND)){
2350 int error_code, sense_key, asc, ascq;
2352 scsi_extract_sense(&ccb.csio.sense_data,
2353 &error_code, &sense_key,
2356 if (sense_key != SSD_KEY_ILLEGAL_REQUEST)
2357 scsi_sense_print(&ccb.csio);
2359 xpt_print(periph->path, "Synchronize "
2360 "cache failed, status == 0x%x, scsi status "
2361 "== 0x%x\n", ccb.ccb_h.status,
2362 ccb.csio.scsi_status);
2366 if ((ccb.ccb_h.status & CAM_DEV_QFRZN) != 0)
2367 cam_release_devq(ccb.ccb_h.path,
2371 /*getcount_only*/0);
2372 cam_periph_unlock(periph);
2376 #else /* !_KERNEL */
2379 * XXX This is only left out of the kernel build to silence warnings. If,
2380 * for some reason this function is used in the kernel, the ifdefs should
2381 * be moved so it is included both in the kernel and userland.
2384 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
2385 void (*cbfcnp)(struct cam_periph *, union ccb *),
2386 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
2387 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
2390 struct scsi_format_unit *scsi_cmd;
2392 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
2393 scsi_cmd->opcode = FORMAT_UNIT;
2394 scsi_cmd->byte2 = byte2;
2395 scsi_ulto2b(ileave, scsi_cmd->interleave);
2400 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
2409 #endif /* _KERNEL */