2 * Implementation of SCSI Direct Access Peripheral driver for CAM.
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (c) 1997 Justin T. Gibbs.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification, immediately at the beginning of the file.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
41 #include <sys/sysctl.h>
42 #include <sys/taskqueue.h>
44 #include <sys/mutex.h>
46 #include <sys/devicestat.h>
47 #include <sys/eventhandler.h>
48 #include <sys/malloc.h>
50 #include <sys/endian.h>
53 #include <geom/geom.h>
54 #include <geom/geom_disk.h>
55 #include <machine/atomic.h>
64 #include <cam/cam_ccb.h>
65 #include <cam/cam_periph.h>
66 #include <cam/cam_xpt_periph.h>
67 #include <cam/cam_sim.h>
68 #include <cam/cam_iosched.h>
70 #include <cam/scsi/scsi_message.h>
71 #include <cam/scsi/scsi_da.h>
75 * Note that there are probe ordering dependencies here. The order isn't
76 * controlled by this enumeration, but by explicit state transitions in
77 * dastart() and dadone(). Here are some of the dependencies:
79 * 1. RC should come first, before RC16, unless there is evidence that RC16
81 * 2. BDC needs to come before any of the ATA probes, or the ZONE probe.
82 * 3. The ATA probes should go in this order:
83 * ATA -> LOGDIR -> IDDIR -> SUP -> ATA_ZONE
90 DA_STATE_PROBE_BLK_LIMITS,
93 DA_STATE_PROBE_ATA_LOGDIR,
94 DA_STATE_PROBE_ATA_IDDIR,
95 DA_STATE_PROBE_ATA_SUP,
96 DA_STATE_PROBE_ATA_ZONE,
102 DA_FLAG_PACK_INVALID = 0x000001,
103 DA_FLAG_NEW_PACK = 0x000002,
104 DA_FLAG_PACK_LOCKED = 0x000004,
105 DA_FLAG_PACK_REMOVABLE = 0x000008,
106 DA_FLAG_NEED_OTAG = 0x000020,
107 DA_FLAG_WAS_OTAG = 0x000040,
108 DA_FLAG_RETRY_UA = 0x000080,
109 DA_FLAG_OPEN = 0x000100,
110 DA_FLAG_SCTX_INIT = 0x000200,
111 DA_FLAG_CAN_RC16 = 0x000400,
112 DA_FLAG_PROBED = 0x000800,
113 DA_FLAG_DIRTY = 0x001000,
114 DA_FLAG_ANNOUNCED = 0x002000,
115 DA_FLAG_CAN_ATA_DMA = 0x004000,
116 DA_FLAG_CAN_ATA_LOG = 0x008000,
117 DA_FLAG_CAN_ATA_IDLOG = 0x010000,
118 DA_FLAG_CAN_ATA_SUPCAP = 0x020000,
119 DA_FLAG_CAN_ATA_ZONE = 0x040000,
120 DA_FLAG_TUR_PENDING = 0x080000
125 DA_Q_NO_SYNC_CACHE = 0x01,
126 DA_Q_NO_6_BYTE = 0x02,
127 DA_Q_NO_PREVENT = 0x04,
130 DA_Q_NO_UNMAP = 0x20,
131 DA_Q_RETRY_BUSY = 0x40,
133 DA_Q_STRICT_UNMAP = 0x100
136 #define DA_Q_BIT_STRING \
138 "\001NO_SYNC_CACHE" \
149 DA_CCB_PROBE_RC = 0x01,
150 DA_CCB_PROBE_RC16 = 0x02,
151 DA_CCB_PROBE_LBP = 0x03,
152 DA_CCB_PROBE_BLK_LIMITS = 0x04,
153 DA_CCB_PROBE_BDC = 0x05,
154 DA_CCB_PROBE_ATA = 0x06,
155 DA_CCB_BUFFER_IO = 0x07,
157 DA_CCB_DELETE = 0x0B,
159 DA_CCB_PROBE_ZONE = 0x0D,
160 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
161 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
162 DA_CCB_PROBE_ATA_SUP = 0x10,
163 DA_CCB_PROBE_ATA_ZONE = 0x11,
164 DA_CCB_PROBE_WP = 0x12,
165 DA_CCB_TYPE_MASK = 0x1F,
166 DA_CCB_RETRY_UA = 0x20
170 * Order here is important for method choice
172 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
173 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
174 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
175 * import taking 5mins.
186 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
187 DA_DELETE_MAX = DA_DELETE_ZERO
191 * For SCSI, host managed drives show up as a separate device type. For
192 * ATA, host managed drives also have a different device signature.
193 * XXX KDM figure out the ATA host managed signature.
197 DA_ZONE_DRIVE_MANAGED = 0x01,
198 DA_ZONE_HOST_AWARE = 0x02,
199 DA_ZONE_HOST_MANAGED = 0x03
203 * We distinguish between these interface cases in addition to the drive type:
204 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
205 * o ATA drive behind a SCSI translation layer that does not know about
206 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
207 * case, we would need to share the ATA code with the ada(4) driver.
217 DA_ZONE_FLAG_RZ_SUP = 0x0001,
218 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
219 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
220 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
221 DA_ZONE_FLAG_RWP_SUP = 0x0010,
222 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
223 DA_ZONE_FLAG_OPEN_SUP |
224 DA_ZONE_FLAG_CLOSE_SUP |
225 DA_ZONE_FLAG_FINISH_SUP |
226 DA_ZONE_FLAG_RWP_SUP),
227 DA_ZONE_FLAG_URSWRZ = 0x0020,
228 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
229 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
230 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
231 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
232 DA_ZONE_FLAG_OPT_NONSEQ_SET |
233 DA_ZONE_FLAG_MAX_SEQ_SET)
236 static struct da_zone_desc {
239 } da_zone_desc_table[] = {
240 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
241 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
242 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
243 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
244 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
247 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
249 static da_delete_func_t da_delete_trim;
250 static da_delete_func_t da_delete_unmap;
251 static da_delete_func_t da_delete_ws;
253 static const void * da_delete_functions[] = {
263 static const char *da_delete_method_names[] =
264 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
265 static const char *da_delete_method_desc[] =
266 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
267 "WRITE SAME(10) with UNMAP", "ZERO" };
269 /* Offsets into our private area for storing information */
270 #define ccb_state ppriv_field0
271 #define ccb_bp ppriv_ptr1
276 u_int8_t secs_per_track;
277 u_int32_t secsize; /* Number of bytes/sector */
278 u_int64_t sectors; /* total number sectors */
283 #define UNMAP_RANGE_MAX 0xffffffff
284 #define UNMAP_HEAD_SIZE 8
285 #define UNMAP_RANGE_SIZE 16
286 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
287 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
290 #define WS10_MAX_BLKS 0xffff
291 #define WS16_MAX_BLKS 0xffffffff
292 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
293 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
295 #define DA_WORK_TUR (1 << 16)
306 DA_REF_MAX /* KEEP LAST */
310 struct cam_iosched_softc *cam_iosched;
311 struct bio_queue_head delete_run_queue;
312 LIST_HEAD(, ccb_hdr) pending_ccbs;
313 int refcount; /* Active xpt_action() calls */
317 int minimum_cmd_size;
320 int delete_available; /* Delete methods possibly available */
321 da_zone_mode zone_mode;
322 da_zone_interface zone_interface;
323 da_zone_flags zone_flags;
324 struct ata_gp_log_dir ata_logdir;
325 int valid_logdir_len;
326 struct ata_identify_log_pages ata_iddir;
328 uint64_t optimal_seq_zones;
329 uint64_t optimal_nonseq_zones;
330 uint64_t max_seq_zones;
332 uint32_t unmap_max_ranges;
333 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
335 uint32_t unmap_gran_align;
336 uint64_t ws_max_blks;
338 uint64_t trim_ranges;
340 da_delete_methods delete_method_pref;
341 da_delete_methods delete_method;
342 da_delete_func_t *delete_func;
345 struct disk_params params;
348 struct task sysctl_task;
349 struct sysctl_ctx_list sysctl_ctx;
350 struct sysctl_oid *sysctl_tree;
351 struct callout sendordered_c;
353 uint8_t unmap_buf[UNMAP_BUF_SIZE];
354 struct scsi_read_capacity_data_long rcaplong;
355 struct callout mediapoll_c;
356 int ref_flags[DA_REF_MAX];
358 struct sysctl_ctx_list sysctl_stats_ctx;
359 struct sysctl_oid *sysctl_stats_tree;
364 #define DA_ANNOUNCETMP_SZ 160
365 char announce_temp[DA_ANNOUNCETMP_SZ];
366 #define DA_ANNOUNCE_SZ 400
367 char announcebuf[DA_ANNOUNCE_SZ];
370 #define dadeleteflag(softc, delete_method, enable) \
372 softc->delete_available |= (1 << delete_method); \
374 softc->delete_available &= ~(1 << delete_method); \
377 struct da_quirk_entry {
378 struct scsi_inquiry_pattern inq_pat;
382 static const char quantum[] = "QUANTUM";
383 static const char microp[] = "MICROP";
385 static struct da_quirk_entry da_quirk_table[] =
387 /* SPI, FC devices */
390 * Fujitsu M2513A MO drives.
391 * Tested devices: M2513A2 firmware versions 1200 & 1300.
392 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
393 * Reported by: W.Scholten <whs@xs4all.nl>
395 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
396 /*quirks*/ DA_Q_NO_SYNC_CACHE
400 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
401 /*quirks*/ DA_Q_NO_SYNC_CACHE
405 * This particular Fujitsu drive doesn't like the
406 * synchronize cache command.
407 * Reported by: Tom Jackson <toj@gorilla.net>
409 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
410 /*quirks*/ DA_Q_NO_SYNC_CACHE
414 * This drive doesn't like the synchronize cache command
415 * either. Reported by: Matthew Jacob <mjacob@feral.com>
416 * in NetBSD PR kern/6027, August 24, 1998.
418 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
419 /*quirks*/ DA_Q_NO_SYNC_CACHE
423 * This drive doesn't like the synchronize cache command
424 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
427 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
428 /*quirks*/ DA_Q_NO_SYNC_CACHE
432 * Doesn't like the synchronize cache command.
433 * Reported by: Blaz Zupan <blaz@gold.amis.net>
435 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
436 /*quirks*/ DA_Q_NO_SYNC_CACHE
440 * Doesn't like the synchronize cache command.
441 * Reported by: Blaz Zupan <blaz@gold.amis.net>
443 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
444 /*quirks*/ DA_Q_NO_SYNC_CACHE
448 * Doesn't like the synchronize cache command.
450 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
451 /*quirks*/ DA_Q_NO_SYNC_CACHE
455 * Doesn't like the synchronize cache command.
456 * Reported by: walter@pelissero.de
458 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
459 /*quirks*/ DA_Q_NO_SYNC_CACHE
463 * Doesn't work correctly with 6 byte reads/writes.
464 * Returns illegal request, and points to byte 9 of the
466 * Reported by: Adam McDougall <bsdx@spawnet.com>
468 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
469 /*quirks*/ DA_Q_NO_6_BYTE
473 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
474 /*quirks*/ DA_Q_NO_6_BYTE
478 * Doesn't like the synchronize cache command.
479 * Reported by: walter@pelissero.de
481 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
482 /*quirks*/ DA_Q_NO_SYNC_CACHE
486 * The CISS RAID controllers do not support SYNC_CACHE
488 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
489 /*quirks*/ DA_Q_NO_SYNC_CACHE
493 * The STEC SSDs sometimes hang on UNMAP.
495 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
496 /*quirks*/ DA_Q_NO_UNMAP
500 * VMware returns BUSY status when storage has transient
501 * connectivity problems, so better wait.
502 * Also VMware returns odd errors on misaligned UNMAPs.
504 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
505 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
507 /* USB mass storage devices supported by umass(4) */
510 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
513 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
514 /*quirks*/ DA_Q_NO_SYNC_CACHE
518 * Power Quotient Int. (PQI) USB flash key
521 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
522 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
526 * Creative Nomad MUVO mp3 player (USB)
529 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
530 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
534 * Jungsoft NEXDISK USB flash key
537 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
538 /*quirks*/ DA_Q_NO_SYNC_CACHE
542 * FreeDik USB Mini Data Drive
545 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
546 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
550 * Sigmatel USB Flash MP3 Player
553 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
554 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
558 * Neuros USB Digital Audio Computer
561 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
562 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
566 * SEAGRAND NP-900 MP3 Player
569 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
570 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
574 * iRiver iFP MP3 player (with UMS Firmware)
575 * PR: kern/54881, i386/63941, kern/66124
577 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
578 /*quirks*/ DA_Q_NO_SYNC_CACHE
582 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
585 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
586 /*quirks*/ DA_Q_NO_SYNC_CACHE
590 * ZICPlay USB MP3 Player with FM
593 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
594 /*quirks*/ DA_Q_NO_SYNC_CACHE
598 * TEAC USB floppy mechanisms
600 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
601 /*quirks*/ DA_Q_NO_SYNC_CACHE
605 * Kingston DataTraveler II+ USB Pen-Drive.
606 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
608 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
609 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
617 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
618 /*quirks*/ DA_Q_NO_SYNC_CACHE
622 * Motorola E398 Mobile Phone (TransFlash memory card).
623 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
626 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
627 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
631 * Qware BeatZkey! Pro
634 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
635 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
639 * Time DPA20B 1GB MP3 Player
642 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
643 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
647 * Samsung USB key 128Mb
650 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
651 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
655 * Kingston DataTraveler 2.0 USB Flash memory.
658 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
659 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
663 * Creative MUVO Slim mp3 player (USB)
666 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
667 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
671 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
674 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
675 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
679 * SanDisk Micro Cruzer 128MB
682 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
683 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
687 * TOSHIBA TransMemory USB sticks
690 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
691 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
695 * PNY USB 3.0 Flash Drives
697 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
698 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
703 * PR: usb/75578, usb/72344, usb/65436
705 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
706 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
712 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
713 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16
717 * Genesys 6-in-1 Card Reader
720 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
721 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
725 * Rekam Digital CAMERA
728 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
729 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
733 * iRiver H10 MP3 player
736 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
737 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
741 * iRiver U10 MP3 player
744 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
745 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
752 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
753 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
757 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
760 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
761 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
768 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
769 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
773 * Philips USB Key Audio KEY013
776 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
777 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
784 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
785 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
792 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
793 /*quirks*/ DA_Q_NO_SYNC_CACHE
797 * I/O Magic USB flash - Giga Bank
800 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
801 /*quirks*/ DA_Q_NO_SYNC_CACHE
805 * JoyFly 128mb USB Flash Drive
808 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
809 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
816 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
817 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
821 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
824 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
825 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
829 * Samsung YP-U3 mp3-player
832 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
833 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
836 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
837 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
841 * Sony Cyber-Shot DSC cameras
844 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
845 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
848 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
849 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
852 /* At least several Transcent USB sticks lie on RC16. */
853 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
854 "*"}, /*quirks*/ DA_Q_NO_RC16
858 * I-O Data USB Flash Disk
861 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
862 "*"}, /*quirks*/ DA_Q_NO_RC16
866 * 16GB SLC CHIPFANCIER
869 {T_DIRECT, SIP_MEDIA_REMOVABLE, "16G SLC", "CHIPFANCIER",
870 "1.00"}, /*quirks*/ DA_Q_NO_RC16
872 /* ATA/SATA devices over SAS/USB/... */
874 /* Hitachi Advanced Format (4k) drives */
875 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
879 /* Micron Advanced Format (4k) drives */
880 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
884 /* Samsung Advanced Format (4k) drives */
885 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
889 /* Samsung Advanced Format (4k) drives */
890 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
894 /* Samsung Advanced Format (4k) drives */
895 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
899 /* Samsung Advanced Format (4k) drives */
900 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
904 /* Seagate Barracuda Green Advanced Format (4k) drives */
905 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
909 /* Seagate Barracuda Green Advanced Format (4k) drives */
910 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
914 /* Seagate Barracuda Green Advanced Format (4k) drives */
915 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
919 /* Seagate Barracuda Green Advanced Format (4k) drives */
920 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
924 /* Seagate Barracuda Green Advanced Format (4k) drives */
925 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
929 /* Seagate Barracuda Green Advanced Format (4k) drives */
930 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
934 /* Seagate Momentus Advanced Format (4k) drives */
935 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
939 /* Seagate Momentus Advanced Format (4k) drives */
940 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
944 /* Seagate Momentus Advanced Format (4k) drives */
945 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
949 /* Seagate Momentus Advanced Format (4k) drives */
950 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
954 /* Seagate Momentus Advanced Format (4k) drives */
955 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
959 /* Seagate Momentus Advanced Format (4k) drives */
960 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
964 /* Seagate Momentus Advanced Format (4k) drives */
965 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
969 /* Seagate Momentus Advanced Format (4k) drives */
970 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
974 /* Seagate Momentus Advanced Format (4k) drives */
975 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
979 /* Seagate Momentus Advanced Format (4k) drives */
980 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
984 /* Seagate Momentus Advanced Format (4k) drives */
985 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
989 /* Seagate Momentus Advanced Format (4k) drives */
990 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
994 /* Seagate Momentus Advanced Format (4k) drives */
995 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
999 /* Seagate Momentus Advanced Format (4k) drives */
1000 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
1004 /* Seagate Momentus Thin Advanced Format (4k) drives */
1005 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
1009 /* Seagate Momentus Thin Advanced Format (4k) drives */
1010 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
1014 /* WDC Caviar Green Advanced Format (4k) drives */
1015 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
1019 /* WDC Caviar Green Advanced Format (4k) drives */
1020 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
1024 /* WDC Caviar Green Advanced Format (4k) drives */
1025 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
1029 /* WDC Caviar Green Advanced Format (4k) drives */
1030 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
1034 /* WDC Caviar Green Advanced Format (4k) drives */
1035 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1039 /* WDC Caviar Green Advanced Format (4k) drives */
1040 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1044 /* WDC Caviar Green Advanced Format (4k) drives */
1045 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1049 /* WDC Caviar Green Advanced Format (4k) drives */
1050 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1054 /* WDC Scorpio Black Advanced Format (4k) drives */
1055 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1059 /* WDC Scorpio Black Advanced Format (4k) drives */
1060 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1064 /* WDC Scorpio Black Advanced Format (4k) drives */
1065 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1069 /* WDC Scorpio Black Advanced Format (4k) drives */
1070 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1074 /* WDC Scorpio Blue Advanced Format (4k) drives */
1075 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1079 /* WDC Scorpio Blue Advanced Format (4k) drives */
1080 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1084 /* WDC Scorpio Blue Advanced Format (4k) drives */
1085 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1089 /* WDC Scorpio Blue Advanced Format (4k) drives */
1090 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1095 * Olympus digital cameras (C-3040ZOOM, C-2040ZOOM, C-1)
1098 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "C*", "*"},
1099 /*quirks*/ DA_Q_NO_6_BYTE | DA_Q_NO_SYNC_CACHE
1103 * Olympus digital cameras (D-370)
1106 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "D*", "*"},
1107 /*quirks*/ DA_Q_NO_6_BYTE
1111 * Olympus digital cameras (E-100RS, E-10).
1114 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "E*", "*"},
1115 /*quirks*/ DA_Q_NO_6_BYTE | DA_Q_NO_SYNC_CACHE
1119 * Olympus FE-210 camera
1121 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1122 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1126 * Pentax Digital Camera
1129 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PENTAX", "DIGITAL CAMERA",
1130 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1134 * LG UP3S MP3 player
1136 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1137 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1141 * Laser MP3-2GA13 MP3 player
1143 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1144 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1148 * LaCie external 250GB Hard drive des by Porsche
1149 * Submitted by: Ben Stuyts <ben@altesco.nl>
1152 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1153 /*quirks*/ DA_Q_NO_SYNC_CACHE
1158 * Corsair Force 2 SSDs
1159 * 4k optimised & trim only works in 4k requests + 4k aligned
1161 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1166 * Corsair Force 3 SSDs
1167 * 4k optimised & trim only works in 4k requests + 4k aligned
1169 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1174 * Corsair Neutron GTX SSDs
1175 * 4k optimised & trim only works in 4k requests + 4k aligned
1177 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1182 * Corsair Force GT & GS SSDs
1183 * 4k optimised & trim only works in 4k requests + 4k aligned
1185 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1191 * 4k optimised & trim only works in 4k requests + 4k aligned
1193 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1198 * Crucial RealSSD C300 SSDs
1201 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1202 "*" }, /*quirks*/DA_Q_4K
1206 * Intel 320 Series SSDs
1207 * 4k optimised & trim only works in 4k requests + 4k aligned
1209 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1214 * Intel 330 Series SSDs
1215 * 4k optimised & trim only works in 4k requests + 4k aligned
1217 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1222 * Intel 510 Series SSDs
1223 * 4k optimised & trim only works in 4k requests + 4k aligned
1225 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1230 * Intel 520 Series SSDs
1231 * 4k optimised & trim only works in 4k requests + 4k aligned
1233 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1238 * Intel S3610 Series SSDs
1239 * 4k optimised & trim only works in 4k requests + 4k aligned
1241 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1246 * Intel X25-M Series SSDs
1247 * 4k optimised & trim only works in 4k requests + 4k aligned
1249 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1254 * Kingston E100 Series SSDs
1255 * 4k optimised & trim only works in 4k requests + 4k aligned
1257 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1262 * Kingston HyperX 3k SSDs
1263 * 4k optimised & trim only works in 4k requests + 4k aligned
1265 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1270 * Marvell SSDs (entry taken from OpenSolaris)
1271 * 4k optimised & trim only works in 4k requests + 4k aligned
1273 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1278 * OCZ Agility 2 SSDs
1279 * 4k optimised & trim only works in 4k requests + 4k aligned
1281 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1286 * OCZ Agility 3 SSDs
1287 * 4k optimised & trim only works in 4k requests + 4k aligned
1289 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1294 * OCZ Deneva R Series SSDs
1295 * 4k optimised & trim only works in 4k requests + 4k aligned
1297 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1302 * OCZ Vertex 2 SSDs (inc pro series)
1303 * 4k optimised & trim only works in 4k requests + 4k aligned
1305 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1311 * 4k optimised & trim only works in 4k requests + 4k aligned
1313 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1319 * 4k optimised & trim only works in 4k requests + 4k aligned
1321 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1326 * Samsung 750 Series SSDs
1327 * 4k optimised & trim only works in 4k requests + 4k aligned
1329 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" },
1334 * Samsung 830 Series SSDs
1335 * 4k optimised & trim only works in 4k requests + 4k aligned
1337 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1343 * 4k optimised & trim only works in 4k requests + 4k aligned
1345 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1351 * 4k optimised & trim only works in 4k requests + 4k aligned
1353 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" },
1359 * 4k optimised & trim only works in 4k requests + 4k aligned
1361 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1366 * Samsung 843T Series SSDs (MZ7WD*)
1367 * Samsung PM851 Series SSDs (MZ7TE*)
1368 * Samsung PM853T Series SSDs (MZ7GE*)
1369 * Samsung SM863 Series SSDs (MZ7KM*)
1372 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1377 * Same as for SAMSUNG MZ7* but enable the quirks for SSD
1378 * starting with MZ7* too
1380 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MZ7*", "*" },
1385 * SuperTalent TeraDrive CT SSDs
1386 * 4k optimised & trim only works in 4k requests + 4k aligned
1388 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1393 * XceedIOPS SATA SSDs
1396 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1401 * Hama Innostor USB-Stick
1403 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1404 /*quirks*/DA_Q_NO_RC16
1408 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1409 * Drive Managed SATA hard drive. This drive doesn't report
1410 * in firmware that it is a drive managed SMR drive.
1412 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS000[23]*", "*" },
1413 /*quirks*/DA_Q_SMR_DM
1417 * MX-ES USB Drive by Mach Xtreme
1419 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1420 /*quirks*/DA_Q_NO_RC16
1424 static disk_strategy_t dastrategy;
1425 static dumper_t dadump;
1426 static periph_init_t dainit;
1427 static void daasync(void *callback_arg, u_int32_t code,
1428 struct cam_path *path, void *arg);
1429 static void dasysctlinit(void *context, int pending);
1430 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1431 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1432 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1433 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1434 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1435 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1436 static void dadeletemethodset(struct da_softc *softc,
1437 da_delete_methods delete_method);
1438 static off_t dadeletemaxsize(struct da_softc *softc,
1439 da_delete_methods delete_method);
1440 static void dadeletemethodchoose(struct da_softc *softc,
1441 da_delete_methods default_method);
1442 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1444 static periph_ctor_t daregister;
1445 static periph_dtor_t dacleanup;
1446 static periph_start_t dastart;
1447 static periph_oninv_t daoninvalidate;
1448 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1449 static void dadone(struct cam_periph *periph,
1450 union ccb *done_ccb);
1451 static void dadone_probewp(struct cam_periph *periph,
1452 union ccb *done_ccb);
1453 static void dadone_proberc(struct cam_periph *periph,
1454 union ccb *done_ccb);
1455 static void dadone_probelbp(struct cam_periph *periph,
1456 union ccb *done_ccb);
1457 static void dadone_probeblklimits(struct cam_periph *periph,
1458 union ccb *done_ccb);
1459 static void dadone_probebdc(struct cam_periph *periph,
1460 union ccb *done_ccb);
1461 static void dadone_probeata(struct cam_periph *periph,
1462 union ccb *done_ccb);
1463 static void dadone_probeatalogdir(struct cam_periph *periph,
1464 union ccb *done_ccb);
1465 static void dadone_probeataiddir(struct cam_periph *periph,
1466 union ccb *done_ccb);
1467 static void dadone_probeatasup(struct cam_periph *periph,
1468 union ccb *done_ccb);
1469 static void dadone_probeatazone(struct cam_periph *periph,
1470 union ccb *done_ccb);
1471 static void dadone_probezone(struct cam_periph *periph,
1472 union ccb *done_ccb);
1473 static void dadone_tur(struct cam_periph *periph,
1474 union ccb *done_ccb);
1475 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1476 u_int32_t sense_flags);
1477 static void daprevent(struct cam_periph *periph, int action);
1478 static void dareprobe(struct cam_periph *periph);
1479 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1481 struct scsi_read_capacity_data_long *rcaplong,
1483 static timeout_t dasendorderedtag;
1484 static void dashutdown(void *arg, int howto);
1485 static timeout_t damediapoll;
1487 #ifndef DA_DEFAULT_POLL_PERIOD
1488 #define DA_DEFAULT_POLL_PERIOD 3
1491 #ifndef DA_DEFAULT_TIMEOUT
1492 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1495 #ifndef DA_DEFAULT_SOFTTIMEOUT
1496 #define DA_DEFAULT_SOFTTIMEOUT 0
1499 #ifndef DA_DEFAULT_RETRY
1500 #define DA_DEFAULT_RETRY 4
1503 #ifndef DA_DEFAULT_SEND_ORDERED
1504 #define DA_DEFAULT_SEND_ORDERED 1
1507 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1508 static int da_retry_count = DA_DEFAULT_RETRY;
1509 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1510 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1511 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1512 static int da_disable_wp_detection = 0;
1514 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1515 "CAM Direct Access Disk driver");
1516 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1517 &da_poll_period, 0, "Media polling period in seconds");
1518 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1519 &da_retry_count, 0, "Normal I/O retry count");
1520 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1521 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1522 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1523 &da_send_ordered, 0, "Send Ordered Tags");
1524 SYSCTL_INT(_kern_cam_da, OID_AUTO, disable_wp_detection, CTLFLAG_RWTUN,
1525 &da_disable_wp_detection, 0,
1526 "Disable detection of write-protected disks");
1528 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1529 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1530 "Soft I/O timeout (ms)");
1531 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1534 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1535 * to the default timeout, we check to see whether an ordered
1536 * tagged transaction is appropriate to prevent simple tag
1537 * starvation. Since we'd like to ensure that there is at least
1538 * 1/2 of the timeout length left for a starved transaction to
1539 * complete after we've sent an ordered tag, we must poll at least
1540 * four times in every timeout period. This takes care of the worst
1541 * case where a starved transaction starts during an interval that
1542 * meets the requirement "don't send an ordered tag" test so it takes
1543 * us two intervals to determine that a tag must be sent.
1545 #ifndef DA_ORDEREDTAG_INTERVAL
1546 #define DA_ORDEREDTAG_INTERVAL 4
1549 static struct periph_driver dadriver =
1552 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1555 PERIPHDRIVER_DECLARE(da, dadriver);
1557 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1560 * This driver takes out references / holds in well defined pairs, never
1561 * recursively. These macros / inline functions enforce those rules. They
1562 * are only enabled with DA_TRACK_REFS or INVARIANTS. If DA_TRACK_REFS is
1563 * defined to be 2 or larger, the tracking also includes debug printfs.
1565 #if defined(DA_TRACK_REFS) || defined(INVARIANTS)
1567 #ifndef DA_TRACK_REFS
1568 #define DA_TRACK_REFS 1
1571 #if DA_TRACK_REFS > 1
1572 static const char *da_ref_text[] = {
1585 #define DA_PERIPH_PRINT(periph, msg, args...) \
1586 CAM_PERIPH_PRINT(periph, msg, ##args)
1588 #define DA_PERIPH_PRINT(periph, msg, args...)
1592 token_sanity(da_ref_token token)
1594 if ((unsigned)token >= DA_REF_MAX)
1595 panic("Bad token value passed in %d\n", token);
1599 da_periph_hold(struct cam_periph *periph, int priority, da_ref_token token)
1601 int err = cam_periph_hold(periph, priority);
1603 token_sanity(token);
1604 DA_PERIPH_PRINT(periph, "Holding device %s (%d): %d\n",
1605 da_ref_text[token], token, err);
1608 struct da_softc *softc = periph->softc;
1610 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1612 panic("Re-holding for reason %d, cnt = %d", token, cnt);
1618 da_periph_unhold(struct cam_periph *periph, da_ref_token token)
1621 struct da_softc *softc = periph->softc;
1623 token_sanity(token);
1624 DA_PERIPH_PRINT(periph, "Unholding device %s (%d)\n",
1625 da_ref_text[token], token);
1626 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1628 panic("Unholding %d with cnt = %d", token, cnt);
1629 cam_periph_unhold(periph);
1633 da_periph_acquire(struct cam_periph *periph, da_ref_token token)
1635 int err = cam_periph_acquire(periph);
1637 token_sanity(token);
1638 DA_PERIPH_PRINT(periph, "acquiring device %s (%d): %d\n",
1639 da_ref_text[token], token, err);
1642 struct da_softc *softc = periph->softc;
1644 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1646 panic("Re-refing for reason %d, cnt = %d", token, cnt);
1652 da_periph_release(struct cam_periph *periph, da_ref_token token)
1655 struct da_softc *softc = periph->softc;
1657 token_sanity(token);
1658 DA_PERIPH_PRINT(periph, "releasing device %s (%d)\n",
1659 da_ref_text[token], token);
1660 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1662 panic("Releasing %d with cnt = %d", token, cnt);
1663 cam_periph_release(periph);
1667 da_periph_release_locked(struct cam_periph *periph, da_ref_token token)
1670 struct da_softc *softc = periph->softc;
1672 token_sanity(token);
1673 DA_PERIPH_PRINT(periph, "releasing device (locked) %s (%d)\n",
1674 da_ref_text[token], token);
1675 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1677 panic("Unholding %d with cnt = %d", token, cnt);
1678 cam_periph_release_locked(periph);
1681 #define cam_periph_hold POISON
1682 #define cam_periph_unhold POISON
1683 #define cam_periph_acquire POISON
1684 #define cam_periph_release POISON
1685 #define cam_periph_release_locked POISON
1688 #define da_periph_hold(periph, prio, token) cam_periph_hold((periph), (prio))
1689 #define da_periph_unhold(periph, token) cam_periph_unhold((periph))
1690 #define da_periph_acquire(periph, token) cam_periph_acquire((periph))
1691 #define da_periph_release(periph, token) cam_periph_release((periph))
1692 #define da_periph_release_locked(periph, token) cam_periph_release_locked((periph))
1696 daopen(struct disk *dp)
1698 struct cam_periph *periph;
1699 struct da_softc *softc;
1702 periph = (struct cam_periph *)dp->d_drv1;
1703 if (da_periph_acquire(periph, DA_REF_OPEN) != 0) {
1707 cam_periph_lock(periph);
1708 if ((error = da_periph_hold(periph, PRIBIO|PCATCH, DA_REF_OPEN_HOLD)) != 0) {
1709 cam_periph_unlock(periph);
1710 da_periph_release(periph, DA_REF_OPEN);
1714 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1717 softc = (struct da_softc *)periph->softc;
1720 /* Wait for the disk size update. */
1721 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1724 xpt_print(periph->path, "unable to retrieve capacity data\n");
1726 if (periph->flags & CAM_PERIPH_INVALID)
1729 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1730 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1731 daprevent(periph, PR_PREVENT);
1734 softc->flags &= ~DA_FLAG_PACK_INVALID;
1735 softc->flags |= DA_FLAG_OPEN;
1738 da_periph_unhold(periph, DA_REF_OPEN_HOLD);
1739 cam_periph_unlock(periph);
1742 da_periph_release(periph, DA_REF_OPEN);
1748 daclose(struct disk *dp)
1750 struct cam_periph *periph;
1751 struct da_softc *softc;
1754 periph = (struct cam_periph *)dp->d_drv1;
1755 softc = (struct da_softc *)periph->softc;
1756 cam_periph_lock(periph);
1757 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1760 if (da_periph_hold(periph, PRIBIO, DA_REF_CLOSE_HOLD) == 0) {
1762 /* Flush disk cache. */
1763 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1764 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1765 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1766 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1767 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1768 /*cbfcnp*/NULL, MSG_SIMPLE_Q_TAG,
1769 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1771 cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1772 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1773 softc->disk->d_devstat);
1774 softc->flags &= ~DA_FLAG_DIRTY;
1775 xpt_release_ccb(ccb);
1778 /* Allow medium removal. */
1779 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1780 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1781 daprevent(periph, PR_ALLOW);
1783 da_periph_unhold(periph, DA_REF_CLOSE_HOLD);
1787 * If we've got removeable media, mark the blocksize as
1788 * unavailable, since it could change when new media is
1791 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1792 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1794 softc->flags &= ~DA_FLAG_OPEN;
1795 while (softc->refcount != 0)
1796 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1797 cam_periph_unlock(periph);
1798 da_periph_release(periph, DA_REF_OPEN);
1803 daschedule(struct cam_periph *periph)
1805 struct da_softc *softc = (struct da_softc *)periph->softc;
1807 if (softc->state != DA_STATE_NORMAL)
1810 cam_iosched_schedule(softc->cam_iosched, periph);
1814 * Actually translate the requested transfer into one the physical driver
1815 * can understand. The transfer is described by a buf and will include
1816 * only one physical transfer.
1819 dastrategy(struct bio *bp)
1821 struct cam_periph *periph;
1822 struct da_softc *softc;
1824 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1825 softc = (struct da_softc *)periph->softc;
1827 cam_periph_lock(periph);
1830 * If the device has been made invalid, error out
1832 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1833 cam_periph_unlock(periph);
1834 biofinish(bp, NULL, ENXIO);
1838 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1841 * Zone commands must be ordered, because they can depend on the
1842 * effects of previously issued commands, and they may affect
1843 * commands after them.
1845 if (bp->bio_cmd == BIO_ZONE)
1846 bp->bio_flags |= BIO_ORDERED;
1849 * Place it in the queue of disk activities for this disk
1851 cam_iosched_queue_work(softc->cam_iosched, bp);
1854 * Schedule ourselves for performing the work.
1857 cam_periph_unlock(periph);
1863 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1865 struct cam_periph *periph;
1866 struct da_softc *softc;
1868 struct ccb_scsiio csio;
1873 periph = dp->d_drv1;
1874 softc = (struct da_softc *)periph->softc;
1875 secsize = softc->params.secsize;
1877 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0)
1880 memset(&csio, 0, sizeof(csio));
1882 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1883 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1884 scsi_read_write(&csio,
1888 /*read*/SCSI_RW_WRITE,
1890 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1893 /*data_ptr*/(u_int8_t *) virtual,
1894 /*dxfer_len*/length,
1895 /*sense_len*/SSD_FULL_SIZE,
1896 da_default_timeout * 1000);
1897 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1898 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1900 printf("Aborting dump due to I/O error.\n");
1905 * Sync the disk cache contents to the physical media.
1907 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1909 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1910 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1911 scsi_synchronize_cache(&csio,
1915 /*begin_lba*/0,/* Cover the whole disk */
1919 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1920 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1922 xpt_print(periph->path, "Synchronize cache failed\n");
1928 dagetattr(struct bio *bp)
1931 struct cam_periph *periph;
1933 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1934 cam_periph_lock(periph);
1935 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1937 cam_periph_unlock(periph);
1939 bp->bio_completed = bp->bio_length;
1949 * Install a global async callback. This callback will
1950 * receive async callbacks like "new device found".
1952 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1954 if (status != CAM_REQ_CMP) {
1955 printf("da: Failed to attach master async callback "
1956 "due to status 0x%x!\n", status);
1957 } else if (da_send_ordered) {
1959 /* Register our shutdown event handler */
1960 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1961 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1962 printf("dainit: shutdown event registration failed!\n");
1967 * Callback from GEOM, called when it has finished cleaning up its
1971 dadiskgonecb(struct disk *dp)
1973 struct cam_periph *periph;
1975 periph = (struct cam_periph *)dp->d_drv1;
1976 da_periph_release(periph, DA_REF_GEOM);
1980 daoninvalidate(struct cam_periph *periph)
1982 struct da_softc *softc;
1984 cam_periph_assert(periph, MA_OWNED);
1985 softc = (struct da_softc *)periph->softc;
1988 * De-register any async callbacks.
1990 xpt_register_async(0, daasync, periph, periph->path);
1992 softc->flags |= DA_FLAG_PACK_INVALID;
1994 softc->invalidations++;
1998 * Return all queued I/O with ENXIO.
1999 * XXX Handle any transactions queued to the card
2000 * with XPT_ABORT_CCB.
2002 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
2005 * Tell GEOM that we've gone away, we'll get a callback when it is
2006 * done cleaning up its resources.
2008 disk_gone(softc->disk);
2012 dacleanup(struct cam_periph *periph)
2014 struct da_softc *softc;
2016 softc = (struct da_softc *)periph->softc;
2018 cam_periph_unlock(periph);
2020 cam_iosched_fini(softc->cam_iosched);
2023 * If we can't free the sysctl tree, oh well...
2025 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
2027 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
2028 xpt_print(periph->path,
2029 "can't remove sysctl stats context\n");
2031 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
2032 xpt_print(periph->path,
2033 "can't remove sysctl context\n");
2036 callout_drain(&softc->mediapoll_c);
2037 disk_destroy(softc->disk);
2038 callout_drain(&softc->sendordered_c);
2039 free(softc, M_DEVBUF);
2040 cam_periph_lock(periph);
2044 daasync(void *callback_arg, u_int32_t code,
2045 struct cam_path *path, void *arg)
2047 struct cam_periph *periph;
2048 struct da_softc *softc;
2050 periph = (struct cam_periph *)callback_arg;
2052 case AC_FOUND_DEVICE: /* callback to create periph, no locking yet */
2054 struct ccb_getdev *cgd;
2057 cgd = (struct ccb_getdev *)arg;
2061 if (cgd->protocol != PROTO_SCSI)
2063 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
2065 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
2066 && SID_TYPE(&cgd->inq_data) != T_RBC
2067 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
2068 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
2072 * Allocate a peripheral instance for
2073 * this device and start the probe
2076 status = cam_periph_alloc(daregister, daoninvalidate,
2078 "da", CAM_PERIPH_BIO,
2080 AC_FOUND_DEVICE, cgd);
2082 if (status != CAM_REQ_CMP
2083 && status != CAM_REQ_INPROG)
2084 printf("daasync: Unable to attach to new device "
2085 "due to status 0x%x\n", status);
2088 case AC_ADVINFO_CHANGED: /* Doesn't touch periph */
2092 buftype = (uintptr_t)arg;
2093 if (buftype == CDAI_TYPE_PHYS_PATH) {
2094 struct da_softc *softc;
2096 softc = periph->softc;
2097 disk_attr_changed(softc->disk, "GEOM::physpath",
2102 case AC_UNIT_ATTENTION:
2105 int error_code, sense_key, asc, ascq;
2107 softc = (struct da_softc *)periph->softc;
2108 ccb = (union ccb *)arg;
2111 * Handle all UNIT ATTENTIONs except our own, as they will be
2112 * handled by daerror(). Since this comes from a different periph,
2113 * that periph's lock is held, not ours, so we have to take it ours
2114 * out to touch softc flags.
2116 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
2117 scsi_extract_sense_ccb(ccb,
2118 &error_code, &sense_key, &asc, &ascq)) {
2119 if (asc == 0x2A && ascq == 0x09) {
2120 xpt_print(ccb->ccb_h.path,
2121 "Capacity data has changed\n");
2122 cam_periph_lock(periph);
2123 softc->flags &= ~DA_FLAG_PROBED;
2124 cam_periph_unlock(periph);
2126 } else if (asc == 0x28 && ascq == 0x00) {
2127 cam_periph_lock(periph);
2128 softc->flags &= ~DA_FLAG_PROBED;
2129 cam_periph_unlock(periph);
2130 disk_media_changed(softc->disk, M_NOWAIT);
2131 } else if (asc == 0x3F && ascq == 0x03) {
2132 xpt_print(ccb->ccb_h.path,
2133 "INQUIRY data has changed\n");
2134 cam_periph_lock(periph);
2135 softc->flags &= ~DA_FLAG_PROBED;
2136 cam_periph_unlock(periph);
2142 case AC_SCSI_AEN: /* Called for this path: periph locked */
2144 * Appears to be currently unused for SCSI devices, only ata SIMs
2147 cam_periph_assert(periph, MA_OWNED);
2148 softc = (struct da_softc *)periph->softc;
2149 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
2150 (softc->flags & DA_FLAG_TUR_PENDING) == 0) {
2151 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
2152 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
2157 case AC_SENT_BDR: /* Called for this path: periph locked */
2158 case AC_BUS_RESET: /* Called for this path: periph locked */
2160 struct ccb_hdr *ccbh;
2162 cam_periph_assert(periph, MA_OWNED);
2163 softc = (struct da_softc *)periph->softc;
2165 * Don't fail on the expected unit attention
2168 softc->flags |= DA_FLAG_RETRY_UA;
2169 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
2170 ccbh->ccb_state |= DA_CCB_RETRY_UA;
2173 case AC_INQ_CHANGED: /* Called for this path: periph locked */
2174 cam_periph_assert(periph, MA_OWNED);
2175 softc = (struct da_softc *)periph->softc;
2176 softc->flags &= ~DA_FLAG_PROBED;
2182 cam_periph_async(periph, code, path, arg);
2186 dasysctlinit(void *context, int pending)
2188 struct cam_periph *periph;
2189 struct da_softc *softc;
2190 char tmpstr[32], tmpstr2[16];
2191 struct ccb_trans_settings cts;
2193 periph = (struct cam_periph *)context;
2195 * periph was held for us when this task was enqueued
2197 if (periph->flags & CAM_PERIPH_INVALID) {
2198 da_periph_release(periph, DA_REF_SYSCTL);
2202 softc = (struct da_softc *)periph->softc;
2203 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
2204 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
2206 sysctl_ctx_init(&softc->sysctl_ctx);
2207 cam_periph_lock(periph);
2208 softc->flags |= DA_FLAG_SCTX_INIT;
2209 cam_periph_unlock(periph);
2210 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
2211 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
2212 CTLFLAG_RD, 0, tmpstr, "device_index");
2213 if (softc->sysctl_tree == NULL) {
2214 printf("dasysctlinit: unable to allocate sysctl tree\n");
2215 da_periph_release(periph, DA_REF_SYSCTL);
2220 * Now register the sysctl handler, so the user can change the value on
2223 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2224 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
2225 softc, 0, dadeletemethodsysctl, "A",
2226 "BIO_DELETE execution method");
2227 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2228 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
2229 softc, 0, dadeletemaxsysctl, "Q",
2230 "Maximum BIO_DELETE size");
2231 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2232 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
2233 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
2234 "Minimum CDB size");
2235 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2236 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2237 "trim_count", CTLFLAG_RD, &softc->trim_count,
2238 "Total number of unmap/dsm commands sent");
2239 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2240 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2241 "trim_ranges", CTLFLAG_RD, &softc->trim_ranges,
2242 "Total number of ranges in unmap/dsm commands");
2243 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2244 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2245 "trim_lbas", CTLFLAG_RD, &softc->trim_lbas,
2246 "Total lbas in the unmap/dsm commands sent");
2248 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2249 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
2250 softc, 0, dazonemodesysctl, "A",
2252 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2253 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
2254 softc, 0, dazonesupsysctl, "A",
2256 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2257 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2258 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2259 "Optimal Number of Open Sequential Write Preferred Zones");
2260 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2261 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2262 "optimal_nonseq_zones", CTLFLAG_RD,
2263 &softc->optimal_nonseq_zones,
2264 "Optimal Number of Non-Sequentially Written Sequential Write "
2266 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2267 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2268 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2269 "Maximum Number of Open Sequential Write Required Zones");
2271 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2272 SYSCTL_CHILDREN(softc->sysctl_tree),
2276 &softc->error_inject,
2278 "error_inject leaf");
2280 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2281 SYSCTL_CHILDREN(softc->sysctl_tree),
2287 "Unmapped I/O leaf");
2289 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2290 SYSCTL_CHILDREN(softc->sysctl_tree),
2298 #ifdef CAM_TEST_FAILURE
2299 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2300 OID_AUTO, "invalidate", CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE,
2301 periph, 0, cam_periph_invalidate_sysctl, "I",
2302 "Write 1 to invalidate the drive immediately");
2306 * Add some addressing info.
2308 memset(&cts, 0, sizeof (cts));
2309 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2310 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2311 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2312 cam_periph_lock(periph);
2313 xpt_action((union ccb *)&cts);
2314 cam_periph_unlock(periph);
2315 if (cts.ccb_h.status != CAM_REQ_CMP) {
2316 da_periph_release(periph, DA_REF_SYSCTL);
2319 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2320 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2321 if (fc->valid & CTS_FC_VALID_WWPN) {
2322 softc->wwpn = fc->wwpn;
2323 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2324 SYSCTL_CHILDREN(softc->sysctl_tree),
2325 OID_AUTO, "wwpn", CTLFLAG_RD,
2326 &softc->wwpn, "World Wide Port Name");
2332 * Now add some useful stats.
2333 * XXX These should live in cam_periph and be common to all periphs
2335 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2336 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2337 CTLFLAG_RD, 0, "Statistics");
2338 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2339 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2345 "Transport errors reported by the SIM");
2346 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2347 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2353 "Device timeouts reported by the SIM");
2354 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2355 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2357 "pack_invalidations",
2359 &softc->invalidations,
2361 "Device pack invalidations");
2364 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2365 softc->sysctl_tree);
2367 da_periph_release(periph, DA_REF_SYSCTL);
2371 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2375 struct da_softc *softc;
2377 softc = (struct da_softc *)arg1;
2379 value = softc->disk->d_delmaxsize;
2380 error = sysctl_handle_64(oidp, &value, 0, req);
2381 if ((error != 0) || (req->newptr == NULL))
2384 /* only accept values smaller than the calculated value */
2385 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2388 softc->disk->d_delmaxsize = value;
2394 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2398 value = *(int *)arg1;
2400 error = sysctl_handle_int(oidp, &value, 0, req);
2403 || (req->newptr == NULL))
2407 * Acceptable values here are 6, 10, 12 or 16.
2411 else if ((value > 6)
2414 else if ((value > 10)
2417 else if (value > 12)
2420 *(int *)arg1 = value;
2426 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2431 value = da_default_softtimeout / SBT_1MS;
2433 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2434 if ((error != 0) || (req->newptr == NULL))
2437 /* XXX Should clip this to a reasonable level */
2438 if (value > da_default_timeout * 1000)
2441 da_default_softtimeout = value * SBT_1MS;
2446 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2449 softc->delete_method = delete_method;
2450 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2451 softc->delete_func = da_delete_functions[delete_method];
2453 if (softc->delete_method > DA_DELETE_DISABLE)
2454 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2456 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2460 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2464 switch(delete_method) {
2465 case DA_DELETE_UNMAP:
2466 sectors = (off_t)softc->unmap_max_lba;
2468 case DA_DELETE_ATA_TRIM:
2469 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2471 case DA_DELETE_WS16:
2472 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2474 case DA_DELETE_ZERO:
2475 case DA_DELETE_WS10:
2476 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2482 return (off_t)softc->params.secsize *
2483 omin(sectors, softc->params.sectors);
2487 daprobedone(struct cam_periph *periph, union ccb *ccb)
2489 struct da_softc *softc;
2491 softc = (struct da_softc *)periph->softc;
2493 cam_periph_assert(periph, MA_OWNED);
2495 dadeletemethodchoose(softc, DA_DELETE_NONE);
2497 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2501 snprintf(buf, sizeof(buf), "Delete methods: <");
2503 for (i = 0; i <= DA_DELETE_MAX; i++) {
2504 if ((softc->delete_available & (1 << i)) == 0 &&
2505 i != softc->delete_method)
2508 strlcat(buf, ",", sizeof(buf));
2509 strlcat(buf, da_delete_method_names[i],
2511 if (i == softc->delete_method)
2512 strlcat(buf, "(*)", sizeof(buf));
2515 strlcat(buf, ">", sizeof(buf));
2516 printf("%s%d: %s\n", periph->periph_name,
2517 periph->unit_number, buf);
2519 if ((softc->disk->d_flags & DISKFLAG_WRITE_PROTECT) != 0 &&
2520 (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2521 printf("%s%d: Write Protected\n", periph->periph_name,
2522 periph->unit_number);
2526 * Since our peripheral may be invalidated by an error
2527 * above or an external event, we must release our CCB
2528 * before releasing the probe lock on the peripheral.
2529 * The peripheral will only go away once the last lock
2530 * is removed, and we need it around for the CCB release
2533 xpt_release_ccb(ccb);
2534 softc->state = DA_STATE_NORMAL;
2535 softc->flags |= DA_FLAG_PROBED;
2537 wakeup(&softc->disk->d_mediasize);
2538 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2539 softc->flags |= DA_FLAG_ANNOUNCED;
2540 da_periph_unhold(periph, DA_REF_PROBE_HOLD);
2542 da_periph_release_locked(periph, DA_REF_REPROBE);
2546 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2550 /* If available, prefer the method requested by user. */
2551 i = softc->delete_method_pref;
2552 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2553 if (methods & (1 << i)) {
2554 dadeletemethodset(softc, i);
2558 /* Use the pre-defined order to choose the best performing delete. */
2559 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2560 if (i == DA_DELETE_ZERO)
2562 if (softc->delete_available & (1 << i)) {
2563 dadeletemethodset(softc, i);
2568 /* Fallback to default. */
2569 dadeletemethodset(softc, default_method);
2573 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2577 struct da_softc *softc;
2578 int i, error, value;
2580 softc = (struct da_softc *)arg1;
2582 value = softc->delete_method;
2583 if (value < 0 || value > DA_DELETE_MAX)
2586 p = da_delete_method_names[value];
2587 strncpy(buf, p, sizeof(buf));
2588 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2589 if (error != 0 || req->newptr == NULL)
2591 for (i = 0; i <= DA_DELETE_MAX; i++) {
2592 if (strcmp(buf, da_delete_method_names[i]) == 0)
2595 if (i > DA_DELETE_MAX)
2597 softc->delete_method_pref = i;
2598 dadeletemethodchoose(softc, DA_DELETE_NONE);
2603 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2606 struct da_softc *softc;
2609 softc = (struct da_softc *)arg1;
2611 switch (softc->zone_mode) {
2612 case DA_ZONE_DRIVE_MANAGED:
2613 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2615 case DA_ZONE_HOST_AWARE:
2616 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2618 case DA_ZONE_HOST_MANAGED:
2619 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2623 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2627 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2633 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2636 struct da_softc *softc;
2641 softc = (struct da_softc *)arg1;
2645 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2647 for (i = 0; i < sizeof(da_zone_desc_table) /
2648 sizeof(da_zone_desc_table[0]); i++) {
2649 if (softc->zone_flags & da_zone_desc_table[i].value) {
2651 sbuf_printf(&sb, ", ");
2654 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2659 sbuf_printf(&sb, "None");
2663 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2669 daregister(struct cam_periph *periph, void *arg)
2671 struct da_softc *softc;
2672 struct ccb_pathinq cpi;
2673 struct ccb_getdev *cgd;
2677 cgd = (struct ccb_getdev *)arg;
2679 printf("daregister: no getdev CCB, can't register device\n");
2680 return(CAM_REQ_CMP_ERR);
2683 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2686 if (softc == NULL) {
2687 printf("daregister: Unable to probe new device. "
2688 "Unable to allocate softc\n");
2689 return(CAM_REQ_CMP_ERR);
2692 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2693 printf("daregister: Unable to probe new device. "
2694 "Unable to allocate iosched memory\n");
2695 free(softc, M_DEVBUF);
2696 return(CAM_REQ_CMP_ERR);
2699 LIST_INIT(&softc->pending_ccbs);
2700 softc->state = DA_STATE_PROBE_WP;
2701 bioq_init(&softc->delete_run_queue);
2702 if (SID_IS_REMOVABLE(&cgd->inq_data))
2703 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2704 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2705 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2706 softc->unmap_gran = 0;
2707 softc->unmap_gran_align = 0;
2708 softc->ws_max_blks = WS16_MAX_BLKS;
2709 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2710 softc->rotating = 1;
2712 periph->softc = softc;
2715 * See if this device has any quirks.
2717 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2718 (caddr_t)da_quirk_table,
2719 nitems(da_quirk_table),
2720 sizeof(*da_quirk_table), scsi_inquiry_match);
2723 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2725 softc->quirks = DA_Q_NONE;
2727 /* Check if the SIM does not want 6 byte commands */
2728 xpt_path_inq(&cpi, periph->path);
2729 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2730 softc->quirks |= DA_Q_NO_6_BYTE;
2732 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2733 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2734 else if (softc->quirks & DA_Q_SMR_DM)
2735 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2737 softc->zone_mode = DA_ZONE_NONE;
2739 if (softc->zone_mode != DA_ZONE_NONE) {
2740 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2741 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2742 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2744 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2746 softc->zone_interface = DA_ZONE_IF_SCSI;
2749 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2752 * Take an exclusive section lock qon the periph while dastart is called
2753 * to finish the probe. The lock will be dropped in dadone at the end
2754 * of probe. This locks out daopen and daclose from racing with the
2757 * XXX if cam_periph_hold returns an error, we don't hold a refcount.
2759 (void)da_periph_hold(periph, PRIBIO, DA_REF_PROBE_HOLD);
2762 * Schedule a periodic event to occasionally send an
2763 * ordered tag to a device.
2765 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2766 callout_reset(&softc->sendordered_c,
2767 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2768 dasendorderedtag, periph);
2770 cam_periph_unlock(periph);
2772 * RBC devices don't have to support READ(6), only READ(10).
2774 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2775 softc->minimum_cmd_size = 10;
2777 softc->minimum_cmd_size = 6;
2780 * Load the user's default, if any.
2782 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2783 periph->unit_number);
2784 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2787 * 6, 10, 12 and 16 are the currently permissible values.
2789 if (softc->minimum_cmd_size > 12)
2790 softc->minimum_cmd_size = 16;
2791 else if (softc->minimum_cmd_size > 10)
2792 softc->minimum_cmd_size = 12;
2793 else if (softc->minimum_cmd_size > 6)
2794 softc->minimum_cmd_size = 10;
2796 softc->minimum_cmd_size = 6;
2798 /* Predict whether device may support READ CAPACITY(16). */
2799 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2800 (softc->quirks & DA_Q_NO_RC16) == 0) {
2801 softc->flags |= DA_FLAG_CAN_RC16;
2805 * Register this media as a disk.
2807 softc->disk = disk_alloc();
2808 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2809 periph->unit_number, 0,
2810 DEVSTAT_BS_UNAVAILABLE,
2811 SID_TYPE(&cgd->inq_data) |
2812 XPORT_DEVSTAT_TYPE(cpi.transport),
2813 DEVSTAT_PRIORITY_DISK);
2814 softc->disk->d_open = daopen;
2815 softc->disk->d_close = daclose;
2816 softc->disk->d_strategy = dastrategy;
2817 softc->disk->d_dump = dadump;
2818 softc->disk->d_getattr = dagetattr;
2819 softc->disk->d_gone = dadiskgonecb;
2820 softc->disk->d_name = "da";
2821 softc->disk->d_drv1 = periph;
2823 softc->maxio = DFLTPHYS; /* traditional default */
2824 else if (cpi.maxio > MAXPHYS)
2825 softc->maxio = MAXPHYS; /* for safety */
2827 softc->maxio = cpi.maxio;
2828 softc->disk->d_maxsize = softc->maxio;
2829 softc->disk->d_unit = periph->unit_number;
2830 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2831 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2832 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2833 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2834 softc->unmappedio = 1;
2835 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2837 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2838 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2839 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2840 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2841 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2842 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2843 softc->disk->d_hba_vendor = cpi.hba_vendor;
2844 softc->disk->d_hba_device = cpi.hba_device;
2845 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2846 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2849 * Acquire a reference to the periph before we register with GEOM.
2850 * We'll release this reference once GEOM calls us back (via
2851 * dadiskgonecb()) telling us that our provider has been freed.
2853 if (da_periph_acquire(periph, DA_REF_GEOM) != 0) {
2854 xpt_print(periph->path, "%s: lost periph during "
2855 "registration!\n", __func__);
2856 cam_periph_lock(periph);
2857 return (CAM_REQ_CMP_ERR);
2860 disk_create(softc->disk, DISK_VERSION);
2861 cam_periph_lock(periph);
2864 * Add async callbacks for events of interest.
2865 * I don't bother checking if this fails as,
2866 * in most cases, the system will function just
2867 * fine without them and the only alternative
2868 * would be to not attach the device on failure.
2870 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2871 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2872 AC_INQ_CHANGED, daasync, periph, periph->path);
2875 * Emit an attribute changed notification just in case
2876 * physical path information arrived before our async
2877 * event handler was registered, but after anyone attaching
2878 * to our disk device polled it.
2880 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2883 * Schedule a periodic media polling events.
2885 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2886 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2887 (cgd->inq_flags & SID_AEN) == 0 &&
2888 da_poll_period != 0)
2889 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2890 damediapoll, periph);
2892 xpt_schedule(periph, CAM_PRIORITY_DEV);
2894 return(CAM_REQ_CMP);
2898 da_zone_bio_to_scsi(int disk_zone_cmd)
2900 switch (disk_zone_cmd) {
2901 case DISK_ZONE_OPEN:
2902 return ZBC_OUT_SA_OPEN;
2903 case DISK_ZONE_CLOSE:
2904 return ZBC_OUT_SA_CLOSE;
2905 case DISK_ZONE_FINISH:
2906 return ZBC_OUT_SA_FINISH;
2908 return ZBC_OUT_SA_RWP;
2915 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2918 struct da_softc *softc;
2923 if (bp->bio_cmd != BIO_ZONE) {
2928 softc = periph->softc;
2930 switch (bp->bio_zone.zone_cmd) {
2931 case DISK_ZONE_OPEN:
2932 case DISK_ZONE_CLOSE:
2933 case DISK_ZONE_FINISH:
2934 case DISK_ZONE_RWP: {
2939 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2940 if (zone_sa == -1) {
2941 xpt_print(periph->path, "Cannot translate zone "
2942 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2948 lba = bp->bio_zone.zone_params.rwp.id;
2950 if (bp->bio_zone.zone_params.rwp.flags &
2951 DISK_ZONE_RWP_FLAG_ALL)
2952 zone_flags |= ZBC_OUT_ALL;
2954 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2955 scsi_zbc_out(&ccb->csio,
2956 /*retries*/ da_retry_count,
2958 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2959 /*service_action*/ zone_sa,
2961 /*zone_flags*/ zone_flags,
2964 /*sense_len*/ SSD_FULL_SIZE,
2965 /*timeout*/ da_default_timeout * 1000);
2968 * Note that in this case, even though we can
2969 * technically use NCQ, we don't bother for several
2971 * 1. It hasn't been tested on a SAT layer that
2972 * supports it. This is new as of SAT-4.
2973 * 2. Even when there is a SAT layer that supports
2974 * it, that SAT layer will also probably support
2975 * ZBC -> ZAC translation, since they are both
2976 * in the SAT-4 spec.
2977 * 3. Translation will likely be preferable to ATA
2978 * passthrough. LSI / Avago at least single
2979 * steps ATA passthrough commands in the HBA,
2980 * regardless of protocol, so unless that
2981 * changes, there is a performance penalty for
2982 * doing ATA passthrough no matter whether
2983 * you're using NCQ/FPDMA, DMA or PIO.
2984 * 4. It requires a 32-byte CDB, which at least at
2985 * this point in CAM requires a CDB pointer, which
2986 * would require us to allocate an additional bit
2987 * of storage separate from the CCB.
2989 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2990 /*retries*/ da_retry_count,
2992 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2994 /*zm_action*/ zone_sa,
2996 /*zone_flags*/ zone_flags,
2999 /*cdb_storage*/ NULL,
3000 /*cdb_storage_len*/ 0,
3001 /*sense_len*/ SSD_FULL_SIZE,
3002 /*timeout*/ da_default_timeout * 1000);
3005 xpt_print(periph->path,
3006 "scsi_ata_zac_mgmt_out() returned an "
3015 case DISK_ZONE_REPORT_ZONES: {
3017 uint32_t num_entries, alloc_size;
3018 struct disk_zone_report *rep;
3020 rep = &bp->bio_zone.zone_params.report;
3022 num_entries = rep->entries_allocated;
3023 if (num_entries == 0) {
3024 xpt_print(periph->path, "No entries allocated for "
3025 "Report Zones request\n");
3029 alloc_size = sizeof(struct scsi_report_zones_hdr) +
3030 (sizeof(struct scsi_report_zones_desc) * num_entries);
3031 alloc_size = min(alloc_size, softc->disk->d_maxsize);
3032 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
3033 if (rz_ptr == NULL) {
3034 xpt_print(periph->path, "Unable to allocate memory "
3035 "for Report Zones request\n");
3040 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
3041 scsi_zbc_in(&ccb->csio,
3042 /*retries*/ da_retry_count,
3044 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3045 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
3046 /*zone_start_lba*/ rep->starting_id,
3047 /*zone_options*/ rep->rep_options,
3048 /*data_ptr*/ rz_ptr,
3049 /*dxfer_len*/ alloc_size,
3050 /*sense_len*/ SSD_FULL_SIZE,
3051 /*timeout*/ da_default_timeout * 1000);
3054 * Note that in this case, even though we can
3055 * technically use NCQ, we don't bother for several
3057 * 1. It hasn't been tested on a SAT layer that
3058 * supports it. This is new as of SAT-4.
3059 * 2. Even when there is a SAT layer that supports
3060 * it, that SAT layer will also probably support
3061 * ZBC -> ZAC translation, since they are both
3062 * in the SAT-4 spec.
3063 * 3. Translation will likely be preferable to ATA
3064 * passthrough. LSI / Avago at least single
3065 * steps ATA passthrough commands in the HBA,
3066 * regardless of protocol, so unless that
3067 * changes, there is a performance penalty for
3068 * doing ATA passthrough no matter whether
3069 * you're using NCQ/FPDMA, DMA or PIO.
3070 * 4. It requires a 32-byte CDB, which at least at
3071 * this point in CAM requires a CDB pointer, which
3072 * would require us to allocate an additional bit
3073 * of storage separate from the CCB.
3075 error = scsi_ata_zac_mgmt_in(&ccb->csio,
3076 /*retries*/ da_retry_count,
3078 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3080 /*zm_action*/ ATA_ZM_REPORT_ZONES,
3081 /*zone_id*/ rep->starting_id,
3082 /*zone_flags*/ rep->rep_options,
3083 /*data_ptr*/ rz_ptr,
3084 /*dxfer_len*/ alloc_size,
3085 /*cdb_storage*/ NULL,
3086 /*cdb_storage_len*/ 0,
3087 /*sense_len*/ SSD_FULL_SIZE,
3088 /*timeout*/ da_default_timeout * 1000);
3091 xpt_print(periph->path,
3092 "scsi_ata_zac_mgmt_in() returned an "
3099 * For BIO_ZONE, this isn't normally needed. However, it
3100 * is used by devstat_end_transaction_bio() to determine
3101 * how much data was transferred.
3104 * XXX KDM we have a problem. But I'm not sure how to fix
3105 * it. devstat uses bio_bcount - bio_resid to calculate
3106 * the amount of data transferred. The GEOM disk code
3107 * uses bio_length - bio_resid to calculate the amount of
3108 * data in bio_completed. We have different structure
3109 * sizes above and below the ada(4) driver. So, if we
3110 * use the sizes above, the amount transferred won't be
3111 * quite accurate for devstat. If we use different sizes
3112 * for bio_bcount and bio_length (above and below
3113 * respectively), then the residual needs to match one or
3114 * the other. Everything is calculated after the bio
3115 * leaves the driver, so changing the values around isn't
3116 * really an option. For now, just set the count to the
3117 * passed in length. This means that the calculations
3118 * above (e.g. bio_completed) will be correct, but the
3119 * amount of data reported to devstat will be slightly
3120 * under or overstated.
3122 bp->bio_bcount = bp->bio_length;
3128 case DISK_ZONE_GET_PARAMS: {
3129 struct disk_zone_disk_params *params;
3131 params = &bp->bio_zone.zone_params.disk_params;
3132 bzero(params, sizeof(*params));
3134 switch (softc->zone_mode) {
3135 case DA_ZONE_DRIVE_MANAGED:
3136 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
3138 case DA_ZONE_HOST_AWARE:
3139 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
3141 case DA_ZONE_HOST_MANAGED:
3142 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
3146 params->zone_mode = DISK_ZONE_MODE_NONE;
3150 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
3151 params->flags |= DISK_ZONE_DISK_URSWRZ;
3153 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
3154 params->optimal_seq_zones = softc->optimal_seq_zones;
3155 params->flags |= DISK_ZONE_OPT_SEQ_SET;
3158 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
3159 params->optimal_nonseq_zones =
3160 softc->optimal_nonseq_zones;
3161 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
3164 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
3165 params->max_seq_zones = softc->max_seq_zones;
3166 params->flags |= DISK_ZONE_MAX_SEQ_SET;
3168 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
3169 params->flags |= DISK_ZONE_RZ_SUP;
3171 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
3172 params->flags |= DISK_ZONE_OPEN_SUP;
3174 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
3175 params->flags |= DISK_ZONE_CLOSE_SUP;
3177 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
3178 params->flags |= DISK_ZONE_FINISH_SUP;
3180 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
3181 params->flags |= DISK_ZONE_RWP_SUP;
3192 dastart(struct cam_periph *periph, union ccb *start_ccb)
3194 struct da_softc *softc;
3196 cam_periph_assert(periph, MA_OWNED);
3197 softc = (struct da_softc *)periph->softc;
3199 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
3202 switch (softc->state) {
3203 case DA_STATE_NORMAL:
3209 bp = cam_iosched_next_bio(softc->cam_iosched);
3211 if (cam_iosched_has_work_flags(softc->cam_iosched,
3213 softc->flags |= DA_FLAG_TUR_PENDING;
3214 cam_iosched_clr_work_flags(softc->cam_iosched,
3216 scsi_test_unit_ready(&start_ccb->csio,
3217 /*retries*/ da_retry_count,
3221 da_default_timeout * 1000);
3222 start_ccb->ccb_h.ccb_bp = NULL;
3223 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
3224 xpt_action(start_ccb);
3226 xpt_release_ccb(start_ccb);
3230 if (bp->bio_cmd == BIO_DELETE) {
3231 if (softc->delete_func != NULL) {
3232 softc->delete_func(periph, start_ccb, bp);
3236 * Not sure this is possible, but failsafe by
3237 * lying and saying "sure, done."
3239 biofinish(bp, NULL, 0);
3244 if (cam_iosched_has_work_flags(softc->cam_iosched,
3246 cam_iosched_clr_work_flags(softc->cam_iosched,
3248 da_periph_release_locked(periph, DA_REF_TUR);
3251 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
3252 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
3253 softc->flags &= ~DA_FLAG_NEED_OTAG;
3254 softc->flags |= DA_FLAG_WAS_OTAG;
3255 tag_code = MSG_ORDERED_Q_TAG;
3257 tag_code = MSG_SIMPLE_Q_TAG;
3260 switch (bp->bio_cmd) {
3267 biotrack(bp, __func__);
3269 if (bp->bio_cmd == BIO_WRITE) {
3270 softc->flags |= DA_FLAG_DIRTY;
3271 rw_op = SCSI_RW_WRITE;
3273 rw_op = SCSI_RW_READ;
3276 data_ptr = bp->bio_data;
3277 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
3278 rw_op |= SCSI_RW_BIO;
3282 scsi_read_write(&start_ccb->csio,
3283 /*retries*/da_retry_count,
3285 /*tag_action*/tag_code,
3288 softc->minimum_cmd_size,
3289 /*lba*/bp->bio_pblkno,
3290 /*block_count*/bp->bio_bcount /
3291 softc->params.secsize,
3293 /*dxfer_len*/ bp->bio_bcount,
3294 /*sense_len*/SSD_FULL_SIZE,
3295 da_default_timeout * 1000);
3296 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3297 start_ccb->csio.bio = bp;
3303 * If we don't support sync cache, or the disk
3304 * isn't dirty, FLUSH is a no-op. Use the
3305 * allocated CCB for the next bio if one is
3308 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) != 0 ||
3309 (softc->flags & DA_FLAG_DIRTY) == 0) {
3315 * BIO_FLUSH doesn't currently communicate
3316 * range data, so we synchronize the cache
3317 * over the whole disk.
3319 scsi_synchronize_cache(&start_ccb->csio,
3322 /*tag_action*/tag_code,
3326 da_default_timeout*1000);
3328 * Clear the dirty flag before sending the command.
3329 * Either this sync cache will be successful, or it
3330 * will fail after a retry. If it fails, it is
3331 * unlikely to be successful if retried later, so
3332 * we'll save ourselves time by just marking the
3335 softc->flags &= ~DA_FLAG_DIRTY;
3338 int error, queue_ccb;
3342 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3344 || (queue_ccb == 0)) {
3345 biofinish(bp, NULL, error);
3346 xpt_release_ccb(start_ccb);
3352 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3353 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3354 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3357 LIST_INSERT_HEAD(&softc->pending_ccbs,
3358 &start_ccb->ccb_h, periph_links.le);
3360 /* We expect a unit attention from this device */
3361 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3362 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3363 softc->flags &= ~DA_FLAG_RETRY_UA;
3366 start_ccb->ccb_h.ccb_bp = bp;
3368 cam_periph_unlock(periph);
3369 xpt_action(start_ccb);
3370 cam_periph_lock(periph);
3372 /* May have more work to do, so ensure we stay scheduled */
3376 case DA_STATE_PROBE_WP:
3381 if (da_disable_wp_detection) {
3382 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3383 softc->state = DA_STATE_PROBE_RC16;
3385 softc->state = DA_STATE_PROBE_RC;
3389 mode_buf = malloc(mode_buf_len, M_SCSIDA, M_NOWAIT);
3390 if (mode_buf == NULL) {
3391 xpt_print(periph->path, "Unable to send mode sense - "
3392 "malloc failure\n");
3393 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3394 softc->state = DA_STATE_PROBE_RC16;
3396 softc->state = DA_STATE_PROBE_RC;
3399 scsi_mode_sense_len(&start_ccb->csio,
3400 /*retries*/ da_retry_count,
3401 /*cbfcnp*/ dadone_probewp,
3402 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3404 /*pc*/ SMS_PAGE_CTRL_CURRENT,
3405 /*page*/ SMS_ALL_PAGES_PAGE,
3406 /*param_buf*/ mode_buf,
3407 /*param_len*/ mode_buf_len,
3408 /*minimum_cmd_size*/ softc->minimum_cmd_size,
3409 /*sense_len*/ SSD_FULL_SIZE,
3410 /*timeout*/ da_default_timeout * 1000);
3411 start_ccb->ccb_h.ccb_bp = NULL;
3412 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_WP;
3413 xpt_action(start_ccb);
3416 case DA_STATE_PROBE_RC:
3418 struct scsi_read_capacity_data *rcap;
3420 rcap = (struct scsi_read_capacity_data *)
3421 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3423 printf("dastart: Couldn't malloc read_capacity data\n");
3424 /* da_free_periph??? */
3427 scsi_read_capacity(&start_ccb->csio,
3428 /*retries*/da_retry_count,
3434 start_ccb->ccb_h.ccb_bp = NULL;
3435 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3436 xpt_action(start_ccb);
3439 case DA_STATE_PROBE_RC16:
3441 struct scsi_read_capacity_data_long *rcaplong;
3443 rcaplong = (struct scsi_read_capacity_data_long *)
3444 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3445 if (rcaplong == NULL) {
3446 printf("dastart: Couldn't malloc read_capacity data\n");
3447 /* da_free_periph??? */
3450 scsi_read_capacity_16(&start_ccb->csio,
3451 /*retries*/ da_retry_count,
3452 /*cbfcnp*/ dadone_proberc,
3453 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3457 /*rcap_buf*/ (uint8_t *)rcaplong,
3458 /*rcap_buf_len*/ sizeof(*rcaplong),
3459 /*sense_len*/ SSD_FULL_SIZE,
3460 /*timeout*/ da_default_timeout * 1000);
3461 start_ccb->ccb_h.ccb_bp = NULL;
3462 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3463 xpt_action(start_ccb);
3466 case DA_STATE_PROBE_LBP:
3468 struct scsi_vpd_logical_block_prov *lbp;
3470 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3472 * If we get here we don't support any SBC-3 delete
3473 * methods with UNMAP as the Logical Block Provisioning
3474 * VPD page support is required for devices which
3475 * support it according to T10/1799-D Revision 31
3476 * however older revisions of the spec don't mandate
3477 * this so we currently don't remove these methods
3478 * from the available set.
3480 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3484 lbp = (struct scsi_vpd_logical_block_prov *)
3485 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3488 printf("dastart: Couldn't malloc lbp data\n");
3489 /* da_free_periph??? */
3493 scsi_inquiry(&start_ccb->csio,
3494 /*retries*/da_retry_count,
3495 /*cbfcnp*/dadone_probelbp,
3496 /*tag_action*/MSG_SIMPLE_Q_TAG,
3497 /*inq_buf*/(u_int8_t *)lbp,
3498 /*inq_len*/sizeof(*lbp),
3500 /*page_code*/SVPD_LBP,
3501 /*sense_len*/SSD_MIN_SIZE,
3502 /*timeout*/da_default_timeout * 1000);
3503 start_ccb->ccb_h.ccb_bp = NULL;
3504 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3505 xpt_action(start_ccb);
3508 case DA_STATE_PROBE_BLK_LIMITS:
3510 struct scsi_vpd_block_limits *block_limits;
3512 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3513 /* Not supported skip to next probe */
3514 softc->state = DA_STATE_PROBE_BDC;
3518 block_limits = (struct scsi_vpd_block_limits *)
3519 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3521 if (block_limits == NULL) {
3522 printf("dastart: Couldn't malloc block_limits data\n");
3523 /* da_free_periph??? */
3527 scsi_inquiry(&start_ccb->csio,
3528 /*retries*/da_retry_count,
3529 /*cbfcnp*/dadone_probeblklimits,
3530 /*tag_action*/MSG_SIMPLE_Q_TAG,
3531 /*inq_buf*/(u_int8_t *)block_limits,
3532 /*inq_len*/sizeof(*block_limits),
3534 /*page_code*/SVPD_BLOCK_LIMITS,
3535 /*sense_len*/SSD_MIN_SIZE,
3536 /*timeout*/da_default_timeout * 1000);
3537 start_ccb->ccb_h.ccb_bp = NULL;
3538 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3539 xpt_action(start_ccb);
3542 case DA_STATE_PROBE_BDC:
3544 struct scsi_vpd_block_characteristics *bdc;
3546 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3547 softc->state = DA_STATE_PROBE_ATA;
3551 bdc = (struct scsi_vpd_block_characteristics *)
3552 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3555 printf("dastart: Couldn't malloc bdc data\n");
3556 /* da_free_periph??? */
3560 scsi_inquiry(&start_ccb->csio,
3561 /*retries*/da_retry_count,
3562 /*cbfcnp*/dadone_probebdc,
3563 /*tag_action*/MSG_SIMPLE_Q_TAG,
3564 /*inq_buf*/(u_int8_t *)bdc,
3565 /*inq_len*/sizeof(*bdc),
3567 /*page_code*/SVPD_BDC,
3568 /*sense_len*/SSD_MIN_SIZE,
3569 /*timeout*/da_default_timeout * 1000);
3570 start_ccb->ccb_h.ccb_bp = NULL;
3571 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3572 xpt_action(start_ccb);
3575 case DA_STATE_PROBE_ATA:
3577 struct ata_params *ata_params;
3579 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3580 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3581 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3583 * Note that if the ATA VPD page isn't
3584 * supported, we aren't talking to an ATA
3585 * device anyway. Support for that VPD
3586 * page is mandatory for SCSI to ATA (SAT)
3587 * translation layers.
3589 softc->state = DA_STATE_PROBE_ZONE;
3592 daprobedone(periph, start_ccb);
3596 ata_params = (struct ata_params*)
3597 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3599 if (ata_params == NULL) {
3600 xpt_print(periph->path, "Couldn't malloc ata_params "
3602 /* da_free_periph??? */
3606 scsi_ata_identify(&start_ccb->csio,
3607 /*retries*/da_retry_count,
3608 /*cbfcnp*/dadone_probeata,
3609 /*tag_action*/MSG_SIMPLE_Q_TAG,
3610 /*data_ptr*/(u_int8_t *)ata_params,
3611 /*dxfer_len*/sizeof(*ata_params),
3612 /*sense_len*/SSD_FULL_SIZE,
3613 /*timeout*/da_default_timeout * 1000);
3614 start_ccb->ccb_h.ccb_bp = NULL;
3615 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3616 xpt_action(start_ccb);
3619 case DA_STATE_PROBE_ATA_LOGDIR:
3621 struct ata_gp_log_dir *log_dir;
3626 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3628 * If we don't have log support, not much point in
3629 * trying to probe zone support.
3631 daprobedone(periph, start_ccb);
3636 * If we have an ATA device (the SCSI ATA Information VPD
3637 * page should be present and the ATA identify should have
3638 * succeeded) and it supports logs, ask for the log directory.
3641 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3642 if (log_dir == NULL) {
3643 xpt_print(periph->path, "Couldn't malloc log_dir "
3645 daprobedone(periph, start_ccb);
3649 retval = scsi_ata_read_log(&start_ccb->csio,
3650 /*retries*/ da_retry_count,
3651 /*cbfcnp*/ dadone_probeatalogdir,
3652 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3653 /*log_address*/ ATA_LOG_DIRECTORY,
3656 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3657 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3658 /*data_ptr*/ (uint8_t *)log_dir,
3659 /*dxfer_len*/ sizeof(*log_dir),
3660 /*sense_len*/ SSD_FULL_SIZE,
3661 /*timeout*/ da_default_timeout * 1000);
3664 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3665 free(log_dir, M_SCSIDA);
3666 daprobedone(periph, start_ccb);
3669 start_ccb->ccb_h.ccb_bp = NULL;
3670 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3671 xpt_action(start_ccb);
3674 case DA_STATE_PROBE_ATA_IDDIR:
3676 struct ata_identify_log_pages *id_dir;
3682 * Check here to see whether the Identify Device log is
3683 * supported in the directory of logs. If so, continue
3684 * with requesting the log of identify device pages.
3686 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3687 daprobedone(periph, start_ccb);
3691 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3692 if (id_dir == NULL) {
3693 xpt_print(periph->path, "Couldn't malloc id_dir "
3695 daprobedone(periph, start_ccb);
3699 retval = scsi_ata_read_log(&start_ccb->csio,
3700 /*retries*/ da_retry_count,
3701 /*cbfcnp*/ dadone_probeataiddir,
3702 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3703 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3704 /*page_number*/ ATA_IDL_PAGE_LIST,
3706 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3707 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3708 /*data_ptr*/ (uint8_t *)id_dir,
3709 /*dxfer_len*/ sizeof(*id_dir),
3710 /*sense_len*/ SSD_FULL_SIZE,
3711 /*timeout*/ da_default_timeout * 1000);
3714 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3715 free(id_dir, M_SCSIDA);
3716 daprobedone(periph, start_ccb);
3719 start_ccb->ccb_h.ccb_bp = NULL;
3720 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3721 xpt_action(start_ccb);
3724 case DA_STATE_PROBE_ATA_SUP:
3726 struct ata_identify_log_sup_cap *sup_cap;
3732 * Check here to see whether the Supported Capabilities log
3733 * is in the list of Identify Device logs.
3735 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3736 daprobedone(periph, start_ccb);
3740 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3741 if (sup_cap == NULL) {
3742 xpt_print(periph->path, "Couldn't malloc sup_cap "
3744 daprobedone(periph, start_ccb);
3748 retval = scsi_ata_read_log(&start_ccb->csio,
3749 /*retries*/ da_retry_count,
3750 /*cbfcnp*/ dadone_probeatasup,
3751 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3752 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3753 /*page_number*/ ATA_IDL_SUP_CAP,
3755 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3756 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3757 /*data_ptr*/ (uint8_t *)sup_cap,
3758 /*dxfer_len*/ sizeof(*sup_cap),
3759 /*sense_len*/ SSD_FULL_SIZE,
3760 /*timeout*/ da_default_timeout * 1000);
3763 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3764 free(sup_cap, M_SCSIDA);
3765 daprobedone(periph, start_ccb);
3770 start_ccb->ccb_h.ccb_bp = NULL;
3771 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3772 xpt_action(start_ccb);
3775 case DA_STATE_PROBE_ATA_ZONE:
3777 struct ata_zoned_info_log *ata_zone;
3783 * Check here to see whether the zoned device information
3784 * page is supported. If so, continue on to request it.
3785 * If not, skip to DA_STATE_PROBE_LOG or done.
3787 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3788 daprobedone(periph, start_ccb);
3791 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3793 if (ata_zone == NULL) {
3794 xpt_print(periph->path, "Couldn't malloc ata_zone "
3796 daprobedone(periph, start_ccb);
3800 retval = scsi_ata_read_log(&start_ccb->csio,
3801 /*retries*/ da_retry_count,
3802 /*cbfcnp*/ dadone_probeatazone,
3803 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3804 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3805 /*page_number*/ ATA_IDL_ZDI,
3807 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3808 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3809 /*data_ptr*/ (uint8_t *)ata_zone,
3810 /*dxfer_len*/ sizeof(*ata_zone),
3811 /*sense_len*/ SSD_FULL_SIZE,
3812 /*timeout*/ da_default_timeout * 1000);
3815 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3816 free(ata_zone, M_SCSIDA);
3817 daprobedone(periph, start_ccb);
3820 start_ccb->ccb_h.ccb_bp = NULL;
3821 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3822 xpt_action(start_ccb);
3826 case DA_STATE_PROBE_ZONE:
3828 struct scsi_vpd_zoned_bdc *bdc;
3831 * Note that this page will be supported for SCSI protocol
3832 * devices that support ZBC (SMR devices), as well as ATA
3833 * protocol devices that are behind a SAT (SCSI to ATA
3834 * Translation) layer that supports converting ZBC commands
3835 * to their ZAC equivalents.
3837 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3838 daprobedone(periph, start_ccb);
3841 bdc = (struct scsi_vpd_zoned_bdc *)
3842 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3845 xpt_release_ccb(start_ccb);
3846 xpt_print(periph->path, "Couldn't malloc zone VPD "
3850 scsi_inquiry(&start_ccb->csio,
3851 /*retries*/da_retry_count,
3852 /*cbfcnp*/dadone_probezone,
3853 /*tag_action*/MSG_SIMPLE_Q_TAG,
3854 /*inq_buf*/(u_int8_t *)bdc,
3855 /*inq_len*/sizeof(*bdc),
3857 /*page_code*/SVPD_ZONED_BDC,
3858 /*sense_len*/SSD_FULL_SIZE,
3859 /*timeout*/da_default_timeout * 1000);
3860 start_ccb->ccb_h.ccb_bp = NULL;
3861 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3862 xpt_action(start_ccb);
3869 * In each of the methods below, while its the caller's
3870 * responsibility to ensure the request will fit into a
3871 * single device request, we might have changed the delete
3872 * method due to the device incorrectly advertising either
3873 * its supported methods or limits.
3875 * To prevent this causing further issues we validate the
3876 * against the methods limits, and warn which would
3877 * otherwise be unnecessary.
3880 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3882 struct da_softc *softc = (struct da_softc *)periph->softc;;
3884 uint8_t *buf = softc->unmap_buf;
3885 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3886 uint64_t lba, lastlba = (uint64_t)-1;
3887 uint64_t totalcount = 0;
3889 uint32_t c, lastcount = 0, ranges = 0;
3892 * Currently this doesn't take the UNMAP
3893 * Granularity and Granularity Alignment
3894 * fields into account.
3896 * This could result in both unoptimal unmap
3897 * requests as as well as UNMAP calls unmapping
3898 * fewer LBA's than requested.
3901 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3905 * Note: ada and da are different in how they store the
3906 * pending bp's in a trim. ada stores all of them in the
3907 * trim_req.bps. da stores all but the first one in the
3908 * delete_run_queue. ada then completes all the bps in
3909 * its adadone() loop. da completes all the bps in the
3910 * delete_run_queue in dadone, and relies on the biodone
3911 * after to complete. This should be reconciled since there's
3912 * no real reason to do it differently. XXX
3915 bioq_insert_tail(&softc->delete_run_queue, bp1);
3916 lba = bp1->bio_pblkno;
3917 count = bp1->bio_bcount / softc->params.secsize;
3919 /* Try to extend the previous range. */
3920 if (lba == lastlba) {
3921 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3924 scsi_ulto4b(lastcount, d[ranges - 1].length);
3928 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3929 softc->unmap_gran != 0) {
3930 /* Align length of the previous range. */
3931 if ((c = lastcount % softc->unmap_gran) != 0) {
3932 if (lastcount <= c) {
3933 totalcount -= lastcount;
3934 lastlba = (uint64_t)-1;
3941 scsi_ulto4b(lastcount,
3942 d[ranges - 1].length);
3945 /* Align beginning of the new range. */
3946 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3948 c = softc->unmap_gran - c;
3959 c = omin(count, UNMAP_RANGE_MAX);
3960 if (totalcount + c > softc->unmap_max_lba ||
3961 ranges >= softc->unmap_max_ranges) {
3962 xpt_print(periph->path,
3963 "%s issuing short delete %ld > %ld"
3965 da_delete_method_desc[softc->delete_method],
3966 totalcount + c, softc->unmap_max_lba,
3967 ranges, softc->unmap_max_ranges);
3970 scsi_u64to8b(lba, d[ranges].lba);
3971 scsi_ulto4b(c, d[ranges].length);
3979 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3982 if (ranges >= softc->unmap_max_ranges ||
3983 totalcount + bp1->bio_bcount /
3984 softc->params.secsize > softc->unmap_max_lba) {
3985 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3990 /* Align length of the last range. */
3991 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
3992 (c = lastcount % softc->unmap_gran) != 0) {
3996 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
3999 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
4000 scsi_ulto2b(ranges * 16, &buf[2]);
4002 scsi_unmap(&ccb->csio,
4003 /*retries*/da_retry_count,
4005 /*tag_action*/MSG_SIMPLE_Q_TAG,
4008 /*dxfer_len*/ ranges * 16 + 8,
4009 /*sense_len*/SSD_FULL_SIZE,
4010 da_default_timeout * 1000);
4011 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4012 ccb->ccb_h.flags |= CAM_UNLOCKED;
4013 softc->trim_count++;
4014 softc->trim_ranges += ranges;
4015 softc->trim_lbas += totalcount;
4016 cam_iosched_submit_trim(softc->cam_iosched);
4020 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4022 struct da_softc *softc = (struct da_softc *)periph->softc;
4024 uint8_t *buf = softc->unmap_buf;
4025 uint64_t lastlba = (uint64_t)-1;
4028 uint32_t lastcount = 0, c, requestcount;
4029 int ranges = 0, off, block_count;
4031 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
4034 if (bp1 != bp)//XXX imp XXX
4035 bioq_insert_tail(&softc->delete_run_queue, bp1);
4036 lba = bp1->bio_pblkno;
4037 count = bp1->bio_bcount / softc->params.secsize;
4038 requestcount = count;
4040 /* Try to extend the previous range. */
4041 if (lba == lastlba) {
4042 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
4044 off = (ranges - 1) * 8;
4045 buf[off + 6] = lastcount & 0xff;
4046 buf[off + 7] = (lastcount >> 8) & 0xff;
4052 c = omin(count, ATA_DSM_RANGE_MAX);
4055 buf[off + 0] = lba & 0xff;
4056 buf[off + 1] = (lba >> 8) & 0xff;
4057 buf[off + 2] = (lba >> 16) & 0xff;
4058 buf[off + 3] = (lba >> 24) & 0xff;
4059 buf[off + 4] = (lba >> 32) & 0xff;
4060 buf[off + 5] = (lba >> 40) & 0xff;
4061 buf[off + 6] = c & 0xff;
4062 buf[off + 7] = (c >> 8) & 0xff;
4067 if (count != 0 && ranges == softc->trim_max_ranges) {
4068 xpt_print(periph->path,
4069 "%s issuing short delete %ld > %ld\n",
4070 da_delete_method_desc[softc->delete_method],
4072 (softc->trim_max_ranges - ranges) *
4078 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4081 if (bp1->bio_bcount / softc->params.secsize >
4082 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
4083 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4088 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
4089 scsi_ata_trim(&ccb->csio,
4090 /*retries*/da_retry_count,
4092 /*tag_action*/MSG_SIMPLE_Q_TAG,
4095 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
4096 /*sense_len*/SSD_FULL_SIZE,
4097 da_default_timeout * 1000);
4098 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4099 ccb->ccb_h.flags |= CAM_UNLOCKED;
4100 cam_iosched_submit_trim(softc->cam_iosched);
4104 * We calculate ws_max_blks here based off d_delmaxsize instead
4105 * of using softc->ws_max_blks as it is absolute max for the
4106 * device not the protocol max which may well be lower.
4109 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4111 struct da_softc *softc;
4113 uint64_t ws_max_blks;
4115 uint64_t count; /* forward compat with WS32 */
4117 softc = (struct da_softc *)periph->softc;
4118 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
4119 lba = bp->bio_pblkno;
4123 if (bp1 != bp)//XXX imp XXX
4124 bioq_insert_tail(&softc->delete_run_queue, bp1);
4125 count += bp1->bio_bcount / softc->params.secsize;
4126 if (count > ws_max_blks) {
4127 xpt_print(periph->path,
4128 "%s issuing short delete %ld > %ld\n",
4129 da_delete_method_desc[softc->delete_method],
4130 count, ws_max_blks);
4131 count = omin(count, ws_max_blks);
4134 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4137 if (lba + count != bp1->bio_pblkno ||
4138 count + bp1->bio_bcount /
4139 softc->params.secsize > ws_max_blks) {
4140 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4145 scsi_write_same(&ccb->csio,
4146 /*retries*/da_retry_count,
4148 /*tag_action*/MSG_SIMPLE_Q_TAG,
4149 /*byte2*/softc->delete_method ==
4150 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
4151 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
4153 /*block_count*/count,
4154 /*data_ptr*/ __DECONST(void *, zero_region),
4155 /*dxfer_len*/ softc->params.secsize,
4156 /*sense_len*/SSD_FULL_SIZE,
4157 da_default_timeout * 1000);
4158 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4159 ccb->ccb_h.flags |= CAM_UNLOCKED;
4160 cam_iosched_submit_trim(softc->cam_iosched);
4164 cmd6workaround(union ccb *ccb)
4166 struct scsi_rw_6 cmd6;
4167 struct scsi_rw_10 *cmd10;
4168 struct da_softc *softc;
4173 cdb = ccb->csio.cdb_io.cdb_bytes;
4174 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
4176 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
4177 da_delete_methods old_method = softc->delete_method;
4180 * Typically there are two reasons for failure here
4181 * 1. Delete method was detected as supported but isn't
4182 * 2. Delete failed due to invalid params e.g. too big
4184 * While we will attempt to choose an alternative delete method
4185 * this may result in short deletes if the existing delete
4186 * requests from geom are big for the new method chosen.
4188 * This method assumes that the error which triggered this
4189 * will not retry the io otherwise a panic will occur
4191 dadeleteflag(softc, old_method, 0);
4192 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
4193 if (softc->delete_method == DA_DELETE_DISABLE)
4194 xpt_print(ccb->ccb_h.path,
4195 "%s failed, disabling BIO_DELETE\n",
4196 da_delete_method_desc[old_method]);
4198 xpt_print(ccb->ccb_h.path,
4199 "%s failed, switching to %s BIO_DELETE\n",
4200 da_delete_method_desc[old_method],
4201 da_delete_method_desc[softc->delete_method]);
4203 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
4204 cam_iosched_queue_work(softc->cam_iosched, bp);
4205 cam_iosched_queue_work(softc->cam_iosched,
4206 (struct bio *)ccb->ccb_h.ccb_bp);
4207 ccb->ccb_h.ccb_bp = NULL;
4211 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
4212 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4213 (*cdb == PREVENT_ALLOW) &&
4214 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
4216 xpt_print(ccb->ccb_h.path,
4217 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
4218 softc->quirks |= DA_Q_NO_PREVENT;
4222 /* Detect unsupported SYNCHRONIZE CACHE(10). */
4223 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4224 (*cdb == SYNCHRONIZE_CACHE) &&
4225 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
4227 xpt_print(ccb->ccb_h.path,
4228 "SYNCHRONIZE CACHE(10) not supported.\n");
4229 softc->quirks |= DA_Q_NO_SYNC_CACHE;
4230 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
4234 /* Translation only possible if CDB is an array and cmd is R/W6 */
4235 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
4236 (*cdb != READ_6 && *cdb != WRITE_6))
4239 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
4240 "increasing minimum_cmd_size to 10.\n");
4241 softc->minimum_cmd_size = 10;
4243 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
4244 cmd10 = (struct scsi_rw_10 *)cdb;
4245 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
4247 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
4248 cmd10->reserved = 0;
4249 scsi_ulto2b(cmd6.length, cmd10->length);
4250 cmd10->control = cmd6.control;
4251 ccb->csio.cdb_len = sizeof(*cmd10);
4253 /* Requeue request, unfreezing queue if necessary */
4254 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
4255 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4258 cam_release_devq(ccb->ccb_h.path,
4262 /*getcount_only*/0);
4268 dazonedone(struct cam_periph *periph, union ccb *ccb)
4270 struct da_softc *softc;
4273 softc = periph->softc;
4274 bp = (struct bio *)ccb->ccb_h.ccb_bp;
4276 switch (bp->bio_zone.zone_cmd) {
4277 case DISK_ZONE_OPEN:
4278 case DISK_ZONE_CLOSE:
4279 case DISK_ZONE_FINISH:
4282 case DISK_ZONE_REPORT_ZONES: {
4284 struct disk_zone_report *rep;
4285 struct scsi_report_zones_hdr *hdr;
4286 struct scsi_report_zones_desc *desc;
4287 struct disk_zone_rep_entry *entry;
4288 uint32_t hdr_len, num_avail;
4289 uint32_t num_to_fill, i;
4292 rep = &bp->bio_zone.zone_params.report;
4293 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
4295 * Note that bio_resid isn't normally used for zone
4296 * commands, but it is used by devstat_end_transaction_bio()
4297 * to determine how much data was transferred. Because
4298 * the size of the SCSI/ATA data structures is different
4299 * than the size of the BIO interface structures, the
4300 * amount of data actually transferred from the drive will
4301 * be different than the amount of data transferred to
4304 bp->bio_resid = ccb->csio.resid;
4305 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
4306 if (avail_len < sizeof(*hdr)) {
4308 * Is there a better error than EIO here? We asked
4309 * for at least the header, and we got less than
4312 bp->bio_error = EIO;
4313 bp->bio_flags |= BIO_ERROR;
4314 bp->bio_resid = bp->bio_bcount;
4318 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4323 hdr_len = ata ? le32dec(hdr->length) :
4324 scsi_4btoul(hdr->length);
4326 rep->entries_available = hdr_len / sizeof(*desc);
4328 rep->entries_available = 0;
4330 * NOTE: using the same values for the BIO version of the
4331 * same field as the SCSI/ATA values. This means we could
4332 * get some additional values that aren't defined in bio.h
4333 * if more values of the same field are defined later.
4335 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4336 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4337 scsi_8btou64(hdr->maximum_lba);
4339 * If the drive reports no entries that match the query,
4343 rep->entries_filled = 0;
4347 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4348 hdr_len / sizeof(*desc));
4350 * If the drive didn't return any data, then we're done.
4352 if (num_avail == 0) {
4353 rep->entries_filled = 0;
4357 num_to_fill = min(num_avail, rep->entries_allocated);
4359 * If the user didn't allocate any entries for us to fill,
4362 if (num_to_fill == 0) {
4363 rep->entries_filled = 0;
4367 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4368 i < num_to_fill; i++, desc++, entry++) {
4370 * NOTE: we're mapping the values here directly
4371 * from the SCSI/ATA bit definitions to the bio.h
4372 * definitons. There is also a warning in
4373 * disk_zone.h, but the impact is that if
4374 * additional values are added in the SCSI/ATA
4375 * specs these will be visible to consumers of
4378 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4379 entry->zone_condition =
4380 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4381 SRZ_ZONE_COND_SHIFT;
4382 entry->zone_flags |= desc->zone_flags &
4383 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4384 entry->zone_length =
4385 ata ? le64dec(desc->zone_length) :
4386 scsi_8btou64(desc->zone_length);
4387 entry->zone_start_lba =
4388 ata ? le64dec(desc->zone_start_lba) :
4389 scsi_8btou64(desc->zone_start_lba);
4390 entry->write_pointer_lba =
4391 ata ? le64dec(desc->write_pointer_lba) :
4392 scsi_8btou64(desc->write_pointer_lba);
4394 rep->entries_filled = num_to_fill;
4397 case DISK_ZONE_GET_PARAMS:
4400 * In theory we should not get a GET_PARAMS bio, since it
4401 * should be handled without queueing the command to the
4404 panic("%s: Invalid zone command %d", __func__,
4405 bp->bio_zone.zone_cmd);
4409 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4410 free(ccb->csio.data_ptr, M_SCSIDA);
4414 dadone(struct cam_periph *periph, union ccb *done_ccb)
4416 struct bio *bp, *bp1;
4417 struct da_softc *softc;
4418 struct ccb_scsiio *csio;
4422 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4424 softc = (struct da_softc *)periph->softc;
4425 priority = done_ccb->ccb_h.pinfo.priority;
4426 csio = &done_ccb->csio;
4428 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4429 if (csio->bio != NULL)
4430 biotrack(csio->bio, __func__);
4432 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4434 cam_periph_lock(periph);
4435 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4436 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4440 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4445 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4446 if (error == ERESTART) {
4447 /* A retry was scheduled, so just return. */
4448 cam_periph_unlock(periph);
4451 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4456 * return all queued I/O with EIO, so that
4457 * the client can retry these I/Os in the
4458 * proper order should it attempt to recover.
4463 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4465 * Catastrophic error. Mark our pack as
4468 * XXX See if this is really a media
4471 xpt_print(periph->path, "Invalidating pack\n");
4472 softc->flags |= DA_FLAG_PACK_INVALID;
4474 softc->invalidations++;
4476 queued_error = ENXIO;
4478 cam_iosched_flush(softc->cam_iosched, NULL,
4481 bp->bio_error = error;
4482 bp->bio_resid = bp->bio_bcount;
4483 bp->bio_flags |= BIO_ERROR;
4485 } else if (bp != NULL) {
4486 if (state == DA_CCB_DELETE)
4489 bp->bio_resid = csio->resid;
4491 if (bp->bio_resid != 0)
4492 bp->bio_flags |= BIO_ERROR;
4494 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4495 cam_release_devq(done_ccb->ccb_h.path,
4499 /*getcount_only*/0);
4500 } else if (bp != NULL) {
4501 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4502 panic("REQ_CMP with QFRZN");
4503 if (bp->bio_cmd == BIO_ZONE)
4504 dazonedone(periph, done_ccb);
4505 else if (state == DA_CCB_DELETE)
4508 bp->bio_resid = csio->resid;
4509 if ((csio->resid > 0) && (bp->bio_cmd != BIO_ZONE))
4510 bp->bio_flags |= BIO_ERROR;
4511 if (softc->error_inject != 0) {
4512 bp->bio_error = softc->error_inject;
4513 bp->bio_resid = bp->bio_bcount;
4514 bp->bio_flags |= BIO_ERROR;
4515 softc->error_inject = 0;
4520 biotrack(bp, __func__);
4521 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4522 if (LIST_EMPTY(&softc->pending_ccbs))
4523 softc->flags |= DA_FLAG_WAS_OTAG;
4526 * We need to call cam_iosched before we call biodone so that we don't
4527 * measure any activity that happens in the completion routine, which in
4528 * the case of sendfile can be quite extensive. Release the periph
4529 * refcount taken in dastart() for each CCB.
4531 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4532 xpt_release_ccb(done_ccb);
4533 KASSERT(softc->refcount >= 1, ("dadone softc %p refcount %d", softc, softc->refcount));
4535 if (state == DA_CCB_DELETE) {
4536 TAILQ_HEAD(, bio) queue;
4539 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4540 softc->delete_run_queue.insert_point = NULL;
4542 * Normally, the xpt_release_ccb() above would make sure
4543 * that when we have more work to do, that work would
4544 * get kicked off. However, we specifically keep
4545 * delete_running set to 0 before the call above to
4546 * allow other I/O to progress when many BIO_DELETE
4547 * requests are pushed down. We set delete_running to 0
4548 * and call daschedule again so that we don't stall if
4549 * there are no other I/Os pending apart from BIO_DELETEs.
4551 cam_iosched_trim_done(softc->cam_iosched);
4553 cam_periph_unlock(periph);
4554 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4555 TAILQ_REMOVE(&queue, bp1, bio_queue);
4556 bp1->bio_error = bp->bio_error;
4557 if (bp->bio_flags & BIO_ERROR) {
4558 bp1->bio_flags |= BIO_ERROR;
4559 bp1->bio_resid = bp1->bio_bcount;
4566 cam_periph_unlock(periph);
4574 dadone_probewp(struct cam_periph *periph, union ccb *done_ccb)
4576 struct scsi_mode_header_6 *mode_hdr6;
4577 struct scsi_mode_header_10 *mode_hdr10;
4578 struct da_softc *softc;
4579 struct ccb_scsiio *csio;
4583 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probewp\n"));
4585 softc = (struct da_softc *)periph->softc;
4586 priority = done_ccb->ccb_h.pinfo.priority;
4587 csio = &done_ccb->csio;
4589 cam_periph_assert(periph, MA_OWNED);
4591 if (softc->minimum_cmd_size > 6) {
4592 mode_hdr10 = (struct scsi_mode_header_10 *)csio->data_ptr;
4593 dev_spec = mode_hdr10->dev_spec;
4595 mode_hdr6 = (struct scsi_mode_header_6 *)csio->data_ptr;
4596 dev_spec = mode_hdr6->dev_spec;
4598 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
4599 if ((dev_spec & 0x80) != 0)
4600 softc->disk->d_flags |= DISKFLAG_WRITE_PROTECT;
4602 softc->disk->d_flags &= ~DISKFLAG_WRITE_PROTECT;
4606 error = daerror(done_ccb, CAM_RETRY_SELTO,
4607 SF_RETRY_UA|SF_NO_PRINT);
4608 if (error == ERESTART)
4610 else if (error != 0) {
4611 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4612 /* Don't wedge this device's queue */
4613 cam_release_devq(done_ccb->ccb_h.path,
4617 /*getcount_only*/0);
4622 free(csio->data_ptr, M_SCSIDA);
4623 xpt_release_ccb(done_ccb);
4624 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
4625 softc->state = DA_STATE_PROBE_RC16;
4627 softc->state = DA_STATE_PROBE_RC;
4628 xpt_schedule(periph, priority);
4633 dadone_proberc(struct cam_periph *periph, union ccb *done_ccb)
4635 struct scsi_read_capacity_data *rdcap;
4636 struct scsi_read_capacity_data_long *rcaplong;
4637 struct da_softc *softc;
4638 struct ccb_scsiio *csio;
4644 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_proberc\n"));
4646 softc = (struct da_softc *)periph->softc;
4647 priority = done_ccb->ccb_h.pinfo.priority;
4648 csio = &done_ccb->csio;
4649 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4654 /* XXX TODO: can this be a malloc? */
4655 announce_buf = softc->announce_temp;
4656 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4658 if (state == DA_CCB_PROBE_RC)
4659 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4661 rcaplong = (struct scsi_read_capacity_data_long *)
4664 cam_periph_assert(periph, MA_OWNED);
4666 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4667 struct disk_params *dp;
4668 uint32_t block_size;
4670 u_int lalba; /* Lowest aligned LBA. */
4672 if (state == DA_CCB_PROBE_RC) {
4673 block_size = scsi_4btoul(rdcap->length);
4674 maxsector = scsi_4btoul(rdcap->addr);
4678 * According to SBC-2, if the standard 10
4679 * byte READ CAPACITY command returns 2^32,
4680 * we should issue the 16 byte version of
4681 * the command, since the device in question
4682 * has more sectors than can be represented
4683 * with the short version of the command.
4685 if (maxsector == 0xffffffff) {
4686 free(rdcap, M_SCSIDA);
4687 xpt_release_ccb(done_ccb);
4688 softc->state = DA_STATE_PROBE_RC16;
4689 xpt_schedule(periph, priority);
4693 block_size = scsi_4btoul(rcaplong->length);
4694 maxsector = scsi_8btou64(rcaplong->addr);
4695 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4699 * Because GEOM code just will panic us if we
4700 * give them an 'illegal' value we'll avoid that
4703 if (block_size == 0) {
4708 if (block_size >= MAXPHYS) {
4709 xpt_print(periph->path,
4710 "unsupportable block size %ju\n",
4711 (uintmax_t) block_size);
4712 announce_buf = NULL;
4713 cam_periph_invalidate(periph);
4716 * We pass rcaplong into dasetgeom(),
4717 * because it will only use it if it is
4720 dasetgeom(periph, block_size, maxsector,
4721 rcaplong, sizeof(*rcaplong));
4722 lbp = (lalba & SRC16_LBPME_A);
4723 dp = &softc->params;
4724 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4725 "%juMB (%ju %u byte sectors)",
4726 ((uintmax_t)dp->secsize * dp->sectors) /
4728 (uintmax_t)dp->sectors, dp->secsize);
4734 * Retry any UNIT ATTENTION type errors. They
4735 * are expected at boot.
4737 error = daerror(done_ccb, CAM_RETRY_SELTO,
4738 SF_RETRY_UA|SF_NO_PRINT);
4739 if (error == ERESTART) {
4741 * A retry was scheuled, so
4745 } else if (error != 0) {
4747 int sense_key, error_code;
4750 struct ccb_getdev cgd;
4752 /* Don't wedge this device's queue */
4753 status = done_ccb->ccb_h.status;
4754 if ((status & CAM_DEV_QFRZN) != 0)
4755 cam_release_devq(done_ccb->ccb_h.path,
4759 /*getcount_only*/0);
4762 xpt_setup_ccb(&cgd.ccb_h, done_ccb->ccb_h.path,
4763 CAM_PRIORITY_NORMAL);
4764 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4765 xpt_action((union ccb *)&cgd);
4767 if (scsi_extract_sense_ccb(done_ccb,
4768 &error_code, &sense_key, &asc, &ascq))
4774 * If we tried READ CAPACITY(16) and failed,
4775 * fallback to READ CAPACITY(10).
4777 if ((state == DA_CCB_PROBE_RC16) &&
4778 (softc->flags & DA_FLAG_CAN_RC16) &&
4779 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4782 (error_code == SSD_CURRENT_ERROR ||
4783 error_code == SSD_DESC_CURRENT_ERROR) &&
4784 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4785 cam_periph_assert(periph, MA_OWNED);
4786 softc->flags &= ~DA_FLAG_CAN_RC16;
4787 free(rdcap, M_SCSIDA);
4788 xpt_release_ccb(done_ccb);
4789 softc->state = DA_STATE_PROBE_RC;
4790 xpt_schedule(periph, priority);
4795 * Attach to anything that claims to be a
4796 * direct access or optical disk device,
4797 * as long as it doesn't return a "Logical
4798 * unit not supported" (0x25) error.
4799 * "Internal Target Failure" (0x44) is also
4800 * special and typically means that the
4801 * device is a SATA drive behind a SATL
4802 * translation that's fallen into a
4803 * terminally fatal state.
4806 && (asc != 0x25) && (asc != 0x44)
4807 && (error_code == SSD_CURRENT_ERROR
4808 || error_code == SSD_DESC_CURRENT_ERROR)) {
4809 const char *sense_key_desc;
4810 const char *asc_desc;
4812 dasetgeom(periph, 512, -1, NULL, 0);
4813 scsi_sense_desc(sense_key, asc, ascq,
4814 &cgd.inq_data, &sense_key_desc,
4816 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4817 "Attempt to query device "
4818 "size failed: %s, %s",
4819 sense_key_desc, asc_desc);
4822 scsi_sense_print(&done_ccb->csio);
4824 xpt_print(periph->path,
4825 "got CAM status %#x\n",
4826 done_ccb->ccb_h.status);
4829 xpt_print(periph->path, "fatal error, "
4830 "failed to attach to device\n");
4832 announce_buf = NULL;
4835 * Free up resources.
4837 cam_periph_invalidate(periph);
4841 free(csio->data_ptr, M_SCSIDA);
4842 if (announce_buf != NULL &&
4843 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4846 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4848 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4849 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4855 * Create our sysctl variables, now that we know
4856 * we have successfully attached.
4858 /* increase the refcount */
4859 if (da_periph_acquire(periph, DA_REF_SYSCTL) == 0) {
4860 taskqueue_enqueue(taskqueue_thread,
4861 &softc->sysctl_task);
4863 /* XXX This message is useless! */
4864 xpt_print(periph->path, "fatal error, "
4865 "could not acquire reference count\n");
4869 /* We already probed the device. */
4870 if (softc->flags & DA_FLAG_PROBED) {
4871 daprobedone(periph, done_ccb);
4875 /* Ensure re-probe doesn't see old delete. */
4876 softc->delete_available = 0;
4877 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4878 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4880 * Based on older SBC-3 spec revisions
4881 * any of the UNMAP methods "may" be
4882 * available via LBP given this flag so
4883 * we flag all of them as available and
4884 * then remove those which further
4885 * probes confirm aren't available
4888 * We could also check readcap(16) p_type
4889 * flag to exclude one or more invalid
4890 * write same (X) types here
4892 dadeleteflag(softc, DA_DELETE_WS16, 1);
4893 dadeleteflag(softc, DA_DELETE_WS10, 1);
4894 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4896 xpt_release_ccb(done_ccb);
4897 softc->state = DA_STATE_PROBE_LBP;
4898 xpt_schedule(periph, priority);
4902 xpt_release_ccb(done_ccb);
4903 softc->state = DA_STATE_PROBE_BDC;
4904 xpt_schedule(periph, priority);
4909 dadone_probelbp(struct cam_periph *periph, union ccb *done_ccb)
4911 struct scsi_vpd_logical_block_prov *lbp;
4912 struct da_softc *softc;
4913 struct ccb_scsiio *csio;
4916 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probelbp\n"));
4918 softc = (struct da_softc *)periph->softc;
4919 priority = done_ccb->ccb_h.pinfo.priority;
4920 csio = &done_ccb->csio;
4921 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4923 cam_periph_assert(periph, MA_OWNED);
4925 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4927 * T10/1799-D Revision 31 states at least one of these
4928 * must be supported but we don't currently enforce this.
4930 dadeleteflag(softc, DA_DELETE_WS16,
4931 (lbp->flags & SVPD_LBP_WS16));
4932 dadeleteflag(softc, DA_DELETE_WS10,
4933 (lbp->flags & SVPD_LBP_WS10));
4934 dadeleteflag(softc, DA_DELETE_UNMAP,
4935 (lbp->flags & SVPD_LBP_UNMAP));
4938 error = daerror(done_ccb, CAM_RETRY_SELTO,
4939 SF_RETRY_UA|SF_NO_PRINT);
4940 if (error == ERESTART)
4942 else if (error != 0) {
4943 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4944 /* Don't wedge this device's queue */
4945 cam_release_devq(done_ccb->ccb_h.path,
4949 /*getcount_only*/0);
4953 * Failure indicates we don't support any SBC-3
4954 * delete methods with UNMAP
4959 free(lbp, M_SCSIDA);
4960 xpt_release_ccb(done_ccb);
4961 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4962 xpt_schedule(periph, priority);
4967 dadone_probeblklimits(struct cam_periph *periph, union ccb *done_ccb)
4969 struct scsi_vpd_block_limits *block_limits;
4970 struct da_softc *softc;
4971 struct ccb_scsiio *csio;
4974 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeblklimits\n"));
4976 softc = (struct da_softc *)periph->softc;
4977 priority = done_ccb->ccb_h.pinfo.priority;
4978 csio = &done_ccb->csio;
4979 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4981 cam_periph_assert(periph, MA_OWNED);
4983 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4984 uint32_t max_txfer_len = scsi_4btoul(
4985 block_limits->max_txfer_len);
4986 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4987 block_limits->max_unmap_lba_cnt);
4988 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4989 block_limits->max_unmap_blk_cnt);
4990 uint32_t unmap_gran = scsi_4btoul(
4991 block_limits->opt_unmap_grain);
4992 uint32_t unmap_gran_align = scsi_4btoul(
4993 block_limits->unmap_grain_align);
4994 uint64_t ws_max_blks = scsi_8btou64(
4995 block_limits->max_write_same_length);
4997 if (max_txfer_len != 0) {
4998 softc->disk->d_maxsize = MIN(softc->maxio,
4999 (off_t)max_txfer_len * softc->params.secsize);
5003 * We should already support UNMAP but we check lba
5004 * and block count to be sure
5006 if (max_unmap_lba_cnt != 0x00L &&
5007 max_unmap_blk_cnt != 0x00L) {
5008 softc->unmap_max_lba = max_unmap_lba_cnt;
5009 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
5011 if (unmap_gran > 1) {
5012 softc->unmap_gran = unmap_gran;
5013 if (unmap_gran_align & 0x80000000) {
5014 softc->unmap_gran_align =
5015 unmap_gran_align & 0x7fffffff;
5020 * Unexpected UNMAP limits which means the
5021 * device doesn't actually support UNMAP
5023 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
5026 if (ws_max_blks != 0x00L)
5027 softc->ws_max_blks = ws_max_blks;
5030 error = daerror(done_ccb, CAM_RETRY_SELTO,
5031 SF_RETRY_UA|SF_NO_PRINT);
5032 if (error == ERESTART)
5034 else if (error != 0) {
5035 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5036 /* Don't wedge this device's queue */
5037 cam_release_devq(done_ccb->ccb_h.path,
5041 /*getcount_only*/0);
5045 * Failure here doesn't mean UNMAP is not
5046 * supported as this is an optional page.
5048 softc->unmap_max_lba = 1;
5049 softc->unmap_max_ranges = 1;
5053 free(block_limits, M_SCSIDA);
5054 xpt_release_ccb(done_ccb);
5055 softc->state = DA_STATE_PROBE_BDC;
5056 xpt_schedule(periph, priority);
5061 dadone_probebdc(struct cam_periph *periph, union ccb *done_ccb)
5063 struct scsi_vpd_block_device_characteristics *bdc;
5064 struct da_softc *softc;
5065 struct ccb_scsiio *csio;
5068 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probebdc\n"));
5070 softc = (struct da_softc *)periph->softc;
5071 priority = done_ccb->ccb_h.pinfo.priority;
5072 csio = &done_ccb->csio;
5073 bdc = (struct scsi_vpd_block_device_characteristics *)csio->data_ptr;
5075 cam_periph_assert(periph, MA_OWNED);
5077 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5081 * Disable queue sorting for non-rotational media
5084 u_int16_t old_rate = softc->disk->d_rotation_rate;
5086 valid_len = csio->dxfer_len - csio->resid;
5087 if (SBDC_IS_PRESENT(bdc, valid_len,
5088 medium_rotation_rate)) {
5089 softc->disk->d_rotation_rate =
5090 scsi_2btoul(bdc->medium_rotation_rate);
5091 if (softc->disk->d_rotation_rate ==
5092 SVPD_BDC_RATE_NON_ROTATING) {
5093 cam_iosched_set_sort_queue(
5094 softc->cam_iosched, 0);
5095 softc->rotating = 0;
5097 if (softc->disk->d_rotation_rate != old_rate) {
5098 disk_attr_changed(softc->disk,
5099 "GEOM::rotation_rate", M_NOWAIT);
5102 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
5103 && (softc->zone_mode == DA_ZONE_NONE)) {
5106 if (scsi_vpd_supported_page(periph,
5107 SVPD_ATA_INFORMATION))
5113 * The Zoned field will only be set for
5114 * Drive Managed and Host Aware drives. If
5115 * they are Host Managed, the device type
5116 * in the standard INQUIRY data should be
5117 * set to T_ZBC_HM (0x14).
5119 if ((bdc->flags & SVPD_ZBC_MASK) ==
5121 softc->zone_mode = DA_ZONE_HOST_AWARE;
5122 softc->zone_interface = (ata_proto) ?
5123 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5124 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
5126 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5127 softc->zone_interface = (ata_proto) ?
5128 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5129 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
5131 xpt_print(periph->path, "Unknown zoned "
5133 bdc->flags & SVPD_ZBC_MASK);
5138 error = daerror(done_ccb, CAM_RETRY_SELTO,
5139 SF_RETRY_UA|SF_NO_PRINT);
5140 if (error == ERESTART)
5142 else if (error != 0) {
5143 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5144 /* Don't wedge this device's queue */
5145 cam_release_devq(done_ccb->ccb_h.path,
5149 /*getcount_only*/0);
5154 free(bdc, M_SCSIDA);
5155 xpt_release_ccb(done_ccb);
5156 softc->state = DA_STATE_PROBE_ATA;
5157 xpt_schedule(periph, priority);
5162 dadone_probeata(struct cam_periph *periph, union ccb *done_ccb)
5164 struct ata_params *ata_params;
5165 struct ccb_scsiio *csio;
5166 struct da_softc *softc;
5172 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeata\n"));
5174 softc = (struct da_softc *)periph->softc;
5175 priority = done_ccb->ccb_h.pinfo.priority;
5176 csio = &done_ccb->csio;
5177 ata_params = (struct ata_params *)csio->data_ptr;
5178 ptr = (uint16_t *)ata_params;
5182 cam_periph_assert(periph, MA_OWNED);
5184 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5187 for (i = 0; i < sizeof(*ata_params) / 2; i++)
5188 ptr[i] = le16toh(ptr[i]);
5189 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
5190 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
5191 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
5192 if (ata_params->max_dsm_blocks != 0)
5193 softc->trim_max_ranges = min(
5194 softc->trim_max_ranges,
5195 ata_params->max_dsm_blocks *
5196 ATA_DSM_BLK_RANGES);
5199 * Disable queue sorting for non-rotational media
5202 old_rate = softc->disk->d_rotation_rate;
5203 softc->disk->d_rotation_rate = ata_params->media_rotation_rate;
5204 if (softc->disk->d_rotation_rate == ATA_RATE_NON_ROTATING) {
5205 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
5206 softc->rotating = 0;
5208 if (softc->disk->d_rotation_rate != old_rate) {
5209 disk_attr_changed(softc->disk,
5210 "GEOM::rotation_rate", M_NOWAIT);
5213 cam_periph_assert(periph, MA_OWNED);
5214 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
5215 softc->flags |= DA_FLAG_CAN_ATA_DMA;
5217 if (ata_params->support.extension & ATA_SUPPORT_GENLOG)
5218 softc->flags |= DA_FLAG_CAN_ATA_LOG;
5221 * At this point, if we have a SATA host aware drive,
5222 * we communicate via ATA passthrough unless the
5223 * SAT layer supports ZBC -> ZAC translation. In
5226 * XXX KDM figure out how to detect a host managed
5229 if (softc->zone_mode == DA_ZONE_NONE) {
5231 * Note that we don't override the zone
5232 * mode or interface if it has already been
5233 * set. This is because it has either been
5234 * set as a quirk, or when we probed the
5235 * SCSI Block Device Characteristics page,
5236 * the zoned field was set. The latter
5237 * means that the SAT layer supports ZBC to
5238 * ZAC translation, and we would prefer to
5239 * use that if it is available.
5241 if ((ata_params->support3 &
5242 ATA_SUPPORT_ZONE_MASK) ==
5243 ATA_SUPPORT_ZONE_HOST_AWARE) {
5244 softc->zone_mode = DA_ZONE_HOST_AWARE;
5245 softc->zone_interface =
5246 DA_ZONE_IF_ATA_PASS;
5247 } else if ((ata_params->support3 &
5248 ATA_SUPPORT_ZONE_MASK) ==
5249 ATA_SUPPORT_ZONE_DEV_MANAGED) {
5250 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5251 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
5256 error = daerror(done_ccb, CAM_RETRY_SELTO,
5257 SF_RETRY_UA|SF_NO_PRINT);
5258 if (error == ERESTART)
5260 else if (error != 0) {
5261 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5262 /* Don't wedge this device's queue */
5263 cam_release_devq(done_ccb->ccb_h.path,
5267 /*getcount_only*/0);
5272 free(ata_params, M_SCSIDA);
5273 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
5274 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
5276 * If the ATA IDENTIFY failed, we could be talking
5277 * to a SCSI drive, although that seems unlikely,
5278 * since the drive did report that it supported the
5279 * ATA Information VPD page. If the ATA IDENTIFY
5280 * succeeded, and the SAT layer doesn't support
5281 * ZBC -> ZAC translation, continue on to get the
5282 * directory of ATA logs, and complete the rest of
5283 * the ZAC probe. If the SAT layer does support
5284 * ZBC -> ZAC translation, we want to use that,
5285 * and we'll probe the SCSI Zoned Block Device
5286 * Characteristics VPD page next.
5289 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
5290 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
5291 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
5293 softc->state = DA_STATE_PROBE_ZONE;
5296 if (continue_probe != 0) {
5297 xpt_release_ccb(done_ccb);
5298 xpt_schedule(periph, priority);
5301 daprobedone(periph, done_ccb);
5306 dadone_probeatalogdir(struct cam_periph *periph, union ccb *done_ccb)
5308 struct da_softc *softc;
5309 struct ccb_scsiio *csio;
5313 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatalogdir\n"));
5315 softc = (struct da_softc *)periph->softc;
5316 priority = done_ccb->ccb_h.pinfo.priority;
5317 csio = &done_ccb->csio;
5319 cam_periph_assert(periph, MA_OWNED);
5320 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5322 softc->valid_logdir_len = 0;
5323 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
5324 softc->valid_logdir_len = csio->dxfer_len - csio->resid;
5325 if (softc->valid_logdir_len > 0)
5326 bcopy(csio->data_ptr, &softc->ata_logdir,
5327 min(softc->valid_logdir_len,
5328 sizeof(softc->ata_logdir)));
5330 * Figure out whether the Identify Device log is
5331 * supported. The General Purpose log directory
5332 * has a header, and lists the number of pages
5333 * available for each GP log identified by the
5334 * offset into the list.
5336 if ((softc->valid_logdir_len >=
5337 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
5338 && (le16dec(softc->ata_logdir.header) ==
5339 ATA_GP_LOG_DIR_VERSION)
5340 && (le16dec(&softc->ata_logdir.num_pages[
5341 (ATA_IDENTIFY_DATA_LOG *
5342 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
5343 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
5345 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5348 error = daerror(done_ccb, CAM_RETRY_SELTO,
5349 SF_RETRY_UA|SF_NO_PRINT);
5350 if (error == ERESTART)
5352 else if (error != 0) {
5354 * If we can't get the ATA log directory,
5355 * then ATA logs are effectively not
5356 * supported even if the bit is set in the
5359 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
5360 DA_FLAG_CAN_ATA_IDLOG);
5361 if ((done_ccb->ccb_h.status &
5362 CAM_DEV_QFRZN) != 0) {
5363 /* Don't wedge this device's queue */
5364 cam_release_devq(done_ccb->ccb_h.path,
5368 /*getcount_only*/0);
5373 free(csio->data_ptr, M_SCSIDA);
5376 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
5377 softc->state = DA_STATE_PROBE_ATA_IDDIR;
5378 xpt_release_ccb(done_ccb);
5379 xpt_schedule(periph, priority);
5382 daprobedone(periph, done_ccb);
5387 dadone_probeataiddir(struct cam_periph *periph, union ccb *done_ccb)
5389 struct da_softc *softc;
5390 struct ccb_scsiio *csio;
5394 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeataiddir\n"));
5396 softc = (struct da_softc *)periph->softc;
5397 priority = done_ccb->ccb_h.pinfo.priority;
5398 csio = &done_ccb->csio;
5400 cam_periph_assert(periph, MA_OWNED);
5402 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5403 off_t entries_offset, max_entries;
5406 softc->valid_iddir_len = 0;
5407 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
5408 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
5409 DA_FLAG_CAN_ATA_ZONE);
5410 softc->valid_iddir_len = csio->dxfer_len - csio->resid;
5411 if (softc->valid_iddir_len > 0)
5412 bcopy(csio->data_ptr, &softc->ata_iddir,
5413 min(softc->valid_iddir_len,
5414 sizeof(softc->ata_iddir)));
5417 __offsetof(struct ata_identify_log_pages,entries);
5418 max_entries = softc->valid_iddir_len - entries_offset;
5419 if ((softc->valid_iddir_len > (entries_offset + 1))
5420 && (le64dec(softc->ata_iddir.header) == ATA_IDLOG_REVISION)
5421 && (softc->ata_iddir.entry_count > 0)) {
5424 num_entries = softc->ata_iddir.entry_count;
5425 num_entries = min(num_entries,
5426 softc->valid_iddir_len - entries_offset);
5427 for (i = 0; i < num_entries && i < max_entries; i++) {
5428 if (softc->ata_iddir.entries[i] ==
5430 softc->flags |= DA_FLAG_CAN_ATA_SUPCAP;
5431 else if (softc->ata_iddir.entries[i] ==
5433 softc->flags |= DA_FLAG_CAN_ATA_ZONE;
5435 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP)
5436 && (softc->flags & DA_FLAG_CAN_ATA_ZONE))
5441 error = daerror(done_ccb, CAM_RETRY_SELTO,
5442 SF_RETRY_UA|SF_NO_PRINT);
5443 if (error == ERESTART)
5445 else if (error != 0) {
5447 * If we can't get the ATA Identify Data log
5448 * directory, then it effectively isn't
5449 * supported even if the ATA Log directory
5450 * a non-zero number of pages present for
5453 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5454 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5455 /* Don't wedge this device's queue */
5456 cam_release_devq(done_ccb->ccb_h.path,
5460 /*getcount_only*/0);
5465 free(csio->data_ptr, M_SCSIDA);
5467 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5468 softc->state = DA_STATE_PROBE_ATA_SUP;
5469 xpt_release_ccb(done_ccb);
5470 xpt_schedule(periph, priority);
5473 daprobedone(periph, done_ccb);
5478 dadone_probeatasup(struct cam_periph *periph, union ccb *done_ccb)
5480 struct da_softc *softc;
5481 struct ccb_scsiio *csio;
5485 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatasup\n"));
5487 softc = (struct da_softc *)periph->softc;
5488 priority = done_ccb->ccb_h.pinfo.priority;
5489 csio = &done_ccb->csio;
5491 cam_periph_assert(periph, MA_OWNED);
5493 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5496 struct ata_identify_log_sup_cap *sup_cap;
5499 sup_cap = (struct ata_identify_log_sup_cap *)csio->data_ptr;
5500 valid_len = csio->dxfer_len - csio->resid;
5501 needed_size = __offsetof(struct ata_identify_log_sup_cap,
5502 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5503 if (valid_len >= needed_size) {
5504 uint64_t zoned, zac_cap;
5506 zoned = le64dec(sup_cap->zoned_cap);
5507 if (zoned & ATA_ZONED_VALID) {
5509 * This should have already been
5510 * set, because this is also in the
5511 * ATA identify data.
5513 if ((zoned & ATA_ZONED_MASK) ==
5514 ATA_SUPPORT_ZONE_HOST_AWARE)
5515 softc->zone_mode = DA_ZONE_HOST_AWARE;
5516 else if ((zoned & ATA_ZONED_MASK) ==
5517 ATA_SUPPORT_ZONE_DEV_MANAGED)
5519 DA_ZONE_DRIVE_MANAGED;
5522 zac_cap = le64dec(sup_cap->sup_zac_cap);
5523 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5524 if (zac_cap & ATA_REPORT_ZONES_SUP)
5525 softc->zone_flags |=
5526 DA_ZONE_FLAG_RZ_SUP;
5527 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5528 softc->zone_flags |=
5529 DA_ZONE_FLAG_OPEN_SUP;
5530 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5531 softc->zone_flags |=
5532 DA_ZONE_FLAG_CLOSE_SUP;
5533 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5534 softc->zone_flags |=
5535 DA_ZONE_FLAG_FINISH_SUP;
5536 if (zac_cap & ATA_ND_RWP_SUP)
5537 softc->zone_flags |=
5538 DA_ZONE_FLAG_RWP_SUP;
5541 * This field was introduced in
5542 * ACS-4, r08 on April 28th, 2015.
5543 * If the drive firmware was written
5544 * to an earlier spec, it won't have
5545 * the field. So, assume all
5546 * commands are supported.
5548 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5552 error = daerror(done_ccb, CAM_RETRY_SELTO,
5553 SF_RETRY_UA|SF_NO_PRINT);
5554 if (error == ERESTART)
5556 else if (error != 0) {
5558 * If we can't get the ATA Identify Data
5559 * Supported Capabilities page, clear the
5562 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5564 * And clear zone capabilities.
5566 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5567 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5568 /* Don't wedge this device's queue */
5569 cam_release_devq(done_ccb->ccb_h.path,
5573 /*getcount_only*/0);
5578 free(csio->data_ptr, M_SCSIDA);
5580 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5581 softc->state = DA_STATE_PROBE_ATA_ZONE;
5582 xpt_release_ccb(done_ccb);
5583 xpt_schedule(periph, priority);
5586 daprobedone(periph, done_ccb);
5591 dadone_probeatazone(struct cam_periph *periph, union ccb *done_ccb)
5593 struct da_softc *softc;
5594 struct ccb_scsiio *csio;
5597 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatazone\n"));
5599 softc = (struct da_softc *)periph->softc;
5600 csio = &done_ccb->csio;
5602 cam_periph_assert(periph, MA_OWNED);
5604 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5605 struct ata_zoned_info_log *zi_log;
5609 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5611 valid_len = csio->dxfer_len - csio->resid;
5612 needed_size = __offsetof(struct ata_zoned_info_log,
5613 version_info) + 1 + sizeof(zi_log->version_info);
5614 if (valid_len >= needed_size) {
5617 tmpvar = le64dec(zi_log->zoned_cap);
5618 if (tmpvar & ATA_ZDI_CAP_VALID) {
5619 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5620 softc->zone_flags |=
5621 DA_ZONE_FLAG_URSWRZ;
5623 softc->zone_flags &=
5624 ~DA_ZONE_FLAG_URSWRZ;
5626 tmpvar = le64dec(zi_log->optimal_seq_zones);
5627 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5628 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5629 softc->optimal_seq_zones = (tmpvar &
5630 ATA_ZDI_OPT_SEQ_MASK);
5632 softc->zone_flags &= ~DA_ZONE_FLAG_OPT_SEQ_SET;
5633 softc->optimal_seq_zones = 0;
5636 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5637 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5638 softc->zone_flags |=
5639 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5640 softc->optimal_nonseq_zones =
5641 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5643 softc->zone_flags &=
5644 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5645 softc->optimal_nonseq_zones = 0;
5648 tmpvar = le64dec(zi_log->max_seq_req_zones);
5649 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5650 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5651 softc->max_seq_zones =
5652 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5654 softc->zone_flags &= ~DA_ZONE_FLAG_MAX_SEQ_SET;
5655 softc->max_seq_zones = 0;
5659 error = daerror(done_ccb, CAM_RETRY_SELTO,
5660 SF_RETRY_UA|SF_NO_PRINT);
5661 if (error == ERESTART)
5663 else if (error != 0) {
5664 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5665 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5667 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5668 /* Don't wedge this device's queue */
5669 cam_release_devq(done_ccb->ccb_h.path,
5673 /*getcount_only*/0);
5679 free(csio->data_ptr, M_SCSIDA);
5681 daprobedone(periph, done_ccb);
5686 dadone_probezone(struct cam_periph *periph, union ccb *done_ccb)
5688 struct da_softc *softc;
5689 struct ccb_scsiio *csio;
5692 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probezone\n"));
5694 softc = (struct da_softc *)periph->softc;
5695 csio = &done_ccb->csio;
5697 cam_periph_assert(periph, MA_OWNED);
5699 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5702 struct scsi_vpd_zoned_bdc *zoned_bdc;
5705 zoned_bdc = (struct scsi_vpd_zoned_bdc *)csio->data_ptr;
5706 valid_len = csio->dxfer_len - csio->resid;
5707 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5708 max_seq_req_zones) + 1 +
5709 sizeof(zoned_bdc->max_seq_req_zones);
5710 if ((valid_len >= needed_len)
5711 && (scsi_2btoul(zoned_bdc->page_length) >= SVPD_ZBDC_PL)) {
5712 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5713 softc->zone_flags |= DA_ZONE_FLAG_URSWRZ;
5715 softc->zone_flags &= ~DA_ZONE_FLAG_URSWRZ;
5716 softc->optimal_seq_zones =
5717 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5718 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5719 softc->optimal_nonseq_zones = scsi_4btoul(
5720 zoned_bdc->optimal_nonseq_zones);
5721 softc->zone_flags |= DA_ZONE_FLAG_OPT_NONSEQ_SET;
5722 softc->max_seq_zones =
5723 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5724 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5727 * All of the zone commands are mandatory for SCSI
5730 * XXX KDM this is valid as of September 2015.
5731 * Re-check this assumption once the SAT spec is
5732 * updated to support SCSI ZBC to ATA ZAC mapping.
5733 * Since ATA allows zone commands to be reported
5734 * as supported or not, this may not necessarily
5735 * be true for an ATA device behind a SAT (SCSI to
5736 * ATA Translation) layer.
5738 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5740 error = daerror(done_ccb, CAM_RETRY_SELTO,
5741 SF_RETRY_UA|SF_NO_PRINT);
5742 if (error == ERESTART)
5744 else if (error != 0) {
5745 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5746 /* Don't wedge this device's queue */
5747 cam_release_devq(done_ccb->ccb_h.path,
5751 /*getcount_only*/0);
5756 free(csio->data_ptr, M_SCSIDA);
5758 daprobedone(periph, done_ccb);
5763 dadone_tur(struct cam_periph *periph, union ccb *done_ccb)
5765 struct da_softc *softc;
5766 struct ccb_scsiio *csio;
5768 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_tur\n"));
5770 softc = (struct da_softc *)periph->softc;
5771 csio = &done_ccb->csio;
5773 cam_periph_assert(periph, MA_OWNED);
5775 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5777 if (daerror(done_ccb, CAM_RETRY_SELTO,
5778 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) == ERESTART)
5779 return; /* Will complete again, keep reference */
5780 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5781 cam_release_devq(done_ccb->ccb_h.path,
5785 /*getcount_only*/0);
5787 xpt_release_ccb(done_ccb);
5788 softc->flags &= ~DA_FLAG_TUR_PENDING;
5789 da_periph_release_locked(periph, DA_REF_TUR);
5794 dareprobe(struct cam_periph *periph)
5796 struct da_softc *softc;
5799 softc = (struct da_softc *)periph->softc;
5801 /* Probe in progress; don't interfere. */
5802 if (softc->state != DA_STATE_NORMAL)
5805 status = da_periph_acquire(periph, DA_REF_REPROBE);
5806 KASSERT(status == 0, ("dareprobe: cam_periph_acquire failed"));
5808 softc->state = DA_STATE_PROBE_WP;
5809 xpt_schedule(periph, CAM_PRIORITY_DEV);
5813 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5815 struct da_softc *softc;
5816 struct cam_periph *periph;
5817 int error, error_code, sense_key, asc, ascq;
5819 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5820 if (ccb->csio.bio != NULL)
5821 biotrack(ccb->csio.bio, __func__);
5824 periph = xpt_path_periph(ccb->ccb_h.path);
5825 softc = (struct da_softc *)periph->softc;
5827 cam_periph_assert(periph, MA_OWNED);
5830 * Automatically detect devices that do not support
5831 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5834 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5835 error = cmd6workaround(ccb);
5836 } else if (scsi_extract_sense_ccb(ccb,
5837 &error_code, &sense_key, &asc, &ascq)) {
5838 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5839 error = cmd6workaround(ccb);
5841 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5842 * query the capacity and notify upper layers.
5844 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5845 asc == 0x2A && ascq == 0x09) {
5846 xpt_print(periph->path, "Capacity data has changed\n");
5847 softc->flags &= ~DA_FLAG_PROBED;
5849 sense_flags |= SF_NO_PRINT;
5850 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5851 asc == 0x28 && ascq == 0x00) {
5852 softc->flags &= ~DA_FLAG_PROBED;
5853 disk_media_changed(softc->disk, M_NOWAIT);
5854 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5855 asc == 0x3F && ascq == 0x03) {
5856 xpt_print(periph->path, "INQUIRY data has changed\n");
5857 softc->flags &= ~DA_FLAG_PROBED;
5859 sense_flags |= SF_NO_PRINT;
5860 } else if (sense_key == SSD_KEY_NOT_READY &&
5861 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5862 softc->flags |= DA_FLAG_PACK_INVALID;
5863 disk_media_gone(softc->disk, M_NOWAIT);
5866 if (error == ERESTART)
5870 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5871 case CAM_CMD_TIMEOUT:
5874 case CAM_REQ_ABORTED:
5875 case CAM_REQ_CMP_ERR:
5876 case CAM_REQ_TERMIO:
5877 case CAM_UNREC_HBA_ERROR:
5878 case CAM_DATA_RUN_ERR:
5888 * Until we have a better way of doing pack validation,
5889 * don't treat UAs as errors.
5891 sense_flags |= SF_RETRY_UA;
5893 if (softc->quirks & DA_Q_RETRY_BUSY)
5894 sense_flags |= SF_RETRY_BUSY;
5895 return(cam_periph_error(ccb, cam_flags, sense_flags));
5899 damediapoll(void *arg)
5901 struct cam_periph *periph = arg;
5902 struct da_softc *softc = periph->softc;
5904 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5905 (softc->flags & DA_FLAG_TUR_PENDING) == 0 &&
5906 LIST_EMPTY(&softc->pending_ccbs)) {
5907 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
5908 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5912 /* Queue us up again */
5913 if (da_poll_period != 0)
5914 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5918 daprevent(struct cam_periph *periph, int action)
5920 struct da_softc *softc;
5924 cam_periph_assert(periph, MA_OWNED);
5925 softc = (struct da_softc *)periph->softc;
5927 if (((action == PR_ALLOW)
5928 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5929 || ((action == PR_PREVENT)
5930 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5934 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5936 scsi_prevent(&ccb->csio,
5944 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5945 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5948 if (action == PR_ALLOW)
5949 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5951 softc->flags |= DA_FLAG_PACK_LOCKED;
5954 xpt_release_ccb(ccb);
5958 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5959 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5961 struct ccb_calc_geometry ccg;
5962 struct da_softc *softc;
5963 struct disk_params *dp;
5964 u_int lbppbe, lalba;
5967 softc = (struct da_softc *)periph->softc;
5969 dp = &softc->params;
5970 dp->secsize = block_len;
5971 dp->sectors = maxsector + 1;
5972 if (rcaplong != NULL) {
5973 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5974 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5975 lalba &= SRC16_LALBA_A;
5982 dp->stripesize = block_len << lbppbe;
5983 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5985 } else if (softc->quirks & DA_Q_4K) {
5986 dp->stripesize = 4096;
5987 dp->stripeoffset = 0;
5988 } else if (softc->unmap_gran != 0) {
5989 dp->stripesize = block_len * softc->unmap_gran;
5990 dp->stripeoffset = (dp->stripesize - block_len *
5991 softc->unmap_gran_align) % dp->stripesize;
5994 dp->stripeoffset = 0;
5997 * Have the controller provide us with a geometry
5998 * for this disk. The only time the geometry
5999 * matters is when we boot and the controller
6000 * is the only one knowledgeable enough to come
6001 * up with something that will make this a bootable
6004 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6005 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
6006 ccg.block_size = dp->secsize;
6007 ccg.volume_size = dp->sectors;
6009 ccg.secs_per_track = 0;
6011 xpt_action((union ccb*)&ccg);
6012 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
6014 * We don't know what went wrong here- but just pick
6015 * a geometry so we don't have nasty things like divide
6019 dp->secs_per_track = 255;
6020 dp->cylinders = dp->sectors / (255 * 255);
6021 if (dp->cylinders == 0) {
6025 dp->heads = ccg.heads;
6026 dp->secs_per_track = ccg.secs_per_track;
6027 dp->cylinders = ccg.cylinders;
6031 * If the user supplied a read capacity buffer, and if it is
6032 * different than the previous buffer, update the data in the EDT.
6033 * If it's the same, we don't bother. This avoids sending an
6034 * update every time someone opens this device.
6036 if ((rcaplong != NULL)
6037 && (bcmp(rcaplong, &softc->rcaplong,
6038 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
6039 struct ccb_dev_advinfo cdai;
6041 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6042 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
6043 cdai.buftype = CDAI_TYPE_RCAPLONG;
6044 cdai.flags = CDAI_FLAG_STORE;
6045 cdai.bufsiz = rcap_len;
6046 cdai.buf = (uint8_t *)rcaplong;
6047 xpt_action((union ccb *)&cdai);
6048 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
6049 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
6050 if (cdai.ccb_h.status != CAM_REQ_CMP) {
6051 xpt_print(periph->path, "%s: failed to set read "
6052 "capacity advinfo\n", __func__);
6053 /* Use cam_error_print() to decode the status */
6054 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
6057 bcopy(rcaplong, &softc->rcaplong,
6058 min(sizeof(softc->rcaplong), rcap_len));
6062 softc->disk->d_sectorsize = softc->params.secsize;
6063 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
6064 softc->disk->d_stripesize = softc->params.stripesize;
6065 softc->disk->d_stripeoffset = softc->params.stripeoffset;
6066 /* XXX: these are not actually "firmware" values, so they may be wrong */
6067 softc->disk->d_fwsectors = softc->params.secs_per_track;
6068 softc->disk->d_fwheads = softc->params.heads;
6069 softc->disk->d_devstat->block_size = softc->params.secsize;
6070 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
6072 error = disk_resize(softc->disk, M_NOWAIT);
6074 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
6078 dasendorderedtag(void *arg)
6080 struct cam_periph *periph = arg;
6081 struct da_softc *softc = periph->softc;
6083 cam_periph_assert(periph, MA_OWNED);
6084 if (da_send_ordered) {
6085 if (!LIST_EMPTY(&softc->pending_ccbs)) {
6086 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
6087 softc->flags |= DA_FLAG_NEED_OTAG;
6088 softc->flags &= ~DA_FLAG_WAS_OTAG;
6092 /* Queue us up again */
6093 callout_reset(&softc->sendordered_c,
6094 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
6095 dasendorderedtag, periph);
6099 * Step through all DA peripheral drivers, and if the device is still open,
6100 * sync the disk cache to physical media.
6103 dashutdown(void * arg, int howto)
6105 struct cam_periph *periph;
6106 struct da_softc *softc;
6110 CAM_PERIPH_FOREACH(periph, &dadriver) {
6111 softc = (struct da_softc *)periph->softc;
6112 if (SCHEDULER_STOPPED()) {
6113 /* If we paniced with the lock held, do not recurse. */
6114 if (!cam_periph_owned(periph) &&
6115 (softc->flags & DA_FLAG_OPEN)) {
6116 dadump(softc->disk, NULL, 0, 0, 0);
6120 cam_periph_lock(periph);
6123 * We only sync the cache if the drive is still open, and
6124 * if the drive is capable of it..
6126 if (((softc->flags & DA_FLAG_OPEN) == 0)
6127 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
6128 cam_periph_unlock(periph);
6132 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
6133 scsi_synchronize_cache(&ccb->csio,
6137 /*begin_lba*/0, /* whole disk */
6142 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
6143 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
6144 softc->disk->d_devstat);
6146 xpt_print(periph->path, "Synchronize cache failed\n");
6147 xpt_release_ccb(ccb);
6148 cam_periph_unlock(periph);
6152 #else /* !_KERNEL */
6155 * XXX These are only left out of the kernel build to silence warnings. If,
6156 * for some reason these functions are used in the kernel, the ifdefs should
6157 * be moved so they are included both in the kernel and userland.
6160 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
6161 void (*cbfcnp)(struct cam_periph *, union ccb *),
6162 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
6163 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6166 struct scsi_format_unit *scsi_cmd;
6168 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
6169 scsi_cmd->opcode = FORMAT_UNIT;
6170 scsi_cmd->byte2 = byte2;
6171 scsi_ulto2b(ileave, scsi_cmd->interleave);
6176 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6186 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
6187 void (*cbfcnp)(struct cam_periph *, union ccb *),
6188 uint8_t tag_action, uint8_t list_format,
6189 uint32_t addr_desc_index, uint8_t *data_ptr,
6190 uint32_t dxfer_len, int minimum_cmd_size,
6191 uint8_t sense_len, uint32_t timeout)
6196 * These conditions allow using the 10 byte command. Otherwise we
6197 * need to use the 12 byte command.
6199 if ((minimum_cmd_size <= 10)
6200 && (addr_desc_index == 0)
6201 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
6202 struct scsi_read_defect_data_10 *cdb10;
6204 cdb10 = (struct scsi_read_defect_data_10 *)
6205 &csio->cdb_io.cdb_bytes;
6207 cdb_len = sizeof(*cdb10);
6208 bzero(cdb10, cdb_len);
6209 cdb10->opcode = READ_DEFECT_DATA_10;
6210 cdb10->format = list_format;
6211 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
6213 struct scsi_read_defect_data_12 *cdb12;
6215 cdb12 = (struct scsi_read_defect_data_12 *)
6216 &csio->cdb_io.cdb_bytes;
6218 cdb_len = sizeof(*cdb12);
6219 bzero(cdb12, cdb_len);
6220 cdb12->opcode = READ_DEFECT_DATA_12;
6221 cdb12->format = list_format;
6222 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
6223 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
6229 /*flags*/ CAM_DIR_IN,
6239 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
6240 void (*cbfcnp)(struct cam_periph *, union ccb *),
6241 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
6242 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6245 struct scsi_sanitize *scsi_cmd;
6247 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
6248 scsi_cmd->opcode = SANITIZE;
6249 scsi_cmd->byte2 = byte2;
6250 scsi_cmd->control = control;
6251 scsi_ulto2b(dxfer_len, scsi_cmd->length);
6256 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6265 #endif /* _KERNEL */
6268 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
6269 void (*cbfcnp)(struct cam_periph *, union ccb *),
6270 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
6271 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
6272 uint8_t sense_len, uint32_t timeout)
6274 struct scsi_zbc_out *scsi_cmd;
6276 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
6277 scsi_cmd->opcode = ZBC_OUT;
6278 scsi_cmd->service_action = service_action;
6279 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
6280 scsi_cmd->zone_flags = zone_flags;
6285 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6295 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
6296 void (*cbfcnp)(struct cam_periph *, union ccb *),
6297 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
6298 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
6299 uint8_t sense_len, uint32_t timeout)
6301 struct scsi_zbc_in *scsi_cmd;
6303 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
6304 scsi_cmd->opcode = ZBC_IN;
6305 scsi_cmd->service_action = service_action;
6306 scsi_ulto4b(dxfer_len, scsi_cmd->length);
6307 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
6308 scsi_cmd->zone_options = zone_options;
6313 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
6324 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
6325 void (*cbfcnp)(struct cam_periph *, union ccb *),
6326 uint8_t tag_action, int use_ncq,
6327 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6328 uint8_t *data_ptr, uint32_t dxfer_len,
6329 uint8_t *cdb_storage, size_t cdb_storage_len,
6330 uint8_t sense_len, uint32_t timeout)
6332 uint8_t command_out, protocol, ata_flags;
6333 uint16_t features_out;
6334 uint32_t sectors_out, auxiliary;
6340 command_out = ATA_ZAC_MANAGEMENT_OUT;
6341 features_out = (zm_action & 0xf) | (zone_flags << 8);
6342 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6343 if (dxfer_len == 0) {
6344 protocol = AP_PROTO_NON_DATA;
6345 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6348 protocol = AP_PROTO_DMA;
6349 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
6350 AP_FLAG_TDIR_TO_DEV;
6351 sectors_out = ((dxfer_len >> 9) & 0xffff);
6355 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6356 if (dxfer_len == 0) {
6357 command_out = ATA_NCQ_NON_DATA;
6358 features_out = ATA_NCQ_ZAC_MGMT_OUT;
6360 * We're assuming the SCSI to ATA translation layer
6361 * will set the NCQ tag number in the tag field.
6362 * That isn't clear from the SAT-4 spec (as of rev 05).
6365 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6367 command_out = ATA_SEND_FPDMA_QUEUED;
6369 * Note that we're defaulting to normal priority,
6370 * and assuming that the SCSI to ATA translation
6371 * layer will insert the NCQ tag number in the tag
6372 * field. That isn't clear in the SAT-4 spec (as
6375 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
6377 ata_flags |= AP_FLAG_TLEN_FEAT |
6378 AP_FLAG_TDIR_TO_DEV;
6381 * For SEND FPDMA QUEUED, the transfer length is
6382 * encoded in the FEATURE register, and 0 means
6383 * that 65536 512 byte blocks are to be tranferred.
6384 * In practice, it seems unlikely that we'll see
6385 * a transfer that large, and it may confuse the
6386 * the SAT layer, because generally that means that
6387 * 0 bytes should be transferred.
6389 if (dxfer_len == (65536 * 512)) {
6391 } else if (dxfer_len <= (65535 * 512)) {
6392 features_out = ((dxfer_len >> 9) & 0xffff);
6394 /* The transfer is too big. */
6401 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
6402 protocol = AP_PROTO_FPDMA;
6405 protocol |= AP_EXTEND;
6407 retval = scsi_ata_pass(csio,
6410 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6412 /*protocol*/ protocol,
6413 /*ata_flags*/ ata_flags,
6414 /*features*/ features_out,
6415 /*sector_count*/ sectors_out,
6417 /*command*/ command_out,
6420 /*auxiliary*/ auxiliary,
6422 /*data_ptr*/ data_ptr,
6423 /*dxfer_len*/ dxfer_len,
6424 /*cdb_storage*/ cdb_storage,
6425 /*cdb_storage_len*/ cdb_storage_len,
6426 /*minimum_cmd_size*/ 0,
6427 /*sense_len*/ SSD_FULL_SIZE,
6428 /*timeout*/ timeout);
6436 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
6437 void (*cbfcnp)(struct cam_periph *, union ccb *),
6438 uint8_t tag_action, int use_ncq,
6439 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6440 uint8_t *data_ptr, uint32_t dxfer_len,
6441 uint8_t *cdb_storage, size_t cdb_storage_len,
6442 uint8_t sense_len, uint32_t timeout)
6444 uint8_t command_out, protocol;
6445 uint16_t features_out, sectors_out;
6451 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
6454 command_out = ATA_ZAC_MANAGEMENT_IN;
6455 /* XXX KDM put a macro here */
6456 features_out = (zm_action & 0xf) | (zone_flags << 8);
6457 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
6458 protocol = AP_PROTO_DMA;
6459 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
6462 ata_flags |= AP_FLAG_TLEN_FEAT;
6464 command_out = ATA_RECV_FPDMA_QUEUED;
6465 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6468 * For RECEIVE FPDMA QUEUED, the transfer length is
6469 * encoded in the FEATURE register, and 0 means
6470 * that 65536 512 byte blocks are to be tranferred.
6471 * In practice, it seems unlikely that we'll see
6472 * a transfer that large, and it may confuse the
6473 * the SAT layer, because generally that means that
6474 * 0 bytes should be transferred.
6476 if (dxfer_len == (65536 * 512)) {
6478 } else if (dxfer_len <= (65535 * 512)) {
6479 features_out = ((dxfer_len >> 9) & 0xffff);
6481 /* The transfer is too big. */
6485 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6486 protocol = AP_PROTO_FPDMA;
6489 protocol |= AP_EXTEND;
6491 retval = scsi_ata_pass(csio,
6494 /*flags*/ CAM_DIR_IN,
6496 /*protocol*/ protocol,
6497 /*ata_flags*/ ata_flags,
6498 /*features*/ features_out,
6499 /*sector_count*/ sectors_out,
6501 /*command*/ command_out,
6504 /*auxiliary*/ auxiliary,
6506 /*data_ptr*/ data_ptr,
6507 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6508 /*cdb_storage*/ cdb_storage,
6509 /*cdb_storage_len*/ cdb_storage_len,
6510 /*minimum_cmd_size*/ 0,
6511 /*sense_len*/ SSD_FULL_SIZE,
6512 /*timeout*/ timeout);