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
124 DA_Q_NO_SYNC_CACHE = 0x01,
125 DA_Q_NO_6_BYTE = 0x02,
126 DA_Q_NO_PREVENT = 0x04,
129 DA_Q_NO_UNMAP = 0x20,
130 DA_Q_RETRY_BUSY = 0x40,
132 DA_Q_STRICT_UNMAP = 0x100
135 #define DA_Q_BIT_STRING \
137 "\001NO_SYNC_CACHE" \
148 DA_CCB_PROBE_RC = 0x01,
149 DA_CCB_PROBE_RC16 = 0x02,
150 DA_CCB_PROBE_LBP = 0x03,
151 DA_CCB_PROBE_BLK_LIMITS = 0x04,
152 DA_CCB_PROBE_BDC = 0x05,
153 DA_CCB_PROBE_ATA = 0x06,
154 DA_CCB_BUFFER_IO = 0x07,
156 DA_CCB_DELETE = 0x0B,
158 DA_CCB_PROBE_ZONE = 0x0D,
159 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
160 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
161 DA_CCB_PROBE_ATA_SUP = 0x10,
162 DA_CCB_PROBE_ATA_ZONE = 0x11,
163 DA_CCB_PROBE_WP = 0x12,
164 DA_CCB_TYPE_MASK = 0x1F,
165 DA_CCB_RETRY_UA = 0x20
169 * Order here is important for method choice
171 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
172 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
173 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
174 * import taking 5mins.
185 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
186 DA_DELETE_MAX = DA_DELETE_ZERO
190 * For SCSI, host managed drives show up as a separate device type. For
191 * ATA, host managed drives also have a different device signature.
192 * XXX KDM figure out the ATA host managed signature.
196 DA_ZONE_DRIVE_MANAGED = 0x01,
197 DA_ZONE_HOST_AWARE = 0x02,
198 DA_ZONE_HOST_MANAGED = 0x03
202 * We distinguish between these interface cases in addition to the drive type:
203 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
204 * o ATA drive behind a SCSI translation layer that does not know about
205 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
206 * case, we would need to share the ATA code with the ada(4) driver.
216 DA_ZONE_FLAG_RZ_SUP = 0x0001,
217 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
218 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
219 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
220 DA_ZONE_FLAG_RWP_SUP = 0x0010,
221 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
222 DA_ZONE_FLAG_OPEN_SUP |
223 DA_ZONE_FLAG_CLOSE_SUP |
224 DA_ZONE_FLAG_FINISH_SUP |
225 DA_ZONE_FLAG_RWP_SUP),
226 DA_ZONE_FLAG_URSWRZ = 0x0020,
227 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
228 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
229 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
230 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
231 DA_ZONE_FLAG_OPT_NONSEQ_SET |
232 DA_ZONE_FLAG_MAX_SEQ_SET)
235 static struct da_zone_desc {
238 } da_zone_desc_table[] = {
239 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
240 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
241 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
242 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
243 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
246 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
248 static da_delete_func_t da_delete_trim;
249 static da_delete_func_t da_delete_unmap;
250 static da_delete_func_t da_delete_ws;
252 static const void * da_delete_functions[] = {
262 static const char *da_delete_method_names[] =
263 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
264 static const char *da_delete_method_desc[] =
265 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
266 "WRITE SAME(10) with UNMAP", "ZERO" };
268 /* Offsets into our private area for storing information */
269 #define ccb_state ppriv_field0
270 #define ccb_bp ppriv_ptr1
275 u_int8_t secs_per_track;
276 u_int32_t secsize; /* Number of bytes/sector */
277 u_int64_t sectors; /* total number sectors */
282 #define UNMAP_RANGE_MAX 0xffffffff
283 #define UNMAP_HEAD_SIZE 8
284 #define UNMAP_RANGE_SIZE 16
285 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
286 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
289 #define WS10_MAX_BLKS 0xffff
290 #define WS16_MAX_BLKS 0xffffffff
291 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
292 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
294 #define DA_WORK_TUR (1 << 16)
305 DA_REF_MAX /* KEEP LAST */
309 struct cam_iosched_softc *cam_iosched;
310 struct bio_queue_head delete_run_queue;
311 LIST_HEAD(, ccb_hdr) pending_ccbs;
312 int refcount; /* Active xpt_action() calls */
316 int minimum_cmd_size;
319 int delete_available; /* Delete methods possibly available */
320 da_zone_mode zone_mode;
321 da_zone_interface zone_interface;
322 da_zone_flags zone_flags;
323 struct ata_gp_log_dir ata_logdir;
324 int valid_logdir_len;
325 struct ata_identify_log_pages ata_iddir;
327 uint64_t optimal_seq_zones;
328 uint64_t optimal_nonseq_zones;
329 uint64_t max_seq_zones;
331 uint32_t unmap_max_ranges;
332 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
334 uint32_t unmap_gran_align;
335 uint64_t ws_max_blks;
336 da_delete_methods delete_method_pref;
337 da_delete_methods delete_method;
338 da_delete_func_t *delete_func;
341 struct disk_params params;
344 struct task sysctl_task;
345 struct sysctl_ctx_list sysctl_ctx;
346 struct sysctl_oid *sysctl_tree;
347 struct callout sendordered_c;
349 uint8_t unmap_buf[UNMAP_BUF_SIZE];
350 struct scsi_read_capacity_data_long rcaplong;
351 struct callout mediapoll_c;
352 int ref_flags[DA_REF_MAX];
354 struct sysctl_ctx_list sysctl_stats_ctx;
355 struct sysctl_oid *sysctl_stats_tree;
360 #define DA_ANNOUNCETMP_SZ 80
361 char announce_temp[DA_ANNOUNCETMP_SZ];
362 #define DA_ANNOUNCE_SZ 400
363 char announcebuf[DA_ANNOUNCE_SZ];
366 #define dadeleteflag(softc, delete_method, enable) \
368 softc->delete_available |= (1 << delete_method); \
370 softc->delete_available &= ~(1 << delete_method); \
373 struct da_quirk_entry {
374 struct scsi_inquiry_pattern inq_pat;
378 static const char quantum[] = "QUANTUM";
379 static const char microp[] = "MICROP";
381 static struct da_quirk_entry da_quirk_table[] =
383 /* SPI, FC devices */
386 * Fujitsu M2513A MO drives.
387 * Tested devices: M2513A2 firmware versions 1200 & 1300.
388 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
389 * Reported by: W.Scholten <whs@xs4all.nl>
391 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
392 /*quirks*/ DA_Q_NO_SYNC_CACHE
396 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
397 /*quirks*/ DA_Q_NO_SYNC_CACHE
401 * This particular Fujitsu drive doesn't like the
402 * synchronize cache command.
403 * Reported by: Tom Jackson <toj@gorilla.net>
405 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
406 /*quirks*/ DA_Q_NO_SYNC_CACHE
410 * This drive doesn't like the synchronize cache command
411 * either. Reported by: Matthew Jacob <mjacob@feral.com>
412 * in NetBSD PR kern/6027, August 24, 1998.
414 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
415 /*quirks*/ DA_Q_NO_SYNC_CACHE
419 * This drive doesn't like the synchronize cache command
420 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
423 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
424 /*quirks*/ DA_Q_NO_SYNC_CACHE
428 * Doesn't like the synchronize cache command.
429 * Reported by: Blaz Zupan <blaz@gold.amis.net>
431 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
432 /*quirks*/ DA_Q_NO_SYNC_CACHE
436 * Doesn't like the synchronize cache command.
437 * Reported by: Blaz Zupan <blaz@gold.amis.net>
439 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
440 /*quirks*/ DA_Q_NO_SYNC_CACHE
444 * Doesn't like the synchronize cache command.
446 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
447 /*quirks*/ DA_Q_NO_SYNC_CACHE
451 * Doesn't like the synchronize cache command.
452 * Reported by: walter@pelissero.de
454 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
455 /*quirks*/ DA_Q_NO_SYNC_CACHE
459 * Doesn't work correctly with 6 byte reads/writes.
460 * Returns illegal request, and points to byte 9 of the
462 * Reported by: Adam McDougall <bsdx@spawnet.com>
464 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
465 /*quirks*/ DA_Q_NO_6_BYTE
469 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
470 /*quirks*/ DA_Q_NO_6_BYTE
474 * Doesn't like the synchronize cache command.
475 * Reported by: walter@pelissero.de
477 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
478 /*quirks*/ DA_Q_NO_SYNC_CACHE
482 * The CISS RAID controllers do not support SYNC_CACHE
484 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
485 /*quirks*/ DA_Q_NO_SYNC_CACHE
489 * The STEC SSDs sometimes hang on UNMAP.
491 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
492 /*quirks*/ DA_Q_NO_UNMAP
496 * VMware returns BUSY status when storage has transient
497 * connectivity problems, so better wait.
498 * Also VMware returns odd errors on misaligned UNMAPs.
500 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
501 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
503 /* USB mass storage devices supported by umass(4) */
506 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
509 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
510 /*quirks*/ DA_Q_NO_SYNC_CACHE
514 * Power Quotient Int. (PQI) USB flash key
517 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
518 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
522 * Creative Nomad MUVO mp3 player (USB)
525 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
526 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
530 * Jungsoft NEXDISK USB flash key
533 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
534 /*quirks*/ DA_Q_NO_SYNC_CACHE
538 * FreeDik USB Mini Data Drive
541 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
542 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
546 * Sigmatel USB Flash MP3 Player
549 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
550 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
554 * Neuros USB Digital Audio Computer
557 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
558 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
562 * SEAGRAND NP-900 MP3 Player
565 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
566 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
570 * iRiver iFP MP3 player (with UMS Firmware)
571 * PR: kern/54881, i386/63941, kern/66124
573 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
574 /*quirks*/ DA_Q_NO_SYNC_CACHE
578 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
581 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
582 /*quirks*/ DA_Q_NO_SYNC_CACHE
586 * ZICPlay USB MP3 Player with FM
589 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
590 /*quirks*/ DA_Q_NO_SYNC_CACHE
594 * TEAC USB floppy mechanisms
596 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
597 /*quirks*/ DA_Q_NO_SYNC_CACHE
601 * Kingston DataTraveler II+ USB Pen-Drive.
602 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
604 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
605 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
613 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
614 /*quirks*/ DA_Q_NO_SYNC_CACHE
618 * Motorola E398 Mobile Phone (TransFlash memory card).
619 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
622 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
623 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
627 * Qware BeatZkey! Pro
630 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
631 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
635 * Time DPA20B 1GB MP3 Player
638 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
639 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
643 * Samsung USB key 128Mb
646 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
647 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
651 * Kingston DataTraveler 2.0 USB Flash memory.
654 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
655 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
659 * Creative MUVO Slim mp3 player (USB)
662 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
663 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
667 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
670 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
671 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
675 * SanDisk Micro Cruzer 128MB
678 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
679 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
683 * TOSHIBA TransMemory USB sticks
686 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
687 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
691 * PNY USB 3.0 Flash Drives
693 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
694 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
699 * PR: usb/75578, usb/72344, usb/65436
701 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
702 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
708 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
709 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16
713 * Genesys 6-in-1 Card Reader
716 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
717 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
721 * Rekam Digital CAMERA
724 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
725 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
729 * iRiver H10 MP3 player
732 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
733 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
737 * iRiver U10 MP3 player
740 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
741 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
748 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
749 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
753 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
756 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
757 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
764 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
765 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
769 * Philips USB Key Audio KEY013
772 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
773 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
780 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
781 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
788 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
789 /*quirks*/ DA_Q_NO_SYNC_CACHE
793 * I/O Magic USB flash - Giga Bank
796 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
797 /*quirks*/ DA_Q_NO_SYNC_CACHE
801 * JoyFly 128mb USB Flash Drive
804 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
805 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
812 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
813 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
817 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
820 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
821 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
825 * Samsung YP-U3 mp3-player
828 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
829 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
832 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
833 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
837 * Sony Cyber-Shot DSC cameras
840 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
841 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
844 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
845 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
848 /* At least several Transcent USB sticks lie on RC16. */
849 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
850 "*"}, /*quirks*/ DA_Q_NO_RC16
854 * I-O Data USB Flash Disk
857 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
858 "*"}, /*quirks*/ DA_Q_NO_RC16
860 /* ATA/SATA devices over SAS/USB/... */
862 /* Hitachi Advanced Format (4k) drives */
863 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
867 /* Micron Advanced Format (4k) drives */
868 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
872 /* Samsung Advanced Format (4k) drives */
873 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
877 /* Samsung Advanced Format (4k) drives */
878 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
882 /* Samsung Advanced Format (4k) drives */
883 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
887 /* Samsung Advanced Format (4k) drives */
888 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
892 /* Seagate Barracuda Green Advanced Format (4k) drives */
893 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
897 /* Seagate Barracuda Green Advanced Format (4k) drives */
898 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
902 /* Seagate Barracuda Green Advanced Format (4k) drives */
903 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
907 /* Seagate Barracuda Green Advanced Format (4k) drives */
908 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
912 /* Seagate Barracuda Green Advanced Format (4k) drives */
913 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
917 /* Seagate Barracuda Green Advanced Format (4k) drives */
918 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
922 /* Seagate Momentus Advanced Format (4k) drives */
923 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
927 /* Seagate Momentus Advanced Format (4k) drives */
928 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
932 /* Seagate Momentus Advanced Format (4k) drives */
933 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
937 /* Seagate Momentus Advanced Format (4k) drives */
938 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
942 /* Seagate Momentus Advanced Format (4k) drives */
943 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
947 /* Seagate Momentus Advanced Format (4k) drives */
948 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
952 /* Seagate Momentus Advanced Format (4k) drives */
953 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
957 /* Seagate Momentus Advanced Format (4k) drives */
958 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
962 /* Seagate Momentus Advanced Format (4k) drives */
963 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
967 /* Seagate Momentus Advanced Format (4k) drives */
968 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
972 /* Seagate Momentus Advanced Format (4k) drives */
973 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
977 /* Seagate Momentus Advanced Format (4k) drives */
978 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
982 /* Seagate Momentus Advanced Format (4k) drives */
983 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
987 /* Seagate Momentus Advanced Format (4k) drives */
988 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
992 /* Seagate Momentus Thin Advanced Format (4k) drives */
993 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
997 /* Seagate Momentus Thin Advanced Format (4k) drives */
998 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
1002 /* WDC Caviar Green Advanced Format (4k) drives */
1003 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
1007 /* WDC Caviar Green Advanced Format (4k) drives */
1008 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
1012 /* WDC Caviar Green Advanced Format (4k) drives */
1013 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
1017 /* WDC Caviar Green Advanced Format (4k) drives */
1018 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
1022 /* WDC Caviar Green Advanced Format (4k) drives */
1023 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1027 /* WDC Caviar Green Advanced Format (4k) drives */
1028 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1032 /* WDC Caviar Green Advanced Format (4k) drives */
1033 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1037 /* WDC Caviar Green Advanced Format (4k) drives */
1038 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1042 /* WDC Scorpio Black Advanced Format (4k) drives */
1043 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1047 /* WDC Scorpio Black Advanced Format (4k) drives */
1048 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1052 /* WDC Scorpio Black Advanced Format (4k) drives */
1053 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1057 /* WDC Scorpio Black Advanced Format (4k) drives */
1058 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1062 /* WDC Scorpio Blue Advanced Format (4k) drives */
1063 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1067 /* WDC Scorpio Blue Advanced Format (4k) drives */
1068 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1072 /* WDC Scorpio Blue Advanced Format (4k) drives */
1073 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1077 /* WDC Scorpio Blue Advanced Format (4k) drives */
1078 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1083 * Olympus FE-210 camera
1085 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1086 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1090 * LG UP3S MP3 player
1092 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1093 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1097 * Laser MP3-2GA13 MP3 player
1099 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1100 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1104 * LaCie external 250GB Hard drive des by Porsche
1105 * Submitted by: Ben Stuyts <ben@altesco.nl>
1108 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1109 /*quirks*/ DA_Q_NO_SYNC_CACHE
1114 * Corsair Force 2 SSDs
1115 * 4k optimised & trim only works in 4k requests + 4k aligned
1117 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1122 * Corsair Force 3 SSDs
1123 * 4k optimised & trim only works in 4k requests + 4k aligned
1125 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1130 * Corsair Neutron GTX SSDs
1131 * 4k optimised & trim only works in 4k requests + 4k aligned
1133 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1138 * Corsair Force GT & GS SSDs
1139 * 4k optimised & trim only works in 4k requests + 4k aligned
1141 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1147 * 4k optimised & trim only works in 4k requests + 4k aligned
1149 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1154 * Crucial RealSSD C300 SSDs
1157 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1158 "*" }, /*quirks*/DA_Q_4K
1162 * Intel 320 Series SSDs
1163 * 4k optimised & trim only works in 4k requests + 4k aligned
1165 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1170 * Intel 330 Series SSDs
1171 * 4k optimised & trim only works in 4k requests + 4k aligned
1173 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1178 * Intel 510 Series SSDs
1179 * 4k optimised & trim only works in 4k requests + 4k aligned
1181 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1186 * Intel 520 Series SSDs
1187 * 4k optimised & trim only works in 4k requests + 4k aligned
1189 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1194 * Intel S3610 Series SSDs
1195 * 4k optimised & trim only works in 4k requests + 4k aligned
1197 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1202 * Intel X25-M Series SSDs
1203 * 4k optimised & trim only works in 4k requests + 4k aligned
1205 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1210 * Kingston E100 Series SSDs
1211 * 4k optimised & trim only works in 4k requests + 4k aligned
1213 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1218 * Kingston HyperX 3k SSDs
1219 * 4k optimised & trim only works in 4k requests + 4k aligned
1221 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1226 * Marvell SSDs (entry taken from OpenSolaris)
1227 * 4k optimised & trim only works in 4k requests + 4k aligned
1229 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1234 * OCZ Agility 2 SSDs
1235 * 4k optimised & trim only works in 4k requests + 4k aligned
1237 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1242 * OCZ Agility 3 SSDs
1243 * 4k optimised & trim only works in 4k requests + 4k aligned
1245 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1250 * OCZ Deneva R Series SSDs
1251 * 4k optimised & trim only works in 4k requests + 4k aligned
1253 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1258 * OCZ Vertex 2 SSDs (inc pro series)
1259 * 4k optimised & trim only works in 4k requests + 4k aligned
1261 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1267 * 4k optimised & trim only works in 4k requests + 4k aligned
1269 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1275 * 4k optimised & trim only works in 4k requests + 4k aligned
1277 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1282 * Samsung 750 Series SSDs
1283 * 4k optimised & trim only works in 4k requests + 4k aligned
1285 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" },
1290 * Samsung 830 Series SSDs
1291 * 4k optimised & trim only works in 4k requests + 4k aligned
1293 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1299 * 4k optimised & trim only works in 4k requests + 4k aligned
1301 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1307 * 4k optimised & trim only works in 4k requests + 4k aligned
1309 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" },
1315 * 4k optimised & trim only works in 4k requests + 4k aligned
1317 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1322 * Samsung 843T Series SSDs (MZ7WD*)
1323 * Samsung PM851 Series SSDs (MZ7TE*)
1324 * Samsung PM853T Series SSDs (MZ7GE*)
1325 * Samsung SM863 Series SSDs (MZ7KM*)
1328 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1333 * Same as for SAMSUNG MZ7* but enable the quirks for SSD
1334 * starting with MZ7* too
1336 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MZ7*", "*" },
1341 * SuperTalent TeraDrive CT SSDs
1342 * 4k optimised & trim only works in 4k requests + 4k aligned
1344 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1349 * XceedIOPS SATA SSDs
1352 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1357 * Hama Innostor USB-Stick
1359 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1360 /*quirks*/DA_Q_NO_RC16
1364 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1365 * Drive Managed SATA hard drive. This drive doesn't report
1366 * in firmware that it is a drive managed SMR drive.
1368 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS000[23]*", "*" },
1369 /*quirks*/DA_Q_SMR_DM
1373 * MX-ES USB Drive by Mach Xtreme
1375 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1376 /*quirks*/DA_Q_NO_RC16
1380 static disk_strategy_t dastrategy;
1381 static dumper_t dadump;
1382 static periph_init_t dainit;
1383 static void daasync(void *callback_arg, u_int32_t code,
1384 struct cam_path *path, void *arg);
1385 static void dasysctlinit(void *context, int pending);
1386 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1387 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1388 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1389 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1390 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1391 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1392 static void dadeletemethodset(struct da_softc *softc,
1393 da_delete_methods delete_method);
1394 static off_t dadeletemaxsize(struct da_softc *softc,
1395 da_delete_methods delete_method);
1396 static void dadeletemethodchoose(struct da_softc *softc,
1397 da_delete_methods default_method);
1398 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1400 static periph_ctor_t daregister;
1401 static periph_dtor_t dacleanup;
1402 static periph_start_t dastart;
1403 static periph_oninv_t daoninvalidate;
1404 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1405 static void dadone(struct cam_periph *periph,
1406 union ccb *done_ccb);
1407 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1408 u_int32_t sense_flags);
1409 static void daprevent(struct cam_periph *periph, int action);
1410 static void dareprobe(struct cam_periph *periph);
1411 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1413 struct scsi_read_capacity_data_long *rcaplong,
1415 static timeout_t dasendorderedtag;
1416 static void dashutdown(void *arg, int howto);
1417 static timeout_t damediapoll;
1419 #ifndef DA_DEFAULT_POLL_PERIOD
1420 #define DA_DEFAULT_POLL_PERIOD 3
1423 #ifndef DA_DEFAULT_TIMEOUT
1424 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1427 #ifndef DA_DEFAULT_SOFTTIMEOUT
1428 #define DA_DEFAULT_SOFTTIMEOUT 0
1431 #ifndef DA_DEFAULT_RETRY
1432 #define DA_DEFAULT_RETRY 4
1435 #ifndef DA_DEFAULT_SEND_ORDERED
1436 #define DA_DEFAULT_SEND_ORDERED 1
1439 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1440 static int da_retry_count = DA_DEFAULT_RETRY;
1441 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1442 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1443 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1445 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1446 "CAM Direct Access Disk driver");
1447 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1448 &da_poll_period, 0, "Media polling period in seconds");
1449 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1450 &da_retry_count, 0, "Normal I/O retry count");
1451 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1452 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1453 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1454 &da_send_ordered, 0, "Send Ordered Tags");
1456 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1457 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1458 "Soft I/O timeout (ms)");
1459 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1462 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1463 * to the default timeout, we check to see whether an ordered
1464 * tagged transaction is appropriate to prevent simple tag
1465 * starvation. Since we'd like to ensure that there is at least
1466 * 1/2 of the timeout length left for a starved transaction to
1467 * complete after we've sent an ordered tag, we must poll at least
1468 * four times in every timeout period. This takes care of the worst
1469 * case where a starved transaction starts during an interval that
1470 * meets the requirement "don't send an ordered tag" test so it takes
1471 * us two intervals to determine that a tag must be sent.
1473 #ifndef DA_ORDEREDTAG_INTERVAL
1474 #define DA_ORDEREDTAG_INTERVAL 4
1477 static struct periph_driver dadriver =
1480 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1483 PERIPHDRIVER_DECLARE(da, dadriver);
1485 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1488 * This driver takes out references / holds in well defined pairs, never
1489 * recursively. These macros / inline functions enforce those rules. They
1490 * are only enabled with DA_TRACK_REFS or INVARIANTS. If DA_TRACK_REFS is
1491 * defined to be 2 or larger, the tracking also includes debug printfs.
1493 #if defined(DA_TRACK_REFS) || defined(INVARIANTS)
1495 #ifndef DA_TRACK_REFS
1496 #define DA_TRACK_REFS 1
1499 #if DA_TRACK_REFS > 1
1500 static const char *da_ref_text[] = {
1513 #define DA_PERIPH_PRINT(periph, msg, args...) \
1514 CAM_PERIPH_PRINT(periph, msg, ##args)
1516 #define DA_PERIPH_PRINT(periph, msg, args...)
1520 token_sanity(da_ref_token token)
1522 if ((unsigned)token >= DA_REF_MAX)
1523 panic("Bad token value passed in %d\n", token);
1527 da_periph_hold(struct cam_periph *periph, int priority, da_ref_token token)
1529 int err = cam_periph_hold(periph, priority);
1531 token_sanity(token);
1532 DA_PERIPH_PRINT(periph, "Holding device %s (%d): %d\n",
1533 da_ref_text[token], token, err);
1536 struct da_softc *softc = periph->softc;
1538 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1540 panic("Re-holding for reason %d, cnt = %d", token, cnt);
1546 da_periph_unhold(struct cam_periph *periph, da_ref_token token)
1549 struct da_softc *softc = periph->softc;
1551 token_sanity(token);
1552 DA_PERIPH_PRINT(periph, "Unholding device %s (%d)\n",
1553 da_ref_text[token], token);
1554 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1556 panic("Unholding %d with cnt = %d", token, cnt);
1557 cam_periph_unhold(periph);
1561 da_periph_acquire(struct cam_periph *periph, da_ref_token token)
1563 int err = cam_periph_acquire(periph);
1565 token_sanity(token);
1566 DA_PERIPH_PRINT(periph, "acquiring device %s (%d): %d\n",
1567 da_ref_text[token], token, err);
1570 struct da_softc *softc = periph->softc;
1572 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1574 panic("Re-refing for reason %d, cnt = %d", token, cnt);
1580 da_periph_release(struct cam_periph *periph, da_ref_token token)
1583 struct da_softc *softc = periph->softc;
1585 token_sanity(token);
1586 DA_PERIPH_PRINT(periph, "releasing device %s (%d)\n",
1587 da_ref_text[token], token);
1588 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1590 panic("Releasing %d with cnt = %d", token, cnt);
1591 cam_periph_release(periph);
1595 da_periph_release_locked(struct cam_periph *periph, da_ref_token token)
1598 struct da_softc *softc = periph->softc;
1600 token_sanity(token);
1601 DA_PERIPH_PRINT(periph, "releasing device (locked) %s (%d)\n",
1602 da_ref_text[token], token);
1603 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1605 panic("Unholding %d with cnt = %d", token, cnt);
1606 cam_periph_release_locked(periph);
1609 #define cam_periph_hold POISON
1610 #define cam_periph_unhold POISON
1611 #define cam_periph_acquire POISON
1612 #define cam_periph_release POISON
1613 #define cam_periph_release_locked POISON
1616 #define da_periph_hold(periph, prio, token) cam_periph_hold((periph), (prio))
1617 #define da_periph_unhold(periph, token) cam_periph_unhold((periph))
1618 #define da_periph_acquire(periph, token) cam_periph_acquire((periph))
1619 #define da_periph_release(periph, token) cam_periph_release((periph))
1620 #define da_periph_release_locked(periph, token) cam_periph_release_locked((periph))
1624 daopen(struct disk *dp)
1626 struct cam_periph *periph;
1627 struct da_softc *softc;
1630 periph = (struct cam_periph *)dp->d_drv1;
1631 if (da_periph_acquire(periph, DA_REF_OPEN) != 0) {
1635 cam_periph_lock(periph);
1636 if ((error = da_periph_hold(periph, PRIBIO|PCATCH, DA_REF_OPEN_HOLD)) != 0) {
1637 cam_periph_unlock(periph);
1638 da_periph_release(periph, DA_REF_OPEN);
1642 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1645 softc = (struct da_softc *)periph->softc;
1648 /* Wait for the disk size update. */
1649 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1652 xpt_print(periph->path, "unable to retrieve capacity data\n");
1654 if (periph->flags & CAM_PERIPH_INVALID)
1657 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1658 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1659 daprevent(periph, PR_PREVENT);
1662 softc->flags &= ~DA_FLAG_PACK_INVALID;
1663 softc->flags |= DA_FLAG_OPEN;
1666 da_periph_unhold(periph, DA_REF_OPEN_HOLD);
1667 cam_periph_unlock(periph);
1670 da_periph_release(periph, DA_REF_OPEN);
1676 daclose(struct disk *dp)
1678 struct cam_periph *periph;
1679 struct da_softc *softc;
1682 periph = (struct cam_periph *)dp->d_drv1;
1683 softc = (struct da_softc *)periph->softc;
1684 cam_periph_lock(periph);
1685 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1688 if (da_periph_hold(periph, PRIBIO, DA_REF_CLOSE_HOLD) == 0) {
1690 /* Flush disk cache. */
1691 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1692 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1693 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1694 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1695 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1696 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1697 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1699 cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1700 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1701 softc->disk->d_devstat);
1702 softc->flags &= ~DA_FLAG_DIRTY;
1703 xpt_release_ccb(ccb);
1706 /* Allow medium removal. */
1707 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1708 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1709 daprevent(periph, PR_ALLOW);
1711 da_periph_unhold(periph, DA_REF_CLOSE_HOLD);
1715 * If we've got removeable media, mark the blocksize as
1716 * unavailable, since it could change when new media is
1719 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1720 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1722 softc->flags &= ~DA_FLAG_OPEN;
1723 while (softc->refcount != 0)
1724 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1725 cam_periph_unlock(periph);
1726 da_periph_release(periph, DA_REF_OPEN);
1731 daschedule(struct cam_periph *periph)
1733 struct da_softc *softc = (struct da_softc *)periph->softc;
1735 if (softc->state != DA_STATE_NORMAL)
1738 cam_iosched_schedule(softc->cam_iosched, periph);
1742 * Actually translate the requested transfer into one the physical driver
1743 * can understand. The transfer is described by a buf and will include
1744 * only one physical transfer.
1747 dastrategy(struct bio *bp)
1749 struct cam_periph *periph;
1750 struct da_softc *softc;
1752 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1753 softc = (struct da_softc *)periph->softc;
1755 cam_periph_lock(periph);
1758 * If the device has been made invalid, error out
1760 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1761 cam_periph_unlock(periph);
1762 biofinish(bp, NULL, ENXIO);
1766 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1769 * Zone commands must be ordered, because they can depend on the
1770 * effects of previously issued commands, and they may affect
1771 * commands after them.
1773 if (bp->bio_cmd == BIO_ZONE)
1774 bp->bio_flags |= BIO_ORDERED;
1777 * Place it in the queue of disk activities for this disk
1779 cam_iosched_queue_work(softc->cam_iosched, bp);
1782 * Schedule ourselves for performing the work.
1785 cam_periph_unlock(periph);
1791 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1793 struct cam_periph *periph;
1794 struct da_softc *softc;
1796 struct ccb_scsiio csio;
1801 periph = dp->d_drv1;
1802 softc = (struct da_softc *)periph->softc;
1803 secsize = softc->params.secsize;
1805 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0)
1808 memset(&csio, 0, sizeof(csio));
1810 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1811 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1812 scsi_read_write(&csio,
1816 /*read*/SCSI_RW_WRITE,
1818 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1821 /*data_ptr*/(u_int8_t *) virtual,
1822 /*dxfer_len*/length,
1823 /*sense_len*/SSD_FULL_SIZE,
1824 da_default_timeout * 1000);
1825 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1826 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1828 printf("Aborting dump due to I/O error.\n");
1833 * Sync the disk cache contents to the physical media.
1835 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1837 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1838 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1839 scsi_synchronize_cache(&csio,
1843 /*begin_lba*/0,/* Cover the whole disk */
1847 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1848 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1850 xpt_print(periph->path, "Synchronize cache failed\n");
1856 dagetattr(struct bio *bp)
1859 struct cam_periph *periph;
1861 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1862 cam_periph_lock(periph);
1863 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1865 cam_periph_unlock(periph);
1867 bp->bio_completed = bp->bio_length;
1877 * Install a global async callback. This callback will
1878 * receive async callbacks like "new device found".
1880 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1882 if (status != CAM_REQ_CMP) {
1883 printf("da: Failed to attach master async callback "
1884 "due to status 0x%x!\n", status);
1885 } else if (da_send_ordered) {
1887 /* Register our shutdown event handler */
1888 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1889 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1890 printf("dainit: shutdown event registration failed!\n");
1895 * Callback from GEOM, called when it has finished cleaning up its
1899 dadiskgonecb(struct disk *dp)
1901 struct cam_periph *periph;
1903 periph = (struct cam_periph *)dp->d_drv1;
1904 da_periph_release(periph, DA_REF_GEOM);
1908 daoninvalidate(struct cam_periph *periph)
1910 struct da_softc *softc;
1912 softc = (struct da_softc *)periph->softc;
1915 * De-register any async callbacks.
1917 xpt_register_async(0, daasync, periph, periph->path);
1919 softc->flags |= DA_FLAG_PACK_INVALID;
1921 softc->invalidations++;
1925 * Return all queued I/O with ENXIO.
1926 * XXX Handle any transactions queued to the card
1927 * with XPT_ABORT_CCB.
1929 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
1932 * Tell GEOM that we've gone away, we'll get a callback when it is
1933 * done cleaning up its resources.
1935 disk_gone(softc->disk);
1939 dacleanup(struct cam_periph *periph)
1941 struct da_softc *softc;
1943 softc = (struct da_softc *)periph->softc;
1945 cam_periph_unlock(periph);
1947 cam_iosched_fini(softc->cam_iosched);
1950 * If we can't free the sysctl tree, oh well...
1952 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
1954 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1955 xpt_print(periph->path,
1956 "can't remove sysctl stats context\n");
1958 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1959 xpt_print(periph->path,
1960 "can't remove sysctl context\n");
1963 callout_drain(&softc->mediapoll_c);
1964 disk_destroy(softc->disk);
1965 callout_drain(&softc->sendordered_c);
1966 free(softc, M_DEVBUF);
1967 cam_periph_lock(periph);
1971 daasync(void *callback_arg, u_int32_t code,
1972 struct cam_path *path, void *arg)
1974 struct cam_periph *periph;
1975 struct da_softc *softc;
1977 periph = (struct cam_periph *)callback_arg;
1979 case AC_FOUND_DEVICE:
1981 struct ccb_getdev *cgd;
1984 cgd = (struct ccb_getdev *)arg;
1988 if (cgd->protocol != PROTO_SCSI)
1990 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
1992 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1993 && SID_TYPE(&cgd->inq_data) != T_RBC
1994 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
1995 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
1999 * Allocate a peripheral instance for
2000 * this device and start the probe
2003 status = cam_periph_alloc(daregister, daoninvalidate,
2005 "da", CAM_PERIPH_BIO,
2007 AC_FOUND_DEVICE, cgd);
2009 if (status != CAM_REQ_CMP
2010 && status != CAM_REQ_INPROG)
2011 printf("daasync: Unable to attach to new device "
2012 "due to status 0x%x\n", status);
2015 case AC_ADVINFO_CHANGED:
2019 buftype = (uintptr_t)arg;
2020 if (buftype == CDAI_TYPE_PHYS_PATH) {
2021 struct da_softc *softc;
2023 softc = periph->softc;
2024 disk_attr_changed(softc->disk, "GEOM::physpath",
2029 case AC_UNIT_ATTENTION:
2032 int error_code, sense_key, asc, ascq;
2034 softc = (struct da_softc *)periph->softc;
2035 ccb = (union ccb *)arg;
2038 * Handle all UNIT ATTENTIONs except our own,
2039 * as they will be handled by daerror().
2041 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
2042 scsi_extract_sense_ccb(ccb,
2043 &error_code, &sense_key, &asc, &ascq)) {
2044 if (asc == 0x2A && ascq == 0x09) {
2045 xpt_print(ccb->ccb_h.path,
2046 "Capacity data has changed\n");
2047 softc->flags &= ~DA_FLAG_PROBED;
2049 } else if (asc == 0x28 && ascq == 0x00) {
2050 softc->flags &= ~DA_FLAG_PROBED;
2051 disk_media_changed(softc->disk, M_NOWAIT);
2052 } else if (asc == 0x3F && ascq == 0x03) {
2053 xpt_print(ccb->ccb_h.path,
2054 "INQUIRY data has changed\n");
2055 softc->flags &= ~DA_FLAG_PROBED;
2062 softc = (struct da_softc *)periph->softc;
2063 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2064 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
2065 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
2073 struct ccb_hdr *ccbh;
2075 softc = (struct da_softc *)periph->softc;
2077 * Don't fail on the expected unit attention
2080 softc->flags |= DA_FLAG_RETRY_UA;
2081 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
2082 ccbh->ccb_state |= DA_CCB_RETRY_UA;
2085 case AC_INQ_CHANGED:
2086 softc = (struct da_softc *)periph->softc;
2087 softc->flags &= ~DA_FLAG_PROBED;
2093 cam_periph_async(periph, code, path, arg);
2097 dasysctlinit(void *context, int pending)
2099 struct cam_periph *periph;
2100 struct da_softc *softc;
2101 char tmpstr[32], tmpstr2[16];
2102 struct ccb_trans_settings cts;
2104 periph = (struct cam_periph *)context;
2106 * periph was held for us when this task was enqueued
2108 if (periph->flags & CAM_PERIPH_INVALID) {
2109 da_periph_release(periph, DA_REF_SYSCTL);
2113 softc = (struct da_softc *)periph->softc;
2114 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
2115 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
2117 sysctl_ctx_init(&softc->sysctl_ctx);
2118 softc->flags |= DA_FLAG_SCTX_INIT;
2119 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
2120 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
2121 CTLFLAG_RD, 0, tmpstr, "device_index");
2122 if (softc->sysctl_tree == NULL) {
2123 printf("dasysctlinit: unable to allocate sysctl tree\n");
2124 da_periph_release(periph, DA_REF_SYSCTL);
2129 * Now register the sysctl handler, so the user can change the value on
2132 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2133 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
2134 softc, 0, dadeletemethodsysctl, "A",
2135 "BIO_DELETE execution method");
2136 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2137 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
2138 softc, 0, dadeletemaxsysctl, "Q",
2139 "Maximum BIO_DELETE size");
2140 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2141 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
2142 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
2143 "Minimum CDB size");
2145 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2146 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
2147 softc, 0, dazonemodesysctl, "A",
2149 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2150 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
2151 softc, 0, dazonesupsysctl, "A",
2153 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2154 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2155 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2156 "Optimal Number of Open Sequential Write Preferred Zones");
2157 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2158 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2159 "optimal_nonseq_zones", CTLFLAG_RD,
2160 &softc->optimal_nonseq_zones,
2161 "Optimal Number of Non-Sequentially Written Sequential Write "
2163 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2164 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2165 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2166 "Maximum Number of Open Sequential Write Required Zones");
2168 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2169 SYSCTL_CHILDREN(softc->sysctl_tree),
2173 &softc->error_inject,
2175 "error_inject leaf");
2177 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2178 SYSCTL_CHILDREN(softc->sysctl_tree),
2184 "Unmapped I/O leaf");
2186 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2187 SYSCTL_CHILDREN(softc->sysctl_tree),
2196 * Add some addressing info.
2198 memset(&cts, 0, sizeof (cts));
2199 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2200 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2201 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2202 cam_periph_lock(periph);
2203 xpt_action((union ccb *)&cts);
2204 cam_periph_unlock(periph);
2205 if (cts.ccb_h.status != CAM_REQ_CMP) {
2206 da_periph_release(periph, DA_REF_SYSCTL);
2209 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2210 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2211 if (fc->valid & CTS_FC_VALID_WWPN) {
2212 softc->wwpn = fc->wwpn;
2213 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2214 SYSCTL_CHILDREN(softc->sysctl_tree),
2215 OID_AUTO, "wwpn", CTLFLAG_RD,
2216 &softc->wwpn, "World Wide Port Name");
2222 * Now add some useful stats.
2223 * XXX These should live in cam_periph and be common to all periphs
2225 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2226 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2227 CTLFLAG_RD, 0, "Statistics");
2228 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2229 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2235 "Transport errors reported by the SIM");
2236 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2237 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2243 "Device timeouts reported by the SIM");
2244 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2245 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2247 "pack_invalidations",
2249 &softc->invalidations,
2251 "Device pack invalidations");
2254 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2255 softc->sysctl_tree);
2257 da_periph_release(periph, DA_REF_SYSCTL);
2261 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2265 struct da_softc *softc;
2267 softc = (struct da_softc *)arg1;
2269 value = softc->disk->d_delmaxsize;
2270 error = sysctl_handle_64(oidp, &value, 0, req);
2271 if ((error != 0) || (req->newptr == NULL))
2274 /* only accept values smaller than the calculated value */
2275 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2278 softc->disk->d_delmaxsize = value;
2284 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2288 value = *(int *)arg1;
2290 error = sysctl_handle_int(oidp, &value, 0, req);
2293 || (req->newptr == NULL))
2297 * Acceptable values here are 6, 10, 12 or 16.
2301 else if ((value > 6)
2304 else if ((value > 10)
2307 else if (value > 12)
2310 *(int *)arg1 = value;
2316 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2321 value = da_default_softtimeout / SBT_1MS;
2323 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2324 if ((error != 0) || (req->newptr == NULL))
2327 /* XXX Should clip this to a reasonable level */
2328 if (value > da_default_timeout * 1000)
2331 da_default_softtimeout = value * SBT_1MS;
2336 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2339 softc->delete_method = delete_method;
2340 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2341 softc->delete_func = da_delete_functions[delete_method];
2343 if (softc->delete_method > DA_DELETE_DISABLE)
2344 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2346 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2350 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2354 switch(delete_method) {
2355 case DA_DELETE_UNMAP:
2356 sectors = (off_t)softc->unmap_max_lba;
2358 case DA_DELETE_ATA_TRIM:
2359 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2361 case DA_DELETE_WS16:
2362 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2364 case DA_DELETE_ZERO:
2365 case DA_DELETE_WS10:
2366 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2372 return (off_t)softc->params.secsize *
2373 omin(sectors, softc->params.sectors);
2377 daprobedone(struct cam_periph *periph, union ccb *ccb)
2379 struct da_softc *softc;
2381 softc = (struct da_softc *)periph->softc;
2383 dadeletemethodchoose(softc, DA_DELETE_NONE);
2385 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2389 snprintf(buf, sizeof(buf), "Delete methods: <");
2391 for (i = 0; i <= DA_DELETE_MAX; i++) {
2392 if ((softc->delete_available & (1 << i)) == 0 &&
2393 i != softc->delete_method)
2396 strlcat(buf, ",", sizeof(buf));
2397 strlcat(buf, da_delete_method_names[i],
2399 if (i == softc->delete_method)
2400 strlcat(buf, "(*)", sizeof(buf));
2403 strlcat(buf, ">", sizeof(buf));
2404 printf("%s%d: %s\n", periph->periph_name,
2405 periph->unit_number, buf);
2409 * Since our peripheral may be invalidated by an error
2410 * above or an external event, we must release our CCB
2411 * before releasing the probe lock on the peripheral.
2412 * The peripheral will only go away once the last lock
2413 * is removed, and we need it around for the CCB release
2416 xpt_release_ccb(ccb);
2417 softc->state = DA_STATE_NORMAL;
2418 softc->flags |= DA_FLAG_PROBED;
2420 wakeup(&softc->disk->d_mediasize);
2421 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2422 softc->flags |= DA_FLAG_ANNOUNCED;
2423 da_periph_unhold(periph, DA_REF_PROBE_HOLD);
2425 da_periph_release_locked(periph, DA_REF_REPROBE);
2429 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2433 /* If available, prefer the method requested by user. */
2434 i = softc->delete_method_pref;
2435 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2436 if (methods & (1 << i)) {
2437 dadeletemethodset(softc, i);
2441 /* Use the pre-defined order to choose the best performing delete. */
2442 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2443 if (i == DA_DELETE_ZERO)
2445 if (softc->delete_available & (1 << i)) {
2446 dadeletemethodset(softc, i);
2451 /* Fallback to default. */
2452 dadeletemethodset(softc, default_method);
2456 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2460 struct da_softc *softc;
2461 int i, error, value;
2463 softc = (struct da_softc *)arg1;
2465 value = softc->delete_method;
2466 if (value < 0 || value > DA_DELETE_MAX)
2469 p = da_delete_method_names[value];
2470 strncpy(buf, p, sizeof(buf));
2471 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2472 if (error != 0 || req->newptr == NULL)
2474 for (i = 0; i <= DA_DELETE_MAX; i++) {
2475 if (strcmp(buf, da_delete_method_names[i]) == 0)
2478 if (i > DA_DELETE_MAX)
2480 softc->delete_method_pref = i;
2481 dadeletemethodchoose(softc, DA_DELETE_NONE);
2486 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2489 struct da_softc *softc;
2492 softc = (struct da_softc *)arg1;
2494 switch (softc->zone_mode) {
2495 case DA_ZONE_DRIVE_MANAGED:
2496 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2498 case DA_ZONE_HOST_AWARE:
2499 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2501 case DA_ZONE_HOST_MANAGED:
2502 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2506 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2510 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2516 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2519 struct da_softc *softc;
2524 softc = (struct da_softc *)arg1;
2528 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2530 for (i = 0; i < sizeof(da_zone_desc_table) /
2531 sizeof(da_zone_desc_table[0]); i++) {
2532 if (softc->zone_flags & da_zone_desc_table[i].value) {
2534 sbuf_printf(&sb, ", ");
2537 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2542 sbuf_printf(&sb, "None");
2546 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2552 daregister(struct cam_periph *periph, void *arg)
2554 struct da_softc *softc;
2555 struct ccb_pathinq cpi;
2556 struct ccb_getdev *cgd;
2560 cgd = (struct ccb_getdev *)arg;
2562 printf("daregister: no getdev CCB, can't register device\n");
2563 return(CAM_REQ_CMP_ERR);
2566 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2569 if (softc == NULL) {
2570 printf("daregister: Unable to probe new device. "
2571 "Unable to allocate softc\n");
2572 return(CAM_REQ_CMP_ERR);
2575 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2576 printf("daregister: Unable to probe new device. "
2577 "Unable to allocate iosched memory\n");
2578 free(softc, M_DEVBUF);
2579 return(CAM_REQ_CMP_ERR);
2582 LIST_INIT(&softc->pending_ccbs);
2583 softc->state = DA_STATE_PROBE_WP;
2584 bioq_init(&softc->delete_run_queue);
2585 if (SID_IS_REMOVABLE(&cgd->inq_data))
2586 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2587 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2588 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2589 softc->unmap_gran = 0;
2590 softc->unmap_gran_align = 0;
2591 softc->ws_max_blks = WS16_MAX_BLKS;
2592 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2593 softc->rotating = 1;
2595 periph->softc = softc;
2598 * See if this device has any quirks.
2600 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2601 (caddr_t)da_quirk_table,
2602 nitems(da_quirk_table),
2603 sizeof(*da_quirk_table), scsi_inquiry_match);
2606 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2608 softc->quirks = DA_Q_NONE;
2610 /* Check if the SIM does not want 6 byte commands */
2611 xpt_path_inq(&cpi, periph->path);
2612 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2613 softc->quirks |= DA_Q_NO_6_BYTE;
2615 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2616 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2617 else if (softc->quirks & DA_Q_SMR_DM)
2618 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2620 softc->zone_mode = DA_ZONE_NONE;
2622 if (softc->zone_mode != DA_ZONE_NONE) {
2623 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2624 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2625 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2627 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2629 softc->zone_interface = DA_ZONE_IF_SCSI;
2632 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2635 * Take an exclusive refcount on the periph while dastart is called
2636 * to finish the probe. The reference will be dropped in dadone at
2639 * XXX if cam_periph_hold returns an error, we don't hold a refcount.
2641 (void)da_periph_hold(periph, PRIBIO, DA_REF_PROBE_HOLD);
2644 * Schedule a periodic event to occasionally send an
2645 * ordered tag to a device.
2647 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2648 callout_reset(&softc->sendordered_c,
2649 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2650 dasendorderedtag, softc);
2652 cam_periph_unlock(periph);
2654 * RBC devices don't have to support READ(6), only READ(10).
2656 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2657 softc->minimum_cmd_size = 10;
2659 softc->minimum_cmd_size = 6;
2662 * Load the user's default, if any.
2664 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2665 periph->unit_number);
2666 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2669 * 6, 10, 12 and 16 are the currently permissible values.
2671 if (softc->minimum_cmd_size > 12)
2672 softc->minimum_cmd_size = 16;
2673 else if (softc->minimum_cmd_size > 10)
2674 softc->minimum_cmd_size = 12;
2675 else if (softc->minimum_cmd_size > 6)
2676 softc->minimum_cmd_size = 10;
2678 softc->minimum_cmd_size = 6;
2680 /* Predict whether device may support READ CAPACITY(16). */
2681 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2682 (softc->quirks & DA_Q_NO_RC16) == 0) {
2683 softc->flags |= DA_FLAG_CAN_RC16;
2687 * Register this media as a disk.
2689 softc->disk = disk_alloc();
2690 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2691 periph->unit_number, 0,
2692 DEVSTAT_BS_UNAVAILABLE,
2693 SID_TYPE(&cgd->inq_data) |
2694 XPORT_DEVSTAT_TYPE(cpi.transport),
2695 DEVSTAT_PRIORITY_DISK);
2696 softc->disk->d_open = daopen;
2697 softc->disk->d_close = daclose;
2698 softc->disk->d_strategy = dastrategy;
2699 softc->disk->d_dump = dadump;
2700 softc->disk->d_getattr = dagetattr;
2701 softc->disk->d_gone = dadiskgonecb;
2702 softc->disk->d_name = "da";
2703 softc->disk->d_drv1 = periph;
2705 softc->maxio = DFLTPHYS; /* traditional default */
2706 else if (cpi.maxio > MAXPHYS)
2707 softc->maxio = MAXPHYS; /* for safety */
2709 softc->maxio = cpi.maxio;
2710 softc->disk->d_maxsize = softc->maxio;
2711 softc->disk->d_unit = periph->unit_number;
2712 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2713 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2714 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2715 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2716 softc->unmappedio = 1;
2717 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2719 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2720 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2721 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2722 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2723 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2724 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2725 softc->disk->d_hba_vendor = cpi.hba_vendor;
2726 softc->disk->d_hba_device = cpi.hba_device;
2727 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2728 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2731 * Acquire a reference to the periph before we register with GEOM.
2732 * We'll release this reference once GEOM calls us back (via
2733 * dadiskgonecb()) telling us that our provider has been freed.
2735 if (da_periph_acquire(periph, DA_REF_GEOM) != 0) {
2736 xpt_print(periph->path, "%s: lost periph during "
2737 "registration!\n", __func__);
2738 cam_periph_lock(periph);
2739 return (CAM_REQ_CMP_ERR);
2742 disk_create(softc->disk, DISK_VERSION);
2743 cam_periph_lock(periph);
2746 * Add async callbacks for events of interest.
2747 * I don't bother checking if this fails as,
2748 * in most cases, the system will function just
2749 * fine without them and the only alternative
2750 * would be to not attach the device on failure.
2752 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2753 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2754 AC_INQ_CHANGED, daasync, periph, periph->path);
2757 * Emit an attribute changed notification just in case
2758 * physical path information arrived before our async
2759 * event handler was registered, but after anyone attaching
2760 * to our disk device polled it.
2762 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2765 * Schedule a periodic media polling events.
2767 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2768 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2769 (cgd->inq_flags & SID_AEN) == 0 &&
2770 da_poll_period != 0)
2771 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2772 damediapoll, periph);
2774 xpt_schedule(periph, CAM_PRIORITY_DEV);
2776 return(CAM_REQ_CMP);
2780 da_zone_bio_to_scsi(int disk_zone_cmd)
2782 switch (disk_zone_cmd) {
2783 case DISK_ZONE_OPEN:
2784 return ZBC_OUT_SA_OPEN;
2785 case DISK_ZONE_CLOSE:
2786 return ZBC_OUT_SA_CLOSE;
2787 case DISK_ZONE_FINISH:
2788 return ZBC_OUT_SA_FINISH;
2790 return ZBC_OUT_SA_RWP;
2797 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2800 struct da_softc *softc;
2805 if (bp->bio_cmd != BIO_ZONE) {
2810 softc = periph->softc;
2812 switch (bp->bio_zone.zone_cmd) {
2813 case DISK_ZONE_OPEN:
2814 case DISK_ZONE_CLOSE:
2815 case DISK_ZONE_FINISH:
2816 case DISK_ZONE_RWP: {
2821 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2822 if (zone_sa == -1) {
2823 xpt_print(periph->path, "Cannot translate zone "
2824 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2830 lba = bp->bio_zone.zone_params.rwp.id;
2832 if (bp->bio_zone.zone_params.rwp.flags &
2833 DISK_ZONE_RWP_FLAG_ALL)
2834 zone_flags |= ZBC_OUT_ALL;
2836 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2837 scsi_zbc_out(&ccb->csio,
2838 /*retries*/ da_retry_count,
2840 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2841 /*service_action*/ zone_sa,
2843 /*zone_flags*/ zone_flags,
2846 /*sense_len*/ SSD_FULL_SIZE,
2847 /*timeout*/ da_default_timeout * 1000);
2850 * Note that in this case, even though we can
2851 * technically use NCQ, we don't bother for several
2853 * 1. It hasn't been tested on a SAT layer that
2854 * supports it. This is new as of SAT-4.
2855 * 2. Even when there is a SAT layer that supports
2856 * it, that SAT layer will also probably support
2857 * ZBC -> ZAC translation, since they are both
2858 * in the SAT-4 spec.
2859 * 3. Translation will likely be preferable to ATA
2860 * passthrough. LSI / Avago at least single
2861 * steps ATA passthrough commands in the HBA,
2862 * regardless of protocol, so unless that
2863 * changes, there is a performance penalty for
2864 * doing ATA passthrough no matter whether
2865 * you're using NCQ/FPDMA, DMA or PIO.
2866 * 4. It requires a 32-byte CDB, which at least at
2867 * this point in CAM requires a CDB pointer, which
2868 * would require us to allocate an additional bit
2869 * of storage separate from the CCB.
2871 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2872 /*retries*/ da_retry_count,
2874 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2876 /*zm_action*/ zone_sa,
2878 /*zone_flags*/ zone_flags,
2881 /*cdb_storage*/ NULL,
2882 /*cdb_storage_len*/ 0,
2883 /*sense_len*/ SSD_FULL_SIZE,
2884 /*timeout*/ da_default_timeout * 1000);
2887 xpt_print(periph->path,
2888 "scsi_ata_zac_mgmt_out() returned an "
2897 case DISK_ZONE_REPORT_ZONES: {
2899 uint32_t num_entries, alloc_size;
2900 struct disk_zone_report *rep;
2902 rep = &bp->bio_zone.zone_params.report;
2904 num_entries = rep->entries_allocated;
2905 if (num_entries == 0) {
2906 xpt_print(periph->path, "No entries allocated for "
2907 "Report Zones request\n");
2911 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2912 (sizeof(struct scsi_report_zones_desc) * num_entries);
2913 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2914 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2915 if (rz_ptr == NULL) {
2916 xpt_print(periph->path, "Unable to allocate memory "
2917 "for Report Zones request\n");
2922 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2923 scsi_zbc_in(&ccb->csio,
2924 /*retries*/ da_retry_count,
2926 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2927 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2928 /*zone_start_lba*/ rep->starting_id,
2929 /*zone_options*/ rep->rep_options,
2930 /*data_ptr*/ rz_ptr,
2931 /*dxfer_len*/ alloc_size,
2932 /*sense_len*/ SSD_FULL_SIZE,
2933 /*timeout*/ da_default_timeout * 1000);
2936 * Note that in this case, even though we can
2937 * technically use NCQ, we don't bother for several
2939 * 1. It hasn't been tested on a SAT layer that
2940 * supports it. This is new as of SAT-4.
2941 * 2. Even when there is a SAT layer that supports
2942 * it, that SAT layer will also probably support
2943 * ZBC -> ZAC translation, since they are both
2944 * in the SAT-4 spec.
2945 * 3. Translation will likely be preferable to ATA
2946 * passthrough. LSI / Avago at least single
2947 * steps ATA passthrough commands in the HBA,
2948 * regardless of protocol, so unless that
2949 * changes, there is a performance penalty for
2950 * doing ATA passthrough no matter whether
2951 * you're using NCQ/FPDMA, DMA or PIO.
2952 * 4. It requires a 32-byte CDB, which at least at
2953 * this point in CAM requires a CDB pointer, which
2954 * would require us to allocate an additional bit
2955 * of storage separate from the CCB.
2957 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2958 /*retries*/ da_retry_count,
2960 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2962 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2963 /*zone_id*/ rep->starting_id,
2964 /*zone_flags*/ rep->rep_options,
2965 /*data_ptr*/ rz_ptr,
2966 /*dxfer_len*/ alloc_size,
2967 /*cdb_storage*/ NULL,
2968 /*cdb_storage_len*/ 0,
2969 /*sense_len*/ SSD_FULL_SIZE,
2970 /*timeout*/ da_default_timeout * 1000);
2973 xpt_print(periph->path,
2974 "scsi_ata_zac_mgmt_in() returned an "
2981 * For BIO_ZONE, this isn't normally needed. However, it
2982 * is used by devstat_end_transaction_bio() to determine
2983 * how much data was transferred.
2986 * XXX KDM we have a problem. But I'm not sure how to fix
2987 * it. devstat uses bio_bcount - bio_resid to calculate
2988 * the amount of data transferred. The GEOM disk code
2989 * uses bio_length - bio_resid to calculate the amount of
2990 * data in bio_completed. We have different structure
2991 * sizes above and below the ada(4) driver. So, if we
2992 * use the sizes above, the amount transferred won't be
2993 * quite accurate for devstat. If we use different sizes
2994 * for bio_bcount and bio_length (above and below
2995 * respectively), then the residual needs to match one or
2996 * the other. Everything is calculated after the bio
2997 * leaves the driver, so changing the values around isn't
2998 * really an option. For now, just set the count to the
2999 * passed in length. This means that the calculations
3000 * above (e.g. bio_completed) will be correct, but the
3001 * amount of data reported to devstat will be slightly
3002 * under or overstated.
3004 bp->bio_bcount = bp->bio_length;
3010 case DISK_ZONE_GET_PARAMS: {
3011 struct disk_zone_disk_params *params;
3013 params = &bp->bio_zone.zone_params.disk_params;
3014 bzero(params, sizeof(*params));
3016 switch (softc->zone_mode) {
3017 case DA_ZONE_DRIVE_MANAGED:
3018 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
3020 case DA_ZONE_HOST_AWARE:
3021 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
3023 case DA_ZONE_HOST_MANAGED:
3024 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
3028 params->zone_mode = DISK_ZONE_MODE_NONE;
3032 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
3033 params->flags |= DISK_ZONE_DISK_URSWRZ;
3035 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
3036 params->optimal_seq_zones = softc->optimal_seq_zones;
3037 params->flags |= DISK_ZONE_OPT_SEQ_SET;
3040 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
3041 params->optimal_nonseq_zones =
3042 softc->optimal_nonseq_zones;
3043 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
3046 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
3047 params->max_seq_zones = softc->max_seq_zones;
3048 params->flags |= DISK_ZONE_MAX_SEQ_SET;
3050 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
3051 params->flags |= DISK_ZONE_RZ_SUP;
3053 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
3054 params->flags |= DISK_ZONE_OPEN_SUP;
3056 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
3057 params->flags |= DISK_ZONE_CLOSE_SUP;
3059 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
3060 params->flags |= DISK_ZONE_FINISH_SUP;
3062 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
3063 params->flags |= DISK_ZONE_RWP_SUP;
3074 dastart(struct cam_periph *periph, union ccb *start_ccb)
3076 struct da_softc *softc;
3078 softc = (struct da_softc *)periph->softc;
3080 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
3083 switch (softc->state) {
3084 case DA_STATE_NORMAL:
3090 bp = cam_iosched_next_bio(softc->cam_iosched);
3092 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
3093 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
3094 scsi_test_unit_ready(&start_ccb->csio,
3095 /*retries*/ da_retry_count,
3099 da_default_timeout * 1000);
3100 start_ccb->ccb_h.ccb_bp = NULL;
3101 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
3102 xpt_action(start_ccb);
3104 xpt_release_ccb(start_ccb);
3108 if (bp->bio_cmd == BIO_DELETE) {
3109 if (softc->delete_func != NULL) {
3110 softc->delete_func(periph, start_ccb, bp);
3113 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
3114 biofinish(bp, NULL, 0);
3119 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
3120 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
3121 da_periph_release_locked(periph, DA_REF_TUR);
3124 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
3125 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
3126 softc->flags &= ~DA_FLAG_NEED_OTAG;
3127 softc->flags |= DA_FLAG_WAS_OTAG;
3128 tag_code = MSG_ORDERED_Q_TAG;
3130 tag_code = MSG_SIMPLE_Q_TAG;
3133 switch (bp->bio_cmd) {
3140 biotrack(bp, __func__);
3142 if (bp->bio_cmd == BIO_WRITE) {
3143 softc->flags |= DA_FLAG_DIRTY;
3144 rw_op = SCSI_RW_WRITE;
3146 rw_op = SCSI_RW_READ;
3149 data_ptr = bp->bio_data;
3150 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
3151 rw_op |= SCSI_RW_BIO;
3155 scsi_read_write(&start_ccb->csio,
3156 /*retries*/da_retry_count,
3158 /*tag_action*/tag_code,
3161 softc->minimum_cmd_size,
3162 /*lba*/bp->bio_pblkno,
3163 /*block_count*/bp->bio_bcount /
3164 softc->params.secsize,
3166 /*dxfer_len*/ bp->bio_bcount,
3167 /*sense_len*/SSD_FULL_SIZE,
3168 da_default_timeout * 1000);
3169 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3170 start_ccb->csio.bio = bp;
3176 * If we don't support sync cache, or the disk
3177 * isn't dirty, FLUSH is a no-op. Use the
3178 * allocated * CCB for the next bio if one is
3181 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) != 0 ||
3182 (softc->flags & DA_FLAG_DIRTY) == 0) {
3188 * BIO_FLUSH doesn't currently communicate
3189 * range data, so we synchronize the cache
3190 * over the whole disk. We also force
3191 * ordered tag semantics the flush applies
3192 * to all previously queued I/O.
3194 scsi_synchronize_cache(&start_ccb->csio,
3201 da_default_timeout*1000);
3203 * Clear the dirty flag before sending the command.
3204 * Either this sync cache will be successful, or it
3205 * will fail after a retry. If it fails, it is
3206 * unlikely to be successful if retried later, so
3207 * we'll save ourselves time by just marking the
3210 softc->flags &= ~DA_FLAG_DIRTY;
3213 int error, queue_ccb;
3217 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3219 || (queue_ccb == 0)) {
3220 biofinish(bp, NULL, error);
3221 xpt_release_ccb(start_ccb);
3227 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3228 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3229 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3232 LIST_INSERT_HEAD(&softc->pending_ccbs,
3233 &start_ccb->ccb_h, periph_links.le);
3235 /* We expect a unit attention from this device */
3236 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3237 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3238 softc->flags &= ~DA_FLAG_RETRY_UA;
3241 start_ccb->ccb_h.ccb_bp = bp;
3243 cam_periph_unlock(periph);
3244 xpt_action(start_ccb);
3245 cam_periph_lock(periph);
3248 /* May have more work to do, so ensure we stay scheduled */
3252 case DA_STATE_PROBE_WP:
3258 mode_buf = malloc(mode_buf_len, M_SCSIDA, M_NOWAIT);
3259 if (mode_buf == NULL) {
3260 xpt_print(periph->path, "Unable to send mode sense - "
3261 "malloc failure\n");
3262 softc->state = DA_STATE_PROBE_RC;
3265 scsi_mode_sense_len(&start_ccb->csio,
3266 /*retries*/ da_retry_count,
3268 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3270 /*pc*/ SMS_PAGE_CTRL_CURRENT,
3271 /*page*/ SMS_ALL_PAGES_PAGE,
3272 /*param_buf*/ mode_buf,
3273 /*param_len*/ mode_buf_len,
3274 /*minimum_cmd_size*/ softc->minimum_cmd_size,
3275 /*sense_len*/ SSD_FULL_SIZE,
3276 /*timeout*/ da_default_timeout * 1000);
3277 start_ccb->ccb_h.ccb_bp = NULL;
3278 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_WP;
3279 xpt_action(start_ccb);
3282 case DA_STATE_PROBE_RC:
3284 struct scsi_read_capacity_data *rcap;
3286 rcap = (struct scsi_read_capacity_data *)
3287 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3289 printf("dastart: Couldn't malloc read_capacity data\n");
3290 /* da_free_periph??? */
3293 scsi_read_capacity(&start_ccb->csio,
3294 /*retries*/da_retry_count,
3300 start_ccb->ccb_h.ccb_bp = NULL;
3301 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3302 xpt_action(start_ccb);
3305 case DA_STATE_PROBE_RC16:
3307 struct scsi_read_capacity_data_long *rcaplong;
3309 rcaplong = (struct scsi_read_capacity_data_long *)
3310 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3311 if (rcaplong == NULL) {
3312 printf("dastart: Couldn't malloc read_capacity data\n");
3313 /* da_free_periph??? */
3316 scsi_read_capacity_16(&start_ccb->csio,
3317 /*retries*/ da_retry_count,
3319 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3323 /*rcap_buf*/ (uint8_t *)rcaplong,
3324 /*rcap_buf_len*/ sizeof(*rcaplong),
3325 /*sense_len*/ SSD_FULL_SIZE,
3326 /*timeout*/ da_default_timeout * 1000);
3327 start_ccb->ccb_h.ccb_bp = NULL;
3328 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3329 xpt_action(start_ccb);
3332 case DA_STATE_PROBE_LBP:
3334 struct scsi_vpd_logical_block_prov *lbp;
3336 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3338 * If we get here we don't support any SBC-3 delete
3339 * methods with UNMAP as the Logical Block Provisioning
3340 * VPD page support is required for devices which
3341 * support it according to T10/1799-D Revision 31
3342 * however older revisions of the spec don't mandate
3343 * this so we currently don't remove these methods
3344 * from the available set.
3346 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3350 lbp = (struct scsi_vpd_logical_block_prov *)
3351 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3354 printf("dastart: Couldn't malloc lbp data\n");
3355 /* da_free_periph??? */
3359 scsi_inquiry(&start_ccb->csio,
3360 /*retries*/da_retry_count,
3362 /*tag_action*/MSG_SIMPLE_Q_TAG,
3363 /*inq_buf*/(u_int8_t *)lbp,
3364 /*inq_len*/sizeof(*lbp),
3366 /*page_code*/SVPD_LBP,
3367 /*sense_len*/SSD_MIN_SIZE,
3368 /*timeout*/da_default_timeout * 1000);
3369 start_ccb->ccb_h.ccb_bp = NULL;
3370 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3371 xpt_action(start_ccb);
3374 case DA_STATE_PROBE_BLK_LIMITS:
3376 struct scsi_vpd_block_limits *block_limits;
3378 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3379 /* Not supported skip to next probe */
3380 softc->state = DA_STATE_PROBE_BDC;
3384 block_limits = (struct scsi_vpd_block_limits *)
3385 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3387 if (block_limits == NULL) {
3388 printf("dastart: Couldn't malloc block_limits data\n");
3389 /* da_free_periph??? */
3393 scsi_inquiry(&start_ccb->csio,
3394 /*retries*/da_retry_count,
3396 /*tag_action*/MSG_SIMPLE_Q_TAG,
3397 /*inq_buf*/(u_int8_t *)block_limits,
3398 /*inq_len*/sizeof(*block_limits),
3400 /*page_code*/SVPD_BLOCK_LIMITS,
3401 /*sense_len*/SSD_MIN_SIZE,
3402 /*timeout*/da_default_timeout * 1000);
3403 start_ccb->ccb_h.ccb_bp = NULL;
3404 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3405 xpt_action(start_ccb);
3408 case DA_STATE_PROBE_BDC:
3410 struct scsi_vpd_block_characteristics *bdc;
3412 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3413 softc->state = DA_STATE_PROBE_ATA;
3417 bdc = (struct scsi_vpd_block_characteristics *)
3418 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3421 printf("dastart: Couldn't malloc bdc data\n");
3422 /* da_free_periph??? */
3426 scsi_inquiry(&start_ccb->csio,
3427 /*retries*/da_retry_count,
3429 /*tag_action*/MSG_SIMPLE_Q_TAG,
3430 /*inq_buf*/(u_int8_t *)bdc,
3431 /*inq_len*/sizeof(*bdc),
3433 /*page_code*/SVPD_BDC,
3434 /*sense_len*/SSD_MIN_SIZE,
3435 /*timeout*/da_default_timeout * 1000);
3436 start_ccb->ccb_h.ccb_bp = NULL;
3437 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3438 xpt_action(start_ccb);
3441 case DA_STATE_PROBE_ATA:
3443 struct ata_params *ata_params;
3445 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3446 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3447 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3449 * Note that if the ATA VPD page isn't
3450 * supported, we aren't talking to an ATA
3451 * device anyway. Support for that VPD
3452 * page is mandatory for SCSI to ATA (SAT)
3453 * translation layers.
3455 softc->state = DA_STATE_PROBE_ZONE;
3458 daprobedone(periph, start_ccb);
3462 ata_params = (struct ata_params*)
3463 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3465 if (ata_params == NULL) {
3466 xpt_print(periph->path, "Couldn't malloc ata_params "
3468 /* da_free_periph??? */
3472 scsi_ata_identify(&start_ccb->csio,
3473 /*retries*/da_retry_count,
3475 /*tag_action*/MSG_SIMPLE_Q_TAG,
3476 /*data_ptr*/(u_int8_t *)ata_params,
3477 /*dxfer_len*/sizeof(*ata_params),
3478 /*sense_len*/SSD_FULL_SIZE,
3479 /*timeout*/da_default_timeout * 1000);
3480 start_ccb->ccb_h.ccb_bp = NULL;
3481 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3482 xpt_action(start_ccb);
3485 case DA_STATE_PROBE_ATA_LOGDIR:
3487 struct ata_gp_log_dir *log_dir;
3492 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3494 * If we don't have log support, not much point in
3495 * trying to probe zone support.
3497 daprobedone(periph, start_ccb);
3502 * If we have an ATA device (the SCSI ATA Information VPD
3503 * page should be present and the ATA identify should have
3504 * succeeded) and it supports logs, ask for the log directory.
3507 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3508 if (log_dir == NULL) {
3509 xpt_print(periph->path, "Couldn't malloc log_dir "
3511 daprobedone(periph, start_ccb);
3515 retval = scsi_ata_read_log(&start_ccb->csio,
3516 /*retries*/ da_retry_count,
3518 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3519 /*log_address*/ ATA_LOG_DIRECTORY,
3522 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3523 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3524 /*data_ptr*/ (uint8_t *)log_dir,
3525 /*dxfer_len*/ sizeof(*log_dir),
3526 /*sense_len*/ SSD_FULL_SIZE,
3527 /*timeout*/ da_default_timeout * 1000);
3530 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3531 free(log_dir, M_SCSIDA);
3532 daprobedone(periph, start_ccb);
3535 start_ccb->ccb_h.ccb_bp = NULL;
3536 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3537 xpt_action(start_ccb);
3540 case DA_STATE_PROBE_ATA_IDDIR:
3542 struct ata_identify_log_pages *id_dir;
3548 * Check here to see whether the Identify Device log is
3549 * supported in the directory of logs. If so, continue
3550 * with requesting the log of identify device pages.
3552 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3553 daprobedone(periph, start_ccb);
3557 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3558 if (id_dir == NULL) {
3559 xpt_print(periph->path, "Couldn't malloc id_dir "
3561 daprobedone(periph, start_ccb);
3565 retval = scsi_ata_read_log(&start_ccb->csio,
3566 /*retries*/ da_retry_count,
3568 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3569 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3570 /*page_number*/ ATA_IDL_PAGE_LIST,
3572 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3573 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3574 /*data_ptr*/ (uint8_t *)id_dir,
3575 /*dxfer_len*/ sizeof(*id_dir),
3576 /*sense_len*/ SSD_FULL_SIZE,
3577 /*timeout*/ da_default_timeout * 1000);
3580 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3581 free(id_dir, M_SCSIDA);
3582 daprobedone(periph, start_ccb);
3585 start_ccb->ccb_h.ccb_bp = NULL;
3586 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3587 xpt_action(start_ccb);
3590 case DA_STATE_PROBE_ATA_SUP:
3592 struct ata_identify_log_sup_cap *sup_cap;
3598 * Check here to see whether the Supported Capabilities log
3599 * is in the list of Identify Device logs.
3601 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3602 daprobedone(periph, start_ccb);
3606 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3607 if (sup_cap == NULL) {
3608 xpt_print(periph->path, "Couldn't malloc sup_cap "
3610 daprobedone(periph, start_ccb);
3614 retval = scsi_ata_read_log(&start_ccb->csio,
3615 /*retries*/ da_retry_count,
3617 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3618 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3619 /*page_number*/ ATA_IDL_SUP_CAP,
3621 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3622 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3623 /*data_ptr*/ (uint8_t *)sup_cap,
3624 /*dxfer_len*/ sizeof(*sup_cap),
3625 /*sense_len*/ SSD_FULL_SIZE,
3626 /*timeout*/ da_default_timeout * 1000);
3629 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3630 free(sup_cap, M_SCSIDA);
3631 daprobedone(periph, start_ccb);
3636 start_ccb->ccb_h.ccb_bp = NULL;
3637 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3638 xpt_action(start_ccb);
3641 case DA_STATE_PROBE_ATA_ZONE:
3643 struct ata_zoned_info_log *ata_zone;
3649 * Check here to see whether the zoned device information
3650 * page is supported. If so, continue on to request it.
3651 * If not, skip to DA_STATE_PROBE_LOG or done.
3653 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3654 daprobedone(periph, start_ccb);
3657 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3659 if (ata_zone == NULL) {
3660 xpt_print(periph->path, "Couldn't malloc ata_zone "
3662 daprobedone(periph, start_ccb);
3666 retval = scsi_ata_read_log(&start_ccb->csio,
3667 /*retries*/ da_retry_count,
3669 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3670 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3671 /*page_number*/ ATA_IDL_ZDI,
3673 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3674 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3675 /*data_ptr*/ (uint8_t *)ata_zone,
3676 /*dxfer_len*/ sizeof(*ata_zone),
3677 /*sense_len*/ SSD_FULL_SIZE,
3678 /*timeout*/ da_default_timeout * 1000);
3681 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3682 free(ata_zone, M_SCSIDA);
3683 daprobedone(periph, start_ccb);
3686 start_ccb->ccb_h.ccb_bp = NULL;
3687 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3688 xpt_action(start_ccb);
3692 case DA_STATE_PROBE_ZONE:
3694 struct scsi_vpd_zoned_bdc *bdc;
3697 * Note that this page will be supported for SCSI protocol
3698 * devices that support ZBC (SMR devices), as well as ATA
3699 * protocol devices that are behind a SAT (SCSI to ATA
3700 * Translation) layer that supports converting ZBC commands
3701 * to their ZAC equivalents.
3703 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3704 daprobedone(periph, start_ccb);
3707 bdc = (struct scsi_vpd_zoned_bdc *)
3708 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3711 xpt_release_ccb(start_ccb);
3712 xpt_print(periph->path, "Couldn't malloc zone VPD "
3716 scsi_inquiry(&start_ccb->csio,
3717 /*retries*/da_retry_count,
3719 /*tag_action*/MSG_SIMPLE_Q_TAG,
3720 /*inq_buf*/(u_int8_t *)bdc,
3721 /*inq_len*/sizeof(*bdc),
3723 /*page_code*/SVPD_ZONED_BDC,
3724 /*sense_len*/SSD_FULL_SIZE,
3725 /*timeout*/da_default_timeout * 1000);
3726 start_ccb->ccb_h.ccb_bp = NULL;
3727 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3728 xpt_action(start_ccb);
3735 * In each of the methods below, while its the caller's
3736 * responsibility to ensure the request will fit into a
3737 * single device request, we might have changed the delete
3738 * method due to the device incorrectly advertising either
3739 * its supported methods or limits.
3741 * To prevent this causing further issues we validate the
3742 * against the methods limits, and warn which would
3743 * otherwise be unnecessary.
3746 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3748 struct da_softc *softc = (struct da_softc *)periph->softc;;
3750 uint8_t *buf = softc->unmap_buf;
3751 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3752 uint64_t lba, lastlba = (uint64_t)-1;
3753 uint64_t totalcount = 0;
3755 uint32_t c, lastcount = 0, ranges = 0;
3758 * Currently this doesn't take the UNMAP
3759 * Granularity and Granularity Alignment
3760 * fields into account.
3762 * This could result in both unoptimal unmap
3763 * requests as as well as UNMAP calls unmapping
3764 * fewer LBA's than requested.
3767 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3771 * Note: ada and da are different in how they store the
3772 * pending bp's in a trim. ada stores all of them in the
3773 * trim_req.bps. da stores all but the first one in the
3774 * delete_run_queue. ada then completes all the bps in
3775 * its adadone() loop. da completes all the bps in the
3776 * delete_run_queue in dadone, and relies on the biodone
3777 * after to complete. This should be reconciled since there's
3778 * no real reason to do it differently. XXX
3781 bioq_insert_tail(&softc->delete_run_queue, bp1);
3782 lba = bp1->bio_pblkno;
3783 count = bp1->bio_bcount / softc->params.secsize;
3785 /* Try to extend the previous range. */
3786 if (lba == lastlba) {
3787 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3790 scsi_ulto4b(lastcount, d[ranges - 1].length);
3794 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3795 softc->unmap_gran != 0) {
3796 /* Align length of the previous range. */
3797 if ((c = lastcount % softc->unmap_gran) != 0) {
3798 if (lastcount <= c) {
3799 totalcount -= lastcount;
3800 lastlba = (uint64_t)-1;
3807 scsi_ulto4b(lastcount, d[ranges - 1].length);
3810 /* Align beginning of the new range. */
3811 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3813 c = softc->unmap_gran - c;
3824 c = omin(count, UNMAP_RANGE_MAX);
3825 if (totalcount + c > softc->unmap_max_lba ||
3826 ranges >= softc->unmap_max_ranges) {
3827 xpt_print(periph->path,
3828 "%s issuing short delete %ld > %ld"
3830 da_delete_method_desc[softc->delete_method],
3831 totalcount + c, softc->unmap_max_lba,
3832 ranges, softc->unmap_max_ranges);
3835 scsi_u64to8b(lba, d[ranges].lba);
3836 scsi_ulto4b(c, d[ranges].length);
3844 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3847 if (ranges >= softc->unmap_max_ranges ||
3848 totalcount + bp1->bio_bcount /
3849 softc->params.secsize > softc->unmap_max_lba) {
3850 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3855 /* Align length of the last range. */
3856 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
3857 (c = lastcount % softc->unmap_gran) != 0) {
3861 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
3864 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3865 scsi_ulto2b(ranges * 16, &buf[2]);
3867 scsi_unmap(&ccb->csio,
3868 /*retries*/da_retry_count,
3870 /*tag_action*/MSG_SIMPLE_Q_TAG,
3873 /*dxfer_len*/ ranges * 16 + 8,
3874 /*sense_len*/SSD_FULL_SIZE,
3875 da_default_timeout * 1000);
3876 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3877 ccb->ccb_h.flags |= CAM_UNLOCKED;
3878 cam_iosched_submit_trim(softc->cam_iosched);
3882 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3884 struct da_softc *softc = (struct da_softc *)periph->softc;
3886 uint8_t *buf = softc->unmap_buf;
3887 uint64_t lastlba = (uint64_t)-1;
3890 uint32_t lastcount = 0, c, requestcount;
3891 int ranges = 0, off, block_count;
3893 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3896 if (bp1 != bp)//XXX imp XXX
3897 bioq_insert_tail(&softc->delete_run_queue, bp1);
3898 lba = bp1->bio_pblkno;
3899 count = bp1->bio_bcount / softc->params.secsize;
3900 requestcount = count;
3902 /* Try to extend the previous range. */
3903 if (lba == lastlba) {
3904 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3906 off = (ranges - 1) * 8;
3907 buf[off + 6] = lastcount & 0xff;
3908 buf[off + 7] = (lastcount >> 8) & 0xff;
3914 c = omin(count, ATA_DSM_RANGE_MAX);
3917 buf[off + 0] = lba & 0xff;
3918 buf[off + 1] = (lba >> 8) & 0xff;
3919 buf[off + 2] = (lba >> 16) & 0xff;
3920 buf[off + 3] = (lba >> 24) & 0xff;
3921 buf[off + 4] = (lba >> 32) & 0xff;
3922 buf[off + 5] = (lba >> 40) & 0xff;
3923 buf[off + 6] = c & 0xff;
3924 buf[off + 7] = (c >> 8) & 0xff;
3929 if (count != 0 && ranges == softc->trim_max_ranges) {
3930 xpt_print(periph->path,
3931 "%s issuing short delete %ld > %ld\n",
3932 da_delete_method_desc[softc->delete_method],
3934 (softc->trim_max_ranges - ranges) *
3940 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3943 if (bp1->bio_bcount / softc->params.secsize >
3944 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3945 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3950 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3951 scsi_ata_trim(&ccb->csio,
3952 /*retries*/da_retry_count,
3954 /*tag_action*/MSG_SIMPLE_Q_TAG,
3957 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3958 /*sense_len*/SSD_FULL_SIZE,
3959 da_default_timeout * 1000);
3960 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3961 ccb->ccb_h.flags |= CAM_UNLOCKED;
3962 cam_iosched_submit_trim(softc->cam_iosched);
3966 * We calculate ws_max_blks here based off d_delmaxsize instead
3967 * of using softc->ws_max_blks as it is absolute max for the
3968 * device not the protocol max which may well be lower.
3971 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3973 struct da_softc *softc;
3975 uint64_t ws_max_blks;
3977 uint64_t count; /* forward compat with WS32 */
3979 softc = (struct da_softc *)periph->softc;
3980 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3981 lba = bp->bio_pblkno;
3985 if (bp1 != bp)//XXX imp XXX
3986 bioq_insert_tail(&softc->delete_run_queue, bp1);
3987 count += bp1->bio_bcount / softc->params.secsize;
3988 if (count > ws_max_blks) {
3989 xpt_print(periph->path,
3990 "%s issuing short delete %ld > %ld\n",
3991 da_delete_method_desc[softc->delete_method],
3992 count, ws_max_blks);
3993 count = omin(count, ws_max_blks);
3996 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3999 if (lba + count != bp1->bio_pblkno ||
4000 count + bp1->bio_bcount /
4001 softc->params.secsize > ws_max_blks) {
4002 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4007 scsi_write_same(&ccb->csio,
4008 /*retries*/da_retry_count,
4010 /*tag_action*/MSG_SIMPLE_Q_TAG,
4011 /*byte2*/softc->delete_method ==
4012 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
4013 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
4015 /*block_count*/count,
4016 /*data_ptr*/ __DECONST(void *, zero_region),
4017 /*dxfer_len*/ softc->params.secsize,
4018 /*sense_len*/SSD_FULL_SIZE,
4019 da_default_timeout * 1000);
4020 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4021 ccb->ccb_h.flags |= CAM_UNLOCKED;
4022 cam_iosched_submit_trim(softc->cam_iosched);
4026 cmd6workaround(union ccb *ccb)
4028 struct scsi_rw_6 cmd6;
4029 struct scsi_rw_10 *cmd10;
4030 struct da_softc *softc;
4035 cdb = ccb->csio.cdb_io.cdb_bytes;
4036 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
4038 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
4039 da_delete_methods old_method = softc->delete_method;
4042 * Typically there are two reasons for failure here
4043 * 1. Delete method was detected as supported but isn't
4044 * 2. Delete failed due to invalid params e.g. too big
4046 * While we will attempt to choose an alternative delete method
4047 * this may result in short deletes if the existing delete
4048 * requests from geom are big for the new method chosen.
4050 * This method assumes that the error which triggered this
4051 * will not retry the io otherwise a panic will occur
4053 dadeleteflag(softc, old_method, 0);
4054 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
4055 if (softc->delete_method == DA_DELETE_DISABLE)
4056 xpt_print(ccb->ccb_h.path,
4057 "%s failed, disabling BIO_DELETE\n",
4058 da_delete_method_desc[old_method]);
4060 xpt_print(ccb->ccb_h.path,
4061 "%s failed, switching to %s BIO_DELETE\n",
4062 da_delete_method_desc[old_method],
4063 da_delete_method_desc[softc->delete_method]);
4065 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
4066 cam_iosched_queue_work(softc->cam_iosched, bp);
4067 cam_iosched_queue_work(softc->cam_iosched,
4068 (struct bio *)ccb->ccb_h.ccb_bp);
4069 ccb->ccb_h.ccb_bp = NULL;
4073 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
4074 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4075 (*cdb == PREVENT_ALLOW) &&
4076 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
4078 xpt_print(ccb->ccb_h.path,
4079 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
4080 softc->quirks |= DA_Q_NO_PREVENT;
4084 /* Detect unsupported SYNCHRONIZE CACHE(10). */
4085 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4086 (*cdb == SYNCHRONIZE_CACHE) &&
4087 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
4089 xpt_print(ccb->ccb_h.path,
4090 "SYNCHRONIZE CACHE(10) not supported.\n");
4091 softc->quirks |= DA_Q_NO_SYNC_CACHE;
4092 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
4096 /* Translation only possible if CDB is an array and cmd is R/W6 */
4097 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
4098 (*cdb != READ_6 && *cdb != WRITE_6))
4101 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
4102 "increasing minimum_cmd_size to 10.\n");
4103 softc->minimum_cmd_size = 10;
4105 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
4106 cmd10 = (struct scsi_rw_10 *)cdb;
4107 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
4109 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
4110 cmd10->reserved = 0;
4111 scsi_ulto2b(cmd6.length, cmd10->length);
4112 cmd10->control = cmd6.control;
4113 ccb->csio.cdb_len = sizeof(*cmd10);
4115 /* Requeue request, unfreezing queue if necessary */
4116 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
4117 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4120 cam_release_devq(ccb->ccb_h.path,
4124 /*getcount_only*/0);
4130 dazonedone(struct cam_periph *periph, union ccb *ccb)
4132 struct da_softc *softc;
4135 softc = periph->softc;
4136 bp = (struct bio *)ccb->ccb_h.ccb_bp;
4138 switch (bp->bio_zone.zone_cmd) {
4139 case DISK_ZONE_OPEN:
4140 case DISK_ZONE_CLOSE:
4141 case DISK_ZONE_FINISH:
4144 case DISK_ZONE_REPORT_ZONES: {
4146 struct disk_zone_report *rep;
4147 struct scsi_report_zones_hdr *hdr;
4148 struct scsi_report_zones_desc *desc;
4149 struct disk_zone_rep_entry *entry;
4150 uint32_t hdr_len, num_avail;
4151 uint32_t num_to_fill, i;
4154 rep = &bp->bio_zone.zone_params.report;
4155 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
4157 * Note that bio_resid isn't normally used for zone
4158 * commands, but it is used by devstat_end_transaction_bio()
4159 * to determine how much data was transferred. Because
4160 * the size of the SCSI/ATA data structures is different
4161 * than the size of the BIO interface structures, the
4162 * amount of data actually transferred from the drive will
4163 * be different than the amount of data transferred to
4166 bp->bio_resid = ccb->csio.resid;
4167 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
4168 if (avail_len < sizeof(*hdr)) {
4170 * Is there a better error than EIO here? We asked
4171 * for at least the header, and we got less than
4174 bp->bio_error = EIO;
4175 bp->bio_flags |= BIO_ERROR;
4176 bp->bio_resid = bp->bio_bcount;
4180 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4185 hdr_len = ata ? le32dec(hdr->length) :
4186 scsi_4btoul(hdr->length);
4188 rep->entries_available = hdr_len / sizeof(*desc);
4190 rep->entries_available = 0;
4192 * NOTE: using the same values for the BIO version of the
4193 * same field as the SCSI/ATA values. This means we could
4194 * get some additional values that aren't defined in bio.h
4195 * if more values of the same field are defined later.
4197 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4198 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4199 scsi_8btou64(hdr->maximum_lba);
4201 * If the drive reports no entries that match the query,
4205 rep->entries_filled = 0;
4209 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4210 hdr_len / sizeof(*desc));
4212 * If the drive didn't return any data, then we're done.
4214 if (num_avail == 0) {
4215 rep->entries_filled = 0;
4219 num_to_fill = min(num_avail, rep->entries_allocated);
4221 * If the user didn't allocate any entries for us to fill,
4224 if (num_to_fill == 0) {
4225 rep->entries_filled = 0;
4229 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4230 i < num_to_fill; i++, desc++, entry++) {
4232 * NOTE: we're mapping the values here directly
4233 * from the SCSI/ATA bit definitions to the bio.h
4234 * definitons. There is also a warning in
4235 * disk_zone.h, but the impact is that if
4236 * additional values are added in the SCSI/ATA
4237 * specs these will be visible to consumers of
4240 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4241 entry->zone_condition =
4242 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4243 SRZ_ZONE_COND_SHIFT;
4244 entry->zone_flags |= desc->zone_flags &
4245 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4246 entry->zone_length =
4247 ata ? le64dec(desc->zone_length) :
4248 scsi_8btou64(desc->zone_length);
4249 entry->zone_start_lba =
4250 ata ? le64dec(desc->zone_start_lba) :
4251 scsi_8btou64(desc->zone_start_lba);
4252 entry->write_pointer_lba =
4253 ata ? le64dec(desc->write_pointer_lba) :
4254 scsi_8btou64(desc->write_pointer_lba);
4256 rep->entries_filled = num_to_fill;
4259 case DISK_ZONE_GET_PARAMS:
4262 * In theory we should not get a GET_PARAMS bio, since it
4263 * should be handled without queueing the command to the
4266 panic("%s: Invalid zone command %d", __func__,
4267 bp->bio_zone.zone_cmd);
4271 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4272 free(ccb->csio.data_ptr, M_SCSIDA);
4276 dadone(struct cam_periph *periph, union ccb *done_ccb)
4278 struct da_softc *softc;
4279 struct ccb_scsiio *csio;
4283 softc = (struct da_softc *)periph->softc;
4284 priority = done_ccb->ccb_h.pinfo.priority;
4286 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4288 csio = &done_ccb->csio;
4289 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4290 if (csio->bio != NULL)
4291 biotrack(csio->bio, __func__);
4293 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4295 case DA_CCB_BUFFER_IO:
4298 struct bio *bp, *bp1;
4300 cam_periph_lock(periph);
4301 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4302 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4306 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4311 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4312 if (error == ERESTART) {
4314 * A retry was scheduled, so
4317 cam_periph_unlock(periph);
4320 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4325 * return all queued I/O with EIO, so that
4326 * the client can retry these I/Os in the
4327 * proper order should it attempt to recover.
4332 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4334 * Catastrophic error. Mark our pack as
4338 * XXX See if this is really a media
4341 xpt_print(periph->path,
4342 "Invalidating pack\n");
4343 softc->flags |= DA_FLAG_PACK_INVALID;
4345 softc->invalidations++;
4347 queued_error = ENXIO;
4349 cam_iosched_flush(softc->cam_iosched, NULL,
4352 bp->bio_error = error;
4353 bp->bio_resid = bp->bio_bcount;
4354 bp->bio_flags |= BIO_ERROR;
4356 } else if (bp != NULL) {
4357 if (state == DA_CCB_DELETE)
4360 bp->bio_resid = csio->resid;
4362 if (bp->bio_resid != 0)
4363 bp->bio_flags |= BIO_ERROR;
4365 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4366 cam_release_devq(done_ccb->ccb_h.path,
4370 /*getcount_only*/0);
4371 } else if (bp != NULL) {
4372 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4373 panic("REQ_CMP with QFRZN");
4374 if (bp->bio_cmd == BIO_ZONE)
4375 dazonedone(periph, done_ccb);
4376 else if (state == DA_CCB_DELETE)
4379 bp->bio_resid = csio->resid;
4380 if ((csio->resid > 0)
4381 && (bp->bio_cmd != BIO_ZONE))
4382 bp->bio_flags |= BIO_ERROR;
4383 if (softc->error_inject != 0) {
4384 bp->bio_error = softc->error_inject;
4385 bp->bio_resid = bp->bio_bcount;
4386 bp->bio_flags |= BIO_ERROR;
4387 softc->error_inject = 0;
4392 biotrack(bp, __func__);
4393 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4394 if (LIST_EMPTY(&softc->pending_ccbs))
4395 softc->flags |= DA_FLAG_WAS_OTAG;
4398 * We need to call cam_iosched before we call biodone so that we
4399 * don't measure any activity that happens in the completion
4400 * routine, which in the case of sendfile can be quite
4403 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4404 xpt_release_ccb(done_ccb);
4405 if (state == DA_CCB_DELETE) {
4406 TAILQ_HEAD(, bio) queue;
4409 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4410 softc->delete_run_queue.insert_point = NULL;
4412 * Normally, the xpt_release_ccb() above would make sure
4413 * that when we have more work to do, that work would
4414 * get kicked off. However, we specifically keep
4415 * delete_running set to 0 before the call above to
4416 * allow other I/O to progress when many BIO_DELETE
4417 * requests are pushed down. We set delete_running to 0
4418 * and call daschedule again so that we don't stall if
4419 * there are no other I/Os pending apart from BIO_DELETEs.
4421 cam_iosched_trim_done(softc->cam_iosched);
4423 cam_periph_unlock(periph);
4424 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4425 TAILQ_REMOVE(&queue, bp1, bio_queue);
4426 bp1->bio_error = bp->bio_error;
4427 if (bp->bio_flags & BIO_ERROR) {
4428 bp1->bio_flags |= BIO_ERROR;
4429 bp1->bio_resid = bp1->bio_bcount;
4436 cam_periph_unlock(periph);
4442 case DA_CCB_PROBE_WP:
4444 struct scsi_mode_header_6 *mode_hdr6;
4445 struct scsi_mode_header_10 *mode_hdr10;
4448 if (softc->minimum_cmd_size > 6) {
4449 mode_hdr10 = (struct scsi_mode_header_10 *)csio->data_ptr;
4450 dev_spec = mode_hdr10->dev_spec;
4452 mode_hdr6 = (struct scsi_mode_header_6 *)csio->data_ptr;
4453 dev_spec = mode_hdr6->dev_spec;
4455 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
4456 if ((dev_spec & 0x80) != 0)
4457 softc->disk->d_flags |= DISKFLAG_WRITE_PROTECT;
4459 softc->disk->d_flags &= ~DISKFLAG_WRITE_PROTECT;
4463 error = daerror(done_ccb, CAM_RETRY_SELTO,
4464 SF_RETRY_UA|SF_NO_PRINT);
4465 if (error == ERESTART)
4467 else if (error != 0) {
4468 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4469 /* Don't wedge this device's queue */
4470 cam_release_devq(done_ccb->ccb_h.path,
4474 /*getcount_only*/0);
4479 free(csio->data_ptr, M_SCSIDA);
4480 xpt_release_ccb(done_ccb);
4481 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
4482 softc->state = DA_STATE_PROBE_RC16;
4484 softc->state = DA_STATE_PROBE_RC;
4485 xpt_schedule(periph, priority);
4488 case DA_CCB_PROBE_RC:
4489 case DA_CCB_PROBE_RC16:
4491 struct scsi_read_capacity_data *rdcap;
4492 struct scsi_read_capacity_data_long *rcaplong;
4499 /* XXX TODO: can this be a malloc? */
4500 announce_buf = softc->announce_temp;
4501 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4503 if (state == DA_CCB_PROBE_RC)
4504 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4506 rcaplong = (struct scsi_read_capacity_data_long *)
4509 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4510 struct disk_params *dp;
4511 uint32_t block_size;
4513 u_int lalba; /* Lowest aligned LBA. */
4515 if (state == DA_CCB_PROBE_RC) {
4516 block_size = scsi_4btoul(rdcap->length);
4517 maxsector = scsi_4btoul(rdcap->addr);
4521 * According to SBC-2, if the standard 10
4522 * byte READ CAPACITY command returns 2^32,
4523 * we should issue the 16 byte version of
4524 * the command, since the device in question
4525 * has more sectors than can be represented
4526 * with the short version of the command.
4528 if (maxsector == 0xffffffff) {
4529 free(rdcap, M_SCSIDA);
4530 xpt_release_ccb(done_ccb);
4531 softc->state = DA_STATE_PROBE_RC16;
4532 xpt_schedule(periph, priority);
4536 block_size = scsi_4btoul(rcaplong->length);
4537 maxsector = scsi_8btou64(rcaplong->addr);
4538 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4542 * Because GEOM code just will panic us if we
4543 * give them an 'illegal' value we'll avoid that
4546 if (block_size == 0) {
4551 if (block_size >= MAXPHYS) {
4552 xpt_print(periph->path,
4553 "unsupportable block size %ju\n",
4554 (uintmax_t) block_size);
4555 announce_buf = NULL;
4556 cam_periph_invalidate(periph);
4559 * We pass rcaplong into dasetgeom(),
4560 * because it will only use it if it is
4563 dasetgeom(periph, block_size, maxsector,
4564 rcaplong, sizeof(*rcaplong));
4565 lbp = (lalba & SRC16_LBPME_A);
4566 dp = &softc->params;
4567 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4568 "%juMB (%ju %u byte sectors)",
4569 ((uintmax_t)dp->secsize * dp->sectors) /
4571 (uintmax_t)dp->sectors, dp->secsize);
4577 * Retry any UNIT ATTENTION type errors. They
4578 * are expected at boot.
4580 error = daerror(done_ccb, CAM_RETRY_SELTO,
4581 SF_RETRY_UA|SF_NO_PRINT);
4582 if (error == ERESTART) {
4584 * A retry was scheuled, so
4588 } else if (error != 0) {
4590 int sense_key, error_code;
4593 struct ccb_getdev cgd;
4595 /* Don't wedge this device's queue */
4596 status = done_ccb->ccb_h.status;
4597 if ((status & CAM_DEV_QFRZN) != 0)
4598 cam_release_devq(done_ccb->ccb_h.path,
4602 /*getcount_only*/0);
4605 xpt_setup_ccb(&cgd.ccb_h,
4606 done_ccb->ccb_h.path,
4607 CAM_PRIORITY_NORMAL);
4608 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4609 xpt_action((union ccb *)&cgd);
4611 if (scsi_extract_sense_ccb(done_ccb,
4612 &error_code, &sense_key, &asc, &ascq))
4618 * If we tried READ CAPACITY(16) and failed,
4619 * fallback to READ CAPACITY(10).
4621 if ((state == DA_CCB_PROBE_RC16) &&
4622 (softc->flags & DA_FLAG_CAN_RC16) &&
4623 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4626 (error_code == SSD_CURRENT_ERROR) &&
4627 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4628 softc->flags &= ~DA_FLAG_CAN_RC16;
4629 free(rdcap, M_SCSIDA);
4630 xpt_release_ccb(done_ccb);
4631 softc->state = DA_STATE_PROBE_RC;
4632 xpt_schedule(periph, priority);
4637 * Attach to anything that claims to be a
4638 * direct access or optical disk device,
4639 * as long as it doesn't return a "Logical
4640 * unit not supported" (0x25) error.
4641 * "Internal Target Failure" (0x44) is also
4642 * special and typically means that the
4643 * device is a SATA drive behind a SATL
4644 * translation that's fallen into a
4645 * terminally fatal state.
4648 && (asc != 0x25) && (asc != 0x44)
4649 && (error_code == SSD_CURRENT_ERROR)) {
4650 const char *sense_key_desc;
4651 const char *asc_desc;
4653 dasetgeom(periph, 512, -1, NULL, 0);
4654 scsi_sense_desc(sense_key, asc, ascq,
4658 snprintf(announce_buf,
4660 "Attempt to query device "
4661 "size failed: %s, %s",
4662 sense_key_desc, asc_desc);
4668 xpt_print(periph->path,
4669 "got CAM status %#x\n",
4670 done_ccb->ccb_h.status);
4673 xpt_print(periph->path, "fatal error, "
4674 "failed to attach to device\n");
4676 announce_buf = NULL;
4679 * Free up resources.
4681 cam_periph_invalidate(periph);
4685 free(csio->data_ptr, M_SCSIDA);
4686 if (announce_buf != NULL &&
4687 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4690 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4692 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4693 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4699 * Create our sysctl variables, now that we know
4700 * we have successfully attached.
4702 /* increase the refcount */
4703 if (da_periph_acquire(periph, DA_REF_SYSCTL) == 0) {
4705 taskqueue_enqueue(taskqueue_thread,
4706 &softc->sysctl_task);
4708 /* XXX This message is useless! */
4709 xpt_print(periph->path, "fatal error, "
4710 "could not acquire reference count\n");
4714 /* We already probed the device. */
4715 if (softc->flags & DA_FLAG_PROBED) {
4716 daprobedone(periph, done_ccb);
4720 /* Ensure re-probe doesn't see old delete. */
4721 softc->delete_available = 0;
4722 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4723 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4725 * Based on older SBC-3 spec revisions
4726 * any of the UNMAP methods "may" be
4727 * available via LBP given this flag so
4728 * we flag all of them as available and
4729 * then remove those which further
4730 * probes confirm aren't available
4733 * We could also check readcap(16) p_type
4734 * flag to exclude one or more invalid
4735 * write same (X) types here
4737 dadeleteflag(softc, DA_DELETE_WS16, 1);
4738 dadeleteflag(softc, DA_DELETE_WS10, 1);
4739 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4741 xpt_release_ccb(done_ccb);
4742 softc->state = DA_STATE_PROBE_LBP;
4743 xpt_schedule(periph, priority);
4747 xpt_release_ccb(done_ccb);
4748 softc->state = DA_STATE_PROBE_BDC;
4749 xpt_schedule(periph, priority);
4752 case DA_CCB_PROBE_LBP:
4754 struct scsi_vpd_logical_block_prov *lbp;
4756 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4758 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4760 * T10/1799-D Revision 31 states at least one of these
4761 * must be supported but we don't currently enforce this.
4763 dadeleteflag(softc, DA_DELETE_WS16,
4764 (lbp->flags & SVPD_LBP_WS16));
4765 dadeleteflag(softc, DA_DELETE_WS10,
4766 (lbp->flags & SVPD_LBP_WS10));
4767 dadeleteflag(softc, DA_DELETE_UNMAP,
4768 (lbp->flags & SVPD_LBP_UNMAP));
4771 error = daerror(done_ccb, CAM_RETRY_SELTO,
4772 SF_RETRY_UA|SF_NO_PRINT);
4773 if (error == ERESTART)
4775 else if (error != 0) {
4776 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4777 /* Don't wedge this device's queue */
4778 cam_release_devq(done_ccb->ccb_h.path,
4782 /*getcount_only*/0);
4786 * Failure indicates we don't support any SBC-3
4787 * delete methods with UNMAP
4792 free(lbp, M_SCSIDA);
4793 xpt_release_ccb(done_ccb);
4794 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4795 xpt_schedule(periph, priority);
4798 case DA_CCB_PROBE_BLK_LIMITS:
4800 struct scsi_vpd_block_limits *block_limits;
4802 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4804 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4805 uint32_t max_txfer_len = scsi_4btoul(
4806 block_limits->max_txfer_len);
4807 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4808 block_limits->max_unmap_lba_cnt);
4809 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4810 block_limits->max_unmap_blk_cnt);
4811 uint32_t unmap_gran = scsi_4btoul(
4812 block_limits->opt_unmap_grain);
4813 uint32_t unmap_gran_align = scsi_4btoul(
4814 block_limits->unmap_grain_align);
4815 uint64_t ws_max_blks = scsi_8btou64(
4816 block_limits->max_write_same_length);
4818 if (max_txfer_len != 0) {
4819 softc->disk->d_maxsize = MIN(softc->maxio,
4820 (off_t)max_txfer_len * softc->params.secsize);
4824 * We should already support UNMAP but we check lba
4825 * and block count to be sure
4827 if (max_unmap_lba_cnt != 0x00L &&
4828 max_unmap_blk_cnt != 0x00L) {
4829 softc->unmap_max_lba = max_unmap_lba_cnt;
4830 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4832 if (unmap_gran > 1) {
4833 softc->unmap_gran = unmap_gran;
4834 if (unmap_gran_align & 0x80000000) {
4835 softc->unmap_gran_align =
4842 * Unexpected UNMAP limits which means the
4843 * device doesn't actually support UNMAP
4845 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4848 if (ws_max_blks != 0x00L)
4849 softc->ws_max_blks = ws_max_blks;
4852 error = daerror(done_ccb, CAM_RETRY_SELTO,
4853 SF_RETRY_UA|SF_NO_PRINT);
4854 if (error == ERESTART)
4856 else if (error != 0) {
4857 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4858 /* Don't wedge this device's queue */
4859 cam_release_devq(done_ccb->ccb_h.path,
4863 /*getcount_only*/0);
4867 * Failure here doesn't mean UNMAP is not
4868 * supported as this is an optional page.
4870 softc->unmap_max_lba = 1;
4871 softc->unmap_max_ranges = 1;
4875 free(block_limits, M_SCSIDA);
4876 xpt_release_ccb(done_ccb);
4877 softc->state = DA_STATE_PROBE_BDC;
4878 xpt_schedule(periph, priority);
4881 case DA_CCB_PROBE_BDC:
4883 struct scsi_vpd_block_device_characteristics *bdc;
4885 bdc = (struct scsi_vpd_block_device_characteristics *)
4888 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4892 * Disable queue sorting for non-rotational media
4895 u_int16_t old_rate = softc->disk->d_rotation_rate;
4897 valid_len = csio->dxfer_len - csio->resid;
4898 if (SBDC_IS_PRESENT(bdc, valid_len,
4899 medium_rotation_rate)) {
4900 softc->disk->d_rotation_rate =
4901 scsi_2btoul(bdc->medium_rotation_rate);
4902 if (softc->disk->d_rotation_rate ==
4903 SVPD_BDC_RATE_NON_ROTATING) {
4904 cam_iosched_set_sort_queue(
4905 softc->cam_iosched, 0);
4906 softc->rotating = 0;
4908 if (softc->disk->d_rotation_rate != old_rate) {
4909 disk_attr_changed(softc->disk,
4910 "GEOM::rotation_rate", M_NOWAIT);
4913 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4914 && (softc->zone_mode == DA_ZONE_NONE)) {
4917 if (scsi_vpd_supported_page(periph,
4918 SVPD_ATA_INFORMATION))
4924 * The Zoned field will only be set for
4925 * Drive Managed and Host Aware drives. If
4926 * they are Host Managed, the device type
4927 * in the standard INQUIRY data should be
4928 * set to T_ZBC_HM (0x14).
4930 if ((bdc->flags & SVPD_ZBC_MASK) ==
4932 softc->zone_mode = DA_ZONE_HOST_AWARE;
4933 softc->zone_interface = (ata_proto) ?
4934 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4935 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4937 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4938 softc->zone_interface = (ata_proto) ?
4939 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4940 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4942 xpt_print(periph->path, "Unknown zoned "
4944 bdc->flags & SVPD_ZBC_MASK);
4949 error = daerror(done_ccb, CAM_RETRY_SELTO,
4950 SF_RETRY_UA|SF_NO_PRINT);
4951 if (error == ERESTART)
4953 else if (error != 0) {
4954 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4955 /* Don't wedge this device's queue */
4956 cam_release_devq(done_ccb->ccb_h.path,
4960 /*getcount_only*/0);
4965 free(bdc, M_SCSIDA);
4966 xpt_release_ccb(done_ccb);
4967 softc->state = DA_STATE_PROBE_ATA;
4968 xpt_schedule(periph, priority);
4971 case DA_CCB_PROBE_ATA:
4974 struct ata_params *ata_params;
4979 ata_params = (struct ata_params *)csio->data_ptr;
4980 ptr = (uint16_t *)ata_params;
4984 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4987 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4988 ptr[i] = le16toh(ptr[i]);
4989 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4990 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4991 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4992 if (ata_params->max_dsm_blocks != 0)
4993 softc->trim_max_ranges = min(
4994 softc->trim_max_ranges,
4995 ata_params->max_dsm_blocks *
4996 ATA_DSM_BLK_RANGES);
4999 * Disable queue sorting for non-rotational media
5002 old_rate = softc->disk->d_rotation_rate;
5003 softc->disk->d_rotation_rate =
5004 ata_params->media_rotation_rate;
5005 if (softc->disk->d_rotation_rate ==
5006 ATA_RATE_NON_ROTATING) {
5007 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
5008 softc->rotating = 0;
5010 if (softc->disk->d_rotation_rate != old_rate) {
5011 disk_attr_changed(softc->disk,
5012 "GEOM::rotation_rate", M_NOWAIT);
5015 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
5016 softc->flags |= DA_FLAG_CAN_ATA_DMA;
5018 if (ata_params->support.extension &
5020 softc->flags |= DA_FLAG_CAN_ATA_LOG;
5023 * At this point, if we have a SATA host aware drive,
5024 * we communicate via ATA passthrough unless the
5025 * SAT layer supports ZBC -> ZAC translation. In
5029 * XXX KDM figure out how to detect a host managed
5032 if (softc->zone_mode == DA_ZONE_NONE) {
5034 * Note that we don't override the zone
5035 * mode or interface if it has already been
5036 * set. This is because it has either been
5037 * set as a quirk, or when we probed the
5038 * SCSI Block Device Characteristics page,
5039 * the zoned field was set. The latter
5040 * means that the SAT layer supports ZBC to
5041 * ZAC translation, and we would prefer to
5042 * use that if it is available.
5044 if ((ata_params->support3 &
5045 ATA_SUPPORT_ZONE_MASK) ==
5046 ATA_SUPPORT_ZONE_HOST_AWARE) {
5047 softc->zone_mode = DA_ZONE_HOST_AWARE;
5048 softc->zone_interface =
5049 DA_ZONE_IF_ATA_PASS;
5050 } else if ((ata_params->support3 &
5051 ATA_SUPPORT_ZONE_MASK) ==
5052 ATA_SUPPORT_ZONE_DEV_MANAGED) {
5053 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5054 softc->zone_interface =
5055 DA_ZONE_IF_ATA_PASS;
5060 error = daerror(done_ccb, CAM_RETRY_SELTO,
5061 SF_RETRY_UA|SF_NO_PRINT);
5062 if (error == ERESTART)
5064 else if (error != 0) {
5065 if ((done_ccb->ccb_h.status &
5066 CAM_DEV_QFRZN) != 0) {
5067 /* Don't wedge this device's queue */
5068 cam_release_devq(done_ccb->ccb_h.path,
5072 /*getcount_only*/0);
5077 free(ata_params, M_SCSIDA);
5078 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
5079 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
5081 * If the ATA IDENTIFY failed, we could be talking
5082 * to a SCSI drive, although that seems unlikely,
5083 * since the drive did report that it supported the
5084 * ATA Information VPD page. If the ATA IDENTIFY
5085 * succeeded, and the SAT layer doesn't support
5086 * ZBC -> ZAC translation, continue on to get the
5087 * directory of ATA logs, and complete the rest of
5088 * the ZAC probe. If the SAT layer does support
5089 * ZBC -> ZAC translation, we want to use that,
5090 * and we'll probe the SCSI Zoned Block Device
5091 * Characteristics VPD page next.
5094 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
5095 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
5096 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
5098 softc->state = DA_STATE_PROBE_ZONE;
5101 if (continue_probe != 0) {
5102 xpt_release_ccb(done_ccb);
5103 xpt_schedule(periph, priority);
5106 daprobedone(periph, done_ccb);
5109 case DA_CCB_PROBE_ATA_LOGDIR:
5113 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5115 softc->valid_logdir_len = 0;
5116 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
5117 softc->valid_logdir_len =
5118 csio->dxfer_len - csio->resid;
5119 if (softc->valid_logdir_len > 0)
5120 bcopy(csio->data_ptr, &softc->ata_logdir,
5121 min(softc->valid_logdir_len,
5122 sizeof(softc->ata_logdir)));
5124 * Figure out whether the Identify Device log is
5125 * supported. The General Purpose log directory
5126 * has a header, and lists the number of pages
5127 * available for each GP log identified by the
5128 * offset into the list.
5130 if ((softc->valid_logdir_len >=
5131 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
5132 && (le16dec(softc->ata_logdir.header) ==
5133 ATA_GP_LOG_DIR_VERSION)
5134 && (le16dec(&softc->ata_logdir.num_pages[
5135 (ATA_IDENTIFY_DATA_LOG *
5136 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
5137 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
5139 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5142 error = daerror(done_ccb, CAM_RETRY_SELTO,
5143 SF_RETRY_UA|SF_NO_PRINT);
5144 if (error == ERESTART)
5146 else if (error != 0) {
5148 * If we can't get the ATA log directory,
5149 * then ATA logs are effectively not
5150 * supported even if the bit is set in the
5153 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
5154 DA_FLAG_CAN_ATA_IDLOG);
5155 if ((done_ccb->ccb_h.status &
5156 CAM_DEV_QFRZN) != 0) {
5157 /* Don't wedge this device's queue */
5158 cam_release_devq(done_ccb->ccb_h.path,
5162 /*getcount_only*/0);
5167 free(csio->data_ptr, M_SCSIDA);
5170 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
5171 softc->state = DA_STATE_PROBE_ATA_IDDIR;
5172 xpt_release_ccb(done_ccb);
5173 xpt_schedule(periph, priority);
5176 daprobedone(periph, done_ccb);
5179 case DA_CCB_PROBE_ATA_IDDIR:
5183 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5184 off_t entries_offset, max_entries;
5187 softc->valid_iddir_len = 0;
5188 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
5189 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
5190 DA_FLAG_CAN_ATA_ZONE);
5191 softc->valid_iddir_len =
5192 csio->dxfer_len - csio->resid;
5193 if (softc->valid_iddir_len > 0)
5194 bcopy(csio->data_ptr, &softc->ata_iddir,
5195 min(softc->valid_iddir_len,
5196 sizeof(softc->ata_iddir)));
5199 __offsetof(struct ata_identify_log_pages,entries);
5200 max_entries = softc->valid_iddir_len - entries_offset;
5201 if ((softc->valid_iddir_len > (entries_offset + 1))
5202 && (le64dec(softc->ata_iddir.header) ==
5204 && (softc->ata_iddir.entry_count > 0)) {
5207 num_entries = softc->ata_iddir.entry_count;
5208 num_entries = min(num_entries,
5209 softc->valid_iddir_len - entries_offset);
5210 for (i = 0; i < num_entries &&
5211 i < max_entries; i++) {
5212 if (softc->ata_iddir.entries[i] ==
5215 DA_FLAG_CAN_ATA_SUPCAP;
5216 else if (softc->ata_iddir.entries[i]==
5219 DA_FLAG_CAN_ATA_ZONE;
5222 DA_FLAG_CAN_ATA_SUPCAP)
5224 DA_FLAG_CAN_ATA_ZONE))
5229 error = daerror(done_ccb, CAM_RETRY_SELTO,
5230 SF_RETRY_UA|SF_NO_PRINT);
5231 if (error == ERESTART)
5233 else if (error != 0) {
5235 * If we can't get the ATA Identify Data log
5236 * directory, then it effectively isn't
5237 * supported even if the ATA Log directory
5238 * a non-zero number of pages present for
5241 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5242 if ((done_ccb->ccb_h.status &
5243 CAM_DEV_QFRZN) != 0) {
5244 /* Don't wedge this device's queue */
5245 cam_release_devq(done_ccb->ccb_h.path,
5249 /*getcount_only*/0);
5254 free(csio->data_ptr, M_SCSIDA);
5257 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5258 softc->state = DA_STATE_PROBE_ATA_SUP;
5259 xpt_release_ccb(done_ccb);
5260 xpt_schedule(periph, priority);
5263 daprobedone(periph, done_ccb);
5266 case DA_CCB_PROBE_ATA_SUP:
5270 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5273 struct ata_identify_log_sup_cap *sup_cap;
5276 sup_cap = (struct ata_identify_log_sup_cap *)
5278 valid_len = csio->dxfer_len - csio->resid;
5280 __offsetof(struct ata_identify_log_sup_cap,
5281 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5282 if (valid_len >= needed_size) {
5283 uint64_t zoned, zac_cap;
5285 zoned = le64dec(sup_cap->zoned_cap);
5286 if (zoned & ATA_ZONED_VALID) {
5288 * This should have already been
5289 * set, because this is also in the
5290 * ATA identify data.
5292 if ((zoned & ATA_ZONED_MASK) ==
5293 ATA_SUPPORT_ZONE_HOST_AWARE)
5296 else if ((zoned & ATA_ZONED_MASK) ==
5297 ATA_SUPPORT_ZONE_DEV_MANAGED)
5299 DA_ZONE_DRIVE_MANAGED;
5302 zac_cap = le64dec(sup_cap->sup_zac_cap);
5303 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5304 if (zac_cap & ATA_REPORT_ZONES_SUP)
5305 softc->zone_flags |=
5306 DA_ZONE_FLAG_RZ_SUP;
5307 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5308 softc->zone_flags |=
5309 DA_ZONE_FLAG_OPEN_SUP;
5310 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5311 softc->zone_flags |=
5312 DA_ZONE_FLAG_CLOSE_SUP;
5313 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5314 softc->zone_flags |=
5315 DA_ZONE_FLAG_FINISH_SUP;
5316 if (zac_cap & ATA_ND_RWP_SUP)
5317 softc->zone_flags |=
5318 DA_ZONE_FLAG_RWP_SUP;
5321 * This field was introduced in
5322 * ACS-4, r08 on April 28th, 2015.
5323 * If the drive firmware was written
5324 * to an earlier spec, it won't have
5325 * the field. So, assume all
5326 * commands are supported.
5328 softc->zone_flags |=
5329 DA_ZONE_FLAG_SUP_MASK;
5334 error = daerror(done_ccb, CAM_RETRY_SELTO,
5335 SF_RETRY_UA|SF_NO_PRINT);
5336 if (error == ERESTART)
5338 else if (error != 0) {
5340 * If we can't get the ATA Identify Data
5341 * Supported Capabilities page, clear the
5344 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5346 * And clear zone capabilities.
5348 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5349 if ((done_ccb->ccb_h.status &
5350 CAM_DEV_QFRZN) != 0) {
5351 /* Don't wedge this device's queue */
5352 cam_release_devq(done_ccb->ccb_h.path,
5356 /*getcount_only*/0);
5361 free(csio->data_ptr, M_SCSIDA);
5364 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5365 softc->state = DA_STATE_PROBE_ATA_ZONE;
5366 xpt_release_ccb(done_ccb);
5367 xpt_schedule(periph, priority);
5370 daprobedone(periph, done_ccb);
5373 case DA_CCB_PROBE_ATA_ZONE:
5377 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5378 struct ata_zoned_info_log *zi_log;
5382 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5384 valid_len = csio->dxfer_len - csio->resid;
5385 needed_size = __offsetof(struct ata_zoned_info_log,
5386 version_info) + 1 + sizeof(zi_log->version_info);
5387 if (valid_len >= needed_size) {
5390 tmpvar = le64dec(zi_log->zoned_cap);
5391 if (tmpvar & ATA_ZDI_CAP_VALID) {
5392 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5393 softc->zone_flags |=
5394 DA_ZONE_FLAG_URSWRZ;
5396 softc->zone_flags &=
5397 ~DA_ZONE_FLAG_URSWRZ;
5399 tmpvar = le64dec(zi_log->optimal_seq_zones);
5400 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5401 softc->zone_flags |=
5402 DA_ZONE_FLAG_OPT_SEQ_SET;
5403 softc->optimal_seq_zones = (tmpvar &
5404 ATA_ZDI_OPT_SEQ_MASK);
5406 softc->zone_flags &=
5407 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5408 softc->optimal_seq_zones = 0;
5411 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5412 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5413 softc->zone_flags |=
5414 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5415 softc->optimal_nonseq_zones =
5416 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5418 softc->zone_flags &=
5419 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5420 softc->optimal_nonseq_zones = 0;
5423 tmpvar = le64dec(zi_log->max_seq_req_zones);
5424 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5425 softc->zone_flags |=
5426 DA_ZONE_FLAG_MAX_SEQ_SET;
5427 softc->max_seq_zones =
5428 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5430 softc->zone_flags &=
5431 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5432 softc->max_seq_zones = 0;
5436 error = daerror(done_ccb, CAM_RETRY_SELTO,
5437 SF_RETRY_UA|SF_NO_PRINT);
5438 if (error == ERESTART)
5440 else if (error != 0) {
5441 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5442 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5444 if ((done_ccb->ccb_h.status &
5445 CAM_DEV_QFRZN) != 0) {
5446 /* Don't wedge this device's queue */
5447 cam_release_devq(done_ccb->ccb_h.path,
5451 /*getcount_only*/0);
5456 free(csio->data_ptr, M_SCSIDA);
5458 daprobedone(periph, done_ccb);
5461 case DA_CCB_PROBE_ZONE:
5465 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5468 struct scsi_vpd_zoned_bdc *zoned_bdc;
5471 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5473 valid_len = csio->dxfer_len - csio->resid;
5474 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5475 max_seq_req_zones) + 1 +
5476 sizeof(zoned_bdc->max_seq_req_zones);
5477 if ((valid_len >= needed_len)
5478 && (scsi_2btoul(zoned_bdc->page_length) >=
5480 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5481 softc->zone_flags |=
5482 DA_ZONE_FLAG_URSWRZ;
5484 softc->zone_flags &=
5485 ~DA_ZONE_FLAG_URSWRZ;
5486 softc->optimal_seq_zones =
5487 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5488 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5489 softc->optimal_nonseq_zones = scsi_4btoul(
5490 zoned_bdc->optimal_nonseq_zones);
5491 softc->zone_flags |=
5492 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5493 softc->max_seq_zones =
5494 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5495 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5498 * All of the zone commands are mandatory for SCSI
5501 * XXX KDM this is valid as of September 2015.
5502 * Re-check this assumption once the SAT spec is
5503 * updated to support SCSI ZBC to ATA ZAC mapping.
5504 * Since ATA allows zone commands to be reported
5505 * as supported or not, this may not necessarily
5506 * be true for an ATA device behind a SAT (SCSI to
5507 * ATA Translation) layer.
5509 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5511 error = daerror(done_ccb, CAM_RETRY_SELTO,
5512 SF_RETRY_UA|SF_NO_PRINT);
5513 if (error == ERESTART)
5515 else if (error != 0) {
5516 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5517 /* Don't wedge this device's queue */
5518 cam_release_devq(done_ccb->ccb_h.path,
5522 /*getcount_only*/0);
5526 daprobedone(periph, done_ccb);
5530 /* No-op. We're polling */
5534 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5536 if (daerror(done_ccb, CAM_RETRY_SELTO,
5537 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5540 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5541 cam_release_devq(done_ccb->ccb_h.path,
5545 /*getcount_only*/0);
5547 xpt_release_ccb(done_ccb);
5548 da_periph_release_locked(periph, DA_REF_TUR);
5554 xpt_release_ccb(done_ccb);
5558 dareprobe(struct cam_periph *periph)
5560 struct da_softc *softc;
5563 softc = (struct da_softc *)periph->softc;
5565 /* Probe in progress; don't interfere. */
5566 if (softc->state != DA_STATE_NORMAL)
5569 status = da_periph_acquire(periph, DA_REF_REPROBE);
5570 KASSERT(status == 0, ("dareprobe: cam_periph_acquire failed"));
5572 softc->state = DA_STATE_PROBE_WP;
5573 xpt_schedule(periph, CAM_PRIORITY_DEV);
5577 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5579 struct da_softc *softc;
5580 struct cam_periph *periph;
5581 int error, error_code, sense_key, asc, ascq;
5583 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5584 if (ccb->csio.bio != NULL)
5585 biotrack(ccb->csio.bio, __func__);
5588 periph = xpt_path_periph(ccb->ccb_h.path);
5589 softc = (struct da_softc *)periph->softc;
5592 * Automatically detect devices that do not support
5593 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5596 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5597 error = cmd6workaround(ccb);
5598 } else if (scsi_extract_sense_ccb(ccb,
5599 &error_code, &sense_key, &asc, &ascq)) {
5600 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5601 error = cmd6workaround(ccb);
5603 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5604 * query the capacity and notify upper layers.
5606 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5607 asc == 0x2A && ascq == 0x09) {
5608 xpt_print(periph->path, "Capacity data has changed\n");
5609 softc->flags &= ~DA_FLAG_PROBED;
5611 sense_flags |= SF_NO_PRINT;
5612 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5613 asc == 0x28 && ascq == 0x00) {
5614 softc->flags &= ~DA_FLAG_PROBED;
5615 disk_media_changed(softc->disk, M_NOWAIT);
5616 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5617 asc == 0x3F && ascq == 0x03) {
5618 xpt_print(periph->path, "INQUIRY data has changed\n");
5619 softc->flags &= ~DA_FLAG_PROBED;
5621 sense_flags |= SF_NO_PRINT;
5622 } else if (sense_key == SSD_KEY_NOT_READY &&
5623 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5624 softc->flags |= DA_FLAG_PACK_INVALID;
5625 disk_media_gone(softc->disk, M_NOWAIT);
5628 if (error == ERESTART)
5632 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5633 case CAM_CMD_TIMEOUT:
5636 case CAM_REQ_ABORTED:
5637 case CAM_REQ_CMP_ERR:
5638 case CAM_REQ_TERMIO:
5639 case CAM_UNREC_HBA_ERROR:
5640 case CAM_DATA_RUN_ERR:
5650 * Until we have a better way of doing pack validation,
5651 * don't treat UAs as errors.
5653 sense_flags |= SF_RETRY_UA;
5655 if (softc->quirks & DA_Q_RETRY_BUSY)
5656 sense_flags |= SF_RETRY_BUSY;
5657 return(cam_periph_error(ccb, cam_flags, sense_flags));
5661 damediapoll(void *arg)
5663 struct cam_periph *periph = arg;
5664 struct da_softc *softc = periph->softc;
5666 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5667 LIST_EMPTY(&softc->pending_ccbs)) {
5668 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
5669 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5673 /* Queue us up again */
5674 if (da_poll_period != 0)
5675 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5679 daprevent(struct cam_periph *periph, int action)
5681 struct da_softc *softc;
5685 softc = (struct da_softc *)periph->softc;
5687 if (((action == PR_ALLOW)
5688 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5689 || ((action == PR_PREVENT)
5690 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5694 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5696 scsi_prevent(&ccb->csio,
5704 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5705 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5708 if (action == PR_ALLOW)
5709 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5711 softc->flags |= DA_FLAG_PACK_LOCKED;
5714 xpt_release_ccb(ccb);
5718 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5719 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5721 struct ccb_calc_geometry ccg;
5722 struct da_softc *softc;
5723 struct disk_params *dp;
5724 u_int lbppbe, lalba;
5727 softc = (struct da_softc *)periph->softc;
5729 dp = &softc->params;
5730 dp->secsize = block_len;
5731 dp->sectors = maxsector + 1;
5732 if (rcaplong != NULL) {
5733 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5734 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5735 lalba &= SRC16_LALBA_A;
5742 dp->stripesize = block_len << lbppbe;
5743 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5745 } else if (softc->quirks & DA_Q_4K) {
5746 dp->stripesize = 4096;
5747 dp->stripeoffset = 0;
5748 } else if (softc->unmap_gran != 0) {
5749 dp->stripesize = block_len * softc->unmap_gran;
5750 dp->stripeoffset = (dp->stripesize - block_len *
5751 softc->unmap_gran_align) % dp->stripesize;
5754 dp->stripeoffset = 0;
5757 * Have the controller provide us with a geometry
5758 * for this disk. The only time the geometry
5759 * matters is when we boot and the controller
5760 * is the only one knowledgeable enough to come
5761 * up with something that will make this a bootable
5764 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5765 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5766 ccg.block_size = dp->secsize;
5767 ccg.volume_size = dp->sectors;
5769 ccg.secs_per_track = 0;
5771 xpt_action((union ccb*)&ccg);
5772 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5774 * We don't know what went wrong here- but just pick
5775 * a geometry so we don't have nasty things like divide
5779 dp->secs_per_track = 255;
5780 dp->cylinders = dp->sectors / (255 * 255);
5781 if (dp->cylinders == 0) {
5785 dp->heads = ccg.heads;
5786 dp->secs_per_track = ccg.secs_per_track;
5787 dp->cylinders = ccg.cylinders;
5791 * If the user supplied a read capacity buffer, and if it is
5792 * different than the previous buffer, update the data in the EDT.
5793 * If it's the same, we don't bother. This avoids sending an
5794 * update every time someone opens this device.
5796 if ((rcaplong != NULL)
5797 && (bcmp(rcaplong, &softc->rcaplong,
5798 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5799 struct ccb_dev_advinfo cdai;
5801 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5802 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5803 cdai.buftype = CDAI_TYPE_RCAPLONG;
5804 cdai.flags = CDAI_FLAG_STORE;
5805 cdai.bufsiz = rcap_len;
5806 cdai.buf = (uint8_t *)rcaplong;
5807 xpt_action((union ccb *)&cdai);
5808 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5809 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5810 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5811 xpt_print(periph->path, "%s: failed to set read "
5812 "capacity advinfo\n", __func__);
5813 /* Use cam_error_print() to decode the status */
5814 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5817 bcopy(rcaplong, &softc->rcaplong,
5818 min(sizeof(softc->rcaplong), rcap_len));
5822 softc->disk->d_sectorsize = softc->params.secsize;
5823 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5824 softc->disk->d_stripesize = softc->params.stripesize;
5825 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5826 /* XXX: these are not actually "firmware" values, so they may be wrong */
5827 softc->disk->d_fwsectors = softc->params.secs_per_track;
5828 softc->disk->d_fwheads = softc->params.heads;
5829 softc->disk->d_devstat->block_size = softc->params.secsize;
5830 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5832 error = disk_resize(softc->disk, M_NOWAIT);
5834 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5838 dasendorderedtag(void *arg)
5840 struct da_softc *softc = arg;
5842 if (da_send_ordered) {
5843 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5844 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5845 softc->flags |= DA_FLAG_NEED_OTAG;
5846 softc->flags &= ~DA_FLAG_WAS_OTAG;
5849 /* Queue us up again */
5850 callout_reset(&softc->sendordered_c,
5851 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5852 dasendorderedtag, softc);
5856 * Step through all DA peripheral drivers, and if the device is still open,
5857 * sync the disk cache to physical media.
5860 dashutdown(void * arg, int howto)
5862 struct cam_periph *periph;
5863 struct da_softc *softc;
5867 CAM_PERIPH_FOREACH(periph, &dadriver) {
5868 softc = (struct da_softc *)periph->softc;
5869 if (SCHEDULER_STOPPED()) {
5870 /* If we paniced with the lock held, do not recurse. */
5871 if (!cam_periph_owned(periph) &&
5872 (softc->flags & DA_FLAG_OPEN)) {
5873 dadump(softc->disk, NULL, 0, 0, 0);
5877 cam_periph_lock(periph);
5880 * We only sync the cache if the drive is still open, and
5881 * if the drive is capable of it..
5883 if (((softc->flags & DA_FLAG_OPEN) == 0)
5884 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5885 cam_periph_unlock(periph);
5889 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5890 scsi_synchronize_cache(&ccb->csio,
5894 /*begin_lba*/0, /* whole disk */
5899 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5900 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5901 softc->disk->d_devstat);
5903 xpt_print(periph->path, "Synchronize cache failed\n");
5904 xpt_release_ccb(ccb);
5905 cam_periph_unlock(periph);
5909 #else /* !_KERNEL */
5912 * XXX These are only left out of the kernel build to silence warnings. If,
5913 * for some reason these functions are used in the kernel, the ifdefs should
5914 * be moved so they are included both in the kernel and userland.
5917 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5918 void (*cbfcnp)(struct cam_periph *, union ccb *),
5919 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5920 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5923 struct scsi_format_unit *scsi_cmd;
5925 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5926 scsi_cmd->opcode = FORMAT_UNIT;
5927 scsi_cmd->byte2 = byte2;
5928 scsi_ulto2b(ileave, scsi_cmd->interleave);
5933 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5943 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5944 void (*cbfcnp)(struct cam_periph *, union ccb *),
5945 uint8_t tag_action, uint8_t list_format,
5946 uint32_t addr_desc_index, uint8_t *data_ptr,
5947 uint32_t dxfer_len, int minimum_cmd_size,
5948 uint8_t sense_len, uint32_t timeout)
5953 * These conditions allow using the 10 byte command. Otherwise we
5954 * need to use the 12 byte command.
5956 if ((minimum_cmd_size <= 10)
5957 && (addr_desc_index == 0)
5958 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5959 struct scsi_read_defect_data_10 *cdb10;
5961 cdb10 = (struct scsi_read_defect_data_10 *)
5962 &csio->cdb_io.cdb_bytes;
5964 cdb_len = sizeof(*cdb10);
5965 bzero(cdb10, cdb_len);
5966 cdb10->opcode = READ_DEFECT_DATA_10;
5967 cdb10->format = list_format;
5968 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5970 struct scsi_read_defect_data_12 *cdb12;
5972 cdb12 = (struct scsi_read_defect_data_12 *)
5973 &csio->cdb_io.cdb_bytes;
5975 cdb_len = sizeof(*cdb12);
5976 bzero(cdb12, cdb_len);
5977 cdb12->opcode = READ_DEFECT_DATA_12;
5978 cdb12->format = list_format;
5979 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5980 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5986 /*flags*/ CAM_DIR_IN,
5996 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5997 void (*cbfcnp)(struct cam_periph *, union ccb *),
5998 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5999 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6002 struct scsi_sanitize *scsi_cmd;
6004 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
6005 scsi_cmd->opcode = SANITIZE;
6006 scsi_cmd->byte2 = byte2;
6007 scsi_cmd->control = control;
6008 scsi_ulto2b(dxfer_len, scsi_cmd->length);
6013 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6022 #endif /* _KERNEL */
6025 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
6026 void (*cbfcnp)(struct cam_periph *, union ccb *),
6027 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
6028 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
6029 uint8_t sense_len, uint32_t timeout)
6031 struct scsi_zbc_out *scsi_cmd;
6033 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
6034 scsi_cmd->opcode = ZBC_OUT;
6035 scsi_cmd->service_action = service_action;
6036 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
6037 scsi_cmd->zone_flags = zone_flags;
6042 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6052 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
6053 void (*cbfcnp)(struct cam_periph *, union ccb *),
6054 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
6055 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
6056 uint8_t sense_len, uint32_t timeout)
6058 struct scsi_zbc_in *scsi_cmd;
6060 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
6061 scsi_cmd->opcode = ZBC_IN;
6062 scsi_cmd->service_action = service_action;
6063 scsi_ulto4b(dxfer_len, scsi_cmd->length);
6064 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
6065 scsi_cmd->zone_options = zone_options;
6070 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
6081 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
6082 void (*cbfcnp)(struct cam_periph *, union ccb *),
6083 uint8_t tag_action, int use_ncq,
6084 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6085 uint8_t *data_ptr, uint32_t dxfer_len,
6086 uint8_t *cdb_storage, size_t cdb_storage_len,
6087 uint8_t sense_len, uint32_t timeout)
6089 uint8_t command_out, protocol, ata_flags;
6090 uint16_t features_out;
6091 uint32_t sectors_out, auxiliary;
6097 command_out = ATA_ZAC_MANAGEMENT_OUT;
6098 features_out = (zm_action & 0xf) | (zone_flags << 8);
6099 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6100 if (dxfer_len == 0) {
6101 protocol = AP_PROTO_NON_DATA;
6102 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6105 protocol = AP_PROTO_DMA;
6106 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
6107 AP_FLAG_TDIR_TO_DEV;
6108 sectors_out = ((dxfer_len >> 9) & 0xffff);
6112 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6113 if (dxfer_len == 0) {
6114 command_out = ATA_NCQ_NON_DATA;
6115 features_out = ATA_NCQ_ZAC_MGMT_OUT;
6117 * We're assuming the SCSI to ATA translation layer
6118 * will set the NCQ tag number in the tag field.
6119 * That isn't clear from the SAT-4 spec (as of rev 05).
6122 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6124 command_out = ATA_SEND_FPDMA_QUEUED;
6126 * Note that we're defaulting to normal priority,
6127 * and assuming that the SCSI to ATA translation
6128 * layer will insert the NCQ tag number in the tag
6129 * field. That isn't clear in the SAT-4 spec (as
6132 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
6134 ata_flags |= AP_FLAG_TLEN_FEAT |
6135 AP_FLAG_TDIR_TO_DEV;
6138 * For SEND FPDMA QUEUED, the transfer length is
6139 * encoded in the FEATURE register, and 0 means
6140 * that 65536 512 byte blocks are to be tranferred.
6141 * In practice, it seems unlikely that we'll see
6142 * a transfer that large, and it may confuse the
6143 * the SAT layer, because generally that means that
6144 * 0 bytes should be transferred.
6146 if (dxfer_len == (65536 * 512)) {
6148 } else if (dxfer_len <= (65535 * 512)) {
6149 features_out = ((dxfer_len >> 9) & 0xffff);
6151 /* The transfer is too big. */
6158 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
6159 protocol = AP_PROTO_FPDMA;
6162 protocol |= AP_EXTEND;
6164 retval = scsi_ata_pass(csio,
6167 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6169 /*protocol*/ protocol,
6170 /*ata_flags*/ ata_flags,
6171 /*features*/ features_out,
6172 /*sector_count*/ sectors_out,
6174 /*command*/ command_out,
6177 /*auxiliary*/ auxiliary,
6179 /*data_ptr*/ data_ptr,
6180 /*dxfer_len*/ dxfer_len,
6181 /*cdb_storage*/ cdb_storage,
6182 /*cdb_storage_len*/ cdb_storage_len,
6183 /*minimum_cmd_size*/ 0,
6184 /*sense_len*/ SSD_FULL_SIZE,
6185 /*timeout*/ timeout);
6193 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
6194 void (*cbfcnp)(struct cam_periph *, union ccb *),
6195 uint8_t tag_action, int use_ncq,
6196 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6197 uint8_t *data_ptr, uint32_t dxfer_len,
6198 uint8_t *cdb_storage, size_t cdb_storage_len,
6199 uint8_t sense_len, uint32_t timeout)
6201 uint8_t command_out, protocol;
6202 uint16_t features_out, sectors_out;
6208 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
6211 command_out = ATA_ZAC_MANAGEMENT_IN;
6212 /* XXX KDM put a macro here */
6213 features_out = (zm_action & 0xf) | (zone_flags << 8);
6214 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
6215 protocol = AP_PROTO_DMA;
6216 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
6219 ata_flags |= AP_FLAG_TLEN_FEAT;
6221 command_out = ATA_RECV_FPDMA_QUEUED;
6222 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6225 * For RECEIVE FPDMA QUEUED, the transfer length is
6226 * encoded in the FEATURE register, and 0 means
6227 * that 65536 512 byte blocks are to be tranferred.
6228 * In practice, it seems unlikely that we'll see
6229 * a transfer that large, and it may confuse the
6230 * the SAT layer, because generally that means that
6231 * 0 bytes should be transferred.
6233 if (dxfer_len == (65536 * 512)) {
6235 } else if (dxfer_len <= (65535 * 512)) {
6236 features_out = ((dxfer_len >> 9) & 0xffff);
6238 /* The transfer is too big. */
6242 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6243 protocol = AP_PROTO_FPDMA;
6246 protocol |= AP_EXTEND;
6248 retval = scsi_ata_pass(csio,
6251 /*flags*/ CAM_DIR_IN,
6253 /*protocol*/ protocol,
6254 /*ata_flags*/ ata_flags,
6255 /*features*/ features_out,
6256 /*sector_count*/ sectors_out,
6258 /*command*/ command_out,
6261 /*auxiliary*/ auxiliary,
6263 /*data_ptr*/ data_ptr,
6264 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6265 /*cdb_storage*/ cdb_storage,
6266 /*cdb_storage_len*/ cdb_storage_len,
6267 /*minimum_cmd_size*/ 0,
6268 /*sense_len*/ SSD_FULL_SIZE,
6269 /*timeout*/ timeout);