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 timeout_t dasendorderedtag;
1496 static void dashutdown(void *arg, int howto);
1497 static timeout_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 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1520 static int da_retry_count = DA_DEFAULT_RETRY;
1521 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1522 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1523 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1524 static int da_disable_wp_detection = 0;
1526 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1527 "CAM Direct Access Disk driver");
1528 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1529 &da_poll_period, 0, "Media polling period in seconds");
1530 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1531 &da_retry_count, 0, "Normal I/O retry count");
1532 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1533 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1534 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1535 &da_send_ordered, 0, "Send Ordered Tags");
1536 SYSCTL_INT(_kern_cam_da, OID_AUTO, disable_wp_detection, CTLFLAG_RWTUN,
1537 &da_disable_wp_detection, 0,
1538 "Disable detection of write-protected disks");
1540 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1541 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1542 "Soft I/O timeout (ms)");
1543 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1546 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1547 * to the default timeout, we check to see whether an ordered
1548 * tagged transaction is appropriate to prevent simple tag
1549 * starvation. Since we'd like to ensure that there is at least
1550 * 1/2 of the timeout length left for a starved transaction to
1551 * complete after we've sent an ordered tag, we must poll at least
1552 * four times in every timeout period. This takes care of the worst
1553 * case where a starved transaction starts during an interval that
1554 * meets the requirement "don't send an ordered tag" test so it takes
1555 * us two intervals to determine that a tag must be sent.
1557 #ifndef DA_ORDEREDTAG_INTERVAL
1558 #define DA_ORDEREDTAG_INTERVAL 4
1561 static struct periph_driver dadriver =
1564 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1567 PERIPHDRIVER_DECLARE(da, dadriver);
1569 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1572 * This driver takes out references / holds in well defined pairs, never
1573 * recursively. These macros / inline functions enforce those rules. They
1574 * are only enabled with DA_TRACK_REFS or INVARIANTS. If DA_TRACK_REFS is
1575 * defined to be 2 or larger, the tracking also includes debug printfs.
1577 #if defined(DA_TRACK_REFS) || defined(INVARIANTS)
1579 #ifndef DA_TRACK_REFS
1580 #define DA_TRACK_REFS 1
1583 #if DA_TRACK_REFS > 1
1584 static const char *da_ref_text[] = {
1597 #define DA_PERIPH_PRINT(periph, msg, args...) \
1598 CAM_PERIPH_PRINT(periph, msg, ##args)
1600 #define DA_PERIPH_PRINT(periph, msg, args...)
1604 token_sanity(da_ref_token token)
1606 if ((unsigned)token >= DA_REF_MAX)
1607 panic("Bad token value passed in %d\n", token);
1611 da_periph_hold(struct cam_periph *periph, int priority, da_ref_token token)
1613 int err = cam_periph_hold(periph, priority);
1615 token_sanity(token);
1616 DA_PERIPH_PRINT(periph, "Holding device %s (%d): %d\n",
1617 da_ref_text[token], token, err);
1620 struct da_softc *softc = periph->softc;
1622 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1624 panic("Re-holding for reason %d, cnt = %d", token, cnt);
1630 da_periph_unhold(struct cam_periph *periph, da_ref_token token)
1633 struct da_softc *softc = periph->softc;
1635 token_sanity(token);
1636 DA_PERIPH_PRINT(periph, "Unholding device %s (%d)\n",
1637 da_ref_text[token], token);
1638 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1640 panic("Unholding %d with cnt = %d", token, cnt);
1641 cam_periph_unhold(periph);
1645 da_periph_acquire(struct cam_periph *periph, da_ref_token token)
1647 int err = cam_periph_acquire(periph);
1649 token_sanity(token);
1650 DA_PERIPH_PRINT(periph, "acquiring device %s (%d): %d\n",
1651 da_ref_text[token], token, err);
1654 struct da_softc *softc = periph->softc;
1656 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1658 panic("Re-refing for reason %d, cnt = %d", token, cnt);
1664 da_periph_release(struct cam_periph *periph, da_ref_token token)
1667 struct da_softc *softc = periph->softc;
1669 token_sanity(token);
1670 DA_PERIPH_PRINT(periph, "releasing device %s (%d)\n",
1671 da_ref_text[token], token);
1672 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1674 panic("Releasing %d with cnt = %d", token, cnt);
1675 cam_periph_release(periph);
1679 da_periph_release_locked(struct cam_periph *periph, da_ref_token token)
1682 struct da_softc *softc = periph->softc;
1684 token_sanity(token);
1685 DA_PERIPH_PRINT(periph, "releasing device (locked) %s (%d)\n",
1686 da_ref_text[token], token);
1687 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1689 panic("Unholding %d with cnt = %d", token, cnt);
1690 cam_periph_release_locked(periph);
1693 #define cam_periph_hold POISON
1694 #define cam_periph_unhold POISON
1695 #define cam_periph_acquire POISON
1696 #define cam_periph_release POISON
1697 #define cam_periph_release_locked POISON
1700 #define da_periph_hold(periph, prio, token) cam_periph_hold((periph), (prio))
1701 #define da_periph_unhold(periph, token) cam_periph_unhold((periph))
1702 #define da_periph_acquire(periph, token) cam_periph_acquire((periph))
1703 #define da_periph_release(periph, token) cam_periph_release((periph))
1704 #define da_periph_release_locked(periph, token) cam_periph_release_locked((periph))
1708 daopen(struct disk *dp)
1710 struct cam_periph *periph;
1711 struct da_softc *softc;
1714 periph = (struct cam_periph *)dp->d_drv1;
1715 if (da_periph_acquire(periph, DA_REF_OPEN) != 0) {
1719 cam_periph_lock(periph);
1720 if ((error = da_periph_hold(periph, PRIBIO|PCATCH, DA_REF_OPEN_HOLD)) != 0) {
1721 cam_periph_unlock(periph);
1722 da_periph_release(periph, DA_REF_OPEN);
1726 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1729 softc = (struct da_softc *)periph->softc;
1732 /* Wait for the disk size update. */
1733 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1736 xpt_print(periph->path, "unable to retrieve capacity data\n");
1738 if (periph->flags & CAM_PERIPH_INVALID)
1741 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1742 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1743 daprevent(periph, PR_PREVENT);
1746 softc->flags &= ~DA_FLAG_PACK_INVALID;
1747 softc->flags |= DA_FLAG_OPEN;
1750 da_periph_unhold(periph, DA_REF_OPEN_HOLD);
1751 cam_periph_unlock(periph);
1754 da_periph_release(periph, DA_REF_OPEN);
1760 daclose(struct disk *dp)
1762 struct cam_periph *periph;
1763 struct da_softc *softc;
1766 periph = (struct cam_periph *)dp->d_drv1;
1767 softc = (struct da_softc *)periph->softc;
1768 cam_periph_lock(periph);
1769 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1772 if (da_periph_hold(periph, PRIBIO, DA_REF_CLOSE_HOLD) == 0) {
1774 /* Flush disk cache. */
1775 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1776 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1777 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1778 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1779 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1780 /*cbfcnp*/NULL, MSG_SIMPLE_Q_TAG,
1781 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1783 cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1784 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1785 softc->disk->d_devstat);
1786 softc->flags &= ~DA_FLAG_DIRTY;
1787 xpt_release_ccb(ccb);
1790 /* Allow medium removal. */
1791 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1792 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1793 daprevent(periph, PR_ALLOW);
1795 da_periph_unhold(periph, DA_REF_CLOSE_HOLD);
1799 * If we've got removeable media, mark the blocksize as
1800 * unavailable, since it could change when new media is
1803 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1804 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1806 softc->flags &= ~DA_FLAG_OPEN;
1807 while (softc->refcount != 0)
1808 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1809 cam_periph_unlock(periph);
1810 da_periph_release(periph, DA_REF_OPEN);
1815 daschedule(struct cam_periph *periph)
1817 struct da_softc *softc = (struct da_softc *)periph->softc;
1819 if (softc->state != DA_STATE_NORMAL)
1822 cam_iosched_schedule(softc->cam_iosched, periph);
1826 * Actually translate the requested transfer into one the physical driver
1827 * can understand. The transfer is described by a buf and will include
1828 * only one physical transfer.
1831 dastrategy(struct bio *bp)
1833 struct cam_periph *periph;
1834 struct da_softc *softc;
1836 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1837 softc = (struct da_softc *)periph->softc;
1839 cam_periph_lock(periph);
1842 * If the device has been made invalid, error out
1844 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1845 cam_periph_unlock(periph);
1846 biofinish(bp, NULL, ENXIO);
1850 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1853 * Zone commands must be ordered, because they can depend on the
1854 * effects of previously issued commands, and they may affect
1855 * commands after them.
1857 if (bp->bio_cmd == BIO_ZONE)
1858 bp->bio_flags |= BIO_ORDERED;
1861 * Place it in the queue of disk activities for this disk
1863 cam_iosched_queue_work(softc->cam_iosched, bp);
1866 * Schedule ourselves for performing the work.
1869 cam_periph_unlock(periph);
1875 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1877 struct cam_periph *periph;
1878 struct da_softc *softc;
1880 struct ccb_scsiio csio;
1885 periph = dp->d_drv1;
1886 softc = (struct da_softc *)periph->softc;
1887 secsize = softc->params.secsize;
1889 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0)
1892 memset(&csio, 0, sizeof(csio));
1894 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1895 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1896 scsi_read_write(&csio,
1900 /*read*/SCSI_RW_WRITE,
1902 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1905 /*data_ptr*/(u_int8_t *) virtual,
1906 /*dxfer_len*/length,
1907 /*sense_len*/SSD_FULL_SIZE,
1908 da_default_timeout * 1000);
1909 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1910 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1912 printf("Aborting dump due to I/O error.\n");
1917 * Sync the disk cache contents to the physical media.
1919 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1921 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1922 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1923 scsi_synchronize_cache(&csio,
1927 /*begin_lba*/0,/* Cover the whole disk */
1931 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1932 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1934 xpt_print(periph->path, "Synchronize cache failed\n");
1940 dagetattr(struct bio *bp)
1943 struct cam_periph *periph;
1945 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1946 cam_periph_lock(periph);
1947 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1949 cam_periph_unlock(periph);
1951 bp->bio_completed = bp->bio_length;
1961 * Install a global async callback. This callback will
1962 * receive async callbacks like "new device found".
1964 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1966 if (status != CAM_REQ_CMP) {
1967 printf("da: Failed to attach master async callback "
1968 "due to status 0x%x!\n", status);
1969 } else if (da_send_ordered) {
1971 /* Register our shutdown event handler */
1972 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1973 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1974 printf("dainit: shutdown event registration failed!\n");
1979 * Callback from GEOM, called when it has finished cleaning up its
1983 dadiskgonecb(struct disk *dp)
1985 struct cam_periph *periph;
1987 periph = (struct cam_periph *)dp->d_drv1;
1988 da_periph_release(periph, DA_REF_GEOM);
1992 daoninvalidate(struct cam_periph *periph)
1994 struct da_softc *softc;
1996 cam_periph_assert(periph, MA_OWNED);
1997 softc = (struct da_softc *)periph->softc;
2000 * De-register any async callbacks.
2002 xpt_register_async(0, daasync, periph, periph->path);
2004 softc->flags |= DA_FLAG_PACK_INVALID;
2006 softc->invalidations++;
2010 * Return all queued I/O with ENXIO.
2011 * XXX Handle any transactions queued to the card
2012 * with XPT_ABORT_CCB.
2014 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
2017 * Tell GEOM that we've gone away, we'll get a callback when it is
2018 * done cleaning up its resources.
2020 disk_gone(softc->disk);
2024 dacleanup(struct cam_periph *periph)
2026 struct da_softc *softc;
2028 softc = (struct da_softc *)periph->softc;
2030 cam_periph_unlock(periph);
2032 cam_iosched_fini(softc->cam_iosched);
2035 * If we can't free the sysctl tree, oh well...
2037 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
2039 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
2040 xpt_print(periph->path,
2041 "can't remove sysctl stats context\n");
2043 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
2044 xpt_print(periph->path,
2045 "can't remove sysctl context\n");
2048 callout_drain(&softc->mediapoll_c);
2049 disk_destroy(softc->disk);
2050 callout_drain(&softc->sendordered_c);
2051 free(softc, M_DEVBUF);
2052 cam_periph_lock(periph);
2056 daasync(void *callback_arg, u_int32_t code,
2057 struct cam_path *path, void *arg)
2059 struct cam_periph *periph;
2060 struct da_softc *softc;
2062 periph = (struct cam_periph *)callback_arg;
2064 case AC_FOUND_DEVICE: /* callback to create periph, no locking yet */
2066 struct ccb_getdev *cgd;
2069 cgd = (struct ccb_getdev *)arg;
2073 if (cgd->protocol != PROTO_SCSI)
2075 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
2077 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
2078 && SID_TYPE(&cgd->inq_data) != T_RBC
2079 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
2080 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
2084 * Allocate a peripheral instance for
2085 * this device and start the probe
2088 status = cam_periph_alloc(daregister, daoninvalidate,
2090 "da", CAM_PERIPH_BIO,
2092 AC_FOUND_DEVICE, cgd);
2094 if (status != CAM_REQ_CMP
2095 && status != CAM_REQ_INPROG)
2096 printf("daasync: Unable to attach to new device "
2097 "due to status 0x%x\n", status);
2100 case AC_ADVINFO_CHANGED: /* Doesn't touch periph */
2104 buftype = (uintptr_t)arg;
2105 if (buftype == CDAI_TYPE_PHYS_PATH) {
2106 struct da_softc *softc;
2108 softc = periph->softc;
2109 disk_attr_changed(softc->disk, "GEOM::physpath",
2114 case AC_UNIT_ATTENTION:
2117 int error_code, sense_key, asc, ascq;
2119 softc = (struct da_softc *)periph->softc;
2120 ccb = (union ccb *)arg;
2123 * Handle all UNIT ATTENTIONs except our own, as they will be
2124 * handled by daerror(). Since this comes from a different periph,
2125 * that periph's lock is held, not ours, so we have to take it ours
2126 * out to touch softc flags.
2128 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
2129 scsi_extract_sense_ccb(ccb,
2130 &error_code, &sense_key, &asc, &ascq)) {
2131 if (asc == 0x2A && ascq == 0x09) {
2132 xpt_print(ccb->ccb_h.path,
2133 "Capacity data has changed\n");
2134 cam_periph_lock(periph);
2135 softc->flags &= ~DA_FLAG_PROBED;
2136 cam_periph_unlock(periph);
2138 } else if (asc == 0x28 && ascq == 0x00) {
2139 cam_periph_lock(periph);
2140 softc->flags &= ~DA_FLAG_PROBED;
2141 cam_periph_unlock(periph);
2142 disk_media_changed(softc->disk, M_NOWAIT);
2143 } else if (asc == 0x3F && ascq == 0x03) {
2144 xpt_print(ccb->ccb_h.path,
2145 "INQUIRY data has changed\n");
2146 cam_periph_lock(periph);
2147 softc->flags &= ~DA_FLAG_PROBED;
2148 cam_periph_unlock(periph);
2154 case AC_SCSI_AEN: /* Called for this path: periph locked */
2156 * Appears to be currently unused for SCSI devices, only ata SIMs
2159 cam_periph_assert(periph, MA_OWNED);
2160 softc = (struct da_softc *)periph->softc;
2161 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
2162 (softc->flags & DA_FLAG_TUR_PENDING) == 0) {
2163 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
2164 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
2169 case AC_SENT_BDR: /* Called for this path: periph locked */
2170 case AC_BUS_RESET: /* Called for this path: periph locked */
2172 struct ccb_hdr *ccbh;
2174 cam_periph_assert(periph, MA_OWNED);
2175 softc = (struct da_softc *)periph->softc;
2177 * Don't fail on the expected unit attention
2180 softc->flags |= DA_FLAG_RETRY_UA;
2181 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
2182 ccbh->ccb_state |= DA_CCB_RETRY_UA;
2185 case AC_INQ_CHANGED: /* Called for this path: periph locked */
2186 cam_periph_assert(periph, MA_OWNED);
2187 softc = (struct da_softc *)periph->softc;
2188 softc->flags &= ~DA_FLAG_PROBED;
2194 cam_periph_async(periph, code, path, arg);
2198 dasysctlinit(void *context, int pending)
2200 struct cam_periph *periph;
2201 struct da_softc *softc;
2202 char tmpstr[32], tmpstr2[16];
2203 struct ccb_trans_settings cts;
2205 periph = (struct cam_periph *)context;
2207 * periph was held for us when this task was enqueued
2209 if (periph->flags & CAM_PERIPH_INVALID) {
2210 da_periph_release(periph, DA_REF_SYSCTL);
2214 softc = (struct da_softc *)periph->softc;
2215 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
2216 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
2218 sysctl_ctx_init(&softc->sysctl_ctx);
2219 cam_periph_lock(periph);
2220 softc->flags |= DA_FLAG_SCTX_INIT;
2221 cam_periph_unlock(periph);
2222 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
2223 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
2224 CTLFLAG_RD, 0, tmpstr, "device_index");
2225 if (softc->sysctl_tree == NULL) {
2226 printf("dasysctlinit: unable to allocate sysctl tree\n");
2227 da_periph_release(periph, DA_REF_SYSCTL);
2232 * Now register the sysctl handler, so the user can change the value on
2235 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2236 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
2237 softc, 0, dadeletemethodsysctl, "A",
2238 "BIO_DELETE execution method");
2239 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2240 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
2241 softc, 0, dadeletemaxsysctl, "Q",
2242 "Maximum BIO_DELETE size");
2243 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2244 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
2245 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
2246 "Minimum CDB size");
2247 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2248 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2249 "trim_count", CTLFLAG_RD, &softc->trim_count,
2250 "Total number of unmap/dsm commands sent");
2251 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2252 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2253 "trim_ranges", CTLFLAG_RD, &softc->trim_ranges,
2254 "Total number of ranges in unmap/dsm commands");
2255 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2256 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2257 "trim_lbas", CTLFLAG_RD, &softc->trim_lbas,
2258 "Total lbas in the unmap/dsm commands sent");
2260 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2261 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
2262 softc, 0, dazonemodesysctl, "A",
2264 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2265 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
2266 softc, 0, dazonesupsysctl, "A",
2268 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2269 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2270 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2271 "Optimal Number of Open Sequential Write Preferred Zones");
2272 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2273 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2274 "optimal_nonseq_zones", CTLFLAG_RD,
2275 &softc->optimal_nonseq_zones,
2276 "Optimal Number of Non-Sequentially Written Sequential Write "
2278 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2279 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2280 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2281 "Maximum Number of Open Sequential Write Required Zones");
2283 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2284 SYSCTL_CHILDREN(softc->sysctl_tree),
2288 &softc->error_inject,
2290 "error_inject leaf");
2292 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2293 SYSCTL_CHILDREN(softc->sysctl_tree),
2299 "Unmapped I/O support");
2301 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2302 SYSCTL_CHILDREN(softc->sysctl_tree),
2310 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2311 SYSCTL_CHILDREN(softc->sysctl_tree),
2317 "DIF protection type");
2319 #ifdef CAM_TEST_FAILURE
2320 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2321 OID_AUTO, "invalidate", CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE,
2322 periph, 0, cam_periph_invalidate_sysctl, "I",
2323 "Write 1 to invalidate the drive immediately");
2327 * Add some addressing info.
2329 memset(&cts, 0, sizeof (cts));
2330 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2331 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2332 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2333 cam_periph_lock(periph);
2334 xpt_action((union ccb *)&cts);
2335 cam_periph_unlock(periph);
2336 if (cts.ccb_h.status != CAM_REQ_CMP) {
2337 da_periph_release(periph, DA_REF_SYSCTL);
2340 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2341 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2342 if (fc->valid & CTS_FC_VALID_WWPN) {
2343 softc->wwpn = fc->wwpn;
2344 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2345 SYSCTL_CHILDREN(softc->sysctl_tree),
2346 OID_AUTO, "wwpn", CTLFLAG_RD,
2347 &softc->wwpn, "World Wide Port Name");
2353 * Now add some useful stats.
2354 * XXX These should live in cam_periph and be common to all periphs
2356 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2357 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2358 CTLFLAG_RD, 0, "Statistics");
2359 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2360 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2366 "Transport errors reported by the SIM");
2367 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2368 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2374 "Device timeouts reported by the SIM");
2375 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2376 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2378 "pack_invalidations",
2380 &softc->invalidations,
2382 "Device pack invalidations");
2385 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2386 softc->sysctl_tree);
2388 da_periph_release(periph, DA_REF_SYSCTL);
2392 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2396 struct da_softc *softc;
2398 softc = (struct da_softc *)arg1;
2400 value = softc->disk->d_delmaxsize;
2401 error = sysctl_handle_64(oidp, &value, 0, req);
2402 if ((error != 0) || (req->newptr == NULL))
2405 /* only accept values smaller than the calculated value */
2406 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2409 softc->disk->d_delmaxsize = value;
2415 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2419 value = *(int *)arg1;
2421 error = sysctl_handle_int(oidp, &value, 0, req);
2424 || (req->newptr == NULL))
2428 * Acceptable values here are 6, 10, 12 or 16.
2432 else if ((value > 6)
2435 else if ((value > 10)
2438 else if (value > 12)
2441 *(int *)arg1 = value;
2447 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2452 value = da_default_softtimeout / SBT_1MS;
2454 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2455 if ((error != 0) || (req->newptr == NULL))
2458 /* XXX Should clip this to a reasonable level */
2459 if (value > da_default_timeout * 1000)
2462 da_default_softtimeout = value * SBT_1MS;
2467 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2470 softc->delete_method = delete_method;
2471 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2472 softc->delete_func = da_delete_functions[delete_method];
2474 if (softc->delete_method > DA_DELETE_DISABLE)
2475 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2477 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2481 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2485 switch(delete_method) {
2486 case DA_DELETE_UNMAP:
2487 sectors = (off_t)softc->unmap_max_lba;
2489 case DA_DELETE_ATA_TRIM:
2490 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2492 case DA_DELETE_WS16:
2493 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2495 case DA_DELETE_ZERO:
2496 case DA_DELETE_WS10:
2497 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2503 return (off_t)softc->params.secsize *
2504 omin(sectors, softc->params.sectors);
2508 daprobedone(struct cam_periph *periph, union ccb *ccb)
2510 struct da_softc *softc;
2512 softc = (struct da_softc *)periph->softc;
2514 cam_periph_assert(periph, MA_OWNED);
2516 dadeletemethodchoose(softc, DA_DELETE_NONE);
2518 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2522 snprintf(buf, sizeof(buf), "Delete methods: <");
2524 for (i = 0; i <= DA_DELETE_MAX; i++) {
2525 if ((softc->delete_available & (1 << i)) == 0 &&
2526 i != softc->delete_method)
2529 strlcat(buf, ",", sizeof(buf));
2530 strlcat(buf, da_delete_method_names[i],
2532 if (i == softc->delete_method)
2533 strlcat(buf, "(*)", sizeof(buf));
2536 strlcat(buf, ">", sizeof(buf));
2537 printf("%s%d: %s\n", periph->periph_name,
2538 periph->unit_number, buf);
2540 if ((softc->disk->d_flags & DISKFLAG_WRITE_PROTECT) != 0 &&
2541 (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2542 printf("%s%d: Write Protected\n", periph->periph_name,
2543 periph->unit_number);
2547 * Since our peripheral may be invalidated by an error
2548 * above or an external event, we must release our CCB
2549 * before releasing the probe lock on the peripheral.
2550 * The peripheral will only go away once the last lock
2551 * is removed, and we need it around for the CCB release
2554 xpt_release_ccb(ccb);
2555 softc->state = DA_STATE_NORMAL;
2556 softc->flags |= DA_FLAG_PROBED;
2558 wakeup(&softc->disk->d_mediasize);
2559 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2560 softc->flags |= DA_FLAG_ANNOUNCED;
2561 da_periph_unhold(periph, DA_REF_PROBE_HOLD);
2563 da_periph_release_locked(periph, DA_REF_REPROBE);
2567 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2571 /* If available, prefer the method requested by user. */
2572 i = softc->delete_method_pref;
2573 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2574 if (methods & (1 << i)) {
2575 dadeletemethodset(softc, i);
2579 /* Use the pre-defined order to choose the best performing delete. */
2580 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2581 if (i == DA_DELETE_ZERO)
2583 if (softc->delete_available & (1 << i)) {
2584 dadeletemethodset(softc, i);
2589 /* Fallback to default. */
2590 dadeletemethodset(softc, default_method);
2594 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2598 struct da_softc *softc;
2599 int i, error, value;
2601 softc = (struct da_softc *)arg1;
2603 value = softc->delete_method;
2604 if (value < 0 || value > DA_DELETE_MAX)
2607 p = da_delete_method_names[value];
2608 strncpy(buf, p, sizeof(buf));
2609 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2610 if (error != 0 || req->newptr == NULL)
2612 for (i = 0; i <= DA_DELETE_MAX; i++) {
2613 if (strcmp(buf, da_delete_method_names[i]) == 0)
2616 if (i > DA_DELETE_MAX)
2618 softc->delete_method_pref = i;
2619 dadeletemethodchoose(softc, DA_DELETE_NONE);
2624 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2627 struct da_softc *softc;
2630 softc = (struct da_softc *)arg1;
2632 switch (softc->zone_mode) {
2633 case DA_ZONE_DRIVE_MANAGED:
2634 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2636 case DA_ZONE_HOST_AWARE:
2637 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2639 case DA_ZONE_HOST_MANAGED:
2640 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2644 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2648 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2654 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2657 struct da_softc *softc;
2662 softc = (struct da_softc *)arg1;
2666 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2668 for (i = 0; i < sizeof(da_zone_desc_table) /
2669 sizeof(da_zone_desc_table[0]); i++) {
2670 if (softc->zone_flags & da_zone_desc_table[i].value) {
2672 sbuf_printf(&sb, ", ");
2675 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2680 sbuf_printf(&sb, "None");
2684 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2690 daregister(struct cam_periph *periph, void *arg)
2692 struct da_softc *softc;
2693 struct ccb_pathinq cpi;
2694 struct ccb_getdev *cgd;
2699 cgd = (struct ccb_getdev *)arg;
2701 printf("daregister: no getdev CCB, can't register device\n");
2702 return(CAM_REQ_CMP_ERR);
2705 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2708 if (softc == NULL) {
2709 printf("daregister: Unable to probe new device. "
2710 "Unable to allocate softc\n");
2711 return(CAM_REQ_CMP_ERR);
2714 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2715 printf("daregister: Unable to probe new device. "
2716 "Unable to allocate iosched memory\n");
2717 free(softc, M_DEVBUF);
2718 return(CAM_REQ_CMP_ERR);
2721 LIST_INIT(&softc->pending_ccbs);
2722 softc->state = DA_STATE_PROBE_WP;
2723 bioq_init(&softc->delete_run_queue);
2724 if (SID_IS_REMOVABLE(&cgd->inq_data))
2725 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2726 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2727 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2728 softc->unmap_gran = 0;
2729 softc->unmap_gran_align = 0;
2730 softc->ws_max_blks = WS16_MAX_BLKS;
2731 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2732 softc->rotating = 1;
2734 periph->softc = softc;
2737 * See if this device has any quirks.
2739 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2740 (caddr_t)da_quirk_table,
2741 nitems(da_quirk_table),
2742 sizeof(*da_quirk_table), scsi_inquiry_match);
2745 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2747 softc->quirks = DA_Q_NONE;
2749 /* Check if the SIM does not want 6 byte commands */
2750 xpt_path_inq(&cpi, periph->path);
2751 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2752 softc->quirks |= DA_Q_NO_6_BYTE;
2754 /* Override quirks if tunable is set */
2755 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.quirks",
2756 periph->unit_number);
2757 quirks = softc->quirks;
2758 TUNABLE_INT_FETCH(tmpstr, &quirks);
2759 softc->quirks = quirks;
2761 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2762 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2763 else if (softc->quirks & DA_Q_SMR_DM)
2764 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2766 softc->zone_mode = DA_ZONE_NONE;
2768 if (softc->zone_mode != DA_ZONE_NONE) {
2769 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2770 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2771 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2773 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2775 softc->zone_interface = DA_ZONE_IF_SCSI;
2778 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2781 * Take an exclusive section lock qon the periph while dastart is called
2782 * to finish the probe. The lock will be dropped in dadone at the end
2783 * of probe. This locks out daopen and daclose from racing with the
2786 * XXX if cam_periph_hold returns an error, we don't hold a refcount.
2788 (void)da_periph_hold(periph, PRIBIO, DA_REF_PROBE_HOLD);
2791 * Schedule a periodic event to occasionally send an
2792 * ordered tag to a device.
2794 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2795 callout_reset(&softc->sendordered_c,
2796 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2797 dasendorderedtag, periph);
2799 cam_periph_unlock(periph);
2801 * RBC devices don't have to support READ(6), only READ(10).
2803 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2804 softc->minimum_cmd_size = 10;
2806 softc->minimum_cmd_size = 6;
2809 * Load the user's default, if any.
2811 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2812 periph->unit_number);
2813 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2816 * 6, 10, 12 and 16 are the currently permissible values.
2818 if (softc->minimum_cmd_size > 12)
2819 softc->minimum_cmd_size = 16;
2820 else if (softc->minimum_cmd_size > 10)
2821 softc->minimum_cmd_size = 12;
2822 else if (softc->minimum_cmd_size > 6)
2823 softc->minimum_cmd_size = 10;
2825 softc->minimum_cmd_size = 6;
2827 /* Predict whether device may support READ CAPACITY(16). */
2828 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2829 (softc->quirks & DA_Q_NO_RC16) == 0) {
2830 softc->flags |= DA_FLAG_CAN_RC16;
2834 * Register this media as a disk.
2836 softc->disk = disk_alloc();
2837 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2838 periph->unit_number, 0,
2839 DEVSTAT_BS_UNAVAILABLE,
2840 SID_TYPE(&cgd->inq_data) |
2841 XPORT_DEVSTAT_TYPE(cpi.transport),
2842 DEVSTAT_PRIORITY_DISK);
2843 softc->disk->d_open = daopen;
2844 softc->disk->d_close = daclose;
2845 softc->disk->d_strategy = dastrategy;
2846 softc->disk->d_dump = dadump;
2847 softc->disk->d_getattr = dagetattr;
2848 softc->disk->d_gone = dadiskgonecb;
2849 softc->disk->d_name = "da";
2850 softc->disk->d_drv1 = periph;
2852 softc->maxio = DFLTPHYS; /* traditional default */
2853 else if (cpi.maxio > MAXPHYS)
2854 softc->maxio = MAXPHYS; /* for safety */
2856 softc->maxio = cpi.maxio;
2857 if (softc->quirks & DA_Q_128KB)
2858 softc->maxio = min(softc->maxio, 128 * 1024);
2859 softc->disk->d_maxsize = softc->maxio;
2860 softc->disk->d_unit = periph->unit_number;
2861 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2862 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2863 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2864 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2865 softc->unmappedio = 1;
2866 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2868 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2869 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2870 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2871 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2872 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2873 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2874 softc->disk->d_hba_vendor = cpi.hba_vendor;
2875 softc->disk->d_hba_device = cpi.hba_device;
2876 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2877 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2880 * Acquire a reference to the periph before we register with GEOM.
2881 * We'll release this reference once GEOM calls us back (via
2882 * dadiskgonecb()) telling us that our provider has been freed.
2884 if (da_periph_acquire(periph, DA_REF_GEOM) != 0) {
2885 xpt_print(periph->path, "%s: lost periph during "
2886 "registration!\n", __func__);
2887 cam_periph_lock(periph);
2888 return (CAM_REQ_CMP_ERR);
2891 disk_create(softc->disk, DISK_VERSION);
2892 cam_periph_lock(periph);
2895 * Add async callbacks for events of interest.
2896 * I don't bother checking if this fails as,
2897 * in most cases, the system will function just
2898 * fine without them and the only alternative
2899 * would be to not attach the device on failure.
2901 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2902 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2903 AC_INQ_CHANGED, daasync, periph, periph->path);
2906 * Emit an attribute changed notification just in case
2907 * physical path information arrived before our async
2908 * event handler was registered, but after anyone attaching
2909 * to our disk device polled it.
2911 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2914 * Schedule a periodic media polling events.
2916 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2917 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2918 (cgd->inq_flags & SID_AEN) == 0 &&
2919 da_poll_period != 0)
2920 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2921 damediapoll, periph);
2923 xpt_schedule(periph, CAM_PRIORITY_DEV);
2925 return(CAM_REQ_CMP);
2929 da_zone_bio_to_scsi(int disk_zone_cmd)
2931 switch (disk_zone_cmd) {
2932 case DISK_ZONE_OPEN:
2933 return ZBC_OUT_SA_OPEN;
2934 case DISK_ZONE_CLOSE:
2935 return ZBC_OUT_SA_CLOSE;
2936 case DISK_ZONE_FINISH:
2937 return ZBC_OUT_SA_FINISH;
2939 return ZBC_OUT_SA_RWP;
2946 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2949 struct da_softc *softc;
2954 if (bp->bio_cmd != BIO_ZONE) {
2959 softc = periph->softc;
2961 switch (bp->bio_zone.zone_cmd) {
2962 case DISK_ZONE_OPEN:
2963 case DISK_ZONE_CLOSE:
2964 case DISK_ZONE_FINISH:
2965 case DISK_ZONE_RWP: {
2970 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2971 if (zone_sa == -1) {
2972 xpt_print(periph->path, "Cannot translate zone "
2973 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2979 lba = bp->bio_zone.zone_params.rwp.id;
2981 if (bp->bio_zone.zone_params.rwp.flags &
2982 DISK_ZONE_RWP_FLAG_ALL)
2983 zone_flags |= ZBC_OUT_ALL;
2985 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2986 scsi_zbc_out(&ccb->csio,
2987 /*retries*/ da_retry_count,
2989 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2990 /*service_action*/ zone_sa,
2992 /*zone_flags*/ zone_flags,
2995 /*sense_len*/ SSD_FULL_SIZE,
2996 /*timeout*/ da_default_timeout * 1000);
2999 * Note that in this case, even though we can
3000 * technically use NCQ, we don't bother for several
3002 * 1. It hasn't been tested on a SAT layer that
3003 * supports it. This is new as of SAT-4.
3004 * 2. Even when there is a SAT layer that supports
3005 * it, that SAT layer will also probably support
3006 * ZBC -> ZAC translation, since they are both
3007 * in the SAT-4 spec.
3008 * 3. Translation will likely be preferable to ATA
3009 * passthrough. LSI / Avago at least single
3010 * steps ATA passthrough commands in the HBA,
3011 * regardless of protocol, so unless that
3012 * changes, there is a performance penalty for
3013 * doing ATA passthrough no matter whether
3014 * you're using NCQ/FPDMA, DMA or PIO.
3015 * 4. It requires a 32-byte CDB, which at least at
3016 * this point in CAM requires a CDB pointer, which
3017 * would require us to allocate an additional bit
3018 * of storage separate from the CCB.
3020 error = scsi_ata_zac_mgmt_out(&ccb->csio,
3021 /*retries*/ da_retry_count,
3023 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3025 /*zm_action*/ zone_sa,
3027 /*zone_flags*/ zone_flags,
3030 /*cdb_storage*/ NULL,
3031 /*cdb_storage_len*/ 0,
3032 /*sense_len*/ SSD_FULL_SIZE,
3033 /*timeout*/ da_default_timeout * 1000);
3036 xpt_print(periph->path,
3037 "scsi_ata_zac_mgmt_out() returned an "
3046 case DISK_ZONE_REPORT_ZONES: {
3048 uint32_t num_entries, alloc_size;
3049 struct disk_zone_report *rep;
3051 rep = &bp->bio_zone.zone_params.report;
3053 num_entries = rep->entries_allocated;
3054 if (num_entries == 0) {
3055 xpt_print(periph->path, "No entries allocated for "
3056 "Report Zones request\n");
3060 alloc_size = sizeof(struct scsi_report_zones_hdr) +
3061 (sizeof(struct scsi_report_zones_desc) * num_entries);
3062 alloc_size = min(alloc_size, softc->disk->d_maxsize);
3063 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
3064 if (rz_ptr == NULL) {
3065 xpt_print(periph->path, "Unable to allocate memory "
3066 "for Report Zones request\n");
3071 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
3072 scsi_zbc_in(&ccb->csio,
3073 /*retries*/ da_retry_count,
3075 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3076 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
3077 /*zone_start_lba*/ rep->starting_id,
3078 /*zone_options*/ rep->rep_options,
3079 /*data_ptr*/ rz_ptr,
3080 /*dxfer_len*/ alloc_size,
3081 /*sense_len*/ SSD_FULL_SIZE,
3082 /*timeout*/ da_default_timeout * 1000);
3085 * Note that in this case, even though we can
3086 * technically use NCQ, we don't bother for several
3088 * 1. It hasn't been tested on a SAT layer that
3089 * supports it. This is new as of SAT-4.
3090 * 2. Even when there is a SAT layer that supports
3091 * it, that SAT layer will also probably support
3092 * ZBC -> ZAC translation, since they are both
3093 * in the SAT-4 spec.
3094 * 3. Translation will likely be preferable to ATA
3095 * passthrough. LSI / Avago at least single
3096 * steps ATA passthrough commands in the HBA,
3097 * regardless of protocol, so unless that
3098 * changes, there is a performance penalty for
3099 * doing ATA passthrough no matter whether
3100 * you're using NCQ/FPDMA, DMA or PIO.
3101 * 4. It requires a 32-byte CDB, which at least at
3102 * this point in CAM requires a CDB pointer, which
3103 * would require us to allocate an additional bit
3104 * of storage separate from the CCB.
3106 error = scsi_ata_zac_mgmt_in(&ccb->csio,
3107 /*retries*/ da_retry_count,
3109 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3111 /*zm_action*/ ATA_ZM_REPORT_ZONES,
3112 /*zone_id*/ rep->starting_id,
3113 /*zone_flags*/ rep->rep_options,
3114 /*data_ptr*/ rz_ptr,
3115 /*dxfer_len*/ alloc_size,
3116 /*cdb_storage*/ NULL,
3117 /*cdb_storage_len*/ 0,
3118 /*sense_len*/ SSD_FULL_SIZE,
3119 /*timeout*/ da_default_timeout * 1000);
3122 xpt_print(periph->path,
3123 "scsi_ata_zac_mgmt_in() returned an "
3130 * For BIO_ZONE, this isn't normally needed. However, it
3131 * is used by devstat_end_transaction_bio() to determine
3132 * how much data was transferred.
3135 * XXX KDM we have a problem. But I'm not sure how to fix
3136 * it. devstat uses bio_bcount - bio_resid to calculate
3137 * the amount of data transferred. The GEOM disk code
3138 * uses bio_length - bio_resid to calculate the amount of
3139 * data in bio_completed. We have different structure
3140 * sizes above and below the ada(4) driver. So, if we
3141 * use the sizes above, the amount transferred won't be
3142 * quite accurate for devstat. If we use different sizes
3143 * for bio_bcount and bio_length (above and below
3144 * respectively), then the residual needs to match one or
3145 * the other. Everything is calculated after the bio
3146 * leaves the driver, so changing the values around isn't
3147 * really an option. For now, just set the count to the
3148 * passed in length. This means that the calculations
3149 * above (e.g. bio_completed) will be correct, but the
3150 * amount of data reported to devstat will be slightly
3151 * under or overstated.
3153 bp->bio_bcount = bp->bio_length;
3159 case DISK_ZONE_GET_PARAMS: {
3160 struct disk_zone_disk_params *params;
3162 params = &bp->bio_zone.zone_params.disk_params;
3163 bzero(params, sizeof(*params));
3165 switch (softc->zone_mode) {
3166 case DA_ZONE_DRIVE_MANAGED:
3167 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
3169 case DA_ZONE_HOST_AWARE:
3170 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
3172 case DA_ZONE_HOST_MANAGED:
3173 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
3177 params->zone_mode = DISK_ZONE_MODE_NONE;
3181 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
3182 params->flags |= DISK_ZONE_DISK_URSWRZ;
3184 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
3185 params->optimal_seq_zones = softc->optimal_seq_zones;
3186 params->flags |= DISK_ZONE_OPT_SEQ_SET;
3189 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
3190 params->optimal_nonseq_zones =
3191 softc->optimal_nonseq_zones;
3192 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
3195 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
3196 params->max_seq_zones = softc->max_seq_zones;
3197 params->flags |= DISK_ZONE_MAX_SEQ_SET;
3199 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
3200 params->flags |= DISK_ZONE_RZ_SUP;
3202 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
3203 params->flags |= DISK_ZONE_OPEN_SUP;
3205 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
3206 params->flags |= DISK_ZONE_CLOSE_SUP;
3208 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
3209 params->flags |= DISK_ZONE_FINISH_SUP;
3211 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
3212 params->flags |= DISK_ZONE_RWP_SUP;
3223 dastart(struct cam_periph *periph, union ccb *start_ccb)
3225 struct da_softc *softc;
3227 cam_periph_assert(periph, MA_OWNED);
3228 softc = (struct da_softc *)periph->softc;
3230 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
3233 switch (softc->state) {
3234 case DA_STATE_NORMAL:
3240 bp = cam_iosched_next_bio(softc->cam_iosched);
3242 if (cam_iosched_has_work_flags(softc->cam_iosched,
3244 softc->flags |= DA_FLAG_TUR_PENDING;
3245 cam_iosched_clr_work_flags(softc->cam_iosched,
3247 scsi_test_unit_ready(&start_ccb->csio,
3248 /*retries*/ da_retry_count,
3252 da_default_timeout * 1000);
3253 start_ccb->ccb_h.ccb_bp = NULL;
3254 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
3255 xpt_action(start_ccb);
3257 xpt_release_ccb(start_ccb);
3261 if (bp->bio_cmd == BIO_DELETE) {
3262 if (softc->delete_func != NULL) {
3263 softc->delete_func(periph, start_ccb, bp);
3267 * Not sure this is possible, but failsafe by
3268 * lying and saying "sure, done."
3270 biofinish(bp, NULL, 0);
3275 if (cam_iosched_has_work_flags(softc->cam_iosched,
3277 cam_iosched_clr_work_flags(softc->cam_iosched,
3279 da_periph_release_locked(periph, DA_REF_TUR);
3282 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
3283 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
3284 softc->flags &= ~DA_FLAG_NEED_OTAG;
3285 softc->flags |= DA_FLAG_WAS_OTAG;
3286 tag_code = MSG_ORDERED_Q_TAG;
3288 tag_code = MSG_SIMPLE_Q_TAG;
3291 switch (bp->bio_cmd) {
3298 biotrack(bp, __func__);
3300 if (bp->bio_cmd == BIO_WRITE) {
3301 softc->flags |= DA_FLAG_DIRTY;
3302 rw_op = SCSI_RW_WRITE;
3304 rw_op = SCSI_RW_READ;
3307 data_ptr = bp->bio_data;
3308 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
3309 rw_op |= SCSI_RW_BIO;
3313 scsi_read_write(&start_ccb->csio,
3314 /*retries*/da_retry_count,
3316 /*tag_action*/tag_code,
3319 softc->minimum_cmd_size,
3320 /*lba*/bp->bio_pblkno,
3321 /*block_count*/bp->bio_bcount /
3322 softc->params.secsize,
3324 /*dxfer_len*/ bp->bio_bcount,
3325 /*sense_len*/SSD_FULL_SIZE,
3326 da_default_timeout * 1000);
3327 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3328 start_ccb->csio.bio = bp;
3334 * If we don't support sync cache, or the disk
3335 * isn't dirty, FLUSH is a no-op. Use the
3336 * allocated CCB for the next bio if one is
3339 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) != 0 ||
3340 (softc->flags & DA_FLAG_DIRTY) == 0) {
3346 * BIO_FLUSH doesn't currently communicate
3347 * range data, so we synchronize the cache
3348 * over the whole disk.
3350 scsi_synchronize_cache(&start_ccb->csio,
3353 /*tag_action*/tag_code,
3357 da_default_timeout*1000);
3359 * Clear the dirty flag before sending the command.
3360 * Either this sync cache will be successful, or it
3361 * will fail after a retry. If it fails, it is
3362 * unlikely to be successful if retried later, so
3363 * we'll save ourselves time by just marking the
3366 softc->flags &= ~DA_FLAG_DIRTY;
3369 int error, queue_ccb;
3373 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3375 || (queue_ccb == 0)) {
3376 biofinish(bp, NULL, error);
3377 xpt_release_ccb(start_ccb);
3383 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3384 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3385 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3388 LIST_INSERT_HEAD(&softc->pending_ccbs,
3389 &start_ccb->ccb_h, periph_links.le);
3391 /* We expect a unit attention from this device */
3392 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3393 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3394 softc->flags &= ~DA_FLAG_RETRY_UA;
3397 start_ccb->ccb_h.ccb_bp = bp;
3399 cam_periph_unlock(periph);
3400 xpt_action(start_ccb);
3401 cam_periph_lock(periph);
3403 /* May have more work to do, so ensure we stay scheduled */
3407 case DA_STATE_PROBE_WP:
3412 if (da_disable_wp_detection) {
3413 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3414 softc->state = DA_STATE_PROBE_RC16;
3416 softc->state = DA_STATE_PROBE_RC;
3420 mode_buf = malloc(mode_buf_len, M_SCSIDA, M_NOWAIT);
3421 if (mode_buf == NULL) {
3422 xpt_print(periph->path, "Unable to send mode sense - "
3423 "malloc failure\n");
3424 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3425 softc->state = DA_STATE_PROBE_RC16;
3427 softc->state = DA_STATE_PROBE_RC;
3430 scsi_mode_sense_len(&start_ccb->csio,
3431 /*retries*/ da_retry_count,
3432 /*cbfcnp*/ dadone_probewp,
3433 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3435 /*pc*/ SMS_PAGE_CTRL_CURRENT,
3436 /*page*/ SMS_ALL_PAGES_PAGE,
3437 /*param_buf*/ mode_buf,
3438 /*param_len*/ mode_buf_len,
3439 /*minimum_cmd_size*/ softc->minimum_cmd_size,
3440 /*sense_len*/ SSD_FULL_SIZE,
3441 /*timeout*/ da_default_timeout * 1000);
3442 start_ccb->ccb_h.ccb_bp = NULL;
3443 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_WP;
3444 xpt_action(start_ccb);
3447 case DA_STATE_PROBE_RC:
3449 struct scsi_read_capacity_data *rcap;
3451 rcap = (struct scsi_read_capacity_data *)
3452 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3454 printf("dastart: Couldn't malloc read_capacity data\n");
3455 /* da_free_periph??? */
3458 scsi_read_capacity(&start_ccb->csio,
3459 /*retries*/da_retry_count,
3465 start_ccb->ccb_h.ccb_bp = NULL;
3466 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3467 xpt_action(start_ccb);
3470 case DA_STATE_PROBE_RC16:
3472 struct scsi_read_capacity_data_long *rcaplong;
3474 rcaplong = (struct scsi_read_capacity_data_long *)
3475 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3476 if (rcaplong == NULL) {
3477 printf("dastart: Couldn't malloc read_capacity data\n");
3478 /* da_free_periph??? */
3481 scsi_read_capacity_16(&start_ccb->csio,
3482 /*retries*/ da_retry_count,
3483 /*cbfcnp*/ dadone_proberc,
3484 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3488 /*rcap_buf*/ (uint8_t *)rcaplong,
3489 /*rcap_buf_len*/ sizeof(*rcaplong),
3490 /*sense_len*/ SSD_FULL_SIZE,
3491 /*timeout*/ da_default_timeout * 1000);
3492 start_ccb->ccb_h.ccb_bp = NULL;
3493 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3494 xpt_action(start_ccb);
3497 case DA_STATE_PROBE_LBP:
3499 struct scsi_vpd_logical_block_prov *lbp;
3501 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3503 * If we get here we don't support any SBC-3 delete
3504 * methods with UNMAP as the Logical Block Provisioning
3505 * VPD page support is required for devices which
3506 * support it according to T10/1799-D Revision 31
3507 * however older revisions of the spec don't mandate
3508 * this so we currently don't remove these methods
3509 * from the available set.
3511 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3515 lbp = (struct scsi_vpd_logical_block_prov *)
3516 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3519 printf("dastart: Couldn't malloc lbp data\n");
3520 /* da_free_periph??? */
3524 scsi_inquiry(&start_ccb->csio,
3525 /*retries*/da_retry_count,
3526 /*cbfcnp*/dadone_probelbp,
3527 /*tag_action*/MSG_SIMPLE_Q_TAG,
3528 /*inq_buf*/(u_int8_t *)lbp,
3529 /*inq_len*/sizeof(*lbp),
3531 /*page_code*/SVPD_LBP,
3532 /*sense_len*/SSD_MIN_SIZE,
3533 /*timeout*/da_default_timeout * 1000);
3534 start_ccb->ccb_h.ccb_bp = NULL;
3535 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3536 xpt_action(start_ccb);
3539 case DA_STATE_PROBE_BLK_LIMITS:
3541 struct scsi_vpd_block_limits *block_limits;
3543 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3544 /* Not supported skip to next probe */
3545 softc->state = DA_STATE_PROBE_BDC;
3549 block_limits = (struct scsi_vpd_block_limits *)
3550 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3552 if (block_limits == NULL) {
3553 printf("dastart: Couldn't malloc block_limits data\n");
3554 /* da_free_periph??? */
3558 scsi_inquiry(&start_ccb->csio,
3559 /*retries*/da_retry_count,
3560 /*cbfcnp*/dadone_probeblklimits,
3561 /*tag_action*/MSG_SIMPLE_Q_TAG,
3562 /*inq_buf*/(u_int8_t *)block_limits,
3563 /*inq_len*/sizeof(*block_limits),
3565 /*page_code*/SVPD_BLOCK_LIMITS,
3566 /*sense_len*/SSD_MIN_SIZE,
3567 /*timeout*/da_default_timeout * 1000);
3568 start_ccb->ccb_h.ccb_bp = NULL;
3569 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3570 xpt_action(start_ccb);
3573 case DA_STATE_PROBE_BDC:
3575 struct scsi_vpd_block_characteristics *bdc;
3577 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3578 softc->state = DA_STATE_PROBE_ATA;
3582 bdc = (struct scsi_vpd_block_characteristics *)
3583 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3586 printf("dastart: Couldn't malloc bdc data\n");
3587 /* da_free_periph??? */
3591 scsi_inquiry(&start_ccb->csio,
3592 /*retries*/da_retry_count,
3593 /*cbfcnp*/dadone_probebdc,
3594 /*tag_action*/MSG_SIMPLE_Q_TAG,
3595 /*inq_buf*/(u_int8_t *)bdc,
3596 /*inq_len*/sizeof(*bdc),
3598 /*page_code*/SVPD_BDC,
3599 /*sense_len*/SSD_MIN_SIZE,
3600 /*timeout*/da_default_timeout * 1000);
3601 start_ccb->ccb_h.ccb_bp = NULL;
3602 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3603 xpt_action(start_ccb);
3606 case DA_STATE_PROBE_ATA:
3608 struct ata_params *ata_params;
3610 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3611 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3612 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3614 * Note that if the ATA VPD page isn't
3615 * supported, we aren't talking to an ATA
3616 * device anyway. Support for that VPD
3617 * page is mandatory for SCSI to ATA (SAT)
3618 * translation layers.
3620 softc->state = DA_STATE_PROBE_ZONE;
3623 daprobedone(periph, start_ccb);
3627 ata_params = &periph->path->device->ident_data;
3629 scsi_ata_identify(&start_ccb->csio,
3630 /*retries*/da_retry_count,
3631 /*cbfcnp*/dadone_probeata,
3632 /*tag_action*/MSG_SIMPLE_Q_TAG,
3633 /*data_ptr*/(u_int8_t *)ata_params,
3634 /*dxfer_len*/sizeof(*ata_params),
3635 /*sense_len*/SSD_FULL_SIZE,
3636 /*timeout*/da_default_timeout * 1000);
3637 start_ccb->ccb_h.ccb_bp = NULL;
3638 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3639 xpt_action(start_ccb);
3642 case DA_STATE_PROBE_ATA_LOGDIR:
3644 struct ata_gp_log_dir *log_dir;
3649 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3651 * If we don't have log support, not much point in
3652 * trying to probe zone support.
3654 daprobedone(periph, start_ccb);
3659 * If we have an ATA device (the SCSI ATA Information VPD
3660 * page should be present and the ATA identify should have
3661 * succeeded) and it supports logs, ask for the log directory.
3664 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3665 if (log_dir == NULL) {
3666 xpt_print(periph->path, "Couldn't malloc log_dir "
3668 daprobedone(periph, start_ccb);
3672 retval = scsi_ata_read_log(&start_ccb->csio,
3673 /*retries*/ da_retry_count,
3674 /*cbfcnp*/ dadone_probeatalogdir,
3675 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3676 /*log_address*/ ATA_LOG_DIRECTORY,
3679 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3680 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3681 /*data_ptr*/ (uint8_t *)log_dir,
3682 /*dxfer_len*/ sizeof(*log_dir),
3683 /*sense_len*/ SSD_FULL_SIZE,
3684 /*timeout*/ da_default_timeout * 1000);
3687 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3688 free(log_dir, M_SCSIDA);
3689 daprobedone(periph, start_ccb);
3692 start_ccb->ccb_h.ccb_bp = NULL;
3693 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3694 xpt_action(start_ccb);
3697 case DA_STATE_PROBE_ATA_IDDIR:
3699 struct ata_identify_log_pages *id_dir;
3705 * Check here to see whether the Identify Device log is
3706 * supported in the directory of logs. If so, continue
3707 * with requesting the log of identify device pages.
3709 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3710 daprobedone(periph, start_ccb);
3714 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3715 if (id_dir == NULL) {
3716 xpt_print(periph->path, "Couldn't malloc id_dir "
3718 daprobedone(periph, start_ccb);
3722 retval = scsi_ata_read_log(&start_ccb->csio,
3723 /*retries*/ da_retry_count,
3724 /*cbfcnp*/ dadone_probeataiddir,
3725 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3726 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3727 /*page_number*/ ATA_IDL_PAGE_LIST,
3729 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3730 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3731 /*data_ptr*/ (uint8_t *)id_dir,
3732 /*dxfer_len*/ sizeof(*id_dir),
3733 /*sense_len*/ SSD_FULL_SIZE,
3734 /*timeout*/ da_default_timeout * 1000);
3737 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3738 free(id_dir, M_SCSIDA);
3739 daprobedone(periph, start_ccb);
3742 start_ccb->ccb_h.ccb_bp = NULL;
3743 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3744 xpt_action(start_ccb);
3747 case DA_STATE_PROBE_ATA_SUP:
3749 struct ata_identify_log_sup_cap *sup_cap;
3755 * Check here to see whether the Supported Capabilities log
3756 * is in the list of Identify Device logs.
3758 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3759 daprobedone(periph, start_ccb);
3763 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3764 if (sup_cap == NULL) {
3765 xpt_print(periph->path, "Couldn't malloc sup_cap "
3767 daprobedone(periph, start_ccb);
3771 retval = scsi_ata_read_log(&start_ccb->csio,
3772 /*retries*/ da_retry_count,
3773 /*cbfcnp*/ dadone_probeatasup,
3774 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3775 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3776 /*page_number*/ ATA_IDL_SUP_CAP,
3778 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3779 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3780 /*data_ptr*/ (uint8_t *)sup_cap,
3781 /*dxfer_len*/ sizeof(*sup_cap),
3782 /*sense_len*/ SSD_FULL_SIZE,
3783 /*timeout*/ da_default_timeout * 1000);
3786 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3787 free(sup_cap, M_SCSIDA);
3788 daprobedone(periph, start_ccb);
3793 start_ccb->ccb_h.ccb_bp = NULL;
3794 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3795 xpt_action(start_ccb);
3798 case DA_STATE_PROBE_ATA_ZONE:
3800 struct ata_zoned_info_log *ata_zone;
3806 * Check here to see whether the zoned device information
3807 * page is supported. If so, continue on to request it.
3808 * If not, skip to DA_STATE_PROBE_LOG or done.
3810 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3811 daprobedone(periph, start_ccb);
3814 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3816 if (ata_zone == NULL) {
3817 xpt_print(periph->path, "Couldn't malloc ata_zone "
3819 daprobedone(periph, start_ccb);
3823 retval = scsi_ata_read_log(&start_ccb->csio,
3824 /*retries*/ da_retry_count,
3825 /*cbfcnp*/ dadone_probeatazone,
3826 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3827 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3828 /*page_number*/ ATA_IDL_ZDI,
3830 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3831 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3832 /*data_ptr*/ (uint8_t *)ata_zone,
3833 /*dxfer_len*/ sizeof(*ata_zone),
3834 /*sense_len*/ SSD_FULL_SIZE,
3835 /*timeout*/ da_default_timeout * 1000);
3838 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3839 free(ata_zone, M_SCSIDA);
3840 daprobedone(periph, start_ccb);
3843 start_ccb->ccb_h.ccb_bp = NULL;
3844 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3845 xpt_action(start_ccb);
3849 case DA_STATE_PROBE_ZONE:
3851 struct scsi_vpd_zoned_bdc *bdc;
3854 * Note that this page will be supported for SCSI protocol
3855 * devices that support ZBC (SMR devices), as well as ATA
3856 * protocol devices that are behind a SAT (SCSI to ATA
3857 * Translation) layer that supports converting ZBC commands
3858 * to their ZAC equivalents.
3860 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3861 daprobedone(periph, start_ccb);
3864 bdc = (struct scsi_vpd_zoned_bdc *)
3865 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3868 xpt_release_ccb(start_ccb);
3869 xpt_print(periph->path, "Couldn't malloc zone VPD "
3873 scsi_inquiry(&start_ccb->csio,
3874 /*retries*/da_retry_count,
3875 /*cbfcnp*/dadone_probezone,
3876 /*tag_action*/MSG_SIMPLE_Q_TAG,
3877 /*inq_buf*/(u_int8_t *)bdc,
3878 /*inq_len*/sizeof(*bdc),
3880 /*page_code*/SVPD_ZONED_BDC,
3881 /*sense_len*/SSD_FULL_SIZE,
3882 /*timeout*/da_default_timeout * 1000);
3883 start_ccb->ccb_h.ccb_bp = NULL;
3884 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3885 xpt_action(start_ccb);
3892 * In each of the methods below, while its the caller's
3893 * responsibility to ensure the request will fit into a
3894 * single device request, we might have changed the delete
3895 * method due to the device incorrectly advertising either
3896 * its supported methods or limits.
3898 * To prevent this causing further issues we validate the
3899 * against the methods limits, and warn which would
3900 * otherwise be unnecessary.
3903 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3905 struct da_softc *softc = (struct da_softc *)periph->softc;;
3907 uint8_t *buf = softc->unmap_buf;
3908 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3909 uint64_t lba, lastlba = (uint64_t)-1;
3910 uint64_t totalcount = 0;
3912 uint32_t c, lastcount = 0, ranges = 0;
3915 * Currently this doesn't take the UNMAP
3916 * Granularity and Granularity Alignment
3917 * fields into account.
3919 * This could result in both unoptimal unmap
3920 * requests as as well as UNMAP calls unmapping
3921 * fewer LBA's than requested.
3924 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3928 * Note: ada and da are different in how they store the
3929 * pending bp's in a trim. ada stores all of them in the
3930 * trim_req.bps. da stores all but the first one in the
3931 * delete_run_queue. ada then completes all the bps in
3932 * its adadone() loop. da completes all the bps in the
3933 * delete_run_queue in dadone, and relies on the biodone
3934 * after to complete. This should be reconciled since there's
3935 * no real reason to do it differently. XXX
3938 bioq_insert_tail(&softc->delete_run_queue, bp1);
3939 lba = bp1->bio_pblkno;
3940 count = bp1->bio_bcount / softc->params.secsize;
3942 /* Try to extend the previous range. */
3943 if (lba == lastlba) {
3944 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3947 scsi_ulto4b(lastcount, d[ranges - 1].length);
3951 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3952 softc->unmap_gran != 0) {
3953 /* Align length of the previous range. */
3954 if ((c = lastcount % softc->unmap_gran) != 0) {
3955 if (lastcount <= c) {
3956 totalcount -= lastcount;
3957 lastlba = (uint64_t)-1;
3964 scsi_ulto4b(lastcount,
3965 d[ranges - 1].length);
3968 /* Align beginning of the new range. */
3969 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3971 c = softc->unmap_gran - c;
3982 c = omin(count, UNMAP_RANGE_MAX);
3983 if (totalcount + c > softc->unmap_max_lba ||
3984 ranges >= softc->unmap_max_ranges) {
3985 xpt_print(periph->path,
3986 "%s issuing short delete %ld > %ld"
3988 da_delete_method_desc[softc->delete_method],
3989 totalcount + c, softc->unmap_max_lba,
3990 ranges, softc->unmap_max_ranges);
3993 scsi_u64to8b(lba, d[ranges].lba);
3994 scsi_ulto4b(c, d[ranges].length);
4002 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4005 if (ranges >= softc->unmap_max_ranges ||
4006 totalcount + bp1->bio_bcount /
4007 softc->params.secsize > softc->unmap_max_lba) {
4008 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4013 /* Align length of the last range. */
4014 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
4015 (c = lastcount % softc->unmap_gran) != 0) {
4019 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
4022 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
4023 scsi_ulto2b(ranges * 16, &buf[2]);
4025 scsi_unmap(&ccb->csio,
4026 /*retries*/da_retry_count,
4028 /*tag_action*/MSG_SIMPLE_Q_TAG,
4031 /*dxfer_len*/ ranges * 16 + 8,
4032 /*sense_len*/SSD_FULL_SIZE,
4033 da_default_timeout * 1000);
4034 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4035 ccb->ccb_h.flags |= CAM_UNLOCKED;
4036 softc->trim_count++;
4037 softc->trim_ranges += ranges;
4038 softc->trim_lbas += totalcount;
4039 cam_iosched_submit_trim(softc->cam_iosched);
4043 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4045 struct da_softc *softc = (struct da_softc *)periph->softc;
4047 uint8_t *buf = softc->unmap_buf;
4048 uint64_t lastlba = (uint64_t)-1;
4051 uint32_t lastcount = 0, c, requestcount;
4052 int ranges = 0, off, block_count;
4054 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
4057 if (bp1 != bp)//XXX imp XXX
4058 bioq_insert_tail(&softc->delete_run_queue, bp1);
4059 lba = bp1->bio_pblkno;
4060 count = bp1->bio_bcount / softc->params.secsize;
4061 requestcount = count;
4063 /* Try to extend the previous range. */
4064 if (lba == lastlba) {
4065 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
4067 off = (ranges - 1) * 8;
4068 buf[off + 6] = lastcount & 0xff;
4069 buf[off + 7] = (lastcount >> 8) & 0xff;
4075 c = omin(count, ATA_DSM_RANGE_MAX);
4078 buf[off + 0] = lba & 0xff;
4079 buf[off + 1] = (lba >> 8) & 0xff;
4080 buf[off + 2] = (lba >> 16) & 0xff;
4081 buf[off + 3] = (lba >> 24) & 0xff;
4082 buf[off + 4] = (lba >> 32) & 0xff;
4083 buf[off + 5] = (lba >> 40) & 0xff;
4084 buf[off + 6] = c & 0xff;
4085 buf[off + 7] = (c >> 8) & 0xff;
4090 if (count != 0 && ranges == softc->trim_max_ranges) {
4091 xpt_print(periph->path,
4092 "%s issuing short delete %ld > %ld\n",
4093 da_delete_method_desc[softc->delete_method],
4095 (softc->trim_max_ranges - ranges) *
4101 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4104 if (bp1->bio_bcount / softc->params.secsize >
4105 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
4106 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4111 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
4112 scsi_ata_trim(&ccb->csio,
4113 /*retries*/da_retry_count,
4115 /*tag_action*/MSG_SIMPLE_Q_TAG,
4118 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
4119 /*sense_len*/SSD_FULL_SIZE,
4120 da_default_timeout * 1000);
4121 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4122 ccb->ccb_h.flags |= CAM_UNLOCKED;
4123 cam_iosched_submit_trim(softc->cam_iosched);
4127 * We calculate ws_max_blks here based off d_delmaxsize instead
4128 * of using softc->ws_max_blks as it is absolute max for the
4129 * device not the protocol max which may well be lower.
4132 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4134 struct da_softc *softc;
4136 uint64_t ws_max_blks;
4138 uint64_t count; /* forward compat with WS32 */
4140 softc = (struct da_softc *)periph->softc;
4141 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
4142 lba = bp->bio_pblkno;
4146 if (bp1 != bp)//XXX imp XXX
4147 bioq_insert_tail(&softc->delete_run_queue, bp1);
4148 count += bp1->bio_bcount / softc->params.secsize;
4149 if (count > ws_max_blks) {
4150 xpt_print(periph->path,
4151 "%s issuing short delete %ld > %ld\n",
4152 da_delete_method_desc[softc->delete_method],
4153 count, ws_max_blks);
4154 count = omin(count, ws_max_blks);
4157 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4160 if (lba + count != bp1->bio_pblkno ||
4161 count + bp1->bio_bcount /
4162 softc->params.secsize > ws_max_blks) {
4163 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4168 scsi_write_same(&ccb->csio,
4169 /*retries*/da_retry_count,
4171 /*tag_action*/MSG_SIMPLE_Q_TAG,
4172 /*byte2*/softc->delete_method ==
4173 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
4174 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
4176 /*block_count*/count,
4177 /*data_ptr*/ __DECONST(void *, zero_region),
4178 /*dxfer_len*/ softc->params.secsize,
4179 /*sense_len*/SSD_FULL_SIZE,
4180 da_default_timeout * 1000);
4181 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4182 ccb->ccb_h.flags |= CAM_UNLOCKED;
4183 cam_iosched_submit_trim(softc->cam_iosched);
4187 cmd6workaround(union ccb *ccb)
4189 struct scsi_rw_6 cmd6;
4190 struct scsi_rw_10 *cmd10;
4191 struct da_softc *softc;
4196 cdb = ccb->csio.cdb_io.cdb_bytes;
4197 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
4199 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
4200 da_delete_methods old_method = softc->delete_method;
4203 * Typically there are two reasons for failure here
4204 * 1. Delete method was detected as supported but isn't
4205 * 2. Delete failed due to invalid params e.g. too big
4207 * While we will attempt to choose an alternative delete method
4208 * this may result in short deletes if the existing delete
4209 * requests from geom are big for the new method chosen.
4211 * This method assumes that the error which triggered this
4212 * will not retry the io otherwise a panic will occur
4214 dadeleteflag(softc, old_method, 0);
4215 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
4216 if (softc->delete_method == DA_DELETE_DISABLE)
4217 xpt_print(ccb->ccb_h.path,
4218 "%s failed, disabling BIO_DELETE\n",
4219 da_delete_method_desc[old_method]);
4221 xpt_print(ccb->ccb_h.path,
4222 "%s failed, switching to %s BIO_DELETE\n",
4223 da_delete_method_desc[old_method],
4224 da_delete_method_desc[softc->delete_method]);
4226 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
4227 cam_iosched_queue_work(softc->cam_iosched, bp);
4228 cam_iosched_queue_work(softc->cam_iosched,
4229 (struct bio *)ccb->ccb_h.ccb_bp);
4230 ccb->ccb_h.ccb_bp = NULL;
4234 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
4235 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4236 (*cdb == PREVENT_ALLOW) &&
4237 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
4239 xpt_print(ccb->ccb_h.path,
4240 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
4241 softc->quirks |= DA_Q_NO_PREVENT;
4245 /* Detect unsupported SYNCHRONIZE CACHE(10). */
4246 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4247 (*cdb == SYNCHRONIZE_CACHE) &&
4248 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
4250 xpt_print(ccb->ccb_h.path,
4251 "SYNCHRONIZE CACHE(10) not supported.\n");
4252 softc->quirks |= DA_Q_NO_SYNC_CACHE;
4253 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
4257 /* Translation only possible if CDB is an array and cmd is R/W6 */
4258 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
4259 (*cdb != READ_6 && *cdb != WRITE_6))
4262 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
4263 "increasing minimum_cmd_size to 10.\n");
4264 softc->minimum_cmd_size = 10;
4266 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
4267 cmd10 = (struct scsi_rw_10 *)cdb;
4268 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
4270 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
4271 cmd10->reserved = 0;
4272 scsi_ulto2b(cmd6.length, cmd10->length);
4273 cmd10->control = cmd6.control;
4274 ccb->csio.cdb_len = sizeof(*cmd10);
4276 /* Requeue request, unfreezing queue if necessary */
4277 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
4278 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4281 cam_release_devq(ccb->ccb_h.path,
4285 /*getcount_only*/0);
4291 dazonedone(struct cam_periph *periph, union ccb *ccb)
4293 struct da_softc *softc;
4296 softc = periph->softc;
4297 bp = (struct bio *)ccb->ccb_h.ccb_bp;
4299 switch (bp->bio_zone.zone_cmd) {
4300 case DISK_ZONE_OPEN:
4301 case DISK_ZONE_CLOSE:
4302 case DISK_ZONE_FINISH:
4305 case DISK_ZONE_REPORT_ZONES: {
4307 struct disk_zone_report *rep;
4308 struct scsi_report_zones_hdr *hdr;
4309 struct scsi_report_zones_desc *desc;
4310 struct disk_zone_rep_entry *entry;
4311 uint32_t hdr_len, num_avail;
4312 uint32_t num_to_fill, i;
4315 rep = &bp->bio_zone.zone_params.report;
4316 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
4318 * Note that bio_resid isn't normally used for zone
4319 * commands, but it is used by devstat_end_transaction_bio()
4320 * to determine how much data was transferred. Because
4321 * the size of the SCSI/ATA data structures is different
4322 * than the size of the BIO interface structures, the
4323 * amount of data actually transferred from the drive will
4324 * be different than the amount of data transferred to
4327 bp->bio_resid = ccb->csio.resid;
4328 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
4329 if (avail_len < sizeof(*hdr)) {
4331 * Is there a better error than EIO here? We asked
4332 * for at least the header, and we got less than
4335 bp->bio_error = EIO;
4336 bp->bio_flags |= BIO_ERROR;
4337 bp->bio_resid = bp->bio_bcount;
4341 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4346 hdr_len = ata ? le32dec(hdr->length) :
4347 scsi_4btoul(hdr->length);
4349 rep->entries_available = hdr_len / sizeof(*desc);
4351 rep->entries_available = 0;
4353 * NOTE: using the same values for the BIO version of the
4354 * same field as the SCSI/ATA values. This means we could
4355 * get some additional values that aren't defined in bio.h
4356 * if more values of the same field are defined later.
4358 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4359 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4360 scsi_8btou64(hdr->maximum_lba);
4362 * If the drive reports no entries that match the query,
4366 rep->entries_filled = 0;
4370 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4371 hdr_len / sizeof(*desc));
4373 * If the drive didn't return any data, then we're done.
4375 if (num_avail == 0) {
4376 rep->entries_filled = 0;
4380 num_to_fill = min(num_avail, rep->entries_allocated);
4382 * If the user didn't allocate any entries for us to fill,
4385 if (num_to_fill == 0) {
4386 rep->entries_filled = 0;
4390 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4391 i < num_to_fill; i++, desc++, entry++) {
4393 * NOTE: we're mapping the values here directly
4394 * from the SCSI/ATA bit definitions to the bio.h
4395 * definitons. There is also a warning in
4396 * disk_zone.h, but the impact is that if
4397 * additional values are added in the SCSI/ATA
4398 * specs these will be visible to consumers of
4401 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4402 entry->zone_condition =
4403 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4404 SRZ_ZONE_COND_SHIFT;
4405 entry->zone_flags |= desc->zone_flags &
4406 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4407 entry->zone_length =
4408 ata ? le64dec(desc->zone_length) :
4409 scsi_8btou64(desc->zone_length);
4410 entry->zone_start_lba =
4411 ata ? le64dec(desc->zone_start_lba) :
4412 scsi_8btou64(desc->zone_start_lba);
4413 entry->write_pointer_lba =
4414 ata ? le64dec(desc->write_pointer_lba) :
4415 scsi_8btou64(desc->write_pointer_lba);
4417 rep->entries_filled = num_to_fill;
4420 case DISK_ZONE_GET_PARAMS:
4423 * In theory we should not get a GET_PARAMS bio, since it
4424 * should be handled without queueing the command to the
4427 panic("%s: Invalid zone command %d", __func__,
4428 bp->bio_zone.zone_cmd);
4432 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4433 free(ccb->csio.data_ptr, M_SCSIDA);
4437 dadone(struct cam_periph *periph, union ccb *done_ccb)
4439 struct bio *bp, *bp1;
4440 struct da_softc *softc;
4441 struct ccb_scsiio *csio;
4445 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4447 softc = (struct da_softc *)periph->softc;
4448 priority = done_ccb->ccb_h.pinfo.priority;
4449 csio = &done_ccb->csio;
4451 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4452 if (csio->bio != NULL)
4453 biotrack(csio->bio, __func__);
4455 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4457 cam_periph_lock(periph);
4458 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4459 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4463 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4468 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4469 if (error == ERESTART) {
4470 /* A retry was scheduled, so just return. */
4471 cam_periph_unlock(periph);
4474 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4479 * return all queued I/O with EIO, so that
4480 * the client can retry these I/Os in the
4481 * proper order should it attempt to recover.
4486 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4488 * Catastrophic error. Mark our pack as
4491 * XXX See if this is really a media
4494 xpt_print(periph->path, "Invalidating pack\n");
4495 softc->flags |= DA_FLAG_PACK_INVALID;
4497 softc->invalidations++;
4499 queued_error = ENXIO;
4501 cam_iosched_flush(softc->cam_iosched, NULL,
4504 bp->bio_error = error;
4505 bp->bio_resid = bp->bio_bcount;
4506 bp->bio_flags |= BIO_ERROR;
4508 } else if (bp != NULL) {
4509 if (state == DA_CCB_DELETE)
4512 bp->bio_resid = csio->resid;
4514 if (bp->bio_resid != 0)
4515 bp->bio_flags |= BIO_ERROR;
4517 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4518 cam_release_devq(done_ccb->ccb_h.path,
4522 /*getcount_only*/0);
4523 } else if (bp != NULL) {
4524 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4525 panic("REQ_CMP with QFRZN");
4526 if (bp->bio_cmd == BIO_ZONE)
4527 dazonedone(periph, done_ccb);
4528 else if (state == DA_CCB_DELETE)
4531 bp->bio_resid = csio->resid;
4532 if ((csio->resid > 0) && (bp->bio_cmd != BIO_ZONE))
4533 bp->bio_flags |= BIO_ERROR;
4534 if (softc->error_inject != 0) {
4535 bp->bio_error = softc->error_inject;
4536 bp->bio_resid = bp->bio_bcount;
4537 bp->bio_flags |= BIO_ERROR;
4538 softc->error_inject = 0;
4543 biotrack(bp, __func__);
4544 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4545 if (LIST_EMPTY(&softc->pending_ccbs))
4546 softc->flags |= DA_FLAG_WAS_OTAG;
4549 * We need to call cam_iosched before we call biodone so that we don't
4550 * measure any activity that happens in the completion routine, which in
4551 * the case of sendfile can be quite extensive. Release the periph
4552 * refcount taken in dastart() for each CCB.
4554 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4555 xpt_release_ccb(done_ccb);
4556 KASSERT(softc->refcount >= 1, ("dadone softc %p refcount %d", softc, softc->refcount));
4558 if (state == DA_CCB_DELETE) {
4559 TAILQ_HEAD(, bio) queue;
4562 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4563 softc->delete_run_queue.insert_point = NULL;
4565 * Normally, the xpt_release_ccb() above would make sure
4566 * that when we have more work to do, that work would
4567 * get kicked off. However, we specifically keep
4568 * delete_running set to 0 before the call above to
4569 * allow other I/O to progress when many BIO_DELETE
4570 * requests are pushed down. We set delete_running to 0
4571 * and call daschedule again so that we don't stall if
4572 * there are no other I/Os pending apart from BIO_DELETEs.
4574 cam_iosched_trim_done(softc->cam_iosched);
4576 cam_periph_unlock(periph);
4577 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4578 TAILQ_REMOVE(&queue, bp1, bio_queue);
4579 bp1->bio_error = bp->bio_error;
4580 if (bp->bio_flags & BIO_ERROR) {
4581 bp1->bio_flags |= BIO_ERROR;
4582 bp1->bio_resid = bp1->bio_bcount;
4589 cam_periph_unlock(periph);
4597 dadone_probewp(struct cam_periph *periph, union ccb *done_ccb)
4599 struct scsi_mode_header_6 *mode_hdr6;
4600 struct scsi_mode_header_10 *mode_hdr10;
4601 struct da_softc *softc;
4602 struct ccb_scsiio *csio;
4606 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probewp\n"));
4608 softc = (struct da_softc *)periph->softc;
4609 priority = done_ccb->ccb_h.pinfo.priority;
4610 csio = &done_ccb->csio;
4612 cam_periph_assert(periph, MA_OWNED);
4614 if (softc->minimum_cmd_size > 6) {
4615 mode_hdr10 = (struct scsi_mode_header_10 *)csio->data_ptr;
4616 dev_spec = mode_hdr10->dev_spec;
4618 mode_hdr6 = (struct scsi_mode_header_6 *)csio->data_ptr;
4619 dev_spec = mode_hdr6->dev_spec;
4621 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
4622 if ((dev_spec & 0x80) != 0)
4623 softc->disk->d_flags |= DISKFLAG_WRITE_PROTECT;
4625 softc->disk->d_flags &= ~DISKFLAG_WRITE_PROTECT;
4629 error = daerror(done_ccb, CAM_RETRY_SELTO,
4630 SF_RETRY_UA|SF_NO_PRINT);
4631 if (error == ERESTART)
4633 else if (error != 0) {
4634 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4635 /* Don't wedge this device's queue */
4636 cam_release_devq(done_ccb->ccb_h.path,
4640 /*getcount_only*/0);
4645 free(csio->data_ptr, M_SCSIDA);
4646 xpt_release_ccb(done_ccb);
4647 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
4648 softc->state = DA_STATE_PROBE_RC16;
4650 softc->state = DA_STATE_PROBE_RC;
4651 xpt_schedule(periph, priority);
4656 dadone_proberc(struct cam_periph *periph, union ccb *done_ccb)
4658 struct scsi_read_capacity_data *rdcap;
4659 struct scsi_read_capacity_data_long *rcaplong;
4660 struct da_softc *softc;
4661 struct ccb_scsiio *csio;
4667 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_proberc\n"));
4669 softc = (struct da_softc *)periph->softc;
4670 priority = done_ccb->ccb_h.pinfo.priority;
4671 csio = &done_ccb->csio;
4672 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4677 /* XXX TODO: can this be a malloc? */
4678 announce_buf = softc->announce_temp;
4679 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4681 if (state == DA_CCB_PROBE_RC)
4682 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4684 rcaplong = (struct scsi_read_capacity_data_long *)
4687 cam_periph_assert(periph, MA_OWNED);
4689 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4690 struct disk_params *dp;
4691 uint32_t block_size;
4693 u_int lalba; /* Lowest aligned LBA. */
4695 if (state == DA_CCB_PROBE_RC) {
4696 block_size = scsi_4btoul(rdcap->length);
4697 maxsector = scsi_4btoul(rdcap->addr);
4701 * According to SBC-2, if the standard 10
4702 * byte READ CAPACITY command returns 2^32,
4703 * we should issue the 16 byte version of
4704 * the command, since the device in question
4705 * has more sectors than can be represented
4706 * with the short version of the command.
4708 if (maxsector == 0xffffffff) {
4709 free(rdcap, M_SCSIDA);
4710 xpt_release_ccb(done_ccb);
4711 softc->state = DA_STATE_PROBE_RC16;
4712 xpt_schedule(periph, priority);
4716 block_size = scsi_4btoul(rcaplong->length);
4717 maxsector = scsi_8btou64(rcaplong->addr);
4718 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4722 * Because GEOM code just will panic us if we
4723 * give them an 'illegal' value we'll avoid that
4726 if (block_size == 0) {
4731 if (block_size >= MAXPHYS) {
4732 xpt_print(periph->path,
4733 "unsupportable block size %ju\n",
4734 (uintmax_t) block_size);
4735 announce_buf = NULL;
4736 cam_periph_invalidate(periph);
4739 * We pass rcaplong into dasetgeom(),
4740 * because it will only use it if it is
4743 dasetgeom(periph, block_size, maxsector,
4744 rcaplong, sizeof(*rcaplong));
4745 lbp = (lalba & SRC16_LBPME_A);
4746 dp = &softc->params;
4747 n = snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4748 "%juMB (%ju %u byte sectors",
4749 ((uintmax_t)dp->secsize * dp->sectors) /
4751 (uintmax_t)dp->sectors, dp->secsize);
4752 if (softc->p_type != 0) {
4753 n += snprintf(announce_buf + n,
4754 DA_ANNOUNCETMP_SZ - n,
4755 ", DIF type %d", softc->p_type);
4757 snprintf(announce_buf + n, DA_ANNOUNCETMP_SZ - n, ")");
4763 * Retry any UNIT ATTENTION type errors. They
4764 * are expected at boot.
4766 error = daerror(done_ccb, CAM_RETRY_SELTO,
4767 SF_RETRY_UA|SF_NO_PRINT);
4768 if (error == ERESTART) {
4770 * A retry was scheuled, so
4774 } else if (error != 0) {
4776 int sense_key, error_code;
4779 struct ccb_getdev cgd;
4781 /* Don't wedge this device's queue */
4782 status = done_ccb->ccb_h.status;
4783 if ((status & CAM_DEV_QFRZN) != 0)
4784 cam_release_devq(done_ccb->ccb_h.path,
4788 /*getcount_only*/0);
4791 xpt_setup_ccb(&cgd.ccb_h, done_ccb->ccb_h.path,
4792 CAM_PRIORITY_NORMAL);
4793 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4794 xpt_action((union ccb *)&cgd);
4796 if (scsi_extract_sense_ccb(done_ccb,
4797 &error_code, &sense_key, &asc, &ascq))
4803 * If we tried READ CAPACITY(16) and failed,
4804 * fallback to READ CAPACITY(10).
4806 if ((state == DA_CCB_PROBE_RC16) &&
4807 (softc->flags & DA_FLAG_CAN_RC16) &&
4808 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4811 (error_code == SSD_CURRENT_ERROR ||
4812 error_code == SSD_DESC_CURRENT_ERROR) &&
4813 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4814 cam_periph_assert(periph, MA_OWNED);
4815 softc->flags &= ~DA_FLAG_CAN_RC16;
4816 free(rdcap, M_SCSIDA);
4817 xpt_release_ccb(done_ccb);
4818 softc->state = DA_STATE_PROBE_RC;
4819 xpt_schedule(periph, priority);
4824 * Attach to anything that claims to be a
4825 * direct access or optical disk device,
4826 * as long as it doesn't return a "Logical
4827 * unit not supported" (0x25) error.
4828 * "Internal Target Failure" (0x44) is also
4829 * special and typically means that the
4830 * device is a SATA drive behind a SATL
4831 * translation that's fallen into a
4832 * terminally fatal state.
4835 && (asc != 0x25) && (asc != 0x44)
4836 && (error_code == SSD_CURRENT_ERROR
4837 || error_code == SSD_DESC_CURRENT_ERROR)) {
4838 const char *sense_key_desc;
4839 const char *asc_desc;
4841 dasetgeom(periph, 512, -1, NULL, 0);
4842 scsi_sense_desc(sense_key, asc, ascq,
4843 &cgd.inq_data, &sense_key_desc,
4845 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4846 "Attempt to query device "
4847 "size failed: %s, %s",
4848 sense_key_desc, asc_desc);
4851 scsi_sense_print(&done_ccb->csio);
4853 xpt_print(periph->path,
4854 "got CAM status %#x\n",
4855 done_ccb->ccb_h.status);
4858 xpt_print(periph->path, "fatal error, "
4859 "failed to attach to device\n");
4861 announce_buf = NULL;
4864 * Free up resources.
4866 cam_periph_invalidate(periph);
4870 free(csio->data_ptr, M_SCSIDA);
4871 if (announce_buf != NULL &&
4872 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4875 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4877 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4878 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4884 * Create our sysctl variables, now that we know
4885 * we have successfully attached.
4887 /* increase the refcount */
4888 if (da_periph_acquire(periph, DA_REF_SYSCTL) == 0) {
4889 taskqueue_enqueue(taskqueue_thread,
4890 &softc->sysctl_task);
4892 /* XXX This message is useless! */
4893 xpt_print(periph->path, "fatal error, "
4894 "could not acquire reference count\n");
4898 /* We already probed the device. */
4899 if (softc->flags & DA_FLAG_PROBED) {
4900 daprobedone(periph, done_ccb);
4904 /* Ensure re-probe doesn't see old delete. */
4905 softc->delete_available = 0;
4906 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4907 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4909 * Based on older SBC-3 spec revisions
4910 * any of the UNMAP methods "may" be
4911 * available via LBP given this flag so
4912 * we flag all of them as available and
4913 * then remove those which further
4914 * probes confirm aren't available
4917 * We could also check readcap(16) p_type
4918 * flag to exclude one or more invalid
4919 * write same (X) types here
4921 dadeleteflag(softc, DA_DELETE_WS16, 1);
4922 dadeleteflag(softc, DA_DELETE_WS10, 1);
4923 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4925 xpt_release_ccb(done_ccb);
4926 softc->state = DA_STATE_PROBE_LBP;
4927 xpt_schedule(periph, priority);
4931 xpt_release_ccb(done_ccb);
4932 softc->state = DA_STATE_PROBE_BDC;
4933 xpt_schedule(periph, priority);
4938 dadone_probelbp(struct cam_periph *periph, union ccb *done_ccb)
4940 struct scsi_vpd_logical_block_prov *lbp;
4941 struct da_softc *softc;
4942 struct ccb_scsiio *csio;
4945 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probelbp\n"));
4947 softc = (struct da_softc *)periph->softc;
4948 priority = done_ccb->ccb_h.pinfo.priority;
4949 csio = &done_ccb->csio;
4950 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4952 cam_periph_assert(periph, MA_OWNED);
4954 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4956 * T10/1799-D Revision 31 states at least one of these
4957 * must be supported but we don't currently enforce this.
4959 dadeleteflag(softc, DA_DELETE_WS16,
4960 (lbp->flags & SVPD_LBP_WS16));
4961 dadeleteflag(softc, DA_DELETE_WS10,
4962 (lbp->flags & SVPD_LBP_WS10));
4963 dadeleteflag(softc, DA_DELETE_UNMAP,
4964 (lbp->flags & SVPD_LBP_UNMAP));
4967 error = daerror(done_ccb, CAM_RETRY_SELTO,
4968 SF_RETRY_UA|SF_NO_PRINT);
4969 if (error == ERESTART)
4971 else if (error != 0) {
4972 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4973 /* Don't wedge this device's queue */
4974 cam_release_devq(done_ccb->ccb_h.path,
4978 /*getcount_only*/0);
4982 * Failure indicates we don't support any SBC-3
4983 * delete methods with UNMAP
4988 free(lbp, M_SCSIDA);
4989 xpt_release_ccb(done_ccb);
4990 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4991 xpt_schedule(periph, priority);
4996 dadone_probeblklimits(struct cam_periph *periph, union ccb *done_ccb)
4998 struct scsi_vpd_block_limits *block_limits;
4999 struct da_softc *softc;
5000 struct ccb_scsiio *csio;
5003 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeblklimits\n"));
5005 softc = (struct da_softc *)periph->softc;
5006 priority = done_ccb->ccb_h.pinfo.priority;
5007 csio = &done_ccb->csio;
5008 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
5010 cam_periph_assert(periph, MA_OWNED);
5012 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5013 uint32_t max_txfer_len = scsi_4btoul(
5014 block_limits->max_txfer_len);
5015 uint32_t max_unmap_lba_cnt = scsi_4btoul(
5016 block_limits->max_unmap_lba_cnt);
5017 uint32_t max_unmap_blk_cnt = scsi_4btoul(
5018 block_limits->max_unmap_blk_cnt);
5019 uint32_t unmap_gran = scsi_4btoul(
5020 block_limits->opt_unmap_grain);
5021 uint32_t unmap_gran_align = scsi_4btoul(
5022 block_limits->unmap_grain_align);
5023 uint64_t ws_max_blks = scsi_8btou64(
5024 block_limits->max_write_same_length);
5026 if (max_txfer_len != 0) {
5027 softc->disk->d_maxsize = MIN(softc->maxio,
5028 (off_t)max_txfer_len * softc->params.secsize);
5032 * We should already support UNMAP but we check lba
5033 * and block count to be sure
5035 if (max_unmap_lba_cnt != 0x00L &&
5036 max_unmap_blk_cnt != 0x00L) {
5037 softc->unmap_max_lba = max_unmap_lba_cnt;
5038 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
5040 if (unmap_gran > 1) {
5041 softc->unmap_gran = unmap_gran;
5042 if (unmap_gran_align & 0x80000000) {
5043 softc->unmap_gran_align =
5044 unmap_gran_align & 0x7fffffff;
5049 * Unexpected UNMAP limits which means the
5050 * device doesn't actually support UNMAP
5052 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
5055 if (ws_max_blks != 0x00L)
5056 softc->ws_max_blks = ws_max_blks;
5059 error = daerror(done_ccb, CAM_RETRY_SELTO,
5060 SF_RETRY_UA|SF_NO_PRINT);
5061 if (error == ERESTART)
5063 else if (error != 0) {
5064 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5065 /* Don't wedge this device's queue */
5066 cam_release_devq(done_ccb->ccb_h.path,
5070 /*getcount_only*/0);
5074 * Failure here doesn't mean UNMAP is not
5075 * supported as this is an optional page.
5077 softc->unmap_max_lba = 1;
5078 softc->unmap_max_ranges = 1;
5082 free(block_limits, M_SCSIDA);
5083 xpt_release_ccb(done_ccb);
5084 softc->state = DA_STATE_PROBE_BDC;
5085 xpt_schedule(periph, priority);
5090 dadone_probebdc(struct cam_periph *periph, union ccb *done_ccb)
5092 struct scsi_vpd_block_device_characteristics *bdc;
5093 struct da_softc *softc;
5094 struct ccb_scsiio *csio;
5097 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probebdc\n"));
5099 softc = (struct da_softc *)periph->softc;
5100 priority = done_ccb->ccb_h.pinfo.priority;
5101 csio = &done_ccb->csio;
5102 bdc = (struct scsi_vpd_block_device_characteristics *)csio->data_ptr;
5104 cam_periph_assert(periph, MA_OWNED);
5106 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5110 * Disable queue sorting for non-rotational media
5113 u_int16_t old_rate = softc->disk->d_rotation_rate;
5115 valid_len = csio->dxfer_len - csio->resid;
5116 if (SBDC_IS_PRESENT(bdc, valid_len,
5117 medium_rotation_rate)) {
5118 softc->disk->d_rotation_rate =
5119 scsi_2btoul(bdc->medium_rotation_rate);
5120 if (softc->disk->d_rotation_rate ==
5121 SVPD_BDC_RATE_NON_ROTATING) {
5122 cam_iosched_set_sort_queue(
5123 softc->cam_iosched, 0);
5124 softc->rotating = 0;
5126 if (softc->disk->d_rotation_rate != old_rate) {
5127 disk_attr_changed(softc->disk,
5128 "GEOM::rotation_rate", M_NOWAIT);
5131 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
5132 && (softc->zone_mode == DA_ZONE_NONE)) {
5135 if (scsi_vpd_supported_page(periph,
5136 SVPD_ATA_INFORMATION))
5142 * The Zoned field will only be set for
5143 * Drive Managed and Host Aware drives. If
5144 * they are Host Managed, the device type
5145 * in the standard INQUIRY data should be
5146 * set to T_ZBC_HM (0x14).
5148 if ((bdc->flags & SVPD_ZBC_MASK) ==
5150 softc->zone_mode = DA_ZONE_HOST_AWARE;
5151 softc->zone_interface = (ata_proto) ?
5152 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5153 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
5155 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5156 softc->zone_interface = (ata_proto) ?
5157 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5158 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
5160 xpt_print(periph->path, "Unknown zoned "
5162 bdc->flags & SVPD_ZBC_MASK);
5167 error = daerror(done_ccb, CAM_RETRY_SELTO,
5168 SF_RETRY_UA|SF_NO_PRINT);
5169 if (error == ERESTART)
5171 else if (error != 0) {
5172 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5173 /* Don't wedge this device's queue */
5174 cam_release_devq(done_ccb->ccb_h.path,
5178 /*getcount_only*/0);
5183 free(bdc, M_SCSIDA);
5184 xpt_release_ccb(done_ccb);
5185 softc->state = DA_STATE_PROBE_ATA;
5186 xpt_schedule(periph, priority);
5191 dadone_probeata(struct cam_periph *periph, union ccb *done_ccb)
5193 struct ata_params *ata_params;
5194 struct ccb_scsiio *csio;
5195 struct da_softc *softc;
5201 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeata\n"));
5203 softc = (struct da_softc *)periph->softc;
5204 priority = done_ccb->ccb_h.pinfo.priority;
5205 csio = &done_ccb->csio;
5206 ata_params = (struct ata_params *)csio->data_ptr;
5207 ptr = (uint16_t *)ata_params;
5211 cam_periph_assert(periph, MA_OWNED);
5213 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5216 ata_param_fixup(ata_params);
5217 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
5218 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
5219 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
5220 if (ata_params->max_dsm_blocks != 0)
5221 softc->trim_max_ranges = min(
5222 softc->trim_max_ranges,
5223 ata_params->max_dsm_blocks *
5224 ATA_DSM_BLK_RANGES);
5227 * Disable queue sorting for non-rotational media
5230 old_rate = softc->disk->d_rotation_rate;
5231 softc->disk->d_rotation_rate = ata_params->media_rotation_rate;
5232 if (softc->disk->d_rotation_rate == ATA_RATE_NON_ROTATING) {
5233 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
5234 softc->rotating = 0;
5236 if (softc->disk->d_rotation_rate != old_rate) {
5237 disk_attr_changed(softc->disk,
5238 "GEOM::rotation_rate", M_NOWAIT);
5241 cam_periph_assert(periph, MA_OWNED);
5242 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
5243 softc->flags |= DA_FLAG_CAN_ATA_DMA;
5245 if (ata_params->support.extension & ATA_SUPPORT_GENLOG)
5246 softc->flags |= DA_FLAG_CAN_ATA_LOG;
5249 * At this point, if we have a SATA host aware drive,
5250 * we communicate via ATA passthrough unless the
5251 * SAT layer supports ZBC -> ZAC translation. In
5254 * XXX KDM figure out how to detect a host managed
5257 if (softc->zone_mode == DA_ZONE_NONE) {
5259 * Note that we don't override the zone
5260 * mode or interface if it has already been
5261 * set. This is because it has either been
5262 * set as a quirk, or when we probed the
5263 * SCSI Block Device Characteristics page,
5264 * the zoned field was set. The latter
5265 * means that the SAT layer supports ZBC to
5266 * ZAC translation, and we would prefer to
5267 * use that if it is available.
5269 if ((ata_params->support3 &
5270 ATA_SUPPORT_ZONE_MASK) ==
5271 ATA_SUPPORT_ZONE_HOST_AWARE) {
5272 softc->zone_mode = DA_ZONE_HOST_AWARE;
5273 softc->zone_interface =
5274 DA_ZONE_IF_ATA_PASS;
5275 } else if ((ata_params->support3 &
5276 ATA_SUPPORT_ZONE_MASK) ==
5277 ATA_SUPPORT_ZONE_DEV_MANAGED) {
5278 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5279 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
5284 error = daerror(done_ccb, CAM_RETRY_SELTO,
5285 SF_RETRY_UA|SF_NO_PRINT);
5286 if (error == ERESTART)
5288 else if (error != 0) {
5289 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5290 /* Don't wedge this device's queue */
5291 cam_release_devq(done_ccb->ccb_h.path,
5295 /*getcount_only*/0);
5300 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
5301 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
5303 * If the ATA IDENTIFY failed, we could be talking
5304 * to a SCSI drive, although that seems unlikely,
5305 * since the drive did report that it supported the
5306 * ATA Information VPD page. If the ATA IDENTIFY
5307 * succeeded, and the SAT layer doesn't support
5308 * ZBC -> ZAC translation, continue on to get the
5309 * directory of ATA logs, and complete the rest of
5310 * the ZAC probe. If the SAT layer does support
5311 * ZBC -> ZAC translation, we want to use that,
5312 * and we'll probe the SCSI Zoned Block Device
5313 * Characteristics VPD page next.
5316 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
5317 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
5318 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
5320 softc->state = DA_STATE_PROBE_ZONE;
5323 if (continue_probe != 0) {
5324 xpt_release_ccb(done_ccb);
5325 xpt_schedule(periph, priority);
5328 daprobedone(periph, done_ccb);
5333 dadone_probeatalogdir(struct cam_periph *periph, union ccb *done_ccb)
5335 struct da_softc *softc;
5336 struct ccb_scsiio *csio;
5340 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatalogdir\n"));
5342 softc = (struct da_softc *)periph->softc;
5343 priority = done_ccb->ccb_h.pinfo.priority;
5344 csio = &done_ccb->csio;
5346 cam_periph_assert(periph, MA_OWNED);
5347 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5349 softc->valid_logdir_len = 0;
5350 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
5351 softc->valid_logdir_len = csio->dxfer_len - csio->resid;
5352 if (softc->valid_logdir_len > 0)
5353 bcopy(csio->data_ptr, &softc->ata_logdir,
5354 min(softc->valid_logdir_len,
5355 sizeof(softc->ata_logdir)));
5357 * Figure out whether the Identify Device log is
5358 * supported. The General Purpose log directory
5359 * has a header, and lists the number of pages
5360 * available for each GP log identified by the
5361 * offset into the list.
5363 if ((softc->valid_logdir_len >=
5364 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
5365 && (le16dec(softc->ata_logdir.header) ==
5366 ATA_GP_LOG_DIR_VERSION)
5367 && (le16dec(&softc->ata_logdir.num_pages[
5368 (ATA_IDENTIFY_DATA_LOG *
5369 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
5370 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
5372 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5375 error = daerror(done_ccb, CAM_RETRY_SELTO,
5376 SF_RETRY_UA|SF_NO_PRINT);
5377 if (error == ERESTART)
5379 else if (error != 0) {
5381 * If we can't get the ATA log directory,
5382 * then ATA logs are effectively not
5383 * supported even if the bit is set in the
5386 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
5387 DA_FLAG_CAN_ATA_IDLOG);
5388 if ((done_ccb->ccb_h.status &
5389 CAM_DEV_QFRZN) != 0) {
5390 /* Don't wedge this device's queue */
5391 cam_release_devq(done_ccb->ccb_h.path,
5395 /*getcount_only*/0);
5400 free(csio->data_ptr, M_SCSIDA);
5403 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
5404 softc->state = DA_STATE_PROBE_ATA_IDDIR;
5405 xpt_release_ccb(done_ccb);
5406 xpt_schedule(periph, priority);
5409 daprobedone(periph, done_ccb);
5414 dadone_probeataiddir(struct cam_periph *periph, union ccb *done_ccb)
5416 struct da_softc *softc;
5417 struct ccb_scsiio *csio;
5421 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeataiddir\n"));
5423 softc = (struct da_softc *)periph->softc;
5424 priority = done_ccb->ccb_h.pinfo.priority;
5425 csio = &done_ccb->csio;
5427 cam_periph_assert(periph, MA_OWNED);
5429 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5430 off_t entries_offset, max_entries;
5433 softc->valid_iddir_len = 0;
5434 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
5435 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
5436 DA_FLAG_CAN_ATA_ZONE);
5437 softc->valid_iddir_len = csio->dxfer_len - csio->resid;
5438 if (softc->valid_iddir_len > 0)
5439 bcopy(csio->data_ptr, &softc->ata_iddir,
5440 min(softc->valid_iddir_len,
5441 sizeof(softc->ata_iddir)));
5444 __offsetof(struct ata_identify_log_pages,entries);
5445 max_entries = softc->valid_iddir_len - entries_offset;
5446 if ((softc->valid_iddir_len > (entries_offset + 1))
5447 && (le64dec(softc->ata_iddir.header) == ATA_IDLOG_REVISION)
5448 && (softc->ata_iddir.entry_count > 0)) {
5451 num_entries = softc->ata_iddir.entry_count;
5452 num_entries = min(num_entries,
5453 softc->valid_iddir_len - entries_offset);
5454 for (i = 0; i < num_entries && i < max_entries; i++) {
5455 if (softc->ata_iddir.entries[i] ==
5457 softc->flags |= DA_FLAG_CAN_ATA_SUPCAP;
5458 else if (softc->ata_iddir.entries[i] ==
5460 softc->flags |= DA_FLAG_CAN_ATA_ZONE;
5462 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP)
5463 && (softc->flags & DA_FLAG_CAN_ATA_ZONE))
5468 error = daerror(done_ccb, CAM_RETRY_SELTO,
5469 SF_RETRY_UA|SF_NO_PRINT);
5470 if (error == ERESTART)
5472 else if (error != 0) {
5474 * If we can't get the ATA Identify Data log
5475 * directory, then it effectively isn't
5476 * supported even if the ATA Log directory
5477 * a non-zero number of pages present for
5480 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5481 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5482 /* Don't wedge this device's queue */
5483 cam_release_devq(done_ccb->ccb_h.path,
5487 /*getcount_only*/0);
5492 free(csio->data_ptr, M_SCSIDA);
5494 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5495 softc->state = DA_STATE_PROBE_ATA_SUP;
5496 xpt_release_ccb(done_ccb);
5497 xpt_schedule(periph, priority);
5500 daprobedone(periph, done_ccb);
5505 dadone_probeatasup(struct cam_periph *periph, union ccb *done_ccb)
5507 struct da_softc *softc;
5508 struct ccb_scsiio *csio;
5512 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatasup\n"));
5514 softc = (struct da_softc *)periph->softc;
5515 priority = done_ccb->ccb_h.pinfo.priority;
5516 csio = &done_ccb->csio;
5518 cam_periph_assert(periph, MA_OWNED);
5520 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5523 struct ata_identify_log_sup_cap *sup_cap;
5526 sup_cap = (struct ata_identify_log_sup_cap *)csio->data_ptr;
5527 valid_len = csio->dxfer_len - csio->resid;
5528 needed_size = __offsetof(struct ata_identify_log_sup_cap,
5529 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5530 if (valid_len >= needed_size) {
5531 uint64_t zoned, zac_cap;
5533 zoned = le64dec(sup_cap->zoned_cap);
5534 if (zoned & ATA_ZONED_VALID) {
5536 * This should have already been
5537 * set, because this is also in the
5538 * ATA identify data.
5540 if ((zoned & ATA_ZONED_MASK) ==
5541 ATA_SUPPORT_ZONE_HOST_AWARE)
5542 softc->zone_mode = DA_ZONE_HOST_AWARE;
5543 else if ((zoned & ATA_ZONED_MASK) ==
5544 ATA_SUPPORT_ZONE_DEV_MANAGED)
5546 DA_ZONE_DRIVE_MANAGED;
5549 zac_cap = le64dec(sup_cap->sup_zac_cap);
5550 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5551 if (zac_cap & ATA_REPORT_ZONES_SUP)
5552 softc->zone_flags |=
5553 DA_ZONE_FLAG_RZ_SUP;
5554 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5555 softc->zone_flags |=
5556 DA_ZONE_FLAG_OPEN_SUP;
5557 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5558 softc->zone_flags |=
5559 DA_ZONE_FLAG_CLOSE_SUP;
5560 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5561 softc->zone_flags |=
5562 DA_ZONE_FLAG_FINISH_SUP;
5563 if (zac_cap & ATA_ND_RWP_SUP)
5564 softc->zone_flags |=
5565 DA_ZONE_FLAG_RWP_SUP;
5568 * This field was introduced in
5569 * ACS-4, r08 on April 28th, 2015.
5570 * If the drive firmware was written
5571 * to an earlier spec, it won't have
5572 * the field. So, assume all
5573 * commands are supported.
5575 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5579 error = daerror(done_ccb, CAM_RETRY_SELTO,
5580 SF_RETRY_UA|SF_NO_PRINT);
5581 if (error == ERESTART)
5583 else if (error != 0) {
5585 * If we can't get the ATA Identify Data
5586 * Supported Capabilities page, clear the
5589 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5591 * And clear zone capabilities.
5593 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5594 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5595 /* Don't wedge this device's queue */
5596 cam_release_devq(done_ccb->ccb_h.path,
5600 /*getcount_only*/0);
5605 free(csio->data_ptr, M_SCSIDA);
5607 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5608 softc->state = DA_STATE_PROBE_ATA_ZONE;
5609 xpt_release_ccb(done_ccb);
5610 xpt_schedule(periph, priority);
5613 daprobedone(periph, done_ccb);
5618 dadone_probeatazone(struct cam_periph *periph, union ccb *done_ccb)
5620 struct da_softc *softc;
5621 struct ccb_scsiio *csio;
5624 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatazone\n"));
5626 softc = (struct da_softc *)periph->softc;
5627 csio = &done_ccb->csio;
5629 cam_periph_assert(periph, MA_OWNED);
5631 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5632 struct ata_zoned_info_log *zi_log;
5636 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5638 valid_len = csio->dxfer_len - csio->resid;
5639 needed_size = __offsetof(struct ata_zoned_info_log,
5640 version_info) + 1 + sizeof(zi_log->version_info);
5641 if (valid_len >= needed_size) {
5644 tmpvar = le64dec(zi_log->zoned_cap);
5645 if (tmpvar & ATA_ZDI_CAP_VALID) {
5646 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5647 softc->zone_flags |=
5648 DA_ZONE_FLAG_URSWRZ;
5650 softc->zone_flags &=
5651 ~DA_ZONE_FLAG_URSWRZ;
5653 tmpvar = le64dec(zi_log->optimal_seq_zones);
5654 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5655 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5656 softc->optimal_seq_zones = (tmpvar &
5657 ATA_ZDI_OPT_SEQ_MASK);
5659 softc->zone_flags &= ~DA_ZONE_FLAG_OPT_SEQ_SET;
5660 softc->optimal_seq_zones = 0;
5663 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5664 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5665 softc->zone_flags |=
5666 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5667 softc->optimal_nonseq_zones =
5668 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5670 softc->zone_flags &=
5671 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5672 softc->optimal_nonseq_zones = 0;
5675 tmpvar = le64dec(zi_log->max_seq_req_zones);
5676 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5677 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5678 softc->max_seq_zones =
5679 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5681 softc->zone_flags &= ~DA_ZONE_FLAG_MAX_SEQ_SET;
5682 softc->max_seq_zones = 0;
5686 error = daerror(done_ccb, CAM_RETRY_SELTO,
5687 SF_RETRY_UA|SF_NO_PRINT);
5688 if (error == ERESTART)
5690 else if (error != 0) {
5691 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5692 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5694 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5695 /* Don't wedge this device's queue */
5696 cam_release_devq(done_ccb->ccb_h.path,
5700 /*getcount_only*/0);
5706 free(csio->data_ptr, M_SCSIDA);
5708 daprobedone(periph, done_ccb);
5713 dadone_probezone(struct cam_periph *periph, union ccb *done_ccb)
5715 struct da_softc *softc;
5716 struct ccb_scsiio *csio;
5719 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probezone\n"));
5721 softc = (struct da_softc *)periph->softc;
5722 csio = &done_ccb->csio;
5724 cam_periph_assert(periph, MA_OWNED);
5726 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5729 struct scsi_vpd_zoned_bdc *zoned_bdc;
5732 zoned_bdc = (struct scsi_vpd_zoned_bdc *)csio->data_ptr;
5733 valid_len = csio->dxfer_len - csio->resid;
5734 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5735 max_seq_req_zones) + 1 +
5736 sizeof(zoned_bdc->max_seq_req_zones);
5737 if ((valid_len >= needed_len)
5738 && (scsi_2btoul(zoned_bdc->page_length) >= SVPD_ZBDC_PL)) {
5739 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5740 softc->zone_flags |= DA_ZONE_FLAG_URSWRZ;
5742 softc->zone_flags &= ~DA_ZONE_FLAG_URSWRZ;
5743 softc->optimal_seq_zones =
5744 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5745 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5746 softc->optimal_nonseq_zones = scsi_4btoul(
5747 zoned_bdc->optimal_nonseq_zones);
5748 softc->zone_flags |= DA_ZONE_FLAG_OPT_NONSEQ_SET;
5749 softc->max_seq_zones =
5750 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5751 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5754 * All of the zone commands are mandatory for SCSI
5757 * XXX KDM this is valid as of September 2015.
5758 * Re-check this assumption once the SAT spec is
5759 * updated to support SCSI ZBC to ATA ZAC mapping.
5760 * Since ATA allows zone commands to be reported
5761 * as supported or not, this may not necessarily
5762 * be true for an ATA device behind a SAT (SCSI to
5763 * ATA Translation) layer.
5765 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5767 error = daerror(done_ccb, CAM_RETRY_SELTO,
5768 SF_RETRY_UA|SF_NO_PRINT);
5769 if (error == ERESTART)
5771 else if (error != 0) {
5772 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5773 /* Don't wedge this device's queue */
5774 cam_release_devq(done_ccb->ccb_h.path,
5778 /*getcount_only*/0);
5783 free(csio->data_ptr, M_SCSIDA);
5785 daprobedone(periph, done_ccb);
5790 dadone_tur(struct cam_periph *periph, union ccb *done_ccb)
5792 struct da_softc *softc;
5793 struct ccb_scsiio *csio;
5795 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_tur\n"));
5797 softc = (struct da_softc *)periph->softc;
5798 csio = &done_ccb->csio;
5800 cam_periph_assert(periph, MA_OWNED);
5802 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5804 if (daerror(done_ccb, CAM_RETRY_SELTO,
5805 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) == ERESTART)
5806 return; /* Will complete again, keep reference */
5807 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5808 cam_release_devq(done_ccb->ccb_h.path,
5812 /*getcount_only*/0);
5814 xpt_release_ccb(done_ccb);
5815 softc->flags &= ~DA_FLAG_TUR_PENDING;
5816 da_periph_release_locked(periph, DA_REF_TUR);
5821 dareprobe(struct cam_periph *periph)
5823 struct da_softc *softc;
5826 softc = (struct da_softc *)periph->softc;
5828 /* Probe in progress; don't interfere. */
5829 if (softc->state != DA_STATE_NORMAL)
5832 status = da_periph_acquire(periph, DA_REF_REPROBE);
5833 KASSERT(status == 0, ("dareprobe: cam_periph_acquire failed"));
5835 softc->state = DA_STATE_PROBE_WP;
5836 xpt_schedule(periph, CAM_PRIORITY_DEV);
5840 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5842 struct da_softc *softc;
5843 struct cam_periph *periph;
5844 int error, error_code, sense_key, asc, ascq;
5846 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5847 if (ccb->csio.bio != NULL)
5848 biotrack(ccb->csio.bio, __func__);
5851 periph = xpt_path_periph(ccb->ccb_h.path);
5852 softc = (struct da_softc *)periph->softc;
5854 cam_periph_assert(periph, MA_OWNED);
5857 * Automatically detect devices that do not support
5858 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5861 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5862 error = cmd6workaround(ccb);
5863 } else if (scsi_extract_sense_ccb(ccb,
5864 &error_code, &sense_key, &asc, &ascq)) {
5865 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5866 error = cmd6workaround(ccb);
5868 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5869 * query the capacity and notify upper layers.
5871 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5872 asc == 0x2A && ascq == 0x09) {
5873 xpt_print(periph->path, "Capacity data has changed\n");
5874 softc->flags &= ~DA_FLAG_PROBED;
5876 sense_flags |= SF_NO_PRINT;
5877 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5878 asc == 0x28 && ascq == 0x00) {
5879 softc->flags &= ~DA_FLAG_PROBED;
5880 disk_media_changed(softc->disk, M_NOWAIT);
5881 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5882 asc == 0x3F && ascq == 0x03) {
5883 xpt_print(periph->path, "INQUIRY data has changed\n");
5884 softc->flags &= ~DA_FLAG_PROBED;
5886 sense_flags |= SF_NO_PRINT;
5887 } else if (sense_key == SSD_KEY_NOT_READY &&
5888 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5889 softc->flags |= DA_FLAG_PACK_INVALID;
5890 disk_media_gone(softc->disk, M_NOWAIT);
5893 if (error == ERESTART)
5897 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5898 case CAM_CMD_TIMEOUT:
5901 case CAM_REQ_ABORTED:
5902 case CAM_REQ_CMP_ERR:
5903 case CAM_REQ_TERMIO:
5904 case CAM_UNREC_HBA_ERROR:
5905 case CAM_DATA_RUN_ERR:
5915 * Until we have a better way of doing pack validation,
5916 * don't treat UAs as errors.
5918 sense_flags |= SF_RETRY_UA;
5920 if (softc->quirks & DA_Q_RETRY_BUSY)
5921 sense_flags |= SF_RETRY_BUSY;
5922 return(cam_periph_error(ccb, cam_flags, sense_flags));
5926 damediapoll(void *arg)
5928 struct cam_periph *periph = arg;
5929 struct da_softc *softc = periph->softc;
5931 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5932 (softc->flags & DA_FLAG_TUR_PENDING) == 0 &&
5933 LIST_EMPTY(&softc->pending_ccbs)) {
5934 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
5935 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5939 /* Queue us up again */
5940 if (da_poll_period != 0)
5941 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5945 daprevent(struct cam_periph *periph, int action)
5947 struct da_softc *softc;
5951 cam_periph_assert(periph, MA_OWNED);
5952 softc = (struct da_softc *)periph->softc;
5954 if (((action == PR_ALLOW)
5955 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5956 || ((action == PR_PREVENT)
5957 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5961 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5963 scsi_prevent(&ccb->csio,
5971 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5972 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5975 if (action == PR_ALLOW)
5976 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5978 softc->flags |= DA_FLAG_PACK_LOCKED;
5981 xpt_release_ccb(ccb);
5985 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5986 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5988 struct ccb_calc_geometry ccg;
5989 struct da_softc *softc;
5990 struct disk_params *dp;
5991 u_int lbppbe, lalba;
5994 softc = (struct da_softc *)periph->softc;
5996 dp = &softc->params;
5997 dp->secsize = block_len;
5998 dp->sectors = maxsector + 1;
5999 if (rcaplong != NULL) {
6000 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
6001 lalba = scsi_2btoul(rcaplong->lalba_lbp);
6002 lalba &= SRC16_LALBA_A;
6003 if (rcaplong->prot & SRC16_PROT_EN)
6004 softc->p_type = ((rcaplong->prot & SRC16_P_TYPE) >>
6005 SRC16_P_TYPE_SHIFT) + 1;
6015 dp->stripesize = block_len << lbppbe;
6016 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
6018 } else if (softc->quirks & DA_Q_4K) {
6019 dp->stripesize = 4096;
6020 dp->stripeoffset = 0;
6021 } else if (softc->unmap_gran != 0) {
6022 dp->stripesize = block_len * softc->unmap_gran;
6023 dp->stripeoffset = (dp->stripesize - block_len *
6024 softc->unmap_gran_align) % dp->stripesize;
6027 dp->stripeoffset = 0;
6030 * Have the controller provide us with a geometry
6031 * for this disk. The only time the geometry
6032 * matters is when we boot and the controller
6033 * is the only one knowledgeable enough to come
6034 * up with something that will make this a bootable
6037 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6038 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
6039 ccg.block_size = dp->secsize;
6040 ccg.volume_size = dp->sectors;
6042 ccg.secs_per_track = 0;
6044 xpt_action((union ccb*)&ccg);
6045 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
6047 * We don't know what went wrong here- but just pick
6048 * a geometry so we don't have nasty things like divide
6052 dp->secs_per_track = 255;
6053 dp->cylinders = dp->sectors / (255 * 255);
6054 if (dp->cylinders == 0) {
6058 dp->heads = ccg.heads;
6059 dp->secs_per_track = ccg.secs_per_track;
6060 dp->cylinders = ccg.cylinders;
6064 * If the user supplied a read capacity buffer, and if it is
6065 * different than the previous buffer, update the data in the EDT.
6066 * If it's the same, we don't bother. This avoids sending an
6067 * update every time someone opens this device.
6069 if ((rcaplong != NULL)
6070 && (bcmp(rcaplong, &softc->rcaplong,
6071 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
6072 struct ccb_dev_advinfo cdai;
6074 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6075 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
6076 cdai.buftype = CDAI_TYPE_RCAPLONG;
6077 cdai.flags = CDAI_FLAG_STORE;
6078 cdai.bufsiz = rcap_len;
6079 cdai.buf = (uint8_t *)rcaplong;
6080 xpt_action((union ccb *)&cdai);
6081 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
6082 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
6083 if (cdai.ccb_h.status != CAM_REQ_CMP) {
6084 xpt_print(periph->path, "%s: failed to set read "
6085 "capacity advinfo\n", __func__);
6086 /* Use cam_error_print() to decode the status */
6087 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
6090 bcopy(rcaplong, &softc->rcaplong,
6091 min(sizeof(softc->rcaplong), rcap_len));
6095 softc->disk->d_sectorsize = softc->params.secsize;
6096 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
6097 softc->disk->d_stripesize = softc->params.stripesize;
6098 softc->disk->d_stripeoffset = softc->params.stripeoffset;
6099 /* XXX: these are not actually "firmware" values, so they may be wrong */
6100 softc->disk->d_fwsectors = softc->params.secs_per_track;
6101 softc->disk->d_fwheads = softc->params.heads;
6102 softc->disk->d_devstat->block_size = softc->params.secsize;
6103 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
6105 error = disk_resize(softc->disk, M_NOWAIT);
6107 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
6111 dasendorderedtag(void *arg)
6113 struct cam_periph *periph = arg;
6114 struct da_softc *softc = periph->softc;
6116 cam_periph_assert(periph, MA_OWNED);
6117 if (da_send_ordered) {
6118 if (!LIST_EMPTY(&softc->pending_ccbs)) {
6119 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
6120 softc->flags |= DA_FLAG_NEED_OTAG;
6121 softc->flags &= ~DA_FLAG_WAS_OTAG;
6125 /* Queue us up again */
6126 callout_reset(&softc->sendordered_c,
6127 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
6128 dasendorderedtag, periph);
6132 * Step through all DA peripheral drivers, and if the device is still open,
6133 * sync the disk cache to physical media.
6136 dashutdown(void * arg, int howto)
6138 struct cam_periph *periph;
6139 struct da_softc *softc;
6143 CAM_PERIPH_FOREACH(periph, &dadriver) {
6144 softc = (struct da_softc *)periph->softc;
6145 if (SCHEDULER_STOPPED()) {
6146 /* If we paniced with the lock held, do not recurse. */
6147 if (!cam_periph_owned(periph) &&
6148 (softc->flags & DA_FLAG_OPEN)) {
6149 dadump(softc->disk, NULL, 0, 0, 0);
6153 cam_periph_lock(periph);
6156 * We only sync the cache if the drive is still open, and
6157 * if the drive is capable of it..
6159 if (((softc->flags & DA_FLAG_OPEN) == 0)
6160 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
6161 cam_periph_unlock(periph);
6165 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
6166 scsi_synchronize_cache(&ccb->csio,
6170 /*begin_lba*/0, /* whole disk */
6175 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
6176 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
6177 softc->disk->d_devstat);
6179 xpt_print(periph->path, "Synchronize cache failed\n");
6180 xpt_release_ccb(ccb);
6181 cam_periph_unlock(periph);
6185 #else /* !_KERNEL */
6188 * XXX These are only left out of the kernel build to silence warnings. If,
6189 * for some reason these functions are used in the kernel, the ifdefs should
6190 * be moved so they are included both in the kernel and userland.
6193 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
6194 void (*cbfcnp)(struct cam_periph *, union ccb *),
6195 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
6196 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6199 struct scsi_format_unit *scsi_cmd;
6201 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
6202 scsi_cmd->opcode = FORMAT_UNIT;
6203 scsi_cmd->byte2 = byte2;
6204 scsi_ulto2b(ileave, scsi_cmd->interleave);
6209 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6219 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
6220 void (*cbfcnp)(struct cam_periph *, union ccb *),
6221 uint8_t tag_action, uint8_t list_format,
6222 uint32_t addr_desc_index, uint8_t *data_ptr,
6223 uint32_t dxfer_len, int minimum_cmd_size,
6224 uint8_t sense_len, uint32_t timeout)
6229 * These conditions allow using the 10 byte command. Otherwise we
6230 * need to use the 12 byte command.
6232 if ((minimum_cmd_size <= 10)
6233 && (addr_desc_index == 0)
6234 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
6235 struct scsi_read_defect_data_10 *cdb10;
6237 cdb10 = (struct scsi_read_defect_data_10 *)
6238 &csio->cdb_io.cdb_bytes;
6240 cdb_len = sizeof(*cdb10);
6241 bzero(cdb10, cdb_len);
6242 cdb10->opcode = READ_DEFECT_DATA_10;
6243 cdb10->format = list_format;
6244 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
6246 struct scsi_read_defect_data_12 *cdb12;
6248 cdb12 = (struct scsi_read_defect_data_12 *)
6249 &csio->cdb_io.cdb_bytes;
6251 cdb_len = sizeof(*cdb12);
6252 bzero(cdb12, cdb_len);
6253 cdb12->opcode = READ_DEFECT_DATA_12;
6254 cdb12->format = list_format;
6255 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
6256 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
6262 /*flags*/ CAM_DIR_IN,
6272 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
6273 void (*cbfcnp)(struct cam_periph *, union ccb *),
6274 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
6275 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6278 struct scsi_sanitize *scsi_cmd;
6280 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
6281 scsi_cmd->opcode = SANITIZE;
6282 scsi_cmd->byte2 = byte2;
6283 scsi_cmd->control = control;
6284 scsi_ulto2b(dxfer_len, scsi_cmd->length);
6289 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6298 #endif /* _KERNEL */
6301 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
6302 void (*cbfcnp)(struct cam_periph *, union ccb *),
6303 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
6304 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
6305 uint8_t sense_len, uint32_t timeout)
6307 struct scsi_zbc_out *scsi_cmd;
6309 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
6310 scsi_cmd->opcode = ZBC_OUT;
6311 scsi_cmd->service_action = service_action;
6312 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
6313 scsi_cmd->zone_flags = zone_flags;
6318 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6328 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
6329 void (*cbfcnp)(struct cam_periph *, union ccb *),
6330 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
6331 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
6332 uint8_t sense_len, uint32_t timeout)
6334 struct scsi_zbc_in *scsi_cmd;
6336 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
6337 scsi_cmd->opcode = ZBC_IN;
6338 scsi_cmd->service_action = service_action;
6339 scsi_ulto4b(dxfer_len, scsi_cmd->length);
6340 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
6341 scsi_cmd->zone_options = zone_options;
6346 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
6357 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
6358 void (*cbfcnp)(struct cam_periph *, union ccb *),
6359 uint8_t tag_action, int use_ncq,
6360 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6361 uint8_t *data_ptr, uint32_t dxfer_len,
6362 uint8_t *cdb_storage, size_t cdb_storage_len,
6363 uint8_t sense_len, uint32_t timeout)
6365 uint8_t command_out, protocol, ata_flags;
6366 uint16_t features_out;
6367 uint32_t sectors_out, auxiliary;
6373 command_out = ATA_ZAC_MANAGEMENT_OUT;
6374 features_out = (zm_action & 0xf) | (zone_flags << 8);
6375 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6376 if (dxfer_len == 0) {
6377 protocol = AP_PROTO_NON_DATA;
6378 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6381 protocol = AP_PROTO_DMA;
6382 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
6383 AP_FLAG_TDIR_TO_DEV;
6384 sectors_out = ((dxfer_len >> 9) & 0xffff);
6388 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6389 if (dxfer_len == 0) {
6390 command_out = ATA_NCQ_NON_DATA;
6391 features_out = ATA_NCQ_ZAC_MGMT_OUT;
6393 * We're assuming the SCSI to ATA translation layer
6394 * will set the NCQ tag number in the tag field.
6395 * That isn't clear from the SAT-4 spec (as of rev 05).
6398 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6400 command_out = ATA_SEND_FPDMA_QUEUED;
6402 * Note that we're defaulting to normal priority,
6403 * and assuming that the SCSI to ATA translation
6404 * layer will insert the NCQ tag number in the tag
6405 * field. That isn't clear in the SAT-4 spec (as
6408 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
6410 ata_flags |= AP_FLAG_TLEN_FEAT |
6411 AP_FLAG_TDIR_TO_DEV;
6414 * For SEND FPDMA QUEUED, the transfer length is
6415 * encoded in the FEATURE register, and 0 means
6416 * that 65536 512 byte blocks are to be tranferred.
6417 * In practice, it seems unlikely that we'll see
6418 * a transfer that large, and it may confuse the
6419 * the SAT layer, because generally that means that
6420 * 0 bytes should be transferred.
6422 if (dxfer_len == (65536 * 512)) {
6424 } else if (dxfer_len <= (65535 * 512)) {
6425 features_out = ((dxfer_len >> 9) & 0xffff);
6427 /* The transfer is too big. */
6434 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
6435 protocol = AP_PROTO_FPDMA;
6438 protocol |= AP_EXTEND;
6440 retval = scsi_ata_pass(csio,
6443 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6445 /*protocol*/ protocol,
6446 /*ata_flags*/ ata_flags,
6447 /*features*/ features_out,
6448 /*sector_count*/ sectors_out,
6450 /*command*/ command_out,
6453 /*auxiliary*/ auxiliary,
6455 /*data_ptr*/ data_ptr,
6456 /*dxfer_len*/ dxfer_len,
6457 /*cdb_storage*/ cdb_storage,
6458 /*cdb_storage_len*/ cdb_storage_len,
6459 /*minimum_cmd_size*/ 0,
6460 /*sense_len*/ SSD_FULL_SIZE,
6461 /*timeout*/ timeout);
6469 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
6470 void (*cbfcnp)(struct cam_periph *, union ccb *),
6471 uint8_t tag_action, int use_ncq,
6472 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6473 uint8_t *data_ptr, uint32_t dxfer_len,
6474 uint8_t *cdb_storage, size_t cdb_storage_len,
6475 uint8_t sense_len, uint32_t timeout)
6477 uint8_t command_out, protocol;
6478 uint16_t features_out, sectors_out;
6484 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
6487 command_out = ATA_ZAC_MANAGEMENT_IN;
6488 /* XXX KDM put a macro here */
6489 features_out = (zm_action & 0xf) | (zone_flags << 8);
6490 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
6491 protocol = AP_PROTO_DMA;
6492 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
6495 ata_flags |= AP_FLAG_TLEN_FEAT;
6497 command_out = ATA_RECV_FPDMA_QUEUED;
6498 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6501 * For RECEIVE FPDMA QUEUED, the transfer length is
6502 * encoded in the FEATURE register, and 0 means
6503 * that 65536 512 byte blocks are to be tranferred.
6504 * In practice, it seems unlikely that we'll see
6505 * a transfer that large, and it may confuse the
6506 * the SAT layer, because generally that means that
6507 * 0 bytes should be transferred.
6509 if (dxfer_len == (65536 * 512)) {
6511 } else if (dxfer_len <= (65535 * 512)) {
6512 features_out = ((dxfer_len >> 9) & 0xffff);
6514 /* The transfer is too big. */
6518 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6519 protocol = AP_PROTO_FPDMA;
6522 protocol |= AP_EXTEND;
6524 retval = scsi_ata_pass(csio,
6527 /*flags*/ CAM_DIR_IN,
6529 /*protocol*/ protocol,
6530 /*ata_flags*/ ata_flags,
6531 /*features*/ features_out,
6532 /*sector_count*/ sectors_out,
6534 /*command*/ command_out,
6537 /*auxiliary*/ auxiliary,
6539 /*data_ptr*/ data_ptr,
6540 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6541 /*cdb_storage*/ cdb_storage,
6542 /*cdb_storage_len*/ cdb_storage_len,
6543 /*minimum_cmd_size*/ 0,
6544 /*sense_len*/ SSD_FULL_SIZE,
6545 /*timeout*/ timeout);