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
687 * Genesys 6-in-1 Card Reader
690 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
691 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
695 * Rekam Digital CAMERA
698 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
699 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
703 * iRiver H10 MP3 player
706 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
707 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
711 * iRiver U10 MP3 player
714 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
715 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
722 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
723 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
727 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
730 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
731 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
738 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
739 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
743 * Philips USB Key Audio KEY013
746 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
747 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
754 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
755 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
762 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
763 /*quirks*/ DA_Q_NO_SYNC_CACHE
767 * I/O Magic USB flash - Giga Bank
770 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
771 /*quirks*/ DA_Q_NO_SYNC_CACHE
775 * JoyFly 128mb USB Flash Drive
778 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
779 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
786 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
787 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
791 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
794 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
795 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
799 * Samsung YP-U3 mp3-player
802 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
803 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
806 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
807 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
811 * Sony Cyber-Shot DSC cameras
814 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
815 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
818 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
819 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
822 /* At least several Transcent USB sticks lie on RC16. */
823 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
824 "*"}, /*quirks*/ DA_Q_NO_RC16
828 * I-O Data USB Flash Disk
831 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
832 "*"}, /*quirks*/ DA_Q_NO_RC16
834 /* ATA/SATA devices over SAS/USB/... */
836 /* Hitachi Advanced Format (4k) drives */
837 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
841 /* Micron Advanced Format (4k) drives */
842 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
846 /* Samsung Advanced Format (4k) drives */
847 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
851 /* Samsung Advanced Format (4k) drives */
852 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
856 /* Samsung Advanced Format (4k) drives */
857 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
861 /* Samsung Advanced Format (4k) drives */
862 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
866 /* Seagate Barracuda Green Advanced Format (4k) drives */
867 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
871 /* Seagate Barracuda Green Advanced Format (4k) drives */
872 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
876 /* Seagate Barracuda Green Advanced Format (4k) drives */
877 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
881 /* Seagate Barracuda Green Advanced Format (4k) drives */
882 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
886 /* Seagate Barracuda Green Advanced Format (4k) drives */
887 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
891 /* Seagate Barracuda Green Advanced Format (4k) drives */
892 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
896 /* Seagate Momentus Advanced Format (4k) drives */
897 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
901 /* Seagate Momentus Advanced Format (4k) drives */
902 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
906 /* Seagate Momentus Advanced Format (4k) drives */
907 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
911 /* Seagate Momentus Advanced Format (4k) drives */
912 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
916 /* Seagate Momentus Advanced Format (4k) drives */
917 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
921 /* Seagate Momentus Advanced Format (4k) drives */
922 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
926 /* Seagate Momentus Advanced Format (4k) drives */
927 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
931 /* Seagate Momentus Advanced Format (4k) drives */
932 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
936 /* Seagate Momentus Advanced Format (4k) drives */
937 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
941 /* Seagate Momentus Advanced Format (4k) drives */
942 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
946 /* Seagate Momentus Advanced Format (4k) drives */
947 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
951 /* Seagate Momentus Advanced Format (4k) drives */
952 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
956 /* Seagate Momentus Advanced Format (4k) drives */
957 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
961 /* Seagate Momentus Advanced Format (4k) drives */
962 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
966 /* Seagate Momentus Thin Advanced Format (4k) drives */
967 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
971 /* Seagate Momentus Thin Advanced Format (4k) drives */
972 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
976 /* WDC Caviar Green Advanced Format (4k) drives */
977 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
981 /* WDC Caviar Green Advanced Format (4k) drives */
982 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
986 /* WDC Caviar Green Advanced Format (4k) drives */
987 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
991 /* WDC Caviar Green Advanced Format (4k) drives */
992 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
996 /* WDC Caviar Green Advanced Format (4k) drives */
997 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1001 /* WDC Caviar Green Advanced Format (4k) drives */
1002 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1006 /* WDC Caviar Green Advanced Format (4k) drives */
1007 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1011 /* WDC Caviar Green Advanced Format (4k) drives */
1012 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1016 /* WDC Scorpio Black Advanced Format (4k) drives */
1017 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1021 /* WDC Scorpio Black Advanced Format (4k) drives */
1022 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1026 /* WDC Scorpio Black Advanced Format (4k) drives */
1027 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1031 /* WDC Scorpio Black Advanced Format (4k) drives */
1032 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1036 /* WDC Scorpio Blue Advanced Format (4k) drives */
1037 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1041 /* WDC Scorpio Blue Advanced Format (4k) drives */
1042 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1046 /* WDC Scorpio Blue Advanced Format (4k) drives */
1047 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1051 /* WDC Scorpio Blue Advanced Format (4k) drives */
1052 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1057 * Olympus FE-210 camera
1059 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1060 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1064 * LG UP3S MP3 player
1066 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1067 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1071 * Laser MP3-2GA13 MP3 player
1073 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1074 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1078 * LaCie external 250GB Hard drive des by Porsche
1079 * Submitted by: Ben Stuyts <ben@altesco.nl>
1082 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1083 /*quirks*/ DA_Q_NO_SYNC_CACHE
1088 * Corsair Force 2 SSDs
1089 * 4k optimised & trim only works in 4k requests + 4k aligned
1091 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1096 * Corsair Force 3 SSDs
1097 * 4k optimised & trim only works in 4k requests + 4k aligned
1099 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1104 * Corsair Neutron GTX SSDs
1105 * 4k optimised & trim only works in 4k requests + 4k aligned
1107 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1112 * Corsair Force GT & GS SSDs
1113 * 4k optimised & trim only works in 4k requests + 4k aligned
1115 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1121 * 4k optimised & trim only works in 4k requests + 4k aligned
1123 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1128 * Crucial RealSSD C300 SSDs
1131 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1132 "*" }, /*quirks*/DA_Q_4K
1136 * Intel 320 Series SSDs
1137 * 4k optimised & trim only works in 4k requests + 4k aligned
1139 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1144 * Intel 330 Series SSDs
1145 * 4k optimised & trim only works in 4k requests + 4k aligned
1147 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1152 * Intel 510 Series SSDs
1153 * 4k optimised & trim only works in 4k requests + 4k aligned
1155 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1160 * Intel 520 Series SSDs
1161 * 4k optimised & trim only works in 4k requests + 4k aligned
1163 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1168 * Intel S3610 Series SSDs
1169 * 4k optimised & trim only works in 4k requests + 4k aligned
1171 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1176 * Intel X25-M Series SSDs
1177 * 4k optimised & trim only works in 4k requests + 4k aligned
1179 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1184 * Kingston E100 Series SSDs
1185 * 4k optimised & trim only works in 4k requests + 4k aligned
1187 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1192 * Kingston HyperX 3k SSDs
1193 * 4k optimised & trim only works in 4k requests + 4k aligned
1195 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1200 * Marvell SSDs (entry taken from OpenSolaris)
1201 * 4k optimised & trim only works in 4k requests + 4k aligned
1203 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1208 * OCZ Agility 2 SSDs
1209 * 4k optimised & trim only works in 4k requests + 4k aligned
1211 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1216 * OCZ Agility 3 SSDs
1217 * 4k optimised & trim only works in 4k requests + 4k aligned
1219 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1224 * OCZ Deneva R Series SSDs
1225 * 4k optimised & trim only works in 4k requests + 4k aligned
1227 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1232 * OCZ Vertex 2 SSDs (inc pro series)
1233 * 4k optimised & trim only works in 4k requests + 4k aligned
1235 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1241 * 4k optimised & trim only works in 4k requests + 4k aligned
1243 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1249 * 4k optimised & trim only works in 4k requests + 4k aligned
1251 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1256 * Samsung 830 Series SSDs
1257 * 4k optimised & trim only works in 4k requests + 4k aligned
1259 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1265 * 4k optimised & trim only works in 4k requests + 4k aligned
1267 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1273 * 4k optimised & trim only works in 4k requests + 4k aligned
1275 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1280 * Samsung 843T Series SSDs (MZ7WD*)
1281 * Samsung PM851 Series SSDs (MZ7TE*)
1282 * Samsung PM853T Series SSDs (MZ7GE*)
1283 * Samsung SM863 Series SSDs (MZ7KM*)
1286 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1291 * SuperTalent TeraDrive CT SSDs
1292 * 4k optimised & trim only works in 4k requests + 4k aligned
1294 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1299 * XceedIOPS SATA SSDs
1302 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1307 * Hama Innostor USB-Stick
1309 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1310 /*quirks*/DA_Q_NO_RC16
1314 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1315 * Drive Managed SATA hard drive. This drive doesn't report
1316 * in firmware that it is a drive managed SMR drive.
1318 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS0002*", "*" },
1319 /*quirks*/DA_Q_SMR_DM
1323 * MX-ES USB Drive by Mach Xtreme
1325 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1326 /*quirks*/DA_Q_NO_RC16
1330 static disk_strategy_t dastrategy;
1331 static dumper_t dadump;
1332 static periph_init_t dainit;
1333 static void daasync(void *callback_arg, u_int32_t code,
1334 struct cam_path *path, void *arg);
1335 static void dasysctlinit(void *context, int pending);
1336 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1337 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1338 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1339 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1340 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1341 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1342 static void dadeletemethodset(struct da_softc *softc,
1343 da_delete_methods delete_method);
1344 static off_t dadeletemaxsize(struct da_softc *softc,
1345 da_delete_methods delete_method);
1346 static void dadeletemethodchoose(struct da_softc *softc,
1347 da_delete_methods default_method);
1348 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1350 static periph_ctor_t daregister;
1351 static periph_dtor_t dacleanup;
1352 static periph_start_t dastart;
1353 static periph_oninv_t daoninvalidate;
1354 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1355 static void dadone(struct cam_periph *periph,
1356 union ccb *done_ccb);
1357 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1358 u_int32_t sense_flags);
1359 static void daprevent(struct cam_periph *periph, int action);
1360 static void dareprobe(struct cam_periph *periph);
1361 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1363 struct scsi_read_capacity_data_long *rcaplong,
1365 static timeout_t dasendorderedtag;
1366 static void dashutdown(void *arg, int howto);
1367 static timeout_t damediapoll;
1369 #ifndef DA_DEFAULT_POLL_PERIOD
1370 #define DA_DEFAULT_POLL_PERIOD 3
1373 #ifndef DA_DEFAULT_TIMEOUT
1374 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1377 #ifndef DA_DEFAULT_SOFTTIMEOUT
1378 #define DA_DEFAULT_SOFTTIMEOUT 0
1381 #ifndef DA_DEFAULT_RETRY
1382 #define DA_DEFAULT_RETRY 4
1385 #ifndef DA_DEFAULT_SEND_ORDERED
1386 #define DA_DEFAULT_SEND_ORDERED 1
1389 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1390 static int da_retry_count = DA_DEFAULT_RETRY;
1391 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1392 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1393 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1395 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1396 "CAM Direct Access Disk driver");
1397 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1398 &da_poll_period, 0, "Media polling period in seconds");
1399 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1400 &da_retry_count, 0, "Normal I/O retry count");
1401 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1402 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1403 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1404 &da_send_ordered, 0, "Send Ordered Tags");
1406 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1407 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1408 "Soft I/O timeout (ms)");
1409 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1412 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1413 * to the default timeout, we check to see whether an ordered
1414 * tagged transaction is appropriate to prevent simple tag
1415 * starvation. Since we'd like to ensure that there is at least
1416 * 1/2 of the timeout length left for a starved transaction to
1417 * complete after we've sent an ordered tag, we must poll at least
1418 * four times in every timeout period. This takes care of the worst
1419 * case where a starved transaction starts during an interval that
1420 * meets the requirement "don't send an ordered tag" test so it takes
1421 * us two intervals to determine that a tag must be sent.
1423 #ifndef DA_ORDEREDTAG_INTERVAL
1424 #define DA_ORDEREDTAG_INTERVAL 4
1427 static struct periph_driver dadriver =
1430 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1433 PERIPHDRIVER_DECLARE(da, dadriver);
1435 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1438 daopen(struct disk *dp)
1440 struct cam_periph *periph;
1441 struct da_softc *softc;
1444 periph = (struct cam_periph *)dp->d_drv1;
1445 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1449 cam_periph_lock(periph);
1450 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1451 cam_periph_unlock(periph);
1452 cam_periph_release(periph);
1456 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1459 softc = (struct da_softc *)periph->softc;
1462 /* Wait for the disk size update. */
1463 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1466 xpt_print(periph->path, "unable to retrieve capacity data\n");
1468 if (periph->flags & CAM_PERIPH_INVALID)
1471 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1472 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1473 daprevent(periph, PR_PREVENT);
1476 softc->flags &= ~DA_FLAG_PACK_INVALID;
1477 softc->flags |= DA_FLAG_OPEN;
1480 cam_periph_unhold(periph);
1481 cam_periph_unlock(periph);
1484 cam_periph_release(periph);
1490 daclose(struct disk *dp)
1492 struct cam_periph *periph;
1493 struct da_softc *softc;
1497 periph = (struct cam_periph *)dp->d_drv1;
1498 softc = (struct da_softc *)periph->softc;
1499 cam_periph_lock(periph);
1500 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1503 if (cam_periph_hold(periph, PRIBIO) == 0) {
1505 /* Flush disk cache. */
1506 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1507 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1508 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1509 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1510 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1511 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1512 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1514 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1515 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1516 softc->disk->d_devstat);
1517 softc->flags &= ~DA_FLAG_DIRTY;
1518 xpt_release_ccb(ccb);
1521 /* Allow medium removal. */
1522 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1523 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1524 daprevent(periph, PR_ALLOW);
1526 cam_periph_unhold(periph);
1530 * If we've got removeable media, mark the blocksize as
1531 * unavailable, since it could change when new media is
1534 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1535 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1537 softc->flags &= ~DA_FLAG_OPEN;
1538 while (softc->refcount != 0)
1539 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1540 cam_periph_unlock(periph);
1541 cam_periph_release(periph);
1546 daschedule(struct cam_periph *periph)
1548 struct da_softc *softc = (struct da_softc *)periph->softc;
1550 if (softc->state != DA_STATE_NORMAL)
1553 cam_iosched_schedule(softc->cam_iosched, periph);
1557 * Actually translate the requested transfer into one the physical driver
1558 * can understand. The transfer is described by a buf and will include
1559 * only one physical transfer.
1562 dastrategy(struct bio *bp)
1564 struct cam_periph *periph;
1565 struct da_softc *softc;
1567 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1568 softc = (struct da_softc *)periph->softc;
1570 cam_periph_lock(periph);
1573 * If the device has been made invalid, error out
1575 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1576 cam_periph_unlock(periph);
1577 biofinish(bp, NULL, ENXIO);
1581 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1584 * Zone commands must be ordered, because they can depend on the
1585 * effects of previously issued commands, and they may affect
1586 * commands after them.
1588 if (bp->bio_cmd == BIO_ZONE)
1589 bp->bio_flags |= BIO_ORDERED;
1592 * Place it in the queue of disk activities for this disk
1594 cam_iosched_queue_work(softc->cam_iosched, bp);
1597 * Schedule ourselves for performing the work.
1600 cam_periph_unlock(periph);
1606 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1608 struct cam_periph *periph;
1609 struct da_softc *softc;
1611 struct ccb_scsiio csio;
1616 periph = dp->d_drv1;
1617 softc = (struct da_softc *)periph->softc;
1618 cam_periph_lock(periph);
1619 secsize = softc->params.secsize;
1621 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1622 cam_periph_unlock(periph);
1627 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1628 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1629 scsi_read_write(&csio,
1633 /*read*/SCSI_RW_WRITE,
1635 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1638 /*data_ptr*/(u_int8_t *) virtual,
1639 /*dxfer_len*/length,
1640 /*sense_len*/SSD_FULL_SIZE,
1641 da_default_timeout * 1000);
1642 xpt_polled_action((union ccb *)&csio);
1644 error = cam_periph_error((union ccb *)&csio,
1645 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1646 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1647 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1648 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1650 printf("Aborting dump due to I/O error.\n");
1651 cam_periph_unlock(periph);
1656 * Sync the disk cache contents to the physical media.
1658 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1660 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1661 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1662 scsi_synchronize_cache(&csio,
1666 /*begin_lba*/0,/* Cover the whole disk */
1670 xpt_polled_action((union ccb *)&csio);
1672 error = cam_periph_error((union ccb *)&csio,
1673 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1674 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1675 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1676 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1678 xpt_print(periph->path, "Synchronize cache failed\n");
1680 cam_periph_unlock(periph);
1685 dagetattr(struct bio *bp)
1688 struct cam_periph *periph;
1690 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1691 cam_periph_lock(periph);
1692 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1694 cam_periph_unlock(periph);
1696 bp->bio_completed = bp->bio_length;
1706 * Install a global async callback. This callback will
1707 * receive async callbacks like "new device found".
1709 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1711 if (status != CAM_REQ_CMP) {
1712 printf("da: Failed to attach master async callback "
1713 "due to status 0x%x!\n", status);
1714 } else if (da_send_ordered) {
1716 /* Register our shutdown event handler */
1717 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1718 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1719 printf("dainit: shutdown event registration failed!\n");
1724 * Callback from GEOM, called when it has finished cleaning up its
1728 dadiskgonecb(struct disk *dp)
1730 struct cam_periph *periph;
1732 periph = (struct cam_periph *)dp->d_drv1;
1733 cam_periph_release(periph);
1737 daoninvalidate(struct cam_periph *periph)
1739 struct da_softc *softc;
1741 softc = (struct da_softc *)periph->softc;
1744 * De-register any async callbacks.
1746 xpt_register_async(0, daasync, periph, periph->path);
1748 softc->flags |= DA_FLAG_PACK_INVALID;
1750 softc->invalidations++;
1754 * Return all queued I/O with ENXIO.
1755 * XXX Handle any transactions queued to the card
1756 * with XPT_ABORT_CCB.
1758 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
1761 * Tell GEOM that we've gone away, we'll get a callback when it is
1762 * done cleaning up its resources.
1764 disk_gone(softc->disk);
1768 dacleanup(struct cam_periph *periph)
1770 struct da_softc *softc;
1772 softc = (struct da_softc *)periph->softc;
1774 cam_periph_unlock(periph);
1776 cam_iosched_fini(softc->cam_iosched);
1779 * If we can't free the sysctl tree, oh well...
1781 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
1783 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1784 xpt_print(periph->path,
1785 "can't remove sysctl stats context\n");
1787 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1788 xpt_print(periph->path,
1789 "can't remove sysctl context\n");
1792 callout_drain(&softc->mediapoll_c);
1793 disk_destroy(softc->disk);
1794 callout_drain(&softc->sendordered_c);
1795 free(softc, M_DEVBUF);
1796 cam_periph_lock(periph);
1800 daasync(void *callback_arg, u_int32_t code,
1801 struct cam_path *path, void *arg)
1803 struct cam_periph *periph;
1804 struct da_softc *softc;
1806 periph = (struct cam_periph *)callback_arg;
1808 case AC_FOUND_DEVICE:
1810 struct ccb_getdev *cgd;
1813 cgd = (struct ccb_getdev *)arg;
1817 if (cgd->protocol != PROTO_SCSI)
1819 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
1821 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1822 && SID_TYPE(&cgd->inq_data) != T_RBC
1823 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
1824 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
1828 * Allocate a peripheral instance for
1829 * this device and start the probe
1832 status = cam_periph_alloc(daregister, daoninvalidate,
1834 "da", CAM_PERIPH_BIO,
1836 AC_FOUND_DEVICE, cgd);
1838 if (status != CAM_REQ_CMP
1839 && status != CAM_REQ_INPROG)
1840 printf("daasync: Unable to attach to new device "
1841 "due to status 0x%x\n", status);
1844 case AC_ADVINFO_CHANGED:
1848 buftype = (uintptr_t)arg;
1849 if (buftype == CDAI_TYPE_PHYS_PATH) {
1850 struct da_softc *softc;
1852 softc = periph->softc;
1853 disk_attr_changed(softc->disk, "GEOM::physpath",
1858 case AC_UNIT_ATTENTION:
1861 int error_code, sense_key, asc, ascq;
1863 softc = (struct da_softc *)periph->softc;
1864 ccb = (union ccb *)arg;
1867 * Handle all UNIT ATTENTIONs except our own,
1868 * as they will be handled by daerror().
1870 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1871 scsi_extract_sense_ccb(ccb,
1872 &error_code, &sense_key, &asc, &ascq)) {
1873 if (asc == 0x2A && ascq == 0x09) {
1874 xpt_print(ccb->ccb_h.path,
1875 "Capacity data has changed\n");
1876 softc->flags &= ~DA_FLAG_PROBED;
1878 } else if (asc == 0x28 && ascq == 0x00) {
1879 softc->flags &= ~DA_FLAG_PROBED;
1880 disk_media_changed(softc->disk, M_NOWAIT);
1881 } else if (asc == 0x3F && ascq == 0x03) {
1882 xpt_print(ccb->ccb_h.path,
1883 "INQUIRY data has changed\n");
1884 softc->flags &= ~DA_FLAG_PROBED;
1888 cam_periph_async(periph, code, path, arg);
1892 softc = (struct da_softc *)periph->softc;
1893 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
1894 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1895 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
1903 struct ccb_hdr *ccbh;
1905 softc = (struct da_softc *)periph->softc;
1907 * Don't fail on the expected unit attention
1910 softc->flags |= DA_FLAG_RETRY_UA;
1911 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1912 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1915 case AC_INQ_CHANGED:
1916 softc = (struct da_softc *)periph->softc;
1917 softc->flags &= ~DA_FLAG_PROBED;
1923 cam_periph_async(periph, code, path, arg);
1927 dasysctlinit(void *context, int pending)
1929 struct cam_periph *periph;
1930 struct da_softc *softc;
1931 char tmpstr[80], tmpstr2[80];
1932 struct ccb_trans_settings cts;
1934 periph = (struct cam_periph *)context;
1936 * periph was held for us when this task was enqueued
1938 if (periph->flags & CAM_PERIPH_INVALID) {
1939 cam_periph_release(periph);
1943 softc = (struct da_softc *)periph->softc;
1944 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1945 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1947 sysctl_ctx_init(&softc->sysctl_ctx);
1948 softc->flags |= DA_FLAG_SCTX_INIT;
1949 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
1950 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1951 CTLFLAG_RD, 0, tmpstr, "device_index");
1952 if (softc->sysctl_tree == NULL) {
1953 printf("dasysctlinit: unable to allocate sysctl tree\n");
1954 cam_periph_release(periph);
1959 * Now register the sysctl handler, so the user can change the value on
1962 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1963 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
1964 softc, 0, dadeletemethodsysctl, "A",
1965 "BIO_DELETE execution method");
1966 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1967 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1968 softc, 0, dadeletemaxsysctl, "Q",
1969 "Maximum BIO_DELETE size");
1970 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1971 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1972 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1973 "Minimum CDB size");
1975 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1976 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
1977 softc, 0, dazonemodesysctl, "A",
1979 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1980 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
1981 softc, 0, dazonesupsysctl, "A",
1983 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1984 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1985 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
1986 "Optimal Number of Open Sequential Write Preferred Zones");
1987 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1988 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1989 "optimal_nonseq_zones", CTLFLAG_RD,
1990 &softc->optimal_nonseq_zones,
1991 "Optimal Number of Non-Sequentially Written Sequential Write "
1993 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1994 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1995 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
1996 "Maximum Number of Open Sequential Write Required Zones");
1998 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1999 SYSCTL_CHILDREN(softc->sysctl_tree),
2003 &softc->error_inject,
2005 "error_inject leaf");
2007 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2008 SYSCTL_CHILDREN(softc->sysctl_tree),
2014 "Unmapped I/O leaf");
2016 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2017 SYSCTL_CHILDREN(softc->sysctl_tree),
2026 * Add some addressing info.
2028 memset(&cts, 0, sizeof (cts));
2029 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2030 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2031 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2032 cam_periph_lock(periph);
2033 xpt_action((union ccb *)&cts);
2034 cam_periph_unlock(periph);
2035 if (cts.ccb_h.status != CAM_REQ_CMP) {
2036 cam_periph_release(periph);
2039 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2040 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2041 if (fc->valid & CTS_FC_VALID_WWPN) {
2042 softc->wwpn = fc->wwpn;
2043 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2044 SYSCTL_CHILDREN(softc->sysctl_tree),
2045 OID_AUTO, "wwpn", CTLFLAG_RD,
2046 &softc->wwpn, "World Wide Port Name");
2052 * Now add some useful stats.
2053 * XXX These should live in cam_periph and be common to all periphs
2055 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2056 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2057 CTLFLAG_RD, 0, "Statistics");
2058 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2059 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2065 "Transport errors reported by the SIM");
2066 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2067 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2073 "Device timeouts reported by the SIM");
2074 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2075 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2077 "pack_invalidations",
2079 &softc->invalidations,
2081 "Device pack invalidations");
2084 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2085 softc->sysctl_tree);
2087 cam_periph_release(periph);
2091 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2095 struct da_softc *softc;
2097 softc = (struct da_softc *)arg1;
2099 value = softc->disk->d_delmaxsize;
2100 error = sysctl_handle_64(oidp, &value, 0, req);
2101 if ((error != 0) || (req->newptr == NULL))
2104 /* only accept values smaller than the calculated value */
2105 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2108 softc->disk->d_delmaxsize = value;
2114 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2118 value = *(int *)arg1;
2120 error = sysctl_handle_int(oidp, &value, 0, req);
2123 || (req->newptr == NULL))
2127 * Acceptable values here are 6, 10, 12 or 16.
2131 else if ((value > 6)
2134 else if ((value > 10)
2137 else if (value > 12)
2140 *(int *)arg1 = value;
2146 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2151 value = da_default_softtimeout / SBT_1MS;
2153 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2154 if ((error != 0) || (req->newptr == NULL))
2157 /* XXX Should clip this to a reasonable level */
2158 if (value > da_default_timeout * 1000)
2161 da_default_softtimeout = value * SBT_1MS;
2166 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2169 softc->delete_method = delete_method;
2170 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2171 softc->delete_func = da_delete_functions[delete_method];
2173 if (softc->delete_method > DA_DELETE_DISABLE)
2174 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2176 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2180 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2184 switch(delete_method) {
2185 case DA_DELETE_UNMAP:
2186 sectors = (off_t)softc->unmap_max_lba;
2188 case DA_DELETE_ATA_TRIM:
2189 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2191 case DA_DELETE_WS16:
2192 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2194 case DA_DELETE_ZERO:
2195 case DA_DELETE_WS10:
2196 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2202 return (off_t)softc->params.secsize *
2203 omin(sectors, softc->params.sectors);
2207 daprobedone(struct cam_periph *periph, union ccb *ccb)
2209 struct da_softc *softc;
2211 softc = (struct da_softc *)periph->softc;
2213 dadeletemethodchoose(softc, DA_DELETE_NONE);
2215 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2219 snprintf(buf, sizeof(buf), "Delete methods: <");
2221 for (i = 0; i <= DA_DELETE_MAX; i++) {
2222 if ((softc->delete_available & (1 << i)) == 0 &&
2223 i != softc->delete_method)
2226 strlcat(buf, ",", sizeof(buf));
2227 strlcat(buf, da_delete_method_names[i],
2229 if (i == softc->delete_method)
2230 strlcat(buf, "(*)", sizeof(buf));
2233 strlcat(buf, ">", sizeof(buf));
2234 printf("%s%d: %s\n", periph->periph_name,
2235 periph->unit_number, buf);
2239 * Since our peripheral may be invalidated by an error
2240 * above or an external event, we must release our CCB
2241 * before releasing the probe lock on the peripheral.
2242 * The peripheral will only go away once the last lock
2243 * is removed, and we need it around for the CCB release
2246 xpt_release_ccb(ccb);
2247 softc->state = DA_STATE_NORMAL;
2248 softc->flags |= DA_FLAG_PROBED;
2250 wakeup(&softc->disk->d_mediasize);
2251 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2252 softc->flags |= DA_FLAG_ANNOUNCED;
2253 cam_periph_unhold(periph);
2255 cam_periph_release_locked(periph);
2259 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2263 /* If available, prefer the method requested by user. */
2264 i = softc->delete_method_pref;
2265 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2266 if (methods & (1 << i)) {
2267 dadeletemethodset(softc, i);
2271 /* Use the pre-defined order to choose the best performing delete. */
2272 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2273 if (i == DA_DELETE_ZERO)
2275 if (softc->delete_available & (1 << i)) {
2276 dadeletemethodset(softc, i);
2281 /* Fallback to default. */
2282 dadeletemethodset(softc, default_method);
2286 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2290 struct da_softc *softc;
2291 int i, error, methods, value;
2293 softc = (struct da_softc *)arg1;
2295 value = softc->delete_method;
2296 if (value < 0 || value > DA_DELETE_MAX)
2299 p = da_delete_method_names[value];
2300 strncpy(buf, p, sizeof(buf));
2301 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2302 if (error != 0 || req->newptr == NULL)
2304 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2305 for (i = 0; i <= DA_DELETE_MAX; i++) {
2306 if (strcmp(buf, da_delete_method_names[i]) == 0)
2309 if (i > DA_DELETE_MAX)
2311 softc->delete_method_pref = i;
2312 dadeletemethodchoose(softc, DA_DELETE_NONE);
2317 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2320 struct da_softc *softc;
2323 softc = (struct da_softc *)arg1;
2325 switch (softc->zone_mode) {
2326 case DA_ZONE_DRIVE_MANAGED:
2327 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2329 case DA_ZONE_HOST_AWARE:
2330 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2332 case DA_ZONE_HOST_MANAGED:
2333 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2337 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2341 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2347 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2350 struct da_softc *softc;
2355 softc = (struct da_softc *)arg1;
2359 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2361 for (i = 0; i < sizeof(da_zone_desc_table) /
2362 sizeof(da_zone_desc_table[0]); i++) {
2363 if (softc->zone_flags & da_zone_desc_table[i].value) {
2365 sbuf_printf(&sb, ", ");
2368 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2373 sbuf_printf(&sb, "None");
2377 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2383 daregister(struct cam_periph *periph, void *arg)
2385 struct da_softc *softc;
2386 struct ccb_pathinq cpi;
2387 struct ccb_getdev *cgd;
2391 cgd = (struct ccb_getdev *)arg;
2393 printf("daregister: no getdev CCB, can't register device\n");
2394 return(CAM_REQ_CMP_ERR);
2397 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2400 if (softc == NULL) {
2401 printf("daregister: Unable to probe new device. "
2402 "Unable to allocate softc\n");
2403 return(CAM_REQ_CMP_ERR);
2406 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2407 printf("daregister: Unable to probe new device. "
2408 "Unable to allocate iosched memory\n");
2409 free(softc, M_DEVBUF);
2410 return(CAM_REQ_CMP_ERR);
2413 LIST_INIT(&softc->pending_ccbs);
2414 softc->state = DA_STATE_PROBE_RC;
2415 bioq_init(&softc->delete_run_queue);
2416 if (SID_IS_REMOVABLE(&cgd->inq_data))
2417 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2418 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2419 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2420 softc->unmap_gran = 0;
2421 softc->unmap_gran_align = 0;
2422 softc->ws_max_blks = WS16_MAX_BLKS;
2423 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2424 softc->rotating = 1;
2426 periph->softc = softc;
2429 * See if this device has any quirks.
2431 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2432 (caddr_t)da_quirk_table,
2433 nitems(da_quirk_table),
2434 sizeof(*da_quirk_table), scsi_inquiry_match);
2437 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2439 softc->quirks = DA_Q_NONE;
2441 /* Check if the SIM does not want 6 byte commands */
2442 bzero(&cpi, sizeof(cpi));
2443 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2444 cpi.ccb_h.func_code = XPT_PATH_INQ;
2445 xpt_action((union ccb *)&cpi);
2446 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2447 softc->quirks |= DA_Q_NO_6_BYTE;
2449 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2450 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2451 else if (softc->quirks & DA_Q_SMR_DM)
2452 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2454 softc->zone_mode = DA_ZONE_NONE;
2456 if (softc->zone_mode != DA_ZONE_NONE) {
2457 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2458 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2459 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2461 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2463 softc->zone_interface = DA_ZONE_IF_SCSI;
2466 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2469 * Take an exclusive refcount on the periph while dastart is called
2470 * to finish the probe. The reference will be dropped in dadone at
2473 (void)cam_periph_hold(periph, PRIBIO);
2476 * Schedule a periodic event to occasionally send an
2477 * ordered tag to a device.
2479 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2480 callout_reset(&softc->sendordered_c,
2481 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2482 dasendorderedtag, softc);
2484 cam_periph_unlock(periph);
2486 * RBC devices don't have to support READ(6), only READ(10).
2488 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2489 softc->minimum_cmd_size = 10;
2491 softc->minimum_cmd_size = 6;
2494 * Load the user's default, if any.
2496 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2497 periph->unit_number);
2498 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2501 * 6, 10, 12 and 16 are the currently permissible values.
2503 if (softc->minimum_cmd_size > 12)
2504 softc->minimum_cmd_size = 16;
2505 else if (softc->minimum_cmd_size > 10)
2506 softc->minimum_cmd_size = 12;
2507 else if (softc->minimum_cmd_size > 6)
2508 softc->minimum_cmd_size = 10;
2510 softc->minimum_cmd_size = 6;
2512 /* Predict whether device may support READ CAPACITY(16). */
2513 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2514 (softc->quirks & DA_Q_NO_RC16) == 0) {
2515 softc->flags |= DA_FLAG_CAN_RC16;
2516 softc->state = DA_STATE_PROBE_RC16;
2520 * Register this media as a disk.
2522 softc->disk = disk_alloc();
2523 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2524 periph->unit_number, 0,
2525 DEVSTAT_BS_UNAVAILABLE,
2526 SID_TYPE(&cgd->inq_data) |
2527 XPORT_DEVSTAT_TYPE(cpi.transport),
2528 DEVSTAT_PRIORITY_DISK);
2529 softc->disk->d_open = daopen;
2530 softc->disk->d_close = daclose;
2531 softc->disk->d_strategy = dastrategy;
2532 softc->disk->d_dump = dadump;
2533 softc->disk->d_getattr = dagetattr;
2534 softc->disk->d_gone = dadiskgonecb;
2535 softc->disk->d_name = "da";
2536 softc->disk->d_drv1 = periph;
2538 softc->maxio = DFLTPHYS; /* traditional default */
2539 else if (cpi.maxio > MAXPHYS)
2540 softc->maxio = MAXPHYS; /* for safety */
2542 softc->maxio = cpi.maxio;
2543 softc->disk->d_maxsize = softc->maxio;
2544 softc->disk->d_unit = periph->unit_number;
2545 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2546 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2547 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2548 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2549 softc->unmappedio = 1;
2550 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2552 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2553 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2554 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2555 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2556 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2557 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2558 softc->disk->d_hba_vendor = cpi.hba_vendor;
2559 softc->disk->d_hba_device = cpi.hba_device;
2560 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2561 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2564 * Acquire a reference to the periph before we register with GEOM.
2565 * We'll release this reference once GEOM calls us back (via
2566 * dadiskgonecb()) telling us that our provider has been freed.
2568 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2569 xpt_print(periph->path, "%s: lost periph during "
2570 "registration!\n", __func__);
2571 cam_periph_lock(periph);
2572 return (CAM_REQ_CMP_ERR);
2575 disk_create(softc->disk, DISK_VERSION);
2576 cam_periph_lock(periph);
2579 * Add async callbacks for events of interest.
2580 * I don't bother checking if this fails as,
2581 * in most cases, the system will function just
2582 * fine without them and the only alternative
2583 * would be to not attach the device on failure.
2585 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2586 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2587 AC_INQ_CHANGED, daasync, periph, periph->path);
2590 * Emit an attribute changed notification just in case
2591 * physical path information arrived before our async
2592 * event handler was registered, but after anyone attaching
2593 * to our disk device polled it.
2595 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2598 * Schedule a periodic media polling events.
2600 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2601 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2602 (cgd->inq_flags & SID_AEN) == 0 &&
2603 da_poll_period != 0)
2604 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2605 damediapoll, periph);
2607 xpt_schedule(periph, CAM_PRIORITY_DEV);
2609 return(CAM_REQ_CMP);
2613 da_zone_bio_to_scsi(int disk_zone_cmd)
2615 switch (disk_zone_cmd) {
2616 case DISK_ZONE_OPEN:
2617 return ZBC_OUT_SA_OPEN;
2618 case DISK_ZONE_CLOSE:
2619 return ZBC_OUT_SA_CLOSE;
2620 case DISK_ZONE_FINISH:
2621 return ZBC_OUT_SA_FINISH;
2623 return ZBC_OUT_SA_RWP;
2630 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2633 struct da_softc *softc;
2638 if (bp->bio_cmd != BIO_ZONE) {
2643 softc = periph->softc;
2645 switch (bp->bio_zone.zone_cmd) {
2646 case DISK_ZONE_OPEN:
2647 case DISK_ZONE_CLOSE:
2648 case DISK_ZONE_FINISH:
2649 case DISK_ZONE_RWP: {
2654 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2655 if (zone_sa == -1) {
2656 xpt_print(periph->path, "Cannot translate zone "
2657 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2663 lba = bp->bio_zone.zone_params.rwp.id;
2665 if (bp->bio_zone.zone_params.rwp.flags &
2666 DISK_ZONE_RWP_FLAG_ALL)
2667 zone_flags |= ZBC_OUT_ALL;
2669 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2670 scsi_zbc_out(&ccb->csio,
2671 /*retries*/ da_retry_count,
2673 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2674 /*service_action*/ zone_sa,
2676 /*zone_flags*/ zone_flags,
2679 /*sense_len*/ SSD_FULL_SIZE,
2680 /*timeout*/ da_default_timeout * 1000);
2683 * Note that in this case, even though we can
2684 * technically use NCQ, we don't bother for several
2686 * 1. It hasn't been tested on a SAT layer that
2687 * supports it. This is new as of SAT-4.
2688 * 2. Even when there is a SAT layer that supports
2689 * it, that SAT layer will also probably support
2690 * ZBC -> ZAC translation, since they are both
2691 * in the SAT-4 spec.
2692 * 3. Translation will likely be preferable to ATA
2693 * passthrough. LSI / Avago at least single
2694 * steps ATA passthrough commands in the HBA,
2695 * regardless of protocol, so unless that
2696 * changes, there is a performance penalty for
2697 * doing ATA passthrough no matter whether
2698 * you're using NCQ/FPDMA, DMA or PIO.
2699 * 4. It requires a 32-byte CDB, which at least at
2700 * this point in CAM requires a CDB pointer, which
2701 * would require us to allocate an additional bit
2702 * of storage separate from the CCB.
2704 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2705 /*retries*/ da_retry_count,
2707 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2709 /*zm_action*/ zone_sa,
2711 /*zone_flags*/ zone_flags,
2714 /*cdb_storage*/ NULL,
2715 /*cdb_storage_len*/ 0,
2716 /*sense_len*/ SSD_FULL_SIZE,
2717 /*timeout*/ da_default_timeout * 1000);
2720 xpt_print(periph->path,
2721 "scsi_ata_zac_mgmt_out() returned an "
2730 case DISK_ZONE_REPORT_ZONES: {
2732 uint32_t num_entries, alloc_size;
2733 struct disk_zone_report *rep;
2735 rep = &bp->bio_zone.zone_params.report;
2737 num_entries = rep->entries_allocated;
2738 if (num_entries == 0) {
2739 xpt_print(periph->path, "No entries allocated for "
2740 "Report Zones request\n");
2744 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2745 (sizeof(struct scsi_report_zones_desc) * num_entries);
2746 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2747 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2748 if (rz_ptr == NULL) {
2749 xpt_print(periph->path, "Unable to allocate memory "
2750 "for Report Zones request\n");
2755 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2756 scsi_zbc_in(&ccb->csio,
2757 /*retries*/ da_retry_count,
2759 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2760 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2761 /*zone_start_lba*/ rep->starting_id,
2762 /*zone_options*/ rep->rep_options,
2763 /*data_ptr*/ rz_ptr,
2764 /*dxfer_len*/ alloc_size,
2765 /*sense_len*/ SSD_FULL_SIZE,
2766 /*timeout*/ da_default_timeout * 1000);
2769 * Note that in this case, even though we can
2770 * technically use NCQ, we don't bother for several
2772 * 1. It hasn't been tested on a SAT layer that
2773 * supports it. This is new as of SAT-4.
2774 * 2. Even when there is a SAT layer that supports
2775 * it, that SAT layer will also probably support
2776 * ZBC -> ZAC translation, since they are both
2777 * in the SAT-4 spec.
2778 * 3. Translation will likely be preferable to ATA
2779 * passthrough. LSI / Avago at least single
2780 * steps ATA passthrough commands in the HBA,
2781 * regardless of protocol, so unless that
2782 * changes, there is a performance penalty for
2783 * doing ATA passthrough no matter whether
2784 * you're using NCQ/FPDMA, DMA or PIO.
2785 * 4. It requires a 32-byte CDB, which at least at
2786 * this point in CAM requires a CDB pointer, which
2787 * would require us to allocate an additional bit
2788 * of storage separate from the CCB.
2790 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2791 /*retries*/ da_retry_count,
2793 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2795 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2796 /*zone_id*/ rep->starting_id,
2797 /*zone_flags*/ rep->rep_options,
2798 /*data_ptr*/ rz_ptr,
2799 /*dxfer_len*/ alloc_size,
2800 /*cdb_storage*/ NULL,
2801 /*cdb_storage_len*/ 0,
2802 /*sense_len*/ SSD_FULL_SIZE,
2803 /*timeout*/ da_default_timeout * 1000);
2806 xpt_print(periph->path,
2807 "scsi_ata_zac_mgmt_in() returned an "
2814 * For BIO_ZONE, this isn't normally needed. However, it
2815 * is used by devstat_end_transaction_bio() to determine
2816 * how much data was transferred.
2819 * XXX KDM we have a problem. But I'm not sure how to fix
2820 * it. devstat uses bio_bcount - bio_resid to calculate
2821 * the amount of data transferred. The GEOM disk code
2822 * uses bio_length - bio_resid to calculate the amount of
2823 * data in bio_completed. We have different structure
2824 * sizes above and below the ada(4) driver. So, if we
2825 * use the sizes above, the amount transferred won't be
2826 * quite accurate for devstat. If we use different sizes
2827 * for bio_bcount and bio_length (above and below
2828 * respectively), then the residual needs to match one or
2829 * the other. Everything is calculated after the bio
2830 * leaves the driver, so changing the values around isn't
2831 * really an option. For now, just set the count to the
2832 * passed in length. This means that the calculations
2833 * above (e.g. bio_completed) will be correct, but the
2834 * amount of data reported to devstat will be slightly
2835 * under or overstated.
2837 bp->bio_bcount = bp->bio_length;
2843 case DISK_ZONE_GET_PARAMS: {
2844 struct disk_zone_disk_params *params;
2846 params = &bp->bio_zone.zone_params.disk_params;
2847 bzero(params, sizeof(*params));
2849 switch (softc->zone_mode) {
2850 case DA_ZONE_DRIVE_MANAGED:
2851 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
2853 case DA_ZONE_HOST_AWARE:
2854 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
2856 case DA_ZONE_HOST_MANAGED:
2857 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
2861 params->zone_mode = DISK_ZONE_MODE_NONE;
2865 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
2866 params->flags |= DISK_ZONE_DISK_URSWRZ;
2868 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
2869 params->optimal_seq_zones = softc->optimal_seq_zones;
2870 params->flags |= DISK_ZONE_OPT_SEQ_SET;
2873 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
2874 params->optimal_nonseq_zones =
2875 softc->optimal_nonseq_zones;
2876 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
2879 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
2880 params->max_seq_zones = softc->max_seq_zones;
2881 params->flags |= DISK_ZONE_MAX_SEQ_SET;
2883 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
2884 params->flags |= DISK_ZONE_RZ_SUP;
2886 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
2887 params->flags |= DISK_ZONE_OPEN_SUP;
2889 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
2890 params->flags |= DISK_ZONE_CLOSE_SUP;
2892 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
2893 params->flags |= DISK_ZONE_FINISH_SUP;
2895 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
2896 params->flags |= DISK_ZONE_RWP_SUP;
2907 dastart(struct cam_periph *periph, union ccb *start_ccb)
2909 struct da_softc *softc;
2911 softc = (struct da_softc *)periph->softc;
2913 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2916 switch (softc->state) {
2917 case DA_STATE_NORMAL:
2923 bp = cam_iosched_next_bio(softc->cam_iosched);
2925 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2926 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2927 scsi_test_unit_ready(&start_ccb->csio,
2928 /*retries*/ da_retry_count,
2932 da_default_timeout * 1000);
2933 start_ccb->ccb_h.ccb_bp = NULL;
2934 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2935 xpt_action(start_ccb);
2937 xpt_release_ccb(start_ccb);
2941 if (bp->bio_cmd == BIO_DELETE) {
2942 if (softc->delete_func != NULL) {
2943 softc->delete_func(periph, start_ccb, bp);
2946 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
2947 biofinish(bp, NULL, 0);
2952 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2953 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2954 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */
2957 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2958 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2959 softc->flags &= ~DA_FLAG_NEED_OTAG;
2960 softc->flags |= DA_FLAG_WAS_OTAG;
2961 tag_code = MSG_ORDERED_Q_TAG;
2963 tag_code = MSG_SIMPLE_Q_TAG;
2966 switch (bp->bio_cmd) {
2973 biotrack(bp, __func__);
2975 if (bp->bio_cmd == BIO_WRITE) {
2976 softc->flags |= DA_FLAG_DIRTY;
2977 rw_op = SCSI_RW_WRITE;
2979 rw_op = SCSI_RW_READ;
2982 data_ptr = bp->bio_data;
2983 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
2984 rw_op |= SCSI_RW_BIO;
2988 scsi_read_write(&start_ccb->csio,
2989 /*retries*/da_retry_count,
2991 /*tag_action*/tag_code,
2994 softc->minimum_cmd_size,
2995 /*lba*/bp->bio_pblkno,
2996 /*block_count*/bp->bio_bcount /
2997 softc->params.secsize,
2999 /*dxfer_len*/ bp->bio_bcount,
3000 /*sense_len*/SSD_FULL_SIZE,
3001 da_default_timeout * 1000);
3002 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3003 start_ccb->csio.bio = bp;
3009 * BIO_FLUSH doesn't currently communicate
3010 * range data, so we synchronize the cache
3011 * over the whole disk. We also force
3012 * ordered tag semantics the flush applies
3013 * to all previously queued I/O.
3015 scsi_synchronize_cache(&start_ccb->csio,
3022 da_default_timeout*1000);
3025 int error, queue_ccb;
3029 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3031 || (queue_ccb == 0)) {
3032 biofinish(bp, NULL, error);
3033 xpt_release_ccb(start_ccb);
3039 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3040 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3041 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3044 LIST_INSERT_HEAD(&softc->pending_ccbs,
3045 &start_ccb->ccb_h, periph_links.le);
3047 /* We expect a unit attention from this device */
3048 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3049 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3050 softc->flags &= ~DA_FLAG_RETRY_UA;
3053 start_ccb->ccb_h.ccb_bp = bp;
3055 cam_periph_unlock(periph);
3056 xpt_action(start_ccb);
3057 cam_periph_lock(periph);
3060 /* May have more work to do, so ensure we stay scheduled */
3064 case DA_STATE_PROBE_RC:
3066 struct scsi_read_capacity_data *rcap;
3068 rcap = (struct scsi_read_capacity_data *)
3069 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3071 printf("dastart: Couldn't malloc read_capacity data\n");
3072 /* da_free_periph??? */
3075 scsi_read_capacity(&start_ccb->csio,
3076 /*retries*/da_retry_count,
3082 start_ccb->ccb_h.ccb_bp = NULL;
3083 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3084 xpt_action(start_ccb);
3087 case DA_STATE_PROBE_RC16:
3089 struct scsi_read_capacity_data_long *rcaplong;
3091 rcaplong = (struct scsi_read_capacity_data_long *)
3092 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3093 if (rcaplong == NULL) {
3094 printf("dastart: Couldn't malloc read_capacity data\n");
3095 /* da_free_periph??? */
3098 scsi_read_capacity_16(&start_ccb->csio,
3099 /*retries*/ da_retry_count,
3101 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3105 /*rcap_buf*/ (uint8_t *)rcaplong,
3106 /*rcap_buf_len*/ sizeof(*rcaplong),
3107 /*sense_len*/ SSD_FULL_SIZE,
3108 /*timeout*/ da_default_timeout * 1000);
3109 start_ccb->ccb_h.ccb_bp = NULL;
3110 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3111 xpt_action(start_ccb);
3114 case DA_STATE_PROBE_LBP:
3116 struct scsi_vpd_logical_block_prov *lbp;
3118 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3120 * If we get here we don't support any SBC-3 delete
3121 * methods with UNMAP as the Logical Block Provisioning
3122 * VPD page support is required for devices which
3123 * support it according to T10/1799-D Revision 31
3124 * however older revisions of the spec don't mandate
3125 * this so we currently don't remove these methods
3126 * from the available set.
3128 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3132 lbp = (struct scsi_vpd_logical_block_prov *)
3133 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3136 printf("dastart: Couldn't malloc lbp data\n");
3137 /* da_free_periph??? */
3141 scsi_inquiry(&start_ccb->csio,
3142 /*retries*/da_retry_count,
3144 /*tag_action*/MSG_SIMPLE_Q_TAG,
3145 /*inq_buf*/(u_int8_t *)lbp,
3146 /*inq_len*/sizeof(*lbp),
3148 /*page_code*/SVPD_LBP,
3149 /*sense_len*/SSD_MIN_SIZE,
3150 /*timeout*/da_default_timeout * 1000);
3151 start_ccb->ccb_h.ccb_bp = NULL;
3152 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3153 xpt_action(start_ccb);
3156 case DA_STATE_PROBE_BLK_LIMITS:
3158 struct scsi_vpd_block_limits *block_limits;
3160 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3161 /* Not supported skip to next probe */
3162 softc->state = DA_STATE_PROBE_BDC;
3166 block_limits = (struct scsi_vpd_block_limits *)
3167 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3169 if (block_limits == NULL) {
3170 printf("dastart: Couldn't malloc block_limits data\n");
3171 /* da_free_periph??? */
3175 scsi_inquiry(&start_ccb->csio,
3176 /*retries*/da_retry_count,
3178 /*tag_action*/MSG_SIMPLE_Q_TAG,
3179 /*inq_buf*/(u_int8_t *)block_limits,
3180 /*inq_len*/sizeof(*block_limits),
3182 /*page_code*/SVPD_BLOCK_LIMITS,
3183 /*sense_len*/SSD_MIN_SIZE,
3184 /*timeout*/da_default_timeout * 1000);
3185 start_ccb->ccb_h.ccb_bp = NULL;
3186 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3187 xpt_action(start_ccb);
3190 case DA_STATE_PROBE_BDC:
3192 struct scsi_vpd_block_characteristics *bdc;
3194 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3195 softc->state = DA_STATE_PROBE_ATA;
3199 bdc = (struct scsi_vpd_block_characteristics *)
3200 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3203 printf("dastart: Couldn't malloc bdc data\n");
3204 /* da_free_periph??? */
3208 scsi_inquiry(&start_ccb->csio,
3209 /*retries*/da_retry_count,
3211 /*tag_action*/MSG_SIMPLE_Q_TAG,
3212 /*inq_buf*/(u_int8_t *)bdc,
3213 /*inq_len*/sizeof(*bdc),
3215 /*page_code*/SVPD_BDC,
3216 /*sense_len*/SSD_MIN_SIZE,
3217 /*timeout*/da_default_timeout * 1000);
3218 start_ccb->ccb_h.ccb_bp = NULL;
3219 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3220 xpt_action(start_ccb);
3223 case DA_STATE_PROBE_ATA:
3225 struct ata_params *ata_params;
3227 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3228 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3229 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3231 * Note that if the ATA VPD page isn't
3232 * supported, we aren't talking to an ATA
3233 * device anyway. Support for that VPD
3234 * page is mandatory for SCSI to ATA (SAT)
3235 * translation layers.
3237 softc->state = DA_STATE_PROBE_ZONE;
3240 daprobedone(periph, start_ccb);
3244 ata_params = (struct ata_params*)
3245 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3247 if (ata_params == NULL) {
3248 xpt_print(periph->path, "Couldn't malloc ata_params "
3250 /* da_free_periph??? */
3254 scsi_ata_identify(&start_ccb->csio,
3255 /*retries*/da_retry_count,
3257 /*tag_action*/MSG_SIMPLE_Q_TAG,
3258 /*data_ptr*/(u_int8_t *)ata_params,
3259 /*dxfer_len*/sizeof(*ata_params),
3260 /*sense_len*/SSD_FULL_SIZE,
3261 /*timeout*/da_default_timeout * 1000);
3262 start_ccb->ccb_h.ccb_bp = NULL;
3263 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3264 xpt_action(start_ccb);
3267 case DA_STATE_PROBE_ATA_LOGDIR:
3269 struct ata_gp_log_dir *log_dir;
3274 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3276 * If we don't have log support, not much point in
3277 * trying to probe zone support.
3279 daprobedone(periph, start_ccb);
3284 * If we have an ATA device (the SCSI ATA Information VPD
3285 * page should be present and the ATA identify should have
3286 * succeeded) and it supports logs, ask for the log directory.
3289 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3290 if (log_dir == NULL) {
3291 xpt_print(periph->path, "Couldn't malloc log_dir "
3293 daprobedone(periph, start_ccb);
3297 retval = scsi_ata_read_log(&start_ccb->csio,
3298 /*retries*/ da_retry_count,
3300 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3301 /*log_address*/ ATA_LOG_DIRECTORY,
3304 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3305 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3306 /*data_ptr*/ (uint8_t *)log_dir,
3307 /*dxfer_len*/ sizeof(*log_dir),
3308 /*sense_len*/ SSD_FULL_SIZE,
3309 /*timeout*/ da_default_timeout * 1000);
3312 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3313 free(log_dir, M_SCSIDA);
3314 daprobedone(periph, start_ccb);
3317 start_ccb->ccb_h.ccb_bp = NULL;
3318 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3319 xpt_action(start_ccb);
3322 case DA_STATE_PROBE_ATA_IDDIR:
3324 struct ata_identify_log_pages *id_dir;
3330 * Check here to see whether the Identify Device log is
3331 * supported in the directory of logs. If so, continue
3332 * with requesting the log of identify device pages.
3334 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3335 daprobedone(periph, start_ccb);
3339 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3340 if (id_dir == NULL) {
3341 xpt_print(periph->path, "Couldn't malloc id_dir "
3343 daprobedone(periph, start_ccb);
3347 retval = scsi_ata_read_log(&start_ccb->csio,
3348 /*retries*/ da_retry_count,
3350 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3351 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3352 /*page_number*/ ATA_IDL_PAGE_LIST,
3354 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3355 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3356 /*data_ptr*/ (uint8_t *)id_dir,
3357 /*dxfer_len*/ sizeof(*id_dir),
3358 /*sense_len*/ SSD_FULL_SIZE,
3359 /*timeout*/ da_default_timeout * 1000);
3362 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3363 free(id_dir, M_SCSIDA);
3364 daprobedone(periph, start_ccb);
3367 start_ccb->ccb_h.ccb_bp = NULL;
3368 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3369 xpt_action(start_ccb);
3372 case DA_STATE_PROBE_ATA_SUP:
3374 struct ata_identify_log_sup_cap *sup_cap;
3380 * Check here to see whether the Supported Capabilities log
3381 * is in the list of Identify Device logs.
3383 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3384 daprobedone(periph, start_ccb);
3388 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3389 if (sup_cap == NULL) {
3390 xpt_print(periph->path, "Couldn't malloc sup_cap "
3392 daprobedone(periph, start_ccb);
3396 retval = scsi_ata_read_log(&start_ccb->csio,
3397 /*retries*/ da_retry_count,
3399 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3400 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3401 /*page_number*/ ATA_IDL_SUP_CAP,
3403 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3404 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3405 /*data_ptr*/ (uint8_t *)sup_cap,
3406 /*dxfer_len*/ sizeof(*sup_cap),
3407 /*sense_len*/ SSD_FULL_SIZE,
3408 /*timeout*/ da_default_timeout * 1000);
3411 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3412 free(sup_cap, M_SCSIDA);
3413 daprobedone(periph, start_ccb);
3418 start_ccb->ccb_h.ccb_bp = NULL;
3419 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3420 xpt_action(start_ccb);
3423 case DA_STATE_PROBE_ATA_ZONE:
3425 struct ata_zoned_info_log *ata_zone;
3431 * Check here to see whether the zoned device information
3432 * page is supported. If so, continue on to request it.
3433 * If not, skip to DA_STATE_PROBE_LOG or done.
3435 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3436 daprobedone(periph, start_ccb);
3439 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3441 if (ata_zone == NULL) {
3442 xpt_print(periph->path, "Couldn't malloc ata_zone "
3444 daprobedone(periph, start_ccb);
3448 retval = scsi_ata_read_log(&start_ccb->csio,
3449 /*retries*/ da_retry_count,
3451 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3452 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3453 /*page_number*/ ATA_IDL_ZDI,
3455 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3456 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3457 /*data_ptr*/ (uint8_t *)ata_zone,
3458 /*dxfer_len*/ sizeof(*ata_zone),
3459 /*sense_len*/ SSD_FULL_SIZE,
3460 /*timeout*/ da_default_timeout * 1000);
3463 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3464 free(ata_zone, M_SCSIDA);
3465 daprobedone(periph, start_ccb);
3468 start_ccb->ccb_h.ccb_bp = NULL;
3469 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3470 xpt_action(start_ccb);
3474 case DA_STATE_PROBE_ZONE:
3476 struct scsi_vpd_zoned_bdc *bdc;
3479 * Note that this page will be supported for SCSI protocol
3480 * devices that support ZBC (SMR devices), as well as ATA
3481 * protocol devices that are behind a SAT (SCSI to ATA
3482 * Translation) layer that supports converting ZBC commands
3483 * to their ZAC equivalents.
3485 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3486 daprobedone(periph, start_ccb);
3489 bdc = (struct scsi_vpd_zoned_bdc *)
3490 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3493 xpt_release_ccb(start_ccb);
3494 xpt_print(periph->path, "Couldn't malloc zone VPD "
3498 scsi_inquiry(&start_ccb->csio,
3499 /*retries*/da_retry_count,
3501 /*tag_action*/MSG_SIMPLE_Q_TAG,
3502 /*inq_buf*/(u_int8_t *)bdc,
3503 /*inq_len*/sizeof(*bdc),
3505 /*page_code*/SVPD_ZONED_BDC,
3506 /*sense_len*/SSD_FULL_SIZE,
3507 /*timeout*/da_default_timeout * 1000);
3508 start_ccb->ccb_h.ccb_bp = NULL;
3509 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3510 xpt_action(start_ccb);
3517 * In each of the methods below, while its the caller's
3518 * responsibility to ensure the request will fit into a
3519 * single device request, we might have changed the delete
3520 * method due to the device incorrectly advertising either
3521 * its supported methods or limits.
3523 * To prevent this causing further issues we validate the
3524 * against the methods limits, and warn which would
3525 * otherwise be unnecessary.
3528 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3530 struct da_softc *softc = (struct da_softc *)periph->softc;;
3532 uint8_t *buf = softc->unmap_buf;
3533 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3534 uint64_t lba, lastlba = (uint64_t)-1;
3535 uint64_t totalcount = 0;
3537 uint32_t c, lastcount = 0, ranges = 0;
3540 * Currently this doesn't take the UNMAP
3541 * Granularity and Granularity Alignment
3542 * fields into account.
3544 * This could result in both unoptimal unmap
3545 * requests as as well as UNMAP calls unmapping
3546 * fewer LBA's than requested.
3549 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3553 * Note: ada and da are different in how they store the
3554 * pending bp's in a trim. ada stores all of them in the
3555 * trim_req.bps. da stores all but the first one in the
3556 * delete_run_queue. ada then completes all the bps in
3557 * its adadone() loop. da completes all the bps in the
3558 * delete_run_queue in dadone, and relies on the biodone
3559 * after to complete. This should be reconciled since there's
3560 * no real reason to do it differently. XXX
3563 bioq_insert_tail(&softc->delete_run_queue, bp1);
3564 lba = bp1->bio_pblkno;
3565 count = bp1->bio_bcount / softc->params.secsize;
3567 /* Try to extend the previous range. */
3568 if (lba == lastlba) {
3569 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3572 scsi_ulto4b(lastcount, d[ranges - 1].length);
3576 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3577 softc->unmap_gran != 0) {
3578 /* Align length of the previous range. */
3579 if ((c = lastcount % softc->unmap_gran) != 0) {
3580 if (lastcount <= c) {
3581 totalcount -= lastcount;
3582 lastlba = (uint64_t)-1;
3589 scsi_ulto4b(lastcount, d[ranges - 1].length);
3592 /* Align beginning of the new range. */
3593 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3595 c = softc->unmap_gran - c;
3606 c = omin(count, UNMAP_RANGE_MAX);
3607 if (totalcount + c > softc->unmap_max_lba ||
3608 ranges >= softc->unmap_max_ranges) {
3609 xpt_print(periph->path,
3610 "%s issuing short delete %ld > %ld"
3612 da_delete_method_desc[softc->delete_method],
3613 totalcount + c, softc->unmap_max_lba,
3614 ranges, softc->unmap_max_ranges);
3617 scsi_u64to8b(lba, d[ranges].lba);
3618 scsi_ulto4b(c, d[ranges].length);
3626 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3629 if (ranges >= softc->unmap_max_ranges ||
3630 totalcount + bp1->bio_bcount /
3631 softc->params.secsize > softc->unmap_max_lba) {
3632 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3637 /* Align length of the last range. */
3638 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
3639 (c = lastcount % softc->unmap_gran) != 0) {
3643 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
3646 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3647 scsi_ulto2b(ranges * 16, &buf[2]);
3649 scsi_unmap(&ccb->csio,
3650 /*retries*/da_retry_count,
3652 /*tag_action*/MSG_SIMPLE_Q_TAG,
3655 /*dxfer_len*/ ranges * 16 + 8,
3656 /*sense_len*/SSD_FULL_SIZE,
3657 da_default_timeout * 1000);
3658 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3659 ccb->ccb_h.flags |= CAM_UNLOCKED;
3660 cam_iosched_submit_trim(softc->cam_iosched);
3664 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3666 struct da_softc *softc = (struct da_softc *)periph->softc;
3668 uint8_t *buf = softc->unmap_buf;
3669 uint64_t lastlba = (uint64_t)-1;
3672 uint32_t lastcount = 0, c, requestcount;
3673 int ranges = 0, off, block_count;
3675 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3678 if (bp1 != bp)//XXX imp XXX
3679 bioq_insert_tail(&softc->delete_run_queue, bp1);
3680 lba = bp1->bio_pblkno;
3681 count = bp1->bio_bcount / softc->params.secsize;
3682 requestcount = count;
3684 /* Try to extend the previous range. */
3685 if (lba == lastlba) {
3686 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3688 off = (ranges - 1) * 8;
3689 buf[off + 6] = lastcount & 0xff;
3690 buf[off + 7] = (lastcount >> 8) & 0xff;
3696 c = omin(count, ATA_DSM_RANGE_MAX);
3699 buf[off + 0] = lba & 0xff;
3700 buf[off + 1] = (lba >> 8) & 0xff;
3701 buf[off + 2] = (lba >> 16) & 0xff;
3702 buf[off + 3] = (lba >> 24) & 0xff;
3703 buf[off + 4] = (lba >> 32) & 0xff;
3704 buf[off + 5] = (lba >> 40) & 0xff;
3705 buf[off + 6] = c & 0xff;
3706 buf[off + 7] = (c >> 8) & 0xff;
3711 if (count != 0 && ranges == softc->trim_max_ranges) {
3712 xpt_print(periph->path,
3713 "%s issuing short delete %ld > %ld\n",
3714 da_delete_method_desc[softc->delete_method],
3716 (softc->trim_max_ranges - ranges) *
3722 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3725 if (bp1->bio_bcount / softc->params.secsize >
3726 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3727 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3732 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3733 scsi_ata_trim(&ccb->csio,
3734 /*retries*/da_retry_count,
3736 /*tag_action*/MSG_SIMPLE_Q_TAG,
3739 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3740 /*sense_len*/SSD_FULL_SIZE,
3741 da_default_timeout * 1000);
3742 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3743 ccb->ccb_h.flags |= CAM_UNLOCKED;
3744 cam_iosched_submit_trim(softc->cam_iosched);
3748 * We calculate ws_max_blks here based off d_delmaxsize instead
3749 * of using softc->ws_max_blks as it is absolute max for the
3750 * device not the protocol max which may well be lower.
3753 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3755 struct da_softc *softc;
3757 uint64_t ws_max_blks;
3759 uint64_t count; /* forward compat with WS32 */
3761 softc = (struct da_softc *)periph->softc;
3762 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3763 lba = bp->bio_pblkno;
3767 if (bp1 != bp)//XXX imp XXX
3768 bioq_insert_tail(&softc->delete_run_queue, bp1);
3769 count += bp1->bio_bcount / softc->params.secsize;
3770 if (count > ws_max_blks) {
3771 xpt_print(periph->path,
3772 "%s issuing short delete %ld > %ld\n",
3773 da_delete_method_desc[softc->delete_method],
3774 count, ws_max_blks);
3775 count = omin(count, ws_max_blks);
3778 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3781 if (lba + count != bp1->bio_pblkno ||
3782 count + bp1->bio_bcount /
3783 softc->params.secsize > ws_max_blks) {
3784 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3789 scsi_write_same(&ccb->csio,
3790 /*retries*/da_retry_count,
3792 /*tag_action*/MSG_SIMPLE_Q_TAG,
3793 /*byte2*/softc->delete_method ==
3794 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3795 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3797 /*block_count*/count,
3798 /*data_ptr*/ __DECONST(void *, zero_region),
3799 /*dxfer_len*/ softc->params.secsize,
3800 /*sense_len*/SSD_FULL_SIZE,
3801 da_default_timeout * 1000);
3802 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3803 ccb->ccb_h.flags |= CAM_UNLOCKED;
3804 cam_iosched_submit_trim(softc->cam_iosched);
3808 cmd6workaround(union ccb *ccb)
3810 struct scsi_rw_6 cmd6;
3811 struct scsi_rw_10 *cmd10;
3812 struct da_softc *softc;
3817 cdb = ccb->csio.cdb_io.cdb_bytes;
3818 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3820 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3821 da_delete_methods old_method = softc->delete_method;
3824 * Typically there are two reasons for failure here
3825 * 1. Delete method was detected as supported but isn't
3826 * 2. Delete failed due to invalid params e.g. too big
3828 * While we will attempt to choose an alternative delete method
3829 * this may result in short deletes if the existing delete
3830 * requests from geom are big for the new method chosen.
3832 * This method assumes that the error which triggered this
3833 * will not retry the io otherwise a panic will occur
3835 dadeleteflag(softc, old_method, 0);
3836 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3837 if (softc->delete_method == DA_DELETE_DISABLE)
3838 xpt_print(ccb->ccb_h.path,
3839 "%s failed, disabling BIO_DELETE\n",
3840 da_delete_method_desc[old_method]);
3842 xpt_print(ccb->ccb_h.path,
3843 "%s failed, switching to %s BIO_DELETE\n",
3844 da_delete_method_desc[old_method],
3845 da_delete_method_desc[softc->delete_method]);
3847 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3848 cam_iosched_queue_work(softc->cam_iosched, bp);
3849 cam_iosched_queue_work(softc->cam_iosched,
3850 (struct bio *)ccb->ccb_h.ccb_bp);
3851 ccb->ccb_h.ccb_bp = NULL;
3855 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3856 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3857 (*cdb == PREVENT_ALLOW) &&
3858 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3860 xpt_print(ccb->ccb_h.path,
3861 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3862 softc->quirks |= DA_Q_NO_PREVENT;
3866 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3867 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3868 (*cdb == SYNCHRONIZE_CACHE) &&
3869 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3871 xpt_print(ccb->ccb_h.path,
3872 "SYNCHRONIZE CACHE(10) not supported.\n");
3873 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3874 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3878 /* Translation only possible if CDB is an array and cmd is R/W6 */
3879 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3880 (*cdb != READ_6 && *cdb != WRITE_6))
3883 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3884 "increasing minimum_cmd_size to 10.\n");
3885 softc->minimum_cmd_size = 10;
3887 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3888 cmd10 = (struct scsi_rw_10 *)cdb;
3889 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3891 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3892 cmd10->reserved = 0;
3893 scsi_ulto2b(cmd6.length, cmd10->length);
3894 cmd10->control = cmd6.control;
3895 ccb->csio.cdb_len = sizeof(*cmd10);
3897 /* Requeue request, unfreezing queue if necessary */
3898 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3899 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3902 cam_release_devq(ccb->ccb_h.path,
3906 /*getcount_only*/0);
3912 dazonedone(struct cam_periph *periph, union ccb *ccb)
3914 struct da_softc *softc;
3917 softc = periph->softc;
3918 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3920 switch (bp->bio_zone.zone_cmd) {
3921 case DISK_ZONE_OPEN:
3922 case DISK_ZONE_CLOSE:
3923 case DISK_ZONE_FINISH:
3926 case DISK_ZONE_REPORT_ZONES: {
3928 struct disk_zone_report *rep;
3929 struct scsi_report_zones_hdr *hdr;
3930 struct scsi_report_zones_desc *desc;
3931 struct disk_zone_rep_entry *entry;
3932 uint32_t num_alloced, hdr_len, num_avail;
3933 uint32_t num_to_fill, i;
3936 rep = &bp->bio_zone.zone_params.report;
3937 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
3939 * Note that bio_resid isn't normally used for zone
3940 * commands, but it is used by devstat_end_transaction_bio()
3941 * to determine how much data was transferred. Because
3942 * the size of the SCSI/ATA data structures is different
3943 * than the size of the BIO interface structures, the
3944 * amount of data actually transferred from the drive will
3945 * be different than the amount of data transferred to
3948 bp->bio_resid = ccb->csio.resid;
3949 num_alloced = rep->entries_allocated;
3950 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
3951 if (avail_len < sizeof(*hdr)) {
3953 * Is there a better error than EIO here? We asked
3954 * for at least the header, and we got less than
3957 bp->bio_error = EIO;
3958 bp->bio_flags |= BIO_ERROR;
3959 bp->bio_resid = bp->bio_bcount;
3963 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
3968 hdr_len = ata ? le32dec(hdr->length) :
3969 scsi_4btoul(hdr->length);
3971 rep->entries_available = hdr_len / sizeof(*desc);
3973 rep->entries_available = 0;
3975 * NOTE: using the same values for the BIO version of the
3976 * same field as the SCSI/ATA values. This means we could
3977 * get some additional values that aren't defined in bio.h
3978 * if more values of the same field are defined later.
3980 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
3981 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
3982 scsi_8btou64(hdr->maximum_lba);
3984 * If the drive reports no entries that match the query,
3988 rep->entries_filled = 0;
3992 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
3993 hdr_len / sizeof(*desc));
3995 * If the drive didn't return any data, then we're done.
3997 if (num_avail == 0) {
3998 rep->entries_filled = 0;
4002 num_to_fill = min(num_avail, rep->entries_allocated);
4004 * If the user didn't allocate any entries for us to fill,
4007 if (num_to_fill == 0) {
4008 rep->entries_filled = 0;
4012 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4013 i < num_to_fill; i++, desc++, entry++) {
4015 * NOTE: we're mapping the values here directly
4016 * from the SCSI/ATA bit definitions to the bio.h
4017 * definitons. There is also a warning in
4018 * disk_zone.h, but the impact is that if
4019 * additional values are added in the SCSI/ATA
4020 * specs these will be visible to consumers of
4023 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4024 entry->zone_condition =
4025 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4026 SRZ_ZONE_COND_SHIFT;
4027 entry->zone_flags |= desc->zone_flags &
4028 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4029 entry->zone_length =
4030 ata ? le64dec(desc->zone_length) :
4031 scsi_8btou64(desc->zone_length);
4032 entry->zone_start_lba =
4033 ata ? le64dec(desc->zone_start_lba) :
4034 scsi_8btou64(desc->zone_start_lba);
4035 entry->write_pointer_lba =
4036 ata ? le64dec(desc->write_pointer_lba) :
4037 scsi_8btou64(desc->write_pointer_lba);
4039 rep->entries_filled = num_to_fill;
4042 case DISK_ZONE_GET_PARAMS:
4045 * In theory we should not get a GET_PARAMS bio, since it
4046 * should be handled without queueing the command to the
4049 panic("%s: Invalid zone command %d", __func__,
4050 bp->bio_zone.zone_cmd);
4054 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4055 free(ccb->csio.data_ptr, M_SCSIDA);
4059 dadone(struct cam_periph *periph, union ccb *done_ccb)
4061 struct da_softc *softc;
4062 struct ccb_scsiio *csio;
4066 softc = (struct da_softc *)periph->softc;
4067 priority = done_ccb->ccb_h.pinfo.priority;
4069 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4071 csio = &done_ccb->csio;
4072 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4073 if (csio->bio != NULL)
4074 biotrack(csio->bio, __func__);
4076 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4078 case DA_CCB_BUFFER_IO:
4081 struct bio *bp, *bp1;
4083 cam_periph_lock(periph);
4084 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4085 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4089 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4094 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4095 if (error == ERESTART) {
4097 * A retry was scheduled, so
4100 cam_periph_unlock(periph);
4103 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4108 * return all queued I/O with EIO, so that
4109 * the client can retry these I/Os in the
4110 * proper order should it attempt to recover.
4115 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4117 * Catastrophic error. Mark our pack as
4121 * XXX See if this is really a media
4124 xpt_print(periph->path,
4125 "Invalidating pack\n");
4126 softc->flags |= DA_FLAG_PACK_INVALID;
4128 softc->invalidations++;
4130 queued_error = ENXIO;
4132 cam_iosched_flush(softc->cam_iosched, NULL,
4135 bp->bio_error = error;
4136 bp->bio_resid = bp->bio_bcount;
4137 bp->bio_flags |= BIO_ERROR;
4139 } else if (bp != NULL) {
4140 if (state == DA_CCB_DELETE)
4143 bp->bio_resid = csio->resid;
4145 if (bp->bio_resid != 0)
4146 bp->bio_flags |= BIO_ERROR;
4148 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4149 cam_release_devq(done_ccb->ccb_h.path,
4153 /*getcount_only*/0);
4154 } else if (bp != NULL) {
4155 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4156 panic("REQ_CMP with QFRZN");
4157 if (bp->bio_cmd == BIO_ZONE)
4158 dazonedone(periph, done_ccb);
4159 else if (state == DA_CCB_DELETE)
4162 bp->bio_resid = csio->resid;
4163 if ((csio->resid > 0)
4164 && (bp->bio_cmd != BIO_ZONE))
4165 bp->bio_flags |= BIO_ERROR;
4166 if (softc->error_inject != 0) {
4167 bp->bio_error = softc->error_inject;
4168 bp->bio_resid = bp->bio_bcount;
4169 bp->bio_flags |= BIO_ERROR;
4170 softc->error_inject = 0;
4175 biotrack(bp, __func__);
4176 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4177 if (LIST_EMPTY(&softc->pending_ccbs))
4178 softc->flags |= DA_FLAG_WAS_OTAG;
4180 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4181 xpt_release_ccb(done_ccb);
4182 if (state == DA_CCB_DELETE) {
4183 TAILQ_HEAD(, bio) queue;
4186 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4187 softc->delete_run_queue.insert_point = NULL;
4189 * Normally, the xpt_release_ccb() above would make sure
4190 * that when we have more work to do, that work would
4191 * get kicked off. However, we specifically keep
4192 * delete_running set to 0 before the call above to
4193 * allow other I/O to progress when many BIO_DELETE
4194 * requests are pushed down. We set delete_running to 0
4195 * and call daschedule again so that we don't stall if
4196 * there are no other I/Os pending apart from BIO_DELETEs.
4198 cam_iosched_trim_done(softc->cam_iosched);
4200 cam_periph_unlock(periph);
4201 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4202 TAILQ_REMOVE(&queue, bp1, bio_queue);
4203 bp1->bio_error = bp->bio_error;
4204 if (bp->bio_flags & BIO_ERROR) {
4205 bp1->bio_flags |= BIO_ERROR;
4206 bp1->bio_resid = bp1->bio_bcount;
4213 cam_periph_unlock(periph);
4219 case DA_CCB_PROBE_RC:
4220 case DA_CCB_PROBE_RC16:
4222 struct scsi_read_capacity_data *rdcap;
4223 struct scsi_read_capacity_data_long *rcaplong;
4230 /* XXX TODO: can this be a malloc? */
4231 announce_buf = softc->announce_temp;
4232 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4234 if (state == DA_CCB_PROBE_RC)
4235 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4237 rcaplong = (struct scsi_read_capacity_data_long *)
4240 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4241 struct disk_params *dp;
4242 uint32_t block_size;
4244 u_int lalba; /* Lowest aligned LBA. */
4246 if (state == DA_CCB_PROBE_RC) {
4247 block_size = scsi_4btoul(rdcap->length);
4248 maxsector = scsi_4btoul(rdcap->addr);
4252 * According to SBC-2, if the standard 10
4253 * byte READ CAPACITY command returns 2^32,
4254 * we should issue the 16 byte version of
4255 * the command, since the device in question
4256 * has more sectors than can be represented
4257 * with the short version of the command.
4259 if (maxsector == 0xffffffff) {
4260 free(rdcap, M_SCSIDA);
4261 xpt_release_ccb(done_ccb);
4262 softc->state = DA_STATE_PROBE_RC16;
4263 xpt_schedule(periph, priority);
4267 block_size = scsi_4btoul(rcaplong->length);
4268 maxsector = scsi_8btou64(rcaplong->addr);
4269 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4273 * Because GEOM code just will panic us if we
4274 * give them an 'illegal' value we'll avoid that
4277 if (block_size == 0) {
4282 if (block_size >= MAXPHYS) {
4283 xpt_print(periph->path,
4284 "unsupportable block size %ju\n",
4285 (uintmax_t) block_size);
4286 announce_buf = NULL;
4287 cam_periph_invalidate(periph);
4290 * We pass rcaplong into dasetgeom(),
4291 * because it will only use it if it is
4294 dasetgeom(periph, block_size, maxsector,
4295 rcaplong, sizeof(*rcaplong));
4296 lbp = (lalba & SRC16_LBPME_A);
4297 dp = &softc->params;
4298 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4299 "%juMB (%ju %u byte sectors)",
4300 ((uintmax_t)dp->secsize * dp->sectors) /
4302 (uintmax_t)dp->sectors, dp->secsize);
4308 * Retry any UNIT ATTENTION type errors. They
4309 * are expected at boot.
4311 error = daerror(done_ccb, CAM_RETRY_SELTO,
4312 SF_RETRY_UA|SF_NO_PRINT);
4313 if (error == ERESTART) {
4315 * A retry was scheuled, so
4319 } else if (error != 0) {
4321 int sense_key, error_code;
4324 struct ccb_getdev cgd;
4326 /* Don't wedge this device's queue */
4327 status = done_ccb->ccb_h.status;
4328 if ((status & CAM_DEV_QFRZN) != 0)
4329 cam_release_devq(done_ccb->ccb_h.path,
4333 /*getcount_only*/0);
4336 xpt_setup_ccb(&cgd.ccb_h,
4337 done_ccb->ccb_h.path,
4338 CAM_PRIORITY_NORMAL);
4339 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4340 xpt_action((union ccb *)&cgd);
4342 if (scsi_extract_sense_ccb(done_ccb,
4343 &error_code, &sense_key, &asc, &ascq))
4349 * If we tried READ CAPACITY(16) and failed,
4350 * fallback to READ CAPACITY(10).
4352 if ((state == DA_CCB_PROBE_RC16) &&
4353 (softc->flags & DA_FLAG_CAN_RC16) &&
4354 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4357 (error_code == SSD_CURRENT_ERROR) &&
4358 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4359 softc->flags &= ~DA_FLAG_CAN_RC16;
4360 free(rdcap, M_SCSIDA);
4361 xpt_release_ccb(done_ccb);
4362 softc->state = DA_STATE_PROBE_RC;
4363 xpt_schedule(periph, priority);
4368 * Attach to anything that claims to be a
4369 * direct access or optical disk device,
4370 * as long as it doesn't return a "Logical
4371 * unit not supported" (0x25) error.
4372 * "Internal Target Failure" (0x44) is also
4373 * special and typically means that the
4374 * device is a SATA drive behind a SATL
4375 * translation that's fallen into a
4376 * terminally fatal state.
4379 && (asc != 0x25) && (asc != 0x44)
4380 && (error_code == SSD_CURRENT_ERROR)) {
4381 const char *sense_key_desc;
4382 const char *asc_desc;
4384 dasetgeom(periph, 512, -1, NULL, 0);
4385 scsi_sense_desc(sense_key, asc, ascq,
4389 snprintf(announce_buf,
4391 "Attempt to query device "
4392 "size failed: %s, %s",
4393 sense_key_desc, asc_desc);
4399 xpt_print(periph->path,
4400 "got CAM status %#x\n",
4401 done_ccb->ccb_h.status);
4404 xpt_print(periph->path, "fatal error, "
4405 "failed to attach to device\n");
4407 announce_buf = NULL;
4410 * Free up resources.
4412 cam_periph_invalidate(periph);
4416 free(csio->data_ptr, M_SCSIDA);
4417 if (announce_buf != NULL &&
4418 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4421 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4423 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4424 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4430 * Create our sysctl variables, now that we know
4431 * we have successfully attached.
4433 /* increase the refcount */
4434 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4436 taskqueue_enqueue(taskqueue_thread,
4437 &softc->sysctl_task);
4439 /* XXX This message is useless! */
4440 xpt_print(periph->path, "fatal error, "
4441 "could not acquire reference count\n");
4445 /* We already probed the device. */
4446 if (softc->flags & DA_FLAG_PROBED) {
4447 daprobedone(periph, done_ccb);
4451 /* Ensure re-probe doesn't see old delete. */
4452 softc->delete_available = 0;
4453 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4454 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4456 * Based on older SBC-3 spec revisions
4457 * any of the UNMAP methods "may" be
4458 * available via LBP given this flag so
4459 * we flag all of them as available and
4460 * then remove those which further
4461 * probes confirm aren't available
4464 * We could also check readcap(16) p_type
4465 * flag to exclude one or more invalid
4466 * write same (X) types here
4468 dadeleteflag(softc, DA_DELETE_WS16, 1);
4469 dadeleteflag(softc, DA_DELETE_WS10, 1);
4470 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4472 xpt_release_ccb(done_ccb);
4473 softc->state = DA_STATE_PROBE_LBP;
4474 xpt_schedule(periph, priority);
4478 xpt_release_ccb(done_ccb);
4479 softc->state = DA_STATE_PROBE_BDC;
4480 xpt_schedule(periph, priority);
4483 case DA_CCB_PROBE_LBP:
4485 struct scsi_vpd_logical_block_prov *lbp;
4487 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4489 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4491 * T10/1799-D Revision 31 states at least one of these
4492 * must be supported but we don't currently enforce this.
4494 dadeleteflag(softc, DA_DELETE_WS16,
4495 (lbp->flags & SVPD_LBP_WS16));
4496 dadeleteflag(softc, DA_DELETE_WS10,
4497 (lbp->flags & SVPD_LBP_WS10));
4498 dadeleteflag(softc, DA_DELETE_UNMAP,
4499 (lbp->flags & SVPD_LBP_UNMAP));
4502 error = daerror(done_ccb, CAM_RETRY_SELTO,
4503 SF_RETRY_UA|SF_NO_PRINT);
4504 if (error == ERESTART)
4506 else if (error != 0) {
4507 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4508 /* Don't wedge this device's queue */
4509 cam_release_devq(done_ccb->ccb_h.path,
4513 /*getcount_only*/0);
4517 * Failure indicates we don't support any SBC-3
4518 * delete methods with UNMAP
4523 free(lbp, M_SCSIDA);
4524 xpt_release_ccb(done_ccb);
4525 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4526 xpt_schedule(periph, priority);
4529 case DA_CCB_PROBE_BLK_LIMITS:
4531 struct scsi_vpd_block_limits *block_limits;
4533 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4535 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4536 uint32_t max_txfer_len = scsi_4btoul(
4537 block_limits->max_txfer_len);
4538 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4539 block_limits->max_unmap_lba_cnt);
4540 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4541 block_limits->max_unmap_blk_cnt);
4542 uint32_t unmap_gran = scsi_4btoul(
4543 block_limits->opt_unmap_grain);
4544 uint32_t unmap_gran_align = scsi_4btoul(
4545 block_limits->unmap_grain_align);
4546 uint64_t ws_max_blks = scsi_8btou64(
4547 block_limits->max_write_same_length);
4549 if (max_txfer_len != 0) {
4550 softc->disk->d_maxsize = MIN(softc->maxio,
4551 (off_t)max_txfer_len * softc->params.secsize);
4555 * We should already support UNMAP but we check lba
4556 * and block count to be sure
4558 if (max_unmap_lba_cnt != 0x00L &&
4559 max_unmap_blk_cnt != 0x00L) {
4560 softc->unmap_max_lba = max_unmap_lba_cnt;
4561 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4563 if (unmap_gran > 1) {
4564 softc->unmap_gran = unmap_gran;
4565 if (unmap_gran_align & 0x80000000) {
4566 softc->unmap_gran_align =
4573 * Unexpected UNMAP limits which means the
4574 * device doesn't actually support UNMAP
4576 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4579 if (ws_max_blks != 0x00L)
4580 softc->ws_max_blks = ws_max_blks;
4583 error = daerror(done_ccb, CAM_RETRY_SELTO,
4584 SF_RETRY_UA|SF_NO_PRINT);
4585 if (error == ERESTART)
4587 else if (error != 0) {
4588 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4589 /* Don't wedge this device's queue */
4590 cam_release_devq(done_ccb->ccb_h.path,
4594 /*getcount_only*/0);
4598 * Failure here doesn't mean UNMAP is not
4599 * supported as this is an optional page.
4601 softc->unmap_max_lba = 1;
4602 softc->unmap_max_ranges = 1;
4606 free(block_limits, M_SCSIDA);
4607 xpt_release_ccb(done_ccb);
4608 softc->state = DA_STATE_PROBE_BDC;
4609 xpt_schedule(periph, priority);
4612 case DA_CCB_PROBE_BDC:
4614 struct scsi_vpd_block_device_characteristics *bdc;
4616 bdc = (struct scsi_vpd_block_device_characteristics *)
4619 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4623 * Disable queue sorting for non-rotational media
4626 u_int16_t old_rate = softc->disk->d_rotation_rate;
4628 valid_len = csio->dxfer_len - csio->resid;
4629 if (SBDC_IS_PRESENT(bdc, valid_len,
4630 medium_rotation_rate)) {
4631 softc->disk->d_rotation_rate =
4632 scsi_2btoul(bdc->medium_rotation_rate);
4633 if (softc->disk->d_rotation_rate ==
4634 SVPD_BDC_RATE_NON_ROTATING) {
4635 cam_iosched_set_sort_queue(
4636 softc->cam_iosched, 0);
4637 softc->rotating = 0;
4639 if (softc->disk->d_rotation_rate != old_rate) {
4640 disk_attr_changed(softc->disk,
4641 "GEOM::rotation_rate", M_NOWAIT);
4644 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4645 && (softc->zone_mode == DA_ZONE_NONE)) {
4648 if (scsi_vpd_supported_page(periph,
4649 SVPD_ATA_INFORMATION))
4655 * The Zoned field will only be set for
4656 * Drive Managed and Host Aware drives. If
4657 * they are Host Managed, the device type
4658 * in the standard INQUIRY data should be
4659 * set to T_ZBC_HM (0x14).
4661 if ((bdc->flags & SVPD_ZBC_MASK) ==
4663 softc->zone_mode = DA_ZONE_HOST_AWARE;
4664 softc->zone_interface = (ata_proto) ?
4665 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4666 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4668 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4669 softc->zone_interface = (ata_proto) ?
4670 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4671 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4673 xpt_print(periph->path, "Unknown zoned "
4675 bdc->flags & SVPD_ZBC_MASK);
4680 error = daerror(done_ccb, CAM_RETRY_SELTO,
4681 SF_RETRY_UA|SF_NO_PRINT);
4682 if (error == ERESTART)
4684 else if (error != 0) {
4685 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4686 /* Don't wedge this device's queue */
4687 cam_release_devq(done_ccb->ccb_h.path,
4691 /*getcount_only*/0);
4696 free(bdc, M_SCSIDA);
4697 xpt_release_ccb(done_ccb);
4698 softc->state = DA_STATE_PROBE_ATA;
4699 xpt_schedule(periph, priority);
4702 case DA_CCB_PROBE_ATA:
4705 struct ata_params *ata_params;
4710 ata_params = (struct ata_params *)csio->data_ptr;
4711 ptr = (uint16_t *)ata_params;
4715 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4718 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4719 ptr[i] = le16toh(ptr[i]);
4720 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4721 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4722 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4723 if (ata_params->max_dsm_blocks != 0)
4724 softc->trim_max_ranges = min(
4725 softc->trim_max_ranges,
4726 ata_params->max_dsm_blocks *
4727 ATA_DSM_BLK_RANGES);
4730 * Disable queue sorting for non-rotational media
4733 old_rate = softc->disk->d_rotation_rate;
4734 softc->disk->d_rotation_rate =
4735 ata_params->media_rotation_rate;
4736 if (softc->disk->d_rotation_rate ==
4737 ATA_RATE_NON_ROTATING) {
4738 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4739 softc->rotating = 0;
4741 if (softc->disk->d_rotation_rate != old_rate) {
4742 disk_attr_changed(softc->disk,
4743 "GEOM::rotation_rate", M_NOWAIT);
4746 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4747 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4749 if (ata_params->support.extension &
4751 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4754 * At this point, if we have a SATA host aware drive,
4755 * we communicate via ATA passthrough unless the
4756 * SAT layer supports ZBC -> ZAC translation. In
4760 * XXX KDM figure out how to detect a host managed
4763 if (softc->zone_mode == DA_ZONE_NONE) {
4765 * Note that we don't override the zone
4766 * mode or interface if it has already been
4767 * set. This is because it has either been
4768 * set as a quirk, or when we probed the
4769 * SCSI Block Device Characteristics page,
4770 * the zoned field was set. The latter
4771 * means that the SAT layer supports ZBC to
4772 * ZAC translation, and we would prefer to
4773 * use that if it is available.
4775 if ((ata_params->support3 &
4776 ATA_SUPPORT_ZONE_MASK) ==
4777 ATA_SUPPORT_ZONE_HOST_AWARE) {
4778 softc->zone_mode = DA_ZONE_HOST_AWARE;
4779 softc->zone_interface =
4780 DA_ZONE_IF_ATA_PASS;
4781 } else if ((ata_params->support3 &
4782 ATA_SUPPORT_ZONE_MASK) ==
4783 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4784 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4785 softc->zone_interface =
4786 DA_ZONE_IF_ATA_PASS;
4791 error = daerror(done_ccb, CAM_RETRY_SELTO,
4792 SF_RETRY_UA|SF_NO_PRINT);
4793 if (error == ERESTART)
4795 else if (error != 0) {
4796 if ((done_ccb->ccb_h.status &
4797 CAM_DEV_QFRZN) != 0) {
4798 /* Don't wedge this device's queue */
4799 cam_release_devq(done_ccb->ccb_h.path,
4803 /*getcount_only*/0);
4808 free(ata_params, M_SCSIDA);
4809 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4810 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4812 * If the ATA IDENTIFY failed, we could be talking
4813 * to a SCSI drive, although that seems unlikely,
4814 * since the drive did report that it supported the
4815 * ATA Information VPD page. If the ATA IDENTIFY
4816 * succeeded, and the SAT layer doesn't support
4817 * ZBC -> ZAC translation, continue on to get the
4818 * directory of ATA logs, and complete the rest of
4819 * the ZAC probe. If the SAT layer does support
4820 * ZBC -> ZAC translation, we want to use that,
4821 * and we'll probe the SCSI Zoned Block Device
4822 * Characteristics VPD page next.
4825 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4826 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4827 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4829 softc->state = DA_STATE_PROBE_ZONE;
4832 if (continue_probe != 0) {
4833 xpt_release_ccb(done_ccb);
4834 xpt_schedule(periph, priority);
4837 daprobedone(periph, done_ccb);
4840 case DA_CCB_PROBE_ATA_LOGDIR:
4844 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4846 softc->valid_logdir_len = 0;
4847 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4848 softc->valid_logdir_len =
4849 csio->dxfer_len - csio->resid;
4850 if (softc->valid_logdir_len > 0)
4851 bcopy(csio->data_ptr, &softc->ata_logdir,
4852 min(softc->valid_logdir_len,
4853 sizeof(softc->ata_logdir)));
4855 * Figure out whether the Identify Device log is
4856 * supported. The General Purpose log directory
4857 * has a header, and lists the number of pages
4858 * available for each GP log identified by the
4859 * offset into the list.
4861 if ((softc->valid_logdir_len >=
4862 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4863 && (le16dec(softc->ata_logdir.header) ==
4864 ATA_GP_LOG_DIR_VERSION)
4865 && (le16dec(&softc->ata_logdir.num_pages[
4866 (ATA_IDENTIFY_DATA_LOG *
4867 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4868 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4870 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4873 error = daerror(done_ccb, CAM_RETRY_SELTO,
4874 SF_RETRY_UA|SF_NO_PRINT);
4875 if (error == ERESTART)
4877 else if (error != 0) {
4879 * If we can't get the ATA log directory,
4880 * then ATA logs are effectively not
4881 * supported even if the bit is set in the
4884 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
4885 DA_FLAG_CAN_ATA_IDLOG);
4886 if ((done_ccb->ccb_h.status &
4887 CAM_DEV_QFRZN) != 0) {
4888 /* Don't wedge this device's queue */
4889 cam_release_devq(done_ccb->ccb_h.path,
4893 /*getcount_only*/0);
4898 free(csio->data_ptr, M_SCSIDA);
4901 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
4902 softc->state = DA_STATE_PROBE_ATA_IDDIR;
4903 xpt_release_ccb(done_ccb);
4904 xpt_schedule(periph, priority);
4907 daprobedone(periph, done_ccb);
4910 case DA_CCB_PROBE_ATA_IDDIR:
4914 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4915 off_t entries_offset, max_entries;
4918 softc->valid_iddir_len = 0;
4919 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
4920 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
4921 DA_FLAG_CAN_ATA_ZONE);
4922 softc->valid_iddir_len =
4923 csio->dxfer_len - csio->resid;
4924 if (softc->valid_iddir_len > 0)
4925 bcopy(csio->data_ptr, &softc->ata_iddir,
4926 min(softc->valid_iddir_len,
4927 sizeof(softc->ata_iddir)));
4930 __offsetof(struct ata_identify_log_pages,entries);
4931 max_entries = softc->valid_iddir_len - entries_offset;
4932 if ((softc->valid_iddir_len > (entries_offset + 1))
4933 && (le64dec(softc->ata_iddir.header) ==
4935 && (softc->ata_iddir.entry_count > 0)) {
4938 num_entries = softc->ata_iddir.entry_count;
4939 num_entries = min(num_entries,
4940 softc->valid_iddir_len - entries_offset);
4941 for (i = 0; i < num_entries &&
4942 i < max_entries; i++) {
4943 if (softc->ata_iddir.entries[i] ==
4946 DA_FLAG_CAN_ATA_SUPCAP;
4947 else if (softc->ata_iddir.entries[i]==
4950 DA_FLAG_CAN_ATA_ZONE;
4953 DA_FLAG_CAN_ATA_SUPCAP)
4955 DA_FLAG_CAN_ATA_ZONE))
4960 error = daerror(done_ccb, CAM_RETRY_SELTO,
4961 SF_RETRY_UA|SF_NO_PRINT);
4962 if (error == ERESTART)
4964 else if (error != 0) {
4966 * If we can't get the ATA Identify Data log
4967 * directory, then it effectively isn't
4968 * supported even if the ATA Log directory
4969 * a non-zero number of pages present for
4972 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4973 if ((done_ccb->ccb_h.status &
4974 CAM_DEV_QFRZN) != 0) {
4975 /* Don't wedge this device's queue */
4976 cam_release_devq(done_ccb->ccb_h.path,
4980 /*getcount_only*/0);
4985 free(csio->data_ptr, M_SCSIDA);
4988 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
4989 softc->state = DA_STATE_PROBE_ATA_SUP;
4990 xpt_release_ccb(done_ccb);
4991 xpt_schedule(periph, priority);
4994 daprobedone(periph, done_ccb);
4997 case DA_CCB_PROBE_ATA_SUP:
5001 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5004 struct ata_identify_log_sup_cap *sup_cap;
5007 sup_cap = (struct ata_identify_log_sup_cap *)
5009 valid_len = csio->dxfer_len - csio->resid;
5011 __offsetof(struct ata_identify_log_sup_cap,
5012 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5013 if (valid_len >= needed_size) {
5014 uint64_t zoned, zac_cap;
5016 zoned = le64dec(sup_cap->zoned_cap);
5017 if (zoned & ATA_ZONED_VALID) {
5019 * This should have already been
5020 * set, because this is also in the
5021 * ATA identify data.
5023 if ((zoned & ATA_ZONED_MASK) ==
5024 ATA_SUPPORT_ZONE_HOST_AWARE)
5027 else if ((zoned & ATA_ZONED_MASK) ==
5028 ATA_SUPPORT_ZONE_DEV_MANAGED)
5030 DA_ZONE_DRIVE_MANAGED;
5033 zac_cap = le64dec(sup_cap->sup_zac_cap);
5034 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5035 if (zac_cap & ATA_REPORT_ZONES_SUP)
5036 softc->zone_flags |=
5037 DA_ZONE_FLAG_RZ_SUP;
5038 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5039 softc->zone_flags |=
5040 DA_ZONE_FLAG_OPEN_SUP;
5041 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5042 softc->zone_flags |=
5043 DA_ZONE_FLAG_CLOSE_SUP;
5044 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5045 softc->zone_flags |=
5046 DA_ZONE_FLAG_FINISH_SUP;
5047 if (zac_cap & ATA_ND_RWP_SUP)
5048 softc->zone_flags |=
5049 DA_ZONE_FLAG_RWP_SUP;
5052 * This field was introduced in
5053 * ACS-4, r08 on April 28th, 2015.
5054 * If the drive firmware was written
5055 * to an earlier spec, it won't have
5056 * the field. So, assume all
5057 * commands are supported.
5059 softc->zone_flags |=
5060 DA_ZONE_FLAG_SUP_MASK;
5065 error = daerror(done_ccb, CAM_RETRY_SELTO,
5066 SF_RETRY_UA|SF_NO_PRINT);
5067 if (error == ERESTART)
5069 else if (error != 0) {
5071 * If we can't get the ATA Identify Data
5072 * Supported Capabilities page, clear the
5075 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5077 * And clear zone capabilities.
5079 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5080 if ((done_ccb->ccb_h.status &
5081 CAM_DEV_QFRZN) != 0) {
5082 /* Don't wedge this device's queue */
5083 cam_release_devq(done_ccb->ccb_h.path,
5087 /*getcount_only*/0);
5092 free(csio->data_ptr, M_SCSIDA);
5095 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5096 softc->state = DA_STATE_PROBE_ATA_ZONE;
5097 xpt_release_ccb(done_ccb);
5098 xpt_schedule(periph, priority);
5101 daprobedone(periph, done_ccb);
5104 case DA_CCB_PROBE_ATA_ZONE:
5108 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5109 struct ata_zoned_info_log *zi_log;
5113 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5115 valid_len = csio->dxfer_len - csio->resid;
5116 needed_size = __offsetof(struct ata_zoned_info_log,
5117 version_info) + 1 + sizeof(zi_log->version_info);
5118 if (valid_len >= needed_size) {
5121 tmpvar = le64dec(zi_log->zoned_cap);
5122 if (tmpvar & ATA_ZDI_CAP_VALID) {
5123 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5124 softc->zone_flags |=
5125 DA_ZONE_FLAG_URSWRZ;
5127 softc->zone_flags &=
5128 ~DA_ZONE_FLAG_URSWRZ;
5130 tmpvar = le64dec(zi_log->optimal_seq_zones);
5131 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5132 softc->zone_flags |=
5133 DA_ZONE_FLAG_OPT_SEQ_SET;
5134 softc->optimal_seq_zones = (tmpvar &
5135 ATA_ZDI_OPT_SEQ_MASK);
5137 softc->zone_flags &=
5138 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5139 softc->optimal_seq_zones = 0;
5142 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5143 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5144 softc->zone_flags |=
5145 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5146 softc->optimal_nonseq_zones =
5147 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5149 softc->zone_flags &=
5150 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5151 softc->optimal_nonseq_zones = 0;
5154 tmpvar = le64dec(zi_log->max_seq_req_zones);
5155 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5156 softc->zone_flags |=
5157 DA_ZONE_FLAG_MAX_SEQ_SET;
5158 softc->max_seq_zones =
5159 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5161 softc->zone_flags &=
5162 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5163 softc->max_seq_zones = 0;
5167 error = daerror(done_ccb, CAM_RETRY_SELTO,
5168 SF_RETRY_UA|SF_NO_PRINT);
5169 if (error == ERESTART)
5171 else if (error != 0) {
5172 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5173 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5175 if ((done_ccb->ccb_h.status &
5176 CAM_DEV_QFRZN) != 0) {
5177 /* Don't wedge this device's queue */
5178 cam_release_devq(done_ccb->ccb_h.path,
5182 /*getcount_only*/0);
5187 free(csio->data_ptr, M_SCSIDA);
5189 daprobedone(periph, done_ccb);
5192 case DA_CCB_PROBE_ZONE:
5196 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5199 struct scsi_vpd_zoned_bdc *zoned_bdc;
5202 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5204 valid_len = csio->dxfer_len - csio->resid;
5205 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5206 max_seq_req_zones) + 1 +
5207 sizeof(zoned_bdc->max_seq_req_zones);
5208 if ((valid_len >= needed_len)
5209 && (scsi_2btoul(zoned_bdc->page_length) >=
5211 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5212 softc->zone_flags |=
5213 DA_ZONE_FLAG_URSWRZ;
5215 softc->zone_flags &=
5216 ~DA_ZONE_FLAG_URSWRZ;
5217 softc->optimal_seq_zones =
5218 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5219 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5220 softc->optimal_nonseq_zones = scsi_4btoul(
5221 zoned_bdc->optimal_nonseq_zones);
5222 softc->zone_flags |=
5223 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5224 softc->max_seq_zones =
5225 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5226 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5229 * All of the zone commands are mandatory for SCSI
5232 * XXX KDM this is valid as of September 2015.
5233 * Re-check this assumption once the SAT spec is
5234 * updated to support SCSI ZBC to ATA ZAC mapping.
5235 * Since ATA allows zone commands to be reported
5236 * as supported or not, this may not necessarily
5237 * be true for an ATA device behind a SAT (SCSI to
5238 * ATA Translation) layer.
5240 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5242 error = daerror(done_ccb, CAM_RETRY_SELTO,
5243 SF_RETRY_UA|SF_NO_PRINT);
5244 if (error == ERESTART)
5246 else if (error != 0) {
5247 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5248 /* Don't wedge this device's queue */
5249 cam_release_devq(done_ccb->ccb_h.path,
5253 /*getcount_only*/0);
5257 daprobedone(periph, done_ccb);
5261 /* No-op. We're polling */
5265 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5267 if (daerror(done_ccb, CAM_RETRY_SELTO,
5268 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5271 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5272 cam_release_devq(done_ccb->ccb_h.path,
5276 /*getcount_only*/0);
5278 xpt_release_ccb(done_ccb);
5279 cam_periph_release_locked(periph);
5285 xpt_release_ccb(done_ccb);
5289 dareprobe(struct cam_periph *periph)
5291 struct da_softc *softc;
5294 softc = (struct da_softc *)periph->softc;
5296 /* Probe in progress; don't interfere. */
5297 if (softc->state != DA_STATE_NORMAL)
5300 status = cam_periph_acquire(periph);
5301 KASSERT(status == CAM_REQ_CMP,
5302 ("dareprobe: cam_periph_acquire failed"));
5304 if (softc->flags & DA_FLAG_CAN_RC16)
5305 softc->state = DA_STATE_PROBE_RC16;
5307 softc->state = DA_STATE_PROBE_RC;
5309 xpt_schedule(periph, CAM_PRIORITY_DEV);
5313 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5315 struct da_softc *softc;
5316 struct cam_periph *periph;
5317 int error, error_code, sense_key, asc, ascq;
5319 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5320 if (ccb->csio.bio != NULL)
5321 biotrack(ccb->csio.bio, __func__);
5324 periph = xpt_path_periph(ccb->ccb_h.path);
5325 softc = (struct da_softc *)periph->softc;
5328 * Automatically detect devices that do not support
5329 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5332 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5333 error = cmd6workaround(ccb);
5334 } else if (scsi_extract_sense_ccb(ccb,
5335 &error_code, &sense_key, &asc, &ascq)) {
5336 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5337 error = cmd6workaround(ccb);
5339 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5340 * query the capacity and notify upper layers.
5342 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5343 asc == 0x2A && ascq == 0x09) {
5344 xpt_print(periph->path, "Capacity data has changed\n");
5345 softc->flags &= ~DA_FLAG_PROBED;
5347 sense_flags |= SF_NO_PRINT;
5348 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5349 asc == 0x28 && ascq == 0x00) {
5350 softc->flags &= ~DA_FLAG_PROBED;
5351 disk_media_changed(softc->disk, M_NOWAIT);
5352 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5353 asc == 0x3F && ascq == 0x03) {
5354 xpt_print(periph->path, "INQUIRY data has changed\n");
5355 softc->flags &= ~DA_FLAG_PROBED;
5357 sense_flags |= SF_NO_PRINT;
5358 } else if (sense_key == SSD_KEY_NOT_READY &&
5359 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5360 softc->flags |= DA_FLAG_PACK_INVALID;
5361 disk_media_gone(softc->disk, M_NOWAIT);
5364 if (error == ERESTART)
5368 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5369 case CAM_CMD_TIMEOUT:
5372 case CAM_REQ_ABORTED:
5373 case CAM_REQ_CMP_ERR:
5374 case CAM_REQ_TERMIO:
5375 case CAM_UNREC_HBA_ERROR:
5376 case CAM_DATA_RUN_ERR:
5386 * Until we have a better way of doing pack validation,
5387 * don't treat UAs as errors.
5389 sense_flags |= SF_RETRY_UA;
5391 if (softc->quirks & DA_Q_RETRY_BUSY)
5392 sense_flags |= SF_RETRY_BUSY;
5393 return(cam_periph_error(ccb, cam_flags, sense_flags,
5394 &softc->saved_ccb));
5398 damediapoll(void *arg)
5400 struct cam_periph *periph = arg;
5401 struct da_softc *softc = periph->softc;
5403 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5404 LIST_EMPTY(&softc->pending_ccbs)) {
5405 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5406 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5410 /* Queue us up again */
5411 if (da_poll_period != 0)
5412 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5416 daprevent(struct cam_periph *periph, int action)
5418 struct da_softc *softc;
5422 softc = (struct da_softc *)periph->softc;
5424 if (((action == PR_ALLOW)
5425 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5426 || ((action == PR_PREVENT)
5427 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5431 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5433 scsi_prevent(&ccb->csio,
5441 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5442 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5445 if (action == PR_ALLOW)
5446 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5448 softc->flags |= DA_FLAG_PACK_LOCKED;
5451 xpt_release_ccb(ccb);
5455 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5456 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5458 struct ccb_calc_geometry ccg;
5459 struct da_softc *softc;
5460 struct disk_params *dp;
5461 u_int lbppbe, lalba;
5464 softc = (struct da_softc *)periph->softc;
5466 dp = &softc->params;
5467 dp->secsize = block_len;
5468 dp->sectors = maxsector + 1;
5469 if (rcaplong != NULL) {
5470 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5471 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5472 lalba &= SRC16_LALBA_A;
5479 dp->stripesize = block_len << lbppbe;
5480 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5482 } else if (softc->quirks & DA_Q_4K) {
5483 dp->stripesize = 4096;
5484 dp->stripeoffset = 0;
5485 } else if (softc->unmap_gran != 0) {
5486 dp->stripesize = block_len * softc->unmap_gran;
5487 dp->stripeoffset = (dp->stripesize - block_len *
5488 softc->unmap_gran_align) % dp->stripesize;
5491 dp->stripeoffset = 0;
5494 * Have the controller provide us with a geometry
5495 * for this disk. The only time the geometry
5496 * matters is when we boot and the controller
5497 * is the only one knowledgeable enough to come
5498 * up with something that will make this a bootable
5501 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5502 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5503 ccg.block_size = dp->secsize;
5504 ccg.volume_size = dp->sectors;
5506 ccg.secs_per_track = 0;
5508 xpt_action((union ccb*)&ccg);
5509 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5511 * We don't know what went wrong here- but just pick
5512 * a geometry so we don't have nasty things like divide
5516 dp->secs_per_track = 255;
5517 dp->cylinders = dp->sectors / (255 * 255);
5518 if (dp->cylinders == 0) {
5522 dp->heads = ccg.heads;
5523 dp->secs_per_track = ccg.secs_per_track;
5524 dp->cylinders = ccg.cylinders;
5528 * If the user supplied a read capacity buffer, and if it is
5529 * different than the previous buffer, update the data in the EDT.
5530 * If it's the same, we don't bother. This avoids sending an
5531 * update every time someone opens this device.
5533 if ((rcaplong != NULL)
5534 && (bcmp(rcaplong, &softc->rcaplong,
5535 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5536 struct ccb_dev_advinfo cdai;
5538 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5539 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5540 cdai.buftype = CDAI_TYPE_RCAPLONG;
5541 cdai.flags = CDAI_FLAG_STORE;
5542 cdai.bufsiz = rcap_len;
5543 cdai.buf = (uint8_t *)rcaplong;
5544 xpt_action((union ccb *)&cdai);
5545 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5546 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5547 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5548 xpt_print(periph->path, "%s: failed to set read "
5549 "capacity advinfo\n", __func__);
5550 /* Use cam_error_print() to decode the status */
5551 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5554 bcopy(rcaplong, &softc->rcaplong,
5555 min(sizeof(softc->rcaplong), rcap_len));
5559 softc->disk->d_sectorsize = softc->params.secsize;
5560 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5561 softc->disk->d_stripesize = softc->params.stripesize;
5562 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5563 /* XXX: these are not actually "firmware" values, so they may be wrong */
5564 softc->disk->d_fwsectors = softc->params.secs_per_track;
5565 softc->disk->d_fwheads = softc->params.heads;
5566 softc->disk->d_devstat->block_size = softc->params.secsize;
5567 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5569 error = disk_resize(softc->disk, M_NOWAIT);
5571 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5575 dasendorderedtag(void *arg)
5577 struct da_softc *softc = arg;
5579 if (da_send_ordered) {
5580 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5581 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5582 softc->flags |= DA_FLAG_NEED_OTAG;
5583 softc->flags &= ~DA_FLAG_WAS_OTAG;
5586 /* Queue us up again */
5587 callout_reset(&softc->sendordered_c,
5588 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5589 dasendorderedtag, softc);
5593 * Step through all DA peripheral drivers, and if the device is still open,
5594 * sync the disk cache to physical media.
5597 dashutdown(void * arg, int howto)
5599 struct cam_periph *periph;
5600 struct da_softc *softc;
5604 CAM_PERIPH_FOREACH(periph, &dadriver) {
5605 softc = (struct da_softc *)periph->softc;
5606 if (SCHEDULER_STOPPED()) {
5607 /* If we paniced with the lock held, do not recurse. */
5608 if (!cam_periph_owned(periph) &&
5609 (softc->flags & DA_FLAG_OPEN)) {
5610 dadump(softc->disk, NULL, 0, 0, 0);
5614 cam_periph_lock(periph);
5617 * We only sync the cache if the drive is still open, and
5618 * if the drive is capable of it..
5620 if (((softc->flags & DA_FLAG_OPEN) == 0)
5621 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5622 cam_periph_unlock(periph);
5626 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5627 scsi_synchronize_cache(&ccb->csio,
5631 /*begin_lba*/0, /* whole disk */
5636 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5637 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5638 softc->disk->d_devstat);
5640 xpt_print(periph->path, "Synchronize cache failed\n");
5641 xpt_release_ccb(ccb);
5642 cam_periph_unlock(periph);
5646 #else /* !_KERNEL */
5649 * XXX These are only left out of the kernel build to silence warnings. If,
5650 * for some reason these functions are used in the kernel, the ifdefs should
5651 * be moved so they are included both in the kernel and userland.
5654 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5655 void (*cbfcnp)(struct cam_periph *, union ccb *),
5656 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5657 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5660 struct scsi_format_unit *scsi_cmd;
5662 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5663 scsi_cmd->opcode = FORMAT_UNIT;
5664 scsi_cmd->byte2 = byte2;
5665 scsi_ulto2b(ileave, scsi_cmd->interleave);
5670 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5680 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5681 void (*cbfcnp)(struct cam_periph *, union ccb *),
5682 uint8_t tag_action, uint8_t list_format,
5683 uint32_t addr_desc_index, uint8_t *data_ptr,
5684 uint32_t dxfer_len, int minimum_cmd_size,
5685 uint8_t sense_len, uint32_t timeout)
5690 * These conditions allow using the 10 byte command. Otherwise we
5691 * need to use the 12 byte command.
5693 if ((minimum_cmd_size <= 10)
5694 && (addr_desc_index == 0)
5695 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5696 struct scsi_read_defect_data_10 *cdb10;
5698 cdb10 = (struct scsi_read_defect_data_10 *)
5699 &csio->cdb_io.cdb_bytes;
5701 cdb_len = sizeof(*cdb10);
5702 bzero(cdb10, cdb_len);
5703 cdb10->opcode = READ_DEFECT_DATA_10;
5704 cdb10->format = list_format;
5705 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5707 struct scsi_read_defect_data_12 *cdb12;
5709 cdb12 = (struct scsi_read_defect_data_12 *)
5710 &csio->cdb_io.cdb_bytes;
5712 cdb_len = sizeof(*cdb12);
5713 bzero(cdb12, cdb_len);
5714 cdb12->opcode = READ_DEFECT_DATA_12;
5715 cdb12->format = list_format;
5716 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5717 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5723 /*flags*/ CAM_DIR_IN,
5733 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5734 void (*cbfcnp)(struct cam_periph *, union ccb *),
5735 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5736 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5739 struct scsi_sanitize *scsi_cmd;
5741 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5742 scsi_cmd->opcode = SANITIZE;
5743 scsi_cmd->byte2 = byte2;
5744 scsi_cmd->control = control;
5745 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5750 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5759 #endif /* _KERNEL */
5762 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5763 void (*cbfcnp)(struct cam_periph *, union ccb *),
5764 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5765 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5766 uint8_t sense_len, uint32_t timeout)
5768 struct scsi_zbc_out *scsi_cmd;
5770 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5771 scsi_cmd->opcode = ZBC_OUT;
5772 scsi_cmd->service_action = service_action;
5773 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5774 scsi_cmd->zone_flags = zone_flags;
5779 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5789 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5790 void (*cbfcnp)(struct cam_periph *, union ccb *),
5791 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5792 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5793 uint8_t sense_len, uint32_t timeout)
5795 struct scsi_zbc_in *scsi_cmd;
5797 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5798 scsi_cmd->opcode = ZBC_IN;
5799 scsi_cmd->service_action = service_action;
5800 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5801 scsi_cmd->zone_options = zone_options;
5806 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5817 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5818 void (*cbfcnp)(struct cam_periph *, union ccb *),
5819 uint8_t tag_action, int use_ncq,
5820 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5821 uint8_t *data_ptr, uint32_t dxfer_len,
5822 uint8_t *cdb_storage, size_t cdb_storage_len,
5823 uint8_t sense_len, uint32_t timeout)
5825 uint8_t command_out, protocol, ata_flags;
5826 uint16_t features_out;
5827 uint32_t sectors_out, auxiliary;
5833 command_out = ATA_ZAC_MANAGEMENT_OUT;
5834 features_out = (zm_action & 0xf) | (zone_flags << 8);
5835 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5836 if (dxfer_len == 0) {
5837 protocol = AP_PROTO_NON_DATA;
5838 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5841 protocol = AP_PROTO_DMA;
5842 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5843 AP_FLAG_TDIR_TO_DEV;
5844 sectors_out = ((dxfer_len >> 9) & 0xffff);
5848 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5849 if (dxfer_len == 0) {
5850 command_out = ATA_NCQ_NON_DATA;
5851 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5853 * We're assuming the SCSI to ATA translation layer
5854 * will set the NCQ tag number in the tag field.
5855 * That isn't clear from the SAT-4 spec (as of rev 05).
5858 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5860 command_out = ATA_SEND_FPDMA_QUEUED;
5862 * Note that we're defaulting to normal priority,
5863 * and assuming that the SCSI to ATA translation
5864 * layer will insert the NCQ tag number in the tag
5865 * field. That isn't clear in the SAT-4 spec (as
5868 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5870 ata_flags |= AP_FLAG_TLEN_FEAT |
5871 AP_FLAG_TDIR_TO_DEV;
5874 * For SEND FPDMA QUEUED, the transfer length is
5875 * encoded in the FEATURE register, and 0 means
5876 * that 65536 512 byte blocks are to be tranferred.
5877 * In practice, it seems unlikely that we'll see
5878 * a transfer that large, and it may confuse the
5879 * the SAT layer, because generally that means that
5880 * 0 bytes should be transferred.
5882 if (dxfer_len == (65536 * 512)) {
5884 } else if (dxfer_len <= (65535 * 512)) {
5885 features_out = ((dxfer_len >> 9) & 0xffff);
5887 /* The transfer is too big. */
5894 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
5895 protocol = AP_PROTO_FPDMA;
5898 protocol |= AP_EXTEND;
5900 retval = scsi_ata_pass(csio,
5903 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5905 /*protocol*/ protocol,
5906 /*ata_flags*/ ata_flags,
5907 /*features*/ features_out,
5908 /*sector_count*/ sectors_out,
5910 /*command*/ command_out,
5913 /*auxiliary*/ auxiliary,
5915 /*data_ptr*/ data_ptr,
5916 /*dxfer_len*/ dxfer_len,
5917 /*cdb_storage*/ cdb_storage,
5918 /*cdb_storage_len*/ cdb_storage_len,
5919 /*minimum_cmd_size*/ 0,
5920 /*sense_len*/ SSD_FULL_SIZE,
5921 /*timeout*/ timeout);
5929 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
5930 void (*cbfcnp)(struct cam_periph *, union ccb *),
5931 uint8_t tag_action, int use_ncq,
5932 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5933 uint8_t *data_ptr, uint32_t dxfer_len,
5934 uint8_t *cdb_storage, size_t cdb_storage_len,
5935 uint8_t sense_len, uint32_t timeout)
5937 uint8_t command_out, protocol;
5938 uint16_t features_out, sectors_out;
5944 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
5947 command_out = ATA_ZAC_MANAGEMENT_IN;
5948 /* XXX KDM put a macro here */
5949 features_out = (zm_action & 0xf) | (zone_flags << 8);
5950 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
5951 protocol = AP_PROTO_DMA;
5952 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
5955 ata_flags |= AP_FLAG_TLEN_FEAT;
5957 command_out = ATA_RECV_FPDMA_QUEUED;
5958 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
5961 * For RECEIVE FPDMA QUEUED, the transfer length is
5962 * encoded in the FEATURE register, and 0 means
5963 * that 65536 512 byte blocks are to be tranferred.
5964 * In practice, it seems unlikely that we'll see
5965 * a transfer that large, and it may confuse the
5966 * the SAT layer, because generally that means that
5967 * 0 bytes should be transferred.
5969 if (dxfer_len == (65536 * 512)) {
5971 } else if (dxfer_len <= (65535 * 512)) {
5972 features_out = ((dxfer_len >> 9) & 0xffff);
5974 /* The transfer is too big. */
5978 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
5979 protocol = AP_PROTO_FPDMA;
5982 protocol |= AP_EXTEND;
5984 retval = scsi_ata_pass(csio,
5987 /*flags*/ CAM_DIR_IN,
5989 /*protocol*/ protocol,
5990 /*ata_flags*/ ata_flags,
5991 /*features*/ features_out,
5992 /*sector_count*/ sectors_out,
5994 /*command*/ command_out,
5997 /*auxiliary*/ auxiliary,
5999 /*data_ptr*/ data_ptr,
6000 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6001 /*cdb_storage*/ cdb_storage,
6002 /*cdb_storage_len*/ cdb_storage_len,
6003 /*minimum_cmd_size*/ 0,
6004 /*sense_len*/ SSD_FULL_SIZE,
6005 /*timeout*/ timeout);