2 * Implementation of SCSI Direct Access Peripheral driver for CAM.
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (c) 1997 Justin T. Gibbs.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification, immediately at the beginning of the file.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
40 #include <sys/sysctl.h>
41 #include <sys/taskqueue.h>
43 #include <sys/mutex.h>
45 #include <sys/devicestat.h>
46 #include <sys/eventhandler.h>
47 #include <sys/malloc.h>
49 #include <sys/endian.h>
52 #include <geom/geom.h>
53 #include <geom/geom_disk.h>
62 #include <cam/cam_ccb.h>
63 #include <cam/cam_periph.h>
64 #include <cam/cam_xpt_periph.h>
65 #include <cam/cam_sim.h>
66 #include <cam/cam_iosched.h>
68 #include <cam/scsi/scsi_message.h>
69 #include <cam/scsi/scsi_da.h>
73 * Note that there are probe ordering dependencies here. The order isn't
74 * controlled by this enumeration, but by explicit state transitions in
75 * dastart() and dadone(). Here are some of the dependencies:
77 * 1. RC should come first, before RC16, unless there is evidence that RC16
79 * 2. BDC needs to come before any of the ATA probes, or the ZONE probe.
80 * 3. The ATA probes should go in this order:
81 * ATA -> LOGDIR -> IDDIR -> SUP -> ATA_ZONE
87 DA_STATE_PROBE_BLK_LIMITS,
90 DA_STATE_PROBE_ATA_LOGDIR,
91 DA_STATE_PROBE_ATA_IDDIR,
92 DA_STATE_PROBE_ATA_SUP,
93 DA_STATE_PROBE_ATA_ZONE,
99 DA_FLAG_PACK_INVALID = 0x000001,
100 DA_FLAG_NEW_PACK = 0x000002,
101 DA_FLAG_PACK_LOCKED = 0x000004,
102 DA_FLAG_PACK_REMOVABLE = 0x000008,
103 DA_FLAG_NEED_OTAG = 0x000020,
104 DA_FLAG_WAS_OTAG = 0x000040,
105 DA_FLAG_RETRY_UA = 0x000080,
106 DA_FLAG_OPEN = 0x000100,
107 DA_FLAG_SCTX_INIT = 0x000200,
108 DA_FLAG_CAN_RC16 = 0x000400,
109 DA_FLAG_PROBED = 0x000800,
110 DA_FLAG_DIRTY = 0x001000,
111 DA_FLAG_ANNOUNCED = 0x002000,
112 DA_FLAG_CAN_ATA_DMA = 0x004000,
113 DA_FLAG_CAN_ATA_LOG = 0x008000,
114 DA_FLAG_CAN_ATA_IDLOG = 0x010000,
115 DA_FLAG_CAN_ATA_SUPCAP = 0x020000,
116 DA_FLAG_CAN_ATA_ZONE = 0x040000
121 DA_Q_NO_SYNC_CACHE = 0x01,
122 DA_Q_NO_6_BYTE = 0x02,
123 DA_Q_NO_PREVENT = 0x04,
126 DA_Q_NO_UNMAP = 0x20,
127 DA_Q_RETRY_BUSY = 0x40,
129 DA_Q_STRICT_UNMAP = 0x100
132 #define DA_Q_BIT_STRING \
134 "\001NO_SYNC_CACHE" \
145 DA_CCB_PROBE_RC = 0x01,
146 DA_CCB_PROBE_RC16 = 0x02,
147 DA_CCB_PROBE_LBP = 0x03,
148 DA_CCB_PROBE_BLK_LIMITS = 0x04,
149 DA_CCB_PROBE_BDC = 0x05,
150 DA_CCB_PROBE_ATA = 0x06,
151 DA_CCB_BUFFER_IO = 0x07,
153 DA_CCB_DELETE = 0x0B,
155 DA_CCB_PROBE_ZONE = 0x0D,
156 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
157 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
158 DA_CCB_PROBE_ATA_SUP = 0x10,
159 DA_CCB_PROBE_ATA_ZONE = 0x11,
160 DA_CCB_TYPE_MASK = 0x1F,
161 DA_CCB_RETRY_UA = 0x20
165 * Order here is important for method choice
167 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
168 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
169 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
170 * import taking 5mins.
181 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
182 DA_DELETE_MAX = DA_DELETE_ZERO
186 * For SCSI, host managed drives show up as a separate device type. For
187 * ATA, host managed drives also have a different device signature.
188 * XXX KDM figure out the ATA host managed signature.
192 DA_ZONE_DRIVE_MANAGED = 0x01,
193 DA_ZONE_HOST_AWARE = 0x02,
194 DA_ZONE_HOST_MANAGED = 0x03
198 * We distinguish between these interface cases in addition to the drive type:
199 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
200 * o ATA drive behind a SCSI translation layer that does not know about
201 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
202 * case, we would need to share the ATA code with the ada(4) driver.
212 DA_ZONE_FLAG_RZ_SUP = 0x0001,
213 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
214 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
215 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
216 DA_ZONE_FLAG_RWP_SUP = 0x0010,
217 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
218 DA_ZONE_FLAG_OPEN_SUP |
219 DA_ZONE_FLAG_CLOSE_SUP |
220 DA_ZONE_FLAG_FINISH_SUP |
221 DA_ZONE_FLAG_RWP_SUP),
222 DA_ZONE_FLAG_URSWRZ = 0x0020,
223 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
224 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
225 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
226 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
227 DA_ZONE_FLAG_OPT_NONSEQ_SET |
228 DA_ZONE_FLAG_MAX_SEQ_SET)
231 static struct da_zone_desc {
234 } da_zone_desc_table[] = {
235 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
236 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
237 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
238 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
239 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
242 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
244 static da_delete_func_t da_delete_trim;
245 static da_delete_func_t da_delete_unmap;
246 static da_delete_func_t da_delete_ws;
248 static const void * da_delete_functions[] = {
258 static const char *da_delete_method_names[] =
259 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
260 static const char *da_delete_method_desc[] =
261 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
262 "WRITE SAME(10) with UNMAP", "ZERO" };
264 /* Offsets into our private area for storing information */
265 #define ccb_state ppriv_field0
266 #define ccb_bp ppriv_ptr1
271 u_int8_t secs_per_track;
272 u_int32_t secsize; /* Number of bytes/sector */
273 u_int64_t sectors; /* total number sectors */
278 #define UNMAP_RANGE_MAX 0xffffffff
279 #define UNMAP_HEAD_SIZE 8
280 #define UNMAP_RANGE_SIZE 16
281 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
282 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
285 #define WS10_MAX_BLKS 0xffff
286 #define WS16_MAX_BLKS 0xffffffff
287 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
288 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
290 #define DA_WORK_TUR (1 << 16)
293 struct cam_iosched_softc *cam_iosched;
294 struct bio_queue_head delete_run_queue;
295 LIST_HEAD(, ccb_hdr) pending_ccbs;
296 int refcount; /* Active xpt_action() calls */
300 int minimum_cmd_size;
303 int delete_available; /* Delete methods possibly available */
304 da_zone_mode zone_mode;
305 da_zone_interface zone_interface;
306 da_zone_flags zone_flags;
307 struct ata_gp_log_dir ata_logdir;
308 int valid_logdir_len;
309 struct ata_identify_log_pages ata_iddir;
311 uint64_t optimal_seq_zones;
312 uint64_t optimal_nonseq_zones;
313 uint64_t max_seq_zones;
315 uint32_t unmap_max_ranges;
316 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
318 uint32_t unmap_gran_align;
319 uint64_t ws_max_blks;
320 da_delete_methods delete_method_pref;
321 da_delete_methods delete_method;
322 da_delete_func_t *delete_func;
325 struct disk_params params;
328 struct task sysctl_task;
329 struct sysctl_ctx_list sysctl_ctx;
330 struct sysctl_oid *sysctl_tree;
331 struct callout sendordered_c;
333 uint8_t unmap_buf[UNMAP_BUF_SIZE];
334 struct scsi_read_capacity_data_long rcaplong;
335 struct callout mediapoll_c;
337 struct sysctl_ctx_list sysctl_stats_ctx;
338 struct sysctl_oid *sysctl_stats_tree;
343 #define DA_ANNOUNCETMP_SZ 80
344 char announce_temp[DA_ANNOUNCETMP_SZ];
345 #define DA_ANNOUNCE_SZ 400
346 char announcebuf[DA_ANNOUNCE_SZ];
349 #define dadeleteflag(softc, delete_method, enable) \
351 softc->delete_available |= (1 << delete_method); \
353 softc->delete_available &= ~(1 << delete_method); \
356 struct da_quirk_entry {
357 struct scsi_inquiry_pattern inq_pat;
361 static const char quantum[] = "QUANTUM";
362 static const char microp[] = "MICROP";
364 static struct da_quirk_entry da_quirk_table[] =
366 /* SPI, FC devices */
369 * Fujitsu M2513A MO drives.
370 * Tested devices: M2513A2 firmware versions 1200 & 1300.
371 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
372 * Reported by: W.Scholten <whs@xs4all.nl>
374 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
375 /*quirks*/ DA_Q_NO_SYNC_CACHE
379 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
380 /*quirks*/ DA_Q_NO_SYNC_CACHE
384 * This particular Fujitsu drive doesn't like the
385 * synchronize cache command.
386 * Reported by: Tom Jackson <toj@gorilla.net>
388 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
389 /*quirks*/ DA_Q_NO_SYNC_CACHE
393 * This drive doesn't like the synchronize cache command
394 * either. Reported by: Matthew Jacob <mjacob@feral.com>
395 * in NetBSD PR kern/6027, August 24, 1998.
397 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
398 /*quirks*/ DA_Q_NO_SYNC_CACHE
402 * This drive doesn't like the synchronize cache command
403 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
406 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
407 /*quirks*/ DA_Q_NO_SYNC_CACHE
411 * Doesn't like the synchronize cache command.
412 * Reported by: Blaz Zupan <blaz@gold.amis.net>
414 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
415 /*quirks*/ DA_Q_NO_SYNC_CACHE
419 * Doesn't like the synchronize cache command.
420 * Reported by: Blaz Zupan <blaz@gold.amis.net>
422 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
423 /*quirks*/ DA_Q_NO_SYNC_CACHE
427 * Doesn't like the synchronize cache command.
429 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
430 /*quirks*/ DA_Q_NO_SYNC_CACHE
434 * Doesn't like the synchronize cache command.
435 * Reported by: walter@pelissero.de
437 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
438 /*quirks*/ DA_Q_NO_SYNC_CACHE
442 * Doesn't work correctly with 6 byte reads/writes.
443 * Returns illegal request, and points to byte 9 of the
445 * Reported by: Adam McDougall <bsdx@spawnet.com>
447 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
448 /*quirks*/ DA_Q_NO_6_BYTE
452 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
453 /*quirks*/ DA_Q_NO_6_BYTE
457 * Doesn't like the synchronize cache command.
458 * Reported by: walter@pelissero.de
460 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
461 /*quirks*/ DA_Q_NO_SYNC_CACHE
465 * The CISS RAID controllers do not support SYNC_CACHE
467 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
468 /*quirks*/ DA_Q_NO_SYNC_CACHE
472 * The STEC SSDs sometimes hang on UNMAP.
474 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
475 /*quirks*/ DA_Q_NO_UNMAP
479 * VMware returns BUSY status when storage has transient
480 * connectivity problems, so better wait.
481 * Also VMware returns odd errors on misaligned UNMAPs.
483 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
484 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
486 /* USB mass storage devices supported by umass(4) */
489 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
492 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
493 /*quirks*/ DA_Q_NO_SYNC_CACHE
497 * Power Quotient Int. (PQI) USB flash key
500 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
501 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
505 * Creative Nomad MUVO mp3 player (USB)
508 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
509 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
513 * Jungsoft NEXDISK USB flash key
516 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
517 /*quirks*/ DA_Q_NO_SYNC_CACHE
521 * FreeDik USB Mini Data Drive
524 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
525 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
529 * Sigmatel USB Flash MP3 Player
532 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
533 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
537 * Neuros USB Digital Audio Computer
540 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
541 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
545 * SEAGRAND NP-900 MP3 Player
548 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
549 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
553 * iRiver iFP MP3 player (with UMS Firmware)
554 * PR: kern/54881, i386/63941, kern/66124
556 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
557 /*quirks*/ DA_Q_NO_SYNC_CACHE
561 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
564 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
565 /*quirks*/ DA_Q_NO_SYNC_CACHE
569 * ZICPlay USB MP3 Player with FM
572 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
573 /*quirks*/ DA_Q_NO_SYNC_CACHE
577 * TEAC USB floppy mechanisms
579 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
580 /*quirks*/ DA_Q_NO_SYNC_CACHE
584 * Kingston DataTraveler II+ USB Pen-Drive.
585 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
587 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
588 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
596 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
597 /*quirks*/ DA_Q_NO_SYNC_CACHE
601 * Motorola E398 Mobile Phone (TransFlash memory card).
602 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
605 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
606 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
610 * Qware BeatZkey! Pro
613 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
614 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
618 * Time DPA20B 1GB MP3 Player
621 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
622 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
626 * Samsung USB key 128Mb
629 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
630 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
634 * Kingston DataTraveler 2.0 USB Flash memory.
637 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
638 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
642 * Creative MUVO Slim mp3 player (USB)
645 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
646 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
650 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
653 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
654 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
658 * SanDisk Micro Cruzer 128MB
661 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
662 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
666 * TOSHIBA TransMemory USB sticks
669 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
670 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
674 * PNY USB 3.0 Flash Drives
676 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
677 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
682 * PR: usb/75578, usb/72344, usb/65436
684 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
685 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
691 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
692 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16
696 * Genesys 6-in-1 Card Reader
699 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
700 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
704 * Rekam Digital CAMERA
707 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
708 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
712 * iRiver H10 MP3 player
715 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
716 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
720 * iRiver U10 MP3 player
723 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
724 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
731 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
732 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
736 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
739 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
740 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
747 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
748 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
752 * Philips USB Key Audio KEY013
755 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
756 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
763 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
764 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
771 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
772 /*quirks*/ DA_Q_NO_SYNC_CACHE
776 * I/O Magic USB flash - Giga Bank
779 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
780 /*quirks*/ DA_Q_NO_SYNC_CACHE
784 * JoyFly 128mb USB Flash Drive
787 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
788 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
795 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
796 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
800 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
803 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
804 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
808 * Samsung YP-U3 mp3-player
811 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
812 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
815 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
816 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
820 * Sony Cyber-Shot DSC cameras
823 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
824 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
827 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
828 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
831 /* At least several Transcent USB sticks lie on RC16. */
832 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
833 "*"}, /*quirks*/ DA_Q_NO_RC16
837 * I-O Data USB Flash Disk
840 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
841 "*"}, /*quirks*/ DA_Q_NO_RC16
843 /* ATA/SATA devices over SAS/USB/... */
845 /* Hitachi Advanced Format (4k) drives */
846 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
850 /* Micron Advanced Format (4k) drives */
851 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
855 /* Samsung Advanced Format (4k) drives */
856 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
860 /* Samsung Advanced Format (4k) drives */
861 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
865 /* Samsung Advanced Format (4k) drives */
866 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
870 /* Samsung Advanced Format (4k) drives */
871 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
875 /* Seagate Barracuda Green Advanced Format (4k) drives */
876 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
880 /* Seagate Barracuda Green Advanced Format (4k) drives */
881 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
885 /* Seagate Barracuda Green Advanced Format (4k) drives */
886 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
890 /* Seagate Barracuda Green Advanced Format (4k) drives */
891 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
895 /* Seagate Barracuda Green Advanced Format (4k) drives */
896 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
900 /* Seagate Barracuda Green Advanced Format (4k) drives */
901 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
905 /* Seagate Momentus Advanced Format (4k) drives */
906 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
910 /* Seagate Momentus Advanced Format (4k) drives */
911 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
915 /* Seagate Momentus Advanced Format (4k) drives */
916 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
920 /* Seagate Momentus Advanced Format (4k) drives */
921 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
925 /* Seagate Momentus Advanced Format (4k) drives */
926 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
930 /* Seagate Momentus Advanced Format (4k) drives */
931 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
935 /* Seagate Momentus Advanced Format (4k) drives */
936 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
940 /* Seagate Momentus Advanced Format (4k) drives */
941 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
945 /* Seagate Momentus Advanced Format (4k) drives */
946 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
950 /* Seagate Momentus Advanced Format (4k) drives */
951 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
955 /* Seagate Momentus Advanced Format (4k) drives */
956 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
960 /* Seagate Momentus Advanced Format (4k) drives */
961 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
965 /* Seagate Momentus Advanced Format (4k) drives */
966 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
970 /* Seagate Momentus Advanced Format (4k) drives */
971 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
975 /* Seagate Momentus Thin Advanced Format (4k) drives */
976 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
980 /* Seagate Momentus Thin Advanced Format (4k) drives */
981 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
985 /* WDC Caviar Green Advanced Format (4k) drives */
986 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
990 /* WDC Caviar Green Advanced Format (4k) drives */
991 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
995 /* WDC Caviar Green Advanced Format (4k) drives */
996 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
1000 /* WDC Caviar Green Advanced Format (4k) drives */
1001 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
1005 /* WDC Caviar Green Advanced Format (4k) drives */
1006 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1010 /* WDC Caviar Green Advanced Format (4k) drives */
1011 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1015 /* WDC Caviar Green Advanced Format (4k) drives */
1016 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1020 /* WDC Caviar Green Advanced Format (4k) drives */
1021 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1025 /* WDC Scorpio Black Advanced Format (4k) drives */
1026 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1030 /* WDC Scorpio Black Advanced Format (4k) drives */
1031 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1035 /* WDC Scorpio Black Advanced Format (4k) drives */
1036 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1040 /* WDC Scorpio Black Advanced Format (4k) drives */
1041 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1045 /* WDC Scorpio Blue Advanced Format (4k) drives */
1046 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1050 /* WDC Scorpio Blue Advanced Format (4k) drives */
1051 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1055 /* WDC Scorpio Blue Advanced Format (4k) drives */
1056 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1060 /* WDC Scorpio Blue Advanced Format (4k) drives */
1061 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1066 * Olympus FE-210 camera
1068 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1069 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1073 * LG UP3S MP3 player
1075 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1076 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1080 * Laser MP3-2GA13 MP3 player
1082 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1083 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1087 * LaCie external 250GB Hard drive des by Porsche
1088 * Submitted by: Ben Stuyts <ben@altesco.nl>
1091 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1092 /*quirks*/ DA_Q_NO_SYNC_CACHE
1097 * Corsair Force 2 SSDs
1098 * 4k optimised & trim only works in 4k requests + 4k aligned
1100 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1105 * Corsair Force 3 SSDs
1106 * 4k optimised & trim only works in 4k requests + 4k aligned
1108 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1113 * Corsair Neutron GTX SSDs
1114 * 4k optimised & trim only works in 4k requests + 4k aligned
1116 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1121 * Corsair Force GT & GS SSDs
1122 * 4k optimised & trim only works in 4k requests + 4k aligned
1124 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1130 * 4k optimised & trim only works in 4k requests + 4k aligned
1132 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1137 * Crucial RealSSD C300 SSDs
1140 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1141 "*" }, /*quirks*/DA_Q_4K
1145 * Intel 320 Series SSDs
1146 * 4k optimised & trim only works in 4k requests + 4k aligned
1148 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1153 * Intel 330 Series SSDs
1154 * 4k optimised & trim only works in 4k requests + 4k aligned
1156 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1161 * Intel 510 Series SSDs
1162 * 4k optimised & trim only works in 4k requests + 4k aligned
1164 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1169 * Intel 520 Series SSDs
1170 * 4k optimised & trim only works in 4k requests + 4k aligned
1172 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1177 * Intel S3610 Series SSDs
1178 * 4k optimised & trim only works in 4k requests + 4k aligned
1180 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1185 * Intel X25-M Series SSDs
1186 * 4k optimised & trim only works in 4k requests + 4k aligned
1188 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1193 * Kingston E100 Series SSDs
1194 * 4k optimised & trim only works in 4k requests + 4k aligned
1196 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1201 * Kingston HyperX 3k SSDs
1202 * 4k optimised & trim only works in 4k requests + 4k aligned
1204 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1209 * Marvell SSDs (entry taken from OpenSolaris)
1210 * 4k optimised & trim only works in 4k requests + 4k aligned
1212 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1217 * OCZ Agility 2 SSDs
1218 * 4k optimised & trim only works in 4k requests + 4k aligned
1220 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1225 * OCZ Agility 3 SSDs
1226 * 4k optimised & trim only works in 4k requests + 4k aligned
1228 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1233 * OCZ Deneva R Series SSDs
1234 * 4k optimised & trim only works in 4k requests + 4k aligned
1236 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1241 * OCZ Vertex 2 SSDs (inc pro series)
1242 * 4k optimised & trim only works in 4k requests + 4k aligned
1244 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1250 * 4k optimised & trim only works in 4k requests + 4k aligned
1252 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1258 * 4k optimised & trim only works in 4k requests + 4k aligned
1260 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1265 * Samsung 750 Series SSDs
1266 * 4k optimised & trim only works in 4k requests + 4k aligned
1268 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" },
1273 * Samsung 830 Series SSDs
1274 * 4k optimised & trim only works in 4k requests + 4k aligned
1276 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1282 * 4k optimised & trim only works in 4k requests + 4k aligned
1284 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1290 * 4k optimised & trim only works in 4k requests + 4k aligned
1292 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" },
1298 * 4k optimised & trim only works in 4k requests + 4k aligned
1300 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1305 * Samsung 843T Series SSDs (MZ7WD*)
1306 * Samsung PM851 Series SSDs (MZ7TE*)
1307 * Samsung PM853T Series SSDs (MZ7GE*)
1308 * Samsung SM863 Series SSDs (MZ7KM*)
1311 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1316 * Same as for SAMSUNG MZ7* but enable the quirks for SSD
1317 * starting with MZ7* too
1319 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MZ7*", "*" },
1324 * SuperTalent TeraDrive CT SSDs
1325 * 4k optimised & trim only works in 4k requests + 4k aligned
1327 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1332 * XceedIOPS SATA SSDs
1335 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1340 * Hama Innostor USB-Stick
1342 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1343 /*quirks*/DA_Q_NO_RC16
1347 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1348 * Drive Managed SATA hard drive. This drive doesn't report
1349 * in firmware that it is a drive managed SMR drive.
1351 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS000[23]*", "*" },
1352 /*quirks*/DA_Q_SMR_DM
1356 * MX-ES USB Drive by Mach Xtreme
1358 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1359 /*quirks*/DA_Q_NO_RC16
1363 static disk_strategy_t dastrategy;
1364 static dumper_t dadump;
1365 static periph_init_t dainit;
1366 static void daasync(void *callback_arg, u_int32_t code,
1367 struct cam_path *path, void *arg);
1368 static void dasysctlinit(void *context, int pending);
1369 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1370 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1371 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1372 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1373 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1374 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1375 static void dadeletemethodset(struct da_softc *softc,
1376 da_delete_methods delete_method);
1377 static off_t dadeletemaxsize(struct da_softc *softc,
1378 da_delete_methods delete_method);
1379 static void dadeletemethodchoose(struct da_softc *softc,
1380 da_delete_methods default_method);
1381 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1383 static periph_ctor_t daregister;
1384 static periph_dtor_t dacleanup;
1385 static periph_start_t dastart;
1386 static periph_oninv_t daoninvalidate;
1387 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1388 static void dadone(struct cam_periph *periph,
1389 union ccb *done_ccb);
1390 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1391 u_int32_t sense_flags);
1392 static void daprevent(struct cam_periph *periph, int action);
1393 static void dareprobe(struct cam_periph *periph);
1394 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1396 struct scsi_read_capacity_data_long *rcaplong,
1398 static timeout_t dasendorderedtag;
1399 static void dashutdown(void *arg, int howto);
1400 static timeout_t damediapoll;
1402 #ifndef DA_DEFAULT_POLL_PERIOD
1403 #define DA_DEFAULT_POLL_PERIOD 3
1406 #ifndef DA_DEFAULT_TIMEOUT
1407 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1410 #ifndef DA_DEFAULT_SOFTTIMEOUT
1411 #define DA_DEFAULT_SOFTTIMEOUT 0
1414 #ifndef DA_DEFAULT_RETRY
1415 #define DA_DEFAULT_RETRY 4
1418 #ifndef DA_DEFAULT_SEND_ORDERED
1419 #define DA_DEFAULT_SEND_ORDERED 1
1422 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1423 static int da_retry_count = DA_DEFAULT_RETRY;
1424 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1425 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1426 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1428 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1429 "CAM Direct Access Disk driver");
1430 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1431 &da_poll_period, 0, "Media polling period in seconds");
1432 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1433 &da_retry_count, 0, "Normal I/O retry count");
1434 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1435 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1436 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1437 &da_send_ordered, 0, "Send Ordered Tags");
1439 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1440 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1441 "Soft I/O timeout (ms)");
1442 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1445 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1446 * to the default timeout, we check to see whether an ordered
1447 * tagged transaction is appropriate to prevent simple tag
1448 * starvation. Since we'd like to ensure that there is at least
1449 * 1/2 of the timeout length left for a starved transaction to
1450 * complete after we've sent an ordered tag, we must poll at least
1451 * four times in every timeout period. This takes care of the worst
1452 * case where a starved transaction starts during an interval that
1453 * meets the requirement "don't send an ordered tag" test so it takes
1454 * us two intervals to determine that a tag must be sent.
1456 #ifndef DA_ORDEREDTAG_INTERVAL
1457 #define DA_ORDEREDTAG_INTERVAL 4
1460 static struct periph_driver dadriver =
1463 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1466 PERIPHDRIVER_DECLARE(da, dadriver);
1468 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1471 daopen(struct disk *dp)
1473 struct cam_periph *periph;
1474 struct da_softc *softc;
1477 periph = (struct cam_periph *)dp->d_drv1;
1478 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1482 cam_periph_lock(periph);
1483 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1484 cam_periph_unlock(periph);
1485 cam_periph_release(periph);
1489 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1492 softc = (struct da_softc *)periph->softc;
1495 /* Wait for the disk size update. */
1496 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1499 xpt_print(periph->path, "unable to retrieve capacity data\n");
1501 if (periph->flags & CAM_PERIPH_INVALID)
1504 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1505 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1506 daprevent(periph, PR_PREVENT);
1509 softc->flags &= ~DA_FLAG_PACK_INVALID;
1510 softc->flags |= DA_FLAG_OPEN;
1513 cam_periph_unhold(periph);
1514 cam_periph_unlock(periph);
1517 cam_periph_release(periph);
1523 daclose(struct disk *dp)
1525 struct cam_periph *periph;
1526 struct da_softc *softc;
1530 periph = (struct cam_periph *)dp->d_drv1;
1531 softc = (struct da_softc *)periph->softc;
1532 cam_periph_lock(periph);
1533 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1536 if (cam_periph_hold(periph, PRIBIO) == 0) {
1538 /* Flush disk cache. */
1539 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1540 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1541 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1542 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1543 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1544 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1545 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1547 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1548 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1549 softc->disk->d_devstat);
1550 softc->flags &= ~DA_FLAG_DIRTY;
1551 xpt_release_ccb(ccb);
1554 /* Allow medium removal. */
1555 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1556 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1557 daprevent(periph, PR_ALLOW);
1559 cam_periph_unhold(periph);
1563 * If we've got removeable media, mark the blocksize as
1564 * unavailable, since it could change when new media is
1567 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1568 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1570 softc->flags &= ~DA_FLAG_OPEN;
1571 while (softc->refcount != 0)
1572 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1573 cam_periph_unlock(periph);
1574 cam_periph_release(periph);
1579 daschedule(struct cam_periph *periph)
1581 struct da_softc *softc = (struct da_softc *)periph->softc;
1583 if (softc->state != DA_STATE_NORMAL)
1586 cam_iosched_schedule(softc->cam_iosched, periph);
1590 * Actually translate the requested transfer into one the physical driver
1591 * can understand. The transfer is described by a buf and will include
1592 * only one physical transfer.
1595 dastrategy(struct bio *bp)
1597 struct cam_periph *periph;
1598 struct da_softc *softc;
1600 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1601 softc = (struct da_softc *)periph->softc;
1603 cam_periph_lock(periph);
1606 * If the device has been made invalid, error out
1608 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1609 cam_periph_unlock(periph);
1610 biofinish(bp, NULL, ENXIO);
1614 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1617 * Zone commands must be ordered, because they can depend on the
1618 * effects of previously issued commands, and they may affect
1619 * commands after them.
1621 if (bp->bio_cmd == BIO_ZONE)
1622 bp->bio_flags |= BIO_ORDERED;
1625 * Place it in the queue of disk activities for this disk
1627 cam_iosched_queue_work(softc->cam_iosched, bp);
1630 * Schedule ourselves for performing the work.
1633 cam_periph_unlock(periph);
1639 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1641 struct cam_periph *periph;
1642 struct da_softc *softc;
1644 struct ccb_scsiio csio;
1649 periph = dp->d_drv1;
1650 softc = (struct da_softc *)periph->softc;
1651 cam_periph_lock(periph);
1652 secsize = softc->params.secsize;
1654 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1655 cam_periph_unlock(periph);
1659 memset(&csio, 0, sizeof(csio));
1661 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1662 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1663 scsi_read_write(&csio,
1667 /*read*/SCSI_RW_WRITE,
1669 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1672 /*data_ptr*/(u_int8_t *) virtual,
1673 /*dxfer_len*/length,
1674 /*sense_len*/SSD_FULL_SIZE,
1675 da_default_timeout * 1000);
1676 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1677 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1679 printf("Aborting dump due to I/O error.\n");
1680 cam_periph_unlock(periph);
1685 * Sync the disk cache contents to the physical media.
1687 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1689 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1690 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1691 scsi_synchronize_cache(&csio,
1695 /*begin_lba*/0,/* Cover the whole disk */
1699 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1700 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1702 xpt_print(periph->path, "Synchronize cache failed\n");
1704 cam_periph_unlock(periph);
1709 dagetattr(struct bio *bp)
1712 struct cam_periph *periph;
1714 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1715 cam_periph_lock(periph);
1716 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1718 cam_periph_unlock(periph);
1720 bp->bio_completed = bp->bio_length;
1730 * Install a global async callback. This callback will
1731 * receive async callbacks like "new device found".
1733 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1735 if (status != CAM_REQ_CMP) {
1736 printf("da: Failed to attach master async callback "
1737 "due to status 0x%x!\n", status);
1738 } else if (da_send_ordered) {
1740 /* Register our shutdown event handler */
1741 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1742 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1743 printf("dainit: shutdown event registration failed!\n");
1748 * Callback from GEOM, called when it has finished cleaning up its
1752 dadiskgonecb(struct disk *dp)
1754 struct cam_periph *periph;
1756 periph = (struct cam_periph *)dp->d_drv1;
1757 cam_periph_release(periph);
1761 daoninvalidate(struct cam_periph *periph)
1763 struct da_softc *softc;
1765 softc = (struct da_softc *)periph->softc;
1768 * De-register any async callbacks.
1770 xpt_register_async(0, daasync, periph, periph->path);
1772 softc->flags |= DA_FLAG_PACK_INVALID;
1774 softc->invalidations++;
1778 * Return all queued I/O with ENXIO.
1779 * XXX Handle any transactions queued to the card
1780 * with XPT_ABORT_CCB.
1782 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
1785 * Tell GEOM that we've gone away, we'll get a callback when it is
1786 * done cleaning up its resources.
1788 disk_gone(softc->disk);
1792 dacleanup(struct cam_periph *periph)
1794 struct da_softc *softc;
1796 softc = (struct da_softc *)periph->softc;
1798 cam_periph_unlock(periph);
1800 cam_iosched_fini(softc->cam_iosched);
1803 * If we can't free the sysctl tree, oh well...
1805 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
1807 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1808 xpt_print(periph->path,
1809 "can't remove sysctl stats context\n");
1811 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1812 xpt_print(periph->path,
1813 "can't remove sysctl context\n");
1816 callout_drain(&softc->mediapoll_c);
1817 disk_destroy(softc->disk);
1818 callout_drain(&softc->sendordered_c);
1819 free(softc, M_DEVBUF);
1820 cam_periph_lock(periph);
1824 daasync(void *callback_arg, u_int32_t code,
1825 struct cam_path *path, void *arg)
1827 struct cam_periph *periph;
1828 struct da_softc *softc;
1830 periph = (struct cam_periph *)callback_arg;
1832 case AC_FOUND_DEVICE:
1834 struct ccb_getdev *cgd;
1837 cgd = (struct ccb_getdev *)arg;
1841 if (cgd->protocol != PROTO_SCSI)
1843 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
1845 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1846 && SID_TYPE(&cgd->inq_data) != T_RBC
1847 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
1848 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
1852 * Allocate a peripheral instance for
1853 * this device and start the probe
1856 status = cam_periph_alloc(daregister, daoninvalidate,
1858 "da", CAM_PERIPH_BIO,
1860 AC_FOUND_DEVICE, cgd);
1862 if (status != CAM_REQ_CMP
1863 && status != CAM_REQ_INPROG)
1864 printf("daasync: Unable to attach to new device "
1865 "due to status 0x%x\n", status);
1868 case AC_ADVINFO_CHANGED:
1872 buftype = (uintptr_t)arg;
1873 if (buftype == CDAI_TYPE_PHYS_PATH) {
1874 struct da_softc *softc;
1876 softc = periph->softc;
1877 disk_attr_changed(softc->disk, "GEOM::physpath",
1882 case AC_UNIT_ATTENTION:
1885 int error_code, sense_key, asc, ascq;
1887 softc = (struct da_softc *)periph->softc;
1888 ccb = (union ccb *)arg;
1891 * Handle all UNIT ATTENTIONs except our own,
1892 * as they will be handled by daerror().
1894 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1895 scsi_extract_sense_ccb(ccb,
1896 &error_code, &sense_key, &asc, &ascq)) {
1897 if (asc == 0x2A && ascq == 0x09) {
1898 xpt_print(ccb->ccb_h.path,
1899 "Capacity data has changed\n");
1900 softc->flags &= ~DA_FLAG_PROBED;
1902 } else if (asc == 0x28 && ascq == 0x00) {
1903 softc->flags &= ~DA_FLAG_PROBED;
1904 disk_media_changed(softc->disk, M_NOWAIT);
1905 } else if (asc == 0x3F && ascq == 0x03) {
1906 xpt_print(ccb->ccb_h.path,
1907 "INQUIRY data has changed\n");
1908 softc->flags &= ~DA_FLAG_PROBED;
1915 softc = (struct da_softc *)periph->softc;
1916 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
1917 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1918 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
1926 struct ccb_hdr *ccbh;
1928 softc = (struct da_softc *)periph->softc;
1930 * Don't fail on the expected unit attention
1933 softc->flags |= DA_FLAG_RETRY_UA;
1934 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1935 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1938 case AC_INQ_CHANGED:
1939 softc = (struct da_softc *)periph->softc;
1940 softc->flags &= ~DA_FLAG_PROBED;
1946 cam_periph_async(periph, code, path, arg);
1950 dasysctlinit(void *context, int pending)
1952 struct cam_periph *periph;
1953 struct da_softc *softc;
1954 char tmpstr[32], tmpstr2[16];
1955 struct ccb_trans_settings cts;
1957 periph = (struct cam_periph *)context;
1959 * periph was held for us when this task was enqueued
1961 if (periph->flags & CAM_PERIPH_INVALID) {
1962 cam_periph_release(periph);
1966 softc = (struct da_softc *)periph->softc;
1967 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1968 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1970 sysctl_ctx_init(&softc->sysctl_ctx);
1971 softc->flags |= DA_FLAG_SCTX_INIT;
1972 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
1973 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1974 CTLFLAG_RD, 0, tmpstr, "device_index");
1975 if (softc->sysctl_tree == NULL) {
1976 printf("dasysctlinit: unable to allocate sysctl tree\n");
1977 cam_periph_release(periph);
1982 * Now register the sysctl handler, so the user can change the value on
1985 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1986 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
1987 softc, 0, dadeletemethodsysctl, "A",
1988 "BIO_DELETE execution method");
1989 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1990 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1991 softc, 0, dadeletemaxsysctl, "Q",
1992 "Maximum BIO_DELETE size");
1993 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1994 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1995 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1996 "Minimum CDB size");
1998 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1999 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
2000 softc, 0, dazonemodesysctl, "A",
2002 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2003 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
2004 softc, 0, dazonesupsysctl, "A",
2006 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2007 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2008 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2009 "Optimal Number of Open Sequential Write Preferred Zones");
2010 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2011 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2012 "optimal_nonseq_zones", CTLFLAG_RD,
2013 &softc->optimal_nonseq_zones,
2014 "Optimal Number of Non-Sequentially Written Sequential Write "
2016 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2017 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2018 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2019 "Maximum Number of Open Sequential Write Required Zones");
2021 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2022 SYSCTL_CHILDREN(softc->sysctl_tree),
2026 &softc->error_inject,
2028 "error_inject leaf");
2030 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2031 SYSCTL_CHILDREN(softc->sysctl_tree),
2037 "Unmapped I/O leaf");
2039 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2040 SYSCTL_CHILDREN(softc->sysctl_tree),
2049 * Add some addressing info.
2051 memset(&cts, 0, sizeof (cts));
2052 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2053 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2054 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2055 cam_periph_lock(periph);
2056 xpt_action((union ccb *)&cts);
2057 cam_periph_unlock(periph);
2058 if (cts.ccb_h.status != CAM_REQ_CMP) {
2059 cam_periph_release(periph);
2062 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2063 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2064 if (fc->valid & CTS_FC_VALID_WWPN) {
2065 softc->wwpn = fc->wwpn;
2066 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2067 SYSCTL_CHILDREN(softc->sysctl_tree),
2068 OID_AUTO, "wwpn", CTLFLAG_RD,
2069 &softc->wwpn, "World Wide Port Name");
2075 * Now add some useful stats.
2076 * XXX These should live in cam_periph and be common to all periphs
2078 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2079 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2080 CTLFLAG_RD, 0, "Statistics");
2081 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2082 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2088 "Transport errors reported by the SIM");
2089 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2090 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2096 "Device timeouts reported by the SIM");
2097 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2098 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2100 "pack_invalidations",
2102 &softc->invalidations,
2104 "Device pack invalidations");
2107 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2108 softc->sysctl_tree);
2110 cam_periph_release(periph);
2114 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2118 struct da_softc *softc;
2120 softc = (struct da_softc *)arg1;
2122 value = softc->disk->d_delmaxsize;
2123 error = sysctl_handle_64(oidp, &value, 0, req);
2124 if ((error != 0) || (req->newptr == NULL))
2127 /* only accept values smaller than the calculated value */
2128 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2131 softc->disk->d_delmaxsize = value;
2137 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2141 value = *(int *)arg1;
2143 error = sysctl_handle_int(oidp, &value, 0, req);
2146 || (req->newptr == NULL))
2150 * Acceptable values here are 6, 10, 12 or 16.
2154 else if ((value > 6)
2157 else if ((value > 10)
2160 else if (value > 12)
2163 *(int *)arg1 = value;
2169 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2174 value = da_default_softtimeout / SBT_1MS;
2176 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2177 if ((error != 0) || (req->newptr == NULL))
2180 /* XXX Should clip this to a reasonable level */
2181 if (value > da_default_timeout * 1000)
2184 da_default_softtimeout = value * SBT_1MS;
2189 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2192 softc->delete_method = delete_method;
2193 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2194 softc->delete_func = da_delete_functions[delete_method];
2196 if (softc->delete_method > DA_DELETE_DISABLE)
2197 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2199 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2203 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2207 switch(delete_method) {
2208 case DA_DELETE_UNMAP:
2209 sectors = (off_t)softc->unmap_max_lba;
2211 case DA_DELETE_ATA_TRIM:
2212 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2214 case DA_DELETE_WS16:
2215 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2217 case DA_DELETE_ZERO:
2218 case DA_DELETE_WS10:
2219 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2225 return (off_t)softc->params.secsize *
2226 omin(sectors, softc->params.sectors);
2230 daprobedone(struct cam_periph *periph, union ccb *ccb)
2232 struct da_softc *softc;
2234 softc = (struct da_softc *)periph->softc;
2236 dadeletemethodchoose(softc, DA_DELETE_NONE);
2238 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2242 snprintf(buf, sizeof(buf), "Delete methods: <");
2244 for (i = 0; i <= DA_DELETE_MAX; i++) {
2245 if ((softc->delete_available & (1 << i)) == 0 &&
2246 i != softc->delete_method)
2249 strlcat(buf, ",", sizeof(buf));
2250 strlcat(buf, da_delete_method_names[i],
2252 if (i == softc->delete_method)
2253 strlcat(buf, "(*)", sizeof(buf));
2256 strlcat(buf, ">", sizeof(buf));
2257 printf("%s%d: %s\n", periph->periph_name,
2258 periph->unit_number, buf);
2262 * Since our peripheral may be invalidated by an error
2263 * above or an external event, we must release our CCB
2264 * before releasing the probe lock on the peripheral.
2265 * The peripheral will only go away once the last lock
2266 * is removed, and we need it around for the CCB release
2269 xpt_release_ccb(ccb);
2270 softc->state = DA_STATE_NORMAL;
2271 softc->flags |= DA_FLAG_PROBED;
2273 wakeup(&softc->disk->d_mediasize);
2274 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2275 softc->flags |= DA_FLAG_ANNOUNCED;
2276 cam_periph_unhold(periph);
2278 cam_periph_release_locked(periph);
2282 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2286 /* If available, prefer the method requested by user. */
2287 i = softc->delete_method_pref;
2288 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2289 if (methods & (1 << i)) {
2290 dadeletemethodset(softc, i);
2294 /* Use the pre-defined order to choose the best performing delete. */
2295 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2296 if (i == DA_DELETE_ZERO)
2298 if (softc->delete_available & (1 << i)) {
2299 dadeletemethodset(softc, i);
2304 /* Fallback to default. */
2305 dadeletemethodset(softc, default_method);
2309 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2313 struct da_softc *softc;
2314 int i, error, methods, value;
2316 softc = (struct da_softc *)arg1;
2318 value = softc->delete_method;
2319 if (value < 0 || value > DA_DELETE_MAX)
2322 p = da_delete_method_names[value];
2323 strncpy(buf, p, sizeof(buf));
2324 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2325 if (error != 0 || req->newptr == NULL)
2327 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2328 for (i = 0; i <= DA_DELETE_MAX; i++) {
2329 if (strcmp(buf, da_delete_method_names[i]) == 0)
2332 if (i > DA_DELETE_MAX)
2334 softc->delete_method_pref = i;
2335 dadeletemethodchoose(softc, DA_DELETE_NONE);
2340 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2343 struct da_softc *softc;
2346 softc = (struct da_softc *)arg1;
2348 switch (softc->zone_mode) {
2349 case DA_ZONE_DRIVE_MANAGED:
2350 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2352 case DA_ZONE_HOST_AWARE:
2353 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2355 case DA_ZONE_HOST_MANAGED:
2356 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2360 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2364 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2370 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2373 struct da_softc *softc;
2378 softc = (struct da_softc *)arg1;
2382 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2384 for (i = 0; i < sizeof(da_zone_desc_table) /
2385 sizeof(da_zone_desc_table[0]); i++) {
2386 if (softc->zone_flags & da_zone_desc_table[i].value) {
2388 sbuf_printf(&sb, ", ");
2391 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2396 sbuf_printf(&sb, "None");
2400 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2406 daregister(struct cam_periph *periph, void *arg)
2408 struct da_softc *softc;
2409 struct ccb_pathinq cpi;
2410 struct ccb_getdev *cgd;
2414 cgd = (struct ccb_getdev *)arg;
2416 printf("daregister: no getdev CCB, can't register device\n");
2417 return(CAM_REQ_CMP_ERR);
2420 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2423 if (softc == NULL) {
2424 printf("daregister: Unable to probe new device. "
2425 "Unable to allocate softc\n");
2426 return(CAM_REQ_CMP_ERR);
2429 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2430 printf("daregister: Unable to probe new device. "
2431 "Unable to allocate iosched memory\n");
2432 free(softc, M_DEVBUF);
2433 return(CAM_REQ_CMP_ERR);
2436 LIST_INIT(&softc->pending_ccbs);
2437 softc->state = DA_STATE_PROBE_RC;
2438 bioq_init(&softc->delete_run_queue);
2439 if (SID_IS_REMOVABLE(&cgd->inq_data))
2440 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2441 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2442 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2443 softc->unmap_gran = 0;
2444 softc->unmap_gran_align = 0;
2445 softc->ws_max_blks = WS16_MAX_BLKS;
2446 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2447 softc->rotating = 1;
2449 periph->softc = softc;
2452 * See if this device has any quirks.
2454 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2455 (caddr_t)da_quirk_table,
2456 nitems(da_quirk_table),
2457 sizeof(*da_quirk_table), scsi_inquiry_match);
2460 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2462 softc->quirks = DA_Q_NONE;
2464 /* Check if the SIM does not want 6 byte commands */
2465 xpt_path_inq(&cpi, periph->path);
2466 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2467 softc->quirks |= DA_Q_NO_6_BYTE;
2469 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2470 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2471 else if (softc->quirks & DA_Q_SMR_DM)
2472 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2474 softc->zone_mode = DA_ZONE_NONE;
2476 if (softc->zone_mode != DA_ZONE_NONE) {
2477 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2478 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2479 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2481 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2483 softc->zone_interface = DA_ZONE_IF_SCSI;
2486 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2489 * Take an exclusive refcount on the periph while dastart is called
2490 * to finish the probe. The reference will be dropped in dadone at
2493 (void)cam_periph_hold(periph, PRIBIO);
2496 * Schedule a periodic event to occasionally send an
2497 * ordered tag to a device.
2499 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2500 callout_reset(&softc->sendordered_c,
2501 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2502 dasendorderedtag, softc);
2504 cam_periph_unlock(periph);
2506 * RBC devices don't have to support READ(6), only READ(10).
2508 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2509 softc->minimum_cmd_size = 10;
2511 softc->minimum_cmd_size = 6;
2514 * Load the user's default, if any.
2516 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2517 periph->unit_number);
2518 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2521 * 6, 10, 12 and 16 are the currently permissible values.
2523 if (softc->minimum_cmd_size > 12)
2524 softc->minimum_cmd_size = 16;
2525 else if (softc->minimum_cmd_size > 10)
2526 softc->minimum_cmd_size = 12;
2527 else if (softc->minimum_cmd_size > 6)
2528 softc->minimum_cmd_size = 10;
2530 softc->minimum_cmd_size = 6;
2532 /* Predict whether device may support READ CAPACITY(16). */
2533 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2534 (softc->quirks & DA_Q_NO_RC16) == 0) {
2535 softc->flags |= DA_FLAG_CAN_RC16;
2536 softc->state = DA_STATE_PROBE_RC16;
2540 * Register this media as a disk.
2542 softc->disk = disk_alloc();
2543 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2544 periph->unit_number, 0,
2545 DEVSTAT_BS_UNAVAILABLE,
2546 SID_TYPE(&cgd->inq_data) |
2547 XPORT_DEVSTAT_TYPE(cpi.transport),
2548 DEVSTAT_PRIORITY_DISK);
2549 softc->disk->d_open = daopen;
2550 softc->disk->d_close = daclose;
2551 softc->disk->d_strategy = dastrategy;
2552 softc->disk->d_dump = dadump;
2553 softc->disk->d_getattr = dagetattr;
2554 softc->disk->d_gone = dadiskgonecb;
2555 softc->disk->d_name = "da";
2556 softc->disk->d_drv1 = periph;
2558 softc->maxio = DFLTPHYS; /* traditional default */
2559 else if (cpi.maxio > MAXPHYS)
2560 softc->maxio = MAXPHYS; /* for safety */
2562 softc->maxio = cpi.maxio;
2563 softc->disk->d_maxsize = softc->maxio;
2564 softc->disk->d_unit = periph->unit_number;
2565 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2566 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2567 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2568 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2569 softc->unmappedio = 1;
2570 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2572 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2573 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2574 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2575 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2576 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2577 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2578 softc->disk->d_hba_vendor = cpi.hba_vendor;
2579 softc->disk->d_hba_device = cpi.hba_device;
2580 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2581 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2584 * Acquire a reference to the periph before we register with GEOM.
2585 * We'll release this reference once GEOM calls us back (via
2586 * dadiskgonecb()) telling us that our provider has been freed.
2588 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2589 xpt_print(periph->path, "%s: lost periph during "
2590 "registration!\n", __func__);
2591 cam_periph_lock(periph);
2592 return (CAM_REQ_CMP_ERR);
2595 disk_create(softc->disk, DISK_VERSION);
2596 cam_periph_lock(periph);
2599 * Add async callbacks for events of interest.
2600 * I don't bother checking if this fails as,
2601 * in most cases, the system will function just
2602 * fine without them and the only alternative
2603 * would be to not attach the device on failure.
2605 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2606 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2607 AC_INQ_CHANGED, daasync, periph, periph->path);
2610 * Emit an attribute changed notification just in case
2611 * physical path information arrived before our async
2612 * event handler was registered, but after anyone attaching
2613 * to our disk device polled it.
2615 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2618 * Schedule a periodic media polling events.
2620 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2621 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2622 (cgd->inq_flags & SID_AEN) == 0 &&
2623 da_poll_period != 0)
2624 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2625 damediapoll, periph);
2627 xpt_schedule(periph, CAM_PRIORITY_DEV);
2629 return(CAM_REQ_CMP);
2633 da_zone_bio_to_scsi(int disk_zone_cmd)
2635 switch (disk_zone_cmd) {
2636 case DISK_ZONE_OPEN:
2637 return ZBC_OUT_SA_OPEN;
2638 case DISK_ZONE_CLOSE:
2639 return ZBC_OUT_SA_CLOSE;
2640 case DISK_ZONE_FINISH:
2641 return ZBC_OUT_SA_FINISH;
2643 return ZBC_OUT_SA_RWP;
2650 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2653 struct da_softc *softc;
2658 if (bp->bio_cmd != BIO_ZONE) {
2663 softc = periph->softc;
2665 switch (bp->bio_zone.zone_cmd) {
2666 case DISK_ZONE_OPEN:
2667 case DISK_ZONE_CLOSE:
2668 case DISK_ZONE_FINISH:
2669 case DISK_ZONE_RWP: {
2674 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2675 if (zone_sa == -1) {
2676 xpt_print(periph->path, "Cannot translate zone "
2677 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2683 lba = bp->bio_zone.zone_params.rwp.id;
2685 if (bp->bio_zone.zone_params.rwp.flags &
2686 DISK_ZONE_RWP_FLAG_ALL)
2687 zone_flags |= ZBC_OUT_ALL;
2689 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2690 scsi_zbc_out(&ccb->csio,
2691 /*retries*/ da_retry_count,
2693 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2694 /*service_action*/ zone_sa,
2696 /*zone_flags*/ zone_flags,
2699 /*sense_len*/ SSD_FULL_SIZE,
2700 /*timeout*/ da_default_timeout * 1000);
2703 * Note that in this case, even though we can
2704 * technically use NCQ, we don't bother for several
2706 * 1. It hasn't been tested on a SAT layer that
2707 * supports it. This is new as of SAT-4.
2708 * 2. Even when there is a SAT layer that supports
2709 * it, that SAT layer will also probably support
2710 * ZBC -> ZAC translation, since they are both
2711 * in the SAT-4 spec.
2712 * 3. Translation will likely be preferable to ATA
2713 * passthrough. LSI / Avago at least single
2714 * steps ATA passthrough commands in the HBA,
2715 * regardless of protocol, so unless that
2716 * changes, there is a performance penalty for
2717 * doing ATA passthrough no matter whether
2718 * you're using NCQ/FPDMA, DMA or PIO.
2719 * 4. It requires a 32-byte CDB, which at least at
2720 * this point in CAM requires a CDB pointer, which
2721 * would require us to allocate an additional bit
2722 * of storage separate from the CCB.
2724 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2725 /*retries*/ da_retry_count,
2727 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2729 /*zm_action*/ zone_sa,
2731 /*zone_flags*/ zone_flags,
2734 /*cdb_storage*/ NULL,
2735 /*cdb_storage_len*/ 0,
2736 /*sense_len*/ SSD_FULL_SIZE,
2737 /*timeout*/ da_default_timeout * 1000);
2740 xpt_print(periph->path,
2741 "scsi_ata_zac_mgmt_out() returned an "
2750 case DISK_ZONE_REPORT_ZONES: {
2752 uint32_t num_entries, alloc_size;
2753 struct disk_zone_report *rep;
2755 rep = &bp->bio_zone.zone_params.report;
2757 num_entries = rep->entries_allocated;
2758 if (num_entries == 0) {
2759 xpt_print(periph->path, "No entries allocated for "
2760 "Report Zones request\n");
2764 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2765 (sizeof(struct scsi_report_zones_desc) * num_entries);
2766 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2767 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2768 if (rz_ptr == NULL) {
2769 xpt_print(periph->path, "Unable to allocate memory "
2770 "for Report Zones request\n");
2775 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2776 scsi_zbc_in(&ccb->csio,
2777 /*retries*/ da_retry_count,
2779 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2780 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2781 /*zone_start_lba*/ rep->starting_id,
2782 /*zone_options*/ rep->rep_options,
2783 /*data_ptr*/ rz_ptr,
2784 /*dxfer_len*/ alloc_size,
2785 /*sense_len*/ SSD_FULL_SIZE,
2786 /*timeout*/ da_default_timeout * 1000);
2789 * Note that in this case, even though we can
2790 * technically use NCQ, we don't bother for several
2792 * 1. It hasn't been tested on a SAT layer that
2793 * supports it. This is new as of SAT-4.
2794 * 2. Even when there is a SAT layer that supports
2795 * it, that SAT layer will also probably support
2796 * ZBC -> ZAC translation, since they are both
2797 * in the SAT-4 spec.
2798 * 3. Translation will likely be preferable to ATA
2799 * passthrough. LSI / Avago at least single
2800 * steps ATA passthrough commands in the HBA,
2801 * regardless of protocol, so unless that
2802 * changes, there is a performance penalty for
2803 * doing ATA passthrough no matter whether
2804 * you're using NCQ/FPDMA, DMA or PIO.
2805 * 4. It requires a 32-byte CDB, which at least at
2806 * this point in CAM requires a CDB pointer, which
2807 * would require us to allocate an additional bit
2808 * of storage separate from the CCB.
2810 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2811 /*retries*/ da_retry_count,
2813 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2815 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2816 /*zone_id*/ rep->starting_id,
2817 /*zone_flags*/ rep->rep_options,
2818 /*data_ptr*/ rz_ptr,
2819 /*dxfer_len*/ alloc_size,
2820 /*cdb_storage*/ NULL,
2821 /*cdb_storage_len*/ 0,
2822 /*sense_len*/ SSD_FULL_SIZE,
2823 /*timeout*/ da_default_timeout * 1000);
2826 xpt_print(periph->path,
2827 "scsi_ata_zac_mgmt_in() returned an "
2834 * For BIO_ZONE, this isn't normally needed. However, it
2835 * is used by devstat_end_transaction_bio() to determine
2836 * how much data was transferred.
2839 * XXX KDM we have a problem. But I'm not sure how to fix
2840 * it. devstat uses bio_bcount - bio_resid to calculate
2841 * the amount of data transferred. The GEOM disk code
2842 * uses bio_length - bio_resid to calculate the amount of
2843 * data in bio_completed. We have different structure
2844 * sizes above and below the ada(4) driver. So, if we
2845 * use the sizes above, the amount transferred won't be
2846 * quite accurate for devstat. If we use different sizes
2847 * for bio_bcount and bio_length (above and below
2848 * respectively), then the residual needs to match one or
2849 * the other. Everything is calculated after the bio
2850 * leaves the driver, so changing the values around isn't
2851 * really an option. For now, just set the count to the
2852 * passed in length. This means that the calculations
2853 * above (e.g. bio_completed) will be correct, but the
2854 * amount of data reported to devstat will be slightly
2855 * under or overstated.
2857 bp->bio_bcount = bp->bio_length;
2863 case DISK_ZONE_GET_PARAMS: {
2864 struct disk_zone_disk_params *params;
2866 params = &bp->bio_zone.zone_params.disk_params;
2867 bzero(params, sizeof(*params));
2869 switch (softc->zone_mode) {
2870 case DA_ZONE_DRIVE_MANAGED:
2871 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
2873 case DA_ZONE_HOST_AWARE:
2874 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
2876 case DA_ZONE_HOST_MANAGED:
2877 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
2881 params->zone_mode = DISK_ZONE_MODE_NONE;
2885 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
2886 params->flags |= DISK_ZONE_DISK_URSWRZ;
2888 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
2889 params->optimal_seq_zones = softc->optimal_seq_zones;
2890 params->flags |= DISK_ZONE_OPT_SEQ_SET;
2893 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
2894 params->optimal_nonseq_zones =
2895 softc->optimal_nonseq_zones;
2896 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
2899 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
2900 params->max_seq_zones = softc->max_seq_zones;
2901 params->flags |= DISK_ZONE_MAX_SEQ_SET;
2903 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
2904 params->flags |= DISK_ZONE_RZ_SUP;
2906 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
2907 params->flags |= DISK_ZONE_OPEN_SUP;
2909 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
2910 params->flags |= DISK_ZONE_CLOSE_SUP;
2912 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
2913 params->flags |= DISK_ZONE_FINISH_SUP;
2915 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
2916 params->flags |= DISK_ZONE_RWP_SUP;
2927 dastart(struct cam_periph *periph, union ccb *start_ccb)
2929 struct da_softc *softc;
2931 softc = (struct da_softc *)periph->softc;
2933 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2936 switch (softc->state) {
2937 case DA_STATE_NORMAL:
2943 bp = cam_iosched_next_bio(softc->cam_iosched);
2945 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2946 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2947 scsi_test_unit_ready(&start_ccb->csio,
2948 /*retries*/ da_retry_count,
2952 da_default_timeout * 1000);
2953 start_ccb->ccb_h.ccb_bp = NULL;
2954 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2955 xpt_action(start_ccb);
2957 xpt_release_ccb(start_ccb);
2961 if (bp->bio_cmd == BIO_DELETE) {
2962 if (softc->delete_func != NULL) {
2963 softc->delete_func(periph, start_ccb, bp);
2966 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
2967 biofinish(bp, NULL, 0);
2972 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2973 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2974 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */
2977 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2978 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2979 softc->flags &= ~DA_FLAG_NEED_OTAG;
2980 softc->flags |= DA_FLAG_WAS_OTAG;
2981 tag_code = MSG_ORDERED_Q_TAG;
2983 tag_code = MSG_SIMPLE_Q_TAG;
2986 switch (bp->bio_cmd) {
2993 biotrack(bp, __func__);
2995 if (bp->bio_cmd == BIO_WRITE) {
2996 softc->flags |= DA_FLAG_DIRTY;
2997 rw_op = SCSI_RW_WRITE;
2999 rw_op = SCSI_RW_READ;
3002 data_ptr = bp->bio_data;
3003 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
3004 rw_op |= SCSI_RW_BIO;
3008 scsi_read_write(&start_ccb->csio,
3009 /*retries*/da_retry_count,
3011 /*tag_action*/tag_code,
3014 softc->minimum_cmd_size,
3015 /*lba*/bp->bio_pblkno,
3016 /*block_count*/bp->bio_bcount /
3017 softc->params.secsize,
3019 /*dxfer_len*/ bp->bio_bcount,
3020 /*sense_len*/SSD_FULL_SIZE,
3021 da_default_timeout * 1000);
3022 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3023 start_ccb->csio.bio = bp;
3029 * If we don't support sync cache, or the disk
3030 * isn't dirty, FLUSH is a no-op. Use the
3031 * allocated * CCB for the next bio if one is
3034 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) != 0 ||
3035 (softc->flags & DA_FLAG_DIRTY) == 0) {
3041 * BIO_FLUSH doesn't currently communicate
3042 * range data, so we synchronize the cache
3043 * over the whole disk. We also force
3044 * ordered tag semantics the flush applies
3045 * to all previously queued I/O.
3047 scsi_synchronize_cache(&start_ccb->csio,
3054 da_default_timeout*1000);
3056 * Clear the dirty flag before sending the command.
3057 * Either this sync cache will be successful, or it
3058 * will fail after a retry. If it fails, it is
3059 * unlikely to be successful if retried later, so
3060 * we'll save ourselves time by just marking the
3063 softc->flags &= ~DA_FLAG_DIRTY;
3066 int error, queue_ccb;
3070 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3072 || (queue_ccb == 0)) {
3073 biofinish(bp, NULL, error);
3074 xpt_release_ccb(start_ccb);
3080 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3081 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3082 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3085 LIST_INSERT_HEAD(&softc->pending_ccbs,
3086 &start_ccb->ccb_h, periph_links.le);
3088 /* We expect a unit attention from this device */
3089 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3090 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3091 softc->flags &= ~DA_FLAG_RETRY_UA;
3094 start_ccb->ccb_h.ccb_bp = bp;
3096 cam_periph_unlock(periph);
3097 xpt_action(start_ccb);
3098 cam_periph_lock(periph);
3101 /* May have more work to do, so ensure we stay scheduled */
3105 case DA_STATE_PROBE_RC:
3107 struct scsi_read_capacity_data *rcap;
3109 rcap = (struct scsi_read_capacity_data *)
3110 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3112 printf("dastart: Couldn't malloc read_capacity data\n");
3113 /* da_free_periph??? */
3116 scsi_read_capacity(&start_ccb->csio,
3117 /*retries*/da_retry_count,
3123 start_ccb->ccb_h.ccb_bp = NULL;
3124 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3125 xpt_action(start_ccb);
3128 case DA_STATE_PROBE_RC16:
3130 struct scsi_read_capacity_data_long *rcaplong;
3132 rcaplong = (struct scsi_read_capacity_data_long *)
3133 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3134 if (rcaplong == NULL) {
3135 printf("dastart: Couldn't malloc read_capacity data\n");
3136 /* da_free_periph??? */
3139 scsi_read_capacity_16(&start_ccb->csio,
3140 /*retries*/ da_retry_count,
3142 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3146 /*rcap_buf*/ (uint8_t *)rcaplong,
3147 /*rcap_buf_len*/ sizeof(*rcaplong),
3148 /*sense_len*/ SSD_FULL_SIZE,
3149 /*timeout*/ da_default_timeout * 1000);
3150 start_ccb->ccb_h.ccb_bp = NULL;
3151 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3152 xpt_action(start_ccb);
3155 case DA_STATE_PROBE_LBP:
3157 struct scsi_vpd_logical_block_prov *lbp;
3159 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3161 * If we get here we don't support any SBC-3 delete
3162 * methods with UNMAP as the Logical Block Provisioning
3163 * VPD page support is required for devices which
3164 * support it according to T10/1799-D Revision 31
3165 * however older revisions of the spec don't mandate
3166 * this so we currently don't remove these methods
3167 * from the available set.
3169 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3173 lbp = (struct scsi_vpd_logical_block_prov *)
3174 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3177 printf("dastart: Couldn't malloc lbp data\n");
3178 /* da_free_periph??? */
3182 scsi_inquiry(&start_ccb->csio,
3183 /*retries*/da_retry_count,
3185 /*tag_action*/MSG_SIMPLE_Q_TAG,
3186 /*inq_buf*/(u_int8_t *)lbp,
3187 /*inq_len*/sizeof(*lbp),
3189 /*page_code*/SVPD_LBP,
3190 /*sense_len*/SSD_MIN_SIZE,
3191 /*timeout*/da_default_timeout * 1000);
3192 start_ccb->ccb_h.ccb_bp = NULL;
3193 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3194 xpt_action(start_ccb);
3197 case DA_STATE_PROBE_BLK_LIMITS:
3199 struct scsi_vpd_block_limits *block_limits;
3201 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3202 /* Not supported skip to next probe */
3203 softc->state = DA_STATE_PROBE_BDC;
3207 block_limits = (struct scsi_vpd_block_limits *)
3208 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3210 if (block_limits == NULL) {
3211 printf("dastart: Couldn't malloc block_limits data\n");
3212 /* da_free_periph??? */
3216 scsi_inquiry(&start_ccb->csio,
3217 /*retries*/da_retry_count,
3219 /*tag_action*/MSG_SIMPLE_Q_TAG,
3220 /*inq_buf*/(u_int8_t *)block_limits,
3221 /*inq_len*/sizeof(*block_limits),
3223 /*page_code*/SVPD_BLOCK_LIMITS,
3224 /*sense_len*/SSD_MIN_SIZE,
3225 /*timeout*/da_default_timeout * 1000);
3226 start_ccb->ccb_h.ccb_bp = NULL;
3227 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3228 xpt_action(start_ccb);
3231 case DA_STATE_PROBE_BDC:
3233 struct scsi_vpd_block_characteristics *bdc;
3235 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3236 softc->state = DA_STATE_PROBE_ATA;
3240 bdc = (struct scsi_vpd_block_characteristics *)
3241 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3244 printf("dastart: Couldn't malloc bdc data\n");
3245 /* da_free_periph??? */
3249 scsi_inquiry(&start_ccb->csio,
3250 /*retries*/da_retry_count,
3252 /*tag_action*/MSG_SIMPLE_Q_TAG,
3253 /*inq_buf*/(u_int8_t *)bdc,
3254 /*inq_len*/sizeof(*bdc),
3256 /*page_code*/SVPD_BDC,
3257 /*sense_len*/SSD_MIN_SIZE,
3258 /*timeout*/da_default_timeout * 1000);
3259 start_ccb->ccb_h.ccb_bp = NULL;
3260 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3261 xpt_action(start_ccb);
3264 case DA_STATE_PROBE_ATA:
3266 struct ata_params *ata_params;
3268 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3269 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3270 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3272 * Note that if the ATA VPD page isn't
3273 * supported, we aren't talking to an ATA
3274 * device anyway. Support for that VPD
3275 * page is mandatory for SCSI to ATA (SAT)
3276 * translation layers.
3278 softc->state = DA_STATE_PROBE_ZONE;
3281 daprobedone(periph, start_ccb);
3285 ata_params = (struct ata_params*)
3286 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3288 if (ata_params == NULL) {
3289 xpt_print(periph->path, "Couldn't malloc ata_params "
3291 /* da_free_periph??? */
3295 scsi_ata_identify(&start_ccb->csio,
3296 /*retries*/da_retry_count,
3298 /*tag_action*/MSG_SIMPLE_Q_TAG,
3299 /*data_ptr*/(u_int8_t *)ata_params,
3300 /*dxfer_len*/sizeof(*ata_params),
3301 /*sense_len*/SSD_FULL_SIZE,
3302 /*timeout*/da_default_timeout * 1000);
3303 start_ccb->ccb_h.ccb_bp = NULL;
3304 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3305 xpt_action(start_ccb);
3308 case DA_STATE_PROBE_ATA_LOGDIR:
3310 struct ata_gp_log_dir *log_dir;
3315 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3317 * If we don't have log support, not much point in
3318 * trying to probe zone support.
3320 daprobedone(periph, start_ccb);
3325 * If we have an ATA device (the SCSI ATA Information VPD
3326 * page should be present and the ATA identify should have
3327 * succeeded) and it supports logs, ask for the log directory.
3330 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3331 if (log_dir == NULL) {
3332 xpt_print(periph->path, "Couldn't malloc log_dir "
3334 daprobedone(periph, start_ccb);
3338 retval = scsi_ata_read_log(&start_ccb->csio,
3339 /*retries*/ da_retry_count,
3341 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3342 /*log_address*/ ATA_LOG_DIRECTORY,
3345 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3346 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3347 /*data_ptr*/ (uint8_t *)log_dir,
3348 /*dxfer_len*/ sizeof(*log_dir),
3349 /*sense_len*/ SSD_FULL_SIZE,
3350 /*timeout*/ da_default_timeout * 1000);
3353 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3354 free(log_dir, M_SCSIDA);
3355 daprobedone(periph, start_ccb);
3358 start_ccb->ccb_h.ccb_bp = NULL;
3359 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3360 xpt_action(start_ccb);
3363 case DA_STATE_PROBE_ATA_IDDIR:
3365 struct ata_identify_log_pages *id_dir;
3371 * Check here to see whether the Identify Device log is
3372 * supported in the directory of logs. If so, continue
3373 * with requesting the log of identify device pages.
3375 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3376 daprobedone(periph, start_ccb);
3380 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3381 if (id_dir == NULL) {
3382 xpt_print(periph->path, "Couldn't malloc id_dir "
3384 daprobedone(periph, start_ccb);
3388 retval = scsi_ata_read_log(&start_ccb->csio,
3389 /*retries*/ da_retry_count,
3391 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3392 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3393 /*page_number*/ ATA_IDL_PAGE_LIST,
3395 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3396 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3397 /*data_ptr*/ (uint8_t *)id_dir,
3398 /*dxfer_len*/ sizeof(*id_dir),
3399 /*sense_len*/ SSD_FULL_SIZE,
3400 /*timeout*/ da_default_timeout * 1000);
3403 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3404 free(id_dir, M_SCSIDA);
3405 daprobedone(periph, start_ccb);
3408 start_ccb->ccb_h.ccb_bp = NULL;
3409 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3410 xpt_action(start_ccb);
3413 case DA_STATE_PROBE_ATA_SUP:
3415 struct ata_identify_log_sup_cap *sup_cap;
3421 * Check here to see whether the Supported Capabilities log
3422 * is in the list of Identify Device logs.
3424 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3425 daprobedone(periph, start_ccb);
3429 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3430 if (sup_cap == NULL) {
3431 xpt_print(periph->path, "Couldn't malloc sup_cap "
3433 daprobedone(periph, start_ccb);
3437 retval = scsi_ata_read_log(&start_ccb->csio,
3438 /*retries*/ da_retry_count,
3440 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3441 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3442 /*page_number*/ ATA_IDL_SUP_CAP,
3444 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3445 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3446 /*data_ptr*/ (uint8_t *)sup_cap,
3447 /*dxfer_len*/ sizeof(*sup_cap),
3448 /*sense_len*/ SSD_FULL_SIZE,
3449 /*timeout*/ da_default_timeout * 1000);
3452 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3453 free(sup_cap, M_SCSIDA);
3454 daprobedone(periph, start_ccb);
3459 start_ccb->ccb_h.ccb_bp = NULL;
3460 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3461 xpt_action(start_ccb);
3464 case DA_STATE_PROBE_ATA_ZONE:
3466 struct ata_zoned_info_log *ata_zone;
3472 * Check here to see whether the zoned device information
3473 * page is supported. If so, continue on to request it.
3474 * If not, skip to DA_STATE_PROBE_LOG or done.
3476 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3477 daprobedone(periph, start_ccb);
3480 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3482 if (ata_zone == NULL) {
3483 xpt_print(periph->path, "Couldn't malloc ata_zone "
3485 daprobedone(periph, start_ccb);
3489 retval = scsi_ata_read_log(&start_ccb->csio,
3490 /*retries*/ da_retry_count,
3492 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3493 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3494 /*page_number*/ ATA_IDL_ZDI,
3496 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3497 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3498 /*data_ptr*/ (uint8_t *)ata_zone,
3499 /*dxfer_len*/ sizeof(*ata_zone),
3500 /*sense_len*/ SSD_FULL_SIZE,
3501 /*timeout*/ da_default_timeout * 1000);
3504 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3505 free(ata_zone, M_SCSIDA);
3506 daprobedone(periph, start_ccb);
3509 start_ccb->ccb_h.ccb_bp = NULL;
3510 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3511 xpt_action(start_ccb);
3515 case DA_STATE_PROBE_ZONE:
3517 struct scsi_vpd_zoned_bdc *bdc;
3520 * Note that this page will be supported for SCSI protocol
3521 * devices that support ZBC (SMR devices), as well as ATA
3522 * protocol devices that are behind a SAT (SCSI to ATA
3523 * Translation) layer that supports converting ZBC commands
3524 * to their ZAC equivalents.
3526 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3527 daprobedone(periph, start_ccb);
3530 bdc = (struct scsi_vpd_zoned_bdc *)
3531 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3534 xpt_release_ccb(start_ccb);
3535 xpt_print(periph->path, "Couldn't malloc zone VPD "
3539 scsi_inquiry(&start_ccb->csio,
3540 /*retries*/da_retry_count,
3542 /*tag_action*/MSG_SIMPLE_Q_TAG,
3543 /*inq_buf*/(u_int8_t *)bdc,
3544 /*inq_len*/sizeof(*bdc),
3546 /*page_code*/SVPD_ZONED_BDC,
3547 /*sense_len*/SSD_FULL_SIZE,
3548 /*timeout*/da_default_timeout * 1000);
3549 start_ccb->ccb_h.ccb_bp = NULL;
3550 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3551 xpt_action(start_ccb);
3558 * In each of the methods below, while its the caller's
3559 * responsibility to ensure the request will fit into a
3560 * single device request, we might have changed the delete
3561 * method due to the device incorrectly advertising either
3562 * its supported methods or limits.
3564 * To prevent this causing further issues we validate the
3565 * against the methods limits, and warn which would
3566 * otherwise be unnecessary.
3569 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3571 struct da_softc *softc = (struct da_softc *)periph->softc;;
3573 uint8_t *buf = softc->unmap_buf;
3574 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3575 uint64_t lba, lastlba = (uint64_t)-1;
3576 uint64_t totalcount = 0;
3578 uint32_t c, lastcount = 0, ranges = 0;
3581 * Currently this doesn't take the UNMAP
3582 * Granularity and Granularity Alignment
3583 * fields into account.
3585 * This could result in both unoptimal unmap
3586 * requests as as well as UNMAP calls unmapping
3587 * fewer LBA's than requested.
3590 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3594 * Note: ada and da are different in how they store the
3595 * pending bp's in a trim. ada stores all of them in the
3596 * trim_req.bps. da stores all but the first one in the
3597 * delete_run_queue. ada then completes all the bps in
3598 * its adadone() loop. da completes all the bps in the
3599 * delete_run_queue in dadone, and relies on the biodone
3600 * after to complete. This should be reconciled since there's
3601 * no real reason to do it differently. XXX
3604 bioq_insert_tail(&softc->delete_run_queue, bp1);
3605 lba = bp1->bio_pblkno;
3606 count = bp1->bio_bcount / softc->params.secsize;
3608 /* Try to extend the previous range. */
3609 if (lba == lastlba) {
3610 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3613 scsi_ulto4b(lastcount, d[ranges - 1].length);
3617 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3618 softc->unmap_gran != 0) {
3619 /* Align length of the previous range. */
3620 if ((c = lastcount % softc->unmap_gran) != 0) {
3621 if (lastcount <= c) {
3622 totalcount -= lastcount;
3623 lastlba = (uint64_t)-1;
3630 scsi_ulto4b(lastcount, d[ranges - 1].length);
3633 /* Align beginning of the new range. */
3634 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3636 c = softc->unmap_gran - c;
3647 c = omin(count, UNMAP_RANGE_MAX);
3648 if (totalcount + c > softc->unmap_max_lba ||
3649 ranges >= softc->unmap_max_ranges) {
3650 xpt_print(periph->path,
3651 "%s issuing short delete %ld > %ld"
3653 da_delete_method_desc[softc->delete_method],
3654 totalcount + c, softc->unmap_max_lba,
3655 ranges, softc->unmap_max_ranges);
3658 scsi_u64to8b(lba, d[ranges].lba);
3659 scsi_ulto4b(c, d[ranges].length);
3667 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3670 if (ranges >= softc->unmap_max_ranges ||
3671 totalcount + bp1->bio_bcount /
3672 softc->params.secsize > softc->unmap_max_lba) {
3673 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3678 /* Align length of the last range. */
3679 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
3680 (c = lastcount % softc->unmap_gran) != 0) {
3684 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
3687 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3688 scsi_ulto2b(ranges * 16, &buf[2]);
3690 scsi_unmap(&ccb->csio,
3691 /*retries*/da_retry_count,
3693 /*tag_action*/MSG_SIMPLE_Q_TAG,
3696 /*dxfer_len*/ ranges * 16 + 8,
3697 /*sense_len*/SSD_FULL_SIZE,
3698 da_default_timeout * 1000);
3699 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3700 ccb->ccb_h.flags |= CAM_UNLOCKED;
3701 cam_iosched_submit_trim(softc->cam_iosched);
3705 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3707 struct da_softc *softc = (struct da_softc *)periph->softc;
3709 uint8_t *buf = softc->unmap_buf;
3710 uint64_t lastlba = (uint64_t)-1;
3713 uint32_t lastcount = 0, c, requestcount;
3714 int ranges = 0, off, block_count;
3716 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3719 if (bp1 != bp)//XXX imp XXX
3720 bioq_insert_tail(&softc->delete_run_queue, bp1);
3721 lba = bp1->bio_pblkno;
3722 count = bp1->bio_bcount / softc->params.secsize;
3723 requestcount = count;
3725 /* Try to extend the previous range. */
3726 if (lba == lastlba) {
3727 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3729 off = (ranges - 1) * 8;
3730 buf[off + 6] = lastcount & 0xff;
3731 buf[off + 7] = (lastcount >> 8) & 0xff;
3737 c = omin(count, ATA_DSM_RANGE_MAX);
3740 buf[off + 0] = lba & 0xff;
3741 buf[off + 1] = (lba >> 8) & 0xff;
3742 buf[off + 2] = (lba >> 16) & 0xff;
3743 buf[off + 3] = (lba >> 24) & 0xff;
3744 buf[off + 4] = (lba >> 32) & 0xff;
3745 buf[off + 5] = (lba >> 40) & 0xff;
3746 buf[off + 6] = c & 0xff;
3747 buf[off + 7] = (c >> 8) & 0xff;
3752 if (count != 0 && ranges == softc->trim_max_ranges) {
3753 xpt_print(periph->path,
3754 "%s issuing short delete %ld > %ld\n",
3755 da_delete_method_desc[softc->delete_method],
3757 (softc->trim_max_ranges - ranges) *
3763 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3766 if (bp1->bio_bcount / softc->params.secsize >
3767 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3768 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3773 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3774 scsi_ata_trim(&ccb->csio,
3775 /*retries*/da_retry_count,
3777 /*tag_action*/MSG_SIMPLE_Q_TAG,
3780 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3781 /*sense_len*/SSD_FULL_SIZE,
3782 da_default_timeout * 1000);
3783 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3784 ccb->ccb_h.flags |= CAM_UNLOCKED;
3785 cam_iosched_submit_trim(softc->cam_iosched);
3789 * We calculate ws_max_blks here based off d_delmaxsize instead
3790 * of using softc->ws_max_blks as it is absolute max for the
3791 * device not the protocol max which may well be lower.
3794 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3796 struct da_softc *softc;
3798 uint64_t ws_max_blks;
3800 uint64_t count; /* forward compat with WS32 */
3802 softc = (struct da_softc *)periph->softc;
3803 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3804 lba = bp->bio_pblkno;
3808 if (bp1 != bp)//XXX imp XXX
3809 bioq_insert_tail(&softc->delete_run_queue, bp1);
3810 count += bp1->bio_bcount / softc->params.secsize;
3811 if (count > ws_max_blks) {
3812 xpt_print(periph->path,
3813 "%s issuing short delete %ld > %ld\n",
3814 da_delete_method_desc[softc->delete_method],
3815 count, ws_max_blks);
3816 count = omin(count, ws_max_blks);
3819 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3822 if (lba + count != bp1->bio_pblkno ||
3823 count + bp1->bio_bcount /
3824 softc->params.secsize > ws_max_blks) {
3825 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3830 scsi_write_same(&ccb->csio,
3831 /*retries*/da_retry_count,
3833 /*tag_action*/MSG_SIMPLE_Q_TAG,
3834 /*byte2*/softc->delete_method ==
3835 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3836 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3838 /*block_count*/count,
3839 /*data_ptr*/ __DECONST(void *, zero_region),
3840 /*dxfer_len*/ softc->params.secsize,
3841 /*sense_len*/SSD_FULL_SIZE,
3842 da_default_timeout * 1000);
3843 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3844 ccb->ccb_h.flags |= CAM_UNLOCKED;
3845 cam_iosched_submit_trim(softc->cam_iosched);
3849 cmd6workaround(union ccb *ccb)
3851 struct scsi_rw_6 cmd6;
3852 struct scsi_rw_10 *cmd10;
3853 struct da_softc *softc;
3858 cdb = ccb->csio.cdb_io.cdb_bytes;
3859 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3861 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3862 da_delete_methods old_method = softc->delete_method;
3865 * Typically there are two reasons for failure here
3866 * 1. Delete method was detected as supported but isn't
3867 * 2. Delete failed due to invalid params e.g. too big
3869 * While we will attempt to choose an alternative delete method
3870 * this may result in short deletes if the existing delete
3871 * requests from geom are big for the new method chosen.
3873 * This method assumes that the error which triggered this
3874 * will not retry the io otherwise a panic will occur
3876 dadeleteflag(softc, old_method, 0);
3877 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3878 if (softc->delete_method == DA_DELETE_DISABLE)
3879 xpt_print(ccb->ccb_h.path,
3880 "%s failed, disabling BIO_DELETE\n",
3881 da_delete_method_desc[old_method]);
3883 xpt_print(ccb->ccb_h.path,
3884 "%s failed, switching to %s BIO_DELETE\n",
3885 da_delete_method_desc[old_method],
3886 da_delete_method_desc[softc->delete_method]);
3888 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3889 cam_iosched_queue_work(softc->cam_iosched, bp);
3890 cam_iosched_queue_work(softc->cam_iosched,
3891 (struct bio *)ccb->ccb_h.ccb_bp);
3892 ccb->ccb_h.ccb_bp = NULL;
3896 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3897 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3898 (*cdb == PREVENT_ALLOW) &&
3899 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3901 xpt_print(ccb->ccb_h.path,
3902 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3903 softc->quirks |= DA_Q_NO_PREVENT;
3907 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3908 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3909 (*cdb == SYNCHRONIZE_CACHE) &&
3910 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3912 xpt_print(ccb->ccb_h.path,
3913 "SYNCHRONIZE CACHE(10) not supported.\n");
3914 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3915 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3919 /* Translation only possible if CDB is an array and cmd is R/W6 */
3920 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3921 (*cdb != READ_6 && *cdb != WRITE_6))
3924 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3925 "increasing minimum_cmd_size to 10.\n");
3926 softc->minimum_cmd_size = 10;
3928 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3929 cmd10 = (struct scsi_rw_10 *)cdb;
3930 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3932 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3933 cmd10->reserved = 0;
3934 scsi_ulto2b(cmd6.length, cmd10->length);
3935 cmd10->control = cmd6.control;
3936 ccb->csio.cdb_len = sizeof(*cmd10);
3938 /* Requeue request, unfreezing queue if necessary */
3939 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3940 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3943 cam_release_devq(ccb->ccb_h.path,
3947 /*getcount_only*/0);
3953 dazonedone(struct cam_periph *periph, union ccb *ccb)
3955 struct da_softc *softc;
3958 softc = periph->softc;
3959 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3961 switch (bp->bio_zone.zone_cmd) {
3962 case DISK_ZONE_OPEN:
3963 case DISK_ZONE_CLOSE:
3964 case DISK_ZONE_FINISH:
3967 case DISK_ZONE_REPORT_ZONES: {
3969 struct disk_zone_report *rep;
3970 struct scsi_report_zones_hdr *hdr;
3971 struct scsi_report_zones_desc *desc;
3972 struct disk_zone_rep_entry *entry;
3973 uint32_t num_alloced, hdr_len, num_avail;
3974 uint32_t num_to_fill, i;
3977 rep = &bp->bio_zone.zone_params.report;
3978 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
3980 * Note that bio_resid isn't normally used for zone
3981 * commands, but it is used by devstat_end_transaction_bio()
3982 * to determine how much data was transferred. Because
3983 * the size of the SCSI/ATA data structures is different
3984 * than the size of the BIO interface structures, the
3985 * amount of data actually transferred from the drive will
3986 * be different than the amount of data transferred to
3989 bp->bio_resid = ccb->csio.resid;
3990 num_alloced = rep->entries_allocated;
3991 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
3992 if (avail_len < sizeof(*hdr)) {
3994 * Is there a better error than EIO here? We asked
3995 * for at least the header, and we got less than
3998 bp->bio_error = EIO;
3999 bp->bio_flags |= BIO_ERROR;
4000 bp->bio_resid = bp->bio_bcount;
4004 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4009 hdr_len = ata ? le32dec(hdr->length) :
4010 scsi_4btoul(hdr->length);
4012 rep->entries_available = hdr_len / sizeof(*desc);
4014 rep->entries_available = 0;
4016 * NOTE: using the same values for the BIO version of the
4017 * same field as the SCSI/ATA values. This means we could
4018 * get some additional values that aren't defined in bio.h
4019 * if more values of the same field are defined later.
4021 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4022 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4023 scsi_8btou64(hdr->maximum_lba);
4025 * If the drive reports no entries that match the query,
4029 rep->entries_filled = 0;
4033 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4034 hdr_len / sizeof(*desc));
4036 * If the drive didn't return any data, then we're done.
4038 if (num_avail == 0) {
4039 rep->entries_filled = 0;
4043 num_to_fill = min(num_avail, rep->entries_allocated);
4045 * If the user didn't allocate any entries for us to fill,
4048 if (num_to_fill == 0) {
4049 rep->entries_filled = 0;
4053 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4054 i < num_to_fill; i++, desc++, entry++) {
4056 * NOTE: we're mapping the values here directly
4057 * from the SCSI/ATA bit definitions to the bio.h
4058 * definitons. There is also a warning in
4059 * disk_zone.h, but the impact is that if
4060 * additional values are added in the SCSI/ATA
4061 * specs these will be visible to consumers of
4064 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4065 entry->zone_condition =
4066 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4067 SRZ_ZONE_COND_SHIFT;
4068 entry->zone_flags |= desc->zone_flags &
4069 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4070 entry->zone_length =
4071 ata ? le64dec(desc->zone_length) :
4072 scsi_8btou64(desc->zone_length);
4073 entry->zone_start_lba =
4074 ata ? le64dec(desc->zone_start_lba) :
4075 scsi_8btou64(desc->zone_start_lba);
4076 entry->write_pointer_lba =
4077 ata ? le64dec(desc->write_pointer_lba) :
4078 scsi_8btou64(desc->write_pointer_lba);
4080 rep->entries_filled = num_to_fill;
4083 case DISK_ZONE_GET_PARAMS:
4086 * In theory we should not get a GET_PARAMS bio, since it
4087 * should be handled without queueing the command to the
4090 panic("%s: Invalid zone command %d", __func__,
4091 bp->bio_zone.zone_cmd);
4095 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4096 free(ccb->csio.data_ptr, M_SCSIDA);
4100 dadone(struct cam_periph *periph, union ccb *done_ccb)
4102 struct da_softc *softc;
4103 struct ccb_scsiio *csio;
4107 softc = (struct da_softc *)periph->softc;
4108 priority = done_ccb->ccb_h.pinfo.priority;
4110 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4112 csio = &done_ccb->csio;
4113 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4114 if (csio->bio != NULL)
4115 biotrack(csio->bio, __func__);
4117 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4119 case DA_CCB_BUFFER_IO:
4122 struct bio *bp, *bp1;
4124 cam_periph_lock(periph);
4125 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4126 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4130 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4135 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4136 if (error == ERESTART) {
4138 * A retry was scheduled, so
4141 cam_periph_unlock(periph);
4144 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4149 * return all queued I/O with EIO, so that
4150 * the client can retry these I/Os in the
4151 * proper order should it attempt to recover.
4156 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4158 * Catastrophic error. Mark our pack as
4162 * XXX See if this is really a media
4165 xpt_print(periph->path,
4166 "Invalidating pack\n");
4167 softc->flags |= DA_FLAG_PACK_INVALID;
4169 softc->invalidations++;
4171 queued_error = ENXIO;
4173 cam_iosched_flush(softc->cam_iosched, NULL,
4176 bp->bio_error = error;
4177 bp->bio_resid = bp->bio_bcount;
4178 bp->bio_flags |= BIO_ERROR;
4180 } else if (bp != NULL) {
4181 if (state == DA_CCB_DELETE)
4184 bp->bio_resid = csio->resid;
4186 if (bp->bio_resid != 0)
4187 bp->bio_flags |= BIO_ERROR;
4189 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4190 cam_release_devq(done_ccb->ccb_h.path,
4194 /*getcount_only*/0);
4195 } else if (bp != NULL) {
4196 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4197 panic("REQ_CMP with QFRZN");
4198 if (bp->bio_cmd == BIO_ZONE)
4199 dazonedone(periph, done_ccb);
4200 else if (state == DA_CCB_DELETE)
4203 bp->bio_resid = csio->resid;
4204 if ((csio->resid > 0)
4205 && (bp->bio_cmd != BIO_ZONE))
4206 bp->bio_flags |= BIO_ERROR;
4207 if (softc->error_inject != 0) {
4208 bp->bio_error = softc->error_inject;
4209 bp->bio_resid = bp->bio_bcount;
4210 bp->bio_flags |= BIO_ERROR;
4211 softc->error_inject = 0;
4216 biotrack(bp, __func__);
4217 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4218 if (LIST_EMPTY(&softc->pending_ccbs))
4219 softc->flags |= DA_FLAG_WAS_OTAG;
4222 * We need to call cam_iosched before we call biodone so that we
4223 * don't measure any activity that happens in the completion
4224 * routine, which in the case of sendfile can be quite
4227 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4228 xpt_release_ccb(done_ccb);
4229 if (state == DA_CCB_DELETE) {
4230 TAILQ_HEAD(, bio) queue;
4233 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4234 softc->delete_run_queue.insert_point = NULL;
4236 * Normally, the xpt_release_ccb() above would make sure
4237 * that when we have more work to do, that work would
4238 * get kicked off. However, we specifically keep
4239 * delete_running set to 0 before the call above to
4240 * allow other I/O to progress when many BIO_DELETE
4241 * requests are pushed down. We set delete_running to 0
4242 * and call daschedule again so that we don't stall if
4243 * there are no other I/Os pending apart from BIO_DELETEs.
4245 cam_iosched_trim_done(softc->cam_iosched);
4247 cam_periph_unlock(periph);
4248 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4249 TAILQ_REMOVE(&queue, bp1, bio_queue);
4250 bp1->bio_error = bp->bio_error;
4251 if (bp->bio_flags & BIO_ERROR) {
4252 bp1->bio_flags |= BIO_ERROR;
4253 bp1->bio_resid = bp1->bio_bcount;
4260 cam_periph_unlock(periph);
4266 case DA_CCB_PROBE_RC:
4267 case DA_CCB_PROBE_RC16:
4269 struct scsi_read_capacity_data *rdcap;
4270 struct scsi_read_capacity_data_long *rcaplong;
4277 /* XXX TODO: can this be a malloc? */
4278 announce_buf = softc->announce_temp;
4279 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4281 if (state == DA_CCB_PROBE_RC)
4282 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4284 rcaplong = (struct scsi_read_capacity_data_long *)
4287 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4288 struct disk_params *dp;
4289 uint32_t block_size;
4291 u_int lalba; /* Lowest aligned LBA. */
4293 if (state == DA_CCB_PROBE_RC) {
4294 block_size = scsi_4btoul(rdcap->length);
4295 maxsector = scsi_4btoul(rdcap->addr);
4299 * According to SBC-2, if the standard 10
4300 * byte READ CAPACITY command returns 2^32,
4301 * we should issue the 16 byte version of
4302 * the command, since the device in question
4303 * has more sectors than can be represented
4304 * with the short version of the command.
4306 if (maxsector == 0xffffffff) {
4307 free(rdcap, M_SCSIDA);
4308 xpt_release_ccb(done_ccb);
4309 softc->state = DA_STATE_PROBE_RC16;
4310 xpt_schedule(periph, priority);
4314 block_size = scsi_4btoul(rcaplong->length);
4315 maxsector = scsi_8btou64(rcaplong->addr);
4316 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4320 * Because GEOM code just will panic us if we
4321 * give them an 'illegal' value we'll avoid that
4324 if (block_size == 0) {
4329 if (block_size >= MAXPHYS) {
4330 xpt_print(periph->path,
4331 "unsupportable block size %ju\n",
4332 (uintmax_t) block_size);
4333 announce_buf = NULL;
4334 cam_periph_invalidate(periph);
4337 * We pass rcaplong into dasetgeom(),
4338 * because it will only use it if it is
4341 dasetgeom(periph, block_size, maxsector,
4342 rcaplong, sizeof(*rcaplong));
4343 lbp = (lalba & SRC16_LBPME_A);
4344 dp = &softc->params;
4345 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4346 "%juMB (%ju %u byte sectors)",
4347 ((uintmax_t)dp->secsize * dp->sectors) /
4349 (uintmax_t)dp->sectors, dp->secsize);
4355 * Retry any UNIT ATTENTION type errors. They
4356 * are expected at boot.
4358 error = daerror(done_ccb, CAM_RETRY_SELTO,
4359 SF_RETRY_UA|SF_NO_PRINT);
4360 if (error == ERESTART) {
4362 * A retry was scheuled, so
4366 } else if (error != 0) {
4368 int sense_key, error_code;
4371 struct ccb_getdev cgd;
4373 /* Don't wedge this device's queue */
4374 status = done_ccb->ccb_h.status;
4375 if ((status & CAM_DEV_QFRZN) != 0)
4376 cam_release_devq(done_ccb->ccb_h.path,
4380 /*getcount_only*/0);
4383 xpt_setup_ccb(&cgd.ccb_h,
4384 done_ccb->ccb_h.path,
4385 CAM_PRIORITY_NORMAL);
4386 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4387 xpt_action((union ccb *)&cgd);
4389 if (scsi_extract_sense_ccb(done_ccb,
4390 &error_code, &sense_key, &asc, &ascq))
4396 * If we tried READ CAPACITY(16) and failed,
4397 * fallback to READ CAPACITY(10).
4399 if ((state == DA_CCB_PROBE_RC16) &&
4400 (softc->flags & DA_FLAG_CAN_RC16) &&
4401 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4404 (error_code == SSD_CURRENT_ERROR) &&
4405 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4406 softc->flags &= ~DA_FLAG_CAN_RC16;
4407 free(rdcap, M_SCSIDA);
4408 xpt_release_ccb(done_ccb);
4409 softc->state = DA_STATE_PROBE_RC;
4410 xpt_schedule(periph, priority);
4415 * Attach to anything that claims to be a
4416 * direct access or optical disk device,
4417 * as long as it doesn't return a "Logical
4418 * unit not supported" (0x25) error.
4419 * "Internal Target Failure" (0x44) is also
4420 * special and typically means that the
4421 * device is a SATA drive behind a SATL
4422 * translation that's fallen into a
4423 * terminally fatal state.
4426 && (asc != 0x25) && (asc != 0x44)
4427 && (error_code == SSD_CURRENT_ERROR)) {
4428 const char *sense_key_desc;
4429 const char *asc_desc;
4431 dasetgeom(periph, 512, -1, NULL, 0);
4432 scsi_sense_desc(sense_key, asc, ascq,
4436 snprintf(announce_buf,
4438 "Attempt to query device "
4439 "size failed: %s, %s",
4440 sense_key_desc, asc_desc);
4446 xpt_print(periph->path,
4447 "got CAM status %#x\n",
4448 done_ccb->ccb_h.status);
4451 xpt_print(periph->path, "fatal error, "
4452 "failed to attach to device\n");
4454 announce_buf = NULL;
4457 * Free up resources.
4459 cam_periph_invalidate(periph);
4463 free(csio->data_ptr, M_SCSIDA);
4464 if (announce_buf != NULL &&
4465 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4468 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4470 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4471 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4477 * Create our sysctl variables, now that we know
4478 * we have successfully attached.
4480 /* increase the refcount */
4481 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4483 taskqueue_enqueue(taskqueue_thread,
4484 &softc->sysctl_task);
4486 /* XXX This message is useless! */
4487 xpt_print(periph->path, "fatal error, "
4488 "could not acquire reference count\n");
4492 /* We already probed the device. */
4493 if (softc->flags & DA_FLAG_PROBED) {
4494 daprobedone(periph, done_ccb);
4498 /* Ensure re-probe doesn't see old delete. */
4499 softc->delete_available = 0;
4500 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4501 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4503 * Based on older SBC-3 spec revisions
4504 * any of the UNMAP methods "may" be
4505 * available via LBP given this flag so
4506 * we flag all of them as available and
4507 * then remove those which further
4508 * probes confirm aren't available
4511 * We could also check readcap(16) p_type
4512 * flag to exclude one or more invalid
4513 * write same (X) types here
4515 dadeleteflag(softc, DA_DELETE_WS16, 1);
4516 dadeleteflag(softc, DA_DELETE_WS10, 1);
4517 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4519 xpt_release_ccb(done_ccb);
4520 softc->state = DA_STATE_PROBE_LBP;
4521 xpt_schedule(periph, priority);
4525 xpt_release_ccb(done_ccb);
4526 softc->state = DA_STATE_PROBE_BDC;
4527 xpt_schedule(periph, priority);
4530 case DA_CCB_PROBE_LBP:
4532 struct scsi_vpd_logical_block_prov *lbp;
4534 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4536 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4538 * T10/1799-D Revision 31 states at least one of these
4539 * must be supported but we don't currently enforce this.
4541 dadeleteflag(softc, DA_DELETE_WS16,
4542 (lbp->flags & SVPD_LBP_WS16));
4543 dadeleteflag(softc, DA_DELETE_WS10,
4544 (lbp->flags & SVPD_LBP_WS10));
4545 dadeleteflag(softc, DA_DELETE_UNMAP,
4546 (lbp->flags & SVPD_LBP_UNMAP));
4549 error = daerror(done_ccb, CAM_RETRY_SELTO,
4550 SF_RETRY_UA|SF_NO_PRINT);
4551 if (error == ERESTART)
4553 else if (error != 0) {
4554 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4555 /* Don't wedge this device's queue */
4556 cam_release_devq(done_ccb->ccb_h.path,
4560 /*getcount_only*/0);
4564 * Failure indicates we don't support any SBC-3
4565 * delete methods with UNMAP
4570 free(lbp, M_SCSIDA);
4571 xpt_release_ccb(done_ccb);
4572 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4573 xpt_schedule(periph, priority);
4576 case DA_CCB_PROBE_BLK_LIMITS:
4578 struct scsi_vpd_block_limits *block_limits;
4580 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4582 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4583 uint32_t max_txfer_len = scsi_4btoul(
4584 block_limits->max_txfer_len);
4585 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4586 block_limits->max_unmap_lba_cnt);
4587 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4588 block_limits->max_unmap_blk_cnt);
4589 uint32_t unmap_gran = scsi_4btoul(
4590 block_limits->opt_unmap_grain);
4591 uint32_t unmap_gran_align = scsi_4btoul(
4592 block_limits->unmap_grain_align);
4593 uint64_t ws_max_blks = scsi_8btou64(
4594 block_limits->max_write_same_length);
4596 if (max_txfer_len != 0) {
4597 softc->disk->d_maxsize = MIN(softc->maxio,
4598 (off_t)max_txfer_len * softc->params.secsize);
4602 * We should already support UNMAP but we check lba
4603 * and block count to be sure
4605 if (max_unmap_lba_cnt != 0x00L &&
4606 max_unmap_blk_cnt != 0x00L) {
4607 softc->unmap_max_lba = max_unmap_lba_cnt;
4608 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4610 if (unmap_gran > 1) {
4611 softc->unmap_gran = unmap_gran;
4612 if (unmap_gran_align & 0x80000000) {
4613 softc->unmap_gran_align =
4620 * Unexpected UNMAP limits which means the
4621 * device doesn't actually support UNMAP
4623 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4626 if (ws_max_blks != 0x00L)
4627 softc->ws_max_blks = ws_max_blks;
4630 error = daerror(done_ccb, CAM_RETRY_SELTO,
4631 SF_RETRY_UA|SF_NO_PRINT);
4632 if (error == ERESTART)
4634 else if (error != 0) {
4635 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4636 /* Don't wedge this device's queue */
4637 cam_release_devq(done_ccb->ccb_h.path,
4641 /*getcount_only*/0);
4645 * Failure here doesn't mean UNMAP is not
4646 * supported as this is an optional page.
4648 softc->unmap_max_lba = 1;
4649 softc->unmap_max_ranges = 1;
4653 free(block_limits, M_SCSIDA);
4654 xpt_release_ccb(done_ccb);
4655 softc->state = DA_STATE_PROBE_BDC;
4656 xpt_schedule(periph, priority);
4659 case DA_CCB_PROBE_BDC:
4661 struct scsi_vpd_block_device_characteristics *bdc;
4663 bdc = (struct scsi_vpd_block_device_characteristics *)
4666 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4670 * Disable queue sorting for non-rotational media
4673 u_int16_t old_rate = softc->disk->d_rotation_rate;
4675 valid_len = csio->dxfer_len - csio->resid;
4676 if (SBDC_IS_PRESENT(bdc, valid_len,
4677 medium_rotation_rate)) {
4678 softc->disk->d_rotation_rate =
4679 scsi_2btoul(bdc->medium_rotation_rate);
4680 if (softc->disk->d_rotation_rate ==
4681 SVPD_BDC_RATE_NON_ROTATING) {
4682 cam_iosched_set_sort_queue(
4683 softc->cam_iosched, 0);
4684 softc->rotating = 0;
4686 if (softc->disk->d_rotation_rate != old_rate) {
4687 disk_attr_changed(softc->disk,
4688 "GEOM::rotation_rate", M_NOWAIT);
4691 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4692 && (softc->zone_mode == DA_ZONE_NONE)) {
4695 if (scsi_vpd_supported_page(periph,
4696 SVPD_ATA_INFORMATION))
4702 * The Zoned field will only be set for
4703 * Drive Managed and Host Aware drives. If
4704 * they are Host Managed, the device type
4705 * in the standard INQUIRY data should be
4706 * set to T_ZBC_HM (0x14).
4708 if ((bdc->flags & SVPD_ZBC_MASK) ==
4710 softc->zone_mode = DA_ZONE_HOST_AWARE;
4711 softc->zone_interface = (ata_proto) ?
4712 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4713 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4715 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4716 softc->zone_interface = (ata_proto) ?
4717 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4718 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4720 xpt_print(periph->path, "Unknown zoned "
4722 bdc->flags & SVPD_ZBC_MASK);
4727 error = daerror(done_ccb, CAM_RETRY_SELTO,
4728 SF_RETRY_UA|SF_NO_PRINT);
4729 if (error == ERESTART)
4731 else if (error != 0) {
4732 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4733 /* Don't wedge this device's queue */
4734 cam_release_devq(done_ccb->ccb_h.path,
4738 /*getcount_only*/0);
4743 free(bdc, M_SCSIDA);
4744 xpt_release_ccb(done_ccb);
4745 softc->state = DA_STATE_PROBE_ATA;
4746 xpt_schedule(periph, priority);
4749 case DA_CCB_PROBE_ATA:
4752 struct ata_params *ata_params;
4757 ata_params = (struct ata_params *)csio->data_ptr;
4758 ptr = (uint16_t *)ata_params;
4762 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4765 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4766 ptr[i] = le16toh(ptr[i]);
4767 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4768 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4769 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4770 if (ata_params->max_dsm_blocks != 0)
4771 softc->trim_max_ranges = min(
4772 softc->trim_max_ranges,
4773 ata_params->max_dsm_blocks *
4774 ATA_DSM_BLK_RANGES);
4777 * Disable queue sorting for non-rotational media
4780 old_rate = softc->disk->d_rotation_rate;
4781 softc->disk->d_rotation_rate =
4782 ata_params->media_rotation_rate;
4783 if (softc->disk->d_rotation_rate ==
4784 ATA_RATE_NON_ROTATING) {
4785 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4786 softc->rotating = 0;
4788 if (softc->disk->d_rotation_rate != old_rate) {
4789 disk_attr_changed(softc->disk,
4790 "GEOM::rotation_rate", M_NOWAIT);
4793 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4794 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4796 if (ata_params->support.extension &
4798 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4801 * At this point, if we have a SATA host aware drive,
4802 * we communicate via ATA passthrough unless the
4803 * SAT layer supports ZBC -> ZAC translation. In
4807 * XXX KDM figure out how to detect a host managed
4810 if (softc->zone_mode == DA_ZONE_NONE) {
4812 * Note that we don't override the zone
4813 * mode or interface if it has already been
4814 * set. This is because it has either been
4815 * set as a quirk, or when we probed the
4816 * SCSI Block Device Characteristics page,
4817 * the zoned field was set. The latter
4818 * means that the SAT layer supports ZBC to
4819 * ZAC translation, and we would prefer to
4820 * use that if it is available.
4822 if ((ata_params->support3 &
4823 ATA_SUPPORT_ZONE_MASK) ==
4824 ATA_SUPPORT_ZONE_HOST_AWARE) {
4825 softc->zone_mode = DA_ZONE_HOST_AWARE;
4826 softc->zone_interface =
4827 DA_ZONE_IF_ATA_PASS;
4828 } else if ((ata_params->support3 &
4829 ATA_SUPPORT_ZONE_MASK) ==
4830 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4831 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4832 softc->zone_interface =
4833 DA_ZONE_IF_ATA_PASS;
4838 error = daerror(done_ccb, CAM_RETRY_SELTO,
4839 SF_RETRY_UA|SF_NO_PRINT);
4840 if (error == ERESTART)
4842 else if (error != 0) {
4843 if ((done_ccb->ccb_h.status &
4844 CAM_DEV_QFRZN) != 0) {
4845 /* Don't wedge this device's queue */
4846 cam_release_devq(done_ccb->ccb_h.path,
4850 /*getcount_only*/0);
4855 free(ata_params, M_SCSIDA);
4856 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4857 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4859 * If the ATA IDENTIFY failed, we could be talking
4860 * to a SCSI drive, although that seems unlikely,
4861 * since the drive did report that it supported the
4862 * ATA Information VPD page. If the ATA IDENTIFY
4863 * succeeded, and the SAT layer doesn't support
4864 * ZBC -> ZAC translation, continue on to get the
4865 * directory of ATA logs, and complete the rest of
4866 * the ZAC probe. If the SAT layer does support
4867 * ZBC -> ZAC translation, we want to use that,
4868 * and we'll probe the SCSI Zoned Block Device
4869 * Characteristics VPD page next.
4872 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4873 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4874 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4876 softc->state = DA_STATE_PROBE_ZONE;
4879 if (continue_probe != 0) {
4880 xpt_release_ccb(done_ccb);
4881 xpt_schedule(periph, priority);
4884 daprobedone(periph, done_ccb);
4887 case DA_CCB_PROBE_ATA_LOGDIR:
4891 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4893 softc->valid_logdir_len = 0;
4894 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4895 softc->valid_logdir_len =
4896 csio->dxfer_len - csio->resid;
4897 if (softc->valid_logdir_len > 0)
4898 bcopy(csio->data_ptr, &softc->ata_logdir,
4899 min(softc->valid_logdir_len,
4900 sizeof(softc->ata_logdir)));
4902 * Figure out whether the Identify Device log is
4903 * supported. The General Purpose log directory
4904 * has a header, and lists the number of pages
4905 * available for each GP log identified by the
4906 * offset into the list.
4908 if ((softc->valid_logdir_len >=
4909 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4910 && (le16dec(softc->ata_logdir.header) ==
4911 ATA_GP_LOG_DIR_VERSION)
4912 && (le16dec(&softc->ata_logdir.num_pages[
4913 (ATA_IDENTIFY_DATA_LOG *
4914 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4915 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4917 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4920 error = daerror(done_ccb, CAM_RETRY_SELTO,
4921 SF_RETRY_UA|SF_NO_PRINT);
4922 if (error == ERESTART)
4924 else if (error != 0) {
4926 * If we can't get the ATA log directory,
4927 * then ATA logs are effectively not
4928 * supported even if the bit is set in the
4931 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
4932 DA_FLAG_CAN_ATA_IDLOG);
4933 if ((done_ccb->ccb_h.status &
4934 CAM_DEV_QFRZN) != 0) {
4935 /* Don't wedge this device's queue */
4936 cam_release_devq(done_ccb->ccb_h.path,
4940 /*getcount_only*/0);
4945 free(csio->data_ptr, M_SCSIDA);
4948 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
4949 softc->state = DA_STATE_PROBE_ATA_IDDIR;
4950 xpt_release_ccb(done_ccb);
4951 xpt_schedule(periph, priority);
4954 daprobedone(periph, done_ccb);
4957 case DA_CCB_PROBE_ATA_IDDIR:
4961 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4962 off_t entries_offset, max_entries;
4965 softc->valid_iddir_len = 0;
4966 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
4967 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
4968 DA_FLAG_CAN_ATA_ZONE);
4969 softc->valid_iddir_len =
4970 csio->dxfer_len - csio->resid;
4971 if (softc->valid_iddir_len > 0)
4972 bcopy(csio->data_ptr, &softc->ata_iddir,
4973 min(softc->valid_iddir_len,
4974 sizeof(softc->ata_iddir)));
4977 __offsetof(struct ata_identify_log_pages,entries);
4978 max_entries = softc->valid_iddir_len - entries_offset;
4979 if ((softc->valid_iddir_len > (entries_offset + 1))
4980 && (le64dec(softc->ata_iddir.header) ==
4982 && (softc->ata_iddir.entry_count > 0)) {
4985 num_entries = softc->ata_iddir.entry_count;
4986 num_entries = min(num_entries,
4987 softc->valid_iddir_len - entries_offset);
4988 for (i = 0; i < num_entries &&
4989 i < max_entries; i++) {
4990 if (softc->ata_iddir.entries[i] ==
4993 DA_FLAG_CAN_ATA_SUPCAP;
4994 else if (softc->ata_iddir.entries[i]==
4997 DA_FLAG_CAN_ATA_ZONE;
5000 DA_FLAG_CAN_ATA_SUPCAP)
5002 DA_FLAG_CAN_ATA_ZONE))
5007 error = daerror(done_ccb, CAM_RETRY_SELTO,
5008 SF_RETRY_UA|SF_NO_PRINT);
5009 if (error == ERESTART)
5011 else if (error != 0) {
5013 * If we can't get the ATA Identify Data log
5014 * directory, then it effectively isn't
5015 * supported even if the ATA Log directory
5016 * a non-zero number of pages present for
5019 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5020 if ((done_ccb->ccb_h.status &
5021 CAM_DEV_QFRZN) != 0) {
5022 /* Don't wedge this device's queue */
5023 cam_release_devq(done_ccb->ccb_h.path,
5027 /*getcount_only*/0);
5032 free(csio->data_ptr, M_SCSIDA);
5035 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5036 softc->state = DA_STATE_PROBE_ATA_SUP;
5037 xpt_release_ccb(done_ccb);
5038 xpt_schedule(periph, priority);
5041 daprobedone(periph, done_ccb);
5044 case DA_CCB_PROBE_ATA_SUP:
5048 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5051 struct ata_identify_log_sup_cap *sup_cap;
5054 sup_cap = (struct ata_identify_log_sup_cap *)
5056 valid_len = csio->dxfer_len - csio->resid;
5058 __offsetof(struct ata_identify_log_sup_cap,
5059 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5060 if (valid_len >= needed_size) {
5061 uint64_t zoned, zac_cap;
5063 zoned = le64dec(sup_cap->zoned_cap);
5064 if (zoned & ATA_ZONED_VALID) {
5066 * This should have already been
5067 * set, because this is also in the
5068 * ATA identify data.
5070 if ((zoned & ATA_ZONED_MASK) ==
5071 ATA_SUPPORT_ZONE_HOST_AWARE)
5074 else if ((zoned & ATA_ZONED_MASK) ==
5075 ATA_SUPPORT_ZONE_DEV_MANAGED)
5077 DA_ZONE_DRIVE_MANAGED;
5080 zac_cap = le64dec(sup_cap->sup_zac_cap);
5081 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5082 if (zac_cap & ATA_REPORT_ZONES_SUP)
5083 softc->zone_flags |=
5084 DA_ZONE_FLAG_RZ_SUP;
5085 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5086 softc->zone_flags |=
5087 DA_ZONE_FLAG_OPEN_SUP;
5088 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5089 softc->zone_flags |=
5090 DA_ZONE_FLAG_CLOSE_SUP;
5091 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5092 softc->zone_flags |=
5093 DA_ZONE_FLAG_FINISH_SUP;
5094 if (zac_cap & ATA_ND_RWP_SUP)
5095 softc->zone_flags |=
5096 DA_ZONE_FLAG_RWP_SUP;
5099 * This field was introduced in
5100 * ACS-4, r08 on April 28th, 2015.
5101 * If the drive firmware was written
5102 * to an earlier spec, it won't have
5103 * the field. So, assume all
5104 * commands are supported.
5106 softc->zone_flags |=
5107 DA_ZONE_FLAG_SUP_MASK;
5112 error = daerror(done_ccb, CAM_RETRY_SELTO,
5113 SF_RETRY_UA|SF_NO_PRINT);
5114 if (error == ERESTART)
5116 else if (error != 0) {
5118 * If we can't get the ATA Identify Data
5119 * Supported Capabilities page, clear the
5122 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5124 * And clear zone capabilities.
5126 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5127 if ((done_ccb->ccb_h.status &
5128 CAM_DEV_QFRZN) != 0) {
5129 /* Don't wedge this device's queue */
5130 cam_release_devq(done_ccb->ccb_h.path,
5134 /*getcount_only*/0);
5139 free(csio->data_ptr, M_SCSIDA);
5142 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5143 softc->state = DA_STATE_PROBE_ATA_ZONE;
5144 xpt_release_ccb(done_ccb);
5145 xpt_schedule(periph, priority);
5148 daprobedone(periph, done_ccb);
5151 case DA_CCB_PROBE_ATA_ZONE:
5155 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5156 struct ata_zoned_info_log *zi_log;
5160 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5162 valid_len = csio->dxfer_len - csio->resid;
5163 needed_size = __offsetof(struct ata_zoned_info_log,
5164 version_info) + 1 + sizeof(zi_log->version_info);
5165 if (valid_len >= needed_size) {
5168 tmpvar = le64dec(zi_log->zoned_cap);
5169 if (tmpvar & ATA_ZDI_CAP_VALID) {
5170 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5171 softc->zone_flags |=
5172 DA_ZONE_FLAG_URSWRZ;
5174 softc->zone_flags &=
5175 ~DA_ZONE_FLAG_URSWRZ;
5177 tmpvar = le64dec(zi_log->optimal_seq_zones);
5178 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5179 softc->zone_flags |=
5180 DA_ZONE_FLAG_OPT_SEQ_SET;
5181 softc->optimal_seq_zones = (tmpvar &
5182 ATA_ZDI_OPT_SEQ_MASK);
5184 softc->zone_flags &=
5185 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5186 softc->optimal_seq_zones = 0;
5189 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5190 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5191 softc->zone_flags |=
5192 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5193 softc->optimal_nonseq_zones =
5194 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5196 softc->zone_flags &=
5197 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5198 softc->optimal_nonseq_zones = 0;
5201 tmpvar = le64dec(zi_log->max_seq_req_zones);
5202 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5203 softc->zone_flags |=
5204 DA_ZONE_FLAG_MAX_SEQ_SET;
5205 softc->max_seq_zones =
5206 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5208 softc->zone_flags &=
5209 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5210 softc->max_seq_zones = 0;
5214 error = daerror(done_ccb, CAM_RETRY_SELTO,
5215 SF_RETRY_UA|SF_NO_PRINT);
5216 if (error == ERESTART)
5218 else if (error != 0) {
5219 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5220 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5222 if ((done_ccb->ccb_h.status &
5223 CAM_DEV_QFRZN) != 0) {
5224 /* Don't wedge this device's queue */
5225 cam_release_devq(done_ccb->ccb_h.path,
5229 /*getcount_only*/0);
5234 free(csio->data_ptr, M_SCSIDA);
5236 daprobedone(periph, done_ccb);
5239 case DA_CCB_PROBE_ZONE:
5243 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5246 struct scsi_vpd_zoned_bdc *zoned_bdc;
5249 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5251 valid_len = csio->dxfer_len - csio->resid;
5252 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5253 max_seq_req_zones) + 1 +
5254 sizeof(zoned_bdc->max_seq_req_zones);
5255 if ((valid_len >= needed_len)
5256 && (scsi_2btoul(zoned_bdc->page_length) >=
5258 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5259 softc->zone_flags |=
5260 DA_ZONE_FLAG_URSWRZ;
5262 softc->zone_flags &=
5263 ~DA_ZONE_FLAG_URSWRZ;
5264 softc->optimal_seq_zones =
5265 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5266 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5267 softc->optimal_nonseq_zones = scsi_4btoul(
5268 zoned_bdc->optimal_nonseq_zones);
5269 softc->zone_flags |=
5270 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5271 softc->max_seq_zones =
5272 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5273 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5276 * All of the zone commands are mandatory for SCSI
5279 * XXX KDM this is valid as of September 2015.
5280 * Re-check this assumption once the SAT spec is
5281 * updated to support SCSI ZBC to ATA ZAC mapping.
5282 * Since ATA allows zone commands to be reported
5283 * as supported or not, this may not necessarily
5284 * be true for an ATA device behind a SAT (SCSI to
5285 * ATA Translation) layer.
5287 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5289 error = daerror(done_ccb, CAM_RETRY_SELTO,
5290 SF_RETRY_UA|SF_NO_PRINT);
5291 if (error == ERESTART)
5293 else if (error != 0) {
5294 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5295 /* Don't wedge this device's queue */
5296 cam_release_devq(done_ccb->ccb_h.path,
5300 /*getcount_only*/0);
5304 daprobedone(periph, done_ccb);
5308 /* No-op. We're polling */
5312 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5314 if (daerror(done_ccb, CAM_RETRY_SELTO,
5315 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5318 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5319 cam_release_devq(done_ccb->ccb_h.path,
5323 /*getcount_only*/0);
5325 xpt_release_ccb(done_ccb);
5326 cam_periph_release_locked(periph);
5332 xpt_release_ccb(done_ccb);
5336 dareprobe(struct cam_periph *periph)
5338 struct da_softc *softc;
5341 softc = (struct da_softc *)periph->softc;
5343 /* Probe in progress; don't interfere. */
5344 if (softc->state != DA_STATE_NORMAL)
5347 status = cam_periph_acquire(periph);
5348 KASSERT(status == CAM_REQ_CMP,
5349 ("dareprobe: cam_periph_acquire failed"));
5351 if (softc->flags & DA_FLAG_CAN_RC16)
5352 softc->state = DA_STATE_PROBE_RC16;
5354 softc->state = DA_STATE_PROBE_RC;
5356 xpt_schedule(periph, CAM_PRIORITY_DEV);
5360 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5362 struct da_softc *softc;
5363 struct cam_periph *periph;
5364 int error, error_code, sense_key, asc, ascq;
5366 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5367 if (ccb->csio.bio != NULL)
5368 biotrack(ccb->csio.bio, __func__);
5371 periph = xpt_path_periph(ccb->ccb_h.path);
5372 softc = (struct da_softc *)periph->softc;
5375 * Automatically detect devices that do not support
5376 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5379 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5380 error = cmd6workaround(ccb);
5381 } else if (scsi_extract_sense_ccb(ccb,
5382 &error_code, &sense_key, &asc, &ascq)) {
5383 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5384 error = cmd6workaround(ccb);
5386 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5387 * query the capacity and notify upper layers.
5389 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5390 asc == 0x2A && ascq == 0x09) {
5391 xpt_print(periph->path, "Capacity data has changed\n");
5392 softc->flags &= ~DA_FLAG_PROBED;
5394 sense_flags |= SF_NO_PRINT;
5395 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5396 asc == 0x28 && ascq == 0x00) {
5397 softc->flags &= ~DA_FLAG_PROBED;
5398 disk_media_changed(softc->disk, M_NOWAIT);
5399 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5400 asc == 0x3F && ascq == 0x03) {
5401 xpt_print(periph->path, "INQUIRY data has changed\n");
5402 softc->flags &= ~DA_FLAG_PROBED;
5404 sense_flags |= SF_NO_PRINT;
5405 } else if (sense_key == SSD_KEY_NOT_READY &&
5406 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5407 softc->flags |= DA_FLAG_PACK_INVALID;
5408 disk_media_gone(softc->disk, M_NOWAIT);
5411 if (error == ERESTART)
5415 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5416 case CAM_CMD_TIMEOUT:
5419 case CAM_REQ_ABORTED:
5420 case CAM_REQ_CMP_ERR:
5421 case CAM_REQ_TERMIO:
5422 case CAM_UNREC_HBA_ERROR:
5423 case CAM_DATA_RUN_ERR:
5433 * Until we have a better way of doing pack validation,
5434 * don't treat UAs as errors.
5436 sense_flags |= SF_RETRY_UA;
5438 if (softc->quirks & DA_Q_RETRY_BUSY)
5439 sense_flags |= SF_RETRY_BUSY;
5440 return(cam_periph_error(ccb, cam_flags, sense_flags));
5444 damediapoll(void *arg)
5446 struct cam_periph *periph = arg;
5447 struct da_softc *softc = periph->softc;
5449 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5450 LIST_EMPTY(&softc->pending_ccbs)) {
5451 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5452 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5456 /* Queue us up again */
5457 if (da_poll_period != 0)
5458 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5462 daprevent(struct cam_periph *periph, int action)
5464 struct da_softc *softc;
5468 softc = (struct da_softc *)periph->softc;
5470 if (((action == PR_ALLOW)
5471 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5472 || ((action == PR_PREVENT)
5473 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5477 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5479 scsi_prevent(&ccb->csio,
5487 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5488 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5491 if (action == PR_ALLOW)
5492 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5494 softc->flags |= DA_FLAG_PACK_LOCKED;
5497 xpt_release_ccb(ccb);
5501 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5502 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5504 struct ccb_calc_geometry ccg;
5505 struct da_softc *softc;
5506 struct disk_params *dp;
5507 u_int lbppbe, lalba;
5510 softc = (struct da_softc *)periph->softc;
5512 dp = &softc->params;
5513 dp->secsize = block_len;
5514 dp->sectors = maxsector + 1;
5515 if (rcaplong != NULL) {
5516 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5517 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5518 lalba &= SRC16_LALBA_A;
5525 dp->stripesize = block_len << lbppbe;
5526 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5528 } else if (softc->quirks & DA_Q_4K) {
5529 dp->stripesize = 4096;
5530 dp->stripeoffset = 0;
5531 } else if (softc->unmap_gran != 0) {
5532 dp->stripesize = block_len * softc->unmap_gran;
5533 dp->stripeoffset = (dp->stripesize - block_len *
5534 softc->unmap_gran_align) % dp->stripesize;
5537 dp->stripeoffset = 0;
5540 * Have the controller provide us with a geometry
5541 * for this disk. The only time the geometry
5542 * matters is when we boot and the controller
5543 * is the only one knowledgeable enough to come
5544 * up with something that will make this a bootable
5547 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5548 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5549 ccg.block_size = dp->secsize;
5550 ccg.volume_size = dp->sectors;
5552 ccg.secs_per_track = 0;
5554 xpt_action((union ccb*)&ccg);
5555 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5557 * We don't know what went wrong here- but just pick
5558 * a geometry so we don't have nasty things like divide
5562 dp->secs_per_track = 255;
5563 dp->cylinders = dp->sectors / (255 * 255);
5564 if (dp->cylinders == 0) {
5568 dp->heads = ccg.heads;
5569 dp->secs_per_track = ccg.secs_per_track;
5570 dp->cylinders = ccg.cylinders;
5574 * If the user supplied a read capacity buffer, and if it is
5575 * different than the previous buffer, update the data in the EDT.
5576 * If it's the same, we don't bother. This avoids sending an
5577 * update every time someone opens this device.
5579 if ((rcaplong != NULL)
5580 && (bcmp(rcaplong, &softc->rcaplong,
5581 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5582 struct ccb_dev_advinfo cdai;
5584 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5585 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5586 cdai.buftype = CDAI_TYPE_RCAPLONG;
5587 cdai.flags = CDAI_FLAG_STORE;
5588 cdai.bufsiz = rcap_len;
5589 cdai.buf = (uint8_t *)rcaplong;
5590 xpt_action((union ccb *)&cdai);
5591 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5592 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5593 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5594 xpt_print(periph->path, "%s: failed to set read "
5595 "capacity advinfo\n", __func__);
5596 /* Use cam_error_print() to decode the status */
5597 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5600 bcopy(rcaplong, &softc->rcaplong,
5601 min(sizeof(softc->rcaplong), rcap_len));
5605 softc->disk->d_sectorsize = softc->params.secsize;
5606 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5607 softc->disk->d_stripesize = softc->params.stripesize;
5608 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5609 /* XXX: these are not actually "firmware" values, so they may be wrong */
5610 softc->disk->d_fwsectors = softc->params.secs_per_track;
5611 softc->disk->d_fwheads = softc->params.heads;
5612 softc->disk->d_devstat->block_size = softc->params.secsize;
5613 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5615 error = disk_resize(softc->disk, M_NOWAIT);
5617 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5621 dasendorderedtag(void *arg)
5623 struct da_softc *softc = arg;
5625 if (da_send_ordered) {
5626 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5627 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5628 softc->flags |= DA_FLAG_NEED_OTAG;
5629 softc->flags &= ~DA_FLAG_WAS_OTAG;
5632 /* Queue us up again */
5633 callout_reset(&softc->sendordered_c,
5634 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5635 dasendorderedtag, softc);
5639 * Step through all DA peripheral drivers, and if the device is still open,
5640 * sync the disk cache to physical media.
5643 dashutdown(void * arg, int howto)
5645 struct cam_periph *periph;
5646 struct da_softc *softc;
5650 CAM_PERIPH_FOREACH(periph, &dadriver) {
5651 softc = (struct da_softc *)periph->softc;
5652 if (SCHEDULER_STOPPED()) {
5653 /* If we paniced with the lock held, do not recurse. */
5654 if (!cam_periph_owned(periph) &&
5655 (softc->flags & DA_FLAG_OPEN)) {
5656 dadump(softc->disk, NULL, 0, 0, 0);
5660 cam_periph_lock(periph);
5663 * We only sync the cache if the drive is still open, and
5664 * if the drive is capable of it..
5666 if (((softc->flags & DA_FLAG_OPEN) == 0)
5667 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5668 cam_periph_unlock(periph);
5672 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5673 scsi_synchronize_cache(&ccb->csio,
5677 /*begin_lba*/0, /* whole disk */
5682 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5683 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5684 softc->disk->d_devstat);
5686 xpt_print(periph->path, "Synchronize cache failed\n");
5687 xpt_release_ccb(ccb);
5688 cam_periph_unlock(periph);
5692 #else /* !_KERNEL */
5695 * XXX These are only left out of the kernel build to silence warnings. If,
5696 * for some reason these functions are used in the kernel, the ifdefs should
5697 * be moved so they are included both in the kernel and userland.
5700 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5701 void (*cbfcnp)(struct cam_periph *, union ccb *),
5702 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5703 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5706 struct scsi_format_unit *scsi_cmd;
5708 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5709 scsi_cmd->opcode = FORMAT_UNIT;
5710 scsi_cmd->byte2 = byte2;
5711 scsi_ulto2b(ileave, scsi_cmd->interleave);
5716 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5726 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5727 void (*cbfcnp)(struct cam_periph *, union ccb *),
5728 uint8_t tag_action, uint8_t list_format,
5729 uint32_t addr_desc_index, uint8_t *data_ptr,
5730 uint32_t dxfer_len, int minimum_cmd_size,
5731 uint8_t sense_len, uint32_t timeout)
5736 * These conditions allow using the 10 byte command. Otherwise we
5737 * need to use the 12 byte command.
5739 if ((minimum_cmd_size <= 10)
5740 && (addr_desc_index == 0)
5741 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5742 struct scsi_read_defect_data_10 *cdb10;
5744 cdb10 = (struct scsi_read_defect_data_10 *)
5745 &csio->cdb_io.cdb_bytes;
5747 cdb_len = sizeof(*cdb10);
5748 bzero(cdb10, cdb_len);
5749 cdb10->opcode = READ_DEFECT_DATA_10;
5750 cdb10->format = list_format;
5751 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5753 struct scsi_read_defect_data_12 *cdb12;
5755 cdb12 = (struct scsi_read_defect_data_12 *)
5756 &csio->cdb_io.cdb_bytes;
5758 cdb_len = sizeof(*cdb12);
5759 bzero(cdb12, cdb_len);
5760 cdb12->opcode = READ_DEFECT_DATA_12;
5761 cdb12->format = list_format;
5762 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5763 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5769 /*flags*/ CAM_DIR_IN,
5779 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5780 void (*cbfcnp)(struct cam_periph *, union ccb *),
5781 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5782 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5785 struct scsi_sanitize *scsi_cmd;
5787 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5788 scsi_cmd->opcode = SANITIZE;
5789 scsi_cmd->byte2 = byte2;
5790 scsi_cmd->control = control;
5791 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5796 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5805 #endif /* _KERNEL */
5808 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5809 void (*cbfcnp)(struct cam_periph *, union ccb *),
5810 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5811 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5812 uint8_t sense_len, uint32_t timeout)
5814 struct scsi_zbc_out *scsi_cmd;
5816 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5817 scsi_cmd->opcode = ZBC_OUT;
5818 scsi_cmd->service_action = service_action;
5819 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5820 scsi_cmd->zone_flags = zone_flags;
5825 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5835 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5836 void (*cbfcnp)(struct cam_periph *, union ccb *),
5837 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5838 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5839 uint8_t sense_len, uint32_t timeout)
5841 struct scsi_zbc_in *scsi_cmd;
5843 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5844 scsi_cmd->opcode = ZBC_IN;
5845 scsi_cmd->service_action = service_action;
5846 scsi_ulto4b(dxfer_len, scsi_cmd->length);
5847 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5848 scsi_cmd->zone_options = zone_options;
5853 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5864 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5865 void (*cbfcnp)(struct cam_periph *, union ccb *),
5866 uint8_t tag_action, int use_ncq,
5867 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5868 uint8_t *data_ptr, uint32_t dxfer_len,
5869 uint8_t *cdb_storage, size_t cdb_storage_len,
5870 uint8_t sense_len, uint32_t timeout)
5872 uint8_t command_out, protocol, ata_flags;
5873 uint16_t features_out;
5874 uint32_t sectors_out, auxiliary;
5880 command_out = ATA_ZAC_MANAGEMENT_OUT;
5881 features_out = (zm_action & 0xf) | (zone_flags << 8);
5882 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5883 if (dxfer_len == 0) {
5884 protocol = AP_PROTO_NON_DATA;
5885 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5888 protocol = AP_PROTO_DMA;
5889 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5890 AP_FLAG_TDIR_TO_DEV;
5891 sectors_out = ((dxfer_len >> 9) & 0xffff);
5895 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5896 if (dxfer_len == 0) {
5897 command_out = ATA_NCQ_NON_DATA;
5898 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5900 * We're assuming the SCSI to ATA translation layer
5901 * will set the NCQ tag number in the tag field.
5902 * That isn't clear from the SAT-4 spec (as of rev 05).
5905 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5907 command_out = ATA_SEND_FPDMA_QUEUED;
5909 * Note that we're defaulting to normal priority,
5910 * and assuming that the SCSI to ATA translation
5911 * layer will insert the NCQ tag number in the tag
5912 * field. That isn't clear in the SAT-4 spec (as
5915 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5917 ata_flags |= AP_FLAG_TLEN_FEAT |
5918 AP_FLAG_TDIR_TO_DEV;
5921 * For SEND FPDMA QUEUED, the transfer length is
5922 * encoded in the FEATURE register, and 0 means
5923 * that 65536 512 byte blocks are to be tranferred.
5924 * In practice, it seems unlikely that we'll see
5925 * a transfer that large, and it may confuse the
5926 * the SAT layer, because generally that means that
5927 * 0 bytes should be transferred.
5929 if (dxfer_len == (65536 * 512)) {
5931 } else if (dxfer_len <= (65535 * 512)) {
5932 features_out = ((dxfer_len >> 9) & 0xffff);
5934 /* The transfer is too big. */
5941 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
5942 protocol = AP_PROTO_FPDMA;
5945 protocol |= AP_EXTEND;
5947 retval = scsi_ata_pass(csio,
5950 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5952 /*protocol*/ protocol,
5953 /*ata_flags*/ ata_flags,
5954 /*features*/ features_out,
5955 /*sector_count*/ sectors_out,
5957 /*command*/ command_out,
5960 /*auxiliary*/ auxiliary,
5962 /*data_ptr*/ data_ptr,
5963 /*dxfer_len*/ dxfer_len,
5964 /*cdb_storage*/ cdb_storage,
5965 /*cdb_storage_len*/ cdb_storage_len,
5966 /*minimum_cmd_size*/ 0,
5967 /*sense_len*/ SSD_FULL_SIZE,
5968 /*timeout*/ timeout);
5976 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
5977 void (*cbfcnp)(struct cam_periph *, union ccb *),
5978 uint8_t tag_action, int use_ncq,
5979 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5980 uint8_t *data_ptr, uint32_t dxfer_len,
5981 uint8_t *cdb_storage, size_t cdb_storage_len,
5982 uint8_t sense_len, uint32_t timeout)
5984 uint8_t command_out, protocol;
5985 uint16_t features_out, sectors_out;
5991 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
5994 command_out = ATA_ZAC_MANAGEMENT_IN;
5995 /* XXX KDM put a macro here */
5996 features_out = (zm_action & 0xf) | (zone_flags << 8);
5997 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
5998 protocol = AP_PROTO_DMA;
5999 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
6002 ata_flags |= AP_FLAG_TLEN_FEAT;
6004 command_out = ATA_RECV_FPDMA_QUEUED;
6005 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6008 * For RECEIVE FPDMA QUEUED, the transfer length is
6009 * encoded in the FEATURE register, and 0 means
6010 * that 65536 512 byte blocks are to be tranferred.
6011 * In practice, it seems unlikely that we'll see
6012 * a transfer that large, and it may confuse the
6013 * the SAT layer, because generally that means that
6014 * 0 bytes should be transferred.
6016 if (dxfer_len == (65536 * 512)) {
6018 } else if (dxfer_len <= (65535 * 512)) {
6019 features_out = ((dxfer_len >> 9) & 0xffff);
6021 /* The transfer is too big. */
6025 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6026 protocol = AP_PROTO_FPDMA;
6029 protocol |= AP_EXTEND;
6031 retval = scsi_ata_pass(csio,
6034 /*flags*/ CAM_DIR_IN,
6036 /*protocol*/ protocol,
6037 /*ata_flags*/ ata_flags,
6038 /*features*/ features_out,
6039 /*sector_count*/ sectors_out,
6041 /*command*/ command_out,
6044 /*auxiliary*/ auxiliary,
6046 /*data_ptr*/ data_ptr,
6047 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6048 /*cdb_storage*/ cdb_storage,
6049 /*cdb_storage_len*/ cdb_storage_len,
6050 /*minimum_cmd_size*/ 0,
6051 /*sense_len*/ SSD_FULL_SIZE,
6052 /*timeout*/ timeout);