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;
341 #define DA_ANNOUNCETMP_SZ 80
342 char announce_temp[DA_ANNOUNCETMP_SZ];
343 #define DA_ANNOUNCE_SZ 400
344 char announcebuf[DA_ANNOUNCE_SZ];
347 #define dadeleteflag(softc, delete_method, enable) \
349 softc->delete_available |= (1 << delete_method); \
351 softc->delete_available &= ~(1 << delete_method); \
354 struct da_quirk_entry {
355 struct scsi_inquiry_pattern inq_pat;
359 static const char quantum[] = "QUANTUM";
360 static const char microp[] = "MICROP";
362 static struct da_quirk_entry da_quirk_table[] =
364 /* SPI, FC devices */
367 * Fujitsu M2513A MO drives.
368 * Tested devices: M2513A2 firmware versions 1200 & 1300.
369 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
370 * Reported by: W.Scholten <whs@xs4all.nl>
372 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
373 /*quirks*/ DA_Q_NO_SYNC_CACHE
377 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
378 /*quirks*/ DA_Q_NO_SYNC_CACHE
382 * This particular Fujitsu drive doesn't like the
383 * synchronize cache command.
384 * Reported by: Tom Jackson <toj@gorilla.net>
386 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
387 /*quirks*/ DA_Q_NO_SYNC_CACHE
391 * This drive doesn't like the synchronize cache command
392 * either. Reported by: Matthew Jacob <mjacob@feral.com>
393 * in NetBSD PR kern/6027, August 24, 1998.
395 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
396 /*quirks*/ DA_Q_NO_SYNC_CACHE
400 * This drive doesn't like the synchronize cache command
401 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
404 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
405 /*quirks*/ DA_Q_NO_SYNC_CACHE
409 * Doesn't like the synchronize cache command.
410 * Reported by: Blaz Zupan <blaz@gold.amis.net>
412 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
413 /*quirks*/ DA_Q_NO_SYNC_CACHE
417 * Doesn't like the synchronize cache command.
418 * Reported by: Blaz Zupan <blaz@gold.amis.net>
420 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
421 /*quirks*/ DA_Q_NO_SYNC_CACHE
425 * Doesn't like the synchronize cache command.
427 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
428 /*quirks*/ DA_Q_NO_SYNC_CACHE
432 * Doesn't like the synchronize cache command.
433 * Reported by: walter@pelissero.de
435 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
436 /*quirks*/ DA_Q_NO_SYNC_CACHE
440 * Doesn't work correctly with 6 byte reads/writes.
441 * Returns illegal request, and points to byte 9 of the
443 * Reported by: Adam McDougall <bsdx@spawnet.com>
445 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
446 /*quirks*/ DA_Q_NO_6_BYTE
450 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
451 /*quirks*/ DA_Q_NO_6_BYTE
455 * Doesn't like the synchronize cache command.
456 * Reported by: walter@pelissero.de
458 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
459 /*quirks*/ DA_Q_NO_SYNC_CACHE
463 * The CISS RAID controllers do not support SYNC_CACHE
465 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
466 /*quirks*/ DA_Q_NO_SYNC_CACHE
470 * The STEC SSDs sometimes hang on UNMAP.
472 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
473 /*quirks*/ DA_Q_NO_UNMAP
477 * VMware returns BUSY status when storage has transient
478 * connectivity problems, so better wait.
479 * Also VMware returns odd errors on misaligned UNMAPs.
481 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
482 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
484 /* USB mass storage devices supported by umass(4) */
487 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
490 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
491 /*quirks*/ DA_Q_NO_SYNC_CACHE
495 * Power Quotient Int. (PQI) USB flash key
498 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
499 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
503 * Creative Nomad MUVO mp3 player (USB)
506 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
507 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
511 * Jungsoft NEXDISK USB flash key
514 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
515 /*quirks*/ DA_Q_NO_SYNC_CACHE
519 * FreeDik USB Mini Data Drive
522 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
523 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
527 * Sigmatel USB Flash MP3 Player
530 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
531 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
535 * Neuros USB Digital Audio Computer
538 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
539 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
543 * SEAGRAND NP-900 MP3 Player
546 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
547 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
551 * iRiver iFP MP3 player (with UMS Firmware)
552 * PR: kern/54881, i386/63941, kern/66124
554 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
555 /*quirks*/ DA_Q_NO_SYNC_CACHE
559 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
562 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
563 /*quirks*/ DA_Q_NO_SYNC_CACHE
567 * ZICPlay USB MP3 Player with FM
570 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
571 /*quirks*/ DA_Q_NO_SYNC_CACHE
575 * TEAC USB floppy mechanisms
577 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
578 /*quirks*/ DA_Q_NO_SYNC_CACHE
582 * Kingston DataTraveler II+ USB Pen-Drive.
583 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
585 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
586 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
594 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
595 /*quirks*/ DA_Q_NO_SYNC_CACHE
599 * Motorola E398 Mobile Phone (TransFlash memory card).
600 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
603 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
604 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
608 * Qware BeatZkey! Pro
611 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
612 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
616 * Time DPA20B 1GB MP3 Player
619 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
620 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
624 * Samsung USB key 128Mb
627 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
628 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
632 * Kingston DataTraveler 2.0 USB Flash memory.
635 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
636 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
640 * Creative MUVO Slim mp3 player (USB)
643 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
644 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
648 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
651 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
652 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
656 * SanDisk Micro Cruzer 128MB
659 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
660 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
664 * TOSHIBA TransMemory USB sticks
667 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
668 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
672 * PNY USB 3.0 Flash Drives
674 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
675 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
680 * PR: usb/75578, usb/72344, usb/65436
682 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
683 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
689 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
690 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16
694 * Genesys 6-in-1 Card Reader
697 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
698 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
702 * Rekam Digital CAMERA
705 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
706 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
710 * iRiver H10 MP3 player
713 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
714 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
718 * iRiver U10 MP3 player
721 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
722 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
729 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
730 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
734 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
737 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
738 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
745 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
746 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
750 * Philips USB Key Audio KEY013
753 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
754 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
761 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
762 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
769 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
770 /*quirks*/ DA_Q_NO_SYNC_CACHE
774 * I/O Magic USB flash - Giga Bank
777 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
778 /*quirks*/ DA_Q_NO_SYNC_CACHE
782 * JoyFly 128mb USB Flash Drive
785 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
786 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
793 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
794 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
798 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
801 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
802 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
806 * Samsung YP-U3 mp3-player
809 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
810 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
813 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
814 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
818 * Sony Cyber-Shot DSC cameras
821 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
822 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
825 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
826 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
829 /* At least several Transcent USB sticks lie on RC16. */
830 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
831 "*"}, /*quirks*/ DA_Q_NO_RC16
835 * I-O Data USB Flash Disk
838 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
839 "*"}, /*quirks*/ DA_Q_NO_RC16
841 /* ATA/SATA devices over SAS/USB/... */
843 /* Hitachi Advanced Format (4k) drives */
844 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
848 /* Micron Advanced Format (4k) drives */
849 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
853 /* Samsung Advanced Format (4k) drives */
854 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
858 /* Samsung Advanced Format (4k) drives */
859 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
863 /* Samsung Advanced Format (4k) drives */
864 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
868 /* Samsung Advanced Format (4k) drives */
869 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
873 /* Seagate Barracuda Green Advanced Format (4k) drives */
874 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
878 /* Seagate Barracuda Green Advanced Format (4k) drives */
879 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
883 /* Seagate Barracuda Green Advanced Format (4k) drives */
884 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
888 /* Seagate Barracuda Green Advanced Format (4k) drives */
889 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
893 /* Seagate Barracuda Green Advanced Format (4k) drives */
894 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
898 /* Seagate Barracuda Green Advanced Format (4k) drives */
899 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
903 /* Seagate Momentus Advanced Format (4k) drives */
904 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
908 /* Seagate Momentus Advanced Format (4k) drives */
909 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
913 /* Seagate Momentus Advanced Format (4k) drives */
914 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
918 /* Seagate Momentus Advanced Format (4k) drives */
919 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
923 /* Seagate Momentus Advanced Format (4k) drives */
924 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
928 /* Seagate Momentus Advanced Format (4k) drives */
929 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
933 /* Seagate Momentus Advanced Format (4k) drives */
934 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
938 /* Seagate Momentus Advanced Format (4k) drives */
939 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
943 /* Seagate Momentus Advanced Format (4k) drives */
944 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
948 /* Seagate Momentus Advanced Format (4k) drives */
949 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
953 /* Seagate Momentus Advanced Format (4k) drives */
954 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
958 /* Seagate Momentus Advanced Format (4k) drives */
959 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
963 /* Seagate Momentus Advanced Format (4k) drives */
964 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
968 /* Seagate Momentus Advanced Format (4k) drives */
969 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
973 /* Seagate Momentus Thin Advanced Format (4k) drives */
974 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
978 /* Seagate Momentus Thin Advanced Format (4k) drives */
979 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
983 /* WDC Caviar Green Advanced Format (4k) drives */
984 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
988 /* WDC Caviar Green Advanced Format (4k) drives */
989 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
993 /* WDC Caviar Green Advanced Format (4k) drives */
994 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
998 /* WDC Caviar Green Advanced Format (4k) drives */
999 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
1003 /* WDC Caviar Green Advanced Format (4k) drives */
1004 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1008 /* WDC Caviar Green Advanced Format (4k) drives */
1009 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1013 /* WDC Caviar Green Advanced Format (4k) drives */
1014 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1018 /* WDC Caviar Green Advanced Format (4k) drives */
1019 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1023 /* WDC Scorpio Black Advanced Format (4k) drives */
1024 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1028 /* WDC Scorpio Black Advanced Format (4k) drives */
1029 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1033 /* WDC Scorpio Black Advanced Format (4k) drives */
1034 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1038 /* WDC Scorpio Black Advanced Format (4k) drives */
1039 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1043 /* WDC Scorpio Blue Advanced Format (4k) drives */
1044 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1048 /* WDC Scorpio Blue Advanced Format (4k) drives */
1049 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1053 /* WDC Scorpio Blue Advanced Format (4k) drives */
1054 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1058 /* WDC Scorpio Blue Advanced Format (4k) drives */
1059 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1064 * Olympus FE-210 camera
1066 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1067 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1071 * LG UP3S MP3 player
1073 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1074 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1078 * Laser MP3-2GA13 MP3 player
1080 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1081 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1085 * LaCie external 250GB Hard drive des by Porsche
1086 * Submitted by: Ben Stuyts <ben@altesco.nl>
1089 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1090 /*quirks*/ DA_Q_NO_SYNC_CACHE
1095 * Corsair Force 2 SSDs
1096 * 4k optimised & trim only works in 4k requests + 4k aligned
1098 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1103 * Corsair Force 3 SSDs
1104 * 4k optimised & trim only works in 4k requests + 4k aligned
1106 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1111 * Corsair Neutron GTX SSDs
1112 * 4k optimised & trim only works in 4k requests + 4k aligned
1114 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1119 * Corsair Force GT & GS SSDs
1120 * 4k optimised & trim only works in 4k requests + 4k aligned
1122 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1128 * 4k optimised & trim only works in 4k requests + 4k aligned
1130 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1135 * Crucial RealSSD C300 SSDs
1138 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1139 "*" }, /*quirks*/DA_Q_4K
1143 * Intel 320 Series SSDs
1144 * 4k optimised & trim only works in 4k requests + 4k aligned
1146 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1151 * Intel 330 Series SSDs
1152 * 4k optimised & trim only works in 4k requests + 4k aligned
1154 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1159 * Intel 510 Series SSDs
1160 * 4k optimised & trim only works in 4k requests + 4k aligned
1162 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1167 * Intel 520 Series SSDs
1168 * 4k optimised & trim only works in 4k requests + 4k aligned
1170 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1175 * Intel S3610 Series SSDs
1176 * 4k optimised & trim only works in 4k requests + 4k aligned
1178 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1183 * Intel X25-M Series SSDs
1184 * 4k optimised & trim only works in 4k requests + 4k aligned
1186 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1191 * Kingston E100 Series SSDs
1192 * 4k optimised & trim only works in 4k requests + 4k aligned
1194 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1199 * Kingston HyperX 3k SSDs
1200 * 4k optimised & trim only works in 4k requests + 4k aligned
1202 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1207 * Marvell SSDs (entry taken from OpenSolaris)
1208 * 4k optimised & trim only works in 4k requests + 4k aligned
1210 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1215 * OCZ Agility 2 SSDs
1216 * 4k optimised & trim only works in 4k requests + 4k aligned
1218 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1223 * OCZ Agility 3 SSDs
1224 * 4k optimised & trim only works in 4k requests + 4k aligned
1226 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1231 * OCZ Deneva R Series SSDs
1232 * 4k optimised & trim only works in 4k requests + 4k aligned
1234 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1239 * OCZ Vertex 2 SSDs (inc pro series)
1240 * 4k optimised & trim only works in 4k requests + 4k aligned
1242 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1248 * 4k optimised & trim only works in 4k requests + 4k aligned
1250 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1256 * 4k optimised & trim only works in 4k requests + 4k aligned
1258 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1263 * Samsung 750 Series SSDs
1264 * 4k optimised & trim only works in 4k requests + 4k aligned
1266 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" },
1271 * Samsung 830 Series SSDs
1272 * 4k optimised & trim only works in 4k requests + 4k aligned
1274 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1280 * 4k optimised & trim only works in 4k requests + 4k aligned
1282 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1288 * 4k optimised & trim only works in 4k requests + 4k aligned
1290 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" },
1296 * 4k optimised & trim only works in 4k requests + 4k aligned
1298 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1303 * Samsung 843T Series SSDs (MZ7WD*)
1304 * Samsung PM851 Series SSDs (MZ7TE*)
1305 * Samsung PM853T Series SSDs (MZ7GE*)
1306 * Samsung SM863 Series SSDs (MZ7KM*)
1309 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1314 * Same as for SAMSUNG MZ7* but enable the quirks for SSD
1315 * starting with MZ7* too
1317 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MZ7*", "*" },
1322 * SuperTalent TeraDrive CT SSDs
1323 * 4k optimised & trim only works in 4k requests + 4k aligned
1325 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1330 * XceedIOPS SATA SSDs
1333 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1338 * Hama Innostor USB-Stick
1340 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1341 /*quirks*/DA_Q_NO_RC16
1345 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1346 * Drive Managed SATA hard drive. This drive doesn't report
1347 * in firmware that it is a drive managed SMR drive.
1349 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS000[23]*", "*" },
1350 /*quirks*/DA_Q_SMR_DM
1354 * MX-ES USB Drive by Mach Xtreme
1356 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1357 /*quirks*/DA_Q_NO_RC16
1361 static disk_strategy_t dastrategy;
1362 static dumper_t dadump;
1363 static periph_init_t dainit;
1364 static void daasync(void *callback_arg, u_int32_t code,
1365 struct cam_path *path, void *arg);
1366 static void dasysctlinit(void *context, int pending);
1367 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1368 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1369 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1370 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1371 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1372 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1373 static void dadeletemethodset(struct da_softc *softc,
1374 da_delete_methods delete_method);
1375 static off_t dadeletemaxsize(struct da_softc *softc,
1376 da_delete_methods delete_method);
1377 static void dadeletemethodchoose(struct da_softc *softc,
1378 da_delete_methods default_method);
1379 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1381 static periph_ctor_t daregister;
1382 static periph_dtor_t dacleanup;
1383 static periph_start_t dastart;
1384 static periph_oninv_t daoninvalidate;
1385 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1386 static void dadone(struct cam_periph *periph,
1387 union ccb *done_ccb);
1388 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1389 u_int32_t sense_flags);
1390 static void daprevent(struct cam_periph *periph, int action);
1391 static void dareprobe(struct cam_periph *periph);
1392 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1394 struct scsi_read_capacity_data_long *rcaplong,
1396 static timeout_t dasendorderedtag;
1397 static void dashutdown(void *arg, int howto);
1398 static timeout_t damediapoll;
1400 #ifndef DA_DEFAULT_POLL_PERIOD
1401 #define DA_DEFAULT_POLL_PERIOD 3
1404 #ifndef DA_DEFAULT_TIMEOUT
1405 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1408 #ifndef DA_DEFAULT_SOFTTIMEOUT
1409 #define DA_DEFAULT_SOFTTIMEOUT 0
1412 #ifndef DA_DEFAULT_RETRY
1413 #define DA_DEFAULT_RETRY 4
1416 #ifndef DA_DEFAULT_SEND_ORDERED
1417 #define DA_DEFAULT_SEND_ORDERED 1
1420 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1421 static int da_retry_count = DA_DEFAULT_RETRY;
1422 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1423 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1424 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1426 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1427 "CAM Direct Access Disk driver");
1428 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1429 &da_poll_period, 0, "Media polling period in seconds");
1430 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1431 &da_retry_count, 0, "Normal I/O retry count");
1432 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1433 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1434 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1435 &da_send_ordered, 0, "Send Ordered Tags");
1437 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1438 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1439 "Soft I/O timeout (ms)");
1440 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1443 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1444 * to the default timeout, we check to see whether an ordered
1445 * tagged transaction is appropriate to prevent simple tag
1446 * starvation. Since we'd like to ensure that there is at least
1447 * 1/2 of the timeout length left for a starved transaction to
1448 * complete after we've sent an ordered tag, we must poll at least
1449 * four times in every timeout period. This takes care of the worst
1450 * case where a starved transaction starts during an interval that
1451 * meets the requirement "don't send an ordered tag" test so it takes
1452 * us two intervals to determine that a tag must be sent.
1454 #ifndef DA_ORDEREDTAG_INTERVAL
1455 #define DA_ORDEREDTAG_INTERVAL 4
1458 static struct periph_driver dadriver =
1461 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1464 PERIPHDRIVER_DECLARE(da, dadriver);
1466 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1469 daopen(struct disk *dp)
1471 struct cam_periph *periph;
1472 struct da_softc *softc;
1475 periph = (struct cam_periph *)dp->d_drv1;
1476 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1480 cam_periph_lock(periph);
1481 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1482 cam_periph_unlock(periph);
1483 cam_periph_release(periph);
1487 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1490 softc = (struct da_softc *)periph->softc;
1493 /* Wait for the disk size update. */
1494 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1497 xpt_print(periph->path, "unable to retrieve capacity data\n");
1499 if (periph->flags & CAM_PERIPH_INVALID)
1502 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1503 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1504 daprevent(periph, PR_PREVENT);
1507 softc->flags &= ~DA_FLAG_PACK_INVALID;
1508 softc->flags |= DA_FLAG_OPEN;
1511 cam_periph_unhold(periph);
1512 cam_periph_unlock(periph);
1515 cam_periph_release(periph);
1521 daclose(struct disk *dp)
1523 struct cam_periph *periph;
1524 struct da_softc *softc;
1528 periph = (struct cam_periph *)dp->d_drv1;
1529 softc = (struct da_softc *)periph->softc;
1530 cam_periph_lock(periph);
1531 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1534 if (cam_periph_hold(periph, PRIBIO) == 0) {
1536 /* Flush disk cache. */
1537 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1538 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1539 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1540 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1541 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1542 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1543 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1545 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1546 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1547 softc->disk->d_devstat);
1548 softc->flags &= ~DA_FLAG_DIRTY;
1549 xpt_release_ccb(ccb);
1552 /* Allow medium removal. */
1553 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1554 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1555 daprevent(periph, PR_ALLOW);
1557 cam_periph_unhold(periph);
1561 * If we've got removeable media, mark the blocksize as
1562 * unavailable, since it could change when new media is
1565 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1566 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1568 softc->flags &= ~DA_FLAG_OPEN;
1569 while (softc->refcount != 0)
1570 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1571 cam_periph_unlock(periph);
1572 cam_periph_release(periph);
1577 daschedule(struct cam_periph *periph)
1579 struct da_softc *softc = (struct da_softc *)periph->softc;
1581 if (softc->state != DA_STATE_NORMAL)
1584 cam_iosched_schedule(softc->cam_iosched, periph);
1588 * Actually translate the requested transfer into one the physical driver
1589 * can understand. The transfer is described by a buf and will include
1590 * only one physical transfer.
1593 dastrategy(struct bio *bp)
1595 struct cam_periph *periph;
1596 struct da_softc *softc;
1598 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1599 softc = (struct da_softc *)periph->softc;
1601 cam_periph_lock(periph);
1604 * If the device has been made invalid, error out
1606 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1607 cam_periph_unlock(periph);
1608 biofinish(bp, NULL, ENXIO);
1612 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1615 * Zone commands must be ordered, because they can depend on the
1616 * effects of previously issued commands, and they may affect
1617 * commands after them.
1619 if (bp->bio_cmd == BIO_ZONE)
1620 bp->bio_flags |= BIO_ORDERED;
1623 * Place it in the queue of disk activities for this disk
1625 cam_iosched_queue_work(softc->cam_iosched, bp);
1628 * Schedule ourselves for performing the work.
1631 cam_periph_unlock(periph);
1637 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1639 struct cam_periph *periph;
1640 struct da_softc *softc;
1642 struct ccb_scsiio csio;
1647 periph = dp->d_drv1;
1648 softc = (struct da_softc *)periph->softc;
1649 cam_periph_lock(periph);
1650 secsize = softc->params.secsize;
1652 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1653 cam_periph_unlock(periph);
1657 memset(&csio, 0, sizeof(csio));
1659 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1660 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1661 scsi_read_write(&csio,
1665 /*read*/SCSI_RW_WRITE,
1667 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1670 /*data_ptr*/(u_int8_t *) virtual,
1671 /*dxfer_len*/length,
1672 /*sense_len*/SSD_FULL_SIZE,
1673 da_default_timeout * 1000);
1674 xpt_polled_action((union ccb *)&csio);
1676 error = cam_periph_error((union ccb *)&csio,
1677 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1678 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1679 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1680 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1682 printf("Aborting dump due to I/O error.\n");
1683 cam_periph_unlock(periph);
1688 * Sync the disk cache contents to the physical media.
1690 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1692 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1693 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1694 scsi_synchronize_cache(&csio,
1698 /*begin_lba*/0,/* Cover the whole disk */
1702 xpt_polled_action((union ccb *)&csio);
1704 error = cam_periph_error((union ccb *)&csio,
1705 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1706 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1707 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1708 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1710 xpt_print(periph->path, "Synchronize cache failed\n");
1712 cam_periph_unlock(periph);
1717 dagetattr(struct bio *bp)
1720 struct cam_periph *periph;
1722 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1723 cam_periph_lock(periph);
1724 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1726 cam_periph_unlock(periph);
1728 bp->bio_completed = bp->bio_length;
1738 * Install a global async callback. This callback will
1739 * receive async callbacks like "new device found".
1741 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1743 if (status != CAM_REQ_CMP) {
1744 printf("da: Failed to attach master async callback "
1745 "due to status 0x%x!\n", status);
1746 } else if (da_send_ordered) {
1748 /* Register our shutdown event handler */
1749 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1750 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1751 printf("dainit: shutdown event registration failed!\n");
1756 * Callback from GEOM, called when it has finished cleaning up its
1760 dadiskgonecb(struct disk *dp)
1762 struct cam_periph *periph;
1764 periph = (struct cam_periph *)dp->d_drv1;
1765 cam_periph_release(periph);
1769 daoninvalidate(struct cam_periph *periph)
1771 struct da_softc *softc;
1773 softc = (struct da_softc *)periph->softc;
1776 * De-register any async callbacks.
1778 xpt_register_async(0, daasync, periph, periph->path);
1780 softc->flags |= DA_FLAG_PACK_INVALID;
1782 softc->invalidations++;
1786 * Return all queued I/O with ENXIO.
1787 * XXX Handle any transactions queued to the card
1788 * with XPT_ABORT_CCB.
1790 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
1793 * Tell GEOM that we've gone away, we'll get a callback when it is
1794 * done cleaning up its resources.
1796 disk_gone(softc->disk);
1800 dacleanup(struct cam_periph *periph)
1802 struct da_softc *softc;
1804 softc = (struct da_softc *)periph->softc;
1806 cam_periph_unlock(periph);
1808 cam_iosched_fini(softc->cam_iosched);
1811 * If we can't free the sysctl tree, oh well...
1813 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
1815 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1816 xpt_print(periph->path,
1817 "can't remove sysctl stats context\n");
1819 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1820 xpt_print(periph->path,
1821 "can't remove sysctl context\n");
1824 callout_drain(&softc->mediapoll_c);
1825 disk_destroy(softc->disk);
1826 callout_drain(&softc->sendordered_c);
1827 free(softc, M_DEVBUF);
1828 cam_periph_lock(periph);
1832 daasync(void *callback_arg, u_int32_t code,
1833 struct cam_path *path, void *arg)
1835 struct cam_periph *periph;
1836 struct da_softc *softc;
1838 periph = (struct cam_periph *)callback_arg;
1840 case AC_FOUND_DEVICE:
1842 struct ccb_getdev *cgd;
1845 cgd = (struct ccb_getdev *)arg;
1849 if (cgd->protocol != PROTO_SCSI)
1851 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
1853 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1854 && SID_TYPE(&cgd->inq_data) != T_RBC
1855 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
1856 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
1860 * Allocate a peripheral instance for
1861 * this device and start the probe
1864 status = cam_periph_alloc(daregister, daoninvalidate,
1866 "da", CAM_PERIPH_BIO,
1868 AC_FOUND_DEVICE, cgd);
1870 if (status != CAM_REQ_CMP
1871 && status != CAM_REQ_INPROG)
1872 printf("daasync: Unable to attach to new device "
1873 "due to status 0x%x\n", status);
1876 case AC_ADVINFO_CHANGED:
1880 buftype = (uintptr_t)arg;
1881 if (buftype == CDAI_TYPE_PHYS_PATH) {
1882 struct da_softc *softc;
1884 softc = periph->softc;
1885 disk_attr_changed(softc->disk, "GEOM::physpath",
1890 case AC_UNIT_ATTENTION:
1893 int error_code, sense_key, asc, ascq;
1895 softc = (struct da_softc *)periph->softc;
1896 ccb = (union ccb *)arg;
1899 * Handle all UNIT ATTENTIONs except our own,
1900 * as they will be handled by daerror().
1902 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1903 scsi_extract_sense_ccb(ccb,
1904 &error_code, &sense_key, &asc, &ascq)) {
1905 if (asc == 0x2A && ascq == 0x09) {
1906 xpt_print(ccb->ccb_h.path,
1907 "Capacity data has changed\n");
1908 softc->flags &= ~DA_FLAG_PROBED;
1910 } else if (asc == 0x28 && ascq == 0x00) {
1911 softc->flags &= ~DA_FLAG_PROBED;
1912 disk_media_changed(softc->disk, M_NOWAIT);
1913 } else if (asc == 0x3F && ascq == 0x03) {
1914 xpt_print(ccb->ccb_h.path,
1915 "INQUIRY data has changed\n");
1916 softc->flags &= ~DA_FLAG_PROBED;
1920 cam_periph_async(periph, code, path, arg);
1924 softc = (struct da_softc *)periph->softc;
1925 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
1926 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1927 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
1935 struct ccb_hdr *ccbh;
1937 softc = (struct da_softc *)periph->softc;
1939 * Don't fail on the expected unit attention
1942 softc->flags |= DA_FLAG_RETRY_UA;
1943 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1944 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1947 case AC_INQ_CHANGED:
1948 softc = (struct da_softc *)periph->softc;
1949 softc->flags &= ~DA_FLAG_PROBED;
1955 cam_periph_async(periph, code, path, arg);
1959 dasysctlinit(void *context, int pending)
1961 struct cam_periph *periph;
1962 struct da_softc *softc;
1963 char tmpstr[80], tmpstr2[80];
1964 struct ccb_trans_settings cts;
1966 periph = (struct cam_periph *)context;
1968 * periph was held for us when this task was enqueued
1970 if (periph->flags & CAM_PERIPH_INVALID) {
1971 cam_periph_release(periph);
1975 softc = (struct da_softc *)periph->softc;
1976 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1977 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1979 sysctl_ctx_init(&softc->sysctl_ctx);
1980 softc->flags |= DA_FLAG_SCTX_INIT;
1981 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
1982 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1983 CTLFLAG_RD, 0, tmpstr, "device_index");
1984 if (softc->sysctl_tree == NULL) {
1985 printf("dasysctlinit: unable to allocate sysctl tree\n");
1986 cam_periph_release(periph);
1991 * Now register the sysctl handler, so the user can change the value on
1994 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1995 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
1996 softc, 0, dadeletemethodsysctl, "A",
1997 "BIO_DELETE execution method");
1998 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1999 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
2000 softc, 0, dadeletemaxsysctl, "Q",
2001 "Maximum BIO_DELETE size");
2002 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2003 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
2004 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
2005 "Minimum CDB size");
2007 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2008 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
2009 softc, 0, dazonemodesysctl, "A",
2011 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2012 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
2013 softc, 0, dazonesupsysctl, "A",
2015 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2016 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2017 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2018 "Optimal Number of Open Sequential Write Preferred Zones");
2019 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2020 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2021 "optimal_nonseq_zones", CTLFLAG_RD,
2022 &softc->optimal_nonseq_zones,
2023 "Optimal Number of Non-Sequentially Written Sequential Write "
2025 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2026 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2027 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2028 "Maximum Number of Open Sequential Write Required Zones");
2030 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2031 SYSCTL_CHILDREN(softc->sysctl_tree),
2035 &softc->error_inject,
2037 "error_inject leaf");
2039 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2040 SYSCTL_CHILDREN(softc->sysctl_tree),
2046 "Unmapped I/O leaf");
2048 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2049 SYSCTL_CHILDREN(softc->sysctl_tree),
2058 * Add some addressing info.
2060 memset(&cts, 0, sizeof (cts));
2061 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2062 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2063 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2064 cam_periph_lock(periph);
2065 xpt_action((union ccb *)&cts);
2066 cam_periph_unlock(periph);
2067 if (cts.ccb_h.status != CAM_REQ_CMP) {
2068 cam_periph_release(periph);
2071 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2072 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2073 if (fc->valid & CTS_FC_VALID_WWPN) {
2074 softc->wwpn = fc->wwpn;
2075 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2076 SYSCTL_CHILDREN(softc->sysctl_tree),
2077 OID_AUTO, "wwpn", CTLFLAG_RD,
2078 &softc->wwpn, "World Wide Port Name");
2084 * Now add some useful stats.
2085 * XXX These should live in cam_periph and be common to all periphs
2087 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2088 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2089 CTLFLAG_RD, 0, "Statistics");
2090 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2091 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2097 "Transport errors reported by the SIM");
2098 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2099 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2105 "Device timeouts reported by the SIM");
2106 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2107 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2109 "pack_invalidations",
2111 &softc->invalidations,
2113 "Device pack invalidations");
2116 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2117 softc->sysctl_tree);
2119 cam_periph_release(periph);
2123 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2127 struct da_softc *softc;
2129 softc = (struct da_softc *)arg1;
2131 value = softc->disk->d_delmaxsize;
2132 error = sysctl_handle_64(oidp, &value, 0, req);
2133 if ((error != 0) || (req->newptr == NULL))
2136 /* only accept values smaller than the calculated value */
2137 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2140 softc->disk->d_delmaxsize = value;
2146 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2150 value = *(int *)arg1;
2152 error = sysctl_handle_int(oidp, &value, 0, req);
2155 || (req->newptr == NULL))
2159 * Acceptable values here are 6, 10, 12 or 16.
2163 else if ((value > 6)
2166 else if ((value > 10)
2169 else if (value > 12)
2172 *(int *)arg1 = value;
2178 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2183 value = da_default_softtimeout / SBT_1MS;
2185 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2186 if ((error != 0) || (req->newptr == NULL))
2189 /* XXX Should clip this to a reasonable level */
2190 if (value > da_default_timeout * 1000)
2193 da_default_softtimeout = value * SBT_1MS;
2198 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2201 softc->delete_method = delete_method;
2202 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2203 softc->delete_func = da_delete_functions[delete_method];
2205 if (softc->delete_method > DA_DELETE_DISABLE)
2206 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2208 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2212 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2216 switch(delete_method) {
2217 case DA_DELETE_UNMAP:
2218 sectors = (off_t)softc->unmap_max_lba;
2220 case DA_DELETE_ATA_TRIM:
2221 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2223 case DA_DELETE_WS16:
2224 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2226 case DA_DELETE_ZERO:
2227 case DA_DELETE_WS10:
2228 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2234 return (off_t)softc->params.secsize *
2235 omin(sectors, softc->params.sectors);
2239 daprobedone(struct cam_periph *periph, union ccb *ccb)
2241 struct da_softc *softc;
2243 softc = (struct da_softc *)periph->softc;
2245 dadeletemethodchoose(softc, DA_DELETE_NONE);
2247 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2251 snprintf(buf, sizeof(buf), "Delete methods: <");
2253 for (i = 0; i <= DA_DELETE_MAX; i++) {
2254 if ((softc->delete_available & (1 << i)) == 0 &&
2255 i != softc->delete_method)
2258 strlcat(buf, ",", sizeof(buf));
2259 strlcat(buf, da_delete_method_names[i],
2261 if (i == softc->delete_method)
2262 strlcat(buf, "(*)", sizeof(buf));
2265 strlcat(buf, ">", sizeof(buf));
2266 printf("%s%d: %s\n", periph->periph_name,
2267 periph->unit_number, buf);
2271 * Since our peripheral may be invalidated by an error
2272 * above or an external event, we must release our CCB
2273 * before releasing the probe lock on the peripheral.
2274 * The peripheral will only go away once the last lock
2275 * is removed, and we need it around for the CCB release
2278 xpt_release_ccb(ccb);
2279 softc->state = DA_STATE_NORMAL;
2280 softc->flags |= DA_FLAG_PROBED;
2282 wakeup(&softc->disk->d_mediasize);
2283 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2284 softc->flags |= DA_FLAG_ANNOUNCED;
2285 cam_periph_unhold(periph);
2287 cam_periph_release_locked(periph);
2291 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2295 /* If available, prefer the method requested by user. */
2296 i = softc->delete_method_pref;
2297 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2298 if (methods & (1 << i)) {
2299 dadeletemethodset(softc, i);
2303 /* Use the pre-defined order to choose the best performing delete. */
2304 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2305 if (i == DA_DELETE_ZERO)
2307 if (softc->delete_available & (1 << i)) {
2308 dadeletemethodset(softc, i);
2313 /* Fallback to default. */
2314 dadeletemethodset(softc, default_method);
2318 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2322 struct da_softc *softc;
2323 int i, error, methods, value;
2325 softc = (struct da_softc *)arg1;
2327 value = softc->delete_method;
2328 if (value < 0 || value > DA_DELETE_MAX)
2331 p = da_delete_method_names[value];
2332 strncpy(buf, p, sizeof(buf));
2333 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2334 if (error != 0 || req->newptr == NULL)
2336 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2337 for (i = 0; i <= DA_DELETE_MAX; i++) {
2338 if (strcmp(buf, da_delete_method_names[i]) == 0)
2341 if (i > DA_DELETE_MAX)
2343 softc->delete_method_pref = i;
2344 dadeletemethodchoose(softc, DA_DELETE_NONE);
2349 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2352 struct da_softc *softc;
2355 softc = (struct da_softc *)arg1;
2357 switch (softc->zone_mode) {
2358 case DA_ZONE_DRIVE_MANAGED:
2359 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2361 case DA_ZONE_HOST_AWARE:
2362 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2364 case DA_ZONE_HOST_MANAGED:
2365 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2369 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2373 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2379 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2382 struct da_softc *softc;
2387 softc = (struct da_softc *)arg1;
2391 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2393 for (i = 0; i < sizeof(da_zone_desc_table) /
2394 sizeof(da_zone_desc_table[0]); i++) {
2395 if (softc->zone_flags & da_zone_desc_table[i].value) {
2397 sbuf_printf(&sb, ", ");
2400 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2405 sbuf_printf(&sb, "None");
2409 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2415 daregister(struct cam_periph *periph, void *arg)
2417 struct da_softc *softc;
2418 struct ccb_pathinq cpi;
2419 struct ccb_getdev *cgd;
2423 cgd = (struct ccb_getdev *)arg;
2425 printf("daregister: no getdev CCB, can't register device\n");
2426 return(CAM_REQ_CMP_ERR);
2429 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2432 if (softc == NULL) {
2433 printf("daregister: Unable to probe new device. "
2434 "Unable to allocate softc\n");
2435 return(CAM_REQ_CMP_ERR);
2438 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2439 printf("daregister: Unable to probe new device. "
2440 "Unable to allocate iosched memory\n");
2441 free(softc, M_DEVBUF);
2442 return(CAM_REQ_CMP_ERR);
2445 LIST_INIT(&softc->pending_ccbs);
2446 softc->state = DA_STATE_PROBE_RC;
2447 bioq_init(&softc->delete_run_queue);
2448 if (SID_IS_REMOVABLE(&cgd->inq_data))
2449 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2450 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2451 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2452 softc->unmap_gran = 0;
2453 softc->unmap_gran_align = 0;
2454 softc->ws_max_blks = WS16_MAX_BLKS;
2455 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2456 softc->rotating = 1;
2458 periph->softc = softc;
2461 * See if this device has any quirks.
2463 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2464 (caddr_t)da_quirk_table,
2465 nitems(da_quirk_table),
2466 sizeof(*da_quirk_table), scsi_inquiry_match);
2469 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2471 softc->quirks = DA_Q_NONE;
2473 /* Check if the SIM does not want 6 byte commands */
2474 bzero(&cpi, sizeof(cpi));
2475 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2476 cpi.ccb_h.func_code = XPT_PATH_INQ;
2477 xpt_action((union ccb *)&cpi);
2478 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2479 softc->quirks |= DA_Q_NO_6_BYTE;
2481 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2482 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2483 else if (softc->quirks & DA_Q_SMR_DM)
2484 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2486 softc->zone_mode = DA_ZONE_NONE;
2488 if (softc->zone_mode != DA_ZONE_NONE) {
2489 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2490 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2491 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2493 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2495 softc->zone_interface = DA_ZONE_IF_SCSI;
2498 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2501 * Take an exclusive refcount on the periph while dastart is called
2502 * to finish the probe. The reference will be dropped in dadone at
2505 (void)cam_periph_hold(periph, PRIBIO);
2508 * Schedule a periodic event to occasionally send an
2509 * ordered tag to a device.
2511 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2512 callout_reset(&softc->sendordered_c,
2513 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2514 dasendorderedtag, softc);
2516 cam_periph_unlock(periph);
2518 * RBC devices don't have to support READ(6), only READ(10).
2520 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2521 softc->minimum_cmd_size = 10;
2523 softc->minimum_cmd_size = 6;
2526 * Load the user's default, if any.
2528 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2529 periph->unit_number);
2530 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2533 * 6, 10, 12 and 16 are the currently permissible values.
2535 if (softc->minimum_cmd_size > 12)
2536 softc->minimum_cmd_size = 16;
2537 else if (softc->minimum_cmd_size > 10)
2538 softc->minimum_cmd_size = 12;
2539 else if (softc->minimum_cmd_size > 6)
2540 softc->minimum_cmd_size = 10;
2542 softc->minimum_cmd_size = 6;
2544 /* Predict whether device may support READ CAPACITY(16). */
2545 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2546 (softc->quirks & DA_Q_NO_RC16) == 0) {
2547 softc->flags |= DA_FLAG_CAN_RC16;
2548 softc->state = DA_STATE_PROBE_RC16;
2552 * Register this media as a disk.
2554 softc->disk = disk_alloc();
2555 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2556 periph->unit_number, 0,
2557 DEVSTAT_BS_UNAVAILABLE,
2558 SID_TYPE(&cgd->inq_data) |
2559 XPORT_DEVSTAT_TYPE(cpi.transport),
2560 DEVSTAT_PRIORITY_DISK);
2561 softc->disk->d_open = daopen;
2562 softc->disk->d_close = daclose;
2563 softc->disk->d_strategy = dastrategy;
2564 softc->disk->d_dump = dadump;
2565 softc->disk->d_getattr = dagetattr;
2566 softc->disk->d_gone = dadiskgonecb;
2567 softc->disk->d_name = "da";
2568 softc->disk->d_drv1 = periph;
2570 softc->maxio = DFLTPHYS; /* traditional default */
2571 else if (cpi.maxio > MAXPHYS)
2572 softc->maxio = MAXPHYS; /* for safety */
2574 softc->maxio = cpi.maxio;
2575 softc->disk->d_maxsize = softc->maxio;
2576 softc->disk->d_unit = periph->unit_number;
2577 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2578 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2579 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2580 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2581 softc->unmappedio = 1;
2582 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2584 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2585 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2586 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2587 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2588 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2589 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2590 softc->disk->d_hba_vendor = cpi.hba_vendor;
2591 softc->disk->d_hba_device = cpi.hba_device;
2592 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2593 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2596 * Acquire a reference to the periph before we register with GEOM.
2597 * We'll release this reference once GEOM calls us back (via
2598 * dadiskgonecb()) telling us that our provider has been freed.
2600 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2601 xpt_print(periph->path, "%s: lost periph during "
2602 "registration!\n", __func__);
2603 cam_periph_lock(periph);
2604 return (CAM_REQ_CMP_ERR);
2607 disk_create(softc->disk, DISK_VERSION);
2608 cam_periph_lock(periph);
2611 * Add async callbacks for events of interest.
2612 * I don't bother checking if this fails as,
2613 * in most cases, the system will function just
2614 * fine without them and the only alternative
2615 * would be to not attach the device on failure.
2617 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2618 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2619 AC_INQ_CHANGED, daasync, periph, periph->path);
2622 * Emit an attribute changed notification just in case
2623 * physical path information arrived before our async
2624 * event handler was registered, but after anyone attaching
2625 * to our disk device polled it.
2627 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2630 * Schedule a periodic media polling events.
2632 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2633 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2634 (cgd->inq_flags & SID_AEN) == 0 &&
2635 da_poll_period != 0)
2636 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2637 damediapoll, periph);
2639 xpt_schedule(periph, CAM_PRIORITY_DEV);
2641 return(CAM_REQ_CMP);
2645 da_zone_bio_to_scsi(int disk_zone_cmd)
2647 switch (disk_zone_cmd) {
2648 case DISK_ZONE_OPEN:
2649 return ZBC_OUT_SA_OPEN;
2650 case DISK_ZONE_CLOSE:
2651 return ZBC_OUT_SA_CLOSE;
2652 case DISK_ZONE_FINISH:
2653 return ZBC_OUT_SA_FINISH;
2655 return ZBC_OUT_SA_RWP;
2662 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2665 struct da_softc *softc;
2670 if (bp->bio_cmd != BIO_ZONE) {
2675 softc = periph->softc;
2677 switch (bp->bio_zone.zone_cmd) {
2678 case DISK_ZONE_OPEN:
2679 case DISK_ZONE_CLOSE:
2680 case DISK_ZONE_FINISH:
2681 case DISK_ZONE_RWP: {
2686 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2687 if (zone_sa == -1) {
2688 xpt_print(periph->path, "Cannot translate zone "
2689 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2695 lba = bp->bio_zone.zone_params.rwp.id;
2697 if (bp->bio_zone.zone_params.rwp.flags &
2698 DISK_ZONE_RWP_FLAG_ALL)
2699 zone_flags |= ZBC_OUT_ALL;
2701 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2702 scsi_zbc_out(&ccb->csio,
2703 /*retries*/ da_retry_count,
2705 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2706 /*service_action*/ zone_sa,
2708 /*zone_flags*/ zone_flags,
2711 /*sense_len*/ SSD_FULL_SIZE,
2712 /*timeout*/ da_default_timeout * 1000);
2715 * Note that in this case, even though we can
2716 * technically use NCQ, we don't bother for several
2718 * 1. It hasn't been tested on a SAT layer that
2719 * supports it. This is new as of SAT-4.
2720 * 2. Even when there is a SAT layer that supports
2721 * it, that SAT layer will also probably support
2722 * ZBC -> ZAC translation, since they are both
2723 * in the SAT-4 spec.
2724 * 3. Translation will likely be preferable to ATA
2725 * passthrough. LSI / Avago at least single
2726 * steps ATA passthrough commands in the HBA,
2727 * regardless of protocol, so unless that
2728 * changes, there is a performance penalty for
2729 * doing ATA passthrough no matter whether
2730 * you're using NCQ/FPDMA, DMA or PIO.
2731 * 4. It requires a 32-byte CDB, which at least at
2732 * this point in CAM requires a CDB pointer, which
2733 * would require us to allocate an additional bit
2734 * of storage separate from the CCB.
2736 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2737 /*retries*/ da_retry_count,
2739 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2741 /*zm_action*/ zone_sa,
2743 /*zone_flags*/ zone_flags,
2746 /*cdb_storage*/ NULL,
2747 /*cdb_storage_len*/ 0,
2748 /*sense_len*/ SSD_FULL_SIZE,
2749 /*timeout*/ da_default_timeout * 1000);
2752 xpt_print(periph->path,
2753 "scsi_ata_zac_mgmt_out() returned an "
2762 case DISK_ZONE_REPORT_ZONES: {
2764 uint32_t num_entries, alloc_size;
2765 struct disk_zone_report *rep;
2767 rep = &bp->bio_zone.zone_params.report;
2769 num_entries = rep->entries_allocated;
2770 if (num_entries == 0) {
2771 xpt_print(periph->path, "No entries allocated for "
2772 "Report Zones request\n");
2776 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2777 (sizeof(struct scsi_report_zones_desc) * num_entries);
2778 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2779 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2780 if (rz_ptr == NULL) {
2781 xpt_print(periph->path, "Unable to allocate memory "
2782 "for Report Zones request\n");
2787 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2788 scsi_zbc_in(&ccb->csio,
2789 /*retries*/ da_retry_count,
2791 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2792 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2793 /*zone_start_lba*/ rep->starting_id,
2794 /*zone_options*/ rep->rep_options,
2795 /*data_ptr*/ rz_ptr,
2796 /*dxfer_len*/ alloc_size,
2797 /*sense_len*/ SSD_FULL_SIZE,
2798 /*timeout*/ da_default_timeout * 1000);
2801 * Note that in this case, even though we can
2802 * technically use NCQ, we don't bother for several
2804 * 1. It hasn't been tested on a SAT layer that
2805 * supports it. This is new as of SAT-4.
2806 * 2. Even when there is a SAT layer that supports
2807 * it, that SAT layer will also probably support
2808 * ZBC -> ZAC translation, since they are both
2809 * in the SAT-4 spec.
2810 * 3. Translation will likely be preferable to ATA
2811 * passthrough. LSI / Avago at least single
2812 * steps ATA passthrough commands in the HBA,
2813 * regardless of protocol, so unless that
2814 * changes, there is a performance penalty for
2815 * doing ATA passthrough no matter whether
2816 * you're using NCQ/FPDMA, DMA or PIO.
2817 * 4. It requires a 32-byte CDB, which at least at
2818 * this point in CAM requires a CDB pointer, which
2819 * would require us to allocate an additional bit
2820 * of storage separate from the CCB.
2822 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2823 /*retries*/ da_retry_count,
2825 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2827 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2828 /*zone_id*/ rep->starting_id,
2829 /*zone_flags*/ rep->rep_options,
2830 /*data_ptr*/ rz_ptr,
2831 /*dxfer_len*/ alloc_size,
2832 /*cdb_storage*/ NULL,
2833 /*cdb_storage_len*/ 0,
2834 /*sense_len*/ SSD_FULL_SIZE,
2835 /*timeout*/ da_default_timeout * 1000);
2838 xpt_print(periph->path,
2839 "scsi_ata_zac_mgmt_in() returned an "
2846 * For BIO_ZONE, this isn't normally needed. However, it
2847 * is used by devstat_end_transaction_bio() to determine
2848 * how much data was transferred.
2851 * XXX KDM we have a problem. But I'm not sure how to fix
2852 * it. devstat uses bio_bcount - bio_resid to calculate
2853 * the amount of data transferred. The GEOM disk code
2854 * uses bio_length - bio_resid to calculate the amount of
2855 * data in bio_completed. We have different structure
2856 * sizes above and below the ada(4) driver. So, if we
2857 * use the sizes above, the amount transferred won't be
2858 * quite accurate for devstat. If we use different sizes
2859 * for bio_bcount and bio_length (above and below
2860 * respectively), then the residual needs to match one or
2861 * the other. Everything is calculated after the bio
2862 * leaves the driver, so changing the values around isn't
2863 * really an option. For now, just set the count to the
2864 * passed in length. This means that the calculations
2865 * above (e.g. bio_completed) will be correct, but the
2866 * amount of data reported to devstat will be slightly
2867 * under or overstated.
2869 bp->bio_bcount = bp->bio_length;
2875 case DISK_ZONE_GET_PARAMS: {
2876 struct disk_zone_disk_params *params;
2878 params = &bp->bio_zone.zone_params.disk_params;
2879 bzero(params, sizeof(*params));
2881 switch (softc->zone_mode) {
2882 case DA_ZONE_DRIVE_MANAGED:
2883 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
2885 case DA_ZONE_HOST_AWARE:
2886 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
2888 case DA_ZONE_HOST_MANAGED:
2889 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
2893 params->zone_mode = DISK_ZONE_MODE_NONE;
2897 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
2898 params->flags |= DISK_ZONE_DISK_URSWRZ;
2900 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
2901 params->optimal_seq_zones = softc->optimal_seq_zones;
2902 params->flags |= DISK_ZONE_OPT_SEQ_SET;
2905 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
2906 params->optimal_nonseq_zones =
2907 softc->optimal_nonseq_zones;
2908 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
2911 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
2912 params->max_seq_zones = softc->max_seq_zones;
2913 params->flags |= DISK_ZONE_MAX_SEQ_SET;
2915 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
2916 params->flags |= DISK_ZONE_RZ_SUP;
2918 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
2919 params->flags |= DISK_ZONE_OPEN_SUP;
2921 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
2922 params->flags |= DISK_ZONE_CLOSE_SUP;
2924 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
2925 params->flags |= DISK_ZONE_FINISH_SUP;
2927 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
2928 params->flags |= DISK_ZONE_RWP_SUP;
2939 dastart(struct cam_periph *periph, union ccb *start_ccb)
2941 struct da_softc *softc;
2943 softc = (struct da_softc *)periph->softc;
2945 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2948 switch (softc->state) {
2949 case DA_STATE_NORMAL:
2955 bp = cam_iosched_next_bio(softc->cam_iosched);
2957 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2958 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2959 scsi_test_unit_ready(&start_ccb->csio,
2960 /*retries*/ da_retry_count,
2964 da_default_timeout * 1000);
2965 start_ccb->ccb_h.ccb_bp = NULL;
2966 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2967 xpt_action(start_ccb);
2969 xpt_release_ccb(start_ccb);
2973 if (bp->bio_cmd == BIO_DELETE) {
2974 if (softc->delete_func != NULL) {
2975 softc->delete_func(periph, start_ccb, bp);
2978 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
2979 biofinish(bp, NULL, 0);
2984 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2985 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2986 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */
2989 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2990 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2991 softc->flags &= ~DA_FLAG_NEED_OTAG;
2992 softc->flags |= DA_FLAG_WAS_OTAG;
2993 tag_code = MSG_ORDERED_Q_TAG;
2995 tag_code = MSG_SIMPLE_Q_TAG;
2998 switch (bp->bio_cmd) {
3005 biotrack(bp, __func__);
3007 if (bp->bio_cmd == BIO_WRITE) {
3008 softc->flags |= DA_FLAG_DIRTY;
3009 rw_op = SCSI_RW_WRITE;
3011 rw_op = SCSI_RW_READ;
3014 data_ptr = bp->bio_data;
3015 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
3016 rw_op |= SCSI_RW_BIO;
3020 scsi_read_write(&start_ccb->csio,
3021 /*retries*/da_retry_count,
3023 /*tag_action*/tag_code,
3026 softc->minimum_cmd_size,
3027 /*lba*/bp->bio_pblkno,
3028 /*block_count*/bp->bio_bcount /
3029 softc->params.secsize,
3031 /*dxfer_len*/ bp->bio_bcount,
3032 /*sense_len*/SSD_FULL_SIZE,
3033 da_default_timeout * 1000);
3034 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3035 start_ccb->csio.bio = bp;
3041 * If we don't support sync cache, or the disk
3042 * isn't dirty, FLUSH is a no-op. Use the
3043 * allocated * CCB for the next bio if one is
3046 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) != 0 ||
3047 (softc->flags & DA_FLAG_DIRTY) == 0) {
3053 * BIO_FLUSH doesn't currently communicate
3054 * range data, so we synchronize the cache
3055 * over the whole disk. We also force
3056 * ordered tag semantics the flush applies
3057 * to all previously queued I/O.
3059 scsi_synchronize_cache(&start_ccb->csio,
3066 da_default_timeout*1000);
3068 * Clear the dirty flag before sending the command.
3069 * Either this sync cache will be successful, or it
3070 * will fail after a retry. If it fails, it is
3071 * unlikely to be successful if retried later, so
3072 * we'll save ourselves time by just marking the
3075 softc->flags &= ~DA_FLAG_DIRTY;
3078 int error, queue_ccb;
3082 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3084 || (queue_ccb == 0)) {
3085 biofinish(bp, NULL, error);
3086 xpt_release_ccb(start_ccb);
3092 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3093 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3094 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3097 LIST_INSERT_HEAD(&softc->pending_ccbs,
3098 &start_ccb->ccb_h, periph_links.le);
3100 /* We expect a unit attention from this device */
3101 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3102 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3103 softc->flags &= ~DA_FLAG_RETRY_UA;
3106 start_ccb->ccb_h.ccb_bp = bp;
3108 cam_periph_unlock(periph);
3109 xpt_action(start_ccb);
3110 cam_periph_lock(periph);
3113 /* May have more work to do, so ensure we stay scheduled */
3117 case DA_STATE_PROBE_RC:
3119 struct scsi_read_capacity_data *rcap;
3121 rcap = (struct scsi_read_capacity_data *)
3122 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3124 printf("dastart: Couldn't malloc read_capacity data\n");
3125 /* da_free_periph??? */
3128 scsi_read_capacity(&start_ccb->csio,
3129 /*retries*/da_retry_count,
3135 start_ccb->ccb_h.ccb_bp = NULL;
3136 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3137 xpt_action(start_ccb);
3140 case DA_STATE_PROBE_RC16:
3142 struct scsi_read_capacity_data_long *rcaplong;
3144 rcaplong = (struct scsi_read_capacity_data_long *)
3145 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3146 if (rcaplong == NULL) {
3147 printf("dastart: Couldn't malloc read_capacity data\n");
3148 /* da_free_periph??? */
3151 scsi_read_capacity_16(&start_ccb->csio,
3152 /*retries*/ da_retry_count,
3154 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3158 /*rcap_buf*/ (uint8_t *)rcaplong,
3159 /*rcap_buf_len*/ sizeof(*rcaplong),
3160 /*sense_len*/ SSD_FULL_SIZE,
3161 /*timeout*/ da_default_timeout * 1000);
3162 start_ccb->ccb_h.ccb_bp = NULL;
3163 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3164 xpt_action(start_ccb);
3167 case DA_STATE_PROBE_LBP:
3169 struct scsi_vpd_logical_block_prov *lbp;
3171 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3173 * If we get here we don't support any SBC-3 delete
3174 * methods with UNMAP as the Logical Block Provisioning
3175 * VPD page support is required for devices which
3176 * support it according to T10/1799-D Revision 31
3177 * however older revisions of the spec don't mandate
3178 * this so we currently don't remove these methods
3179 * from the available set.
3181 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3185 lbp = (struct scsi_vpd_logical_block_prov *)
3186 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3189 printf("dastart: Couldn't malloc lbp data\n");
3190 /* da_free_periph??? */
3194 scsi_inquiry(&start_ccb->csio,
3195 /*retries*/da_retry_count,
3197 /*tag_action*/MSG_SIMPLE_Q_TAG,
3198 /*inq_buf*/(u_int8_t *)lbp,
3199 /*inq_len*/sizeof(*lbp),
3201 /*page_code*/SVPD_LBP,
3202 /*sense_len*/SSD_MIN_SIZE,
3203 /*timeout*/da_default_timeout * 1000);
3204 start_ccb->ccb_h.ccb_bp = NULL;
3205 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3206 xpt_action(start_ccb);
3209 case DA_STATE_PROBE_BLK_LIMITS:
3211 struct scsi_vpd_block_limits *block_limits;
3213 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3214 /* Not supported skip to next probe */
3215 softc->state = DA_STATE_PROBE_BDC;
3219 block_limits = (struct scsi_vpd_block_limits *)
3220 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3222 if (block_limits == NULL) {
3223 printf("dastart: Couldn't malloc block_limits data\n");
3224 /* da_free_periph??? */
3228 scsi_inquiry(&start_ccb->csio,
3229 /*retries*/da_retry_count,
3231 /*tag_action*/MSG_SIMPLE_Q_TAG,
3232 /*inq_buf*/(u_int8_t *)block_limits,
3233 /*inq_len*/sizeof(*block_limits),
3235 /*page_code*/SVPD_BLOCK_LIMITS,
3236 /*sense_len*/SSD_MIN_SIZE,
3237 /*timeout*/da_default_timeout * 1000);
3238 start_ccb->ccb_h.ccb_bp = NULL;
3239 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3240 xpt_action(start_ccb);
3243 case DA_STATE_PROBE_BDC:
3245 struct scsi_vpd_block_characteristics *bdc;
3247 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3248 softc->state = DA_STATE_PROBE_ATA;
3252 bdc = (struct scsi_vpd_block_characteristics *)
3253 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3256 printf("dastart: Couldn't malloc bdc data\n");
3257 /* da_free_periph??? */
3261 scsi_inquiry(&start_ccb->csio,
3262 /*retries*/da_retry_count,
3264 /*tag_action*/MSG_SIMPLE_Q_TAG,
3265 /*inq_buf*/(u_int8_t *)bdc,
3266 /*inq_len*/sizeof(*bdc),
3268 /*page_code*/SVPD_BDC,
3269 /*sense_len*/SSD_MIN_SIZE,
3270 /*timeout*/da_default_timeout * 1000);
3271 start_ccb->ccb_h.ccb_bp = NULL;
3272 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3273 xpt_action(start_ccb);
3276 case DA_STATE_PROBE_ATA:
3278 struct ata_params *ata_params;
3280 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3281 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3282 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3284 * Note that if the ATA VPD page isn't
3285 * supported, we aren't talking to an ATA
3286 * device anyway. Support for that VPD
3287 * page is mandatory for SCSI to ATA (SAT)
3288 * translation layers.
3290 softc->state = DA_STATE_PROBE_ZONE;
3293 daprobedone(periph, start_ccb);
3297 ata_params = (struct ata_params*)
3298 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3300 if (ata_params == NULL) {
3301 xpt_print(periph->path, "Couldn't malloc ata_params "
3303 /* da_free_periph??? */
3307 scsi_ata_identify(&start_ccb->csio,
3308 /*retries*/da_retry_count,
3310 /*tag_action*/MSG_SIMPLE_Q_TAG,
3311 /*data_ptr*/(u_int8_t *)ata_params,
3312 /*dxfer_len*/sizeof(*ata_params),
3313 /*sense_len*/SSD_FULL_SIZE,
3314 /*timeout*/da_default_timeout * 1000);
3315 start_ccb->ccb_h.ccb_bp = NULL;
3316 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3317 xpt_action(start_ccb);
3320 case DA_STATE_PROBE_ATA_LOGDIR:
3322 struct ata_gp_log_dir *log_dir;
3327 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3329 * If we don't have log support, not much point in
3330 * trying to probe zone support.
3332 daprobedone(periph, start_ccb);
3337 * If we have an ATA device (the SCSI ATA Information VPD
3338 * page should be present and the ATA identify should have
3339 * succeeded) and it supports logs, ask for the log directory.
3342 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3343 if (log_dir == NULL) {
3344 xpt_print(periph->path, "Couldn't malloc log_dir "
3346 daprobedone(periph, start_ccb);
3350 retval = scsi_ata_read_log(&start_ccb->csio,
3351 /*retries*/ da_retry_count,
3353 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3354 /*log_address*/ ATA_LOG_DIRECTORY,
3357 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3358 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3359 /*data_ptr*/ (uint8_t *)log_dir,
3360 /*dxfer_len*/ sizeof(*log_dir),
3361 /*sense_len*/ SSD_FULL_SIZE,
3362 /*timeout*/ da_default_timeout * 1000);
3365 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3366 free(log_dir, M_SCSIDA);
3367 daprobedone(periph, start_ccb);
3370 start_ccb->ccb_h.ccb_bp = NULL;
3371 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3372 xpt_action(start_ccb);
3375 case DA_STATE_PROBE_ATA_IDDIR:
3377 struct ata_identify_log_pages *id_dir;
3383 * Check here to see whether the Identify Device log is
3384 * supported in the directory of logs. If so, continue
3385 * with requesting the log of identify device pages.
3387 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3388 daprobedone(periph, start_ccb);
3392 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3393 if (id_dir == NULL) {
3394 xpt_print(periph->path, "Couldn't malloc id_dir "
3396 daprobedone(periph, start_ccb);
3400 retval = scsi_ata_read_log(&start_ccb->csio,
3401 /*retries*/ da_retry_count,
3403 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3404 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3405 /*page_number*/ ATA_IDL_PAGE_LIST,
3407 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3408 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3409 /*data_ptr*/ (uint8_t *)id_dir,
3410 /*dxfer_len*/ sizeof(*id_dir),
3411 /*sense_len*/ SSD_FULL_SIZE,
3412 /*timeout*/ da_default_timeout * 1000);
3415 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3416 free(id_dir, M_SCSIDA);
3417 daprobedone(periph, start_ccb);
3420 start_ccb->ccb_h.ccb_bp = NULL;
3421 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3422 xpt_action(start_ccb);
3425 case DA_STATE_PROBE_ATA_SUP:
3427 struct ata_identify_log_sup_cap *sup_cap;
3433 * Check here to see whether the Supported Capabilities log
3434 * is in the list of Identify Device logs.
3436 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3437 daprobedone(periph, start_ccb);
3441 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3442 if (sup_cap == NULL) {
3443 xpt_print(periph->path, "Couldn't malloc sup_cap "
3445 daprobedone(periph, start_ccb);
3449 retval = scsi_ata_read_log(&start_ccb->csio,
3450 /*retries*/ da_retry_count,
3452 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3453 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3454 /*page_number*/ ATA_IDL_SUP_CAP,
3456 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3457 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3458 /*data_ptr*/ (uint8_t *)sup_cap,
3459 /*dxfer_len*/ sizeof(*sup_cap),
3460 /*sense_len*/ SSD_FULL_SIZE,
3461 /*timeout*/ da_default_timeout * 1000);
3464 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3465 free(sup_cap, M_SCSIDA);
3466 daprobedone(periph, start_ccb);
3471 start_ccb->ccb_h.ccb_bp = NULL;
3472 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3473 xpt_action(start_ccb);
3476 case DA_STATE_PROBE_ATA_ZONE:
3478 struct ata_zoned_info_log *ata_zone;
3484 * Check here to see whether the zoned device information
3485 * page is supported. If so, continue on to request it.
3486 * If not, skip to DA_STATE_PROBE_LOG or done.
3488 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3489 daprobedone(periph, start_ccb);
3492 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3494 if (ata_zone == NULL) {
3495 xpt_print(periph->path, "Couldn't malloc ata_zone "
3497 daprobedone(periph, start_ccb);
3501 retval = scsi_ata_read_log(&start_ccb->csio,
3502 /*retries*/ da_retry_count,
3504 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3505 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3506 /*page_number*/ ATA_IDL_ZDI,
3508 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3509 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3510 /*data_ptr*/ (uint8_t *)ata_zone,
3511 /*dxfer_len*/ sizeof(*ata_zone),
3512 /*sense_len*/ SSD_FULL_SIZE,
3513 /*timeout*/ da_default_timeout * 1000);
3516 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3517 free(ata_zone, M_SCSIDA);
3518 daprobedone(periph, start_ccb);
3521 start_ccb->ccb_h.ccb_bp = NULL;
3522 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3523 xpt_action(start_ccb);
3527 case DA_STATE_PROBE_ZONE:
3529 struct scsi_vpd_zoned_bdc *bdc;
3532 * Note that this page will be supported for SCSI protocol
3533 * devices that support ZBC (SMR devices), as well as ATA
3534 * protocol devices that are behind a SAT (SCSI to ATA
3535 * Translation) layer that supports converting ZBC commands
3536 * to their ZAC equivalents.
3538 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3539 daprobedone(periph, start_ccb);
3542 bdc = (struct scsi_vpd_zoned_bdc *)
3543 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3546 xpt_release_ccb(start_ccb);
3547 xpt_print(periph->path, "Couldn't malloc zone VPD "
3551 scsi_inquiry(&start_ccb->csio,
3552 /*retries*/da_retry_count,
3554 /*tag_action*/MSG_SIMPLE_Q_TAG,
3555 /*inq_buf*/(u_int8_t *)bdc,
3556 /*inq_len*/sizeof(*bdc),
3558 /*page_code*/SVPD_ZONED_BDC,
3559 /*sense_len*/SSD_FULL_SIZE,
3560 /*timeout*/da_default_timeout * 1000);
3561 start_ccb->ccb_h.ccb_bp = NULL;
3562 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3563 xpt_action(start_ccb);
3570 * In each of the methods below, while its the caller's
3571 * responsibility to ensure the request will fit into a
3572 * single device request, we might have changed the delete
3573 * method due to the device incorrectly advertising either
3574 * its supported methods or limits.
3576 * To prevent this causing further issues we validate the
3577 * against the methods limits, and warn which would
3578 * otherwise be unnecessary.
3581 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3583 struct da_softc *softc = (struct da_softc *)periph->softc;;
3585 uint8_t *buf = softc->unmap_buf;
3586 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3587 uint64_t lba, lastlba = (uint64_t)-1;
3588 uint64_t totalcount = 0;
3590 uint32_t c, lastcount = 0, ranges = 0;
3593 * Currently this doesn't take the UNMAP
3594 * Granularity and Granularity Alignment
3595 * fields into account.
3597 * This could result in both unoptimal unmap
3598 * requests as as well as UNMAP calls unmapping
3599 * fewer LBA's than requested.
3602 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3606 * Note: ada and da are different in how they store the
3607 * pending bp's in a trim. ada stores all of them in the
3608 * trim_req.bps. da stores all but the first one in the
3609 * delete_run_queue. ada then completes all the bps in
3610 * its adadone() loop. da completes all the bps in the
3611 * delete_run_queue in dadone, and relies on the biodone
3612 * after to complete. This should be reconciled since there's
3613 * no real reason to do it differently. XXX
3616 bioq_insert_tail(&softc->delete_run_queue, bp1);
3617 lba = bp1->bio_pblkno;
3618 count = bp1->bio_bcount / softc->params.secsize;
3620 /* Try to extend the previous range. */
3621 if (lba == lastlba) {
3622 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3625 scsi_ulto4b(lastcount, d[ranges - 1].length);
3629 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3630 softc->unmap_gran != 0) {
3631 /* Align length of the previous range. */
3632 if ((c = lastcount % softc->unmap_gran) != 0) {
3633 if (lastcount <= c) {
3634 totalcount -= lastcount;
3635 lastlba = (uint64_t)-1;
3642 scsi_ulto4b(lastcount, d[ranges - 1].length);
3645 /* Align beginning of the new range. */
3646 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3648 c = softc->unmap_gran - c;
3659 c = omin(count, UNMAP_RANGE_MAX);
3660 if (totalcount + c > softc->unmap_max_lba ||
3661 ranges >= softc->unmap_max_ranges) {
3662 xpt_print(periph->path,
3663 "%s issuing short delete %ld > %ld"
3665 da_delete_method_desc[softc->delete_method],
3666 totalcount + c, softc->unmap_max_lba,
3667 ranges, softc->unmap_max_ranges);
3670 scsi_u64to8b(lba, d[ranges].lba);
3671 scsi_ulto4b(c, d[ranges].length);
3679 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3682 if (ranges >= softc->unmap_max_ranges ||
3683 totalcount + bp1->bio_bcount /
3684 softc->params.secsize > softc->unmap_max_lba) {
3685 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3690 /* Align length of the last range. */
3691 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
3692 (c = lastcount % softc->unmap_gran) != 0) {
3696 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
3699 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3700 scsi_ulto2b(ranges * 16, &buf[2]);
3702 scsi_unmap(&ccb->csio,
3703 /*retries*/da_retry_count,
3705 /*tag_action*/MSG_SIMPLE_Q_TAG,
3708 /*dxfer_len*/ ranges * 16 + 8,
3709 /*sense_len*/SSD_FULL_SIZE,
3710 da_default_timeout * 1000);
3711 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3712 ccb->ccb_h.flags |= CAM_UNLOCKED;
3713 cam_iosched_submit_trim(softc->cam_iosched);
3717 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3719 struct da_softc *softc = (struct da_softc *)periph->softc;
3721 uint8_t *buf = softc->unmap_buf;
3722 uint64_t lastlba = (uint64_t)-1;
3725 uint32_t lastcount = 0, c, requestcount;
3726 int ranges = 0, off, block_count;
3728 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3731 if (bp1 != bp)//XXX imp XXX
3732 bioq_insert_tail(&softc->delete_run_queue, bp1);
3733 lba = bp1->bio_pblkno;
3734 count = bp1->bio_bcount / softc->params.secsize;
3735 requestcount = count;
3737 /* Try to extend the previous range. */
3738 if (lba == lastlba) {
3739 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3741 off = (ranges - 1) * 8;
3742 buf[off + 6] = lastcount & 0xff;
3743 buf[off + 7] = (lastcount >> 8) & 0xff;
3749 c = omin(count, ATA_DSM_RANGE_MAX);
3752 buf[off + 0] = lba & 0xff;
3753 buf[off + 1] = (lba >> 8) & 0xff;
3754 buf[off + 2] = (lba >> 16) & 0xff;
3755 buf[off + 3] = (lba >> 24) & 0xff;
3756 buf[off + 4] = (lba >> 32) & 0xff;
3757 buf[off + 5] = (lba >> 40) & 0xff;
3758 buf[off + 6] = c & 0xff;
3759 buf[off + 7] = (c >> 8) & 0xff;
3764 if (count != 0 && ranges == softc->trim_max_ranges) {
3765 xpt_print(periph->path,
3766 "%s issuing short delete %ld > %ld\n",
3767 da_delete_method_desc[softc->delete_method],
3769 (softc->trim_max_ranges - ranges) *
3775 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3778 if (bp1->bio_bcount / softc->params.secsize >
3779 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3780 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3785 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3786 scsi_ata_trim(&ccb->csio,
3787 /*retries*/da_retry_count,
3789 /*tag_action*/MSG_SIMPLE_Q_TAG,
3792 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3793 /*sense_len*/SSD_FULL_SIZE,
3794 da_default_timeout * 1000);
3795 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3796 ccb->ccb_h.flags |= CAM_UNLOCKED;
3797 cam_iosched_submit_trim(softc->cam_iosched);
3801 * We calculate ws_max_blks here based off d_delmaxsize instead
3802 * of using softc->ws_max_blks as it is absolute max for the
3803 * device not the protocol max which may well be lower.
3806 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3808 struct da_softc *softc;
3810 uint64_t ws_max_blks;
3812 uint64_t count; /* forward compat with WS32 */
3814 softc = (struct da_softc *)periph->softc;
3815 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3816 lba = bp->bio_pblkno;
3820 if (bp1 != bp)//XXX imp XXX
3821 bioq_insert_tail(&softc->delete_run_queue, bp1);
3822 count += bp1->bio_bcount / softc->params.secsize;
3823 if (count > ws_max_blks) {
3824 xpt_print(periph->path,
3825 "%s issuing short delete %ld > %ld\n",
3826 da_delete_method_desc[softc->delete_method],
3827 count, ws_max_blks);
3828 count = omin(count, ws_max_blks);
3831 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3834 if (lba + count != bp1->bio_pblkno ||
3835 count + bp1->bio_bcount /
3836 softc->params.secsize > ws_max_blks) {
3837 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3842 scsi_write_same(&ccb->csio,
3843 /*retries*/da_retry_count,
3845 /*tag_action*/MSG_SIMPLE_Q_TAG,
3846 /*byte2*/softc->delete_method ==
3847 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3848 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3850 /*block_count*/count,
3851 /*data_ptr*/ __DECONST(void *, zero_region),
3852 /*dxfer_len*/ softc->params.secsize,
3853 /*sense_len*/SSD_FULL_SIZE,
3854 da_default_timeout * 1000);
3855 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3856 ccb->ccb_h.flags |= CAM_UNLOCKED;
3857 cam_iosched_submit_trim(softc->cam_iosched);
3861 cmd6workaround(union ccb *ccb)
3863 struct scsi_rw_6 cmd6;
3864 struct scsi_rw_10 *cmd10;
3865 struct da_softc *softc;
3870 cdb = ccb->csio.cdb_io.cdb_bytes;
3871 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3873 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3874 da_delete_methods old_method = softc->delete_method;
3877 * Typically there are two reasons for failure here
3878 * 1. Delete method was detected as supported but isn't
3879 * 2. Delete failed due to invalid params e.g. too big
3881 * While we will attempt to choose an alternative delete method
3882 * this may result in short deletes if the existing delete
3883 * requests from geom are big for the new method chosen.
3885 * This method assumes that the error which triggered this
3886 * will not retry the io otherwise a panic will occur
3888 dadeleteflag(softc, old_method, 0);
3889 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3890 if (softc->delete_method == DA_DELETE_DISABLE)
3891 xpt_print(ccb->ccb_h.path,
3892 "%s failed, disabling BIO_DELETE\n",
3893 da_delete_method_desc[old_method]);
3895 xpt_print(ccb->ccb_h.path,
3896 "%s failed, switching to %s BIO_DELETE\n",
3897 da_delete_method_desc[old_method],
3898 da_delete_method_desc[softc->delete_method]);
3900 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3901 cam_iosched_queue_work(softc->cam_iosched, bp);
3902 cam_iosched_queue_work(softc->cam_iosched,
3903 (struct bio *)ccb->ccb_h.ccb_bp);
3904 ccb->ccb_h.ccb_bp = NULL;
3908 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3909 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3910 (*cdb == PREVENT_ALLOW) &&
3911 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3913 xpt_print(ccb->ccb_h.path,
3914 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3915 softc->quirks |= DA_Q_NO_PREVENT;
3919 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3920 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3921 (*cdb == SYNCHRONIZE_CACHE) &&
3922 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3924 xpt_print(ccb->ccb_h.path,
3925 "SYNCHRONIZE CACHE(10) not supported.\n");
3926 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3927 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3931 /* Translation only possible if CDB is an array and cmd is R/W6 */
3932 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3933 (*cdb != READ_6 && *cdb != WRITE_6))
3936 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3937 "increasing minimum_cmd_size to 10.\n");
3938 softc->minimum_cmd_size = 10;
3940 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3941 cmd10 = (struct scsi_rw_10 *)cdb;
3942 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3944 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3945 cmd10->reserved = 0;
3946 scsi_ulto2b(cmd6.length, cmd10->length);
3947 cmd10->control = cmd6.control;
3948 ccb->csio.cdb_len = sizeof(*cmd10);
3950 /* Requeue request, unfreezing queue if necessary */
3951 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3952 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3955 cam_release_devq(ccb->ccb_h.path,
3959 /*getcount_only*/0);
3965 dazonedone(struct cam_periph *periph, union ccb *ccb)
3967 struct da_softc *softc;
3970 softc = periph->softc;
3971 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3973 switch (bp->bio_zone.zone_cmd) {
3974 case DISK_ZONE_OPEN:
3975 case DISK_ZONE_CLOSE:
3976 case DISK_ZONE_FINISH:
3979 case DISK_ZONE_REPORT_ZONES: {
3981 struct disk_zone_report *rep;
3982 struct scsi_report_zones_hdr *hdr;
3983 struct scsi_report_zones_desc *desc;
3984 struct disk_zone_rep_entry *entry;
3985 uint32_t num_alloced, hdr_len, num_avail;
3986 uint32_t num_to_fill, i;
3989 rep = &bp->bio_zone.zone_params.report;
3990 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
3992 * Note that bio_resid isn't normally used for zone
3993 * commands, but it is used by devstat_end_transaction_bio()
3994 * to determine how much data was transferred. Because
3995 * the size of the SCSI/ATA data structures is different
3996 * than the size of the BIO interface structures, the
3997 * amount of data actually transferred from the drive will
3998 * be different than the amount of data transferred to
4001 bp->bio_resid = ccb->csio.resid;
4002 num_alloced = rep->entries_allocated;
4003 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
4004 if (avail_len < sizeof(*hdr)) {
4006 * Is there a better error than EIO here? We asked
4007 * for at least the header, and we got less than
4010 bp->bio_error = EIO;
4011 bp->bio_flags |= BIO_ERROR;
4012 bp->bio_resid = bp->bio_bcount;
4016 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4021 hdr_len = ata ? le32dec(hdr->length) :
4022 scsi_4btoul(hdr->length);
4024 rep->entries_available = hdr_len / sizeof(*desc);
4026 rep->entries_available = 0;
4028 * NOTE: using the same values for the BIO version of the
4029 * same field as the SCSI/ATA values. This means we could
4030 * get some additional values that aren't defined in bio.h
4031 * if more values of the same field are defined later.
4033 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4034 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4035 scsi_8btou64(hdr->maximum_lba);
4037 * If the drive reports no entries that match the query,
4041 rep->entries_filled = 0;
4045 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4046 hdr_len / sizeof(*desc));
4048 * If the drive didn't return any data, then we're done.
4050 if (num_avail == 0) {
4051 rep->entries_filled = 0;
4055 num_to_fill = min(num_avail, rep->entries_allocated);
4057 * If the user didn't allocate any entries for us to fill,
4060 if (num_to_fill == 0) {
4061 rep->entries_filled = 0;
4065 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4066 i < num_to_fill; i++, desc++, entry++) {
4068 * NOTE: we're mapping the values here directly
4069 * from the SCSI/ATA bit definitions to the bio.h
4070 * definitons. There is also a warning in
4071 * disk_zone.h, but the impact is that if
4072 * additional values are added in the SCSI/ATA
4073 * specs these will be visible to consumers of
4076 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4077 entry->zone_condition =
4078 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4079 SRZ_ZONE_COND_SHIFT;
4080 entry->zone_flags |= desc->zone_flags &
4081 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4082 entry->zone_length =
4083 ata ? le64dec(desc->zone_length) :
4084 scsi_8btou64(desc->zone_length);
4085 entry->zone_start_lba =
4086 ata ? le64dec(desc->zone_start_lba) :
4087 scsi_8btou64(desc->zone_start_lba);
4088 entry->write_pointer_lba =
4089 ata ? le64dec(desc->write_pointer_lba) :
4090 scsi_8btou64(desc->write_pointer_lba);
4092 rep->entries_filled = num_to_fill;
4095 case DISK_ZONE_GET_PARAMS:
4098 * In theory we should not get a GET_PARAMS bio, since it
4099 * should be handled without queueing the command to the
4102 panic("%s: Invalid zone command %d", __func__,
4103 bp->bio_zone.zone_cmd);
4107 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4108 free(ccb->csio.data_ptr, M_SCSIDA);
4112 dadone(struct cam_periph *periph, union ccb *done_ccb)
4114 struct da_softc *softc;
4115 struct ccb_scsiio *csio;
4119 softc = (struct da_softc *)periph->softc;
4120 priority = done_ccb->ccb_h.pinfo.priority;
4122 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4124 csio = &done_ccb->csio;
4125 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4126 if (csio->bio != NULL)
4127 biotrack(csio->bio, __func__);
4129 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4131 case DA_CCB_BUFFER_IO:
4134 struct bio *bp, *bp1;
4136 cam_periph_lock(periph);
4137 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4138 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4142 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4147 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4148 if (error == ERESTART) {
4150 * A retry was scheduled, so
4153 cam_periph_unlock(periph);
4156 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4161 * return all queued I/O with EIO, so that
4162 * the client can retry these I/Os in the
4163 * proper order should it attempt to recover.
4168 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4170 * Catastrophic error. Mark our pack as
4174 * XXX See if this is really a media
4177 xpt_print(periph->path,
4178 "Invalidating pack\n");
4179 softc->flags |= DA_FLAG_PACK_INVALID;
4181 softc->invalidations++;
4183 queued_error = ENXIO;
4185 cam_iosched_flush(softc->cam_iosched, NULL,
4188 bp->bio_error = error;
4189 bp->bio_resid = bp->bio_bcount;
4190 bp->bio_flags |= BIO_ERROR;
4192 } else if (bp != NULL) {
4193 if (state == DA_CCB_DELETE)
4196 bp->bio_resid = csio->resid;
4198 if (bp->bio_resid != 0)
4199 bp->bio_flags |= BIO_ERROR;
4201 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4202 cam_release_devq(done_ccb->ccb_h.path,
4206 /*getcount_only*/0);
4207 } else if (bp != NULL) {
4208 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4209 panic("REQ_CMP with QFRZN");
4210 if (bp->bio_cmd == BIO_ZONE)
4211 dazonedone(periph, done_ccb);
4212 else if (state == DA_CCB_DELETE)
4215 bp->bio_resid = csio->resid;
4216 if ((csio->resid > 0)
4217 && (bp->bio_cmd != BIO_ZONE))
4218 bp->bio_flags |= BIO_ERROR;
4219 if (softc->error_inject != 0) {
4220 bp->bio_error = softc->error_inject;
4221 bp->bio_resid = bp->bio_bcount;
4222 bp->bio_flags |= BIO_ERROR;
4223 softc->error_inject = 0;
4228 biotrack(bp, __func__);
4229 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4230 if (LIST_EMPTY(&softc->pending_ccbs))
4231 softc->flags |= DA_FLAG_WAS_OTAG;
4234 * We need to call cam_iosched before we call biodone so that we
4235 * don't measure any activity that happens in the completion
4236 * routine, which in the case of sendfile can be quite
4239 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4240 xpt_release_ccb(done_ccb);
4241 if (state == DA_CCB_DELETE) {
4242 TAILQ_HEAD(, bio) queue;
4245 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4246 softc->delete_run_queue.insert_point = NULL;
4248 * Normally, the xpt_release_ccb() above would make sure
4249 * that when we have more work to do, that work would
4250 * get kicked off. However, we specifically keep
4251 * delete_running set to 0 before the call above to
4252 * allow other I/O to progress when many BIO_DELETE
4253 * requests are pushed down. We set delete_running to 0
4254 * and call daschedule again so that we don't stall if
4255 * there are no other I/Os pending apart from BIO_DELETEs.
4257 cam_iosched_trim_done(softc->cam_iosched);
4259 cam_periph_unlock(periph);
4260 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4261 TAILQ_REMOVE(&queue, bp1, bio_queue);
4262 bp1->bio_error = bp->bio_error;
4263 if (bp->bio_flags & BIO_ERROR) {
4264 bp1->bio_flags |= BIO_ERROR;
4265 bp1->bio_resid = bp1->bio_bcount;
4272 cam_periph_unlock(periph);
4278 case DA_CCB_PROBE_RC:
4279 case DA_CCB_PROBE_RC16:
4281 struct scsi_read_capacity_data *rdcap;
4282 struct scsi_read_capacity_data_long *rcaplong;
4289 /* XXX TODO: can this be a malloc? */
4290 announce_buf = softc->announce_temp;
4291 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4293 if (state == DA_CCB_PROBE_RC)
4294 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4296 rcaplong = (struct scsi_read_capacity_data_long *)
4299 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4300 struct disk_params *dp;
4301 uint32_t block_size;
4303 u_int lalba; /* Lowest aligned LBA. */
4305 if (state == DA_CCB_PROBE_RC) {
4306 block_size = scsi_4btoul(rdcap->length);
4307 maxsector = scsi_4btoul(rdcap->addr);
4311 * According to SBC-2, if the standard 10
4312 * byte READ CAPACITY command returns 2^32,
4313 * we should issue the 16 byte version of
4314 * the command, since the device in question
4315 * has more sectors than can be represented
4316 * with the short version of the command.
4318 if (maxsector == 0xffffffff) {
4319 free(rdcap, M_SCSIDA);
4320 xpt_release_ccb(done_ccb);
4321 softc->state = DA_STATE_PROBE_RC16;
4322 xpt_schedule(periph, priority);
4326 block_size = scsi_4btoul(rcaplong->length);
4327 maxsector = scsi_8btou64(rcaplong->addr);
4328 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4332 * Because GEOM code just will panic us if we
4333 * give them an 'illegal' value we'll avoid that
4336 if (block_size == 0) {
4341 if (block_size >= MAXPHYS) {
4342 xpt_print(periph->path,
4343 "unsupportable block size %ju\n",
4344 (uintmax_t) block_size);
4345 announce_buf = NULL;
4346 cam_periph_invalidate(periph);
4349 * We pass rcaplong into dasetgeom(),
4350 * because it will only use it if it is
4353 dasetgeom(periph, block_size, maxsector,
4354 rcaplong, sizeof(*rcaplong));
4355 lbp = (lalba & SRC16_LBPME_A);
4356 dp = &softc->params;
4357 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4358 "%juMB (%ju %u byte sectors)",
4359 ((uintmax_t)dp->secsize * dp->sectors) /
4361 (uintmax_t)dp->sectors, dp->secsize);
4367 * Retry any UNIT ATTENTION type errors. They
4368 * are expected at boot.
4370 error = daerror(done_ccb, CAM_RETRY_SELTO,
4371 SF_RETRY_UA|SF_NO_PRINT);
4372 if (error == ERESTART) {
4374 * A retry was scheuled, so
4378 } else if (error != 0) {
4380 int sense_key, error_code;
4383 struct ccb_getdev cgd;
4385 /* Don't wedge this device's queue */
4386 status = done_ccb->ccb_h.status;
4387 if ((status & CAM_DEV_QFRZN) != 0)
4388 cam_release_devq(done_ccb->ccb_h.path,
4392 /*getcount_only*/0);
4395 xpt_setup_ccb(&cgd.ccb_h,
4396 done_ccb->ccb_h.path,
4397 CAM_PRIORITY_NORMAL);
4398 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4399 xpt_action((union ccb *)&cgd);
4401 if (scsi_extract_sense_ccb(done_ccb,
4402 &error_code, &sense_key, &asc, &ascq))
4408 * If we tried READ CAPACITY(16) and failed,
4409 * fallback to READ CAPACITY(10).
4411 if ((state == DA_CCB_PROBE_RC16) &&
4412 (softc->flags & DA_FLAG_CAN_RC16) &&
4413 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4416 (error_code == SSD_CURRENT_ERROR) &&
4417 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4418 softc->flags &= ~DA_FLAG_CAN_RC16;
4419 free(rdcap, M_SCSIDA);
4420 xpt_release_ccb(done_ccb);
4421 softc->state = DA_STATE_PROBE_RC;
4422 xpt_schedule(periph, priority);
4427 * Attach to anything that claims to be a
4428 * direct access or optical disk device,
4429 * as long as it doesn't return a "Logical
4430 * unit not supported" (0x25) error.
4431 * "Internal Target Failure" (0x44) is also
4432 * special and typically means that the
4433 * device is a SATA drive behind a SATL
4434 * translation that's fallen into a
4435 * terminally fatal state.
4438 && (asc != 0x25) && (asc != 0x44)
4439 && (error_code == SSD_CURRENT_ERROR)) {
4440 const char *sense_key_desc;
4441 const char *asc_desc;
4443 dasetgeom(periph, 512, -1, NULL, 0);
4444 scsi_sense_desc(sense_key, asc, ascq,
4448 snprintf(announce_buf,
4450 "Attempt to query device "
4451 "size failed: %s, %s",
4452 sense_key_desc, asc_desc);
4458 xpt_print(periph->path,
4459 "got CAM status %#x\n",
4460 done_ccb->ccb_h.status);
4463 xpt_print(periph->path, "fatal error, "
4464 "failed to attach to device\n");
4466 announce_buf = NULL;
4469 * Free up resources.
4471 cam_periph_invalidate(periph);
4475 free(csio->data_ptr, M_SCSIDA);
4476 if (announce_buf != NULL &&
4477 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4480 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4482 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4483 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4489 * Create our sysctl variables, now that we know
4490 * we have successfully attached.
4492 /* increase the refcount */
4493 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4495 taskqueue_enqueue(taskqueue_thread,
4496 &softc->sysctl_task);
4498 /* XXX This message is useless! */
4499 xpt_print(periph->path, "fatal error, "
4500 "could not acquire reference count\n");
4504 /* We already probed the device. */
4505 if (softc->flags & DA_FLAG_PROBED) {
4506 daprobedone(periph, done_ccb);
4510 /* Ensure re-probe doesn't see old delete. */
4511 softc->delete_available = 0;
4512 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4513 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4515 * Based on older SBC-3 spec revisions
4516 * any of the UNMAP methods "may" be
4517 * available via LBP given this flag so
4518 * we flag all of them as available and
4519 * then remove those which further
4520 * probes confirm aren't available
4523 * We could also check readcap(16) p_type
4524 * flag to exclude one or more invalid
4525 * write same (X) types here
4527 dadeleteflag(softc, DA_DELETE_WS16, 1);
4528 dadeleteflag(softc, DA_DELETE_WS10, 1);
4529 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4531 xpt_release_ccb(done_ccb);
4532 softc->state = DA_STATE_PROBE_LBP;
4533 xpt_schedule(periph, priority);
4537 xpt_release_ccb(done_ccb);
4538 softc->state = DA_STATE_PROBE_BDC;
4539 xpt_schedule(periph, priority);
4542 case DA_CCB_PROBE_LBP:
4544 struct scsi_vpd_logical_block_prov *lbp;
4546 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4548 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4550 * T10/1799-D Revision 31 states at least one of these
4551 * must be supported but we don't currently enforce this.
4553 dadeleteflag(softc, DA_DELETE_WS16,
4554 (lbp->flags & SVPD_LBP_WS16));
4555 dadeleteflag(softc, DA_DELETE_WS10,
4556 (lbp->flags & SVPD_LBP_WS10));
4557 dadeleteflag(softc, DA_DELETE_UNMAP,
4558 (lbp->flags & SVPD_LBP_UNMAP));
4561 error = daerror(done_ccb, CAM_RETRY_SELTO,
4562 SF_RETRY_UA|SF_NO_PRINT);
4563 if (error == ERESTART)
4565 else if (error != 0) {
4566 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4567 /* Don't wedge this device's queue */
4568 cam_release_devq(done_ccb->ccb_h.path,
4572 /*getcount_only*/0);
4576 * Failure indicates we don't support any SBC-3
4577 * delete methods with UNMAP
4582 free(lbp, M_SCSIDA);
4583 xpt_release_ccb(done_ccb);
4584 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4585 xpt_schedule(periph, priority);
4588 case DA_CCB_PROBE_BLK_LIMITS:
4590 struct scsi_vpd_block_limits *block_limits;
4592 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4594 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4595 uint32_t max_txfer_len = scsi_4btoul(
4596 block_limits->max_txfer_len);
4597 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4598 block_limits->max_unmap_lba_cnt);
4599 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4600 block_limits->max_unmap_blk_cnt);
4601 uint32_t unmap_gran = scsi_4btoul(
4602 block_limits->opt_unmap_grain);
4603 uint32_t unmap_gran_align = scsi_4btoul(
4604 block_limits->unmap_grain_align);
4605 uint64_t ws_max_blks = scsi_8btou64(
4606 block_limits->max_write_same_length);
4608 if (max_txfer_len != 0) {
4609 softc->disk->d_maxsize = MIN(softc->maxio,
4610 (off_t)max_txfer_len * softc->params.secsize);
4614 * We should already support UNMAP but we check lba
4615 * and block count to be sure
4617 if (max_unmap_lba_cnt != 0x00L &&
4618 max_unmap_blk_cnt != 0x00L) {
4619 softc->unmap_max_lba = max_unmap_lba_cnt;
4620 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4622 if (unmap_gran > 1) {
4623 softc->unmap_gran = unmap_gran;
4624 if (unmap_gran_align & 0x80000000) {
4625 softc->unmap_gran_align =
4632 * Unexpected UNMAP limits which means the
4633 * device doesn't actually support UNMAP
4635 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4638 if (ws_max_blks != 0x00L)
4639 softc->ws_max_blks = ws_max_blks;
4642 error = daerror(done_ccb, CAM_RETRY_SELTO,
4643 SF_RETRY_UA|SF_NO_PRINT);
4644 if (error == ERESTART)
4646 else if (error != 0) {
4647 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4648 /* Don't wedge this device's queue */
4649 cam_release_devq(done_ccb->ccb_h.path,
4653 /*getcount_only*/0);
4657 * Failure here doesn't mean UNMAP is not
4658 * supported as this is an optional page.
4660 softc->unmap_max_lba = 1;
4661 softc->unmap_max_ranges = 1;
4665 free(block_limits, M_SCSIDA);
4666 xpt_release_ccb(done_ccb);
4667 softc->state = DA_STATE_PROBE_BDC;
4668 xpt_schedule(periph, priority);
4671 case DA_CCB_PROBE_BDC:
4673 struct scsi_vpd_block_device_characteristics *bdc;
4675 bdc = (struct scsi_vpd_block_device_characteristics *)
4678 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4682 * Disable queue sorting for non-rotational media
4685 u_int16_t old_rate = softc->disk->d_rotation_rate;
4687 valid_len = csio->dxfer_len - csio->resid;
4688 if (SBDC_IS_PRESENT(bdc, valid_len,
4689 medium_rotation_rate)) {
4690 softc->disk->d_rotation_rate =
4691 scsi_2btoul(bdc->medium_rotation_rate);
4692 if (softc->disk->d_rotation_rate ==
4693 SVPD_BDC_RATE_NON_ROTATING) {
4694 cam_iosched_set_sort_queue(
4695 softc->cam_iosched, 0);
4696 softc->rotating = 0;
4698 if (softc->disk->d_rotation_rate != old_rate) {
4699 disk_attr_changed(softc->disk,
4700 "GEOM::rotation_rate", M_NOWAIT);
4703 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4704 && (softc->zone_mode == DA_ZONE_NONE)) {
4707 if (scsi_vpd_supported_page(periph,
4708 SVPD_ATA_INFORMATION))
4714 * The Zoned field will only be set for
4715 * Drive Managed and Host Aware drives. If
4716 * they are Host Managed, the device type
4717 * in the standard INQUIRY data should be
4718 * set to T_ZBC_HM (0x14).
4720 if ((bdc->flags & SVPD_ZBC_MASK) ==
4722 softc->zone_mode = DA_ZONE_HOST_AWARE;
4723 softc->zone_interface = (ata_proto) ?
4724 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4725 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4727 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4728 softc->zone_interface = (ata_proto) ?
4729 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4730 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4732 xpt_print(periph->path, "Unknown zoned "
4734 bdc->flags & SVPD_ZBC_MASK);
4739 error = daerror(done_ccb, CAM_RETRY_SELTO,
4740 SF_RETRY_UA|SF_NO_PRINT);
4741 if (error == ERESTART)
4743 else if (error != 0) {
4744 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4745 /* Don't wedge this device's queue */
4746 cam_release_devq(done_ccb->ccb_h.path,
4750 /*getcount_only*/0);
4755 free(bdc, M_SCSIDA);
4756 xpt_release_ccb(done_ccb);
4757 softc->state = DA_STATE_PROBE_ATA;
4758 xpt_schedule(periph, priority);
4761 case DA_CCB_PROBE_ATA:
4764 struct ata_params *ata_params;
4769 ata_params = (struct ata_params *)csio->data_ptr;
4770 ptr = (uint16_t *)ata_params;
4774 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4777 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4778 ptr[i] = le16toh(ptr[i]);
4779 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4780 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4781 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4782 if (ata_params->max_dsm_blocks != 0)
4783 softc->trim_max_ranges = min(
4784 softc->trim_max_ranges,
4785 ata_params->max_dsm_blocks *
4786 ATA_DSM_BLK_RANGES);
4789 * Disable queue sorting for non-rotational media
4792 old_rate = softc->disk->d_rotation_rate;
4793 softc->disk->d_rotation_rate =
4794 ata_params->media_rotation_rate;
4795 if (softc->disk->d_rotation_rate ==
4796 ATA_RATE_NON_ROTATING) {
4797 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4798 softc->rotating = 0;
4800 if (softc->disk->d_rotation_rate != old_rate) {
4801 disk_attr_changed(softc->disk,
4802 "GEOM::rotation_rate", M_NOWAIT);
4805 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4806 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4808 if (ata_params->support.extension &
4810 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4813 * At this point, if we have a SATA host aware drive,
4814 * we communicate via ATA passthrough unless the
4815 * SAT layer supports ZBC -> ZAC translation. In
4819 * XXX KDM figure out how to detect a host managed
4822 if (softc->zone_mode == DA_ZONE_NONE) {
4824 * Note that we don't override the zone
4825 * mode or interface if it has already been
4826 * set. This is because it has either been
4827 * set as a quirk, or when we probed the
4828 * SCSI Block Device Characteristics page,
4829 * the zoned field was set. The latter
4830 * means that the SAT layer supports ZBC to
4831 * ZAC translation, and we would prefer to
4832 * use that if it is available.
4834 if ((ata_params->support3 &
4835 ATA_SUPPORT_ZONE_MASK) ==
4836 ATA_SUPPORT_ZONE_HOST_AWARE) {
4837 softc->zone_mode = DA_ZONE_HOST_AWARE;
4838 softc->zone_interface =
4839 DA_ZONE_IF_ATA_PASS;
4840 } else if ((ata_params->support3 &
4841 ATA_SUPPORT_ZONE_MASK) ==
4842 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4843 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4844 softc->zone_interface =
4845 DA_ZONE_IF_ATA_PASS;
4850 error = daerror(done_ccb, CAM_RETRY_SELTO,
4851 SF_RETRY_UA|SF_NO_PRINT);
4852 if (error == ERESTART)
4854 else if (error != 0) {
4855 if ((done_ccb->ccb_h.status &
4856 CAM_DEV_QFRZN) != 0) {
4857 /* Don't wedge this device's queue */
4858 cam_release_devq(done_ccb->ccb_h.path,
4862 /*getcount_only*/0);
4867 free(ata_params, M_SCSIDA);
4868 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4869 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4871 * If the ATA IDENTIFY failed, we could be talking
4872 * to a SCSI drive, although that seems unlikely,
4873 * since the drive did report that it supported the
4874 * ATA Information VPD page. If the ATA IDENTIFY
4875 * succeeded, and the SAT layer doesn't support
4876 * ZBC -> ZAC translation, continue on to get the
4877 * directory of ATA logs, and complete the rest of
4878 * the ZAC probe. If the SAT layer does support
4879 * ZBC -> ZAC translation, we want to use that,
4880 * and we'll probe the SCSI Zoned Block Device
4881 * Characteristics VPD page next.
4884 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4885 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4886 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4888 softc->state = DA_STATE_PROBE_ZONE;
4891 if (continue_probe != 0) {
4892 xpt_release_ccb(done_ccb);
4893 xpt_schedule(periph, priority);
4896 daprobedone(periph, done_ccb);
4899 case DA_CCB_PROBE_ATA_LOGDIR:
4903 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4905 softc->valid_logdir_len = 0;
4906 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4907 softc->valid_logdir_len =
4908 csio->dxfer_len - csio->resid;
4909 if (softc->valid_logdir_len > 0)
4910 bcopy(csio->data_ptr, &softc->ata_logdir,
4911 min(softc->valid_logdir_len,
4912 sizeof(softc->ata_logdir)));
4914 * Figure out whether the Identify Device log is
4915 * supported. The General Purpose log directory
4916 * has a header, and lists the number of pages
4917 * available for each GP log identified by the
4918 * offset into the list.
4920 if ((softc->valid_logdir_len >=
4921 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4922 && (le16dec(softc->ata_logdir.header) ==
4923 ATA_GP_LOG_DIR_VERSION)
4924 && (le16dec(&softc->ata_logdir.num_pages[
4925 (ATA_IDENTIFY_DATA_LOG *
4926 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4927 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4929 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4932 error = daerror(done_ccb, CAM_RETRY_SELTO,
4933 SF_RETRY_UA|SF_NO_PRINT);
4934 if (error == ERESTART)
4936 else if (error != 0) {
4938 * If we can't get the ATA log directory,
4939 * then ATA logs are effectively not
4940 * supported even if the bit is set in the
4943 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
4944 DA_FLAG_CAN_ATA_IDLOG);
4945 if ((done_ccb->ccb_h.status &
4946 CAM_DEV_QFRZN) != 0) {
4947 /* Don't wedge this device's queue */
4948 cam_release_devq(done_ccb->ccb_h.path,
4952 /*getcount_only*/0);
4957 free(csio->data_ptr, M_SCSIDA);
4960 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
4961 softc->state = DA_STATE_PROBE_ATA_IDDIR;
4962 xpt_release_ccb(done_ccb);
4963 xpt_schedule(periph, priority);
4966 daprobedone(periph, done_ccb);
4969 case DA_CCB_PROBE_ATA_IDDIR:
4973 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4974 off_t entries_offset, max_entries;
4977 softc->valid_iddir_len = 0;
4978 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
4979 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
4980 DA_FLAG_CAN_ATA_ZONE);
4981 softc->valid_iddir_len =
4982 csio->dxfer_len - csio->resid;
4983 if (softc->valid_iddir_len > 0)
4984 bcopy(csio->data_ptr, &softc->ata_iddir,
4985 min(softc->valid_iddir_len,
4986 sizeof(softc->ata_iddir)));
4989 __offsetof(struct ata_identify_log_pages,entries);
4990 max_entries = softc->valid_iddir_len - entries_offset;
4991 if ((softc->valid_iddir_len > (entries_offset + 1))
4992 && (le64dec(softc->ata_iddir.header) ==
4994 && (softc->ata_iddir.entry_count > 0)) {
4997 num_entries = softc->ata_iddir.entry_count;
4998 num_entries = min(num_entries,
4999 softc->valid_iddir_len - entries_offset);
5000 for (i = 0; i < num_entries &&
5001 i < max_entries; i++) {
5002 if (softc->ata_iddir.entries[i] ==
5005 DA_FLAG_CAN_ATA_SUPCAP;
5006 else if (softc->ata_iddir.entries[i]==
5009 DA_FLAG_CAN_ATA_ZONE;
5012 DA_FLAG_CAN_ATA_SUPCAP)
5014 DA_FLAG_CAN_ATA_ZONE))
5019 error = daerror(done_ccb, CAM_RETRY_SELTO,
5020 SF_RETRY_UA|SF_NO_PRINT);
5021 if (error == ERESTART)
5023 else if (error != 0) {
5025 * If we can't get the ATA Identify Data log
5026 * directory, then it effectively isn't
5027 * supported even if the ATA Log directory
5028 * a non-zero number of pages present for
5031 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5032 if ((done_ccb->ccb_h.status &
5033 CAM_DEV_QFRZN) != 0) {
5034 /* Don't wedge this device's queue */
5035 cam_release_devq(done_ccb->ccb_h.path,
5039 /*getcount_only*/0);
5044 free(csio->data_ptr, M_SCSIDA);
5047 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5048 softc->state = DA_STATE_PROBE_ATA_SUP;
5049 xpt_release_ccb(done_ccb);
5050 xpt_schedule(periph, priority);
5053 daprobedone(periph, done_ccb);
5056 case DA_CCB_PROBE_ATA_SUP:
5060 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5063 struct ata_identify_log_sup_cap *sup_cap;
5066 sup_cap = (struct ata_identify_log_sup_cap *)
5068 valid_len = csio->dxfer_len - csio->resid;
5070 __offsetof(struct ata_identify_log_sup_cap,
5071 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5072 if (valid_len >= needed_size) {
5073 uint64_t zoned, zac_cap;
5075 zoned = le64dec(sup_cap->zoned_cap);
5076 if (zoned & ATA_ZONED_VALID) {
5078 * This should have already been
5079 * set, because this is also in the
5080 * ATA identify data.
5082 if ((zoned & ATA_ZONED_MASK) ==
5083 ATA_SUPPORT_ZONE_HOST_AWARE)
5086 else if ((zoned & ATA_ZONED_MASK) ==
5087 ATA_SUPPORT_ZONE_DEV_MANAGED)
5089 DA_ZONE_DRIVE_MANAGED;
5092 zac_cap = le64dec(sup_cap->sup_zac_cap);
5093 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5094 if (zac_cap & ATA_REPORT_ZONES_SUP)
5095 softc->zone_flags |=
5096 DA_ZONE_FLAG_RZ_SUP;
5097 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5098 softc->zone_flags |=
5099 DA_ZONE_FLAG_OPEN_SUP;
5100 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5101 softc->zone_flags |=
5102 DA_ZONE_FLAG_CLOSE_SUP;
5103 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5104 softc->zone_flags |=
5105 DA_ZONE_FLAG_FINISH_SUP;
5106 if (zac_cap & ATA_ND_RWP_SUP)
5107 softc->zone_flags |=
5108 DA_ZONE_FLAG_RWP_SUP;
5111 * This field was introduced in
5112 * ACS-4, r08 on April 28th, 2015.
5113 * If the drive firmware was written
5114 * to an earlier spec, it won't have
5115 * the field. So, assume all
5116 * commands are supported.
5118 softc->zone_flags |=
5119 DA_ZONE_FLAG_SUP_MASK;
5124 error = daerror(done_ccb, CAM_RETRY_SELTO,
5125 SF_RETRY_UA|SF_NO_PRINT);
5126 if (error == ERESTART)
5128 else if (error != 0) {
5130 * If we can't get the ATA Identify Data
5131 * Supported Capabilities page, clear the
5134 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5136 * And clear zone capabilities.
5138 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5139 if ((done_ccb->ccb_h.status &
5140 CAM_DEV_QFRZN) != 0) {
5141 /* Don't wedge this device's queue */
5142 cam_release_devq(done_ccb->ccb_h.path,
5146 /*getcount_only*/0);
5151 free(csio->data_ptr, M_SCSIDA);
5154 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5155 softc->state = DA_STATE_PROBE_ATA_ZONE;
5156 xpt_release_ccb(done_ccb);
5157 xpt_schedule(periph, priority);
5160 daprobedone(periph, done_ccb);
5163 case DA_CCB_PROBE_ATA_ZONE:
5167 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5168 struct ata_zoned_info_log *zi_log;
5172 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5174 valid_len = csio->dxfer_len - csio->resid;
5175 needed_size = __offsetof(struct ata_zoned_info_log,
5176 version_info) + 1 + sizeof(zi_log->version_info);
5177 if (valid_len >= needed_size) {
5180 tmpvar = le64dec(zi_log->zoned_cap);
5181 if (tmpvar & ATA_ZDI_CAP_VALID) {
5182 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5183 softc->zone_flags |=
5184 DA_ZONE_FLAG_URSWRZ;
5186 softc->zone_flags &=
5187 ~DA_ZONE_FLAG_URSWRZ;
5189 tmpvar = le64dec(zi_log->optimal_seq_zones);
5190 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5191 softc->zone_flags |=
5192 DA_ZONE_FLAG_OPT_SEQ_SET;
5193 softc->optimal_seq_zones = (tmpvar &
5194 ATA_ZDI_OPT_SEQ_MASK);
5196 softc->zone_flags &=
5197 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5198 softc->optimal_seq_zones = 0;
5201 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5202 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5203 softc->zone_flags |=
5204 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5205 softc->optimal_nonseq_zones =
5206 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5208 softc->zone_flags &=
5209 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5210 softc->optimal_nonseq_zones = 0;
5213 tmpvar = le64dec(zi_log->max_seq_req_zones);
5214 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5215 softc->zone_flags |=
5216 DA_ZONE_FLAG_MAX_SEQ_SET;
5217 softc->max_seq_zones =
5218 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5220 softc->zone_flags &=
5221 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5222 softc->max_seq_zones = 0;
5226 error = daerror(done_ccb, CAM_RETRY_SELTO,
5227 SF_RETRY_UA|SF_NO_PRINT);
5228 if (error == ERESTART)
5230 else if (error != 0) {
5231 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5232 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5234 if ((done_ccb->ccb_h.status &
5235 CAM_DEV_QFRZN) != 0) {
5236 /* Don't wedge this device's queue */
5237 cam_release_devq(done_ccb->ccb_h.path,
5241 /*getcount_only*/0);
5246 free(csio->data_ptr, M_SCSIDA);
5248 daprobedone(periph, done_ccb);
5251 case DA_CCB_PROBE_ZONE:
5255 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5258 struct scsi_vpd_zoned_bdc *zoned_bdc;
5261 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5263 valid_len = csio->dxfer_len - csio->resid;
5264 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5265 max_seq_req_zones) + 1 +
5266 sizeof(zoned_bdc->max_seq_req_zones);
5267 if ((valid_len >= needed_len)
5268 && (scsi_2btoul(zoned_bdc->page_length) >=
5270 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5271 softc->zone_flags |=
5272 DA_ZONE_FLAG_URSWRZ;
5274 softc->zone_flags &=
5275 ~DA_ZONE_FLAG_URSWRZ;
5276 softc->optimal_seq_zones =
5277 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5278 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5279 softc->optimal_nonseq_zones = scsi_4btoul(
5280 zoned_bdc->optimal_nonseq_zones);
5281 softc->zone_flags |=
5282 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5283 softc->max_seq_zones =
5284 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5285 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5288 * All of the zone commands are mandatory for SCSI
5291 * XXX KDM this is valid as of September 2015.
5292 * Re-check this assumption once the SAT spec is
5293 * updated to support SCSI ZBC to ATA ZAC mapping.
5294 * Since ATA allows zone commands to be reported
5295 * as supported or not, this may not necessarily
5296 * be true for an ATA device behind a SAT (SCSI to
5297 * ATA Translation) layer.
5299 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5301 error = daerror(done_ccb, CAM_RETRY_SELTO,
5302 SF_RETRY_UA|SF_NO_PRINT);
5303 if (error == ERESTART)
5305 else if (error != 0) {
5306 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5307 /* Don't wedge this device's queue */
5308 cam_release_devq(done_ccb->ccb_h.path,
5312 /*getcount_only*/0);
5316 daprobedone(periph, done_ccb);
5320 /* No-op. We're polling */
5324 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5326 if (daerror(done_ccb, CAM_RETRY_SELTO,
5327 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5330 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5331 cam_release_devq(done_ccb->ccb_h.path,
5335 /*getcount_only*/0);
5337 xpt_release_ccb(done_ccb);
5338 cam_periph_release_locked(periph);
5344 xpt_release_ccb(done_ccb);
5348 dareprobe(struct cam_periph *periph)
5350 struct da_softc *softc;
5353 softc = (struct da_softc *)periph->softc;
5355 /* Probe in progress; don't interfere. */
5356 if (softc->state != DA_STATE_NORMAL)
5359 status = cam_periph_acquire(periph);
5360 KASSERT(status == CAM_REQ_CMP,
5361 ("dareprobe: cam_periph_acquire failed"));
5363 if (softc->flags & DA_FLAG_CAN_RC16)
5364 softc->state = DA_STATE_PROBE_RC16;
5366 softc->state = DA_STATE_PROBE_RC;
5368 xpt_schedule(periph, CAM_PRIORITY_DEV);
5372 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5374 struct da_softc *softc;
5375 struct cam_periph *periph;
5376 int error, error_code, sense_key, asc, ascq;
5378 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5379 if (ccb->csio.bio != NULL)
5380 biotrack(ccb->csio.bio, __func__);
5383 periph = xpt_path_periph(ccb->ccb_h.path);
5384 softc = (struct da_softc *)periph->softc;
5387 * Automatically detect devices that do not support
5388 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5391 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5392 error = cmd6workaround(ccb);
5393 } else if (scsi_extract_sense_ccb(ccb,
5394 &error_code, &sense_key, &asc, &ascq)) {
5395 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5396 error = cmd6workaround(ccb);
5398 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5399 * query the capacity and notify upper layers.
5401 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5402 asc == 0x2A && ascq == 0x09) {
5403 xpt_print(periph->path, "Capacity data has changed\n");
5404 softc->flags &= ~DA_FLAG_PROBED;
5406 sense_flags |= SF_NO_PRINT;
5407 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5408 asc == 0x28 && ascq == 0x00) {
5409 softc->flags &= ~DA_FLAG_PROBED;
5410 disk_media_changed(softc->disk, M_NOWAIT);
5411 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5412 asc == 0x3F && ascq == 0x03) {
5413 xpt_print(periph->path, "INQUIRY data has changed\n");
5414 softc->flags &= ~DA_FLAG_PROBED;
5416 sense_flags |= SF_NO_PRINT;
5417 } else if (sense_key == SSD_KEY_NOT_READY &&
5418 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5419 softc->flags |= DA_FLAG_PACK_INVALID;
5420 disk_media_gone(softc->disk, M_NOWAIT);
5423 if (error == ERESTART)
5427 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5428 case CAM_CMD_TIMEOUT:
5431 case CAM_REQ_ABORTED:
5432 case CAM_REQ_CMP_ERR:
5433 case CAM_REQ_TERMIO:
5434 case CAM_UNREC_HBA_ERROR:
5435 case CAM_DATA_RUN_ERR:
5445 * Until we have a better way of doing pack validation,
5446 * don't treat UAs as errors.
5448 sense_flags |= SF_RETRY_UA;
5450 if (softc->quirks & DA_Q_RETRY_BUSY)
5451 sense_flags |= SF_RETRY_BUSY;
5452 return(cam_periph_error(ccb, cam_flags, sense_flags,
5453 &softc->saved_ccb));
5457 damediapoll(void *arg)
5459 struct cam_periph *periph = arg;
5460 struct da_softc *softc = periph->softc;
5462 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5463 LIST_EMPTY(&softc->pending_ccbs)) {
5464 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5465 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5469 /* Queue us up again */
5470 if (da_poll_period != 0)
5471 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5475 daprevent(struct cam_periph *periph, int action)
5477 struct da_softc *softc;
5481 softc = (struct da_softc *)periph->softc;
5483 if (((action == PR_ALLOW)
5484 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5485 || ((action == PR_PREVENT)
5486 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5490 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5492 scsi_prevent(&ccb->csio,
5500 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5501 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5504 if (action == PR_ALLOW)
5505 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5507 softc->flags |= DA_FLAG_PACK_LOCKED;
5510 xpt_release_ccb(ccb);
5514 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5515 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5517 struct ccb_calc_geometry ccg;
5518 struct da_softc *softc;
5519 struct disk_params *dp;
5520 u_int lbppbe, lalba;
5523 softc = (struct da_softc *)periph->softc;
5525 dp = &softc->params;
5526 dp->secsize = block_len;
5527 dp->sectors = maxsector + 1;
5528 if (rcaplong != NULL) {
5529 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5530 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5531 lalba &= SRC16_LALBA_A;
5538 dp->stripesize = block_len << lbppbe;
5539 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5541 } else if (softc->quirks & DA_Q_4K) {
5542 dp->stripesize = 4096;
5543 dp->stripeoffset = 0;
5544 } else if (softc->unmap_gran != 0) {
5545 dp->stripesize = block_len * softc->unmap_gran;
5546 dp->stripeoffset = (dp->stripesize - block_len *
5547 softc->unmap_gran_align) % dp->stripesize;
5550 dp->stripeoffset = 0;
5553 * Have the controller provide us with a geometry
5554 * for this disk. The only time the geometry
5555 * matters is when we boot and the controller
5556 * is the only one knowledgeable enough to come
5557 * up with something that will make this a bootable
5560 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5561 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5562 ccg.block_size = dp->secsize;
5563 ccg.volume_size = dp->sectors;
5565 ccg.secs_per_track = 0;
5567 xpt_action((union ccb*)&ccg);
5568 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5570 * We don't know what went wrong here- but just pick
5571 * a geometry so we don't have nasty things like divide
5575 dp->secs_per_track = 255;
5576 dp->cylinders = dp->sectors / (255 * 255);
5577 if (dp->cylinders == 0) {
5581 dp->heads = ccg.heads;
5582 dp->secs_per_track = ccg.secs_per_track;
5583 dp->cylinders = ccg.cylinders;
5587 * If the user supplied a read capacity buffer, and if it is
5588 * different than the previous buffer, update the data in the EDT.
5589 * If it's the same, we don't bother. This avoids sending an
5590 * update every time someone opens this device.
5592 if ((rcaplong != NULL)
5593 && (bcmp(rcaplong, &softc->rcaplong,
5594 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5595 struct ccb_dev_advinfo cdai;
5597 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5598 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5599 cdai.buftype = CDAI_TYPE_RCAPLONG;
5600 cdai.flags = CDAI_FLAG_STORE;
5601 cdai.bufsiz = rcap_len;
5602 cdai.buf = (uint8_t *)rcaplong;
5603 xpt_action((union ccb *)&cdai);
5604 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5605 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5606 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5607 xpt_print(periph->path, "%s: failed to set read "
5608 "capacity advinfo\n", __func__);
5609 /* Use cam_error_print() to decode the status */
5610 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5613 bcopy(rcaplong, &softc->rcaplong,
5614 min(sizeof(softc->rcaplong), rcap_len));
5618 softc->disk->d_sectorsize = softc->params.secsize;
5619 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5620 softc->disk->d_stripesize = softc->params.stripesize;
5621 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5622 /* XXX: these are not actually "firmware" values, so they may be wrong */
5623 softc->disk->d_fwsectors = softc->params.secs_per_track;
5624 softc->disk->d_fwheads = softc->params.heads;
5625 softc->disk->d_devstat->block_size = softc->params.secsize;
5626 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5628 error = disk_resize(softc->disk, M_NOWAIT);
5630 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5634 dasendorderedtag(void *arg)
5636 struct da_softc *softc = arg;
5638 if (da_send_ordered) {
5639 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5640 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5641 softc->flags |= DA_FLAG_NEED_OTAG;
5642 softc->flags &= ~DA_FLAG_WAS_OTAG;
5645 /* Queue us up again */
5646 callout_reset(&softc->sendordered_c,
5647 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5648 dasendorderedtag, softc);
5652 * Step through all DA peripheral drivers, and if the device is still open,
5653 * sync the disk cache to physical media.
5656 dashutdown(void * arg, int howto)
5658 struct cam_periph *periph;
5659 struct da_softc *softc;
5663 CAM_PERIPH_FOREACH(periph, &dadriver) {
5664 softc = (struct da_softc *)periph->softc;
5665 if (SCHEDULER_STOPPED()) {
5666 /* If we paniced with the lock held, do not recurse. */
5667 if (!cam_periph_owned(periph) &&
5668 (softc->flags & DA_FLAG_OPEN)) {
5669 dadump(softc->disk, NULL, 0, 0, 0);
5673 cam_periph_lock(periph);
5676 * We only sync the cache if the drive is still open, and
5677 * if the drive is capable of it..
5679 if (((softc->flags & DA_FLAG_OPEN) == 0)
5680 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5681 cam_periph_unlock(periph);
5685 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5686 scsi_synchronize_cache(&ccb->csio,
5690 /*begin_lba*/0, /* whole disk */
5695 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5696 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5697 softc->disk->d_devstat);
5699 xpt_print(periph->path, "Synchronize cache failed\n");
5700 xpt_release_ccb(ccb);
5701 cam_periph_unlock(periph);
5705 #else /* !_KERNEL */
5708 * XXX These are only left out of the kernel build to silence warnings. If,
5709 * for some reason these functions are used in the kernel, the ifdefs should
5710 * be moved so they are included both in the kernel and userland.
5713 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5714 void (*cbfcnp)(struct cam_periph *, union ccb *),
5715 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5716 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5719 struct scsi_format_unit *scsi_cmd;
5721 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5722 scsi_cmd->opcode = FORMAT_UNIT;
5723 scsi_cmd->byte2 = byte2;
5724 scsi_ulto2b(ileave, scsi_cmd->interleave);
5729 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5739 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5740 void (*cbfcnp)(struct cam_periph *, union ccb *),
5741 uint8_t tag_action, uint8_t list_format,
5742 uint32_t addr_desc_index, uint8_t *data_ptr,
5743 uint32_t dxfer_len, int minimum_cmd_size,
5744 uint8_t sense_len, uint32_t timeout)
5749 * These conditions allow using the 10 byte command. Otherwise we
5750 * need to use the 12 byte command.
5752 if ((minimum_cmd_size <= 10)
5753 && (addr_desc_index == 0)
5754 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5755 struct scsi_read_defect_data_10 *cdb10;
5757 cdb10 = (struct scsi_read_defect_data_10 *)
5758 &csio->cdb_io.cdb_bytes;
5760 cdb_len = sizeof(*cdb10);
5761 bzero(cdb10, cdb_len);
5762 cdb10->opcode = READ_DEFECT_DATA_10;
5763 cdb10->format = list_format;
5764 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5766 struct scsi_read_defect_data_12 *cdb12;
5768 cdb12 = (struct scsi_read_defect_data_12 *)
5769 &csio->cdb_io.cdb_bytes;
5771 cdb_len = sizeof(*cdb12);
5772 bzero(cdb12, cdb_len);
5773 cdb12->opcode = READ_DEFECT_DATA_12;
5774 cdb12->format = list_format;
5775 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5776 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5782 /*flags*/ CAM_DIR_IN,
5792 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5793 void (*cbfcnp)(struct cam_periph *, union ccb *),
5794 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5795 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5798 struct scsi_sanitize *scsi_cmd;
5800 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5801 scsi_cmd->opcode = SANITIZE;
5802 scsi_cmd->byte2 = byte2;
5803 scsi_cmd->control = control;
5804 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5809 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5818 #endif /* _KERNEL */
5821 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5822 void (*cbfcnp)(struct cam_periph *, union ccb *),
5823 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5824 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5825 uint8_t sense_len, uint32_t timeout)
5827 struct scsi_zbc_out *scsi_cmd;
5829 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5830 scsi_cmd->opcode = ZBC_OUT;
5831 scsi_cmd->service_action = service_action;
5832 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5833 scsi_cmd->zone_flags = zone_flags;
5838 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5848 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5849 void (*cbfcnp)(struct cam_periph *, union ccb *),
5850 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5851 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5852 uint8_t sense_len, uint32_t timeout)
5854 struct scsi_zbc_in *scsi_cmd;
5856 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5857 scsi_cmd->opcode = ZBC_IN;
5858 scsi_cmd->service_action = service_action;
5859 scsi_ulto4b(dxfer_len, scsi_cmd->length);
5860 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5861 scsi_cmd->zone_options = zone_options;
5866 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5877 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5878 void (*cbfcnp)(struct cam_periph *, union ccb *),
5879 uint8_t tag_action, int use_ncq,
5880 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5881 uint8_t *data_ptr, uint32_t dxfer_len,
5882 uint8_t *cdb_storage, size_t cdb_storage_len,
5883 uint8_t sense_len, uint32_t timeout)
5885 uint8_t command_out, protocol, ata_flags;
5886 uint16_t features_out;
5887 uint32_t sectors_out, auxiliary;
5893 command_out = ATA_ZAC_MANAGEMENT_OUT;
5894 features_out = (zm_action & 0xf) | (zone_flags << 8);
5895 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5896 if (dxfer_len == 0) {
5897 protocol = AP_PROTO_NON_DATA;
5898 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5901 protocol = AP_PROTO_DMA;
5902 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5903 AP_FLAG_TDIR_TO_DEV;
5904 sectors_out = ((dxfer_len >> 9) & 0xffff);
5908 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5909 if (dxfer_len == 0) {
5910 command_out = ATA_NCQ_NON_DATA;
5911 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5913 * We're assuming the SCSI to ATA translation layer
5914 * will set the NCQ tag number in the tag field.
5915 * That isn't clear from the SAT-4 spec (as of rev 05).
5918 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5920 command_out = ATA_SEND_FPDMA_QUEUED;
5922 * Note that we're defaulting to normal priority,
5923 * and assuming that the SCSI to ATA translation
5924 * layer will insert the NCQ tag number in the tag
5925 * field. That isn't clear in the SAT-4 spec (as
5928 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5930 ata_flags |= AP_FLAG_TLEN_FEAT |
5931 AP_FLAG_TDIR_TO_DEV;
5934 * For SEND FPDMA QUEUED, the transfer length is
5935 * encoded in the FEATURE register, and 0 means
5936 * that 65536 512 byte blocks are to be tranferred.
5937 * In practice, it seems unlikely that we'll see
5938 * a transfer that large, and it may confuse the
5939 * the SAT layer, because generally that means that
5940 * 0 bytes should be transferred.
5942 if (dxfer_len == (65536 * 512)) {
5944 } else if (dxfer_len <= (65535 * 512)) {
5945 features_out = ((dxfer_len >> 9) & 0xffff);
5947 /* The transfer is too big. */
5954 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
5955 protocol = AP_PROTO_FPDMA;
5958 protocol |= AP_EXTEND;
5960 retval = scsi_ata_pass(csio,
5963 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5965 /*protocol*/ protocol,
5966 /*ata_flags*/ ata_flags,
5967 /*features*/ features_out,
5968 /*sector_count*/ sectors_out,
5970 /*command*/ command_out,
5973 /*auxiliary*/ auxiliary,
5975 /*data_ptr*/ data_ptr,
5976 /*dxfer_len*/ dxfer_len,
5977 /*cdb_storage*/ cdb_storage,
5978 /*cdb_storage_len*/ cdb_storage_len,
5979 /*minimum_cmd_size*/ 0,
5980 /*sense_len*/ SSD_FULL_SIZE,
5981 /*timeout*/ timeout);
5989 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
5990 void (*cbfcnp)(struct cam_periph *, union ccb *),
5991 uint8_t tag_action, int use_ncq,
5992 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5993 uint8_t *data_ptr, uint32_t dxfer_len,
5994 uint8_t *cdb_storage, size_t cdb_storage_len,
5995 uint8_t sense_len, uint32_t timeout)
5997 uint8_t command_out, protocol;
5998 uint16_t features_out, sectors_out;
6004 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
6007 command_out = ATA_ZAC_MANAGEMENT_IN;
6008 /* XXX KDM put a macro here */
6009 features_out = (zm_action & 0xf) | (zone_flags << 8);
6010 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
6011 protocol = AP_PROTO_DMA;
6012 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
6015 ata_flags |= AP_FLAG_TLEN_FEAT;
6017 command_out = ATA_RECV_FPDMA_QUEUED;
6018 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6021 * For RECEIVE FPDMA QUEUED, the transfer length is
6022 * encoded in the FEATURE register, and 0 means
6023 * that 65536 512 byte blocks are to be tranferred.
6024 * In practice, it seems unlikely that we'll see
6025 * a transfer that large, and it may confuse the
6026 * the SAT layer, because generally that means that
6027 * 0 bytes should be transferred.
6029 if (dxfer_len == (65536 * 512)) {
6031 } else if (dxfer_len <= (65535 * 512)) {
6032 features_out = ((dxfer_len >> 9) & 0xffff);
6034 /* The transfer is too big. */
6038 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6039 protocol = AP_PROTO_FPDMA;
6042 protocol |= AP_EXTEND;
6044 retval = scsi_ata_pass(csio,
6047 /*flags*/ CAM_DIR_IN,
6049 /*protocol*/ protocol,
6050 /*ata_flags*/ ata_flags,
6051 /*features*/ features_out,
6052 /*sector_count*/ sectors_out,
6054 /*command*/ command_out,
6057 /*auxiliary*/ auxiliary,
6059 /*data_ptr*/ data_ptr,
6060 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6061 /*cdb_storage*/ cdb_storage,
6062 /*cdb_storage_len*/ cdb_storage_len,
6063 /*minimum_cmd_size*/ 0,
6064 /*sense_len*/ SSD_FULL_SIZE,
6065 /*timeout*/ timeout);