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 <sys/endian.h>
49 #include <geom/geom.h>
50 #include <geom/geom_disk.h>
59 #include <cam/cam_ccb.h>
60 #include <cam/cam_periph.h>
61 #include <cam/cam_xpt_periph.h>
62 #include <cam/cam_sim.h>
64 #include <cam/scsi/scsi_message.h>
67 #include <cam/scsi/scsi_da.h>
75 DA_STATE_PROBE_BLK_LIMITS,
82 DA_FLAG_PACK_INVALID = 0x001,
83 DA_FLAG_NEW_PACK = 0x002,
84 DA_FLAG_PACK_LOCKED = 0x004,
85 DA_FLAG_PACK_REMOVABLE = 0x008,
86 DA_FLAG_SAW_MEDIA = 0x010,
87 DA_FLAG_NEED_OTAG = 0x020,
88 DA_FLAG_WENT_IDLE = 0x040,
89 DA_FLAG_RETRY_UA = 0x080,
91 DA_FLAG_SCTX_INIT = 0x200,
92 DA_FLAG_CAN_RC16 = 0x400,
93 DA_FLAG_PROBED = 0x800,
94 DA_FLAG_DIRTY = 0x1000
99 DA_Q_NO_SYNC_CACHE = 0x01,
100 DA_Q_NO_6_BYTE = 0x02,
101 DA_Q_NO_PREVENT = 0x04,
106 #define DA_Q_BIT_STRING \
108 "\001NO_SYNC_CACHE" \
115 DA_CCB_PROBE_RC = 0x01,
116 DA_CCB_PROBE_RC16 = 0x02,
117 DA_CCB_PROBE_LBP = 0x03,
118 DA_CCB_PROBE_BLK_LIMITS = 0x04,
119 DA_CCB_PROBE_BDC = 0x05,
120 DA_CCB_PROBE_ATA = 0x06,
121 DA_CCB_BUFFER_IO = 0x07,
122 DA_CCB_WAITING = 0x08,
124 DA_CCB_DELETE = 0x0B,
126 DA_CCB_TYPE_MASK = 0x0F,
127 DA_CCB_RETRY_UA = 0x10
131 * Order here is important for method choice
133 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
134 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
135 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
136 * import taking 5mins.
147 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
148 DA_DELETE_MAX = DA_DELETE_ZERO
151 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
153 static da_delete_func_t da_delete_trim;
154 static da_delete_func_t da_delete_unmap;
155 static da_delete_func_t da_delete_ws;
157 static const void * da_delete_functions[] = {
167 static const char *da_delete_method_names[] =
168 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
169 static const char *da_delete_method_desc[] =
170 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
171 "WRITE SAME(10) with UNMAP", "ZERO" };
173 /* Offsets into our private area for storing information */
174 #define ccb_state ppriv_field0
175 #define ccb_bp ppriv_ptr1
180 u_int8_t secs_per_track;
181 u_int32_t secsize; /* Number of bytes/sector */
182 u_int64_t sectors; /* total number sectors */
187 #define UNMAP_RANGE_MAX 0xffffffff
188 #define UNMAP_HEAD_SIZE 8
189 #define UNMAP_RANGE_SIZE 16
190 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
191 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
194 #define WS10_MAX_BLKS 0xffff
195 #define WS16_MAX_BLKS 0xffffffff
196 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
197 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
200 struct bio_queue_head bio_queue;
201 struct bio_queue_head delete_queue;
202 struct bio_queue_head delete_run_queue;
203 SLIST_ENTRY(da_softc) links;
204 LIST_HEAD(, ccb_hdr) pending_ccbs;
209 int minimum_cmd_size;
211 int ordered_tag_count;
212 int outstanding_cmds;
216 int delete_available; /* Delete methods possibly available */
217 uint32_t unmap_max_ranges;
218 uint32_t unmap_max_lba;
219 uint64_t ws_max_blks;
220 da_delete_methods delete_method;
221 da_delete_func_t *delete_func;
222 struct disk_params params;
225 struct task sysctl_task;
226 struct sysctl_ctx_list sysctl_ctx;
227 struct sysctl_oid *sysctl_tree;
228 struct callout sendordered_c;
230 uint8_t unmap_buf[UNMAP_BUF_SIZE];
231 struct scsi_read_capacity_data_long rcaplong;
232 struct callout mediapoll_c;
235 #define dadeleteflag(softc, delete_method, enable) \
237 softc->delete_available |= (1 << delete_method); \
239 softc->delete_available &= ~(1 << delete_method); \
242 struct da_quirk_entry {
243 struct scsi_inquiry_pattern inq_pat;
247 static const char quantum[] = "QUANTUM";
248 static const char microp[] = "MICROP";
250 static struct da_quirk_entry da_quirk_table[] =
252 /* SPI, FC devices */
255 * Fujitsu M2513A MO drives.
256 * Tested devices: M2513A2 firmware versions 1200 & 1300.
257 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
258 * Reported by: W.Scholten <whs@xs4all.nl>
260 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
261 /*quirks*/ DA_Q_NO_SYNC_CACHE
265 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
266 /*quirks*/ DA_Q_NO_SYNC_CACHE
270 * This particular Fujitsu drive doesn't like the
271 * synchronize cache command.
272 * Reported by: Tom Jackson <toj@gorilla.net>
274 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
275 /*quirks*/ DA_Q_NO_SYNC_CACHE
279 * This drive doesn't like the synchronize cache command
280 * either. Reported by: Matthew Jacob <mjacob@feral.com>
281 * in NetBSD PR kern/6027, August 24, 1998.
283 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
284 /*quirks*/ DA_Q_NO_SYNC_CACHE
288 * This drive doesn't like the synchronize cache command
289 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
292 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
293 /*quirks*/ DA_Q_NO_SYNC_CACHE
297 * Doesn't like the synchronize cache command.
298 * Reported by: Blaz Zupan <blaz@gold.amis.net>
300 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
301 /*quirks*/ DA_Q_NO_SYNC_CACHE
305 * Doesn't like the synchronize cache command.
306 * Reported by: Blaz Zupan <blaz@gold.amis.net>
308 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
309 /*quirks*/ DA_Q_NO_SYNC_CACHE
313 * Doesn't like the synchronize cache command.
315 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
316 /*quirks*/ DA_Q_NO_SYNC_CACHE
320 * Doesn't like the synchronize cache command.
321 * Reported by: walter@pelissero.de
323 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
324 /*quirks*/ DA_Q_NO_SYNC_CACHE
328 * Doesn't work correctly with 6 byte reads/writes.
329 * Returns illegal request, and points to byte 9 of the
331 * Reported by: Adam McDougall <bsdx@spawnet.com>
333 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
334 /*quirks*/ DA_Q_NO_6_BYTE
338 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
339 /*quirks*/ DA_Q_NO_6_BYTE
343 * Doesn't like the synchronize cache command.
344 * Reported by: walter@pelissero.de
346 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
347 /*quirks*/ DA_Q_NO_SYNC_CACHE
351 * The CISS RAID controllers do not support SYNC_CACHE
353 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
354 /*quirks*/ DA_Q_NO_SYNC_CACHE
356 /* USB mass storage devices supported by umass(4) */
359 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
362 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
363 /*quirks*/ DA_Q_NO_SYNC_CACHE
367 * Power Quotient Int. (PQI) USB flash key
370 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
371 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
375 * Creative Nomad MUVO mp3 player (USB)
378 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
379 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
383 * Jungsoft NEXDISK USB flash key
386 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
387 /*quirks*/ DA_Q_NO_SYNC_CACHE
391 * FreeDik USB Mini Data Drive
394 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
395 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
399 * Sigmatel USB Flash MP3 Player
402 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
403 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
407 * Neuros USB Digital Audio Computer
410 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
411 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
415 * SEAGRAND NP-900 MP3 Player
418 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
419 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
423 * iRiver iFP MP3 player (with UMS Firmware)
424 * PR: kern/54881, i386/63941, kern/66124
426 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
427 /*quirks*/ DA_Q_NO_SYNC_CACHE
431 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
434 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
435 /*quirks*/ DA_Q_NO_SYNC_CACHE
439 * ZICPlay USB MP3 Player with FM
442 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
443 /*quirks*/ DA_Q_NO_SYNC_CACHE
447 * TEAC USB floppy mechanisms
449 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
450 /*quirks*/ DA_Q_NO_SYNC_CACHE
454 * Kingston DataTraveler II+ USB Pen-Drive.
455 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
457 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
458 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
466 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
467 /*quirks*/ DA_Q_NO_SYNC_CACHE
471 * Motorola E398 Mobile Phone (TransFlash memory card).
472 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
475 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
476 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
480 * Qware BeatZkey! Pro
483 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
484 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
488 * Time DPA20B 1GB MP3 Player
491 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
492 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
496 * Samsung USB key 128Mb
499 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
500 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
504 * Kingston DataTraveler 2.0 USB Flash memory.
507 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
508 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
512 * Creative MUVO Slim mp3 player (USB)
515 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
516 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
520 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
523 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
524 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
528 * SanDisk Micro Cruzer 128MB
531 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
532 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
536 * TOSHIBA TransMemory USB sticks
539 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
540 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
545 * PR: usb/75578, usb/72344, usb/65436
547 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
548 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
552 * Genesys 6-in-1 Card Reader
555 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
556 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
560 * Rekam Digital CAMERA
563 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
564 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
568 * iRiver H10 MP3 player
571 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
572 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
576 * iRiver U10 MP3 player
579 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
580 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
587 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
588 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
592 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
595 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
596 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
603 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
604 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
608 * Philips USB Key Audio KEY013
611 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
612 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
619 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
620 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
627 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
628 /*quirks*/ DA_Q_NO_SYNC_CACHE
632 * I/O Magic USB flash - Giga Bank
635 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
636 /*quirks*/ DA_Q_NO_SYNC_CACHE
640 * JoyFly 128mb USB Flash Drive
643 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
644 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
651 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
652 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
656 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
659 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
660 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
664 * Samsung YP-U3 mp3-player
667 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
668 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
671 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
672 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
676 * Sony Cyber-Shot DSC cameras
679 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
680 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
683 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
684 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
687 /* At least several Transcent USB sticks lie on RC16. */
688 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
689 "*"}, /*quirks*/ DA_Q_NO_RC16
691 /* ATA/SATA devices over SAS/USB/... */
693 /* Hitachi Advanced Format (4k) drives */
694 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
698 /* Samsung Advanced Format (4k) drives */
699 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
703 /* Samsung Advanced Format (4k) drives */
704 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
708 /* Samsung Advanced Format (4k) drives */
709 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
713 /* Samsung Advanced Format (4k) drives */
714 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
718 /* Seagate Barracuda Green Advanced Format (4k) drives */
719 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
723 /* Seagate Barracuda Green Advanced Format (4k) drives */
724 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
728 /* Seagate Barracuda Green Advanced Format (4k) drives */
729 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
733 /* Seagate Barracuda Green Advanced Format (4k) drives */
734 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
738 /* Seagate Barracuda Green Advanced Format (4k) drives */
739 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
743 /* Seagate Barracuda Green Advanced Format (4k) drives */
744 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
748 /* Seagate Momentus Advanced Format (4k) drives */
749 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
753 /* Seagate Momentus Advanced Format (4k) drives */
754 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
758 /* Seagate Momentus Advanced Format (4k) drives */
759 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
763 /* Seagate Momentus Advanced Format (4k) drives */
764 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
768 /* Seagate Momentus Advanced Format (4k) drives */
769 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
773 /* Seagate Momentus Advanced Format (4k) drives */
774 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
778 /* Seagate Momentus Advanced Format (4k) drives */
779 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
783 /* Seagate Momentus Advanced Format (4k) drives */
784 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
788 /* Seagate Momentus Advanced Format (4k) drives */
789 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
793 /* Seagate Momentus Advanced Format (4k) drives */
794 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
798 /* Seagate Momentus Advanced Format (4k) drives */
799 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
803 /* Seagate Momentus Advanced Format (4k) drives */
804 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
808 /* Seagate Momentus Advanced Format (4k) drives */
809 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
813 /* Seagate Momentus Advanced Format (4k) drives */
814 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
818 /* Seagate Momentus Thin Advanced Format (4k) drives */
819 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
823 /* Seagate Momentus Thin Advanced Format (4k) drives */
824 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
828 /* WDC Caviar Green Advanced Format (4k) drives */
829 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
833 /* WDC Caviar Green Advanced Format (4k) drives */
834 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
838 /* WDC Caviar Green Advanced Format (4k) drives */
839 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
843 /* WDC Caviar Green Advanced Format (4k) drives */
844 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
848 /* WDC Caviar Green Advanced Format (4k) drives */
849 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
853 /* WDC Caviar Green Advanced Format (4k) drives */
854 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
858 /* WDC Caviar Green Advanced Format (4k) drives */
859 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
863 /* WDC Caviar Green Advanced Format (4k) drives */
864 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
868 /* WDC Scorpio Black Advanced Format (4k) drives */
869 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
873 /* WDC Scorpio Black Advanced Format (4k) drives */
874 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
878 /* WDC Scorpio Black Advanced Format (4k) drives */
879 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
883 /* WDC Scorpio Black Advanced Format (4k) drives */
884 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
888 /* WDC Scorpio Blue Advanced Format (4k) drives */
889 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
893 /* WDC Scorpio Blue Advanced Format (4k) drives */
894 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
898 /* WDC Scorpio Blue Advanced Format (4k) drives */
899 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
903 /* WDC Scorpio Blue Advanced Format (4k) drives */
904 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
909 * Olympus FE-210 camera
911 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
912 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
918 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
919 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
923 * Laser MP3-2GA13 MP3 player
925 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
926 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
930 * LaCie external 250GB Hard drive des by Porsche
931 * Submitted by: Ben Stuyts <ben@altesco.nl>
934 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
935 /*quirks*/ DA_Q_NO_SYNC_CACHE
940 * Corsair Force 2 SSDs
941 * 4k optimised & trim only works in 4k requests + 4k aligned
943 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
948 * Corsair Force 3 SSDs
949 * 4k optimised & trim only works in 4k requests + 4k aligned
951 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
956 * Corsair Force GT SSDs
957 * 4k optimised & trim only works in 4k requests + 4k aligned
959 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force GT*", "*" },
965 * 4k optimised & trim only works in 4k requests + 4k aligned
967 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
972 * Crucial RealSSD C300 SSDs
975 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
976 "*" }, /*quirks*/DA_Q_4K
980 * Intel 320 Series SSDs
981 * 4k optimised & trim only works in 4k requests + 4k aligned
983 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
988 * Intel 330 Series SSDs
989 * 4k optimised & trim only works in 4k requests + 4k aligned
991 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
996 * Intel 510 Series SSDs
997 * 4k optimised & trim only works in 4k requests + 4k aligned
999 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1004 * Intel 520 Series SSDs
1005 * 4k optimised & trim only works in 4k requests + 4k aligned
1007 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1012 * Kingston E100 Series SSDs
1013 * 4k optimised & trim only works in 4k requests + 4k aligned
1015 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1020 * Kingston HyperX 3k SSDs
1021 * 4k optimised & trim only works in 4k requests + 4k aligned
1023 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1028 * OCZ Agility 3 SSDs
1029 * 4k optimised & trim only works in 4k requests + 4k aligned
1031 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1036 * OCZ Deneva R Series SSDs
1037 * 4k optimised & trim only works in 4k requests + 4k aligned
1039 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1044 * OCZ Vertex 2 SSDs (inc pro series)
1045 * 4k optimised & trim only works in 4k requests + 4k aligned
1047 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1053 * 4k optimised & trim only works in 4k requests + 4k aligned
1055 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1061 * 4k optimised & trim only works in 4k requests + 4k aligned
1063 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1068 * Samsung 830 Series SSDs
1069 * 4k optimised & trim only works in 4k requests + 4k aligned
1071 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1076 * SuperTalent TeraDrive CT SSDs
1077 * 4k optimised & trim only works in 4k requests + 4k aligned
1079 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1084 * XceedIOPS SATA SSDs
1087 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1092 static disk_strategy_t dastrategy;
1093 static dumper_t dadump;
1094 static periph_init_t dainit;
1095 static void daasync(void *callback_arg, u_int32_t code,
1096 struct cam_path *path, void *arg);
1097 static void dasysctlinit(void *context, int pending);
1098 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1099 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1100 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1101 static void dadeletemethodset(struct da_softc *softc,
1102 da_delete_methods delete_method);
1103 static off_t dadeletemaxsize(struct da_softc *softc,
1104 da_delete_methods delete_method);
1105 static void dadeletemethodchoose(struct da_softc *softc,
1106 da_delete_methods default_method);
1107 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1109 static periph_ctor_t daregister;
1110 static periph_dtor_t dacleanup;
1111 static periph_start_t dastart;
1112 static periph_oninv_t daoninvalidate;
1113 static void dadone(struct cam_periph *periph,
1114 union ccb *done_ccb);
1115 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1116 u_int32_t sense_flags);
1117 static void daprevent(struct cam_periph *periph, int action);
1118 static void dareprobe(struct cam_periph *periph);
1119 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1121 struct scsi_read_capacity_data_long *rcaplong,
1123 static timeout_t dasendorderedtag;
1124 static void dashutdown(void *arg, int howto);
1125 static timeout_t damediapoll;
1127 #ifndef DA_DEFAULT_POLL_PERIOD
1128 #define DA_DEFAULT_POLL_PERIOD 3
1131 #ifndef DA_DEFAULT_TIMEOUT
1132 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1135 #ifndef DA_DEFAULT_RETRY
1136 #define DA_DEFAULT_RETRY 4
1139 #ifndef DA_DEFAULT_SEND_ORDERED
1140 #define DA_DEFAULT_SEND_ORDERED 1
1143 #define DA_SIO (softc->sort_io_queue >= 0 ? \
1144 softc->sort_io_queue : cam_sort_io_queues)
1146 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1147 static int da_retry_count = DA_DEFAULT_RETRY;
1148 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1149 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1151 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1152 "CAM Direct Access Disk driver");
1153 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RW,
1154 &da_poll_period, 0, "Media polling period in seconds");
1155 TUNABLE_INT("kern.cam.da.poll_period", &da_poll_period);
1156 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RW,
1157 &da_retry_count, 0, "Normal I/O retry count");
1158 TUNABLE_INT("kern.cam.da.retry_count", &da_retry_count);
1159 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RW,
1160 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1161 TUNABLE_INT("kern.cam.da.default_timeout", &da_default_timeout);
1162 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RW,
1163 &da_send_ordered, 0, "Send Ordered Tags");
1164 TUNABLE_INT("kern.cam.da.send_ordered", &da_send_ordered);
1167 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1168 * to the default timeout, we check to see whether an ordered
1169 * tagged transaction is appropriate to prevent simple tag
1170 * starvation. Since we'd like to ensure that there is at least
1171 * 1/2 of the timeout length left for a starved transaction to
1172 * complete after we've sent an ordered tag, we must poll at least
1173 * four times in every timeout period. This takes care of the worst
1174 * case where a starved transaction starts during an interval that
1175 * meets the requirement "don't send an ordered tag" test so it takes
1176 * us two intervals to determine that a tag must be sent.
1178 #ifndef DA_ORDEREDTAG_INTERVAL
1179 #define DA_ORDEREDTAG_INTERVAL 4
1182 static struct periph_driver dadriver =
1185 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1188 PERIPHDRIVER_DECLARE(da, dadriver);
1190 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1193 daopen(struct disk *dp)
1195 struct cam_periph *periph;
1196 struct da_softc *softc;
1199 periph = (struct cam_periph *)dp->d_drv1;
1200 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1204 cam_periph_lock(periph);
1205 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1206 cam_periph_unlock(periph);
1207 cam_periph_release(periph);
1211 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1214 softc = (struct da_softc *)periph->softc;
1215 softc->flags |= DA_FLAG_OPEN;
1216 softc->flags &= ~DA_FLAG_PACK_INVALID;
1220 /* Wait for the disk size update. */
1221 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1224 xpt_print(periph->path, "unable to retrieve capacity data");
1226 if (periph->flags & CAM_PERIPH_INVALID ||
1227 softc->disk->d_sectorsize == 0 ||
1228 softc->disk->d_mediasize == 0)
1231 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1232 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1233 daprevent(periph, PR_PREVENT);
1236 softc->flags |= DA_FLAG_SAW_MEDIA;
1238 cam_periph_unhold(periph);
1239 cam_periph_unlock(periph);
1242 softc->flags &= ~DA_FLAG_OPEN;
1243 cam_periph_release(periph);
1250 daclose(struct disk *dp)
1252 struct cam_periph *periph;
1253 struct da_softc *softc;
1256 periph = (struct cam_periph *)dp->d_drv1;
1257 cam_periph_lock(periph);
1258 if (cam_periph_hold(periph, PRIBIO) != 0) {
1259 cam_periph_unlock(periph);
1260 cam_periph_release(periph);
1264 softc = (struct da_softc *)periph->softc;
1266 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1269 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1270 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1271 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1274 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1276 scsi_synchronize_cache(&ccb->csio,
1280 /*begin_lba*/0,/* Cover the whole disk */
1285 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1286 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1287 softc->disk->d_devstat);
1289 softc->flags &= ~DA_FLAG_DIRTY;
1290 xpt_release_ccb(ccb);
1294 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0) {
1295 if ((softc->quirks & DA_Q_NO_PREVENT) == 0)
1296 daprevent(periph, PR_ALLOW);
1298 * If we've got removeable media, mark the blocksize as
1299 * unavailable, since it could change when new media is
1302 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1305 softc->flags &= ~DA_FLAG_OPEN;
1306 cam_periph_unhold(periph);
1307 cam_periph_unlock(periph);
1308 cam_periph_release(periph);
1313 daschedule(struct cam_periph *periph)
1315 struct da_softc *softc = (struct da_softc *)periph->softc;
1318 if (softc->state != DA_STATE_NORMAL)
1321 /* Check if cam_periph_getccb() was called. */
1322 prio = periph->immediate_priority;
1324 /* Check if we have more work to do. */
1325 if (bioq_first(&softc->bio_queue) ||
1326 (!softc->delete_running && bioq_first(&softc->delete_queue)) ||
1328 prio = CAM_PRIORITY_NORMAL;
1331 /* Schedule CCB if any of above is true. */
1332 if (prio != CAM_PRIORITY_NONE)
1333 xpt_schedule(periph, prio);
1337 * Actually translate the requested transfer into one the physical driver
1338 * can understand. The transfer is described by a buf and will include
1339 * only one physical transfer.
1342 dastrategy(struct bio *bp)
1344 struct cam_periph *periph;
1345 struct da_softc *softc;
1347 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1348 softc = (struct da_softc *)periph->softc;
1350 cam_periph_lock(periph);
1353 * If the device has been made invalid, error out
1355 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1356 cam_periph_unlock(periph);
1357 biofinish(bp, NULL, ENXIO);
1361 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1364 * Place it in the queue of disk activities for this disk
1366 if (bp->bio_cmd == BIO_DELETE) {
1367 if (bp->bio_bcount == 0)
1370 bioq_disksort(&softc->delete_queue, bp);
1372 bioq_insert_tail(&softc->delete_queue, bp);
1373 } else if (DA_SIO) {
1374 bioq_disksort(&softc->bio_queue, bp);
1376 bioq_insert_tail(&softc->bio_queue, bp);
1380 * Schedule ourselves for performing the work.
1383 cam_periph_unlock(periph);
1389 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1391 struct cam_periph *periph;
1392 struct da_softc *softc;
1394 struct ccb_scsiio csio;
1399 periph = dp->d_drv1;
1400 softc = (struct da_softc *)periph->softc;
1401 cam_periph_lock(periph);
1402 secsize = softc->params.secsize;
1404 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1405 cam_periph_unlock(periph);
1410 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1411 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1412 scsi_read_write(&csio,
1416 /*read*/SCSI_RW_WRITE,
1418 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1421 /*data_ptr*/(u_int8_t *) virtual,
1422 /*dxfer_len*/length,
1423 /*sense_len*/SSD_FULL_SIZE,
1424 da_default_timeout * 1000);
1425 xpt_polled_action((union ccb *)&csio);
1427 error = cam_periph_error((union ccb *)&csio,
1428 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1429 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1430 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1431 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1433 printf("Aborting dump due to I/O error.\n");
1434 cam_periph_unlock(periph);
1439 * Sync the disk cache contents to the physical media.
1441 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1443 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1444 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1445 scsi_synchronize_cache(&csio,
1449 /*begin_lba*/0,/* Cover the whole disk */
1453 xpt_polled_action((union ccb *)&csio);
1455 error = cam_periph_error((union ccb *)&csio,
1456 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1457 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1458 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1459 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1461 xpt_print(periph->path, "Synchronize cache failed\n");
1463 cam_periph_unlock(periph);
1468 dagetattr(struct bio *bp)
1471 struct cam_periph *periph;
1473 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1474 cam_periph_lock(periph);
1475 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1477 cam_periph_unlock(periph);
1479 bp->bio_completed = bp->bio_length;
1489 * Install a global async callback. This callback will
1490 * receive async callbacks like "new device found".
1492 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1494 if (status != CAM_REQ_CMP) {
1495 printf("da: Failed to attach master async callback "
1496 "due to status 0x%x!\n", status);
1497 } else if (da_send_ordered) {
1499 /* Register our shutdown event handler */
1500 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1501 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1502 printf("dainit: shutdown event registration failed!\n");
1507 * Callback from GEOM, called when it has finished cleaning up its
1511 dadiskgonecb(struct disk *dp)
1513 struct cam_periph *periph;
1515 periph = (struct cam_periph *)dp->d_drv1;
1516 cam_periph_release(periph);
1520 daoninvalidate(struct cam_periph *periph)
1522 struct da_softc *softc;
1524 softc = (struct da_softc *)periph->softc;
1527 * De-register any async callbacks.
1529 xpt_register_async(0, daasync, periph, periph->path);
1531 softc->flags |= DA_FLAG_PACK_INVALID;
1534 * Return all queued I/O with ENXIO.
1535 * XXX Handle any transactions queued to the card
1536 * with XPT_ABORT_CCB.
1538 bioq_flush(&softc->bio_queue, NULL, ENXIO);
1539 bioq_flush(&softc->delete_queue, NULL, ENXIO);
1542 * Tell GEOM that we've gone away, we'll get a callback when it is
1543 * done cleaning up its resources.
1545 disk_gone(softc->disk);
1547 xpt_print(periph->path, "lost device - %d outstanding, %d refs\n",
1548 softc->outstanding_cmds, periph->refcount);
1552 dacleanup(struct cam_periph *periph)
1554 struct da_softc *softc;
1556 softc = (struct da_softc *)periph->softc;
1558 xpt_print(periph->path, "removing device entry\n");
1559 cam_periph_unlock(periph);
1562 * If we can't free the sysctl tree, oh well...
1564 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0
1565 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
1566 xpt_print(periph->path, "can't remove sysctl context\n");
1569 callout_drain(&softc->mediapoll_c);
1570 disk_destroy(softc->disk);
1571 callout_drain(&softc->sendordered_c);
1572 free(softc, M_DEVBUF);
1573 cam_periph_lock(periph);
1577 daasync(void *callback_arg, u_int32_t code,
1578 struct cam_path *path, void *arg)
1580 struct cam_periph *periph;
1581 struct da_softc *softc;
1583 periph = (struct cam_periph *)callback_arg;
1585 case AC_FOUND_DEVICE:
1587 struct ccb_getdev *cgd;
1590 cgd = (struct ccb_getdev *)arg;
1594 if (cgd->protocol != PROTO_SCSI)
1597 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1598 && SID_TYPE(&cgd->inq_data) != T_RBC
1599 && SID_TYPE(&cgd->inq_data) != T_OPTICAL)
1603 * Allocate a peripheral instance for
1604 * this device and start the probe
1607 status = cam_periph_alloc(daregister, daoninvalidate,
1609 "da", CAM_PERIPH_BIO,
1610 cgd->ccb_h.path, daasync,
1611 AC_FOUND_DEVICE, cgd);
1613 if (status != CAM_REQ_CMP
1614 && status != CAM_REQ_INPROG)
1615 printf("daasync: Unable to attach to new device "
1616 "due to status 0x%x\n", status);
1619 case AC_ADVINFO_CHANGED:
1623 buftype = (uintptr_t)arg;
1624 if (buftype == CDAI_TYPE_PHYS_PATH) {
1625 struct da_softc *softc;
1627 softc = periph->softc;
1628 disk_attr_changed(softc->disk, "GEOM::physpath",
1633 case AC_UNIT_ATTENTION:
1636 int error_code, sense_key, asc, ascq;
1638 softc = (struct da_softc *)periph->softc;
1639 ccb = (union ccb *)arg;
1642 * Handle all UNIT ATTENTIONs except our own,
1643 * as they will be handled by daerror().
1645 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1646 scsi_extract_sense_ccb(ccb,
1647 &error_code, &sense_key, &asc, &ascq)) {
1648 if (asc == 0x2A && ascq == 0x09) {
1649 xpt_print(ccb->ccb_h.path,
1650 "capacity data has changed\n");
1652 } else if (asc == 0x28 && ascq == 0x00)
1653 disk_media_changed(softc->disk, M_NOWAIT);
1655 cam_periph_async(periph, code, path, arg);
1659 softc = (struct da_softc *)periph->softc;
1661 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1670 struct ccb_hdr *ccbh;
1672 softc = (struct da_softc *)periph->softc;
1674 * Don't fail on the expected unit attention
1677 softc->flags |= DA_FLAG_RETRY_UA;
1678 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1679 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1685 cam_periph_async(periph, code, path, arg);
1689 dasysctlinit(void *context, int pending)
1691 struct cam_periph *periph;
1692 struct da_softc *softc;
1693 char tmpstr[80], tmpstr2[80];
1694 struct ccb_trans_settings cts;
1696 periph = (struct cam_periph *)context;
1698 * periph was held for us when this task was enqueued
1700 if (periph->flags & CAM_PERIPH_INVALID) {
1701 cam_periph_release(periph);
1705 softc = (struct da_softc *)periph->softc;
1706 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1707 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1709 sysctl_ctx_init(&softc->sysctl_ctx);
1710 softc->flags |= DA_FLAG_SCTX_INIT;
1711 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
1712 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1713 CTLFLAG_RD, 0, tmpstr);
1714 if (softc->sysctl_tree == NULL) {
1715 printf("dasysctlinit: unable to allocate sysctl tree\n");
1716 cam_periph_release(periph);
1721 * Now register the sysctl handler, so the user can change the value on
1724 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1725 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RW,
1726 softc, 0, dadeletemethodsysctl, "A",
1727 "BIO_DELETE execution method");
1728 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1729 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1730 softc, 0, dadeletemaxsysctl, "Q",
1731 "Maximum BIO_DELETE size");
1732 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1733 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1734 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1735 "Minimum CDB size");
1736 SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1737 OID_AUTO, "sort_io_queue", CTLFLAG_RW, &softc->sort_io_queue, 0,
1738 "Sort IO queue to try and optimise disk access patterns");
1740 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1741 SYSCTL_CHILDREN(softc->sysctl_tree),
1745 &softc->error_inject,
1747 "error_inject leaf");
1751 * Add some addressing info.
1753 memset(&cts, 0, sizeof (cts));
1754 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1755 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1756 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1757 cam_periph_lock(periph);
1758 xpt_action((union ccb *)&cts);
1759 cam_periph_unlock(periph);
1760 if (cts.ccb_h.status != CAM_REQ_CMP) {
1761 cam_periph_release(periph);
1764 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
1765 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
1766 if (fc->valid & CTS_FC_VALID_WWPN) {
1767 softc->wwpn = fc->wwpn;
1768 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1769 SYSCTL_CHILDREN(softc->sysctl_tree),
1770 OID_AUTO, "wwpn", CTLFLAG_RD,
1771 &softc->wwpn, "World Wide Port Name");
1774 cam_periph_release(periph);
1778 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
1782 struct da_softc *softc;
1784 softc = (struct da_softc *)arg1;
1786 value = softc->disk->d_delmaxsize;
1787 error = sysctl_handle_64(oidp, &value, 0, req);
1788 if ((error != 0) || (req->newptr == NULL))
1791 /* only accept values smaller than the calculated value */
1792 if (value > dadeletemaxsize(softc, softc->delete_method)) {
1795 softc->disk->d_delmaxsize = value;
1801 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
1805 value = *(int *)arg1;
1807 error = sysctl_handle_int(oidp, &value, 0, req);
1810 || (req->newptr == NULL))
1814 * Acceptable values here are 6, 10, 12 or 16.
1818 else if ((value > 6)
1821 else if ((value > 10)
1824 else if (value > 12)
1827 *(int *)arg1 = value;
1833 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
1837 softc->delete_method = delete_method;
1838 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
1839 softc->delete_func = da_delete_functions[delete_method];
1841 if (softc->delete_method > DA_DELETE_DISABLE)
1842 softc->disk->d_flags |= DISKFLAG_CANDELETE;
1844 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
1848 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
1852 switch(delete_method) {
1853 case DA_DELETE_UNMAP:
1854 sectors = (off_t)softc->unmap_max_lba * softc->unmap_max_ranges;
1856 case DA_DELETE_ATA_TRIM:
1857 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
1859 case DA_DELETE_WS16:
1860 sectors = (off_t)min(softc->ws_max_blks, WS16_MAX_BLKS);
1862 case DA_DELETE_ZERO:
1863 case DA_DELETE_WS10:
1864 sectors = (off_t)min(softc->ws_max_blks, WS10_MAX_BLKS);
1870 return (off_t)softc->params.secsize *
1871 min(sectors, (off_t)softc->params.sectors);
1875 daprobedone(struct cam_periph *periph, union ccb *ccb)
1877 struct da_softc *softc;
1879 softc = (struct da_softc *)periph->softc;
1881 dadeletemethodchoose(softc, DA_DELETE_NONE);
1883 if (bootverbose && (softc->flags & DA_FLAG_PROBED) == 0) {
1887 snprintf(buf, sizeof(buf), "Delete methods: <");
1889 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
1890 if (softc->delete_available & (1 << i)) {
1892 strlcat(buf, ",", sizeof(buf));
1896 strlcat(buf, da_delete_method_names[i],
1898 if (i == softc->delete_method) {
1899 strlcat(buf, "(*)", sizeof(buf));
1904 if (softc->delete_method == DA_DELETE_NONE)
1905 strlcat(buf, "NONE(*)", sizeof(buf));
1907 strlcat(buf, "DISABLED(*)", sizeof(buf));
1909 strlcat(buf, ">", sizeof(buf));
1910 printf("%s%d: %s\n", periph->periph_name,
1911 periph->unit_number, buf);
1915 * Since our peripheral may be invalidated by an error
1916 * above or an external event, we must release our CCB
1917 * before releasing the probe lock on the peripheral.
1918 * The peripheral will only go away once the last lock
1919 * is removed, and we need it around for the CCB release
1922 xpt_release_ccb(ccb);
1923 softc->state = DA_STATE_NORMAL;
1925 wakeup(&softc->disk->d_mediasize);
1926 if ((softc->flags & DA_FLAG_PROBED) == 0) {
1927 softc->flags |= DA_FLAG_PROBED;
1928 cam_periph_unhold(periph);
1930 cam_periph_release_locked(periph);
1934 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
1936 int i, delete_method;
1938 delete_method = default_method;
1941 * Use the pre-defined order to choose the best
1942 * performing delete.
1944 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
1945 if (softc->delete_available & (1 << i)) {
1946 dadeletemethodset(softc, i);
1950 dadeletemethodset(softc, delete_method);
1954 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
1958 struct da_softc *softc;
1959 int i, error, value;
1961 softc = (struct da_softc *)arg1;
1963 value = softc->delete_method;
1964 if (value < 0 || value > DA_DELETE_MAX)
1967 p = da_delete_method_names[value];
1968 strncpy(buf, p, sizeof(buf));
1969 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1970 if (error != 0 || req->newptr == NULL)
1972 for (i = 0; i <= DA_DELETE_MAX; i++) {
1973 if (!(softc->delete_available & (1 << i)) ||
1974 strcmp(buf, da_delete_method_names[i]) != 0)
1976 dadeletemethodset(softc, i);
1983 daregister(struct cam_periph *periph, void *arg)
1985 struct da_softc *softc;
1986 struct ccb_pathinq cpi;
1987 struct ccb_getdev *cgd;
1991 cgd = (struct ccb_getdev *)arg;
1993 printf("daregister: no getdev CCB, can't register device\n");
1994 return(CAM_REQ_CMP_ERR);
1997 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2000 if (softc == NULL) {
2001 printf("daregister: Unable to probe new device. "
2002 "Unable to allocate softc\n");
2003 return(CAM_REQ_CMP_ERR);
2006 LIST_INIT(&softc->pending_ccbs);
2007 softc->state = DA_STATE_PROBE_RC;
2008 bioq_init(&softc->bio_queue);
2009 bioq_init(&softc->delete_queue);
2010 bioq_init(&softc->delete_run_queue);
2011 if (SID_IS_REMOVABLE(&cgd->inq_data))
2012 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2013 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2014 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2015 softc->ws_max_blks = WS16_MAX_BLKS;
2016 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2017 softc->sort_io_queue = -1;
2019 periph->softc = softc;
2022 * See if this device has any quirks.
2024 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2025 (caddr_t)da_quirk_table,
2026 sizeof(da_quirk_table)/sizeof(*da_quirk_table),
2027 sizeof(*da_quirk_table), scsi_inquiry_match);
2030 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2032 softc->quirks = DA_Q_NONE;
2034 /* Check if the SIM does not want 6 byte commands */
2035 bzero(&cpi, sizeof(cpi));
2036 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2037 cpi.ccb_h.func_code = XPT_PATH_INQ;
2038 xpt_action((union ccb *)&cpi);
2039 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2040 softc->quirks |= DA_Q_NO_6_BYTE;
2042 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2045 * Take an exclusive refcount on the periph while dastart is called
2046 * to finish the probe. The reference will be dropped in dadone at
2049 (void)cam_periph_hold(periph, PRIBIO);
2052 * Schedule a periodic event to occasionally send an
2053 * ordered tag to a device.
2055 callout_init_mtx(&softc->sendordered_c, periph->sim->mtx, 0);
2056 callout_reset(&softc->sendordered_c,
2057 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2058 dasendorderedtag, softc);
2060 cam_periph_unlock(periph);
2062 * RBC devices don't have to support READ(6), only READ(10).
2064 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2065 softc->minimum_cmd_size = 10;
2067 softc->minimum_cmd_size = 6;
2070 * Load the user's default, if any.
2072 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2073 periph->unit_number);
2074 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2077 * 6, 10, 12 and 16 are the currently permissible values.
2079 if (softc->minimum_cmd_size < 6)
2080 softc->minimum_cmd_size = 6;
2081 else if ((softc->minimum_cmd_size > 6)
2082 && (softc->minimum_cmd_size <= 10))
2083 softc->minimum_cmd_size = 10;
2084 else if ((softc->minimum_cmd_size > 10)
2085 && (softc->minimum_cmd_size <= 12))
2086 softc->minimum_cmd_size = 12;
2087 else if (softc->minimum_cmd_size > 12)
2088 softc->minimum_cmd_size = 16;
2090 /* Predict whether device may support READ CAPACITY(16). */
2091 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2092 (softc->quirks & DA_Q_NO_RC16) == 0) {
2093 softc->flags |= DA_FLAG_CAN_RC16;
2094 softc->state = DA_STATE_PROBE_RC16;
2098 * Register this media as a disk.
2100 softc->disk = disk_alloc();
2101 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2102 periph->unit_number, 0,
2103 DEVSTAT_BS_UNAVAILABLE,
2104 SID_TYPE(&cgd->inq_data) |
2105 XPORT_DEVSTAT_TYPE(cpi.transport),
2106 DEVSTAT_PRIORITY_DISK);
2107 softc->disk->d_open = daopen;
2108 softc->disk->d_close = daclose;
2109 softc->disk->d_strategy = dastrategy;
2110 softc->disk->d_dump = dadump;
2111 softc->disk->d_getattr = dagetattr;
2112 softc->disk->d_gone = dadiskgonecb;
2113 softc->disk->d_name = "da";
2114 softc->disk->d_drv1 = periph;
2116 softc->disk->d_maxsize = DFLTPHYS; /* traditional default */
2117 else if (cpi.maxio > MAXPHYS)
2118 softc->disk->d_maxsize = MAXPHYS; /* for safety */
2120 softc->disk->d_maxsize = cpi.maxio;
2121 softc->disk->d_unit = periph->unit_number;
2122 softc->disk->d_flags = 0;
2123 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2124 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2125 if ((cpi.hba_misc & PIM_UNMAPPED) != 0)
2126 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2127 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2128 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2129 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2130 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2131 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2132 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2133 softc->disk->d_hba_vendor = cpi.hba_vendor;
2134 softc->disk->d_hba_device = cpi.hba_device;
2135 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2136 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2139 * Acquire a reference to the periph before we register with GEOM.
2140 * We'll release this reference once GEOM calls us back (via
2141 * dadiskgonecb()) telling us that our provider has been freed.
2143 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2144 xpt_print(periph->path, "%s: lost periph during "
2145 "registration!\n", __func__);
2146 cam_periph_lock(periph);
2147 return (CAM_REQ_CMP_ERR);
2150 disk_create(softc->disk, DISK_VERSION);
2151 cam_periph_lock(periph);
2154 * Add async callbacks for events of interest.
2155 * I don't bother checking if this fails as,
2156 * in most cases, the system will function just
2157 * fine without them and the only alternative
2158 * would be to not attach the device on failure.
2160 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2161 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION,
2162 daasync, periph, periph->path);
2165 * Emit an attribute changed notification just in case
2166 * physical path information arrived before our async
2167 * event handler was registered, but after anyone attaching
2168 * to our disk device polled it.
2170 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2173 * Schedule a periodic media polling events.
2175 callout_init_mtx(&softc->mediapoll_c, periph->sim->mtx, 0);
2176 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2177 (cgd->inq_flags & SID_AEN) == 0 &&
2178 da_poll_period != 0)
2179 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2180 damediapoll, periph);
2182 xpt_schedule(periph, CAM_PRIORITY_DEV);
2184 return(CAM_REQ_CMP);
2188 dastart(struct cam_periph *periph, union ccb *start_ccb)
2190 struct da_softc *softc;
2192 softc = (struct da_softc *)periph->softc;
2194 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2197 switch (softc->state) {
2198 case DA_STATE_NORMAL:
2203 /* Execute immediate CCB if waiting. */
2204 if (periph->immediate_priority <= periph->pinfo.priority) {
2205 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2206 ("queuing for immediate ccb\n"));
2207 start_ccb->ccb_h.ccb_state = DA_CCB_WAITING;
2208 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
2210 periph->immediate_priority = CAM_PRIORITY_NONE;
2211 wakeup(&periph->ccb_list);
2212 /* May have more work to do, so ensure we stay scheduled */
2217 /* Run BIO_DELETE if not running yet. */
2218 if (!softc->delete_running &&
2219 (bp = bioq_first(&softc->delete_queue)) != NULL) {
2220 if (softc->delete_func != NULL) {
2221 softc->delete_func(periph, start_ccb, bp);
2224 bioq_flush(&softc->delete_queue, NULL, 0);
2229 /* Run regular command. */
2230 bp = bioq_takefirst(&softc->bio_queue);
2234 scsi_test_unit_ready(&start_ccb->csio,
2235 /*retries*/ da_retry_count,
2239 da_default_timeout * 1000);
2240 start_ccb->ccb_h.ccb_bp = NULL;
2241 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2242 xpt_action(start_ccb);
2244 xpt_release_ccb(start_ccb);
2249 cam_periph_release_locked(periph);
2252 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2253 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2254 softc->flags &= ~DA_FLAG_NEED_OTAG;
2255 softc->ordered_tag_count++;
2256 tag_code = MSG_ORDERED_Q_TAG;
2258 tag_code = MSG_SIMPLE_Q_TAG;
2261 switch (bp->bio_cmd) {
2263 softc->flags |= DA_FLAG_DIRTY;
2266 scsi_read_write(&start_ccb->csio,
2267 /*retries*/da_retry_count,
2269 /*tag_action*/tag_code,
2270 /*read_op*/(bp->bio_cmd == BIO_READ ?
2271 SCSI_RW_READ : SCSI_RW_WRITE) |
2272 ((bp->bio_flags & BIO_UNMAPPED) != 0 ?
2275 softc->minimum_cmd_size,
2276 /*lba*/bp->bio_pblkno,
2277 /*block_count*/bp->bio_bcount /
2278 softc->params.secsize,
2279 /*data_ptr*/ (bp->bio_flags &
2280 BIO_UNMAPPED) != 0 ? (void *)bp :
2282 /*dxfer_len*/ bp->bio_bcount,
2283 /*sense_len*/SSD_FULL_SIZE,
2284 da_default_timeout * 1000);
2288 * BIO_FLUSH doesn't currently communicate
2289 * range data, so we synchronize the cache
2290 * over the whole disk. We also force
2291 * ordered tag semantics the flush applies
2292 * to all previously queued I/O.
2294 scsi_synchronize_cache(&start_ccb->csio,
2301 da_default_timeout*1000);
2304 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
2308 * Block out any asyncronous callbacks
2309 * while we touch the pending ccb list.
2311 LIST_INSERT_HEAD(&softc->pending_ccbs,
2312 &start_ccb->ccb_h, periph_links.le);
2313 softc->outstanding_cmds++;
2315 /* We expect a unit attention from this device */
2316 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
2317 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
2318 softc->flags &= ~DA_FLAG_RETRY_UA;
2321 start_ccb->ccb_h.ccb_bp = bp;
2322 xpt_action(start_ccb);
2324 /* May have more work to do, so ensure we stay scheduled */
2328 case DA_STATE_PROBE_RC:
2330 struct scsi_read_capacity_data *rcap;
2332 rcap = (struct scsi_read_capacity_data *)
2333 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
2335 printf("dastart: Couldn't malloc read_capacity data\n");
2336 /* da_free_periph??? */
2339 scsi_read_capacity(&start_ccb->csio,
2340 /*retries*/da_retry_count,
2346 start_ccb->ccb_h.ccb_bp = NULL;
2347 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
2348 xpt_action(start_ccb);
2351 case DA_STATE_PROBE_RC16:
2353 struct scsi_read_capacity_data_long *rcaplong;
2355 rcaplong = (struct scsi_read_capacity_data_long *)
2356 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
2357 if (rcaplong == NULL) {
2358 printf("dastart: Couldn't malloc read_capacity data\n");
2359 /* da_free_periph??? */
2362 scsi_read_capacity_16(&start_ccb->csio,
2363 /*retries*/ da_retry_count,
2365 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2370 /*sense_len*/ SSD_FULL_SIZE,
2371 /*timeout*/ da_default_timeout * 1000);
2372 start_ccb->ccb_h.ccb_bp = NULL;
2373 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
2374 xpt_action(start_ccb);
2377 case DA_STATE_PROBE_LBP:
2379 struct scsi_vpd_logical_block_prov *lbp;
2381 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
2383 * If we get here we don't support any SBC-3 delete
2384 * methods with UNMAP as the Logical Block Provisioning
2385 * VPD page support is required for devices which
2386 * support it according to T10/1799-D Revision 31
2387 * however older revisions of the spec don't mandate
2388 * this so we currently don't remove these methods
2389 * from the available set.
2391 softc->state = DA_STATE_PROBE_BLK_LIMITS;
2395 lbp = (struct scsi_vpd_logical_block_prov *)
2396 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
2399 printf("dastart: Couldn't malloc lbp data\n");
2400 /* da_free_periph??? */
2404 scsi_inquiry(&start_ccb->csio,
2405 /*retries*/da_retry_count,
2407 /*tag_action*/MSG_SIMPLE_Q_TAG,
2408 /*inq_buf*/(u_int8_t *)lbp,
2409 /*inq_len*/sizeof(*lbp),
2411 /*page_code*/SVPD_LBP,
2412 /*sense_len*/SSD_MIN_SIZE,
2413 /*timeout*/da_default_timeout * 1000);
2414 start_ccb->ccb_h.ccb_bp = NULL;
2415 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
2416 xpt_action(start_ccb);
2419 case DA_STATE_PROBE_BLK_LIMITS:
2421 struct scsi_vpd_block_limits *block_limits;
2423 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
2424 /* Not supported skip to next probe */
2425 softc->state = DA_STATE_PROBE_BDC;
2429 block_limits = (struct scsi_vpd_block_limits *)
2430 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
2432 if (block_limits == NULL) {
2433 printf("dastart: Couldn't malloc block_limits data\n");
2434 /* da_free_periph??? */
2438 scsi_inquiry(&start_ccb->csio,
2439 /*retries*/da_retry_count,
2441 /*tag_action*/MSG_SIMPLE_Q_TAG,
2442 /*inq_buf*/(u_int8_t *)block_limits,
2443 /*inq_len*/sizeof(*block_limits),
2445 /*page_code*/SVPD_BLOCK_LIMITS,
2446 /*sense_len*/SSD_MIN_SIZE,
2447 /*timeout*/da_default_timeout * 1000);
2448 start_ccb->ccb_h.ccb_bp = NULL;
2449 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
2450 xpt_action(start_ccb);
2453 case DA_STATE_PROBE_BDC:
2455 struct scsi_vpd_block_characteristics *bdc;
2457 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
2458 softc->state = DA_STATE_PROBE_ATA;
2462 bdc = (struct scsi_vpd_block_characteristics *)
2463 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
2466 printf("dastart: Couldn't malloc bdc data\n");
2467 /* da_free_periph??? */
2471 scsi_inquiry(&start_ccb->csio,
2472 /*retries*/da_retry_count,
2474 /*tag_action*/MSG_SIMPLE_Q_TAG,
2475 /*inq_buf*/(u_int8_t *)bdc,
2476 /*inq_len*/sizeof(*bdc),
2478 /*page_code*/SVPD_BDC,
2479 /*sense_len*/SSD_MIN_SIZE,
2480 /*timeout*/da_default_timeout * 1000);
2481 start_ccb->ccb_h.ccb_bp = NULL;
2482 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
2483 xpt_action(start_ccb);
2486 case DA_STATE_PROBE_ATA:
2488 struct ata_params *ata_params;
2490 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2491 daprobedone(periph, start_ccb);
2495 ata_params = (struct ata_params*)
2496 malloc(sizeof(*ata_params), M_SCSIDA, M_NOWAIT|M_ZERO);
2498 if (ata_params == NULL) {
2499 printf("dastart: Couldn't malloc ata_params data\n");
2500 /* da_free_periph??? */
2504 scsi_ata_identify(&start_ccb->csio,
2505 /*retries*/da_retry_count,
2507 /*tag_action*/MSG_SIMPLE_Q_TAG,
2508 /*data_ptr*/(u_int8_t *)ata_params,
2509 /*dxfer_len*/sizeof(*ata_params),
2510 /*sense_len*/SSD_FULL_SIZE,
2511 /*timeout*/da_default_timeout * 1000);
2512 start_ccb->ccb_h.ccb_bp = NULL;
2513 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
2514 xpt_action(start_ccb);
2521 * In each of the methods below, while its the caller's
2522 * responsibility to ensure the request will fit into a
2523 * single device request, we might have changed the delete
2524 * method due to the device incorrectly advertising either
2525 * its supported methods or limits.
2527 * To prevent this causing further issues we validate the
2528 * against the methods limits, and warn which would
2529 * otherwise be unnecessary.
2532 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2534 struct da_softc *softc = (struct da_softc *)periph->softc;;
2536 uint8_t *buf = softc->unmap_buf;
2537 uint64_t lba, lastlba = (uint64_t)-1;
2538 uint64_t totalcount = 0;
2540 uint32_t lastcount = 0, c;
2541 uint32_t off, ranges = 0;
2544 * Currently this doesn't take the UNMAP
2545 * Granularity and Granularity Alignment
2546 * fields into account.
2548 * This could result in both unoptimal unmap
2549 * requests as as well as UNMAP calls unmapping
2550 * fewer LBA's than requested.
2553 softc->delete_running = 1;
2554 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
2557 bioq_remove(&softc->delete_queue, bp1);
2559 bioq_insert_tail(&softc->delete_run_queue, bp1);
2560 lba = bp1->bio_pblkno;
2561 count = bp1->bio_bcount / softc->params.secsize;
2563 /* Try to extend the previous range. */
2564 if (lba == lastlba) {
2565 c = min(count, softc->unmap_max_lba - lastcount);
2567 off = ((ranges - 1) * UNMAP_RANGE_SIZE) +
2569 scsi_ulto4b(lastcount, &buf[off + 8]);
2576 c = min(count, softc->unmap_max_lba);
2577 if (totalcount + c > softc->unmap_max_lba ||
2578 ranges >= softc->unmap_max_ranges) {
2579 xpt_print(periph->path,
2580 "%s issuing short delete %ld > %ld"
2582 da_delete_method_desc[softc->delete_method],
2583 totalcount + c, softc->unmap_max_lba,
2584 ranges, softc->unmap_max_ranges);
2587 off = (ranges * UNMAP_RANGE_SIZE) + UNMAP_HEAD_SIZE;
2588 scsi_u64to8b(lba, &buf[off + 0]);
2589 scsi_ulto4b(c, &buf[off + 8]);
2597 bp1 = bioq_first(&softc->delete_queue);
2598 if (bp1 == NULL || ranges >= softc->unmap_max_ranges ||
2599 totalcount + bp1->bio_bcount /
2600 softc->params.secsize > softc->unmap_max_lba)
2603 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
2604 scsi_ulto2b(ranges * 16, &buf[2]);
2606 scsi_unmap(&ccb->csio,
2607 /*retries*/da_retry_count,
2609 /*tag_action*/MSG_SIMPLE_Q_TAG,
2612 /*dxfer_len*/ ranges * 16 + 8,
2613 /*sense_len*/SSD_FULL_SIZE,
2614 da_default_timeout * 1000);
2615 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2619 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2621 struct da_softc *softc = (struct da_softc *)periph->softc;
2623 uint8_t *buf = softc->unmap_buf;
2624 uint64_t lastlba = (uint64_t)-1;
2627 uint32_t lastcount = 0, c, requestcount;
2628 int ranges = 0, off, block_count;
2630 softc->delete_running = 1;
2631 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
2634 bioq_remove(&softc->delete_queue, bp1);
2636 bioq_insert_tail(&softc->delete_run_queue, bp1);
2637 lba = bp1->bio_pblkno;
2638 count = bp1->bio_bcount / softc->params.secsize;
2639 requestcount = count;
2641 /* Try to extend the previous range. */
2642 if (lba == lastlba) {
2643 c = min(count, ATA_DSM_RANGE_MAX - lastcount);
2645 off = (ranges - 1) * 8;
2646 buf[off + 6] = lastcount & 0xff;
2647 buf[off + 7] = (lastcount >> 8) & 0xff;
2653 c = min(count, ATA_DSM_RANGE_MAX);
2656 buf[off + 0] = lba & 0xff;
2657 buf[off + 1] = (lba >> 8) & 0xff;
2658 buf[off + 2] = (lba >> 16) & 0xff;
2659 buf[off + 3] = (lba >> 24) & 0xff;
2660 buf[off + 4] = (lba >> 32) & 0xff;
2661 buf[off + 5] = (lba >> 40) & 0xff;
2662 buf[off + 6] = c & 0xff;
2663 buf[off + 7] = (c >> 8) & 0xff;
2668 if (count != 0 && ranges == softc->trim_max_ranges) {
2669 xpt_print(periph->path,
2670 "%s issuing short delete %ld > %ld",
2671 da_delete_method_desc[softc->delete_method],
2673 (softc->trim_max_ranges - ranges) *
2679 bp1 = bioq_first(&softc->delete_queue);
2680 if (bp1 == NULL || bp1->bio_bcount / softc->params.secsize >
2681 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX)
2685 block_count = (ranges + ATA_DSM_BLK_RANGES - 1) / ATA_DSM_BLK_RANGES;
2686 scsi_ata_trim(&ccb->csio,
2687 /*retries*/da_retry_count,
2689 /*tag_action*/MSG_SIMPLE_Q_TAG,
2692 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
2693 /*sense_len*/SSD_FULL_SIZE,
2694 da_default_timeout * 1000);
2695 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2699 * We calculate ws_max_blks here based off d_delmaxsize instead
2700 * of using softc->ws_max_blks as it is absolute max for the
2701 * device not the protocol max which may well be lower
2704 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2706 struct da_softc *softc;
2708 uint64_t ws_max_blks;
2710 uint64_t count; /* forward compat with WS32 */
2712 softc = (struct da_softc *)periph->softc;
2713 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
2714 softc->delete_running = 1;
2715 lba = bp->bio_pblkno;
2719 bioq_remove(&softc->delete_queue, bp1);
2721 bioq_insert_tail(&softc->delete_run_queue, bp1);
2722 count += bp1->bio_bcount / softc->params.secsize;
2723 if (count > ws_max_blks) {
2724 count = min(count, ws_max_blks);
2725 xpt_print(periph->path,
2726 "%s issuing short delete %ld > %ld",
2727 da_delete_method_desc[softc->delete_method],
2728 count, ws_max_blks);
2731 bp1 = bioq_first(&softc->delete_queue);
2732 if (bp1 == NULL || lba + count != bp1->bio_pblkno ||
2733 count + bp1->bio_bcount /
2734 softc->params.secsize > ws_max_blks)
2738 scsi_write_same(&ccb->csio,
2739 /*retries*/da_retry_count,
2741 /*tag_action*/MSG_SIMPLE_Q_TAG,
2742 /*byte2*/softc->delete_method ==
2743 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
2744 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
2746 /*block_count*/count,
2747 /*data_ptr*/ __DECONST(void *, zero_region),
2748 /*dxfer_len*/ softc->params.secsize,
2749 /*sense_len*/SSD_FULL_SIZE,
2750 da_default_timeout * 1000);
2751 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2755 cmd6workaround(union ccb *ccb)
2757 struct scsi_rw_6 cmd6;
2758 struct scsi_rw_10 *cmd10;
2759 struct da_softc *softc;
2764 cdb = ccb->csio.cdb_io.cdb_bytes;
2765 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
2767 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
2768 da_delete_methods old_method = softc->delete_method;
2771 * Typically there are two reasons for failure here
2772 * 1. Delete method was detected as supported but isn't
2773 * 2. Delete failed due to invalid params e.g. too big
2775 * While we will attempt to choose an alternative delete method
2776 * this may result in short deletes if the existing delete
2777 * requests from geom are big for the new method choosen.
2779 * This method assumes that the error which triggered this
2780 * will not retry the io otherwise a panic will occur
2782 dadeleteflag(softc, old_method, 0);
2783 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
2784 if (softc->delete_method == DA_DELETE_DISABLE)
2785 xpt_print(ccb->ccb_h.path,
2786 "%s failed, disabling BIO_DELETE\n",
2787 da_delete_method_desc[old_method]);
2789 xpt_print(ccb->ccb_h.path,
2790 "%s failed, switching to %s BIO_DELETE\n",
2791 da_delete_method_desc[old_method],
2792 da_delete_method_desc[softc->delete_method]);
2795 while ((bp = bioq_takefirst(&softc->delete_run_queue))
2797 bioq_disksort(&softc->delete_queue, bp);
2799 while ((bp = bioq_takefirst(&softc->delete_run_queue))
2801 bioq_insert_tail(&softc->delete_queue, bp);
2803 bioq_insert_tail(&softc->delete_queue,
2804 (struct bio *)ccb->ccb_h.ccb_bp);
2805 ccb->ccb_h.ccb_bp = NULL;
2809 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
2810 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
2811 (*cdb == PREVENT_ALLOW) &&
2812 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
2814 xpt_print(ccb->ccb_h.path,
2815 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
2816 softc->quirks |= DA_Q_NO_PREVENT;
2820 /* Detect unsupported SYNCHRONIZE CACHE(10). */
2821 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
2822 (*cdb == SYNCHRONIZE_CACHE) &&
2823 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
2825 xpt_print(ccb->ccb_h.path,
2826 "SYNCHRONIZE CACHE(10) not supported.\n");
2827 softc->quirks |= DA_Q_NO_SYNC_CACHE;
2828 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
2832 /* Translation only possible if CDB is an array and cmd is R/W6 */
2833 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
2834 (*cdb != READ_6 && *cdb != WRITE_6))
2837 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
2838 "increasing minimum_cmd_size to 10.\n");
2839 softc->minimum_cmd_size = 10;
2841 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
2842 cmd10 = (struct scsi_rw_10 *)cdb;
2843 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
2845 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
2846 cmd10->reserved = 0;
2847 scsi_ulto2b(cmd6.length, cmd10->length);
2848 cmd10->control = cmd6.control;
2849 ccb->csio.cdb_len = sizeof(*cmd10);
2851 /* Requeue request, unfreezing queue if necessary */
2852 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
2853 ccb->ccb_h.status = CAM_REQUEUE_REQ;
2856 cam_release_devq(ccb->ccb_h.path,
2860 /*getcount_only*/0);
2866 dadone(struct cam_periph *periph, union ccb *done_ccb)
2868 struct da_softc *softc;
2869 struct ccb_scsiio *csio;
2873 softc = (struct da_softc *)periph->softc;
2874 priority = done_ccb->ccb_h.pinfo.priority;
2876 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
2878 csio = &done_ccb->csio;
2879 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
2881 case DA_CCB_BUFFER_IO:
2884 struct bio *bp, *bp1;
2886 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
2887 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2891 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
2896 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
2897 if (error == ERESTART) {
2899 * A retry was scheduled, so
2904 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
2909 * return all queued I/O with EIO, so that
2910 * the client can retry these I/Os in the
2911 * proper order should it attempt to recover.
2916 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
2918 * Catastrophic error. Mark our pack as
2922 * XXX See if this is really a media
2925 xpt_print(periph->path,
2926 "Invalidating pack\n");
2927 softc->flags |= DA_FLAG_PACK_INVALID;
2928 queued_error = ENXIO;
2930 bioq_flush(&softc->bio_queue, NULL,
2933 bp->bio_error = error;
2934 bp->bio_resid = bp->bio_bcount;
2935 bp->bio_flags |= BIO_ERROR;
2937 } else if (bp != NULL) {
2938 bp->bio_resid = csio->resid;
2940 if (bp->bio_resid != 0)
2941 bp->bio_flags |= BIO_ERROR;
2943 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2944 cam_release_devq(done_ccb->ccb_h.path,
2948 /*getcount_only*/0);
2949 } else if (bp != NULL) {
2950 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2951 panic("REQ_CMP with QFRZN");
2952 bp->bio_resid = csio->resid;
2953 if (csio->resid > 0)
2954 bp->bio_flags |= BIO_ERROR;
2955 if (softc->error_inject != 0) {
2956 bp->bio_error = softc->error_inject;
2957 bp->bio_resid = bp->bio_bcount;
2958 bp->bio_flags |= BIO_ERROR;
2959 softc->error_inject = 0;
2965 * Block out any asyncronous callbacks
2966 * while we touch the pending ccb list.
2968 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
2969 softc->outstanding_cmds--;
2970 if (softc->outstanding_cmds == 0)
2971 softc->flags |= DA_FLAG_WENT_IDLE;
2973 if (state == DA_CCB_DELETE) {
2974 while ((bp1 = bioq_takefirst(&softc->delete_run_queue))
2976 bp1->bio_resid = bp->bio_resid;
2977 bp1->bio_error = bp->bio_error;
2978 if (bp->bio_flags & BIO_ERROR)
2979 bp1->bio_flags |= BIO_ERROR;
2982 softc->delete_running = 0;
2986 } else if (bp != NULL)
2990 case DA_CCB_PROBE_RC:
2991 case DA_CCB_PROBE_RC16:
2993 struct scsi_read_capacity_data *rdcap;
2994 struct scsi_read_capacity_data_long *rcaplong;
2995 char announce_buf[80];
3001 if (state == DA_CCB_PROBE_RC)
3002 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
3004 rcaplong = (struct scsi_read_capacity_data_long *)
3007 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3008 struct disk_params *dp;
3009 uint32_t block_size;
3011 u_int lbppbe; /* LB per physical block exponent. */
3012 u_int lalba; /* Lowest aligned LBA. */
3014 if (state == DA_CCB_PROBE_RC) {
3015 block_size = scsi_4btoul(rdcap->length);
3016 maxsector = scsi_4btoul(rdcap->addr);
3021 * According to SBC-2, if the standard 10
3022 * byte READ CAPACITY command returns 2^32,
3023 * we should issue the 16 byte version of
3024 * the command, since the device in question
3025 * has more sectors than can be represented
3026 * with the short version of the command.
3028 if (maxsector == 0xffffffff) {
3029 free(rdcap, M_SCSIDA);
3030 xpt_release_ccb(done_ccb);
3031 softc->state = DA_STATE_PROBE_RC16;
3032 xpt_schedule(periph, priority);
3036 block_size = scsi_4btoul(rcaplong->length);
3037 maxsector = scsi_8btou64(rcaplong->addr);
3038 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
3039 lalba = scsi_2btoul(rcaplong->lalba_lbp);
3043 * Because GEOM code just will panic us if we
3044 * give them an 'illegal' value we'll avoid that
3047 if (block_size == 0 && maxsector == 0) {
3048 snprintf(announce_buf, sizeof(announce_buf),
3050 } else if (block_size >= MAXPHYS || block_size == 0) {
3051 xpt_print(periph->path,
3052 "unsupportable block size %ju\n",
3053 (uintmax_t) block_size);
3054 announce_buf[0] = '\0';
3055 cam_periph_invalidate(periph);
3058 * We pass rcaplong into dasetgeom(),
3059 * because it will only use it if it is
3062 dasetgeom(periph, block_size, maxsector,
3063 rcaplong, sizeof(*rcaplong));
3064 lbp = (lalba & SRC16_LBPME_A);
3065 dp = &softc->params;
3066 snprintf(announce_buf, sizeof(announce_buf),
3067 "%juMB (%ju %u byte sectors: %dH %dS/T "
3069 (((uintmax_t)dp->secsize *
3070 dp->sectors) / (1024*1024)),
3071 (uintmax_t)dp->sectors,
3072 dp->secsize, dp->heads,
3073 dp->secs_per_track, dp->cylinders);
3078 announce_buf[0] = '\0';
3081 * Retry any UNIT ATTENTION type errors. They
3082 * are expected at boot.
3084 error = daerror(done_ccb, CAM_RETRY_SELTO,
3085 SF_RETRY_UA|SF_NO_PRINT);
3086 if (error == ERESTART) {
3088 * A retry was scheuled, so
3092 } else if (error != 0) {
3094 int sense_key, error_code;
3097 struct ccb_getdev cgd;
3099 /* Don't wedge this device's queue */
3100 status = done_ccb->ccb_h.status;
3101 if ((status & CAM_DEV_QFRZN) != 0)
3102 cam_release_devq(done_ccb->ccb_h.path,
3106 /*getcount_only*/0);
3109 xpt_setup_ccb(&cgd.ccb_h,
3110 done_ccb->ccb_h.path,
3111 CAM_PRIORITY_NORMAL);
3112 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
3113 xpt_action((union ccb *)&cgd);
3115 if (scsi_extract_sense_ccb(done_ccb,
3116 &error_code, &sense_key, &asc, &ascq))
3122 * If we tried READ CAPACITY(16) and failed,
3123 * fallback to READ CAPACITY(10).
3125 if ((state == DA_CCB_PROBE_RC16) &&
3126 (softc->flags & DA_FLAG_CAN_RC16) &&
3127 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
3130 (error_code == SSD_CURRENT_ERROR) &&
3131 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
3132 softc->flags &= ~DA_FLAG_CAN_RC16;
3133 free(rdcap, M_SCSIDA);
3134 xpt_release_ccb(done_ccb);
3135 softc->state = DA_STATE_PROBE_RC;
3136 xpt_schedule(periph, priority);
3140 * Attach to anything that claims to be a
3141 * direct access or optical disk device,
3142 * as long as it doesn't return a "Logical
3143 * unit not supported" (0x25) error.
3145 if ((have_sense) && (asc != 0x25)
3146 && (error_code == SSD_CURRENT_ERROR)) {
3147 const char *sense_key_desc;
3148 const char *asc_desc;
3150 scsi_sense_desc(sense_key, asc, ascq,
3154 snprintf(announce_buf,
3155 sizeof(announce_buf),
3156 "Attempt to query device "
3157 "size failed: %s, %s",
3165 xpt_print(periph->path,
3166 "got CAM status %#x\n",
3167 done_ccb->ccb_h.status);
3170 xpt_print(periph->path, "fatal error, "
3171 "failed to attach to device\n");
3174 * Free up resources.
3176 cam_periph_invalidate(periph);
3180 free(csio->data_ptr, M_SCSIDA);
3181 if (announce_buf[0] != '\0' && ((softc->flags & DA_FLAG_PROBED) == 0)) {
3183 * Create our sysctl variables, now that we know
3184 * we have successfully attached.
3186 /* increase the refcount */
3187 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
3188 taskqueue_enqueue(taskqueue_thread,
3189 &softc->sysctl_task);
3190 xpt_announce_periph(periph, announce_buf);
3191 xpt_announce_quirks(periph, softc->quirks,
3194 xpt_print(periph->path, "fatal error, "
3195 "could not acquire reference count\n");
3199 /* Ensure re-probe doesn't see old delete. */
3200 softc->delete_available = 0;
3203 * Based on older SBC-3 spec revisions
3204 * any of the UNMAP methods "may" be
3205 * available via LBP given this flag so
3206 * we flag all of them as availble and
3207 * then remove those which further
3208 * probes confirm aren't available
3211 * We could also check readcap(16) p_type
3212 * flag to exclude one or more invalid
3213 * write same (X) types here
3215 dadeleteflag(softc, DA_DELETE_WS16, 1);
3216 dadeleteflag(softc, DA_DELETE_WS10, 1);
3217 dadeleteflag(softc, DA_DELETE_ZERO, 1);
3218 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
3220 xpt_release_ccb(done_ccb);
3221 softc->state = DA_STATE_PROBE_LBP;
3222 xpt_schedule(periph, priority);
3226 xpt_release_ccb(done_ccb);
3227 softc->state = DA_STATE_PROBE_BDC;
3228 xpt_schedule(periph, priority);
3231 case DA_CCB_PROBE_LBP:
3233 struct scsi_vpd_logical_block_prov *lbp;
3235 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
3237 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3239 * T10/1799-D Revision 31 states at least one of these
3240 * must be supported but we don't currently enforce this.
3242 dadeleteflag(softc, DA_DELETE_WS16,
3243 (lbp->flags & SVPD_LBP_WS16));
3244 dadeleteflag(softc, DA_DELETE_WS10,
3245 (lbp->flags & SVPD_LBP_WS10));
3246 dadeleteflag(softc, DA_DELETE_ZERO,
3247 (lbp->flags & SVPD_LBP_WS10));
3248 dadeleteflag(softc, DA_DELETE_UNMAP,
3249 (lbp->flags & SVPD_LBP_UNMAP));
3251 if (lbp->flags & SVPD_LBP_UNMAP) {
3252 free(lbp, M_SCSIDA);
3253 xpt_release_ccb(done_ccb);
3254 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3255 xpt_schedule(periph, priority);
3260 error = daerror(done_ccb, CAM_RETRY_SELTO,
3261 SF_RETRY_UA|SF_NO_PRINT);
3262 if (error == ERESTART)
3264 else if (error != 0) {
3265 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3266 /* Don't wedge this device's queue */
3267 cam_release_devq(done_ccb->ccb_h.path,
3271 /*getcount_only*/0);
3275 * Failure indicates we don't support any SBC-3
3276 * delete methods with UNMAP
3281 free(lbp, M_SCSIDA);
3282 xpt_release_ccb(done_ccb);
3283 softc->state = DA_STATE_PROBE_BDC;
3284 xpt_schedule(periph, priority);
3287 case DA_CCB_PROBE_BLK_LIMITS:
3289 struct scsi_vpd_block_limits *block_limits;
3291 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
3293 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3294 uint32_t max_unmap_lba_cnt = scsi_4btoul(
3295 block_limits->max_unmap_lba_cnt);
3296 uint32_t max_unmap_blk_cnt = scsi_4btoul(
3297 block_limits->max_unmap_blk_cnt);
3298 uint64_t ws_max_blks = scsi_8btou64(
3299 block_limits->max_write_same_length);
3301 * We should already support UNMAP but we check lba
3302 * and block count to be sure
3304 if (max_unmap_lba_cnt != 0x00L &&
3305 max_unmap_blk_cnt != 0x00L) {
3306 softc->unmap_max_lba = max_unmap_lba_cnt;
3307 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
3311 * Unexpected UNMAP limits which means the
3312 * device doesn't actually support UNMAP
3314 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
3317 if (ws_max_blks != 0x00L)
3318 softc->ws_max_blks = ws_max_blks;
3321 error = daerror(done_ccb, CAM_RETRY_SELTO,
3322 SF_RETRY_UA|SF_NO_PRINT);
3323 if (error == ERESTART)
3325 else if (error != 0) {
3326 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3327 /* Don't wedge this device's queue */
3328 cam_release_devq(done_ccb->ccb_h.path,
3332 /*getcount_only*/0);
3336 * Failure here doesn't mean UNMAP is not
3337 * supported as this is an optional page.
3339 softc->unmap_max_lba = 1;
3340 softc->unmap_max_ranges = 1;
3344 free(block_limits, M_SCSIDA);
3345 xpt_release_ccb(done_ccb);
3346 softc->state = DA_STATE_PROBE_BDC;
3347 xpt_schedule(periph, priority);
3350 case DA_CCB_PROBE_BDC:
3352 struct scsi_vpd_block_characteristics *bdc;
3354 bdc = (struct scsi_vpd_block_characteristics *)csio->data_ptr;
3356 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3358 * Disable queue sorting for non-rotational media
3361 if (scsi_2btoul(bdc->medium_rotation_rate) ==
3362 SVPD_BDC_RATE_NONE_ROTATING)
3363 softc->sort_io_queue = 0;
3366 error = daerror(done_ccb, CAM_RETRY_SELTO,
3367 SF_RETRY_UA|SF_NO_PRINT);
3368 if (error == ERESTART)
3370 else if (error != 0) {
3371 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3372 /* Don't wedge this device's queue */
3373 cam_release_devq(done_ccb->ccb_h.path,
3377 /*getcount_only*/0);
3382 free(bdc, M_SCSIDA);
3383 xpt_release_ccb(done_ccb);
3384 softc->state = DA_STATE_PROBE_ATA;
3385 xpt_schedule(periph, priority);
3388 case DA_CCB_PROBE_ATA:
3391 struct ata_params *ata_params;
3394 ata_params = (struct ata_params *)csio->data_ptr;
3395 ptr = (uint16_t *)ata_params;
3397 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3398 for (i = 0; i < sizeof(*ata_params) / 2; i++)
3399 ptr[i] = le16toh(ptr[i]);
3400 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM) {
3401 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
3402 if (ata_params->max_dsm_blocks != 0)
3403 softc->trim_max_ranges = min(
3404 softc->trim_max_ranges,
3405 ata_params->max_dsm_blocks *
3406 ATA_DSM_BLK_RANGES);
3409 * Disable queue sorting for non-rotational media
3412 if (ata_params->media_rotation_rate == 1)
3413 softc->sort_io_queue = 0;
3416 error = daerror(done_ccb, CAM_RETRY_SELTO,
3417 SF_RETRY_UA|SF_NO_PRINT);
3418 if (error == ERESTART)
3420 else if (error != 0) {
3421 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3422 /* Don't wedge this device's queue */
3423 cam_release_devq(done_ccb->ccb_h.path,
3427 /*getcount_only*/0);
3432 free(ata_params, M_SCSIDA);
3433 daprobedone(periph, done_ccb);
3436 case DA_CCB_WAITING:
3438 /* Caller will release the CCB */
3439 wakeup(&done_ccb->ccb_h.cbfcnp);
3443 /* No-op. We're polling */
3447 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3449 if (daerror(done_ccb, CAM_RETRY_SELTO,
3450 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
3453 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
3454 cam_release_devq(done_ccb->ccb_h.path,
3458 /*getcount_only*/0);
3460 xpt_release_ccb(done_ccb);
3461 cam_periph_release_locked(periph);
3467 xpt_release_ccb(done_ccb);
3471 dareprobe(struct cam_periph *periph)
3473 struct da_softc *softc;
3476 softc = (struct da_softc *)periph->softc;
3478 /* Probe in progress; don't interfere. */
3479 if (softc->state != DA_STATE_NORMAL)
3482 status = cam_periph_acquire(periph);
3483 KASSERT(status == CAM_REQ_CMP,
3484 ("dareprobe: cam_periph_acquire failed"));
3486 if (softc->flags & DA_FLAG_CAN_RC16)
3487 softc->state = DA_STATE_PROBE_RC16;
3489 softc->state = DA_STATE_PROBE_RC;
3491 xpt_schedule(periph, CAM_PRIORITY_DEV);
3495 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
3497 struct da_softc *softc;
3498 struct cam_periph *periph;
3499 int error, error_code, sense_key, asc, ascq;
3501 periph = xpt_path_periph(ccb->ccb_h.path);
3502 softc = (struct da_softc *)periph->softc;
3505 * Automatically detect devices that do not support
3506 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
3509 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
3510 error = cmd6workaround(ccb);
3511 } else if (scsi_extract_sense_ccb(ccb,
3512 &error_code, &sense_key, &asc, &ascq)) {
3513 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
3514 error = cmd6workaround(ccb);
3516 * If the target replied with CAPACITY DATA HAS CHANGED UA,
3517 * query the capacity and notify upper layers.
3519 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
3520 asc == 0x2A && ascq == 0x09) {
3521 xpt_print(periph->path, "capacity data has changed\n");
3523 sense_flags |= SF_NO_PRINT;
3524 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
3525 asc == 0x28 && ascq == 0x00)
3526 disk_media_changed(softc->disk, M_NOWAIT);
3527 else if (sense_key == SSD_KEY_NOT_READY &&
3528 asc == 0x3a && (softc->flags & DA_FLAG_SAW_MEDIA)) {
3529 softc->flags &= ~DA_FLAG_SAW_MEDIA;
3530 disk_media_gone(softc->disk, M_NOWAIT);
3533 if (error == ERESTART)
3538 * Until we have a better way of doing pack validation,
3539 * don't treat UAs as errors.
3541 sense_flags |= SF_RETRY_UA;
3542 return(cam_periph_error(ccb, cam_flags, sense_flags,
3543 &softc->saved_ccb));
3547 damediapoll(void *arg)
3549 struct cam_periph *periph = arg;
3550 struct da_softc *softc = periph->softc;
3552 if (!softc->tur && softc->outstanding_cmds == 0) {
3553 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
3558 /* Queue us up again */
3559 if (da_poll_period != 0)
3560 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
3564 daprevent(struct cam_periph *periph, int action)
3566 struct da_softc *softc;
3570 softc = (struct da_softc *)periph->softc;
3572 if (((action == PR_ALLOW)
3573 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
3574 || ((action == PR_PREVENT)
3575 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
3579 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
3581 scsi_prevent(&ccb->csio,
3589 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
3590 SF_RETRY_UA | SF_QUIET_IR, softc->disk->d_devstat);
3593 if (action == PR_ALLOW)
3594 softc->flags &= ~DA_FLAG_PACK_LOCKED;
3596 softc->flags |= DA_FLAG_PACK_LOCKED;
3599 xpt_release_ccb(ccb);
3603 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
3604 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
3606 struct ccb_calc_geometry ccg;
3607 struct da_softc *softc;
3608 struct disk_params *dp;
3609 u_int lbppbe, lalba;
3611 softc = (struct da_softc *)periph->softc;
3613 dp = &softc->params;
3614 dp->secsize = block_len;
3615 dp->sectors = maxsector + 1;
3616 if (rcaplong != NULL) {
3617 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
3618 lalba = scsi_2btoul(rcaplong->lalba_lbp);
3619 lalba &= SRC16_LALBA_A;
3626 dp->stripesize = block_len << lbppbe;
3627 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
3629 } else if (softc->quirks & DA_Q_4K) {
3630 dp->stripesize = 4096;
3631 dp->stripeoffset = 0;
3634 dp->stripeoffset = 0;
3637 * Have the controller provide us with a geometry
3638 * for this disk. The only time the geometry
3639 * matters is when we boot and the controller
3640 * is the only one knowledgeable enough to come
3641 * up with something that will make this a bootable
3644 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
3645 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
3646 ccg.block_size = dp->secsize;
3647 ccg.volume_size = dp->sectors;
3649 ccg.secs_per_track = 0;
3651 xpt_action((union ccb*)&ccg);
3652 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3654 * We don't know what went wrong here- but just pick
3655 * a geometry so we don't have nasty things like divide
3659 dp->secs_per_track = 255;
3660 dp->cylinders = dp->sectors / (255 * 255);
3661 if (dp->cylinders == 0) {
3665 dp->heads = ccg.heads;
3666 dp->secs_per_track = ccg.secs_per_track;
3667 dp->cylinders = ccg.cylinders;
3671 * If the user supplied a read capacity buffer, and if it is
3672 * different than the previous buffer, update the data in the EDT.
3673 * If it's the same, we don't bother. This avoids sending an
3674 * update every time someone opens this device.
3676 if ((rcaplong != NULL)
3677 && (bcmp(rcaplong, &softc->rcaplong,
3678 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
3679 struct ccb_dev_advinfo cdai;
3681 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
3682 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
3683 cdai.buftype = CDAI_TYPE_RCAPLONG;
3684 cdai.flags |= CDAI_FLAG_STORE;
3685 cdai.bufsiz = rcap_len;
3686 cdai.buf = (uint8_t *)rcaplong;
3687 xpt_action((union ccb *)&cdai);
3688 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
3689 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
3690 if (cdai.ccb_h.status != CAM_REQ_CMP) {
3691 xpt_print(periph->path, "%s: failed to set read "
3692 "capacity advinfo\n", __func__);
3693 /* Use cam_error_print() to decode the status */
3694 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
3697 bcopy(rcaplong, &softc->rcaplong,
3698 min(sizeof(softc->rcaplong), rcap_len));
3702 softc->disk->d_sectorsize = softc->params.secsize;
3703 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
3704 softc->disk->d_stripesize = softc->params.stripesize;
3705 softc->disk->d_stripeoffset = softc->params.stripeoffset;
3706 /* XXX: these are not actually "firmware" values, so they may be wrong */
3707 softc->disk->d_fwsectors = softc->params.secs_per_track;
3708 softc->disk->d_fwheads = softc->params.heads;
3709 softc->disk->d_devstat->block_size = softc->params.secsize;
3710 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
3714 dasendorderedtag(void *arg)
3716 struct da_softc *softc = arg;
3718 if (da_send_ordered) {
3719 if ((softc->ordered_tag_count == 0)
3720 && ((softc->flags & DA_FLAG_WENT_IDLE) == 0)) {
3721 softc->flags |= DA_FLAG_NEED_OTAG;
3723 if (softc->outstanding_cmds > 0)
3724 softc->flags &= ~DA_FLAG_WENT_IDLE;
3726 softc->ordered_tag_count = 0;
3728 /* Queue us up again */
3729 callout_reset(&softc->sendordered_c,
3730 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
3731 dasendorderedtag, softc);
3735 * Step through all DA peripheral drivers, and if the device is still open,
3736 * sync the disk cache to physical media.
3739 dashutdown(void * arg, int howto)
3741 struct cam_periph *periph;
3742 struct da_softc *softc;
3746 CAM_PERIPH_FOREACH(periph, &dadriver) {
3747 softc = (struct da_softc *)periph->softc;
3748 if (SCHEDULER_STOPPED()) {
3749 /* If we paniced with the lock held, do not recurse. */
3750 if (!cam_periph_owned(periph) &&
3751 (softc->flags & DA_FLAG_OPEN)) {
3752 dadump(softc->disk, NULL, 0, 0, 0);
3756 cam_periph_lock(periph);
3759 * We only sync the cache if the drive is still open, and
3760 * if the drive is capable of it..
3762 if (((softc->flags & DA_FLAG_OPEN) == 0)
3763 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
3764 cam_periph_unlock(periph);
3768 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
3769 scsi_synchronize_cache(&ccb->csio,
3773 /*begin_lba*/0, /* whole disk */
3778 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
3779 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
3780 softc->disk->d_devstat);
3782 xpt_print(periph->path, "Synchronize cache failed\n");
3783 xpt_release_ccb(ccb);
3784 cam_periph_unlock(periph);
3788 #else /* !_KERNEL */
3791 * XXX This is only left out of the kernel build to silence warnings. If,
3792 * for some reason this function is used in the kernel, the ifdefs should
3793 * be moved so it is included both in the kernel and userland.
3796 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
3797 void (*cbfcnp)(struct cam_periph *, union ccb *),
3798 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
3799 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
3802 struct scsi_format_unit *scsi_cmd;
3804 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
3805 scsi_cmd->opcode = FORMAT_UNIT;
3806 scsi_cmd->byte2 = byte2;
3807 scsi_ulto2b(ileave, scsi_cmd->interleave);
3812 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
3821 #endif /* _KERNEL */