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", "ST8000AS0002*", "*" },
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 * BIO_FLUSH doesn't currently communicate
3042 * range data, so we synchronize the cache
3043 * over the whole disk. We also force
3044 * ordered tag semantics the flush applies
3045 * to all previously queued I/O.
3047 scsi_synchronize_cache(&start_ccb->csio,
3054 da_default_timeout*1000);
3057 int error, queue_ccb;
3061 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3063 || (queue_ccb == 0)) {
3064 biofinish(bp, NULL, error);
3065 xpt_release_ccb(start_ccb);
3071 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3072 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3073 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3076 LIST_INSERT_HEAD(&softc->pending_ccbs,
3077 &start_ccb->ccb_h, periph_links.le);
3079 /* We expect a unit attention from this device */
3080 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3081 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3082 softc->flags &= ~DA_FLAG_RETRY_UA;
3085 start_ccb->ccb_h.ccb_bp = bp;
3087 cam_periph_unlock(periph);
3088 xpt_action(start_ccb);
3089 cam_periph_lock(periph);
3092 /* May have more work to do, so ensure we stay scheduled */
3096 case DA_STATE_PROBE_RC:
3098 struct scsi_read_capacity_data *rcap;
3100 rcap = (struct scsi_read_capacity_data *)
3101 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3103 printf("dastart: Couldn't malloc read_capacity data\n");
3104 /* da_free_periph??? */
3107 scsi_read_capacity(&start_ccb->csio,
3108 /*retries*/da_retry_count,
3114 start_ccb->ccb_h.ccb_bp = NULL;
3115 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3116 xpt_action(start_ccb);
3119 case DA_STATE_PROBE_RC16:
3121 struct scsi_read_capacity_data_long *rcaplong;
3123 rcaplong = (struct scsi_read_capacity_data_long *)
3124 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3125 if (rcaplong == NULL) {
3126 printf("dastart: Couldn't malloc read_capacity data\n");
3127 /* da_free_periph??? */
3130 scsi_read_capacity_16(&start_ccb->csio,
3131 /*retries*/ da_retry_count,
3133 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3137 /*rcap_buf*/ (uint8_t *)rcaplong,
3138 /*rcap_buf_len*/ sizeof(*rcaplong),
3139 /*sense_len*/ SSD_FULL_SIZE,
3140 /*timeout*/ da_default_timeout * 1000);
3141 start_ccb->ccb_h.ccb_bp = NULL;
3142 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3143 xpt_action(start_ccb);
3146 case DA_STATE_PROBE_LBP:
3148 struct scsi_vpd_logical_block_prov *lbp;
3150 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3152 * If we get here we don't support any SBC-3 delete
3153 * methods with UNMAP as the Logical Block Provisioning
3154 * VPD page support is required for devices which
3155 * support it according to T10/1799-D Revision 31
3156 * however older revisions of the spec don't mandate
3157 * this so we currently don't remove these methods
3158 * from the available set.
3160 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3164 lbp = (struct scsi_vpd_logical_block_prov *)
3165 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3168 printf("dastart: Couldn't malloc lbp data\n");
3169 /* da_free_periph??? */
3173 scsi_inquiry(&start_ccb->csio,
3174 /*retries*/da_retry_count,
3176 /*tag_action*/MSG_SIMPLE_Q_TAG,
3177 /*inq_buf*/(u_int8_t *)lbp,
3178 /*inq_len*/sizeof(*lbp),
3180 /*page_code*/SVPD_LBP,
3181 /*sense_len*/SSD_MIN_SIZE,
3182 /*timeout*/da_default_timeout * 1000);
3183 start_ccb->ccb_h.ccb_bp = NULL;
3184 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3185 xpt_action(start_ccb);
3188 case DA_STATE_PROBE_BLK_LIMITS:
3190 struct scsi_vpd_block_limits *block_limits;
3192 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3193 /* Not supported skip to next probe */
3194 softc->state = DA_STATE_PROBE_BDC;
3198 block_limits = (struct scsi_vpd_block_limits *)
3199 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3201 if (block_limits == NULL) {
3202 printf("dastart: Couldn't malloc block_limits data\n");
3203 /* da_free_periph??? */
3207 scsi_inquiry(&start_ccb->csio,
3208 /*retries*/da_retry_count,
3210 /*tag_action*/MSG_SIMPLE_Q_TAG,
3211 /*inq_buf*/(u_int8_t *)block_limits,
3212 /*inq_len*/sizeof(*block_limits),
3214 /*page_code*/SVPD_BLOCK_LIMITS,
3215 /*sense_len*/SSD_MIN_SIZE,
3216 /*timeout*/da_default_timeout * 1000);
3217 start_ccb->ccb_h.ccb_bp = NULL;
3218 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3219 xpt_action(start_ccb);
3222 case DA_STATE_PROBE_BDC:
3224 struct scsi_vpd_block_characteristics *bdc;
3226 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3227 softc->state = DA_STATE_PROBE_ATA;
3231 bdc = (struct scsi_vpd_block_characteristics *)
3232 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3235 printf("dastart: Couldn't malloc bdc data\n");
3236 /* da_free_periph??? */
3240 scsi_inquiry(&start_ccb->csio,
3241 /*retries*/da_retry_count,
3243 /*tag_action*/MSG_SIMPLE_Q_TAG,
3244 /*inq_buf*/(u_int8_t *)bdc,
3245 /*inq_len*/sizeof(*bdc),
3247 /*page_code*/SVPD_BDC,
3248 /*sense_len*/SSD_MIN_SIZE,
3249 /*timeout*/da_default_timeout * 1000);
3250 start_ccb->ccb_h.ccb_bp = NULL;
3251 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3252 xpt_action(start_ccb);
3255 case DA_STATE_PROBE_ATA:
3257 struct ata_params *ata_params;
3259 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3260 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3261 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3263 * Note that if the ATA VPD page isn't
3264 * supported, we aren't talking to an ATA
3265 * device anyway. Support for that VPD
3266 * page is mandatory for SCSI to ATA (SAT)
3267 * translation layers.
3269 softc->state = DA_STATE_PROBE_ZONE;
3272 daprobedone(periph, start_ccb);
3276 ata_params = (struct ata_params*)
3277 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3279 if (ata_params == NULL) {
3280 xpt_print(periph->path, "Couldn't malloc ata_params "
3282 /* da_free_periph??? */
3286 scsi_ata_identify(&start_ccb->csio,
3287 /*retries*/da_retry_count,
3289 /*tag_action*/MSG_SIMPLE_Q_TAG,
3290 /*data_ptr*/(u_int8_t *)ata_params,
3291 /*dxfer_len*/sizeof(*ata_params),
3292 /*sense_len*/SSD_FULL_SIZE,
3293 /*timeout*/da_default_timeout * 1000);
3294 start_ccb->ccb_h.ccb_bp = NULL;
3295 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3296 xpt_action(start_ccb);
3299 case DA_STATE_PROBE_ATA_LOGDIR:
3301 struct ata_gp_log_dir *log_dir;
3306 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3308 * If we don't have log support, not much point in
3309 * trying to probe zone support.
3311 daprobedone(periph, start_ccb);
3316 * If we have an ATA device (the SCSI ATA Information VPD
3317 * page should be present and the ATA identify should have
3318 * succeeded) and it supports logs, ask for the log directory.
3321 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3322 if (log_dir == NULL) {
3323 xpt_print(periph->path, "Couldn't malloc log_dir "
3325 daprobedone(periph, start_ccb);
3329 retval = scsi_ata_read_log(&start_ccb->csio,
3330 /*retries*/ da_retry_count,
3332 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3333 /*log_address*/ ATA_LOG_DIRECTORY,
3336 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3337 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3338 /*data_ptr*/ (uint8_t *)log_dir,
3339 /*dxfer_len*/ sizeof(*log_dir),
3340 /*sense_len*/ SSD_FULL_SIZE,
3341 /*timeout*/ da_default_timeout * 1000);
3344 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3345 free(log_dir, M_SCSIDA);
3346 daprobedone(periph, start_ccb);
3349 start_ccb->ccb_h.ccb_bp = NULL;
3350 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3351 xpt_action(start_ccb);
3354 case DA_STATE_PROBE_ATA_IDDIR:
3356 struct ata_identify_log_pages *id_dir;
3362 * Check here to see whether the Identify Device log is
3363 * supported in the directory of logs. If so, continue
3364 * with requesting the log of identify device pages.
3366 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3367 daprobedone(periph, start_ccb);
3371 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3372 if (id_dir == NULL) {
3373 xpt_print(periph->path, "Couldn't malloc id_dir "
3375 daprobedone(periph, start_ccb);
3379 retval = scsi_ata_read_log(&start_ccb->csio,
3380 /*retries*/ da_retry_count,
3382 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3383 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3384 /*page_number*/ ATA_IDL_PAGE_LIST,
3386 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3387 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3388 /*data_ptr*/ (uint8_t *)id_dir,
3389 /*dxfer_len*/ sizeof(*id_dir),
3390 /*sense_len*/ SSD_FULL_SIZE,
3391 /*timeout*/ da_default_timeout * 1000);
3394 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3395 free(id_dir, M_SCSIDA);
3396 daprobedone(periph, start_ccb);
3399 start_ccb->ccb_h.ccb_bp = NULL;
3400 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3401 xpt_action(start_ccb);
3404 case DA_STATE_PROBE_ATA_SUP:
3406 struct ata_identify_log_sup_cap *sup_cap;
3412 * Check here to see whether the Supported Capabilities log
3413 * is in the list of Identify Device logs.
3415 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3416 daprobedone(periph, start_ccb);
3420 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3421 if (sup_cap == NULL) {
3422 xpt_print(periph->path, "Couldn't malloc sup_cap "
3424 daprobedone(periph, start_ccb);
3428 retval = scsi_ata_read_log(&start_ccb->csio,
3429 /*retries*/ da_retry_count,
3431 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3432 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3433 /*page_number*/ ATA_IDL_SUP_CAP,
3435 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3436 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3437 /*data_ptr*/ (uint8_t *)sup_cap,
3438 /*dxfer_len*/ sizeof(*sup_cap),
3439 /*sense_len*/ SSD_FULL_SIZE,
3440 /*timeout*/ da_default_timeout * 1000);
3443 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3444 free(sup_cap, M_SCSIDA);
3445 daprobedone(periph, start_ccb);
3450 start_ccb->ccb_h.ccb_bp = NULL;
3451 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3452 xpt_action(start_ccb);
3455 case DA_STATE_PROBE_ATA_ZONE:
3457 struct ata_zoned_info_log *ata_zone;
3463 * Check here to see whether the zoned device information
3464 * page is supported. If so, continue on to request it.
3465 * If not, skip to DA_STATE_PROBE_LOG or done.
3467 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3468 daprobedone(periph, start_ccb);
3471 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3473 if (ata_zone == NULL) {
3474 xpt_print(periph->path, "Couldn't malloc ata_zone "
3476 daprobedone(periph, start_ccb);
3480 retval = scsi_ata_read_log(&start_ccb->csio,
3481 /*retries*/ da_retry_count,
3483 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3484 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3485 /*page_number*/ ATA_IDL_ZDI,
3487 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3488 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3489 /*data_ptr*/ (uint8_t *)ata_zone,
3490 /*dxfer_len*/ sizeof(*ata_zone),
3491 /*sense_len*/ SSD_FULL_SIZE,
3492 /*timeout*/ da_default_timeout * 1000);
3495 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3496 free(ata_zone, M_SCSIDA);
3497 daprobedone(periph, start_ccb);
3500 start_ccb->ccb_h.ccb_bp = NULL;
3501 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3502 xpt_action(start_ccb);
3506 case DA_STATE_PROBE_ZONE:
3508 struct scsi_vpd_zoned_bdc *bdc;
3511 * Note that this page will be supported for SCSI protocol
3512 * devices that support ZBC (SMR devices), as well as ATA
3513 * protocol devices that are behind a SAT (SCSI to ATA
3514 * Translation) layer that supports converting ZBC commands
3515 * to their ZAC equivalents.
3517 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3518 daprobedone(periph, start_ccb);
3521 bdc = (struct scsi_vpd_zoned_bdc *)
3522 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3525 xpt_release_ccb(start_ccb);
3526 xpt_print(periph->path, "Couldn't malloc zone VPD "
3530 scsi_inquiry(&start_ccb->csio,
3531 /*retries*/da_retry_count,
3533 /*tag_action*/MSG_SIMPLE_Q_TAG,
3534 /*inq_buf*/(u_int8_t *)bdc,
3535 /*inq_len*/sizeof(*bdc),
3537 /*page_code*/SVPD_ZONED_BDC,
3538 /*sense_len*/SSD_FULL_SIZE,
3539 /*timeout*/da_default_timeout * 1000);
3540 start_ccb->ccb_h.ccb_bp = NULL;
3541 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3542 xpt_action(start_ccb);
3549 * In each of the methods below, while its the caller's
3550 * responsibility to ensure the request will fit into a
3551 * single device request, we might have changed the delete
3552 * method due to the device incorrectly advertising either
3553 * its supported methods or limits.
3555 * To prevent this causing further issues we validate the
3556 * against the methods limits, and warn which would
3557 * otherwise be unnecessary.
3560 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3562 struct da_softc *softc = (struct da_softc *)periph->softc;;
3564 uint8_t *buf = softc->unmap_buf;
3565 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3566 uint64_t lba, lastlba = (uint64_t)-1;
3567 uint64_t totalcount = 0;
3569 uint32_t c, lastcount = 0, ranges = 0;
3572 * Currently this doesn't take the UNMAP
3573 * Granularity and Granularity Alignment
3574 * fields into account.
3576 * This could result in both unoptimal unmap
3577 * requests as as well as UNMAP calls unmapping
3578 * fewer LBA's than requested.
3581 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3585 * Note: ada and da are different in how they store the
3586 * pending bp's in a trim. ada stores all of them in the
3587 * trim_req.bps. da stores all but the first one in the
3588 * delete_run_queue. ada then completes all the bps in
3589 * its adadone() loop. da completes all the bps in the
3590 * delete_run_queue in dadone, and relies on the biodone
3591 * after to complete. This should be reconciled since there's
3592 * no real reason to do it differently. XXX
3595 bioq_insert_tail(&softc->delete_run_queue, bp1);
3596 lba = bp1->bio_pblkno;
3597 count = bp1->bio_bcount / softc->params.secsize;
3599 /* Try to extend the previous range. */
3600 if (lba == lastlba) {
3601 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3604 scsi_ulto4b(lastcount, d[ranges - 1].length);
3608 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3609 softc->unmap_gran != 0) {
3610 /* Align length of the previous range. */
3611 if ((c = lastcount % softc->unmap_gran) != 0) {
3612 if (lastcount <= c) {
3613 totalcount -= lastcount;
3614 lastlba = (uint64_t)-1;
3621 scsi_ulto4b(lastcount, d[ranges - 1].length);
3624 /* Align beginning of the new range. */
3625 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3627 c = softc->unmap_gran - c;
3638 c = omin(count, UNMAP_RANGE_MAX);
3639 if (totalcount + c > softc->unmap_max_lba ||
3640 ranges >= softc->unmap_max_ranges) {
3641 xpt_print(periph->path,
3642 "%s issuing short delete %ld > %ld"
3644 da_delete_method_desc[softc->delete_method],
3645 totalcount + c, softc->unmap_max_lba,
3646 ranges, softc->unmap_max_ranges);
3649 scsi_u64to8b(lba, d[ranges].lba);
3650 scsi_ulto4b(c, d[ranges].length);
3658 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3661 if (ranges >= softc->unmap_max_ranges ||
3662 totalcount + bp1->bio_bcount /
3663 softc->params.secsize > softc->unmap_max_lba) {
3664 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3669 /* Align length of the last range. */
3670 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
3671 (c = lastcount % softc->unmap_gran) != 0) {
3675 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
3678 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3679 scsi_ulto2b(ranges * 16, &buf[2]);
3681 scsi_unmap(&ccb->csio,
3682 /*retries*/da_retry_count,
3684 /*tag_action*/MSG_SIMPLE_Q_TAG,
3687 /*dxfer_len*/ ranges * 16 + 8,
3688 /*sense_len*/SSD_FULL_SIZE,
3689 da_default_timeout * 1000);
3690 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3691 ccb->ccb_h.flags |= CAM_UNLOCKED;
3692 cam_iosched_submit_trim(softc->cam_iosched);
3696 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3698 struct da_softc *softc = (struct da_softc *)periph->softc;
3700 uint8_t *buf = softc->unmap_buf;
3701 uint64_t lastlba = (uint64_t)-1;
3704 uint32_t lastcount = 0, c, requestcount;
3705 int ranges = 0, off, block_count;
3707 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3710 if (bp1 != bp)//XXX imp XXX
3711 bioq_insert_tail(&softc->delete_run_queue, bp1);
3712 lba = bp1->bio_pblkno;
3713 count = bp1->bio_bcount / softc->params.secsize;
3714 requestcount = count;
3716 /* Try to extend the previous range. */
3717 if (lba == lastlba) {
3718 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3720 off = (ranges - 1) * 8;
3721 buf[off + 6] = lastcount & 0xff;
3722 buf[off + 7] = (lastcount >> 8) & 0xff;
3728 c = omin(count, ATA_DSM_RANGE_MAX);
3731 buf[off + 0] = lba & 0xff;
3732 buf[off + 1] = (lba >> 8) & 0xff;
3733 buf[off + 2] = (lba >> 16) & 0xff;
3734 buf[off + 3] = (lba >> 24) & 0xff;
3735 buf[off + 4] = (lba >> 32) & 0xff;
3736 buf[off + 5] = (lba >> 40) & 0xff;
3737 buf[off + 6] = c & 0xff;
3738 buf[off + 7] = (c >> 8) & 0xff;
3743 if (count != 0 && ranges == softc->trim_max_ranges) {
3744 xpt_print(periph->path,
3745 "%s issuing short delete %ld > %ld\n",
3746 da_delete_method_desc[softc->delete_method],
3748 (softc->trim_max_ranges - ranges) *
3754 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3757 if (bp1->bio_bcount / softc->params.secsize >
3758 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3759 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3764 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3765 scsi_ata_trim(&ccb->csio,
3766 /*retries*/da_retry_count,
3768 /*tag_action*/MSG_SIMPLE_Q_TAG,
3771 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3772 /*sense_len*/SSD_FULL_SIZE,
3773 da_default_timeout * 1000);
3774 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3775 ccb->ccb_h.flags |= CAM_UNLOCKED;
3776 cam_iosched_submit_trim(softc->cam_iosched);
3780 * We calculate ws_max_blks here based off d_delmaxsize instead
3781 * of using softc->ws_max_blks as it is absolute max for the
3782 * device not the protocol max which may well be lower.
3785 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3787 struct da_softc *softc;
3789 uint64_t ws_max_blks;
3791 uint64_t count; /* forward compat with WS32 */
3793 softc = (struct da_softc *)periph->softc;
3794 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3795 lba = bp->bio_pblkno;
3799 if (bp1 != bp)//XXX imp XXX
3800 bioq_insert_tail(&softc->delete_run_queue, bp1);
3801 count += bp1->bio_bcount / softc->params.secsize;
3802 if (count > ws_max_blks) {
3803 xpt_print(periph->path,
3804 "%s issuing short delete %ld > %ld\n",
3805 da_delete_method_desc[softc->delete_method],
3806 count, ws_max_blks);
3807 count = omin(count, ws_max_blks);
3810 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3813 if (lba + count != bp1->bio_pblkno ||
3814 count + bp1->bio_bcount /
3815 softc->params.secsize > ws_max_blks) {
3816 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3821 scsi_write_same(&ccb->csio,
3822 /*retries*/da_retry_count,
3824 /*tag_action*/MSG_SIMPLE_Q_TAG,
3825 /*byte2*/softc->delete_method ==
3826 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3827 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3829 /*block_count*/count,
3830 /*data_ptr*/ __DECONST(void *, zero_region),
3831 /*dxfer_len*/ softc->params.secsize,
3832 /*sense_len*/SSD_FULL_SIZE,
3833 da_default_timeout * 1000);
3834 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3835 ccb->ccb_h.flags |= CAM_UNLOCKED;
3836 cam_iosched_submit_trim(softc->cam_iosched);
3840 cmd6workaround(union ccb *ccb)
3842 struct scsi_rw_6 cmd6;
3843 struct scsi_rw_10 *cmd10;
3844 struct da_softc *softc;
3849 cdb = ccb->csio.cdb_io.cdb_bytes;
3850 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3852 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3853 da_delete_methods old_method = softc->delete_method;
3856 * Typically there are two reasons for failure here
3857 * 1. Delete method was detected as supported but isn't
3858 * 2. Delete failed due to invalid params e.g. too big
3860 * While we will attempt to choose an alternative delete method
3861 * this may result in short deletes if the existing delete
3862 * requests from geom are big for the new method chosen.
3864 * This method assumes that the error which triggered this
3865 * will not retry the io otherwise a panic will occur
3867 dadeleteflag(softc, old_method, 0);
3868 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3869 if (softc->delete_method == DA_DELETE_DISABLE)
3870 xpt_print(ccb->ccb_h.path,
3871 "%s failed, disabling BIO_DELETE\n",
3872 da_delete_method_desc[old_method]);
3874 xpt_print(ccb->ccb_h.path,
3875 "%s failed, switching to %s BIO_DELETE\n",
3876 da_delete_method_desc[old_method],
3877 da_delete_method_desc[softc->delete_method]);
3879 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3880 cam_iosched_queue_work(softc->cam_iosched, bp);
3881 cam_iosched_queue_work(softc->cam_iosched,
3882 (struct bio *)ccb->ccb_h.ccb_bp);
3883 ccb->ccb_h.ccb_bp = NULL;
3887 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3888 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3889 (*cdb == PREVENT_ALLOW) &&
3890 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3892 xpt_print(ccb->ccb_h.path,
3893 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3894 softc->quirks |= DA_Q_NO_PREVENT;
3898 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3899 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3900 (*cdb == SYNCHRONIZE_CACHE) &&
3901 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3903 xpt_print(ccb->ccb_h.path,
3904 "SYNCHRONIZE CACHE(10) not supported.\n");
3905 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3906 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3910 /* Translation only possible if CDB is an array and cmd is R/W6 */
3911 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3912 (*cdb != READ_6 && *cdb != WRITE_6))
3915 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3916 "increasing minimum_cmd_size to 10.\n");
3917 softc->minimum_cmd_size = 10;
3919 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3920 cmd10 = (struct scsi_rw_10 *)cdb;
3921 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3923 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3924 cmd10->reserved = 0;
3925 scsi_ulto2b(cmd6.length, cmd10->length);
3926 cmd10->control = cmd6.control;
3927 ccb->csio.cdb_len = sizeof(*cmd10);
3929 /* Requeue request, unfreezing queue if necessary */
3930 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3931 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3934 cam_release_devq(ccb->ccb_h.path,
3938 /*getcount_only*/0);
3944 dazonedone(struct cam_periph *periph, union ccb *ccb)
3946 struct da_softc *softc;
3949 softc = periph->softc;
3950 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3952 switch (bp->bio_zone.zone_cmd) {
3953 case DISK_ZONE_OPEN:
3954 case DISK_ZONE_CLOSE:
3955 case DISK_ZONE_FINISH:
3958 case DISK_ZONE_REPORT_ZONES: {
3960 struct disk_zone_report *rep;
3961 struct scsi_report_zones_hdr *hdr;
3962 struct scsi_report_zones_desc *desc;
3963 struct disk_zone_rep_entry *entry;
3964 uint32_t num_alloced, hdr_len, num_avail;
3965 uint32_t num_to_fill, i;
3968 rep = &bp->bio_zone.zone_params.report;
3969 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
3971 * Note that bio_resid isn't normally used for zone
3972 * commands, but it is used by devstat_end_transaction_bio()
3973 * to determine how much data was transferred. Because
3974 * the size of the SCSI/ATA data structures is different
3975 * than the size of the BIO interface structures, the
3976 * amount of data actually transferred from the drive will
3977 * be different than the amount of data transferred to
3980 bp->bio_resid = ccb->csio.resid;
3981 num_alloced = rep->entries_allocated;
3982 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
3983 if (avail_len < sizeof(*hdr)) {
3985 * Is there a better error than EIO here? We asked
3986 * for at least the header, and we got less than
3989 bp->bio_error = EIO;
3990 bp->bio_flags |= BIO_ERROR;
3991 bp->bio_resid = bp->bio_bcount;
3995 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4000 hdr_len = ata ? le32dec(hdr->length) :
4001 scsi_4btoul(hdr->length);
4003 rep->entries_available = hdr_len / sizeof(*desc);
4005 rep->entries_available = 0;
4007 * NOTE: using the same values for the BIO version of the
4008 * same field as the SCSI/ATA values. This means we could
4009 * get some additional values that aren't defined in bio.h
4010 * if more values of the same field are defined later.
4012 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4013 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4014 scsi_8btou64(hdr->maximum_lba);
4016 * If the drive reports no entries that match the query,
4020 rep->entries_filled = 0;
4024 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4025 hdr_len / sizeof(*desc));
4027 * If the drive didn't return any data, then we're done.
4029 if (num_avail == 0) {
4030 rep->entries_filled = 0;
4034 num_to_fill = min(num_avail, rep->entries_allocated);
4036 * If the user didn't allocate any entries for us to fill,
4039 if (num_to_fill == 0) {
4040 rep->entries_filled = 0;
4044 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4045 i < num_to_fill; i++, desc++, entry++) {
4047 * NOTE: we're mapping the values here directly
4048 * from the SCSI/ATA bit definitions to the bio.h
4049 * definitons. There is also a warning in
4050 * disk_zone.h, but the impact is that if
4051 * additional values are added in the SCSI/ATA
4052 * specs these will be visible to consumers of
4055 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4056 entry->zone_condition =
4057 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4058 SRZ_ZONE_COND_SHIFT;
4059 entry->zone_flags |= desc->zone_flags &
4060 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4061 entry->zone_length =
4062 ata ? le64dec(desc->zone_length) :
4063 scsi_8btou64(desc->zone_length);
4064 entry->zone_start_lba =
4065 ata ? le64dec(desc->zone_start_lba) :
4066 scsi_8btou64(desc->zone_start_lba);
4067 entry->write_pointer_lba =
4068 ata ? le64dec(desc->write_pointer_lba) :
4069 scsi_8btou64(desc->write_pointer_lba);
4071 rep->entries_filled = num_to_fill;
4074 case DISK_ZONE_GET_PARAMS:
4077 * In theory we should not get a GET_PARAMS bio, since it
4078 * should be handled without queueing the command to the
4081 panic("%s: Invalid zone command %d", __func__,
4082 bp->bio_zone.zone_cmd);
4086 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4087 free(ccb->csio.data_ptr, M_SCSIDA);
4091 dadone(struct cam_periph *periph, union ccb *done_ccb)
4093 struct da_softc *softc;
4094 struct ccb_scsiio *csio;
4098 softc = (struct da_softc *)periph->softc;
4099 priority = done_ccb->ccb_h.pinfo.priority;
4101 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4103 csio = &done_ccb->csio;
4104 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4105 if (csio->bio != NULL)
4106 biotrack(csio->bio, __func__);
4108 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4110 case DA_CCB_BUFFER_IO:
4113 struct bio *bp, *bp1;
4115 cam_periph_lock(periph);
4116 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4117 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4121 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4126 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4127 if (error == ERESTART) {
4129 * A retry was scheduled, so
4132 cam_periph_unlock(periph);
4135 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4140 * return all queued I/O with EIO, so that
4141 * the client can retry these I/Os in the
4142 * proper order should it attempt to recover.
4147 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4149 * Catastrophic error. Mark our pack as
4153 * XXX See if this is really a media
4156 xpt_print(periph->path,
4157 "Invalidating pack\n");
4158 softc->flags |= DA_FLAG_PACK_INVALID;
4160 softc->invalidations++;
4162 queued_error = ENXIO;
4164 cam_iosched_flush(softc->cam_iosched, NULL,
4167 bp->bio_error = error;
4168 bp->bio_resid = bp->bio_bcount;
4169 bp->bio_flags |= BIO_ERROR;
4171 } else if (bp != NULL) {
4172 if (state == DA_CCB_DELETE)
4175 bp->bio_resid = csio->resid;
4177 if (bp->bio_resid != 0)
4178 bp->bio_flags |= BIO_ERROR;
4180 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4181 cam_release_devq(done_ccb->ccb_h.path,
4185 /*getcount_only*/0);
4186 } else if (bp != NULL) {
4187 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4188 panic("REQ_CMP with QFRZN");
4189 if (bp->bio_cmd == BIO_ZONE)
4190 dazonedone(periph, done_ccb);
4191 else if (state == DA_CCB_DELETE)
4194 bp->bio_resid = csio->resid;
4195 if ((csio->resid > 0)
4196 && (bp->bio_cmd != BIO_ZONE))
4197 bp->bio_flags |= BIO_ERROR;
4198 if (softc->error_inject != 0) {
4199 bp->bio_error = softc->error_inject;
4200 bp->bio_resid = bp->bio_bcount;
4201 bp->bio_flags |= BIO_ERROR;
4202 softc->error_inject = 0;
4207 biotrack(bp, __func__);
4208 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4209 if (LIST_EMPTY(&softc->pending_ccbs))
4210 softc->flags |= DA_FLAG_WAS_OTAG;
4213 * We need to call cam_iosched before we call biodone so that we
4214 * don't measure any activity that happens in the completion
4215 * routine, which in the case of sendfile can be quite
4218 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4219 xpt_release_ccb(done_ccb);
4220 if (state == DA_CCB_DELETE) {
4221 TAILQ_HEAD(, bio) queue;
4224 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4225 softc->delete_run_queue.insert_point = NULL;
4227 * Normally, the xpt_release_ccb() above would make sure
4228 * that when we have more work to do, that work would
4229 * get kicked off. However, we specifically keep
4230 * delete_running set to 0 before the call above to
4231 * allow other I/O to progress when many BIO_DELETE
4232 * requests are pushed down. We set delete_running to 0
4233 * and call daschedule again so that we don't stall if
4234 * there are no other I/Os pending apart from BIO_DELETEs.
4236 cam_iosched_trim_done(softc->cam_iosched);
4238 cam_periph_unlock(periph);
4239 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4240 TAILQ_REMOVE(&queue, bp1, bio_queue);
4241 bp1->bio_error = bp->bio_error;
4242 if (bp->bio_flags & BIO_ERROR) {
4243 bp1->bio_flags |= BIO_ERROR;
4244 bp1->bio_resid = bp1->bio_bcount;
4251 cam_periph_unlock(periph);
4257 case DA_CCB_PROBE_RC:
4258 case DA_CCB_PROBE_RC16:
4260 struct scsi_read_capacity_data *rdcap;
4261 struct scsi_read_capacity_data_long *rcaplong;
4268 /* XXX TODO: can this be a malloc? */
4269 announce_buf = softc->announce_temp;
4270 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4272 if (state == DA_CCB_PROBE_RC)
4273 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4275 rcaplong = (struct scsi_read_capacity_data_long *)
4278 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4279 struct disk_params *dp;
4280 uint32_t block_size;
4282 u_int lalba; /* Lowest aligned LBA. */
4284 if (state == DA_CCB_PROBE_RC) {
4285 block_size = scsi_4btoul(rdcap->length);
4286 maxsector = scsi_4btoul(rdcap->addr);
4290 * According to SBC-2, if the standard 10
4291 * byte READ CAPACITY command returns 2^32,
4292 * we should issue the 16 byte version of
4293 * the command, since the device in question
4294 * has more sectors than can be represented
4295 * with the short version of the command.
4297 if (maxsector == 0xffffffff) {
4298 free(rdcap, M_SCSIDA);
4299 xpt_release_ccb(done_ccb);
4300 softc->state = DA_STATE_PROBE_RC16;
4301 xpt_schedule(periph, priority);
4305 block_size = scsi_4btoul(rcaplong->length);
4306 maxsector = scsi_8btou64(rcaplong->addr);
4307 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4311 * Because GEOM code just will panic us if we
4312 * give them an 'illegal' value we'll avoid that
4315 if (block_size == 0) {
4320 if (block_size >= MAXPHYS) {
4321 xpt_print(periph->path,
4322 "unsupportable block size %ju\n",
4323 (uintmax_t) block_size);
4324 announce_buf = NULL;
4325 cam_periph_invalidate(periph);
4328 * We pass rcaplong into dasetgeom(),
4329 * because it will only use it if it is
4332 dasetgeom(periph, block_size, maxsector,
4333 rcaplong, sizeof(*rcaplong));
4334 lbp = (lalba & SRC16_LBPME_A);
4335 dp = &softc->params;
4336 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4337 "%juMB (%ju %u byte sectors)",
4338 ((uintmax_t)dp->secsize * dp->sectors) /
4340 (uintmax_t)dp->sectors, dp->secsize);
4346 * Retry any UNIT ATTENTION type errors. They
4347 * are expected at boot.
4349 error = daerror(done_ccb, CAM_RETRY_SELTO,
4350 SF_RETRY_UA|SF_NO_PRINT);
4351 if (error == ERESTART) {
4353 * A retry was scheuled, so
4357 } else if (error != 0) {
4359 int sense_key, error_code;
4362 struct ccb_getdev cgd;
4364 /* Don't wedge this device's queue */
4365 status = done_ccb->ccb_h.status;
4366 if ((status & CAM_DEV_QFRZN) != 0)
4367 cam_release_devq(done_ccb->ccb_h.path,
4371 /*getcount_only*/0);
4374 xpt_setup_ccb(&cgd.ccb_h,
4375 done_ccb->ccb_h.path,
4376 CAM_PRIORITY_NORMAL);
4377 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4378 xpt_action((union ccb *)&cgd);
4380 if (scsi_extract_sense_ccb(done_ccb,
4381 &error_code, &sense_key, &asc, &ascq))
4387 * If we tried READ CAPACITY(16) and failed,
4388 * fallback to READ CAPACITY(10).
4390 if ((state == DA_CCB_PROBE_RC16) &&
4391 (softc->flags & DA_FLAG_CAN_RC16) &&
4392 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4395 (error_code == SSD_CURRENT_ERROR) &&
4396 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4397 softc->flags &= ~DA_FLAG_CAN_RC16;
4398 free(rdcap, M_SCSIDA);
4399 xpt_release_ccb(done_ccb);
4400 softc->state = DA_STATE_PROBE_RC;
4401 xpt_schedule(periph, priority);
4406 * Attach to anything that claims to be a
4407 * direct access or optical disk device,
4408 * as long as it doesn't return a "Logical
4409 * unit not supported" (0x25) error.
4410 * "Internal Target Failure" (0x44) is also
4411 * special and typically means that the
4412 * device is a SATA drive behind a SATL
4413 * translation that's fallen into a
4414 * terminally fatal state.
4417 && (asc != 0x25) && (asc != 0x44)
4418 && (error_code == SSD_CURRENT_ERROR)) {
4419 const char *sense_key_desc;
4420 const char *asc_desc;
4422 dasetgeom(periph, 512, -1, NULL, 0);
4423 scsi_sense_desc(sense_key, asc, ascq,
4427 snprintf(announce_buf,
4429 "Attempt to query device "
4430 "size failed: %s, %s",
4431 sense_key_desc, asc_desc);
4437 xpt_print(periph->path,
4438 "got CAM status %#x\n",
4439 done_ccb->ccb_h.status);
4442 xpt_print(periph->path, "fatal error, "
4443 "failed to attach to device\n");
4445 announce_buf = NULL;
4448 * Free up resources.
4450 cam_periph_invalidate(periph);
4454 free(csio->data_ptr, M_SCSIDA);
4455 if (announce_buf != NULL &&
4456 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4459 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4461 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4462 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4468 * Create our sysctl variables, now that we know
4469 * we have successfully attached.
4471 /* increase the refcount */
4472 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4474 taskqueue_enqueue(taskqueue_thread,
4475 &softc->sysctl_task);
4477 /* XXX This message is useless! */
4478 xpt_print(periph->path, "fatal error, "
4479 "could not acquire reference count\n");
4483 /* We already probed the device. */
4484 if (softc->flags & DA_FLAG_PROBED) {
4485 daprobedone(periph, done_ccb);
4489 /* Ensure re-probe doesn't see old delete. */
4490 softc->delete_available = 0;
4491 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4492 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4494 * Based on older SBC-3 spec revisions
4495 * any of the UNMAP methods "may" be
4496 * available via LBP given this flag so
4497 * we flag all of them as available and
4498 * then remove those which further
4499 * probes confirm aren't available
4502 * We could also check readcap(16) p_type
4503 * flag to exclude one or more invalid
4504 * write same (X) types here
4506 dadeleteflag(softc, DA_DELETE_WS16, 1);
4507 dadeleteflag(softc, DA_DELETE_WS10, 1);
4508 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4510 xpt_release_ccb(done_ccb);
4511 softc->state = DA_STATE_PROBE_LBP;
4512 xpt_schedule(periph, priority);
4516 xpt_release_ccb(done_ccb);
4517 softc->state = DA_STATE_PROBE_BDC;
4518 xpt_schedule(periph, priority);
4521 case DA_CCB_PROBE_LBP:
4523 struct scsi_vpd_logical_block_prov *lbp;
4525 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4527 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4529 * T10/1799-D Revision 31 states at least one of these
4530 * must be supported but we don't currently enforce this.
4532 dadeleteflag(softc, DA_DELETE_WS16,
4533 (lbp->flags & SVPD_LBP_WS16));
4534 dadeleteflag(softc, DA_DELETE_WS10,
4535 (lbp->flags & SVPD_LBP_WS10));
4536 dadeleteflag(softc, DA_DELETE_UNMAP,
4537 (lbp->flags & SVPD_LBP_UNMAP));
4540 error = daerror(done_ccb, CAM_RETRY_SELTO,
4541 SF_RETRY_UA|SF_NO_PRINT);
4542 if (error == ERESTART)
4544 else if (error != 0) {
4545 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4546 /* Don't wedge this device's queue */
4547 cam_release_devq(done_ccb->ccb_h.path,
4551 /*getcount_only*/0);
4555 * Failure indicates we don't support any SBC-3
4556 * delete methods with UNMAP
4561 free(lbp, M_SCSIDA);
4562 xpt_release_ccb(done_ccb);
4563 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4564 xpt_schedule(periph, priority);
4567 case DA_CCB_PROBE_BLK_LIMITS:
4569 struct scsi_vpd_block_limits *block_limits;
4571 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4573 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4574 uint32_t max_txfer_len = scsi_4btoul(
4575 block_limits->max_txfer_len);
4576 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4577 block_limits->max_unmap_lba_cnt);
4578 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4579 block_limits->max_unmap_blk_cnt);
4580 uint32_t unmap_gran = scsi_4btoul(
4581 block_limits->opt_unmap_grain);
4582 uint32_t unmap_gran_align = scsi_4btoul(
4583 block_limits->unmap_grain_align);
4584 uint64_t ws_max_blks = scsi_8btou64(
4585 block_limits->max_write_same_length);
4587 if (max_txfer_len != 0) {
4588 softc->disk->d_maxsize = MIN(softc->maxio,
4589 (off_t)max_txfer_len * softc->params.secsize);
4593 * We should already support UNMAP but we check lba
4594 * and block count to be sure
4596 if (max_unmap_lba_cnt != 0x00L &&
4597 max_unmap_blk_cnt != 0x00L) {
4598 softc->unmap_max_lba = max_unmap_lba_cnt;
4599 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4601 if (unmap_gran > 1) {
4602 softc->unmap_gran = unmap_gran;
4603 if (unmap_gran_align & 0x80000000) {
4604 softc->unmap_gran_align =
4611 * Unexpected UNMAP limits which means the
4612 * device doesn't actually support UNMAP
4614 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4617 if (ws_max_blks != 0x00L)
4618 softc->ws_max_blks = ws_max_blks;
4621 error = daerror(done_ccb, CAM_RETRY_SELTO,
4622 SF_RETRY_UA|SF_NO_PRINT);
4623 if (error == ERESTART)
4625 else if (error != 0) {
4626 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4627 /* Don't wedge this device's queue */
4628 cam_release_devq(done_ccb->ccb_h.path,
4632 /*getcount_only*/0);
4636 * Failure here doesn't mean UNMAP is not
4637 * supported as this is an optional page.
4639 softc->unmap_max_lba = 1;
4640 softc->unmap_max_ranges = 1;
4644 free(block_limits, M_SCSIDA);
4645 xpt_release_ccb(done_ccb);
4646 softc->state = DA_STATE_PROBE_BDC;
4647 xpt_schedule(periph, priority);
4650 case DA_CCB_PROBE_BDC:
4652 struct scsi_vpd_block_device_characteristics *bdc;
4654 bdc = (struct scsi_vpd_block_device_characteristics *)
4657 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4661 * Disable queue sorting for non-rotational media
4664 u_int16_t old_rate = softc->disk->d_rotation_rate;
4666 valid_len = csio->dxfer_len - csio->resid;
4667 if (SBDC_IS_PRESENT(bdc, valid_len,
4668 medium_rotation_rate)) {
4669 softc->disk->d_rotation_rate =
4670 scsi_2btoul(bdc->medium_rotation_rate);
4671 if (softc->disk->d_rotation_rate ==
4672 SVPD_BDC_RATE_NON_ROTATING) {
4673 cam_iosched_set_sort_queue(
4674 softc->cam_iosched, 0);
4675 softc->rotating = 0;
4677 if (softc->disk->d_rotation_rate != old_rate) {
4678 disk_attr_changed(softc->disk,
4679 "GEOM::rotation_rate", M_NOWAIT);
4682 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4683 && (softc->zone_mode == DA_ZONE_NONE)) {
4686 if (scsi_vpd_supported_page(periph,
4687 SVPD_ATA_INFORMATION))
4693 * The Zoned field will only be set for
4694 * Drive Managed and Host Aware drives. If
4695 * they are Host Managed, the device type
4696 * in the standard INQUIRY data should be
4697 * set to T_ZBC_HM (0x14).
4699 if ((bdc->flags & SVPD_ZBC_MASK) ==
4701 softc->zone_mode = DA_ZONE_HOST_AWARE;
4702 softc->zone_interface = (ata_proto) ?
4703 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4704 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4706 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4707 softc->zone_interface = (ata_proto) ?
4708 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4709 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4711 xpt_print(periph->path, "Unknown zoned "
4713 bdc->flags & SVPD_ZBC_MASK);
4718 error = daerror(done_ccb, CAM_RETRY_SELTO,
4719 SF_RETRY_UA|SF_NO_PRINT);
4720 if (error == ERESTART)
4722 else if (error != 0) {
4723 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4724 /* Don't wedge this device's queue */
4725 cam_release_devq(done_ccb->ccb_h.path,
4729 /*getcount_only*/0);
4734 free(bdc, M_SCSIDA);
4735 xpt_release_ccb(done_ccb);
4736 softc->state = DA_STATE_PROBE_ATA;
4737 xpt_schedule(periph, priority);
4740 case DA_CCB_PROBE_ATA:
4743 struct ata_params *ata_params;
4748 ata_params = (struct ata_params *)csio->data_ptr;
4749 ptr = (uint16_t *)ata_params;
4753 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4756 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4757 ptr[i] = le16toh(ptr[i]);
4758 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4759 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4760 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4761 if (ata_params->max_dsm_blocks != 0)
4762 softc->trim_max_ranges = min(
4763 softc->trim_max_ranges,
4764 ata_params->max_dsm_blocks *
4765 ATA_DSM_BLK_RANGES);
4768 * Disable queue sorting for non-rotational media
4771 old_rate = softc->disk->d_rotation_rate;
4772 softc->disk->d_rotation_rate =
4773 ata_params->media_rotation_rate;
4774 if (softc->disk->d_rotation_rate ==
4775 ATA_RATE_NON_ROTATING) {
4776 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4777 softc->rotating = 0;
4779 if (softc->disk->d_rotation_rate != old_rate) {
4780 disk_attr_changed(softc->disk,
4781 "GEOM::rotation_rate", M_NOWAIT);
4784 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4785 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4787 if (ata_params->support.extension &
4789 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4792 * At this point, if we have a SATA host aware drive,
4793 * we communicate via ATA passthrough unless the
4794 * SAT layer supports ZBC -> ZAC translation. In
4798 * XXX KDM figure out how to detect a host managed
4801 if (softc->zone_mode == DA_ZONE_NONE) {
4803 * Note that we don't override the zone
4804 * mode or interface if it has already been
4805 * set. This is because it has either been
4806 * set as a quirk, or when we probed the
4807 * SCSI Block Device Characteristics page,
4808 * the zoned field was set. The latter
4809 * means that the SAT layer supports ZBC to
4810 * ZAC translation, and we would prefer to
4811 * use that if it is available.
4813 if ((ata_params->support3 &
4814 ATA_SUPPORT_ZONE_MASK) ==
4815 ATA_SUPPORT_ZONE_HOST_AWARE) {
4816 softc->zone_mode = DA_ZONE_HOST_AWARE;
4817 softc->zone_interface =
4818 DA_ZONE_IF_ATA_PASS;
4819 } else if ((ata_params->support3 &
4820 ATA_SUPPORT_ZONE_MASK) ==
4821 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4822 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4823 softc->zone_interface =
4824 DA_ZONE_IF_ATA_PASS;
4829 error = daerror(done_ccb, CAM_RETRY_SELTO,
4830 SF_RETRY_UA|SF_NO_PRINT);
4831 if (error == ERESTART)
4833 else if (error != 0) {
4834 if ((done_ccb->ccb_h.status &
4835 CAM_DEV_QFRZN) != 0) {
4836 /* Don't wedge this device's queue */
4837 cam_release_devq(done_ccb->ccb_h.path,
4841 /*getcount_only*/0);
4846 free(ata_params, M_SCSIDA);
4847 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4848 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4850 * If the ATA IDENTIFY failed, we could be talking
4851 * to a SCSI drive, although that seems unlikely,
4852 * since the drive did report that it supported the
4853 * ATA Information VPD page. If the ATA IDENTIFY
4854 * succeeded, and the SAT layer doesn't support
4855 * ZBC -> ZAC translation, continue on to get the
4856 * directory of ATA logs, and complete the rest of
4857 * the ZAC probe. If the SAT layer does support
4858 * ZBC -> ZAC translation, we want to use that,
4859 * and we'll probe the SCSI Zoned Block Device
4860 * Characteristics VPD page next.
4863 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4864 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4865 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4867 softc->state = DA_STATE_PROBE_ZONE;
4870 if (continue_probe != 0) {
4871 xpt_release_ccb(done_ccb);
4872 xpt_schedule(periph, priority);
4875 daprobedone(periph, done_ccb);
4878 case DA_CCB_PROBE_ATA_LOGDIR:
4882 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4884 softc->valid_logdir_len = 0;
4885 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4886 softc->valid_logdir_len =
4887 csio->dxfer_len - csio->resid;
4888 if (softc->valid_logdir_len > 0)
4889 bcopy(csio->data_ptr, &softc->ata_logdir,
4890 min(softc->valid_logdir_len,
4891 sizeof(softc->ata_logdir)));
4893 * Figure out whether the Identify Device log is
4894 * supported. The General Purpose log directory
4895 * has a header, and lists the number of pages
4896 * available for each GP log identified by the
4897 * offset into the list.
4899 if ((softc->valid_logdir_len >=
4900 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4901 && (le16dec(softc->ata_logdir.header) ==
4902 ATA_GP_LOG_DIR_VERSION)
4903 && (le16dec(&softc->ata_logdir.num_pages[
4904 (ATA_IDENTIFY_DATA_LOG *
4905 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4906 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4908 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4911 error = daerror(done_ccb, CAM_RETRY_SELTO,
4912 SF_RETRY_UA|SF_NO_PRINT);
4913 if (error == ERESTART)
4915 else if (error != 0) {
4917 * If we can't get the ATA log directory,
4918 * then ATA logs are effectively not
4919 * supported even if the bit is set in the
4922 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
4923 DA_FLAG_CAN_ATA_IDLOG);
4924 if ((done_ccb->ccb_h.status &
4925 CAM_DEV_QFRZN) != 0) {
4926 /* Don't wedge this device's queue */
4927 cam_release_devq(done_ccb->ccb_h.path,
4931 /*getcount_only*/0);
4936 free(csio->data_ptr, M_SCSIDA);
4939 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
4940 softc->state = DA_STATE_PROBE_ATA_IDDIR;
4941 xpt_release_ccb(done_ccb);
4942 xpt_schedule(periph, priority);
4945 daprobedone(periph, done_ccb);
4948 case DA_CCB_PROBE_ATA_IDDIR:
4952 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4953 off_t entries_offset, max_entries;
4956 softc->valid_iddir_len = 0;
4957 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
4958 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
4959 DA_FLAG_CAN_ATA_ZONE);
4960 softc->valid_iddir_len =
4961 csio->dxfer_len - csio->resid;
4962 if (softc->valid_iddir_len > 0)
4963 bcopy(csio->data_ptr, &softc->ata_iddir,
4964 min(softc->valid_iddir_len,
4965 sizeof(softc->ata_iddir)));
4968 __offsetof(struct ata_identify_log_pages,entries);
4969 max_entries = softc->valid_iddir_len - entries_offset;
4970 if ((softc->valid_iddir_len > (entries_offset + 1))
4971 && (le64dec(softc->ata_iddir.header) ==
4973 && (softc->ata_iddir.entry_count > 0)) {
4976 num_entries = softc->ata_iddir.entry_count;
4977 num_entries = min(num_entries,
4978 softc->valid_iddir_len - entries_offset);
4979 for (i = 0; i < num_entries &&
4980 i < max_entries; i++) {
4981 if (softc->ata_iddir.entries[i] ==
4984 DA_FLAG_CAN_ATA_SUPCAP;
4985 else if (softc->ata_iddir.entries[i]==
4988 DA_FLAG_CAN_ATA_ZONE;
4991 DA_FLAG_CAN_ATA_SUPCAP)
4993 DA_FLAG_CAN_ATA_ZONE))
4998 error = daerror(done_ccb, CAM_RETRY_SELTO,
4999 SF_RETRY_UA|SF_NO_PRINT);
5000 if (error == ERESTART)
5002 else if (error != 0) {
5004 * If we can't get the ATA Identify Data log
5005 * directory, then it effectively isn't
5006 * supported even if the ATA Log directory
5007 * a non-zero number of pages present for
5010 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5011 if ((done_ccb->ccb_h.status &
5012 CAM_DEV_QFRZN) != 0) {
5013 /* Don't wedge this device's queue */
5014 cam_release_devq(done_ccb->ccb_h.path,
5018 /*getcount_only*/0);
5023 free(csio->data_ptr, M_SCSIDA);
5026 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5027 softc->state = DA_STATE_PROBE_ATA_SUP;
5028 xpt_release_ccb(done_ccb);
5029 xpt_schedule(periph, priority);
5032 daprobedone(periph, done_ccb);
5035 case DA_CCB_PROBE_ATA_SUP:
5039 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5042 struct ata_identify_log_sup_cap *sup_cap;
5045 sup_cap = (struct ata_identify_log_sup_cap *)
5047 valid_len = csio->dxfer_len - csio->resid;
5049 __offsetof(struct ata_identify_log_sup_cap,
5050 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5051 if (valid_len >= needed_size) {
5052 uint64_t zoned, zac_cap;
5054 zoned = le64dec(sup_cap->zoned_cap);
5055 if (zoned & ATA_ZONED_VALID) {
5057 * This should have already been
5058 * set, because this is also in the
5059 * ATA identify data.
5061 if ((zoned & ATA_ZONED_MASK) ==
5062 ATA_SUPPORT_ZONE_HOST_AWARE)
5065 else if ((zoned & ATA_ZONED_MASK) ==
5066 ATA_SUPPORT_ZONE_DEV_MANAGED)
5068 DA_ZONE_DRIVE_MANAGED;
5071 zac_cap = le64dec(sup_cap->sup_zac_cap);
5072 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5073 if (zac_cap & ATA_REPORT_ZONES_SUP)
5074 softc->zone_flags |=
5075 DA_ZONE_FLAG_RZ_SUP;
5076 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5077 softc->zone_flags |=
5078 DA_ZONE_FLAG_OPEN_SUP;
5079 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5080 softc->zone_flags |=
5081 DA_ZONE_FLAG_CLOSE_SUP;
5082 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5083 softc->zone_flags |=
5084 DA_ZONE_FLAG_FINISH_SUP;
5085 if (zac_cap & ATA_ND_RWP_SUP)
5086 softc->zone_flags |=
5087 DA_ZONE_FLAG_RWP_SUP;
5090 * This field was introduced in
5091 * ACS-4, r08 on April 28th, 2015.
5092 * If the drive firmware was written
5093 * to an earlier spec, it won't have
5094 * the field. So, assume all
5095 * commands are supported.
5097 softc->zone_flags |=
5098 DA_ZONE_FLAG_SUP_MASK;
5103 error = daerror(done_ccb, CAM_RETRY_SELTO,
5104 SF_RETRY_UA|SF_NO_PRINT);
5105 if (error == ERESTART)
5107 else if (error != 0) {
5109 * If we can't get the ATA Identify Data
5110 * Supported Capabilities page, clear the
5113 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5115 * And clear zone capabilities.
5117 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5118 if ((done_ccb->ccb_h.status &
5119 CAM_DEV_QFRZN) != 0) {
5120 /* Don't wedge this device's queue */
5121 cam_release_devq(done_ccb->ccb_h.path,
5125 /*getcount_only*/0);
5130 free(csio->data_ptr, M_SCSIDA);
5133 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5134 softc->state = DA_STATE_PROBE_ATA_ZONE;
5135 xpt_release_ccb(done_ccb);
5136 xpt_schedule(periph, priority);
5139 daprobedone(periph, done_ccb);
5142 case DA_CCB_PROBE_ATA_ZONE:
5146 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5147 struct ata_zoned_info_log *zi_log;
5151 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5153 valid_len = csio->dxfer_len - csio->resid;
5154 needed_size = __offsetof(struct ata_zoned_info_log,
5155 version_info) + 1 + sizeof(zi_log->version_info);
5156 if (valid_len >= needed_size) {
5159 tmpvar = le64dec(zi_log->zoned_cap);
5160 if (tmpvar & ATA_ZDI_CAP_VALID) {
5161 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5162 softc->zone_flags |=
5163 DA_ZONE_FLAG_URSWRZ;
5165 softc->zone_flags &=
5166 ~DA_ZONE_FLAG_URSWRZ;
5168 tmpvar = le64dec(zi_log->optimal_seq_zones);
5169 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5170 softc->zone_flags |=
5171 DA_ZONE_FLAG_OPT_SEQ_SET;
5172 softc->optimal_seq_zones = (tmpvar &
5173 ATA_ZDI_OPT_SEQ_MASK);
5175 softc->zone_flags &=
5176 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5177 softc->optimal_seq_zones = 0;
5180 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5181 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5182 softc->zone_flags |=
5183 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5184 softc->optimal_nonseq_zones =
5185 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5187 softc->zone_flags &=
5188 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5189 softc->optimal_nonseq_zones = 0;
5192 tmpvar = le64dec(zi_log->max_seq_req_zones);
5193 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5194 softc->zone_flags |=
5195 DA_ZONE_FLAG_MAX_SEQ_SET;
5196 softc->max_seq_zones =
5197 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5199 softc->zone_flags &=
5200 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5201 softc->max_seq_zones = 0;
5205 error = daerror(done_ccb, CAM_RETRY_SELTO,
5206 SF_RETRY_UA|SF_NO_PRINT);
5207 if (error == ERESTART)
5209 else if (error != 0) {
5210 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5211 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5213 if ((done_ccb->ccb_h.status &
5214 CAM_DEV_QFRZN) != 0) {
5215 /* Don't wedge this device's queue */
5216 cam_release_devq(done_ccb->ccb_h.path,
5220 /*getcount_only*/0);
5225 free(csio->data_ptr, M_SCSIDA);
5227 daprobedone(periph, done_ccb);
5230 case DA_CCB_PROBE_ZONE:
5234 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5237 struct scsi_vpd_zoned_bdc *zoned_bdc;
5240 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5242 valid_len = csio->dxfer_len - csio->resid;
5243 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5244 max_seq_req_zones) + 1 +
5245 sizeof(zoned_bdc->max_seq_req_zones);
5246 if ((valid_len >= needed_len)
5247 && (scsi_2btoul(zoned_bdc->page_length) >=
5249 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5250 softc->zone_flags |=
5251 DA_ZONE_FLAG_URSWRZ;
5253 softc->zone_flags &=
5254 ~DA_ZONE_FLAG_URSWRZ;
5255 softc->optimal_seq_zones =
5256 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5257 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5258 softc->optimal_nonseq_zones = scsi_4btoul(
5259 zoned_bdc->optimal_nonseq_zones);
5260 softc->zone_flags |=
5261 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5262 softc->max_seq_zones =
5263 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5264 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5267 * All of the zone commands are mandatory for SCSI
5270 * XXX KDM this is valid as of September 2015.
5271 * Re-check this assumption once the SAT spec is
5272 * updated to support SCSI ZBC to ATA ZAC mapping.
5273 * Since ATA allows zone commands to be reported
5274 * as supported or not, this may not necessarily
5275 * be true for an ATA device behind a SAT (SCSI to
5276 * ATA Translation) layer.
5278 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5280 error = daerror(done_ccb, CAM_RETRY_SELTO,
5281 SF_RETRY_UA|SF_NO_PRINT);
5282 if (error == ERESTART)
5284 else if (error != 0) {
5285 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5286 /* Don't wedge this device's queue */
5287 cam_release_devq(done_ccb->ccb_h.path,
5291 /*getcount_only*/0);
5295 daprobedone(periph, done_ccb);
5299 /* No-op. We're polling */
5303 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5305 if (daerror(done_ccb, CAM_RETRY_SELTO,
5306 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5309 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5310 cam_release_devq(done_ccb->ccb_h.path,
5314 /*getcount_only*/0);
5316 xpt_release_ccb(done_ccb);
5317 cam_periph_release_locked(periph);
5323 xpt_release_ccb(done_ccb);
5327 dareprobe(struct cam_periph *periph)
5329 struct da_softc *softc;
5332 softc = (struct da_softc *)periph->softc;
5334 /* Probe in progress; don't interfere. */
5335 if (softc->state != DA_STATE_NORMAL)
5338 status = cam_periph_acquire(periph);
5339 KASSERT(status == CAM_REQ_CMP,
5340 ("dareprobe: cam_periph_acquire failed"));
5342 if (softc->flags & DA_FLAG_CAN_RC16)
5343 softc->state = DA_STATE_PROBE_RC16;
5345 softc->state = DA_STATE_PROBE_RC;
5347 xpt_schedule(periph, CAM_PRIORITY_DEV);
5351 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5353 struct da_softc *softc;
5354 struct cam_periph *periph;
5355 int error, error_code, sense_key, asc, ascq;
5357 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5358 if (ccb->csio.bio != NULL)
5359 biotrack(ccb->csio.bio, __func__);
5362 periph = xpt_path_periph(ccb->ccb_h.path);
5363 softc = (struct da_softc *)periph->softc;
5366 * Automatically detect devices that do not support
5367 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5370 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5371 error = cmd6workaround(ccb);
5372 } else if (scsi_extract_sense_ccb(ccb,
5373 &error_code, &sense_key, &asc, &ascq)) {
5374 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5375 error = cmd6workaround(ccb);
5377 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5378 * query the capacity and notify upper layers.
5380 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5381 asc == 0x2A && ascq == 0x09) {
5382 xpt_print(periph->path, "Capacity data has changed\n");
5383 softc->flags &= ~DA_FLAG_PROBED;
5385 sense_flags |= SF_NO_PRINT;
5386 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5387 asc == 0x28 && ascq == 0x00) {
5388 softc->flags &= ~DA_FLAG_PROBED;
5389 disk_media_changed(softc->disk, M_NOWAIT);
5390 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5391 asc == 0x3F && ascq == 0x03) {
5392 xpt_print(periph->path, "INQUIRY data has changed\n");
5393 softc->flags &= ~DA_FLAG_PROBED;
5395 sense_flags |= SF_NO_PRINT;
5396 } else if (sense_key == SSD_KEY_NOT_READY &&
5397 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5398 softc->flags |= DA_FLAG_PACK_INVALID;
5399 disk_media_gone(softc->disk, M_NOWAIT);
5402 if (error == ERESTART)
5406 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5407 case CAM_CMD_TIMEOUT:
5410 case CAM_REQ_ABORTED:
5411 case CAM_REQ_CMP_ERR:
5412 case CAM_REQ_TERMIO:
5413 case CAM_UNREC_HBA_ERROR:
5414 case CAM_DATA_RUN_ERR:
5424 * Until we have a better way of doing pack validation,
5425 * don't treat UAs as errors.
5427 sense_flags |= SF_RETRY_UA;
5429 if (softc->quirks & DA_Q_RETRY_BUSY)
5430 sense_flags |= SF_RETRY_BUSY;
5431 return(cam_periph_error(ccb, cam_flags, sense_flags,
5432 &softc->saved_ccb));
5436 damediapoll(void *arg)
5438 struct cam_periph *periph = arg;
5439 struct da_softc *softc = periph->softc;
5441 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5442 LIST_EMPTY(&softc->pending_ccbs)) {
5443 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5444 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5448 /* Queue us up again */
5449 if (da_poll_period != 0)
5450 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5454 daprevent(struct cam_periph *periph, int action)
5456 struct da_softc *softc;
5460 softc = (struct da_softc *)periph->softc;
5462 if (((action == PR_ALLOW)
5463 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5464 || ((action == PR_PREVENT)
5465 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5469 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5471 scsi_prevent(&ccb->csio,
5479 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5480 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5483 if (action == PR_ALLOW)
5484 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5486 softc->flags |= DA_FLAG_PACK_LOCKED;
5489 xpt_release_ccb(ccb);
5493 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5494 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5496 struct ccb_calc_geometry ccg;
5497 struct da_softc *softc;
5498 struct disk_params *dp;
5499 u_int lbppbe, lalba;
5502 softc = (struct da_softc *)periph->softc;
5504 dp = &softc->params;
5505 dp->secsize = block_len;
5506 dp->sectors = maxsector + 1;
5507 if (rcaplong != NULL) {
5508 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5509 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5510 lalba &= SRC16_LALBA_A;
5517 dp->stripesize = block_len << lbppbe;
5518 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5520 } else if (softc->quirks & DA_Q_4K) {
5521 dp->stripesize = 4096;
5522 dp->stripeoffset = 0;
5523 } else if (softc->unmap_gran != 0) {
5524 dp->stripesize = block_len * softc->unmap_gran;
5525 dp->stripeoffset = (dp->stripesize - block_len *
5526 softc->unmap_gran_align) % dp->stripesize;
5529 dp->stripeoffset = 0;
5532 * Have the controller provide us with a geometry
5533 * for this disk. The only time the geometry
5534 * matters is when we boot and the controller
5535 * is the only one knowledgeable enough to come
5536 * up with something that will make this a bootable
5539 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5540 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5541 ccg.block_size = dp->secsize;
5542 ccg.volume_size = dp->sectors;
5544 ccg.secs_per_track = 0;
5546 xpt_action((union ccb*)&ccg);
5547 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5549 * We don't know what went wrong here- but just pick
5550 * a geometry so we don't have nasty things like divide
5554 dp->secs_per_track = 255;
5555 dp->cylinders = dp->sectors / (255 * 255);
5556 if (dp->cylinders == 0) {
5560 dp->heads = ccg.heads;
5561 dp->secs_per_track = ccg.secs_per_track;
5562 dp->cylinders = ccg.cylinders;
5566 * If the user supplied a read capacity buffer, and if it is
5567 * different than the previous buffer, update the data in the EDT.
5568 * If it's the same, we don't bother. This avoids sending an
5569 * update every time someone opens this device.
5571 if ((rcaplong != NULL)
5572 && (bcmp(rcaplong, &softc->rcaplong,
5573 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5574 struct ccb_dev_advinfo cdai;
5576 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5577 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5578 cdai.buftype = CDAI_TYPE_RCAPLONG;
5579 cdai.flags = CDAI_FLAG_STORE;
5580 cdai.bufsiz = rcap_len;
5581 cdai.buf = (uint8_t *)rcaplong;
5582 xpt_action((union ccb *)&cdai);
5583 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5584 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5585 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5586 xpt_print(periph->path, "%s: failed to set read "
5587 "capacity advinfo\n", __func__);
5588 /* Use cam_error_print() to decode the status */
5589 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5592 bcopy(rcaplong, &softc->rcaplong,
5593 min(sizeof(softc->rcaplong), rcap_len));
5597 softc->disk->d_sectorsize = softc->params.secsize;
5598 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5599 softc->disk->d_stripesize = softc->params.stripesize;
5600 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5601 /* XXX: these are not actually "firmware" values, so they may be wrong */
5602 softc->disk->d_fwsectors = softc->params.secs_per_track;
5603 softc->disk->d_fwheads = softc->params.heads;
5604 softc->disk->d_devstat->block_size = softc->params.secsize;
5605 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5607 error = disk_resize(softc->disk, M_NOWAIT);
5609 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5613 dasendorderedtag(void *arg)
5615 struct da_softc *softc = arg;
5617 if (da_send_ordered) {
5618 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5619 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5620 softc->flags |= DA_FLAG_NEED_OTAG;
5621 softc->flags &= ~DA_FLAG_WAS_OTAG;
5624 /* Queue us up again */
5625 callout_reset(&softc->sendordered_c,
5626 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5627 dasendorderedtag, softc);
5631 * Step through all DA peripheral drivers, and if the device is still open,
5632 * sync the disk cache to physical media.
5635 dashutdown(void * arg, int howto)
5637 struct cam_periph *periph;
5638 struct da_softc *softc;
5642 CAM_PERIPH_FOREACH(periph, &dadriver) {
5643 softc = (struct da_softc *)periph->softc;
5644 if (SCHEDULER_STOPPED()) {
5645 /* If we paniced with the lock held, do not recurse. */
5646 if (!cam_periph_owned(periph) &&
5647 (softc->flags & DA_FLAG_OPEN)) {
5648 dadump(softc->disk, NULL, 0, 0, 0);
5652 cam_periph_lock(periph);
5655 * We only sync the cache if the drive is still open, and
5656 * if the drive is capable of it..
5658 if (((softc->flags & DA_FLAG_OPEN) == 0)
5659 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5660 cam_periph_unlock(periph);
5664 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5665 scsi_synchronize_cache(&ccb->csio,
5669 /*begin_lba*/0, /* whole disk */
5674 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5675 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5676 softc->disk->d_devstat);
5678 xpt_print(periph->path, "Synchronize cache failed\n");
5679 xpt_release_ccb(ccb);
5680 cam_periph_unlock(periph);
5684 #else /* !_KERNEL */
5687 * XXX These are only left out of the kernel build to silence warnings. If,
5688 * for some reason these functions are used in the kernel, the ifdefs should
5689 * be moved so they are included both in the kernel and userland.
5692 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5693 void (*cbfcnp)(struct cam_periph *, union ccb *),
5694 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5695 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5698 struct scsi_format_unit *scsi_cmd;
5700 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5701 scsi_cmd->opcode = FORMAT_UNIT;
5702 scsi_cmd->byte2 = byte2;
5703 scsi_ulto2b(ileave, scsi_cmd->interleave);
5708 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5718 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5719 void (*cbfcnp)(struct cam_periph *, union ccb *),
5720 uint8_t tag_action, uint8_t list_format,
5721 uint32_t addr_desc_index, uint8_t *data_ptr,
5722 uint32_t dxfer_len, int minimum_cmd_size,
5723 uint8_t sense_len, uint32_t timeout)
5728 * These conditions allow using the 10 byte command. Otherwise we
5729 * need to use the 12 byte command.
5731 if ((minimum_cmd_size <= 10)
5732 && (addr_desc_index == 0)
5733 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5734 struct scsi_read_defect_data_10 *cdb10;
5736 cdb10 = (struct scsi_read_defect_data_10 *)
5737 &csio->cdb_io.cdb_bytes;
5739 cdb_len = sizeof(*cdb10);
5740 bzero(cdb10, cdb_len);
5741 cdb10->opcode = READ_DEFECT_DATA_10;
5742 cdb10->format = list_format;
5743 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5745 struct scsi_read_defect_data_12 *cdb12;
5747 cdb12 = (struct scsi_read_defect_data_12 *)
5748 &csio->cdb_io.cdb_bytes;
5750 cdb_len = sizeof(*cdb12);
5751 bzero(cdb12, cdb_len);
5752 cdb12->opcode = READ_DEFECT_DATA_12;
5753 cdb12->format = list_format;
5754 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5755 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5761 /*flags*/ CAM_DIR_IN,
5771 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5772 void (*cbfcnp)(struct cam_periph *, union ccb *),
5773 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5774 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5777 struct scsi_sanitize *scsi_cmd;
5779 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5780 scsi_cmd->opcode = SANITIZE;
5781 scsi_cmd->byte2 = byte2;
5782 scsi_cmd->control = control;
5783 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5788 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5797 #endif /* _KERNEL */
5800 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5801 void (*cbfcnp)(struct cam_periph *, union ccb *),
5802 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5803 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5804 uint8_t sense_len, uint32_t timeout)
5806 struct scsi_zbc_out *scsi_cmd;
5808 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5809 scsi_cmd->opcode = ZBC_OUT;
5810 scsi_cmd->service_action = service_action;
5811 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5812 scsi_cmd->zone_flags = zone_flags;
5817 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5827 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5828 void (*cbfcnp)(struct cam_periph *, union ccb *),
5829 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5830 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5831 uint8_t sense_len, uint32_t timeout)
5833 struct scsi_zbc_in *scsi_cmd;
5835 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5836 scsi_cmd->opcode = ZBC_IN;
5837 scsi_cmd->service_action = service_action;
5838 scsi_ulto4b(dxfer_len, scsi_cmd->length);
5839 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5840 scsi_cmd->zone_options = zone_options;
5845 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5856 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5857 void (*cbfcnp)(struct cam_periph *, union ccb *),
5858 uint8_t tag_action, int use_ncq,
5859 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5860 uint8_t *data_ptr, uint32_t dxfer_len,
5861 uint8_t *cdb_storage, size_t cdb_storage_len,
5862 uint8_t sense_len, uint32_t timeout)
5864 uint8_t command_out, protocol, ata_flags;
5865 uint16_t features_out;
5866 uint32_t sectors_out, auxiliary;
5872 command_out = ATA_ZAC_MANAGEMENT_OUT;
5873 features_out = (zm_action & 0xf) | (zone_flags << 8);
5874 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5875 if (dxfer_len == 0) {
5876 protocol = AP_PROTO_NON_DATA;
5877 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5880 protocol = AP_PROTO_DMA;
5881 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5882 AP_FLAG_TDIR_TO_DEV;
5883 sectors_out = ((dxfer_len >> 9) & 0xffff);
5887 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5888 if (dxfer_len == 0) {
5889 command_out = ATA_NCQ_NON_DATA;
5890 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5892 * We're assuming the SCSI to ATA translation layer
5893 * will set the NCQ tag number in the tag field.
5894 * That isn't clear from the SAT-4 spec (as of rev 05).
5897 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5899 command_out = ATA_SEND_FPDMA_QUEUED;
5901 * Note that we're defaulting to normal priority,
5902 * and assuming that the SCSI to ATA translation
5903 * layer will insert the NCQ tag number in the tag
5904 * field. That isn't clear in the SAT-4 spec (as
5907 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5909 ata_flags |= AP_FLAG_TLEN_FEAT |
5910 AP_FLAG_TDIR_TO_DEV;
5913 * For SEND FPDMA QUEUED, the transfer length is
5914 * encoded in the FEATURE register, and 0 means
5915 * that 65536 512 byte blocks are to be tranferred.
5916 * In practice, it seems unlikely that we'll see
5917 * a transfer that large, and it may confuse the
5918 * the SAT layer, because generally that means that
5919 * 0 bytes should be transferred.
5921 if (dxfer_len == (65536 * 512)) {
5923 } else if (dxfer_len <= (65535 * 512)) {
5924 features_out = ((dxfer_len >> 9) & 0xffff);
5926 /* The transfer is too big. */
5933 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
5934 protocol = AP_PROTO_FPDMA;
5937 protocol |= AP_EXTEND;
5939 retval = scsi_ata_pass(csio,
5942 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5944 /*protocol*/ protocol,
5945 /*ata_flags*/ ata_flags,
5946 /*features*/ features_out,
5947 /*sector_count*/ sectors_out,
5949 /*command*/ command_out,
5952 /*auxiliary*/ auxiliary,
5954 /*data_ptr*/ data_ptr,
5955 /*dxfer_len*/ dxfer_len,
5956 /*cdb_storage*/ cdb_storage,
5957 /*cdb_storage_len*/ cdb_storage_len,
5958 /*minimum_cmd_size*/ 0,
5959 /*sense_len*/ SSD_FULL_SIZE,
5960 /*timeout*/ timeout);
5968 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
5969 void (*cbfcnp)(struct cam_periph *, union ccb *),
5970 uint8_t tag_action, int use_ncq,
5971 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5972 uint8_t *data_ptr, uint32_t dxfer_len,
5973 uint8_t *cdb_storage, size_t cdb_storage_len,
5974 uint8_t sense_len, uint32_t timeout)
5976 uint8_t command_out, protocol;
5977 uint16_t features_out, sectors_out;
5983 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
5986 command_out = ATA_ZAC_MANAGEMENT_IN;
5987 /* XXX KDM put a macro here */
5988 features_out = (zm_action & 0xf) | (zone_flags << 8);
5989 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
5990 protocol = AP_PROTO_DMA;
5991 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
5994 ata_flags |= AP_FLAG_TLEN_FEAT;
5996 command_out = ATA_RECV_FPDMA_QUEUED;
5997 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6000 * For RECEIVE FPDMA QUEUED, the transfer length is
6001 * encoded in the FEATURE register, and 0 means
6002 * that 65536 512 byte blocks are to be tranferred.
6003 * In practice, it seems unlikely that we'll see
6004 * a transfer that large, and it may confuse the
6005 * the SAT layer, because generally that means that
6006 * 0 bytes should be transferred.
6008 if (dxfer_len == (65536 * 512)) {
6010 } else if (dxfer_len <= (65535 * 512)) {
6011 features_out = ((dxfer_len >> 9) & 0xffff);
6013 /* The transfer is too big. */
6017 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6018 protocol = AP_PROTO_FPDMA;
6021 protocol |= AP_EXTEND;
6023 retval = scsi_ata_pass(csio,
6026 /*flags*/ CAM_DIR_IN,
6028 /*protocol*/ protocol,
6029 /*ata_flags*/ ata_flags,
6030 /*features*/ features_out,
6031 /*sector_count*/ sectors_out,
6033 /*command*/ command_out,
6036 /*auxiliary*/ auxiliary,
6038 /*data_ptr*/ data_ptr,
6039 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6040 /*cdb_storage*/ cdb_storage,
6041 /*cdb_storage_len*/ cdb_storage_len,
6042 /*minimum_cmd_size*/ 0,
6043 /*sense_len*/ SSD_FULL_SIZE,
6044 /*timeout*/ timeout);