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.h>
48 #include <geom/geom_disk.h>
57 #include <cam/cam_ccb.h>
58 #include <cam/cam_periph.h>
59 #include <cam/cam_xpt_periph.h>
60 #include <cam/cam_sim.h>
62 #include <cam/scsi/scsi_message.h>
65 #include <cam/scsi/scsi_da.h>
76 DA_FLAG_PACK_INVALID = 0x001,
77 DA_FLAG_NEW_PACK = 0x002,
78 DA_FLAG_PACK_LOCKED = 0x004,
79 DA_FLAG_PACK_REMOVABLE = 0x008,
80 DA_FLAG_TAGGED_QUEUING = 0x010,
81 DA_FLAG_NEED_OTAG = 0x020,
82 DA_FLAG_WENT_IDLE = 0x040,
83 DA_FLAG_RETRY_UA = 0x080,
85 DA_FLAG_SCTX_INIT = 0x200
90 DA_Q_NO_SYNC_CACHE = 0x01,
91 DA_Q_NO_6_BYTE = 0x02,
92 DA_Q_NO_PREVENT = 0x04,
99 DA_CCB_BUFFER_IO = 0x03,
100 DA_CCB_WAITING = 0x04,
102 DA_CCB_TYPE_MASK = 0x0F,
103 DA_CCB_RETRY_UA = 0x10
106 /* Offsets into our private area for storing information */
107 #define ccb_state ppriv_field0
108 #define ccb_bp ppriv_ptr1
113 u_int8_t secs_per_track;
114 u_int32_t secsize; /* Number of bytes/sector */
115 u_int64_t sectors; /* total number sectors */
121 struct bio_queue_head bio_queue;
122 SLIST_ENTRY(da_softc) links;
123 LIST_HEAD(, ccb_hdr) pending_ccbs;
127 int minimum_cmd_size;
129 int ordered_tag_count;
130 int outstanding_cmds;
131 struct disk_params params;
134 struct task sysctl_task;
135 struct sysctl_ctx_list sysctl_ctx;
136 struct sysctl_oid *sysctl_tree;
137 struct callout sendordered_c;
141 struct da_quirk_entry {
142 struct scsi_inquiry_pattern inq_pat;
146 static const char quantum[] = "QUANTUM";
147 static const char microp[] = "MICROP";
149 static struct da_quirk_entry da_quirk_table[] =
151 /* SPI, FC devices */
154 * Fujitsu M2513A MO drives.
155 * Tested devices: M2513A2 firmware versions 1200 & 1300.
156 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
157 * Reported by: W.Scholten <whs@xs4all.nl>
159 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
160 /*quirks*/ DA_Q_NO_SYNC_CACHE
164 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
165 /*quirks*/ DA_Q_NO_SYNC_CACHE
169 * This particular Fujitsu drive doesn't like the
170 * synchronize cache command.
171 * Reported by: Tom Jackson <toj@gorilla.net>
173 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
174 /*quirks*/ DA_Q_NO_SYNC_CACHE
178 * This drive doesn't like the synchronize cache command
179 * either. Reported by: Matthew Jacob <mjacob@feral.com>
180 * in NetBSD PR kern/6027, August 24, 1998.
182 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
183 /*quirks*/ DA_Q_NO_SYNC_CACHE
187 * This drive doesn't like the synchronize cache command
188 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
191 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
192 /*quirks*/ DA_Q_NO_SYNC_CACHE
196 * Doesn't like the synchronize cache command.
197 * Reported by: Blaz Zupan <blaz@gold.amis.net>
199 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
200 /*quirks*/ DA_Q_NO_SYNC_CACHE
204 * Doesn't like the synchronize cache command.
205 * Reported by: Blaz Zupan <blaz@gold.amis.net>
207 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
208 /*quirks*/ DA_Q_NO_SYNC_CACHE
212 * Doesn't like the synchronize cache command.
214 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
215 /*quirks*/ DA_Q_NO_SYNC_CACHE
219 * Doesn't like the synchronize cache command.
220 * Reported by: walter@pelissero.de
222 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
223 /*quirks*/ DA_Q_NO_SYNC_CACHE
227 * Doesn't work correctly with 6 byte reads/writes.
228 * Returns illegal request, and points to byte 9 of the
230 * Reported by: Adam McDougall <bsdx@spawnet.com>
232 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
233 /*quirks*/ DA_Q_NO_6_BYTE
237 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
238 /*quirks*/ DA_Q_NO_6_BYTE
242 * Doesn't like the synchronize cache command.
243 * Reported by: walter@pelissero.de
245 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
246 /*quirks*/ DA_Q_NO_SYNC_CACHE
250 * The CISS RAID controllers do not support SYNC_CACHE
252 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
253 /*quirks*/ DA_Q_NO_SYNC_CACHE
255 /* USB mass storage devices supported by umass(4) */
258 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
261 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
262 /*quirks*/ DA_Q_NO_SYNC_CACHE
266 * Power Quotient Int. (PQI) USB flash key
269 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
270 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
274 * Creative Nomad MUVO mp3 player (USB)
277 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
278 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
282 * Jungsoft NEXDISK USB flash key
285 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
286 /*quirks*/ DA_Q_NO_SYNC_CACHE
290 * FreeDik USB Mini Data Drive
293 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
294 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
298 * Sigmatel USB Flash MP3 Player
301 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
302 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
306 * Neuros USB Digital Audio Computer
309 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
310 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
314 * SEAGRAND NP-900 MP3 Player
317 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
318 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
322 * iRiver iFP MP3 player (with UMS Firmware)
323 * PR: kern/54881, i386/63941, kern/66124
325 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
326 /*quirks*/ DA_Q_NO_SYNC_CACHE
330 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
333 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
334 /*quirks*/ DA_Q_NO_SYNC_CACHE
338 * ZICPlay USB MP3 Player with FM
341 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
342 /*quirks*/ DA_Q_NO_SYNC_CACHE
346 * TEAC USB floppy mechanisms
348 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
349 /*quirks*/ DA_Q_NO_SYNC_CACHE
353 * Kingston DataTraveler II+ USB Pen-Drive.
354 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
356 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
357 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
361 * Motorola E398 Mobile Phone (TransFlash memory card).
362 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
365 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
366 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
370 * Qware BeatZkey! Pro
373 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
374 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
378 * Time DPA20B 1GB MP3 Player
381 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
382 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
386 * Samsung USB key 128Mb
389 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
390 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
394 * Kingston DataTraveler 2.0 USB Flash memory.
397 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
398 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
402 * Creative MUVO Slim mp3 player (USB)
405 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
406 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
410 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
413 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
414 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
418 * SanDisk Micro Cruzer 128MB
421 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
422 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
426 * TOSHIBA TransMemory USB sticks
429 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
430 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
435 * PR: usb/75578, usb/72344, usb/65436
437 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
438 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
442 * Genesys 6-in-1 Card Reader
445 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
446 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
450 * Rekam Digital CAMERA
453 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
454 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
458 * iRiver H10 MP3 player
461 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
462 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
466 * iRiver U10 MP3 player
469 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
470 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
477 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
478 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
482 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
485 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
486 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
493 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
494 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
498 * Philips USB Key Audio KEY013
501 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
502 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
509 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
510 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
517 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
518 /*quirks*/ DA_Q_NO_SYNC_CACHE
522 * I/O Magic USB flash - Giga Bank
525 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
526 /*quirks*/ DA_Q_NO_SYNC_CACHE
530 * JoyFly 128mb USB Flash Drive
533 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
534 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
541 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
542 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
546 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
549 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
550 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
554 * Samsung YP-U3 mp3-player
557 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
558 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
561 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
562 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
566 * Sony Cyber-Shot DSC cameras
569 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
570 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
572 /* ATA/SATA devices over SAS/USB/... */
574 /* Hitachi Advanced Format (4k) drives */
575 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
579 /* Samsung Advanced Format (4k) drives */
580 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
584 /* Samsung Advanced Format (4k) drives */
585 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
589 /* Samsung Advanced Format (4k) drives */
590 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
594 /* Samsung Advanced Format (4k) drives */
595 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
599 /* Seagate Barracuda Green Advanced Format (4k) drives */
600 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
604 /* Seagate Barracuda Green Advanced Format (4k) drives */
605 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
609 /* Seagate Barracuda Green Advanced Format (4k) drives */
610 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
614 /* Seagate Barracuda Green Advanced Format (4k) drives */
615 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
619 /* Seagate Barracuda Green Advanced Format (4k) drives */
620 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
624 /* Seagate Barracuda Green Advanced Format (4k) drives */
625 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
629 /* Seagate Momentus Advanced Format (4k) drives */
630 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
634 /* Seagate Momentus Advanced Format (4k) drives */
635 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
639 /* Seagate Momentus Advanced Format (4k) drives */
640 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
644 /* Seagate Momentus Advanced Format (4k) drives */
645 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
649 /* Seagate Momentus Advanced Format (4k) drives */
650 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
654 /* Seagate Momentus Advanced Format (4k) drives */
655 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
659 /* Seagate Momentus Advanced Format (4k) drives */
660 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
664 /* Seagate Momentus Advanced Format (4k) drives */
665 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
669 /* Seagate Momentus Advanced Format (4k) drives */
670 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
674 /* Seagate Momentus Advanced Format (4k) drives */
675 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
679 /* Seagate Momentus Advanced Format (4k) drives */
680 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
684 /* Seagate Momentus Advanced Format (4k) drives */
685 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
689 /* Seagate Momentus Advanced Format (4k) drives */
690 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
694 /* Seagate Momentus Advanced Format (4k) drives */
695 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
699 /* Seagate Momentus Thin Advanced Format (4k) drives */
700 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
704 /* Seagate Momentus Thin Advanced Format (4k) drives */
705 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
709 /* WDC Caviar Green Advanced Format (4k) drives */
710 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
714 /* WDC Caviar Green Advanced Format (4k) drives */
715 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
719 /* WDC Caviar Green Advanced Format (4k) drives */
720 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
724 /* WDC Caviar Green Advanced Format (4k) drives */
725 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
729 /* WDC Caviar Green Advanced Format (4k) drives */
730 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
734 /* WDC Caviar Green Advanced Format (4k) drives */
735 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
739 /* WDC Caviar Green Advanced Format (4k) drives */
740 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
744 /* WDC Caviar Green Advanced Format (4k) drives */
745 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
749 /* WDC Scorpio Black Advanced Format (4k) drives */
750 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
754 /* WDC Scorpio Black Advanced Format (4k) drives */
755 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
759 /* WDC Scorpio Black Advanced Format (4k) drives */
760 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
764 /* WDC Scorpio Black Advanced Format (4k) drives */
765 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
769 /* WDC Scorpio Blue Advanced Format (4k) drives */
770 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
774 /* WDC Scorpio Blue Advanced Format (4k) drives */
775 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
779 /* WDC Scorpio Blue Advanced Format (4k) drives */
780 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
784 /* WDC Scorpio Blue Advanced Format (4k) drives */
785 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
790 static disk_strategy_t dastrategy;
791 static dumper_t dadump;
792 static periph_init_t dainit;
793 static void daasync(void *callback_arg, u_int32_t code,
794 struct cam_path *path, void *arg);
795 static void dasysctlinit(void *context, int pending);
796 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
797 static periph_ctor_t daregister;
798 static periph_dtor_t dacleanup;
799 static periph_start_t dastart;
800 static periph_oninv_t daoninvalidate;
801 static void dadone(struct cam_periph *periph,
802 union ccb *done_ccb);
803 static int daerror(union ccb *ccb, u_int32_t cam_flags,
804 u_int32_t sense_flags);
805 static void daprevent(struct cam_periph *periph, int action);
806 static int dagetcapacity(struct cam_periph *periph);
807 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
808 uint64_t maxsector, u_int lbppbe, u_int lalba);
809 static timeout_t dasendorderedtag;
810 static void dashutdown(void *arg, int howto);
812 #ifndef DA_DEFAULT_TIMEOUT
813 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
816 #ifndef DA_DEFAULT_RETRY
817 #define DA_DEFAULT_RETRY 4
820 #ifndef DA_DEFAULT_SEND_ORDERED
821 #define DA_DEFAULT_SEND_ORDERED 1
825 static int da_retry_count = DA_DEFAULT_RETRY;
826 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
827 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
829 SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
830 "CAM Direct Access Disk driver");
831 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RW,
832 &da_retry_count, 0, "Normal I/O retry count");
833 TUNABLE_INT("kern.cam.da.retry_count", &da_retry_count);
834 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RW,
835 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
836 TUNABLE_INT("kern.cam.da.default_timeout", &da_default_timeout);
837 SYSCTL_INT(_kern_cam_da, OID_AUTO, da_send_ordered, CTLFLAG_RW,
838 &da_send_ordered, 0, "Send Ordered Tags");
839 TUNABLE_INT("kern.cam.da.da_send_ordered", &da_send_ordered);
842 * DA_ORDEREDTAG_INTERVAL determines how often, relative
843 * to the default timeout, we check to see whether an ordered
844 * tagged transaction is appropriate to prevent simple tag
845 * starvation. Since we'd like to ensure that there is at least
846 * 1/2 of the timeout length left for a starved transaction to
847 * complete after we've sent an ordered tag, we must poll at least
848 * four times in every timeout period. This takes care of the worst
849 * case where a starved transaction starts during an interval that
850 * meets the requirement "don't send an ordered tag" test so it takes
851 * us two intervals to determine that a tag must be sent.
853 #ifndef DA_ORDEREDTAG_INTERVAL
854 #define DA_ORDEREDTAG_INTERVAL 4
857 static struct periph_driver dadriver =
860 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
863 PERIPHDRIVER_DECLARE(da, dadriver);
865 MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
868 daopen(struct disk *dp)
870 struct cam_periph *periph;
871 struct da_softc *softc;
875 periph = (struct cam_periph *)dp->d_drv1;
876 if (periph == NULL) {
880 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
884 cam_periph_lock(periph);
885 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
886 cam_periph_unlock(periph);
887 cam_periph_release(periph);
891 unit = periph->unit_number;
892 softc = (struct da_softc *)periph->softc;
893 softc->flags |= DA_FLAG_OPEN;
895 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
896 ("daopen: disk=%s%d (unit %d)\n", dp->d_name, dp->d_unit,
899 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
900 /* Invalidate our pack information. */
901 softc->flags &= ~DA_FLAG_PACK_INVALID;
904 error = dagetcapacity(periph);
908 softc->disk->d_sectorsize = softc->params.secsize;
909 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
910 softc->disk->d_stripesize = softc->params.stripesize;
911 softc->disk->d_stripeoffset = softc->params.stripeoffset;
912 /* XXX: these are not actually "firmware" values, so they may be wrong */
913 softc->disk->d_fwsectors = softc->params.secs_per_track;
914 softc->disk->d_fwheads = softc->params.heads;
915 softc->disk->d_devstat->block_size = softc->params.secsize;
916 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
918 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
919 (softc->quirks & DA_Q_NO_PREVENT) == 0)
920 daprevent(periph, PR_PREVENT);
922 softc->flags &= ~DA_FLAG_OPEN;
924 cam_periph_unhold(periph);
925 cam_periph_unlock(periph);
928 cam_periph_release(periph);
934 daclose(struct disk *dp)
936 struct cam_periph *periph;
937 struct da_softc *softc;
940 periph = (struct cam_periph *)dp->d_drv1;
944 cam_periph_lock(periph);
945 if ((error = cam_periph_hold(periph, PRIBIO)) != 0) {
946 cam_periph_unlock(periph);
947 cam_periph_release(periph);
951 softc = (struct da_softc *)periph->softc;
953 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0
954 && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
957 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
959 scsi_synchronize_cache(&ccb->csio,
963 /*begin_lba*/0,/* Cover the whole disk */
968 cam_periph_runccb(ccb, /*error_routine*/NULL, /*cam_flags*/0,
969 /*sense_flags*/SF_RETRY_UA,
970 softc->disk->d_devstat);
972 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
973 if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
974 CAM_SCSI_STATUS_ERROR) {
976 int sense_key, error_code;
978 scsi_extract_sense_len(&ccb->csio.sense_data,
979 ccb->csio.sense_len - ccb->csio.sense_resid,
980 &error_code, &sense_key, &asc, &ascq,
982 if (sense_key != SSD_KEY_ILLEGAL_REQUEST)
983 scsi_sense_print(&ccb->csio);
985 xpt_print(periph->path, "Synchronize cache "
986 "failed, status == 0x%x, scsi status == "
987 "0x%x\n", ccb->csio.ccb_h.status,
988 ccb->csio.scsi_status);
992 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
993 cam_release_devq(ccb->ccb_h.path,
999 xpt_release_ccb(ccb);
1003 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0) {
1004 if ((softc->quirks & DA_Q_NO_PREVENT) == 0)
1005 daprevent(periph, PR_ALLOW);
1007 * If we've got removeable media, mark the blocksize as
1008 * unavailable, since it could change when new media is
1011 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1014 softc->flags &= ~DA_FLAG_OPEN;
1015 cam_periph_unhold(periph);
1016 cam_periph_unlock(periph);
1017 cam_periph_release(periph);
1022 * Actually translate the requested transfer into one the physical driver
1023 * can understand. The transfer is described by a buf and will include
1024 * only one physical transfer.
1027 dastrategy(struct bio *bp)
1029 struct cam_periph *periph;
1030 struct da_softc *softc;
1032 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1033 if (periph == NULL) {
1034 biofinish(bp, NULL, ENXIO);
1037 softc = (struct da_softc *)periph->softc;
1039 cam_periph_lock(periph);
1042 * If the device has been made invalid, error out
1044 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1045 cam_periph_unlock(periph);
1046 biofinish(bp, NULL, ENXIO);
1051 * Place it in the queue of disk activities for this disk
1053 bioq_disksort(&softc->bio_queue, bp);
1056 * Schedule ourselves for performing the work.
1058 xpt_schedule(periph, CAM_PRIORITY_NORMAL);
1059 cam_periph_unlock(periph);
1065 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1067 struct cam_periph *periph;
1068 struct da_softc *softc;
1070 struct ccb_scsiio csio;
1074 periph = dp->d_drv1;
1077 softc = (struct da_softc *)periph->softc;
1078 cam_periph_lock(periph);
1079 secsize = softc->params.secsize;
1081 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1082 cam_periph_unlock(periph);
1087 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1088 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1089 scsi_read_write(&csio,
1095 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1098 /*data_ptr*/(u_int8_t *) virtual,
1099 /*dxfer_len*/length,
1100 /*sense_len*/SSD_FULL_SIZE,
1101 DA_DEFAULT_TIMEOUT * 1000);
1102 xpt_polled_action((union ccb *)&csio);
1104 if ((csio.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1105 printf("Aborting dump due to I/O error.\n");
1106 if ((csio.ccb_h.status & CAM_STATUS_MASK) ==
1107 CAM_SCSI_STATUS_ERROR)
1108 scsi_sense_print(&csio);
1110 printf("status == 0x%x, scsi status == 0x%x\n",
1111 csio.ccb_h.status, csio.scsi_status);
1114 cam_periph_unlock(periph);
1119 * Sync the disk cache contents to the physical media.
1121 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1123 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1124 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1125 scsi_synchronize_cache(&csio,
1129 /*begin_lba*/0,/* Cover the whole disk */
1133 xpt_polled_action((union ccb *)&csio);
1135 if ((csio.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1136 if ((csio.ccb_h.status & CAM_STATUS_MASK) ==
1137 CAM_SCSI_STATUS_ERROR) {
1139 int sense_key, error_code;
1141 scsi_extract_sense_len(&csio.sense_data,
1142 csio.sense_len - csio.sense_resid,
1143 &error_code, &sense_key, &asc, &ascq,
1145 if (sense_key != SSD_KEY_ILLEGAL_REQUEST)
1146 scsi_sense_print(&csio);
1148 xpt_print(periph->path, "Synchronize cache "
1149 "failed, status == 0x%x, scsi status == "
1150 "0x%x\n", csio.ccb_h.status,
1155 cam_periph_unlock(periph);
1160 dagetattr(struct bio *bp)
1163 struct cam_periph *periph;
1165 if (bp->bio_disk == NULL || bp->bio_disk->d_drv1 == NULL)
1167 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1168 if (periph->path == NULL)
1171 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1174 bp->bio_completed = bp->bio_length;
1184 * Install a global async callback. This callback will
1185 * receive async callbacks like "new device found".
1187 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1189 if (status != CAM_REQ_CMP) {
1190 printf("da: Failed to attach master async callback "
1191 "due to status 0x%x!\n", status);
1192 } else if (da_send_ordered) {
1194 /* Register our shutdown event handler */
1195 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1196 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1197 printf("dainit: shutdown event registration failed!\n");
1202 daoninvalidate(struct cam_periph *periph)
1204 struct da_softc *softc;
1206 softc = (struct da_softc *)periph->softc;
1209 * De-register any async callbacks.
1211 xpt_register_async(0, daasync, periph, periph->path);
1213 softc->flags |= DA_FLAG_PACK_INVALID;
1216 * Return all queued I/O with ENXIO.
1217 * XXX Handle any transactions queued to the card
1218 * with XPT_ABORT_CCB.
1220 bioq_flush(&softc->bio_queue, NULL, ENXIO);
1222 disk_gone(softc->disk);
1223 xpt_print(periph->path, "lost device - %d outstanding, %d refs\n",
1224 softc->outstanding_cmds, periph->refcount);
1228 dacleanup(struct cam_periph *periph)
1230 struct da_softc *softc;
1232 softc = (struct da_softc *)periph->softc;
1234 xpt_print(periph->path, "removing device entry\n");
1235 cam_periph_unlock(periph);
1238 * If we can't free the sysctl tree, oh well...
1240 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0
1241 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
1242 xpt_print(periph->path, "can't remove sysctl context\n");
1245 disk_destroy(softc->disk);
1246 callout_drain(&softc->sendordered_c);
1247 free(softc, M_DEVBUF);
1248 cam_periph_lock(periph);
1252 daasync(void *callback_arg, u_int32_t code,
1253 struct cam_path *path, void *arg)
1255 struct cam_periph *periph;
1257 periph = (struct cam_periph *)callback_arg;
1259 case AC_FOUND_DEVICE:
1261 struct ccb_getdev *cgd;
1264 cgd = (struct ccb_getdev *)arg;
1268 if (cgd->protocol != PROTO_SCSI)
1271 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1272 && SID_TYPE(&cgd->inq_data) != T_RBC
1273 && SID_TYPE(&cgd->inq_data) != T_OPTICAL)
1277 * Allocate a peripheral instance for
1278 * this device and start the probe
1281 status = cam_periph_alloc(daregister, daoninvalidate,
1283 "da", CAM_PERIPH_BIO,
1284 cgd->ccb_h.path, daasync,
1285 AC_FOUND_DEVICE, cgd);
1287 if (status != CAM_REQ_CMP
1288 && status != CAM_REQ_INPROG)
1289 printf("daasync: Unable to attach to new device "
1290 "due to status 0x%x\n", status);
1293 case AC_ADVINFO_CHANGED:
1297 buftype = (uintptr_t)arg;
1298 if (buftype == CDAI_TYPE_PHYS_PATH) {
1299 struct da_softc *softc;
1301 softc = periph->softc;
1302 disk_attr_changed(softc->disk, "GEOM::physpath",
1310 struct da_softc *softc;
1311 struct ccb_hdr *ccbh;
1313 softc = (struct da_softc *)periph->softc;
1315 * Don't fail on the expected unit attention
1318 softc->flags |= DA_FLAG_RETRY_UA;
1319 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1320 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1326 cam_periph_async(periph, code, path, arg);
1330 dasysctlinit(void *context, int pending)
1332 struct cam_periph *periph;
1333 struct da_softc *softc;
1334 char tmpstr[80], tmpstr2[80];
1335 struct ccb_trans_settings cts;
1337 periph = (struct cam_periph *)context;
1339 * periph was held for us when this task was enqueued
1341 if (periph->flags & CAM_PERIPH_INVALID) {
1342 cam_periph_release(periph);
1346 softc = (struct da_softc *)periph->softc;
1347 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1348 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1350 sysctl_ctx_init(&softc->sysctl_ctx);
1351 softc->flags |= DA_FLAG_SCTX_INIT;
1352 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
1353 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1354 CTLFLAG_RD, 0, tmpstr);
1355 if (softc->sysctl_tree == NULL) {
1356 printf("dasysctlinit: unable to allocate sysctl tree\n");
1357 cam_periph_release(periph);
1362 * Now register the sysctl handler, so the user can change the value on
1365 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1366 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1367 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1368 "Minimum CDB size");
1370 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1371 SYSCTL_CHILDREN(softc->sysctl_tree),
1375 &softc->error_inject,
1377 "error_inject leaf");
1381 * Add some addressing info.
1383 memset(&cts, 0, sizeof (cts));
1384 xpt_setup_ccb(&cts.ccb_h, periph->path, /*priority*/1);
1385 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1386 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1387 cam_periph_lock(periph);
1388 xpt_action((union ccb *)&cts);
1389 cam_periph_unlock(periph);
1390 if (cts.ccb_h.status != CAM_REQ_CMP) {
1391 cam_periph_release(periph);
1394 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
1395 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
1396 if (fc->valid & CTS_FC_VALID_WWPN) {
1397 softc->wwpn = fc->wwpn;
1398 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1399 SYSCTL_CHILDREN(softc->sysctl_tree),
1400 OID_AUTO, "wwpn", CTLFLAG_RD,
1401 &softc->wwpn, "World Wide Port Name");
1404 cam_periph_release(periph);
1408 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
1412 value = *(int *)arg1;
1414 error = sysctl_handle_int(oidp, &value, 0, req);
1417 || (req->newptr == NULL))
1421 * Acceptable values here are 6, 10, 12 or 16.
1425 else if ((value > 6)
1428 else if ((value > 10)
1431 else if (value > 12)
1434 *(int *)arg1 = value;
1440 daregister(struct cam_periph *periph, void *arg)
1442 struct da_softc *softc;
1443 struct ccb_pathinq cpi;
1444 struct ccb_getdev *cgd;
1448 cgd = (struct ccb_getdev *)arg;
1449 if (periph == NULL) {
1450 printf("daregister: periph was NULL!!\n");
1451 return(CAM_REQ_CMP_ERR);
1455 printf("daregister: no getdev CCB, can't register device\n");
1456 return(CAM_REQ_CMP_ERR);
1459 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
1462 if (softc == NULL) {
1463 printf("daregister: Unable to probe new device. "
1464 "Unable to allocate softc\n");
1465 return(CAM_REQ_CMP_ERR);
1468 LIST_INIT(&softc->pending_ccbs);
1469 softc->state = DA_STATE_PROBE;
1470 bioq_init(&softc->bio_queue);
1471 if (SID_IS_REMOVABLE(&cgd->inq_data))
1472 softc->flags |= DA_FLAG_PACK_REMOVABLE;
1473 if ((cgd->inq_data.flags & SID_CmdQue) != 0)
1474 softc->flags |= DA_FLAG_TAGGED_QUEUING;
1476 periph->softc = softc;
1479 * See if this device has any quirks.
1481 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
1482 (caddr_t)da_quirk_table,
1483 sizeof(da_quirk_table)/sizeof(*da_quirk_table),
1484 sizeof(*da_quirk_table), scsi_inquiry_match);
1487 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
1489 softc->quirks = DA_Q_NONE;
1491 /* Check if the SIM does not want 6 byte commands */
1492 bzero(&cpi, sizeof(cpi));
1493 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1494 cpi.ccb_h.func_code = XPT_PATH_INQ;
1495 xpt_action((union ccb *)&cpi);
1496 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
1497 softc->quirks |= DA_Q_NO_6_BYTE;
1499 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
1502 * Take an exclusive refcount on the periph while dastart is called
1503 * to finish the probe. The reference will be dropped in dadone at
1506 (void)cam_periph_hold(periph, PRIBIO);
1509 * Schedule a periodic event to occasionally send an
1510 * ordered tag to a device.
1512 callout_init_mtx(&softc->sendordered_c, periph->sim->mtx, 0);
1513 callout_reset(&softc->sendordered_c,
1514 (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL,
1515 dasendorderedtag, softc);
1517 mtx_unlock(periph->sim->mtx);
1519 * RBC devices don't have to support READ(6), only READ(10).
1521 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
1522 softc->minimum_cmd_size = 10;
1524 softc->minimum_cmd_size = 6;
1527 * Load the user's default, if any.
1529 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
1530 periph->unit_number);
1531 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
1534 * 6, 10, 12 and 16 are the currently permissible values.
1536 if (softc->minimum_cmd_size < 6)
1537 softc->minimum_cmd_size = 6;
1538 else if ((softc->minimum_cmd_size > 6)
1539 && (softc->minimum_cmd_size <= 10))
1540 softc->minimum_cmd_size = 10;
1541 else if ((softc->minimum_cmd_size > 10)
1542 && (softc->minimum_cmd_size <= 12))
1543 softc->minimum_cmd_size = 12;
1544 else if (softc->minimum_cmd_size > 12)
1545 softc->minimum_cmd_size = 16;
1548 * Register this media as a disk.
1550 softc->disk = disk_alloc();
1551 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
1552 periph->unit_number, 0,
1553 DEVSTAT_BS_UNAVAILABLE,
1554 SID_TYPE(&cgd->inq_data) |
1555 XPORT_DEVSTAT_TYPE(cpi.transport),
1556 DEVSTAT_PRIORITY_DISK);
1557 softc->disk->d_open = daopen;
1558 softc->disk->d_close = daclose;
1559 softc->disk->d_strategy = dastrategy;
1560 softc->disk->d_dump = dadump;
1561 softc->disk->d_getattr = dagetattr;
1562 softc->disk->d_name = "da";
1563 softc->disk->d_drv1 = periph;
1565 softc->disk->d_maxsize = DFLTPHYS; /* traditional default */
1566 else if (cpi.maxio > MAXPHYS)
1567 softc->disk->d_maxsize = MAXPHYS; /* for safety */
1569 softc->disk->d_maxsize = cpi.maxio;
1570 softc->disk->d_unit = periph->unit_number;
1571 softc->disk->d_flags = 0;
1572 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
1573 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
1574 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
1575 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
1576 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
1577 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
1578 cgd->inq_data.product, sizeof(cgd->inq_data.product),
1579 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
1580 softc->disk->d_hba_vendor = cpi.hba_vendor;
1581 softc->disk->d_hba_device = cpi.hba_device;
1582 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
1583 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
1584 disk_create(softc->disk, DISK_VERSION);
1585 mtx_lock(periph->sim->mtx);
1588 * Add async callbacks for events of interest.
1589 * I don't bother checking if this fails as,
1590 * in most cases, the system will function just
1591 * fine without them and the only alternative
1592 * would be to not attach the device on failure.
1594 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET
1595 | AC_LOST_DEVICE | AC_ADVINFO_CHANGED,
1596 daasync, periph, periph->path);
1599 * Emit an attribute changed notification just in case
1600 * physical path information arrived before our async
1601 * event handler was registered, but after anyone attaching
1602 * to our disk device polled it.
1604 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
1606 xpt_schedule(periph, CAM_PRIORITY_DEV);
1608 return(CAM_REQ_CMP);
1612 dastart(struct cam_periph *periph, union ccb *start_ccb)
1614 struct da_softc *softc;
1616 softc = (struct da_softc *)periph->softc;
1618 switch (softc->state) {
1619 case DA_STATE_NORMAL:
1621 /* Pull a buffer from the queue and get going on it */
1625 * See if there is a buf with work for us to do..
1627 bp = bioq_first(&softc->bio_queue);
1628 if (periph->immediate_priority <= periph->pinfo.priority) {
1629 CAM_DEBUG_PRINT(CAM_DEBUG_SUBTRACE,
1630 ("queuing for immediate ccb\n"));
1631 start_ccb->ccb_h.ccb_state = DA_CCB_WAITING;
1632 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
1634 periph->immediate_priority = CAM_PRIORITY_NONE;
1635 wakeup(&periph->ccb_list);
1636 } else if (bp == NULL) {
1637 xpt_release_ccb(start_ccb);
1641 bioq_remove(&softc->bio_queue, bp);
1643 if ((bp->bio_flags & BIO_ORDERED) != 0
1644 || (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
1645 softc->flags &= ~DA_FLAG_NEED_OTAG;
1646 softc->ordered_tag_count++;
1647 tag_code = MSG_ORDERED_Q_TAG;
1649 tag_code = MSG_SIMPLE_Q_TAG;
1651 switch (bp->bio_cmd) {
1654 scsi_read_write(&start_ccb->csio,
1655 /*retries*/da_retry_count,
1657 /*tag_action*/tag_code,
1658 /*read_op*/bp->bio_cmd
1661 softc->minimum_cmd_size,
1662 /*lba*/bp->bio_pblkno,
1663 /*block_count*/bp->bio_bcount /
1664 softc->params.secsize,
1665 /*data_ptr*/ bp->bio_data,
1666 /*dxfer_len*/ bp->bio_bcount,
1667 /*sense_len*/SSD_FULL_SIZE,
1668 da_default_timeout * 1000);
1672 * BIO_FLUSH doesn't currently communicate
1673 * range data, so we synchronize the cache
1674 * over the whole disk. We also force
1675 * ordered tag semantics the flush applies
1676 * to all previously queued I/O.
1678 scsi_synchronize_cache(&start_ccb->csio,
1685 da_default_timeout*1000);
1688 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
1691 * Block out any asyncronous callbacks
1692 * while we touch the pending ccb list.
1694 LIST_INSERT_HEAD(&softc->pending_ccbs,
1695 &start_ccb->ccb_h, periph_links.le);
1696 softc->outstanding_cmds++;
1698 /* We expect a unit attention from this device */
1699 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
1700 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
1701 softc->flags &= ~DA_FLAG_RETRY_UA;
1704 start_ccb->ccb_h.ccb_bp = bp;
1705 bp = bioq_first(&softc->bio_queue);
1707 xpt_action(start_ccb);
1711 /* Have more work to do, so ensure we stay scheduled */
1712 xpt_schedule(periph, CAM_PRIORITY_NORMAL);
1716 case DA_STATE_PROBE:
1718 struct ccb_scsiio *csio;
1719 struct scsi_read_capacity_data *rcap;
1721 rcap = (struct scsi_read_capacity_data *)
1722 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
1724 printf("dastart: Couldn't malloc read_capacity data\n");
1725 /* da_free_periph??? */
1728 csio = &start_ccb->csio;
1729 scsi_read_capacity(csio,
1736 start_ccb->ccb_h.ccb_bp = NULL;
1737 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE;
1738 xpt_action(start_ccb);
1741 case DA_STATE_PROBE2:
1743 struct ccb_scsiio *csio;
1744 struct scsi_read_capacity_data_long *rcaplong;
1746 rcaplong = (struct scsi_read_capacity_data_long *)
1747 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
1748 if (rcaplong == NULL) {
1749 printf("dastart: Couldn't malloc read_capacity data\n");
1750 /* da_free_periph??? */
1753 csio = &start_ccb->csio;
1754 scsi_read_capacity_16(csio,
1757 /*tag_action*/ MSG_SIMPLE_Q_TAG,
1762 /*sense_len*/ SSD_FULL_SIZE,
1764 start_ccb->ccb_h.ccb_bp = NULL;
1765 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE2;
1766 xpt_action(start_ccb);
1773 cmd6workaround(union ccb *ccb)
1775 struct scsi_rw_6 cmd6;
1776 struct scsi_rw_10 *cmd10;
1777 struct da_softc *softc;
1781 cdb = ccb->csio.cdb_io.cdb_bytes;
1783 /* Translation only possible if CDB is an array and cmd is R/W6 */
1784 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
1785 (*cdb != READ_6 && *cdb != WRITE_6))
1788 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
1789 "increasing minimum_cmd_size to 10.\n");
1790 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
1791 softc->minimum_cmd_size = 10;
1793 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
1794 cmd10 = (struct scsi_rw_10 *)cdb;
1795 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
1797 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
1798 cmd10->reserved = 0;
1799 scsi_ulto2b(cmd6.length, cmd10->length);
1800 cmd10->control = cmd6.control;
1801 ccb->csio.cdb_len = sizeof(*cmd10);
1803 /* Requeue request, unfreezing queue if necessary */
1804 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
1805 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1808 cam_release_devq(ccb->ccb_h.path,
1812 /*getcount_only*/0);
1818 dadone(struct cam_periph *periph, union ccb *done_ccb)
1820 struct da_softc *softc;
1821 struct ccb_scsiio *csio;
1824 softc = (struct da_softc *)periph->softc;
1825 priority = done_ccb->ccb_h.pinfo.priority;
1826 csio = &done_ccb->csio;
1827 switch (csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK) {
1828 case DA_CCB_BUFFER_IO:
1832 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
1833 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1837 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
1842 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
1843 if (error == ERESTART) {
1845 * A retry was scheuled, so
1854 * return all queued I/O with EIO, so that
1855 * the client can retry these I/Os in the
1856 * proper order should it attempt to recover.
1861 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
1863 * Catastrophic error. Mark our pack as
1867 * XXX See if this is really a media
1870 xpt_print(periph->path,
1871 "Invalidating pack\n");
1872 softc->flags |= DA_FLAG_PACK_INVALID;
1873 queued_error = ENXIO;
1875 bioq_flush(&softc->bio_queue, NULL,
1877 bp->bio_error = error;
1878 bp->bio_resid = bp->bio_bcount;
1879 bp->bio_flags |= BIO_ERROR;
1881 bp->bio_resid = csio->resid;
1883 if (bp->bio_resid != 0)
1884 bp->bio_flags |= BIO_ERROR;
1886 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1887 cam_release_devq(done_ccb->ccb_h.path,
1891 /*getcount_only*/0);
1893 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1894 panic("REQ_CMP with QFRZN");
1895 bp->bio_resid = csio->resid;
1896 if (csio->resid > 0)
1897 bp->bio_flags |= BIO_ERROR;
1898 if (softc->error_inject != 0) {
1899 bp->bio_error = softc->error_inject;
1900 bp->bio_resid = bp->bio_bcount;
1901 bp->bio_flags |= BIO_ERROR;
1902 softc->error_inject = 0;
1908 * Block out any asyncronous callbacks
1909 * while we touch the pending ccb list.
1911 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
1912 softc->outstanding_cmds--;
1913 if (softc->outstanding_cmds == 0)
1914 softc->flags |= DA_FLAG_WENT_IDLE;
1916 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1917 xpt_print(periph->path, "oustanding %d\n",
1918 softc->outstanding_cmds);
1927 struct scsi_read_capacity_data *rdcap;
1928 struct scsi_read_capacity_data_long *rcaplong;
1929 char announce_buf[80];
1933 if (softc->state == DA_STATE_PROBE)
1934 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
1936 rcaplong = (struct scsi_read_capacity_data_long *)
1939 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1940 struct disk_params *dp;
1941 uint32_t block_size;
1944 if (softc->state == DA_STATE_PROBE) {
1945 block_size = scsi_4btoul(rdcap->length);
1946 maxsector = scsi_4btoul(rdcap->addr);
1949 * According to SBC-2, if the standard 10
1950 * byte READ CAPACITY command returns 2^32,
1951 * we should issue the 16 byte version of
1952 * the command, since the device in question
1953 * has more sectors than can be represented
1954 * with the short version of the command.
1956 if (maxsector == 0xffffffff) {
1957 softc->state = DA_STATE_PROBE2;
1958 free(rdcap, M_SCSIDA);
1959 xpt_release_ccb(done_ccb);
1960 xpt_schedule(periph, priority);
1964 block_size = scsi_4btoul(rcaplong->length);
1965 maxsector = scsi_8btou64(rcaplong->addr);
1969 * Because GEOM code just will panic us if we
1970 * give them an 'illegal' value we'll avoid that
1973 if (block_size == 0 && maxsector == 0) {
1974 snprintf(announce_buf, sizeof(announce_buf),
1976 } else if (block_size >= MAXPHYS || block_size == 0) {
1977 xpt_print(periph->path,
1978 "unsupportable block size %ju\n",
1979 (uintmax_t) block_size);
1980 announce_buf[0] = '\0';
1981 cam_periph_invalidate(periph);
1983 dasetgeom(periph, block_size, maxsector, 0, 0);
1984 dp = &softc->params;
1985 snprintf(announce_buf, sizeof(announce_buf),
1986 "%juMB (%ju %u byte sectors: %dH %dS/T "
1988 (((uintmax_t)dp->secsize *
1989 dp->sectors) / (1024*1024)),
1990 (uintmax_t)dp->sectors,
1991 dp->secsize, dp->heads,
1992 dp->secs_per_track, dp->cylinders);
1997 announce_buf[0] = '\0';
2000 * Retry any UNIT ATTENTION type errors. They
2001 * are expected at boot.
2003 error = daerror(done_ccb, CAM_RETRY_SELTO,
2004 SF_RETRY_UA|SF_NO_PRINT);
2005 if (error == ERESTART) {
2007 * A retry was scheuled, so
2011 } else if (error != 0) {
2012 struct scsi_sense_data *sense;
2014 int sense_key, error_code;
2017 struct ccb_getdev cgd;
2019 /* Don't wedge this device's queue */
2020 status = done_ccb->ccb_h.status;
2021 if ((status & CAM_DEV_QFRZN) != 0)
2022 cam_release_devq(done_ccb->ccb_h.path,
2026 /*getcount_only*/0);
2029 xpt_setup_ccb(&cgd.ccb_h,
2030 done_ccb->ccb_h.path,
2031 CAM_PRIORITY_NORMAL);
2032 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
2033 xpt_action((union ccb *)&cgd);
2035 if (((csio->ccb_h.flags & CAM_SENSE_PHYS) != 0)
2036 || ((csio->ccb_h.flags & CAM_SENSE_PTR) != 0)
2037 || ((status & CAM_AUTOSNS_VALID) == 0))
2043 sense = &csio->sense_data;
2044 scsi_extract_sense_len(sense,
2045 csio->sense_len - csio->sense_resid,
2046 &error_code, &sense_key, &asc,
2047 &ascq, /*show_errors*/ 1);
2050 * Attach to anything that claims to be a
2051 * direct access or optical disk device,
2052 * as long as it doesn't return a "Logical
2053 * unit not supported" (0x25) error.
2055 if ((have_sense) && (asc != 0x25)
2056 && (error_code == SSD_CURRENT_ERROR)) {
2057 const char *sense_key_desc;
2058 const char *asc_desc;
2060 scsi_sense_desc(sense_key, asc, ascq,
2064 snprintf(announce_buf,
2065 sizeof(announce_buf),
2066 "Attempt to query device "
2067 "size failed: %s, %s",
2075 xpt_print(periph->path,
2076 "got CAM status %#x\n",
2077 done_ccb->ccb_h.status);
2080 xpt_print(periph->path, "fatal error, "
2081 "failed to attach to device\n");
2084 * Free up resources.
2086 cam_periph_invalidate(periph);
2090 free(csio->data_ptr, M_SCSIDA);
2091 if (announce_buf[0] != '\0') {
2093 * Create our sysctl variables, now that we know
2094 * we have successfully attached.
2096 /* increase the refcount */
2097 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
2098 taskqueue_enqueue(taskqueue_thread,
2099 &softc->sysctl_task);
2100 xpt_announce_periph(periph, announce_buf);
2102 xpt_print(periph->path, "fatal error, "
2103 "could not acquire reference count\n");
2107 softc->state = DA_STATE_NORMAL;
2109 * Since our peripheral may be invalidated by an error
2110 * above or an external event, we must release our CCB
2111 * before releasing the probe lock on the peripheral.
2112 * The peripheral will only go away once the last lock
2113 * is removed, and we need it around for the CCB release
2116 xpt_release_ccb(done_ccb);
2117 cam_periph_unhold(periph);
2120 case DA_CCB_WAITING:
2122 /* Caller will release the CCB */
2123 wakeup(&done_ccb->ccb_h.cbfcnp);
2127 /* No-op. We're polling */
2132 xpt_release_ccb(done_ccb);
2136 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
2138 struct da_softc *softc;
2139 struct cam_periph *periph;
2142 periph = xpt_path_periph(ccb->ccb_h.path);
2143 softc = (struct da_softc *)periph->softc;
2146 * Automatically detect devices that do not support
2147 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
2150 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
2151 error = cmd6workaround(ccb);
2152 } else if (((ccb->ccb_h.status & CAM_STATUS_MASK) ==
2153 CAM_SCSI_STATUS_ERROR)
2154 && (ccb->ccb_h.status & CAM_AUTOSNS_VALID)
2155 && (ccb->csio.scsi_status == SCSI_STATUS_CHECK_COND)
2156 && ((ccb->ccb_h.flags & CAM_SENSE_PHYS) == 0)
2157 && ((ccb->ccb_h.flags & CAM_SENSE_PTR) == 0)) {
2158 int sense_key, error_code, asc, ascq;
2160 scsi_extract_sense(&ccb->csio.sense_data,
2161 &error_code, &sense_key, &asc, &ascq);
2162 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
2163 error = cmd6workaround(ccb);
2165 if (error == ERESTART)
2170 * Until we have a better way of doing pack validation,
2171 * don't treat UAs as errors.
2173 sense_flags |= SF_RETRY_UA;
2174 return(cam_periph_error(ccb, cam_flags, sense_flags,
2175 &softc->saved_ccb));
2179 daprevent(struct cam_periph *periph, int action)
2181 struct da_softc *softc;
2185 softc = (struct da_softc *)periph->softc;
2187 if (((action == PR_ALLOW)
2188 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
2189 || ((action == PR_PREVENT)
2190 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
2194 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
2196 scsi_prevent(&ccb->csio,
2204 error = cam_periph_runccb(ccb, /*error_routine*/NULL, CAM_RETRY_SELTO,
2205 SF_RETRY_UA, softc->disk->d_devstat);
2208 if (action == PR_ALLOW)
2209 softc->flags &= ~DA_FLAG_PACK_LOCKED;
2211 softc->flags |= DA_FLAG_PACK_LOCKED;
2214 xpt_release_ccb(ccb);
2218 dagetcapacity(struct cam_periph *periph)
2220 struct da_softc *softc;
2222 struct scsi_read_capacity_data *rcap;
2223 struct scsi_read_capacity_data_long *rcaplong;
2227 u_int32_t sense_flags;
2229 softc = (struct da_softc *)periph->softc;
2233 sense_flags = SF_RETRY_UA;
2234 if (softc->flags & DA_FLAG_PACK_REMOVABLE)
2235 sense_flags |= SF_NO_PRINT;
2237 /* Do a read capacity */
2238 rcap = (struct scsi_read_capacity_data *)malloc(sizeof(*rcaplong),
2244 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
2245 scsi_read_capacity(&ccb->csio,
2252 ccb->ccb_h.ccb_bp = NULL;
2254 error = cam_periph_runccb(ccb, daerror,
2255 /*cam_flags*/CAM_RETRY_SELTO,
2257 softc->disk->d_devstat);
2259 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2260 cam_release_devq(ccb->ccb_h.path,
2264 /*getcount_only*/0);
2267 block_len = scsi_4btoul(rcap->length);
2268 maxsector = scsi_4btoul(rcap->addr);
2270 if (maxsector != 0xffffffff)
2275 rcaplong = (struct scsi_read_capacity_data_long *)rcap;
2277 scsi_read_capacity_16(&ccb->csio,
2280 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2285 /*sense_len*/ SSD_FULL_SIZE,
2287 ccb->ccb_h.ccb_bp = NULL;
2289 error = cam_periph_runccb(ccb, daerror,
2290 /*cam_flags*/CAM_RETRY_SELTO,
2292 softc->disk->d_devstat);
2294 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2295 cam_release_devq(ccb->ccb_h.path,
2299 /*getcount_only*/0);
2302 block_len = scsi_4btoul(rcaplong->length);
2303 maxsector = scsi_8btou64(rcaplong->addr);
2309 if (block_len >= MAXPHYS || block_len == 0) {
2310 xpt_print(periph->path,
2311 "unsupportable block size %ju\n",
2312 (uintmax_t) block_len);
2315 dasetgeom(periph, block_len, maxsector, 0, 0);
2318 xpt_release_ccb(ccb);
2320 free(rcap, M_SCSIDA);
2326 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
2327 u_int lbppbe, u_int lalba)
2329 struct ccb_calc_geometry ccg;
2330 struct da_softc *softc;
2331 struct disk_params *dp;
2333 softc = (struct da_softc *)periph->softc;
2335 dp = &softc->params;
2336 dp->secsize = block_len;
2337 dp->sectors = maxsector + 1;
2339 dp->stripesize = block_len << lbppbe;
2340 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
2342 } else if (softc->quirks & DA_Q_4K) {
2343 dp->stripesize = 4096;
2344 dp->stripeoffset = 0;
2347 dp->stripeoffset = 0;
2350 * Have the controller provide us with a geometry
2351 * for this disk. The only time the geometry
2352 * matters is when we boot and the controller
2353 * is the only one knowledgeable enough to come
2354 * up with something that will make this a bootable
2357 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2358 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
2359 ccg.block_size = dp->secsize;
2360 ccg.volume_size = dp->sectors;
2362 ccg.secs_per_track = 0;
2364 xpt_action((union ccb*)&ccg);
2365 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2367 * We don't know what went wrong here- but just pick
2368 * a geometry so we don't have nasty things like divide
2372 dp->secs_per_track = 255;
2373 dp->cylinders = dp->sectors / (255 * 255);
2374 if (dp->cylinders == 0) {
2378 dp->heads = ccg.heads;
2379 dp->secs_per_track = ccg.secs_per_track;
2380 dp->cylinders = ccg.cylinders;
2385 dasendorderedtag(void *arg)
2387 struct da_softc *softc = arg;
2389 if (da_send_ordered) {
2390 if ((softc->ordered_tag_count == 0)
2391 && ((softc->flags & DA_FLAG_WENT_IDLE) == 0)) {
2392 softc->flags |= DA_FLAG_NEED_OTAG;
2394 if (softc->outstanding_cmds > 0)
2395 softc->flags &= ~DA_FLAG_WENT_IDLE;
2397 softc->ordered_tag_count = 0;
2399 /* Queue us up again */
2400 callout_reset(&softc->sendordered_c,
2401 (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL,
2402 dasendorderedtag, softc);
2406 * Step through all DA peripheral drivers, and if the device is still open,
2407 * sync the disk cache to physical media.
2410 dashutdown(void * arg, int howto)
2412 struct cam_periph *periph;
2413 struct da_softc *softc;
2415 TAILQ_FOREACH(periph, &dadriver.units, unit_links) {
2418 cam_periph_lock(periph);
2419 softc = (struct da_softc *)periph->softc;
2422 * We only sync the cache if the drive is still open, and
2423 * if the drive is capable of it..
2425 if (((softc->flags & DA_FLAG_OPEN) == 0)
2426 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
2427 cam_periph_unlock(periph);
2431 xpt_setup_ccb(&ccb.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2433 ccb.ccb_h.ccb_state = DA_CCB_DUMP;
2434 scsi_synchronize_cache(&ccb.csio,
2438 /*begin_lba*/0, /* whole disk */
2443 xpt_polled_action(&ccb);
2445 if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2446 if (((ccb.ccb_h.status & CAM_STATUS_MASK) ==
2447 CAM_SCSI_STATUS_ERROR)
2448 && (ccb.csio.scsi_status == SCSI_STATUS_CHECK_COND)){
2449 int error_code, sense_key, asc, ascq;
2451 scsi_extract_sense(&ccb.csio.sense_data,
2452 &error_code, &sense_key,
2455 if (sense_key != SSD_KEY_ILLEGAL_REQUEST)
2456 scsi_sense_print(&ccb.csio);
2458 xpt_print(periph->path, "Synchronize "
2459 "cache failed, status == 0x%x, scsi status "
2460 "== 0x%x\n", ccb.ccb_h.status,
2461 ccb.csio.scsi_status);
2465 if ((ccb.ccb_h.status & CAM_DEV_QFRZN) != 0)
2466 cam_release_devq(ccb.ccb_h.path,
2470 /*getcount_only*/0);
2471 cam_periph_unlock(periph);
2475 #else /* !_KERNEL */
2478 * XXX This is only left out of the kernel build to silence warnings. If,
2479 * for some reason this function is used in the kernel, the ifdefs should
2480 * be moved so it is included both in the kernel and userland.
2483 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
2484 void (*cbfcnp)(struct cam_periph *, union ccb *),
2485 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
2486 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
2489 struct scsi_format_unit *scsi_cmd;
2491 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
2492 scsi_cmd->opcode = FORMAT_UNIT;
2493 scsi_cmd->byte2 = byte2;
2494 scsi_ulto2b(ileave, scsi_cmd->interleave);
2499 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
2508 #endif /* _KERNEL */