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>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
40 #include <sys/sysctl.h>
41 #include <sys/taskqueue.h>
43 #include <sys/mutex.h>
45 #include <sys/devicestat.h>
46 #include <sys/eventhandler.h>
47 #include <sys/malloc.h>
49 #include <sys/endian.h>
52 #include <geom/geom.h>
53 #include <geom/geom_disk.h>
62 #include <cam/cam_ccb.h>
63 #include <cam/cam_periph.h>
64 #include <cam/cam_xpt_periph.h>
65 #include <cam/cam_sim.h>
66 #include <cam/cam_iosched.h>
68 #include <cam/scsi/scsi_message.h>
69 #include <cam/scsi/scsi_da.h>
73 * Note that there are probe ordering dependencies here. The order isn't
74 * controlled by this enumeration, but by explicit state transitions in
75 * dastart() and dadone(). Here are some of the dependencies:
77 * 1. RC should come first, before RC16, unless there is evidence that RC16
79 * 2. BDC needs to come before any of the ATA probes, or the ZONE probe.
80 * 3. The ATA probes should go in this order:
81 * ATA -> LOGDIR -> IDDIR -> SUP -> ATA_ZONE
88 DA_STATE_PROBE_BLK_LIMITS,
91 DA_STATE_PROBE_ATA_LOGDIR,
92 DA_STATE_PROBE_ATA_IDDIR,
93 DA_STATE_PROBE_ATA_SUP,
94 DA_STATE_PROBE_ATA_ZONE,
100 DA_FLAG_PACK_INVALID = 0x000001,
101 DA_FLAG_NEW_PACK = 0x000002,
102 DA_FLAG_PACK_LOCKED = 0x000004,
103 DA_FLAG_PACK_REMOVABLE = 0x000008,
104 DA_FLAG_NEED_OTAG = 0x000020,
105 DA_FLAG_WAS_OTAG = 0x000040,
106 DA_FLAG_RETRY_UA = 0x000080,
107 DA_FLAG_OPEN = 0x000100,
108 DA_FLAG_SCTX_INIT = 0x000200,
109 DA_FLAG_CAN_RC16 = 0x000400,
110 DA_FLAG_PROBED = 0x000800,
111 DA_FLAG_DIRTY = 0x001000,
112 DA_FLAG_ANNOUNCED = 0x002000,
113 DA_FLAG_CAN_ATA_DMA = 0x004000,
114 DA_FLAG_CAN_ATA_LOG = 0x008000,
115 DA_FLAG_CAN_ATA_IDLOG = 0x010000,
116 DA_FLAG_CAN_ATA_SUPCAP = 0x020000,
117 DA_FLAG_CAN_ATA_ZONE = 0x040000
122 DA_Q_NO_SYNC_CACHE = 0x01,
123 DA_Q_NO_6_BYTE = 0x02,
124 DA_Q_NO_PREVENT = 0x04,
127 DA_Q_NO_UNMAP = 0x20,
128 DA_Q_RETRY_BUSY = 0x40,
130 DA_Q_STRICT_UNMAP = 0x100
133 #define DA_Q_BIT_STRING \
135 "\001NO_SYNC_CACHE" \
146 DA_CCB_PROBE_RC = 0x01,
147 DA_CCB_PROBE_RC16 = 0x02,
148 DA_CCB_PROBE_LBP = 0x03,
149 DA_CCB_PROBE_BLK_LIMITS = 0x04,
150 DA_CCB_PROBE_BDC = 0x05,
151 DA_CCB_PROBE_ATA = 0x06,
152 DA_CCB_BUFFER_IO = 0x07,
154 DA_CCB_DELETE = 0x0B,
156 DA_CCB_PROBE_ZONE = 0x0D,
157 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
158 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
159 DA_CCB_PROBE_ATA_SUP = 0x10,
160 DA_CCB_PROBE_ATA_ZONE = 0x11,
161 DA_CCB_PROBE_WP = 0x12,
162 DA_CCB_TYPE_MASK = 0x1F,
163 DA_CCB_RETRY_UA = 0x20
167 * Order here is important for method choice
169 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
170 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
171 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
172 * import taking 5mins.
183 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
184 DA_DELETE_MAX = DA_DELETE_ZERO
188 * For SCSI, host managed drives show up as a separate device type. For
189 * ATA, host managed drives also have a different device signature.
190 * XXX KDM figure out the ATA host managed signature.
194 DA_ZONE_DRIVE_MANAGED = 0x01,
195 DA_ZONE_HOST_AWARE = 0x02,
196 DA_ZONE_HOST_MANAGED = 0x03
200 * We distinguish between these interface cases in addition to the drive type:
201 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
202 * o ATA drive behind a SCSI translation layer that does not know about
203 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
204 * case, we would need to share the ATA code with the ada(4) driver.
214 DA_ZONE_FLAG_RZ_SUP = 0x0001,
215 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
216 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
217 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
218 DA_ZONE_FLAG_RWP_SUP = 0x0010,
219 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
220 DA_ZONE_FLAG_OPEN_SUP |
221 DA_ZONE_FLAG_CLOSE_SUP |
222 DA_ZONE_FLAG_FINISH_SUP |
223 DA_ZONE_FLAG_RWP_SUP),
224 DA_ZONE_FLAG_URSWRZ = 0x0020,
225 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
226 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
227 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
228 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
229 DA_ZONE_FLAG_OPT_NONSEQ_SET |
230 DA_ZONE_FLAG_MAX_SEQ_SET)
233 static struct da_zone_desc {
236 } da_zone_desc_table[] = {
237 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
238 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
239 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
240 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
241 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
244 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
246 static da_delete_func_t da_delete_trim;
247 static da_delete_func_t da_delete_unmap;
248 static da_delete_func_t da_delete_ws;
250 static const void * da_delete_functions[] = {
260 static const char *da_delete_method_names[] =
261 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
262 static const char *da_delete_method_desc[] =
263 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
264 "WRITE SAME(10) with UNMAP", "ZERO" };
266 /* Offsets into our private area for storing information */
267 #define ccb_state ppriv_field0
268 #define ccb_bp ppriv_ptr1
273 u_int8_t secs_per_track;
274 u_int32_t secsize; /* Number of bytes/sector */
275 u_int64_t sectors; /* total number sectors */
280 #define UNMAP_RANGE_MAX 0xffffffff
281 #define UNMAP_HEAD_SIZE 8
282 #define UNMAP_RANGE_SIZE 16
283 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
284 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
287 #define WS10_MAX_BLKS 0xffff
288 #define WS16_MAX_BLKS 0xffffffff
289 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
290 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
292 #define DA_WORK_TUR (1 << 16)
295 struct cam_iosched_softc *cam_iosched;
296 struct bio_queue_head delete_run_queue;
297 LIST_HEAD(, ccb_hdr) pending_ccbs;
298 int refcount; /* Active xpt_action() calls */
302 int minimum_cmd_size;
305 int delete_available; /* Delete methods possibly available */
306 da_zone_mode zone_mode;
307 da_zone_interface zone_interface;
308 da_zone_flags zone_flags;
309 struct ata_gp_log_dir ata_logdir;
310 int valid_logdir_len;
311 struct ata_identify_log_pages ata_iddir;
313 uint64_t optimal_seq_zones;
314 uint64_t optimal_nonseq_zones;
315 uint64_t max_seq_zones;
317 uint32_t unmap_max_ranges;
318 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
320 uint32_t unmap_gran_align;
321 uint64_t ws_max_blks;
322 da_delete_methods delete_method_pref;
323 da_delete_methods delete_method;
324 da_delete_func_t *delete_func;
327 struct disk_params params;
330 struct task sysctl_task;
331 struct sysctl_ctx_list sysctl_ctx;
332 struct sysctl_oid *sysctl_tree;
333 struct callout sendordered_c;
335 uint8_t unmap_buf[UNMAP_BUF_SIZE];
336 struct scsi_read_capacity_data_long rcaplong;
337 struct callout mediapoll_c;
339 struct sysctl_ctx_list sysctl_stats_ctx;
340 struct sysctl_oid *sysctl_stats_tree;
345 #define DA_ANNOUNCETMP_SZ 80
346 char announce_temp[DA_ANNOUNCETMP_SZ];
347 #define DA_ANNOUNCE_SZ 400
348 char announcebuf[DA_ANNOUNCE_SZ];
351 #define dadeleteflag(softc, delete_method, enable) \
353 softc->delete_available |= (1 << delete_method); \
355 softc->delete_available &= ~(1 << delete_method); \
358 struct da_quirk_entry {
359 struct scsi_inquiry_pattern inq_pat;
363 static const char quantum[] = "QUANTUM";
364 static const char microp[] = "MICROP";
366 static struct da_quirk_entry da_quirk_table[] =
368 /* SPI, FC devices */
371 * Fujitsu M2513A MO drives.
372 * Tested devices: M2513A2 firmware versions 1200 & 1300.
373 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
374 * Reported by: W.Scholten <whs@xs4all.nl>
376 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
377 /*quirks*/ DA_Q_NO_SYNC_CACHE
381 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
382 /*quirks*/ DA_Q_NO_SYNC_CACHE
386 * This particular Fujitsu drive doesn't like the
387 * synchronize cache command.
388 * Reported by: Tom Jackson <toj@gorilla.net>
390 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
391 /*quirks*/ DA_Q_NO_SYNC_CACHE
395 * This drive doesn't like the synchronize cache command
396 * either. Reported by: Matthew Jacob <mjacob@feral.com>
397 * in NetBSD PR kern/6027, August 24, 1998.
399 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
400 /*quirks*/ DA_Q_NO_SYNC_CACHE
404 * This drive doesn't like the synchronize cache command
405 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
408 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
409 /*quirks*/ DA_Q_NO_SYNC_CACHE
413 * Doesn't like the synchronize cache command.
414 * Reported by: Blaz Zupan <blaz@gold.amis.net>
416 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
417 /*quirks*/ DA_Q_NO_SYNC_CACHE
421 * Doesn't like the synchronize cache command.
422 * Reported by: Blaz Zupan <blaz@gold.amis.net>
424 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
425 /*quirks*/ DA_Q_NO_SYNC_CACHE
429 * Doesn't like the synchronize cache command.
431 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
432 /*quirks*/ DA_Q_NO_SYNC_CACHE
436 * Doesn't like the synchronize cache command.
437 * Reported by: walter@pelissero.de
439 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
440 /*quirks*/ DA_Q_NO_SYNC_CACHE
444 * Doesn't work correctly with 6 byte reads/writes.
445 * Returns illegal request, and points to byte 9 of the
447 * Reported by: Adam McDougall <bsdx@spawnet.com>
449 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
450 /*quirks*/ DA_Q_NO_6_BYTE
454 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
455 /*quirks*/ DA_Q_NO_6_BYTE
459 * Doesn't like the synchronize cache command.
460 * Reported by: walter@pelissero.de
462 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
463 /*quirks*/ DA_Q_NO_SYNC_CACHE
467 * The CISS RAID controllers do not support SYNC_CACHE
469 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
470 /*quirks*/ DA_Q_NO_SYNC_CACHE
474 * The STEC SSDs sometimes hang on UNMAP.
476 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
477 /*quirks*/ DA_Q_NO_UNMAP
481 * VMware returns BUSY status when storage has transient
482 * connectivity problems, so better wait.
483 * Also VMware returns odd errors on misaligned UNMAPs.
485 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
486 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
488 /* USB mass storage devices supported by umass(4) */
491 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
494 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
495 /*quirks*/ DA_Q_NO_SYNC_CACHE
499 * Power Quotient Int. (PQI) USB flash key
502 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
503 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
507 * Creative Nomad MUVO mp3 player (USB)
510 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
511 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
515 * Jungsoft NEXDISK USB flash key
518 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
519 /*quirks*/ DA_Q_NO_SYNC_CACHE
523 * FreeDik USB Mini Data Drive
526 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
527 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
531 * Sigmatel USB Flash MP3 Player
534 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
535 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
539 * Neuros USB Digital Audio Computer
542 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
543 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
547 * SEAGRAND NP-900 MP3 Player
550 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
551 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
555 * iRiver iFP MP3 player (with UMS Firmware)
556 * PR: kern/54881, i386/63941, kern/66124
558 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
559 /*quirks*/ DA_Q_NO_SYNC_CACHE
563 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
566 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
567 /*quirks*/ DA_Q_NO_SYNC_CACHE
571 * ZICPlay USB MP3 Player with FM
574 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
575 /*quirks*/ DA_Q_NO_SYNC_CACHE
579 * TEAC USB floppy mechanisms
581 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
582 /*quirks*/ DA_Q_NO_SYNC_CACHE
586 * Kingston DataTraveler II+ USB Pen-Drive.
587 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
589 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
590 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
598 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
599 /*quirks*/ DA_Q_NO_SYNC_CACHE
603 * Motorola E398 Mobile Phone (TransFlash memory card).
604 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
607 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
608 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
612 * Qware BeatZkey! Pro
615 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
616 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
620 * Time DPA20B 1GB MP3 Player
623 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
624 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
628 * Samsung USB key 128Mb
631 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
632 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
636 * Kingston DataTraveler 2.0 USB Flash memory.
639 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
640 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
644 * Creative MUVO Slim mp3 player (USB)
647 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
648 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
652 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
655 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
656 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
660 * SanDisk Micro Cruzer 128MB
663 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
664 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
668 * TOSHIBA TransMemory USB sticks
671 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
672 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
676 * PNY USB 3.0 Flash Drives
678 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
679 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
684 * PR: usb/75578, usb/72344, usb/65436
686 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
687 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
693 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
694 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16
698 * Genesys 6-in-1 Card Reader
701 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
702 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
706 * Rekam Digital CAMERA
709 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
710 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
714 * iRiver H10 MP3 player
717 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
718 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
722 * iRiver U10 MP3 player
725 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
726 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
733 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
734 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
738 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
741 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
742 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
749 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
750 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
754 * Philips USB Key Audio KEY013
757 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
758 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
765 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
766 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
773 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
774 /*quirks*/ DA_Q_NO_SYNC_CACHE
778 * I/O Magic USB flash - Giga Bank
781 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
782 /*quirks*/ DA_Q_NO_SYNC_CACHE
786 * JoyFly 128mb USB Flash Drive
789 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
790 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
797 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
798 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
802 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
805 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
806 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
810 * Samsung YP-U3 mp3-player
813 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
814 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
817 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
818 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
822 * Sony Cyber-Shot DSC cameras
825 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
826 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
829 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
830 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
833 /* At least several Transcent USB sticks lie on RC16. */
834 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
835 "*"}, /*quirks*/ DA_Q_NO_RC16
839 * I-O Data USB Flash Disk
842 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
843 "*"}, /*quirks*/ DA_Q_NO_RC16
845 /* ATA/SATA devices over SAS/USB/... */
847 /* Hitachi Advanced Format (4k) drives */
848 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
852 /* Micron Advanced Format (4k) drives */
853 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
857 /* Samsung Advanced Format (4k) drives */
858 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
862 /* Samsung Advanced Format (4k) drives */
863 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
867 /* Samsung Advanced Format (4k) drives */
868 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
872 /* Samsung Advanced Format (4k) drives */
873 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
877 /* Seagate Barracuda Green Advanced Format (4k) drives */
878 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
882 /* Seagate Barracuda Green Advanced Format (4k) drives */
883 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
887 /* Seagate Barracuda Green Advanced Format (4k) drives */
888 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
892 /* Seagate Barracuda Green Advanced Format (4k) drives */
893 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
897 /* Seagate Barracuda Green Advanced Format (4k) drives */
898 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
902 /* Seagate Barracuda Green Advanced Format (4k) drives */
903 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
907 /* Seagate Momentus Advanced Format (4k) drives */
908 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
912 /* Seagate Momentus Advanced Format (4k) drives */
913 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
917 /* Seagate Momentus Advanced Format (4k) drives */
918 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
922 /* Seagate Momentus Advanced Format (4k) drives */
923 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
927 /* Seagate Momentus Advanced Format (4k) drives */
928 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
932 /* Seagate Momentus Advanced Format (4k) drives */
933 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
937 /* Seagate Momentus Advanced Format (4k) drives */
938 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
942 /* Seagate Momentus Advanced Format (4k) drives */
943 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
947 /* Seagate Momentus Advanced Format (4k) drives */
948 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
952 /* Seagate Momentus Advanced Format (4k) drives */
953 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
957 /* Seagate Momentus Advanced Format (4k) drives */
958 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
962 /* Seagate Momentus Advanced Format (4k) drives */
963 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
967 /* Seagate Momentus Advanced Format (4k) drives */
968 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
972 /* Seagate Momentus Advanced Format (4k) drives */
973 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
977 /* Seagate Momentus Thin Advanced Format (4k) drives */
978 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
982 /* Seagate Momentus Thin Advanced Format (4k) drives */
983 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
987 /* WDC Caviar Green Advanced Format (4k) drives */
988 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
992 /* WDC Caviar Green Advanced Format (4k) drives */
993 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
997 /* WDC Caviar Green Advanced Format (4k) drives */
998 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
1002 /* WDC Caviar Green Advanced Format (4k) drives */
1003 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
1007 /* WDC Caviar Green Advanced Format (4k) drives */
1008 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1012 /* WDC Caviar Green Advanced Format (4k) drives */
1013 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1017 /* WDC Caviar Green Advanced Format (4k) drives */
1018 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1022 /* WDC Caviar Green Advanced Format (4k) drives */
1023 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1027 /* WDC Scorpio Black Advanced Format (4k) drives */
1028 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1032 /* WDC Scorpio Black Advanced Format (4k) drives */
1033 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1037 /* WDC Scorpio Black Advanced Format (4k) drives */
1038 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1042 /* WDC Scorpio Black Advanced Format (4k) drives */
1043 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1047 /* WDC Scorpio Blue Advanced Format (4k) drives */
1048 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1052 /* WDC Scorpio Blue Advanced Format (4k) drives */
1053 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1057 /* WDC Scorpio Blue Advanced Format (4k) drives */
1058 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1062 /* WDC Scorpio Blue Advanced Format (4k) drives */
1063 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1068 * Olympus FE-210 camera
1070 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1071 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1075 * LG UP3S MP3 player
1077 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1078 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1082 * Laser MP3-2GA13 MP3 player
1084 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1085 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1089 * LaCie external 250GB Hard drive des by Porsche
1090 * Submitted by: Ben Stuyts <ben@altesco.nl>
1093 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1094 /*quirks*/ DA_Q_NO_SYNC_CACHE
1099 * Corsair Force 2 SSDs
1100 * 4k optimised & trim only works in 4k requests + 4k aligned
1102 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1107 * Corsair Force 3 SSDs
1108 * 4k optimised & trim only works in 4k requests + 4k aligned
1110 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1115 * Corsair Neutron GTX SSDs
1116 * 4k optimised & trim only works in 4k requests + 4k aligned
1118 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1123 * Corsair Force GT & GS SSDs
1124 * 4k optimised & trim only works in 4k requests + 4k aligned
1126 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1132 * 4k optimised & trim only works in 4k requests + 4k aligned
1134 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1139 * Crucial RealSSD C300 SSDs
1142 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1143 "*" }, /*quirks*/DA_Q_4K
1147 * Intel 320 Series SSDs
1148 * 4k optimised & trim only works in 4k requests + 4k aligned
1150 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1155 * Intel 330 Series SSDs
1156 * 4k optimised & trim only works in 4k requests + 4k aligned
1158 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1163 * Intel 510 Series SSDs
1164 * 4k optimised & trim only works in 4k requests + 4k aligned
1166 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1171 * Intel 520 Series SSDs
1172 * 4k optimised & trim only works in 4k requests + 4k aligned
1174 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1179 * Intel S3610 Series SSDs
1180 * 4k optimised & trim only works in 4k requests + 4k aligned
1182 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1187 * Intel X25-M Series SSDs
1188 * 4k optimised & trim only works in 4k requests + 4k aligned
1190 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1195 * Kingston E100 Series SSDs
1196 * 4k optimised & trim only works in 4k requests + 4k aligned
1198 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1203 * Kingston HyperX 3k SSDs
1204 * 4k optimised & trim only works in 4k requests + 4k aligned
1206 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1211 * Marvell SSDs (entry taken from OpenSolaris)
1212 * 4k optimised & trim only works in 4k requests + 4k aligned
1214 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1219 * OCZ Agility 2 SSDs
1220 * 4k optimised & trim only works in 4k requests + 4k aligned
1222 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1227 * OCZ Agility 3 SSDs
1228 * 4k optimised & trim only works in 4k requests + 4k aligned
1230 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1235 * OCZ Deneva R Series SSDs
1236 * 4k optimised & trim only works in 4k requests + 4k aligned
1238 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1243 * OCZ Vertex 2 SSDs (inc pro series)
1244 * 4k optimised & trim only works in 4k requests + 4k aligned
1246 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1252 * 4k optimised & trim only works in 4k requests + 4k aligned
1254 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1260 * 4k optimised & trim only works in 4k requests + 4k aligned
1262 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1267 * Samsung 750 Series SSDs
1268 * 4k optimised & trim only works in 4k requests + 4k aligned
1270 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" },
1275 * Samsung 830 Series SSDs
1276 * 4k optimised & trim only works in 4k requests + 4k aligned
1278 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1284 * 4k optimised & trim only works in 4k requests + 4k aligned
1286 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1292 * 4k optimised & trim only works in 4k requests + 4k aligned
1294 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" },
1300 * 4k optimised & trim only works in 4k requests + 4k aligned
1302 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1307 * Samsung 843T Series SSDs (MZ7WD*)
1308 * Samsung PM851 Series SSDs (MZ7TE*)
1309 * Samsung PM853T Series SSDs (MZ7GE*)
1310 * Samsung SM863 Series SSDs (MZ7KM*)
1313 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1318 * Same as for SAMSUNG MZ7* but enable the quirks for SSD
1319 * starting with MZ7* too
1321 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MZ7*", "*" },
1326 * SuperTalent TeraDrive CT SSDs
1327 * 4k optimised & trim only works in 4k requests + 4k aligned
1329 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1334 * XceedIOPS SATA SSDs
1337 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1342 * Hama Innostor USB-Stick
1344 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1345 /*quirks*/DA_Q_NO_RC16
1349 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1350 * Drive Managed SATA hard drive. This drive doesn't report
1351 * in firmware that it is a drive managed SMR drive.
1353 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS000[23]*", "*" },
1354 /*quirks*/DA_Q_SMR_DM
1358 * MX-ES USB Drive by Mach Xtreme
1360 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1361 /*quirks*/DA_Q_NO_RC16
1365 static disk_strategy_t dastrategy;
1366 static dumper_t dadump;
1367 static periph_init_t dainit;
1368 static void daasync(void *callback_arg, u_int32_t code,
1369 struct cam_path *path, void *arg);
1370 static void dasysctlinit(void *context, int pending);
1371 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1372 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1373 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1374 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1375 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1376 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1377 static void dadeletemethodset(struct da_softc *softc,
1378 da_delete_methods delete_method);
1379 static off_t dadeletemaxsize(struct da_softc *softc,
1380 da_delete_methods delete_method);
1381 static void dadeletemethodchoose(struct da_softc *softc,
1382 da_delete_methods default_method);
1383 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1385 static periph_ctor_t daregister;
1386 static periph_dtor_t dacleanup;
1387 static periph_start_t dastart;
1388 static periph_oninv_t daoninvalidate;
1389 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1390 static void dadone(struct cam_periph *periph,
1391 union ccb *done_ccb);
1392 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1393 u_int32_t sense_flags);
1394 static void daprevent(struct cam_periph *periph, int action);
1395 static void dareprobe(struct cam_periph *periph);
1396 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1398 struct scsi_read_capacity_data_long *rcaplong,
1400 static timeout_t dasendorderedtag;
1401 static void dashutdown(void *arg, int howto);
1402 static timeout_t damediapoll;
1404 #ifndef DA_DEFAULT_POLL_PERIOD
1405 #define DA_DEFAULT_POLL_PERIOD 3
1408 #ifndef DA_DEFAULT_TIMEOUT
1409 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1412 #ifndef DA_DEFAULT_SOFTTIMEOUT
1413 #define DA_DEFAULT_SOFTTIMEOUT 0
1416 #ifndef DA_DEFAULT_RETRY
1417 #define DA_DEFAULT_RETRY 4
1420 #ifndef DA_DEFAULT_SEND_ORDERED
1421 #define DA_DEFAULT_SEND_ORDERED 1
1424 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1425 static int da_retry_count = DA_DEFAULT_RETRY;
1426 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1427 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1428 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1430 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1431 "CAM Direct Access Disk driver");
1432 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1433 &da_poll_period, 0, "Media polling period in seconds");
1434 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1435 &da_retry_count, 0, "Normal I/O retry count");
1436 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1437 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1438 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1439 &da_send_ordered, 0, "Send Ordered Tags");
1441 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1442 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1443 "Soft I/O timeout (ms)");
1444 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1447 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1448 * to the default timeout, we check to see whether an ordered
1449 * tagged transaction is appropriate to prevent simple tag
1450 * starvation. Since we'd like to ensure that there is at least
1451 * 1/2 of the timeout length left for a starved transaction to
1452 * complete after we've sent an ordered tag, we must poll at least
1453 * four times in every timeout period. This takes care of the worst
1454 * case where a starved transaction starts during an interval that
1455 * meets the requirement "don't send an ordered tag" test so it takes
1456 * us two intervals to determine that a tag must be sent.
1458 #ifndef DA_ORDEREDTAG_INTERVAL
1459 #define DA_ORDEREDTAG_INTERVAL 4
1462 static struct periph_driver dadriver =
1465 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1468 PERIPHDRIVER_DECLARE(da, dadriver);
1470 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1473 daopen(struct disk *dp)
1475 struct cam_periph *periph;
1476 struct da_softc *softc;
1479 periph = (struct cam_periph *)dp->d_drv1;
1480 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1484 cam_periph_lock(periph);
1485 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1486 cam_periph_unlock(periph);
1487 cam_periph_release(periph);
1491 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1494 softc = (struct da_softc *)periph->softc;
1497 /* Wait for the disk size update. */
1498 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1501 xpt_print(periph->path, "unable to retrieve capacity data\n");
1503 if (periph->flags & CAM_PERIPH_INVALID)
1506 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1507 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1508 daprevent(periph, PR_PREVENT);
1511 softc->flags &= ~DA_FLAG_PACK_INVALID;
1512 softc->flags |= DA_FLAG_OPEN;
1515 cam_periph_unhold(periph);
1516 cam_periph_unlock(periph);
1519 cam_periph_release(periph);
1525 daclose(struct disk *dp)
1527 struct cam_periph *periph;
1528 struct da_softc *softc;
1531 periph = (struct cam_periph *)dp->d_drv1;
1532 softc = (struct da_softc *)periph->softc;
1533 cam_periph_lock(periph);
1534 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1537 if (cam_periph_hold(periph, PRIBIO) == 0) {
1539 /* Flush disk cache. */
1540 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1541 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1542 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1543 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1544 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1545 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1546 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1548 cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1549 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1550 softc->disk->d_devstat);
1551 softc->flags &= ~DA_FLAG_DIRTY;
1552 xpt_release_ccb(ccb);
1555 /* Allow medium removal. */
1556 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1557 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1558 daprevent(periph, PR_ALLOW);
1560 cam_periph_unhold(periph);
1564 * If we've got removeable media, mark the blocksize as
1565 * unavailable, since it could change when new media is
1568 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1569 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1571 softc->flags &= ~DA_FLAG_OPEN;
1572 while (softc->refcount != 0)
1573 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1574 cam_periph_unlock(periph);
1575 cam_periph_release(periph);
1580 daschedule(struct cam_periph *periph)
1582 struct da_softc *softc = (struct da_softc *)periph->softc;
1584 if (softc->state != DA_STATE_NORMAL)
1587 cam_iosched_schedule(softc->cam_iosched, periph);
1591 * Actually translate the requested transfer into one the physical driver
1592 * can understand. The transfer is described by a buf and will include
1593 * only one physical transfer.
1596 dastrategy(struct bio *bp)
1598 struct cam_periph *periph;
1599 struct da_softc *softc;
1601 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1602 softc = (struct da_softc *)periph->softc;
1604 cam_periph_lock(periph);
1607 * If the device has been made invalid, error out
1609 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1610 cam_periph_unlock(periph);
1611 biofinish(bp, NULL, ENXIO);
1615 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1618 * Zone commands must be ordered, because they can depend on the
1619 * effects of previously issued commands, and they may affect
1620 * commands after them.
1622 if (bp->bio_cmd == BIO_ZONE)
1623 bp->bio_flags |= BIO_ORDERED;
1626 * Place it in the queue of disk activities for this disk
1628 cam_iosched_queue_work(softc->cam_iosched, bp);
1631 * Schedule ourselves for performing the work.
1634 cam_periph_unlock(periph);
1640 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1642 struct cam_periph *periph;
1643 struct da_softc *softc;
1645 struct ccb_scsiio csio;
1650 periph = dp->d_drv1;
1651 softc = (struct da_softc *)periph->softc;
1652 secsize = softc->params.secsize;
1654 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0)
1657 memset(&csio, 0, sizeof(csio));
1659 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1660 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1661 scsi_read_write(&csio,
1665 /*read*/SCSI_RW_WRITE,
1667 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1670 /*data_ptr*/(u_int8_t *) virtual,
1671 /*dxfer_len*/length,
1672 /*sense_len*/SSD_FULL_SIZE,
1673 da_default_timeout * 1000);
1674 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1675 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1677 printf("Aborting dump due to I/O error.\n");
1682 * Sync the disk cache contents to the physical media.
1684 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1686 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1687 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1688 scsi_synchronize_cache(&csio,
1692 /*begin_lba*/0,/* Cover the whole disk */
1696 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1697 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1699 xpt_print(periph->path, "Synchronize cache failed\n");
1705 dagetattr(struct bio *bp)
1708 struct cam_periph *periph;
1710 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1711 cam_periph_lock(periph);
1712 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1714 cam_periph_unlock(periph);
1716 bp->bio_completed = bp->bio_length;
1726 * Install a global async callback. This callback will
1727 * receive async callbacks like "new device found".
1729 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1731 if (status != CAM_REQ_CMP) {
1732 printf("da: Failed to attach master async callback "
1733 "due to status 0x%x!\n", status);
1734 } else if (da_send_ordered) {
1736 /* Register our shutdown event handler */
1737 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1738 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1739 printf("dainit: shutdown event registration failed!\n");
1744 * Callback from GEOM, called when it has finished cleaning up its
1748 dadiskgonecb(struct disk *dp)
1750 struct cam_periph *periph;
1752 periph = (struct cam_periph *)dp->d_drv1;
1753 cam_periph_release(periph);
1757 daoninvalidate(struct cam_periph *periph)
1759 struct da_softc *softc;
1761 softc = (struct da_softc *)periph->softc;
1764 * De-register any async callbacks.
1766 xpt_register_async(0, daasync, periph, periph->path);
1768 softc->flags |= DA_FLAG_PACK_INVALID;
1770 softc->invalidations++;
1774 * Return all queued I/O with ENXIO.
1775 * XXX Handle any transactions queued to the card
1776 * with XPT_ABORT_CCB.
1778 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
1781 * Tell GEOM that we've gone away, we'll get a callback when it is
1782 * done cleaning up its resources.
1784 disk_gone(softc->disk);
1788 dacleanup(struct cam_periph *periph)
1790 struct da_softc *softc;
1792 softc = (struct da_softc *)periph->softc;
1794 cam_periph_unlock(periph);
1796 cam_iosched_fini(softc->cam_iosched);
1799 * If we can't free the sysctl tree, oh well...
1801 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
1803 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1804 xpt_print(periph->path,
1805 "can't remove sysctl stats context\n");
1807 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1808 xpt_print(periph->path,
1809 "can't remove sysctl context\n");
1812 callout_drain(&softc->mediapoll_c);
1813 disk_destroy(softc->disk);
1814 callout_drain(&softc->sendordered_c);
1815 free(softc, M_DEVBUF);
1816 cam_periph_lock(periph);
1820 daasync(void *callback_arg, u_int32_t code,
1821 struct cam_path *path, void *arg)
1823 struct cam_periph *periph;
1824 struct da_softc *softc;
1826 periph = (struct cam_periph *)callback_arg;
1828 case AC_FOUND_DEVICE:
1830 struct ccb_getdev *cgd;
1833 cgd = (struct ccb_getdev *)arg;
1837 if (cgd->protocol != PROTO_SCSI)
1839 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
1841 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1842 && SID_TYPE(&cgd->inq_data) != T_RBC
1843 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
1844 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
1848 * Allocate a peripheral instance for
1849 * this device and start the probe
1852 status = cam_periph_alloc(daregister, daoninvalidate,
1854 "da", CAM_PERIPH_BIO,
1856 AC_FOUND_DEVICE, cgd);
1858 if (status != CAM_REQ_CMP
1859 && status != CAM_REQ_INPROG)
1860 printf("daasync: Unable to attach to new device "
1861 "due to status 0x%x\n", status);
1864 case AC_ADVINFO_CHANGED:
1868 buftype = (uintptr_t)arg;
1869 if (buftype == CDAI_TYPE_PHYS_PATH) {
1870 struct da_softc *softc;
1872 softc = periph->softc;
1873 disk_attr_changed(softc->disk, "GEOM::physpath",
1878 case AC_UNIT_ATTENTION:
1881 int error_code, sense_key, asc, ascq;
1883 softc = (struct da_softc *)periph->softc;
1884 ccb = (union ccb *)arg;
1887 * Handle all UNIT ATTENTIONs except our own,
1888 * as they will be handled by daerror().
1890 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1891 scsi_extract_sense_ccb(ccb,
1892 &error_code, &sense_key, &asc, &ascq)) {
1893 if (asc == 0x2A && ascq == 0x09) {
1894 xpt_print(ccb->ccb_h.path,
1895 "Capacity data has changed\n");
1896 softc->flags &= ~DA_FLAG_PROBED;
1898 } else if (asc == 0x28 && ascq == 0x00) {
1899 softc->flags &= ~DA_FLAG_PROBED;
1900 disk_media_changed(softc->disk, M_NOWAIT);
1901 } else if (asc == 0x3F && ascq == 0x03) {
1902 xpt_print(ccb->ccb_h.path,
1903 "INQUIRY data has changed\n");
1904 softc->flags &= ~DA_FLAG_PROBED;
1911 softc = (struct da_softc *)periph->softc;
1912 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
1913 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1914 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
1922 struct ccb_hdr *ccbh;
1924 softc = (struct da_softc *)periph->softc;
1926 * Don't fail on the expected unit attention
1929 softc->flags |= DA_FLAG_RETRY_UA;
1930 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1931 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1934 case AC_INQ_CHANGED:
1935 softc = (struct da_softc *)periph->softc;
1936 softc->flags &= ~DA_FLAG_PROBED;
1942 cam_periph_async(periph, code, path, arg);
1946 dasysctlinit(void *context, int pending)
1948 struct cam_periph *periph;
1949 struct da_softc *softc;
1950 char tmpstr[32], tmpstr2[16];
1951 struct ccb_trans_settings cts;
1953 periph = (struct cam_periph *)context;
1955 * periph was held for us when this task was enqueued
1957 if (periph->flags & CAM_PERIPH_INVALID) {
1958 cam_periph_release(periph);
1962 softc = (struct da_softc *)periph->softc;
1963 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1964 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1966 sysctl_ctx_init(&softc->sysctl_ctx);
1967 softc->flags |= DA_FLAG_SCTX_INIT;
1968 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
1969 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1970 CTLFLAG_RD, 0, tmpstr, "device_index");
1971 if (softc->sysctl_tree == NULL) {
1972 printf("dasysctlinit: unable to allocate sysctl tree\n");
1973 cam_periph_release(periph);
1978 * Now register the sysctl handler, so the user can change the value on
1981 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1982 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
1983 softc, 0, dadeletemethodsysctl, "A",
1984 "BIO_DELETE execution method");
1985 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1986 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1987 softc, 0, dadeletemaxsysctl, "Q",
1988 "Maximum BIO_DELETE size");
1989 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1990 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1991 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1992 "Minimum CDB size");
1994 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1995 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
1996 softc, 0, dazonemodesysctl, "A",
1998 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1999 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
2000 softc, 0, dazonesupsysctl, "A",
2002 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2003 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2004 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2005 "Optimal Number of Open Sequential Write Preferred Zones");
2006 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2007 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2008 "optimal_nonseq_zones", CTLFLAG_RD,
2009 &softc->optimal_nonseq_zones,
2010 "Optimal Number of Non-Sequentially Written Sequential Write "
2012 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2013 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2014 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2015 "Maximum Number of Open Sequential Write Required Zones");
2017 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2018 SYSCTL_CHILDREN(softc->sysctl_tree),
2022 &softc->error_inject,
2024 "error_inject leaf");
2026 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2027 SYSCTL_CHILDREN(softc->sysctl_tree),
2033 "Unmapped I/O leaf");
2035 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2036 SYSCTL_CHILDREN(softc->sysctl_tree),
2045 * Add some addressing info.
2047 memset(&cts, 0, sizeof (cts));
2048 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2049 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2050 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2051 cam_periph_lock(periph);
2052 xpt_action((union ccb *)&cts);
2053 cam_periph_unlock(periph);
2054 if (cts.ccb_h.status != CAM_REQ_CMP) {
2055 cam_periph_release(periph);
2058 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2059 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2060 if (fc->valid & CTS_FC_VALID_WWPN) {
2061 softc->wwpn = fc->wwpn;
2062 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2063 SYSCTL_CHILDREN(softc->sysctl_tree),
2064 OID_AUTO, "wwpn", CTLFLAG_RD,
2065 &softc->wwpn, "World Wide Port Name");
2071 * Now add some useful stats.
2072 * XXX These should live in cam_periph and be common to all periphs
2074 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2075 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2076 CTLFLAG_RD, 0, "Statistics");
2077 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2078 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2084 "Transport errors reported by the SIM");
2085 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2086 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2092 "Device timeouts reported by the SIM");
2093 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2094 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2096 "pack_invalidations",
2098 &softc->invalidations,
2100 "Device pack invalidations");
2103 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2104 softc->sysctl_tree);
2106 cam_periph_release(periph);
2110 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2114 struct da_softc *softc;
2116 softc = (struct da_softc *)arg1;
2118 value = softc->disk->d_delmaxsize;
2119 error = sysctl_handle_64(oidp, &value, 0, req);
2120 if ((error != 0) || (req->newptr == NULL))
2123 /* only accept values smaller than the calculated value */
2124 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2127 softc->disk->d_delmaxsize = value;
2133 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2137 value = *(int *)arg1;
2139 error = sysctl_handle_int(oidp, &value, 0, req);
2142 || (req->newptr == NULL))
2146 * Acceptable values here are 6, 10, 12 or 16.
2150 else if ((value > 6)
2153 else if ((value > 10)
2156 else if (value > 12)
2159 *(int *)arg1 = value;
2165 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2170 value = da_default_softtimeout / SBT_1MS;
2172 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2173 if ((error != 0) || (req->newptr == NULL))
2176 /* XXX Should clip this to a reasonable level */
2177 if (value > da_default_timeout * 1000)
2180 da_default_softtimeout = value * SBT_1MS;
2185 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2188 softc->delete_method = delete_method;
2189 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2190 softc->delete_func = da_delete_functions[delete_method];
2192 if (softc->delete_method > DA_DELETE_DISABLE)
2193 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2195 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2199 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2203 switch(delete_method) {
2204 case DA_DELETE_UNMAP:
2205 sectors = (off_t)softc->unmap_max_lba;
2207 case DA_DELETE_ATA_TRIM:
2208 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2210 case DA_DELETE_WS16:
2211 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2213 case DA_DELETE_ZERO:
2214 case DA_DELETE_WS10:
2215 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2221 return (off_t)softc->params.secsize *
2222 omin(sectors, softc->params.sectors);
2226 daprobedone(struct cam_periph *periph, union ccb *ccb)
2228 struct da_softc *softc;
2230 softc = (struct da_softc *)periph->softc;
2232 dadeletemethodchoose(softc, DA_DELETE_NONE);
2234 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2238 snprintf(buf, sizeof(buf), "Delete methods: <");
2240 for (i = 0; i <= DA_DELETE_MAX; i++) {
2241 if ((softc->delete_available & (1 << i)) == 0 &&
2242 i != softc->delete_method)
2245 strlcat(buf, ",", sizeof(buf));
2246 strlcat(buf, da_delete_method_names[i],
2248 if (i == softc->delete_method)
2249 strlcat(buf, "(*)", sizeof(buf));
2252 strlcat(buf, ">", sizeof(buf));
2253 printf("%s%d: %s\n", periph->periph_name,
2254 periph->unit_number, buf);
2258 * Since our peripheral may be invalidated by an error
2259 * above or an external event, we must release our CCB
2260 * before releasing the probe lock on the peripheral.
2261 * The peripheral will only go away once the last lock
2262 * is removed, and we need it around for the CCB release
2265 xpt_release_ccb(ccb);
2266 softc->state = DA_STATE_NORMAL;
2267 softc->flags |= DA_FLAG_PROBED;
2269 wakeup(&softc->disk->d_mediasize);
2270 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2271 softc->flags |= DA_FLAG_ANNOUNCED;
2272 cam_periph_unhold(periph);
2274 cam_periph_release_locked(periph);
2278 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2282 /* If available, prefer the method requested by user. */
2283 i = softc->delete_method_pref;
2284 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2285 if (methods & (1 << i)) {
2286 dadeletemethodset(softc, i);
2290 /* Use the pre-defined order to choose the best performing delete. */
2291 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2292 if (i == DA_DELETE_ZERO)
2294 if (softc->delete_available & (1 << i)) {
2295 dadeletemethodset(softc, i);
2300 /* Fallback to default. */
2301 dadeletemethodset(softc, default_method);
2305 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2309 struct da_softc *softc;
2310 int i, error, value;
2312 softc = (struct da_softc *)arg1;
2314 value = softc->delete_method;
2315 if (value < 0 || value > DA_DELETE_MAX)
2318 p = da_delete_method_names[value];
2319 strncpy(buf, p, sizeof(buf));
2320 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2321 if (error != 0 || req->newptr == NULL)
2323 for (i = 0; i <= DA_DELETE_MAX; i++) {
2324 if (strcmp(buf, da_delete_method_names[i]) == 0)
2327 if (i > DA_DELETE_MAX)
2329 softc->delete_method_pref = i;
2330 dadeletemethodchoose(softc, DA_DELETE_NONE);
2335 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2338 struct da_softc *softc;
2341 softc = (struct da_softc *)arg1;
2343 switch (softc->zone_mode) {
2344 case DA_ZONE_DRIVE_MANAGED:
2345 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2347 case DA_ZONE_HOST_AWARE:
2348 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2350 case DA_ZONE_HOST_MANAGED:
2351 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2355 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2359 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2365 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2368 struct da_softc *softc;
2373 softc = (struct da_softc *)arg1;
2377 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2379 for (i = 0; i < sizeof(da_zone_desc_table) /
2380 sizeof(da_zone_desc_table[0]); i++) {
2381 if (softc->zone_flags & da_zone_desc_table[i].value) {
2383 sbuf_printf(&sb, ", ");
2386 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2391 sbuf_printf(&sb, "None");
2395 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2401 daregister(struct cam_periph *periph, void *arg)
2403 struct da_softc *softc;
2404 struct ccb_pathinq cpi;
2405 struct ccb_getdev *cgd;
2409 cgd = (struct ccb_getdev *)arg;
2411 printf("daregister: no getdev CCB, can't register device\n");
2412 return(CAM_REQ_CMP_ERR);
2415 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2418 if (softc == NULL) {
2419 printf("daregister: Unable to probe new device. "
2420 "Unable to allocate softc\n");
2421 return(CAM_REQ_CMP_ERR);
2424 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2425 printf("daregister: Unable to probe new device. "
2426 "Unable to allocate iosched memory\n");
2427 free(softc, M_DEVBUF);
2428 return(CAM_REQ_CMP_ERR);
2431 LIST_INIT(&softc->pending_ccbs);
2432 softc->state = DA_STATE_PROBE_WP;
2433 bioq_init(&softc->delete_run_queue);
2434 if (SID_IS_REMOVABLE(&cgd->inq_data))
2435 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2436 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2437 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2438 softc->unmap_gran = 0;
2439 softc->unmap_gran_align = 0;
2440 softc->ws_max_blks = WS16_MAX_BLKS;
2441 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2442 softc->rotating = 1;
2444 periph->softc = softc;
2447 * See if this device has any quirks.
2449 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2450 (caddr_t)da_quirk_table,
2451 nitems(da_quirk_table),
2452 sizeof(*da_quirk_table), scsi_inquiry_match);
2455 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2457 softc->quirks = DA_Q_NONE;
2459 /* Check if the SIM does not want 6 byte commands */
2460 xpt_path_inq(&cpi, periph->path);
2461 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2462 softc->quirks |= DA_Q_NO_6_BYTE;
2464 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2465 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2466 else if (softc->quirks & DA_Q_SMR_DM)
2467 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2469 softc->zone_mode = DA_ZONE_NONE;
2471 if (softc->zone_mode != DA_ZONE_NONE) {
2472 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2473 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2474 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2476 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2478 softc->zone_interface = DA_ZONE_IF_SCSI;
2481 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2484 * Take an exclusive refcount on the periph while dastart is called
2485 * to finish the probe. The reference will be dropped in dadone at
2488 (void)cam_periph_hold(periph, PRIBIO);
2491 * Schedule a periodic event to occasionally send an
2492 * ordered tag to a device.
2494 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2495 callout_reset(&softc->sendordered_c,
2496 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2497 dasendorderedtag, softc);
2499 cam_periph_unlock(periph);
2501 * RBC devices don't have to support READ(6), only READ(10).
2503 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2504 softc->minimum_cmd_size = 10;
2506 softc->minimum_cmd_size = 6;
2509 * Load the user's default, if any.
2511 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2512 periph->unit_number);
2513 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2516 * 6, 10, 12 and 16 are the currently permissible values.
2518 if (softc->minimum_cmd_size > 12)
2519 softc->minimum_cmd_size = 16;
2520 else if (softc->minimum_cmd_size > 10)
2521 softc->minimum_cmd_size = 12;
2522 else if (softc->minimum_cmd_size > 6)
2523 softc->minimum_cmd_size = 10;
2525 softc->minimum_cmd_size = 6;
2527 /* Predict whether device may support READ CAPACITY(16). */
2528 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2529 (softc->quirks & DA_Q_NO_RC16) == 0) {
2530 softc->flags |= DA_FLAG_CAN_RC16;
2534 * Register this media as a disk.
2536 softc->disk = disk_alloc();
2537 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2538 periph->unit_number, 0,
2539 DEVSTAT_BS_UNAVAILABLE,
2540 SID_TYPE(&cgd->inq_data) |
2541 XPORT_DEVSTAT_TYPE(cpi.transport),
2542 DEVSTAT_PRIORITY_DISK);
2543 softc->disk->d_open = daopen;
2544 softc->disk->d_close = daclose;
2545 softc->disk->d_strategy = dastrategy;
2546 softc->disk->d_dump = dadump;
2547 softc->disk->d_getattr = dagetattr;
2548 softc->disk->d_gone = dadiskgonecb;
2549 softc->disk->d_name = "da";
2550 softc->disk->d_drv1 = periph;
2552 softc->maxio = DFLTPHYS; /* traditional default */
2553 else if (cpi.maxio > MAXPHYS)
2554 softc->maxio = MAXPHYS; /* for safety */
2556 softc->maxio = cpi.maxio;
2557 softc->disk->d_maxsize = softc->maxio;
2558 softc->disk->d_unit = periph->unit_number;
2559 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2560 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2561 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2562 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2563 softc->unmappedio = 1;
2564 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2566 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2567 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2568 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2569 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2570 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2571 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2572 softc->disk->d_hba_vendor = cpi.hba_vendor;
2573 softc->disk->d_hba_device = cpi.hba_device;
2574 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2575 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2578 * Acquire a reference to the periph before we register with GEOM.
2579 * We'll release this reference once GEOM calls us back (via
2580 * dadiskgonecb()) telling us that our provider has been freed.
2582 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2583 xpt_print(periph->path, "%s: lost periph during "
2584 "registration!\n", __func__);
2585 cam_periph_lock(periph);
2586 return (CAM_REQ_CMP_ERR);
2589 disk_create(softc->disk, DISK_VERSION);
2590 cam_periph_lock(periph);
2593 * Add async callbacks for events of interest.
2594 * I don't bother checking if this fails as,
2595 * in most cases, the system will function just
2596 * fine without them and the only alternative
2597 * would be to not attach the device on failure.
2599 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2600 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2601 AC_INQ_CHANGED, daasync, periph, periph->path);
2604 * Emit an attribute changed notification just in case
2605 * physical path information arrived before our async
2606 * event handler was registered, but after anyone attaching
2607 * to our disk device polled it.
2609 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2612 * Schedule a periodic media polling events.
2614 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2615 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2616 (cgd->inq_flags & SID_AEN) == 0 &&
2617 da_poll_period != 0)
2618 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2619 damediapoll, periph);
2621 xpt_schedule(periph, CAM_PRIORITY_DEV);
2623 return(CAM_REQ_CMP);
2627 da_zone_bio_to_scsi(int disk_zone_cmd)
2629 switch (disk_zone_cmd) {
2630 case DISK_ZONE_OPEN:
2631 return ZBC_OUT_SA_OPEN;
2632 case DISK_ZONE_CLOSE:
2633 return ZBC_OUT_SA_CLOSE;
2634 case DISK_ZONE_FINISH:
2635 return ZBC_OUT_SA_FINISH;
2637 return ZBC_OUT_SA_RWP;
2644 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2647 struct da_softc *softc;
2652 if (bp->bio_cmd != BIO_ZONE) {
2657 softc = periph->softc;
2659 switch (bp->bio_zone.zone_cmd) {
2660 case DISK_ZONE_OPEN:
2661 case DISK_ZONE_CLOSE:
2662 case DISK_ZONE_FINISH:
2663 case DISK_ZONE_RWP: {
2668 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2669 if (zone_sa == -1) {
2670 xpt_print(periph->path, "Cannot translate zone "
2671 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2677 lba = bp->bio_zone.zone_params.rwp.id;
2679 if (bp->bio_zone.zone_params.rwp.flags &
2680 DISK_ZONE_RWP_FLAG_ALL)
2681 zone_flags |= ZBC_OUT_ALL;
2683 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2684 scsi_zbc_out(&ccb->csio,
2685 /*retries*/ da_retry_count,
2687 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2688 /*service_action*/ zone_sa,
2690 /*zone_flags*/ zone_flags,
2693 /*sense_len*/ SSD_FULL_SIZE,
2694 /*timeout*/ da_default_timeout * 1000);
2697 * Note that in this case, even though we can
2698 * technically use NCQ, we don't bother for several
2700 * 1. It hasn't been tested on a SAT layer that
2701 * supports it. This is new as of SAT-4.
2702 * 2. Even when there is a SAT layer that supports
2703 * it, that SAT layer will also probably support
2704 * ZBC -> ZAC translation, since they are both
2705 * in the SAT-4 spec.
2706 * 3. Translation will likely be preferable to ATA
2707 * passthrough. LSI / Avago at least single
2708 * steps ATA passthrough commands in the HBA,
2709 * regardless of protocol, so unless that
2710 * changes, there is a performance penalty for
2711 * doing ATA passthrough no matter whether
2712 * you're using NCQ/FPDMA, DMA or PIO.
2713 * 4. It requires a 32-byte CDB, which at least at
2714 * this point in CAM requires a CDB pointer, which
2715 * would require us to allocate an additional bit
2716 * of storage separate from the CCB.
2718 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2719 /*retries*/ da_retry_count,
2721 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2723 /*zm_action*/ zone_sa,
2725 /*zone_flags*/ zone_flags,
2728 /*cdb_storage*/ NULL,
2729 /*cdb_storage_len*/ 0,
2730 /*sense_len*/ SSD_FULL_SIZE,
2731 /*timeout*/ da_default_timeout * 1000);
2734 xpt_print(periph->path,
2735 "scsi_ata_zac_mgmt_out() returned an "
2744 case DISK_ZONE_REPORT_ZONES: {
2746 uint32_t num_entries, alloc_size;
2747 struct disk_zone_report *rep;
2749 rep = &bp->bio_zone.zone_params.report;
2751 num_entries = rep->entries_allocated;
2752 if (num_entries == 0) {
2753 xpt_print(periph->path, "No entries allocated for "
2754 "Report Zones request\n");
2758 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2759 (sizeof(struct scsi_report_zones_desc) * num_entries);
2760 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2761 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2762 if (rz_ptr == NULL) {
2763 xpt_print(periph->path, "Unable to allocate memory "
2764 "for Report Zones request\n");
2769 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2770 scsi_zbc_in(&ccb->csio,
2771 /*retries*/ da_retry_count,
2773 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2774 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2775 /*zone_start_lba*/ rep->starting_id,
2776 /*zone_options*/ rep->rep_options,
2777 /*data_ptr*/ rz_ptr,
2778 /*dxfer_len*/ alloc_size,
2779 /*sense_len*/ SSD_FULL_SIZE,
2780 /*timeout*/ da_default_timeout * 1000);
2783 * Note that in this case, even though we can
2784 * technically use NCQ, we don't bother for several
2786 * 1. It hasn't been tested on a SAT layer that
2787 * supports it. This is new as of SAT-4.
2788 * 2. Even when there is a SAT layer that supports
2789 * it, that SAT layer will also probably support
2790 * ZBC -> ZAC translation, since they are both
2791 * in the SAT-4 spec.
2792 * 3. Translation will likely be preferable to ATA
2793 * passthrough. LSI / Avago at least single
2794 * steps ATA passthrough commands in the HBA,
2795 * regardless of protocol, so unless that
2796 * changes, there is a performance penalty for
2797 * doing ATA passthrough no matter whether
2798 * you're using NCQ/FPDMA, DMA or PIO.
2799 * 4. It requires a 32-byte CDB, which at least at
2800 * this point in CAM requires a CDB pointer, which
2801 * would require us to allocate an additional bit
2802 * of storage separate from the CCB.
2804 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2805 /*retries*/ da_retry_count,
2807 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2809 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2810 /*zone_id*/ rep->starting_id,
2811 /*zone_flags*/ rep->rep_options,
2812 /*data_ptr*/ rz_ptr,
2813 /*dxfer_len*/ alloc_size,
2814 /*cdb_storage*/ NULL,
2815 /*cdb_storage_len*/ 0,
2816 /*sense_len*/ SSD_FULL_SIZE,
2817 /*timeout*/ da_default_timeout * 1000);
2820 xpt_print(periph->path,
2821 "scsi_ata_zac_mgmt_in() returned an "
2828 * For BIO_ZONE, this isn't normally needed. However, it
2829 * is used by devstat_end_transaction_bio() to determine
2830 * how much data was transferred.
2833 * XXX KDM we have a problem. But I'm not sure how to fix
2834 * it. devstat uses bio_bcount - bio_resid to calculate
2835 * the amount of data transferred. The GEOM disk code
2836 * uses bio_length - bio_resid to calculate the amount of
2837 * data in bio_completed. We have different structure
2838 * sizes above and below the ada(4) driver. So, if we
2839 * use the sizes above, the amount transferred won't be
2840 * quite accurate for devstat. If we use different sizes
2841 * for bio_bcount and bio_length (above and below
2842 * respectively), then the residual needs to match one or
2843 * the other. Everything is calculated after the bio
2844 * leaves the driver, so changing the values around isn't
2845 * really an option. For now, just set the count to the
2846 * passed in length. This means that the calculations
2847 * above (e.g. bio_completed) will be correct, but the
2848 * amount of data reported to devstat will be slightly
2849 * under or overstated.
2851 bp->bio_bcount = bp->bio_length;
2857 case DISK_ZONE_GET_PARAMS: {
2858 struct disk_zone_disk_params *params;
2860 params = &bp->bio_zone.zone_params.disk_params;
2861 bzero(params, sizeof(*params));
2863 switch (softc->zone_mode) {
2864 case DA_ZONE_DRIVE_MANAGED:
2865 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
2867 case DA_ZONE_HOST_AWARE:
2868 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
2870 case DA_ZONE_HOST_MANAGED:
2871 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
2875 params->zone_mode = DISK_ZONE_MODE_NONE;
2879 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
2880 params->flags |= DISK_ZONE_DISK_URSWRZ;
2882 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
2883 params->optimal_seq_zones = softc->optimal_seq_zones;
2884 params->flags |= DISK_ZONE_OPT_SEQ_SET;
2887 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
2888 params->optimal_nonseq_zones =
2889 softc->optimal_nonseq_zones;
2890 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
2893 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
2894 params->max_seq_zones = softc->max_seq_zones;
2895 params->flags |= DISK_ZONE_MAX_SEQ_SET;
2897 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
2898 params->flags |= DISK_ZONE_RZ_SUP;
2900 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
2901 params->flags |= DISK_ZONE_OPEN_SUP;
2903 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
2904 params->flags |= DISK_ZONE_CLOSE_SUP;
2906 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
2907 params->flags |= DISK_ZONE_FINISH_SUP;
2909 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
2910 params->flags |= DISK_ZONE_RWP_SUP;
2921 dastart(struct cam_periph *periph, union ccb *start_ccb)
2923 struct da_softc *softc;
2925 softc = (struct da_softc *)periph->softc;
2927 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2930 switch (softc->state) {
2931 case DA_STATE_NORMAL:
2937 bp = cam_iosched_next_bio(softc->cam_iosched);
2939 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2940 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2941 scsi_test_unit_ready(&start_ccb->csio,
2942 /*retries*/ da_retry_count,
2946 da_default_timeout * 1000);
2947 start_ccb->ccb_h.ccb_bp = NULL;
2948 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2949 xpt_action(start_ccb);
2951 xpt_release_ccb(start_ccb);
2955 if (bp->bio_cmd == BIO_DELETE) {
2956 if (softc->delete_func != NULL) {
2957 softc->delete_func(periph, start_ccb, bp);
2960 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
2961 biofinish(bp, NULL, 0);
2966 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2967 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2968 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */
2971 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2972 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2973 softc->flags &= ~DA_FLAG_NEED_OTAG;
2974 softc->flags |= DA_FLAG_WAS_OTAG;
2975 tag_code = MSG_ORDERED_Q_TAG;
2977 tag_code = MSG_SIMPLE_Q_TAG;
2980 switch (bp->bio_cmd) {
2987 biotrack(bp, __func__);
2989 if (bp->bio_cmd == BIO_WRITE) {
2990 softc->flags |= DA_FLAG_DIRTY;
2991 rw_op = SCSI_RW_WRITE;
2993 rw_op = SCSI_RW_READ;
2996 data_ptr = bp->bio_data;
2997 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
2998 rw_op |= SCSI_RW_BIO;
3002 scsi_read_write(&start_ccb->csio,
3003 /*retries*/da_retry_count,
3005 /*tag_action*/tag_code,
3008 softc->minimum_cmd_size,
3009 /*lba*/bp->bio_pblkno,
3010 /*block_count*/bp->bio_bcount /
3011 softc->params.secsize,
3013 /*dxfer_len*/ bp->bio_bcount,
3014 /*sense_len*/SSD_FULL_SIZE,
3015 da_default_timeout * 1000);
3016 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3017 start_ccb->csio.bio = bp;
3023 * If we don't support sync cache, or the disk
3024 * isn't dirty, FLUSH is a no-op. Use the
3025 * allocated * CCB for the next bio if one is
3028 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) != 0 ||
3029 (softc->flags & DA_FLAG_DIRTY) == 0) {
3035 * BIO_FLUSH doesn't currently communicate
3036 * range data, so we synchronize the cache
3037 * over the whole disk. We also force
3038 * ordered tag semantics the flush applies
3039 * to all previously queued I/O.
3041 scsi_synchronize_cache(&start_ccb->csio,
3048 da_default_timeout*1000);
3050 * Clear the dirty flag before sending the command.
3051 * Either this sync cache will be successful, or it
3052 * will fail after a retry. If it fails, it is
3053 * unlikely to be successful if retried later, so
3054 * we'll save ourselves time by just marking the
3057 softc->flags &= ~DA_FLAG_DIRTY;
3060 int error, queue_ccb;
3064 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3066 || (queue_ccb == 0)) {
3067 biofinish(bp, NULL, error);
3068 xpt_release_ccb(start_ccb);
3074 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3075 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3076 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3079 LIST_INSERT_HEAD(&softc->pending_ccbs,
3080 &start_ccb->ccb_h, periph_links.le);
3082 /* We expect a unit attention from this device */
3083 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3084 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3085 softc->flags &= ~DA_FLAG_RETRY_UA;
3088 start_ccb->ccb_h.ccb_bp = bp;
3090 cam_periph_unlock(periph);
3091 xpt_action(start_ccb);
3092 cam_periph_lock(periph);
3095 /* May have more work to do, so ensure we stay scheduled */
3099 case DA_STATE_PROBE_WP:
3105 mode_buf = malloc(mode_buf_len, M_SCSIDA, M_NOWAIT);
3106 if (mode_buf == NULL) {
3107 xpt_print(periph->path, "Unable to send mode sense - "
3108 "malloc failure\n");
3109 softc->state = DA_STATE_PROBE_RC;
3112 scsi_mode_sense_len(&start_ccb->csio,
3113 /*retries*/ da_retry_count,
3115 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3117 /*pc*/ SMS_PAGE_CTRL_CURRENT,
3118 /*page*/ SMS_ALL_PAGES_PAGE,
3119 /*param_buf*/ mode_buf,
3120 /*param_len*/ mode_buf_len,
3121 /*minimum_cmd_size*/ softc->minimum_cmd_size,
3122 /*sense_len*/ SSD_FULL_SIZE,
3123 /*timeout*/ da_default_timeout * 1000);
3124 start_ccb->ccb_h.ccb_bp = NULL;
3125 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_WP;
3126 xpt_action(start_ccb);
3129 case DA_STATE_PROBE_RC:
3131 struct scsi_read_capacity_data *rcap;
3133 rcap = (struct scsi_read_capacity_data *)
3134 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3136 printf("dastart: Couldn't malloc read_capacity data\n");
3137 /* da_free_periph??? */
3140 scsi_read_capacity(&start_ccb->csio,
3141 /*retries*/da_retry_count,
3147 start_ccb->ccb_h.ccb_bp = NULL;
3148 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3149 xpt_action(start_ccb);
3152 case DA_STATE_PROBE_RC16:
3154 struct scsi_read_capacity_data_long *rcaplong;
3156 rcaplong = (struct scsi_read_capacity_data_long *)
3157 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3158 if (rcaplong == NULL) {
3159 printf("dastart: Couldn't malloc read_capacity data\n");
3160 /* da_free_periph??? */
3163 scsi_read_capacity_16(&start_ccb->csio,
3164 /*retries*/ da_retry_count,
3166 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3170 /*rcap_buf*/ (uint8_t *)rcaplong,
3171 /*rcap_buf_len*/ sizeof(*rcaplong),
3172 /*sense_len*/ SSD_FULL_SIZE,
3173 /*timeout*/ da_default_timeout * 1000);
3174 start_ccb->ccb_h.ccb_bp = NULL;
3175 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3176 xpt_action(start_ccb);
3179 case DA_STATE_PROBE_LBP:
3181 struct scsi_vpd_logical_block_prov *lbp;
3183 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3185 * If we get here we don't support any SBC-3 delete
3186 * methods with UNMAP as the Logical Block Provisioning
3187 * VPD page support is required for devices which
3188 * support it according to T10/1799-D Revision 31
3189 * however older revisions of the spec don't mandate
3190 * this so we currently don't remove these methods
3191 * from the available set.
3193 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3197 lbp = (struct scsi_vpd_logical_block_prov *)
3198 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3201 printf("dastart: Couldn't malloc lbp data\n");
3202 /* da_free_periph??? */
3206 scsi_inquiry(&start_ccb->csio,
3207 /*retries*/da_retry_count,
3209 /*tag_action*/MSG_SIMPLE_Q_TAG,
3210 /*inq_buf*/(u_int8_t *)lbp,
3211 /*inq_len*/sizeof(*lbp),
3213 /*page_code*/SVPD_LBP,
3214 /*sense_len*/SSD_MIN_SIZE,
3215 /*timeout*/da_default_timeout * 1000);
3216 start_ccb->ccb_h.ccb_bp = NULL;
3217 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3218 xpt_action(start_ccb);
3221 case DA_STATE_PROBE_BLK_LIMITS:
3223 struct scsi_vpd_block_limits *block_limits;
3225 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3226 /* Not supported skip to next probe */
3227 softc->state = DA_STATE_PROBE_BDC;
3231 block_limits = (struct scsi_vpd_block_limits *)
3232 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3234 if (block_limits == NULL) {
3235 printf("dastart: Couldn't malloc block_limits data\n");
3236 /* da_free_periph??? */
3240 scsi_inquiry(&start_ccb->csio,
3241 /*retries*/da_retry_count,
3243 /*tag_action*/MSG_SIMPLE_Q_TAG,
3244 /*inq_buf*/(u_int8_t *)block_limits,
3245 /*inq_len*/sizeof(*block_limits),
3247 /*page_code*/SVPD_BLOCK_LIMITS,
3248 /*sense_len*/SSD_MIN_SIZE,
3249 /*timeout*/da_default_timeout * 1000);
3250 start_ccb->ccb_h.ccb_bp = NULL;
3251 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3252 xpt_action(start_ccb);
3255 case DA_STATE_PROBE_BDC:
3257 struct scsi_vpd_block_characteristics *bdc;
3259 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3260 softc->state = DA_STATE_PROBE_ATA;
3264 bdc = (struct scsi_vpd_block_characteristics *)
3265 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3268 printf("dastart: Couldn't malloc bdc data\n");
3269 /* da_free_periph??? */
3273 scsi_inquiry(&start_ccb->csio,
3274 /*retries*/da_retry_count,
3276 /*tag_action*/MSG_SIMPLE_Q_TAG,
3277 /*inq_buf*/(u_int8_t *)bdc,
3278 /*inq_len*/sizeof(*bdc),
3280 /*page_code*/SVPD_BDC,
3281 /*sense_len*/SSD_MIN_SIZE,
3282 /*timeout*/da_default_timeout * 1000);
3283 start_ccb->ccb_h.ccb_bp = NULL;
3284 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3285 xpt_action(start_ccb);
3288 case DA_STATE_PROBE_ATA:
3290 struct ata_params *ata_params;
3292 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3293 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3294 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3296 * Note that if the ATA VPD page isn't
3297 * supported, we aren't talking to an ATA
3298 * device anyway. Support for that VPD
3299 * page is mandatory for SCSI to ATA (SAT)
3300 * translation layers.
3302 softc->state = DA_STATE_PROBE_ZONE;
3305 daprobedone(periph, start_ccb);
3309 ata_params = (struct ata_params*)
3310 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3312 if (ata_params == NULL) {
3313 xpt_print(periph->path, "Couldn't malloc ata_params "
3315 /* da_free_periph??? */
3319 scsi_ata_identify(&start_ccb->csio,
3320 /*retries*/da_retry_count,
3322 /*tag_action*/MSG_SIMPLE_Q_TAG,
3323 /*data_ptr*/(u_int8_t *)ata_params,
3324 /*dxfer_len*/sizeof(*ata_params),
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_ATA;
3329 xpt_action(start_ccb);
3332 case DA_STATE_PROBE_ATA_LOGDIR:
3334 struct ata_gp_log_dir *log_dir;
3339 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3341 * If we don't have log support, not much point in
3342 * trying to probe zone support.
3344 daprobedone(periph, start_ccb);
3349 * If we have an ATA device (the SCSI ATA Information VPD
3350 * page should be present and the ATA identify should have
3351 * succeeded) and it supports logs, ask for the log directory.
3354 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3355 if (log_dir == NULL) {
3356 xpt_print(periph->path, "Couldn't malloc log_dir "
3358 daprobedone(periph, start_ccb);
3362 retval = scsi_ata_read_log(&start_ccb->csio,
3363 /*retries*/ da_retry_count,
3365 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3366 /*log_address*/ ATA_LOG_DIRECTORY,
3369 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3370 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3371 /*data_ptr*/ (uint8_t *)log_dir,
3372 /*dxfer_len*/ sizeof(*log_dir),
3373 /*sense_len*/ SSD_FULL_SIZE,
3374 /*timeout*/ da_default_timeout * 1000);
3377 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3378 free(log_dir, M_SCSIDA);
3379 daprobedone(periph, start_ccb);
3382 start_ccb->ccb_h.ccb_bp = NULL;
3383 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3384 xpt_action(start_ccb);
3387 case DA_STATE_PROBE_ATA_IDDIR:
3389 struct ata_identify_log_pages *id_dir;
3395 * Check here to see whether the Identify Device log is
3396 * supported in the directory of logs. If so, continue
3397 * with requesting the log of identify device pages.
3399 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3400 daprobedone(periph, start_ccb);
3404 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3405 if (id_dir == NULL) {
3406 xpt_print(periph->path, "Couldn't malloc id_dir "
3408 daprobedone(periph, start_ccb);
3412 retval = scsi_ata_read_log(&start_ccb->csio,
3413 /*retries*/ da_retry_count,
3415 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3416 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3417 /*page_number*/ ATA_IDL_PAGE_LIST,
3419 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3420 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3421 /*data_ptr*/ (uint8_t *)id_dir,
3422 /*dxfer_len*/ sizeof(*id_dir),
3423 /*sense_len*/ SSD_FULL_SIZE,
3424 /*timeout*/ da_default_timeout * 1000);
3427 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3428 free(id_dir, M_SCSIDA);
3429 daprobedone(periph, start_ccb);
3432 start_ccb->ccb_h.ccb_bp = NULL;
3433 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3434 xpt_action(start_ccb);
3437 case DA_STATE_PROBE_ATA_SUP:
3439 struct ata_identify_log_sup_cap *sup_cap;
3445 * Check here to see whether the Supported Capabilities log
3446 * is in the list of Identify Device logs.
3448 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3449 daprobedone(periph, start_ccb);
3453 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3454 if (sup_cap == NULL) {
3455 xpt_print(periph->path, "Couldn't malloc sup_cap "
3457 daprobedone(periph, start_ccb);
3461 retval = scsi_ata_read_log(&start_ccb->csio,
3462 /*retries*/ da_retry_count,
3464 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3465 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3466 /*page_number*/ ATA_IDL_SUP_CAP,
3468 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3469 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3470 /*data_ptr*/ (uint8_t *)sup_cap,
3471 /*dxfer_len*/ sizeof(*sup_cap),
3472 /*sense_len*/ SSD_FULL_SIZE,
3473 /*timeout*/ da_default_timeout * 1000);
3476 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3477 free(sup_cap, M_SCSIDA);
3478 daprobedone(periph, start_ccb);
3483 start_ccb->ccb_h.ccb_bp = NULL;
3484 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3485 xpt_action(start_ccb);
3488 case DA_STATE_PROBE_ATA_ZONE:
3490 struct ata_zoned_info_log *ata_zone;
3496 * Check here to see whether the zoned device information
3497 * page is supported. If so, continue on to request it.
3498 * If not, skip to DA_STATE_PROBE_LOG or done.
3500 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3501 daprobedone(periph, start_ccb);
3504 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3506 if (ata_zone == NULL) {
3507 xpt_print(periph->path, "Couldn't malloc ata_zone "
3509 daprobedone(periph, start_ccb);
3513 retval = scsi_ata_read_log(&start_ccb->csio,
3514 /*retries*/ da_retry_count,
3516 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3517 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3518 /*page_number*/ ATA_IDL_ZDI,
3520 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3521 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3522 /*data_ptr*/ (uint8_t *)ata_zone,
3523 /*dxfer_len*/ sizeof(*ata_zone),
3524 /*sense_len*/ SSD_FULL_SIZE,
3525 /*timeout*/ da_default_timeout * 1000);
3528 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3529 free(ata_zone, M_SCSIDA);
3530 daprobedone(periph, start_ccb);
3533 start_ccb->ccb_h.ccb_bp = NULL;
3534 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3535 xpt_action(start_ccb);
3539 case DA_STATE_PROBE_ZONE:
3541 struct scsi_vpd_zoned_bdc *bdc;
3544 * Note that this page will be supported for SCSI protocol
3545 * devices that support ZBC (SMR devices), as well as ATA
3546 * protocol devices that are behind a SAT (SCSI to ATA
3547 * Translation) layer that supports converting ZBC commands
3548 * to their ZAC equivalents.
3550 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3551 daprobedone(periph, start_ccb);
3554 bdc = (struct scsi_vpd_zoned_bdc *)
3555 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3558 xpt_release_ccb(start_ccb);
3559 xpt_print(periph->path, "Couldn't malloc zone VPD "
3563 scsi_inquiry(&start_ccb->csio,
3564 /*retries*/da_retry_count,
3566 /*tag_action*/MSG_SIMPLE_Q_TAG,
3567 /*inq_buf*/(u_int8_t *)bdc,
3568 /*inq_len*/sizeof(*bdc),
3570 /*page_code*/SVPD_ZONED_BDC,
3571 /*sense_len*/SSD_FULL_SIZE,
3572 /*timeout*/da_default_timeout * 1000);
3573 start_ccb->ccb_h.ccb_bp = NULL;
3574 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3575 xpt_action(start_ccb);
3582 * In each of the methods below, while its the caller's
3583 * responsibility to ensure the request will fit into a
3584 * single device request, we might have changed the delete
3585 * method due to the device incorrectly advertising either
3586 * its supported methods or limits.
3588 * To prevent this causing further issues we validate the
3589 * against the methods limits, and warn which would
3590 * otherwise be unnecessary.
3593 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3595 struct da_softc *softc = (struct da_softc *)periph->softc;;
3597 uint8_t *buf = softc->unmap_buf;
3598 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3599 uint64_t lba, lastlba = (uint64_t)-1;
3600 uint64_t totalcount = 0;
3602 uint32_t c, lastcount = 0, ranges = 0;
3605 * Currently this doesn't take the UNMAP
3606 * Granularity and Granularity Alignment
3607 * fields into account.
3609 * This could result in both unoptimal unmap
3610 * requests as as well as UNMAP calls unmapping
3611 * fewer LBA's than requested.
3614 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3618 * Note: ada and da are different in how they store the
3619 * pending bp's in a trim. ada stores all of them in the
3620 * trim_req.bps. da stores all but the first one in the
3621 * delete_run_queue. ada then completes all the bps in
3622 * its adadone() loop. da completes all the bps in the
3623 * delete_run_queue in dadone, and relies on the biodone
3624 * after to complete. This should be reconciled since there's
3625 * no real reason to do it differently. XXX
3628 bioq_insert_tail(&softc->delete_run_queue, bp1);
3629 lba = bp1->bio_pblkno;
3630 count = bp1->bio_bcount / softc->params.secsize;
3632 /* Try to extend the previous range. */
3633 if (lba == lastlba) {
3634 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3637 scsi_ulto4b(lastcount, d[ranges - 1].length);
3641 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3642 softc->unmap_gran != 0) {
3643 /* Align length of the previous range. */
3644 if ((c = lastcount % softc->unmap_gran) != 0) {
3645 if (lastcount <= c) {
3646 totalcount -= lastcount;
3647 lastlba = (uint64_t)-1;
3654 scsi_ulto4b(lastcount, d[ranges - 1].length);
3657 /* Align beginning of the new range. */
3658 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3660 c = softc->unmap_gran - c;
3671 c = omin(count, UNMAP_RANGE_MAX);
3672 if (totalcount + c > softc->unmap_max_lba ||
3673 ranges >= softc->unmap_max_ranges) {
3674 xpt_print(periph->path,
3675 "%s issuing short delete %ld > %ld"
3677 da_delete_method_desc[softc->delete_method],
3678 totalcount + c, softc->unmap_max_lba,
3679 ranges, softc->unmap_max_ranges);
3682 scsi_u64to8b(lba, d[ranges].lba);
3683 scsi_ulto4b(c, d[ranges].length);
3691 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3694 if (ranges >= softc->unmap_max_ranges ||
3695 totalcount + bp1->bio_bcount /
3696 softc->params.secsize > softc->unmap_max_lba) {
3697 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3702 /* Align length of the last range. */
3703 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
3704 (c = lastcount % softc->unmap_gran) != 0) {
3708 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
3711 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3712 scsi_ulto2b(ranges * 16, &buf[2]);
3714 scsi_unmap(&ccb->csio,
3715 /*retries*/da_retry_count,
3717 /*tag_action*/MSG_SIMPLE_Q_TAG,
3720 /*dxfer_len*/ ranges * 16 + 8,
3721 /*sense_len*/SSD_FULL_SIZE,
3722 da_default_timeout * 1000);
3723 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3724 ccb->ccb_h.flags |= CAM_UNLOCKED;
3725 cam_iosched_submit_trim(softc->cam_iosched);
3729 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3731 struct da_softc *softc = (struct da_softc *)periph->softc;
3733 uint8_t *buf = softc->unmap_buf;
3734 uint64_t lastlba = (uint64_t)-1;
3737 uint32_t lastcount = 0, c, requestcount;
3738 int ranges = 0, off, block_count;
3740 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3743 if (bp1 != bp)//XXX imp XXX
3744 bioq_insert_tail(&softc->delete_run_queue, bp1);
3745 lba = bp1->bio_pblkno;
3746 count = bp1->bio_bcount / softc->params.secsize;
3747 requestcount = count;
3749 /* Try to extend the previous range. */
3750 if (lba == lastlba) {
3751 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3753 off = (ranges - 1) * 8;
3754 buf[off + 6] = lastcount & 0xff;
3755 buf[off + 7] = (lastcount >> 8) & 0xff;
3761 c = omin(count, ATA_DSM_RANGE_MAX);
3764 buf[off + 0] = lba & 0xff;
3765 buf[off + 1] = (lba >> 8) & 0xff;
3766 buf[off + 2] = (lba >> 16) & 0xff;
3767 buf[off + 3] = (lba >> 24) & 0xff;
3768 buf[off + 4] = (lba >> 32) & 0xff;
3769 buf[off + 5] = (lba >> 40) & 0xff;
3770 buf[off + 6] = c & 0xff;
3771 buf[off + 7] = (c >> 8) & 0xff;
3776 if (count != 0 && ranges == softc->trim_max_ranges) {
3777 xpt_print(periph->path,
3778 "%s issuing short delete %ld > %ld\n",
3779 da_delete_method_desc[softc->delete_method],
3781 (softc->trim_max_ranges - ranges) *
3787 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3790 if (bp1->bio_bcount / softc->params.secsize >
3791 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3792 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3797 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3798 scsi_ata_trim(&ccb->csio,
3799 /*retries*/da_retry_count,
3801 /*tag_action*/MSG_SIMPLE_Q_TAG,
3804 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3805 /*sense_len*/SSD_FULL_SIZE,
3806 da_default_timeout * 1000);
3807 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3808 ccb->ccb_h.flags |= CAM_UNLOCKED;
3809 cam_iosched_submit_trim(softc->cam_iosched);
3813 * We calculate ws_max_blks here based off d_delmaxsize instead
3814 * of using softc->ws_max_blks as it is absolute max for the
3815 * device not the protocol max which may well be lower.
3818 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3820 struct da_softc *softc;
3822 uint64_t ws_max_blks;
3824 uint64_t count; /* forward compat with WS32 */
3826 softc = (struct da_softc *)periph->softc;
3827 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3828 lba = bp->bio_pblkno;
3832 if (bp1 != bp)//XXX imp XXX
3833 bioq_insert_tail(&softc->delete_run_queue, bp1);
3834 count += bp1->bio_bcount / softc->params.secsize;
3835 if (count > ws_max_blks) {
3836 xpt_print(periph->path,
3837 "%s issuing short delete %ld > %ld\n",
3838 da_delete_method_desc[softc->delete_method],
3839 count, ws_max_blks);
3840 count = omin(count, ws_max_blks);
3843 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3846 if (lba + count != bp1->bio_pblkno ||
3847 count + bp1->bio_bcount /
3848 softc->params.secsize > ws_max_blks) {
3849 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3854 scsi_write_same(&ccb->csio,
3855 /*retries*/da_retry_count,
3857 /*tag_action*/MSG_SIMPLE_Q_TAG,
3858 /*byte2*/softc->delete_method ==
3859 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3860 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3862 /*block_count*/count,
3863 /*data_ptr*/ __DECONST(void *, zero_region),
3864 /*dxfer_len*/ softc->params.secsize,
3865 /*sense_len*/SSD_FULL_SIZE,
3866 da_default_timeout * 1000);
3867 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3868 ccb->ccb_h.flags |= CAM_UNLOCKED;
3869 cam_iosched_submit_trim(softc->cam_iosched);
3873 cmd6workaround(union ccb *ccb)
3875 struct scsi_rw_6 cmd6;
3876 struct scsi_rw_10 *cmd10;
3877 struct da_softc *softc;
3882 cdb = ccb->csio.cdb_io.cdb_bytes;
3883 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3885 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3886 da_delete_methods old_method = softc->delete_method;
3889 * Typically there are two reasons for failure here
3890 * 1. Delete method was detected as supported but isn't
3891 * 2. Delete failed due to invalid params e.g. too big
3893 * While we will attempt to choose an alternative delete method
3894 * this may result in short deletes if the existing delete
3895 * requests from geom are big for the new method chosen.
3897 * This method assumes that the error which triggered this
3898 * will not retry the io otherwise a panic will occur
3900 dadeleteflag(softc, old_method, 0);
3901 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3902 if (softc->delete_method == DA_DELETE_DISABLE)
3903 xpt_print(ccb->ccb_h.path,
3904 "%s failed, disabling BIO_DELETE\n",
3905 da_delete_method_desc[old_method]);
3907 xpt_print(ccb->ccb_h.path,
3908 "%s failed, switching to %s BIO_DELETE\n",
3909 da_delete_method_desc[old_method],
3910 da_delete_method_desc[softc->delete_method]);
3912 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3913 cam_iosched_queue_work(softc->cam_iosched, bp);
3914 cam_iosched_queue_work(softc->cam_iosched,
3915 (struct bio *)ccb->ccb_h.ccb_bp);
3916 ccb->ccb_h.ccb_bp = NULL;
3920 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3921 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3922 (*cdb == PREVENT_ALLOW) &&
3923 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3925 xpt_print(ccb->ccb_h.path,
3926 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3927 softc->quirks |= DA_Q_NO_PREVENT;
3931 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3932 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3933 (*cdb == SYNCHRONIZE_CACHE) &&
3934 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3936 xpt_print(ccb->ccb_h.path,
3937 "SYNCHRONIZE CACHE(10) not supported.\n");
3938 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3939 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3943 /* Translation only possible if CDB is an array and cmd is R/W6 */
3944 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3945 (*cdb != READ_6 && *cdb != WRITE_6))
3948 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3949 "increasing minimum_cmd_size to 10.\n");
3950 softc->minimum_cmd_size = 10;
3952 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3953 cmd10 = (struct scsi_rw_10 *)cdb;
3954 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3956 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3957 cmd10->reserved = 0;
3958 scsi_ulto2b(cmd6.length, cmd10->length);
3959 cmd10->control = cmd6.control;
3960 ccb->csio.cdb_len = sizeof(*cmd10);
3962 /* Requeue request, unfreezing queue if necessary */
3963 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3964 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3967 cam_release_devq(ccb->ccb_h.path,
3971 /*getcount_only*/0);
3977 dazonedone(struct cam_periph *periph, union ccb *ccb)
3979 struct da_softc *softc;
3982 softc = periph->softc;
3983 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3985 switch (bp->bio_zone.zone_cmd) {
3986 case DISK_ZONE_OPEN:
3987 case DISK_ZONE_CLOSE:
3988 case DISK_ZONE_FINISH:
3991 case DISK_ZONE_REPORT_ZONES: {
3993 struct disk_zone_report *rep;
3994 struct scsi_report_zones_hdr *hdr;
3995 struct scsi_report_zones_desc *desc;
3996 struct disk_zone_rep_entry *entry;
3997 uint32_t hdr_len, num_avail;
3998 uint32_t num_to_fill, i;
4001 rep = &bp->bio_zone.zone_params.report;
4002 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
4004 * Note that bio_resid isn't normally used for zone
4005 * commands, but it is used by devstat_end_transaction_bio()
4006 * to determine how much data was transferred. Because
4007 * the size of the SCSI/ATA data structures is different
4008 * than the size of the BIO interface structures, the
4009 * amount of data actually transferred from the drive will
4010 * be different than the amount of data transferred to
4013 bp->bio_resid = ccb->csio.resid;
4014 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
4015 if (avail_len < sizeof(*hdr)) {
4017 * Is there a better error than EIO here? We asked
4018 * for at least the header, and we got less than
4021 bp->bio_error = EIO;
4022 bp->bio_flags |= BIO_ERROR;
4023 bp->bio_resid = bp->bio_bcount;
4027 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4032 hdr_len = ata ? le32dec(hdr->length) :
4033 scsi_4btoul(hdr->length);
4035 rep->entries_available = hdr_len / sizeof(*desc);
4037 rep->entries_available = 0;
4039 * NOTE: using the same values for the BIO version of the
4040 * same field as the SCSI/ATA values. This means we could
4041 * get some additional values that aren't defined in bio.h
4042 * if more values of the same field are defined later.
4044 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4045 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4046 scsi_8btou64(hdr->maximum_lba);
4048 * If the drive reports no entries that match the query,
4052 rep->entries_filled = 0;
4056 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4057 hdr_len / sizeof(*desc));
4059 * If the drive didn't return any data, then we're done.
4061 if (num_avail == 0) {
4062 rep->entries_filled = 0;
4066 num_to_fill = min(num_avail, rep->entries_allocated);
4068 * If the user didn't allocate any entries for us to fill,
4071 if (num_to_fill == 0) {
4072 rep->entries_filled = 0;
4076 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4077 i < num_to_fill; i++, desc++, entry++) {
4079 * NOTE: we're mapping the values here directly
4080 * from the SCSI/ATA bit definitions to the bio.h
4081 * definitons. There is also a warning in
4082 * disk_zone.h, but the impact is that if
4083 * additional values are added in the SCSI/ATA
4084 * specs these will be visible to consumers of
4087 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4088 entry->zone_condition =
4089 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4090 SRZ_ZONE_COND_SHIFT;
4091 entry->zone_flags |= desc->zone_flags &
4092 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4093 entry->zone_length =
4094 ata ? le64dec(desc->zone_length) :
4095 scsi_8btou64(desc->zone_length);
4096 entry->zone_start_lba =
4097 ata ? le64dec(desc->zone_start_lba) :
4098 scsi_8btou64(desc->zone_start_lba);
4099 entry->write_pointer_lba =
4100 ata ? le64dec(desc->write_pointer_lba) :
4101 scsi_8btou64(desc->write_pointer_lba);
4103 rep->entries_filled = num_to_fill;
4106 case DISK_ZONE_GET_PARAMS:
4109 * In theory we should not get a GET_PARAMS bio, since it
4110 * should be handled without queueing the command to the
4113 panic("%s: Invalid zone command %d", __func__,
4114 bp->bio_zone.zone_cmd);
4118 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4119 free(ccb->csio.data_ptr, M_SCSIDA);
4123 dadone(struct cam_periph *periph, union ccb *done_ccb)
4125 struct da_softc *softc;
4126 struct ccb_scsiio *csio;
4130 softc = (struct da_softc *)periph->softc;
4131 priority = done_ccb->ccb_h.pinfo.priority;
4133 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4135 csio = &done_ccb->csio;
4136 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4137 if (csio->bio != NULL)
4138 biotrack(csio->bio, __func__);
4140 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4142 case DA_CCB_BUFFER_IO:
4145 struct bio *bp, *bp1;
4147 cam_periph_lock(periph);
4148 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4149 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4153 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4158 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4159 if (error == ERESTART) {
4161 * A retry was scheduled, so
4164 cam_periph_unlock(periph);
4167 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4172 * return all queued I/O with EIO, so that
4173 * the client can retry these I/Os in the
4174 * proper order should it attempt to recover.
4179 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4181 * Catastrophic error. Mark our pack as
4185 * XXX See if this is really a media
4188 xpt_print(periph->path,
4189 "Invalidating pack\n");
4190 softc->flags |= DA_FLAG_PACK_INVALID;
4192 softc->invalidations++;
4194 queued_error = ENXIO;
4196 cam_iosched_flush(softc->cam_iosched, NULL,
4199 bp->bio_error = error;
4200 bp->bio_resid = bp->bio_bcount;
4201 bp->bio_flags |= BIO_ERROR;
4203 } else if (bp != NULL) {
4204 if (state == DA_CCB_DELETE)
4207 bp->bio_resid = csio->resid;
4209 if (bp->bio_resid != 0)
4210 bp->bio_flags |= BIO_ERROR;
4212 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4213 cam_release_devq(done_ccb->ccb_h.path,
4217 /*getcount_only*/0);
4218 } else if (bp != NULL) {
4219 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4220 panic("REQ_CMP with QFRZN");
4221 if (bp->bio_cmd == BIO_ZONE)
4222 dazonedone(periph, done_ccb);
4223 else if (state == DA_CCB_DELETE)
4226 bp->bio_resid = csio->resid;
4227 if ((csio->resid > 0)
4228 && (bp->bio_cmd != BIO_ZONE))
4229 bp->bio_flags |= BIO_ERROR;
4230 if (softc->error_inject != 0) {
4231 bp->bio_error = softc->error_inject;
4232 bp->bio_resid = bp->bio_bcount;
4233 bp->bio_flags |= BIO_ERROR;
4234 softc->error_inject = 0;
4239 biotrack(bp, __func__);
4240 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4241 if (LIST_EMPTY(&softc->pending_ccbs))
4242 softc->flags |= DA_FLAG_WAS_OTAG;
4245 * We need to call cam_iosched before we call biodone so that we
4246 * don't measure any activity that happens in the completion
4247 * routine, which in the case of sendfile can be quite
4250 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4251 xpt_release_ccb(done_ccb);
4252 if (state == DA_CCB_DELETE) {
4253 TAILQ_HEAD(, bio) queue;
4256 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4257 softc->delete_run_queue.insert_point = NULL;
4259 * Normally, the xpt_release_ccb() above would make sure
4260 * that when we have more work to do, that work would
4261 * get kicked off. However, we specifically keep
4262 * delete_running set to 0 before the call above to
4263 * allow other I/O to progress when many BIO_DELETE
4264 * requests are pushed down. We set delete_running to 0
4265 * and call daschedule again so that we don't stall if
4266 * there are no other I/Os pending apart from BIO_DELETEs.
4268 cam_iosched_trim_done(softc->cam_iosched);
4270 cam_periph_unlock(periph);
4271 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4272 TAILQ_REMOVE(&queue, bp1, bio_queue);
4273 bp1->bio_error = bp->bio_error;
4274 if (bp->bio_flags & BIO_ERROR) {
4275 bp1->bio_flags |= BIO_ERROR;
4276 bp1->bio_resid = bp1->bio_bcount;
4283 cam_periph_unlock(periph);
4289 case DA_CCB_PROBE_WP:
4291 struct scsi_mode_header_6 *mode_hdr6;
4292 struct scsi_mode_header_10 *mode_hdr10;
4295 if (softc->minimum_cmd_size > 6) {
4296 mode_hdr10 = (struct scsi_mode_header_10 *)csio->data_ptr;
4297 dev_spec = mode_hdr10->dev_spec;
4299 mode_hdr6 = (struct scsi_mode_header_6 *)csio->data_ptr;
4300 dev_spec = mode_hdr6->dev_spec;
4302 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
4303 if ((dev_spec & 0x80) != 0)
4304 softc->disk->d_flags |= DISKFLAG_WRITE_PROTECT;
4306 softc->disk->d_flags &= ~DISKFLAG_WRITE_PROTECT;
4310 error = daerror(done_ccb, CAM_RETRY_SELTO,
4311 SF_RETRY_UA|SF_NO_PRINT);
4312 if (error == ERESTART)
4314 else if (error != 0) {
4315 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4316 /* Don't wedge this device's queue */
4317 cam_release_devq(done_ccb->ccb_h.path,
4321 /*getcount_only*/0);
4326 free(csio->data_ptr, M_SCSIDA);
4327 xpt_release_ccb(done_ccb);
4328 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
4329 softc->state = DA_STATE_PROBE_RC16;
4331 softc->state = DA_STATE_PROBE_RC;
4332 xpt_schedule(periph, priority);
4335 case DA_CCB_PROBE_RC:
4336 case DA_CCB_PROBE_RC16:
4338 struct scsi_read_capacity_data *rdcap;
4339 struct scsi_read_capacity_data_long *rcaplong;
4346 /* XXX TODO: can this be a malloc? */
4347 announce_buf = softc->announce_temp;
4348 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4350 if (state == DA_CCB_PROBE_RC)
4351 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4353 rcaplong = (struct scsi_read_capacity_data_long *)
4356 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4357 struct disk_params *dp;
4358 uint32_t block_size;
4360 u_int lalba; /* Lowest aligned LBA. */
4362 if (state == DA_CCB_PROBE_RC) {
4363 block_size = scsi_4btoul(rdcap->length);
4364 maxsector = scsi_4btoul(rdcap->addr);
4368 * According to SBC-2, if the standard 10
4369 * byte READ CAPACITY command returns 2^32,
4370 * we should issue the 16 byte version of
4371 * the command, since the device in question
4372 * has more sectors than can be represented
4373 * with the short version of the command.
4375 if (maxsector == 0xffffffff) {
4376 free(rdcap, M_SCSIDA);
4377 xpt_release_ccb(done_ccb);
4378 softc->state = DA_STATE_PROBE_RC16;
4379 xpt_schedule(periph, priority);
4383 block_size = scsi_4btoul(rcaplong->length);
4384 maxsector = scsi_8btou64(rcaplong->addr);
4385 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4389 * Because GEOM code just will panic us if we
4390 * give them an 'illegal' value we'll avoid that
4393 if (block_size == 0) {
4398 if (block_size >= MAXPHYS) {
4399 xpt_print(periph->path,
4400 "unsupportable block size %ju\n",
4401 (uintmax_t) block_size);
4402 announce_buf = NULL;
4403 cam_periph_invalidate(periph);
4406 * We pass rcaplong into dasetgeom(),
4407 * because it will only use it if it is
4410 dasetgeom(periph, block_size, maxsector,
4411 rcaplong, sizeof(*rcaplong));
4412 lbp = (lalba & SRC16_LBPME_A);
4413 dp = &softc->params;
4414 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4415 "%juMB (%ju %u byte sectors)",
4416 ((uintmax_t)dp->secsize * dp->sectors) /
4418 (uintmax_t)dp->sectors, dp->secsize);
4424 * Retry any UNIT ATTENTION type errors. They
4425 * are expected at boot.
4427 error = daerror(done_ccb, CAM_RETRY_SELTO,
4428 SF_RETRY_UA|SF_NO_PRINT);
4429 if (error == ERESTART) {
4431 * A retry was scheuled, so
4435 } else if (error != 0) {
4437 int sense_key, error_code;
4440 struct ccb_getdev cgd;
4442 /* Don't wedge this device's queue */
4443 status = done_ccb->ccb_h.status;
4444 if ((status & CAM_DEV_QFRZN) != 0)
4445 cam_release_devq(done_ccb->ccb_h.path,
4449 /*getcount_only*/0);
4452 xpt_setup_ccb(&cgd.ccb_h,
4453 done_ccb->ccb_h.path,
4454 CAM_PRIORITY_NORMAL);
4455 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4456 xpt_action((union ccb *)&cgd);
4458 if (scsi_extract_sense_ccb(done_ccb,
4459 &error_code, &sense_key, &asc, &ascq))
4465 * If we tried READ CAPACITY(16) and failed,
4466 * fallback to READ CAPACITY(10).
4468 if ((state == DA_CCB_PROBE_RC16) &&
4469 (softc->flags & DA_FLAG_CAN_RC16) &&
4470 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4473 (error_code == SSD_CURRENT_ERROR) &&
4474 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4475 softc->flags &= ~DA_FLAG_CAN_RC16;
4476 free(rdcap, M_SCSIDA);
4477 xpt_release_ccb(done_ccb);
4478 softc->state = DA_STATE_PROBE_RC;
4479 xpt_schedule(periph, priority);
4484 * Attach to anything that claims to be a
4485 * direct access or optical disk device,
4486 * as long as it doesn't return a "Logical
4487 * unit not supported" (0x25) error.
4488 * "Internal Target Failure" (0x44) is also
4489 * special and typically means that the
4490 * device is a SATA drive behind a SATL
4491 * translation that's fallen into a
4492 * terminally fatal state.
4495 && (asc != 0x25) && (asc != 0x44)
4496 && (error_code == SSD_CURRENT_ERROR)) {
4497 const char *sense_key_desc;
4498 const char *asc_desc;
4500 dasetgeom(periph, 512, -1, NULL, 0);
4501 scsi_sense_desc(sense_key, asc, ascq,
4505 snprintf(announce_buf,
4507 "Attempt to query device "
4508 "size failed: %s, %s",
4509 sense_key_desc, asc_desc);
4515 xpt_print(periph->path,
4516 "got CAM status %#x\n",
4517 done_ccb->ccb_h.status);
4520 xpt_print(periph->path, "fatal error, "
4521 "failed to attach to device\n");
4523 announce_buf = NULL;
4526 * Free up resources.
4528 cam_periph_invalidate(periph);
4532 free(csio->data_ptr, M_SCSIDA);
4533 if (announce_buf != NULL &&
4534 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4537 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4539 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4540 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4546 * Create our sysctl variables, now that we know
4547 * we have successfully attached.
4549 /* increase the refcount */
4550 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4552 taskqueue_enqueue(taskqueue_thread,
4553 &softc->sysctl_task);
4555 /* XXX This message is useless! */
4556 xpt_print(periph->path, "fatal error, "
4557 "could not acquire reference count\n");
4561 /* We already probed the device. */
4562 if (softc->flags & DA_FLAG_PROBED) {
4563 daprobedone(periph, done_ccb);
4567 /* Ensure re-probe doesn't see old delete. */
4568 softc->delete_available = 0;
4569 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4570 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4572 * Based on older SBC-3 spec revisions
4573 * any of the UNMAP methods "may" be
4574 * available via LBP given this flag so
4575 * we flag all of them as available and
4576 * then remove those which further
4577 * probes confirm aren't available
4580 * We could also check readcap(16) p_type
4581 * flag to exclude one or more invalid
4582 * write same (X) types here
4584 dadeleteflag(softc, DA_DELETE_WS16, 1);
4585 dadeleteflag(softc, DA_DELETE_WS10, 1);
4586 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4588 xpt_release_ccb(done_ccb);
4589 softc->state = DA_STATE_PROBE_LBP;
4590 xpt_schedule(periph, priority);
4594 xpt_release_ccb(done_ccb);
4595 softc->state = DA_STATE_PROBE_BDC;
4596 xpt_schedule(periph, priority);
4599 case DA_CCB_PROBE_LBP:
4601 struct scsi_vpd_logical_block_prov *lbp;
4603 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4605 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4607 * T10/1799-D Revision 31 states at least one of these
4608 * must be supported but we don't currently enforce this.
4610 dadeleteflag(softc, DA_DELETE_WS16,
4611 (lbp->flags & SVPD_LBP_WS16));
4612 dadeleteflag(softc, DA_DELETE_WS10,
4613 (lbp->flags & SVPD_LBP_WS10));
4614 dadeleteflag(softc, DA_DELETE_UNMAP,
4615 (lbp->flags & SVPD_LBP_UNMAP));
4618 error = daerror(done_ccb, CAM_RETRY_SELTO,
4619 SF_RETRY_UA|SF_NO_PRINT);
4620 if (error == ERESTART)
4622 else if (error != 0) {
4623 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4624 /* Don't wedge this device's queue */
4625 cam_release_devq(done_ccb->ccb_h.path,
4629 /*getcount_only*/0);
4633 * Failure indicates we don't support any SBC-3
4634 * delete methods with UNMAP
4639 free(lbp, M_SCSIDA);
4640 xpt_release_ccb(done_ccb);
4641 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4642 xpt_schedule(periph, priority);
4645 case DA_CCB_PROBE_BLK_LIMITS:
4647 struct scsi_vpd_block_limits *block_limits;
4649 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4651 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4652 uint32_t max_txfer_len = scsi_4btoul(
4653 block_limits->max_txfer_len);
4654 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4655 block_limits->max_unmap_lba_cnt);
4656 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4657 block_limits->max_unmap_blk_cnt);
4658 uint32_t unmap_gran = scsi_4btoul(
4659 block_limits->opt_unmap_grain);
4660 uint32_t unmap_gran_align = scsi_4btoul(
4661 block_limits->unmap_grain_align);
4662 uint64_t ws_max_blks = scsi_8btou64(
4663 block_limits->max_write_same_length);
4665 if (max_txfer_len != 0) {
4666 softc->disk->d_maxsize = MIN(softc->maxio,
4667 (off_t)max_txfer_len * softc->params.secsize);
4671 * We should already support UNMAP but we check lba
4672 * and block count to be sure
4674 if (max_unmap_lba_cnt != 0x00L &&
4675 max_unmap_blk_cnt != 0x00L) {
4676 softc->unmap_max_lba = max_unmap_lba_cnt;
4677 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4679 if (unmap_gran > 1) {
4680 softc->unmap_gran = unmap_gran;
4681 if (unmap_gran_align & 0x80000000) {
4682 softc->unmap_gran_align =
4689 * Unexpected UNMAP limits which means the
4690 * device doesn't actually support UNMAP
4692 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4695 if (ws_max_blks != 0x00L)
4696 softc->ws_max_blks = ws_max_blks;
4699 error = daerror(done_ccb, CAM_RETRY_SELTO,
4700 SF_RETRY_UA|SF_NO_PRINT);
4701 if (error == ERESTART)
4703 else if (error != 0) {
4704 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4705 /* Don't wedge this device's queue */
4706 cam_release_devq(done_ccb->ccb_h.path,
4710 /*getcount_only*/0);
4714 * Failure here doesn't mean UNMAP is not
4715 * supported as this is an optional page.
4717 softc->unmap_max_lba = 1;
4718 softc->unmap_max_ranges = 1;
4722 free(block_limits, M_SCSIDA);
4723 xpt_release_ccb(done_ccb);
4724 softc->state = DA_STATE_PROBE_BDC;
4725 xpt_schedule(periph, priority);
4728 case DA_CCB_PROBE_BDC:
4730 struct scsi_vpd_block_device_characteristics *bdc;
4732 bdc = (struct scsi_vpd_block_device_characteristics *)
4735 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4739 * Disable queue sorting for non-rotational media
4742 u_int16_t old_rate = softc->disk->d_rotation_rate;
4744 valid_len = csio->dxfer_len - csio->resid;
4745 if (SBDC_IS_PRESENT(bdc, valid_len,
4746 medium_rotation_rate)) {
4747 softc->disk->d_rotation_rate =
4748 scsi_2btoul(bdc->medium_rotation_rate);
4749 if (softc->disk->d_rotation_rate ==
4750 SVPD_BDC_RATE_NON_ROTATING) {
4751 cam_iosched_set_sort_queue(
4752 softc->cam_iosched, 0);
4753 softc->rotating = 0;
4755 if (softc->disk->d_rotation_rate != old_rate) {
4756 disk_attr_changed(softc->disk,
4757 "GEOM::rotation_rate", M_NOWAIT);
4760 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4761 && (softc->zone_mode == DA_ZONE_NONE)) {
4764 if (scsi_vpd_supported_page(periph,
4765 SVPD_ATA_INFORMATION))
4771 * The Zoned field will only be set for
4772 * Drive Managed and Host Aware drives. If
4773 * they are Host Managed, the device type
4774 * in the standard INQUIRY data should be
4775 * set to T_ZBC_HM (0x14).
4777 if ((bdc->flags & SVPD_ZBC_MASK) ==
4779 softc->zone_mode = DA_ZONE_HOST_AWARE;
4780 softc->zone_interface = (ata_proto) ?
4781 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4782 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4784 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4785 softc->zone_interface = (ata_proto) ?
4786 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4787 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4789 xpt_print(periph->path, "Unknown zoned "
4791 bdc->flags & SVPD_ZBC_MASK);
4796 error = daerror(done_ccb, CAM_RETRY_SELTO,
4797 SF_RETRY_UA|SF_NO_PRINT);
4798 if (error == ERESTART)
4800 else if (error != 0) {
4801 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4802 /* Don't wedge this device's queue */
4803 cam_release_devq(done_ccb->ccb_h.path,
4807 /*getcount_only*/0);
4812 free(bdc, M_SCSIDA);
4813 xpt_release_ccb(done_ccb);
4814 softc->state = DA_STATE_PROBE_ATA;
4815 xpt_schedule(periph, priority);
4818 case DA_CCB_PROBE_ATA:
4821 struct ata_params *ata_params;
4826 ata_params = (struct ata_params *)csio->data_ptr;
4827 ptr = (uint16_t *)ata_params;
4831 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4834 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4835 ptr[i] = le16toh(ptr[i]);
4836 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4837 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4838 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4839 if (ata_params->max_dsm_blocks != 0)
4840 softc->trim_max_ranges = min(
4841 softc->trim_max_ranges,
4842 ata_params->max_dsm_blocks *
4843 ATA_DSM_BLK_RANGES);
4846 * Disable queue sorting for non-rotational media
4849 old_rate = softc->disk->d_rotation_rate;
4850 softc->disk->d_rotation_rate =
4851 ata_params->media_rotation_rate;
4852 if (softc->disk->d_rotation_rate ==
4853 ATA_RATE_NON_ROTATING) {
4854 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4855 softc->rotating = 0;
4857 if (softc->disk->d_rotation_rate != old_rate) {
4858 disk_attr_changed(softc->disk,
4859 "GEOM::rotation_rate", M_NOWAIT);
4862 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4863 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4865 if (ata_params->support.extension &
4867 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4870 * At this point, if we have a SATA host aware drive,
4871 * we communicate via ATA passthrough unless the
4872 * SAT layer supports ZBC -> ZAC translation. In
4876 * XXX KDM figure out how to detect a host managed
4879 if (softc->zone_mode == DA_ZONE_NONE) {
4881 * Note that we don't override the zone
4882 * mode or interface if it has already been
4883 * set. This is because it has either been
4884 * set as a quirk, or when we probed the
4885 * SCSI Block Device Characteristics page,
4886 * the zoned field was set. The latter
4887 * means that the SAT layer supports ZBC to
4888 * ZAC translation, and we would prefer to
4889 * use that if it is available.
4891 if ((ata_params->support3 &
4892 ATA_SUPPORT_ZONE_MASK) ==
4893 ATA_SUPPORT_ZONE_HOST_AWARE) {
4894 softc->zone_mode = DA_ZONE_HOST_AWARE;
4895 softc->zone_interface =
4896 DA_ZONE_IF_ATA_PASS;
4897 } else if ((ata_params->support3 &
4898 ATA_SUPPORT_ZONE_MASK) ==
4899 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4900 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4901 softc->zone_interface =
4902 DA_ZONE_IF_ATA_PASS;
4907 error = daerror(done_ccb, CAM_RETRY_SELTO,
4908 SF_RETRY_UA|SF_NO_PRINT);
4909 if (error == ERESTART)
4911 else if (error != 0) {
4912 if ((done_ccb->ccb_h.status &
4913 CAM_DEV_QFRZN) != 0) {
4914 /* Don't wedge this device's queue */
4915 cam_release_devq(done_ccb->ccb_h.path,
4919 /*getcount_only*/0);
4924 free(ata_params, M_SCSIDA);
4925 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4926 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4928 * If the ATA IDENTIFY failed, we could be talking
4929 * to a SCSI drive, although that seems unlikely,
4930 * since the drive did report that it supported the
4931 * ATA Information VPD page. If the ATA IDENTIFY
4932 * succeeded, and the SAT layer doesn't support
4933 * ZBC -> ZAC translation, continue on to get the
4934 * directory of ATA logs, and complete the rest of
4935 * the ZAC probe. If the SAT layer does support
4936 * ZBC -> ZAC translation, we want to use that,
4937 * and we'll probe the SCSI Zoned Block Device
4938 * Characteristics VPD page next.
4941 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4942 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4943 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4945 softc->state = DA_STATE_PROBE_ZONE;
4948 if (continue_probe != 0) {
4949 xpt_release_ccb(done_ccb);
4950 xpt_schedule(periph, priority);
4953 daprobedone(periph, done_ccb);
4956 case DA_CCB_PROBE_ATA_LOGDIR:
4960 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4962 softc->valid_logdir_len = 0;
4963 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4964 softc->valid_logdir_len =
4965 csio->dxfer_len - csio->resid;
4966 if (softc->valid_logdir_len > 0)
4967 bcopy(csio->data_ptr, &softc->ata_logdir,
4968 min(softc->valid_logdir_len,
4969 sizeof(softc->ata_logdir)));
4971 * Figure out whether the Identify Device log is
4972 * supported. The General Purpose log directory
4973 * has a header, and lists the number of pages
4974 * available for each GP log identified by the
4975 * offset into the list.
4977 if ((softc->valid_logdir_len >=
4978 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4979 && (le16dec(softc->ata_logdir.header) ==
4980 ATA_GP_LOG_DIR_VERSION)
4981 && (le16dec(&softc->ata_logdir.num_pages[
4982 (ATA_IDENTIFY_DATA_LOG *
4983 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4984 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4986 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4989 error = daerror(done_ccb, CAM_RETRY_SELTO,
4990 SF_RETRY_UA|SF_NO_PRINT);
4991 if (error == ERESTART)
4993 else if (error != 0) {
4995 * If we can't get the ATA log directory,
4996 * then ATA logs are effectively not
4997 * supported even if the bit is set in the
5000 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
5001 DA_FLAG_CAN_ATA_IDLOG);
5002 if ((done_ccb->ccb_h.status &
5003 CAM_DEV_QFRZN) != 0) {
5004 /* Don't wedge this device's queue */
5005 cam_release_devq(done_ccb->ccb_h.path,
5009 /*getcount_only*/0);
5014 free(csio->data_ptr, M_SCSIDA);
5017 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
5018 softc->state = DA_STATE_PROBE_ATA_IDDIR;
5019 xpt_release_ccb(done_ccb);
5020 xpt_schedule(periph, priority);
5023 daprobedone(periph, done_ccb);
5026 case DA_CCB_PROBE_ATA_IDDIR:
5030 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5031 off_t entries_offset, max_entries;
5034 softc->valid_iddir_len = 0;
5035 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
5036 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
5037 DA_FLAG_CAN_ATA_ZONE);
5038 softc->valid_iddir_len =
5039 csio->dxfer_len - csio->resid;
5040 if (softc->valid_iddir_len > 0)
5041 bcopy(csio->data_ptr, &softc->ata_iddir,
5042 min(softc->valid_iddir_len,
5043 sizeof(softc->ata_iddir)));
5046 __offsetof(struct ata_identify_log_pages,entries);
5047 max_entries = softc->valid_iddir_len - entries_offset;
5048 if ((softc->valid_iddir_len > (entries_offset + 1))
5049 && (le64dec(softc->ata_iddir.header) ==
5051 && (softc->ata_iddir.entry_count > 0)) {
5054 num_entries = softc->ata_iddir.entry_count;
5055 num_entries = min(num_entries,
5056 softc->valid_iddir_len - entries_offset);
5057 for (i = 0; i < num_entries &&
5058 i < max_entries; i++) {
5059 if (softc->ata_iddir.entries[i] ==
5062 DA_FLAG_CAN_ATA_SUPCAP;
5063 else if (softc->ata_iddir.entries[i]==
5066 DA_FLAG_CAN_ATA_ZONE;
5069 DA_FLAG_CAN_ATA_SUPCAP)
5071 DA_FLAG_CAN_ATA_ZONE))
5076 error = daerror(done_ccb, CAM_RETRY_SELTO,
5077 SF_RETRY_UA|SF_NO_PRINT);
5078 if (error == ERESTART)
5080 else if (error != 0) {
5082 * If we can't get the ATA Identify Data log
5083 * directory, then it effectively isn't
5084 * supported even if the ATA Log directory
5085 * a non-zero number of pages present for
5088 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5089 if ((done_ccb->ccb_h.status &
5090 CAM_DEV_QFRZN) != 0) {
5091 /* Don't wedge this device's queue */
5092 cam_release_devq(done_ccb->ccb_h.path,
5096 /*getcount_only*/0);
5101 free(csio->data_ptr, M_SCSIDA);
5104 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5105 softc->state = DA_STATE_PROBE_ATA_SUP;
5106 xpt_release_ccb(done_ccb);
5107 xpt_schedule(periph, priority);
5110 daprobedone(periph, done_ccb);
5113 case DA_CCB_PROBE_ATA_SUP:
5117 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5120 struct ata_identify_log_sup_cap *sup_cap;
5123 sup_cap = (struct ata_identify_log_sup_cap *)
5125 valid_len = csio->dxfer_len - csio->resid;
5127 __offsetof(struct ata_identify_log_sup_cap,
5128 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5129 if (valid_len >= needed_size) {
5130 uint64_t zoned, zac_cap;
5132 zoned = le64dec(sup_cap->zoned_cap);
5133 if (zoned & ATA_ZONED_VALID) {
5135 * This should have already been
5136 * set, because this is also in the
5137 * ATA identify data.
5139 if ((zoned & ATA_ZONED_MASK) ==
5140 ATA_SUPPORT_ZONE_HOST_AWARE)
5143 else if ((zoned & ATA_ZONED_MASK) ==
5144 ATA_SUPPORT_ZONE_DEV_MANAGED)
5146 DA_ZONE_DRIVE_MANAGED;
5149 zac_cap = le64dec(sup_cap->sup_zac_cap);
5150 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5151 if (zac_cap & ATA_REPORT_ZONES_SUP)
5152 softc->zone_flags |=
5153 DA_ZONE_FLAG_RZ_SUP;
5154 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5155 softc->zone_flags |=
5156 DA_ZONE_FLAG_OPEN_SUP;
5157 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5158 softc->zone_flags |=
5159 DA_ZONE_FLAG_CLOSE_SUP;
5160 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5161 softc->zone_flags |=
5162 DA_ZONE_FLAG_FINISH_SUP;
5163 if (zac_cap & ATA_ND_RWP_SUP)
5164 softc->zone_flags |=
5165 DA_ZONE_FLAG_RWP_SUP;
5168 * This field was introduced in
5169 * ACS-4, r08 on April 28th, 2015.
5170 * If the drive firmware was written
5171 * to an earlier spec, it won't have
5172 * the field. So, assume all
5173 * commands are supported.
5175 softc->zone_flags |=
5176 DA_ZONE_FLAG_SUP_MASK;
5181 error = daerror(done_ccb, CAM_RETRY_SELTO,
5182 SF_RETRY_UA|SF_NO_PRINT);
5183 if (error == ERESTART)
5185 else if (error != 0) {
5187 * If we can't get the ATA Identify Data
5188 * Supported Capabilities page, clear the
5191 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5193 * And clear zone capabilities.
5195 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5196 if ((done_ccb->ccb_h.status &
5197 CAM_DEV_QFRZN) != 0) {
5198 /* Don't wedge this device's queue */
5199 cam_release_devq(done_ccb->ccb_h.path,
5203 /*getcount_only*/0);
5208 free(csio->data_ptr, M_SCSIDA);
5211 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5212 softc->state = DA_STATE_PROBE_ATA_ZONE;
5213 xpt_release_ccb(done_ccb);
5214 xpt_schedule(periph, priority);
5217 daprobedone(periph, done_ccb);
5220 case DA_CCB_PROBE_ATA_ZONE:
5224 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5225 struct ata_zoned_info_log *zi_log;
5229 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5231 valid_len = csio->dxfer_len - csio->resid;
5232 needed_size = __offsetof(struct ata_zoned_info_log,
5233 version_info) + 1 + sizeof(zi_log->version_info);
5234 if (valid_len >= needed_size) {
5237 tmpvar = le64dec(zi_log->zoned_cap);
5238 if (tmpvar & ATA_ZDI_CAP_VALID) {
5239 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5240 softc->zone_flags |=
5241 DA_ZONE_FLAG_URSWRZ;
5243 softc->zone_flags &=
5244 ~DA_ZONE_FLAG_URSWRZ;
5246 tmpvar = le64dec(zi_log->optimal_seq_zones);
5247 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5248 softc->zone_flags |=
5249 DA_ZONE_FLAG_OPT_SEQ_SET;
5250 softc->optimal_seq_zones = (tmpvar &
5251 ATA_ZDI_OPT_SEQ_MASK);
5253 softc->zone_flags &=
5254 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5255 softc->optimal_seq_zones = 0;
5258 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5259 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5260 softc->zone_flags |=
5261 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5262 softc->optimal_nonseq_zones =
5263 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5265 softc->zone_flags &=
5266 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5267 softc->optimal_nonseq_zones = 0;
5270 tmpvar = le64dec(zi_log->max_seq_req_zones);
5271 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5272 softc->zone_flags |=
5273 DA_ZONE_FLAG_MAX_SEQ_SET;
5274 softc->max_seq_zones =
5275 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5277 softc->zone_flags &=
5278 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5279 softc->max_seq_zones = 0;
5283 error = daerror(done_ccb, CAM_RETRY_SELTO,
5284 SF_RETRY_UA|SF_NO_PRINT);
5285 if (error == ERESTART)
5287 else if (error != 0) {
5288 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5289 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5291 if ((done_ccb->ccb_h.status &
5292 CAM_DEV_QFRZN) != 0) {
5293 /* Don't wedge this device's queue */
5294 cam_release_devq(done_ccb->ccb_h.path,
5298 /*getcount_only*/0);
5303 free(csio->data_ptr, M_SCSIDA);
5305 daprobedone(periph, done_ccb);
5308 case DA_CCB_PROBE_ZONE:
5312 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5315 struct scsi_vpd_zoned_bdc *zoned_bdc;
5318 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5320 valid_len = csio->dxfer_len - csio->resid;
5321 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5322 max_seq_req_zones) + 1 +
5323 sizeof(zoned_bdc->max_seq_req_zones);
5324 if ((valid_len >= needed_len)
5325 && (scsi_2btoul(zoned_bdc->page_length) >=
5327 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5328 softc->zone_flags |=
5329 DA_ZONE_FLAG_URSWRZ;
5331 softc->zone_flags &=
5332 ~DA_ZONE_FLAG_URSWRZ;
5333 softc->optimal_seq_zones =
5334 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5335 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5336 softc->optimal_nonseq_zones = scsi_4btoul(
5337 zoned_bdc->optimal_nonseq_zones);
5338 softc->zone_flags |=
5339 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5340 softc->max_seq_zones =
5341 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5342 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5345 * All of the zone commands are mandatory for SCSI
5348 * XXX KDM this is valid as of September 2015.
5349 * Re-check this assumption once the SAT spec is
5350 * updated to support SCSI ZBC to ATA ZAC mapping.
5351 * Since ATA allows zone commands to be reported
5352 * as supported or not, this may not necessarily
5353 * be true for an ATA device behind a SAT (SCSI to
5354 * ATA Translation) layer.
5356 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5358 error = daerror(done_ccb, CAM_RETRY_SELTO,
5359 SF_RETRY_UA|SF_NO_PRINT);
5360 if (error == ERESTART)
5362 else if (error != 0) {
5363 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5364 /* Don't wedge this device's queue */
5365 cam_release_devq(done_ccb->ccb_h.path,
5369 /*getcount_only*/0);
5373 daprobedone(periph, done_ccb);
5377 /* No-op. We're polling */
5381 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5383 if (daerror(done_ccb, CAM_RETRY_SELTO,
5384 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5387 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5388 cam_release_devq(done_ccb->ccb_h.path,
5392 /*getcount_only*/0);
5394 xpt_release_ccb(done_ccb);
5395 cam_periph_release_locked(periph);
5401 xpt_release_ccb(done_ccb);
5405 dareprobe(struct cam_periph *periph)
5407 struct da_softc *softc;
5410 softc = (struct da_softc *)periph->softc;
5412 /* Probe in progress; don't interfere. */
5413 if (softc->state != DA_STATE_NORMAL)
5416 status = cam_periph_acquire(periph);
5417 KASSERT(status == CAM_REQ_CMP,
5418 ("dareprobe: cam_periph_acquire failed"));
5420 softc->state = DA_STATE_PROBE_WP;
5421 xpt_schedule(periph, CAM_PRIORITY_DEV);
5425 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5427 struct da_softc *softc;
5428 struct cam_periph *periph;
5429 int error, error_code, sense_key, asc, ascq;
5431 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5432 if (ccb->csio.bio != NULL)
5433 biotrack(ccb->csio.bio, __func__);
5436 periph = xpt_path_periph(ccb->ccb_h.path);
5437 softc = (struct da_softc *)periph->softc;
5440 * Automatically detect devices that do not support
5441 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5444 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5445 error = cmd6workaround(ccb);
5446 } else if (scsi_extract_sense_ccb(ccb,
5447 &error_code, &sense_key, &asc, &ascq)) {
5448 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5449 error = cmd6workaround(ccb);
5451 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5452 * query the capacity and notify upper layers.
5454 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5455 asc == 0x2A && ascq == 0x09) {
5456 xpt_print(periph->path, "Capacity data has changed\n");
5457 softc->flags &= ~DA_FLAG_PROBED;
5459 sense_flags |= SF_NO_PRINT;
5460 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5461 asc == 0x28 && ascq == 0x00) {
5462 softc->flags &= ~DA_FLAG_PROBED;
5463 disk_media_changed(softc->disk, M_NOWAIT);
5464 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5465 asc == 0x3F && ascq == 0x03) {
5466 xpt_print(periph->path, "INQUIRY data has changed\n");
5467 softc->flags &= ~DA_FLAG_PROBED;
5469 sense_flags |= SF_NO_PRINT;
5470 } else if (sense_key == SSD_KEY_NOT_READY &&
5471 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5472 softc->flags |= DA_FLAG_PACK_INVALID;
5473 disk_media_gone(softc->disk, M_NOWAIT);
5476 if (error == ERESTART)
5480 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5481 case CAM_CMD_TIMEOUT:
5484 case CAM_REQ_ABORTED:
5485 case CAM_REQ_CMP_ERR:
5486 case CAM_REQ_TERMIO:
5487 case CAM_UNREC_HBA_ERROR:
5488 case CAM_DATA_RUN_ERR:
5498 * Until we have a better way of doing pack validation,
5499 * don't treat UAs as errors.
5501 sense_flags |= SF_RETRY_UA;
5503 if (softc->quirks & DA_Q_RETRY_BUSY)
5504 sense_flags |= SF_RETRY_BUSY;
5505 return(cam_periph_error(ccb, cam_flags, sense_flags));
5509 damediapoll(void *arg)
5511 struct cam_periph *periph = arg;
5512 struct da_softc *softc = periph->softc;
5514 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5515 LIST_EMPTY(&softc->pending_ccbs)) {
5516 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5517 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5521 /* Queue us up again */
5522 if (da_poll_period != 0)
5523 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5527 daprevent(struct cam_periph *periph, int action)
5529 struct da_softc *softc;
5533 softc = (struct da_softc *)periph->softc;
5535 if (((action == PR_ALLOW)
5536 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5537 || ((action == PR_PREVENT)
5538 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5542 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5544 scsi_prevent(&ccb->csio,
5552 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5553 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5556 if (action == PR_ALLOW)
5557 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5559 softc->flags |= DA_FLAG_PACK_LOCKED;
5562 xpt_release_ccb(ccb);
5566 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5567 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5569 struct ccb_calc_geometry ccg;
5570 struct da_softc *softc;
5571 struct disk_params *dp;
5572 u_int lbppbe, lalba;
5575 softc = (struct da_softc *)periph->softc;
5577 dp = &softc->params;
5578 dp->secsize = block_len;
5579 dp->sectors = maxsector + 1;
5580 if (rcaplong != NULL) {
5581 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5582 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5583 lalba &= SRC16_LALBA_A;
5590 dp->stripesize = block_len << lbppbe;
5591 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5593 } else if (softc->quirks & DA_Q_4K) {
5594 dp->stripesize = 4096;
5595 dp->stripeoffset = 0;
5596 } else if (softc->unmap_gran != 0) {
5597 dp->stripesize = block_len * softc->unmap_gran;
5598 dp->stripeoffset = (dp->stripesize - block_len *
5599 softc->unmap_gran_align) % dp->stripesize;
5602 dp->stripeoffset = 0;
5605 * Have the controller provide us with a geometry
5606 * for this disk. The only time the geometry
5607 * matters is when we boot and the controller
5608 * is the only one knowledgeable enough to come
5609 * up with something that will make this a bootable
5612 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5613 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5614 ccg.block_size = dp->secsize;
5615 ccg.volume_size = dp->sectors;
5617 ccg.secs_per_track = 0;
5619 xpt_action((union ccb*)&ccg);
5620 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5622 * We don't know what went wrong here- but just pick
5623 * a geometry so we don't have nasty things like divide
5627 dp->secs_per_track = 255;
5628 dp->cylinders = dp->sectors / (255 * 255);
5629 if (dp->cylinders == 0) {
5633 dp->heads = ccg.heads;
5634 dp->secs_per_track = ccg.secs_per_track;
5635 dp->cylinders = ccg.cylinders;
5639 * If the user supplied a read capacity buffer, and if it is
5640 * different than the previous buffer, update the data in the EDT.
5641 * If it's the same, we don't bother. This avoids sending an
5642 * update every time someone opens this device.
5644 if ((rcaplong != NULL)
5645 && (bcmp(rcaplong, &softc->rcaplong,
5646 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5647 struct ccb_dev_advinfo cdai;
5649 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5650 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5651 cdai.buftype = CDAI_TYPE_RCAPLONG;
5652 cdai.flags = CDAI_FLAG_STORE;
5653 cdai.bufsiz = rcap_len;
5654 cdai.buf = (uint8_t *)rcaplong;
5655 xpt_action((union ccb *)&cdai);
5656 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5657 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5658 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5659 xpt_print(periph->path, "%s: failed to set read "
5660 "capacity advinfo\n", __func__);
5661 /* Use cam_error_print() to decode the status */
5662 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5665 bcopy(rcaplong, &softc->rcaplong,
5666 min(sizeof(softc->rcaplong), rcap_len));
5670 softc->disk->d_sectorsize = softc->params.secsize;
5671 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5672 softc->disk->d_stripesize = softc->params.stripesize;
5673 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5674 /* XXX: these are not actually "firmware" values, so they may be wrong */
5675 softc->disk->d_fwsectors = softc->params.secs_per_track;
5676 softc->disk->d_fwheads = softc->params.heads;
5677 softc->disk->d_devstat->block_size = softc->params.secsize;
5678 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5680 error = disk_resize(softc->disk, M_NOWAIT);
5682 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5686 dasendorderedtag(void *arg)
5688 struct da_softc *softc = arg;
5690 if (da_send_ordered) {
5691 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5692 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5693 softc->flags |= DA_FLAG_NEED_OTAG;
5694 softc->flags &= ~DA_FLAG_WAS_OTAG;
5697 /* Queue us up again */
5698 callout_reset(&softc->sendordered_c,
5699 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5700 dasendorderedtag, softc);
5704 * Step through all DA peripheral drivers, and if the device is still open,
5705 * sync the disk cache to physical media.
5708 dashutdown(void * arg, int howto)
5710 struct cam_periph *periph;
5711 struct da_softc *softc;
5715 CAM_PERIPH_FOREACH(periph, &dadriver) {
5716 softc = (struct da_softc *)periph->softc;
5717 if (SCHEDULER_STOPPED()) {
5718 /* If we paniced with the lock held, do not recurse. */
5719 if (!cam_periph_owned(periph) &&
5720 (softc->flags & DA_FLAG_OPEN)) {
5721 dadump(softc->disk, NULL, 0, 0, 0);
5725 cam_periph_lock(periph);
5728 * We only sync the cache if the drive is still open, and
5729 * if the drive is capable of it..
5731 if (((softc->flags & DA_FLAG_OPEN) == 0)
5732 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5733 cam_periph_unlock(periph);
5737 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5738 scsi_synchronize_cache(&ccb->csio,
5742 /*begin_lba*/0, /* whole disk */
5747 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5748 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5749 softc->disk->d_devstat);
5751 xpt_print(periph->path, "Synchronize cache failed\n");
5752 xpt_release_ccb(ccb);
5753 cam_periph_unlock(periph);
5757 #else /* !_KERNEL */
5760 * XXX These are only left out of the kernel build to silence warnings. If,
5761 * for some reason these functions are used in the kernel, the ifdefs should
5762 * be moved so they are included both in the kernel and userland.
5765 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5766 void (*cbfcnp)(struct cam_periph *, union ccb *),
5767 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5768 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5771 struct scsi_format_unit *scsi_cmd;
5773 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5774 scsi_cmd->opcode = FORMAT_UNIT;
5775 scsi_cmd->byte2 = byte2;
5776 scsi_ulto2b(ileave, scsi_cmd->interleave);
5781 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5791 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5792 void (*cbfcnp)(struct cam_periph *, union ccb *),
5793 uint8_t tag_action, uint8_t list_format,
5794 uint32_t addr_desc_index, uint8_t *data_ptr,
5795 uint32_t dxfer_len, int minimum_cmd_size,
5796 uint8_t sense_len, uint32_t timeout)
5801 * These conditions allow using the 10 byte command. Otherwise we
5802 * need to use the 12 byte command.
5804 if ((minimum_cmd_size <= 10)
5805 && (addr_desc_index == 0)
5806 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5807 struct scsi_read_defect_data_10 *cdb10;
5809 cdb10 = (struct scsi_read_defect_data_10 *)
5810 &csio->cdb_io.cdb_bytes;
5812 cdb_len = sizeof(*cdb10);
5813 bzero(cdb10, cdb_len);
5814 cdb10->opcode = READ_DEFECT_DATA_10;
5815 cdb10->format = list_format;
5816 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5818 struct scsi_read_defect_data_12 *cdb12;
5820 cdb12 = (struct scsi_read_defect_data_12 *)
5821 &csio->cdb_io.cdb_bytes;
5823 cdb_len = sizeof(*cdb12);
5824 bzero(cdb12, cdb_len);
5825 cdb12->opcode = READ_DEFECT_DATA_12;
5826 cdb12->format = list_format;
5827 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5828 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5834 /*flags*/ CAM_DIR_IN,
5844 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5845 void (*cbfcnp)(struct cam_periph *, union ccb *),
5846 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5847 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5850 struct scsi_sanitize *scsi_cmd;
5852 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5853 scsi_cmd->opcode = SANITIZE;
5854 scsi_cmd->byte2 = byte2;
5855 scsi_cmd->control = control;
5856 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5861 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5870 #endif /* _KERNEL */
5873 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5874 void (*cbfcnp)(struct cam_periph *, union ccb *),
5875 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5876 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5877 uint8_t sense_len, uint32_t timeout)
5879 struct scsi_zbc_out *scsi_cmd;
5881 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5882 scsi_cmd->opcode = ZBC_OUT;
5883 scsi_cmd->service_action = service_action;
5884 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5885 scsi_cmd->zone_flags = zone_flags;
5890 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5900 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5901 void (*cbfcnp)(struct cam_periph *, union ccb *),
5902 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5903 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5904 uint8_t sense_len, uint32_t timeout)
5906 struct scsi_zbc_in *scsi_cmd;
5908 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5909 scsi_cmd->opcode = ZBC_IN;
5910 scsi_cmd->service_action = service_action;
5911 scsi_ulto4b(dxfer_len, scsi_cmd->length);
5912 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5913 scsi_cmd->zone_options = zone_options;
5918 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5929 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5930 void (*cbfcnp)(struct cam_periph *, union ccb *),
5931 uint8_t tag_action, int use_ncq,
5932 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5933 uint8_t *data_ptr, uint32_t dxfer_len,
5934 uint8_t *cdb_storage, size_t cdb_storage_len,
5935 uint8_t sense_len, uint32_t timeout)
5937 uint8_t command_out, protocol, ata_flags;
5938 uint16_t features_out;
5939 uint32_t sectors_out, auxiliary;
5945 command_out = ATA_ZAC_MANAGEMENT_OUT;
5946 features_out = (zm_action & 0xf) | (zone_flags << 8);
5947 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5948 if (dxfer_len == 0) {
5949 protocol = AP_PROTO_NON_DATA;
5950 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5953 protocol = AP_PROTO_DMA;
5954 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5955 AP_FLAG_TDIR_TO_DEV;
5956 sectors_out = ((dxfer_len >> 9) & 0xffff);
5960 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5961 if (dxfer_len == 0) {
5962 command_out = ATA_NCQ_NON_DATA;
5963 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5965 * We're assuming the SCSI to ATA translation layer
5966 * will set the NCQ tag number in the tag field.
5967 * That isn't clear from the SAT-4 spec (as of rev 05).
5970 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5972 command_out = ATA_SEND_FPDMA_QUEUED;
5974 * Note that we're defaulting to normal priority,
5975 * and assuming that the SCSI to ATA translation
5976 * layer will insert the NCQ tag number in the tag
5977 * field. That isn't clear in the SAT-4 spec (as
5980 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5982 ata_flags |= AP_FLAG_TLEN_FEAT |
5983 AP_FLAG_TDIR_TO_DEV;
5986 * For SEND FPDMA QUEUED, the transfer length is
5987 * encoded in the FEATURE register, and 0 means
5988 * that 65536 512 byte blocks are to be tranferred.
5989 * In practice, it seems unlikely that we'll see
5990 * a transfer that large, and it may confuse the
5991 * the SAT layer, because generally that means that
5992 * 0 bytes should be transferred.
5994 if (dxfer_len == (65536 * 512)) {
5996 } else if (dxfer_len <= (65535 * 512)) {
5997 features_out = ((dxfer_len >> 9) & 0xffff);
5999 /* The transfer is too big. */
6006 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
6007 protocol = AP_PROTO_FPDMA;
6010 protocol |= AP_EXTEND;
6012 retval = scsi_ata_pass(csio,
6015 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6017 /*protocol*/ protocol,
6018 /*ata_flags*/ ata_flags,
6019 /*features*/ features_out,
6020 /*sector_count*/ sectors_out,
6022 /*command*/ command_out,
6025 /*auxiliary*/ auxiliary,
6027 /*data_ptr*/ data_ptr,
6028 /*dxfer_len*/ dxfer_len,
6029 /*cdb_storage*/ cdb_storage,
6030 /*cdb_storage_len*/ cdb_storage_len,
6031 /*minimum_cmd_size*/ 0,
6032 /*sense_len*/ SSD_FULL_SIZE,
6033 /*timeout*/ timeout);
6041 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
6042 void (*cbfcnp)(struct cam_periph *, union ccb *),
6043 uint8_t tag_action, int use_ncq,
6044 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6045 uint8_t *data_ptr, uint32_t dxfer_len,
6046 uint8_t *cdb_storage, size_t cdb_storage_len,
6047 uint8_t sense_len, uint32_t timeout)
6049 uint8_t command_out, protocol;
6050 uint16_t features_out, sectors_out;
6056 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
6059 command_out = ATA_ZAC_MANAGEMENT_IN;
6060 /* XXX KDM put a macro here */
6061 features_out = (zm_action & 0xf) | (zone_flags << 8);
6062 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
6063 protocol = AP_PROTO_DMA;
6064 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
6067 ata_flags |= AP_FLAG_TLEN_FEAT;
6069 command_out = ATA_RECV_FPDMA_QUEUED;
6070 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6073 * For RECEIVE FPDMA QUEUED, the transfer length is
6074 * encoded in the FEATURE register, and 0 means
6075 * that 65536 512 byte blocks are to be tranferred.
6076 * In practice, it seems unlikely that we'll see
6077 * a transfer that large, and it may confuse the
6078 * the SAT layer, because generally that means that
6079 * 0 bytes should be transferred.
6081 if (dxfer_len == (65536 * 512)) {
6083 } else if (dxfer_len <= (65535 * 512)) {
6084 features_out = ((dxfer_len >> 9) & 0xffff);
6086 /* The transfer is too big. */
6090 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6091 protocol = AP_PROTO_FPDMA;
6094 protocol |= AP_EXTEND;
6096 retval = scsi_ata_pass(csio,
6099 /*flags*/ CAM_DIR_IN,
6101 /*protocol*/ protocol,
6102 /*ata_flags*/ ata_flags,
6103 /*features*/ features_out,
6104 /*sector_count*/ sectors_out,
6106 /*command*/ command_out,
6109 /*auxiliary*/ auxiliary,
6111 /*data_ptr*/ data_ptr,
6112 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6113 /*cdb_storage*/ cdb_storage,
6114 /*cdb_storage_len*/ cdb_storage_len,
6115 /*minimum_cmd_size*/ 0,
6116 /*sense_len*/ SSD_FULL_SIZE,
6117 /*timeout*/ timeout);