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>
50 #include <geom/geom.h>
51 #include <geom/geom_disk.h>
60 #include <cam/cam_ccb.h>
61 #include <cam/cam_periph.h>
62 #include <cam/cam_xpt_periph.h>
63 #include <cam/cam_sim.h>
64 #include <cam/cam_iosched.h>
66 #include <cam/scsi/scsi_message.h>
67 #include <cam/scsi/scsi_da.h>
71 * Note that there are probe ordering dependencies here. The order isn't
72 * controlled by this enumeration, but by explicit state transitions in
73 * dastart() and dadone(). Here are some of the dependencies:
75 * 1. RC should come first, before RC16, unless there is evidence that RC16
77 * 2. BDC needs to come before any of the ATA probes, or the ZONE probe.
78 * 3. The ATA probes should go in this order:
79 * ATA -> LOGDIR -> IDDIR -> SUP -> ATA_ZONE
85 DA_STATE_PROBE_BLK_LIMITS,
88 DA_STATE_PROBE_ATA_LOGDIR,
89 DA_STATE_PROBE_ATA_IDDIR,
90 DA_STATE_PROBE_ATA_SUP,
91 DA_STATE_PROBE_ATA_ZONE,
97 DA_FLAG_PACK_INVALID = 0x000001,
98 DA_FLAG_NEW_PACK = 0x000002,
99 DA_FLAG_PACK_LOCKED = 0x000004,
100 DA_FLAG_PACK_REMOVABLE = 0x000008,
101 DA_FLAG_NEED_OTAG = 0x000020,
102 DA_FLAG_WAS_OTAG = 0x000040,
103 DA_FLAG_RETRY_UA = 0x000080,
104 DA_FLAG_OPEN = 0x000100,
105 DA_FLAG_SCTX_INIT = 0x000200,
106 DA_FLAG_CAN_RC16 = 0x000400,
107 DA_FLAG_PROBED = 0x000800,
108 DA_FLAG_DIRTY = 0x001000,
109 DA_FLAG_ANNOUNCED = 0x002000,
110 DA_FLAG_CAN_ATA_DMA = 0x004000,
111 DA_FLAG_CAN_ATA_LOG = 0x008000,
112 DA_FLAG_CAN_ATA_IDLOG = 0x010000,
113 DA_FLAG_CAN_ATA_SUPCAP = 0x020000,
114 DA_FLAG_CAN_ATA_ZONE = 0x040000
119 DA_Q_NO_SYNC_CACHE = 0x01,
120 DA_Q_NO_6_BYTE = 0x02,
121 DA_Q_NO_PREVENT = 0x04,
124 DA_Q_NO_UNMAP = 0x20,
125 DA_Q_RETRY_BUSY = 0x40,
129 #define DA_Q_BIT_STRING \
131 "\001NO_SYNC_CACHE" \
141 DA_CCB_PROBE_RC = 0x01,
142 DA_CCB_PROBE_RC16 = 0x02,
143 DA_CCB_PROBE_LBP = 0x03,
144 DA_CCB_PROBE_BLK_LIMITS = 0x04,
145 DA_CCB_PROBE_BDC = 0x05,
146 DA_CCB_PROBE_ATA = 0x06,
147 DA_CCB_BUFFER_IO = 0x07,
149 DA_CCB_DELETE = 0x0B,
151 DA_CCB_PROBE_ZONE = 0x0D,
152 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
153 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
154 DA_CCB_PROBE_ATA_SUP = 0x10,
155 DA_CCB_PROBE_ATA_ZONE = 0x11,
156 DA_CCB_TYPE_MASK = 0x1F,
157 DA_CCB_RETRY_UA = 0x20
161 * Order here is important for method choice
163 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
164 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
165 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
166 * import taking 5mins.
177 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
178 DA_DELETE_MAX = DA_DELETE_ZERO
182 * For SCSI, host managed drives show up as a separate device type. For
183 * ATA, host managed drives also have a different device signature.
184 * XXX KDM figure out the ATA host managed signature.
188 DA_ZONE_DRIVE_MANAGED = 0x01,
189 DA_ZONE_HOST_AWARE = 0x02,
190 DA_ZONE_HOST_MANAGED = 0x03
194 * We distinguish between these interface cases in addition to the drive type:
195 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
196 * o ATA drive behind a SCSI translation layer that does not know about
197 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
198 * case, we would need to share the ATA code with the ada(4) driver.
208 DA_ZONE_FLAG_RZ_SUP = 0x0001,
209 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
210 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
211 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
212 DA_ZONE_FLAG_RWP_SUP = 0x0010,
213 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
214 DA_ZONE_FLAG_OPEN_SUP |
215 DA_ZONE_FLAG_CLOSE_SUP |
216 DA_ZONE_FLAG_FINISH_SUP |
217 DA_ZONE_FLAG_RWP_SUP),
218 DA_ZONE_FLAG_URSWRZ = 0x0020,
219 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
220 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
221 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
222 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
223 DA_ZONE_FLAG_OPT_NONSEQ_SET |
224 DA_ZONE_FLAG_MAX_SEQ_SET)
227 static struct da_zone_desc {
230 } da_zone_desc_table[] = {
231 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
232 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
233 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
234 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
235 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
238 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
240 static da_delete_func_t da_delete_trim;
241 static da_delete_func_t da_delete_unmap;
242 static da_delete_func_t da_delete_ws;
244 static const void * da_delete_functions[] = {
254 static const char *da_delete_method_names[] =
255 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
256 static const char *da_delete_method_desc[] =
257 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
258 "WRITE SAME(10) with UNMAP", "ZERO" };
260 /* Offsets into our private area for storing information */
261 #define ccb_state ppriv_field0
262 #define ccb_bp ppriv_ptr1
267 u_int8_t secs_per_track;
268 u_int32_t secsize; /* Number of bytes/sector */
269 u_int64_t sectors; /* total number sectors */
274 #define UNMAP_RANGE_MAX 0xffffffff
275 #define UNMAP_HEAD_SIZE 8
276 #define UNMAP_RANGE_SIZE 16
277 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
278 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
281 #define WS10_MAX_BLKS 0xffff
282 #define WS16_MAX_BLKS 0xffffffff
283 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
284 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
286 #define DA_WORK_TUR (1 << 16)
289 struct cam_iosched_softc *cam_iosched;
290 struct bio_queue_head delete_run_queue;
291 LIST_HEAD(, ccb_hdr) pending_ccbs;
292 int refcount; /* Active xpt_action() calls */
296 int minimum_cmd_size;
299 int delete_available; /* Delete methods possibly available */
300 da_zone_mode zone_mode;
301 da_zone_interface zone_interface;
302 da_zone_flags zone_flags;
303 struct ata_gp_log_dir ata_logdir;
304 int valid_logdir_len;
305 struct ata_identify_log_pages ata_iddir;
307 uint64_t optimal_seq_zones;
308 uint64_t optimal_nonseq_zones;
309 uint64_t max_seq_zones;
311 uint32_t unmap_max_ranges;
312 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
313 uint64_t ws_max_blks;
314 da_delete_methods delete_method_pref;
315 da_delete_methods delete_method;
316 da_delete_func_t *delete_func;
319 struct disk_params params;
322 struct task sysctl_task;
323 struct sysctl_ctx_list sysctl_ctx;
324 struct sysctl_oid *sysctl_tree;
325 struct callout sendordered_c;
327 uint8_t unmap_buf[UNMAP_BUF_SIZE];
328 struct scsi_read_capacity_data_long rcaplong;
329 struct callout mediapoll_c;
331 struct sysctl_ctx_list sysctl_stats_ctx;
332 struct sysctl_oid *sysctl_stats_tree;
339 #define dadeleteflag(softc, delete_method, enable) \
341 softc->delete_available |= (1 << delete_method); \
343 softc->delete_available &= ~(1 << delete_method); \
346 struct da_quirk_entry {
347 struct scsi_inquiry_pattern inq_pat;
351 static const char quantum[] = "QUANTUM";
352 static const char microp[] = "MICROP";
354 static struct da_quirk_entry da_quirk_table[] =
356 /* SPI, FC devices */
359 * Fujitsu M2513A MO drives.
360 * Tested devices: M2513A2 firmware versions 1200 & 1300.
361 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
362 * Reported by: W.Scholten <whs@xs4all.nl>
364 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
365 /*quirks*/ DA_Q_NO_SYNC_CACHE
369 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
370 /*quirks*/ DA_Q_NO_SYNC_CACHE
374 * This particular Fujitsu drive doesn't like the
375 * synchronize cache command.
376 * Reported by: Tom Jackson <toj@gorilla.net>
378 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
379 /*quirks*/ DA_Q_NO_SYNC_CACHE
383 * This drive doesn't like the synchronize cache command
384 * either. Reported by: Matthew Jacob <mjacob@feral.com>
385 * in NetBSD PR kern/6027, August 24, 1998.
387 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
388 /*quirks*/ DA_Q_NO_SYNC_CACHE
392 * This drive doesn't like the synchronize cache command
393 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
396 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
397 /*quirks*/ DA_Q_NO_SYNC_CACHE
401 * Doesn't like the synchronize cache command.
402 * Reported by: Blaz Zupan <blaz@gold.amis.net>
404 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
405 /*quirks*/ DA_Q_NO_SYNC_CACHE
409 * Doesn't like the synchronize cache command.
410 * Reported by: Blaz Zupan <blaz@gold.amis.net>
412 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
413 /*quirks*/ DA_Q_NO_SYNC_CACHE
417 * Doesn't like the synchronize cache command.
419 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
420 /*quirks*/ DA_Q_NO_SYNC_CACHE
424 * Doesn't like the synchronize cache command.
425 * Reported by: walter@pelissero.de
427 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
428 /*quirks*/ DA_Q_NO_SYNC_CACHE
432 * Doesn't work correctly with 6 byte reads/writes.
433 * Returns illegal request, and points to byte 9 of the
435 * Reported by: Adam McDougall <bsdx@spawnet.com>
437 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
438 /*quirks*/ DA_Q_NO_6_BYTE
442 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
443 /*quirks*/ DA_Q_NO_6_BYTE
447 * Doesn't like the synchronize cache command.
448 * Reported by: walter@pelissero.de
450 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
451 /*quirks*/ DA_Q_NO_SYNC_CACHE
455 * The CISS RAID controllers do not support SYNC_CACHE
457 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
458 /*quirks*/ DA_Q_NO_SYNC_CACHE
462 * The STEC SSDs sometimes hang on UNMAP.
464 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
465 /*quirks*/ DA_Q_NO_UNMAP
469 * VMware returns BUSY status when storage has transient
470 * connectivity problems, so better wait.
472 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
473 /*quirks*/ DA_Q_RETRY_BUSY
475 /* USB mass storage devices supported by umass(4) */
478 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
481 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
482 /*quirks*/ DA_Q_NO_SYNC_CACHE
486 * Power Quotient Int. (PQI) USB flash key
489 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
490 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
494 * Creative Nomad MUVO mp3 player (USB)
497 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
498 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
502 * Jungsoft NEXDISK USB flash key
505 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
506 /*quirks*/ DA_Q_NO_SYNC_CACHE
510 * FreeDik USB Mini Data Drive
513 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
514 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
518 * Sigmatel USB Flash MP3 Player
521 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
522 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
526 * Neuros USB Digital Audio Computer
529 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
530 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
534 * SEAGRAND NP-900 MP3 Player
537 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
538 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
542 * iRiver iFP MP3 player (with UMS Firmware)
543 * PR: kern/54881, i386/63941, kern/66124
545 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
546 /*quirks*/ DA_Q_NO_SYNC_CACHE
550 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
553 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
554 /*quirks*/ DA_Q_NO_SYNC_CACHE
558 * ZICPlay USB MP3 Player with FM
561 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
562 /*quirks*/ DA_Q_NO_SYNC_CACHE
566 * TEAC USB floppy mechanisms
568 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
569 /*quirks*/ DA_Q_NO_SYNC_CACHE
573 * Kingston DataTraveler II+ USB Pen-Drive.
574 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
576 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
577 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
585 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
586 /*quirks*/ DA_Q_NO_SYNC_CACHE
590 * Motorola E398 Mobile Phone (TransFlash memory card).
591 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
594 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
595 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
599 * Qware BeatZkey! Pro
602 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
603 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
607 * Time DPA20B 1GB MP3 Player
610 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
611 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
615 * Samsung USB key 128Mb
618 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
619 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
623 * Kingston DataTraveler 2.0 USB Flash memory.
626 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
627 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
631 * Creative MUVO Slim mp3 player (USB)
634 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
635 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
639 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
642 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
643 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
647 * SanDisk Micro Cruzer 128MB
650 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
651 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
655 * TOSHIBA TransMemory USB sticks
658 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
659 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
663 * PNY USB 3.0 Flash Drives
665 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
666 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
671 * PR: usb/75578, usb/72344, usb/65436
673 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
674 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
678 * Genesys 6-in-1 Card Reader
681 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
682 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
686 * Rekam Digital CAMERA
689 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
690 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
694 * iRiver H10 MP3 player
697 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
698 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
702 * iRiver U10 MP3 player
705 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
706 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
713 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
714 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
718 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
721 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
722 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
729 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
730 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
734 * Philips USB Key Audio KEY013
737 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
738 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
745 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
746 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
753 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
754 /*quirks*/ DA_Q_NO_SYNC_CACHE
758 * I/O Magic USB flash - Giga Bank
761 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
762 /*quirks*/ DA_Q_NO_SYNC_CACHE
766 * JoyFly 128mb USB Flash Drive
769 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
770 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
777 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
778 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
782 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
785 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
786 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
790 * Samsung YP-U3 mp3-player
793 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
794 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
797 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
798 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
802 * Sony Cyber-Shot DSC cameras
805 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
806 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
809 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
810 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
813 /* At least several Transcent USB sticks lie on RC16. */
814 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
815 "*"}, /*quirks*/ DA_Q_NO_RC16
817 /* ATA/SATA devices over SAS/USB/... */
819 /* Hitachi Advanced Format (4k) drives */
820 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
824 /* Samsung Advanced Format (4k) drives */
825 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
829 /* Samsung Advanced Format (4k) drives */
830 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
834 /* Samsung Advanced Format (4k) drives */
835 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
839 /* Samsung Advanced Format (4k) drives */
840 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
844 /* Seagate Barracuda Green Advanced Format (4k) drives */
845 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
849 /* Seagate Barracuda Green Advanced Format (4k) drives */
850 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
854 /* Seagate Barracuda Green Advanced Format (4k) drives */
855 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
859 /* Seagate Barracuda Green Advanced Format (4k) drives */
860 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
864 /* Seagate Barracuda Green Advanced Format (4k) drives */
865 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
869 /* Seagate Barracuda Green Advanced Format (4k) drives */
870 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
874 /* Seagate Momentus Advanced Format (4k) drives */
875 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
879 /* Seagate Momentus Advanced Format (4k) drives */
880 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
884 /* Seagate Momentus Advanced Format (4k) drives */
885 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
889 /* Seagate Momentus Advanced Format (4k) drives */
890 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
894 /* Seagate Momentus Advanced Format (4k) drives */
895 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
899 /* Seagate Momentus Advanced Format (4k) drives */
900 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
904 /* Seagate Momentus Advanced Format (4k) drives */
905 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
909 /* Seagate Momentus Advanced Format (4k) drives */
910 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
914 /* Seagate Momentus Advanced Format (4k) drives */
915 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
919 /* Seagate Momentus Advanced Format (4k) drives */
920 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
924 /* Seagate Momentus Advanced Format (4k) drives */
925 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
929 /* Seagate Momentus Advanced Format (4k) drives */
930 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
934 /* Seagate Momentus Advanced Format (4k) drives */
935 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
939 /* Seagate Momentus Advanced Format (4k) drives */
940 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
944 /* Seagate Momentus Thin Advanced Format (4k) drives */
945 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
949 /* Seagate Momentus Thin Advanced Format (4k) drives */
950 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
954 /* WDC Caviar Green Advanced Format (4k) drives */
955 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
959 /* WDC Caviar Green Advanced Format (4k) drives */
960 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
964 /* WDC Caviar Green Advanced Format (4k) drives */
965 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
969 /* WDC Caviar Green Advanced Format (4k) drives */
970 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
974 /* WDC Caviar Green Advanced Format (4k) drives */
975 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
979 /* WDC Caviar Green Advanced Format (4k) drives */
980 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
984 /* WDC Caviar Green Advanced Format (4k) drives */
985 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
989 /* WDC Caviar Green Advanced Format (4k) drives */
990 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
994 /* WDC Scorpio Black Advanced Format (4k) drives */
995 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
999 /* WDC Scorpio Black Advanced Format (4k) drives */
1000 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1004 /* WDC Scorpio Black Advanced Format (4k) drives */
1005 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1009 /* WDC Scorpio Black Advanced Format (4k) drives */
1010 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1014 /* WDC Scorpio Blue Advanced Format (4k) drives */
1015 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1019 /* WDC Scorpio Blue Advanced Format (4k) drives */
1020 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1024 /* WDC Scorpio Blue Advanced Format (4k) drives */
1025 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1029 /* WDC Scorpio Blue Advanced Format (4k) drives */
1030 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1035 * Olympus FE-210 camera
1037 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1038 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1042 * LG UP3S MP3 player
1044 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1045 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1049 * Laser MP3-2GA13 MP3 player
1051 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1052 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1056 * LaCie external 250GB Hard drive des by Porsche
1057 * Submitted by: Ben Stuyts <ben@altesco.nl>
1060 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1061 /*quirks*/ DA_Q_NO_SYNC_CACHE
1066 * Corsair Force 2 SSDs
1067 * 4k optimised & trim only works in 4k requests + 4k aligned
1069 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1074 * Corsair Force 3 SSDs
1075 * 4k optimised & trim only works in 4k requests + 4k aligned
1077 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1082 * Corsair Neutron GTX SSDs
1083 * 4k optimised & trim only works in 4k requests + 4k aligned
1085 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1090 * Corsair Force GT & GS SSDs
1091 * 4k optimised & trim only works in 4k requests + 4k aligned
1093 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1099 * 4k optimised & trim only works in 4k requests + 4k aligned
1101 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1106 * Crucial RealSSD C300 SSDs
1109 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1110 "*" }, /*quirks*/DA_Q_4K
1114 * Intel 320 Series SSDs
1115 * 4k optimised & trim only works in 4k requests + 4k aligned
1117 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1122 * Intel 330 Series SSDs
1123 * 4k optimised & trim only works in 4k requests + 4k aligned
1125 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1130 * Intel 510 Series SSDs
1131 * 4k optimised & trim only works in 4k requests + 4k aligned
1133 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1138 * Intel 520 Series SSDs
1139 * 4k optimised & trim only works in 4k requests + 4k aligned
1141 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1146 * Intel X25-M Series SSDs
1147 * 4k optimised & trim only works in 4k requests + 4k aligned
1149 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1154 * Kingston E100 Series SSDs
1155 * 4k optimised & trim only works in 4k requests + 4k aligned
1157 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1162 * Kingston HyperX 3k SSDs
1163 * 4k optimised & trim only works in 4k requests + 4k aligned
1165 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1170 * Marvell SSDs (entry taken from OpenSolaris)
1171 * 4k optimised & trim only works in 4k requests + 4k aligned
1173 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1178 * OCZ Agility 2 SSDs
1179 * 4k optimised & trim only works in 4k requests + 4k aligned
1181 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1186 * OCZ Agility 3 SSDs
1187 * 4k optimised & trim only works in 4k requests + 4k aligned
1189 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1194 * OCZ Deneva R Series SSDs
1195 * 4k optimised & trim only works in 4k requests + 4k aligned
1197 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1202 * OCZ Vertex 2 SSDs (inc pro series)
1203 * 4k optimised & trim only works in 4k requests + 4k aligned
1205 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1211 * 4k optimised & trim only works in 4k requests + 4k aligned
1213 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1219 * 4k optimised & trim only works in 4k requests + 4k aligned
1221 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1226 * Samsung 830 Series SSDs
1227 * 4k optimised & trim only works in 4k requests + 4k aligned
1229 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1235 * 4k optimised & trim only works in 4k requests + 4k aligned
1237 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1243 * 4k optimised & trim only works in 4k requests + 4k aligned
1245 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1250 * Samsung 843T Series SSDs (MZ7WD*)
1251 * Samsung PM851 Series SSDs (MZ7TE*)
1252 * Samsung PM853T Series SSDs (MZ7GE*)
1253 * Samsung SM863 Series SSDs (MZ7KM*)
1256 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1261 * SuperTalent TeraDrive CT SSDs
1262 * 4k optimised & trim only works in 4k requests + 4k aligned
1264 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1269 * XceedIOPS SATA SSDs
1272 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1277 * Hama Innostor USB-Stick
1279 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1280 /*quirks*/DA_Q_NO_RC16
1284 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1285 * Drive Managed SATA hard drive. This drive doesn't report
1286 * in firmware that it is a drive managed SMR drive.
1288 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS0002*", "*" },
1289 /*quirks*/DA_Q_SMR_DM
1293 * MX-ES USB Drive by Mach Xtreme
1295 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1296 /*quirks*/DA_Q_NO_RC16
1300 static disk_strategy_t dastrategy;
1301 static dumper_t dadump;
1302 static periph_init_t dainit;
1303 static void daasync(void *callback_arg, u_int32_t code,
1304 struct cam_path *path, void *arg);
1305 static void dasysctlinit(void *context, int pending);
1306 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1307 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1308 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1309 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1310 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1311 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1312 static void dadeletemethodset(struct da_softc *softc,
1313 da_delete_methods delete_method);
1314 static off_t dadeletemaxsize(struct da_softc *softc,
1315 da_delete_methods delete_method);
1316 static void dadeletemethodchoose(struct da_softc *softc,
1317 da_delete_methods default_method);
1318 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1320 static periph_ctor_t daregister;
1321 static periph_dtor_t dacleanup;
1322 static periph_start_t dastart;
1323 static periph_oninv_t daoninvalidate;
1324 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1325 static void dadone(struct cam_periph *periph,
1326 union ccb *done_ccb);
1327 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1328 u_int32_t sense_flags);
1329 static void daprevent(struct cam_periph *periph, int action);
1330 static void dareprobe(struct cam_periph *periph);
1331 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1333 struct scsi_read_capacity_data_long *rcaplong,
1335 static timeout_t dasendorderedtag;
1336 static void dashutdown(void *arg, int howto);
1337 static timeout_t damediapoll;
1339 #ifndef DA_DEFAULT_POLL_PERIOD
1340 #define DA_DEFAULT_POLL_PERIOD 3
1343 #ifndef DA_DEFAULT_TIMEOUT
1344 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1347 #ifndef DA_DEFAULT_SOFTTIMEOUT
1348 #define DA_DEFAULT_SOFTTIMEOUT 0
1351 #ifndef DA_DEFAULT_RETRY
1352 #define DA_DEFAULT_RETRY 4
1355 #ifndef DA_DEFAULT_SEND_ORDERED
1356 #define DA_DEFAULT_SEND_ORDERED 1
1359 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1360 static int da_retry_count = DA_DEFAULT_RETRY;
1361 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1362 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1363 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1365 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1366 "CAM Direct Access Disk driver");
1367 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1368 &da_poll_period, 0, "Media polling period in seconds");
1369 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1370 &da_retry_count, 0, "Normal I/O retry count");
1371 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1372 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1373 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1374 &da_send_ordered, 0, "Send Ordered Tags");
1376 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1377 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1378 "Soft I/O timeout (ms)");
1379 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1382 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1383 * to the default timeout, we check to see whether an ordered
1384 * tagged transaction is appropriate to prevent simple tag
1385 * starvation. Since we'd like to ensure that there is at least
1386 * 1/2 of the timeout length left for a starved transaction to
1387 * complete after we've sent an ordered tag, we must poll at least
1388 * four times in every timeout period. This takes care of the worst
1389 * case where a starved transaction starts during an interval that
1390 * meets the requirement "don't send an ordered tag" test so it takes
1391 * us two intervals to determine that a tag must be sent.
1393 #ifndef DA_ORDEREDTAG_INTERVAL
1394 #define DA_ORDEREDTAG_INTERVAL 4
1397 static struct periph_driver dadriver =
1400 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1403 PERIPHDRIVER_DECLARE(da, dadriver);
1405 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1408 daopen(struct disk *dp)
1410 struct cam_periph *periph;
1411 struct da_softc *softc;
1414 periph = (struct cam_periph *)dp->d_drv1;
1415 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1419 cam_periph_lock(periph);
1420 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1421 cam_periph_unlock(periph);
1422 cam_periph_release(periph);
1426 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1429 softc = (struct da_softc *)periph->softc;
1432 /* Wait for the disk size update. */
1433 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1436 xpt_print(periph->path, "unable to retrieve capacity data\n");
1438 if (periph->flags & CAM_PERIPH_INVALID)
1441 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1442 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1443 daprevent(periph, PR_PREVENT);
1446 softc->flags &= ~DA_FLAG_PACK_INVALID;
1447 softc->flags |= DA_FLAG_OPEN;
1450 cam_periph_unhold(periph);
1451 cam_periph_unlock(periph);
1454 cam_periph_release(periph);
1460 daclose(struct disk *dp)
1462 struct cam_periph *periph;
1463 struct da_softc *softc;
1467 periph = (struct cam_periph *)dp->d_drv1;
1468 softc = (struct da_softc *)periph->softc;
1469 cam_periph_lock(periph);
1470 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1473 if (cam_periph_hold(periph, PRIBIO) == 0) {
1475 /* Flush disk cache. */
1476 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1477 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1478 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1479 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1480 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1481 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1482 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1484 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1485 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1486 softc->disk->d_devstat);
1488 softc->flags &= ~DA_FLAG_DIRTY;
1489 xpt_release_ccb(ccb);
1492 /* Allow medium removal. */
1493 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1494 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1495 daprevent(periph, PR_ALLOW);
1497 cam_periph_unhold(periph);
1501 * If we've got removeable media, mark the blocksize as
1502 * unavailable, since it could change when new media is
1505 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1506 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1508 softc->flags &= ~DA_FLAG_OPEN;
1509 while (softc->refcount != 0)
1510 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1511 cam_periph_unlock(periph);
1512 cam_periph_release(periph);
1517 daschedule(struct cam_periph *periph)
1519 struct da_softc *softc = (struct da_softc *)periph->softc;
1521 if (softc->state != DA_STATE_NORMAL)
1524 cam_iosched_schedule(softc->cam_iosched, periph);
1528 * Actually translate the requested transfer into one the physical driver
1529 * can understand. The transfer is described by a buf and will include
1530 * only one physical transfer.
1533 dastrategy(struct bio *bp)
1535 struct cam_periph *periph;
1536 struct da_softc *softc;
1538 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1539 softc = (struct da_softc *)periph->softc;
1541 cam_periph_lock(periph);
1544 * If the device has been made invalid, error out
1546 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1547 cam_periph_unlock(periph);
1548 biofinish(bp, NULL, ENXIO);
1552 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1555 * Zone commands must be ordered, because they can depend on the
1556 * effects of previously issued commands, and they may affect
1557 * commands after them.
1559 if (bp->bio_cmd == BIO_ZONE)
1560 bp->bio_flags |= BIO_ORDERED;
1563 * Place it in the queue of disk activities for this disk
1565 cam_iosched_queue_work(softc->cam_iosched, bp);
1568 * Schedule ourselves for performing the work.
1571 cam_periph_unlock(periph);
1577 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1579 struct cam_periph *periph;
1580 struct da_softc *softc;
1582 struct ccb_scsiio csio;
1587 periph = dp->d_drv1;
1588 softc = (struct da_softc *)periph->softc;
1589 cam_periph_lock(periph);
1590 secsize = softc->params.secsize;
1592 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1593 cam_periph_unlock(periph);
1598 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1599 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1600 scsi_read_write(&csio,
1604 /*read*/SCSI_RW_WRITE,
1606 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1609 /*data_ptr*/(u_int8_t *) virtual,
1610 /*dxfer_len*/length,
1611 /*sense_len*/SSD_FULL_SIZE,
1612 da_default_timeout * 1000);
1613 xpt_polled_action((union ccb *)&csio);
1615 error = cam_periph_error((union ccb *)&csio,
1616 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1617 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1618 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1619 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1621 printf("Aborting dump due to I/O error.\n");
1622 cam_periph_unlock(periph);
1627 * Sync the disk cache contents to the physical media.
1629 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1631 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1632 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1633 scsi_synchronize_cache(&csio,
1637 /*begin_lba*/0,/* Cover the whole disk */
1641 xpt_polled_action((union ccb *)&csio);
1643 error = cam_periph_error((union ccb *)&csio,
1644 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1645 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1646 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1647 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1649 xpt_print(periph->path, "Synchronize cache failed\n");
1651 cam_periph_unlock(periph);
1656 dagetattr(struct bio *bp)
1659 struct cam_periph *periph;
1661 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1662 cam_periph_lock(periph);
1663 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1665 cam_periph_unlock(periph);
1667 bp->bio_completed = bp->bio_length;
1677 * Install a global async callback. This callback will
1678 * receive async callbacks like "new device found".
1680 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1682 if (status != CAM_REQ_CMP) {
1683 printf("da: Failed to attach master async callback "
1684 "due to status 0x%x!\n", status);
1685 } else if (da_send_ordered) {
1687 /* Register our shutdown event handler */
1688 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1689 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1690 printf("dainit: shutdown event registration failed!\n");
1695 * Callback from GEOM, called when it has finished cleaning up its
1699 dadiskgonecb(struct disk *dp)
1701 struct cam_periph *periph;
1703 periph = (struct cam_periph *)dp->d_drv1;
1704 cam_periph_release(periph);
1708 daoninvalidate(struct cam_periph *periph)
1710 struct da_softc *softc;
1712 softc = (struct da_softc *)periph->softc;
1715 * De-register any async callbacks.
1717 xpt_register_async(0, daasync, periph, periph->path);
1719 softc->flags |= DA_FLAG_PACK_INVALID;
1721 softc->invalidations++;
1725 * Return all queued I/O with ENXIO.
1726 * XXX Handle any transactions queued to the card
1727 * with XPT_ABORT_CCB.
1729 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
1732 * Tell GEOM that we've gone away, we'll get a callback when it is
1733 * done cleaning up its resources.
1735 disk_gone(softc->disk);
1739 dacleanup(struct cam_periph *periph)
1741 struct da_softc *softc;
1743 softc = (struct da_softc *)periph->softc;
1745 cam_periph_unlock(periph);
1747 cam_iosched_fini(softc->cam_iosched);
1750 * If we can't free the sysctl tree, oh well...
1752 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
1754 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1755 xpt_print(periph->path,
1756 "can't remove sysctl stats context\n");
1758 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1759 xpt_print(periph->path,
1760 "can't remove sysctl context\n");
1763 callout_drain(&softc->mediapoll_c);
1764 disk_destroy(softc->disk);
1765 callout_drain(&softc->sendordered_c);
1766 free(softc, M_DEVBUF);
1767 cam_periph_lock(periph);
1771 daasync(void *callback_arg, u_int32_t code,
1772 struct cam_path *path, void *arg)
1774 struct cam_periph *periph;
1775 struct da_softc *softc;
1777 periph = (struct cam_periph *)callback_arg;
1779 case AC_FOUND_DEVICE:
1781 struct ccb_getdev *cgd;
1784 cgd = (struct ccb_getdev *)arg;
1788 if (cgd->protocol != PROTO_SCSI)
1790 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
1792 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1793 && SID_TYPE(&cgd->inq_data) != T_RBC
1794 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
1795 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
1799 * Allocate a peripheral instance for
1800 * this device and start the probe
1803 status = cam_periph_alloc(daregister, daoninvalidate,
1805 "da", CAM_PERIPH_BIO,
1807 AC_FOUND_DEVICE, cgd);
1809 if (status != CAM_REQ_CMP
1810 && status != CAM_REQ_INPROG)
1811 printf("daasync: Unable to attach to new device "
1812 "due to status 0x%x\n", status);
1815 case AC_ADVINFO_CHANGED:
1819 buftype = (uintptr_t)arg;
1820 if (buftype == CDAI_TYPE_PHYS_PATH) {
1821 struct da_softc *softc;
1823 softc = periph->softc;
1824 disk_attr_changed(softc->disk, "GEOM::physpath",
1829 case AC_UNIT_ATTENTION:
1832 int error_code, sense_key, asc, ascq;
1834 softc = (struct da_softc *)periph->softc;
1835 ccb = (union ccb *)arg;
1838 * Handle all UNIT ATTENTIONs except our own,
1839 * as they will be handled by daerror().
1841 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1842 scsi_extract_sense_ccb(ccb,
1843 &error_code, &sense_key, &asc, &ascq)) {
1844 if (asc == 0x2A && ascq == 0x09) {
1845 xpt_print(ccb->ccb_h.path,
1846 "Capacity data has changed\n");
1847 softc->flags &= ~DA_FLAG_PROBED;
1849 } else if (asc == 0x28 && ascq == 0x00) {
1850 softc->flags &= ~DA_FLAG_PROBED;
1851 disk_media_changed(softc->disk, M_NOWAIT);
1852 } else if (asc == 0x3F && ascq == 0x03) {
1853 xpt_print(ccb->ccb_h.path,
1854 "INQUIRY data has changed\n");
1855 softc->flags &= ~DA_FLAG_PROBED;
1859 cam_periph_async(periph, code, path, arg);
1863 softc = (struct da_softc *)periph->softc;
1864 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
1865 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1866 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
1874 struct ccb_hdr *ccbh;
1876 softc = (struct da_softc *)periph->softc;
1878 * Don't fail on the expected unit attention
1881 softc->flags |= DA_FLAG_RETRY_UA;
1882 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1883 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1886 case AC_INQ_CHANGED:
1887 softc = (struct da_softc *)periph->softc;
1888 softc->flags &= ~DA_FLAG_PROBED;
1894 cam_periph_async(periph, code, path, arg);
1898 dasysctlinit(void *context, int pending)
1900 struct cam_periph *periph;
1901 struct da_softc *softc;
1902 char tmpstr[80], tmpstr2[80];
1903 struct ccb_trans_settings cts;
1905 periph = (struct cam_periph *)context;
1907 * periph was held for us when this task was enqueued
1909 if (periph->flags & CAM_PERIPH_INVALID) {
1910 cam_periph_release(periph);
1914 softc = (struct da_softc *)periph->softc;
1915 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1916 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1918 sysctl_ctx_init(&softc->sysctl_ctx);
1919 softc->flags |= DA_FLAG_SCTX_INIT;
1920 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
1921 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1922 CTLFLAG_RD, 0, tmpstr);
1923 if (softc->sysctl_tree == NULL) {
1924 printf("dasysctlinit: unable to allocate sysctl tree\n");
1925 cam_periph_release(periph);
1930 * Now register the sysctl handler, so the user can change the value on
1933 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1934 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
1935 softc, 0, dadeletemethodsysctl, "A",
1936 "BIO_DELETE execution method");
1937 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1938 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1939 softc, 0, dadeletemaxsysctl, "Q",
1940 "Maximum BIO_DELETE size");
1941 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1942 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1943 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1944 "Minimum CDB size");
1946 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1947 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
1948 softc, 0, dazonemodesysctl, "A",
1950 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1951 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
1952 softc, 0, dazonesupsysctl, "A",
1954 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1955 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1956 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
1957 "Optimal Number of Open Sequential Write Preferred Zones");
1958 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1959 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1960 "optimal_nonseq_zones", CTLFLAG_RD,
1961 &softc->optimal_nonseq_zones,
1962 "Optimal Number of Non-Sequentially Written Sequential Write "
1964 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1965 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1966 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
1967 "Maximum Number of Open Sequential Write Required Zones");
1969 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1970 SYSCTL_CHILDREN(softc->sysctl_tree),
1974 &softc->error_inject,
1976 "error_inject leaf");
1978 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1979 SYSCTL_CHILDREN(softc->sysctl_tree),
1985 "Unmapped I/O leaf");
1987 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1988 SYSCTL_CHILDREN(softc->sysctl_tree),
1997 * Add some addressing info.
1999 memset(&cts, 0, sizeof (cts));
2000 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2001 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2002 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2003 cam_periph_lock(periph);
2004 xpt_action((union ccb *)&cts);
2005 cam_periph_unlock(periph);
2006 if (cts.ccb_h.status != CAM_REQ_CMP) {
2007 cam_periph_release(periph);
2010 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2011 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2012 if (fc->valid & CTS_FC_VALID_WWPN) {
2013 softc->wwpn = fc->wwpn;
2014 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2015 SYSCTL_CHILDREN(softc->sysctl_tree),
2016 OID_AUTO, "wwpn", CTLFLAG_RD,
2017 &softc->wwpn, "World Wide Port Name");
2023 * Now add some useful stats.
2024 * XXX These should live in cam_periph and be common to all periphs
2026 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2027 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2028 CTLFLAG_RD, 0, "Statistics");
2029 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2030 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2036 "Transport errors reported by the SIM");
2037 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2038 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2044 "Device timeouts reported by the SIM");
2045 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2046 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2048 "pack_invalidations",
2050 &softc->invalidations,
2052 "Device pack invalidations");
2055 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2056 softc->sysctl_tree);
2058 cam_periph_release(periph);
2062 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2066 struct da_softc *softc;
2068 softc = (struct da_softc *)arg1;
2070 value = softc->disk->d_delmaxsize;
2071 error = sysctl_handle_64(oidp, &value, 0, req);
2072 if ((error != 0) || (req->newptr == NULL))
2075 /* only accept values smaller than the calculated value */
2076 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2079 softc->disk->d_delmaxsize = value;
2085 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2089 value = *(int *)arg1;
2091 error = sysctl_handle_int(oidp, &value, 0, req);
2094 || (req->newptr == NULL))
2098 * Acceptable values here are 6, 10, 12 or 16.
2102 else if ((value > 6)
2105 else if ((value > 10)
2108 else if (value > 12)
2111 *(int *)arg1 = value;
2117 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2122 value = da_default_softtimeout / SBT_1MS;
2124 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2125 if ((error != 0) || (req->newptr == NULL))
2128 /* XXX Should clip this to a reasonable level */
2129 if (value > da_default_timeout * 1000)
2132 da_default_softtimeout = value * SBT_1MS;
2137 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2140 softc->delete_method = delete_method;
2141 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2142 softc->delete_func = da_delete_functions[delete_method];
2144 if (softc->delete_method > DA_DELETE_DISABLE)
2145 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2147 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2151 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2155 switch(delete_method) {
2156 case DA_DELETE_UNMAP:
2157 sectors = (off_t)softc->unmap_max_lba;
2159 case DA_DELETE_ATA_TRIM:
2160 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2162 case DA_DELETE_WS16:
2163 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2165 case DA_DELETE_ZERO:
2166 case DA_DELETE_WS10:
2167 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2173 return (off_t)softc->params.secsize *
2174 omin(sectors, softc->params.sectors);
2178 daprobedone(struct cam_periph *periph, union ccb *ccb)
2180 struct da_softc *softc;
2182 softc = (struct da_softc *)periph->softc;
2184 dadeletemethodchoose(softc, DA_DELETE_NONE);
2186 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2190 snprintf(buf, sizeof(buf), "Delete methods: <");
2192 for (i = 0; i <= DA_DELETE_MAX; i++) {
2193 if ((softc->delete_available & (1 << i)) == 0 &&
2194 i != softc->delete_method)
2197 strlcat(buf, ",", sizeof(buf));
2198 strlcat(buf, da_delete_method_names[i],
2200 if (i == softc->delete_method)
2201 strlcat(buf, "(*)", sizeof(buf));
2204 strlcat(buf, ">", sizeof(buf));
2205 printf("%s%d: %s\n", periph->periph_name,
2206 periph->unit_number, buf);
2210 * Since our peripheral may be invalidated by an error
2211 * above or an external event, we must release our CCB
2212 * before releasing the probe lock on the peripheral.
2213 * The peripheral will only go away once the last lock
2214 * is removed, and we need it around for the CCB release
2217 xpt_release_ccb(ccb);
2218 softc->state = DA_STATE_NORMAL;
2219 softc->flags |= DA_FLAG_PROBED;
2221 wakeup(&softc->disk->d_mediasize);
2222 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2223 softc->flags |= DA_FLAG_ANNOUNCED;
2224 cam_periph_unhold(periph);
2226 cam_periph_release_locked(periph);
2230 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2234 /* If available, prefer the method requested by user. */
2235 i = softc->delete_method_pref;
2236 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2237 if (methods & (1 << i)) {
2238 dadeletemethodset(softc, i);
2242 /* Use the pre-defined order to choose the best performing delete. */
2243 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2244 if (i == DA_DELETE_ZERO)
2246 if (softc->delete_available & (1 << i)) {
2247 dadeletemethodset(softc, i);
2252 /* Fallback to default. */
2253 dadeletemethodset(softc, default_method);
2257 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2261 struct da_softc *softc;
2262 int i, error, methods, value;
2264 softc = (struct da_softc *)arg1;
2266 value = softc->delete_method;
2267 if (value < 0 || value > DA_DELETE_MAX)
2270 p = da_delete_method_names[value];
2271 strncpy(buf, p, sizeof(buf));
2272 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2273 if (error != 0 || req->newptr == NULL)
2275 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2276 for (i = 0; i <= DA_DELETE_MAX; i++) {
2277 if (strcmp(buf, da_delete_method_names[i]) == 0)
2280 if (i > DA_DELETE_MAX)
2282 softc->delete_method_pref = i;
2283 dadeletemethodchoose(softc, DA_DELETE_NONE);
2288 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2291 struct da_softc *softc;
2294 softc = (struct da_softc *)arg1;
2296 switch (softc->zone_mode) {
2297 case DA_ZONE_DRIVE_MANAGED:
2298 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2300 case DA_ZONE_HOST_AWARE:
2301 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2303 case DA_ZONE_HOST_MANAGED:
2304 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2308 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2312 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2318 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2321 struct da_softc *softc;
2326 softc = (struct da_softc *)arg1;
2330 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2332 for (i = 0; i < sizeof(da_zone_desc_table) /
2333 sizeof(da_zone_desc_table[0]); i++) {
2334 if (softc->zone_flags & da_zone_desc_table[i].value) {
2336 sbuf_printf(&sb, ", ");
2339 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2344 sbuf_printf(&sb, "None");
2348 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2354 daregister(struct cam_periph *periph, void *arg)
2356 struct da_softc *softc;
2357 struct ccb_pathinq cpi;
2358 struct ccb_getdev *cgd;
2362 cgd = (struct ccb_getdev *)arg;
2364 printf("daregister: no getdev CCB, can't register device\n");
2365 return(CAM_REQ_CMP_ERR);
2368 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2371 if (softc == NULL) {
2372 printf("daregister: Unable to probe new device. "
2373 "Unable to allocate softc\n");
2374 return(CAM_REQ_CMP_ERR);
2377 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2378 printf("daregister: Unable to probe new device. "
2379 "Unable to allocate iosched memory\n");
2380 free(softc, M_DEVBUF);
2381 return(CAM_REQ_CMP_ERR);
2384 LIST_INIT(&softc->pending_ccbs);
2385 softc->state = DA_STATE_PROBE_RC;
2386 bioq_init(&softc->delete_run_queue);
2387 if (SID_IS_REMOVABLE(&cgd->inq_data))
2388 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2389 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2390 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2391 softc->ws_max_blks = WS16_MAX_BLKS;
2392 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2393 softc->rotating = 1;
2395 periph->softc = softc;
2398 * See if this device has any quirks.
2400 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2401 (caddr_t)da_quirk_table,
2402 nitems(da_quirk_table),
2403 sizeof(*da_quirk_table), scsi_inquiry_match);
2406 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2408 softc->quirks = DA_Q_NONE;
2410 /* Check if the SIM does not want 6 byte commands */
2411 bzero(&cpi, sizeof(cpi));
2412 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2413 cpi.ccb_h.func_code = XPT_PATH_INQ;
2414 xpt_action((union ccb *)&cpi);
2415 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2416 softc->quirks |= DA_Q_NO_6_BYTE;
2418 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2419 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2420 else if (softc->quirks & DA_Q_SMR_DM)
2421 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2423 softc->zone_mode = DA_ZONE_NONE;
2425 if (softc->zone_mode != DA_ZONE_NONE) {
2426 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2427 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2428 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2430 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2432 softc->zone_interface = DA_ZONE_IF_SCSI;
2435 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2438 * Take an exclusive refcount on the periph while dastart is called
2439 * to finish the probe. The reference will be dropped in dadone at
2442 (void)cam_periph_hold(periph, PRIBIO);
2445 * Schedule a periodic event to occasionally send an
2446 * ordered tag to a device.
2448 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2449 callout_reset(&softc->sendordered_c,
2450 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2451 dasendorderedtag, softc);
2453 cam_periph_unlock(periph);
2455 * RBC devices don't have to support READ(6), only READ(10).
2457 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2458 softc->minimum_cmd_size = 10;
2460 softc->minimum_cmd_size = 6;
2463 * Load the user's default, if any.
2465 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2466 periph->unit_number);
2467 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2470 * 6, 10, 12 and 16 are the currently permissible values.
2472 if (softc->minimum_cmd_size < 6)
2473 softc->minimum_cmd_size = 6;
2474 else if ((softc->minimum_cmd_size > 6)
2475 && (softc->minimum_cmd_size <= 10))
2476 softc->minimum_cmd_size = 10;
2477 else if ((softc->minimum_cmd_size > 10)
2478 && (softc->minimum_cmd_size <= 12))
2479 softc->minimum_cmd_size = 12;
2480 else if (softc->minimum_cmd_size > 12)
2481 softc->minimum_cmd_size = 16;
2483 /* Predict whether device may support READ CAPACITY(16). */
2484 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2485 (softc->quirks & DA_Q_NO_RC16) == 0) {
2486 softc->flags |= DA_FLAG_CAN_RC16;
2487 softc->state = DA_STATE_PROBE_RC16;
2491 * Register this media as a disk.
2493 softc->disk = disk_alloc();
2494 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2495 periph->unit_number, 0,
2496 DEVSTAT_BS_UNAVAILABLE,
2497 SID_TYPE(&cgd->inq_data) |
2498 XPORT_DEVSTAT_TYPE(cpi.transport),
2499 DEVSTAT_PRIORITY_DISK);
2500 softc->disk->d_open = daopen;
2501 softc->disk->d_close = daclose;
2502 softc->disk->d_strategy = dastrategy;
2503 softc->disk->d_dump = dadump;
2504 softc->disk->d_getattr = dagetattr;
2505 softc->disk->d_gone = dadiskgonecb;
2506 softc->disk->d_name = "da";
2507 softc->disk->d_drv1 = periph;
2509 softc->maxio = DFLTPHYS; /* traditional default */
2510 else if (cpi.maxio > MAXPHYS)
2511 softc->maxio = MAXPHYS; /* for safety */
2513 softc->maxio = cpi.maxio;
2514 softc->disk->d_maxsize = softc->maxio;
2515 softc->disk->d_unit = periph->unit_number;
2516 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2517 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2518 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2519 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2520 softc->unmappedio = 1;
2521 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2522 xpt_print(periph->path, "UNMAPPED\n");
2524 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2525 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2526 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2527 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2528 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2529 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2530 softc->disk->d_hba_vendor = cpi.hba_vendor;
2531 softc->disk->d_hba_device = cpi.hba_device;
2532 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2533 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2536 * Acquire a reference to the periph before we register with GEOM.
2537 * We'll release this reference once GEOM calls us back (via
2538 * dadiskgonecb()) telling us that our provider has been freed.
2540 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2541 xpt_print(periph->path, "%s: lost periph during "
2542 "registration!\n", __func__);
2543 cam_periph_lock(periph);
2544 return (CAM_REQ_CMP_ERR);
2547 disk_create(softc->disk, DISK_VERSION);
2548 cam_periph_lock(periph);
2551 * Add async callbacks for events of interest.
2552 * I don't bother checking if this fails as,
2553 * in most cases, the system will function just
2554 * fine without them and the only alternative
2555 * would be to not attach the device on failure.
2557 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2558 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2559 AC_INQ_CHANGED, daasync, periph, periph->path);
2562 * Emit an attribute changed notification just in case
2563 * physical path information arrived before our async
2564 * event handler was registered, but after anyone attaching
2565 * to our disk device polled it.
2567 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2570 * Schedule a periodic media polling events.
2572 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2573 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2574 (cgd->inq_flags & SID_AEN) == 0 &&
2575 da_poll_period != 0)
2576 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2577 damediapoll, periph);
2579 xpt_schedule(periph, CAM_PRIORITY_DEV);
2581 return(CAM_REQ_CMP);
2585 da_zone_bio_to_scsi(int disk_zone_cmd)
2587 switch (disk_zone_cmd) {
2588 case DISK_ZONE_OPEN:
2589 return ZBC_OUT_SA_OPEN;
2590 case DISK_ZONE_CLOSE:
2591 return ZBC_OUT_SA_CLOSE;
2592 case DISK_ZONE_FINISH:
2593 return ZBC_OUT_SA_FINISH;
2595 return ZBC_OUT_SA_RWP;
2602 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2605 struct da_softc *softc;
2610 if (bp->bio_cmd != BIO_ZONE) {
2615 softc = periph->softc;
2617 switch (bp->bio_zone.zone_cmd) {
2618 case DISK_ZONE_OPEN:
2619 case DISK_ZONE_CLOSE:
2620 case DISK_ZONE_FINISH:
2621 case DISK_ZONE_RWP: {
2626 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2627 if (zone_sa == -1) {
2628 xpt_print(periph->path, "Cannot translate zone "
2629 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2635 lba = bp->bio_zone.zone_params.rwp.id;
2637 if (bp->bio_zone.zone_params.rwp.flags &
2638 DISK_ZONE_RWP_FLAG_ALL)
2639 zone_flags |= ZBC_OUT_ALL;
2641 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2642 scsi_zbc_out(&ccb->csio,
2643 /*retries*/ da_retry_count,
2645 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2646 /*service_action*/ zone_sa,
2648 /*zone_flags*/ zone_flags,
2651 /*sense_len*/ SSD_FULL_SIZE,
2652 /*timeout*/ da_default_timeout * 1000);
2655 * Note that in this case, even though we can
2656 * technically use NCQ, we don't bother for several
2658 * 1. It hasn't been tested on a SAT layer that
2659 * supports it. This is new as of SAT-4.
2660 * 2. Even when there is a SAT layer that supports
2661 * it, that SAT layer will also probably support
2662 * ZBC -> ZAC translation, since they are both
2663 * in the SAT-4 spec.
2664 * 3. Translation will likely be preferable to ATA
2665 * passthrough. LSI / Avago at least single
2666 * steps ATA passthrough commands in the HBA,
2667 * regardless of protocol, so unless that
2668 * changes, there is a performance penalty for
2669 * doing ATA passthrough no matter whether
2670 * you're using NCQ/FPDMA, DMA or PIO.
2671 * 4. It requires a 32-byte CDB, which at least at
2672 * this point in CAM requires a CDB pointer, which
2673 * would require us to allocate an additional bit
2674 * of storage separate from the CCB.
2676 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2677 /*retries*/ da_retry_count,
2679 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2681 /*zm_action*/ zone_sa,
2683 /*zone_flags*/ zone_flags,
2686 /*cdb_storage*/ NULL,
2687 /*cdb_storage_len*/ 0,
2688 /*sense_len*/ SSD_FULL_SIZE,
2689 /*timeout*/ da_default_timeout * 1000);
2692 xpt_print(periph->path,
2693 "scsi_ata_zac_mgmt_out() returned an "
2702 case DISK_ZONE_REPORT_ZONES: {
2704 uint32_t num_entries, alloc_size;
2705 struct disk_zone_report *rep;
2707 rep = &bp->bio_zone.zone_params.report;
2709 num_entries = rep->entries_allocated;
2710 if (num_entries == 0) {
2711 xpt_print(periph->path, "No entries allocated for "
2712 "Report Zones request\n");
2716 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2717 (sizeof(struct scsi_report_zones_desc) * num_entries);
2718 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2719 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2720 if (rz_ptr == NULL) {
2721 xpt_print(periph->path, "Unable to allocate memory "
2722 "for Report Zones request\n");
2727 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2728 scsi_zbc_in(&ccb->csio,
2729 /*retries*/ da_retry_count,
2731 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2732 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2733 /*zone_start_lba*/ rep->starting_id,
2734 /*zone_options*/ rep->rep_options,
2735 /*data_ptr*/ rz_ptr,
2736 /*dxfer_len*/ alloc_size,
2737 /*sense_len*/ SSD_FULL_SIZE,
2738 /*timeout*/ da_default_timeout * 1000);
2741 * Note that in this case, even though we can
2742 * technically use NCQ, we don't bother for several
2744 * 1. It hasn't been tested on a SAT layer that
2745 * supports it. This is new as of SAT-4.
2746 * 2. Even when there is a SAT layer that supports
2747 * it, that SAT layer will also probably support
2748 * ZBC -> ZAC translation, since they are both
2749 * in the SAT-4 spec.
2750 * 3. Translation will likely be preferable to ATA
2751 * passthrough. LSI / Avago at least single
2752 * steps ATA passthrough commands in the HBA,
2753 * regardless of protocol, so unless that
2754 * changes, there is a performance penalty for
2755 * doing ATA passthrough no matter whether
2756 * you're using NCQ/FPDMA, DMA or PIO.
2757 * 4. It requires a 32-byte CDB, which at least at
2758 * this point in CAM requires a CDB pointer, which
2759 * would require us to allocate an additional bit
2760 * of storage separate from the CCB.
2762 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2763 /*retries*/ da_retry_count,
2765 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2767 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2768 /*zone_id*/ rep->starting_id,
2769 /*zone_flags*/ rep->rep_options,
2770 /*data_ptr*/ rz_ptr,
2771 /*dxfer_len*/ alloc_size,
2772 /*cdb_storage*/ NULL,
2773 /*cdb_storage_len*/ 0,
2774 /*sense_len*/ SSD_FULL_SIZE,
2775 /*timeout*/ da_default_timeout * 1000);
2778 xpt_print(periph->path,
2779 "scsi_ata_zac_mgmt_in() returned an "
2786 * For BIO_ZONE, this isn't normally needed. However, it
2787 * is used by devstat_end_transaction_bio() to determine
2788 * how much data was transferred.
2791 * XXX KDM we have a problem. But I'm not sure how to fix
2792 * it. devstat uses bio_bcount - bio_resid to calculate
2793 * the amount of data transferred. The GEOM disk code
2794 * uses bio_length - bio_resid to calculate the amount of
2795 * data in bio_completed. We have different structure
2796 * sizes above and below the ada(4) driver. So, if we
2797 * use the sizes above, the amount transferred won't be
2798 * quite accurate for devstat. If we use different sizes
2799 * for bio_bcount and bio_length (above and below
2800 * respectively), then the residual needs to match one or
2801 * the other. Everything is calculated after the bio
2802 * leaves the driver, so changing the values around isn't
2803 * really an option. For now, just set the count to the
2804 * passed in length. This means that the calculations
2805 * above (e.g. bio_completed) will be correct, but the
2806 * amount of data reported to devstat will be slightly
2807 * under or overstated.
2809 bp->bio_bcount = bp->bio_length;
2815 case DISK_ZONE_GET_PARAMS: {
2816 struct disk_zone_disk_params *params;
2818 params = &bp->bio_zone.zone_params.disk_params;
2819 bzero(params, sizeof(*params));
2821 switch (softc->zone_mode) {
2822 case DA_ZONE_DRIVE_MANAGED:
2823 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
2825 case DA_ZONE_HOST_AWARE:
2826 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
2828 case DA_ZONE_HOST_MANAGED:
2829 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
2833 params->zone_mode = DISK_ZONE_MODE_NONE;
2837 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
2838 params->flags |= DISK_ZONE_DISK_URSWRZ;
2840 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
2841 params->optimal_seq_zones = softc->optimal_seq_zones;
2842 params->flags |= DISK_ZONE_OPT_SEQ_SET;
2845 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
2846 params->optimal_nonseq_zones =
2847 softc->optimal_nonseq_zones;
2848 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
2851 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
2852 params->max_seq_zones = softc->max_seq_zones;
2853 params->flags |= DISK_ZONE_MAX_SEQ_SET;
2855 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
2856 params->flags |= DISK_ZONE_RZ_SUP;
2858 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
2859 params->flags |= DISK_ZONE_OPEN_SUP;
2861 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
2862 params->flags |= DISK_ZONE_CLOSE_SUP;
2864 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
2865 params->flags |= DISK_ZONE_FINISH_SUP;
2867 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
2868 params->flags |= DISK_ZONE_RWP_SUP;
2879 dastart(struct cam_periph *periph, union ccb *start_ccb)
2881 struct da_softc *softc;
2883 softc = (struct da_softc *)periph->softc;
2885 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2888 switch (softc->state) {
2889 case DA_STATE_NORMAL:
2895 bp = cam_iosched_next_bio(softc->cam_iosched);
2897 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2898 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2899 scsi_test_unit_ready(&start_ccb->csio,
2900 /*retries*/ da_retry_count,
2904 da_default_timeout * 1000);
2905 start_ccb->ccb_h.ccb_bp = NULL;
2906 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2907 xpt_action(start_ccb);
2909 xpt_release_ccb(start_ccb);
2913 if (bp->bio_cmd == BIO_DELETE) {
2914 if (softc->delete_func != NULL) {
2915 softc->delete_func(periph, start_ccb, bp);
2918 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
2919 biofinish(bp, NULL, 0);
2924 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2925 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2926 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */
2929 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2930 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2931 softc->flags &= ~DA_FLAG_NEED_OTAG;
2932 softc->flags |= DA_FLAG_WAS_OTAG;
2933 tag_code = MSG_ORDERED_Q_TAG;
2935 tag_code = MSG_SIMPLE_Q_TAG;
2938 switch (bp->bio_cmd) {
2945 if (bp->bio_cmd == BIO_WRITE) {
2946 softc->flags |= DA_FLAG_DIRTY;
2947 rw_op = SCSI_RW_WRITE;
2949 rw_op = SCSI_RW_READ;
2952 data_ptr = bp->bio_data;
2953 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
2954 rw_op |= SCSI_RW_BIO;
2958 scsi_read_write(&start_ccb->csio,
2959 /*retries*/da_retry_count,
2961 /*tag_action*/tag_code,
2964 softc->minimum_cmd_size,
2965 /*lba*/bp->bio_pblkno,
2966 /*block_count*/bp->bio_bcount /
2967 softc->params.secsize,
2969 /*dxfer_len*/ bp->bio_bcount,
2970 /*sense_len*/SSD_FULL_SIZE,
2971 da_default_timeout * 1000);
2976 * BIO_FLUSH doesn't currently communicate
2977 * range data, so we synchronize the cache
2978 * over the whole disk. We also force
2979 * ordered tag semantics the flush applies
2980 * to all previously queued I/O.
2982 scsi_synchronize_cache(&start_ccb->csio,
2989 da_default_timeout*1000);
2992 int error, queue_ccb;
2996 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
2998 || (queue_ccb == 0)) {
2999 biofinish(bp, NULL, error);
3000 xpt_release_ccb(start_ccb);
3006 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3007 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3008 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3011 LIST_INSERT_HEAD(&softc->pending_ccbs,
3012 &start_ccb->ccb_h, periph_links.le);
3014 /* We expect a unit attention from this device */
3015 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3016 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3017 softc->flags &= ~DA_FLAG_RETRY_UA;
3020 start_ccb->ccb_h.ccb_bp = bp;
3022 cam_periph_unlock(periph);
3023 xpt_action(start_ccb);
3024 cam_periph_lock(periph);
3027 /* May have more work to do, so ensure we stay scheduled */
3031 case DA_STATE_PROBE_RC:
3033 struct scsi_read_capacity_data *rcap;
3035 rcap = (struct scsi_read_capacity_data *)
3036 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3038 printf("dastart: Couldn't malloc read_capacity data\n");
3039 /* da_free_periph??? */
3042 scsi_read_capacity(&start_ccb->csio,
3043 /*retries*/da_retry_count,
3049 start_ccb->ccb_h.ccb_bp = NULL;
3050 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3051 xpt_action(start_ccb);
3054 case DA_STATE_PROBE_RC16:
3056 struct scsi_read_capacity_data_long *rcaplong;
3058 rcaplong = (struct scsi_read_capacity_data_long *)
3059 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3060 if (rcaplong == NULL) {
3061 printf("dastart: Couldn't malloc read_capacity data\n");
3062 /* da_free_periph??? */
3065 scsi_read_capacity_16(&start_ccb->csio,
3066 /*retries*/ da_retry_count,
3068 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3072 /*rcap_buf*/ (uint8_t *)rcaplong,
3073 /*rcap_buf_len*/ sizeof(*rcaplong),
3074 /*sense_len*/ SSD_FULL_SIZE,
3075 /*timeout*/ da_default_timeout * 1000);
3076 start_ccb->ccb_h.ccb_bp = NULL;
3077 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3078 xpt_action(start_ccb);
3081 case DA_STATE_PROBE_LBP:
3083 struct scsi_vpd_logical_block_prov *lbp;
3085 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3087 * If we get here we don't support any SBC-3 delete
3088 * methods with UNMAP as the Logical Block Provisioning
3089 * VPD page support is required for devices which
3090 * support it according to T10/1799-D Revision 31
3091 * however older revisions of the spec don't mandate
3092 * this so we currently don't remove these methods
3093 * from the available set.
3095 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3099 lbp = (struct scsi_vpd_logical_block_prov *)
3100 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3103 printf("dastart: Couldn't malloc lbp data\n");
3104 /* da_free_periph??? */
3108 scsi_inquiry(&start_ccb->csio,
3109 /*retries*/da_retry_count,
3111 /*tag_action*/MSG_SIMPLE_Q_TAG,
3112 /*inq_buf*/(u_int8_t *)lbp,
3113 /*inq_len*/sizeof(*lbp),
3115 /*page_code*/SVPD_LBP,
3116 /*sense_len*/SSD_MIN_SIZE,
3117 /*timeout*/da_default_timeout * 1000);
3118 start_ccb->ccb_h.ccb_bp = NULL;
3119 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3120 xpt_action(start_ccb);
3123 case DA_STATE_PROBE_BLK_LIMITS:
3125 struct scsi_vpd_block_limits *block_limits;
3127 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3128 /* Not supported skip to next probe */
3129 softc->state = DA_STATE_PROBE_BDC;
3133 block_limits = (struct scsi_vpd_block_limits *)
3134 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3136 if (block_limits == NULL) {
3137 printf("dastart: Couldn't malloc block_limits data\n");
3138 /* da_free_periph??? */
3142 scsi_inquiry(&start_ccb->csio,
3143 /*retries*/da_retry_count,
3145 /*tag_action*/MSG_SIMPLE_Q_TAG,
3146 /*inq_buf*/(u_int8_t *)block_limits,
3147 /*inq_len*/sizeof(*block_limits),
3149 /*page_code*/SVPD_BLOCK_LIMITS,
3150 /*sense_len*/SSD_MIN_SIZE,
3151 /*timeout*/da_default_timeout * 1000);
3152 start_ccb->ccb_h.ccb_bp = NULL;
3153 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3154 xpt_action(start_ccb);
3157 case DA_STATE_PROBE_BDC:
3159 struct scsi_vpd_block_characteristics *bdc;
3161 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3162 softc->state = DA_STATE_PROBE_ATA;
3166 bdc = (struct scsi_vpd_block_characteristics *)
3167 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3170 printf("dastart: Couldn't malloc bdc data\n");
3171 /* da_free_periph??? */
3175 scsi_inquiry(&start_ccb->csio,
3176 /*retries*/da_retry_count,
3178 /*tag_action*/MSG_SIMPLE_Q_TAG,
3179 /*inq_buf*/(u_int8_t *)bdc,
3180 /*inq_len*/sizeof(*bdc),
3182 /*page_code*/SVPD_BDC,
3183 /*sense_len*/SSD_MIN_SIZE,
3184 /*timeout*/da_default_timeout * 1000);
3185 start_ccb->ccb_h.ccb_bp = NULL;
3186 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3187 xpt_action(start_ccb);
3190 case DA_STATE_PROBE_ATA:
3192 struct ata_params *ata_params;
3194 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3195 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3196 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3198 * Note that if the ATA VPD page isn't
3199 * supported, we aren't talking to an ATA
3200 * device anyway. Support for that VPD
3201 * page is mandatory for SCSI to ATA (SAT)
3202 * translation layers.
3204 softc->state = DA_STATE_PROBE_ZONE;
3207 daprobedone(periph, start_ccb);
3211 ata_params = (struct ata_params*)
3212 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3214 if (ata_params == NULL) {
3215 xpt_print(periph->path, "Couldn't malloc ata_params "
3217 /* da_free_periph??? */
3221 scsi_ata_identify(&start_ccb->csio,
3222 /*retries*/da_retry_count,
3224 /*tag_action*/MSG_SIMPLE_Q_TAG,
3225 /*data_ptr*/(u_int8_t *)ata_params,
3226 /*dxfer_len*/sizeof(*ata_params),
3227 /*sense_len*/SSD_FULL_SIZE,
3228 /*timeout*/da_default_timeout * 1000);
3229 start_ccb->ccb_h.ccb_bp = NULL;
3230 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3231 xpt_action(start_ccb);
3234 case DA_STATE_PROBE_ATA_LOGDIR:
3236 struct ata_gp_log_dir *log_dir;
3241 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3243 * If we don't have log support, not much point in
3244 * trying to probe zone support.
3246 daprobedone(periph, start_ccb);
3251 * If we have an ATA device (the SCSI ATA Information VPD
3252 * page should be present and the ATA identify should have
3253 * succeeded) and it supports logs, ask for the log directory.
3256 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3257 if (log_dir == NULL) {
3258 xpt_print(periph->path, "Couldn't malloc log_dir "
3260 daprobedone(periph, start_ccb);
3264 retval = scsi_ata_read_log(&start_ccb->csio,
3265 /*retries*/ da_retry_count,
3267 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3268 /*log_address*/ ATA_LOG_DIRECTORY,
3271 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3272 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3273 /*data_ptr*/ (uint8_t *)log_dir,
3274 /*dxfer_len*/ sizeof(*log_dir),
3275 /*sense_len*/ SSD_FULL_SIZE,
3276 /*timeout*/ da_default_timeout * 1000);
3279 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3280 free(log_dir, M_SCSIDA);
3281 daprobedone(periph, start_ccb);
3284 start_ccb->ccb_h.ccb_bp = NULL;
3285 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3286 xpt_action(start_ccb);
3289 case DA_STATE_PROBE_ATA_IDDIR:
3291 struct ata_identify_log_pages *id_dir;
3297 * Check here to see whether the Identify Device log is
3298 * supported in the directory of logs. If so, continue
3299 * with requesting the log of identify device pages.
3301 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3302 daprobedone(periph, start_ccb);
3306 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3307 if (id_dir == NULL) {
3308 xpt_print(periph->path, "Couldn't malloc id_dir "
3310 daprobedone(periph, start_ccb);
3314 retval = scsi_ata_read_log(&start_ccb->csio,
3315 /*retries*/ da_retry_count,
3317 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3318 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3319 /*page_number*/ ATA_IDL_PAGE_LIST,
3321 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3322 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3323 /*data_ptr*/ (uint8_t *)id_dir,
3324 /*dxfer_len*/ sizeof(*id_dir),
3325 /*sense_len*/ SSD_FULL_SIZE,
3326 /*timeout*/ da_default_timeout * 1000);
3329 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3330 free(id_dir, M_SCSIDA);
3331 daprobedone(periph, start_ccb);
3334 start_ccb->ccb_h.ccb_bp = NULL;
3335 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3336 xpt_action(start_ccb);
3339 case DA_STATE_PROBE_ATA_SUP:
3341 struct ata_identify_log_sup_cap *sup_cap;
3347 * Check here to see whether the Supported Capabilities log
3348 * is in the list of Identify Device logs.
3350 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3351 daprobedone(periph, start_ccb);
3355 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3356 if (sup_cap == NULL) {
3357 xpt_print(periph->path, "Couldn't malloc sup_cap "
3359 daprobedone(periph, start_ccb);
3363 retval = scsi_ata_read_log(&start_ccb->csio,
3364 /*retries*/ da_retry_count,
3366 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3367 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3368 /*page_number*/ ATA_IDL_SUP_CAP,
3370 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3371 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3372 /*data_ptr*/ (uint8_t *)sup_cap,
3373 /*dxfer_len*/ sizeof(*sup_cap),
3374 /*sense_len*/ SSD_FULL_SIZE,
3375 /*timeout*/ da_default_timeout * 1000);
3378 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3379 free(sup_cap, M_SCSIDA);
3380 daprobedone(periph, start_ccb);
3385 start_ccb->ccb_h.ccb_bp = NULL;
3386 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3387 xpt_action(start_ccb);
3390 case DA_STATE_PROBE_ATA_ZONE:
3392 struct ata_zoned_info_log *ata_zone;
3398 * Check here to see whether the zoned device information
3399 * page is supported. If so, continue on to request it.
3400 * If not, skip to DA_STATE_PROBE_LOG or done.
3402 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3403 daprobedone(periph, start_ccb);
3406 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3408 if (ata_zone == NULL) {
3409 xpt_print(periph->path, "Couldn't malloc ata_zone "
3411 daprobedone(periph, start_ccb);
3415 retval = scsi_ata_read_log(&start_ccb->csio,
3416 /*retries*/ da_retry_count,
3418 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3419 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3420 /*page_number*/ ATA_IDL_ZDI,
3422 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3423 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3424 /*data_ptr*/ (uint8_t *)ata_zone,
3425 /*dxfer_len*/ sizeof(*ata_zone),
3426 /*sense_len*/ SSD_FULL_SIZE,
3427 /*timeout*/ da_default_timeout * 1000);
3430 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3431 free(ata_zone, M_SCSIDA);
3432 daprobedone(periph, start_ccb);
3435 start_ccb->ccb_h.ccb_bp = NULL;
3436 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3437 xpt_action(start_ccb);
3441 case DA_STATE_PROBE_ZONE:
3443 struct scsi_vpd_zoned_bdc *bdc;
3446 * Note that this page will be supported for SCSI protocol
3447 * devices that support ZBC (SMR devices), as well as ATA
3448 * protocol devices that are behind a SAT (SCSI to ATA
3449 * Translation) layer that supports converting ZBC commands
3450 * to their ZAC equivalents.
3452 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3453 daprobedone(periph, start_ccb);
3456 bdc = (struct scsi_vpd_zoned_bdc *)
3457 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3460 xpt_release_ccb(start_ccb);
3461 xpt_print(periph->path, "Couldn't malloc zone VPD "
3465 scsi_inquiry(&start_ccb->csio,
3466 /*retries*/da_retry_count,
3468 /*tag_action*/MSG_SIMPLE_Q_TAG,
3469 /*inq_buf*/(u_int8_t *)bdc,
3470 /*inq_len*/sizeof(*bdc),
3472 /*page_code*/SVPD_ZONED_BDC,
3473 /*sense_len*/SSD_FULL_SIZE,
3474 /*timeout*/da_default_timeout * 1000);
3475 start_ccb->ccb_h.ccb_bp = NULL;
3476 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3477 xpt_action(start_ccb);
3484 * In each of the methods below, while its the caller's
3485 * responsibility to ensure the request will fit into a
3486 * single device request, we might have changed the delete
3487 * method due to the device incorrectly advertising either
3488 * its supported methods or limits.
3490 * To prevent this causing further issues we validate the
3491 * against the methods limits, and warn which would
3492 * otherwise be unnecessary.
3495 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3497 struct da_softc *softc = (struct da_softc *)periph->softc;;
3499 uint8_t *buf = softc->unmap_buf;
3500 uint64_t lba, lastlba = (uint64_t)-1;
3501 uint64_t totalcount = 0;
3503 uint32_t lastcount = 0, c;
3504 uint32_t off, ranges = 0;
3507 * Currently this doesn't take the UNMAP
3508 * Granularity and Granularity Alignment
3509 * fields into account.
3511 * This could result in both unoptimal unmap
3512 * requests as as well as UNMAP calls unmapping
3513 * fewer LBA's than requested.
3516 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3520 * Note: ada and da are different in how they store the
3521 * pending bp's in a trim. ada stores all of them in the
3522 * trim_req.bps. da stores all but the first one in the
3523 * delete_run_queue. ada then completes all the bps in
3524 * its adadone() loop. da completes all the bps in the
3525 * delete_run_queue in dadone, and relies on the biodone
3526 * after to complete. This should be reconciled since there's
3527 * no real reason to do it differently. XXX
3530 bioq_insert_tail(&softc->delete_run_queue, bp1);
3531 lba = bp1->bio_pblkno;
3532 count = bp1->bio_bcount / softc->params.secsize;
3534 /* Try to extend the previous range. */
3535 if (lba == lastlba) {
3536 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3538 off = ((ranges - 1) * UNMAP_RANGE_SIZE) +
3540 scsi_ulto4b(lastcount, &buf[off + 8]);
3547 c = omin(count, UNMAP_RANGE_MAX);
3548 if (totalcount + c > softc->unmap_max_lba ||
3549 ranges >= softc->unmap_max_ranges) {
3550 xpt_print(periph->path,
3551 "%s issuing short delete %ld > %ld"
3553 da_delete_method_desc[softc->delete_method],
3554 totalcount + c, softc->unmap_max_lba,
3555 ranges, softc->unmap_max_ranges);
3558 off = (ranges * UNMAP_RANGE_SIZE) + UNMAP_HEAD_SIZE;
3559 scsi_u64to8b(lba, &buf[off + 0]);
3560 scsi_ulto4b(c, &buf[off + 8]);
3568 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3571 if (ranges >= softc->unmap_max_ranges ||
3572 totalcount + bp1->bio_bcount /
3573 softc->params.secsize > softc->unmap_max_lba) {
3574 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3578 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3579 scsi_ulto2b(ranges * 16, &buf[2]);
3581 scsi_unmap(&ccb->csio,
3582 /*retries*/da_retry_count,
3584 /*tag_action*/MSG_SIMPLE_Q_TAG,
3587 /*dxfer_len*/ ranges * 16 + 8,
3588 /*sense_len*/SSD_FULL_SIZE,
3589 da_default_timeout * 1000);
3590 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3591 ccb->ccb_h.flags |= CAM_UNLOCKED;
3592 cam_iosched_submit_trim(softc->cam_iosched);
3596 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3598 struct da_softc *softc = (struct da_softc *)periph->softc;
3600 uint8_t *buf = softc->unmap_buf;
3601 uint64_t lastlba = (uint64_t)-1;
3604 uint32_t lastcount = 0, c, requestcount;
3605 int ranges = 0, off, block_count;
3607 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3610 if (bp1 != bp)//XXX imp XXX
3611 bioq_insert_tail(&softc->delete_run_queue, bp1);
3612 lba = bp1->bio_pblkno;
3613 count = bp1->bio_bcount / softc->params.secsize;
3614 requestcount = count;
3616 /* Try to extend the previous range. */
3617 if (lba == lastlba) {
3618 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3620 off = (ranges - 1) * 8;
3621 buf[off + 6] = lastcount & 0xff;
3622 buf[off + 7] = (lastcount >> 8) & 0xff;
3628 c = omin(count, ATA_DSM_RANGE_MAX);
3631 buf[off + 0] = lba & 0xff;
3632 buf[off + 1] = (lba >> 8) & 0xff;
3633 buf[off + 2] = (lba >> 16) & 0xff;
3634 buf[off + 3] = (lba >> 24) & 0xff;
3635 buf[off + 4] = (lba >> 32) & 0xff;
3636 buf[off + 5] = (lba >> 40) & 0xff;
3637 buf[off + 6] = c & 0xff;
3638 buf[off + 7] = (c >> 8) & 0xff;
3643 if (count != 0 && ranges == softc->trim_max_ranges) {
3644 xpt_print(periph->path,
3645 "%s issuing short delete %ld > %ld\n",
3646 da_delete_method_desc[softc->delete_method],
3648 (softc->trim_max_ranges - ranges) *
3654 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3657 if (bp1->bio_bcount / softc->params.secsize >
3658 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3659 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3664 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3665 scsi_ata_trim(&ccb->csio,
3666 /*retries*/da_retry_count,
3668 /*tag_action*/MSG_SIMPLE_Q_TAG,
3671 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3672 /*sense_len*/SSD_FULL_SIZE,
3673 da_default_timeout * 1000);
3674 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3675 ccb->ccb_h.flags |= CAM_UNLOCKED;
3676 cam_iosched_submit_trim(softc->cam_iosched);
3680 * We calculate ws_max_blks here based off d_delmaxsize instead
3681 * of using softc->ws_max_blks as it is absolute max for the
3682 * device not the protocol max which may well be lower.
3685 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3687 struct da_softc *softc;
3689 uint64_t ws_max_blks;
3691 uint64_t count; /* forward compat with WS32 */
3693 softc = (struct da_softc *)periph->softc;
3694 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3695 lba = bp->bio_pblkno;
3699 if (bp1 != bp)//XXX imp XXX
3700 bioq_insert_tail(&softc->delete_run_queue, bp1);
3701 count += bp1->bio_bcount / softc->params.secsize;
3702 if (count > ws_max_blks) {
3703 xpt_print(periph->path,
3704 "%s issuing short delete %ld > %ld\n",
3705 da_delete_method_desc[softc->delete_method],
3706 count, ws_max_blks);
3707 count = omin(count, ws_max_blks);
3710 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3713 if (lba + count != bp1->bio_pblkno ||
3714 count + bp1->bio_bcount /
3715 softc->params.secsize > ws_max_blks) {
3716 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3721 scsi_write_same(&ccb->csio,
3722 /*retries*/da_retry_count,
3724 /*tag_action*/MSG_SIMPLE_Q_TAG,
3725 /*byte2*/softc->delete_method ==
3726 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3727 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3729 /*block_count*/count,
3730 /*data_ptr*/ __DECONST(void *, zero_region),
3731 /*dxfer_len*/ softc->params.secsize,
3732 /*sense_len*/SSD_FULL_SIZE,
3733 da_default_timeout * 1000);
3734 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3735 ccb->ccb_h.flags |= CAM_UNLOCKED;
3736 cam_iosched_submit_trim(softc->cam_iosched);
3740 cmd6workaround(union ccb *ccb)
3742 struct scsi_rw_6 cmd6;
3743 struct scsi_rw_10 *cmd10;
3744 struct da_softc *softc;
3749 cdb = ccb->csio.cdb_io.cdb_bytes;
3750 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3752 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3753 da_delete_methods old_method = softc->delete_method;
3756 * Typically there are two reasons for failure here
3757 * 1. Delete method was detected as supported but isn't
3758 * 2. Delete failed due to invalid params e.g. too big
3760 * While we will attempt to choose an alternative delete method
3761 * this may result in short deletes if the existing delete
3762 * requests from geom are big for the new method chosen.
3764 * This method assumes that the error which triggered this
3765 * will not retry the io otherwise a panic will occur
3767 dadeleteflag(softc, old_method, 0);
3768 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3769 if (softc->delete_method == DA_DELETE_DISABLE)
3770 xpt_print(ccb->ccb_h.path,
3771 "%s failed, disabling BIO_DELETE\n",
3772 da_delete_method_desc[old_method]);
3774 xpt_print(ccb->ccb_h.path,
3775 "%s failed, switching to %s BIO_DELETE\n",
3776 da_delete_method_desc[old_method],
3777 da_delete_method_desc[softc->delete_method]);
3779 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3780 cam_iosched_queue_work(softc->cam_iosched, bp);
3781 cam_iosched_queue_work(softc->cam_iosched,
3782 (struct bio *)ccb->ccb_h.ccb_bp);
3783 ccb->ccb_h.ccb_bp = NULL;
3787 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3788 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3789 (*cdb == PREVENT_ALLOW) &&
3790 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3792 xpt_print(ccb->ccb_h.path,
3793 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3794 softc->quirks |= DA_Q_NO_PREVENT;
3798 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3799 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3800 (*cdb == SYNCHRONIZE_CACHE) &&
3801 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3803 xpt_print(ccb->ccb_h.path,
3804 "SYNCHRONIZE CACHE(10) not supported.\n");
3805 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3806 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3810 /* Translation only possible if CDB is an array and cmd is R/W6 */
3811 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3812 (*cdb != READ_6 && *cdb != WRITE_6))
3815 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3816 "increasing minimum_cmd_size to 10.\n");
3817 softc->minimum_cmd_size = 10;
3819 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3820 cmd10 = (struct scsi_rw_10 *)cdb;
3821 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3823 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3824 cmd10->reserved = 0;
3825 scsi_ulto2b(cmd6.length, cmd10->length);
3826 cmd10->control = cmd6.control;
3827 ccb->csio.cdb_len = sizeof(*cmd10);
3829 /* Requeue request, unfreezing queue if necessary */
3830 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3831 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3834 cam_release_devq(ccb->ccb_h.path,
3838 /*getcount_only*/0);
3844 dazonedone(struct cam_periph *periph, union ccb *ccb)
3846 struct da_softc *softc;
3849 softc = periph->softc;
3850 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3852 switch (bp->bio_zone.zone_cmd) {
3853 case DISK_ZONE_OPEN:
3854 case DISK_ZONE_CLOSE:
3855 case DISK_ZONE_FINISH:
3858 case DISK_ZONE_REPORT_ZONES: {
3860 struct disk_zone_report *rep;
3861 struct scsi_report_zones_hdr *hdr;
3862 struct scsi_report_zones_desc *desc;
3863 struct disk_zone_rep_entry *entry;
3864 uint32_t num_alloced, hdr_len, num_avail;
3865 uint32_t num_to_fill, i;
3868 rep = &bp->bio_zone.zone_params.report;
3869 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
3871 * Note that bio_resid isn't normally used for zone
3872 * commands, but it is used by devstat_end_transaction_bio()
3873 * to determine how much data was transferred. Because
3874 * the size of the SCSI/ATA data structures is different
3875 * than the size of the BIO interface structures, the
3876 * amount of data actually transferred from the drive will
3877 * be different than the amount of data transferred to
3880 bp->bio_resid = ccb->csio.resid;
3881 num_alloced = rep->entries_allocated;
3882 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
3883 if (avail_len < sizeof(*hdr)) {
3885 * Is there a better error than EIO here? We asked
3886 * for at least the header, and we got less than
3889 bp->bio_error = EIO;
3890 bp->bio_flags |= BIO_ERROR;
3891 bp->bio_resid = bp->bio_bcount;
3895 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
3900 hdr_len = ata ? le32dec(hdr->length) :
3901 scsi_4btoul(hdr->length);
3903 rep->entries_available = hdr_len / sizeof(*desc);
3905 rep->entries_available = 0;
3907 * NOTE: using the same values for the BIO version of the
3908 * same field as the SCSI/ATA values. This means we could
3909 * get some additional values that aren't defined in bio.h
3910 * if more values of the same field are defined later.
3912 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
3913 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
3914 scsi_8btou64(hdr->maximum_lba);
3916 * If the drive reports no entries that match the query,
3920 rep->entries_filled = 0;
3924 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
3925 hdr_len / sizeof(*desc));
3927 * If the drive didn't return any data, then we're done.
3929 if (num_avail == 0) {
3930 rep->entries_filled = 0;
3934 num_to_fill = min(num_avail, rep->entries_allocated);
3936 * If the user didn't allocate any entries for us to fill,
3939 if (num_to_fill == 0) {
3940 rep->entries_filled = 0;
3944 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
3945 i < num_to_fill; i++, desc++, entry++) {
3947 * NOTE: we're mapping the values here directly
3948 * from the SCSI/ATA bit definitions to the bio.h
3949 * definitons. There is also a warning in
3950 * disk_zone.h, but the impact is that if
3951 * additional values are added in the SCSI/ATA
3952 * specs these will be visible to consumers of
3955 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
3956 entry->zone_condition =
3957 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
3958 SRZ_ZONE_COND_SHIFT;
3959 entry->zone_flags |= desc->zone_flags &
3960 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
3961 entry->zone_length =
3962 ata ? le64dec(desc->zone_length) :
3963 scsi_8btou64(desc->zone_length);
3964 entry->zone_start_lba =
3965 ata ? le64dec(desc->zone_start_lba) :
3966 scsi_8btou64(desc->zone_start_lba);
3967 entry->write_pointer_lba =
3968 ata ? le64dec(desc->write_pointer_lba) :
3969 scsi_8btou64(desc->write_pointer_lba);
3971 rep->entries_filled = num_to_fill;
3974 case DISK_ZONE_GET_PARAMS:
3977 * In theory we should not get a GET_PARAMS bio, since it
3978 * should be handled without queueing the command to the
3981 panic("%s: Invalid zone command %d", __func__,
3982 bp->bio_zone.zone_cmd);
3986 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
3987 free(ccb->csio.data_ptr, M_SCSIDA);
3991 dadone(struct cam_periph *periph, union ccb *done_ccb)
3993 struct da_softc *softc;
3994 struct ccb_scsiio *csio;
3998 softc = (struct da_softc *)periph->softc;
3999 priority = done_ccb->ccb_h.pinfo.priority;
4001 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4003 csio = &done_ccb->csio;
4004 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4006 case DA_CCB_BUFFER_IO:
4009 struct bio *bp, *bp1;
4011 cam_periph_lock(periph);
4012 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4013 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4017 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4022 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4023 if (error == ERESTART) {
4025 * A retry was scheduled, so
4028 cam_periph_unlock(periph);
4031 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4036 * return all queued I/O with EIO, so that
4037 * the client can retry these I/Os in the
4038 * proper order should it attempt to recover.
4043 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4045 * Catastrophic error. Mark our pack as
4049 * XXX See if this is really a media
4052 xpt_print(periph->path,
4053 "Invalidating pack\n");
4054 softc->flags |= DA_FLAG_PACK_INVALID;
4056 softc->invalidations++;
4058 queued_error = ENXIO;
4060 cam_iosched_flush(softc->cam_iosched, NULL,
4063 bp->bio_error = error;
4064 bp->bio_resid = bp->bio_bcount;
4065 bp->bio_flags |= BIO_ERROR;
4067 } else if (bp != NULL) {
4068 if (state == DA_CCB_DELETE)
4071 bp->bio_resid = csio->resid;
4073 if (bp->bio_resid != 0)
4074 bp->bio_flags |= BIO_ERROR;
4076 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4077 cam_release_devq(done_ccb->ccb_h.path,
4081 /*getcount_only*/0);
4082 } else if (bp != NULL) {
4083 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4084 panic("REQ_CMP with QFRZN");
4085 if (bp->bio_cmd == BIO_ZONE)
4086 dazonedone(periph, done_ccb);
4087 else if (state == DA_CCB_DELETE)
4090 bp->bio_resid = csio->resid;
4091 if ((csio->resid > 0)
4092 && (bp->bio_cmd != BIO_ZONE))
4093 bp->bio_flags |= BIO_ERROR;
4094 if (softc->error_inject != 0) {
4095 bp->bio_error = softc->error_inject;
4096 bp->bio_resid = bp->bio_bcount;
4097 bp->bio_flags |= BIO_ERROR;
4098 softc->error_inject = 0;
4102 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4103 if (LIST_EMPTY(&softc->pending_ccbs))
4104 softc->flags |= DA_FLAG_WAS_OTAG;
4106 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4107 xpt_release_ccb(done_ccb);
4108 if (state == DA_CCB_DELETE) {
4109 TAILQ_HEAD(, bio) queue;
4112 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4113 softc->delete_run_queue.insert_point = NULL;
4115 * Normally, the xpt_release_ccb() above would make sure
4116 * that when we have more work to do, that work would
4117 * get kicked off. However, we specifically keep
4118 * delete_running set to 0 before the call above to
4119 * allow other I/O to progress when many BIO_DELETE
4120 * requests are pushed down. We set delete_running to 0
4121 * and call daschedule again so that we don't stall if
4122 * there are no other I/Os pending apart from BIO_DELETEs.
4124 cam_iosched_trim_done(softc->cam_iosched);
4126 cam_periph_unlock(periph);
4127 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4128 TAILQ_REMOVE(&queue, bp1, bio_queue);
4129 bp1->bio_error = bp->bio_error;
4130 if (bp->bio_flags & BIO_ERROR) {
4131 bp1->bio_flags |= BIO_ERROR;
4132 bp1->bio_resid = bp1->bio_bcount;
4139 cam_periph_unlock(periph);
4145 case DA_CCB_PROBE_RC:
4146 case DA_CCB_PROBE_RC16:
4148 struct scsi_read_capacity_data *rdcap;
4149 struct scsi_read_capacity_data_long *rcaplong;
4150 char announce_buf[80];
4156 if (state == DA_CCB_PROBE_RC)
4157 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4159 rcaplong = (struct scsi_read_capacity_data_long *)
4162 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4163 struct disk_params *dp;
4164 uint32_t block_size;
4166 u_int lalba; /* Lowest aligned LBA. */
4168 if (state == DA_CCB_PROBE_RC) {
4169 block_size = scsi_4btoul(rdcap->length);
4170 maxsector = scsi_4btoul(rdcap->addr);
4174 * According to SBC-2, if the standard 10
4175 * byte READ CAPACITY command returns 2^32,
4176 * we should issue the 16 byte version of
4177 * the command, since the device in question
4178 * has more sectors than can be represented
4179 * with the short version of the command.
4181 if (maxsector == 0xffffffff) {
4182 free(rdcap, M_SCSIDA);
4183 xpt_release_ccb(done_ccb);
4184 softc->state = DA_STATE_PROBE_RC16;
4185 xpt_schedule(periph, priority);
4189 block_size = scsi_4btoul(rcaplong->length);
4190 maxsector = scsi_8btou64(rcaplong->addr);
4191 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4195 * Because GEOM code just will panic us if we
4196 * give them an 'illegal' value we'll avoid that
4199 if (block_size == 0) {
4204 if (block_size >= MAXPHYS) {
4205 xpt_print(periph->path,
4206 "unsupportable block size %ju\n",
4207 (uintmax_t) block_size);
4208 announce_buf[0] = '\0';
4209 cam_periph_invalidate(periph);
4212 * We pass rcaplong into dasetgeom(),
4213 * because it will only use it if it is
4216 dasetgeom(periph, block_size, maxsector,
4217 rcaplong, sizeof(*rcaplong));
4218 lbp = (lalba & SRC16_LBPME_A);
4219 dp = &softc->params;
4220 snprintf(announce_buf, sizeof(announce_buf),
4221 "%juMB (%ju %u byte sectors)",
4222 ((uintmax_t)dp->secsize * dp->sectors) /
4224 (uintmax_t)dp->sectors, dp->secsize);
4229 announce_buf[0] = '\0';
4232 * Retry any UNIT ATTENTION type errors. They
4233 * are expected at boot.
4235 error = daerror(done_ccb, CAM_RETRY_SELTO,
4236 SF_RETRY_UA|SF_NO_PRINT);
4237 if (error == ERESTART) {
4239 * A retry was scheuled, so
4243 } else if (error != 0) {
4245 int sense_key, error_code;
4248 struct ccb_getdev cgd;
4250 /* Don't wedge this device's queue */
4251 status = done_ccb->ccb_h.status;
4252 if ((status & CAM_DEV_QFRZN) != 0)
4253 cam_release_devq(done_ccb->ccb_h.path,
4257 /*getcount_only*/0);
4260 xpt_setup_ccb(&cgd.ccb_h,
4261 done_ccb->ccb_h.path,
4262 CAM_PRIORITY_NORMAL);
4263 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4264 xpt_action((union ccb *)&cgd);
4266 if (scsi_extract_sense_ccb(done_ccb,
4267 &error_code, &sense_key, &asc, &ascq))
4273 * If we tried READ CAPACITY(16) and failed,
4274 * fallback to READ CAPACITY(10).
4276 if ((state == DA_CCB_PROBE_RC16) &&
4277 (softc->flags & DA_FLAG_CAN_RC16) &&
4278 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4281 (error_code == SSD_CURRENT_ERROR) &&
4282 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4283 softc->flags &= ~DA_FLAG_CAN_RC16;
4284 free(rdcap, M_SCSIDA);
4285 xpt_release_ccb(done_ccb);
4286 softc->state = DA_STATE_PROBE_RC;
4287 xpt_schedule(periph, priority);
4292 * Attach to anything that claims to be a
4293 * direct access or optical disk device,
4294 * as long as it doesn't return a "Logical
4295 * unit not supported" (0x25) error.
4297 if ((have_sense) && (asc != 0x25)
4298 && (error_code == SSD_CURRENT_ERROR)) {
4299 const char *sense_key_desc;
4300 const char *asc_desc;
4302 dasetgeom(periph, 512, -1, NULL, 0);
4303 scsi_sense_desc(sense_key, asc, ascq,
4307 snprintf(announce_buf,
4308 sizeof(announce_buf),
4309 "Attempt to query device "
4310 "size failed: %s, %s",
4318 xpt_print(periph->path,
4319 "got CAM status %#x\n",
4320 done_ccb->ccb_h.status);
4323 xpt_print(periph->path, "fatal error, "
4324 "failed to attach to device\n");
4327 * Free up resources.
4329 cam_periph_invalidate(periph);
4333 free(csio->data_ptr, M_SCSIDA);
4334 if (announce_buf[0] != '\0' &&
4335 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4337 * Create our sysctl variables, now that we know
4338 * we have successfully attached.
4340 /* increase the refcount */
4341 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4342 taskqueue_enqueue(taskqueue_thread,
4343 &softc->sysctl_task);
4344 xpt_announce_periph(periph, announce_buf);
4345 xpt_announce_quirks(periph, softc->quirks,
4348 xpt_print(periph->path, "fatal error, "
4349 "could not acquire reference count\n");
4353 /* We already probed the device. */
4354 if (softc->flags & DA_FLAG_PROBED) {
4355 daprobedone(periph, done_ccb);
4359 /* Ensure re-probe doesn't see old delete. */
4360 softc->delete_available = 0;
4361 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4362 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4364 * Based on older SBC-3 spec revisions
4365 * any of the UNMAP methods "may" be
4366 * available via LBP given this flag so
4367 * we flag all of them as available and
4368 * then remove those which further
4369 * probes confirm aren't available
4372 * We could also check readcap(16) p_type
4373 * flag to exclude one or more invalid
4374 * write same (X) types here
4376 dadeleteflag(softc, DA_DELETE_WS16, 1);
4377 dadeleteflag(softc, DA_DELETE_WS10, 1);
4378 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4380 xpt_release_ccb(done_ccb);
4381 softc->state = DA_STATE_PROBE_LBP;
4382 xpt_schedule(periph, priority);
4386 xpt_release_ccb(done_ccb);
4387 softc->state = DA_STATE_PROBE_BDC;
4388 xpt_schedule(periph, priority);
4391 case DA_CCB_PROBE_LBP:
4393 struct scsi_vpd_logical_block_prov *lbp;
4395 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4397 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4399 * T10/1799-D Revision 31 states at least one of these
4400 * must be supported but we don't currently enforce this.
4402 dadeleteflag(softc, DA_DELETE_WS16,
4403 (lbp->flags & SVPD_LBP_WS16));
4404 dadeleteflag(softc, DA_DELETE_WS10,
4405 (lbp->flags & SVPD_LBP_WS10));
4406 dadeleteflag(softc, DA_DELETE_UNMAP,
4407 (lbp->flags & SVPD_LBP_UNMAP));
4410 error = daerror(done_ccb, CAM_RETRY_SELTO,
4411 SF_RETRY_UA|SF_NO_PRINT);
4412 if (error == ERESTART)
4414 else if (error != 0) {
4415 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4416 /* Don't wedge this device's queue */
4417 cam_release_devq(done_ccb->ccb_h.path,
4421 /*getcount_only*/0);
4425 * Failure indicates we don't support any SBC-3
4426 * delete methods with UNMAP
4431 free(lbp, M_SCSIDA);
4432 xpt_release_ccb(done_ccb);
4433 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4434 xpt_schedule(periph, priority);
4437 case DA_CCB_PROBE_BLK_LIMITS:
4439 struct scsi_vpd_block_limits *block_limits;
4441 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4443 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4444 uint32_t max_txfer_len = scsi_4btoul(
4445 block_limits->max_txfer_len);
4446 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4447 block_limits->max_unmap_lba_cnt);
4448 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4449 block_limits->max_unmap_blk_cnt);
4450 uint64_t ws_max_blks = scsi_8btou64(
4451 block_limits->max_write_same_length);
4453 if (max_txfer_len != 0) {
4454 softc->disk->d_maxsize = MIN(softc->maxio,
4455 (off_t)max_txfer_len * softc->params.secsize);
4459 * We should already support UNMAP but we check lba
4460 * and block count to be sure
4462 if (max_unmap_lba_cnt != 0x00L &&
4463 max_unmap_blk_cnt != 0x00L) {
4464 softc->unmap_max_lba = max_unmap_lba_cnt;
4465 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4469 * Unexpected UNMAP limits which means the
4470 * device doesn't actually support UNMAP
4472 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4475 if (ws_max_blks != 0x00L)
4476 softc->ws_max_blks = ws_max_blks;
4479 error = daerror(done_ccb, CAM_RETRY_SELTO,
4480 SF_RETRY_UA|SF_NO_PRINT);
4481 if (error == ERESTART)
4483 else if (error != 0) {
4484 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4485 /* Don't wedge this device's queue */
4486 cam_release_devq(done_ccb->ccb_h.path,
4490 /*getcount_only*/0);
4494 * Failure here doesn't mean UNMAP is not
4495 * supported as this is an optional page.
4497 softc->unmap_max_lba = 1;
4498 softc->unmap_max_ranges = 1;
4502 free(block_limits, M_SCSIDA);
4503 xpt_release_ccb(done_ccb);
4504 softc->state = DA_STATE_PROBE_BDC;
4505 xpt_schedule(periph, priority);
4508 case DA_CCB_PROBE_BDC:
4510 struct scsi_vpd_block_device_characteristics *bdc;
4512 bdc = (struct scsi_vpd_block_device_characteristics *)
4515 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4519 * Disable queue sorting for non-rotational media
4522 u_int16_t old_rate = softc->disk->d_rotation_rate;
4524 valid_len = csio->dxfer_len - csio->resid;
4525 if (SBDC_IS_PRESENT(bdc, valid_len,
4526 medium_rotation_rate)) {
4527 softc->disk->d_rotation_rate =
4528 scsi_2btoul(bdc->medium_rotation_rate);
4529 if (softc->disk->d_rotation_rate ==
4530 SVPD_BDC_RATE_NON_ROTATING) {
4531 cam_iosched_set_sort_queue(
4532 softc->cam_iosched, 0);
4533 softc->rotating = 0;
4535 if (softc->disk->d_rotation_rate != old_rate) {
4536 disk_attr_changed(softc->disk,
4537 "GEOM::rotation_rate", M_NOWAIT);
4540 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4541 && (softc->zone_mode == DA_ZONE_NONE)) {
4544 if (scsi_vpd_supported_page(periph,
4545 SVPD_ATA_INFORMATION))
4551 * The Zoned field will only be set for
4552 * Drive Managed and Host Aware drives. If
4553 * they are Host Managed, the device type
4554 * in the standard INQUIRY data should be
4555 * set to T_ZBC_HM (0x14).
4557 if ((bdc->flags & SVPD_ZBC_MASK) ==
4559 softc->zone_mode = DA_ZONE_HOST_AWARE;
4560 softc->zone_interface = (ata_proto) ?
4561 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4562 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4564 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4565 softc->zone_interface = (ata_proto) ?
4566 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4567 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4569 xpt_print(periph->path, "Unknown zoned "
4571 bdc->flags & SVPD_ZBC_MASK);
4576 error = daerror(done_ccb, CAM_RETRY_SELTO,
4577 SF_RETRY_UA|SF_NO_PRINT);
4578 if (error == ERESTART)
4580 else if (error != 0) {
4581 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4582 /* Don't wedge this device's queue */
4583 cam_release_devq(done_ccb->ccb_h.path,
4587 /*getcount_only*/0);
4592 free(bdc, M_SCSIDA);
4593 xpt_release_ccb(done_ccb);
4594 softc->state = DA_STATE_PROBE_ATA;
4595 xpt_schedule(periph, priority);
4598 case DA_CCB_PROBE_ATA:
4601 struct ata_params *ata_params;
4606 ata_params = (struct ata_params *)csio->data_ptr;
4607 ptr = (uint16_t *)ata_params;
4611 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4614 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4615 ptr[i] = le16toh(ptr[i]);
4616 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4617 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4618 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4619 if (ata_params->max_dsm_blocks != 0)
4620 softc->trim_max_ranges = min(
4621 softc->trim_max_ranges,
4622 ata_params->max_dsm_blocks *
4623 ATA_DSM_BLK_RANGES);
4626 * Disable queue sorting for non-rotational media
4629 old_rate = softc->disk->d_rotation_rate;
4630 softc->disk->d_rotation_rate =
4631 ata_params->media_rotation_rate;
4632 if (softc->disk->d_rotation_rate ==
4633 ATA_RATE_NON_ROTATING) {
4634 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4635 softc->rotating = 0;
4637 if (softc->disk->d_rotation_rate != old_rate) {
4638 disk_attr_changed(softc->disk,
4639 "GEOM::rotation_rate", M_NOWAIT);
4642 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4643 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4645 if (ata_params->support.extension &
4647 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4650 * At this point, if we have a SATA host aware drive,
4651 * we communicate via ATA passthrough unless the
4652 * SAT layer supports ZBC -> ZAC translation. In
4656 * XXX KDM figure out how to detect a host managed
4659 if (softc->zone_mode == DA_ZONE_NONE) {
4661 * Note that we don't override the zone
4662 * mode or interface if it has already been
4663 * set. This is because it has either been
4664 * set as a quirk, or when we probed the
4665 * SCSI Block Device Characteristics page,
4666 * the zoned field was set. The latter
4667 * means that the SAT layer supports ZBC to
4668 * ZAC translation, and we would prefer to
4669 * use that if it is available.
4671 if ((ata_params->support3 &
4672 ATA_SUPPORT_ZONE_MASK) ==
4673 ATA_SUPPORT_ZONE_HOST_AWARE) {
4674 softc->zone_mode = DA_ZONE_HOST_AWARE;
4675 softc->zone_interface =
4676 DA_ZONE_IF_ATA_PASS;
4677 } else if ((ata_params->support3 &
4678 ATA_SUPPORT_ZONE_MASK) ==
4679 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4680 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4681 softc->zone_interface =
4682 DA_ZONE_IF_ATA_PASS;
4687 error = daerror(done_ccb, CAM_RETRY_SELTO,
4688 SF_RETRY_UA|SF_NO_PRINT);
4689 if (error == ERESTART)
4691 else if (error != 0) {
4692 if ((done_ccb->ccb_h.status &
4693 CAM_DEV_QFRZN) != 0) {
4694 /* Don't wedge this device's queue */
4695 cam_release_devq(done_ccb->ccb_h.path,
4699 /*getcount_only*/0);
4704 free(ata_params, M_SCSIDA);
4705 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4706 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4708 * If the ATA IDENTIFY failed, we could be talking
4709 * to a SCSI drive, although that seems unlikely,
4710 * since the drive did report that it supported the
4711 * ATA Information VPD page. If the ATA IDENTIFY
4712 * succeeded, and the SAT layer doesn't support
4713 * ZBC -> ZAC translation, continue on to get the
4714 * directory of ATA logs, and complete the rest of
4715 * the ZAC probe. If the SAT layer does support
4716 * ZBC -> ZAC translation, we want to use that,
4717 * and we'll probe the SCSI Zoned Block Device
4718 * Characteristics VPD page next.
4721 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4722 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4723 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4725 softc->state = DA_STATE_PROBE_ZONE;
4728 if (continue_probe != 0) {
4729 xpt_release_ccb(done_ccb);
4730 xpt_schedule(periph, priority);
4733 daprobedone(periph, done_ccb);
4736 case DA_CCB_PROBE_ATA_LOGDIR:
4740 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4742 softc->valid_logdir_len = 0;
4743 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4744 softc->valid_logdir_len =
4745 csio->dxfer_len - csio->resid;
4746 if (softc->valid_logdir_len > 0)
4747 bcopy(csio->data_ptr, &softc->ata_logdir,
4748 min(softc->valid_logdir_len,
4749 sizeof(softc->ata_logdir)));
4751 * Figure out whether the Identify Device log is
4752 * supported. The General Purpose log directory
4753 * has a header, and lists the number of pages
4754 * available for each GP log identified by the
4755 * offset into the list.
4757 if ((softc->valid_logdir_len >=
4758 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4759 && (le16dec(softc->ata_logdir.header) ==
4760 ATA_GP_LOG_DIR_VERSION)
4761 && (le16dec(&softc->ata_logdir.num_pages[
4762 (ATA_IDENTIFY_DATA_LOG *
4763 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4764 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4766 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4769 error = daerror(done_ccb, CAM_RETRY_SELTO,
4770 SF_RETRY_UA|SF_NO_PRINT);
4771 if (error == ERESTART)
4773 else if (error != 0) {
4775 * If we can't get the ATA log directory,
4776 * then ATA logs are effectively not
4777 * supported even if the bit is set in the
4780 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
4781 DA_FLAG_CAN_ATA_IDLOG);
4782 if ((done_ccb->ccb_h.status &
4783 CAM_DEV_QFRZN) != 0) {
4784 /* Don't wedge this device's queue */
4785 cam_release_devq(done_ccb->ccb_h.path,
4789 /*getcount_only*/0);
4794 free(csio->data_ptr, M_SCSIDA);
4797 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
4798 softc->state = DA_STATE_PROBE_ATA_IDDIR;
4799 xpt_release_ccb(done_ccb);
4800 xpt_schedule(periph, priority);
4803 daprobedone(periph, done_ccb);
4806 case DA_CCB_PROBE_ATA_IDDIR:
4810 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4811 off_t entries_offset, max_entries;
4814 softc->valid_iddir_len = 0;
4815 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
4816 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
4817 DA_FLAG_CAN_ATA_ZONE);
4818 softc->valid_iddir_len =
4819 csio->dxfer_len - csio->resid;
4820 if (softc->valid_iddir_len > 0)
4821 bcopy(csio->data_ptr, &softc->ata_iddir,
4822 min(softc->valid_iddir_len,
4823 sizeof(softc->ata_iddir)));
4826 __offsetof(struct ata_identify_log_pages,entries);
4827 max_entries = softc->valid_iddir_len - entries_offset;
4828 if ((softc->valid_iddir_len > (entries_offset + 1))
4829 && (le64dec(softc->ata_iddir.header) ==
4831 && (softc->ata_iddir.entry_count > 0)) {
4834 num_entries = softc->ata_iddir.entry_count;
4835 num_entries = min(num_entries,
4836 softc->valid_iddir_len - entries_offset);
4837 for (i = 0; i < num_entries &&
4838 i < max_entries; i++) {
4839 if (softc->ata_iddir.entries[i] ==
4842 DA_FLAG_CAN_ATA_SUPCAP;
4843 else if (softc->ata_iddir.entries[i]==
4846 DA_FLAG_CAN_ATA_ZONE;
4849 DA_FLAG_CAN_ATA_SUPCAP)
4851 DA_FLAG_CAN_ATA_ZONE))
4856 error = daerror(done_ccb, CAM_RETRY_SELTO,
4857 SF_RETRY_UA|SF_NO_PRINT);
4858 if (error == ERESTART)
4860 else if (error != 0) {
4862 * If we can't get the ATA Identify Data log
4863 * directory, then it effectively isn't
4864 * supported even if the ATA Log directory
4865 * a non-zero number of pages present for
4868 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4869 if ((done_ccb->ccb_h.status &
4870 CAM_DEV_QFRZN) != 0) {
4871 /* Don't wedge this device's queue */
4872 cam_release_devq(done_ccb->ccb_h.path,
4876 /*getcount_only*/0);
4881 free(csio->data_ptr, M_SCSIDA);
4884 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
4885 softc->state = DA_STATE_PROBE_ATA_SUP;
4886 xpt_release_ccb(done_ccb);
4887 xpt_schedule(periph, priority);
4890 daprobedone(periph, done_ccb);
4893 case DA_CCB_PROBE_ATA_SUP:
4897 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4900 struct ata_identify_log_sup_cap *sup_cap;
4903 sup_cap = (struct ata_identify_log_sup_cap *)
4905 valid_len = csio->dxfer_len - csio->resid;
4907 __offsetof(struct ata_identify_log_sup_cap,
4908 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
4909 if (valid_len >= needed_size) {
4910 uint64_t zoned, zac_cap;
4912 zoned = le64dec(sup_cap->zoned_cap);
4913 if (zoned & ATA_ZONED_VALID) {
4915 * This should have already been
4916 * set, because this is also in the
4917 * ATA identify data.
4919 if ((zoned & ATA_ZONED_MASK) ==
4920 ATA_SUPPORT_ZONE_HOST_AWARE)
4923 else if ((zoned & ATA_ZONED_MASK) ==
4924 ATA_SUPPORT_ZONE_DEV_MANAGED)
4926 DA_ZONE_DRIVE_MANAGED;
4929 zac_cap = le64dec(sup_cap->sup_zac_cap);
4930 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
4931 if (zac_cap & ATA_REPORT_ZONES_SUP)
4932 softc->zone_flags |=
4933 DA_ZONE_FLAG_RZ_SUP;
4934 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
4935 softc->zone_flags |=
4936 DA_ZONE_FLAG_OPEN_SUP;
4937 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
4938 softc->zone_flags |=
4939 DA_ZONE_FLAG_CLOSE_SUP;
4940 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
4941 softc->zone_flags |=
4942 DA_ZONE_FLAG_FINISH_SUP;
4943 if (zac_cap & ATA_ND_RWP_SUP)
4944 softc->zone_flags |=
4945 DA_ZONE_FLAG_RWP_SUP;
4948 * This field was introduced in
4949 * ACS-4, r08 on April 28th, 2015.
4950 * If the drive firmware was written
4951 * to an earlier spec, it won't have
4952 * the field. So, assume all
4953 * commands are supported.
4955 softc->zone_flags |=
4956 DA_ZONE_FLAG_SUP_MASK;
4961 error = daerror(done_ccb, CAM_RETRY_SELTO,
4962 SF_RETRY_UA|SF_NO_PRINT);
4963 if (error == ERESTART)
4965 else if (error != 0) {
4967 * If we can't get the ATA Identify Data
4968 * Supported Capabilities page, clear the
4971 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
4973 * And clear zone capabilities.
4975 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
4976 if ((done_ccb->ccb_h.status &
4977 CAM_DEV_QFRZN) != 0) {
4978 /* Don't wedge this device's queue */
4979 cam_release_devq(done_ccb->ccb_h.path,
4983 /*getcount_only*/0);
4988 free(csio->data_ptr, M_SCSIDA);
4991 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
4992 softc->state = DA_STATE_PROBE_ATA_ZONE;
4993 xpt_release_ccb(done_ccb);
4994 xpt_schedule(periph, priority);
4997 daprobedone(periph, done_ccb);
5000 case DA_CCB_PROBE_ATA_ZONE:
5004 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5005 struct ata_zoned_info_log *zi_log;
5009 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5011 valid_len = csio->dxfer_len - csio->resid;
5012 needed_size = __offsetof(struct ata_zoned_info_log,
5013 version_info) + 1 + sizeof(zi_log->version_info);
5014 if (valid_len >= needed_size) {
5017 tmpvar = le64dec(zi_log->zoned_cap);
5018 if (tmpvar & ATA_ZDI_CAP_VALID) {
5019 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5020 softc->zone_flags |=
5021 DA_ZONE_FLAG_URSWRZ;
5023 softc->zone_flags &=
5024 ~DA_ZONE_FLAG_URSWRZ;
5026 tmpvar = le64dec(zi_log->optimal_seq_zones);
5027 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5028 softc->zone_flags |=
5029 DA_ZONE_FLAG_OPT_SEQ_SET;
5030 softc->optimal_seq_zones = (tmpvar &
5031 ATA_ZDI_OPT_SEQ_MASK);
5033 softc->zone_flags &=
5034 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5035 softc->optimal_seq_zones = 0;
5038 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5039 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5040 softc->zone_flags |=
5041 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5042 softc->optimal_nonseq_zones =
5043 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5045 softc->zone_flags &=
5046 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5047 softc->optimal_nonseq_zones = 0;
5050 tmpvar = le64dec(zi_log->max_seq_req_zones);
5051 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5052 softc->zone_flags |=
5053 DA_ZONE_FLAG_MAX_SEQ_SET;
5054 softc->max_seq_zones =
5055 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5057 softc->zone_flags &=
5058 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5059 softc->max_seq_zones = 0;
5063 error = daerror(done_ccb, CAM_RETRY_SELTO,
5064 SF_RETRY_UA|SF_NO_PRINT);
5065 if (error == ERESTART)
5067 else if (error != 0) {
5068 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5069 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5071 if ((done_ccb->ccb_h.status &
5072 CAM_DEV_QFRZN) != 0) {
5073 /* Don't wedge this device's queue */
5074 cam_release_devq(done_ccb->ccb_h.path,
5078 /*getcount_only*/0);
5083 free(csio->data_ptr, M_SCSIDA);
5085 daprobedone(periph, done_ccb);
5088 case DA_CCB_PROBE_ZONE:
5092 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5095 struct scsi_vpd_zoned_bdc *zoned_bdc;
5098 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5100 valid_len = csio->dxfer_len - csio->resid;
5101 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5102 max_seq_req_zones) + 1 +
5103 sizeof(zoned_bdc->max_seq_req_zones);
5104 if ((valid_len >= needed_len)
5105 && (scsi_2btoul(zoned_bdc->page_length) >=
5107 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5108 softc->zone_flags |=
5109 DA_ZONE_FLAG_URSWRZ;
5111 softc->zone_flags &=
5112 ~DA_ZONE_FLAG_URSWRZ;
5113 softc->optimal_seq_zones =
5114 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5115 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5116 softc->optimal_nonseq_zones = scsi_4btoul(
5117 zoned_bdc->optimal_nonseq_zones);
5118 softc->zone_flags |=
5119 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5120 softc->max_seq_zones =
5121 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5122 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5125 * All of the zone commands are mandatory for SCSI
5128 * XXX KDM this is valid as of September 2015.
5129 * Re-check this assumption once the SAT spec is
5130 * updated to support SCSI ZBC to ATA ZAC mapping.
5131 * Since ATA allows zone commands to be reported
5132 * as supported or not, this may not necessarily
5133 * be true for an ATA device behind a SAT (SCSI to
5134 * ATA Translation) layer.
5136 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5138 error = daerror(done_ccb, CAM_RETRY_SELTO,
5139 SF_RETRY_UA|SF_NO_PRINT);
5140 if (error == ERESTART)
5142 else if (error != 0) {
5143 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5144 /* Don't wedge this device's queue */
5145 cam_release_devq(done_ccb->ccb_h.path,
5149 /*getcount_only*/0);
5153 daprobedone(periph, done_ccb);
5157 /* No-op. We're polling */
5161 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5163 if (daerror(done_ccb, CAM_RETRY_SELTO,
5164 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5167 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5168 cam_release_devq(done_ccb->ccb_h.path,
5172 /*getcount_only*/0);
5174 xpt_release_ccb(done_ccb);
5175 cam_periph_release_locked(periph);
5181 xpt_release_ccb(done_ccb);
5185 dareprobe(struct cam_periph *periph)
5187 struct da_softc *softc;
5190 softc = (struct da_softc *)periph->softc;
5192 /* Probe in progress; don't interfere. */
5193 if (softc->state != DA_STATE_NORMAL)
5196 status = cam_periph_acquire(periph);
5197 KASSERT(status == CAM_REQ_CMP,
5198 ("dareprobe: cam_periph_acquire failed"));
5200 if (softc->flags & DA_FLAG_CAN_RC16)
5201 softc->state = DA_STATE_PROBE_RC16;
5203 softc->state = DA_STATE_PROBE_RC;
5205 xpt_schedule(periph, CAM_PRIORITY_DEV);
5209 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5211 struct da_softc *softc;
5212 struct cam_periph *periph;
5213 int error, error_code, sense_key, asc, ascq;
5215 periph = xpt_path_periph(ccb->ccb_h.path);
5216 softc = (struct da_softc *)periph->softc;
5219 * Automatically detect devices that do not support
5220 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5223 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5224 error = cmd6workaround(ccb);
5225 } else if (scsi_extract_sense_ccb(ccb,
5226 &error_code, &sense_key, &asc, &ascq)) {
5227 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5228 error = cmd6workaround(ccb);
5230 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5231 * query the capacity and notify upper layers.
5233 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5234 asc == 0x2A && ascq == 0x09) {
5235 xpt_print(periph->path, "Capacity data has changed\n");
5236 softc->flags &= ~DA_FLAG_PROBED;
5238 sense_flags |= SF_NO_PRINT;
5239 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5240 asc == 0x28 && ascq == 0x00) {
5241 softc->flags &= ~DA_FLAG_PROBED;
5242 disk_media_changed(softc->disk, M_NOWAIT);
5243 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5244 asc == 0x3F && ascq == 0x03) {
5245 xpt_print(periph->path, "INQUIRY data has changed\n");
5246 softc->flags &= ~DA_FLAG_PROBED;
5248 sense_flags |= SF_NO_PRINT;
5249 } else if (sense_key == SSD_KEY_NOT_READY &&
5250 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5251 softc->flags |= DA_FLAG_PACK_INVALID;
5252 disk_media_gone(softc->disk, M_NOWAIT);
5255 if (error == ERESTART)
5259 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5260 case CAM_CMD_TIMEOUT:
5263 case CAM_REQ_ABORTED:
5264 case CAM_REQ_CMP_ERR:
5265 case CAM_REQ_TERMIO:
5266 case CAM_UNREC_HBA_ERROR:
5267 case CAM_DATA_RUN_ERR:
5277 * Until we have a better way of doing pack validation,
5278 * don't treat UAs as errors.
5280 sense_flags |= SF_RETRY_UA;
5282 if (softc->quirks & DA_Q_RETRY_BUSY)
5283 sense_flags |= SF_RETRY_BUSY;
5284 return(cam_periph_error(ccb, cam_flags, sense_flags,
5285 &softc->saved_ccb));
5289 damediapoll(void *arg)
5291 struct cam_periph *periph = arg;
5292 struct da_softc *softc = periph->softc;
5294 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5295 LIST_EMPTY(&softc->pending_ccbs)) {
5296 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5297 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5301 /* Queue us up again */
5302 if (da_poll_period != 0)
5303 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5307 daprevent(struct cam_periph *periph, int action)
5309 struct da_softc *softc;
5313 softc = (struct da_softc *)periph->softc;
5315 if (((action == PR_ALLOW)
5316 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5317 || ((action == PR_PREVENT)
5318 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5322 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5324 scsi_prevent(&ccb->csio,
5332 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5333 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5336 if (action == PR_ALLOW)
5337 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5339 softc->flags |= DA_FLAG_PACK_LOCKED;
5342 xpt_release_ccb(ccb);
5346 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5347 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5349 struct ccb_calc_geometry ccg;
5350 struct da_softc *softc;
5351 struct disk_params *dp;
5352 u_int lbppbe, lalba;
5355 softc = (struct da_softc *)periph->softc;
5357 dp = &softc->params;
5358 dp->secsize = block_len;
5359 dp->sectors = maxsector + 1;
5360 if (rcaplong != NULL) {
5361 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5362 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5363 lalba &= SRC16_LALBA_A;
5370 dp->stripesize = block_len << lbppbe;
5371 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5373 } else if (softc->quirks & DA_Q_4K) {
5374 dp->stripesize = 4096;
5375 dp->stripeoffset = 0;
5378 dp->stripeoffset = 0;
5381 * Have the controller provide us with a geometry
5382 * for this disk. The only time the geometry
5383 * matters is when we boot and the controller
5384 * is the only one knowledgeable enough to come
5385 * up with something that will make this a bootable
5388 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5389 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5390 ccg.block_size = dp->secsize;
5391 ccg.volume_size = dp->sectors;
5393 ccg.secs_per_track = 0;
5395 xpt_action((union ccb*)&ccg);
5396 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5398 * We don't know what went wrong here- but just pick
5399 * a geometry so we don't have nasty things like divide
5403 dp->secs_per_track = 255;
5404 dp->cylinders = dp->sectors / (255 * 255);
5405 if (dp->cylinders == 0) {
5409 dp->heads = ccg.heads;
5410 dp->secs_per_track = ccg.secs_per_track;
5411 dp->cylinders = ccg.cylinders;
5415 * If the user supplied a read capacity buffer, and if it is
5416 * different than the previous buffer, update the data in the EDT.
5417 * If it's the same, we don't bother. This avoids sending an
5418 * update every time someone opens this device.
5420 if ((rcaplong != NULL)
5421 && (bcmp(rcaplong, &softc->rcaplong,
5422 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5423 struct ccb_dev_advinfo cdai;
5425 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5426 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5427 cdai.buftype = CDAI_TYPE_RCAPLONG;
5428 cdai.flags = CDAI_FLAG_STORE;
5429 cdai.bufsiz = rcap_len;
5430 cdai.buf = (uint8_t *)rcaplong;
5431 xpt_action((union ccb *)&cdai);
5432 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5433 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5434 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5435 xpt_print(periph->path, "%s: failed to set read "
5436 "capacity advinfo\n", __func__);
5437 /* Use cam_error_print() to decode the status */
5438 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5441 bcopy(rcaplong, &softc->rcaplong,
5442 min(sizeof(softc->rcaplong), rcap_len));
5446 softc->disk->d_sectorsize = softc->params.secsize;
5447 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5448 softc->disk->d_stripesize = softc->params.stripesize;
5449 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5450 /* XXX: these are not actually "firmware" values, so they may be wrong */
5451 softc->disk->d_fwsectors = softc->params.secs_per_track;
5452 softc->disk->d_fwheads = softc->params.heads;
5453 softc->disk->d_devstat->block_size = softc->params.secsize;
5454 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5456 error = disk_resize(softc->disk, M_NOWAIT);
5458 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5462 dasendorderedtag(void *arg)
5464 struct da_softc *softc = arg;
5466 if (da_send_ordered) {
5467 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5468 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5469 softc->flags |= DA_FLAG_NEED_OTAG;
5470 softc->flags &= ~DA_FLAG_WAS_OTAG;
5473 /* Queue us up again */
5474 callout_reset(&softc->sendordered_c,
5475 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5476 dasendorderedtag, softc);
5480 * Step through all DA peripheral drivers, and if the device is still open,
5481 * sync the disk cache to physical media.
5484 dashutdown(void * arg, int howto)
5486 struct cam_periph *periph;
5487 struct da_softc *softc;
5491 CAM_PERIPH_FOREACH(periph, &dadriver) {
5492 softc = (struct da_softc *)periph->softc;
5493 if (SCHEDULER_STOPPED()) {
5494 /* If we paniced with the lock held, do not recurse. */
5495 if (!cam_periph_owned(periph) &&
5496 (softc->flags & DA_FLAG_OPEN)) {
5497 dadump(softc->disk, NULL, 0, 0, 0);
5501 cam_periph_lock(periph);
5504 * We only sync the cache if the drive is still open, and
5505 * if the drive is capable of it..
5507 if (((softc->flags & DA_FLAG_OPEN) == 0)
5508 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5509 cam_periph_unlock(periph);
5513 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5514 scsi_synchronize_cache(&ccb->csio,
5518 /*begin_lba*/0, /* whole disk */
5523 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5524 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5525 softc->disk->d_devstat);
5527 xpt_print(periph->path, "Synchronize cache failed\n");
5528 xpt_release_ccb(ccb);
5529 cam_periph_unlock(periph);
5533 #else /* !_KERNEL */
5536 * XXX These are only left out of the kernel build to silence warnings. If,
5537 * for some reason these functions are used in the kernel, the ifdefs should
5538 * be moved so they are included both in the kernel and userland.
5541 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5542 void (*cbfcnp)(struct cam_periph *, union ccb *),
5543 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5544 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5547 struct scsi_format_unit *scsi_cmd;
5549 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5550 scsi_cmd->opcode = FORMAT_UNIT;
5551 scsi_cmd->byte2 = byte2;
5552 scsi_ulto2b(ileave, scsi_cmd->interleave);
5557 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5567 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5568 void (*cbfcnp)(struct cam_periph *, union ccb *),
5569 uint8_t tag_action, uint8_t list_format,
5570 uint32_t addr_desc_index, uint8_t *data_ptr,
5571 uint32_t dxfer_len, int minimum_cmd_size,
5572 uint8_t sense_len, uint32_t timeout)
5577 * These conditions allow using the 10 byte command. Otherwise we
5578 * need to use the 12 byte command.
5580 if ((minimum_cmd_size <= 10)
5581 && (addr_desc_index == 0)
5582 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5583 struct scsi_read_defect_data_10 *cdb10;
5585 cdb10 = (struct scsi_read_defect_data_10 *)
5586 &csio->cdb_io.cdb_bytes;
5588 cdb_len = sizeof(*cdb10);
5589 bzero(cdb10, cdb_len);
5590 cdb10->opcode = READ_DEFECT_DATA_10;
5591 cdb10->format = list_format;
5592 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5594 struct scsi_read_defect_data_12 *cdb12;
5596 cdb12 = (struct scsi_read_defect_data_12 *)
5597 &csio->cdb_io.cdb_bytes;
5599 cdb_len = sizeof(*cdb12);
5600 bzero(cdb12, cdb_len);
5601 cdb12->opcode = READ_DEFECT_DATA_12;
5602 cdb12->format = list_format;
5603 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5604 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5610 /*flags*/ CAM_DIR_IN,
5620 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5621 void (*cbfcnp)(struct cam_periph *, union ccb *),
5622 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5623 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5626 struct scsi_sanitize *scsi_cmd;
5628 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5629 scsi_cmd->opcode = SANITIZE;
5630 scsi_cmd->byte2 = byte2;
5631 scsi_cmd->control = control;
5632 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5637 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5646 #endif /* _KERNEL */
5649 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5650 void (*cbfcnp)(struct cam_periph *, union ccb *),
5651 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5652 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5653 uint8_t sense_len, uint32_t timeout)
5655 struct scsi_zbc_out *scsi_cmd;
5657 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5658 scsi_cmd->opcode = ZBC_OUT;
5659 scsi_cmd->service_action = service_action;
5660 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5661 scsi_cmd->zone_flags = zone_flags;
5666 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5676 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5677 void (*cbfcnp)(struct cam_periph *, union ccb *),
5678 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5679 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5680 uint8_t sense_len, uint32_t timeout)
5682 struct scsi_zbc_in *scsi_cmd;
5684 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5685 scsi_cmd->opcode = ZBC_IN;
5686 scsi_cmd->service_action = service_action;
5687 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5688 scsi_cmd->zone_options = zone_options;
5693 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5704 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5705 void (*cbfcnp)(struct cam_periph *, union ccb *),
5706 uint8_t tag_action, int use_ncq,
5707 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5708 uint8_t *data_ptr, uint32_t dxfer_len,
5709 uint8_t *cdb_storage, size_t cdb_storage_len,
5710 uint8_t sense_len, uint32_t timeout)
5712 uint8_t command_out, protocol, ata_flags;
5713 uint16_t features_out;
5714 uint32_t sectors_out, auxiliary;
5720 command_out = ATA_ZAC_MANAGEMENT_OUT;
5721 features_out = (zm_action & 0xf) | (zone_flags << 8),
5722 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5723 if (dxfer_len == 0) {
5724 protocol = AP_PROTO_NON_DATA;
5725 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5728 protocol = AP_PROTO_DMA;
5729 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5730 AP_FLAG_TDIR_TO_DEV;
5731 sectors_out = ((dxfer_len >> 9) & 0xffff);
5735 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5736 if (dxfer_len == 0) {
5737 command_out = ATA_NCQ_NON_DATA;
5738 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5740 * We're assuming the SCSI to ATA translation layer
5741 * will set the NCQ tag number in the tag field.
5742 * That isn't clear from the SAT-4 spec (as of rev 05).
5745 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5747 command_out = ATA_SEND_FPDMA_QUEUED;
5749 * Note that we're defaulting to normal priority,
5750 * and assuming that the SCSI to ATA translation
5751 * layer will insert the NCQ tag number in the tag
5752 * field. That isn't clear in the SAT-4 spec (as
5755 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5757 ata_flags |= AP_FLAG_TLEN_FEAT |
5758 AP_FLAG_TDIR_TO_DEV;
5761 * For SEND FPDMA QUEUED, the transfer length is
5762 * encoded in the FEATURE register, and 0 means
5763 * that 65536 512 byte blocks are to be tranferred.
5764 * In practice, it seems unlikely that we'll see
5765 * a transfer that large, and it may confuse the
5766 * the SAT layer, because generally that means that
5767 * 0 bytes should be transferred.
5769 if (dxfer_len == (65536 * 512)) {
5771 } else if (dxfer_len <= (65535 * 512)) {
5772 features_out = ((dxfer_len >> 9) & 0xffff);
5774 /* The transfer is too big. */
5781 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
5782 protocol = AP_PROTO_FPDMA;
5785 protocol |= AP_EXTEND;
5787 retval = scsi_ata_pass(csio,
5790 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5792 /*protocol*/ protocol,
5793 /*ata_flags*/ ata_flags,
5794 /*features*/ features_out,
5795 /*sector_count*/ sectors_out,
5797 /*command*/ command_out,
5800 /*auxiliary*/ auxiliary,
5802 /*data_ptr*/ data_ptr,
5803 /*dxfer_len*/ dxfer_len,
5804 /*cdb_storage*/ cdb_storage,
5805 /*cdb_storage_len*/ cdb_storage_len,
5806 /*minimum_cmd_size*/ 0,
5807 /*sense_len*/ SSD_FULL_SIZE,
5808 /*timeout*/ timeout);
5816 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
5817 void (*cbfcnp)(struct cam_periph *, union ccb *),
5818 uint8_t tag_action, int use_ncq,
5819 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5820 uint8_t *data_ptr, uint32_t dxfer_len,
5821 uint8_t *cdb_storage, size_t cdb_storage_len,
5822 uint8_t sense_len, uint32_t timeout)
5824 uint8_t command_out, protocol;
5825 uint16_t features_out, sectors_out;
5831 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
5834 command_out = ATA_ZAC_MANAGEMENT_IN;
5835 /* XXX KDM put a macro here */
5836 features_out = (zm_action & 0xf) | (zone_flags << 8),
5837 sectors_out = dxfer_len >> 9, /* XXX KDM macro*/
5838 protocol = AP_PROTO_DMA;
5839 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
5842 ata_flags |= AP_FLAG_TLEN_FEAT;
5844 command_out = ATA_RECV_FPDMA_QUEUED;
5845 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
5848 * For RECEIVE FPDMA QUEUED, the transfer length is
5849 * encoded in the FEATURE register, and 0 means
5850 * that 65536 512 byte blocks are to be tranferred.
5851 * In practice, it seems unlikely that we'll see
5852 * a transfer that large, and it may confuse the
5853 * the SAT layer, because generally that means that
5854 * 0 bytes should be transferred.
5856 if (dxfer_len == (65536 * 512)) {
5858 } else if (dxfer_len <= (65535 * 512)) {
5859 features_out = ((dxfer_len >> 9) & 0xffff);
5861 /* The transfer is too big. */
5865 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
5866 protocol = AP_PROTO_FPDMA;
5869 protocol |= AP_EXTEND;
5871 retval = scsi_ata_pass(csio,
5874 /*flags*/ CAM_DIR_IN,
5876 /*protocol*/ protocol,
5877 /*ata_flags*/ ata_flags,
5878 /*features*/ features_out,
5879 /*sector_count*/ sectors_out,
5881 /*command*/ command_out,
5884 /*auxiliary*/ auxiliary,
5886 /*data_ptr*/ data_ptr,
5887 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
5888 /*cdb_storage*/ cdb_storage,
5889 /*cdb_storage_len*/ cdb_storage_len,
5890 /*minimum_cmd_size*/ 0,
5891 /*sense_len*/ SSD_FULL_SIZE,
5892 /*timeout*/ timeout);