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>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
41 #include <sys/sysctl.h>
42 #include <sys/taskqueue.h>
44 #include <sys/mutex.h>
46 #include <sys/devicestat.h>
47 #include <sys/eventhandler.h>
48 #include <sys/malloc.h>
50 #include <sys/endian.h>
53 #include <geom/geom.h>
54 #include <geom/geom_disk.h>
55 #include <machine/atomic.h>
64 #include <cam/cam_ccb.h>
65 #include <cam/cam_periph.h>
66 #include <cam/cam_xpt_periph.h>
68 #include <cam/cam_xpt_internal.h>
70 #include <cam/cam_sim.h>
71 #include <cam/cam_iosched.h>
73 #include <cam/scsi/scsi_message.h>
74 #include <cam/scsi/scsi_da.h>
78 * Note that there are probe ordering dependencies here. The order isn't
79 * controlled by this enumeration, but by explicit state transitions in
80 * dastart() and dadone(). Here are some of the dependencies:
82 * 1. RC should come first, before RC16, unless there is evidence that RC16
84 * 2. BDC needs to come before any of the ATA probes, or the ZONE probe.
85 * 3. The ATA probes should go in this order:
86 * ATA -> LOGDIR -> IDDIR -> SUP -> ATA_ZONE
93 DA_STATE_PROBE_BLK_LIMITS,
96 DA_STATE_PROBE_ATA_LOGDIR,
97 DA_STATE_PROBE_ATA_IDDIR,
98 DA_STATE_PROBE_ATA_SUP,
99 DA_STATE_PROBE_ATA_ZONE,
105 DA_FLAG_PACK_INVALID = 0x000001,
106 DA_FLAG_NEW_PACK = 0x000002,
107 DA_FLAG_PACK_LOCKED = 0x000004,
108 DA_FLAG_PACK_REMOVABLE = 0x000008,
109 DA_FLAG_NEED_OTAG = 0x000020,
110 DA_FLAG_WAS_OTAG = 0x000040,
111 DA_FLAG_RETRY_UA = 0x000080,
112 DA_FLAG_OPEN = 0x000100,
113 DA_FLAG_SCTX_INIT = 0x000200,
114 DA_FLAG_CAN_RC16 = 0x000400,
115 DA_FLAG_PROBED = 0x000800,
116 DA_FLAG_DIRTY = 0x001000,
117 DA_FLAG_ANNOUNCED = 0x002000,
118 DA_FLAG_CAN_ATA_DMA = 0x004000,
119 DA_FLAG_CAN_ATA_LOG = 0x008000,
120 DA_FLAG_CAN_ATA_IDLOG = 0x010000,
121 DA_FLAG_CAN_ATA_SUPCAP = 0x020000,
122 DA_FLAG_CAN_ATA_ZONE = 0x040000,
123 DA_FLAG_TUR_PENDING = 0x080000
128 DA_Q_NO_SYNC_CACHE = 0x01,
129 DA_Q_NO_6_BYTE = 0x02,
130 DA_Q_NO_PREVENT = 0x04,
133 DA_Q_NO_UNMAP = 0x20,
134 DA_Q_RETRY_BUSY = 0x40,
136 DA_Q_STRICT_UNMAP = 0x100,
140 #define DA_Q_BIT_STRING \
142 "\001NO_SYNC_CACHE" \
154 DA_CCB_PROBE_RC = 0x01,
155 DA_CCB_PROBE_RC16 = 0x02,
156 DA_CCB_PROBE_LBP = 0x03,
157 DA_CCB_PROBE_BLK_LIMITS = 0x04,
158 DA_CCB_PROBE_BDC = 0x05,
159 DA_CCB_PROBE_ATA = 0x06,
160 DA_CCB_BUFFER_IO = 0x07,
162 DA_CCB_DELETE = 0x0B,
164 DA_CCB_PROBE_ZONE = 0x0D,
165 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
166 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
167 DA_CCB_PROBE_ATA_SUP = 0x10,
168 DA_CCB_PROBE_ATA_ZONE = 0x11,
169 DA_CCB_PROBE_WP = 0x12,
170 DA_CCB_TYPE_MASK = 0x1F,
171 DA_CCB_RETRY_UA = 0x20
175 * Order here is important for method choice
177 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
178 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
179 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
180 * import taking 5mins.
191 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
192 DA_DELETE_MAX = DA_DELETE_ZERO
196 * For SCSI, host managed drives show up as a separate device type. For
197 * ATA, host managed drives also have a different device signature.
198 * XXX KDM figure out the ATA host managed signature.
202 DA_ZONE_DRIVE_MANAGED = 0x01,
203 DA_ZONE_HOST_AWARE = 0x02,
204 DA_ZONE_HOST_MANAGED = 0x03
208 * We distinguish between these interface cases in addition to the drive type:
209 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
210 * o ATA drive behind a SCSI translation layer that does not know about
211 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
212 * case, we would need to share the ATA code with the ada(4) driver.
222 DA_ZONE_FLAG_RZ_SUP = 0x0001,
223 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
224 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
225 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
226 DA_ZONE_FLAG_RWP_SUP = 0x0010,
227 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
228 DA_ZONE_FLAG_OPEN_SUP |
229 DA_ZONE_FLAG_CLOSE_SUP |
230 DA_ZONE_FLAG_FINISH_SUP |
231 DA_ZONE_FLAG_RWP_SUP),
232 DA_ZONE_FLAG_URSWRZ = 0x0020,
233 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
234 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
235 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
236 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
237 DA_ZONE_FLAG_OPT_NONSEQ_SET |
238 DA_ZONE_FLAG_MAX_SEQ_SET)
241 static struct da_zone_desc {
244 } da_zone_desc_table[] = {
245 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
246 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
247 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
248 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
249 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
252 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
254 static da_delete_func_t da_delete_trim;
255 static da_delete_func_t da_delete_unmap;
256 static da_delete_func_t da_delete_ws;
258 static const void * da_delete_functions[] = {
268 static const char *da_delete_method_names[] =
269 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
270 static const char *da_delete_method_desc[] =
271 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
272 "WRITE SAME(10) with UNMAP", "ZERO" };
274 /* Offsets into our private area for storing information */
275 #define ccb_state ppriv_field0
276 #define ccb_bp ppriv_ptr1
281 u_int8_t secs_per_track;
282 u_int32_t secsize; /* Number of bytes/sector */
283 u_int64_t sectors; /* total number sectors */
288 #define UNMAP_RANGE_MAX 0xffffffff
289 #define UNMAP_HEAD_SIZE 8
290 #define UNMAP_RANGE_SIZE 16
291 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
292 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
295 #define WS10_MAX_BLKS 0xffff
296 #define WS16_MAX_BLKS 0xffffffff
297 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
298 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
300 #define DA_WORK_TUR (1 << 16)
311 DA_REF_MAX /* KEEP LAST */
315 struct cam_iosched_softc *cam_iosched;
316 struct bio_queue_head delete_run_queue;
317 LIST_HEAD(, ccb_hdr) pending_ccbs;
318 int refcount; /* Active xpt_action() calls */
322 int minimum_cmd_size;
325 int delete_available; /* Delete methods possibly available */
326 da_zone_mode zone_mode;
327 da_zone_interface zone_interface;
328 da_zone_flags zone_flags;
329 struct ata_gp_log_dir ata_logdir;
330 int valid_logdir_len;
331 struct ata_identify_log_pages ata_iddir;
333 uint64_t optimal_seq_zones;
334 uint64_t optimal_nonseq_zones;
335 uint64_t max_seq_zones;
337 uint32_t unmap_max_ranges;
338 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
340 uint32_t unmap_gran_align;
341 uint64_t ws_max_blks;
343 uint64_t trim_ranges;
345 da_delete_methods delete_method_pref;
346 da_delete_methods delete_method;
347 da_delete_func_t *delete_func;
351 struct disk_params params;
354 struct task sysctl_task;
355 struct sysctl_ctx_list sysctl_ctx;
356 struct sysctl_oid *sysctl_tree;
357 struct callout sendordered_c;
359 uint8_t unmap_buf[UNMAP_BUF_SIZE];
360 struct scsi_read_capacity_data_long rcaplong;
361 struct callout mediapoll_c;
362 int ref_flags[DA_REF_MAX];
364 struct sysctl_ctx_list sysctl_stats_ctx;
365 struct sysctl_oid *sysctl_stats_tree;
370 #define DA_ANNOUNCETMP_SZ 160
371 char announce_temp[DA_ANNOUNCETMP_SZ];
372 #define DA_ANNOUNCE_SZ 400
373 char announcebuf[DA_ANNOUNCE_SZ];
376 #define dadeleteflag(softc, delete_method, enable) \
378 softc->delete_available |= (1 << delete_method); \
380 softc->delete_available &= ~(1 << delete_method); \
383 struct da_quirk_entry {
384 struct scsi_inquiry_pattern inq_pat;
388 static const char quantum[] = "QUANTUM";
389 static const char microp[] = "MICROP";
391 static struct da_quirk_entry da_quirk_table[] =
393 /* SPI, FC devices */
396 * Fujitsu M2513A MO drives.
397 * Tested devices: M2513A2 firmware versions 1200 & 1300.
398 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
399 * Reported by: W.Scholten <whs@xs4all.nl>
401 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
402 /*quirks*/ DA_Q_NO_SYNC_CACHE
406 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
407 /*quirks*/ DA_Q_NO_SYNC_CACHE
411 * This particular Fujitsu drive doesn't like the
412 * synchronize cache command.
413 * Reported by: Tom Jackson <toj@gorilla.net>
415 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
416 /*quirks*/ DA_Q_NO_SYNC_CACHE
420 * This drive doesn't like the synchronize cache command
421 * either. Reported by: Matthew Jacob <mjacob@feral.com>
422 * in NetBSD PR kern/6027, August 24, 1998.
424 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
425 /*quirks*/ DA_Q_NO_SYNC_CACHE
429 * This drive doesn't like the synchronize cache command
430 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
433 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
434 /*quirks*/ DA_Q_NO_SYNC_CACHE
438 * Doesn't like the synchronize cache command.
439 * Reported by: Blaz Zupan <blaz@gold.amis.net>
441 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
442 /*quirks*/ DA_Q_NO_SYNC_CACHE
446 * Doesn't like the synchronize cache command.
447 * Reported by: Blaz Zupan <blaz@gold.amis.net>
449 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
450 /*quirks*/ DA_Q_NO_SYNC_CACHE
454 * Doesn't like the synchronize cache command.
456 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
457 /*quirks*/ DA_Q_NO_SYNC_CACHE
461 * Doesn't like the synchronize cache command.
462 * Reported by: walter@pelissero.de
464 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
465 /*quirks*/ DA_Q_NO_SYNC_CACHE
469 * Doesn't work correctly with 6 byte reads/writes.
470 * Returns illegal request, and points to byte 9 of the
472 * Reported by: Adam McDougall <bsdx@spawnet.com>
474 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
475 /*quirks*/ DA_Q_NO_6_BYTE
479 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
480 /*quirks*/ DA_Q_NO_6_BYTE
484 * Doesn't like the synchronize cache command.
485 * Reported by: walter@pelissero.de
487 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
488 /*quirks*/ DA_Q_NO_SYNC_CACHE
492 * The CISS RAID controllers do not support SYNC_CACHE
494 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
495 /*quirks*/ DA_Q_NO_SYNC_CACHE
499 * The STEC SSDs sometimes hang on UNMAP.
501 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
502 /*quirks*/ DA_Q_NO_UNMAP
506 * VMware returns BUSY status when storage has transient
507 * connectivity problems, so better wait.
508 * Also VMware returns odd errors on misaligned UNMAPs.
510 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
511 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
513 /* USB mass storage devices supported by umass(4) */
516 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
519 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
520 /*quirks*/ DA_Q_NO_SYNC_CACHE
524 * Power Quotient Int. (PQI) USB flash key
527 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
528 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
532 * Creative Nomad MUVO mp3 player (USB)
535 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
536 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
540 * Jungsoft NEXDISK USB flash key
543 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
544 /*quirks*/ DA_Q_NO_SYNC_CACHE
548 * FreeDik USB Mini Data Drive
551 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
552 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
556 * Sigmatel USB Flash MP3 Player
559 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
560 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
564 * Neuros USB Digital Audio Computer
567 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
568 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
572 * SEAGRAND NP-900 MP3 Player
575 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
576 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
580 * iRiver iFP MP3 player (with UMS Firmware)
581 * PR: kern/54881, i386/63941, kern/66124
583 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
584 /*quirks*/ DA_Q_NO_SYNC_CACHE
588 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
591 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
592 /*quirks*/ DA_Q_NO_SYNC_CACHE
596 * ZICPlay USB MP3 Player with FM
599 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
600 /*quirks*/ DA_Q_NO_SYNC_CACHE
604 * TEAC USB floppy mechanisms
606 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
607 /*quirks*/ DA_Q_NO_SYNC_CACHE
611 * Kingston DataTraveler II+ USB Pen-Drive.
612 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
614 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
615 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
623 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
624 /*quirks*/ DA_Q_NO_SYNC_CACHE
628 * Motorola E398 Mobile Phone (TransFlash memory card).
629 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
632 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
633 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
637 * Qware BeatZkey! Pro
640 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
641 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
645 * Time DPA20B 1GB MP3 Player
648 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
649 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
653 * Samsung USB key 128Mb
656 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
657 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
661 * Kingston DataTraveler 2.0 USB Flash memory.
664 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
665 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
669 * Creative MUVO Slim mp3 player (USB)
672 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
673 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
677 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
680 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
681 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
685 * SanDisk Micro Cruzer 128MB
688 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
689 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
693 * TOSHIBA TransMemory USB sticks
696 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
697 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
701 * PNY USB 3.0 Flash Drives
703 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
704 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
709 * PR: usb/75578, usb/72344, usb/65436
711 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
712 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
718 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
719 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16
723 * Genesys 6-in-1 Card Reader
726 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
727 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
731 * Rekam Digital CAMERA
734 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
735 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
739 * iRiver H10 MP3 player
742 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
743 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
747 * iRiver U10 MP3 player
750 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
751 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
758 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
759 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
763 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
766 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
767 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
774 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
775 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
779 * Philips USB Key Audio KEY013
782 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
783 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
790 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
791 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
798 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
799 /*quirks*/ DA_Q_NO_SYNC_CACHE
803 * I/O Magic USB flash - Giga Bank
806 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
807 /*quirks*/ DA_Q_NO_SYNC_CACHE
811 * JoyFly 128mb USB Flash Drive
814 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
815 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
822 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
823 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
827 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
830 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
831 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
835 * Samsung YP-U3 mp3-player
838 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
839 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
842 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
843 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
847 * Sony Cyber-Shot DSC cameras
850 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
851 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
854 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
855 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
858 /* At least several Transcent USB sticks lie on RC16. */
859 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
860 "*"}, /*quirks*/ DA_Q_NO_RC16
864 * I-O Data USB Flash Disk
867 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
868 "*"}, /*quirks*/ DA_Q_NO_RC16
872 * SLC CHIPFANCIER USB drives
873 * PR: usb/234503 (RC10 right, RC16 wrong)
874 * 16GB, 32GB and 128GB confirmed to have same issue
876 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*SLC", "CHIPFANCIER",
877 "*"}, /*quirks*/ DA_Q_NO_RC16
879 /* ATA/SATA devices over SAS/USB/... */
882 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SanDisk SD8SB8U1*", "*" },
886 /* Hitachi Advanced Format (4k) drives */
887 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
891 /* Micron Advanced Format (4k) drives */
892 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
896 /* Samsung Advanced Format (4k) drives */
897 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
901 /* Samsung Advanced Format (4k) drives */
902 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
906 /* Samsung Advanced Format (4k) drives */
907 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
911 /* Samsung Advanced Format (4k) drives */
912 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
916 /* Seagate Barracuda Green Advanced Format (4k) drives */
917 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
921 /* Seagate Barracuda Green Advanced Format (4k) drives */
922 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
926 /* Seagate Barracuda Green Advanced Format (4k) drives */
927 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
931 /* Seagate Barracuda Green Advanced Format (4k) drives */
932 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
936 /* Seagate Barracuda Green Advanced Format (4k) drives */
937 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
941 /* Seagate Barracuda Green Advanced Format (4k) drives */
942 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
946 /* Seagate Momentus Advanced Format (4k) drives */
947 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
951 /* Seagate Momentus Advanced Format (4k) drives */
952 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
956 /* Seagate Momentus Advanced Format (4k) drives */
957 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
961 /* Seagate Momentus Advanced Format (4k) drives */
962 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
966 /* Seagate Momentus Advanced Format (4k) drives */
967 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
971 /* Seagate Momentus Advanced Format (4k) drives */
972 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
976 /* Seagate Momentus Advanced Format (4k) drives */
977 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
981 /* Seagate Momentus Advanced Format (4k) drives */
982 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
986 /* Seagate Momentus Advanced Format (4k) drives */
987 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
991 /* Seagate Momentus Advanced Format (4k) drives */
992 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
996 /* Seagate Momentus Advanced Format (4k) drives */
997 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
1001 /* Seagate Momentus Advanced Format (4k) drives */
1002 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
1006 /* Seagate Momentus Advanced Format (4k) drives */
1007 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
1011 /* Seagate Momentus Advanced Format (4k) drives */
1012 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
1016 /* Seagate Momentus Thin Advanced Format (4k) drives */
1017 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
1021 /* Seagate Momentus Thin Advanced Format (4k) drives */
1022 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
1026 /* WDC Caviar Green Advanced Format (4k) drives */
1027 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
1031 /* WDC Caviar Green Advanced Format (4k) drives */
1032 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
1036 /* WDC Caviar Green Advanced Format (4k) drives */
1037 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
1041 /* WDC Caviar Green Advanced Format (4k) drives */
1042 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
1046 /* WDC Caviar Green Advanced Format (4k) drives */
1047 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1051 /* WDC Caviar Green Advanced Format (4k) drives */
1052 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1056 /* WDC Caviar Green Advanced Format (4k) drives */
1057 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1061 /* WDC Caviar Green Advanced Format (4k) drives */
1062 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1066 /* WDC Scorpio Black Advanced Format (4k) drives */
1067 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1071 /* WDC Scorpio Black Advanced Format (4k) drives */
1072 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1076 /* WDC Scorpio Black Advanced Format (4k) drives */
1077 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1081 /* WDC Scorpio Black Advanced Format (4k) drives */
1082 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1086 /* WDC Scorpio Blue Advanced Format (4k) drives */
1087 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1091 /* WDC Scorpio Blue Advanced Format (4k) drives */
1092 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1096 /* WDC Scorpio Blue Advanced Format (4k) drives */
1097 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1101 /* WDC Scorpio Blue Advanced Format (4k) drives */
1102 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1107 * Olympus digital cameras (C-3040ZOOM, C-2040ZOOM, C-1)
1110 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "C*", "*"},
1111 /*quirks*/ DA_Q_NO_6_BYTE | DA_Q_NO_SYNC_CACHE
1115 * Olympus digital cameras (D-370)
1118 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "D*", "*"},
1119 /*quirks*/ DA_Q_NO_6_BYTE
1123 * Olympus digital cameras (E-100RS, E-10).
1126 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "E*", "*"},
1127 /*quirks*/ DA_Q_NO_6_BYTE | DA_Q_NO_SYNC_CACHE
1131 * Olympus FE-210 camera
1133 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1134 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1138 * Pentax Digital Camera
1141 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PENTAX", "DIGITAL CAMERA",
1142 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1146 * LG UP3S MP3 player
1148 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1149 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1153 * Laser MP3-2GA13 MP3 player
1155 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1156 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1160 * LaCie external 250GB Hard drive des by Porsche
1161 * Submitted by: Ben Stuyts <ben@altesco.nl>
1164 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1165 /*quirks*/ DA_Q_NO_SYNC_CACHE
1170 * Corsair Force 2 SSDs
1171 * 4k optimised & trim only works in 4k requests + 4k aligned
1173 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1178 * Corsair Force 3 SSDs
1179 * 4k optimised & trim only works in 4k requests + 4k aligned
1181 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1186 * Corsair Neutron GTX SSDs
1187 * 4k optimised & trim only works in 4k requests + 4k aligned
1189 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1194 * Corsair Force GT & GS SSDs
1195 * 4k optimised & trim only works in 4k requests + 4k aligned
1197 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1203 * 4k optimised & trim only works in 4k requests + 4k aligned
1205 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1210 * Crucial RealSSD C300 SSDs
1213 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1214 "*" }, /*quirks*/DA_Q_4K
1218 * Intel 320 Series SSDs
1219 * 4k optimised & trim only works in 4k requests + 4k aligned
1221 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1226 * Intel 330 Series SSDs
1227 * 4k optimised & trim only works in 4k requests + 4k aligned
1229 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1234 * Intel 510 Series SSDs
1235 * 4k optimised & trim only works in 4k requests + 4k aligned
1237 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1242 * Intel 520 Series SSDs
1243 * 4k optimised & trim only works in 4k requests + 4k aligned
1245 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1250 * Intel S3610 Series SSDs
1251 * 4k optimised & trim only works in 4k requests + 4k aligned
1253 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1258 * Intel X25-M Series SSDs
1259 * 4k optimised & trim only works in 4k requests + 4k aligned
1261 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1266 * Kingston E100 Series SSDs
1267 * 4k optimised & trim only works in 4k requests + 4k aligned
1269 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1274 * Kingston HyperX 3k SSDs
1275 * 4k optimised & trim only works in 4k requests + 4k aligned
1277 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1282 * Marvell SSDs (entry taken from OpenSolaris)
1283 * 4k optimised & trim only works in 4k requests + 4k aligned
1285 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1290 * OCZ Agility 2 SSDs
1291 * 4k optimised & trim only works in 4k requests + 4k aligned
1293 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1298 * OCZ Agility 3 SSDs
1299 * 4k optimised & trim only works in 4k requests + 4k aligned
1301 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1306 * OCZ Deneva R Series SSDs
1307 * 4k optimised & trim only works in 4k requests + 4k aligned
1309 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1314 * OCZ Vertex 2 SSDs (inc pro series)
1315 * 4k optimised & trim only works in 4k requests + 4k aligned
1317 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1323 * 4k optimised & trim only works in 4k requests + 4k aligned
1325 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1331 * 4k optimised & trim only works in 4k requests + 4k aligned
1333 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1338 * Samsung 750 Series SSDs
1339 * 4k optimised & trim only works in 4k requests + 4k aligned
1341 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" },
1346 * Samsung 830 Series SSDs
1347 * 4k optimised & trim only works in 4k requests + 4k aligned
1349 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1355 * 4k optimised & trim only works in 4k requests + 4k aligned
1357 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1363 * 4k optimised & trim only works in 4k requests + 4k aligned
1365 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" },
1371 * 4k optimised & trim only works in 4k requests + 4k aligned
1373 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1378 * Samsung 843T Series SSDs (MZ7WD*)
1379 * Samsung PM851 Series SSDs (MZ7TE*)
1380 * Samsung PM853T Series SSDs (MZ7GE*)
1381 * Samsung SM863 Series SSDs (MZ7KM*)
1384 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1389 * Same as for SAMSUNG MZ7* but enable the quirks for SSD
1390 * starting with MZ7* too
1392 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MZ7*", "*" },
1397 * SuperTalent TeraDrive CT SSDs
1398 * 4k optimised & trim only works in 4k requests + 4k aligned
1400 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1405 * XceedIOPS SATA SSDs
1408 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1413 * Hama Innostor USB-Stick
1415 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1416 /*quirks*/DA_Q_NO_RC16
1420 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1421 * Drive Managed SATA hard drive. This drive doesn't report
1422 * in firmware that it is a drive managed SMR drive.
1424 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS000[23]*", "*" },
1425 /*quirks*/DA_Q_SMR_DM
1429 * MX-ES USB Drive by Mach Xtreme
1431 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1432 /*quirks*/DA_Q_NO_RC16
1436 static disk_strategy_t dastrategy;
1437 static dumper_t dadump;
1438 static periph_init_t dainit;
1439 static void daasync(void *callback_arg, u_int32_t code,
1440 struct cam_path *path, void *arg);
1441 static void dasysctlinit(void *context, int pending);
1442 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1443 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1444 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1445 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1446 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1447 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1448 static void dadeletemethodset(struct da_softc *softc,
1449 da_delete_methods delete_method);
1450 static off_t dadeletemaxsize(struct da_softc *softc,
1451 da_delete_methods delete_method);
1452 static void dadeletemethodchoose(struct da_softc *softc,
1453 da_delete_methods default_method);
1454 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1456 static periph_ctor_t daregister;
1457 static periph_dtor_t dacleanup;
1458 static periph_start_t dastart;
1459 static periph_oninv_t daoninvalidate;
1460 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1461 static void dadone(struct cam_periph *periph,
1462 union ccb *done_ccb);
1463 static void dadone_probewp(struct cam_periph *periph,
1464 union ccb *done_ccb);
1465 static void dadone_proberc(struct cam_periph *periph,
1466 union ccb *done_ccb);
1467 static void dadone_probelbp(struct cam_periph *periph,
1468 union ccb *done_ccb);
1469 static void dadone_probeblklimits(struct cam_periph *periph,
1470 union ccb *done_ccb);
1471 static void dadone_probebdc(struct cam_periph *periph,
1472 union ccb *done_ccb);
1473 static void dadone_probeata(struct cam_periph *periph,
1474 union ccb *done_ccb);
1475 static void dadone_probeatalogdir(struct cam_periph *periph,
1476 union ccb *done_ccb);
1477 static void dadone_probeataiddir(struct cam_periph *periph,
1478 union ccb *done_ccb);
1479 static void dadone_probeatasup(struct cam_periph *periph,
1480 union ccb *done_ccb);
1481 static void dadone_probeatazone(struct cam_periph *periph,
1482 union ccb *done_ccb);
1483 static void dadone_probezone(struct cam_periph *periph,
1484 union ccb *done_ccb);
1485 static void dadone_tur(struct cam_periph *periph,
1486 union ccb *done_ccb);
1487 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1488 u_int32_t sense_flags);
1489 static void daprevent(struct cam_periph *periph, int action);
1490 static void dareprobe(struct cam_periph *periph);
1491 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1493 struct scsi_read_capacity_data_long *rcaplong,
1495 static callout_func_t dasendorderedtag;
1496 static void dashutdown(void *arg, int howto);
1497 static callout_func_t damediapoll;
1499 #ifndef DA_DEFAULT_POLL_PERIOD
1500 #define DA_DEFAULT_POLL_PERIOD 3
1503 #ifndef DA_DEFAULT_TIMEOUT
1504 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1507 #ifndef DA_DEFAULT_SOFTTIMEOUT
1508 #define DA_DEFAULT_SOFTTIMEOUT 0
1511 #ifndef DA_DEFAULT_RETRY
1512 #define DA_DEFAULT_RETRY 4
1515 #ifndef DA_DEFAULT_SEND_ORDERED
1516 #define DA_DEFAULT_SEND_ORDERED 1
1519 #ifndef DA_DEFAULT_MAX_DELETE
1520 #define DA_DEFAULT_MAX_DELETE (1 * 1024 * 1024 * 1024) /* 1GB max trim by default */
1523 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1524 static int da_retry_count = DA_DEFAULT_RETRY;
1525 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1526 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1527 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1528 static int da_disable_wp_detection = 0;
1529 static int64_t da_default_max_delete = DA_DEFAULT_MAX_DELETE;
1531 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1532 "CAM Direct Access Disk driver");
1533 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1534 &da_poll_period, 0, "Media polling period in seconds");
1535 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1536 &da_retry_count, 0, "Normal I/O retry count");
1537 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1538 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1539 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1540 &da_send_ordered, 0, "Send Ordered Tags");
1541 SYSCTL_INT(_kern_cam_da, OID_AUTO, disable_wp_detection, CTLFLAG_RWTUN,
1542 &da_disable_wp_detection, 0,
1543 "Disable detection of write-protected disks");
1544 SYSCTL_INT64(_kern_cam_da, OID_AUTO, default_max_delete, CTLFLAG_RWTUN,
1545 &da_default_max_delete, 0,
1546 "Default system wide maximum delete");
1548 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1549 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1550 "Soft I/O timeout (ms)");
1551 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1554 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1555 * to the default timeout, we check to see whether an ordered
1556 * tagged transaction is appropriate to prevent simple tag
1557 * starvation. Since we'd like to ensure that there is at least
1558 * 1/2 of the timeout length left for a starved transaction to
1559 * complete after we've sent an ordered tag, we must poll at least
1560 * four times in every timeout period. This takes care of the worst
1561 * case where a starved transaction starts during an interval that
1562 * meets the requirement "don't send an ordered tag" test so it takes
1563 * us two intervals to determine that a tag must be sent.
1565 #ifndef DA_ORDEREDTAG_INTERVAL
1566 #define DA_ORDEREDTAG_INTERVAL 4
1569 static struct periph_driver dadriver =
1572 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1575 PERIPHDRIVER_DECLARE(da, dadriver);
1577 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1580 * This driver takes out references / holds in well defined pairs, never
1581 * recursively. These macros / inline functions enforce those rules. They
1582 * are only enabled with DA_TRACK_REFS or INVARIANTS. If DA_TRACK_REFS is
1583 * defined to be 2 or larger, the tracking also includes debug printfs.
1585 #if defined(DA_TRACK_REFS) || defined(INVARIANTS)
1587 #ifndef DA_TRACK_REFS
1588 #define DA_TRACK_REFS 1
1591 #if DA_TRACK_REFS > 1
1592 static const char *da_ref_text[] = {
1605 #define DA_PERIPH_PRINT(periph, msg, args...) \
1606 CAM_PERIPH_PRINT(periph, msg, ##args)
1608 #define DA_PERIPH_PRINT(periph, msg, args...)
1612 token_sanity(da_ref_token token)
1614 if ((unsigned)token >= DA_REF_MAX)
1615 panic("Bad token value passed in %d\n", token);
1619 da_periph_hold(struct cam_periph *periph, int priority, da_ref_token token)
1621 int err = cam_periph_hold(periph, priority);
1623 token_sanity(token);
1624 DA_PERIPH_PRINT(periph, "Holding device %s (%d): %d\n",
1625 da_ref_text[token], token, err);
1628 struct da_softc *softc = periph->softc;
1630 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1632 panic("Re-holding for reason %d, cnt = %d", token, cnt);
1638 da_periph_unhold(struct cam_periph *periph, da_ref_token token)
1641 struct da_softc *softc = periph->softc;
1643 token_sanity(token);
1644 DA_PERIPH_PRINT(periph, "Unholding device %s (%d)\n",
1645 da_ref_text[token], token);
1646 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1648 panic("Unholding %d with cnt = %d", token, cnt);
1649 cam_periph_unhold(periph);
1653 da_periph_acquire(struct cam_periph *periph, da_ref_token token)
1655 int err = cam_periph_acquire(periph);
1657 token_sanity(token);
1658 DA_PERIPH_PRINT(periph, "acquiring device %s (%d): %d\n",
1659 da_ref_text[token], token, err);
1662 struct da_softc *softc = periph->softc;
1664 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1666 panic("Re-refing for reason %d, cnt = %d", token, cnt);
1672 da_periph_release(struct cam_periph *periph, da_ref_token token)
1675 struct da_softc *softc = periph->softc;
1677 token_sanity(token);
1678 DA_PERIPH_PRINT(periph, "releasing device %s (%d)\n",
1679 da_ref_text[token], token);
1680 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1682 panic("Releasing %d with cnt = %d", token, cnt);
1683 cam_periph_release(periph);
1687 da_periph_release_locked(struct cam_periph *periph, da_ref_token token)
1690 struct da_softc *softc = periph->softc;
1692 token_sanity(token);
1693 DA_PERIPH_PRINT(periph, "releasing device (locked) %s (%d)\n",
1694 da_ref_text[token], token);
1695 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1697 panic("releasing (locked) %d with cnt = %d", token, cnt);
1698 cam_periph_release_locked(periph);
1701 #define cam_periph_hold POISON
1702 #define cam_periph_unhold POISON
1703 #define cam_periph_acquire POISON
1704 #define cam_periph_release POISON
1705 #define cam_periph_release_locked POISON
1708 #define da_periph_hold(periph, prio, token) cam_periph_hold((periph), (prio))
1709 #define da_periph_unhold(periph, token) cam_periph_unhold((periph))
1710 #define da_periph_acquire(periph, token) cam_periph_acquire((periph))
1711 #define da_periph_release(periph, token) cam_periph_release((periph))
1712 #define da_periph_release_locked(periph, token) cam_periph_release_locked((periph))
1716 daopen(struct disk *dp)
1718 struct cam_periph *periph;
1719 struct da_softc *softc;
1722 periph = (struct cam_periph *)dp->d_drv1;
1723 if (da_periph_acquire(periph, DA_REF_OPEN) != 0) {
1727 cam_periph_lock(periph);
1728 if ((error = da_periph_hold(periph, PRIBIO|PCATCH, DA_REF_OPEN_HOLD)) != 0) {
1729 cam_periph_unlock(periph);
1730 da_periph_release(periph, DA_REF_OPEN);
1734 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1737 softc = (struct da_softc *)periph->softc;
1740 /* Wait for the disk size update. */
1741 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1744 xpt_print(periph->path, "unable to retrieve capacity data\n");
1746 if (periph->flags & CAM_PERIPH_INVALID)
1749 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1750 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1751 daprevent(periph, PR_PREVENT);
1754 softc->flags &= ~DA_FLAG_PACK_INVALID;
1755 softc->flags |= DA_FLAG_OPEN;
1758 da_periph_unhold(periph, DA_REF_OPEN_HOLD);
1759 cam_periph_unlock(periph);
1762 da_periph_release(periph, DA_REF_OPEN);
1768 daclose(struct disk *dp)
1770 struct cam_periph *periph;
1771 struct da_softc *softc;
1774 periph = (struct cam_periph *)dp->d_drv1;
1775 softc = (struct da_softc *)periph->softc;
1776 cam_periph_lock(periph);
1777 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1780 if (da_periph_hold(periph, PRIBIO, DA_REF_CLOSE_HOLD) == 0) {
1782 /* Flush disk cache. */
1783 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1784 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1785 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1786 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1787 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1788 /*cbfcnp*/NULL, MSG_SIMPLE_Q_TAG,
1789 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1791 cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1792 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1793 softc->disk->d_devstat);
1794 softc->flags &= ~DA_FLAG_DIRTY;
1795 xpt_release_ccb(ccb);
1798 /* Allow medium removal. */
1799 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1800 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1801 daprevent(periph, PR_ALLOW);
1803 da_periph_unhold(periph, DA_REF_CLOSE_HOLD);
1807 * If we've got removeable media, mark the blocksize as
1808 * unavailable, since it could change when new media is
1811 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1812 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1814 softc->flags &= ~DA_FLAG_OPEN;
1815 while (softc->refcount != 0)
1816 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1817 cam_periph_unlock(periph);
1818 da_periph_release(periph, DA_REF_OPEN);
1823 daschedule(struct cam_periph *periph)
1825 struct da_softc *softc = (struct da_softc *)periph->softc;
1827 if (softc->state != DA_STATE_NORMAL)
1830 cam_iosched_schedule(softc->cam_iosched, periph);
1834 * Actually translate the requested transfer into one the physical driver
1835 * can understand. The transfer is described by a buf and will include
1836 * only one physical transfer.
1839 dastrategy(struct bio *bp)
1841 struct cam_periph *periph;
1842 struct da_softc *softc;
1844 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1845 softc = (struct da_softc *)periph->softc;
1847 cam_periph_lock(periph);
1850 * If the device has been made invalid, error out
1852 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1853 cam_periph_unlock(periph);
1854 biofinish(bp, NULL, ENXIO);
1858 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1861 * Zone commands must be ordered, because they can depend on the
1862 * effects of previously issued commands, and they may affect
1863 * commands after them.
1865 if (bp->bio_cmd == BIO_ZONE)
1866 bp->bio_flags |= BIO_ORDERED;
1869 * Place it in the queue of disk activities for this disk
1871 cam_iosched_queue_work(softc->cam_iosched, bp);
1874 * Schedule ourselves for performing the work.
1877 cam_periph_unlock(periph);
1883 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1885 struct cam_periph *periph;
1886 struct da_softc *softc;
1888 struct ccb_scsiio csio;
1893 periph = dp->d_drv1;
1894 softc = (struct da_softc *)periph->softc;
1895 secsize = softc->params.secsize;
1897 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0)
1900 memset(&csio, 0, sizeof(csio));
1902 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1903 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1904 scsi_read_write(&csio,
1908 /*read*/SCSI_RW_WRITE,
1910 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1913 /*data_ptr*/(u_int8_t *) virtual,
1914 /*dxfer_len*/length,
1915 /*sense_len*/SSD_FULL_SIZE,
1916 da_default_timeout * 1000);
1917 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1918 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1920 printf("Aborting dump due to I/O error.\n");
1925 * Sync the disk cache contents to the physical media.
1927 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1929 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1930 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1931 scsi_synchronize_cache(&csio,
1935 /*begin_lba*/0,/* Cover the whole disk */
1939 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1940 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1942 xpt_print(periph->path, "Synchronize cache failed\n");
1948 dagetattr(struct bio *bp)
1951 struct cam_periph *periph;
1953 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1954 cam_periph_lock(periph);
1955 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1957 cam_periph_unlock(periph);
1959 bp->bio_completed = bp->bio_length;
1969 * Install a global async callback. This callback will
1970 * receive async callbacks like "new device found".
1972 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1974 if (status != CAM_REQ_CMP) {
1975 printf("da: Failed to attach master async callback "
1976 "due to status 0x%x!\n", status);
1977 } else if (da_send_ordered) {
1979 /* Register our shutdown event handler */
1980 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1981 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1982 printf("dainit: shutdown event registration failed!\n");
1987 * Callback from GEOM, called when it has finished cleaning up its
1991 dadiskgonecb(struct disk *dp)
1993 struct cam_periph *periph;
1995 periph = (struct cam_periph *)dp->d_drv1;
1996 da_periph_release(periph, DA_REF_GEOM);
2000 daoninvalidate(struct cam_periph *periph)
2002 struct da_softc *softc;
2004 cam_periph_assert(periph, MA_OWNED);
2005 softc = (struct da_softc *)periph->softc;
2008 * De-register any async callbacks.
2010 xpt_register_async(0, daasync, periph, periph->path);
2012 softc->flags |= DA_FLAG_PACK_INVALID;
2014 softc->invalidations++;
2018 * Return all queued I/O with ENXIO.
2019 * XXX Handle any transactions queued to the card
2020 * with XPT_ABORT_CCB.
2022 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
2025 * Tell GEOM that we've gone away, we'll get a callback when it is
2026 * done cleaning up its resources.
2028 disk_gone(softc->disk);
2032 dacleanup(struct cam_periph *periph)
2034 struct da_softc *softc;
2036 softc = (struct da_softc *)periph->softc;
2038 cam_periph_unlock(periph);
2040 cam_iosched_fini(softc->cam_iosched);
2043 * If we can't free the sysctl tree, oh well...
2045 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
2047 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
2048 xpt_print(periph->path,
2049 "can't remove sysctl stats context\n");
2051 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
2052 xpt_print(periph->path,
2053 "can't remove sysctl context\n");
2056 callout_drain(&softc->mediapoll_c);
2057 disk_destroy(softc->disk);
2058 callout_drain(&softc->sendordered_c);
2059 free(softc, M_DEVBUF);
2060 cam_periph_lock(periph);
2064 daasync(void *callback_arg, u_int32_t code,
2065 struct cam_path *path, void *arg)
2067 struct cam_periph *periph;
2068 struct da_softc *softc;
2070 periph = (struct cam_periph *)callback_arg;
2072 case AC_FOUND_DEVICE: /* callback to create periph, no locking yet */
2074 struct ccb_getdev *cgd;
2077 cgd = (struct ccb_getdev *)arg;
2081 if (cgd->protocol != PROTO_SCSI)
2083 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
2085 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
2086 && SID_TYPE(&cgd->inq_data) != T_RBC
2087 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
2088 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
2092 * Allocate a peripheral instance for
2093 * this device and start the probe
2096 status = cam_periph_alloc(daregister, daoninvalidate,
2098 "da", CAM_PERIPH_BIO,
2100 AC_FOUND_DEVICE, cgd);
2102 if (status != CAM_REQ_CMP
2103 && status != CAM_REQ_INPROG)
2104 printf("daasync: Unable to attach to new device "
2105 "due to status 0x%x\n", status);
2108 case AC_ADVINFO_CHANGED: /* Doesn't touch periph */
2112 buftype = (uintptr_t)arg;
2113 if (buftype == CDAI_TYPE_PHYS_PATH) {
2114 struct da_softc *softc;
2116 softc = periph->softc;
2117 disk_attr_changed(softc->disk, "GEOM::physpath",
2122 case AC_UNIT_ATTENTION:
2125 int error_code, sense_key, asc, ascq;
2127 softc = (struct da_softc *)periph->softc;
2128 ccb = (union ccb *)arg;
2131 * Handle all UNIT ATTENTIONs except our own, as they will be
2132 * handled by daerror(). Since this comes from a different periph,
2133 * that periph's lock is held, not ours, so we have to take it ours
2134 * out to touch softc flags.
2136 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
2137 scsi_extract_sense_ccb(ccb,
2138 &error_code, &sense_key, &asc, &ascq)) {
2139 if (asc == 0x2A && ascq == 0x09) {
2140 xpt_print(ccb->ccb_h.path,
2141 "Capacity data has changed\n");
2142 cam_periph_lock(periph);
2143 softc->flags &= ~DA_FLAG_PROBED;
2145 cam_periph_unlock(periph);
2146 } else if (asc == 0x28 && ascq == 0x00) {
2147 cam_periph_lock(periph);
2148 softc->flags &= ~DA_FLAG_PROBED;
2149 cam_periph_unlock(periph);
2150 disk_media_changed(softc->disk, M_NOWAIT);
2151 } else if (asc == 0x3F && ascq == 0x03) {
2152 xpt_print(ccb->ccb_h.path,
2153 "INQUIRY data has changed\n");
2154 cam_periph_lock(periph);
2155 softc->flags &= ~DA_FLAG_PROBED;
2157 cam_periph_unlock(periph);
2162 case AC_SCSI_AEN: /* Called for this path: periph locked */
2164 * Appears to be currently unused for SCSI devices, only ata SIMs
2167 cam_periph_assert(periph, MA_OWNED);
2168 softc = (struct da_softc *)periph->softc;
2169 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
2170 (softc->flags & DA_FLAG_TUR_PENDING) == 0) {
2171 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
2172 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
2177 case AC_SENT_BDR: /* Called for this path: periph locked */
2178 case AC_BUS_RESET: /* Called for this path: periph locked */
2180 struct ccb_hdr *ccbh;
2182 cam_periph_assert(periph, MA_OWNED);
2183 softc = (struct da_softc *)periph->softc;
2185 * Don't fail on the expected unit attention
2188 softc->flags |= DA_FLAG_RETRY_UA;
2189 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
2190 ccbh->ccb_state |= DA_CCB_RETRY_UA;
2193 case AC_INQ_CHANGED: /* Called for this path: periph locked */
2194 cam_periph_assert(periph, MA_OWNED);
2195 softc = (struct da_softc *)periph->softc;
2196 softc->flags &= ~DA_FLAG_PROBED;
2202 cam_periph_async(periph, code, path, arg);
2206 dasysctlinit(void *context, int pending)
2208 struct cam_periph *periph;
2209 struct da_softc *softc;
2210 char tmpstr[32], tmpstr2[16];
2211 struct ccb_trans_settings cts;
2213 periph = (struct cam_periph *)context;
2215 * periph was held for us when this task was enqueued
2217 if (periph->flags & CAM_PERIPH_INVALID) {
2218 da_periph_release(periph, DA_REF_SYSCTL);
2222 softc = (struct da_softc *)periph->softc;
2223 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
2224 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
2226 sysctl_ctx_init(&softc->sysctl_ctx);
2227 cam_periph_lock(periph);
2228 softc->flags |= DA_FLAG_SCTX_INIT;
2229 cam_periph_unlock(periph);
2230 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
2231 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
2232 CTLFLAG_RD, 0, tmpstr, "device_index");
2233 if (softc->sysctl_tree == NULL) {
2234 printf("dasysctlinit: unable to allocate sysctl tree\n");
2235 da_periph_release(periph, DA_REF_SYSCTL);
2240 * Now register the sysctl handler, so the user can change the value on
2243 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2244 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
2245 softc, 0, dadeletemethodsysctl, "A",
2246 "BIO_DELETE execution method");
2247 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2248 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
2249 softc, 0, dadeletemaxsysctl, "Q",
2250 "Maximum BIO_DELETE size");
2251 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2252 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
2253 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
2254 "Minimum CDB size");
2255 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2256 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2257 "trim_count", CTLFLAG_RD, &softc->trim_count,
2258 "Total number of unmap/dsm commands sent");
2259 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2260 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2261 "trim_ranges", CTLFLAG_RD, &softc->trim_ranges,
2262 "Total number of ranges in unmap/dsm commands");
2263 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2264 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2265 "trim_lbas", CTLFLAG_RD, &softc->trim_lbas,
2266 "Total lbas in the unmap/dsm commands sent");
2268 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2269 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
2270 softc, 0, dazonemodesysctl, "A",
2272 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2273 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
2274 softc, 0, dazonesupsysctl, "A",
2276 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2277 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2278 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2279 "Optimal Number of Open Sequential Write Preferred Zones");
2280 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2281 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2282 "optimal_nonseq_zones", CTLFLAG_RD,
2283 &softc->optimal_nonseq_zones,
2284 "Optimal Number of Non-Sequentially Written Sequential Write "
2286 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2287 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2288 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2289 "Maximum Number of Open Sequential Write Required Zones");
2291 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2292 SYSCTL_CHILDREN(softc->sysctl_tree),
2296 &softc->error_inject,
2298 "error_inject leaf");
2300 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2301 SYSCTL_CHILDREN(softc->sysctl_tree),
2307 "Unmapped I/O support");
2309 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2310 SYSCTL_CHILDREN(softc->sysctl_tree),
2318 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2319 SYSCTL_CHILDREN(softc->sysctl_tree),
2325 "DIF protection type");
2327 #ifdef CAM_TEST_FAILURE
2328 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2329 OID_AUTO, "invalidate", CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE,
2330 periph, 0, cam_periph_invalidate_sysctl, "I",
2331 "Write 1 to invalidate the drive immediately");
2335 * Add some addressing info.
2337 memset(&cts, 0, sizeof (cts));
2338 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2339 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2340 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2341 cam_periph_lock(periph);
2342 xpt_action((union ccb *)&cts);
2343 cam_periph_unlock(periph);
2344 if (cts.ccb_h.status != CAM_REQ_CMP) {
2345 da_periph_release(periph, DA_REF_SYSCTL);
2348 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2349 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2350 if (fc->valid & CTS_FC_VALID_WWPN) {
2351 softc->wwpn = fc->wwpn;
2352 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2353 SYSCTL_CHILDREN(softc->sysctl_tree),
2354 OID_AUTO, "wwpn", CTLFLAG_RD,
2355 &softc->wwpn, "World Wide Port Name");
2361 * Now add some useful stats.
2362 * XXX These should live in cam_periph and be common to all periphs
2364 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2365 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2366 CTLFLAG_RD, 0, "Statistics");
2367 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2368 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2374 "Transport errors reported by the SIM");
2375 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2376 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2382 "Device timeouts reported by the SIM");
2383 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2384 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2386 "pack_invalidations",
2388 &softc->invalidations,
2390 "Device pack invalidations");
2393 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2394 softc->sysctl_tree);
2396 da_periph_release(periph, DA_REF_SYSCTL);
2400 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2404 struct da_softc *softc;
2406 softc = (struct da_softc *)arg1;
2408 value = softc->disk->d_delmaxsize;
2409 error = sysctl_handle_64(oidp, &value, 0, req);
2410 if ((error != 0) || (req->newptr == NULL))
2413 /* only accept values smaller than the calculated value */
2414 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2417 softc->disk->d_delmaxsize = value;
2423 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2427 value = *(int *)arg1;
2429 error = sysctl_handle_int(oidp, &value, 0, req);
2432 || (req->newptr == NULL))
2436 * Acceptable values here are 6, 10, 12 or 16.
2440 else if ((value > 6)
2443 else if ((value > 10)
2446 else if (value > 12)
2449 *(int *)arg1 = value;
2455 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2460 value = da_default_softtimeout / SBT_1MS;
2462 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2463 if ((error != 0) || (req->newptr == NULL))
2466 /* XXX Should clip this to a reasonable level */
2467 if (value > da_default_timeout * 1000)
2470 da_default_softtimeout = value * SBT_1MS;
2475 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2478 softc->delete_method = delete_method;
2479 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2480 softc->delete_func = da_delete_functions[delete_method];
2482 if (softc->delete_method > DA_DELETE_DISABLE)
2483 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2485 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2489 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2493 switch(delete_method) {
2494 case DA_DELETE_UNMAP:
2495 sectors = (off_t)softc->unmap_max_lba;
2497 case DA_DELETE_ATA_TRIM:
2498 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2500 case DA_DELETE_WS16:
2501 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2503 case DA_DELETE_ZERO:
2504 case DA_DELETE_WS10:
2505 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2511 return (off_t)MIN(da_default_max_delete, softc->params.secsize *
2512 omin(sectors, softc->params.sectors));
2516 daprobedone(struct cam_periph *periph, union ccb *ccb)
2518 struct da_softc *softc;
2520 softc = (struct da_softc *)periph->softc;
2522 cam_periph_assert(periph, MA_OWNED);
2524 dadeletemethodchoose(softc, DA_DELETE_NONE);
2526 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2530 snprintf(buf, sizeof(buf), "Delete methods: <");
2532 for (i = 0; i <= DA_DELETE_MAX; i++) {
2533 if ((softc->delete_available & (1 << i)) == 0 &&
2534 i != softc->delete_method)
2537 strlcat(buf, ",", sizeof(buf));
2538 strlcat(buf, da_delete_method_names[i],
2540 if (i == softc->delete_method)
2541 strlcat(buf, "(*)", sizeof(buf));
2544 strlcat(buf, ">", sizeof(buf));
2545 printf("%s%d: %s\n", periph->periph_name,
2546 periph->unit_number, buf);
2548 if ((softc->disk->d_flags & DISKFLAG_WRITE_PROTECT) != 0 &&
2549 (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2550 printf("%s%d: Write Protected\n", periph->periph_name,
2551 periph->unit_number);
2555 * Since our peripheral may be invalidated by an error
2556 * above or an external event, we must release our CCB
2557 * before releasing the probe lock on the peripheral.
2558 * The peripheral will only go away once the last lock
2559 * is removed, and we need it around for the CCB release
2562 xpt_release_ccb(ccb);
2563 softc->state = DA_STATE_NORMAL;
2564 softc->flags |= DA_FLAG_PROBED;
2566 wakeup(&softc->disk->d_mediasize);
2567 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2568 softc->flags |= DA_FLAG_ANNOUNCED;
2569 da_periph_unhold(periph, DA_REF_PROBE_HOLD);
2571 da_periph_release_locked(periph, DA_REF_REPROBE);
2575 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2579 /* If available, prefer the method requested by user. */
2580 i = softc->delete_method_pref;
2581 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2582 if (methods & (1 << i)) {
2583 dadeletemethodset(softc, i);
2587 /* Use the pre-defined order to choose the best performing delete. */
2588 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2589 if (i == DA_DELETE_ZERO)
2591 if (softc->delete_available & (1 << i)) {
2592 dadeletemethodset(softc, i);
2597 /* Fallback to default. */
2598 dadeletemethodset(softc, default_method);
2602 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2606 struct da_softc *softc;
2607 int i, error, value;
2609 softc = (struct da_softc *)arg1;
2611 value = softc->delete_method;
2612 if (value < 0 || value > DA_DELETE_MAX)
2615 p = da_delete_method_names[value];
2616 strncpy(buf, p, sizeof(buf));
2617 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2618 if (error != 0 || req->newptr == NULL)
2620 for (i = 0; i <= DA_DELETE_MAX; i++) {
2621 if (strcmp(buf, da_delete_method_names[i]) == 0)
2624 if (i > DA_DELETE_MAX)
2626 softc->delete_method_pref = i;
2627 dadeletemethodchoose(softc, DA_DELETE_NONE);
2632 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2635 struct da_softc *softc;
2638 softc = (struct da_softc *)arg1;
2640 switch (softc->zone_mode) {
2641 case DA_ZONE_DRIVE_MANAGED:
2642 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2644 case DA_ZONE_HOST_AWARE:
2645 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2647 case DA_ZONE_HOST_MANAGED:
2648 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2652 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2656 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2662 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2665 struct da_softc *softc;
2670 softc = (struct da_softc *)arg1;
2674 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2676 for (i = 0; i < sizeof(da_zone_desc_table) /
2677 sizeof(da_zone_desc_table[0]); i++) {
2678 if (softc->zone_flags & da_zone_desc_table[i].value) {
2680 sbuf_printf(&sb, ", ");
2683 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2688 sbuf_printf(&sb, "None");
2692 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2698 daregister(struct cam_periph *periph, void *arg)
2700 struct da_softc *softc;
2701 struct ccb_pathinq cpi;
2702 struct ccb_getdev *cgd;
2707 cgd = (struct ccb_getdev *)arg;
2709 printf("daregister: no getdev CCB, can't register device\n");
2710 return(CAM_REQ_CMP_ERR);
2713 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2716 if (softc == NULL) {
2717 printf("daregister: Unable to probe new device. "
2718 "Unable to allocate softc\n");
2719 return(CAM_REQ_CMP_ERR);
2722 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2723 printf("daregister: Unable to probe new device. "
2724 "Unable to allocate iosched memory\n");
2725 free(softc, M_DEVBUF);
2726 return(CAM_REQ_CMP_ERR);
2729 LIST_INIT(&softc->pending_ccbs);
2730 softc->state = DA_STATE_PROBE_WP;
2731 bioq_init(&softc->delete_run_queue);
2732 if (SID_IS_REMOVABLE(&cgd->inq_data))
2733 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2734 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2735 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2736 softc->unmap_gran = 0;
2737 softc->unmap_gran_align = 0;
2738 softc->ws_max_blks = WS16_MAX_BLKS;
2739 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2740 softc->rotating = 1;
2742 periph->softc = softc;
2745 * See if this device has any quirks.
2747 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2748 (caddr_t)da_quirk_table,
2749 nitems(da_quirk_table),
2750 sizeof(*da_quirk_table), scsi_inquiry_match);
2753 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2755 softc->quirks = DA_Q_NONE;
2757 /* Check if the SIM does not want 6 byte commands */
2758 xpt_path_inq(&cpi, periph->path);
2759 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2760 softc->quirks |= DA_Q_NO_6_BYTE;
2762 /* Override quirks if tunable is set */
2763 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.quirks",
2764 periph->unit_number);
2765 quirks = softc->quirks;
2766 TUNABLE_INT_FETCH(tmpstr, &quirks);
2767 softc->quirks = quirks;
2769 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2770 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2771 else if (softc->quirks & DA_Q_SMR_DM)
2772 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2774 softc->zone_mode = DA_ZONE_NONE;
2776 if (softc->zone_mode != DA_ZONE_NONE) {
2777 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2778 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2779 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2781 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2783 softc->zone_interface = DA_ZONE_IF_SCSI;
2786 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2789 * Take an exclusive section lock qon the periph while dastart is called
2790 * to finish the probe. The lock will be dropped in dadone at the end
2791 * of probe. This locks out daopen and daclose from racing with the
2794 * XXX if cam_periph_hold returns an error, we don't hold a refcount.
2796 (void)da_periph_hold(periph, PRIBIO, DA_REF_PROBE_HOLD);
2799 * Schedule a periodic event to occasionally send an
2800 * ordered tag to a device.
2802 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2803 callout_reset(&softc->sendordered_c,
2804 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2805 dasendorderedtag, periph);
2807 cam_periph_unlock(periph);
2809 * RBC devices don't have to support READ(6), only READ(10).
2811 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2812 softc->minimum_cmd_size = 10;
2814 softc->minimum_cmd_size = 6;
2817 * Load the user's default, if any.
2819 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2820 periph->unit_number);
2821 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2824 * 6, 10, 12 and 16 are the currently permissible values.
2826 if (softc->minimum_cmd_size > 12)
2827 softc->minimum_cmd_size = 16;
2828 else if (softc->minimum_cmd_size > 10)
2829 softc->minimum_cmd_size = 12;
2830 else if (softc->minimum_cmd_size > 6)
2831 softc->minimum_cmd_size = 10;
2833 softc->minimum_cmd_size = 6;
2835 /* Predict whether device may support READ CAPACITY(16). */
2836 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2837 (softc->quirks & DA_Q_NO_RC16) == 0) {
2838 softc->flags |= DA_FLAG_CAN_RC16;
2842 * Register this media as a disk.
2844 softc->disk = disk_alloc();
2845 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2846 periph->unit_number, 0,
2847 DEVSTAT_BS_UNAVAILABLE,
2848 SID_TYPE(&cgd->inq_data) |
2849 XPORT_DEVSTAT_TYPE(cpi.transport),
2850 DEVSTAT_PRIORITY_DISK);
2851 softc->disk->d_open = daopen;
2852 softc->disk->d_close = daclose;
2853 softc->disk->d_strategy = dastrategy;
2854 softc->disk->d_dump = dadump;
2855 softc->disk->d_getattr = dagetattr;
2856 softc->disk->d_gone = dadiskgonecb;
2857 softc->disk->d_name = "da";
2858 softc->disk->d_drv1 = periph;
2860 softc->maxio = DFLTPHYS; /* traditional default */
2861 else if (cpi.maxio > MAXPHYS)
2862 softc->maxio = MAXPHYS; /* for safety */
2864 softc->maxio = cpi.maxio;
2865 if (softc->quirks & DA_Q_128KB)
2866 softc->maxio = min(softc->maxio, 128 * 1024);
2867 softc->disk->d_maxsize = softc->maxio;
2868 softc->disk->d_unit = periph->unit_number;
2869 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2870 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2871 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2872 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2873 softc->unmappedio = 1;
2874 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2876 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2877 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2878 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2879 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2880 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2881 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2882 softc->disk->d_hba_vendor = cpi.hba_vendor;
2883 softc->disk->d_hba_device = cpi.hba_device;
2884 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2885 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2886 snprintf(softc->disk->d_attachment, sizeof(softc->disk->d_attachment),
2887 "%s%d", cpi.dev_name, cpi.unit_number);
2890 * Acquire a reference to the periph before we register with GEOM.
2891 * We'll release this reference once GEOM calls us back (via
2892 * dadiskgonecb()) telling us that our provider has been freed.
2894 if (da_periph_acquire(periph, DA_REF_GEOM) != 0) {
2895 xpt_print(periph->path, "%s: lost periph during "
2896 "registration!\n", __func__);
2897 cam_periph_lock(periph);
2898 return (CAM_REQ_CMP_ERR);
2901 disk_create(softc->disk, DISK_VERSION);
2902 cam_periph_lock(periph);
2905 * Add async callbacks for events of interest.
2906 * I don't bother checking if this fails as,
2907 * in most cases, the system will function just
2908 * fine without them and the only alternative
2909 * would be to not attach the device on failure.
2911 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2912 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2913 AC_INQ_CHANGED, daasync, periph, periph->path);
2916 * Emit an attribute changed notification just in case
2917 * physical path information arrived before our async
2918 * event handler was registered, but after anyone attaching
2919 * to our disk device polled it.
2921 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2924 * Schedule a periodic media polling events.
2926 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2927 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2928 (cgd->inq_flags & SID_AEN) == 0 &&
2929 da_poll_period != 0)
2930 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2931 damediapoll, periph);
2933 xpt_schedule(periph, CAM_PRIORITY_DEV);
2935 return(CAM_REQ_CMP);
2939 da_zone_bio_to_scsi(int disk_zone_cmd)
2941 switch (disk_zone_cmd) {
2942 case DISK_ZONE_OPEN:
2943 return ZBC_OUT_SA_OPEN;
2944 case DISK_ZONE_CLOSE:
2945 return ZBC_OUT_SA_CLOSE;
2946 case DISK_ZONE_FINISH:
2947 return ZBC_OUT_SA_FINISH;
2949 return ZBC_OUT_SA_RWP;
2956 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2959 struct da_softc *softc;
2964 if (bp->bio_cmd != BIO_ZONE) {
2969 softc = periph->softc;
2971 switch (bp->bio_zone.zone_cmd) {
2972 case DISK_ZONE_OPEN:
2973 case DISK_ZONE_CLOSE:
2974 case DISK_ZONE_FINISH:
2975 case DISK_ZONE_RWP: {
2980 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2981 if (zone_sa == -1) {
2982 xpt_print(periph->path, "Cannot translate zone "
2983 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2989 lba = bp->bio_zone.zone_params.rwp.id;
2991 if (bp->bio_zone.zone_params.rwp.flags &
2992 DISK_ZONE_RWP_FLAG_ALL)
2993 zone_flags |= ZBC_OUT_ALL;
2995 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2996 scsi_zbc_out(&ccb->csio,
2997 /*retries*/ da_retry_count,
2999 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3000 /*service_action*/ zone_sa,
3002 /*zone_flags*/ zone_flags,
3005 /*sense_len*/ SSD_FULL_SIZE,
3006 /*timeout*/ da_default_timeout * 1000);
3009 * Note that in this case, even though we can
3010 * technically use NCQ, we don't bother for several
3012 * 1. It hasn't been tested on a SAT layer that
3013 * supports it. This is new as of SAT-4.
3014 * 2. Even when there is a SAT layer that supports
3015 * it, that SAT layer will also probably support
3016 * ZBC -> ZAC translation, since they are both
3017 * in the SAT-4 spec.
3018 * 3. Translation will likely be preferable to ATA
3019 * passthrough. LSI / Avago at least single
3020 * steps ATA passthrough commands in the HBA,
3021 * regardless of protocol, so unless that
3022 * changes, there is a performance penalty for
3023 * doing ATA passthrough no matter whether
3024 * you're using NCQ/FPDMA, DMA or PIO.
3025 * 4. It requires a 32-byte CDB, which at least at
3026 * this point in CAM requires a CDB pointer, which
3027 * would require us to allocate an additional bit
3028 * of storage separate from the CCB.
3030 error = scsi_ata_zac_mgmt_out(&ccb->csio,
3031 /*retries*/ da_retry_count,
3033 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3035 /*zm_action*/ zone_sa,
3037 /*zone_flags*/ zone_flags,
3040 /*cdb_storage*/ NULL,
3041 /*cdb_storage_len*/ 0,
3042 /*sense_len*/ SSD_FULL_SIZE,
3043 /*timeout*/ da_default_timeout * 1000);
3046 xpt_print(periph->path,
3047 "scsi_ata_zac_mgmt_out() returned an "
3056 case DISK_ZONE_REPORT_ZONES: {
3058 uint32_t num_entries, alloc_size;
3059 struct disk_zone_report *rep;
3061 rep = &bp->bio_zone.zone_params.report;
3063 num_entries = rep->entries_allocated;
3064 if (num_entries == 0) {
3065 xpt_print(periph->path, "No entries allocated for "
3066 "Report Zones request\n");
3070 alloc_size = sizeof(struct scsi_report_zones_hdr) +
3071 (sizeof(struct scsi_report_zones_desc) * num_entries);
3072 alloc_size = min(alloc_size, softc->disk->d_maxsize);
3073 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
3074 if (rz_ptr == NULL) {
3075 xpt_print(periph->path, "Unable to allocate memory "
3076 "for Report Zones request\n");
3081 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
3082 scsi_zbc_in(&ccb->csio,
3083 /*retries*/ da_retry_count,
3085 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3086 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
3087 /*zone_start_lba*/ rep->starting_id,
3088 /*zone_options*/ rep->rep_options,
3089 /*data_ptr*/ rz_ptr,
3090 /*dxfer_len*/ alloc_size,
3091 /*sense_len*/ SSD_FULL_SIZE,
3092 /*timeout*/ da_default_timeout * 1000);
3095 * Note that in this case, even though we can
3096 * technically use NCQ, we don't bother for several
3098 * 1. It hasn't been tested on a SAT layer that
3099 * supports it. This is new as of SAT-4.
3100 * 2. Even when there is a SAT layer that supports
3101 * it, that SAT layer will also probably support
3102 * ZBC -> ZAC translation, since they are both
3103 * in the SAT-4 spec.
3104 * 3. Translation will likely be preferable to ATA
3105 * passthrough. LSI / Avago at least single
3106 * steps ATA passthrough commands in the HBA,
3107 * regardless of protocol, so unless that
3108 * changes, there is a performance penalty for
3109 * doing ATA passthrough no matter whether
3110 * you're using NCQ/FPDMA, DMA or PIO.
3111 * 4. It requires a 32-byte CDB, which at least at
3112 * this point in CAM requires a CDB pointer, which
3113 * would require us to allocate an additional bit
3114 * of storage separate from the CCB.
3116 error = scsi_ata_zac_mgmt_in(&ccb->csio,
3117 /*retries*/ da_retry_count,
3119 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3121 /*zm_action*/ ATA_ZM_REPORT_ZONES,
3122 /*zone_id*/ rep->starting_id,
3123 /*zone_flags*/ rep->rep_options,
3124 /*data_ptr*/ rz_ptr,
3125 /*dxfer_len*/ alloc_size,
3126 /*cdb_storage*/ NULL,
3127 /*cdb_storage_len*/ 0,
3128 /*sense_len*/ SSD_FULL_SIZE,
3129 /*timeout*/ da_default_timeout * 1000);
3132 xpt_print(periph->path,
3133 "scsi_ata_zac_mgmt_in() returned an "
3140 * For BIO_ZONE, this isn't normally needed. However, it
3141 * is used by devstat_end_transaction_bio() to determine
3142 * how much data was transferred.
3145 * XXX KDM we have a problem. But I'm not sure how to fix
3146 * it. devstat uses bio_bcount - bio_resid to calculate
3147 * the amount of data transferred. The GEOM disk code
3148 * uses bio_length - bio_resid to calculate the amount of
3149 * data in bio_completed. We have different structure
3150 * sizes above and below the ada(4) driver. So, if we
3151 * use the sizes above, the amount transferred won't be
3152 * quite accurate for devstat. If we use different sizes
3153 * for bio_bcount and bio_length (above and below
3154 * respectively), then the residual needs to match one or
3155 * the other. Everything is calculated after the bio
3156 * leaves the driver, so changing the values around isn't
3157 * really an option. For now, just set the count to the
3158 * passed in length. This means that the calculations
3159 * above (e.g. bio_completed) will be correct, but the
3160 * amount of data reported to devstat will be slightly
3161 * under or overstated.
3163 bp->bio_bcount = bp->bio_length;
3169 case DISK_ZONE_GET_PARAMS: {
3170 struct disk_zone_disk_params *params;
3172 params = &bp->bio_zone.zone_params.disk_params;
3173 bzero(params, sizeof(*params));
3175 switch (softc->zone_mode) {
3176 case DA_ZONE_DRIVE_MANAGED:
3177 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
3179 case DA_ZONE_HOST_AWARE:
3180 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
3182 case DA_ZONE_HOST_MANAGED:
3183 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
3187 params->zone_mode = DISK_ZONE_MODE_NONE;
3191 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
3192 params->flags |= DISK_ZONE_DISK_URSWRZ;
3194 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
3195 params->optimal_seq_zones = softc->optimal_seq_zones;
3196 params->flags |= DISK_ZONE_OPT_SEQ_SET;
3199 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
3200 params->optimal_nonseq_zones =
3201 softc->optimal_nonseq_zones;
3202 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
3205 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
3206 params->max_seq_zones = softc->max_seq_zones;
3207 params->flags |= DISK_ZONE_MAX_SEQ_SET;
3209 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
3210 params->flags |= DISK_ZONE_RZ_SUP;
3212 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
3213 params->flags |= DISK_ZONE_OPEN_SUP;
3215 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
3216 params->flags |= DISK_ZONE_CLOSE_SUP;
3218 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
3219 params->flags |= DISK_ZONE_FINISH_SUP;
3221 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
3222 params->flags |= DISK_ZONE_RWP_SUP;
3233 dastart(struct cam_periph *periph, union ccb *start_ccb)
3235 struct da_softc *softc;
3237 cam_periph_assert(periph, MA_OWNED);
3238 softc = (struct da_softc *)periph->softc;
3240 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
3243 switch (softc->state) {
3244 case DA_STATE_NORMAL:
3250 bp = cam_iosched_next_bio(softc->cam_iosched);
3252 if (cam_iosched_has_work_flags(softc->cam_iosched,
3254 softc->flags |= DA_FLAG_TUR_PENDING;
3255 cam_iosched_clr_work_flags(softc->cam_iosched,
3257 scsi_test_unit_ready(&start_ccb->csio,
3258 /*retries*/ da_retry_count,
3262 da_default_timeout * 1000);
3263 start_ccb->ccb_h.ccb_bp = NULL;
3264 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
3265 xpt_action(start_ccb);
3267 xpt_release_ccb(start_ccb);
3271 if (bp->bio_cmd == BIO_DELETE) {
3272 if (softc->delete_func != NULL) {
3273 softc->delete_func(periph, start_ccb, bp);
3277 * Not sure this is possible, but failsafe by
3278 * lying and saying "sure, done."
3280 biofinish(bp, NULL, 0);
3285 if (cam_iosched_has_work_flags(softc->cam_iosched,
3287 cam_iosched_clr_work_flags(softc->cam_iosched,
3289 da_periph_release_locked(periph, DA_REF_TUR);
3292 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
3293 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
3294 softc->flags &= ~DA_FLAG_NEED_OTAG;
3295 softc->flags |= DA_FLAG_WAS_OTAG;
3296 tag_code = MSG_ORDERED_Q_TAG;
3298 tag_code = MSG_SIMPLE_Q_TAG;
3301 switch (bp->bio_cmd) {
3308 biotrack(bp, __func__);
3310 if (bp->bio_cmd == BIO_WRITE) {
3311 softc->flags |= DA_FLAG_DIRTY;
3312 rw_op = SCSI_RW_WRITE;
3314 rw_op = SCSI_RW_READ;
3317 data_ptr = bp->bio_data;
3318 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
3319 rw_op |= SCSI_RW_BIO;
3323 scsi_read_write(&start_ccb->csio,
3324 /*retries*/da_retry_count,
3326 /*tag_action*/tag_code,
3329 softc->minimum_cmd_size,
3330 /*lba*/bp->bio_pblkno,
3331 /*block_count*/bp->bio_bcount /
3332 softc->params.secsize,
3334 /*dxfer_len*/ bp->bio_bcount,
3335 /*sense_len*/SSD_FULL_SIZE,
3336 da_default_timeout * 1000);
3337 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3338 start_ccb->csio.bio = bp;
3344 * If we don't support sync cache, or the disk
3345 * isn't dirty, FLUSH is a no-op. Use the
3346 * allocated CCB for the next bio if one is
3349 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) != 0 ||
3350 (softc->flags & DA_FLAG_DIRTY) == 0) {
3356 * BIO_FLUSH doesn't currently communicate
3357 * range data, so we synchronize the cache
3358 * over the whole disk.
3360 scsi_synchronize_cache(&start_ccb->csio,
3363 /*tag_action*/tag_code,
3367 da_default_timeout*1000);
3369 * Clear the dirty flag before sending the command.
3370 * Either this sync cache will be successful, or it
3371 * will fail after a retry. If it fails, it is
3372 * unlikely to be successful if retried later, so
3373 * we'll save ourselves time by just marking the
3376 softc->flags &= ~DA_FLAG_DIRTY;
3379 int error, queue_ccb;
3383 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3385 || (queue_ccb == 0)) {
3386 biofinish(bp, NULL, error);
3387 xpt_release_ccb(start_ccb);
3393 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3394 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3395 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3398 LIST_INSERT_HEAD(&softc->pending_ccbs,
3399 &start_ccb->ccb_h, periph_links.le);
3401 /* We expect a unit attention from this device */
3402 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3403 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3404 softc->flags &= ~DA_FLAG_RETRY_UA;
3407 start_ccb->ccb_h.ccb_bp = bp;
3409 cam_periph_unlock(periph);
3410 xpt_action(start_ccb);
3411 cam_periph_lock(periph);
3413 /* May have more work to do, so ensure we stay scheduled */
3417 case DA_STATE_PROBE_WP:
3422 if (da_disable_wp_detection) {
3423 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3424 softc->state = DA_STATE_PROBE_RC16;
3426 softc->state = DA_STATE_PROBE_RC;
3430 mode_buf = malloc(mode_buf_len, M_SCSIDA, M_NOWAIT);
3431 if (mode_buf == NULL) {
3432 xpt_print(periph->path, "Unable to send mode sense - "
3433 "malloc failure\n");
3434 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3435 softc->state = DA_STATE_PROBE_RC16;
3437 softc->state = DA_STATE_PROBE_RC;
3440 scsi_mode_sense_len(&start_ccb->csio,
3441 /*retries*/ da_retry_count,
3442 /*cbfcnp*/ dadone_probewp,
3443 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3445 /*pc*/ SMS_PAGE_CTRL_CURRENT,
3446 /*page*/ SMS_ALL_PAGES_PAGE,
3447 /*param_buf*/ mode_buf,
3448 /*param_len*/ mode_buf_len,
3449 /*minimum_cmd_size*/ softc->minimum_cmd_size,
3450 /*sense_len*/ SSD_FULL_SIZE,
3451 /*timeout*/ da_default_timeout * 1000);
3452 start_ccb->ccb_h.ccb_bp = NULL;
3453 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_WP;
3454 xpt_action(start_ccb);
3457 case DA_STATE_PROBE_RC:
3459 struct scsi_read_capacity_data *rcap;
3461 rcap = (struct scsi_read_capacity_data *)
3462 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3464 printf("dastart: Couldn't malloc read_capacity data\n");
3465 /* da_free_periph??? */
3468 scsi_read_capacity(&start_ccb->csio,
3469 /*retries*/da_retry_count,
3475 start_ccb->ccb_h.ccb_bp = NULL;
3476 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3477 xpt_action(start_ccb);
3480 case DA_STATE_PROBE_RC16:
3482 struct scsi_read_capacity_data_long *rcaplong;
3484 rcaplong = (struct scsi_read_capacity_data_long *)
3485 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3486 if (rcaplong == NULL) {
3487 printf("dastart: Couldn't malloc read_capacity data\n");
3488 /* da_free_periph??? */
3491 scsi_read_capacity_16(&start_ccb->csio,
3492 /*retries*/ da_retry_count,
3493 /*cbfcnp*/ dadone_proberc,
3494 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3498 /*rcap_buf*/ (uint8_t *)rcaplong,
3499 /*rcap_buf_len*/ sizeof(*rcaplong),
3500 /*sense_len*/ SSD_FULL_SIZE,
3501 /*timeout*/ da_default_timeout * 1000);
3502 start_ccb->ccb_h.ccb_bp = NULL;
3503 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3504 xpt_action(start_ccb);
3507 case DA_STATE_PROBE_LBP:
3509 struct scsi_vpd_logical_block_prov *lbp;
3511 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3513 * If we get here we don't support any SBC-3 delete
3514 * methods with UNMAP as the Logical Block Provisioning
3515 * VPD page support is required for devices which
3516 * support it according to T10/1799-D Revision 31
3517 * however older revisions of the spec don't mandate
3518 * this so we currently don't remove these methods
3519 * from the available set.
3521 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3525 lbp = (struct scsi_vpd_logical_block_prov *)
3526 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3529 printf("dastart: Couldn't malloc lbp data\n");
3530 /* da_free_periph??? */
3534 scsi_inquiry(&start_ccb->csio,
3535 /*retries*/da_retry_count,
3536 /*cbfcnp*/dadone_probelbp,
3537 /*tag_action*/MSG_SIMPLE_Q_TAG,
3538 /*inq_buf*/(u_int8_t *)lbp,
3539 /*inq_len*/sizeof(*lbp),
3541 /*page_code*/SVPD_LBP,
3542 /*sense_len*/SSD_MIN_SIZE,
3543 /*timeout*/da_default_timeout * 1000);
3544 start_ccb->ccb_h.ccb_bp = NULL;
3545 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3546 xpt_action(start_ccb);
3549 case DA_STATE_PROBE_BLK_LIMITS:
3551 struct scsi_vpd_block_limits *block_limits;
3553 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3554 /* Not supported skip to next probe */
3555 softc->state = DA_STATE_PROBE_BDC;
3559 block_limits = (struct scsi_vpd_block_limits *)
3560 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3562 if (block_limits == NULL) {
3563 printf("dastart: Couldn't malloc block_limits data\n");
3564 /* da_free_periph??? */
3568 scsi_inquiry(&start_ccb->csio,
3569 /*retries*/da_retry_count,
3570 /*cbfcnp*/dadone_probeblklimits,
3571 /*tag_action*/MSG_SIMPLE_Q_TAG,
3572 /*inq_buf*/(u_int8_t *)block_limits,
3573 /*inq_len*/sizeof(*block_limits),
3575 /*page_code*/SVPD_BLOCK_LIMITS,
3576 /*sense_len*/SSD_MIN_SIZE,
3577 /*timeout*/da_default_timeout * 1000);
3578 start_ccb->ccb_h.ccb_bp = NULL;
3579 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3580 xpt_action(start_ccb);
3583 case DA_STATE_PROBE_BDC:
3585 struct scsi_vpd_block_characteristics *bdc;
3587 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3588 softc->state = DA_STATE_PROBE_ATA;
3592 bdc = (struct scsi_vpd_block_characteristics *)
3593 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3596 printf("dastart: Couldn't malloc bdc data\n");
3597 /* da_free_periph??? */
3601 scsi_inquiry(&start_ccb->csio,
3602 /*retries*/da_retry_count,
3603 /*cbfcnp*/dadone_probebdc,
3604 /*tag_action*/MSG_SIMPLE_Q_TAG,
3605 /*inq_buf*/(u_int8_t *)bdc,
3606 /*inq_len*/sizeof(*bdc),
3608 /*page_code*/SVPD_BDC,
3609 /*sense_len*/SSD_MIN_SIZE,
3610 /*timeout*/da_default_timeout * 1000);
3611 start_ccb->ccb_h.ccb_bp = NULL;
3612 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3613 xpt_action(start_ccb);
3616 case DA_STATE_PROBE_ATA:
3618 struct ata_params *ata_params;
3620 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3621 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3622 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3624 * Note that if the ATA VPD page isn't
3625 * supported, we aren't talking to an ATA
3626 * device anyway. Support for that VPD
3627 * page is mandatory for SCSI to ATA (SAT)
3628 * translation layers.
3630 softc->state = DA_STATE_PROBE_ZONE;
3633 daprobedone(periph, start_ccb);
3637 ata_params = &periph->path->device->ident_data;
3639 scsi_ata_identify(&start_ccb->csio,
3640 /*retries*/da_retry_count,
3641 /*cbfcnp*/dadone_probeata,
3642 /*tag_action*/MSG_SIMPLE_Q_TAG,
3643 /*data_ptr*/(u_int8_t *)ata_params,
3644 /*dxfer_len*/sizeof(*ata_params),
3645 /*sense_len*/SSD_FULL_SIZE,
3646 /*timeout*/da_default_timeout * 1000);
3647 start_ccb->ccb_h.ccb_bp = NULL;
3648 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3649 xpt_action(start_ccb);
3652 case DA_STATE_PROBE_ATA_LOGDIR:
3654 struct ata_gp_log_dir *log_dir;
3659 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3661 * If we don't have log support, not much point in
3662 * trying to probe zone support.
3664 daprobedone(periph, start_ccb);
3669 * If we have an ATA device (the SCSI ATA Information VPD
3670 * page should be present and the ATA identify should have
3671 * succeeded) and it supports logs, ask for the log directory.
3674 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3675 if (log_dir == NULL) {
3676 xpt_print(periph->path, "Couldn't malloc log_dir "
3678 daprobedone(periph, start_ccb);
3682 retval = scsi_ata_read_log(&start_ccb->csio,
3683 /*retries*/ da_retry_count,
3684 /*cbfcnp*/ dadone_probeatalogdir,
3685 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3686 /*log_address*/ ATA_LOG_DIRECTORY,
3689 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3690 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3691 /*data_ptr*/ (uint8_t *)log_dir,
3692 /*dxfer_len*/ sizeof(*log_dir),
3693 /*sense_len*/ SSD_FULL_SIZE,
3694 /*timeout*/ da_default_timeout * 1000);
3697 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3698 free(log_dir, M_SCSIDA);
3699 daprobedone(periph, start_ccb);
3702 start_ccb->ccb_h.ccb_bp = NULL;
3703 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3704 xpt_action(start_ccb);
3707 case DA_STATE_PROBE_ATA_IDDIR:
3709 struct ata_identify_log_pages *id_dir;
3715 * Check here to see whether the Identify Device log is
3716 * supported in the directory of logs. If so, continue
3717 * with requesting the log of identify device pages.
3719 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3720 daprobedone(periph, start_ccb);
3724 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3725 if (id_dir == NULL) {
3726 xpt_print(periph->path, "Couldn't malloc id_dir "
3728 daprobedone(periph, start_ccb);
3732 retval = scsi_ata_read_log(&start_ccb->csio,
3733 /*retries*/ da_retry_count,
3734 /*cbfcnp*/ dadone_probeataiddir,
3735 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3736 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3737 /*page_number*/ ATA_IDL_PAGE_LIST,
3739 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3740 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3741 /*data_ptr*/ (uint8_t *)id_dir,
3742 /*dxfer_len*/ sizeof(*id_dir),
3743 /*sense_len*/ SSD_FULL_SIZE,
3744 /*timeout*/ da_default_timeout * 1000);
3747 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3748 free(id_dir, M_SCSIDA);
3749 daprobedone(periph, start_ccb);
3752 start_ccb->ccb_h.ccb_bp = NULL;
3753 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3754 xpt_action(start_ccb);
3757 case DA_STATE_PROBE_ATA_SUP:
3759 struct ata_identify_log_sup_cap *sup_cap;
3765 * Check here to see whether the Supported Capabilities log
3766 * is in the list of Identify Device logs.
3768 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3769 daprobedone(periph, start_ccb);
3773 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3774 if (sup_cap == NULL) {
3775 xpt_print(periph->path, "Couldn't malloc sup_cap "
3777 daprobedone(periph, start_ccb);
3781 retval = scsi_ata_read_log(&start_ccb->csio,
3782 /*retries*/ da_retry_count,
3783 /*cbfcnp*/ dadone_probeatasup,
3784 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3785 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3786 /*page_number*/ ATA_IDL_SUP_CAP,
3788 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3789 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3790 /*data_ptr*/ (uint8_t *)sup_cap,
3791 /*dxfer_len*/ sizeof(*sup_cap),
3792 /*sense_len*/ SSD_FULL_SIZE,
3793 /*timeout*/ da_default_timeout * 1000);
3796 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3797 free(sup_cap, M_SCSIDA);
3798 daprobedone(periph, start_ccb);
3803 start_ccb->ccb_h.ccb_bp = NULL;
3804 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3805 xpt_action(start_ccb);
3808 case DA_STATE_PROBE_ATA_ZONE:
3810 struct ata_zoned_info_log *ata_zone;
3816 * Check here to see whether the zoned device information
3817 * page is supported. If so, continue on to request it.
3818 * If not, skip to DA_STATE_PROBE_LOG or done.
3820 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3821 daprobedone(periph, start_ccb);
3824 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3826 if (ata_zone == NULL) {
3827 xpt_print(periph->path, "Couldn't malloc ata_zone "
3829 daprobedone(periph, start_ccb);
3833 retval = scsi_ata_read_log(&start_ccb->csio,
3834 /*retries*/ da_retry_count,
3835 /*cbfcnp*/ dadone_probeatazone,
3836 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3837 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3838 /*page_number*/ ATA_IDL_ZDI,
3840 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3841 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3842 /*data_ptr*/ (uint8_t *)ata_zone,
3843 /*dxfer_len*/ sizeof(*ata_zone),
3844 /*sense_len*/ SSD_FULL_SIZE,
3845 /*timeout*/ da_default_timeout * 1000);
3848 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3849 free(ata_zone, M_SCSIDA);
3850 daprobedone(periph, start_ccb);
3853 start_ccb->ccb_h.ccb_bp = NULL;
3854 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3855 xpt_action(start_ccb);
3859 case DA_STATE_PROBE_ZONE:
3861 struct scsi_vpd_zoned_bdc *bdc;
3864 * Note that this page will be supported for SCSI protocol
3865 * devices that support ZBC (SMR devices), as well as ATA
3866 * protocol devices that are behind a SAT (SCSI to ATA
3867 * Translation) layer that supports converting ZBC commands
3868 * to their ZAC equivalents.
3870 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3871 daprobedone(periph, start_ccb);
3874 bdc = (struct scsi_vpd_zoned_bdc *)
3875 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3878 xpt_release_ccb(start_ccb);
3879 xpt_print(periph->path, "Couldn't malloc zone VPD "
3883 scsi_inquiry(&start_ccb->csio,
3884 /*retries*/da_retry_count,
3885 /*cbfcnp*/dadone_probezone,
3886 /*tag_action*/MSG_SIMPLE_Q_TAG,
3887 /*inq_buf*/(u_int8_t *)bdc,
3888 /*inq_len*/sizeof(*bdc),
3890 /*page_code*/SVPD_ZONED_BDC,
3891 /*sense_len*/SSD_FULL_SIZE,
3892 /*timeout*/da_default_timeout * 1000);
3893 start_ccb->ccb_h.ccb_bp = NULL;
3894 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3895 xpt_action(start_ccb);
3902 * In each of the methods below, while its the caller's
3903 * responsibility to ensure the request will fit into a
3904 * single device request, we might have changed the delete
3905 * method due to the device incorrectly advertising either
3906 * its supported methods or limits.
3908 * To prevent this causing further issues we validate the
3909 * against the methods limits, and warn which would
3910 * otherwise be unnecessary.
3913 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3915 struct da_softc *softc = (struct da_softc *)periph->softc;;
3917 uint8_t *buf = softc->unmap_buf;
3918 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3919 uint64_t lba, lastlba = (uint64_t)-1;
3920 uint64_t totalcount = 0;
3922 uint32_t c, lastcount = 0, ranges = 0;
3925 * Currently this doesn't take the UNMAP
3926 * Granularity and Granularity Alignment
3927 * fields into account.
3929 * This could result in both unoptimal unmap
3930 * requests as as well as UNMAP calls unmapping
3931 * fewer LBA's than requested.
3934 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3938 * Note: ada and da are different in how they store the
3939 * pending bp's in a trim. ada stores all of them in the
3940 * trim_req.bps. da stores all but the first one in the
3941 * delete_run_queue. ada then completes all the bps in
3942 * its adadone() loop. da completes all the bps in the
3943 * delete_run_queue in dadone, and relies on the biodone
3944 * after to complete. This should be reconciled since there's
3945 * no real reason to do it differently. XXX
3948 bioq_insert_tail(&softc->delete_run_queue, bp1);
3949 lba = bp1->bio_pblkno;
3950 count = bp1->bio_bcount / softc->params.secsize;
3952 /* Try to extend the previous range. */
3953 if (lba == lastlba) {
3954 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3957 scsi_ulto4b(lastcount, d[ranges - 1].length);
3961 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3962 softc->unmap_gran != 0) {
3963 /* Align length of the previous range. */
3964 if ((c = lastcount % softc->unmap_gran) != 0) {
3965 if (lastcount <= c) {
3966 totalcount -= lastcount;
3967 lastlba = (uint64_t)-1;
3974 scsi_ulto4b(lastcount,
3975 d[ranges - 1].length);
3978 /* Align beginning of the new range. */
3979 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3981 c = softc->unmap_gran - c;
3992 c = omin(count, UNMAP_RANGE_MAX);
3993 if (totalcount + c > softc->unmap_max_lba ||
3994 ranges >= softc->unmap_max_ranges) {
3995 xpt_print(periph->path,
3996 "%s issuing short delete %ld > %ld"
3998 da_delete_method_desc[softc->delete_method],
3999 totalcount + c, softc->unmap_max_lba,
4000 ranges, softc->unmap_max_ranges);
4003 scsi_u64to8b(lba, d[ranges].lba);
4004 scsi_ulto4b(c, d[ranges].length);
4012 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4015 if (ranges >= softc->unmap_max_ranges ||
4016 totalcount + bp1->bio_bcount /
4017 softc->params.secsize > softc->unmap_max_lba) {
4018 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4023 /* Align length of the last range. */
4024 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
4025 (c = lastcount % softc->unmap_gran) != 0) {
4029 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
4032 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
4033 scsi_ulto2b(ranges * 16, &buf[2]);
4035 scsi_unmap(&ccb->csio,
4036 /*retries*/da_retry_count,
4038 /*tag_action*/MSG_SIMPLE_Q_TAG,
4041 /*dxfer_len*/ ranges * 16 + 8,
4042 /*sense_len*/SSD_FULL_SIZE,
4043 da_default_timeout * 1000);
4044 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4045 ccb->ccb_h.flags |= CAM_UNLOCKED;
4046 softc->trim_count++;
4047 softc->trim_ranges += ranges;
4048 softc->trim_lbas += totalcount;
4049 cam_iosched_submit_trim(softc->cam_iosched);
4053 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4055 struct da_softc *softc = (struct da_softc *)periph->softc;
4057 uint8_t *buf = softc->unmap_buf;
4058 uint64_t lastlba = (uint64_t)-1;
4061 uint32_t lastcount = 0, c, requestcount;
4062 int ranges = 0, off, block_count;
4064 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
4067 if (bp1 != bp)//XXX imp XXX
4068 bioq_insert_tail(&softc->delete_run_queue, bp1);
4069 lba = bp1->bio_pblkno;
4070 count = bp1->bio_bcount / softc->params.secsize;
4071 requestcount = count;
4073 /* Try to extend the previous range. */
4074 if (lba == lastlba) {
4075 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
4077 off = (ranges - 1) * 8;
4078 buf[off + 6] = lastcount & 0xff;
4079 buf[off + 7] = (lastcount >> 8) & 0xff;
4085 c = omin(count, ATA_DSM_RANGE_MAX);
4088 buf[off + 0] = lba & 0xff;
4089 buf[off + 1] = (lba >> 8) & 0xff;
4090 buf[off + 2] = (lba >> 16) & 0xff;
4091 buf[off + 3] = (lba >> 24) & 0xff;
4092 buf[off + 4] = (lba >> 32) & 0xff;
4093 buf[off + 5] = (lba >> 40) & 0xff;
4094 buf[off + 6] = c & 0xff;
4095 buf[off + 7] = (c >> 8) & 0xff;
4100 if (count != 0 && ranges == softc->trim_max_ranges) {
4101 xpt_print(periph->path,
4102 "%s issuing short delete %ld > %ld\n",
4103 da_delete_method_desc[softc->delete_method],
4105 (softc->trim_max_ranges - ranges) *
4111 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4114 if (bp1->bio_bcount / softc->params.secsize >
4115 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
4116 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4121 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
4122 scsi_ata_trim(&ccb->csio,
4123 /*retries*/da_retry_count,
4125 /*tag_action*/MSG_SIMPLE_Q_TAG,
4128 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
4129 /*sense_len*/SSD_FULL_SIZE,
4130 da_default_timeout * 1000);
4131 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4132 ccb->ccb_h.flags |= CAM_UNLOCKED;
4133 cam_iosched_submit_trim(softc->cam_iosched);
4137 * We calculate ws_max_blks here based off d_delmaxsize instead
4138 * of using softc->ws_max_blks as it is absolute max for the
4139 * device not the protocol max which may well be lower.
4142 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4144 struct da_softc *softc;
4146 uint64_t ws_max_blks;
4148 uint64_t count; /* forward compat with WS32 */
4150 softc = (struct da_softc *)periph->softc;
4151 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
4152 lba = bp->bio_pblkno;
4156 if (bp1 != bp)//XXX imp XXX
4157 bioq_insert_tail(&softc->delete_run_queue, bp1);
4158 count += bp1->bio_bcount / softc->params.secsize;
4159 if (count > ws_max_blks) {
4160 xpt_print(periph->path,
4161 "%s issuing short delete %ld > %ld\n",
4162 da_delete_method_desc[softc->delete_method],
4163 count, ws_max_blks);
4164 count = omin(count, ws_max_blks);
4167 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4170 if (lba + count != bp1->bio_pblkno ||
4171 count + bp1->bio_bcount /
4172 softc->params.secsize > ws_max_blks) {
4173 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4178 scsi_write_same(&ccb->csio,
4179 /*retries*/da_retry_count,
4181 /*tag_action*/MSG_SIMPLE_Q_TAG,
4182 /*byte2*/softc->delete_method ==
4183 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
4184 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
4186 /*block_count*/count,
4187 /*data_ptr*/ __DECONST(void *, zero_region),
4188 /*dxfer_len*/ softc->params.secsize,
4189 /*sense_len*/SSD_FULL_SIZE,
4190 da_default_timeout * 1000);
4191 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4192 ccb->ccb_h.flags |= CAM_UNLOCKED;
4193 cam_iosched_submit_trim(softc->cam_iosched);
4197 cmd6workaround(union ccb *ccb)
4199 struct scsi_rw_6 cmd6;
4200 struct scsi_rw_10 *cmd10;
4201 struct da_softc *softc;
4206 cdb = ccb->csio.cdb_io.cdb_bytes;
4207 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
4209 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
4210 da_delete_methods old_method = softc->delete_method;
4213 * Typically there are two reasons for failure here
4214 * 1. Delete method was detected as supported but isn't
4215 * 2. Delete failed due to invalid params e.g. too big
4217 * While we will attempt to choose an alternative delete method
4218 * this may result in short deletes if the existing delete
4219 * requests from geom are big for the new method chosen.
4221 * This method assumes that the error which triggered this
4222 * will not retry the io otherwise a panic will occur
4224 dadeleteflag(softc, old_method, 0);
4225 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
4226 if (softc->delete_method == DA_DELETE_DISABLE)
4227 xpt_print(ccb->ccb_h.path,
4228 "%s failed, disabling BIO_DELETE\n",
4229 da_delete_method_desc[old_method]);
4231 xpt_print(ccb->ccb_h.path,
4232 "%s failed, switching to %s BIO_DELETE\n",
4233 da_delete_method_desc[old_method],
4234 da_delete_method_desc[softc->delete_method]);
4236 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
4237 cam_iosched_queue_work(softc->cam_iosched, bp);
4238 cam_iosched_queue_work(softc->cam_iosched,
4239 (struct bio *)ccb->ccb_h.ccb_bp);
4240 ccb->ccb_h.ccb_bp = NULL;
4244 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
4245 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4246 (*cdb == PREVENT_ALLOW) &&
4247 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
4249 xpt_print(ccb->ccb_h.path,
4250 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
4251 softc->quirks |= DA_Q_NO_PREVENT;
4255 /* Detect unsupported SYNCHRONIZE CACHE(10). */
4256 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4257 (*cdb == SYNCHRONIZE_CACHE) &&
4258 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
4260 xpt_print(ccb->ccb_h.path,
4261 "SYNCHRONIZE CACHE(10) not supported.\n");
4262 softc->quirks |= DA_Q_NO_SYNC_CACHE;
4263 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
4267 /* Translation only possible if CDB is an array and cmd is R/W6 */
4268 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
4269 (*cdb != READ_6 && *cdb != WRITE_6))
4272 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
4273 "increasing minimum_cmd_size to 10.\n");
4274 softc->minimum_cmd_size = 10;
4276 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
4277 cmd10 = (struct scsi_rw_10 *)cdb;
4278 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
4280 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
4281 cmd10->reserved = 0;
4282 scsi_ulto2b(cmd6.length, cmd10->length);
4283 cmd10->control = cmd6.control;
4284 ccb->csio.cdb_len = sizeof(*cmd10);
4286 /* Requeue request, unfreezing queue if necessary */
4287 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
4288 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4291 cam_release_devq(ccb->ccb_h.path,
4295 /*getcount_only*/0);
4301 dazonedone(struct cam_periph *periph, union ccb *ccb)
4303 struct da_softc *softc;
4306 softc = periph->softc;
4307 bp = (struct bio *)ccb->ccb_h.ccb_bp;
4309 switch (bp->bio_zone.zone_cmd) {
4310 case DISK_ZONE_OPEN:
4311 case DISK_ZONE_CLOSE:
4312 case DISK_ZONE_FINISH:
4315 case DISK_ZONE_REPORT_ZONES: {
4317 struct disk_zone_report *rep;
4318 struct scsi_report_zones_hdr *hdr;
4319 struct scsi_report_zones_desc *desc;
4320 struct disk_zone_rep_entry *entry;
4321 uint32_t hdr_len, num_avail;
4322 uint32_t num_to_fill, i;
4325 rep = &bp->bio_zone.zone_params.report;
4326 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
4328 * Note that bio_resid isn't normally used for zone
4329 * commands, but it is used by devstat_end_transaction_bio()
4330 * to determine how much data was transferred. Because
4331 * the size of the SCSI/ATA data structures is different
4332 * than the size of the BIO interface structures, the
4333 * amount of data actually transferred from the drive will
4334 * be different than the amount of data transferred to
4337 bp->bio_resid = ccb->csio.resid;
4338 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
4339 if (avail_len < sizeof(*hdr)) {
4341 * Is there a better error than EIO here? We asked
4342 * for at least the header, and we got less than
4345 bp->bio_error = EIO;
4346 bp->bio_flags |= BIO_ERROR;
4347 bp->bio_resid = bp->bio_bcount;
4351 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4356 hdr_len = ata ? le32dec(hdr->length) :
4357 scsi_4btoul(hdr->length);
4359 rep->entries_available = hdr_len / sizeof(*desc);
4361 rep->entries_available = 0;
4363 * NOTE: using the same values for the BIO version of the
4364 * same field as the SCSI/ATA values. This means we could
4365 * get some additional values that aren't defined in bio.h
4366 * if more values of the same field are defined later.
4368 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4369 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4370 scsi_8btou64(hdr->maximum_lba);
4372 * If the drive reports no entries that match the query,
4376 rep->entries_filled = 0;
4380 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4381 hdr_len / sizeof(*desc));
4383 * If the drive didn't return any data, then we're done.
4385 if (num_avail == 0) {
4386 rep->entries_filled = 0;
4390 num_to_fill = min(num_avail, rep->entries_allocated);
4392 * If the user didn't allocate any entries for us to fill,
4395 if (num_to_fill == 0) {
4396 rep->entries_filled = 0;
4400 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4401 i < num_to_fill; i++, desc++, entry++) {
4403 * NOTE: we're mapping the values here directly
4404 * from the SCSI/ATA bit definitions to the bio.h
4405 * definitons. There is also a warning in
4406 * disk_zone.h, but the impact is that if
4407 * additional values are added in the SCSI/ATA
4408 * specs these will be visible to consumers of
4411 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4412 entry->zone_condition =
4413 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4414 SRZ_ZONE_COND_SHIFT;
4415 entry->zone_flags |= desc->zone_flags &
4416 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4417 entry->zone_length =
4418 ata ? le64dec(desc->zone_length) :
4419 scsi_8btou64(desc->zone_length);
4420 entry->zone_start_lba =
4421 ata ? le64dec(desc->zone_start_lba) :
4422 scsi_8btou64(desc->zone_start_lba);
4423 entry->write_pointer_lba =
4424 ata ? le64dec(desc->write_pointer_lba) :
4425 scsi_8btou64(desc->write_pointer_lba);
4427 rep->entries_filled = num_to_fill;
4430 case DISK_ZONE_GET_PARAMS:
4433 * In theory we should not get a GET_PARAMS bio, since it
4434 * should be handled without queueing the command to the
4437 panic("%s: Invalid zone command %d", __func__,
4438 bp->bio_zone.zone_cmd);
4442 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4443 free(ccb->csio.data_ptr, M_SCSIDA);
4447 dadone(struct cam_periph *periph, union ccb *done_ccb)
4449 struct bio *bp, *bp1;
4450 struct da_softc *softc;
4451 struct ccb_scsiio *csio;
4455 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4457 softc = (struct da_softc *)periph->softc;
4458 priority = done_ccb->ccb_h.pinfo.priority;
4459 csio = &done_ccb->csio;
4461 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4462 if (csio->bio != NULL)
4463 biotrack(csio->bio, __func__);
4465 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4467 cam_periph_lock(periph);
4468 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4469 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4473 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4478 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4479 if (error == ERESTART) {
4480 /* A retry was scheduled, so just return. */
4481 cam_periph_unlock(periph);
4484 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4489 * return all queued I/O with EIO, so that
4490 * the client can retry these I/Os in the
4491 * proper order should it attempt to recover.
4496 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4498 * Catastrophic error. Mark our pack as
4501 * XXX See if this is really a media
4504 xpt_print(periph->path, "Invalidating pack\n");
4505 softc->flags |= DA_FLAG_PACK_INVALID;
4507 softc->invalidations++;
4509 queued_error = ENXIO;
4511 cam_iosched_flush(softc->cam_iosched, NULL,
4514 bp->bio_error = error;
4515 bp->bio_resid = bp->bio_bcount;
4516 bp->bio_flags |= BIO_ERROR;
4518 } else if (bp != NULL) {
4519 if (state == DA_CCB_DELETE)
4522 bp->bio_resid = csio->resid;
4524 if (bp->bio_resid != 0)
4525 bp->bio_flags |= BIO_ERROR;
4527 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4528 cam_release_devq(done_ccb->ccb_h.path,
4532 /*getcount_only*/0);
4533 } else if (bp != NULL) {
4534 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4535 panic("REQ_CMP with QFRZN");
4536 if (bp->bio_cmd == BIO_ZONE)
4537 dazonedone(periph, done_ccb);
4538 else if (state == DA_CCB_DELETE)
4541 bp->bio_resid = csio->resid;
4542 if ((csio->resid > 0) && (bp->bio_cmd != BIO_ZONE))
4543 bp->bio_flags |= BIO_ERROR;
4544 if (softc->error_inject != 0) {
4545 bp->bio_error = softc->error_inject;
4546 bp->bio_resid = bp->bio_bcount;
4547 bp->bio_flags |= BIO_ERROR;
4548 softc->error_inject = 0;
4553 biotrack(bp, __func__);
4554 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4555 if (LIST_EMPTY(&softc->pending_ccbs))
4556 softc->flags |= DA_FLAG_WAS_OTAG;
4559 * We need to call cam_iosched before we call biodone so that we don't
4560 * measure any activity that happens in the completion routine, which in
4561 * the case of sendfile can be quite extensive. Release the periph
4562 * refcount taken in dastart() for each CCB.
4564 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4565 xpt_release_ccb(done_ccb);
4566 KASSERT(softc->refcount >= 1, ("dadone softc %p refcount %d", softc, softc->refcount));
4568 if (state == DA_CCB_DELETE) {
4569 TAILQ_HEAD(, bio) queue;
4572 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4573 softc->delete_run_queue.insert_point = NULL;
4575 * Normally, the xpt_release_ccb() above would make sure
4576 * that when we have more work to do, that work would
4577 * get kicked off. However, we specifically keep
4578 * delete_running set to 0 before the call above to
4579 * allow other I/O to progress when many BIO_DELETE
4580 * requests are pushed down. We set delete_running to 0
4581 * and call daschedule again so that we don't stall if
4582 * there are no other I/Os pending apart from BIO_DELETEs.
4584 cam_iosched_trim_done(softc->cam_iosched);
4586 cam_periph_unlock(periph);
4587 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4588 TAILQ_REMOVE(&queue, bp1, bio_queue);
4589 bp1->bio_error = bp->bio_error;
4590 if (bp->bio_flags & BIO_ERROR) {
4591 bp1->bio_flags |= BIO_ERROR;
4592 bp1->bio_resid = bp1->bio_bcount;
4599 cam_periph_unlock(periph);
4607 dadone_probewp(struct cam_periph *periph, union ccb *done_ccb)
4609 struct scsi_mode_header_6 *mode_hdr6;
4610 struct scsi_mode_header_10 *mode_hdr10;
4611 struct da_softc *softc;
4612 struct ccb_scsiio *csio;
4616 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probewp\n"));
4618 softc = (struct da_softc *)periph->softc;
4619 priority = done_ccb->ccb_h.pinfo.priority;
4620 csio = &done_ccb->csio;
4622 cam_periph_assert(periph, MA_OWNED);
4624 KASSERT(softc->state == DA_STATE_PROBE_WP,
4625 ("State (%d) not PROBE_WP in dadone_probewp, periph %p ccb %p",
4626 softc->state, periph, done_ccb));
4627 KASSERT((csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK) == DA_CCB_PROBE_WP,
4628 ("CCB State (%lu) not PROBE_WP in dadone_probewp, periph %p ccb %p",
4629 (unsigned long)csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK, periph,
4632 if (softc->minimum_cmd_size > 6) {
4633 mode_hdr10 = (struct scsi_mode_header_10 *)csio->data_ptr;
4634 dev_spec = mode_hdr10->dev_spec;
4636 mode_hdr6 = (struct scsi_mode_header_6 *)csio->data_ptr;
4637 dev_spec = mode_hdr6->dev_spec;
4639 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
4640 if ((dev_spec & 0x80) != 0)
4641 softc->disk->d_flags |= DISKFLAG_WRITE_PROTECT;
4643 softc->disk->d_flags &= ~DISKFLAG_WRITE_PROTECT;
4647 error = daerror(done_ccb, CAM_RETRY_SELTO,
4648 SF_RETRY_UA|SF_NO_PRINT);
4649 if (error == ERESTART)
4651 else if (error != 0) {
4652 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4653 /* Don't wedge this device's queue */
4654 cam_release_devq(done_ccb->ccb_h.path,
4658 /*getcount_only*/0);
4663 free(csio->data_ptr, M_SCSIDA);
4664 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
4665 softc->state = DA_STATE_PROBE_RC16;
4667 softc->state = DA_STATE_PROBE_RC;
4668 xpt_release_ccb(done_ccb);
4669 xpt_schedule(periph, priority);
4674 dadone_proberc(struct cam_periph *periph, union ccb *done_ccb)
4676 struct scsi_read_capacity_data *rdcap;
4677 struct scsi_read_capacity_data_long *rcaplong;
4678 struct da_softc *softc;
4679 struct ccb_scsiio *csio;
4685 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_proberc\n"));
4687 softc = (struct da_softc *)periph->softc;
4688 priority = done_ccb->ccb_h.pinfo.priority;
4689 csio = &done_ccb->csio;
4690 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4692 KASSERT(softc->state == DA_STATE_PROBE_RC || softc->state == DA_STATE_PROBE_RC16,
4693 ("State (%d) not PROBE_RC* in dadone_proberc, periph %p ccb %p",
4694 softc->state, periph, done_ccb));
4695 KASSERT(state == DA_CCB_PROBE_RC || state == DA_CCB_PROBE_RC16,
4696 ("CCB State (%lu) not PROBE_RC* in dadone_probewp, periph %p ccb %p",
4697 (unsigned long)state, periph, done_ccb));
4702 /* XXX TODO: can this be a malloc? */
4703 announce_buf = softc->announce_temp;
4704 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4706 if (state == DA_CCB_PROBE_RC)
4707 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4709 rcaplong = (struct scsi_read_capacity_data_long *)
4712 cam_periph_assert(periph, MA_OWNED);
4714 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4715 struct disk_params *dp;
4716 uint32_t block_size;
4718 u_int lalba; /* Lowest aligned LBA. */
4720 if (state == DA_CCB_PROBE_RC) {
4721 block_size = scsi_4btoul(rdcap->length);
4722 maxsector = scsi_4btoul(rdcap->addr);
4726 * According to SBC-2, if the standard 10
4727 * byte READ CAPACITY command returns 2^32,
4728 * we should issue the 16 byte version of
4729 * the command, since the device in question
4730 * has more sectors than can be represented
4731 * with the short version of the command.
4733 if (maxsector == 0xffffffff) {
4734 free(rdcap, M_SCSIDA);
4735 softc->state = DA_STATE_PROBE_RC16;
4736 xpt_release_ccb(done_ccb);
4737 xpt_schedule(periph, priority);
4741 block_size = scsi_4btoul(rcaplong->length);
4742 maxsector = scsi_8btou64(rcaplong->addr);
4743 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4747 * Because GEOM code just will panic us if we
4748 * give them an 'illegal' value we'll avoid that
4751 if (block_size == 0) {
4756 if (block_size >= MAXPHYS) {
4757 xpt_print(periph->path,
4758 "unsupportable block size %ju\n",
4759 (uintmax_t) block_size);
4760 announce_buf = NULL;
4761 cam_periph_invalidate(periph);
4764 * We pass rcaplong into dasetgeom(),
4765 * because it will only use it if it is
4768 dasetgeom(periph, block_size, maxsector,
4769 rcaplong, sizeof(*rcaplong));
4770 lbp = (lalba & SRC16_LBPME_A);
4771 dp = &softc->params;
4772 n = snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4773 "%juMB (%ju %u byte sectors",
4774 ((uintmax_t)dp->secsize * dp->sectors) /
4776 (uintmax_t)dp->sectors, dp->secsize);
4777 if (softc->p_type != 0) {
4778 n += snprintf(announce_buf + n,
4779 DA_ANNOUNCETMP_SZ - n,
4780 ", DIF type %d", softc->p_type);
4782 snprintf(announce_buf + n, DA_ANNOUNCETMP_SZ - n, ")");
4788 * Retry any UNIT ATTENTION type errors. They
4789 * are expected at boot.
4791 error = daerror(done_ccb, CAM_RETRY_SELTO,
4792 SF_RETRY_UA|SF_NO_PRINT);
4793 if (error == ERESTART) {
4795 * A retry was scheuled, so
4799 } else if (error != 0) {
4801 int sense_key, error_code;
4804 struct ccb_getdev cgd;
4806 /* Don't wedge this device's queue */
4807 status = done_ccb->ccb_h.status;
4808 if ((status & CAM_DEV_QFRZN) != 0)
4809 cam_release_devq(done_ccb->ccb_h.path,
4813 /*getcount_only*/0);
4816 xpt_setup_ccb(&cgd.ccb_h, done_ccb->ccb_h.path,
4817 CAM_PRIORITY_NORMAL);
4818 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4819 xpt_action((union ccb *)&cgd);
4821 if (scsi_extract_sense_ccb(done_ccb,
4822 &error_code, &sense_key, &asc, &ascq))
4828 * If we tried READ CAPACITY(16) and failed,
4829 * fallback to READ CAPACITY(10).
4831 if ((state == DA_CCB_PROBE_RC16) &&
4832 (softc->flags & DA_FLAG_CAN_RC16) &&
4833 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4836 (error_code == SSD_CURRENT_ERROR ||
4837 error_code == SSD_DESC_CURRENT_ERROR) &&
4838 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4839 cam_periph_assert(periph, MA_OWNED);
4840 softc->flags &= ~DA_FLAG_CAN_RC16;
4841 free(rdcap, M_SCSIDA);
4842 softc->state = DA_STATE_PROBE_RC;
4843 xpt_release_ccb(done_ccb);
4844 xpt_schedule(periph, priority);
4849 * Attach to anything that claims to be a
4850 * direct access or optical disk device,
4851 * as long as it doesn't return a "Logical
4852 * unit not supported" (0x25) error.
4853 * "Internal Target Failure" (0x44) is also
4854 * special and typically means that the
4855 * device is a SATA drive behind a SATL
4856 * translation that's fallen into a
4857 * terminally fatal state.
4860 && (asc != 0x25) && (asc != 0x44)
4861 && (error_code == SSD_CURRENT_ERROR
4862 || error_code == SSD_DESC_CURRENT_ERROR)) {
4863 const char *sense_key_desc;
4864 const char *asc_desc;
4866 dasetgeom(periph, 512, -1, NULL, 0);
4867 scsi_sense_desc(sense_key, asc, ascq,
4868 &cgd.inq_data, &sense_key_desc,
4870 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4871 "Attempt to query device "
4872 "size failed: %s, %s",
4873 sense_key_desc, asc_desc);
4876 scsi_sense_print(&done_ccb->csio);
4878 xpt_print(periph->path,
4879 "got CAM status %#x\n",
4880 done_ccb->ccb_h.status);
4883 xpt_print(periph->path, "fatal error, "
4884 "failed to attach to device\n");
4886 announce_buf = NULL;
4889 * Free up resources.
4891 cam_periph_invalidate(periph);
4895 free(csio->data_ptr, M_SCSIDA);
4896 if (announce_buf != NULL &&
4897 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4900 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4902 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4903 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4909 * Create our sysctl variables, now that we know
4910 * we have successfully attached.
4912 /* increase the refcount */
4913 if (da_periph_acquire(periph, DA_REF_SYSCTL) == 0) {
4914 taskqueue_enqueue(taskqueue_thread,
4915 &softc->sysctl_task);
4917 /* XXX This message is useless! */
4918 xpt_print(periph->path, "fatal error, "
4919 "could not acquire reference count\n");
4923 /* We already probed the device. */
4924 if (softc->flags & DA_FLAG_PROBED) {
4925 daprobedone(periph, done_ccb);
4929 /* Ensure re-probe doesn't see old delete. */
4930 softc->delete_available = 0;
4931 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4932 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4934 * Based on older SBC-3 spec revisions
4935 * any of the UNMAP methods "may" be
4936 * available via LBP given this flag so
4937 * we flag all of them as available and
4938 * then remove those which further
4939 * probes confirm aren't available
4942 * We could also check readcap(16) p_type
4943 * flag to exclude one or more invalid
4944 * write same (X) types here
4946 dadeleteflag(softc, DA_DELETE_WS16, 1);
4947 dadeleteflag(softc, DA_DELETE_WS10, 1);
4948 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4950 softc->state = DA_STATE_PROBE_LBP;
4951 xpt_release_ccb(done_ccb);
4952 xpt_schedule(periph, priority);
4956 softc->state = DA_STATE_PROBE_BDC;
4957 xpt_release_ccb(done_ccb);
4958 xpt_schedule(periph, priority);
4963 dadone_probelbp(struct cam_periph *periph, union ccb *done_ccb)
4965 struct scsi_vpd_logical_block_prov *lbp;
4966 struct da_softc *softc;
4967 struct ccb_scsiio *csio;
4970 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probelbp\n"));
4972 softc = (struct da_softc *)periph->softc;
4973 priority = done_ccb->ccb_h.pinfo.priority;
4974 csio = &done_ccb->csio;
4975 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4977 cam_periph_assert(periph, MA_OWNED);
4979 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4981 * T10/1799-D Revision 31 states at least one of these
4982 * must be supported but we don't currently enforce this.
4984 dadeleteflag(softc, DA_DELETE_WS16,
4985 (lbp->flags & SVPD_LBP_WS16));
4986 dadeleteflag(softc, DA_DELETE_WS10,
4987 (lbp->flags & SVPD_LBP_WS10));
4988 dadeleteflag(softc, DA_DELETE_UNMAP,
4989 (lbp->flags & SVPD_LBP_UNMAP));
4992 error = daerror(done_ccb, CAM_RETRY_SELTO,
4993 SF_RETRY_UA|SF_NO_PRINT);
4994 if (error == ERESTART)
4996 else if (error != 0) {
4997 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4998 /* Don't wedge this device's queue */
4999 cam_release_devq(done_ccb->ccb_h.path,
5003 /*getcount_only*/0);
5007 * Failure indicates we don't support any SBC-3
5008 * delete methods with UNMAP
5013 free(lbp, M_SCSIDA);
5014 softc->state = DA_STATE_PROBE_BLK_LIMITS;
5015 xpt_release_ccb(done_ccb);
5016 xpt_schedule(periph, priority);
5021 dadone_probeblklimits(struct cam_periph *periph, union ccb *done_ccb)
5023 struct scsi_vpd_block_limits *block_limits;
5024 struct da_softc *softc;
5025 struct ccb_scsiio *csio;
5028 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeblklimits\n"));
5030 softc = (struct da_softc *)periph->softc;
5031 priority = done_ccb->ccb_h.pinfo.priority;
5032 csio = &done_ccb->csio;
5033 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
5035 cam_periph_assert(periph, MA_OWNED);
5037 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5038 uint32_t max_txfer_len = scsi_4btoul(
5039 block_limits->max_txfer_len);
5040 uint32_t max_unmap_lba_cnt = scsi_4btoul(
5041 block_limits->max_unmap_lba_cnt);
5042 uint32_t max_unmap_blk_cnt = scsi_4btoul(
5043 block_limits->max_unmap_blk_cnt);
5044 uint32_t unmap_gran = scsi_4btoul(
5045 block_limits->opt_unmap_grain);
5046 uint32_t unmap_gran_align = scsi_4btoul(
5047 block_limits->unmap_grain_align);
5048 uint64_t ws_max_blks = scsi_8btou64(
5049 block_limits->max_write_same_length);
5051 if (max_txfer_len != 0) {
5052 softc->disk->d_maxsize = MIN(softc->maxio,
5053 (off_t)max_txfer_len * softc->params.secsize);
5057 * We should already support UNMAP but we check lba
5058 * and block count to be sure
5060 if (max_unmap_lba_cnt != 0x00L &&
5061 max_unmap_blk_cnt != 0x00L) {
5062 softc->unmap_max_lba = max_unmap_lba_cnt;
5063 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
5065 if (unmap_gran > 1) {
5066 softc->unmap_gran = unmap_gran;
5067 if (unmap_gran_align & 0x80000000) {
5068 softc->unmap_gran_align =
5069 unmap_gran_align & 0x7fffffff;
5074 * Unexpected UNMAP limits which means the
5075 * device doesn't actually support UNMAP
5077 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
5080 if (ws_max_blks != 0x00L)
5081 softc->ws_max_blks = ws_max_blks;
5084 error = daerror(done_ccb, CAM_RETRY_SELTO,
5085 SF_RETRY_UA|SF_NO_PRINT);
5086 if (error == ERESTART)
5088 else if (error != 0) {
5089 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5090 /* Don't wedge this device's queue */
5091 cam_release_devq(done_ccb->ccb_h.path,
5095 /*getcount_only*/0);
5099 * Failure here doesn't mean UNMAP is not
5100 * supported as this is an optional page.
5102 softc->unmap_max_lba = 1;
5103 softc->unmap_max_ranges = 1;
5107 free(block_limits, M_SCSIDA);
5108 softc->state = DA_STATE_PROBE_BDC;
5109 xpt_release_ccb(done_ccb);
5110 xpt_schedule(periph, priority);
5115 dadone_probebdc(struct cam_periph *periph, union ccb *done_ccb)
5117 struct scsi_vpd_block_device_characteristics *bdc;
5118 struct da_softc *softc;
5119 struct ccb_scsiio *csio;
5122 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probebdc\n"));
5124 softc = (struct da_softc *)periph->softc;
5125 priority = done_ccb->ccb_h.pinfo.priority;
5126 csio = &done_ccb->csio;
5127 bdc = (struct scsi_vpd_block_device_characteristics *)csio->data_ptr;
5129 cam_periph_assert(periph, MA_OWNED);
5131 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5135 * Disable queue sorting for non-rotational media
5138 u_int16_t old_rate = softc->disk->d_rotation_rate;
5140 valid_len = csio->dxfer_len - csio->resid;
5141 if (SBDC_IS_PRESENT(bdc, valid_len,
5142 medium_rotation_rate)) {
5143 softc->disk->d_rotation_rate =
5144 scsi_2btoul(bdc->medium_rotation_rate);
5145 if (softc->disk->d_rotation_rate ==
5146 SVPD_BDC_RATE_NON_ROTATING) {
5147 cam_iosched_set_sort_queue(
5148 softc->cam_iosched, 0);
5149 softc->rotating = 0;
5151 if (softc->disk->d_rotation_rate != old_rate) {
5152 disk_attr_changed(softc->disk,
5153 "GEOM::rotation_rate", M_NOWAIT);
5156 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
5157 && (softc->zone_mode == DA_ZONE_NONE)) {
5160 if (scsi_vpd_supported_page(periph,
5161 SVPD_ATA_INFORMATION))
5167 * The Zoned field will only be set for
5168 * Drive Managed and Host Aware drives. If
5169 * they are Host Managed, the device type
5170 * in the standard INQUIRY data should be
5171 * set to T_ZBC_HM (0x14).
5173 if ((bdc->flags & SVPD_ZBC_MASK) ==
5175 softc->zone_mode = DA_ZONE_HOST_AWARE;
5176 softc->zone_interface = (ata_proto) ?
5177 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5178 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
5180 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5181 softc->zone_interface = (ata_proto) ?
5182 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5183 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
5185 xpt_print(periph->path, "Unknown zoned "
5187 bdc->flags & SVPD_ZBC_MASK);
5192 error = daerror(done_ccb, CAM_RETRY_SELTO,
5193 SF_RETRY_UA|SF_NO_PRINT);
5194 if (error == ERESTART)
5196 else if (error != 0) {
5197 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5198 /* Don't wedge this device's queue */
5199 cam_release_devq(done_ccb->ccb_h.path,
5203 /*getcount_only*/0);
5208 free(bdc, M_SCSIDA);
5209 softc->state = DA_STATE_PROBE_ATA;
5210 xpt_release_ccb(done_ccb);
5211 xpt_schedule(periph, priority);
5216 dadone_probeata(struct cam_periph *periph, union ccb *done_ccb)
5218 struct ata_params *ata_params;
5219 struct ccb_scsiio *csio;
5220 struct da_softc *softc;
5226 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeata\n"));
5228 softc = (struct da_softc *)periph->softc;
5229 priority = done_ccb->ccb_h.pinfo.priority;
5230 csio = &done_ccb->csio;
5231 ata_params = (struct ata_params *)csio->data_ptr;
5232 ptr = (uint16_t *)ata_params;
5236 cam_periph_assert(periph, MA_OWNED);
5238 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5241 ata_param_fixup(ata_params);
5242 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
5243 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
5244 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
5245 if (ata_params->max_dsm_blocks != 0)
5246 softc->trim_max_ranges = min(
5247 softc->trim_max_ranges,
5248 ata_params->max_dsm_blocks *
5249 ATA_DSM_BLK_RANGES);
5252 * Disable queue sorting for non-rotational media
5255 old_rate = softc->disk->d_rotation_rate;
5256 softc->disk->d_rotation_rate = ata_params->media_rotation_rate;
5257 if (softc->disk->d_rotation_rate == ATA_RATE_NON_ROTATING) {
5258 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
5259 softc->rotating = 0;
5261 if (softc->disk->d_rotation_rate != old_rate) {
5262 disk_attr_changed(softc->disk,
5263 "GEOM::rotation_rate", M_NOWAIT);
5266 cam_periph_assert(periph, MA_OWNED);
5267 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
5268 softc->flags |= DA_FLAG_CAN_ATA_DMA;
5270 if (ata_params->support.extension & ATA_SUPPORT_GENLOG)
5271 softc->flags |= DA_FLAG_CAN_ATA_LOG;
5274 * At this point, if we have a SATA host aware drive,
5275 * we communicate via ATA passthrough unless the
5276 * SAT layer supports ZBC -> ZAC translation. In
5279 * XXX KDM figure out how to detect a host managed
5282 if (softc->zone_mode == DA_ZONE_NONE) {
5284 * Note that we don't override the zone
5285 * mode or interface if it has already been
5286 * set. This is because it has either been
5287 * set as a quirk, or when we probed the
5288 * SCSI Block Device Characteristics page,
5289 * the zoned field was set. The latter
5290 * means that the SAT layer supports ZBC to
5291 * ZAC translation, and we would prefer to
5292 * use that if it is available.
5294 if ((ata_params->support3 &
5295 ATA_SUPPORT_ZONE_MASK) ==
5296 ATA_SUPPORT_ZONE_HOST_AWARE) {
5297 softc->zone_mode = DA_ZONE_HOST_AWARE;
5298 softc->zone_interface =
5299 DA_ZONE_IF_ATA_PASS;
5300 } else if ((ata_params->support3 &
5301 ATA_SUPPORT_ZONE_MASK) ==
5302 ATA_SUPPORT_ZONE_DEV_MANAGED) {
5303 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5304 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
5309 error = daerror(done_ccb, CAM_RETRY_SELTO,
5310 SF_RETRY_UA|SF_NO_PRINT);
5311 if (error == ERESTART)
5313 else if (error != 0) {
5314 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5315 /* Don't wedge this device's queue */
5316 cam_release_devq(done_ccb->ccb_h.path,
5320 /*getcount_only*/0);
5325 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
5326 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
5328 * If the ATA IDENTIFY failed, we could be talking
5329 * to a SCSI drive, although that seems unlikely,
5330 * since the drive did report that it supported the
5331 * ATA Information VPD page. If the ATA IDENTIFY
5332 * succeeded, and the SAT layer doesn't support
5333 * ZBC -> ZAC translation, continue on to get the
5334 * directory of ATA logs, and complete the rest of
5335 * the ZAC probe. If the SAT layer does support
5336 * ZBC -> ZAC translation, we want to use that,
5337 * and we'll probe the SCSI Zoned Block Device
5338 * Characteristics VPD page next.
5341 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
5342 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
5343 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
5345 softc->state = DA_STATE_PROBE_ZONE;
5348 if (continue_probe != 0) {
5349 xpt_schedule(periph, priority);
5350 xpt_release_ccb(done_ccb);
5353 daprobedone(periph, done_ccb);
5358 dadone_probeatalogdir(struct cam_periph *periph, union ccb *done_ccb)
5360 struct da_softc *softc;
5361 struct ccb_scsiio *csio;
5365 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatalogdir\n"));
5367 softc = (struct da_softc *)periph->softc;
5368 priority = done_ccb->ccb_h.pinfo.priority;
5369 csio = &done_ccb->csio;
5371 cam_periph_assert(periph, MA_OWNED);
5372 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5374 softc->valid_logdir_len = 0;
5375 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
5376 softc->valid_logdir_len = csio->dxfer_len - csio->resid;
5377 if (softc->valid_logdir_len > 0)
5378 bcopy(csio->data_ptr, &softc->ata_logdir,
5379 min(softc->valid_logdir_len,
5380 sizeof(softc->ata_logdir)));
5382 * Figure out whether the Identify Device log is
5383 * supported. The General Purpose log directory
5384 * has a header, and lists the number of pages
5385 * available for each GP log identified by the
5386 * offset into the list.
5388 if ((softc->valid_logdir_len >=
5389 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
5390 && (le16dec(softc->ata_logdir.header) ==
5391 ATA_GP_LOG_DIR_VERSION)
5392 && (le16dec(&softc->ata_logdir.num_pages[
5393 (ATA_IDENTIFY_DATA_LOG *
5394 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
5395 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
5397 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5400 error = daerror(done_ccb, CAM_RETRY_SELTO,
5401 SF_RETRY_UA|SF_NO_PRINT);
5402 if (error == ERESTART)
5404 else if (error != 0) {
5406 * If we can't get the ATA log directory,
5407 * then ATA logs are effectively not
5408 * supported even if the bit is set in the
5411 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
5412 DA_FLAG_CAN_ATA_IDLOG);
5413 if ((done_ccb->ccb_h.status &
5414 CAM_DEV_QFRZN) != 0) {
5415 /* Don't wedge this device's queue */
5416 cam_release_devq(done_ccb->ccb_h.path,
5420 /*getcount_only*/0);
5425 free(csio->data_ptr, M_SCSIDA);
5428 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
5429 softc->state = DA_STATE_PROBE_ATA_IDDIR;
5430 xpt_release_ccb(done_ccb);
5431 xpt_schedule(periph, priority);
5434 daprobedone(periph, done_ccb);
5439 dadone_probeataiddir(struct cam_periph *periph, union ccb *done_ccb)
5441 struct da_softc *softc;
5442 struct ccb_scsiio *csio;
5446 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeataiddir\n"));
5448 softc = (struct da_softc *)periph->softc;
5449 priority = done_ccb->ccb_h.pinfo.priority;
5450 csio = &done_ccb->csio;
5452 cam_periph_assert(periph, MA_OWNED);
5454 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5455 off_t entries_offset, max_entries;
5458 softc->valid_iddir_len = 0;
5459 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
5460 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
5461 DA_FLAG_CAN_ATA_ZONE);
5462 softc->valid_iddir_len = csio->dxfer_len - csio->resid;
5463 if (softc->valid_iddir_len > 0)
5464 bcopy(csio->data_ptr, &softc->ata_iddir,
5465 min(softc->valid_iddir_len,
5466 sizeof(softc->ata_iddir)));
5469 __offsetof(struct ata_identify_log_pages,entries);
5470 max_entries = softc->valid_iddir_len - entries_offset;
5471 if ((softc->valid_iddir_len > (entries_offset + 1))
5472 && (le64dec(softc->ata_iddir.header) == ATA_IDLOG_REVISION)
5473 && (softc->ata_iddir.entry_count > 0)) {
5476 num_entries = softc->ata_iddir.entry_count;
5477 num_entries = min(num_entries,
5478 softc->valid_iddir_len - entries_offset);
5479 for (i = 0; i < num_entries && i < max_entries; i++) {
5480 if (softc->ata_iddir.entries[i] ==
5482 softc->flags |= DA_FLAG_CAN_ATA_SUPCAP;
5483 else if (softc->ata_iddir.entries[i] ==
5485 softc->flags |= DA_FLAG_CAN_ATA_ZONE;
5487 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP)
5488 && (softc->flags & DA_FLAG_CAN_ATA_ZONE))
5493 error = daerror(done_ccb, CAM_RETRY_SELTO,
5494 SF_RETRY_UA|SF_NO_PRINT);
5495 if (error == ERESTART)
5497 else if (error != 0) {
5499 * If we can't get the ATA Identify Data log
5500 * directory, then it effectively isn't
5501 * supported even if the ATA Log directory
5502 * a non-zero number of pages present for
5505 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5506 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5507 /* Don't wedge this device's queue */
5508 cam_release_devq(done_ccb->ccb_h.path,
5512 /*getcount_only*/0);
5517 free(csio->data_ptr, M_SCSIDA);
5519 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5520 softc->state = DA_STATE_PROBE_ATA_SUP;
5521 xpt_release_ccb(done_ccb);
5522 xpt_schedule(periph, priority);
5525 daprobedone(periph, done_ccb);
5530 dadone_probeatasup(struct cam_periph *periph, union ccb *done_ccb)
5532 struct da_softc *softc;
5533 struct ccb_scsiio *csio;
5537 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatasup\n"));
5539 softc = (struct da_softc *)periph->softc;
5540 priority = done_ccb->ccb_h.pinfo.priority;
5541 csio = &done_ccb->csio;
5543 cam_periph_assert(periph, MA_OWNED);
5545 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5548 struct ata_identify_log_sup_cap *sup_cap;
5551 sup_cap = (struct ata_identify_log_sup_cap *)csio->data_ptr;
5552 valid_len = csio->dxfer_len - csio->resid;
5553 needed_size = __offsetof(struct ata_identify_log_sup_cap,
5554 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5555 if (valid_len >= needed_size) {
5556 uint64_t zoned, zac_cap;
5558 zoned = le64dec(sup_cap->zoned_cap);
5559 if (zoned & ATA_ZONED_VALID) {
5561 * This should have already been
5562 * set, because this is also in the
5563 * ATA identify data.
5565 if ((zoned & ATA_ZONED_MASK) ==
5566 ATA_SUPPORT_ZONE_HOST_AWARE)
5567 softc->zone_mode = DA_ZONE_HOST_AWARE;
5568 else if ((zoned & ATA_ZONED_MASK) ==
5569 ATA_SUPPORT_ZONE_DEV_MANAGED)
5571 DA_ZONE_DRIVE_MANAGED;
5574 zac_cap = le64dec(sup_cap->sup_zac_cap);
5575 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5576 if (zac_cap & ATA_REPORT_ZONES_SUP)
5577 softc->zone_flags |=
5578 DA_ZONE_FLAG_RZ_SUP;
5579 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5580 softc->zone_flags |=
5581 DA_ZONE_FLAG_OPEN_SUP;
5582 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5583 softc->zone_flags |=
5584 DA_ZONE_FLAG_CLOSE_SUP;
5585 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5586 softc->zone_flags |=
5587 DA_ZONE_FLAG_FINISH_SUP;
5588 if (zac_cap & ATA_ND_RWP_SUP)
5589 softc->zone_flags |=
5590 DA_ZONE_FLAG_RWP_SUP;
5593 * This field was introduced in
5594 * ACS-4, r08 on April 28th, 2015.
5595 * If the drive firmware was written
5596 * to an earlier spec, it won't have
5597 * the field. So, assume all
5598 * commands are supported.
5600 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5604 error = daerror(done_ccb, CAM_RETRY_SELTO,
5605 SF_RETRY_UA|SF_NO_PRINT);
5606 if (error == ERESTART)
5608 else if (error != 0) {
5610 * If we can't get the ATA Identify Data
5611 * Supported Capabilities page, clear the
5614 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5616 * And clear zone capabilities.
5618 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5619 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5620 /* Don't wedge this device's queue */
5621 cam_release_devq(done_ccb->ccb_h.path,
5625 /*getcount_only*/0);
5630 free(csio->data_ptr, M_SCSIDA);
5632 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5633 softc->state = DA_STATE_PROBE_ATA_ZONE;
5634 xpt_release_ccb(done_ccb);
5635 xpt_schedule(periph, priority);
5638 daprobedone(periph, done_ccb);
5643 dadone_probeatazone(struct cam_periph *periph, union ccb *done_ccb)
5645 struct da_softc *softc;
5646 struct ccb_scsiio *csio;
5649 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatazone\n"));
5651 softc = (struct da_softc *)periph->softc;
5652 csio = &done_ccb->csio;
5654 cam_periph_assert(periph, MA_OWNED);
5656 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5657 struct ata_zoned_info_log *zi_log;
5661 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5663 valid_len = csio->dxfer_len - csio->resid;
5664 needed_size = __offsetof(struct ata_zoned_info_log,
5665 version_info) + 1 + sizeof(zi_log->version_info);
5666 if (valid_len >= needed_size) {
5669 tmpvar = le64dec(zi_log->zoned_cap);
5670 if (tmpvar & ATA_ZDI_CAP_VALID) {
5671 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5672 softc->zone_flags |=
5673 DA_ZONE_FLAG_URSWRZ;
5675 softc->zone_flags &=
5676 ~DA_ZONE_FLAG_URSWRZ;
5678 tmpvar = le64dec(zi_log->optimal_seq_zones);
5679 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5680 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5681 softc->optimal_seq_zones = (tmpvar &
5682 ATA_ZDI_OPT_SEQ_MASK);
5684 softc->zone_flags &= ~DA_ZONE_FLAG_OPT_SEQ_SET;
5685 softc->optimal_seq_zones = 0;
5688 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5689 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5690 softc->zone_flags |=
5691 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5692 softc->optimal_nonseq_zones =
5693 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5695 softc->zone_flags &=
5696 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5697 softc->optimal_nonseq_zones = 0;
5700 tmpvar = le64dec(zi_log->max_seq_req_zones);
5701 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5702 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5703 softc->max_seq_zones =
5704 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5706 softc->zone_flags &= ~DA_ZONE_FLAG_MAX_SEQ_SET;
5707 softc->max_seq_zones = 0;
5711 error = daerror(done_ccb, CAM_RETRY_SELTO,
5712 SF_RETRY_UA|SF_NO_PRINT);
5713 if (error == ERESTART)
5715 else if (error != 0) {
5716 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5717 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5719 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5720 /* Don't wedge this device's queue */
5721 cam_release_devq(done_ccb->ccb_h.path,
5725 /*getcount_only*/0);
5731 free(csio->data_ptr, M_SCSIDA);
5733 daprobedone(periph, done_ccb);
5738 dadone_probezone(struct cam_periph *periph, union ccb *done_ccb)
5740 struct da_softc *softc;
5741 struct ccb_scsiio *csio;
5744 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probezone\n"));
5746 softc = (struct da_softc *)periph->softc;
5747 csio = &done_ccb->csio;
5749 cam_periph_assert(periph, MA_OWNED);
5751 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5754 struct scsi_vpd_zoned_bdc *zoned_bdc;
5757 zoned_bdc = (struct scsi_vpd_zoned_bdc *)csio->data_ptr;
5758 valid_len = csio->dxfer_len - csio->resid;
5759 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5760 max_seq_req_zones) + 1 +
5761 sizeof(zoned_bdc->max_seq_req_zones);
5762 if ((valid_len >= needed_len)
5763 && (scsi_2btoul(zoned_bdc->page_length) >= SVPD_ZBDC_PL)) {
5764 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5765 softc->zone_flags |= DA_ZONE_FLAG_URSWRZ;
5767 softc->zone_flags &= ~DA_ZONE_FLAG_URSWRZ;
5768 softc->optimal_seq_zones =
5769 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5770 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5771 softc->optimal_nonseq_zones = scsi_4btoul(
5772 zoned_bdc->optimal_nonseq_zones);
5773 softc->zone_flags |= DA_ZONE_FLAG_OPT_NONSEQ_SET;
5774 softc->max_seq_zones =
5775 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5776 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5779 * All of the zone commands are mandatory for SCSI
5782 * XXX KDM this is valid as of September 2015.
5783 * Re-check this assumption once the SAT spec is
5784 * updated to support SCSI ZBC to ATA ZAC mapping.
5785 * Since ATA allows zone commands to be reported
5786 * as supported or not, this may not necessarily
5787 * be true for an ATA device behind a SAT (SCSI to
5788 * ATA Translation) layer.
5790 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5792 error = daerror(done_ccb, CAM_RETRY_SELTO,
5793 SF_RETRY_UA|SF_NO_PRINT);
5794 if (error == ERESTART)
5796 else if (error != 0) {
5797 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5798 /* Don't wedge this device's queue */
5799 cam_release_devq(done_ccb->ccb_h.path,
5803 /*getcount_only*/0);
5808 free(csio->data_ptr, M_SCSIDA);
5810 daprobedone(periph, done_ccb);
5815 dadone_tur(struct cam_periph *periph, union ccb *done_ccb)
5817 struct da_softc *softc;
5818 struct ccb_scsiio *csio;
5820 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_tur\n"));
5822 softc = (struct da_softc *)periph->softc;
5823 csio = &done_ccb->csio;
5825 cam_periph_assert(periph, MA_OWNED);
5827 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5829 if (daerror(done_ccb, CAM_RETRY_SELTO,
5830 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) == ERESTART)
5831 return; /* Will complete again, keep reference */
5832 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5833 cam_release_devq(done_ccb->ccb_h.path,
5837 /*getcount_only*/0);
5839 softc->flags &= ~DA_FLAG_TUR_PENDING;
5840 xpt_release_ccb(done_ccb);
5841 da_periph_release_locked(periph, DA_REF_TUR);
5846 dareprobe(struct cam_periph *periph)
5848 struct da_softc *softc;
5851 softc = (struct da_softc *)periph->softc;
5853 cam_periph_assert(periph, MA_OWNED);
5855 /* Probe in progress; don't interfere. */
5856 if (softc->state != DA_STATE_NORMAL)
5859 status = da_periph_acquire(periph, DA_REF_REPROBE);
5860 KASSERT(status == 0, ("dareprobe: cam_periph_acquire failed"));
5862 softc->state = DA_STATE_PROBE_WP;
5863 xpt_schedule(periph, CAM_PRIORITY_DEV);
5867 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5869 struct da_softc *softc;
5870 struct cam_periph *periph;
5871 int error, error_code, sense_key, asc, ascq;
5873 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5874 if (ccb->csio.bio != NULL)
5875 biotrack(ccb->csio.bio, __func__);
5878 periph = xpt_path_periph(ccb->ccb_h.path);
5879 softc = (struct da_softc *)periph->softc;
5881 cam_periph_assert(periph, MA_OWNED);
5884 * Automatically detect devices that do not support
5885 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5888 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5889 error = cmd6workaround(ccb);
5890 } else if (scsi_extract_sense_ccb(ccb,
5891 &error_code, &sense_key, &asc, &ascq)) {
5892 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5893 error = cmd6workaround(ccb);
5895 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5896 * query the capacity and notify upper layers.
5898 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5899 asc == 0x2A && ascq == 0x09) {
5900 xpt_print(periph->path, "Capacity data has changed\n");
5901 softc->flags &= ~DA_FLAG_PROBED;
5903 sense_flags |= SF_NO_PRINT;
5904 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5905 asc == 0x28 && ascq == 0x00) {
5906 softc->flags &= ~DA_FLAG_PROBED;
5907 disk_media_changed(softc->disk, M_NOWAIT);
5908 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5909 asc == 0x3F && ascq == 0x03) {
5910 xpt_print(periph->path, "INQUIRY data has changed\n");
5911 softc->flags &= ~DA_FLAG_PROBED;
5913 sense_flags |= SF_NO_PRINT;
5914 } else if (sense_key == SSD_KEY_NOT_READY &&
5915 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5916 softc->flags |= DA_FLAG_PACK_INVALID;
5917 disk_media_gone(softc->disk, M_NOWAIT);
5920 if (error == ERESTART)
5924 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5925 case CAM_CMD_TIMEOUT:
5928 case CAM_REQ_ABORTED:
5929 case CAM_REQ_CMP_ERR:
5930 case CAM_REQ_TERMIO:
5931 case CAM_UNREC_HBA_ERROR:
5932 case CAM_DATA_RUN_ERR:
5942 * Until we have a better way of doing pack validation,
5943 * don't treat UAs as errors.
5945 sense_flags |= SF_RETRY_UA;
5947 if (softc->quirks & DA_Q_RETRY_BUSY)
5948 sense_flags |= SF_RETRY_BUSY;
5949 return(cam_periph_error(ccb, cam_flags, sense_flags));
5953 damediapoll(void *arg)
5955 struct cam_periph *periph = arg;
5956 struct da_softc *softc = periph->softc;
5958 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5959 (softc->flags & DA_FLAG_TUR_PENDING) == 0 &&
5960 softc->state == DA_STATE_NORMAL &&
5961 LIST_EMPTY(&softc->pending_ccbs)) {
5962 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
5963 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5967 /* Queue us up again */
5968 if (da_poll_period != 0)
5969 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5973 daprevent(struct cam_periph *periph, int action)
5975 struct da_softc *softc;
5979 cam_periph_assert(periph, MA_OWNED);
5980 softc = (struct da_softc *)periph->softc;
5982 if (((action == PR_ALLOW)
5983 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5984 || ((action == PR_PREVENT)
5985 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5989 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5991 scsi_prevent(&ccb->csio,
5999 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
6000 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
6003 if (action == PR_ALLOW)
6004 softc->flags &= ~DA_FLAG_PACK_LOCKED;
6006 softc->flags |= DA_FLAG_PACK_LOCKED;
6009 xpt_release_ccb(ccb);
6013 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
6014 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
6016 struct ccb_calc_geometry ccg;
6017 struct da_softc *softc;
6018 struct disk_params *dp;
6019 u_int lbppbe, lalba;
6022 softc = (struct da_softc *)periph->softc;
6024 dp = &softc->params;
6025 dp->secsize = block_len;
6026 dp->sectors = maxsector + 1;
6027 if (rcaplong != NULL) {
6028 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
6029 lalba = scsi_2btoul(rcaplong->lalba_lbp);
6030 lalba &= SRC16_LALBA_A;
6031 if (rcaplong->prot & SRC16_PROT_EN)
6032 softc->p_type = ((rcaplong->prot & SRC16_P_TYPE) >>
6033 SRC16_P_TYPE_SHIFT) + 1;
6043 dp->stripesize = block_len << lbppbe;
6044 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
6046 } else if (softc->quirks & DA_Q_4K) {
6047 dp->stripesize = 4096;
6048 dp->stripeoffset = 0;
6049 } else if (softc->unmap_gran != 0) {
6050 dp->stripesize = block_len * softc->unmap_gran;
6051 dp->stripeoffset = (dp->stripesize - block_len *
6052 softc->unmap_gran_align) % dp->stripesize;
6055 dp->stripeoffset = 0;
6058 * Have the controller provide us with a geometry
6059 * for this disk. The only time the geometry
6060 * matters is when we boot and the controller
6061 * is the only one knowledgeable enough to come
6062 * up with something that will make this a bootable
6065 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6066 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
6067 ccg.block_size = dp->secsize;
6068 ccg.volume_size = dp->sectors;
6070 ccg.secs_per_track = 0;
6072 xpt_action((union ccb*)&ccg);
6073 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
6075 * We don't know what went wrong here- but just pick
6076 * a geometry so we don't have nasty things like divide
6080 dp->secs_per_track = 255;
6081 dp->cylinders = dp->sectors / (255 * 255);
6082 if (dp->cylinders == 0) {
6086 dp->heads = ccg.heads;
6087 dp->secs_per_track = ccg.secs_per_track;
6088 dp->cylinders = ccg.cylinders;
6092 * If the user supplied a read capacity buffer, and if it is
6093 * different than the previous buffer, update the data in the EDT.
6094 * If it's the same, we don't bother. This avoids sending an
6095 * update every time someone opens this device.
6097 if ((rcaplong != NULL)
6098 && (bcmp(rcaplong, &softc->rcaplong,
6099 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
6100 struct ccb_dev_advinfo cdai;
6102 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6103 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
6104 cdai.buftype = CDAI_TYPE_RCAPLONG;
6105 cdai.flags = CDAI_FLAG_STORE;
6106 cdai.bufsiz = rcap_len;
6107 cdai.buf = (uint8_t *)rcaplong;
6108 xpt_action((union ccb *)&cdai);
6109 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
6110 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
6111 if (cdai.ccb_h.status != CAM_REQ_CMP) {
6112 xpt_print(periph->path, "%s: failed to set read "
6113 "capacity advinfo\n", __func__);
6114 /* Use cam_error_print() to decode the status */
6115 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
6118 bcopy(rcaplong, &softc->rcaplong,
6119 min(sizeof(softc->rcaplong), rcap_len));
6123 softc->disk->d_sectorsize = softc->params.secsize;
6124 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
6125 softc->disk->d_stripesize = softc->params.stripesize;
6126 softc->disk->d_stripeoffset = softc->params.stripeoffset;
6127 /* XXX: these are not actually "firmware" values, so they may be wrong */
6128 softc->disk->d_fwsectors = softc->params.secs_per_track;
6129 softc->disk->d_fwheads = softc->params.heads;
6130 softc->disk->d_devstat->block_size = softc->params.secsize;
6131 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
6133 error = disk_resize(softc->disk, M_NOWAIT);
6135 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
6139 dasendorderedtag(void *arg)
6141 struct cam_periph *periph = arg;
6142 struct da_softc *softc = periph->softc;
6144 cam_periph_assert(periph, MA_OWNED);
6145 if (da_send_ordered) {
6146 if (!LIST_EMPTY(&softc->pending_ccbs)) {
6147 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
6148 softc->flags |= DA_FLAG_NEED_OTAG;
6149 softc->flags &= ~DA_FLAG_WAS_OTAG;
6153 /* Queue us up again */
6154 callout_reset(&softc->sendordered_c,
6155 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
6156 dasendorderedtag, periph);
6160 * Step through all DA peripheral drivers, and if the device is still open,
6161 * sync the disk cache to physical media.
6164 dashutdown(void * arg, int howto)
6166 struct cam_periph *periph;
6167 struct da_softc *softc;
6171 CAM_PERIPH_FOREACH(periph, &dadriver) {
6172 softc = (struct da_softc *)periph->softc;
6173 if (SCHEDULER_STOPPED()) {
6174 /* If we paniced with the lock held, do not recurse. */
6175 if (!cam_periph_owned(periph) &&
6176 (softc->flags & DA_FLAG_OPEN)) {
6177 dadump(softc->disk, NULL, 0, 0, 0);
6181 cam_periph_lock(periph);
6184 * We only sync the cache if the drive is still open, and
6185 * if the drive is capable of it..
6187 if (((softc->flags & DA_FLAG_OPEN) == 0)
6188 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
6189 cam_periph_unlock(periph);
6193 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
6194 scsi_synchronize_cache(&ccb->csio,
6198 /*begin_lba*/0, /* whole disk */
6203 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
6204 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
6205 softc->disk->d_devstat);
6207 xpt_print(periph->path, "Synchronize cache failed\n");
6208 xpt_release_ccb(ccb);
6209 cam_periph_unlock(periph);
6213 #else /* !_KERNEL */
6216 * XXX These are only left out of the kernel build to silence warnings. If,
6217 * for some reason these functions are used in the kernel, the ifdefs should
6218 * be moved so they are included both in the kernel and userland.
6221 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
6222 void (*cbfcnp)(struct cam_periph *, union ccb *),
6223 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
6224 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6227 struct scsi_format_unit *scsi_cmd;
6229 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
6230 scsi_cmd->opcode = FORMAT_UNIT;
6231 scsi_cmd->byte2 = byte2;
6232 scsi_ulto2b(ileave, scsi_cmd->interleave);
6237 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6247 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
6248 void (*cbfcnp)(struct cam_periph *, union ccb *),
6249 uint8_t tag_action, uint8_t list_format,
6250 uint32_t addr_desc_index, uint8_t *data_ptr,
6251 uint32_t dxfer_len, int minimum_cmd_size,
6252 uint8_t sense_len, uint32_t timeout)
6257 * These conditions allow using the 10 byte command. Otherwise we
6258 * need to use the 12 byte command.
6260 if ((minimum_cmd_size <= 10)
6261 && (addr_desc_index == 0)
6262 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
6263 struct scsi_read_defect_data_10 *cdb10;
6265 cdb10 = (struct scsi_read_defect_data_10 *)
6266 &csio->cdb_io.cdb_bytes;
6268 cdb_len = sizeof(*cdb10);
6269 bzero(cdb10, cdb_len);
6270 cdb10->opcode = READ_DEFECT_DATA_10;
6271 cdb10->format = list_format;
6272 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
6274 struct scsi_read_defect_data_12 *cdb12;
6276 cdb12 = (struct scsi_read_defect_data_12 *)
6277 &csio->cdb_io.cdb_bytes;
6279 cdb_len = sizeof(*cdb12);
6280 bzero(cdb12, cdb_len);
6281 cdb12->opcode = READ_DEFECT_DATA_12;
6282 cdb12->format = list_format;
6283 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
6284 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
6290 /*flags*/ CAM_DIR_IN,
6300 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
6301 void (*cbfcnp)(struct cam_periph *, union ccb *),
6302 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
6303 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6306 struct scsi_sanitize *scsi_cmd;
6308 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
6309 scsi_cmd->opcode = SANITIZE;
6310 scsi_cmd->byte2 = byte2;
6311 scsi_cmd->control = control;
6312 scsi_ulto2b(dxfer_len, scsi_cmd->length);
6317 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6326 #endif /* _KERNEL */
6329 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
6330 void (*cbfcnp)(struct cam_periph *, union ccb *),
6331 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
6332 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
6333 uint8_t sense_len, uint32_t timeout)
6335 struct scsi_zbc_out *scsi_cmd;
6337 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
6338 scsi_cmd->opcode = ZBC_OUT;
6339 scsi_cmd->service_action = service_action;
6340 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
6341 scsi_cmd->zone_flags = zone_flags;
6346 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6356 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
6357 void (*cbfcnp)(struct cam_periph *, union ccb *),
6358 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
6359 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
6360 uint8_t sense_len, uint32_t timeout)
6362 struct scsi_zbc_in *scsi_cmd;
6364 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
6365 scsi_cmd->opcode = ZBC_IN;
6366 scsi_cmd->service_action = service_action;
6367 scsi_ulto4b(dxfer_len, scsi_cmd->length);
6368 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
6369 scsi_cmd->zone_options = zone_options;
6374 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
6385 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
6386 void (*cbfcnp)(struct cam_periph *, union ccb *),
6387 uint8_t tag_action, int use_ncq,
6388 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6389 uint8_t *data_ptr, uint32_t dxfer_len,
6390 uint8_t *cdb_storage, size_t cdb_storage_len,
6391 uint8_t sense_len, uint32_t timeout)
6393 uint8_t command_out, protocol, ata_flags;
6394 uint16_t features_out;
6395 uint32_t sectors_out, auxiliary;
6401 command_out = ATA_ZAC_MANAGEMENT_OUT;
6402 features_out = (zm_action & 0xf) | (zone_flags << 8);
6403 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6404 if (dxfer_len == 0) {
6405 protocol = AP_PROTO_NON_DATA;
6406 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6409 protocol = AP_PROTO_DMA;
6410 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
6411 AP_FLAG_TDIR_TO_DEV;
6412 sectors_out = ((dxfer_len >> 9) & 0xffff);
6416 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6417 if (dxfer_len == 0) {
6418 command_out = ATA_NCQ_NON_DATA;
6419 features_out = ATA_NCQ_ZAC_MGMT_OUT;
6421 * We're assuming the SCSI to ATA translation layer
6422 * will set the NCQ tag number in the tag field.
6423 * That isn't clear from the SAT-4 spec (as of rev 05).
6426 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6428 command_out = ATA_SEND_FPDMA_QUEUED;
6430 * Note that we're defaulting to normal priority,
6431 * and assuming that the SCSI to ATA translation
6432 * layer will insert the NCQ tag number in the tag
6433 * field. That isn't clear in the SAT-4 spec (as
6436 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
6438 ata_flags |= AP_FLAG_TLEN_FEAT |
6439 AP_FLAG_TDIR_TO_DEV;
6442 * For SEND FPDMA QUEUED, the transfer length is
6443 * encoded in the FEATURE register, and 0 means
6444 * that 65536 512 byte blocks are to be tranferred.
6445 * In practice, it seems unlikely that we'll see
6446 * a transfer that large, and it may confuse the
6447 * the SAT layer, because generally that means that
6448 * 0 bytes should be transferred.
6450 if (dxfer_len == (65536 * 512)) {
6452 } else if (dxfer_len <= (65535 * 512)) {
6453 features_out = ((dxfer_len >> 9) & 0xffff);
6455 /* The transfer is too big. */
6462 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
6463 protocol = AP_PROTO_FPDMA;
6466 protocol |= AP_EXTEND;
6468 retval = scsi_ata_pass(csio,
6471 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6473 /*protocol*/ protocol,
6474 /*ata_flags*/ ata_flags,
6475 /*features*/ features_out,
6476 /*sector_count*/ sectors_out,
6478 /*command*/ command_out,
6481 /*auxiliary*/ auxiliary,
6483 /*data_ptr*/ data_ptr,
6484 /*dxfer_len*/ dxfer_len,
6485 /*cdb_storage*/ cdb_storage,
6486 /*cdb_storage_len*/ cdb_storage_len,
6487 /*minimum_cmd_size*/ 0,
6488 /*sense_len*/ SSD_FULL_SIZE,
6489 /*timeout*/ timeout);
6497 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
6498 void (*cbfcnp)(struct cam_periph *, union ccb *),
6499 uint8_t tag_action, int use_ncq,
6500 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6501 uint8_t *data_ptr, uint32_t dxfer_len,
6502 uint8_t *cdb_storage, size_t cdb_storage_len,
6503 uint8_t sense_len, uint32_t timeout)
6505 uint8_t command_out, protocol;
6506 uint16_t features_out, sectors_out;
6512 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
6515 command_out = ATA_ZAC_MANAGEMENT_IN;
6516 /* XXX KDM put a macro here */
6517 features_out = (zm_action & 0xf) | (zone_flags << 8);
6518 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
6519 protocol = AP_PROTO_DMA;
6520 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
6523 ata_flags |= AP_FLAG_TLEN_FEAT;
6525 command_out = ATA_RECV_FPDMA_QUEUED;
6526 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6529 * For RECEIVE FPDMA QUEUED, the transfer length is
6530 * encoded in the FEATURE register, and 0 means
6531 * that 65536 512 byte blocks are to be tranferred.
6532 * In practice, it seems unlikely that we'll see
6533 * a transfer that large, and it may confuse the
6534 * the SAT layer, because generally that means that
6535 * 0 bytes should be transferred.
6537 if (dxfer_len == (65536 * 512)) {
6539 } else if (dxfer_len <= (65535 * 512)) {
6540 features_out = ((dxfer_len >> 9) & 0xffff);
6542 /* The transfer is too big. */
6546 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6547 protocol = AP_PROTO_FPDMA;
6550 protocol |= AP_EXTEND;
6552 retval = scsi_ata_pass(csio,
6555 /*flags*/ CAM_DIR_IN,
6557 /*protocol*/ protocol,
6558 /*ata_flags*/ ata_flags,
6559 /*features*/ features_out,
6560 /*sector_count*/ sectors_out,
6562 /*command*/ command_out,
6565 /*auxiliary*/ auxiliary,
6567 /*data_ptr*/ data_ptr,
6568 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6569 /*cdb_storage*/ cdb_storage,
6570 /*cdb_storage_len*/ cdb_storage_len,
6571 /*minimum_cmd_size*/ 0,
6572 /*sense_len*/ SSD_FULL_SIZE,
6573 /*timeout*/ timeout);