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 return(CAM_REQ_CMP_ERR);
2383 LIST_INIT(&softc->pending_ccbs);
2384 softc->state = DA_STATE_PROBE_RC;
2385 bioq_init(&softc->delete_run_queue);
2386 if (SID_IS_REMOVABLE(&cgd->inq_data))
2387 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2388 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2389 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2390 softc->ws_max_blks = WS16_MAX_BLKS;
2391 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2392 softc->rotating = 1;
2394 periph->softc = softc;
2397 * See if this device has any quirks.
2399 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2400 (caddr_t)da_quirk_table,
2401 nitems(da_quirk_table),
2402 sizeof(*da_quirk_table), scsi_inquiry_match);
2405 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2407 softc->quirks = DA_Q_NONE;
2409 /* Check if the SIM does not want 6 byte commands */
2410 bzero(&cpi, sizeof(cpi));
2411 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2412 cpi.ccb_h.func_code = XPT_PATH_INQ;
2413 xpt_action((union ccb *)&cpi);
2414 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2415 softc->quirks |= DA_Q_NO_6_BYTE;
2417 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2418 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2419 else if (softc->quirks & DA_Q_SMR_DM)
2420 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2422 softc->zone_mode = DA_ZONE_NONE;
2424 if (softc->zone_mode != DA_ZONE_NONE) {
2425 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2426 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2427 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2429 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2431 softc->zone_interface = DA_ZONE_IF_SCSI;
2434 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2437 * Take an exclusive refcount on the periph while dastart is called
2438 * to finish the probe. The reference will be dropped in dadone at
2441 (void)cam_periph_hold(periph, PRIBIO);
2444 * Schedule a periodic event to occasionally send an
2445 * ordered tag to a device.
2447 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2448 callout_reset(&softc->sendordered_c,
2449 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2450 dasendorderedtag, softc);
2452 cam_periph_unlock(periph);
2454 * RBC devices don't have to support READ(6), only READ(10).
2456 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2457 softc->minimum_cmd_size = 10;
2459 softc->minimum_cmd_size = 6;
2462 * Load the user's default, if any.
2464 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2465 periph->unit_number);
2466 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2469 * 6, 10, 12 and 16 are the currently permissible values.
2471 if (softc->minimum_cmd_size < 6)
2472 softc->minimum_cmd_size = 6;
2473 else if ((softc->minimum_cmd_size > 6)
2474 && (softc->minimum_cmd_size <= 10))
2475 softc->minimum_cmd_size = 10;
2476 else if ((softc->minimum_cmd_size > 10)
2477 && (softc->minimum_cmd_size <= 12))
2478 softc->minimum_cmd_size = 12;
2479 else if (softc->minimum_cmd_size > 12)
2480 softc->minimum_cmd_size = 16;
2482 /* Predict whether device may support READ CAPACITY(16). */
2483 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2484 (softc->quirks & DA_Q_NO_RC16) == 0) {
2485 softc->flags |= DA_FLAG_CAN_RC16;
2486 softc->state = DA_STATE_PROBE_RC16;
2490 * Register this media as a disk.
2492 softc->disk = disk_alloc();
2493 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2494 periph->unit_number, 0,
2495 DEVSTAT_BS_UNAVAILABLE,
2496 SID_TYPE(&cgd->inq_data) |
2497 XPORT_DEVSTAT_TYPE(cpi.transport),
2498 DEVSTAT_PRIORITY_DISK);
2499 softc->disk->d_open = daopen;
2500 softc->disk->d_close = daclose;
2501 softc->disk->d_strategy = dastrategy;
2502 softc->disk->d_dump = dadump;
2503 softc->disk->d_getattr = dagetattr;
2504 softc->disk->d_gone = dadiskgonecb;
2505 softc->disk->d_name = "da";
2506 softc->disk->d_drv1 = periph;
2508 softc->maxio = DFLTPHYS; /* traditional default */
2509 else if (cpi.maxio > MAXPHYS)
2510 softc->maxio = MAXPHYS; /* for safety */
2512 softc->maxio = cpi.maxio;
2513 softc->disk->d_maxsize = softc->maxio;
2514 softc->disk->d_unit = periph->unit_number;
2515 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2516 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2517 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2518 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2519 softc->unmappedio = 1;
2520 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2521 xpt_print(periph->path, "UNMAPPED\n");
2523 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2524 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2525 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2526 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2527 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2528 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2529 softc->disk->d_hba_vendor = cpi.hba_vendor;
2530 softc->disk->d_hba_device = cpi.hba_device;
2531 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2532 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2535 * Acquire a reference to the periph before we register with GEOM.
2536 * We'll release this reference once GEOM calls us back (via
2537 * dadiskgonecb()) telling us that our provider has been freed.
2539 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2540 xpt_print(periph->path, "%s: lost periph during "
2541 "registration!\n", __func__);
2542 cam_periph_lock(periph);
2543 return (CAM_REQ_CMP_ERR);
2546 disk_create(softc->disk, DISK_VERSION);
2547 cam_periph_lock(periph);
2550 * Add async callbacks for events of interest.
2551 * I don't bother checking if this fails as,
2552 * in most cases, the system will function just
2553 * fine without them and the only alternative
2554 * would be to not attach the device on failure.
2556 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2557 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2558 AC_INQ_CHANGED, daasync, periph, periph->path);
2561 * Emit an attribute changed notification just in case
2562 * physical path information arrived before our async
2563 * event handler was registered, but after anyone attaching
2564 * to our disk device polled it.
2566 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2569 * Schedule a periodic media polling events.
2571 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2572 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2573 (cgd->inq_flags & SID_AEN) == 0 &&
2574 da_poll_period != 0)
2575 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2576 damediapoll, periph);
2578 xpt_schedule(periph, CAM_PRIORITY_DEV);
2580 return(CAM_REQ_CMP);
2584 da_zone_bio_to_scsi(int disk_zone_cmd)
2586 switch (disk_zone_cmd) {
2587 case DISK_ZONE_OPEN:
2588 return ZBC_OUT_SA_OPEN;
2589 case DISK_ZONE_CLOSE:
2590 return ZBC_OUT_SA_CLOSE;
2591 case DISK_ZONE_FINISH:
2592 return ZBC_OUT_SA_FINISH;
2594 return ZBC_OUT_SA_RWP;
2601 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2604 struct da_softc *softc;
2609 if (bp->bio_cmd != BIO_ZONE) {
2614 softc = periph->softc;
2616 switch (bp->bio_zone.zone_cmd) {
2617 case DISK_ZONE_OPEN:
2618 case DISK_ZONE_CLOSE:
2619 case DISK_ZONE_FINISH:
2620 case DISK_ZONE_RWP: {
2625 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2626 if (zone_sa == -1) {
2627 xpt_print(periph->path, "Cannot translate zone "
2628 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2634 lba = bp->bio_zone.zone_params.rwp.id;
2636 if (bp->bio_zone.zone_params.rwp.flags &
2637 DISK_ZONE_RWP_FLAG_ALL)
2638 zone_flags |= ZBC_OUT_ALL;
2640 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2641 scsi_zbc_out(&ccb->csio,
2642 /*retries*/ da_retry_count,
2644 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2645 /*service_action*/ zone_sa,
2647 /*zone_flags*/ zone_flags,
2650 /*sense_len*/ SSD_FULL_SIZE,
2651 /*timeout*/ da_default_timeout * 1000);
2654 * Note that in this case, even though we can
2655 * technically use NCQ, we don't bother for several
2657 * 1. It hasn't been tested on a SAT layer that
2658 * supports it. This is new as of SAT-4.
2659 * 2. Even when there is a SAT layer that supports
2660 * it, that SAT layer will also probably support
2661 * ZBC -> ZAC translation, since they are both
2662 * in the SAT-4 spec.
2663 * 3. Translation will likely be preferable to ATA
2664 * passthrough. LSI / Avago at least single
2665 * steps ATA passthrough commands in the HBA,
2666 * regardless of protocol, so unless that
2667 * changes, there is a performance penalty for
2668 * doing ATA passthrough no matter whether
2669 * you're using NCQ/FPDMA, DMA or PIO.
2670 * 4. It requires a 32-byte CDB, which at least at
2671 * this point in CAM requires a CDB pointer, which
2672 * would require us to allocate an additional bit
2673 * of storage separate from the CCB.
2675 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2676 /*retries*/ da_retry_count,
2678 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2680 /*zm_action*/ zone_sa,
2682 /*zone_flags*/ zone_flags,
2685 /*cdb_storage*/ NULL,
2686 /*cdb_storage_len*/ 0,
2687 /*sense_len*/ SSD_FULL_SIZE,
2688 /*timeout*/ da_default_timeout * 1000);
2691 xpt_print(periph->path,
2692 "scsi_ata_zac_mgmt_out() returned an "
2701 case DISK_ZONE_REPORT_ZONES: {
2703 uint32_t num_entries, alloc_size;
2704 struct disk_zone_report *rep;
2706 rep = &bp->bio_zone.zone_params.report;
2708 num_entries = rep->entries_allocated;
2709 if (num_entries == 0) {
2710 xpt_print(periph->path, "No entries allocated for "
2711 "Report Zones request\n");
2715 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2716 (sizeof(struct scsi_report_zones_desc) * num_entries);
2717 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2718 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2719 if (rz_ptr == NULL) {
2720 xpt_print(periph->path, "Unable to allocate memory "
2721 "for Report Zones request\n");
2726 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2727 scsi_zbc_in(&ccb->csio,
2728 /*retries*/ da_retry_count,
2730 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2731 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2732 /*zone_start_lba*/ rep->starting_id,
2733 /*zone_options*/ rep->rep_options,
2734 /*data_ptr*/ rz_ptr,
2735 /*dxfer_len*/ alloc_size,
2736 /*sense_len*/ SSD_FULL_SIZE,
2737 /*timeout*/ da_default_timeout * 1000);
2740 * Note that in this case, even though we can
2741 * technically use NCQ, we don't bother for several
2743 * 1. It hasn't been tested on a SAT layer that
2744 * supports it. This is new as of SAT-4.
2745 * 2. Even when there is a SAT layer that supports
2746 * it, that SAT layer will also probably support
2747 * ZBC -> ZAC translation, since they are both
2748 * in the SAT-4 spec.
2749 * 3. Translation will likely be preferable to ATA
2750 * passthrough. LSI / Avago at least single
2751 * steps ATA passthrough commands in the HBA,
2752 * regardless of protocol, so unless that
2753 * changes, there is a performance penalty for
2754 * doing ATA passthrough no matter whether
2755 * you're using NCQ/FPDMA, DMA or PIO.
2756 * 4. It requires a 32-byte CDB, which at least at
2757 * this point in CAM requires a CDB pointer, which
2758 * would require us to allocate an additional bit
2759 * of storage separate from the CCB.
2761 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2762 /*retries*/ da_retry_count,
2764 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2766 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2767 /*zone_id*/ rep->starting_id,
2768 /*zone_flags*/ rep->rep_options,
2769 /*data_ptr*/ rz_ptr,
2770 /*dxfer_len*/ alloc_size,
2771 /*cdb_storage*/ NULL,
2772 /*cdb_storage_len*/ 0,
2773 /*sense_len*/ SSD_FULL_SIZE,
2774 /*timeout*/ da_default_timeout * 1000);
2777 xpt_print(periph->path,
2778 "scsi_ata_zac_mgmt_in() returned an "
2785 * For BIO_ZONE, this isn't normally needed. However, it
2786 * is used by devstat_end_transaction_bio() to determine
2787 * how much data was transferred.
2790 * XXX KDM we have a problem. But I'm not sure how to fix
2791 * it. devstat uses bio_bcount - bio_resid to calculate
2792 * the amount of data transferred. The GEOM disk code
2793 * uses bio_length - bio_resid to calculate the amount of
2794 * data in bio_completed. We have different structure
2795 * sizes above and below the ada(4) driver. So, if we
2796 * use the sizes above, the amount transferred won't be
2797 * quite accurate for devstat. If we use different sizes
2798 * for bio_bcount and bio_length (above and below
2799 * respectively), then the residual needs to match one or
2800 * the other. Everything is calculated after the bio
2801 * leaves the driver, so changing the values around isn't
2802 * really an option. For now, just set the count to the
2803 * passed in length. This means that the calculations
2804 * above (e.g. bio_completed) will be correct, but the
2805 * amount of data reported to devstat will be slightly
2806 * under or overstated.
2808 bp->bio_bcount = bp->bio_length;
2814 case DISK_ZONE_GET_PARAMS: {
2815 struct disk_zone_disk_params *params;
2817 params = &bp->bio_zone.zone_params.disk_params;
2818 bzero(params, sizeof(*params));
2820 switch (softc->zone_mode) {
2821 case DA_ZONE_DRIVE_MANAGED:
2822 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
2824 case DA_ZONE_HOST_AWARE:
2825 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
2827 case DA_ZONE_HOST_MANAGED:
2828 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
2832 params->zone_mode = DISK_ZONE_MODE_NONE;
2836 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
2837 params->flags |= DISK_ZONE_DISK_URSWRZ;
2839 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
2840 params->optimal_seq_zones = softc->optimal_seq_zones;
2841 params->flags |= DISK_ZONE_OPT_SEQ_SET;
2844 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
2845 params->optimal_nonseq_zones =
2846 softc->optimal_nonseq_zones;
2847 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
2850 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
2851 params->max_seq_zones = softc->max_seq_zones;
2852 params->flags |= DISK_ZONE_MAX_SEQ_SET;
2854 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
2855 params->flags |= DISK_ZONE_RZ_SUP;
2857 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
2858 params->flags |= DISK_ZONE_OPEN_SUP;
2860 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
2861 params->flags |= DISK_ZONE_CLOSE_SUP;
2863 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
2864 params->flags |= DISK_ZONE_FINISH_SUP;
2866 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
2867 params->flags |= DISK_ZONE_RWP_SUP;
2878 dastart(struct cam_periph *periph, union ccb *start_ccb)
2880 struct da_softc *softc;
2882 softc = (struct da_softc *)periph->softc;
2884 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2887 switch (softc->state) {
2888 case DA_STATE_NORMAL:
2894 bp = cam_iosched_next_bio(softc->cam_iosched);
2896 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2897 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2898 scsi_test_unit_ready(&start_ccb->csio,
2899 /*retries*/ da_retry_count,
2903 da_default_timeout * 1000);
2904 start_ccb->ccb_h.ccb_bp = NULL;
2905 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2906 xpt_action(start_ccb);
2908 xpt_release_ccb(start_ccb);
2912 if (bp->bio_cmd == BIO_DELETE) {
2913 if (softc->delete_func != NULL) {
2914 softc->delete_func(periph, start_ccb, bp);
2917 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
2918 biofinish(bp, NULL, 0);
2923 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2924 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2925 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */
2928 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2929 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2930 softc->flags &= ~DA_FLAG_NEED_OTAG;
2931 softc->flags |= DA_FLAG_WAS_OTAG;
2932 tag_code = MSG_ORDERED_Q_TAG;
2934 tag_code = MSG_SIMPLE_Q_TAG;
2937 switch (bp->bio_cmd) {
2944 if (bp->bio_cmd == BIO_WRITE) {
2945 softc->flags |= DA_FLAG_DIRTY;
2946 rw_op = SCSI_RW_WRITE;
2948 rw_op = SCSI_RW_READ;
2951 data_ptr = bp->bio_data;
2952 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
2953 rw_op |= SCSI_RW_BIO;
2957 scsi_read_write(&start_ccb->csio,
2958 /*retries*/da_retry_count,
2960 /*tag_action*/tag_code,
2963 softc->minimum_cmd_size,
2964 /*lba*/bp->bio_pblkno,
2965 /*block_count*/bp->bio_bcount /
2966 softc->params.secsize,
2968 /*dxfer_len*/ bp->bio_bcount,
2969 /*sense_len*/SSD_FULL_SIZE,
2970 da_default_timeout * 1000);
2975 * BIO_FLUSH doesn't currently communicate
2976 * range data, so we synchronize the cache
2977 * over the whole disk. We also force
2978 * ordered tag semantics the flush applies
2979 * to all previously queued I/O.
2981 scsi_synchronize_cache(&start_ccb->csio,
2988 da_default_timeout*1000);
2991 int error, queue_ccb;
2995 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
2997 || (queue_ccb == 0)) {
2998 biofinish(bp, NULL, error);
2999 xpt_release_ccb(start_ccb);
3005 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3006 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3007 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3010 LIST_INSERT_HEAD(&softc->pending_ccbs,
3011 &start_ccb->ccb_h, periph_links.le);
3013 /* We expect a unit attention from this device */
3014 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3015 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3016 softc->flags &= ~DA_FLAG_RETRY_UA;
3019 start_ccb->ccb_h.ccb_bp = bp;
3021 cam_periph_unlock(periph);
3022 xpt_action(start_ccb);
3023 cam_periph_lock(periph);
3026 /* May have more work to do, so ensure we stay scheduled */
3030 case DA_STATE_PROBE_RC:
3032 struct scsi_read_capacity_data *rcap;
3034 rcap = (struct scsi_read_capacity_data *)
3035 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3037 printf("dastart: Couldn't malloc read_capacity data\n");
3038 /* da_free_periph??? */
3041 scsi_read_capacity(&start_ccb->csio,
3042 /*retries*/da_retry_count,
3048 start_ccb->ccb_h.ccb_bp = NULL;
3049 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3050 xpt_action(start_ccb);
3053 case DA_STATE_PROBE_RC16:
3055 struct scsi_read_capacity_data_long *rcaplong;
3057 rcaplong = (struct scsi_read_capacity_data_long *)
3058 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3059 if (rcaplong == NULL) {
3060 printf("dastart: Couldn't malloc read_capacity data\n");
3061 /* da_free_periph??? */
3064 scsi_read_capacity_16(&start_ccb->csio,
3065 /*retries*/ da_retry_count,
3067 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3071 /*rcap_buf*/ (uint8_t *)rcaplong,
3072 /*rcap_buf_len*/ sizeof(*rcaplong),
3073 /*sense_len*/ SSD_FULL_SIZE,
3074 /*timeout*/ da_default_timeout * 1000);
3075 start_ccb->ccb_h.ccb_bp = NULL;
3076 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3077 xpt_action(start_ccb);
3080 case DA_STATE_PROBE_LBP:
3082 struct scsi_vpd_logical_block_prov *lbp;
3084 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3086 * If we get here we don't support any SBC-3 delete
3087 * methods with UNMAP as the Logical Block Provisioning
3088 * VPD page support is required for devices which
3089 * support it according to T10/1799-D Revision 31
3090 * however older revisions of the spec don't mandate
3091 * this so we currently don't remove these methods
3092 * from the available set.
3094 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3098 lbp = (struct scsi_vpd_logical_block_prov *)
3099 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3102 printf("dastart: Couldn't malloc lbp data\n");
3103 /* da_free_periph??? */
3107 scsi_inquiry(&start_ccb->csio,
3108 /*retries*/da_retry_count,
3110 /*tag_action*/MSG_SIMPLE_Q_TAG,
3111 /*inq_buf*/(u_int8_t *)lbp,
3112 /*inq_len*/sizeof(*lbp),
3114 /*page_code*/SVPD_LBP,
3115 /*sense_len*/SSD_MIN_SIZE,
3116 /*timeout*/da_default_timeout * 1000);
3117 start_ccb->ccb_h.ccb_bp = NULL;
3118 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3119 xpt_action(start_ccb);
3122 case DA_STATE_PROBE_BLK_LIMITS:
3124 struct scsi_vpd_block_limits *block_limits;
3126 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3127 /* Not supported skip to next probe */
3128 softc->state = DA_STATE_PROBE_BDC;
3132 block_limits = (struct scsi_vpd_block_limits *)
3133 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3135 if (block_limits == NULL) {
3136 printf("dastart: Couldn't malloc block_limits data\n");
3137 /* da_free_periph??? */
3141 scsi_inquiry(&start_ccb->csio,
3142 /*retries*/da_retry_count,
3144 /*tag_action*/MSG_SIMPLE_Q_TAG,
3145 /*inq_buf*/(u_int8_t *)block_limits,
3146 /*inq_len*/sizeof(*block_limits),
3148 /*page_code*/SVPD_BLOCK_LIMITS,
3149 /*sense_len*/SSD_MIN_SIZE,
3150 /*timeout*/da_default_timeout * 1000);
3151 start_ccb->ccb_h.ccb_bp = NULL;
3152 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3153 xpt_action(start_ccb);
3156 case DA_STATE_PROBE_BDC:
3158 struct scsi_vpd_block_characteristics *bdc;
3160 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3161 softc->state = DA_STATE_PROBE_ATA;
3165 bdc = (struct scsi_vpd_block_characteristics *)
3166 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3169 printf("dastart: Couldn't malloc bdc data\n");
3170 /* da_free_periph??? */
3174 scsi_inquiry(&start_ccb->csio,
3175 /*retries*/da_retry_count,
3177 /*tag_action*/MSG_SIMPLE_Q_TAG,
3178 /*inq_buf*/(u_int8_t *)bdc,
3179 /*inq_len*/sizeof(*bdc),
3181 /*page_code*/SVPD_BDC,
3182 /*sense_len*/SSD_MIN_SIZE,
3183 /*timeout*/da_default_timeout * 1000);
3184 start_ccb->ccb_h.ccb_bp = NULL;
3185 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3186 xpt_action(start_ccb);
3189 case DA_STATE_PROBE_ATA:
3191 struct ata_params *ata_params;
3193 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3194 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3195 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3197 * Note that if the ATA VPD page isn't
3198 * supported, we aren't talking to an ATA
3199 * device anyway. Support for that VPD
3200 * page is mandatory for SCSI to ATA (SAT)
3201 * translation layers.
3203 softc->state = DA_STATE_PROBE_ZONE;
3206 daprobedone(periph, start_ccb);
3210 ata_params = (struct ata_params*)
3211 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3213 if (ata_params == NULL) {
3214 xpt_print(periph->path, "Couldn't malloc ata_params "
3216 /* da_free_periph??? */
3220 scsi_ata_identify(&start_ccb->csio,
3221 /*retries*/da_retry_count,
3223 /*tag_action*/MSG_SIMPLE_Q_TAG,
3224 /*data_ptr*/(u_int8_t *)ata_params,
3225 /*dxfer_len*/sizeof(*ata_params),
3226 /*sense_len*/SSD_FULL_SIZE,
3227 /*timeout*/da_default_timeout * 1000);
3228 start_ccb->ccb_h.ccb_bp = NULL;
3229 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3230 xpt_action(start_ccb);
3233 case DA_STATE_PROBE_ATA_LOGDIR:
3235 struct ata_gp_log_dir *log_dir;
3240 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3242 * If we don't have log support, not much point in
3243 * trying to probe zone support.
3245 daprobedone(periph, start_ccb);
3250 * If we have an ATA device (the SCSI ATA Information VPD
3251 * page should be present and the ATA identify should have
3252 * succeeded) and it supports logs, ask for the log directory.
3255 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3256 if (log_dir == NULL) {
3257 xpt_print(periph->path, "Couldn't malloc log_dir "
3259 daprobedone(periph, start_ccb);
3263 retval = scsi_ata_read_log(&start_ccb->csio,
3264 /*retries*/ da_retry_count,
3266 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3267 /*log_address*/ ATA_LOG_DIRECTORY,
3270 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3271 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3272 /*data_ptr*/ (uint8_t *)log_dir,
3273 /*dxfer_len*/ sizeof(*log_dir),
3274 /*sense_len*/ SSD_FULL_SIZE,
3275 /*timeout*/ da_default_timeout * 1000);
3278 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3279 free(log_dir, M_SCSIDA);
3280 daprobedone(periph, start_ccb);
3283 start_ccb->ccb_h.ccb_bp = NULL;
3284 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3285 xpt_action(start_ccb);
3288 case DA_STATE_PROBE_ATA_IDDIR:
3290 struct ata_identify_log_pages *id_dir;
3296 * Check here to see whether the Identify Device log is
3297 * supported in the directory of logs. If so, continue
3298 * with requesting the log of identify device pages.
3300 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3301 daprobedone(periph, start_ccb);
3305 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3306 if (id_dir == NULL) {
3307 xpt_print(periph->path, "Couldn't malloc id_dir "
3309 daprobedone(periph, start_ccb);
3313 retval = scsi_ata_read_log(&start_ccb->csio,
3314 /*retries*/ da_retry_count,
3316 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3317 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3318 /*page_number*/ ATA_IDL_PAGE_LIST,
3320 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3321 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3322 /*data_ptr*/ (uint8_t *)id_dir,
3323 /*dxfer_len*/ sizeof(*id_dir),
3324 /*sense_len*/ SSD_FULL_SIZE,
3325 /*timeout*/ da_default_timeout * 1000);
3328 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3329 free(id_dir, M_SCSIDA);
3330 daprobedone(periph, start_ccb);
3333 start_ccb->ccb_h.ccb_bp = NULL;
3334 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3335 xpt_action(start_ccb);
3338 case DA_STATE_PROBE_ATA_SUP:
3340 struct ata_identify_log_sup_cap *sup_cap;
3346 * Check here to see whether the Supported Capabilities log
3347 * is in the list of Identify Device logs.
3349 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3350 daprobedone(periph, start_ccb);
3354 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3355 if (sup_cap == NULL) {
3356 xpt_print(periph->path, "Couldn't malloc sup_cap "
3358 daprobedone(periph, start_ccb);
3362 retval = scsi_ata_read_log(&start_ccb->csio,
3363 /*retries*/ da_retry_count,
3365 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3366 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3367 /*page_number*/ ATA_IDL_SUP_CAP,
3369 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3370 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3371 /*data_ptr*/ (uint8_t *)sup_cap,
3372 /*dxfer_len*/ sizeof(*sup_cap),
3373 /*sense_len*/ SSD_FULL_SIZE,
3374 /*timeout*/ da_default_timeout * 1000);
3377 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3378 free(sup_cap, M_SCSIDA);
3379 daprobedone(periph, start_ccb);
3384 start_ccb->ccb_h.ccb_bp = NULL;
3385 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3386 xpt_action(start_ccb);
3389 case DA_STATE_PROBE_ATA_ZONE:
3391 struct ata_zoned_info_log *ata_zone;
3397 * Check here to see whether the zoned device information
3398 * page is supported. If so, continue on to request it.
3399 * If not, skip to DA_STATE_PROBE_LOG or done.
3401 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3402 daprobedone(periph, start_ccb);
3405 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3407 if (ata_zone == NULL) {
3408 xpt_print(periph->path, "Couldn't malloc ata_zone "
3410 daprobedone(periph, start_ccb);
3414 retval = scsi_ata_read_log(&start_ccb->csio,
3415 /*retries*/ da_retry_count,
3417 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3418 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3419 /*page_number*/ ATA_IDL_ZDI,
3421 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3422 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3423 /*data_ptr*/ (uint8_t *)ata_zone,
3424 /*dxfer_len*/ sizeof(*ata_zone),
3425 /*sense_len*/ SSD_FULL_SIZE,
3426 /*timeout*/ da_default_timeout * 1000);
3429 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3430 free(ata_zone, M_SCSIDA);
3431 daprobedone(periph, start_ccb);
3434 start_ccb->ccb_h.ccb_bp = NULL;
3435 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3436 xpt_action(start_ccb);
3440 case DA_STATE_PROBE_ZONE:
3442 struct scsi_vpd_zoned_bdc *bdc;
3445 * Note that this page will be supported for SCSI protocol
3446 * devices that support ZBC (SMR devices), as well as ATA
3447 * protocol devices that are behind a SAT (SCSI to ATA
3448 * Translation) layer that supports converting ZBC commands
3449 * to their ZAC equivalents.
3451 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3452 daprobedone(periph, start_ccb);
3455 bdc = (struct scsi_vpd_zoned_bdc *)
3456 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3459 xpt_release_ccb(start_ccb);
3460 xpt_print(periph->path, "Couldn't malloc zone VPD "
3464 scsi_inquiry(&start_ccb->csio,
3465 /*retries*/da_retry_count,
3467 /*tag_action*/MSG_SIMPLE_Q_TAG,
3468 /*inq_buf*/(u_int8_t *)bdc,
3469 /*inq_len*/sizeof(*bdc),
3471 /*page_code*/SVPD_ZONED_BDC,
3472 /*sense_len*/SSD_FULL_SIZE,
3473 /*timeout*/da_default_timeout * 1000);
3474 start_ccb->ccb_h.ccb_bp = NULL;
3475 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3476 xpt_action(start_ccb);
3483 * In each of the methods below, while its the caller's
3484 * responsibility to ensure the request will fit into a
3485 * single device request, we might have changed the delete
3486 * method due to the device incorrectly advertising either
3487 * its supported methods or limits.
3489 * To prevent this causing further issues we validate the
3490 * against the methods limits, and warn which would
3491 * otherwise be unnecessary.
3494 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3496 struct da_softc *softc = (struct da_softc *)periph->softc;;
3498 uint8_t *buf = softc->unmap_buf;
3499 uint64_t lba, lastlba = (uint64_t)-1;
3500 uint64_t totalcount = 0;
3502 uint32_t lastcount = 0, c;
3503 uint32_t off, ranges = 0;
3506 * Currently this doesn't take the UNMAP
3507 * Granularity and Granularity Alignment
3508 * fields into account.
3510 * This could result in both unoptimal unmap
3511 * requests as as well as UNMAP calls unmapping
3512 * fewer LBA's than requested.
3515 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3519 * Note: ada and da are different in how they store the
3520 * pending bp's in a trim. ada stores all of them in the
3521 * trim_req.bps. da stores all but the first one in the
3522 * delete_run_queue. ada then completes all the bps in
3523 * its adadone() loop. da completes all the bps in the
3524 * delete_run_queue in dadone, and relies on the biodone
3525 * after to complete. This should be reconciled since there's
3526 * no real reason to do it differently. XXX
3529 bioq_insert_tail(&softc->delete_run_queue, bp1);
3530 lba = bp1->bio_pblkno;
3531 count = bp1->bio_bcount / softc->params.secsize;
3533 /* Try to extend the previous range. */
3534 if (lba == lastlba) {
3535 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3537 off = ((ranges - 1) * UNMAP_RANGE_SIZE) +
3539 scsi_ulto4b(lastcount, &buf[off + 8]);
3546 c = omin(count, UNMAP_RANGE_MAX);
3547 if (totalcount + c > softc->unmap_max_lba ||
3548 ranges >= softc->unmap_max_ranges) {
3549 xpt_print(periph->path,
3550 "%s issuing short delete %ld > %ld"
3552 da_delete_method_desc[softc->delete_method],
3553 totalcount + c, softc->unmap_max_lba,
3554 ranges, softc->unmap_max_ranges);
3557 off = (ranges * UNMAP_RANGE_SIZE) + UNMAP_HEAD_SIZE;
3558 scsi_u64to8b(lba, &buf[off + 0]);
3559 scsi_ulto4b(c, &buf[off + 8]);
3567 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3570 if (ranges >= softc->unmap_max_ranges ||
3571 totalcount + bp1->bio_bcount /
3572 softc->params.secsize > softc->unmap_max_lba) {
3573 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3577 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3578 scsi_ulto2b(ranges * 16, &buf[2]);
3580 scsi_unmap(&ccb->csio,
3581 /*retries*/da_retry_count,
3583 /*tag_action*/MSG_SIMPLE_Q_TAG,
3586 /*dxfer_len*/ ranges * 16 + 8,
3587 /*sense_len*/SSD_FULL_SIZE,
3588 da_default_timeout * 1000);
3589 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3590 ccb->ccb_h.flags |= CAM_UNLOCKED;
3591 cam_iosched_submit_trim(softc->cam_iosched);
3595 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3597 struct da_softc *softc = (struct da_softc *)periph->softc;
3599 uint8_t *buf = softc->unmap_buf;
3600 uint64_t lastlba = (uint64_t)-1;
3603 uint32_t lastcount = 0, c, requestcount;
3604 int ranges = 0, off, block_count;
3606 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3609 if (bp1 != bp)//XXX imp XXX
3610 bioq_insert_tail(&softc->delete_run_queue, bp1);
3611 lba = bp1->bio_pblkno;
3612 count = bp1->bio_bcount / softc->params.secsize;
3613 requestcount = count;
3615 /* Try to extend the previous range. */
3616 if (lba == lastlba) {
3617 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3619 off = (ranges - 1) * 8;
3620 buf[off + 6] = lastcount & 0xff;
3621 buf[off + 7] = (lastcount >> 8) & 0xff;
3627 c = omin(count, ATA_DSM_RANGE_MAX);
3630 buf[off + 0] = lba & 0xff;
3631 buf[off + 1] = (lba >> 8) & 0xff;
3632 buf[off + 2] = (lba >> 16) & 0xff;
3633 buf[off + 3] = (lba >> 24) & 0xff;
3634 buf[off + 4] = (lba >> 32) & 0xff;
3635 buf[off + 5] = (lba >> 40) & 0xff;
3636 buf[off + 6] = c & 0xff;
3637 buf[off + 7] = (c >> 8) & 0xff;
3642 if (count != 0 && ranges == softc->trim_max_ranges) {
3643 xpt_print(periph->path,
3644 "%s issuing short delete %ld > %ld\n",
3645 da_delete_method_desc[softc->delete_method],
3647 (softc->trim_max_ranges - ranges) *
3653 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3656 if (bp1->bio_bcount / softc->params.secsize >
3657 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3658 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3663 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3664 scsi_ata_trim(&ccb->csio,
3665 /*retries*/da_retry_count,
3667 /*tag_action*/MSG_SIMPLE_Q_TAG,
3670 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3671 /*sense_len*/SSD_FULL_SIZE,
3672 da_default_timeout * 1000);
3673 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3674 ccb->ccb_h.flags |= CAM_UNLOCKED;
3675 cam_iosched_submit_trim(softc->cam_iosched);
3679 * We calculate ws_max_blks here based off d_delmaxsize instead
3680 * of using softc->ws_max_blks as it is absolute max for the
3681 * device not the protocol max which may well be lower.
3684 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3686 struct da_softc *softc;
3688 uint64_t ws_max_blks;
3690 uint64_t count; /* forward compat with WS32 */
3692 softc = (struct da_softc *)periph->softc;
3693 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3694 lba = bp->bio_pblkno;
3698 if (bp1 != bp)//XXX imp XXX
3699 bioq_insert_tail(&softc->delete_run_queue, bp1);
3700 count += bp1->bio_bcount / softc->params.secsize;
3701 if (count > ws_max_blks) {
3702 xpt_print(periph->path,
3703 "%s issuing short delete %ld > %ld\n",
3704 da_delete_method_desc[softc->delete_method],
3705 count, ws_max_blks);
3706 count = omin(count, ws_max_blks);
3709 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3712 if (lba + count != bp1->bio_pblkno ||
3713 count + bp1->bio_bcount /
3714 softc->params.secsize > ws_max_blks) {
3715 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3720 scsi_write_same(&ccb->csio,
3721 /*retries*/da_retry_count,
3723 /*tag_action*/MSG_SIMPLE_Q_TAG,
3724 /*byte2*/softc->delete_method ==
3725 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3726 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3728 /*block_count*/count,
3729 /*data_ptr*/ __DECONST(void *, zero_region),
3730 /*dxfer_len*/ softc->params.secsize,
3731 /*sense_len*/SSD_FULL_SIZE,
3732 da_default_timeout * 1000);
3733 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3734 ccb->ccb_h.flags |= CAM_UNLOCKED;
3735 cam_iosched_submit_trim(softc->cam_iosched);
3739 cmd6workaround(union ccb *ccb)
3741 struct scsi_rw_6 cmd6;
3742 struct scsi_rw_10 *cmd10;
3743 struct da_softc *softc;
3748 cdb = ccb->csio.cdb_io.cdb_bytes;
3749 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3751 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3752 da_delete_methods old_method = softc->delete_method;
3755 * Typically there are two reasons for failure here
3756 * 1. Delete method was detected as supported but isn't
3757 * 2. Delete failed due to invalid params e.g. too big
3759 * While we will attempt to choose an alternative delete method
3760 * this may result in short deletes if the existing delete
3761 * requests from geom are big for the new method chosen.
3763 * This method assumes that the error which triggered this
3764 * will not retry the io otherwise a panic will occur
3766 dadeleteflag(softc, old_method, 0);
3767 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3768 if (softc->delete_method == DA_DELETE_DISABLE)
3769 xpt_print(ccb->ccb_h.path,
3770 "%s failed, disabling BIO_DELETE\n",
3771 da_delete_method_desc[old_method]);
3773 xpt_print(ccb->ccb_h.path,
3774 "%s failed, switching to %s BIO_DELETE\n",
3775 da_delete_method_desc[old_method],
3776 da_delete_method_desc[softc->delete_method]);
3778 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3779 cam_iosched_queue_work(softc->cam_iosched, bp);
3780 cam_iosched_queue_work(softc->cam_iosched,
3781 (struct bio *)ccb->ccb_h.ccb_bp);
3782 ccb->ccb_h.ccb_bp = NULL;
3786 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3787 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3788 (*cdb == PREVENT_ALLOW) &&
3789 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3791 xpt_print(ccb->ccb_h.path,
3792 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3793 softc->quirks |= DA_Q_NO_PREVENT;
3797 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3798 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3799 (*cdb == SYNCHRONIZE_CACHE) &&
3800 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3802 xpt_print(ccb->ccb_h.path,
3803 "SYNCHRONIZE CACHE(10) not supported.\n");
3804 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3805 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3809 /* Translation only possible if CDB is an array and cmd is R/W6 */
3810 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3811 (*cdb != READ_6 && *cdb != WRITE_6))
3814 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3815 "increasing minimum_cmd_size to 10.\n");
3816 softc->minimum_cmd_size = 10;
3818 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3819 cmd10 = (struct scsi_rw_10 *)cdb;
3820 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3822 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3823 cmd10->reserved = 0;
3824 scsi_ulto2b(cmd6.length, cmd10->length);
3825 cmd10->control = cmd6.control;
3826 ccb->csio.cdb_len = sizeof(*cmd10);
3828 /* Requeue request, unfreezing queue if necessary */
3829 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3830 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3833 cam_release_devq(ccb->ccb_h.path,
3837 /*getcount_only*/0);
3843 dazonedone(struct cam_periph *periph, union ccb *ccb)
3845 struct da_softc *softc;
3848 softc = periph->softc;
3849 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3851 switch (bp->bio_zone.zone_cmd) {
3852 case DISK_ZONE_OPEN:
3853 case DISK_ZONE_CLOSE:
3854 case DISK_ZONE_FINISH:
3857 case DISK_ZONE_REPORT_ZONES: {
3859 struct disk_zone_report *rep;
3860 struct scsi_report_zones_hdr *hdr;
3861 struct scsi_report_zones_desc *desc;
3862 struct disk_zone_rep_entry *entry;
3863 uint32_t num_alloced, hdr_len, num_avail;
3864 uint32_t num_to_fill, i;
3867 rep = &bp->bio_zone.zone_params.report;
3868 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
3870 * Note that bio_resid isn't normally used for zone
3871 * commands, but it is used by devstat_end_transaction_bio()
3872 * to determine how much data was transferred. Because
3873 * the size of the SCSI/ATA data structures is different
3874 * than the size of the BIO interface structures, the
3875 * amount of data actually transferred from the drive will
3876 * be different than the amount of data transferred to
3879 bp->bio_resid = ccb->csio.resid;
3880 num_alloced = rep->entries_allocated;
3881 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
3882 if (avail_len < sizeof(*hdr)) {
3884 * Is there a better error than EIO here? We asked
3885 * for at least the header, and we got less than
3888 bp->bio_error = EIO;
3889 bp->bio_flags |= BIO_ERROR;
3890 bp->bio_resid = bp->bio_bcount;
3894 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
3899 hdr_len = ata ? le32dec(hdr->length) :
3900 scsi_4btoul(hdr->length);
3902 rep->entries_available = hdr_len / sizeof(*desc);
3904 rep->entries_available = 0;
3906 * NOTE: using the same values for the BIO version of the
3907 * same field as the SCSI/ATA values. This means we could
3908 * get some additional values that aren't defined in bio.h
3909 * if more values of the same field are defined later.
3911 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
3912 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
3913 scsi_8btou64(hdr->maximum_lba);
3915 * If the drive reports no entries that match the query,
3919 rep->entries_filled = 0;
3923 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
3924 hdr_len / sizeof(*desc));
3926 * If the drive didn't return any data, then we're done.
3928 if (num_avail == 0) {
3929 rep->entries_filled = 0;
3933 num_to_fill = min(num_avail, rep->entries_allocated);
3935 * If the user didn't allocate any entries for us to fill,
3938 if (num_to_fill == 0) {
3939 rep->entries_filled = 0;
3943 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
3944 i < num_to_fill; i++, desc++, entry++) {
3946 * NOTE: we're mapping the values here directly
3947 * from the SCSI/ATA bit definitions to the bio.h
3948 * definitons. There is also a warning in
3949 * disk_zone.h, but the impact is that if
3950 * additional values are added in the SCSI/ATA
3951 * specs these will be visible to consumers of
3954 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
3955 entry->zone_condition =
3956 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
3957 SRZ_ZONE_COND_SHIFT;
3958 entry->zone_flags |= desc->zone_flags &
3959 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
3960 entry->zone_length =
3961 ata ? le64dec(desc->zone_length) :
3962 scsi_8btou64(desc->zone_length);
3963 entry->zone_start_lba =
3964 ata ? le64dec(desc->zone_start_lba) :
3965 scsi_8btou64(desc->zone_start_lba);
3966 entry->write_pointer_lba =
3967 ata ? le64dec(desc->write_pointer_lba) :
3968 scsi_8btou64(desc->write_pointer_lba);
3970 rep->entries_filled = num_to_fill;
3973 case DISK_ZONE_GET_PARAMS:
3976 * In theory we should not get a GET_PARAMS bio, since it
3977 * should be handled without queueing the command to the
3980 panic("%s: Invalid zone command %d", __func__,
3981 bp->bio_zone.zone_cmd);
3985 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
3986 free(ccb->csio.data_ptr, M_SCSIDA);
3990 dadone(struct cam_periph *periph, union ccb *done_ccb)
3992 struct da_softc *softc;
3993 struct ccb_scsiio *csio;
3997 softc = (struct da_softc *)periph->softc;
3998 priority = done_ccb->ccb_h.pinfo.priority;
4000 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4002 csio = &done_ccb->csio;
4003 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4005 case DA_CCB_BUFFER_IO:
4008 struct bio *bp, *bp1;
4010 cam_periph_lock(periph);
4011 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4012 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4016 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4021 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4022 if (error == ERESTART) {
4024 * A retry was scheduled, so
4027 cam_periph_unlock(periph);
4030 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4035 * return all queued I/O with EIO, so that
4036 * the client can retry these I/Os in the
4037 * proper order should it attempt to recover.
4042 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4044 * Catastrophic error. Mark our pack as
4048 * XXX See if this is really a media
4051 xpt_print(periph->path,
4052 "Invalidating pack\n");
4053 softc->flags |= DA_FLAG_PACK_INVALID;
4055 softc->invalidations++;
4057 queued_error = ENXIO;
4059 cam_iosched_flush(softc->cam_iosched, NULL,
4062 bp->bio_error = error;
4063 bp->bio_resid = bp->bio_bcount;
4064 bp->bio_flags |= BIO_ERROR;
4066 } else if (bp != NULL) {
4067 if (state == DA_CCB_DELETE)
4070 bp->bio_resid = csio->resid;
4072 if (bp->bio_resid != 0)
4073 bp->bio_flags |= BIO_ERROR;
4075 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4076 cam_release_devq(done_ccb->ccb_h.path,
4080 /*getcount_only*/0);
4081 } else if (bp != NULL) {
4082 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4083 panic("REQ_CMP with QFRZN");
4084 if (bp->bio_cmd == BIO_ZONE)
4085 dazonedone(periph, done_ccb);
4086 else if (state == DA_CCB_DELETE)
4089 bp->bio_resid = csio->resid;
4090 if ((csio->resid > 0)
4091 && (bp->bio_cmd != BIO_ZONE))
4092 bp->bio_flags |= BIO_ERROR;
4093 if (softc->error_inject != 0) {
4094 bp->bio_error = softc->error_inject;
4095 bp->bio_resid = bp->bio_bcount;
4096 bp->bio_flags |= BIO_ERROR;
4097 softc->error_inject = 0;
4101 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4102 if (LIST_EMPTY(&softc->pending_ccbs))
4103 softc->flags |= DA_FLAG_WAS_OTAG;
4105 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4106 xpt_release_ccb(done_ccb);
4107 if (state == DA_CCB_DELETE) {
4108 TAILQ_HEAD(, bio) queue;
4111 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4112 softc->delete_run_queue.insert_point = NULL;
4114 * Normally, the xpt_release_ccb() above would make sure
4115 * that when we have more work to do, that work would
4116 * get kicked off. However, we specifically keep
4117 * delete_running set to 0 before the call above to
4118 * allow other I/O to progress when many BIO_DELETE
4119 * requests are pushed down. We set delete_running to 0
4120 * and call daschedule again so that we don't stall if
4121 * there are no other I/Os pending apart from BIO_DELETEs.
4123 cam_iosched_trim_done(softc->cam_iosched);
4125 cam_periph_unlock(periph);
4126 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4127 TAILQ_REMOVE(&queue, bp1, bio_queue);
4128 bp1->bio_error = bp->bio_error;
4129 if (bp->bio_flags & BIO_ERROR) {
4130 bp1->bio_flags |= BIO_ERROR;
4131 bp1->bio_resid = bp1->bio_bcount;
4138 cam_periph_unlock(periph);
4144 case DA_CCB_PROBE_RC:
4145 case DA_CCB_PROBE_RC16:
4147 struct scsi_read_capacity_data *rdcap;
4148 struct scsi_read_capacity_data_long *rcaplong;
4149 char announce_buf[80];
4155 if (state == DA_CCB_PROBE_RC)
4156 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4158 rcaplong = (struct scsi_read_capacity_data_long *)
4161 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4162 struct disk_params *dp;
4163 uint32_t block_size;
4165 u_int lalba; /* Lowest aligned LBA. */
4167 if (state == DA_CCB_PROBE_RC) {
4168 block_size = scsi_4btoul(rdcap->length);
4169 maxsector = scsi_4btoul(rdcap->addr);
4173 * According to SBC-2, if the standard 10
4174 * byte READ CAPACITY command returns 2^32,
4175 * we should issue the 16 byte version of
4176 * the command, since the device in question
4177 * has more sectors than can be represented
4178 * with the short version of the command.
4180 if (maxsector == 0xffffffff) {
4181 free(rdcap, M_SCSIDA);
4182 xpt_release_ccb(done_ccb);
4183 softc->state = DA_STATE_PROBE_RC16;
4184 xpt_schedule(periph, priority);
4188 block_size = scsi_4btoul(rcaplong->length);
4189 maxsector = scsi_8btou64(rcaplong->addr);
4190 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4194 * Because GEOM code just will panic us if we
4195 * give them an 'illegal' value we'll avoid that
4198 if (block_size == 0) {
4203 if (block_size >= MAXPHYS) {
4204 xpt_print(periph->path,
4205 "unsupportable block size %ju\n",
4206 (uintmax_t) block_size);
4207 announce_buf[0] = '\0';
4208 cam_periph_invalidate(periph);
4211 * We pass rcaplong into dasetgeom(),
4212 * because it will only use it if it is
4215 dasetgeom(periph, block_size, maxsector,
4216 rcaplong, sizeof(*rcaplong));
4217 lbp = (lalba & SRC16_LBPME_A);
4218 dp = &softc->params;
4219 snprintf(announce_buf, sizeof(announce_buf),
4220 "%juMB (%ju %u byte sectors)",
4221 ((uintmax_t)dp->secsize * dp->sectors) /
4223 (uintmax_t)dp->sectors, dp->secsize);
4228 announce_buf[0] = '\0';
4231 * Retry any UNIT ATTENTION type errors. They
4232 * are expected at boot.
4234 error = daerror(done_ccb, CAM_RETRY_SELTO,
4235 SF_RETRY_UA|SF_NO_PRINT);
4236 if (error == ERESTART) {
4238 * A retry was scheuled, so
4242 } else if (error != 0) {
4244 int sense_key, error_code;
4247 struct ccb_getdev cgd;
4249 /* Don't wedge this device's queue */
4250 status = done_ccb->ccb_h.status;
4251 if ((status & CAM_DEV_QFRZN) != 0)
4252 cam_release_devq(done_ccb->ccb_h.path,
4256 /*getcount_only*/0);
4259 xpt_setup_ccb(&cgd.ccb_h,
4260 done_ccb->ccb_h.path,
4261 CAM_PRIORITY_NORMAL);
4262 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4263 xpt_action((union ccb *)&cgd);
4265 if (scsi_extract_sense_ccb(done_ccb,
4266 &error_code, &sense_key, &asc, &ascq))
4272 * If we tried READ CAPACITY(16) and failed,
4273 * fallback to READ CAPACITY(10).
4275 if ((state == DA_CCB_PROBE_RC16) &&
4276 (softc->flags & DA_FLAG_CAN_RC16) &&
4277 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4280 (error_code == SSD_CURRENT_ERROR) &&
4281 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4282 softc->flags &= ~DA_FLAG_CAN_RC16;
4283 free(rdcap, M_SCSIDA);
4284 xpt_release_ccb(done_ccb);
4285 softc->state = DA_STATE_PROBE_RC;
4286 xpt_schedule(periph, priority);
4291 * Attach to anything that claims to be a
4292 * direct access or optical disk device,
4293 * as long as it doesn't return a "Logical
4294 * unit not supported" (0x25) error.
4296 if ((have_sense) && (asc != 0x25)
4297 && (error_code == SSD_CURRENT_ERROR)) {
4298 const char *sense_key_desc;
4299 const char *asc_desc;
4301 dasetgeom(periph, 512, -1, NULL, 0);
4302 scsi_sense_desc(sense_key, asc, ascq,
4306 snprintf(announce_buf,
4307 sizeof(announce_buf),
4308 "Attempt to query device "
4309 "size failed: %s, %s",
4317 xpt_print(periph->path,
4318 "got CAM status %#x\n",
4319 done_ccb->ccb_h.status);
4322 xpt_print(periph->path, "fatal error, "
4323 "failed to attach to device\n");
4326 * Free up resources.
4328 cam_periph_invalidate(periph);
4332 free(csio->data_ptr, M_SCSIDA);
4333 if (announce_buf[0] != '\0' &&
4334 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4336 * Create our sysctl variables, now that we know
4337 * we have successfully attached.
4339 /* increase the refcount */
4340 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4341 taskqueue_enqueue(taskqueue_thread,
4342 &softc->sysctl_task);
4343 xpt_announce_periph(periph, announce_buf);
4344 xpt_announce_quirks(periph, softc->quirks,
4347 xpt_print(periph->path, "fatal error, "
4348 "could not acquire reference count\n");
4352 /* We already probed the device. */
4353 if (softc->flags & DA_FLAG_PROBED) {
4354 daprobedone(periph, done_ccb);
4358 /* Ensure re-probe doesn't see old delete. */
4359 softc->delete_available = 0;
4360 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4361 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4363 * Based on older SBC-3 spec revisions
4364 * any of the UNMAP methods "may" be
4365 * available via LBP given this flag so
4366 * we flag all of them as available and
4367 * then remove those which further
4368 * probes confirm aren't available
4371 * We could also check readcap(16) p_type
4372 * flag to exclude one or more invalid
4373 * write same (X) types here
4375 dadeleteflag(softc, DA_DELETE_WS16, 1);
4376 dadeleteflag(softc, DA_DELETE_WS10, 1);
4377 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4379 xpt_release_ccb(done_ccb);
4380 softc->state = DA_STATE_PROBE_LBP;
4381 xpt_schedule(periph, priority);
4385 xpt_release_ccb(done_ccb);
4386 softc->state = DA_STATE_PROBE_BDC;
4387 xpt_schedule(periph, priority);
4390 case DA_CCB_PROBE_LBP:
4392 struct scsi_vpd_logical_block_prov *lbp;
4394 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4396 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4398 * T10/1799-D Revision 31 states at least one of these
4399 * must be supported but we don't currently enforce this.
4401 dadeleteflag(softc, DA_DELETE_WS16,
4402 (lbp->flags & SVPD_LBP_WS16));
4403 dadeleteflag(softc, DA_DELETE_WS10,
4404 (lbp->flags & SVPD_LBP_WS10));
4405 dadeleteflag(softc, DA_DELETE_UNMAP,
4406 (lbp->flags & SVPD_LBP_UNMAP));
4409 error = daerror(done_ccb, CAM_RETRY_SELTO,
4410 SF_RETRY_UA|SF_NO_PRINT);
4411 if (error == ERESTART)
4413 else if (error != 0) {
4414 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4415 /* Don't wedge this device's queue */
4416 cam_release_devq(done_ccb->ccb_h.path,
4420 /*getcount_only*/0);
4424 * Failure indicates we don't support any SBC-3
4425 * delete methods with UNMAP
4430 free(lbp, M_SCSIDA);
4431 xpt_release_ccb(done_ccb);
4432 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4433 xpt_schedule(periph, priority);
4436 case DA_CCB_PROBE_BLK_LIMITS:
4438 struct scsi_vpd_block_limits *block_limits;
4440 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4442 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4443 uint32_t max_txfer_len = scsi_4btoul(
4444 block_limits->max_txfer_len);
4445 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4446 block_limits->max_unmap_lba_cnt);
4447 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4448 block_limits->max_unmap_blk_cnt);
4449 uint64_t ws_max_blks = scsi_8btou64(
4450 block_limits->max_write_same_length);
4452 if (max_txfer_len != 0) {
4453 softc->disk->d_maxsize = MIN(softc->maxio,
4454 (off_t)max_txfer_len * softc->params.secsize);
4458 * We should already support UNMAP but we check lba
4459 * and block count to be sure
4461 if (max_unmap_lba_cnt != 0x00L &&
4462 max_unmap_blk_cnt != 0x00L) {
4463 softc->unmap_max_lba = max_unmap_lba_cnt;
4464 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4468 * Unexpected UNMAP limits which means the
4469 * device doesn't actually support UNMAP
4471 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4474 if (ws_max_blks != 0x00L)
4475 softc->ws_max_blks = ws_max_blks;
4478 error = daerror(done_ccb, CAM_RETRY_SELTO,
4479 SF_RETRY_UA|SF_NO_PRINT);
4480 if (error == ERESTART)
4482 else if (error != 0) {
4483 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4484 /* Don't wedge this device's queue */
4485 cam_release_devq(done_ccb->ccb_h.path,
4489 /*getcount_only*/0);
4493 * Failure here doesn't mean UNMAP is not
4494 * supported as this is an optional page.
4496 softc->unmap_max_lba = 1;
4497 softc->unmap_max_ranges = 1;
4501 free(block_limits, M_SCSIDA);
4502 xpt_release_ccb(done_ccb);
4503 softc->state = DA_STATE_PROBE_BDC;
4504 xpt_schedule(periph, priority);
4507 case DA_CCB_PROBE_BDC:
4509 struct scsi_vpd_block_device_characteristics *bdc;
4511 bdc = (struct scsi_vpd_block_device_characteristics *)
4514 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4518 * Disable queue sorting for non-rotational media
4521 u_int16_t old_rate = softc->disk->d_rotation_rate;
4523 valid_len = csio->dxfer_len - csio->resid;
4524 if (SBDC_IS_PRESENT(bdc, valid_len,
4525 medium_rotation_rate)) {
4526 softc->disk->d_rotation_rate =
4527 scsi_2btoul(bdc->medium_rotation_rate);
4528 if (softc->disk->d_rotation_rate ==
4529 SVPD_BDC_RATE_NON_ROTATING) {
4530 cam_iosched_set_sort_queue(
4531 softc->cam_iosched, 0);
4532 softc->rotating = 0;
4534 if (softc->disk->d_rotation_rate != old_rate) {
4535 disk_attr_changed(softc->disk,
4536 "GEOM::rotation_rate", M_NOWAIT);
4539 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4540 && (softc->zone_mode == DA_ZONE_NONE)) {
4543 if (scsi_vpd_supported_page(periph,
4544 SVPD_ATA_INFORMATION))
4550 * The Zoned field will only be set for
4551 * Drive Managed and Host Aware drives. If
4552 * they are Host Managed, the device type
4553 * in the standard INQUIRY data should be
4554 * set to T_ZBC_HM (0x14).
4556 if ((bdc->flags & SVPD_ZBC_MASK) ==
4558 softc->zone_mode = DA_ZONE_HOST_AWARE;
4559 softc->zone_interface = (ata_proto) ?
4560 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4561 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4563 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4564 softc->zone_interface = (ata_proto) ?
4565 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4566 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4568 xpt_print(periph->path, "Unknown zoned "
4570 bdc->flags & SVPD_ZBC_MASK);
4575 error = daerror(done_ccb, CAM_RETRY_SELTO,
4576 SF_RETRY_UA|SF_NO_PRINT);
4577 if (error == ERESTART)
4579 else if (error != 0) {
4580 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4581 /* Don't wedge this device's queue */
4582 cam_release_devq(done_ccb->ccb_h.path,
4586 /*getcount_only*/0);
4591 free(bdc, M_SCSIDA);
4592 xpt_release_ccb(done_ccb);
4593 softc->state = DA_STATE_PROBE_ATA;
4594 xpt_schedule(periph, priority);
4597 case DA_CCB_PROBE_ATA:
4600 struct ata_params *ata_params;
4605 ata_params = (struct ata_params *)csio->data_ptr;
4606 ptr = (uint16_t *)ata_params;
4610 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4613 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4614 ptr[i] = le16toh(ptr[i]);
4615 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4616 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4617 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4618 if (ata_params->max_dsm_blocks != 0)
4619 softc->trim_max_ranges = min(
4620 softc->trim_max_ranges,
4621 ata_params->max_dsm_blocks *
4622 ATA_DSM_BLK_RANGES);
4625 * Disable queue sorting for non-rotational media
4628 old_rate = softc->disk->d_rotation_rate;
4629 softc->disk->d_rotation_rate =
4630 ata_params->media_rotation_rate;
4631 if (softc->disk->d_rotation_rate ==
4632 ATA_RATE_NON_ROTATING) {
4633 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4634 softc->rotating = 0;
4636 if (softc->disk->d_rotation_rate != old_rate) {
4637 disk_attr_changed(softc->disk,
4638 "GEOM::rotation_rate", M_NOWAIT);
4641 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4642 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4644 if (ata_params->support.extension &
4646 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4649 * At this point, if we have a SATA host aware drive,
4650 * we communicate via ATA passthrough unless the
4651 * SAT layer supports ZBC -> ZAC translation. In
4655 * XXX KDM figure out how to detect a host managed
4658 if (softc->zone_mode == DA_ZONE_NONE) {
4660 * Note that we don't override the zone
4661 * mode or interface if it has already been
4662 * set. This is because it has either been
4663 * set as a quirk, or when we probed the
4664 * SCSI Block Device Characteristics page,
4665 * the zoned field was set. The latter
4666 * means that the SAT layer supports ZBC to
4667 * ZAC translation, and we would prefer to
4668 * use that if it is available.
4670 if ((ata_params->support3 &
4671 ATA_SUPPORT_ZONE_MASK) ==
4672 ATA_SUPPORT_ZONE_HOST_AWARE) {
4673 softc->zone_mode = DA_ZONE_HOST_AWARE;
4674 softc->zone_interface =
4675 DA_ZONE_IF_ATA_PASS;
4676 } else if ((ata_params->support3 &
4677 ATA_SUPPORT_ZONE_MASK) ==
4678 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4679 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4680 softc->zone_interface =
4681 DA_ZONE_IF_ATA_PASS;
4686 error = daerror(done_ccb, CAM_RETRY_SELTO,
4687 SF_RETRY_UA|SF_NO_PRINT);
4688 if (error == ERESTART)
4690 else if (error != 0) {
4691 if ((done_ccb->ccb_h.status &
4692 CAM_DEV_QFRZN) != 0) {
4693 /* Don't wedge this device's queue */
4694 cam_release_devq(done_ccb->ccb_h.path,
4698 /*getcount_only*/0);
4703 free(ata_params, M_SCSIDA);
4704 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4705 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4707 * If the ATA IDENTIFY failed, we could be talking
4708 * to a SCSI drive, although that seems unlikely,
4709 * since the drive did report that it supported the
4710 * ATA Information VPD page. If the ATA IDENTIFY
4711 * succeeded, and the SAT layer doesn't support
4712 * ZBC -> ZAC translation, continue on to get the
4713 * directory of ATA logs, and complete the rest of
4714 * the ZAC probe. If the SAT layer does support
4715 * ZBC -> ZAC translation, we want to use that,
4716 * and we'll probe the SCSI Zoned Block Device
4717 * Characteristics VPD page next.
4720 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4721 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4722 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4724 softc->state = DA_STATE_PROBE_ZONE;
4727 if (continue_probe != 0) {
4728 xpt_release_ccb(done_ccb);
4729 xpt_schedule(periph, priority);
4732 daprobedone(periph, done_ccb);
4735 case DA_CCB_PROBE_ATA_LOGDIR:
4739 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4741 softc->valid_logdir_len = 0;
4742 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4743 softc->valid_logdir_len =
4744 csio->dxfer_len - csio->resid;
4745 if (softc->valid_logdir_len > 0)
4746 bcopy(csio->data_ptr, &softc->ata_logdir,
4747 min(softc->valid_logdir_len,
4748 sizeof(softc->ata_logdir)));
4750 * Figure out whether the Identify Device log is
4751 * supported. The General Purpose log directory
4752 * has a header, and lists the number of pages
4753 * available for each GP log identified by the
4754 * offset into the list.
4756 if ((softc->valid_logdir_len >=
4757 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4758 && (le16dec(softc->ata_logdir.header) ==
4759 ATA_GP_LOG_DIR_VERSION)
4760 && (le16dec(&softc->ata_logdir.num_pages[
4761 (ATA_IDENTIFY_DATA_LOG *
4762 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4763 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4765 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4768 error = daerror(done_ccb, CAM_RETRY_SELTO,
4769 SF_RETRY_UA|SF_NO_PRINT);
4770 if (error == ERESTART)
4772 else if (error != 0) {
4774 * If we can't get the ATA log directory,
4775 * then ATA logs are effectively not
4776 * supported even if the bit is set in the
4779 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
4780 DA_FLAG_CAN_ATA_IDLOG);
4781 if ((done_ccb->ccb_h.status &
4782 CAM_DEV_QFRZN) != 0) {
4783 /* Don't wedge this device's queue */
4784 cam_release_devq(done_ccb->ccb_h.path,
4788 /*getcount_only*/0);
4793 free(csio->data_ptr, M_SCSIDA);
4796 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
4797 softc->state = DA_STATE_PROBE_ATA_IDDIR;
4798 xpt_release_ccb(done_ccb);
4799 xpt_schedule(periph, priority);
4802 daprobedone(periph, done_ccb);
4805 case DA_CCB_PROBE_ATA_IDDIR:
4809 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4810 off_t entries_offset, max_entries;
4813 softc->valid_iddir_len = 0;
4814 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
4815 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
4816 DA_FLAG_CAN_ATA_ZONE);
4817 softc->valid_iddir_len =
4818 csio->dxfer_len - csio->resid;
4819 if (softc->valid_iddir_len > 0)
4820 bcopy(csio->data_ptr, &softc->ata_iddir,
4821 min(softc->valid_iddir_len,
4822 sizeof(softc->ata_iddir)));
4825 __offsetof(struct ata_identify_log_pages,entries);
4826 max_entries = softc->valid_iddir_len - entries_offset;
4827 if ((softc->valid_iddir_len > (entries_offset + 1))
4828 && (le64dec(softc->ata_iddir.header) ==
4830 && (softc->ata_iddir.entry_count > 0)) {
4833 num_entries = softc->ata_iddir.entry_count;
4834 num_entries = min(num_entries,
4835 softc->valid_iddir_len - entries_offset);
4836 for (i = 0; i < num_entries &&
4837 i < max_entries; i++) {
4838 if (softc->ata_iddir.entries[i] ==
4841 DA_FLAG_CAN_ATA_SUPCAP;
4842 else if (softc->ata_iddir.entries[i]==
4845 DA_FLAG_CAN_ATA_ZONE;
4848 DA_FLAG_CAN_ATA_SUPCAP)
4850 DA_FLAG_CAN_ATA_ZONE))
4855 error = daerror(done_ccb, CAM_RETRY_SELTO,
4856 SF_RETRY_UA|SF_NO_PRINT);
4857 if (error == ERESTART)
4859 else if (error != 0) {
4861 * If we can't get the ATA Identify Data log
4862 * directory, then it effectively isn't
4863 * supported even if the ATA Log directory
4864 * a non-zero number of pages present for
4867 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4868 if ((done_ccb->ccb_h.status &
4869 CAM_DEV_QFRZN) != 0) {
4870 /* Don't wedge this device's queue */
4871 cam_release_devq(done_ccb->ccb_h.path,
4875 /*getcount_only*/0);
4880 free(csio->data_ptr, M_SCSIDA);
4883 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
4884 softc->state = DA_STATE_PROBE_ATA_SUP;
4885 xpt_release_ccb(done_ccb);
4886 xpt_schedule(periph, priority);
4889 daprobedone(periph, done_ccb);
4892 case DA_CCB_PROBE_ATA_SUP:
4896 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4899 struct ata_identify_log_sup_cap *sup_cap;
4902 sup_cap = (struct ata_identify_log_sup_cap *)
4904 valid_len = csio->dxfer_len - csio->resid;
4906 __offsetof(struct ata_identify_log_sup_cap,
4907 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
4908 if (valid_len >= needed_size) {
4909 uint64_t zoned, zac_cap;
4911 zoned = le64dec(sup_cap->zoned_cap);
4912 if (zoned & ATA_ZONED_VALID) {
4914 * This should have already been
4915 * set, because this is also in the
4916 * ATA identify data.
4918 if ((zoned & ATA_ZONED_MASK) ==
4919 ATA_SUPPORT_ZONE_HOST_AWARE)
4922 else if ((zoned & ATA_ZONED_MASK) ==
4923 ATA_SUPPORT_ZONE_DEV_MANAGED)
4925 DA_ZONE_DRIVE_MANAGED;
4928 zac_cap = le64dec(sup_cap->sup_zac_cap);
4929 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
4930 if (zac_cap & ATA_REPORT_ZONES_SUP)
4931 softc->zone_flags |=
4932 DA_ZONE_FLAG_RZ_SUP;
4933 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
4934 softc->zone_flags |=
4935 DA_ZONE_FLAG_OPEN_SUP;
4936 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
4937 softc->zone_flags |=
4938 DA_ZONE_FLAG_CLOSE_SUP;
4939 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
4940 softc->zone_flags |=
4941 DA_ZONE_FLAG_FINISH_SUP;
4942 if (zac_cap & ATA_ND_RWP_SUP)
4943 softc->zone_flags |=
4944 DA_ZONE_FLAG_RWP_SUP;
4947 * This field was introduced in
4948 * ACS-4, r08 on April 28th, 2015.
4949 * If the drive firmware was written
4950 * to an earlier spec, it won't have
4951 * the field. So, assume all
4952 * commands are supported.
4954 softc->zone_flags |=
4955 DA_ZONE_FLAG_SUP_MASK;
4960 error = daerror(done_ccb, CAM_RETRY_SELTO,
4961 SF_RETRY_UA|SF_NO_PRINT);
4962 if (error == ERESTART)
4964 else if (error != 0) {
4966 * If we can't get the ATA Identify Data
4967 * Supported Capabilities page, clear the
4970 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
4972 * And clear zone capabilities.
4974 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
4975 if ((done_ccb->ccb_h.status &
4976 CAM_DEV_QFRZN) != 0) {
4977 /* Don't wedge this device's queue */
4978 cam_release_devq(done_ccb->ccb_h.path,
4982 /*getcount_only*/0);
4987 free(csio->data_ptr, M_SCSIDA);
4990 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
4991 softc->state = DA_STATE_PROBE_ATA_ZONE;
4992 xpt_release_ccb(done_ccb);
4993 xpt_schedule(periph, priority);
4996 daprobedone(periph, done_ccb);
4999 case DA_CCB_PROBE_ATA_ZONE:
5003 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5004 struct ata_zoned_info_log *zi_log;
5008 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5010 valid_len = csio->dxfer_len - csio->resid;
5011 needed_size = __offsetof(struct ata_zoned_info_log,
5012 version_info) + 1 + sizeof(zi_log->version_info);
5013 if (valid_len >= needed_size) {
5016 tmpvar = le64dec(zi_log->zoned_cap);
5017 if (tmpvar & ATA_ZDI_CAP_VALID) {
5018 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5019 softc->zone_flags |=
5020 DA_ZONE_FLAG_URSWRZ;
5022 softc->zone_flags &=
5023 ~DA_ZONE_FLAG_URSWRZ;
5025 tmpvar = le64dec(zi_log->optimal_seq_zones);
5026 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5027 softc->zone_flags |=
5028 DA_ZONE_FLAG_OPT_SEQ_SET;
5029 softc->optimal_seq_zones = (tmpvar &
5030 ATA_ZDI_OPT_SEQ_MASK);
5032 softc->zone_flags &=
5033 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5034 softc->optimal_seq_zones = 0;
5037 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5038 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5039 softc->zone_flags |=
5040 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5041 softc->optimal_nonseq_zones =
5042 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5044 softc->zone_flags &=
5045 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5046 softc->optimal_nonseq_zones = 0;
5049 tmpvar = le64dec(zi_log->max_seq_req_zones);
5050 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5051 softc->zone_flags |=
5052 DA_ZONE_FLAG_MAX_SEQ_SET;
5053 softc->max_seq_zones =
5054 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5056 softc->zone_flags &=
5057 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5058 softc->max_seq_zones = 0;
5062 error = daerror(done_ccb, CAM_RETRY_SELTO,
5063 SF_RETRY_UA|SF_NO_PRINT);
5064 if (error == ERESTART)
5066 else if (error != 0) {
5067 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5068 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5070 if ((done_ccb->ccb_h.status &
5071 CAM_DEV_QFRZN) != 0) {
5072 /* Don't wedge this device's queue */
5073 cam_release_devq(done_ccb->ccb_h.path,
5077 /*getcount_only*/0);
5082 free(csio->data_ptr, M_SCSIDA);
5084 daprobedone(periph, done_ccb);
5087 case DA_CCB_PROBE_ZONE:
5091 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5094 struct scsi_vpd_zoned_bdc *zoned_bdc;
5097 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5099 valid_len = csio->dxfer_len - csio->resid;
5100 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5101 max_seq_req_zones) + 1 +
5102 sizeof(zoned_bdc->max_seq_req_zones);
5103 if ((valid_len >= needed_len)
5104 && (scsi_2btoul(zoned_bdc->page_length) >=
5106 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5107 softc->zone_flags |=
5108 DA_ZONE_FLAG_URSWRZ;
5110 softc->zone_flags &=
5111 ~DA_ZONE_FLAG_URSWRZ;
5112 softc->optimal_seq_zones =
5113 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5114 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5115 softc->optimal_nonseq_zones = scsi_4btoul(
5116 zoned_bdc->optimal_nonseq_zones);
5117 softc->zone_flags |=
5118 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5119 softc->max_seq_zones =
5120 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5121 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5124 * All of the zone commands are mandatory for SCSI
5127 * XXX KDM this is valid as of September 2015.
5128 * Re-check this assumption once the SAT spec is
5129 * updated to support SCSI ZBC to ATA ZAC mapping.
5130 * Since ATA allows zone commands to be reported
5131 * as supported or not, this may not necessarily
5132 * be true for an ATA device behind a SAT (SCSI to
5133 * ATA Translation) layer.
5135 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5137 error = daerror(done_ccb, CAM_RETRY_SELTO,
5138 SF_RETRY_UA|SF_NO_PRINT);
5139 if (error == ERESTART)
5141 else if (error != 0) {
5142 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5143 /* Don't wedge this device's queue */
5144 cam_release_devq(done_ccb->ccb_h.path,
5148 /*getcount_only*/0);
5152 daprobedone(periph, done_ccb);
5156 /* No-op. We're polling */
5160 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5162 if (daerror(done_ccb, CAM_RETRY_SELTO,
5163 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5166 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5167 cam_release_devq(done_ccb->ccb_h.path,
5171 /*getcount_only*/0);
5173 xpt_release_ccb(done_ccb);
5174 cam_periph_release_locked(periph);
5180 xpt_release_ccb(done_ccb);
5184 dareprobe(struct cam_periph *periph)
5186 struct da_softc *softc;
5189 softc = (struct da_softc *)periph->softc;
5191 /* Probe in progress; don't interfere. */
5192 if (softc->state != DA_STATE_NORMAL)
5195 status = cam_periph_acquire(periph);
5196 KASSERT(status == CAM_REQ_CMP,
5197 ("dareprobe: cam_periph_acquire failed"));
5199 if (softc->flags & DA_FLAG_CAN_RC16)
5200 softc->state = DA_STATE_PROBE_RC16;
5202 softc->state = DA_STATE_PROBE_RC;
5204 xpt_schedule(periph, CAM_PRIORITY_DEV);
5208 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5210 struct da_softc *softc;
5211 struct cam_periph *periph;
5212 int error, error_code, sense_key, asc, ascq;
5214 periph = xpt_path_periph(ccb->ccb_h.path);
5215 softc = (struct da_softc *)periph->softc;
5218 * Automatically detect devices that do not support
5219 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5222 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5223 error = cmd6workaround(ccb);
5224 } else if (scsi_extract_sense_ccb(ccb,
5225 &error_code, &sense_key, &asc, &ascq)) {
5226 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5227 error = cmd6workaround(ccb);
5229 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5230 * query the capacity and notify upper layers.
5232 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5233 asc == 0x2A && ascq == 0x09) {
5234 xpt_print(periph->path, "Capacity data has changed\n");
5235 softc->flags &= ~DA_FLAG_PROBED;
5237 sense_flags |= SF_NO_PRINT;
5238 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5239 asc == 0x28 && ascq == 0x00) {
5240 softc->flags &= ~DA_FLAG_PROBED;
5241 disk_media_changed(softc->disk, M_NOWAIT);
5242 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5243 asc == 0x3F && ascq == 0x03) {
5244 xpt_print(periph->path, "INQUIRY data has changed\n");
5245 softc->flags &= ~DA_FLAG_PROBED;
5247 sense_flags |= SF_NO_PRINT;
5248 } else if (sense_key == SSD_KEY_NOT_READY &&
5249 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5250 softc->flags |= DA_FLAG_PACK_INVALID;
5251 disk_media_gone(softc->disk, M_NOWAIT);
5254 if (error == ERESTART)
5258 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5259 case CAM_CMD_TIMEOUT:
5262 case CAM_REQ_ABORTED:
5263 case CAM_REQ_CMP_ERR:
5264 case CAM_REQ_TERMIO:
5265 case CAM_UNREC_HBA_ERROR:
5266 case CAM_DATA_RUN_ERR:
5276 * Until we have a better way of doing pack validation,
5277 * don't treat UAs as errors.
5279 sense_flags |= SF_RETRY_UA;
5281 if (softc->quirks & DA_Q_RETRY_BUSY)
5282 sense_flags |= SF_RETRY_BUSY;
5283 return(cam_periph_error(ccb, cam_flags, sense_flags,
5284 &softc->saved_ccb));
5288 damediapoll(void *arg)
5290 struct cam_periph *periph = arg;
5291 struct da_softc *softc = periph->softc;
5293 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5294 LIST_EMPTY(&softc->pending_ccbs)) {
5295 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5296 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5300 /* Queue us up again */
5301 if (da_poll_period != 0)
5302 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5306 daprevent(struct cam_periph *periph, int action)
5308 struct da_softc *softc;
5312 softc = (struct da_softc *)periph->softc;
5314 if (((action == PR_ALLOW)
5315 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5316 || ((action == PR_PREVENT)
5317 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5321 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5323 scsi_prevent(&ccb->csio,
5331 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5332 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5335 if (action == PR_ALLOW)
5336 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5338 softc->flags |= DA_FLAG_PACK_LOCKED;
5341 xpt_release_ccb(ccb);
5345 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5346 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5348 struct ccb_calc_geometry ccg;
5349 struct da_softc *softc;
5350 struct disk_params *dp;
5351 u_int lbppbe, lalba;
5354 softc = (struct da_softc *)periph->softc;
5356 dp = &softc->params;
5357 dp->secsize = block_len;
5358 dp->sectors = maxsector + 1;
5359 if (rcaplong != NULL) {
5360 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5361 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5362 lalba &= SRC16_LALBA_A;
5369 dp->stripesize = block_len << lbppbe;
5370 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5372 } else if (softc->quirks & DA_Q_4K) {
5373 dp->stripesize = 4096;
5374 dp->stripeoffset = 0;
5377 dp->stripeoffset = 0;
5380 * Have the controller provide us with a geometry
5381 * for this disk. The only time the geometry
5382 * matters is when we boot and the controller
5383 * is the only one knowledgeable enough to come
5384 * up with something that will make this a bootable
5387 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5388 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5389 ccg.block_size = dp->secsize;
5390 ccg.volume_size = dp->sectors;
5392 ccg.secs_per_track = 0;
5394 xpt_action((union ccb*)&ccg);
5395 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5397 * We don't know what went wrong here- but just pick
5398 * a geometry so we don't have nasty things like divide
5402 dp->secs_per_track = 255;
5403 dp->cylinders = dp->sectors / (255 * 255);
5404 if (dp->cylinders == 0) {
5408 dp->heads = ccg.heads;
5409 dp->secs_per_track = ccg.secs_per_track;
5410 dp->cylinders = ccg.cylinders;
5414 * If the user supplied a read capacity buffer, and if it is
5415 * different than the previous buffer, update the data in the EDT.
5416 * If it's the same, we don't bother. This avoids sending an
5417 * update every time someone opens this device.
5419 if ((rcaplong != NULL)
5420 && (bcmp(rcaplong, &softc->rcaplong,
5421 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5422 struct ccb_dev_advinfo cdai;
5424 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5425 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5426 cdai.buftype = CDAI_TYPE_RCAPLONG;
5427 cdai.flags = CDAI_FLAG_STORE;
5428 cdai.bufsiz = rcap_len;
5429 cdai.buf = (uint8_t *)rcaplong;
5430 xpt_action((union ccb *)&cdai);
5431 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5432 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5433 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5434 xpt_print(periph->path, "%s: failed to set read "
5435 "capacity advinfo\n", __func__);
5436 /* Use cam_error_print() to decode the status */
5437 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5440 bcopy(rcaplong, &softc->rcaplong,
5441 min(sizeof(softc->rcaplong), rcap_len));
5445 softc->disk->d_sectorsize = softc->params.secsize;
5446 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5447 softc->disk->d_stripesize = softc->params.stripesize;
5448 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5449 /* XXX: these are not actually "firmware" values, so they may be wrong */
5450 softc->disk->d_fwsectors = softc->params.secs_per_track;
5451 softc->disk->d_fwheads = softc->params.heads;
5452 softc->disk->d_devstat->block_size = softc->params.secsize;
5453 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5455 error = disk_resize(softc->disk, M_NOWAIT);
5457 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5461 dasendorderedtag(void *arg)
5463 struct da_softc *softc = arg;
5465 if (da_send_ordered) {
5466 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5467 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5468 softc->flags |= DA_FLAG_NEED_OTAG;
5469 softc->flags &= ~DA_FLAG_WAS_OTAG;
5472 /* Queue us up again */
5473 callout_reset(&softc->sendordered_c,
5474 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5475 dasendorderedtag, softc);
5479 * Step through all DA peripheral drivers, and if the device is still open,
5480 * sync the disk cache to physical media.
5483 dashutdown(void * arg, int howto)
5485 struct cam_periph *periph;
5486 struct da_softc *softc;
5490 CAM_PERIPH_FOREACH(periph, &dadriver) {
5491 softc = (struct da_softc *)periph->softc;
5492 if (SCHEDULER_STOPPED()) {
5493 /* If we paniced with the lock held, do not recurse. */
5494 if (!cam_periph_owned(periph) &&
5495 (softc->flags & DA_FLAG_OPEN)) {
5496 dadump(softc->disk, NULL, 0, 0, 0);
5500 cam_periph_lock(periph);
5503 * We only sync the cache if the drive is still open, and
5504 * if the drive is capable of it..
5506 if (((softc->flags & DA_FLAG_OPEN) == 0)
5507 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5508 cam_periph_unlock(periph);
5512 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5513 scsi_synchronize_cache(&ccb->csio,
5517 /*begin_lba*/0, /* whole disk */
5522 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5523 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5524 softc->disk->d_devstat);
5526 xpt_print(periph->path, "Synchronize cache failed\n");
5527 xpt_release_ccb(ccb);
5528 cam_periph_unlock(periph);
5532 #else /* !_KERNEL */
5535 * XXX These are only left out of the kernel build to silence warnings. If,
5536 * for some reason these functions are used in the kernel, the ifdefs should
5537 * be moved so they are included both in the kernel and userland.
5540 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5541 void (*cbfcnp)(struct cam_periph *, union ccb *),
5542 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5543 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5546 struct scsi_format_unit *scsi_cmd;
5548 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5549 scsi_cmd->opcode = FORMAT_UNIT;
5550 scsi_cmd->byte2 = byte2;
5551 scsi_ulto2b(ileave, scsi_cmd->interleave);
5556 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5566 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5567 void (*cbfcnp)(struct cam_periph *, union ccb *),
5568 uint8_t tag_action, uint8_t list_format,
5569 uint32_t addr_desc_index, uint8_t *data_ptr,
5570 uint32_t dxfer_len, int minimum_cmd_size,
5571 uint8_t sense_len, uint32_t timeout)
5576 * These conditions allow using the 10 byte command. Otherwise we
5577 * need to use the 12 byte command.
5579 if ((minimum_cmd_size <= 10)
5580 && (addr_desc_index == 0)
5581 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5582 struct scsi_read_defect_data_10 *cdb10;
5584 cdb10 = (struct scsi_read_defect_data_10 *)
5585 &csio->cdb_io.cdb_bytes;
5587 cdb_len = sizeof(*cdb10);
5588 bzero(cdb10, cdb_len);
5589 cdb10->opcode = READ_DEFECT_DATA_10;
5590 cdb10->format = list_format;
5591 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5593 struct scsi_read_defect_data_12 *cdb12;
5595 cdb12 = (struct scsi_read_defect_data_12 *)
5596 &csio->cdb_io.cdb_bytes;
5598 cdb_len = sizeof(*cdb12);
5599 bzero(cdb12, cdb_len);
5600 cdb12->opcode = READ_DEFECT_DATA_12;
5601 cdb12->format = list_format;
5602 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5603 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5609 /*flags*/ CAM_DIR_IN,
5619 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5620 void (*cbfcnp)(struct cam_periph *, union ccb *),
5621 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5622 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5625 struct scsi_sanitize *scsi_cmd;
5627 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5628 scsi_cmd->opcode = SANITIZE;
5629 scsi_cmd->byte2 = byte2;
5630 scsi_cmd->control = control;
5631 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5636 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5645 #endif /* _KERNEL */
5648 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5649 void (*cbfcnp)(struct cam_periph *, union ccb *),
5650 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5651 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5652 uint8_t sense_len, uint32_t timeout)
5654 struct scsi_zbc_out *scsi_cmd;
5656 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5657 scsi_cmd->opcode = ZBC_OUT;
5658 scsi_cmd->service_action = service_action;
5659 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5660 scsi_cmd->zone_flags = zone_flags;
5665 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5675 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5676 void (*cbfcnp)(struct cam_periph *, union ccb *),
5677 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5678 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5679 uint8_t sense_len, uint32_t timeout)
5681 struct scsi_zbc_in *scsi_cmd;
5683 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5684 scsi_cmd->opcode = ZBC_IN;
5685 scsi_cmd->service_action = service_action;
5686 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5687 scsi_cmd->zone_options = zone_options;
5692 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5703 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5704 void (*cbfcnp)(struct cam_periph *, union ccb *),
5705 uint8_t tag_action, int use_ncq,
5706 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5707 uint8_t *data_ptr, uint32_t dxfer_len,
5708 uint8_t *cdb_storage, size_t cdb_storage_len,
5709 uint8_t sense_len, uint32_t timeout)
5711 uint8_t command_out, protocol, ata_flags;
5712 uint16_t features_out;
5713 uint32_t sectors_out, auxiliary;
5719 command_out = ATA_ZAC_MANAGEMENT_OUT;
5720 features_out = (zm_action & 0xf) | (zone_flags << 8),
5721 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5722 if (dxfer_len == 0) {
5723 protocol = AP_PROTO_NON_DATA;
5724 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5727 protocol = AP_PROTO_DMA;
5728 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5729 AP_FLAG_TDIR_TO_DEV;
5730 sectors_out = ((dxfer_len >> 9) & 0xffff);
5734 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5735 if (dxfer_len == 0) {
5736 command_out = ATA_NCQ_NON_DATA;
5737 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5739 * We're assuming the SCSI to ATA translation layer
5740 * will set the NCQ tag number in the tag field.
5741 * That isn't clear from the SAT-4 spec (as of rev 05).
5744 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5746 command_out = ATA_SEND_FPDMA_QUEUED;
5748 * Note that we're defaulting to normal priority,
5749 * and assuming that the SCSI to ATA translation
5750 * layer will insert the NCQ tag number in the tag
5751 * field. That isn't clear in the SAT-4 spec (as
5754 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5756 ata_flags |= AP_FLAG_TLEN_FEAT |
5757 AP_FLAG_TDIR_TO_DEV;
5760 * For SEND FPDMA QUEUED, the transfer length is
5761 * encoded in the FEATURE register, and 0 means
5762 * that 65536 512 byte blocks are to be tranferred.
5763 * In practice, it seems unlikely that we'll see
5764 * a transfer that large, and it may confuse the
5765 * the SAT layer, because generally that means that
5766 * 0 bytes should be transferred.
5768 if (dxfer_len == (65536 * 512)) {
5770 } else if (dxfer_len <= (65535 * 512)) {
5771 features_out = ((dxfer_len >> 9) & 0xffff);
5773 /* The transfer is too big. */
5780 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
5781 protocol = AP_PROTO_FPDMA;
5784 protocol |= AP_EXTEND;
5786 retval = scsi_ata_pass(csio,
5789 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5791 /*protocol*/ protocol,
5792 /*ata_flags*/ ata_flags,
5793 /*features*/ features_out,
5794 /*sector_count*/ sectors_out,
5796 /*command*/ command_out,
5799 /*auxiliary*/ auxiliary,
5801 /*data_ptr*/ data_ptr,
5802 /*dxfer_len*/ dxfer_len,
5803 /*cdb_storage*/ cdb_storage,
5804 /*cdb_storage_len*/ cdb_storage_len,
5805 /*minimum_cmd_size*/ 0,
5806 /*sense_len*/ SSD_FULL_SIZE,
5807 /*timeout*/ timeout);
5815 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
5816 void (*cbfcnp)(struct cam_periph *, union ccb *),
5817 uint8_t tag_action, int use_ncq,
5818 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5819 uint8_t *data_ptr, uint32_t dxfer_len,
5820 uint8_t *cdb_storage, size_t cdb_storage_len,
5821 uint8_t sense_len, uint32_t timeout)
5823 uint8_t command_out, protocol;
5824 uint16_t features_out, sectors_out;
5830 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
5833 command_out = ATA_ZAC_MANAGEMENT_IN;
5834 /* XXX KDM put a macro here */
5835 features_out = (zm_action & 0xf) | (zone_flags << 8),
5836 sectors_out = dxfer_len >> 9, /* XXX KDM macro*/
5837 protocol = AP_PROTO_DMA;
5838 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
5841 ata_flags |= AP_FLAG_TLEN_FEAT;
5843 command_out = ATA_RECV_FPDMA_QUEUED;
5844 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
5847 * For RECEIVE FPDMA QUEUED, the transfer length is
5848 * encoded in the FEATURE register, and 0 means
5849 * that 65536 512 byte blocks are to be tranferred.
5850 * In practice, it seems unlikely that we'll see
5851 * a transfer that large, and it may confuse the
5852 * the SAT layer, because generally that means that
5853 * 0 bytes should be transferred.
5855 if (dxfer_len == (65536 * 512)) {
5857 } else if (dxfer_len <= (65535 * 512)) {
5858 features_out = ((dxfer_len >> 9) & 0xffff);
5860 /* The transfer is too big. */
5864 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
5865 protocol = AP_PROTO_FPDMA;
5868 protocol |= AP_EXTEND;
5870 retval = scsi_ata_pass(csio,
5873 /*flags*/ CAM_DIR_IN,
5875 /*protocol*/ protocol,
5876 /*ata_flags*/ ata_flags,
5877 /*features*/ features_out,
5878 /*sector_count*/ sectors_out,
5880 /*command*/ command_out,
5883 /*auxiliary*/ auxiliary,
5885 /*data_ptr*/ data_ptr,
5886 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
5887 /*cdb_storage*/ cdb_storage,
5888 /*cdb_storage_len*/ cdb_storage_len,
5889 /*minimum_cmd_size*/ 0,
5890 /*sense_len*/ SSD_FULL_SIZE,
5891 /*timeout*/ timeout);