2 * Implementation of SCSI Direct Access Peripheral driver for CAM.
4 * Copyright (c) 1997 Justin T. Gibbs.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
38 #include <sys/sysctl.h>
39 #include <sys/taskqueue.h>
41 #include <sys/mutex.h>
43 #include <sys/devicestat.h>
44 #include <sys/eventhandler.h>
45 #include <sys/malloc.h>
47 #include <sys/endian.h>
50 #include <geom/geom.h>
51 #include <geom/geom_disk.h>
60 #include <cam/cam_ccb.h>
61 #include <cam/cam_periph.h>
62 #include <cam/cam_xpt_periph.h>
63 #include <cam/cam_sim.h>
64 #include <cam/cam_iosched.h>
66 #include <cam/scsi/scsi_message.h>
67 #include <cam/scsi/scsi_da.h>
71 * Note that there are probe ordering dependencies here. The order isn't
72 * controlled by this enumeration, but by explicit state transitions in
73 * dastart() and dadone(). Here are some of the dependencies:
75 * 1. RC should come first, before RC16, unless there is evidence that RC16
77 * 2. BDC needs to come before any of the ATA probes, or the ZONE probe.
78 * 3. The ATA probes should go in this order:
79 * ATA -> LOGDIR -> IDDIR -> SUP -> ATA_ZONE
85 DA_STATE_PROBE_BLK_LIMITS,
88 DA_STATE_PROBE_ATA_LOGDIR,
89 DA_STATE_PROBE_ATA_IDDIR,
90 DA_STATE_PROBE_ATA_SUP,
91 DA_STATE_PROBE_ATA_ZONE,
97 DA_FLAG_PACK_INVALID = 0x000001,
98 DA_FLAG_NEW_PACK = 0x000002,
99 DA_FLAG_PACK_LOCKED = 0x000004,
100 DA_FLAG_PACK_REMOVABLE = 0x000008,
101 DA_FLAG_NEED_OTAG = 0x000020,
102 DA_FLAG_WAS_OTAG = 0x000040,
103 DA_FLAG_RETRY_UA = 0x000080,
104 DA_FLAG_OPEN = 0x000100,
105 DA_FLAG_SCTX_INIT = 0x000200,
106 DA_FLAG_CAN_RC16 = 0x000400,
107 DA_FLAG_PROBED = 0x000800,
108 DA_FLAG_DIRTY = 0x001000,
109 DA_FLAG_ANNOUNCED = 0x002000,
110 DA_FLAG_CAN_ATA_DMA = 0x004000,
111 DA_FLAG_CAN_ATA_LOG = 0x008000,
112 DA_FLAG_CAN_ATA_IDLOG = 0x010000,
113 DA_FLAG_CAN_ATA_SUPCAP = 0x020000,
114 DA_FLAG_CAN_ATA_ZONE = 0x040000
119 DA_Q_NO_SYNC_CACHE = 0x01,
120 DA_Q_NO_6_BYTE = 0x02,
121 DA_Q_NO_PREVENT = 0x04,
124 DA_Q_NO_UNMAP = 0x20,
125 DA_Q_RETRY_BUSY = 0x40,
127 DA_Q_STRICT_UNMAP = 0x100
130 #define DA_Q_BIT_STRING \
132 "\001NO_SYNC_CACHE" \
143 DA_CCB_PROBE_RC = 0x01,
144 DA_CCB_PROBE_RC16 = 0x02,
145 DA_CCB_PROBE_LBP = 0x03,
146 DA_CCB_PROBE_BLK_LIMITS = 0x04,
147 DA_CCB_PROBE_BDC = 0x05,
148 DA_CCB_PROBE_ATA = 0x06,
149 DA_CCB_BUFFER_IO = 0x07,
151 DA_CCB_DELETE = 0x0B,
153 DA_CCB_PROBE_ZONE = 0x0D,
154 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
155 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
156 DA_CCB_PROBE_ATA_SUP = 0x10,
157 DA_CCB_PROBE_ATA_ZONE = 0x11,
158 DA_CCB_TYPE_MASK = 0x1F,
159 DA_CCB_RETRY_UA = 0x20
163 * Order here is important for method choice
165 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
166 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
167 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
168 * import taking 5mins.
179 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
180 DA_DELETE_MAX = DA_DELETE_ZERO
184 * For SCSI, host managed drives show up as a separate device type. For
185 * ATA, host managed drives also have a different device signature.
186 * XXX KDM figure out the ATA host managed signature.
190 DA_ZONE_DRIVE_MANAGED = 0x01,
191 DA_ZONE_HOST_AWARE = 0x02,
192 DA_ZONE_HOST_MANAGED = 0x03
196 * We distinguish between these interface cases in addition to the drive type:
197 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
198 * o ATA drive behind a SCSI translation layer that does not know about
199 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
200 * case, we would need to share the ATA code with the ada(4) driver.
210 DA_ZONE_FLAG_RZ_SUP = 0x0001,
211 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
212 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
213 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
214 DA_ZONE_FLAG_RWP_SUP = 0x0010,
215 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
216 DA_ZONE_FLAG_OPEN_SUP |
217 DA_ZONE_FLAG_CLOSE_SUP |
218 DA_ZONE_FLAG_FINISH_SUP |
219 DA_ZONE_FLAG_RWP_SUP),
220 DA_ZONE_FLAG_URSWRZ = 0x0020,
221 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
222 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
223 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
224 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
225 DA_ZONE_FLAG_OPT_NONSEQ_SET |
226 DA_ZONE_FLAG_MAX_SEQ_SET)
229 static struct da_zone_desc {
232 } da_zone_desc_table[] = {
233 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
234 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
235 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
236 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
237 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
240 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
242 static da_delete_func_t da_delete_trim;
243 static da_delete_func_t da_delete_unmap;
244 static da_delete_func_t da_delete_ws;
246 static const void * da_delete_functions[] = {
256 static const char *da_delete_method_names[] =
257 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
258 static const char *da_delete_method_desc[] =
259 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
260 "WRITE SAME(10) with UNMAP", "ZERO" };
262 /* Offsets into our private area for storing information */
263 #define ccb_state ppriv_field0
264 #define ccb_bp ppriv_ptr1
269 u_int8_t secs_per_track;
270 u_int32_t secsize; /* Number of bytes/sector */
271 u_int64_t sectors; /* total number sectors */
276 #define UNMAP_RANGE_MAX 0xffffffff
277 #define UNMAP_HEAD_SIZE 8
278 #define UNMAP_RANGE_SIZE 16
279 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
280 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
283 #define WS10_MAX_BLKS 0xffff
284 #define WS16_MAX_BLKS 0xffffffff
285 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
286 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
288 #define DA_WORK_TUR (1 << 16)
291 struct cam_iosched_softc *cam_iosched;
292 struct bio_queue_head delete_run_queue;
293 LIST_HEAD(, ccb_hdr) pending_ccbs;
294 int refcount; /* Active xpt_action() calls */
298 int minimum_cmd_size;
301 int delete_available; /* Delete methods possibly available */
302 da_zone_mode zone_mode;
303 da_zone_interface zone_interface;
304 da_zone_flags zone_flags;
305 struct ata_gp_log_dir ata_logdir;
306 int valid_logdir_len;
307 struct ata_identify_log_pages ata_iddir;
309 uint64_t optimal_seq_zones;
310 uint64_t optimal_nonseq_zones;
311 uint64_t max_seq_zones;
313 uint32_t unmap_max_ranges;
314 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
316 uint32_t unmap_gran_align;
317 uint64_t ws_max_blks;
318 da_delete_methods delete_method_pref;
319 da_delete_methods delete_method;
320 da_delete_func_t *delete_func;
323 struct disk_params params;
326 struct task sysctl_task;
327 struct sysctl_ctx_list sysctl_ctx;
328 struct sysctl_oid *sysctl_tree;
329 struct callout sendordered_c;
331 uint8_t unmap_buf[UNMAP_BUF_SIZE];
332 struct scsi_read_capacity_data_long rcaplong;
333 struct callout mediapoll_c;
335 struct sysctl_ctx_list sysctl_stats_ctx;
336 struct sysctl_oid *sysctl_stats_tree;
343 #define dadeleteflag(softc, delete_method, enable) \
345 softc->delete_available |= (1 << delete_method); \
347 softc->delete_available &= ~(1 << delete_method); \
350 struct da_quirk_entry {
351 struct scsi_inquiry_pattern inq_pat;
355 static const char quantum[] = "QUANTUM";
356 static const char microp[] = "MICROP";
358 static struct da_quirk_entry da_quirk_table[] =
360 /* SPI, FC devices */
363 * Fujitsu M2513A MO drives.
364 * Tested devices: M2513A2 firmware versions 1200 & 1300.
365 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
366 * Reported by: W.Scholten <whs@xs4all.nl>
368 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
369 /*quirks*/ DA_Q_NO_SYNC_CACHE
373 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
374 /*quirks*/ DA_Q_NO_SYNC_CACHE
378 * This particular Fujitsu drive doesn't like the
379 * synchronize cache command.
380 * Reported by: Tom Jackson <toj@gorilla.net>
382 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
383 /*quirks*/ DA_Q_NO_SYNC_CACHE
387 * This drive doesn't like the synchronize cache command
388 * either. Reported by: Matthew Jacob <mjacob@feral.com>
389 * in NetBSD PR kern/6027, August 24, 1998.
391 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
392 /*quirks*/ DA_Q_NO_SYNC_CACHE
396 * This drive doesn't like the synchronize cache command
397 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
400 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
401 /*quirks*/ DA_Q_NO_SYNC_CACHE
405 * Doesn't like the synchronize cache command.
406 * Reported by: Blaz Zupan <blaz@gold.amis.net>
408 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
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, quantum, "MAVERICK 540S", "*"},
417 /*quirks*/ DA_Q_NO_SYNC_CACHE
421 * Doesn't like the synchronize cache command.
423 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
424 /*quirks*/ DA_Q_NO_SYNC_CACHE
428 * Doesn't like the synchronize cache command.
429 * Reported by: walter@pelissero.de
431 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
432 /*quirks*/ DA_Q_NO_SYNC_CACHE
436 * Doesn't work correctly with 6 byte reads/writes.
437 * Returns illegal request, and points to byte 9 of the
439 * Reported by: Adam McDougall <bsdx@spawnet.com>
441 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
442 /*quirks*/ DA_Q_NO_6_BYTE
446 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
447 /*quirks*/ DA_Q_NO_6_BYTE
451 * Doesn't like the synchronize cache command.
452 * Reported by: walter@pelissero.de
454 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
455 /*quirks*/ DA_Q_NO_SYNC_CACHE
459 * The CISS RAID controllers do not support SYNC_CACHE
461 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
462 /*quirks*/ DA_Q_NO_SYNC_CACHE
466 * The STEC SSDs sometimes hang on UNMAP.
468 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
469 /*quirks*/ DA_Q_NO_UNMAP
473 * VMware returns BUSY status when storage has transient
474 * connectivity problems, so better wait.
475 * Also VMware returns odd errors on misaligned UNMAPs.
477 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
478 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
480 /* USB mass storage devices supported by umass(4) */
483 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
486 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
487 /*quirks*/ DA_Q_NO_SYNC_CACHE
491 * Power Quotient Int. (PQI) USB flash key
494 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
495 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
499 * Creative Nomad MUVO mp3 player (USB)
502 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
503 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
507 * Jungsoft NEXDISK USB flash key
510 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
511 /*quirks*/ DA_Q_NO_SYNC_CACHE
515 * FreeDik USB Mini Data Drive
518 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
519 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
523 * Sigmatel USB Flash MP3 Player
526 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
527 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
531 * Neuros USB Digital Audio Computer
534 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
535 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
539 * SEAGRAND NP-900 MP3 Player
542 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
543 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
547 * iRiver iFP MP3 player (with UMS Firmware)
548 * PR: kern/54881, i386/63941, kern/66124
550 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
551 /*quirks*/ DA_Q_NO_SYNC_CACHE
555 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
558 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
559 /*quirks*/ DA_Q_NO_SYNC_CACHE
563 * ZICPlay USB MP3 Player with FM
566 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
567 /*quirks*/ DA_Q_NO_SYNC_CACHE
571 * TEAC USB floppy mechanisms
573 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
574 /*quirks*/ DA_Q_NO_SYNC_CACHE
578 * Kingston DataTraveler II+ USB Pen-Drive.
579 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
581 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
582 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
590 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
591 /*quirks*/ DA_Q_NO_SYNC_CACHE
595 * Motorola E398 Mobile Phone (TransFlash memory card).
596 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
599 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
600 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
604 * Qware BeatZkey! Pro
607 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
608 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
612 * Time DPA20B 1GB MP3 Player
615 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
616 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
620 * Samsung USB key 128Mb
623 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
624 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
628 * Kingston DataTraveler 2.0 USB Flash memory.
631 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
632 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
636 * Creative MUVO Slim mp3 player (USB)
639 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
640 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
644 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
647 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
648 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
652 * SanDisk Micro Cruzer 128MB
655 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
656 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
660 * TOSHIBA TransMemory USB sticks
663 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
664 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
668 * PNY USB 3.0 Flash Drives
670 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
671 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
676 * PR: usb/75578, usb/72344, usb/65436
678 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
679 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
683 * Genesys 6-in-1 Card Reader
686 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
687 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
691 * Rekam Digital CAMERA
694 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
695 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
699 * iRiver H10 MP3 player
702 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
703 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
707 * iRiver U10 MP3 player
710 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
711 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
718 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
719 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
723 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
726 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
727 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
734 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
735 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
739 * Philips USB Key Audio KEY013
742 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
743 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
750 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
751 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
758 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
759 /*quirks*/ DA_Q_NO_SYNC_CACHE
763 * I/O Magic USB flash - Giga Bank
766 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
767 /*quirks*/ DA_Q_NO_SYNC_CACHE
771 * JoyFly 128mb USB Flash Drive
774 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
775 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
782 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
783 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
787 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
790 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
791 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
795 * Samsung YP-U3 mp3-player
798 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
799 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
802 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
803 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
807 * Sony Cyber-Shot DSC cameras
810 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
811 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
814 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
815 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
818 /* At least several Transcent USB sticks lie on RC16. */
819 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
820 "*"}, /*quirks*/ DA_Q_NO_RC16
824 * I-O Data USB Flash Disk
827 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
828 "*"}, /*quirks*/ DA_Q_NO_RC16
830 /* ATA/SATA devices over SAS/USB/... */
832 /* Hitachi Advanced Format (4k) drives */
833 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
837 /* Samsung Advanced Format (4k) drives */
838 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
842 /* Samsung Advanced Format (4k) drives */
843 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
847 /* Samsung Advanced Format (4k) drives */
848 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
852 /* Samsung Advanced Format (4k) drives */
853 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
857 /* Seagate Barracuda Green Advanced Format (4k) drives */
858 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
862 /* Seagate Barracuda Green Advanced Format (4k) drives */
863 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
867 /* Seagate Barracuda Green Advanced Format (4k) drives */
868 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
872 /* Seagate Barracuda Green Advanced Format (4k) drives */
873 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
877 /* Seagate Barracuda Green Advanced Format (4k) drives */
878 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
882 /* Seagate Barracuda Green Advanced Format (4k) drives */
883 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
887 /* Seagate Momentus Advanced Format (4k) drives */
888 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
892 /* Seagate Momentus Advanced Format (4k) drives */
893 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
897 /* Seagate Momentus Advanced Format (4k) drives */
898 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
902 /* Seagate Momentus Advanced Format (4k) drives */
903 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
907 /* Seagate Momentus Advanced Format (4k) drives */
908 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
912 /* Seagate Momentus Advanced Format (4k) drives */
913 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
917 /* Seagate Momentus Advanced Format (4k) drives */
918 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
922 /* Seagate Momentus Advanced Format (4k) drives */
923 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
927 /* Seagate Momentus Advanced Format (4k) drives */
928 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
932 /* Seagate Momentus Advanced Format (4k) drives */
933 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
937 /* Seagate Momentus Advanced Format (4k) drives */
938 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
942 /* Seagate Momentus Advanced Format (4k) drives */
943 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
947 /* Seagate Momentus Advanced Format (4k) drives */
948 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
952 /* Seagate Momentus Advanced Format (4k) drives */
953 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
957 /* Seagate Momentus Thin Advanced Format (4k) drives */
958 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
962 /* Seagate Momentus Thin Advanced Format (4k) drives */
963 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
967 /* WDC Caviar Green Advanced Format (4k) drives */
968 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
972 /* WDC Caviar Green Advanced Format (4k) drives */
973 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
977 /* WDC Caviar Green Advanced Format (4k) drives */
978 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
982 /* WDC Caviar Green Advanced Format (4k) drives */
983 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
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 Scorpio Black Advanced Format (4k) drives */
1008 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1012 /* WDC Scorpio Black Advanced Format (4k) drives */
1013 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1017 /* WDC Scorpio Black Advanced Format (4k) drives */
1018 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1022 /* WDC Scorpio Black Advanced Format (4k) drives */
1023 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1027 /* WDC Scorpio Blue Advanced Format (4k) drives */
1028 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1032 /* WDC Scorpio Blue Advanced Format (4k) drives */
1033 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1037 /* WDC Scorpio Blue Advanced Format (4k) drives */
1038 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1042 /* WDC Scorpio Blue Advanced Format (4k) drives */
1043 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1048 * Olympus FE-210 camera
1050 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1051 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1055 * LG UP3S MP3 player
1057 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1058 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1062 * Laser MP3-2GA13 MP3 player
1064 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1065 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1069 * LaCie external 250GB Hard drive des by Porsche
1070 * Submitted by: Ben Stuyts <ben@altesco.nl>
1073 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1074 /*quirks*/ DA_Q_NO_SYNC_CACHE
1079 * Corsair Force 2 SSDs
1080 * 4k optimised & trim only works in 4k requests + 4k aligned
1082 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1087 * Corsair Force 3 SSDs
1088 * 4k optimised & trim only works in 4k requests + 4k aligned
1090 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1095 * Corsair Neutron GTX SSDs
1096 * 4k optimised & trim only works in 4k requests + 4k aligned
1098 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1103 * Corsair Force GT & GS SSDs
1104 * 4k optimised & trim only works in 4k requests + 4k aligned
1106 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1112 * 4k optimised & trim only works in 4k requests + 4k aligned
1114 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1119 * Crucial RealSSD C300 SSDs
1122 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1123 "*" }, /*quirks*/DA_Q_4K
1127 * Intel 320 Series SSDs
1128 * 4k optimised & trim only works in 4k requests + 4k aligned
1130 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1135 * Intel 330 Series SSDs
1136 * 4k optimised & trim only works in 4k requests + 4k aligned
1138 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1143 * Intel 510 Series SSDs
1144 * 4k optimised & trim only works in 4k requests + 4k aligned
1146 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1151 * Intel 520 Series SSDs
1152 * 4k optimised & trim only works in 4k requests + 4k aligned
1154 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1159 * Intel X25-M Series SSDs
1160 * 4k optimised & trim only works in 4k requests + 4k aligned
1162 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1167 * Kingston E100 Series SSDs
1168 * 4k optimised & trim only works in 4k requests + 4k aligned
1170 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1175 * Kingston HyperX 3k SSDs
1176 * 4k optimised & trim only works in 4k requests + 4k aligned
1178 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1183 * Marvell SSDs (entry taken from OpenSolaris)
1184 * 4k optimised & trim only works in 4k requests + 4k aligned
1186 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1191 * OCZ Agility 2 SSDs
1192 * 4k optimised & trim only works in 4k requests + 4k aligned
1194 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1199 * OCZ Agility 3 SSDs
1200 * 4k optimised & trim only works in 4k requests + 4k aligned
1202 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1207 * OCZ Deneva R Series SSDs
1208 * 4k optimised & trim only works in 4k requests + 4k aligned
1210 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1215 * OCZ Vertex 2 SSDs (inc pro series)
1216 * 4k optimised & trim only works in 4k requests + 4k aligned
1218 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1224 * 4k optimised & trim only works in 4k requests + 4k aligned
1226 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1232 * 4k optimised & trim only works in 4k requests + 4k aligned
1234 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1239 * Samsung 830 Series SSDs
1240 * 4k optimised & trim only works in 4k requests + 4k aligned
1242 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1248 * 4k optimised & trim only works in 4k requests + 4k aligned
1250 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1256 * 4k optimised & trim only works in 4k requests + 4k aligned
1258 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1263 * Samsung 843T Series SSDs (MZ7WD*)
1264 * Samsung PM851 Series SSDs (MZ7TE*)
1265 * Samsung PM853T Series SSDs (MZ7GE*)
1266 * Samsung SM863 Series SSDs (MZ7KM*)
1269 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1274 * SuperTalent TeraDrive CT SSDs
1275 * 4k optimised & trim only works in 4k requests + 4k aligned
1277 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1282 * XceedIOPS SATA SSDs
1285 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1290 * Hama Innostor USB-Stick
1292 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1293 /*quirks*/DA_Q_NO_RC16
1297 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1298 * Drive Managed SATA hard drive. This drive doesn't report
1299 * in firmware that it is a drive managed SMR drive.
1301 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS0002*", "*" },
1302 /*quirks*/DA_Q_SMR_DM
1306 * MX-ES USB Drive by Mach Xtreme
1308 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1309 /*quirks*/DA_Q_NO_RC16
1313 static disk_strategy_t dastrategy;
1314 static dumper_t dadump;
1315 static periph_init_t dainit;
1316 static void daasync(void *callback_arg, u_int32_t code,
1317 struct cam_path *path, void *arg);
1318 static void dasysctlinit(void *context, int pending);
1319 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1320 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1321 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1322 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1323 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1324 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1325 static void dadeletemethodset(struct da_softc *softc,
1326 da_delete_methods delete_method);
1327 static off_t dadeletemaxsize(struct da_softc *softc,
1328 da_delete_methods delete_method);
1329 static void dadeletemethodchoose(struct da_softc *softc,
1330 da_delete_methods default_method);
1331 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1333 static periph_ctor_t daregister;
1334 static periph_dtor_t dacleanup;
1335 static periph_start_t dastart;
1336 static periph_oninv_t daoninvalidate;
1337 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1338 static void dadone(struct cam_periph *periph,
1339 union ccb *done_ccb);
1340 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1341 u_int32_t sense_flags);
1342 static void daprevent(struct cam_periph *periph, int action);
1343 static void dareprobe(struct cam_periph *periph);
1344 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1346 struct scsi_read_capacity_data_long *rcaplong,
1348 static timeout_t dasendorderedtag;
1349 static void dashutdown(void *arg, int howto);
1350 static timeout_t damediapoll;
1352 #ifndef DA_DEFAULT_POLL_PERIOD
1353 #define DA_DEFAULT_POLL_PERIOD 3
1356 #ifndef DA_DEFAULT_TIMEOUT
1357 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1360 #ifndef DA_DEFAULT_SOFTTIMEOUT
1361 #define DA_DEFAULT_SOFTTIMEOUT 0
1364 #ifndef DA_DEFAULT_RETRY
1365 #define DA_DEFAULT_RETRY 4
1368 #ifndef DA_DEFAULT_SEND_ORDERED
1369 #define DA_DEFAULT_SEND_ORDERED 1
1372 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1373 static int da_retry_count = DA_DEFAULT_RETRY;
1374 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1375 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1376 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1378 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1379 "CAM Direct Access Disk driver");
1380 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1381 &da_poll_period, 0, "Media polling period in seconds");
1382 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1383 &da_retry_count, 0, "Normal I/O retry count");
1384 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1385 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1386 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1387 &da_send_ordered, 0, "Send Ordered Tags");
1389 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1390 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1391 "Soft I/O timeout (ms)");
1392 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1395 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1396 * to the default timeout, we check to see whether an ordered
1397 * tagged transaction is appropriate to prevent simple tag
1398 * starvation. Since we'd like to ensure that there is at least
1399 * 1/2 of the timeout length left for a starved transaction to
1400 * complete after we've sent an ordered tag, we must poll at least
1401 * four times in every timeout period. This takes care of the worst
1402 * case where a starved transaction starts during an interval that
1403 * meets the requirement "don't send an ordered tag" test so it takes
1404 * us two intervals to determine that a tag must be sent.
1406 #ifndef DA_ORDEREDTAG_INTERVAL
1407 #define DA_ORDEREDTAG_INTERVAL 4
1410 static struct periph_driver dadriver =
1413 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1416 PERIPHDRIVER_DECLARE(da, dadriver);
1418 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1421 daopen(struct disk *dp)
1423 struct cam_periph *periph;
1424 struct da_softc *softc;
1427 periph = (struct cam_periph *)dp->d_drv1;
1428 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1432 cam_periph_lock(periph);
1433 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1434 cam_periph_unlock(periph);
1435 cam_periph_release(periph);
1439 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1442 softc = (struct da_softc *)periph->softc;
1445 /* Wait for the disk size update. */
1446 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1449 xpt_print(periph->path, "unable to retrieve capacity data\n");
1451 if (periph->flags & CAM_PERIPH_INVALID)
1454 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1455 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1456 daprevent(periph, PR_PREVENT);
1459 softc->flags &= ~DA_FLAG_PACK_INVALID;
1460 softc->flags |= DA_FLAG_OPEN;
1463 cam_periph_unhold(periph);
1464 cam_periph_unlock(periph);
1467 cam_periph_release(periph);
1473 daclose(struct disk *dp)
1475 struct cam_periph *periph;
1476 struct da_softc *softc;
1480 periph = (struct cam_periph *)dp->d_drv1;
1481 softc = (struct da_softc *)periph->softc;
1482 cam_periph_lock(periph);
1483 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1486 if (cam_periph_hold(periph, PRIBIO) == 0) {
1488 /* Flush disk cache. */
1489 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1490 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1491 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1492 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1493 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1494 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1495 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1497 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1498 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1499 softc->disk->d_devstat);
1500 softc->flags &= ~DA_FLAG_DIRTY;
1501 xpt_release_ccb(ccb);
1504 /* Allow medium removal. */
1505 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1506 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1507 daprevent(periph, PR_ALLOW);
1509 cam_periph_unhold(periph);
1513 * If we've got removeable media, mark the blocksize as
1514 * unavailable, since it could change when new media is
1517 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1518 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1520 softc->flags &= ~DA_FLAG_OPEN;
1521 while (softc->refcount != 0)
1522 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1523 cam_periph_unlock(periph);
1524 cam_periph_release(periph);
1529 daschedule(struct cam_periph *periph)
1531 struct da_softc *softc = (struct da_softc *)periph->softc;
1533 if (softc->state != DA_STATE_NORMAL)
1536 cam_iosched_schedule(softc->cam_iosched, periph);
1540 * Actually translate the requested transfer into one the physical driver
1541 * can understand. The transfer is described by a buf and will include
1542 * only one physical transfer.
1545 dastrategy(struct bio *bp)
1547 struct cam_periph *periph;
1548 struct da_softc *softc;
1550 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1551 softc = (struct da_softc *)periph->softc;
1553 cam_periph_lock(periph);
1556 * If the device has been made invalid, error out
1558 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1559 cam_periph_unlock(periph);
1560 biofinish(bp, NULL, ENXIO);
1564 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1567 * Zone commands must be ordered, because they can depend on the
1568 * effects of previously issued commands, and they may affect
1569 * commands after them.
1571 if (bp->bio_cmd == BIO_ZONE)
1572 bp->bio_flags |= BIO_ORDERED;
1575 * Place it in the queue of disk activities for this disk
1577 cam_iosched_queue_work(softc->cam_iosched, bp);
1580 * Schedule ourselves for performing the work.
1583 cam_periph_unlock(periph);
1589 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1591 struct cam_periph *periph;
1592 struct da_softc *softc;
1594 struct ccb_scsiio csio;
1599 periph = dp->d_drv1;
1600 softc = (struct da_softc *)periph->softc;
1601 cam_periph_lock(periph);
1602 secsize = softc->params.secsize;
1604 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1605 cam_periph_unlock(periph);
1610 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1611 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1612 scsi_read_write(&csio,
1616 /*read*/SCSI_RW_WRITE,
1618 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1621 /*data_ptr*/(u_int8_t *) virtual,
1622 /*dxfer_len*/length,
1623 /*sense_len*/SSD_FULL_SIZE,
1624 da_default_timeout * 1000);
1625 xpt_polled_action((union ccb *)&csio);
1627 error = cam_periph_error((union ccb *)&csio,
1628 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1629 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1630 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1631 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1633 printf("Aborting dump due to I/O error.\n");
1634 cam_periph_unlock(periph);
1639 * Sync the disk cache contents to the physical media.
1641 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1643 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1644 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1645 scsi_synchronize_cache(&csio,
1649 /*begin_lba*/0,/* Cover the whole disk */
1653 xpt_polled_action((union ccb *)&csio);
1655 error = cam_periph_error((union ccb *)&csio,
1656 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1657 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1658 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1659 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1661 xpt_print(periph->path, "Synchronize cache failed\n");
1663 cam_periph_unlock(periph);
1668 dagetattr(struct bio *bp)
1671 struct cam_periph *periph;
1673 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1674 cam_periph_lock(periph);
1675 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1677 cam_periph_unlock(periph);
1679 bp->bio_completed = bp->bio_length;
1689 * Install a global async callback. This callback will
1690 * receive async callbacks like "new device found".
1692 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1694 if (status != CAM_REQ_CMP) {
1695 printf("da: Failed to attach master async callback "
1696 "due to status 0x%x!\n", status);
1697 } else if (da_send_ordered) {
1699 /* Register our shutdown event handler */
1700 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1701 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1702 printf("dainit: shutdown event registration failed!\n");
1707 * Callback from GEOM, called when it has finished cleaning up its
1711 dadiskgonecb(struct disk *dp)
1713 struct cam_periph *periph;
1715 periph = (struct cam_periph *)dp->d_drv1;
1716 cam_periph_release(periph);
1720 daoninvalidate(struct cam_periph *periph)
1722 struct da_softc *softc;
1724 softc = (struct da_softc *)periph->softc;
1727 * De-register any async callbacks.
1729 xpt_register_async(0, daasync, periph, periph->path);
1731 softc->flags |= DA_FLAG_PACK_INVALID;
1733 softc->invalidations++;
1737 * Return all queued I/O with ENXIO.
1738 * XXX Handle any transactions queued to the card
1739 * with XPT_ABORT_CCB.
1741 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
1744 * Tell GEOM that we've gone away, we'll get a callback when it is
1745 * done cleaning up its resources.
1747 disk_gone(softc->disk);
1751 dacleanup(struct cam_periph *periph)
1753 struct da_softc *softc;
1755 softc = (struct da_softc *)periph->softc;
1757 cam_periph_unlock(periph);
1759 cam_iosched_fini(softc->cam_iosched);
1762 * If we can't free the sysctl tree, oh well...
1764 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
1766 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1767 xpt_print(periph->path,
1768 "can't remove sysctl stats context\n");
1770 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1771 xpt_print(periph->path,
1772 "can't remove sysctl context\n");
1775 callout_drain(&softc->mediapoll_c);
1776 disk_destroy(softc->disk);
1777 callout_drain(&softc->sendordered_c);
1778 free(softc, M_DEVBUF);
1779 cam_periph_lock(periph);
1783 daasync(void *callback_arg, u_int32_t code,
1784 struct cam_path *path, void *arg)
1786 struct cam_periph *periph;
1787 struct da_softc *softc;
1789 periph = (struct cam_periph *)callback_arg;
1791 case AC_FOUND_DEVICE:
1793 struct ccb_getdev *cgd;
1796 cgd = (struct ccb_getdev *)arg;
1800 if (cgd->protocol != PROTO_SCSI)
1802 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
1804 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1805 && SID_TYPE(&cgd->inq_data) != T_RBC
1806 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
1807 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
1811 * Allocate a peripheral instance for
1812 * this device and start the probe
1815 status = cam_periph_alloc(daregister, daoninvalidate,
1817 "da", CAM_PERIPH_BIO,
1819 AC_FOUND_DEVICE, cgd);
1821 if (status != CAM_REQ_CMP
1822 && status != CAM_REQ_INPROG)
1823 printf("daasync: Unable to attach to new device "
1824 "due to status 0x%x\n", status);
1827 case AC_ADVINFO_CHANGED:
1831 buftype = (uintptr_t)arg;
1832 if (buftype == CDAI_TYPE_PHYS_PATH) {
1833 struct da_softc *softc;
1835 softc = periph->softc;
1836 disk_attr_changed(softc->disk, "GEOM::physpath",
1841 case AC_UNIT_ATTENTION:
1844 int error_code, sense_key, asc, ascq;
1846 softc = (struct da_softc *)periph->softc;
1847 ccb = (union ccb *)arg;
1850 * Handle all UNIT ATTENTIONs except our own,
1851 * as they will be handled by daerror().
1853 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1854 scsi_extract_sense_ccb(ccb,
1855 &error_code, &sense_key, &asc, &ascq)) {
1856 if (asc == 0x2A && ascq == 0x09) {
1857 xpt_print(ccb->ccb_h.path,
1858 "Capacity data has changed\n");
1859 softc->flags &= ~DA_FLAG_PROBED;
1861 } else if (asc == 0x28 && ascq == 0x00) {
1862 softc->flags &= ~DA_FLAG_PROBED;
1863 disk_media_changed(softc->disk, M_NOWAIT);
1864 } else if (asc == 0x3F && ascq == 0x03) {
1865 xpt_print(ccb->ccb_h.path,
1866 "INQUIRY data has changed\n");
1867 softc->flags &= ~DA_FLAG_PROBED;
1871 cam_periph_async(periph, code, path, arg);
1875 softc = (struct da_softc *)periph->softc;
1876 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
1877 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1878 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
1886 struct ccb_hdr *ccbh;
1888 softc = (struct da_softc *)periph->softc;
1890 * Don't fail on the expected unit attention
1893 softc->flags |= DA_FLAG_RETRY_UA;
1894 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1895 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1898 case AC_INQ_CHANGED:
1899 softc = (struct da_softc *)periph->softc;
1900 softc->flags &= ~DA_FLAG_PROBED;
1906 cam_periph_async(periph, code, path, arg);
1910 dasysctlinit(void *context, int pending)
1912 struct cam_periph *periph;
1913 struct da_softc *softc;
1914 char tmpstr[80], tmpstr2[80];
1915 struct ccb_trans_settings cts;
1917 periph = (struct cam_periph *)context;
1919 * periph was held for us when this task was enqueued
1921 if (periph->flags & CAM_PERIPH_INVALID) {
1922 cam_periph_release(periph);
1926 softc = (struct da_softc *)periph->softc;
1927 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1928 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1930 sysctl_ctx_init(&softc->sysctl_ctx);
1931 softc->flags |= DA_FLAG_SCTX_INIT;
1932 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
1933 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1934 CTLFLAG_RD, 0, tmpstr);
1935 if (softc->sysctl_tree == NULL) {
1936 printf("dasysctlinit: unable to allocate sysctl tree\n");
1937 cam_periph_release(periph);
1942 * Now register the sysctl handler, so the user can change the value on
1945 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1946 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
1947 softc, 0, dadeletemethodsysctl, "A",
1948 "BIO_DELETE execution method");
1949 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1950 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1951 softc, 0, dadeletemaxsysctl, "Q",
1952 "Maximum BIO_DELETE size");
1953 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1954 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1955 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1956 "Minimum CDB size");
1958 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1959 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
1960 softc, 0, dazonemodesysctl, "A",
1962 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1963 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
1964 softc, 0, dazonesupsysctl, "A",
1966 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1967 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1968 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
1969 "Optimal Number of Open Sequential Write Preferred Zones");
1970 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1971 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1972 "optimal_nonseq_zones", CTLFLAG_RD,
1973 &softc->optimal_nonseq_zones,
1974 "Optimal Number of Non-Sequentially Written Sequential Write "
1976 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1977 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1978 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
1979 "Maximum Number of Open Sequential Write Required Zones");
1981 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1982 SYSCTL_CHILDREN(softc->sysctl_tree),
1986 &softc->error_inject,
1988 "error_inject leaf");
1990 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1991 SYSCTL_CHILDREN(softc->sysctl_tree),
1997 "Unmapped I/O leaf");
1999 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2000 SYSCTL_CHILDREN(softc->sysctl_tree),
2009 * Add some addressing info.
2011 memset(&cts, 0, sizeof (cts));
2012 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2013 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2014 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2015 cam_periph_lock(periph);
2016 xpt_action((union ccb *)&cts);
2017 cam_periph_unlock(periph);
2018 if (cts.ccb_h.status != CAM_REQ_CMP) {
2019 cam_periph_release(periph);
2022 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2023 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2024 if (fc->valid & CTS_FC_VALID_WWPN) {
2025 softc->wwpn = fc->wwpn;
2026 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2027 SYSCTL_CHILDREN(softc->sysctl_tree),
2028 OID_AUTO, "wwpn", CTLFLAG_RD,
2029 &softc->wwpn, "World Wide Port Name");
2035 * Now add some useful stats.
2036 * XXX These should live in cam_periph and be common to all periphs
2038 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2039 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2040 CTLFLAG_RD, 0, "Statistics");
2041 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2042 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2048 "Transport errors reported by the SIM");
2049 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2050 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2056 "Device timeouts reported by the SIM");
2057 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2058 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2060 "pack_invalidations",
2062 &softc->invalidations,
2064 "Device pack invalidations");
2067 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2068 softc->sysctl_tree);
2070 cam_periph_release(periph);
2074 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2078 struct da_softc *softc;
2080 softc = (struct da_softc *)arg1;
2082 value = softc->disk->d_delmaxsize;
2083 error = sysctl_handle_64(oidp, &value, 0, req);
2084 if ((error != 0) || (req->newptr == NULL))
2087 /* only accept values smaller than the calculated value */
2088 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2091 softc->disk->d_delmaxsize = value;
2097 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2101 value = *(int *)arg1;
2103 error = sysctl_handle_int(oidp, &value, 0, req);
2106 || (req->newptr == NULL))
2110 * Acceptable values here are 6, 10, 12 or 16.
2114 else if ((value > 6)
2117 else if ((value > 10)
2120 else if (value > 12)
2123 *(int *)arg1 = value;
2129 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2134 value = da_default_softtimeout / SBT_1MS;
2136 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2137 if ((error != 0) || (req->newptr == NULL))
2140 /* XXX Should clip this to a reasonable level */
2141 if (value > da_default_timeout * 1000)
2144 da_default_softtimeout = value * SBT_1MS;
2149 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2152 softc->delete_method = delete_method;
2153 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2154 softc->delete_func = da_delete_functions[delete_method];
2156 if (softc->delete_method > DA_DELETE_DISABLE)
2157 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2159 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2163 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2167 switch(delete_method) {
2168 case DA_DELETE_UNMAP:
2169 sectors = (off_t)softc->unmap_max_lba;
2171 case DA_DELETE_ATA_TRIM:
2172 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2174 case DA_DELETE_WS16:
2175 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2177 case DA_DELETE_ZERO:
2178 case DA_DELETE_WS10:
2179 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2185 return (off_t)softc->params.secsize *
2186 omin(sectors, softc->params.sectors);
2190 daprobedone(struct cam_periph *periph, union ccb *ccb)
2192 struct da_softc *softc;
2194 softc = (struct da_softc *)periph->softc;
2196 dadeletemethodchoose(softc, DA_DELETE_NONE);
2198 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2202 snprintf(buf, sizeof(buf), "Delete methods: <");
2204 for (i = 0; i <= DA_DELETE_MAX; i++) {
2205 if ((softc->delete_available & (1 << i)) == 0 &&
2206 i != softc->delete_method)
2209 strlcat(buf, ",", sizeof(buf));
2210 strlcat(buf, da_delete_method_names[i],
2212 if (i == softc->delete_method)
2213 strlcat(buf, "(*)", sizeof(buf));
2216 strlcat(buf, ">", sizeof(buf));
2217 printf("%s%d: %s\n", periph->periph_name,
2218 periph->unit_number, buf);
2222 * Since our peripheral may be invalidated by an error
2223 * above or an external event, we must release our CCB
2224 * before releasing the probe lock on the peripheral.
2225 * The peripheral will only go away once the last lock
2226 * is removed, and we need it around for the CCB release
2229 xpt_release_ccb(ccb);
2230 softc->state = DA_STATE_NORMAL;
2231 softc->flags |= DA_FLAG_PROBED;
2233 wakeup(&softc->disk->d_mediasize);
2234 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2235 softc->flags |= DA_FLAG_ANNOUNCED;
2236 cam_periph_unhold(periph);
2238 cam_periph_release_locked(periph);
2242 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2246 /* If available, prefer the method requested by user. */
2247 i = softc->delete_method_pref;
2248 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2249 if (methods & (1 << i)) {
2250 dadeletemethodset(softc, i);
2254 /* Use the pre-defined order to choose the best performing delete. */
2255 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2256 if (i == DA_DELETE_ZERO)
2258 if (softc->delete_available & (1 << i)) {
2259 dadeletemethodset(softc, i);
2264 /* Fallback to default. */
2265 dadeletemethodset(softc, default_method);
2269 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2273 struct da_softc *softc;
2274 int i, error, methods, value;
2276 softc = (struct da_softc *)arg1;
2278 value = softc->delete_method;
2279 if (value < 0 || value > DA_DELETE_MAX)
2282 p = da_delete_method_names[value];
2283 strncpy(buf, p, sizeof(buf));
2284 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2285 if (error != 0 || req->newptr == NULL)
2287 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2288 for (i = 0; i <= DA_DELETE_MAX; i++) {
2289 if (strcmp(buf, da_delete_method_names[i]) == 0)
2292 if (i > DA_DELETE_MAX)
2294 softc->delete_method_pref = i;
2295 dadeletemethodchoose(softc, DA_DELETE_NONE);
2300 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2303 struct da_softc *softc;
2306 softc = (struct da_softc *)arg1;
2308 switch (softc->zone_mode) {
2309 case DA_ZONE_DRIVE_MANAGED:
2310 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2312 case DA_ZONE_HOST_AWARE:
2313 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2315 case DA_ZONE_HOST_MANAGED:
2316 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2320 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2324 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2330 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2333 struct da_softc *softc;
2338 softc = (struct da_softc *)arg1;
2342 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2344 for (i = 0; i < sizeof(da_zone_desc_table) /
2345 sizeof(da_zone_desc_table[0]); i++) {
2346 if (softc->zone_flags & da_zone_desc_table[i].value) {
2348 sbuf_printf(&sb, ", ");
2351 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2356 sbuf_printf(&sb, "None");
2360 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2366 daregister(struct cam_periph *periph, void *arg)
2368 struct da_softc *softc;
2369 struct ccb_pathinq cpi;
2370 struct ccb_getdev *cgd;
2374 cgd = (struct ccb_getdev *)arg;
2376 printf("daregister: no getdev CCB, can't register device\n");
2377 return(CAM_REQ_CMP_ERR);
2380 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2383 if (softc == NULL) {
2384 printf("daregister: Unable to probe new device. "
2385 "Unable to allocate softc\n");
2386 return(CAM_REQ_CMP_ERR);
2389 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2390 printf("daregister: Unable to probe new device. "
2391 "Unable to allocate iosched memory\n");
2392 free(softc, M_DEVBUF);
2393 return(CAM_REQ_CMP_ERR);
2396 LIST_INIT(&softc->pending_ccbs);
2397 softc->state = DA_STATE_PROBE_RC;
2398 bioq_init(&softc->delete_run_queue);
2399 if (SID_IS_REMOVABLE(&cgd->inq_data))
2400 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2401 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2402 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2403 softc->unmap_gran = 0;
2404 softc->unmap_gran_align = 0;
2405 softc->ws_max_blks = WS16_MAX_BLKS;
2406 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2407 softc->rotating = 1;
2409 periph->softc = softc;
2412 * See if this device has any quirks.
2414 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2415 (caddr_t)da_quirk_table,
2416 nitems(da_quirk_table),
2417 sizeof(*da_quirk_table), scsi_inquiry_match);
2420 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2422 softc->quirks = DA_Q_NONE;
2424 /* Check if the SIM does not want 6 byte commands */
2425 bzero(&cpi, sizeof(cpi));
2426 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2427 cpi.ccb_h.func_code = XPT_PATH_INQ;
2428 xpt_action((union ccb *)&cpi);
2429 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2430 softc->quirks |= DA_Q_NO_6_BYTE;
2432 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2433 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2434 else if (softc->quirks & DA_Q_SMR_DM)
2435 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2437 softc->zone_mode = DA_ZONE_NONE;
2439 if (softc->zone_mode != DA_ZONE_NONE) {
2440 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2441 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2442 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2444 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2446 softc->zone_interface = DA_ZONE_IF_SCSI;
2449 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2452 * Take an exclusive refcount on the periph while dastart is called
2453 * to finish the probe. The reference will be dropped in dadone at
2456 (void)cam_periph_hold(periph, PRIBIO);
2459 * Schedule a periodic event to occasionally send an
2460 * ordered tag to a device.
2462 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2463 callout_reset(&softc->sendordered_c,
2464 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2465 dasendorderedtag, softc);
2467 cam_periph_unlock(periph);
2469 * RBC devices don't have to support READ(6), only READ(10).
2471 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2472 softc->minimum_cmd_size = 10;
2474 softc->minimum_cmd_size = 6;
2477 * Load the user's default, if any.
2479 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2480 periph->unit_number);
2481 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2484 * 6, 10, 12 and 16 are the currently permissible values.
2486 if (softc->minimum_cmd_size < 6)
2487 softc->minimum_cmd_size = 6;
2488 else if ((softc->minimum_cmd_size > 6)
2489 && (softc->minimum_cmd_size <= 10))
2490 softc->minimum_cmd_size = 10;
2491 else if ((softc->minimum_cmd_size > 10)
2492 && (softc->minimum_cmd_size <= 12))
2493 softc->minimum_cmd_size = 12;
2494 else if (softc->minimum_cmd_size > 12)
2495 softc->minimum_cmd_size = 16;
2497 /* Predict whether device may support READ CAPACITY(16). */
2498 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2499 (softc->quirks & DA_Q_NO_RC16) == 0) {
2500 softc->flags |= DA_FLAG_CAN_RC16;
2501 softc->state = DA_STATE_PROBE_RC16;
2505 * Register this media as a disk.
2507 softc->disk = disk_alloc();
2508 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2509 periph->unit_number, 0,
2510 DEVSTAT_BS_UNAVAILABLE,
2511 SID_TYPE(&cgd->inq_data) |
2512 XPORT_DEVSTAT_TYPE(cpi.transport),
2513 DEVSTAT_PRIORITY_DISK);
2514 softc->disk->d_open = daopen;
2515 softc->disk->d_close = daclose;
2516 softc->disk->d_strategy = dastrategy;
2517 softc->disk->d_dump = dadump;
2518 softc->disk->d_getattr = dagetattr;
2519 softc->disk->d_gone = dadiskgonecb;
2520 softc->disk->d_name = "da";
2521 softc->disk->d_drv1 = periph;
2523 softc->maxio = DFLTPHYS; /* traditional default */
2524 else if (cpi.maxio > MAXPHYS)
2525 softc->maxio = MAXPHYS; /* for safety */
2527 softc->maxio = cpi.maxio;
2528 softc->disk->d_maxsize = softc->maxio;
2529 softc->disk->d_unit = periph->unit_number;
2530 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2531 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2532 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2533 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2534 softc->unmappedio = 1;
2535 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2537 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2538 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2539 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2540 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2541 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2542 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2543 softc->disk->d_hba_vendor = cpi.hba_vendor;
2544 softc->disk->d_hba_device = cpi.hba_device;
2545 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2546 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2549 * Acquire a reference to the periph before we register with GEOM.
2550 * We'll release this reference once GEOM calls us back (via
2551 * dadiskgonecb()) telling us that our provider has been freed.
2553 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2554 xpt_print(periph->path, "%s: lost periph during "
2555 "registration!\n", __func__);
2556 cam_periph_lock(periph);
2557 return (CAM_REQ_CMP_ERR);
2560 disk_create(softc->disk, DISK_VERSION);
2561 cam_periph_lock(periph);
2564 * Add async callbacks for events of interest.
2565 * I don't bother checking if this fails as,
2566 * in most cases, the system will function just
2567 * fine without them and the only alternative
2568 * would be to not attach the device on failure.
2570 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2571 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2572 AC_INQ_CHANGED, daasync, periph, periph->path);
2575 * Emit an attribute changed notification just in case
2576 * physical path information arrived before our async
2577 * event handler was registered, but after anyone attaching
2578 * to our disk device polled it.
2580 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2583 * Schedule a periodic media polling events.
2585 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2586 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2587 (cgd->inq_flags & SID_AEN) == 0 &&
2588 da_poll_period != 0)
2589 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2590 damediapoll, periph);
2592 xpt_schedule(periph, CAM_PRIORITY_DEV);
2594 return(CAM_REQ_CMP);
2598 da_zone_bio_to_scsi(int disk_zone_cmd)
2600 switch (disk_zone_cmd) {
2601 case DISK_ZONE_OPEN:
2602 return ZBC_OUT_SA_OPEN;
2603 case DISK_ZONE_CLOSE:
2604 return ZBC_OUT_SA_CLOSE;
2605 case DISK_ZONE_FINISH:
2606 return ZBC_OUT_SA_FINISH;
2608 return ZBC_OUT_SA_RWP;
2615 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2618 struct da_softc *softc;
2623 if (bp->bio_cmd != BIO_ZONE) {
2628 softc = periph->softc;
2630 switch (bp->bio_zone.zone_cmd) {
2631 case DISK_ZONE_OPEN:
2632 case DISK_ZONE_CLOSE:
2633 case DISK_ZONE_FINISH:
2634 case DISK_ZONE_RWP: {
2639 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2640 if (zone_sa == -1) {
2641 xpt_print(periph->path, "Cannot translate zone "
2642 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2648 lba = bp->bio_zone.zone_params.rwp.id;
2650 if (bp->bio_zone.zone_params.rwp.flags &
2651 DISK_ZONE_RWP_FLAG_ALL)
2652 zone_flags |= ZBC_OUT_ALL;
2654 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2655 scsi_zbc_out(&ccb->csio,
2656 /*retries*/ da_retry_count,
2658 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2659 /*service_action*/ zone_sa,
2661 /*zone_flags*/ zone_flags,
2664 /*sense_len*/ SSD_FULL_SIZE,
2665 /*timeout*/ da_default_timeout * 1000);
2668 * Note that in this case, even though we can
2669 * technically use NCQ, we don't bother for several
2671 * 1. It hasn't been tested on a SAT layer that
2672 * supports it. This is new as of SAT-4.
2673 * 2. Even when there is a SAT layer that supports
2674 * it, that SAT layer will also probably support
2675 * ZBC -> ZAC translation, since they are both
2676 * in the SAT-4 spec.
2677 * 3. Translation will likely be preferable to ATA
2678 * passthrough. LSI / Avago at least single
2679 * steps ATA passthrough commands in the HBA,
2680 * regardless of protocol, so unless that
2681 * changes, there is a performance penalty for
2682 * doing ATA passthrough no matter whether
2683 * you're using NCQ/FPDMA, DMA or PIO.
2684 * 4. It requires a 32-byte CDB, which at least at
2685 * this point in CAM requires a CDB pointer, which
2686 * would require us to allocate an additional bit
2687 * of storage separate from the CCB.
2689 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2690 /*retries*/ da_retry_count,
2692 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2694 /*zm_action*/ zone_sa,
2696 /*zone_flags*/ zone_flags,
2699 /*cdb_storage*/ NULL,
2700 /*cdb_storage_len*/ 0,
2701 /*sense_len*/ SSD_FULL_SIZE,
2702 /*timeout*/ da_default_timeout * 1000);
2705 xpt_print(periph->path,
2706 "scsi_ata_zac_mgmt_out() returned an "
2715 case DISK_ZONE_REPORT_ZONES: {
2717 uint32_t num_entries, alloc_size;
2718 struct disk_zone_report *rep;
2720 rep = &bp->bio_zone.zone_params.report;
2722 num_entries = rep->entries_allocated;
2723 if (num_entries == 0) {
2724 xpt_print(periph->path, "No entries allocated for "
2725 "Report Zones request\n");
2729 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2730 (sizeof(struct scsi_report_zones_desc) * num_entries);
2731 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2732 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2733 if (rz_ptr == NULL) {
2734 xpt_print(periph->path, "Unable to allocate memory "
2735 "for Report Zones request\n");
2740 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2741 scsi_zbc_in(&ccb->csio,
2742 /*retries*/ da_retry_count,
2744 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2745 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2746 /*zone_start_lba*/ rep->starting_id,
2747 /*zone_options*/ rep->rep_options,
2748 /*data_ptr*/ rz_ptr,
2749 /*dxfer_len*/ alloc_size,
2750 /*sense_len*/ SSD_FULL_SIZE,
2751 /*timeout*/ da_default_timeout * 1000);
2754 * Note that in this case, even though we can
2755 * technically use NCQ, we don't bother for several
2757 * 1. It hasn't been tested on a SAT layer that
2758 * supports it. This is new as of SAT-4.
2759 * 2. Even when there is a SAT layer that supports
2760 * it, that SAT layer will also probably support
2761 * ZBC -> ZAC translation, since they are both
2762 * in the SAT-4 spec.
2763 * 3. Translation will likely be preferable to ATA
2764 * passthrough. LSI / Avago at least single
2765 * steps ATA passthrough commands in the HBA,
2766 * regardless of protocol, so unless that
2767 * changes, there is a performance penalty for
2768 * doing ATA passthrough no matter whether
2769 * you're using NCQ/FPDMA, DMA or PIO.
2770 * 4. It requires a 32-byte CDB, which at least at
2771 * this point in CAM requires a CDB pointer, which
2772 * would require us to allocate an additional bit
2773 * of storage separate from the CCB.
2775 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2776 /*retries*/ da_retry_count,
2778 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2780 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2781 /*zone_id*/ rep->starting_id,
2782 /*zone_flags*/ rep->rep_options,
2783 /*data_ptr*/ rz_ptr,
2784 /*dxfer_len*/ alloc_size,
2785 /*cdb_storage*/ NULL,
2786 /*cdb_storage_len*/ 0,
2787 /*sense_len*/ SSD_FULL_SIZE,
2788 /*timeout*/ da_default_timeout * 1000);
2791 xpt_print(periph->path,
2792 "scsi_ata_zac_mgmt_in() returned an "
2799 * For BIO_ZONE, this isn't normally needed. However, it
2800 * is used by devstat_end_transaction_bio() to determine
2801 * how much data was transferred.
2804 * XXX KDM we have a problem. But I'm not sure how to fix
2805 * it. devstat uses bio_bcount - bio_resid to calculate
2806 * the amount of data transferred. The GEOM disk code
2807 * uses bio_length - bio_resid to calculate the amount of
2808 * data in bio_completed. We have different structure
2809 * sizes above and below the ada(4) driver. So, if we
2810 * use the sizes above, the amount transferred won't be
2811 * quite accurate for devstat. If we use different sizes
2812 * for bio_bcount and bio_length (above and below
2813 * respectively), then the residual needs to match one or
2814 * the other. Everything is calculated after the bio
2815 * leaves the driver, so changing the values around isn't
2816 * really an option. For now, just set the count to the
2817 * passed in length. This means that the calculations
2818 * above (e.g. bio_completed) will be correct, but the
2819 * amount of data reported to devstat will be slightly
2820 * under or overstated.
2822 bp->bio_bcount = bp->bio_length;
2828 case DISK_ZONE_GET_PARAMS: {
2829 struct disk_zone_disk_params *params;
2831 params = &bp->bio_zone.zone_params.disk_params;
2832 bzero(params, sizeof(*params));
2834 switch (softc->zone_mode) {
2835 case DA_ZONE_DRIVE_MANAGED:
2836 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
2838 case DA_ZONE_HOST_AWARE:
2839 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
2841 case DA_ZONE_HOST_MANAGED:
2842 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
2846 params->zone_mode = DISK_ZONE_MODE_NONE;
2850 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
2851 params->flags |= DISK_ZONE_DISK_URSWRZ;
2853 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
2854 params->optimal_seq_zones = softc->optimal_seq_zones;
2855 params->flags |= DISK_ZONE_OPT_SEQ_SET;
2858 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
2859 params->optimal_nonseq_zones =
2860 softc->optimal_nonseq_zones;
2861 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
2864 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
2865 params->max_seq_zones = softc->max_seq_zones;
2866 params->flags |= DISK_ZONE_MAX_SEQ_SET;
2868 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
2869 params->flags |= DISK_ZONE_RZ_SUP;
2871 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
2872 params->flags |= DISK_ZONE_OPEN_SUP;
2874 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
2875 params->flags |= DISK_ZONE_CLOSE_SUP;
2877 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
2878 params->flags |= DISK_ZONE_FINISH_SUP;
2880 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
2881 params->flags |= DISK_ZONE_RWP_SUP;
2892 dastart(struct cam_periph *periph, union ccb *start_ccb)
2894 struct da_softc *softc;
2896 softc = (struct da_softc *)periph->softc;
2898 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2901 switch (softc->state) {
2902 case DA_STATE_NORMAL:
2908 bp = cam_iosched_next_bio(softc->cam_iosched);
2910 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2911 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2912 scsi_test_unit_ready(&start_ccb->csio,
2913 /*retries*/ da_retry_count,
2917 da_default_timeout * 1000);
2918 start_ccb->ccb_h.ccb_bp = NULL;
2919 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2920 xpt_action(start_ccb);
2922 xpt_release_ccb(start_ccb);
2926 if (bp->bio_cmd == BIO_DELETE) {
2927 if (softc->delete_func != NULL) {
2928 softc->delete_func(periph, start_ccb, bp);
2931 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
2932 biofinish(bp, NULL, 0);
2937 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2938 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2939 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */
2942 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2943 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2944 softc->flags &= ~DA_FLAG_NEED_OTAG;
2945 softc->flags |= DA_FLAG_WAS_OTAG;
2946 tag_code = MSG_ORDERED_Q_TAG;
2948 tag_code = MSG_SIMPLE_Q_TAG;
2951 switch (bp->bio_cmd) {
2958 if (bp->bio_cmd == BIO_WRITE) {
2959 softc->flags |= DA_FLAG_DIRTY;
2960 rw_op = SCSI_RW_WRITE;
2962 rw_op = SCSI_RW_READ;
2965 data_ptr = bp->bio_data;
2966 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
2967 rw_op |= SCSI_RW_BIO;
2971 scsi_read_write(&start_ccb->csio,
2972 /*retries*/da_retry_count,
2974 /*tag_action*/tag_code,
2977 softc->minimum_cmd_size,
2978 /*lba*/bp->bio_pblkno,
2979 /*block_count*/bp->bio_bcount /
2980 softc->params.secsize,
2982 /*dxfer_len*/ bp->bio_bcount,
2983 /*sense_len*/SSD_FULL_SIZE,
2984 da_default_timeout * 1000);
2989 * BIO_FLUSH doesn't currently communicate
2990 * range data, so we synchronize the cache
2991 * over the whole disk. We also force
2992 * ordered tag semantics the flush applies
2993 * to all previously queued I/O.
2995 scsi_synchronize_cache(&start_ccb->csio,
3002 da_default_timeout*1000);
3005 int error, queue_ccb;
3009 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3011 || (queue_ccb == 0)) {
3012 biofinish(bp, NULL, error);
3013 xpt_release_ccb(start_ccb);
3019 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3020 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3021 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3024 LIST_INSERT_HEAD(&softc->pending_ccbs,
3025 &start_ccb->ccb_h, periph_links.le);
3027 /* We expect a unit attention from this device */
3028 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3029 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3030 softc->flags &= ~DA_FLAG_RETRY_UA;
3033 start_ccb->ccb_h.ccb_bp = bp;
3035 cam_periph_unlock(periph);
3036 xpt_action(start_ccb);
3037 cam_periph_lock(periph);
3040 /* May have more work to do, so ensure we stay scheduled */
3044 case DA_STATE_PROBE_RC:
3046 struct scsi_read_capacity_data *rcap;
3048 rcap = (struct scsi_read_capacity_data *)
3049 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3051 printf("dastart: Couldn't malloc read_capacity data\n");
3052 /* da_free_periph??? */
3055 scsi_read_capacity(&start_ccb->csio,
3056 /*retries*/da_retry_count,
3062 start_ccb->ccb_h.ccb_bp = NULL;
3063 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3064 xpt_action(start_ccb);
3067 case DA_STATE_PROBE_RC16:
3069 struct scsi_read_capacity_data_long *rcaplong;
3071 rcaplong = (struct scsi_read_capacity_data_long *)
3072 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3073 if (rcaplong == NULL) {
3074 printf("dastart: Couldn't malloc read_capacity data\n");
3075 /* da_free_periph??? */
3078 scsi_read_capacity_16(&start_ccb->csio,
3079 /*retries*/ da_retry_count,
3081 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3085 /*rcap_buf*/ (uint8_t *)rcaplong,
3086 /*rcap_buf_len*/ sizeof(*rcaplong),
3087 /*sense_len*/ SSD_FULL_SIZE,
3088 /*timeout*/ da_default_timeout * 1000);
3089 start_ccb->ccb_h.ccb_bp = NULL;
3090 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3091 xpt_action(start_ccb);
3094 case DA_STATE_PROBE_LBP:
3096 struct scsi_vpd_logical_block_prov *lbp;
3098 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3100 * If we get here we don't support any SBC-3 delete
3101 * methods with UNMAP as the Logical Block Provisioning
3102 * VPD page support is required for devices which
3103 * support it according to T10/1799-D Revision 31
3104 * however older revisions of the spec don't mandate
3105 * this so we currently don't remove these methods
3106 * from the available set.
3108 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3112 lbp = (struct scsi_vpd_logical_block_prov *)
3113 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3116 printf("dastart: Couldn't malloc lbp data\n");
3117 /* da_free_periph??? */
3121 scsi_inquiry(&start_ccb->csio,
3122 /*retries*/da_retry_count,
3124 /*tag_action*/MSG_SIMPLE_Q_TAG,
3125 /*inq_buf*/(u_int8_t *)lbp,
3126 /*inq_len*/sizeof(*lbp),
3128 /*page_code*/SVPD_LBP,
3129 /*sense_len*/SSD_MIN_SIZE,
3130 /*timeout*/da_default_timeout * 1000);
3131 start_ccb->ccb_h.ccb_bp = NULL;
3132 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3133 xpt_action(start_ccb);
3136 case DA_STATE_PROBE_BLK_LIMITS:
3138 struct scsi_vpd_block_limits *block_limits;
3140 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3141 /* Not supported skip to next probe */
3142 softc->state = DA_STATE_PROBE_BDC;
3146 block_limits = (struct scsi_vpd_block_limits *)
3147 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3149 if (block_limits == NULL) {
3150 printf("dastart: Couldn't malloc block_limits data\n");
3151 /* da_free_periph??? */
3155 scsi_inquiry(&start_ccb->csio,
3156 /*retries*/da_retry_count,
3158 /*tag_action*/MSG_SIMPLE_Q_TAG,
3159 /*inq_buf*/(u_int8_t *)block_limits,
3160 /*inq_len*/sizeof(*block_limits),
3162 /*page_code*/SVPD_BLOCK_LIMITS,
3163 /*sense_len*/SSD_MIN_SIZE,
3164 /*timeout*/da_default_timeout * 1000);
3165 start_ccb->ccb_h.ccb_bp = NULL;
3166 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3167 xpt_action(start_ccb);
3170 case DA_STATE_PROBE_BDC:
3172 struct scsi_vpd_block_characteristics *bdc;
3174 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3175 softc->state = DA_STATE_PROBE_ATA;
3179 bdc = (struct scsi_vpd_block_characteristics *)
3180 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3183 printf("dastart: Couldn't malloc bdc data\n");
3184 /* da_free_periph??? */
3188 scsi_inquiry(&start_ccb->csio,
3189 /*retries*/da_retry_count,
3191 /*tag_action*/MSG_SIMPLE_Q_TAG,
3192 /*inq_buf*/(u_int8_t *)bdc,
3193 /*inq_len*/sizeof(*bdc),
3195 /*page_code*/SVPD_BDC,
3196 /*sense_len*/SSD_MIN_SIZE,
3197 /*timeout*/da_default_timeout * 1000);
3198 start_ccb->ccb_h.ccb_bp = NULL;
3199 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3200 xpt_action(start_ccb);
3203 case DA_STATE_PROBE_ATA:
3205 struct ata_params *ata_params;
3207 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3208 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3209 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3211 * Note that if the ATA VPD page isn't
3212 * supported, we aren't talking to an ATA
3213 * device anyway. Support for that VPD
3214 * page is mandatory for SCSI to ATA (SAT)
3215 * translation layers.
3217 softc->state = DA_STATE_PROBE_ZONE;
3220 daprobedone(periph, start_ccb);
3224 ata_params = (struct ata_params*)
3225 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3227 if (ata_params == NULL) {
3228 xpt_print(periph->path, "Couldn't malloc ata_params "
3230 /* da_free_periph??? */
3234 scsi_ata_identify(&start_ccb->csio,
3235 /*retries*/da_retry_count,
3237 /*tag_action*/MSG_SIMPLE_Q_TAG,
3238 /*data_ptr*/(u_int8_t *)ata_params,
3239 /*dxfer_len*/sizeof(*ata_params),
3240 /*sense_len*/SSD_FULL_SIZE,
3241 /*timeout*/da_default_timeout * 1000);
3242 start_ccb->ccb_h.ccb_bp = NULL;
3243 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3244 xpt_action(start_ccb);
3247 case DA_STATE_PROBE_ATA_LOGDIR:
3249 struct ata_gp_log_dir *log_dir;
3254 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3256 * If we don't have log support, not much point in
3257 * trying to probe zone support.
3259 daprobedone(periph, start_ccb);
3264 * If we have an ATA device (the SCSI ATA Information VPD
3265 * page should be present and the ATA identify should have
3266 * succeeded) and it supports logs, ask for the log directory.
3269 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3270 if (log_dir == NULL) {
3271 xpt_print(periph->path, "Couldn't malloc log_dir "
3273 daprobedone(periph, start_ccb);
3277 retval = scsi_ata_read_log(&start_ccb->csio,
3278 /*retries*/ da_retry_count,
3280 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3281 /*log_address*/ ATA_LOG_DIRECTORY,
3284 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3285 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3286 /*data_ptr*/ (uint8_t *)log_dir,
3287 /*dxfer_len*/ sizeof(*log_dir),
3288 /*sense_len*/ SSD_FULL_SIZE,
3289 /*timeout*/ da_default_timeout * 1000);
3292 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3293 free(log_dir, M_SCSIDA);
3294 daprobedone(periph, start_ccb);
3297 start_ccb->ccb_h.ccb_bp = NULL;
3298 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3299 xpt_action(start_ccb);
3302 case DA_STATE_PROBE_ATA_IDDIR:
3304 struct ata_identify_log_pages *id_dir;
3310 * Check here to see whether the Identify Device log is
3311 * supported in the directory of logs. If so, continue
3312 * with requesting the log of identify device pages.
3314 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3315 daprobedone(periph, start_ccb);
3319 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3320 if (id_dir == NULL) {
3321 xpt_print(periph->path, "Couldn't malloc id_dir "
3323 daprobedone(periph, start_ccb);
3327 retval = scsi_ata_read_log(&start_ccb->csio,
3328 /*retries*/ da_retry_count,
3330 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3331 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3332 /*page_number*/ ATA_IDL_PAGE_LIST,
3334 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3335 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3336 /*data_ptr*/ (uint8_t *)id_dir,
3337 /*dxfer_len*/ sizeof(*id_dir),
3338 /*sense_len*/ SSD_FULL_SIZE,
3339 /*timeout*/ da_default_timeout * 1000);
3342 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3343 free(id_dir, M_SCSIDA);
3344 daprobedone(periph, start_ccb);
3347 start_ccb->ccb_h.ccb_bp = NULL;
3348 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3349 xpt_action(start_ccb);
3352 case DA_STATE_PROBE_ATA_SUP:
3354 struct ata_identify_log_sup_cap *sup_cap;
3360 * Check here to see whether the Supported Capabilities log
3361 * is in the list of Identify Device logs.
3363 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3364 daprobedone(periph, start_ccb);
3368 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3369 if (sup_cap == NULL) {
3370 xpt_print(periph->path, "Couldn't malloc sup_cap "
3372 daprobedone(periph, start_ccb);
3376 retval = scsi_ata_read_log(&start_ccb->csio,
3377 /*retries*/ da_retry_count,
3379 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3380 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3381 /*page_number*/ ATA_IDL_SUP_CAP,
3383 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3384 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3385 /*data_ptr*/ (uint8_t *)sup_cap,
3386 /*dxfer_len*/ sizeof(*sup_cap),
3387 /*sense_len*/ SSD_FULL_SIZE,
3388 /*timeout*/ da_default_timeout * 1000);
3391 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3392 free(sup_cap, M_SCSIDA);
3393 daprobedone(periph, start_ccb);
3398 start_ccb->ccb_h.ccb_bp = NULL;
3399 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3400 xpt_action(start_ccb);
3403 case DA_STATE_PROBE_ATA_ZONE:
3405 struct ata_zoned_info_log *ata_zone;
3411 * Check here to see whether the zoned device information
3412 * page is supported. If so, continue on to request it.
3413 * If not, skip to DA_STATE_PROBE_LOG or done.
3415 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3416 daprobedone(periph, start_ccb);
3419 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3421 if (ata_zone == NULL) {
3422 xpt_print(periph->path, "Couldn't malloc ata_zone "
3424 daprobedone(periph, start_ccb);
3428 retval = scsi_ata_read_log(&start_ccb->csio,
3429 /*retries*/ da_retry_count,
3431 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3432 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3433 /*page_number*/ ATA_IDL_ZDI,
3435 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3436 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3437 /*data_ptr*/ (uint8_t *)ata_zone,
3438 /*dxfer_len*/ sizeof(*ata_zone),
3439 /*sense_len*/ SSD_FULL_SIZE,
3440 /*timeout*/ da_default_timeout * 1000);
3443 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3444 free(ata_zone, M_SCSIDA);
3445 daprobedone(periph, start_ccb);
3448 start_ccb->ccb_h.ccb_bp = NULL;
3449 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3450 xpt_action(start_ccb);
3454 case DA_STATE_PROBE_ZONE:
3456 struct scsi_vpd_zoned_bdc *bdc;
3459 * Note that this page will be supported for SCSI protocol
3460 * devices that support ZBC (SMR devices), as well as ATA
3461 * protocol devices that are behind a SAT (SCSI to ATA
3462 * Translation) layer that supports converting ZBC commands
3463 * to their ZAC equivalents.
3465 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3466 daprobedone(periph, start_ccb);
3469 bdc = (struct scsi_vpd_zoned_bdc *)
3470 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3473 xpt_release_ccb(start_ccb);
3474 xpt_print(periph->path, "Couldn't malloc zone VPD "
3478 scsi_inquiry(&start_ccb->csio,
3479 /*retries*/da_retry_count,
3481 /*tag_action*/MSG_SIMPLE_Q_TAG,
3482 /*inq_buf*/(u_int8_t *)bdc,
3483 /*inq_len*/sizeof(*bdc),
3485 /*page_code*/SVPD_ZONED_BDC,
3486 /*sense_len*/SSD_FULL_SIZE,
3487 /*timeout*/da_default_timeout * 1000);
3488 start_ccb->ccb_h.ccb_bp = NULL;
3489 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3490 xpt_action(start_ccb);
3497 * In each of the methods below, while its the caller's
3498 * responsibility to ensure the request will fit into a
3499 * single device request, we might have changed the delete
3500 * method due to the device incorrectly advertising either
3501 * its supported methods or limits.
3503 * To prevent this causing further issues we validate the
3504 * against the methods limits, and warn which would
3505 * otherwise be unnecessary.
3508 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3510 struct da_softc *softc = (struct da_softc *)periph->softc;;
3512 uint8_t *buf = softc->unmap_buf;
3513 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3514 uint64_t lba, lastlba = (uint64_t)-1;
3515 uint64_t totalcount = 0;
3517 uint32_t c, lastcount = 0, ranges = 0;
3520 * Currently this doesn't take the UNMAP
3521 * Granularity and Granularity Alignment
3522 * fields into account.
3524 * This could result in both unoptimal unmap
3525 * requests as as well as UNMAP calls unmapping
3526 * fewer LBA's than requested.
3529 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3533 * Note: ada and da are different in how they store the
3534 * pending bp's in a trim. ada stores all of them in the
3535 * trim_req.bps. da stores all but the first one in the
3536 * delete_run_queue. ada then completes all the bps in
3537 * its adadone() loop. da completes all the bps in the
3538 * delete_run_queue in dadone, and relies on the biodone
3539 * after to complete. This should be reconciled since there's
3540 * no real reason to do it differently. XXX
3543 bioq_insert_tail(&softc->delete_run_queue, bp1);
3544 lba = bp1->bio_pblkno;
3545 count = bp1->bio_bcount / softc->params.secsize;
3547 /* Try to extend the previous range. */
3548 if (lba == lastlba) {
3549 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3552 scsi_ulto4b(lastcount, d[ranges - 1].length);
3556 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3557 softc->unmap_gran != 0) {
3558 /* Align length of the previous range. */
3559 if ((c = lastcount % softc->unmap_gran) != 0) {
3560 if (lastcount <= c) {
3561 totalcount -= lastcount;
3562 lastlba = (uint64_t)-1;
3569 scsi_ulto4b(lastcount, d[ranges - 1].length);
3572 /* Align beginning of the new range. */
3573 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3575 c = softc->unmap_gran - c;
3586 c = omin(count, UNMAP_RANGE_MAX);
3587 if (totalcount + c > softc->unmap_max_lba ||
3588 ranges >= softc->unmap_max_ranges) {
3589 xpt_print(periph->path,
3590 "%s issuing short delete %ld > %ld"
3592 da_delete_method_desc[softc->delete_method],
3593 totalcount + c, softc->unmap_max_lba,
3594 ranges, softc->unmap_max_ranges);
3597 scsi_u64to8b(lba, d[ranges].lba);
3598 scsi_ulto4b(c, d[ranges].length);
3606 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3609 if (ranges >= softc->unmap_max_ranges ||
3610 totalcount + bp1->bio_bcount /
3611 softc->params.secsize > softc->unmap_max_lba) {
3612 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3617 /* Align length of the last range. */
3618 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
3619 (c = lastcount % softc->unmap_gran) != 0) {
3623 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
3626 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3627 scsi_ulto2b(ranges * 16, &buf[2]);
3629 scsi_unmap(&ccb->csio,
3630 /*retries*/da_retry_count,
3632 /*tag_action*/MSG_SIMPLE_Q_TAG,
3635 /*dxfer_len*/ ranges * 16 + 8,
3636 /*sense_len*/SSD_FULL_SIZE,
3637 da_default_timeout * 1000);
3638 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3639 ccb->ccb_h.flags |= CAM_UNLOCKED;
3640 cam_iosched_submit_trim(softc->cam_iosched);
3644 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3646 struct da_softc *softc = (struct da_softc *)periph->softc;
3648 uint8_t *buf = softc->unmap_buf;
3649 uint64_t lastlba = (uint64_t)-1;
3652 uint32_t lastcount = 0, c, requestcount;
3653 int ranges = 0, off, block_count;
3655 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3658 if (bp1 != bp)//XXX imp XXX
3659 bioq_insert_tail(&softc->delete_run_queue, bp1);
3660 lba = bp1->bio_pblkno;
3661 count = bp1->bio_bcount / softc->params.secsize;
3662 requestcount = count;
3664 /* Try to extend the previous range. */
3665 if (lba == lastlba) {
3666 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3668 off = (ranges - 1) * 8;
3669 buf[off + 6] = lastcount & 0xff;
3670 buf[off + 7] = (lastcount >> 8) & 0xff;
3676 c = omin(count, ATA_DSM_RANGE_MAX);
3679 buf[off + 0] = lba & 0xff;
3680 buf[off + 1] = (lba >> 8) & 0xff;
3681 buf[off + 2] = (lba >> 16) & 0xff;
3682 buf[off + 3] = (lba >> 24) & 0xff;
3683 buf[off + 4] = (lba >> 32) & 0xff;
3684 buf[off + 5] = (lba >> 40) & 0xff;
3685 buf[off + 6] = c & 0xff;
3686 buf[off + 7] = (c >> 8) & 0xff;
3691 if (count != 0 && ranges == softc->trim_max_ranges) {
3692 xpt_print(periph->path,
3693 "%s issuing short delete %ld > %ld\n",
3694 da_delete_method_desc[softc->delete_method],
3696 (softc->trim_max_ranges - ranges) *
3702 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3705 if (bp1->bio_bcount / softc->params.secsize >
3706 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3707 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3712 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3713 scsi_ata_trim(&ccb->csio,
3714 /*retries*/da_retry_count,
3716 /*tag_action*/MSG_SIMPLE_Q_TAG,
3719 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3720 /*sense_len*/SSD_FULL_SIZE,
3721 da_default_timeout * 1000);
3722 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3723 ccb->ccb_h.flags |= CAM_UNLOCKED;
3724 cam_iosched_submit_trim(softc->cam_iosched);
3728 * We calculate ws_max_blks here based off d_delmaxsize instead
3729 * of using softc->ws_max_blks as it is absolute max for the
3730 * device not the protocol max which may well be lower.
3733 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3735 struct da_softc *softc;
3737 uint64_t ws_max_blks;
3739 uint64_t count; /* forward compat with WS32 */
3741 softc = (struct da_softc *)periph->softc;
3742 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3743 lba = bp->bio_pblkno;
3747 if (bp1 != bp)//XXX imp XXX
3748 bioq_insert_tail(&softc->delete_run_queue, bp1);
3749 count += bp1->bio_bcount / softc->params.secsize;
3750 if (count > ws_max_blks) {
3751 xpt_print(periph->path,
3752 "%s issuing short delete %ld > %ld\n",
3753 da_delete_method_desc[softc->delete_method],
3754 count, ws_max_blks);
3755 count = omin(count, ws_max_blks);
3758 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3761 if (lba + count != bp1->bio_pblkno ||
3762 count + bp1->bio_bcount /
3763 softc->params.secsize > ws_max_blks) {
3764 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3769 scsi_write_same(&ccb->csio,
3770 /*retries*/da_retry_count,
3772 /*tag_action*/MSG_SIMPLE_Q_TAG,
3773 /*byte2*/softc->delete_method ==
3774 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3775 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3777 /*block_count*/count,
3778 /*data_ptr*/ __DECONST(void *, zero_region),
3779 /*dxfer_len*/ softc->params.secsize,
3780 /*sense_len*/SSD_FULL_SIZE,
3781 da_default_timeout * 1000);
3782 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3783 ccb->ccb_h.flags |= CAM_UNLOCKED;
3784 cam_iosched_submit_trim(softc->cam_iosched);
3788 cmd6workaround(union ccb *ccb)
3790 struct scsi_rw_6 cmd6;
3791 struct scsi_rw_10 *cmd10;
3792 struct da_softc *softc;
3797 cdb = ccb->csio.cdb_io.cdb_bytes;
3798 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3800 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3801 da_delete_methods old_method = softc->delete_method;
3804 * Typically there are two reasons for failure here
3805 * 1. Delete method was detected as supported but isn't
3806 * 2. Delete failed due to invalid params e.g. too big
3808 * While we will attempt to choose an alternative delete method
3809 * this may result in short deletes if the existing delete
3810 * requests from geom are big for the new method chosen.
3812 * This method assumes that the error which triggered this
3813 * will not retry the io otherwise a panic will occur
3815 dadeleteflag(softc, old_method, 0);
3816 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3817 if (softc->delete_method == DA_DELETE_DISABLE)
3818 xpt_print(ccb->ccb_h.path,
3819 "%s failed, disabling BIO_DELETE\n",
3820 da_delete_method_desc[old_method]);
3822 xpt_print(ccb->ccb_h.path,
3823 "%s failed, switching to %s BIO_DELETE\n",
3824 da_delete_method_desc[old_method],
3825 da_delete_method_desc[softc->delete_method]);
3827 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3828 cam_iosched_queue_work(softc->cam_iosched, bp);
3829 cam_iosched_queue_work(softc->cam_iosched,
3830 (struct bio *)ccb->ccb_h.ccb_bp);
3831 ccb->ccb_h.ccb_bp = NULL;
3835 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3836 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3837 (*cdb == PREVENT_ALLOW) &&
3838 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3840 xpt_print(ccb->ccb_h.path,
3841 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3842 softc->quirks |= DA_Q_NO_PREVENT;
3846 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3847 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3848 (*cdb == SYNCHRONIZE_CACHE) &&
3849 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3851 xpt_print(ccb->ccb_h.path,
3852 "SYNCHRONIZE CACHE(10) not supported.\n");
3853 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3854 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3858 /* Translation only possible if CDB is an array and cmd is R/W6 */
3859 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3860 (*cdb != READ_6 && *cdb != WRITE_6))
3863 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3864 "increasing minimum_cmd_size to 10.\n");
3865 softc->minimum_cmd_size = 10;
3867 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3868 cmd10 = (struct scsi_rw_10 *)cdb;
3869 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3871 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3872 cmd10->reserved = 0;
3873 scsi_ulto2b(cmd6.length, cmd10->length);
3874 cmd10->control = cmd6.control;
3875 ccb->csio.cdb_len = sizeof(*cmd10);
3877 /* Requeue request, unfreezing queue if necessary */
3878 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3879 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3882 cam_release_devq(ccb->ccb_h.path,
3886 /*getcount_only*/0);
3892 dazonedone(struct cam_periph *periph, union ccb *ccb)
3894 struct da_softc *softc;
3897 softc = periph->softc;
3898 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3900 switch (bp->bio_zone.zone_cmd) {
3901 case DISK_ZONE_OPEN:
3902 case DISK_ZONE_CLOSE:
3903 case DISK_ZONE_FINISH:
3906 case DISK_ZONE_REPORT_ZONES: {
3908 struct disk_zone_report *rep;
3909 struct scsi_report_zones_hdr *hdr;
3910 struct scsi_report_zones_desc *desc;
3911 struct disk_zone_rep_entry *entry;
3912 uint32_t num_alloced, hdr_len, num_avail;
3913 uint32_t num_to_fill, i;
3916 rep = &bp->bio_zone.zone_params.report;
3917 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
3919 * Note that bio_resid isn't normally used for zone
3920 * commands, but it is used by devstat_end_transaction_bio()
3921 * to determine how much data was transferred. Because
3922 * the size of the SCSI/ATA data structures is different
3923 * than the size of the BIO interface structures, the
3924 * amount of data actually transferred from the drive will
3925 * be different than the amount of data transferred to
3928 bp->bio_resid = ccb->csio.resid;
3929 num_alloced = rep->entries_allocated;
3930 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
3931 if (avail_len < sizeof(*hdr)) {
3933 * Is there a better error than EIO here? We asked
3934 * for at least the header, and we got less than
3937 bp->bio_error = EIO;
3938 bp->bio_flags |= BIO_ERROR;
3939 bp->bio_resid = bp->bio_bcount;
3943 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
3948 hdr_len = ata ? le32dec(hdr->length) :
3949 scsi_4btoul(hdr->length);
3951 rep->entries_available = hdr_len / sizeof(*desc);
3953 rep->entries_available = 0;
3955 * NOTE: using the same values for the BIO version of the
3956 * same field as the SCSI/ATA values. This means we could
3957 * get some additional values that aren't defined in bio.h
3958 * if more values of the same field are defined later.
3960 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
3961 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
3962 scsi_8btou64(hdr->maximum_lba);
3964 * If the drive reports no entries that match the query,
3968 rep->entries_filled = 0;
3972 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
3973 hdr_len / sizeof(*desc));
3975 * If the drive didn't return any data, then we're done.
3977 if (num_avail == 0) {
3978 rep->entries_filled = 0;
3982 num_to_fill = min(num_avail, rep->entries_allocated);
3984 * If the user didn't allocate any entries for us to fill,
3987 if (num_to_fill == 0) {
3988 rep->entries_filled = 0;
3992 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
3993 i < num_to_fill; i++, desc++, entry++) {
3995 * NOTE: we're mapping the values here directly
3996 * from the SCSI/ATA bit definitions to the bio.h
3997 * definitons. There is also a warning in
3998 * disk_zone.h, but the impact is that if
3999 * additional values are added in the SCSI/ATA
4000 * specs these will be visible to consumers of
4003 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4004 entry->zone_condition =
4005 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4006 SRZ_ZONE_COND_SHIFT;
4007 entry->zone_flags |= desc->zone_flags &
4008 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4009 entry->zone_length =
4010 ata ? le64dec(desc->zone_length) :
4011 scsi_8btou64(desc->zone_length);
4012 entry->zone_start_lba =
4013 ata ? le64dec(desc->zone_start_lba) :
4014 scsi_8btou64(desc->zone_start_lba);
4015 entry->write_pointer_lba =
4016 ata ? le64dec(desc->write_pointer_lba) :
4017 scsi_8btou64(desc->write_pointer_lba);
4019 rep->entries_filled = num_to_fill;
4022 case DISK_ZONE_GET_PARAMS:
4025 * In theory we should not get a GET_PARAMS bio, since it
4026 * should be handled without queueing the command to the
4029 panic("%s: Invalid zone command %d", __func__,
4030 bp->bio_zone.zone_cmd);
4034 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4035 free(ccb->csio.data_ptr, M_SCSIDA);
4039 dadone(struct cam_periph *periph, union ccb *done_ccb)
4041 struct da_softc *softc;
4042 struct ccb_scsiio *csio;
4046 softc = (struct da_softc *)periph->softc;
4047 priority = done_ccb->ccb_h.pinfo.priority;
4049 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4051 csio = &done_ccb->csio;
4052 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4054 case DA_CCB_BUFFER_IO:
4057 struct bio *bp, *bp1;
4059 cam_periph_lock(periph);
4060 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4061 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4065 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4070 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4071 if (error == ERESTART) {
4073 * A retry was scheduled, so
4076 cam_periph_unlock(periph);
4079 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4084 * return all queued I/O with EIO, so that
4085 * the client can retry these I/Os in the
4086 * proper order should it attempt to recover.
4091 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4093 * Catastrophic error. Mark our pack as
4097 * XXX See if this is really a media
4100 xpt_print(periph->path,
4101 "Invalidating pack\n");
4102 softc->flags |= DA_FLAG_PACK_INVALID;
4104 softc->invalidations++;
4106 queued_error = ENXIO;
4108 cam_iosched_flush(softc->cam_iosched, NULL,
4111 bp->bio_error = error;
4112 bp->bio_resid = bp->bio_bcount;
4113 bp->bio_flags |= BIO_ERROR;
4115 } else if (bp != NULL) {
4116 if (state == DA_CCB_DELETE)
4119 bp->bio_resid = csio->resid;
4121 if (bp->bio_resid != 0)
4122 bp->bio_flags |= BIO_ERROR;
4124 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4125 cam_release_devq(done_ccb->ccb_h.path,
4129 /*getcount_only*/0);
4130 } else if (bp != NULL) {
4131 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4132 panic("REQ_CMP with QFRZN");
4133 if (bp->bio_cmd == BIO_ZONE)
4134 dazonedone(periph, done_ccb);
4135 else if (state == DA_CCB_DELETE)
4138 bp->bio_resid = csio->resid;
4139 if ((csio->resid > 0)
4140 && (bp->bio_cmd != BIO_ZONE))
4141 bp->bio_flags |= BIO_ERROR;
4142 if (softc->error_inject != 0) {
4143 bp->bio_error = softc->error_inject;
4144 bp->bio_resid = bp->bio_bcount;
4145 bp->bio_flags |= BIO_ERROR;
4146 softc->error_inject = 0;
4150 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4151 if (LIST_EMPTY(&softc->pending_ccbs))
4152 softc->flags |= DA_FLAG_WAS_OTAG;
4154 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4155 xpt_release_ccb(done_ccb);
4156 if (state == DA_CCB_DELETE) {
4157 TAILQ_HEAD(, bio) queue;
4160 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4161 softc->delete_run_queue.insert_point = NULL;
4163 * Normally, the xpt_release_ccb() above would make sure
4164 * that when we have more work to do, that work would
4165 * get kicked off. However, we specifically keep
4166 * delete_running set to 0 before the call above to
4167 * allow other I/O to progress when many BIO_DELETE
4168 * requests are pushed down. We set delete_running to 0
4169 * and call daschedule again so that we don't stall if
4170 * there are no other I/Os pending apart from BIO_DELETEs.
4172 cam_iosched_trim_done(softc->cam_iosched);
4174 cam_periph_unlock(periph);
4175 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4176 TAILQ_REMOVE(&queue, bp1, bio_queue);
4177 bp1->bio_error = bp->bio_error;
4178 if (bp->bio_flags & BIO_ERROR) {
4179 bp1->bio_flags |= BIO_ERROR;
4180 bp1->bio_resid = bp1->bio_bcount;
4187 cam_periph_unlock(periph);
4193 case DA_CCB_PROBE_RC:
4194 case DA_CCB_PROBE_RC16:
4196 struct scsi_read_capacity_data *rdcap;
4197 struct scsi_read_capacity_data_long *rcaplong;
4198 char announce_buf[80];
4204 if (state == DA_CCB_PROBE_RC)
4205 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4207 rcaplong = (struct scsi_read_capacity_data_long *)
4210 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4211 struct disk_params *dp;
4212 uint32_t block_size;
4214 u_int lalba; /* Lowest aligned LBA. */
4216 if (state == DA_CCB_PROBE_RC) {
4217 block_size = scsi_4btoul(rdcap->length);
4218 maxsector = scsi_4btoul(rdcap->addr);
4222 * According to SBC-2, if the standard 10
4223 * byte READ CAPACITY command returns 2^32,
4224 * we should issue the 16 byte version of
4225 * the command, since the device in question
4226 * has more sectors than can be represented
4227 * with the short version of the command.
4229 if (maxsector == 0xffffffff) {
4230 free(rdcap, M_SCSIDA);
4231 xpt_release_ccb(done_ccb);
4232 softc->state = DA_STATE_PROBE_RC16;
4233 xpt_schedule(periph, priority);
4237 block_size = scsi_4btoul(rcaplong->length);
4238 maxsector = scsi_8btou64(rcaplong->addr);
4239 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4243 * Because GEOM code just will panic us if we
4244 * give them an 'illegal' value we'll avoid that
4247 if (block_size == 0) {
4252 if (block_size >= MAXPHYS) {
4253 xpt_print(periph->path,
4254 "unsupportable block size %ju\n",
4255 (uintmax_t) block_size);
4256 announce_buf[0] = '\0';
4257 cam_periph_invalidate(periph);
4260 * We pass rcaplong into dasetgeom(),
4261 * because it will only use it if it is
4264 dasetgeom(periph, block_size, maxsector,
4265 rcaplong, sizeof(*rcaplong));
4266 lbp = (lalba & SRC16_LBPME_A);
4267 dp = &softc->params;
4268 snprintf(announce_buf, sizeof(announce_buf),
4269 "%juMB (%ju %u byte sectors)",
4270 ((uintmax_t)dp->secsize * dp->sectors) /
4272 (uintmax_t)dp->sectors, dp->secsize);
4277 announce_buf[0] = '\0';
4280 * Retry any UNIT ATTENTION type errors. They
4281 * are expected at boot.
4283 error = daerror(done_ccb, CAM_RETRY_SELTO,
4284 SF_RETRY_UA|SF_NO_PRINT);
4285 if (error == ERESTART) {
4287 * A retry was scheuled, so
4291 } else if (error != 0) {
4293 int sense_key, error_code;
4296 struct ccb_getdev cgd;
4298 /* Don't wedge this device's queue */
4299 status = done_ccb->ccb_h.status;
4300 if ((status & CAM_DEV_QFRZN) != 0)
4301 cam_release_devq(done_ccb->ccb_h.path,
4305 /*getcount_only*/0);
4308 xpt_setup_ccb(&cgd.ccb_h,
4309 done_ccb->ccb_h.path,
4310 CAM_PRIORITY_NORMAL);
4311 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4312 xpt_action((union ccb *)&cgd);
4314 if (scsi_extract_sense_ccb(done_ccb,
4315 &error_code, &sense_key, &asc, &ascq))
4321 * If we tried READ CAPACITY(16) and failed,
4322 * fallback to READ CAPACITY(10).
4324 if ((state == DA_CCB_PROBE_RC16) &&
4325 (softc->flags & DA_FLAG_CAN_RC16) &&
4326 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4329 (error_code == SSD_CURRENT_ERROR) &&
4330 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4331 softc->flags &= ~DA_FLAG_CAN_RC16;
4332 free(rdcap, M_SCSIDA);
4333 xpt_release_ccb(done_ccb);
4334 softc->state = DA_STATE_PROBE_RC;
4335 xpt_schedule(periph, priority);
4340 * Attach to anything that claims to be a
4341 * direct access or optical disk device,
4342 * as long as it doesn't return a "Logical
4343 * unit not supported" (0x25) error.
4345 if ((have_sense) && (asc != 0x25)
4346 && (error_code == SSD_CURRENT_ERROR)) {
4347 const char *sense_key_desc;
4348 const char *asc_desc;
4350 dasetgeom(periph, 512, -1, NULL, 0);
4351 scsi_sense_desc(sense_key, asc, ascq,
4355 snprintf(announce_buf,
4356 sizeof(announce_buf),
4357 "Attempt to query device "
4358 "size failed: %s, %s",
4366 xpt_print(periph->path,
4367 "got CAM status %#x\n",
4368 done_ccb->ccb_h.status);
4371 xpt_print(periph->path, "fatal error, "
4372 "failed to attach to device\n");
4375 * Free up resources.
4377 cam_periph_invalidate(periph);
4381 free(csio->data_ptr, M_SCSIDA);
4382 if (announce_buf[0] != '\0' &&
4383 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4385 * Create our sysctl variables, now that we know
4386 * we have successfully attached.
4388 /* increase the refcount */
4389 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4390 taskqueue_enqueue(taskqueue_thread,
4391 &softc->sysctl_task);
4392 xpt_announce_periph(periph, announce_buf);
4393 xpt_announce_quirks(periph, softc->quirks,
4396 xpt_print(periph->path, "fatal error, "
4397 "could not acquire reference count\n");
4401 /* We already probed the device. */
4402 if (softc->flags & DA_FLAG_PROBED) {
4403 daprobedone(periph, done_ccb);
4407 /* Ensure re-probe doesn't see old delete. */
4408 softc->delete_available = 0;
4409 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4410 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4412 * Based on older SBC-3 spec revisions
4413 * any of the UNMAP methods "may" be
4414 * available via LBP given this flag so
4415 * we flag all of them as available and
4416 * then remove those which further
4417 * probes confirm aren't available
4420 * We could also check readcap(16) p_type
4421 * flag to exclude one or more invalid
4422 * write same (X) types here
4424 dadeleteflag(softc, DA_DELETE_WS16, 1);
4425 dadeleteflag(softc, DA_DELETE_WS10, 1);
4426 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4428 xpt_release_ccb(done_ccb);
4429 softc->state = DA_STATE_PROBE_LBP;
4430 xpt_schedule(periph, priority);
4434 xpt_release_ccb(done_ccb);
4435 softc->state = DA_STATE_PROBE_BDC;
4436 xpt_schedule(periph, priority);
4439 case DA_CCB_PROBE_LBP:
4441 struct scsi_vpd_logical_block_prov *lbp;
4443 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4445 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4447 * T10/1799-D Revision 31 states at least one of these
4448 * must be supported but we don't currently enforce this.
4450 dadeleteflag(softc, DA_DELETE_WS16,
4451 (lbp->flags & SVPD_LBP_WS16));
4452 dadeleteflag(softc, DA_DELETE_WS10,
4453 (lbp->flags & SVPD_LBP_WS10));
4454 dadeleteflag(softc, DA_DELETE_UNMAP,
4455 (lbp->flags & SVPD_LBP_UNMAP));
4458 error = daerror(done_ccb, CAM_RETRY_SELTO,
4459 SF_RETRY_UA|SF_NO_PRINT);
4460 if (error == ERESTART)
4462 else if (error != 0) {
4463 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4464 /* Don't wedge this device's queue */
4465 cam_release_devq(done_ccb->ccb_h.path,
4469 /*getcount_only*/0);
4473 * Failure indicates we don't support any SBC-3
4474 * delete methods with UNMAP
4479 free(lbp, M_SCSIDA);
4480 xpt_release_ccb(done_ccb);
4481 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4482 xpt_schedule(periph, priority);
4485 case DA_CCB_PROBE_BLK_LIMITS:
4487 struct scsi_vpd_block_limits *block_limits;
4489 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4491 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4492 uint32_t max_txfer_len = scsi_4btoul(
4493 block_limits->max_txfer_len);
4494 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4495 block_limits->max_unmap_lba_cnt);
4496 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4497 block_limits->max_unmap_blk_cnt);
4498 uint32_t unmap_gran = scsi_4btoul(
4499 block_limits->opt_unmap_grain);
4500 uint32_t unmap_gran_align = scsi_4btoul(
4501 block_limits->unmap_grain_align);
4502 uint64_t ws_max_blks = scsi_8btou64(
4503 block_limits->max_write_same_length);
4505 if (max_txfer_len != 0) {
4506 softc->disk->d_maxsize = MIN(softc->maxio,
4507 (off_t)max_txfer_len * softc->params.secsize);
4511 * We should already support UNMAP but we check lba
4512 * and block count to be sure
4514 if (max_unmap_lba_cnt != 0x00L &&
4515 max_unmap_blk_cnt != 0x00L) {
4516 softc->unmap_max_lba = max_unmap_lba_cnt;
4517 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4519 if (unmap_gran > 1) {
4520 softc->unmap_gran = unmap_gran;
4521 if (unmap_gran_align & 0x80000000) {
4522 softc->unmap_gran_align =
4529 * Unexpected UNMAP limits which means the
4530 * device doesn't actually support UNMAP
4532 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4535 if (ws_max_blks != 0x00L)
4536 softc->ws_max_blks = ws_max_blks;
4539 error = daerror(done_ccb, CAM_RETRY_SELTO,
4540 SF_RETRY_UA|SF_NO_PRINT);
4541 if (error == ERESTART)
4543 else if (error != 0) {
4544 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4545 /* Don't wedge this device's queue */
4546 cam_release_devq(done_ccb->ccb_h.path,
4550 /*getcount_only*/0);
4554 * Failure here doesn't mean UNMAP is not
4555 * supported as this is an optional page.
4557 softc->unmap_max_lba = 1;
4558 softc->unmap_max_ranges = 1;
4562 free(block_limits, M_SCSIDA);
4563 xpt_release_ccb(done_ccb);
4564 softc->state = DA_STATE_PROBE_BDC;
4565 xpt_schedule(periph, priority);
4568 case DA_CCB_PROBE_BDC:
4570 struct scsi_vpd_block_device_characteristics *bdc;
4572 bdc = (struct scsi_vpd_block_device_characteristics *)
4575 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4579 * Disable queue sorting for non-rotational media
4582 u_int16_t old_rate = softc->disk->d_rotation_rate;
4584 valid_len = csio->dxfer_len - csio->resid;
4585 if (SBDC_IS_PRESENT(bdc, valid_len,
4586 medium_rotation_rate)) {
4587 softc->disk->d_rotation_rate =
4588 scsi_2btoul(bdc->medium_rotation_rate);
4589 if (softc->disk->d_rotation_rate ==
4590 SVPD_BDC_RATE_NON_ROTATING) {
4591 cam_iosched_set_sort_queue(
4592 softc->cam_iosched, 0);
4593 softc->rotating = 0;
4595 if (softc->disk->d_rotation_rate != old_rate) {
4596 disk_attr_changed(softc->disk,
4597 "GEOM::rotation_rate", M_NOWAIT);
4600 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4601 && (softc->zone_mode == DA_ZONE_NONE)) {
4604 if (scsi_vpd_supported_page(periph,
4605 SVPD_ATA_INFORMATION))
4611 * The Zoned field will only be set for
4612 * Drive Managed and Host Aware drives. If
4613 * they are Host Managed, the device type
4614 * in the standard INQUIRY data should be
4615 * set to T_ZBC_HM (0x14).
4617 if ((bdc->flags & SVPD_ZBC_MASK) ==
4619 softc->zone_mode = DA_ZONE_HOST_AWARE;
4620 softc->zone_interface = (ata_proto) ?
4621 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4622 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4624 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4625 softc->zone_interface = (ata_proto) ?
4626 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4627 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4629 xpt_print(periph->path, "Unknown zoned "
4631 bdc->flags & SVPD_ZBC_MASK);
4636 error = daerror(done_ccb, CAM_RETRY_SELTO,
4637 SF_RETRY_UA|SF_NO_PRINT);
4638 if (error == ERESTART)
4640 else if (error != 0) {
4641 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4642 /* Don't wedge this device's queue */
4643 cam_release_devq(done_ccb->ccb_h.path,
4647 /*getcount_only*/0);
4652 free(bdc, M_SCSIDA);
4653 xpt_release_ccb(done_ccb);
4654 softc->state = DA_STATE_PROBE_ATA;
4655 xpt_schedule(periph, priority);
4658 case DA_CCB_PROBE_ATA:
4661 struct ata_params *ata_params;
4666 ata_params = (struct ata_params *)csio->data_ptr;
4667 ptr = (uint16_t *)ata_params;
4671 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4674 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4675 ptr[i] = le16toh(ptr[i]);
4676 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4677 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4678 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4679 if (ata_params->max_dsm_blocks != 0)
4680 softc->trim_max_ranges = min(
4681 softc->trim_max_ranges,
4682 ata_params->max_dsm_blocks *
4683 ATA_DSM_BLK_RANGES);
4686 * Disable queue sorting for non-rotational media
4689 old_rate = softc->disk->d_rotation_rate;
4690 softc->disk->d_rotation_rate =
4691 ata_params->media_rotation_rate;
4692 if (softc->disk->d_rotation_rate ==
4693 ATA_RATE_NON_ROTATING) {
4694 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4695 softc->rotating = 0;
4697 if (softc->disk->d_rotation_rate != old_rate) {
4698 disk_attr_changed(softc->disk,
4699 "GEOM::rotation_rate", M_NOWAIT);
4702 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4703 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4705 if (ata_params->support.extension &
4707 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4710 * At this point, if we have a SATA host aware drive,
4711 * we communicate via ATA passthrough unless the
4712 * SAT layer supports ZBC -> ZAC translation. In
4716 * XXX KDM figure out how to detect a host managed
4719 if (softc->zone_mode == DA_ZONE_NONE) {
4721 * Note that we don't override the zone
4722 * mode or interface if it has already been
4723 * set. This is because it has either been
4724 * set as a quirk, or when we probed the
4725 * SCSI Block Device Characteristics page,
4726 * the zoned field was set. The latter
4727 * means that the SAT layer supports ZBC to
4728 * ZAC translation, and we would prefer to
4729 * use that if it is available.
4731 if ((ata_params->support3 &
4732 ATA_SUPPORT_ZONE_MASK) ==
4733 ATA_SUPPORT_ZONE_HOST_AWARE) {
4734 softc->zone_mode = DA_ZONE_HOST_AWARE;
4735 softc->zone_interface =
4736 DA_ZONE_IF_ATA_PASS;
4737 } else if ((ata_params->support3 &
4738 ATA_SUPPORT_ZONE_MASK) ==
4739 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4740 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4741 softc->zone_interface =
4742 DA_ZONE_IF_ATA_PASS;
4747 error = daerror(done_ccb, CAM_RETRY_SELTO,
4748 SF_RETRY_UA|SF_NO_PRINT);
4749 if (error == ERESTART)
4751 else if (error != 0) {
4752 if ((done_ccb->ccb_h.status &
4753 CAM_DEV_QFRZN) != 0) {
4754 /* Don't wedge this device's queue */
4755 cam_release_devq(done_ccb->ccb_h.path,
4759 /*getcount_only*/0);
4764 free(ata_params, M_SCSIDA);
4765 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4766 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4768 * If the ATA IDENTIFY failed, we could be talking
4769 * to a SCSI drive, although that seems unlikely,
4770 * since the drive did report that it supported the
4771 * ATA Information VPD page. If the ATA IDENTIFY
4772 * succeeded, and the SAT layer doesn't support
4773 * ZBC -> ZAC translation, continue on to get the
4774 * directory of ATA logs, and complete the rest of
4775 * the ZAC probe. If the SAT layer does support
4776 * ZBC -> ZAC translation, we want to use that,
4777 * and we'll probe the SCSI Zoned Block Device
4778 * Characteristics VPD page next.
4781 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4782 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4783 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4785 softc->state = DA_STATE_PROBE_ZONE;
4788 if (continue_probe != 0) {
4789 xpt_release_ccb(done_ccb);
4790 xpt_schedule(periph, priority);
4793 daprobedone(periph, done_ccb);
4796 case DA_CCB_PROBE_ATA_LOGDIR:
4800 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4802 softc->valid_logdir_len = 0;
4803 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4804 softc->valid_logdir_len =
4805 csio->dxfer_len - csio->resid;
4806 if (softc->valid_logdir_len > 0)
4807 bcopy(csio->data_ptr, &softc->ata_logdir,
4808 min(softc->valid_logdir_len,
4809 sizeof(softc->ata_logdir)));
4811 * Figure out whether the Identify Device log is
4812 * supported. The General Purpose log directory
4813 * has a header, and lists the number of pages
4814 * available for each GP log identified by the
4815 * offset into the list.
4817 if ((softc->valid_logdir_len >=
4818 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4819 && (le16dec(softc->ata_logdir.header) ==
4820 ATA_GP_LOG_DIR_VERSION)
4821 && (le16dec(&softc->ata_logdir.num_pages[
4822 (ATA_IDENTIFY_DATA_LOG *
4823 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4824 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4826 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4829 error = daerror(done_ccb, CAM_RETRY_SELTO,
4830 SF_RETRY_UA|SF_NO_PRINT);
4831 if (error == ERESTART)
4833 else if (error != 0) {
4835 * If we can't get the ATA log directory,
4836 * then ATA logs are effectively not
4837 * supported even if the bit is set in the
4840 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
4841 DA_FLAG_CAN_ATA_IDLOG);
4842 if ((done_ccb->ccb_h.status &
4843 CAM_DEV_QFRZN) != 0) {
4844 /* Don't wedge this device's queue */
4845 cam_release_devq(done_ccb->ccb_h.path,
4849 /*getcount_only*/0);
4854 free(csio->data_ptr, M_SCSIDA);
4857 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
4858 softc->state = DA_STATE_PROBE_ATA_IDDIR;
4859 xpt_release_ccb(done_ccb);
4860 xpt_schedule(periph, priority);
4863 daprobedone(periph, done_ccb);
4866 case DA_CCB_PROBE_ATA_IDDIR:
4870 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4871 off_t entries_offset, max_entries;
4874 softc->valid_iddir_len = 0;
4875 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
4876 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
4877 DA_FLAG_CAN_ATA_ZONE);
4878 softc->valid_iddir_len =
4879 csio->dxfer_len - csio->resid;
4880 if (softc->valid_iddir_len > 0)
4881 bcopy(csio->data_ptr, &softc->ata_iddir,
4882 min(softc->valid_iddir_len,
4883 sizeof(softc->ata_iddir)));
4886 __offsetof(struct ata_identify_log_pages,entries);
4887 max_entries = softc->valid_iddir_len - entries_offset;
4888 if ((softc->valid_iddir_len > (entries_offset + 1))
4889 && (le64dec(softc->ata_iddir.header) ==
4891 && (softc->ata_iddir.entry_count > 0)) {
4894 num_entries = softc->ata_iddir.entry_count;
4895 num_entries = min(num_entries,
4896 softc->valid_iddir_len - entries_offset);
4897 for (i = 0; i < num_entries &&
4898 i < max_entries; i++) {
4899 if (softc->ata_iddir.entries[i] ==
4902 DA_FLAG_CAN_ATA_SUPCAP;
4903 else if (softc->ata_iddir.entries[i]==
4906 DA_FLAG_CAN_ATA_ZONE;
4909 DA_FLAG_CAN_ATA_SUPCAP)
4911 DA_FLAG_CAN_ATA_ZONE))
4916 error = daerror(done_ccb, CAM_RETRY_SELTO,
4917 SF_RETRY_UA|SF_NO_PRINT);
4918 if (error == ERESTART)
4920 else if (error != 0) {
4922 * If we can't get the ATA Identify Data log
4923 * directory, then it effectively isn't
4924 * supported even if the ATA Log directory
4925 * a non-zero number of pages present for
4928 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4929 if ((done_ccb->ccb_h.status &
4930 CAM_DEV_QFRZN) != 0) {
4931 /* Don't wedge this device's queue */
4932 cam_release_devq(done_ccb->ccb_h.path,
4936 /*getcount_only*/0);
4941 free(csio->data_ptr, M_SCSIDA);
4944 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
4945 softc->state = DA_STATE_PROBE_ATA_SUP;
4946 xpt_release_ccb(done_ccb);
4947 xpt_schedule(periph, priority);
4950 daprobedone(periph, done_ccb);
4953 case DA_CCB_PROBE_ATA_SUP:
4957 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4960 struct ata_identify_log_sup_cap *sup_cap;
4963 sup_cap = (struct ata_identify_log_sup_cap *)
4965 valid_len = csio->dxfer_len - csio->resid;
4967 __offsetof(struct ata_identify_log_sup_cap,
4968 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
4969 if (valid_len >= needed_size) {
4970 uint64_t zoned, zac_cap;
4972 zoned = le64dec(sup_cap->zoned_cap);
4973 if (zoned & ATA_ZONED_VALID) {
4975 * This should have already been
4976 * set, because this is also in the
4977 * ATA identify data.
4979 if ((zoned & ATA_ZONED_MASK) ==
4980 ATA_SUPPORT_ZONE_HOST_AWARE)
4983 else if ((zoned & ATA_ZONED_MASK) ==
4984 ATA_SUPPORT_ZONE_DEV_MANAGED)
4986 DA_ZONE_DRIVE_MANAGED;
4989 zac_cap = le64dec(sup_cap->sup_zac_cap);
4990 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
4991 if (zac_cap & ATA_REPORT_ZONES_SUP)
4992 softc->zone_flags |=
4993 DA_ZONE_FLAG_RZ_SUP;
4994 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
4995 softc->zone_flags |=
4996 DA_ZONE_FLAG_OPEN_SUP;
4997 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
4998 softc->zone_flags |=
4999 DA_ZONE_FLAG_CLOSE_SUP;
5000 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5001 softc->zone_flags |=
5002 DA_ZONE_FLAG_FINISH_SUP;
5003 if (zac_cap & ATA_ND_RWP_SUP)
5004 softc->zone_flags |=
5005 DA_ZONE_FLAG_RWP_SUP;
5008 * This field was introduced in
5009 * ACS-4, r08 on April 28th, 2015.
5010 * If the drive firmware was written
5011 * to an earlier spec, it won't have
5012 * the field. So, assume all
5013 * commands are supported.
5015 softc->zone_flags |=
5016 DA_ZONE_FLAG_SUP_MASK;
5021 error = daerror(done_ccb, CAM_RETRY_SELTO,
5022 SF_RETRY_UA|SF_NO_PRINT);
5023 if (error == ERESTART)
5025 else if (error != 0) {
5027 * If we can't get the ATA Identify Data
5028 * Supported Capabilities page, clear the
5031 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5033 * And clear zone capabilities.
5035 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5036 if ((done_ccb->ccb_h.status &
5037 CAM_DEV_QFRZN) != 0) {
5038 /* Don't wedge this device's queue */
5039 cam_release_devq(done_ccb->ccb_h.path,
5043 /*getcount_only*/0);
5048 free(csio->data_ptr, M_SCSIDA);
5051 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5052 softc->state = DA_STATE_PROBE_ATA_ZONE;
5053 xpt_release_ccb(done_ccb);
5054 xpt_schedule(periph, priority);
5057 daprobedone(periph, done_ccb);
5060 case DA_CCB_PROBE_ATA_ZONE:
5064 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5065 struct ata_zoned_info_log *zi_log;
5069 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5071 valid_len = csio->dxfer_len - csio->resid;
5072 needed_size = __offsetof(struct ata_zoned_info_log,
5073 version_info) + 1 + sizeof(zi_log->version_info);
5074 if (valid_len >= needed_size) {
5077 tmpvar = le64dec(zi_log->zoned_cap);
5078 if (tmpvar & ATA_ZDI_CAP_VALID) {
5079 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5080 softc->zone_flags |=
5081 DA_ZONE_FLAG_URSWRZ;
5083 softc->zone_flags &=
5084 ~DA_ZONE_FLAG_URSWRZ;
5086 tmpvar = le64dec(zi_log->optimal_seq_zones);
5087 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5088 softc->zone_flags |=
5089 DA_ZONE_FLAG_OPT_SEQ_SET;
5090 softc->optimal_seq_zones = (tmpvar &
5091 ATA_ZDI_OPT_SEQ_MASK);
5093 softc->zone_flags &=
5094 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5095 softc->optimal_seq_zones = 0;
5098 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5099 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5100 softc->zone_flags |=
5101 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5102 softc->optimal_nonseq_zones =
5103 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5105 softc->zone_flags &=
5106 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5107 softc->optimal_nonseq_zones = 0;
5110 tmpvar = le64dec(zi_log->max_seq_req_zones);
5111 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5112 softc->zone_flags |=
5113 DA_ZONE_FLAG_MAX_SEQ_SET;
5114 softc->max_seq_zones =
5115 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5117 softc->zone_flags &=
5118 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5119 softc->max_seq_zones = 0;
5123 error = daerror(done_ccb, CAM_RETRY_SELTO,
5124 SF_RETRY_UA|SF_NO_PRINT);
5125 if (error == ERESTART)
5127 else if (error != 0) {
5128 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5129 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5131 if ((done_ccb->ccb_h.status &
5132 CAM_DEV_QFRZN) != 0) {
5133 /* Don't wedge this device's queue */
5134 cam_release_devq(done_ccb->ccb_h.path,
5138 /*getcount_only*/0);
5143 free(csio->data_ptr, M_SCSIDA);
5145 daprobedone(periph, done_ccb);
5148 case DA_CCB_PROBE_ZONE:
5152 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5155 struct scsi_vpd_zoned_bdc *zoned_bdc;
5158 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5160 valid_len = csio->dxfer_len - csio->resid;
5161 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5162 max_seq_req_zones) + 1 +
5163 sizeof(zoned_bdc->max_seq_req_zones);
5164 if ((valid_len >= needed_len)
5165 && (scsi_2btoul(zoned_bdc->page_length) >=
5167 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5168 softc->zone_flags |=
5169 DA_ZONE_FLAG_URSWRZ;
5171 softc->zone_flags &=
5172 ~DA_ZONE_FLAG_URSWRZ;
5173 softc->optimal_seq_zones =
5174 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5175 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5176 softc->optimal_nonseq_zones = scsi_4btoul(
5177 zoned_bdc->optimal_nonseq_zones);
5178 softc->zone_flags |=
5179 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5180 softc->max_seq_zones =
5181 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5182 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5185 * All of the zone commands are mandatory for SCSI
5188 * XXX KDM this is valid as of September 2015.
5189 * Re-check this assumption once the SAT spec is
5190 * updated to support SCSI ZBC to ATA ZAC mapping.
5191 * Since ATA allows zone commands to be reported
5192 * as supported or not, this may not necessarily
5193 * be true for an ATA device behind a SAT (SCSI to
5194 * ATA Translation) layer.
5196 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5198 error = daerror(done_ccb, CAM_RETRY_SELTO,
5199 SF_RETRY_UA|SF_NO_PRINT);
5200 if (error == ERESTART)
5202 else if (error != 0) {
5203 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5204 /* Don't wedge this device's queue */
5205 cam_release_devq(done_ccb->ccb_h.path,
5209 /*getcount_only*/0);
5213 daprobedone(periph, done_ccb);
5217 /* No-op. We're polling */
5221 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5223 if (daerror(done_ccb, CAM_RETRY_SELTO,
5224 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5227 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5228 cam_release_devq(done_ccb->ccb_h.path,
5232 /*getcount_only*/0);
5234 xpt_release_ccb(done_ccb);
5235 cam_periph_release_locked(periph);
5241 xpt_release_ccb(done_ccb);
5245 dareprobe(struct cam_periph *periph)
5247 struct da_softc *softc;
5250 softc = (struct da_softc *)periph->softc;
5252 /* Probe in progress; don't interfere. */
5253 if (softc->state != DA_STATE_NORMAL)
5256 status = cam_periph_acquire(periph);
5257 KASSERT(status == CAM_REQ_CMP,
5258 ("dareprobe: cam_periph_acquire failed"));
5260 if (softc->flags & DA_FLAG_CAN_RC16)
5261 softc->state = DA_STATE_PROBE_RC16;
5263 softc->state = DA_STATE_PROBE_RC;
5265 xpt_schedule(periph, CAM_PRIORITY_DEV);
5269 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5271 struct da_softc *softc;
5272 struct cam_periph *periph;
5273 int error, error_code, sense_key, asc, ascq;
5275 periph = xpt_path_periph(ccb->ccb_h.path);
5276 softc = (struct da_softc *)periph->softc;
5279 * Automatically detect devices that do not support
5280 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5283 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5284 error = cmd6workaround(ccb);
5285 } else if (scsi_extract_sense_ccb(ccb,
5286 &error_code, &sense_key, &asc, &ascq)) {
5287 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5288 error = cmd6workaround(ccb);
5290 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5291 * query the capacity and notify upper layers.
5293 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5294 asc == 0x2A && ascq == 0x09) {
5295 xpt_print(periph->path, "Capacity data has changed\n");
5296 softc->flags &= ~DA_FLAG_PROBED;
5298 sense_flags |= SF_NO_PRINT;
5299 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5300 asc == 0x28 && ascq == 0x00) {
5301 softc->flags &= ~DA_FLAG_PROBED;
5302 disk_media_changed(softc->disk, M_NOWAIT);
5303 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5304 asc == 0x3F && ascq == 0x03) {
5305 xpt_print(periph->path, "INQUIRY data has changed\n");
5306 softc->flags &= ~DA_FLAG_PROBED;
5308 sense_flags |= SF_NO_PRINT;
5309 } else if (sense_key == SSD_KEY_NOT_READY &&
5310 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5311 softc->flags |= DA_FLAG_PACK_INVALID;
5312 disk_media_gone(softc->disk, M_NOWAIT);
5315 if (error == ERESTART)
5319 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5320 case CAM_CMD_TIMEOUT:
5323 case CAM_REQ_ABORTED:
5324 case CAM_REQ_CMP_ERR:
5325 case CAM_REQ_TERMIO:
5326 case CAM_UNREC_HBA_ERROR:
5327 case CAM_DATA_RUN_ERR:
5337 * Until we have a better way of doing pack validation,
5338 * don't treat UAs as errors.
5340 sense_flags |= SF_RETRY_UA;
5342 if (softc->quirks & DA_Q_RETRY_BUSY)
5343 sense_flags |= SF_RETRY_BUSY;
5344 return(cam_periph_error(ccb, cam_flags, sense_flags,
5345 &softc->saved_ccb));
5349 damediapoll(void *arg)
5351 struct cam_periph *periph = arg;
5352 struct da_softc *softc = periph->softc;
5354 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5355 LIST_EMPTY(&softc->pending_ccbs)) {
5356 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5357 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5361 /* Queue us up again */
5362 if (da_poll_period != 0)
5363 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5367 daprevent(struct cam_periph *periph, int action)
5369 struct da_softc *softc;
5373 softc = (struct da_softc *)periph->softc;
5375 if (((action == PR_ALLOW)
5376 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5377 || ((action == PR_PREVENT)
5378 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5382 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5384 scsi_prevent(&ccb->csio,
5392 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5393 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5396 if (action == PR_ALLOW)
5397 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5399 softc->flags |= DA_FLAG_PACK_LOCKED;
5402 xpt_release_ccb(ccb);
5406 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5407 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5409 struct ccb_calc_geometry ccg;
5410 struct da_softc *softc;
5411 struct disk_params *dp;
5412 u_int lbppbe, lalba;
5415 softc = (struct da_softc *)periph->softc;
5417 dp = &softc->params;
5418 dp->secsize = block_len;
5419 dp->sectors = maxsector + 1;
5420 if (rcaplong != NULL) {
5421 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5422 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5423 lalba &= SRC16_LALBA_A;
5430 dp->stripesize = block_len << lbppbe;
5431 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5433 } else if (softc->quirks & DA_Q_4K) {
5434 dp->stripesize = 4096;
5435 dp->stripeoffset = 0;
5436 } else if (softc->unmap_gran != 0) {
5437 dp->stripesize = block_len * softc->unmap_gran;
5438 dp->stripeoffset = (dp->stripesize - block_len *
5439 softc->unmap_gran_align) % dp->stripesize;
5442 dp->stripeoffset = 0;
5445 * Have the controller provide us with a geometry
5446 * for this disk. The only time the geometry
5447 * matters is when we boot and the controller
5448 * is the only one knowledgeable enough to come
5449 * up with something that will make this a bootable
5452 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5453 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5454 ccg.block_size = dp->secsize;
5455 ccg.volume_size = dp->sectors;
5457 ccg.secs_per_track = 0;
5459 xpt_action((union ccb*)&ccg);
5460 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5462 * We don't know what went wrong here- but just pick
5463 * a geometry so we don't have nasty things like divide
5467 dp->secs_per_track = 255;
5468 dp->cylinders = dp->sectors / (255 * 255);
5469 if (dp->cylinders == 0) {
5473 dp->heads = ccg.heads;
5474 dp->secs_per_track = ccg.secs_per_track;
5475 dp->cylinders = ccg.cylinders;
5479 * If the user supplied a read capacity buffer, and if it is
5480 * different than the previous buffer, update the data in the EDT.
5481 * If it's the same, we don't bother. This avoids sending an
5482 * update every time someone opens this device.
5484 if ((rcaplong != NULL)
5485 && (bcmp(rcaplong, &softc->rcaplong,
5486 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5487 struct ccb_dev_advinfo cdai;
5489 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5490 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5491 cdai.buftype = CDAI_TYPE_RCAPLONG;
5492 cdai.flags = CDAI_FLAG_STORE;
5493 cdai.bufsiz = rcap_len;
5494 cdai.buf = (uint8_t *)rcaplong;
5495 xpt_action((union ccb *)&cdai);
5496 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5497 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5498 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5499 xpt_print(periph->path, "%s: failed to set read "
5500 "capacity advinfo\n", __func__);
5501 /* Use cam_error_print() to decode the status */
5502 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5505 bcopy(rcaplong, &softc->rcaplong,
5506 min(sizeof(softc->rcaplong), rcap_len));
5510 softc->disk->d_sectorsize = softc->params.secsize;
5511 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5512 softc->disk->d_stripesize = softc->params.stripesize;
5513 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5514 /* XXX: these are not actually "firmware" values, so they may be wrong */
5515 softc->disk->d_fwsectors = softc->params.secs_per_track;
5516 softc->disk->d_fwheads = softc->params.heads;
5517 softc->disk->d_devstat->block_size = softc->params.secsize;
5518 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5520 error = disk_resize(softc->disk, M_NOWAIT);
5522 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5526 dasendorderedtag(void *arg)
5528 struct da_softc *softc = arg;
5530 if (da_send_ordered) {
5531 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5532 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5533 softc->flags |= DA_FLAG_NEED_OTAG;
5534 softc->flags &= ~DA_FLAG_WAS_OTAG;
5537 /* Queue us up again */
5538 callout_reset(&softc->sendordered_c,
5539 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5540 dasendorderedtag, softc);
5544 * Step through all DA peripheral drivers, and if the device is still open,
5545 * sync the disk cache to physical media.
5548 dashutdown(void * arg, int howto)
5550 struct cam_periph *periph;
5551 struct da_softc *softc;
5555 CAM_PERIPH_FOREACH(periph, &dadriver) {
5556 softc = (struct da_softc *)periph->softc;
5557 if (SCHEDULER_STOPPED()) {
5558 /* If we paniced with the lock held, do not recurse. */
5559 if (!cam_periph_owned(periph) &&
5560 (softc->flags & DA_FLAG_OPEN)) {
5561 dadump(softc->disk, NULL, 0, 0, 0);
5565 cam_periph_lock(periph);
5568 * We only sync the cache if the drive is still open, and
5569 * if the drive is capable of it..
5571 if (((softc->flags & DA_FLAG_OPEN) == 0)
5572 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5573 cam_periph_unlock(periph);
5577 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5578 scsi_synchronize_cache(&ccb->csio,
5582 /*begin_lba*/0, /* whole disk */
5587 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5588 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5589 softc->disk->d_devstat);
5591 xpt_print(periph->path, "Synchronize cache failed\n");
5592 xpt_release_ccb(ccb);
5593 cam_periph_unlock(periph);
5597 #else /* !_KERNEL */
5600 * XXX These are only left out of the kernel build to silence warnings. If,
5601 * for some reason these functions are used in the kernel, the ifdefs should
5602 * be moved so they are included both in the kernel and userland.
5605 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5606 void (*cbfcnp)(struct cam_periph *, union ccb *),
5607 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5608 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5611 struct scsi_format_unit *scsi_cmd;
5613 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5614 scsi_cmd->opcode = FORMAT_UNIT;
5615 scsi_cmd->byte2 = byte2;
5616 scsi_ulto2b(ileave, scsi_cmd->interleave);
5621 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5631 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5632 void (*cbfcnp)(struct cam_periph *, union ccb *),
5633 uint8_t tag_action, uint8_t list_format,
5634 uint32_t addr_desc_index, uint8_t *data_ptr,
5635 uint32_t dxfer_len, int minimum_cmd_size,
5636 uint8_t sense_len, uint32_t timeout)
5641 * These conditions allow using the 10 byte command. Otherwise we
5642 * need to use the 12 byte command.
5644 if ((minimum_cmd_size <= 10)
5645 && (addr_desc_index == 0)
5646 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5647 struct scsi_read_defect_data_10 *cdb10;
5649 cdb10 = (struct scsi_read_defect_data_10 *)
5650 &csio->cdb_io.cdb_bytes;
5652 cdb_len = sizeof(*cdb10);
5653 bzero(cdb10, cdb_len);
5654 cdb10->opcode = READ_DEFECT_DATA_10;
5655 cdb10->format = list_format;
5656 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5658 struct scsi_read_defect_data_12 *cdb12;
5660 cdb12 = (struct scsi_read_defect_data_12 *)
5661 &csio->cdb_io.cdb_bytes;
5663 cdb_len = sizeof(*cdb12);
5664 bzero(cdb12, cdb_len);
5665 cdb12->opcode = READ_DEFECT_DATA_12;
5666 cdb12->format = list_format;
5667 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5668 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5674 /*flags*/ CAM_DIR_IN,
5684 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5685 void (*cbfcnp)(struct cam_periph *, union ccb *),
5686 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5687 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5690 struct scsi_sanitize *scsi_cmd;
5692 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5693 scsi_cmd->opcode = SANITIZE;
5694 scsi_cmd->byte2 = byte2;
5695 scsi_cmd->control = control;
5696 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5701 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5710 #endif /* _KERNEL */
5713 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5714 void (*cbfcnp)(struct cam_periph *, union ccb *),
5715 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5716 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5717 uint8_t sense_len, uint32_t timeout)
5719 struct scsi_zbc_out *scsi_cmd;
5721 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5722 scsi_cmd->opcode = ZBC_OUT;
5723 scsi_cmd->service_action = service_action;
5724 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5725 scsi_cmd->zone_flags = zone_flags;
5730 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5740 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5741 void (*cbfcnp)(struct cam_periph *, union ccb *),
5742 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5743 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5744 uint8_t sense_len, uint32_t timeout)
5746 struct scsi_zbc_in *scsi_cmd;
5748 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5749 scsi_cmd->opcode = ZBC_IN;
5750 scsi_cmd->service_action = service_action;
5751 scsi_ulto4b(dxfer_len, scsi_cmd->length);
5752 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5753 scsi_cmd->zone_options = zone_options;
5758 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5769 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5770 void (*cbfcnp)(struct cam_periph *, union ccb *),
5771 uint8_t tag_action, int use_ncq,
5772 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5773 uint8_t *data_ptr, uint32_t dxfer_len,
5774 uint8_t *cdb_storage, size_t cdb_storage_len,
5775 uint8_t sense_len, uint32_t timeout)
5777 uint8_t command_out, protocol, ata_flags;
5778 uint16_t features_out;
5779 uint32_t sectors_out, auxiliary;
5785 command_out = ATA_ZAC_MANAGEMENT_OUT;
5786 features_out = (zm_action & 0xf) | (zone_flags << 8);
5787 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5788 if (dxfer_len == 0) {
5789 protocol = AP_PROTO_NON_DATA;
5790 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5793 protocol = AP_PROTO_DMA;
5794 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5795 AP_FLAG_TDIR_TO_DEV;
5796 sectors_out = ((dxfer_len >> 9) & 0xffff);
5800 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5801 if (dxfer_len == 0) {
5802 command_out = ATA_NCQ_NON_DATA;
5803 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5805 * We're assuming the SCSI to ATA translation layer
5806 * will set the NCQ tag number in the tag field.
5807 * That isn't clear from the SAT-4 spec (as of rev 05).
5810 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5812 command_out = ATA_SEND_FPDMA_QUEUED;
5814 * Note that we're defaulting to normal priority,
5815 * and assuming that the SCSI to ATA translation
5816 * layer will insert the NCQ tag number in the tag
5817 * field. That isn't clear in the SAT-4 spec (as
5820 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5822 ata_flags |= AP_FLAG_TLEN_FEAT |
5823 AP_FLAG_TDIR_TO_DEV;
5826 * For SEND FPDMA QUEUED, the transfer length is
5827 * encoded in the FEATURE register, and 0 means
5828 * that 65536 512 byte blocks are to be tranferred.
5829 * In practice, it seems unlikely that we'll see
5830 * a transfer that large, and it may confuse the
5831 * the SAT layer, because generally that means that
5832 * 0 bytes should be transferred.
5834 if (dxfer_len == (65536 * 512)) {
5836 } else if (dxfer_len <= (65535 * 512)) {
5837 features_out = ((dxfer_len >> 9) & 0xffff);
5839 /* The transfer is too big. */
5846 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
5847 protocol = AP_PROTO_FPDMA;
5850 protocol |= AP_EXTEND;
5852 retval = scsi_ata_pass(csio,
5855 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5857 /*protocol*/ protocol,
5858 /*ata_flags*/ ata_flags,
5859 /*features*/ features_out,
5860 /*sector_count*/ sectors_out,
5862 /*command*/ command_out,
5865 /*auxiliary*/ auxiliary,
5867 /*data_ptr*/ data_ptr,
5868 /*dxfer_len*/ dxfer_len,
5869 /*cdb_storage*/ cdb_storage,
5870 /*cdb_storage_len*/ cdb_storage_len,
5871 /*minimum_cmd_size*/ 0,
5872 /*sense_len*/ SSD_FULL_SIZE,
5873 /*timeout*/ timeout);
5881 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
5882 void (*cbfcnp)(struct cam_periph *, union ccb *),
5883 uint8_t tag_action, int use_ncq,
5884 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5885 uint8_t *data_ptr, uint32_t dxfer_len,
5886 uint8_t *cdb_storage, size_t cdb_storage_len,
5887 uint8_t sense_len, uint32_t timeout)
5889 uint8_t command_out, protocol;
5890 uint16_t features_out, sectors_out;
5896 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
5899 command_out = ATA_ZAC_MANAGEMENT_IN;
5900 /* XXX KDM put a macro here */
5901 features_out = (zm_action & 0xf) | (zone_flags << 8);
5902 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
5903 protocol = AP_PROTO_DMA;
5904 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
5907 ata_flags |= AP_FLAG_TLEN_FEAT;
5909 command_out = ATA_RECV_FPDMA_QUEUED;
5910 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
5913 * For RECEIVE FPDMA QUEUED, the transfer length is
5914 * encoded in the FEATURE register, and 0 means
5915 * that 65536 512 byte blocks are to be tranferred.
5916 * In practice, it seems unlikely that we'll see
5917 * a transfer that large, and it may confuse the
5918 * the SAT layer, because generally that means that
5919 * 0 bytes should be transferred.
5921 if (dxfer_len == (65536 * 512)) {
5923 } else if (dxfer_len <= (65535 * 512)) {
5924 features_out = ((dxfer_len >> 9) & 0xffff);
5926 /* The transfer is too big. */
5930 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
5931 protocol = AP_PROTO_FPDMA;
5934 protocol |= AP_EXTEND;
5936 retval = scsi_ata_pass(csio,
5939 /*flags*/ CAM_DIR_IN,
5941 /*protocol*/ protocol,
5942 /*ata_flags*/ ata_flags,
5943 /*features*/ features_out,
5944 /*sector_count*/ sectors_out,
5946 /*command*/ command_out,
5949 /*auxiliary*/ auxiliary,
5951 /*data_ptr*/ data_ptr,
5952 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
5953 /*cdb_storage*/ cdb_storage,
5954 /*cdb_storage_len*/ cdb_storage_len,
5955 /*minimum_cmd_size*/ 0,
5956 /*sense_len*/ SSD_FULL_SIZE,
5957 /*timeout*/ timeout);