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>
67 #include <cam/cam_sim.h>
68 #include <cam/cam_iosched.h>
70 #include <cam/scsi/scsi_message.h>
71 #include <cam/scsi/scsi_da.h>
75 * Note that there are probe ordering dependencies here. The order isn't
76 * controlled by this enumeration, but by explicit state transitions in
77 * dastart() and dadone(). Here are some of the dependencies:
79 * 1. RC should come first, before RC16, unless there is evidence that RC16
81 * 2. BDC needs to come before any of the ATA probes, or the ZONE probe.
82 * 3. The ATA probes should go in this order:
83 * ATA -> LOGDIR -> IDDIR -> SUP -> ATA_ZONE
90 DA_STATE_PROBE_BLK_LIMITS,
93 DA_STATE_PROBE_ATA_LOGDIR,
94 DA_STATE_PROBE_ATA_IDDIR,
95 DA_STATE_PROBE_ATA_SUP,
96 DA_STATE_PROBE_ATA_ZONE,
102 DA_FLAG_PACK_INVALID = 0x000001,
103 DA_FLAG_NEW_PACK = 0x000002,
104 DA_FLAG_PACK_LOCKED = 0x000004,
105 DA_FLAG_PACK_REMOVABLE = 0x000008,
106 DA_FLAG_NEED_OTAG = 0x000020,
107 DA_FLAG_WAS_OTAG = 0x000040,
108 DA_FLAG_RETRY_UA = 0x000080,
109 DA_FLAG_OPEN = 0x000100,
110 DA_FLAG_SCTX_INIT = 0x000200,
111 DA_FLAG_CAN_RC16 = 0x000400,
112 DA_FLAG_PROBED = 0x000800,
113 DA_FLAG_DIRTY = 0x001000,
114 DA_FLAG_ANNOUNCED = 0x002000,
115 DA_FLAG_CAN_ATA_DMA = 0x004000,
116 DA_FLAG_CAN_ATA_LOG = 0x008000,
117 DA_FLAG_CAN_ATA_IDLOG = 0x010000,
118 DA_FLAG_CAN_ATA_SUPCAP = 0x020000,
119 DA_FLAG_CAN_ATA_ZONE = 0x040000,
120 DA_FLAG_TUR_PENDING = 0x080000
125 DA_Q_NO_SYNC_CACHE = 0x01,
126 DA_Q_NO_6_BYTE = 0x02,
127 DA_Q_NO_PREVENT = 0x04,
130 DA_Q_NO_UNMAP = 0x20,
131 DA_Q_RETRY_BUSY = 0x40,
133 DA_Q_STRICT_UNMAP = 0x100,
137 #define DA_Q_BIT_STRING \
139 "\001NO_SYNC_CACHE" \
151 DA_CCB_PROBE_RC = 0x01,
152 DA_CCB_PROBE_RC16 = 0x02,
153 DA_CCB_PROBE_LBP = 0x03,
154 DA_CCB_PROBE_BLK_LIMITS = 0x04,
155 DA_CCB_PROBE_BDC = 0x05,
156 DA_CCB_PROBE_ATA = 0x06,
157 DA_CCB_BUFFER_IO = 0x07,
159 DA_CCB_DELETE = 0x0B,
161 DA_CCB_PROBE_ZONE = 0x0D,
162 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
163 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
164 DA_CCB_PROBE_ATA_SUP = 0x10,
165 DA_CCB_PROBE_ATA_ZONE = 0x11,
166 DA_CCB_PROBE_WP = 0x12,
167 DA_CCB_TYPE_MASK = 0x1F,
168 DA_CCB_RETRY_UA = 0x20
172 * Order here is important for method choice
174 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
175 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
176 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
177 * import taking 5mins.
188 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
189 DA_DELETE_MAX = DA_DELETE_ZERO
193 * For SCSI, host managed drives show up as a separate device type. For
194 * ATA, host managed drives also have a different device signature.
195 * XXX KDM figure out the ATA host managed signature.
199 DA_ZONE_DRIVE_MANAGED = 0x01,
200 DA_ZONE_HOST_AWARE = 0x02,
201 DA_ZONE_HOST_MANAGED = 0x03
205 * We distinguish between these interface cases in addition to the drive type:
206 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
207 * o ATA drive behind a SCSI translation layer that does not know about
208 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
209 * case, we would need to share the ATA code with the ada(4) driver.
219 DA_ZONE_FLAG_RZ_SUP = 0x0001,
220 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
221 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
222 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
223 DA_ZONE_FLAG_RWP_SUP = 0x0010,
224 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
225 DA_ZONE_FLAG_OPEN_SUP |
226 DA_ZONE_FLAG_CLOSE_SUP |
227 DA_ZONE_FLAG_FINISH_SUP |
228 DA_ZONE_FLAG_RWP_SUP),
229 DA_ZONE_FLAG_URSWRZ = 0x0020,
230 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
231 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
232 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
233 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
234 DA_ZONE_FLAG_OPT_NONSEQ_SET |
235 DA_ZONE_FLAG_MAX_SEQ_SET)
238 static struct da_zone_desc {
241 } da_zone_desc_table[] = {
242 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
243 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
244 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
245 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
246 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
249 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
251 static da_delete_func_t da_delete_trim;
252 static da_delete_func_t da_delete_unmap;
253 static da_delete_func_t da_delete_ws;
255 static const void * da_delete_functions[] = {
265 static const char *da_delete_method_names[] =
266 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
267 static const char *da_delete_method_desc[] =
268 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
269 "WRITE SAME(10) with UNMAP", "ZERO" };
271 /* Offsets into our private area for storing information */
272 #define ccb_state ppriv_field0
273 #define ccb_bp ppriv_ptr1
278 u_int8_t secs_per_track;
279 u_int32_t secsize; /* Number of bytes/sector */
280 u_int64_t sectors; /* total number sectors */
285 #define UNMAP_RANGE_MAX 0xffffffff
286 #define UNMAP_HEAD_SIZE 8
287 #define UNMAP_RANGE_SIZE 16
288 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
289 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
292 #define WS10_MAX_BLKS 0xffff
293 #define WS16_MAX_BLKS 0xffffffff
294 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
295 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
297 #define DA_WORK_TUR (1 << 16)
308 DA_REF_MAX /* KEEP LAST */
312 struct cam_iosched_softc *cam_iosched;
313 struct bio_queue_head delete_run_queue;
314 LIST_HEAD(, ccb_hdr) pending_ccbs;
315 int refcount; /* Active xpt_action() calls */
319 int minimum_cmd_size;
322 int delete_available; /* Delete methods possibly available */
323 da_zone_mode zone_mode;
324 da_zone_interface zone_interface;
325 da_zone_flags zone_flags;
326 struct ata_gp_log_dir ata_logdir;
327 int valid_logdir_len;
328 struct ata_identify_log_pages ata_iddir;
330 uint64_t optimal_seq_zones;
331 uint64_t optimal_nonseq_zones;
332 uint64_t max_seq_zones;
334 uint32_t unmap_max_ranges;
335 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
337 uint32_t unmap_gran_align;
338 uint64_t ws_max_blks;
340 uint64_t trim_ranges;
342 da_delete_methods delete_method_pref;
343 da_delete_methods delete_method;
344 da_delete_func_t *delete_func;
348 struct disk_params params;
351 struct task sysctl_task;
352 struct sysctl_ctx_list sysctl_ctx;
353 struct sysctl_oid *sysctl_tree;
354 struct callout sendordered_c;
356 uint8_t unmap_buf[UNMAP_BUF_SIZE];
357 struct scsi_read_capacity_data_long rcaplong;
358 struct callout mediapoll_c;
359 int ref_flags[DA_REF_MAX];
361 struct sysctl_ctx_list sysctl_stats_ctx;
362 struct sysctl_oid *sysctl_stats_tree;
367 #define DA_ANNOUNCETMP_SZ 160
368 char announce_temp[DA_ANNOUNCETMP_SZ];
369 #define DA_ANNOUNCE_SZ 400
370 char announcebuf[DA_ANNOUNCE_SZ];
373 #define dadeleteflag(softc, delete_method, enable) \
375 softc->delete_available |= (1 << delete_method); \
377 softc->delete_available &= ~(1 << delete_method); \
380 struct da_quirk_entry {
381 struct scsi_inquiry_pattern inq_pat;
385 static const char quantum[] = "QUANTUM";
386 static const char microp[] = "MICROP";
388 static struct da_quirk_entry da_quirk_table[] =
390 /* SPI, FC devices */
393 * Fujitsu M2513A MO drives.
394 * Tested devices: M2513A2 firmware versions 1200 & 1300.
395 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
396 * Reported by: W.Scholten <whs@xs4all.nl>
398 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
399 /*quirks*/ DA_Q_NO_SYNC_CACHE
403 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
404 /*quirks*/ DA_Q_NO_SYNC_CACHE
408 * This particular Fujitsu drive doesn't like the
409 * synchronize cache command.
410 * Reported by: Tom Jackson <toj@gorilla.net>
412 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
413 /*quirks*/ DA_Q_NO_SYNC_CACHE
417 * This drive doesn't like the synchronize cache command
418 * either. Reported by: Matthew Jacob <mjacob@feral.com>
419 * in NetBSD PR kern/6027, August 24, 1998.
421 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
422 /*quirks*/ DA_Q_NO_SYNC_CACHE
426 * This drive doesn't like the synchronize cache command
427 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
430 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
431 /*quirks*/ DA_Q_NO_SYNC_CACHE
435 * Doesn't like the synchronize cache command.
436 * Reported by: Blaz Zupan <blaz@gold.amis.net>
438 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
439 /*quirks*/ DA_Q_NO_SYNC_CACHE
443 * Doesn't like the synchronize cache command.
444 * Reported by: Blaz Zupan <blaz@gold.amis.net>
446 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
447 /*quirks*/ DA_Q_NO_SYNC_CACHE
451 * Doesn't like the synchronize cache command.
453 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
454 /*quirks*/ DA_Q_NO_SYNC_CACHE
458 * Doesn't like the synchronize cache command.
459 * Reported by: walter@pelissero.de
461 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
462 /*quirks*/ DA_Q_NO_SYNC_CACHE
466 * Doesn't work correctly with 6 byte reads/writes.
467 * Returns illegal request, and points to byte 9 of the
469 * Reported by: Adam McDougall <bsdx@spawnet.com>
471 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
472 /*quirks*/ DA_Q_NO_6_BYTE
476 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
477 /*quirks*/ DA_Q_NO_6_BYTE
481 * Doesn't like the synchronize cache command.
482 * Reported by: walter@pelissero.de
484 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
485 /*quirks*/ DA_Q_NO_SYNC_CACHE
489 * The CISS RAID controllers do not support SYNC_CACHE
491 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
492 /*quirks*/ DA_Q_NO_SYNC_CACHE
496 * The STEC SSDs sometimes hang on UNMAP.
498 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
499 /*quirks*/ DA_Q_NO_UNMAP
503 * VMware returns BUSY status when storage has transient
504 * connectivity problems, so better wait.
505 * Also VMware returns odd errors on misaligned UNMAPs.
507 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
508 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
510 /* USB mass storage devices supported by umass(4) */
513 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
516 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
517 /*quirks*/ DA_Q_NO_SYNC_CACHE
521 * Power Quotient Int. (PQI) USB flash key
524 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
525 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
529 * Creative Nomad MUVO mp3 player (USB)
532 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
533 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
537 * Jungsoft NEXDISK USB flash key
540 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
541 /*quirks*/ DA_Q_NO_SYNC_CACHE
545 * FreeDik USB Mini Data Drive
548 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
549 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
553 * Sigmatel USB Flash MP3 Player
556 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
557 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
561 * Neuros USB Digital Audio Computer
564 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
565 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
569 * SEAGRAND NP-900 MP3 Player
572 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
573 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
577 * iRiver iFP MP3 player (with UMS Firmware)
578 * PR: kern/54881, i386/63941, kern/66124
580 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
581 /*quirks*/ DA_Q_NO_SYNC_CACHE
585 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
588 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
589 /*quirks*/ DA_Q_NO_SYNC_CACHE
593 * ZICPlay USB MP3 Player with FM
596 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
597 /*quirks*/ DA_Q_NO_SYNC_CACHE
601 * TEAC USB floppy mechanisms
603 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
604 /*quirks*/ DA_Q_NO_SYNC_CACHE
608 * Kingston DataTraveler II+ USB Pen-Drive.
609 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
611 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
612 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
620 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
621 /*quirks*/ DA_Q_NO_SYNC_CACHE
625 * Motorola E398 Mobile Phone (TransFlash memory card).
626 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
629 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
630 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
634 * Qware BeatZkey! Pro
637 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
638 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
642 * Time DPA20B 1GB MP3 Player
645 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
646 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
650 * Samsung USB key 128Mb
653 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
654 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
658 * Kingston DataTraveler 2.0 USB Flash memory.
661 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
662 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
666 * Creative MUVO Slim mp3 player (USB)
669 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
670 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
674 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
677 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
678 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
682 * SanDisk Micro Cruzer 128MB
685 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
686 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
690 * TOSHIBA TransMemory USB sticks
693 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
694 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
698 * PNY USB 3.0 Flash Drives
700 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
701 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
706 * PR: usb/75578, usb/72344, usb/65436
708 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
709 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
715 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
716 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16
720 * Genesys 6-in-1 Card Reader
723 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
724 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
728 * Rekam Digital CAMERA
731 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
732 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
736 * iRiver H10 MP3 player
739 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
740 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
744 * iRiver U10 MP3 player
747 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
748 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
755 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
756 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
760 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
763 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
764 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
771 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
772 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
776 * Philips USB Key Audio KEY013
779 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
780 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
787 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
788 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
795 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
796 /*quirks*/ DA_Q_NO_SYNC_CACHE
800 * I/O Magic USB flash - Giga Bank
803 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
804 /*quirks*/ DA_Q_NO_SYNC_CACHE
808 * JoyFly 128mb USB Flash Drive
811 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
812 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
819 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
820 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
824 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
827 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
828 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
832 * Samsung YP-U3 mp3-player
835 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
836 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
839 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
840 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
844 * Sony Cyber-Shot DSC cameras
847 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
848 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
851 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
852 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
855 /* At least several Transcent USB sticks lie on RC16. */
856 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
857 "*"}, /*quirks*/ DA_Q_NO_RC16
861 * I-O Data USB Flash Disk
864 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
865 "*"}, /*quirks*/ DA_Q_NO_RC16
869 * SLC CHIPFANCIER USB drives
870 * PR: usb/234503 (RC10 right, RC16 wrong)
871 * 16GB, 32GB and 128GB confirmed to have same issue
873 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*SLC", "CHIPFANCIER",
874 "*"}, /*quirks*/ DA_Q_NO_RC16
876 /* ATA/SATA devices over SAS/USB/... */
879 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SanDisk SD8SB8U1*", "*" },
883 /* Hitachi Advanced Format (4k) drives */
884 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
888 /* Micron Advanced Format (4k) drives */
889 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
893 /* Samsung Advanced Format (4k) drives */
894 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
898 /* Samsung Advanced Format (4k) drives */
899 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
903 /* Samsung Advanced Format (4k) drives */
904 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
908 /* Samsung Advanced Format (4k) drives */
909 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
913 /* Seagate Barracuda Green Advanced Format (4k) drives */
914 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
918 /* Seagate Barracuda Green Advanced Format (4k) drives */
919 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
923 /* Seagate Barracuda Green Advanced Format (4k) drives */
924 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
928 /* Seagate Barracuda Green Advanced Format (4k) drives */
929 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
933 /* Seagate Barracuda Green Advanced Format (4k) drives */
934 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
938 /* Seagate Barracuda Green Advanced Format (4k) drives */
939 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
943 /* Seagate Momentus Advanced Format (4k) drives */
944 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
948 /* Seagate Momentus Advanced Format (4k) drives */
949 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
953 /* Seagate Momentus Advanced Format (4k) drives */
954 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
958 /* Seagate Momentus Advanced Format (4k) drives */
959 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
963 /* Seagate Momentus Advanced Format (4k) drives */
964 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
968 /* Seagate Momentus Advanced Format (4k) drives */
969 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
973 /* Seagate Momentus Advanced Format (4k) drives */
974 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
978 /* Seagate Momentus Advanced Format (4k) drives */
979 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
983 /* Seagate Momentus Advanced Format (4k) drives */
984 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
988 /* Seagate Momentus Advanced Format (4k) drives */
989 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
993 /* Seagate Momentus Advanced Format (4k) drives */
994 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
998 /* Seagate Momentus Advanced Format (4k) drives */
999 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
1003 /* Seagate Momentus Advanced Format (4k) drives */
1004 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
1008 /* Seagate Momentus Advanced Format (4k) drives */
1009 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
1013 /* Seagate Momentus Thin Advanced Format (4k) drives */
1014 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
1018 /* Seagate Momentus Thin Advanced Format (4k) drives */
1019 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
1023 /* WDC Caviar Green Advanced Format (4k) drives */
1024 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
1028 /* WDC Caviar Green Advanced Format (4k) drives */
1029 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
1033 /* WDC Caviar Green Advanced Format (4k) drives */
1034 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
1038 /* WDC Caviar Green Advanced Format (4k) drives */
1039 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
1043 /* WDC Caviar Green Advanced Format (4k) drives */
1044 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1048 /* WDC Caviar Green Advanced Format (4k) drives */
1049 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1053 /* WDC Caviar Green Advanced Format (4k) drives */
1054 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1058 /* WDC Caviar Green Advanced Format (4k) drives */
1059 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1063 /* WDC Scorpio Black Advanced Format (4k) drives */
1064 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1068 /* WDC Scorpio Black Advanced Format (4k) drives */
1069 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1073 /* WDC Scorpio Black Advanced Format (4k) drives */
1074 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1078 /* WDC Scorpio Black Advanced Format (4k) drives */
1079 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1083 /* WDC Scorpio Blue Advanced Format (4k) drives */
1084 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1088 /* WDC Scorpio Blue Advanced Format (4k) drives */
1089 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1093 /* WDC Scorpio Blue Advanced Format (4k) drives */
1094 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1098 /* WDC Scorpio Blue Advanced Format (4k) drives */
1099 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1104 * Olympus digital cameras (C-3040ZOOM, C-2040ZOOM, C-1)
1107 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "C*", "*"},
1108 /*quirks*/ DA_Q_NO_6_BYTE | DA_Q_NO_SYNC_CACHE
1112 * Olympus digital cameras (D-370)
1115 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "D*", "*"},
1116 /*quirks*/ DA_Q_NO_6_BYTE
1120 * Olympus digital cameras (E-100RS, E-10).
1123 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "E*", "*"},
1124 /*quirks*/ DA_Q_NO_6_BYTE | DA_Q_NO_SYNC_CACHE
1128 * Olympus FE-210 camera
1130 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1131 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1135 * Pentax Digital Camera
1138 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PENTAX", "DIGITAL CAMERA",
1139 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1143 * LG UP3S MP3 player
1145 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1146 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1150 * Laser MP3-2GA13 MP3 player
1152 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1153 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1157 * LaCie external 250GB Hard drive des by Porsche
1158 * Submitted by: Ben Stuyts <ben@altesco.nl>
1161 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1162 /*quirks*/ DA_Q_NO_SYNC_CACHE
1167 * Corsair Force 2 SSDs
1168 * 4k optimised & trim only works in 4k requests + 4k aligned
1170 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1175 * Corsair Force 3 SSDs
1176 * 4k optimised & trim only works in 4k requests + 4k aligned
1178 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1183 * Corsair Neutron GTX SSDs
1184 * 4k optimised & trim only works in 4k requests + 4k aligned
1186 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1191 * Corsair Force GT & GS SSDs
1192 * 4k optimised & trim only works in 4k requests + 4k aligned
1194 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1200 * 4k optimised & trim only works in 4k requests + 4k aligned
1202 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1207 * Crucial RealSSD C300 SSDs
1210 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1211 "*" }, /*quirks*/DA_Q_4K
1215 * Intel 320 Series SSDs
1216 * 4k optimised & trim only works in 4k requests + 4k aligned
1218 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1223 * Intel 330 Series SSDs
1224 * 4k optimised & trim only works in 4k requests + 4k aligned
1226 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1231 * Intel 510 Series SSDs
1232 * 4k optimised & trim only works in 4k requests + 4k aligned
1234 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1239 * Intel 520 Series SSDs
1240 * 4k optimised & trim only works in 4k requests + 4k aligned
1242 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1247 * Intel S3610 Series SSDs
1248 * 4k optimised & trim only works in 4k requests + 4k aligned
1250 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1255 * Intel X25-M Series SSDs
1256 * 4k optimised & trim only works in 4k requests + 4k aligned
1258 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1263 * Kingston E100 Series SSDs
1264 * 4k optimised & trim only works in 4k requests + 4k aligned
1266 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1271 * Kingston HyperX 3k SSDs
1272 * 4k optimised & trim only works in 4k requests + 4k aligned
1274 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1279 * Marvell SSDs (entry taken from OpenSolaris)
1280 * 4k optimised & trim only works in 4k requests + 4k aligned
1282 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1287 * OCZ Agility 2 SSDs
1288 * 4k optimised & trim only works in 4k requests + 4k aligned
1290 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1295 * OCZ Agility 3 SSDs
1296 * 4k optimised & trim only works in 4k requests + 4k aligned
1298 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1303 * OCZ Deneva R Series SSDs
1304 * 4k optimised & trim only works in 4k requests + 4k aligned
1306 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1311 * OCZ Vertex 2 SSDs (inc pro series)
1312 * 4k optimised & trim only works in 4k requests + 4k aligned
1314 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1320 * 4k optimised & trim only works in 4k requests + 4k aligned
1322 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1328 * 4k optimised & trim only works in 4k requests + 4k aligned
1330 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1335 * Samsung 750 Series SSDs
1336 * 4k optimised & trim only works in 4k requests + 4k aligned
1338 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" },
1343 * Samsung 830 Series SSDs
1344 * 4k optimised & trim only works in 4k requests + 4k aligned
1346 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1352 * 4k optimised & trim only works in 4k requests + 4k aligned
1354 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1360 * 4k optimised & trim only works in 4k requests + 4k aligned
1362 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" },
1368 * 4k optimised & trim only works in 4k requests + 4k aligned
1370 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1375 * Samsung 843T Series SSDs (MZ7WD*)
1376 * Samsung PM851 Series SSDs (MZ7TE*)
1377 * Samsung PM853T Series SSDs (MZ7GE*)
1378 * Samsung SM863 Series SSDs (MZ7KM*)
1381 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1386 * Same as for SAMSUNG MZ7* but enable the quirks for SSD
1387 * starting with MZ7* too
1389 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MZ7*", "*" },
1394 * SuperTalent TeraDrive CT SSDs
1395 * 4k optimised & trim only works in 4k requests + 4k aligned
1397 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1402 * XceedIOPS SATA SSDs
1405 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1410 * Hama Innostor USB-Stick
1412 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1413 /*quirks*/DA_Q_NO_RC16
1417 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1418 * Drive Managed SATA hard drive. This drive doesn't report
1419 * in firmware that it is a drive managed SMR drive.
1421 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS000[23]*", "*" },
1422 /*quirks*/DA_Q_SMR_DM
1426 * MX-ES USB Drive by Mach Xtreme
1428 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1429 /*quirks*/DA_Q_NO_RC16
1433 static disk_strategy_t dastrategy;
1434 static dumper_t dadump;
1435 static periph_init_t dainit;
1436 static void daasync(void *callback_arg, u_int32_t code,
1437 struct cam_path *path, void *arg);
1438 static void dasysctlinit(void *context, int pending);
1439 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1440 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1441 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1442 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1443 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1444 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1445 static void dadeletemethodset(struct da_softc *softc,
1446 da_delete_methods delete_method);
1447 static off_t dadeletemaxsize(struct da_softc *softc,
1448 da_delete_methods delete_method);
1449 static void dadeletemethodchoose(struct da_softc *softc,
1450 da_delete_methods default_method);
1451 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1453 static periph_ctor_t daregister;
1454 static periph_dtor_t dacleanup;
1455 static periph_start_t dastart;
1456 static periph_oninv_t daoninvalidate;
1457 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1458 static void dadone(struct cam_periph *periph,
1459 union ccb *done_ccb);
1460 static void dadone_probewp(struct cam_periph *periph,
1461 union ccb *done_ccb);
1462 static void dadone_proberc(struct cam_periph *periph,
1463 union ccb *done_ccb);
1464 static void dadone_probelbp(struct cam_periph *periph,
1465 union ccb *done_ccb);
1466 static void dadone_probeblklimits(struct cam_periph *periph,
1467 union ccb *done_ccb);
1468 static void dadone_probebdc(struct cam_periph *periph,
1469 union ccb *done_ccb);
1470 static void dadone_probeata(struct cam_periph *periph,
1471 union ccb *done_ccb);
1472 static void dadone_probeatalogdir(struct cam_periph *periph,
1473 union ccb *done_ccb);
1474 static void dadone_probeataiddir(struct cam_periph *periph,
1475 union ccb *done_ccb);
1476 static void dadone_probeatasup(struct cam_periph *periph,
1477 union ccb *done_ccb);
1478 static void dadone_probeatazone(struct cam_periph *periph,
1479 union ccb *done_ccb);
1480 static void dadone_probezone(struct cam_periph *periph,
1481 union ccb *done_ccb);
1482 static void dadone_tur(struct cam_periph *periph,
1483 union ccb *done_ccb);
1484 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1485 u_int32_t sense_flags);
1486 static void daprevent(struct cam_periph *periph, int action);
1487 static void dareprobe(struct cam_periph *periph);
1488 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1490 struct scsi_read_capacity_data_long *rcaplong,
1492 static timeout_t dasendorderedtag;
1493 static void dashutdown(void *arg, int howto);
1494 static timeout_t damediapoll;
1496 #ifndef DA_DEFAULT_POLL_PERIOD
1497 #define DA_DEFAULT_POLL_PERIOD 3
1500 #ifndef DA_DEFAULT_TIMEOUT
1501 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1504 #ifndef DA_DEFAULT_SOFTTIMEOUT
1505 #define DA_DEFAULT_SOFTTIMEOUT 0
1508 #ifndef DA_DEFAULT_RETRY
1509 #define DA_DEFAULT_RETRY 4
1512 #ifndef DA_DEFAULT_SEND_ORDERED
1513 #define DA_DEFAULT_SEND_ORDERED 1
1516 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1517 static int da_retry_count = DA_DEFAULT_RETRY;
1518 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1519 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1520 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1521 static int da_disable_wp_detection = 0;
1523 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1524 "CAM Direct Access Disk driver");
1525 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1526 &da_poll_period, 0, "Media polling period in seconds");
1527 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1528 &da_retry_count, 0, "Normal I/O retry count");
1529 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1530 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1531 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1532 &da_send_ordered, 0, "Send Ordered Tags");
1533 SYSCTL_INT(_kern_cam_da, OID_AUTO, disable_wp_detection, CTLFLAG_RWTUN,
1534 &da_disable_wp_detection, 0,
1535 "Disable detection of write-protected disks");
1537 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1538 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1539 "Soft I/O timeout (ms)");
1540 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1543 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1544 * to the default timeout, we check to see whether an ordered
1545 * tagged transaction is appropriate to prevent simple tag
1546 * starvation. Since we'd like to ensure that there is at least
1547 * 1/2 of the timeout length left for a starved transaction to
1548 * complete after we've sent an ordered tag, we must poll at least
1549 * four times in every timeout period. This takes care of the worst
1550 * case where a starved transaction starts during an interval that
1551 * meets the requirement "don't send an ordered tag" test so it takes
1552 * us two intervals to determine that a tag must be sent.
1554 #ifndef DA_ORDEREDTAG_INTERVAL
1555 #define DA_ORDEREDTAG_INTERVAL 4
1558 static struct periph_driver dadriver =
1561 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1564 PERIPHDRIVER_DECLARE(da, dadriver);
1566 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1569 * This driver takes out references / holds in well defined pairs, never
1570 * recursively. These macros / inline functions enforce those rules. They
1571 * are only enabled with DA_TRACK_REFS or INVARIANTS. If DA_TRACK_REFS is
1572 * defined to be 2 or larger, the tracking also includes debug printfs.
1574 #if defined(DA_TRACK_REFS) || defined(INVARIANTS)
1576 #ifndef DA_TRACK_REFS
1577 #define DA_TRACK_REFS 1
1580 #if DA_TRACK_REFS > 1
1581 static const char *da_ref_text[] = {
1594 #define DA_PERIPH_PRINT(periph, msg, args...) \
1595 CAM_PERIPH_PRINT(periph, msg, ##args)
1597 #define DA_PERIPH_PRINT(periph, msg, args...)
1601 token_sanity(da_ref_token token)
1603 if ((unsigned)token >= DA_REF_MAX)
1604 panic("Bad token value passed in %d\n", token);
1608 da_periph_hold(struct cam_periph *periph, int priority, da_ref_token token)
1610 int err = cam_periph_hold(periph, priority);
1612 token_sanity(token);
1613 DA_PERIPH_PRINT(periph, "Holding device %s (%d): %d\n",
1614 da_ref_text[token], token, err);
1617 struct da_softc *softc = periph->softc;
1619 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1621 panic("Re-holding for reason %d, cnt = %d", token, cnt);
1627 da_periph_unhold(struct cam_periph *periph, da_ref_token token)
1630 struct da_softc *softc = periph->softc;
1632 token_sanity(token);
1633 DA_PERIPH_PRINT(periph, "Unholding device %s (%d)\n",
1634 da_ref_text[token], token);
1635 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1637 panic("Unholding %d with cnt = %d", token, cnt);
1638 cam_periph_unhold(periph);
1642 da_periph_acquire(struct cam_periph *periph, da_ref_token token)
1644 int err = cam_periph_acquire(periph);
1646 token_sanity(token);
1647 DA_PERIPH_PRINT(periph, "acquiring device %s (%d): %d\n",
1648 da_ref_text[token], token, err);
1651 struct da_softc *softc = periph->softc;
1653 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1655 panic("Re-refing for reason %d, cnt = %d", token, cnt);
1661 da_periph_release(struct cam_periph *periph, da_ref_token token)
1664 struct da_softc *softc = periph->softc;
1666 token_sanity(token);
1667 DA_PERIPH_PRINT(periph, "releasing device %s (%d)\n",
1668 da_ref_text[token], token);
1669 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1671 panic("Releasing %d with cnt = %d", token, cnt);
1672 cam_periph_release(periph);
1676 da_periph_release_locked(struct cam_periph *periph, da_ref_token token)
1679 struct da_softc *softc = periph->softc;
1681 token_sanity(token);
1682 DA_PERIPH_PRINT(periph, "releasing device (locked) %s (%d)\n",
1683 da_ref_text[token], token);
1684 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1686 panic("Unholding %d with cnt = %d", token, cnt);
1687 cam_periph_release_locked(periph);
1690 #define cam_periph_hold POISON
1691 #define cam_periph_unhold POISON
1692 #define cam_periph_acquire POISON
1693 #define cam_periph_release POISON
1694 #define cam_periph_release_locked POISON
1697 #define da_periph_hold(periph, prio, token) cam_periph_hold((periph), (prio))
1698 #define da_periph_unhold(periph, token) cam_periph_unhold((periph))
1699 #define da_periph_acquire(periph, token) cam_periph_acquire((periph))
1700 #define da_periph_release(periph, token) cam_periph_release((periph))
1701 #define da_periph_release_locked(periph, token) cam_periph_release_locked((periph))
1705 daopen(struct disk *dp)
1707 struct cam_periph *periph;
1708 struct da_softc *softc;
1711 periph = (struct cam_periph *)dp->d_drv1;
1712 if (da_periph_acquire(periph, DA_REF_OPEN) != 0) {
1716 cam_periph_lock(periph);
1717 if ((error = da_periph_hold(periph, PRIBIO|PCATCH, DA_REF_OPEN_HOLD)) != 0) {
1718 cam_periph_unlock(periph);
1719 da_periph_release(periph, DA_REF_OPEN);
1723 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1726 softc = (struct da_softc *)periph->softc;
1729 /* Wait for the disk size update. */
1730 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1733 xpt_print(periph->path, "unable to retrieve capacity data\n");
1735 if (periph->flags & CAM_PERIPH_INVALID)
1738 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1739 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1740 daprevent(periph, PR_PREVENT);
1743 softc->flags &= ~DA_FLAG_PACK_INVALID;
1744 softc->flags |= DA_FLAG_OPEN;
1747 da_periph_unhold(periph, DA_REF_OPEN_HOLD);
1748 cam_periph_unlock(periph);
1751 da_periph_release(periph, DA_REF_OPEN);
1757 daclose(struct disk *dp)
1759 struct cam_periph *periph;
1760 struct da_softc *softc;
1763 periph = (struct cam_periph *)dp->d_drv1;
1764 softc = (struct da_softc *)periph->softc;
1765 cam_periph_lock(periph);
1766 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1769 if (da_periph_hold(periph, PRIBIO, DA_REF_CLOSE_HOLD) == 0) {
1771 /* Flush disk cache. */
1772 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1773 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1774 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1775 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1776 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1777 /*cbfcnp*/NULL, MSG_SIMPLE_Q_TAG,
1778 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1780 cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1781 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1782 softc->disk->d_devstat);
1783 softc->flags &= ~DA_FLAG_DIRTY;
1784 xpt_release_ccb(ccb);
1787 /* Allow medium removal. */
1788 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1789 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1790 daprevent(periph, PR_ALLOW);
1792 da_periph_unhold(periph, DA_REF_CLOSE_HOLD);
1796 * If we've got removeable media, mark the blocksize as
1797 * unavailable, since it could change when new media is
1800 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1801 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1803 softc->flags &= ~DA_FLAG_OPEN;
1804 while (softc->refcount != 0)
1805 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1806 cam_periph_unlock(periph);
1807 da_periph_release(periph, DA_REF_OPEN);
1812 daschedule(struct cam_periph *periph)
1814 struct da_softc *softc = (struct da_softc *)periph->softc;
1816 if (softc->state != DA_STATE_NORMAL)
1819 cam_iosched_schedule(softc->cam_iosched, periph);
1823 * Actually translate the requested transfer into one the physical driver
1824 * can understand. The transfer is described by a buf and will include
1825 * only one physical transfer.
1828 dastrategy(struct bio *bp)
1830 struct cam_periph *periph;
1831 struct da_softc *softc;
1833 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1834 softc = (struct da_softc *)periph->softc;
1836 cam_periph_lock(periph);
1839 * If the device has been made invalid, error out
1841 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1842 cam_periph_unlock(periph);
1843 biofinish(bp, NULL, ENXIO);
1847 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1850 * Zone commands must be ordered, because they can depend on the
1851 * effects of previously issued commands, and they may affect
1852 * commands after them.
1854 if (bp->bio_cmd == BIO_ZONE)
1855 bp->bio_flags |= BIO_ORDERED;
1858 * Place it in the queue of disk activities for this disk
1860 cam_iosched_queue_work(softc->cam_iosched, bp);
1863 * Schedule ourselves for performing the work.
1866 cam_periph_unlock(periph);
1872 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1874 struct cam_periph *periph;
1875 struct da_softc *softc;
1877 struct ccb_scsiio csio;
1882 periph = dp->d_drv1;
1883 softc = (struct da_softc *)periph->softc;
1884 secsize = softc->params.secsize;
1886 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0)
1889 memset(&csio, 0, sizeof(csio));
1891 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1892 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1893 scsi_read_write(&csio,
1897 /*read*/SCSI_RW_WRITE,
1899 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1902 /*data_ptr*/(u_int8_t *) virtual,
1903 /*dxfer_len*/length,
1904 /*sense_len*/SSD_FULL_SIZE,
1905 da_default_timeout * 1000);
1906 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1907 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1909 printf("Aborting dump due to I/O error.\n");
1914 * Sync the disk cache contents to the physical media.
1916 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1918 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1919 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1920 scsi_synchronize_cache(&csio,
1924 /*begin_lba*/0,/* Cover the whole disk */
1928 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1929 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1931 xpt_print(periph->path, "Synchronize cache failed\n");
1937 dagetattr(struct bio *bp)
1940 struct cam_periph *periph;
1942 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1943 cam_periph_lock(periph);
1944 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1946 cam_periph_unlock(periph);
1948 bp->bio_completed = bp->bio_length;
1958 * Install a global async callback. This callback will
1959 * receive async callbacks like "new device found".
1961 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1963 if (status != CAM_REQ_CMP) {
1964 printf("da: Failed to attach master async callback "
1965 "due to status 0x%x!\n", status);
1966 } else if (da_send_ordered) {
1968 /* Register our shutdown event handler */
1969 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1970 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1971 printf("dainit: shutdown event registration failed!\n");
1976 * Callback from GEOM, called when it has finished cleaning up its
1980 dadiskgonecb(struct disk *dp)
1982 struct cam_periph *periph;
1984 periph = (struct cam_periph *)dp->d_drv1;
1985 da_periph_release(periph, DA_REF_GEOM);
1989 daoninvalidate(struct cam_periph *periph)
1991 struct da_softc *softc;
1993 cam_periph_assert(periph, MA_OWNED);
1994 softc = (struct da_softc *)periph->softc;
1997 * De-register any async callbacks.
1999 xpt_register_async(0, daasync, periph, periph->path);
2001 softc->flags |= DA_FLAG_PACK_INVALID;
2003 softc->invalidations++;
2007 * Return all queued I/O with ENXIO.
2008 * XXX Handle any transactions queued to the card
2009 * with XPT_ABORT_CCB.
2011 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
2014 * Tell GEOM that we've gone away, we'll get a callback when it is
2015 * done cleaning up its resources.
2017 disk_gone(softc->disk);
2021 dacleanup(struct cam_periph *periph)
2023 struct da_softc *softc;
2025 softc = (struct da_softc *)periph->softc;
2027 cam_periph_unlock(periph);
2029 cam_iosched_fini(softc->cam_iosched);
2032 * If we can't free the sysctl tree, oh well...
2034 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
2036 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
2037 xpt_print(periph->path,
2038 "can't remove sysctl stats context\n");
2040 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
2041 xpt_print(periph->path,
2042 "can't remove sysctl context\n");
2045 callout_drain(&softc->mediapoll_c);
2046 disk_destroy(softc->disk);
2047 callout_drain(&softc->sendordered_c);
2048 free(softc, M_DEVBUF);
2049 cam_periph_lock(periph);
2053 daasync(void *callback_arg, u_int32_t code,
2054 struct cam_path *path, void *arg)
2056 struct cam_periph *periph;
2057 struct da_softc *softc;
2059 periph = (struct cam_periph *)callback_arg;
2061 case AC_FOUND_DEVICE: /* callback to create periph, no locking yet */
2063 struct ccb_getdev *cgd;
2066 cgd = (struct ccb_getdev *)arg;
2070 if (cgd->protocol != PROTO_SCSI)
2072 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
2074 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
2075 && SID_TYPE(&cgd->inq_data) != T_RBC
2076 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
2077 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
2081 * Allocate a peripheral instance for
2082 * this device and start the probe
2085 status = cam_periph_alloc(daregister, daoninvalidate,
2087 "da", CAM_PERIPH_BIO,
2089 AC_FOUND_DEVICE, cgd);
2091 if (status != CAM_REQ_CMP
2092 && status != CAM_REQ_INPROG)
2093 printf("daasync: Unable to attach to new device "
2094 "due to status 0x%x\n", status);
2097 case AC_ADVINFO_CHANGED: /* Doesn't touch periph */
2101 buftype = (uintptr_t)arg;
2102 if (buftype == CDAI_TYPE_PHYS_PATH) {
2103 struct da_softc *softc;
2105 softc = periph->softc;
2106 disk_attr_changed(softc->disk, "GEOM::physpath",
2111 case AC_UNIT_ATTENTION:
2114 int error_code, sense_key, asc, ascq;
2116 softc = (struct da_softc *)periph->softc;
2117 ccb = (union ccb *)arg;
2120 * Handle all UNIT ATTENTIONs except our own, as they will be
2121 * handled by daerror(). Since this comes from a different periph,
2122 * that periph's lock is held, not ours, so we have to take it ours
2123 * out to touch softc flags.
2125 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
2126 scsi_extract_sense_ccb(ccb,
2127 &error_code, &sense_key, &asc, &ascq)) {
2128 if (asc == 0x2A && ascq == 0x09) {
2129 xpt_print(ccb->ccb_h.path,
2130 "Capacity data has changed\n");
2131 cam_periph_lock(periph);
2132 softc->flags &= ~DA_FLAG_PROBED;
2133 cam_periph_unlock(periph);
2135 } else if (asc == 0x28 && ascq == 0x00) {
2136 cam_periph_lock(periph);
2137 softc->flags &= ~DA_FLAG_PROBED;
2138 cam_periph_unlock(periph);
2139 disk_media_changed(softc->disk, M_NOWAIT);
2140 } else if (asc == 0x3F && ascq == 0x03) {
2141 xpt_print(ccb->ccb_h.path,
2142 "INQUIRY data has changed\n");
2143 cam_periph_lock(periph);
2144 softc->flags &= ~DA_FLAG_PROBED;
2145 cam_periph_unlock(periph);
2151 case AC_SCSI_AEN: /* Called for this path: periph locked */
2153 * Appears to be currently unused for SCSI devices, only ata SIMs
2156 cam_periph_assert(periph, MA_OWNED);
2157 softc = (struct da_softc *)periph->softc;
2158 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
2159 (softc->flags & DA_FLAG_TUR_PENDING) == 0) {
2160 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
2161 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
2166 case AC_SENT_BDR: /* Called for this path: periph locked */
2167 case AC_BUS_RESET: /* Called for this path: periph locked */
2169 struct ccb_hdr *ccbh;
2171 cam_periph_assert(periph, MA_OWNED);
2172 softc = (struct da_softc *)periph->softc;
2174 * Don't fail on the expected unit attention
2177 softc->flags |= DA_FLAG_RETRY_UA;
2178 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
2179 ccbh->ccb_state |= DA_CCB_RETRY_UA;
2182 case AC_INQ_CHANGED: /* Called for this path: periph locked */
2183 cam_periph_assert(periph, MA_OWNED);
2184 softc = (struct da_softc *)periph->softc;
2185 softc->flags &= ~DA_FLAG_PROBED;
2191 cam_periph_async(periph, code, path, arg);
2195 dasysctlinit(void *context, int pending)
2197 struct cam_periph *periph;
2198 struct da_softc *softc;
2199 char tmpstr[32], tmpstr2[16];
2200 struct ccb_trans_settings cts;
2202 periph = (struct cam_periph *)context;
2204 * periph was held for us when this task was enqueued
2206 if (periph->flags & CAM_PERIPH_INVALID) {
2207 da_periph_release(periph, DA_REF_SYSCTL);
2211 softc = (struct da_softc *)periph->softc;
2212 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
2213 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
2215 sysctl_ctx_init(&softc->sysctl_ctx);
2216 cam_periph_lock(periph);
2217 softc->flags |= DA_FLAG_SCTX_INIT;
2218 cam_periph_unlock(periph);
2219 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
2220 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
2221 CTLFLAG_RD, 0, tmpstr, "device_index");
2222 if (softc->sysctl_tree == NULL) {
2223 printf("dasysctlinit: unable to allocate sysctl tree\n");
2224 da_periph_release(periph, DA_REF_SYSCTL);
2229 * Now register the sysctl handler, so the user can change the value on
2232 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2233 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
2234 softc, 0, dadeletemethodsysctl, "A",
2235 "BIO_DELETE execution method");
2236 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2237 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
2238 softc, 0, dadeletemaxsysctl, "Q",
2239 "Maximum BIO_DELETE size");
2240 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2241 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
2242 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
2243 "Minimum CDB size");
2244 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2245 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2246 "trim_count", CTLFLAG_RD, &softc->trim_count,
2247 "Total number of unmap/dsm commands sent");
2248 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2249 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2250 "trim_ranges", CTLFLAG_RD, &softc->trim_ranges,
2251 "Total number of ranges in unmap/dsm commands");
2252 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2253 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2254 "trim_lbas", CTLFLAG_RD, &softc->trim_lbas,
2255 "Total lbas in the unmap/dsm commands sent");
2257 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2258 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
2259 softc, 0, dazonemodesysctl, "A",
2261 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2262 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
2263 softc, 0, dazonesupsysctl, "A",
2265 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2266 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2267 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2268 "Optimal Number of Open Sequential Write Preferred Zones");
2269 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2270 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2271 "optimal_nonseq_zones", CTLFLAG_RD,
2272 &softc->optimal_nonseq_zones,
2273 "Optimal Number of Non-Sequentially Written Sequential Write "
2275 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2276 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2277 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2278 "Maximum Number of Open Sequential Write Required Zones");
2280 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2281 SYSCTL_CHILDREN(softc->sysctl_tree),
2285 &softc->error_inject,
2287 "error_inject leaf");
2289 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2290 SYSCTL_CHILDREN(softc->sysctl_tree),
2296 "Unmapped I/O support");
2298 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2299 SYSCTL_CHILDREN(softc->sysctl_tree),
2307 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2308 SYSCTL_CHILDREN(softc->sysctl_tree),
2314 "DIF protection type");
2316 #ifdef CAM_TEST_FAILURE
2317 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2318 OID_AUTO, "invalidate", CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE,
2319 periph, 0, cam_periph_invalidate_sysctl, "I",
2320 "Write 1 to invalidate the drive immediately");
2324 * Add some addressing info.
2326 memset(&cts, 0, sizeof (cts));
2327 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2328 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2329 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2330 cam_periph_lock(periph);
2331 xpt_action((union ccb *)&cts);
2332 cam_periph_unlock(periph);
2333 if (cts.ccb_h.status != CAM_REQ_CMP) {
2334 da_periph_release(periph, DA_REF_SYSCTL);
2337 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2338 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2339 if (fc->valid & CTS_FC_VALID_WWPN) {
2340 softc->wwpn = fc->wwpn;
2341 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2342 SYSCTL_CHILDREN(softc->sysctl_tree),
2343 OID_AUTO, "wwpn", CTLFLAG_RD,
2344 &softc->wwpn, "World Wide Port Name");
2350 * Now add some useful stats.
2351 * XXX These should live in cam_periph and be common to all periphs
2353 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2354 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2355 CTLFLAG_RD, 0, "Statistics");
2356 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2357 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2363 "Transport errors reported by the SIM");
2364 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2365 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2371 "Device timeouts reported by the SIM");
2372 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2373 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2375 "pack_invalidations",
2377 &softc->invalidations,
2379 "Device pack invalidations");
2382 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2383 softc->sysctl_tree);
2385 da_periph_release(periph, DA_REF_SYSCTL);
2389 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2393 struct da_softc *softc;
2395 softc = (struct da_softc *)arg1;
2397 value = softc->disk->d_delmaxsize;
2398 error = sysctl_handle_64(oidp, &value, 0, req);
2399 if ((error != 0) || (req->newptr == NULL))
2402 /* only accept values smaller than the calculated value */
2403 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2406 softc->disk->d_delmaxsize = value;
2412 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2416 value = *(int *)arg1;
2418 error = sysctl_handle_int(oidp, &value, 0, req);
2421 || (req->newptr == NULL))
2425 * Acceptable values here are 6, 10, 12 or 16.
2429 else if ((value > 6)
2432 else if ((value > 10)
2435 else if (value > 12)
2438 *(int *)arg1 = value;
2444 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2449 value = da_default_softtimeout / SBT_1MS;
2451 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2452 if ((error != 0) || (req->newptr == NULL))
2455 /* XXX Should clip this to a reasonable level */
2456 if (value > da_default_timeout * 1000)
2459 da_default_softtimeout = value * SBT_1MS;
2464 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2467 softc->delete_method = delete_method;
2468 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2469 softc->delete_func = da_delete_functions[delete_method];
2471 if (softc->delete_method > DA_DELETE_DISABLE)
2472 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2474 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2478 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2482 switch(delete_method) {
2483 case DA_DELETE_UNMAP:
2484 sectors = (off_t)softc->unmap_max_lba;
2486 case DA_DELETE_ATA_TRIM:
2487 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2489 case DA_DELETE_WS16:
2490 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2492 case DA_DELETE_ZERO:
2493 case DA_DELETE_WS10:
2494 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2500 return (off_t)softc->params.secsize *
2501 omin(sectors, softc->params.sectors);
2505 daprobedone(struct cam_periph *periph, union ccb *ccb)
2507 struct da_softc *softc;
2509 softc = (struct da_softc *)periph->softc;
2511 cam_periph_assert(periph, MA_OWNED);
2513 dadeletemethodchoose(softc, DA_DELETE_NONE);
2515 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2519 snprintf(buf, sizeof(buf), "Delete methods: <");
2521 for (i = 0; i <= DA_DELETE_MAX; i++) {
2522 if ((softc->delete_available & (1 << i)) == 0 &&
2523 i != softc->delete_method)
2526 strlcat(buf, ",", sizeof(buf));
2527 strlcat(buf, da_delete_method_names[i],
2529 if (i == softc->delete_method)
2530 strlcat(buf, "(*)", sizeof(buf));
2533 strlcat(buf, ">", sizeof(buf));
2534 printf("%s%d: %s\n", periph->periph_name,
2535 periph->unit_number, buf);
2537 if ((softc->disk->d_flags & DISKFLAG_WRITE_PROTECT) != 0 &&
2538 (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2539 printf("%s%d: Write Protected\n", periph->periph_name,
2540 periph->unit_number);
2544 * Since our peripheral may be invalidated by an error
2545 * above or an external event, we must release our CCB
2546 * before releasing the probe lock on the peripheral.
2547 * The peripheral will only go away once the last lock
2548 * is removed, and we need it around for the CCB release
2551 xpt_release_ccb(ccb);
2552 softc->state = DA_STATE_NORMAL;
2553 softc->flags |= DA_FLAG_PROBED;
2555 wakeup(&softc->disk->d_mediasize);
2556 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2557 softc->flags |= DA_FLAG_ANNOUNCED;
2558 da_periph_unhold(periph, DA_REF_PROBE_HOLD);
2560 da_periph_release_locked(periph, DA_REF_REPROBE);
2564 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2568 /* If available, prefer the method requested by user. */
2569 i = softc->delete_method_pref;
2570 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2571 if (methods & (1 << i)) {
2572 dadeletemethodset(softc, i);
2576 /* Use the pre-defined order to choose the best performing delete. */
2577 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2578 if (i == DA_DELETE_ZERO)
2580 if (softc->delete_available & (1 << i)) {
2581 dadeletemethodset(softc, i);
2586 /* Fallback to default. */
2587 dadeletemethodset(softc, default_method);
2591 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2595 struct da_softc *softc;
2596 int i, error, value;
2598 softc = (struct da_softc *)arg1;
2600 value = softc->delete_method;
2601 if (value < 0 || value > DA_DELETE_MAX)
2604 p = da_delete_method_names[value];
2605 strncpy(buf, p, sizeof(buf));
2606 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2607 if (error != 0 || req->newptr == NULL)
2609 for (i = 0; i <= DA_DELETE_MAX; i++) {
2610 if (strcmp(buf, da_delete_method_names[i]) == 0)
2613 if (i > DA_DELETE_MAX)
2615 softc->delete_method_pref = i;
2616 dadeletemethodchoose(softc, DA_DELETE_NONE);
2621 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2624 struct da_softc *softc;
2627 softc = (struct da_softc *)arg1;
2629 switch (softc->zone_mode) {
2630 case DA_ZONE_DRIVE_MANAGED:
2631 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2633 case DA_ZONE_HOST_AWARE:
2634 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2636 case DA_ZONE_HOST_MANAGED:
2637 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2641 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2645 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2651 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2654 struct da_softc *softc;
2659 softc = (struct da_softc *)arg1;
2663 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2665 for (i = 0; i < sizeof(da_zone_desc_table) /
2666 sizeof(da_zone_desc_table[0]); i++) {
2667 if (softc->zone_flags & da_zone_desc_table[i].value) {
2669 sbuf_printf(&sb, ", ");
2672 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2677 sbuf_printf(&sb, "None");
2681 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2687 daregister(struct cam_periph *periph, void *arg)
2689 struct da_softc *softc;
2690 struct ccb_pathinq cpi;
2691 struct ccb_getdev *cgd;
2695 cgd = (struct ccb_getdev *)arg;
2697 printf("daregister: no getdev CCB, can't register device\n");
2698 return(CAM_REQ_CMP_ERR);
2701 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2704 if (softc == NULL) {
2705 printf("daregister: Unable to probe new device. "
2706 "Unable to allocate softc\n");
2707 return(CAM_REQ_CMP_ERR);
2710 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2711 printf("daregister: Unable to probe new device. "
2712 "Unable to allocate iosched memory\n");
2713 free(softc, M_DEVBUF);
2714 return(CAM_REQ_CMP_ERR);
2717 LIST_INIT(&softc->pending_ccbs);
2718 softc->state = DA_STATE_PROBE_WP;
2719 bioq_init(&softc->delete_run_queue);
2720 if (SID_IS_REMOVABLE(&cgd->inq_data))
2721 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2722 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2723 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2724 softc->unmap_gran = 0;
2725 softc->unmap_gran_align = 0;
2726 softc->ws_max_blks = WS16_MAX_BLKS;
2727 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2728 softc->rotating = 1;
2730 periph->softc = softc;
2733 * See if this device has any quirks.
2735 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2736 (caddr_t)da_quirk_table,
2737 nitems(da_quirk_table),
2738 sizeof(*da_quirk_table), scsi_inquiry_match);
2741 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2743 softc->quirks = DA_Q_NONE;
2745 /* Check if the SIM does not want 6 byte commands */
2746 xpt_path_inq(&cpi, periph->path);
2747 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2748 softc->quirks |= DA_Q_NO_6_BYTE;
2750 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2751 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2752 else if (softc->quirks & DA_Q_SMR_DM)
2753 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2755 softc->zone_mode = DA_ZONE_NONE;
2757 if (softc->zone_mode != DA_ZONE_NONE) {
2758 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2759 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2760 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2762 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2764 softc->zone_interface = DA_ZONE_IF_SCSI;
2767 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2770 * Take an exclusive section lock qon the periph while dastart is called
2771 * to finish the probe. The lock will be dropped in dadone at the end
2772 * of probe. This locks out daopen and daclose from racing with the
2775 * XXX if cam_periph_hold returns an error, we don't hold a refcount.
2777 (void)da_periph_hold(periph, PRIBIO, DA_REF_PROBE_HOLD);
2780 * Schedule a periodic event to occasionally send an
2781 * ordered tag to a device.
2783 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2784 callout_reset(&softc->sendordered_c,
2785 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2786 dasendorderedtag, periph);
2788 cam_periph_unlock(periph);
2790 * RBC devices don't have to support READ(6), only READ(10).
2792 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2793 softc->minimum_cmd_size = 10;
2795 softc->minimum_cmd_size = 6;
2798 * Load the user's default, if any.
2800 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2801 periph->unit_number);
2802 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2805 * 6, 10, 12 and 16 are the currently permissible values.
2807 if (softc->minimum_cmd_size > 12)
2808 softc->minimum_cmd_size = 16;
2809 else if (softc->minimum_cmd_size > 10)
2810 softc->minimum_cmd_size = 12;
2811 else if (softc->minimum_cmd_size > 6)
2812 softc->minimum_cmd_size = 10;
2814 softc->minimum_cmd_size = 6;
2816 /* Predict whether device may support READ CAPACITY(16). */
2817 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2818 (softc->quirks & DA_Q_NO_RC16) == 0) {
2819 softc->flags |= DA_FLAG_CAN_RC16;
2823 * Register this media as a disk.
2825 softc->disk = disk_alloc();
2826 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2827 periph->unit_number, 0,
2828 DEVSTAT_BS_UNAVAILABLE,
2829 SID_TYPE(&cgd->inq_data) |
2830 XPORT_DEVSTAT_TYPE(cpi.transport),
2831 DEVSTAT_PRIORITY_DISK);
2832 softc->disk->d_open = daopen;
2833 softc->disk->d_close = daclose;
2834 softc->disk->d_strategy = dastrategy;
2835 softc->disk->d_dump = dadump;
2836 softc->disk->d_getattr = dagetattr;
2837 softc->disk->d_gone = dadiskgonecb;
2838 softc->disk->d_name = "da";
2839 softc->disk->d_drv1 = periph;
2841 softc->maxio = DFLTPHYS; /* traditional default */
2842 else if (cpi.maxio > MAXPHYS)
2843 softc->maxio = MAXPHYS; /* for safety */
2845 softc->maxio = cpi.maxio;
2846 if (softc->quirks & DA_Q_128KB)
2847 softc->maxio = min(softc->maxio, 128 * 1024);
2848 softc->disk->d_maxsize = softc->maxio;
2849 softc->disk->d_unit = periph->unit_number;
2850 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2851 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2852 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2853 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2854 softc->unmappedio = 1;
2855 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2857 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2858 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2859 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2860 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2861 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2862 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2863 softc->disk->d_hba_vendor = cpi.hba_vendor;
2864 softc->disk->d_hba_device = cpi.hba_device;
2865 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2866 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2869 * Acquire a reference to the periph before we register with GEOM.
2870 * We'll release this reference once GEOM calls us back (via
2871 * dadiskgonecb()) telling us that our provider has been freed.
2873 if (da_periph_acquire(periph, DA_REF_GEOM) != 0) {
2874 xpt_print(periph->path, "%s: lost periph during "
2875 "registration!\n", __func__);
2876 cam_periph_lock(periph);
2877 return (CAM_REQ_CMP_ERR);
2880 disk_create(softc->disk, DISK_VERSION);
2881 cam_periph_lock(periph);
2884 * Add async callbacks for events of interest.
2885 * I don't bother checking if this fails as,
2886 * in most cases, the system will function just
2887 * fine without them and the only alternative
2888 * would be to not attach the device on failure.
2890 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2891 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2892 AC_INQ_CHANGED, daasync, periph, periph->path);
2895 * Emit an attribute changed notification just in case
2896 * physical path information arrived before our async
2897 * event handler was registered, but after anyone attaching
2898 * to our disk device polled it.
2900 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2903 * Schedule a periodic media polling events.
2905 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2906 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2907 (cgd->inq_flags & SID_AEN) == 0 &&
2908 da_poll_period != 0)
2909 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2910 damediapoll, periph);
2912 xpt_schedule(periph, CAM_PRIORITY_DEV);
2914 return(CAM_REQ_CMP);
2918 da_zone_bio_to_scsi(int disk_zone_cmd)
2920 switch (disk_zone_cmd) {
2921 case DISK_ZONE_OPEN:
2922 return ZBC_OUT_SA_OPEN;
2923 case DISK_ZONE_CLOSE:
2924 return ZBC_OUT_SA_CLOSE;
2925 case DISK_ZONE_FINISH:
2926 return ZBC_OUT_SA_FINISH;
2928 return ZBC_OUT_SA_RWP;
2935 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2938 struct da_softc *softc;
2943 if (bp->bio_cmd != BIO_ZONE) {
2948 softc = periph->softc;
2950 switch (bp->bio_zone.zone_cmd) {
2951 case DISK_ZONE_OPEN:
2952 case DISK_ZONE_CLOSE:
2953 case DISK_ZONE_FINISH:
2954 case DISK_ZONE_RWP: {
2959 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2960 if (zone_sa == -1) {
2961 xpt_print(periph->path, "Cannot translate zone "
2962 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2968 lba = bp->bio_zone.zone_params.rwp.id;
2970 if (bp->bio_zone.zone_params.rwp.flags &
2971 DISK_ZONE_RWP_FLAG_ALL)
2972 zone_flags |= ZBC_OUT_ALL;
2974 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2975 scsi_zbc_out(&ccb->csio,
2976 /*retries*/ da_retry_count,
2978 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2979 /*service_action*/ zone_sa,
2981 /*zone_flags*/ zone_flags,
2984 /*sense_len*/ SSD_FULL_SIZE,
2985 /*timeout*/ da_default_timeout * 1000);
2988 * Note that in this case, even though we can
2989 * technically use NCQ, we don't bother for several
2991 * 1. It hasn't been tested on a SAT layer that
2992 * supports it. This is new as of SAT-4.
2993 * 2. Even when there is a SAT layer that supports
2994 * it, that SAT layer will also probably support
2995 * ZBC -> ZAC translation, since they are both
2996 * in the SAT-4 spec.
2997 * 3. Translation will likely be preferable to ATA
2998 * passthrough. LSI / Avago at least single
2999 * steps ATA passthrough commands in the HBA,
3000 * regardless of protocol, so unless that
3001 * changes, there is a performance penalty for
3002 * doing ATA passthrough no matter whether
3003 * you're using NCQ/FPDMA, DMA or PIO.
3004 * 4. It requires a 32-byte CDB, which at least at
3005 * this point in CAM requires a CDB pointer, which
3006 * would require us to allocate an additional bit
3007 * of storage separate from the CCB.
3009 error = scsi_ata_zac_mgmt_out(&ccb->csio,
3010 /*retries*/ da_retry_count,
3012 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3014 /*zm_action*/ zone_sa,
3016 /*zone_flags*/ zone_flags,
3019 /*cdb_storage*/ NULL,
3020 /*cdb_storage_len*/ 0,
3021 /*sense_len*/ SSD_FULL_SIZE,
3022 /*timeout*/ da_default_timeout * 1000);
3025 xpt_print(periph->path,
3026 "scsi_ata_zac_mgmt_out() returned an "
3035 case DISK_ZONE_REPORT_ZONES: {
3037 uint32_t num_entries, alloc_size;
3038 struct disk_zone_report *rep;
3040 rep = &bp->bio_zone.zone_params.report;
3042 num_entries = rep->entries_allocated;
3043 if (num_entries == 0) {
3044 xpt_print(periph->path, "No entries allocated for "
3045 "Report Zones request\n");
3049 alloc_size = sizeof(struct scsi_report_zones_hdr) +
3050 (sizeof(struct scsi_report_zones_desc) * num_entries);
3051 alloc_size = min(alloc_size, softc->disk->d_maxsize);
3052 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
3053 if (rz_ptr == NULL) {
3054 xpt_print(periph->path, "Unable to allocate memory "
3055 "for Report Zones request\n");
3060 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
3061 scsi_zbc_in(&ccb->csio,
3062 /*retries*/ da_retry_count,
3064 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3065 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
3066 /*zone_start_lba*/ rep->starting_id,
3067 /*zone_options*/ rep->rep_options,
3068 /*data_ptr*/ rz_ptr,
3069 /*dxfer_len*/ alloc_size,
3070 /*sense_len*/ SSD_FULL_SIZE,
3071 /*timeout*/ da_default_timeout * 1000);
3074 * Note that in this case, even though we can
3075 * technically use NCQ, we don't bother for several
3077 * 1. It hasn't been tested on a SAT layer that
3078 * supports it. This is new as of SAT-4.
3079 * 2. Even when there is a SAT layer that supports
3080 * it, that SAT layer will also probably support
3081 * ZBC -> ZAC translation, since they are both
3082 * in the SAT-4 spec.
3083 * 3. Translation will likely be preferable to ATA
3084 * passthrough. LSI / Avago at least single
3085 * steps ATA passthrough commands in the HBA,
3086 * regardless of protocol, so unless that
3087 * changes, there is a performance penalty for
3088 * doing ATA passthrough no matter whether
3089 * you're using NCQ/FPDMA, DMA or PIO.
3090 * 4. It requires a 32-byte CDB, which at least at
3091 * this point in CAM requires a CDB pointer, which
3092 * would require us to allocate an additional bit
3093 * of storage separate from the CCB.
3095 error = scsi_ata_zac_mgmt_in(&ccb->csio,
3096 /*retries*/ da_retry_count,
3098 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3100 /*zm_action*/ ATA_ZM_REPORT_ZONES,
3101 /*zone_id*/ rep->starting_id,
3102 /*zone_flags*/ rep->rep_options,
3103 /*data_ptr*/ rz_ptr,
3104 /*dxfer_len*/ alloc_size,
3105 /*cdb_storage*/ NULL,
3106 /*cdb_storage_len*/ 0,
3107 /*sense_len*/ SSD_FULL_SIZE,
3108 /*timeout*/ da_default_timeout * 1000);
3111 xpt_print(periph->path,
3112 "scsi_ata_zac_mgmt_in() returned an "
3119 * For BIO_ZONE, this isn't normally needed. However, it
3120 * is used by devstat_end_transaction_bio() to determine
3121 * how much data was transferred.
3124 * XXX KDM we have a problem. But I'm not sure how to fix
3125 * it. devstat uses bio_bcount - bio_resid to calculate
3126 * the amount of data transferred. The GEOM disk code
3127 * uses bio_length - bio_resid to calculate the amount of
3128 * data in bio_completed. We have different structure
3129 * sizes above and below the ada(4) driver. So, if we
3130 * use the sizes above, the amount transferred won't be
3131 * quite accurate for devstat. If we use different sizes
3132 * for bio_bcount and bio_length (above and below
3133 * respectively), then the residual needs to match one or
3134 * the other. Everything is calculated after the bio
3135 * leaves the driver, so changing the values around isn't
3136 * really an option. For now, just set the count to the
3137 * passed in length. This means that the calculations
3138 * above (e.g. bio_completed) will be correct, but the
3139 * amount of data reported to devstat will be slightly
3140 * under or overstated.
3142 bp->bio_bcount = bp->bio_length;
3148 case DISK_ZONE_GET_PARAMS: {
3149 struct disk_zone_disk_params *params;
3151 params = &bp->bio_zone.zone_params.disk_params;
3152 bzero(params, sizeof(*params));
3154 switch (softc->zone_mode) {
3155 case DA_ZONE_DRIVE_MANAGED:
3156 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
3158 case DA_ZONE_HOST_AWARE:
3159 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
3161 case DA_ZONE_HOST_MANAGED:
3162 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
3166 params->zone_mode = DISK_ZONE_MODE_NONE;
3170 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
3171 params->flags |= DISK_ZONE_DISK_URSWRZ;
3173 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
3174 params->optimal_seq_zones = softc->optimal_seq_zones;
3175 params->flags |= DISK_ZONE_OPT_SEQ_SET;
3178 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
3179 params->optimal_nonseq_zones =
3180 softc->optimal_nonseq_zones;
3181 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
3184 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
3185 params->max_seq_zones = softc->max_seq_zones;
3186 params->flags |= DISK_ZONE_MAX_SEQ_SET;
3188 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
3189 params->flags |= DISK_ZONE_RZ_SUP;
3191 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
3192 params->flags |= DISK_ZONE_OPEN_SUP;
3194 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
3195 params->flags |= DISK_ZONE_CLOSE_SUP;
3197 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
3198 params->flags |= DISK_ZONE_FINISH_SUP;
3200 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
3201 params->flags |= DISK_ZONE_RWP_SUP;
3212 dastart(struct cam_periph *periph, union ccb *start_ccb)
3214 struct da_softc *softc;
3216 cam_periph_assert(periph, MA_OWNED);
3217 softc = (struct da_softc *)periph->softc;
3219 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
3222 switch (softc->state) {
3223 case DA_STATE_NORMAL:
3229 bp = cam_iosched_next_bio(softc->cam_iosched);
3231 if (cam_iosched_has_work_flags(softc->cam_iosched,
3233 softc->flags |= DA_FLAG_TUR_PENDING;
3234 cam_iosched_clr_work_flags(softc->cam_iosched,
3236 scsi_test_unit_ready(&start_ccb->csio,
3237 /*retries*/ da_retry_count,
3241 da_default_timeout * 1000);
3242 start_ccb->ccb_h.ccb_bp = NULL;
3243 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
3244 xpt_action(start_ccb);
3246 xpt_release_ccb(start_ccb);
3250 if (bp->bio_cmd == BIO_DELETE) {
3251 if (softc->delete_func != NULL) {
3252 softc->delete_func(periph, start_ccb, bp);
3256 * Not sure this is possible, but failsafe by
3257 * lying and saying "sure, done."
3259 biofinish(bp, NULL, 0);
3264 if (cam_iosched_has_work_flags(softc->cam_iosched,
3266 cam_iosched_clr_work_flags(softc->cam_iosched,
3268 da_periph_release_locked(periph, DA_REF_TUR);
3271 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
3272 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
3273 softc->flags &= ~DA_FLAG_NEED_OTAG;
3274 softc->flags |= DA_FLAG_WAS_OTAG;
3275 tag_code = MSG_ORDERED_Q_TAG;
3277 tag_code = MSG_SIMPLE_Q_TAG;
3280 switch (bp->bio_cmd) {
3287 biotrack(bp, __func__);
3289 if (bp->bio_cmd == BIO_WRITE) {
3290 softc->flags |= DA_FLAG_DIRTY;
3291 rw_op = SCSI_RW_WRITE;
3293 rw_op = SCSI_RW_READ;
3296 data_ptr = bp->bio_data;
3297 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
3298 rw_op |= SCSI_RW_BIO;
3302 scsi_read_write(&start_ccb->csio,
3303 /*retries*/da_retry_count,
3305 /*tag_action*/tag_code,
3308 softc->minimum_cmd_size,
3309 /*lba*/bp->bio_pblkno,
3310 /*block_count*/bp->bio_bcount /
3311 softc->params.secsize,
3313 /*dxfer_len*/ bp->bio_bcount,
3314 /*sense_len*/SSD_FULL_SIZE,
3315 da_default_timeout * 1000);
3316 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3317 start_ccb->csio.bio = bp;
3323 * If we don't support sync cache, or the disk
3324 * isn't dirty, FLUSH is a no-op. Use the
3325 * allocated CCB for the next bio if one is
3328 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) != 0 ||
3329 (softc->flags & DA_FLAG_DIRTY) == 0) {
3335 * BIO_FLUSH doesn't currently communicate
3336 * range data, so we synchronize the cache
3337 * over the whole disk.
3339 scsi_synchronize_cache(&start_ccb->csio,
3342 /*tag_action*/tag_code,
3346 da_default_timeout*1000);
3348 * Clear the dirty flag before sending the command.
3349 * Either this sync cache will be successful, or it
3350 * will fail after a retry. If it fails, it is
3351 * unlikely to be successful if retried later, so
3352 * we'll save ourselves time by just marking the
3355 softc->flags &= ~DA_FLAG_DIRTY;
3358 int error, queue_ccb;
3362 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3364 || (queue_ccb == 0)) {
3365 biofinish(bp, NULL, error);
3366 xpt_release_ccb(start_ccb);
3372 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3373 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3374 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3377 LIST_INSERT_HEAD(&softc->pending_ccbs,
3378 &start_ccb->ccb_h, periph_links.le);
3380 /* We expect a unit attention from this device */
3381 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3382 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3383 softc->flags &= ~DA_FLAG_RETRY_UA;
3386 start_ccb->ccb_h.ccb_bp = bp;
3388 cam_periph_unlock(periph);
3389 xpt_action(start_ccb);
3390 cam_periph_lock(periph);
3392 /* May have more work to do, so ensure we stay scheduled */
3396 case DA_STATE_PROBE_WP:
3401 if (da_disable_wp_detection) {
3402 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3403 softc->state = DA_STATE_PROBE_RC16;
3405 softc->state = DA_STATE_PROBE_RC;
3409 mode_buf = malloc(mode_buf_len, M_SCSIDA, M_NOWAIT);
3410 if (mode_buf == NULL) {
3411 xpt_print(periph->path, "Unable to send mode sense - "
3412 "malloc failure\n");
3413 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3414 softc->state = DA_STATE_PROBE_RC16;
3416 softc->state = DA_STATE_PROBE_RC;
3419 scsi_mode_sense_len(&start_ccb->csio,
3420 /*retries*/ da_retry_count,
3421 /*cbfcnp*/ dadone_probewp,
3422 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3424 /*pc*/ SMS_PAGE_CTRL_CURRENT,
3425 /*page*/ SMS_ALL_PAGES_PAGE,
3426 /*param_buf*/ mode_buf,
3427 /*param_len*/ mode_buf_len,
3428 /*minimum_cmd_size*/ softc->minimum_cmd_size,
3429 /*sense_len*/ SSD_FULL_SIZE,
3430 /*timeout*/ da_default_timeout * 1000);
3431 start_ccb->ccb_h.ccb_bp = NULL;
3432 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_WP;
3433 xpt_action(start_ccb);
3436 case DA_STATE_PROBE_RC:
3438 struct scsi_read_capacity_data *rcap;
3440 rcap = (struct scsi_read_capacity_data *)
3441 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3443 printf("dastart: Couldn't malloc read_capacity data\n");
3444 /* da_free_periph??? */
3447 scsi_read_capacity(&start_ccb->csio,
3448 /*retries*/da_retry_count,
3454 start_ccb->ccb_h.ccb_bp = NULL;
3455 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3456 xpt_action(start_ccb);
3459 case DA_STATE_PROBE_RC16:
3461 struct scsi_read_capacity_data_long *rcaplong;
3463 rcaplong = (struct scsi_read_capacity_data_long *)
3464 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3465 if (rcaplong == NULL) {
3466 printf("dastart: Couldn't malloc read_capacity data\n");
3467 /* da_free_periph??? */
3470 scsi_read_capacity_16(&start_ccb->csio,
3471 /*retries*/ da_retry_count,
3472 /*cbfcnp*/ dadone_proberc,
3473 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3477 /*rcap_buf*/ (uint8_t *)rcaplong,
3478 /*rcap_buf_len*/ sizeof(*rcaplong),
3479 /*sense_len*/ SSD_FULL_SIZE,
3480 /*timeout*/ da_default_timeout * 1000);
3481 start_ccb->ccb_h.ccb_bp = NULL;
3482 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3483 xpt_action(start_ccb);
3486 case DA_STATE_PROBE_LBP:
3488 struct scsi_vpd_logical_block_prov *lbp;
3490 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3492 * If we get here we don't support any SBC-3 delete
3493 * methods with UNMAP as the Logical Block Provisioning
3494 * VPD page support is required for devices which
3495 * support it according to T10/1799-D Revision 31
3496 * however older revisions of the spec don't mandate
3497 * this so we currently don't remove these methods
3498 * from the available set.
3500 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3504 lbp = (struct scsi_vpd_logical_block_prov *)
3505 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3508 printf("dastart: Couldn't malloc lbp data\n");
3509 /* da_free_periph??? */
3513 scsi_inquiry(&start_ccb->csio,
3514 /*retries*/da_retry_count,
3515 /*cbfcnp*/dadone_probelbp,
3516 /*tag_action*/MSG_SIMPLE_Q_TAG,
3517 /*inq_buf*/(u_int8_t *)lbp,
3518 /*inq_len*/sizeof(*lbp),
3520 /*page_code*/SVPD_LBP,
3521 /*sense_len*/SSD_MIN_SIZE,
3522 /*timeout*/da_default_timeout * 1000);
3523 start_ccb->ccb_h.ccb_bp = NULL;
3524 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3525 xpt_action(start_ccb);
3528 case DA_STATE_PROBE_BLK_LIMITS:
3530 struct scsi_vpd_block_limits *block_limits;
3532 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3533 /* Not supported skip to next probe */
3534 softc->state = DA_STATE_PROBE_BDC;
3538 block_limits = (struct scsi_vpd_block_limits *)
3539 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3541 if (block_limits == NULL) {
3542 printf("dastart: Couldn't malloc block_limits data\n");
3543 /* da_free_periph??? */
3547 scsi_inquiry(&start_ccb->csio,
3548 /*retries*/da_retry_count,
3549 /*cbfcnp*/dadone_probeblklimits,
3550 /*tag_action*/MSG_SIMPLE_Q_TAG,
3551 /*inq_buf*/(u_int8_t *)block_limits,
3552 /*inq_len*/sizeof(*block_limits),
3554 /*page_code*/SVPD_BLOCK_LIMITS,
3555 /*sense_len*/SSD_MIN_SIZE,
3556 /*timeout*/da_default_timeout * 1000);
3557 start_ccb->ccb_h.ccb_bp = NULL;
3558 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3559 xpt_action(start_ccb);
3562 case DA_STATE_PROBE_BDC:
3564 struct scsi_vpd_block_characteristics *bdc;
3566 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3567 softc->state = DA_STATE_PROBE_ATA;
3571 bdc = (struct scsi_vpd_block_characteristics *)
3572 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3575 printf("dastart: Couldn't malloc bdc data\n");
3576 /* da_free_periph??? */
3580 scsi_inquiry(&start_ccb->csio,
3581 /*retries*/da_retry_count,
3582 /*cbfcnp*/dadone_probebdc,
3583 /*tag_action*/MSG_SIMPLE_Q_TAG,
3584 /*inq_buf*/(u_int8_t *)bdc,
3585 /*inq_len*/sizeof(*bdc),
3587 /*page_code*/SVPD_BDC,
3588 /*sense_len*/SSD_MIN_SIZE,
3589 /*timeout*/da_default_timeout * 1000);
3590 start_ccb->ccb_h.ccb_bp = NULL;
3591 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3592 xpt_action(start_ccb);
3595 case DA_STATE_PROBE_ATA:
3597 struct ata_params *ata_params;
3599 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3600 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3601 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3603 * Note that if the ATA VPD page isn't
3604 * supported, we aren't talking to an ATA
3605 * device anyway. Support for that VPD
3606 * page is mandatory for SCSI to ATA (SAT)
3607 * translation layers.
3609 softc->state = DA_STATE_PROBE_ZONE;
3612 daprobedone(periph, start_ccb);
3616 ata_params = (struct ata_params*)
3617 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3619 if (ata_params == NULL) {
3620 xpt_print(periph->path, "Couldn't malloc ata_params "
3622 /* da_free_periph??? */
3626 scsi_ata_identify(&start_ccb->csio,
3627 /*retries*/da_retry_count,
3628 /*cbfcnp*/dadone_probeata,
3629 /*tag_action*/MSG_SIMPLE_Q_TAG,
3630 /*data_ptr*/(u_int8_t *)ata_params,
3631 /*dxfer_len*/sizeof(*ata_params),
3632 /*sense_len*/SSD_FULL_SIZE,
3633 /*timeout*/da_default_timeout * 1000);
3634 start_ccb->ccb_h.ccb_bp = NULL;
3635 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3636 xpt_action(start_ccb);
3639 case DA_STATE_PROBE_ATA_LOGDIR:
3641 struct ata_gp_log_dir *log_dir;
3646 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3648 * If we don't have log support, not much point in
3649 * trying to probe zone support.
3651 daprobedone(periph, start_ccb);
3656 * If we have an ATA device (the SCSI ATA Information VPD
3657 * page should be present and the ATA identify should have
3658 * succeeded) and it supports logs, ask for the log directory.
3661 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3662 if (log_dir == NULL) {
3663 xpt_print(periph->path, "Couldn't malloc log_dir "
3665 daprobedone(periph, start_ccb);
3669 retval = scsi_ata_read_log(&start_ccb->csio,
3670 /*retries*/ da_retry_count,
3671 /*cbfcnp*/ dadone_probeatalogdir,
3672 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3673 /*log_address*/ ATA_LOG_DIRECTORY,
3676 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3677 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3678 /*data_ptr*/ (uint8_t *)log_dir,
3679 /*dxfer_len*/ sizeof(*log_dir),
3680 /*sense_len*/ SSD_FULL_SIZE,
3681 /*timeout*/ da_default_timeout * 1000);
3684 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3685 free(log_dir, M_SCSIDA);
3686 daprobedone(periph, start_ccb);
3689 start_ccb->ccb_h.ccb_bp = NULL;
3690 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3691 xpt_action(start_ccb);
3694 case DA_STATE_PROBE_ATA_IDDIR:
3696 struct ata_identify_log_pages *id_dir;
3702 * Check here to see whether the Identify Device log is
3703 * supported in the directory of logs. If so, continue
3704 * with requesting the log of identify device pages.
3706 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3707 daprobedone(periph, start_ccb);
3711 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3712 if (id_dir == NULL) {
3713 xpt_print(periph->path, "Couldn't malloc id_dir "
3715 daprobedone(periph, start_ccb);
3719 retval = scsi_ata_read_log(&start_ccb->csio,
3720 /*retries*/ da_retry_count,
3721 /*cbfcnp*/ dadone_probeataiddir,
3722 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3723 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3724 /*page_number*/ ATA_IDL_PAGE_LIST,
3726 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3727 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3728 /*data_ptr*/ (uint8_t *)id_dir,
3729 /*dxfer_len*/ sizeof(*id_dir),
3730 /*sense_len*/ SSD_FULL_SIZE,
3731 /*timeout*/ da_default_timeout * 1000);
3734 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3735 free(id_dir, M_SCSIDA);
3736 daprobedone(periph, start_ccb);
3739 start_ccb->ccb_h.ccb_bp = NULL;
3740 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3741 xpt_action(start_ccb);
3744 case DA_STATE_PROBE_ATA_SUP:
3746 struct ata_identify_log_sup_cap *sup_cap;
3752 * Check here to see whether the Supported Capabilities log
3753 * is in the list of Identify Device logs.
3755 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3756 daprobedone(periph, start_ccb);
3760 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3761 if (sup_cap == NULL) {
3762 xpt_print(periph->path, "Couldn't malloc sup_cap "
3764 daprobedone(periph, start_ccb);
3768 retval = scsi_ata_read_log(&start_ccb->csio,
3769 /*retries*/ da_retry_count,
3770 /*cbfcnp*/ dadone_probeatasup,
3771 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3772 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3773 /*page_number*/ ATA_IDL_SUP_CAP,
3775 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3776 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3777 /*data_ptr*/ (uint8_t *)sup_cap,
3778 /*dxfer_len*/ sizeof(*sup_cap),
3779 /*sense_len*/ SSD_FULL_SIZE,
3780 /*timeout*/ da_default_timeout * 1000);
3783 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3784 free(sup_cap, M_SCSIDA);
3785 daprobedone(periph, start_ccb);
3790 start_ccb->ccb_h.ccb_bp = NULL;
3791 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3792 xpt_action(start_ccb);
3795 case DA_STATE_PROBE_ATA_ZONE:
3797 struct ata_zoned_info_log *ata_zone;
3803 * Check here to see whether the zoned device information
3804 * page is supported. If so, continue on to request it.
3805 * If not, skip to DA_STATE_PROBE_LOG or done.
3807 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3808 daprobedone(periph, start_ccb);
3811 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3813 if (ata_zone == NULL) {
3814 xpt_print(periph->path, "Couldn't malloc ata_zone "
3816 daprobedone(periph, start_ccb);
3820 retval = scsi_ata_read_log(&start_ccb->csio,
3821 /*retries*/ da_retry_count,
3822 /*cbfcnp*/ dadone_probeatazone,
3823 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3824 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3825 /*page_number*/ ATA_IDL_ZDI,
3827 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3828 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3829 /*data_ptr*/ (uint8_t *)ata_zone,
3830 /*dxfer_len*/ sizeof(*ata_zone),
3831 /*sense_len*/ SSD_FULL_SIZE,
3832 /*timeout*/ da_default_timeout * 1000);
3835 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3836 free(ata_zone, M_SCSIDA);
3837 daprobedone(periph, start_ccb);
3840 start_ccb->ccb_h.ccb_bp = NULL;
3841 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3842 xpt_action(start_ccb);
3846 case DA_STATE_PROBE_ZONE:
3848 struct scsi_vpd_zoned_bdc *bdc;
3851 * Note that this page will be supported for SCSI protocol
3852 * devices that support ZBC (SMR devices), as well as ATA
3853 * protocol devices that are behind a SAT (SCSI to ATA
3854 * Translation) layer that supports converting ZBC commands
3855 * to their ZAC equivalents.
3857 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3858 daprobedone(periph, start_ccb);
3861 bdc = (struct scsi_vpd_zoned_bdc *)
3862 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3865 xpt_release_ccb(start_ccb);
3866 xpt_print(periph->path, "Couldn't malloc zone VPD "
3870 scsi_inquiry(&start_ccb->csio,
3871 /*retries*/da_retry_count,
3872 /*cbfcnp*/dadone_probezone,
3873 /*tag_action*/MSG_SIMPLE_Q_TAG,
3874 /*inq_buf*/(u_int8_t *)bdc,
3875 /*inq_len*/sizeof(*bdc),
3877 /*page_code*/SVPD_ZONED_BDC,
3878 /*sense_len*/SSD_FULL_SIZE,
3879 /*timeout*/da_default_timeout * 1000);
3880 start_ccb->ccb_h.ccb_bp = NULL;
3881 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3882 xpt_action(start_ccb);
3889 * In each of the methods below, while its the caller's
3890 * responsibility to ensure the request will fit into a
3891 * single device request, we might have changed the delete
3892 * method due to the device incorrectly advertising either
3893 * its supported methods or limits.
3895 * To prevent this causing further issues we validate the
3896 * against the methods limits, and warn which would
3897 * otherwise be unnecessary.
3900 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3902 struct da_softc *softc = (struct da_softc *)periph->softc;;
3904 uint8_t *buf = softc->unmap_buf;
3905 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3906 uint64_t lba, lastlba = (uint64_t)-1;
3907 uint64_t totalcount = 0;
3909 uint32_t c, lastcount = 0, ranges = 0;
3912 * Currently this doesn't take the UNMAP
3913 * Granularity and Granularity Alignment
3914 * fields into account.
3916 * This could result in both unoptimal unmap
3917 * requests as as well as UNMAP calls unmapping
3918 * fewer LBA's than requested.
3921 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3925 * Note: ada and da are different in how they store the
3926 * pending bp's in a trim. ada stores all of them in the
3927 * trim_req.bps. da stores all but the first one in the
3928 * delete_run_queue. ada then completes all the bps in
3929 * its adadone() loop. da completes all the bps in the
3930 * delete_run_queue in dadone, and relies on the biodone
3931 * after to complete. This should be reconciled since there's
3932 * no real reason to do it differently. XXX
3935 bioq_insert_tail(&softc->delete_run_queue, bp1);
3936 lba = bp1->bio_pblkno;
3937 count = bp1->bio_bcount / softc->params.secsize;
3939 /* Try to extend the previous range. */
3940 if (lba == lastlba) {
3941 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3944 scsi_ulto4b(lastcount, d[ranges - 1].length);
3948 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3949 softc->unmap_gran != 0) {
3950 /* Align length of the previous range. */
3951 if ((c = lastcount % softc->unmap_gran) != 0) {
3952 if (lastcount <= c) {
3953 totalcount -= lastcount;
3954 lastlba = (uint64_t)-1;
3961 scsi_ulto4b(lastcount,
3962 d[ranges - 1].length);
3965 /* Align beginning of the new range. */
3966 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3968 c = softc->unmap_gran - c;
3979 c = omin(count, UNMAP_RANGE_MAX);
3980 if (totalcount + c > softc->unmap_max_lba ||
3981 ranges >= softc->unmap_max_ranges) {
3982 xpt_print(periph->path,
3983 "%s issuing short delete %ld > %ld"
3985 da_delete_method_desc[softc->delete_method],
3986 totalcount + c, softc->unmap_max_lba,
3987 ranges, softc->unmap_max_ranges);
3990 scsi_u64to8b(lba, d[ranges].lba);
3991 scsi_ulto4b(c, d[ranges].length);
3999 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4002 if (ranges >= softc->unmap_max_ranges ||
4003 totalcount + bp1->bio_bcount /
4004 softc->params.secsize > softc->unmap_max_lba) {
4005 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4010 /* Align length of the last range. */
4011 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
4012 (c = lastcount % softc->unmap_gran) != 0) {
4016 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
4019 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
4020 scsi_ulto2b(ranges * 16, &buf[2]);
4022 scsi_unmap(&ccb->csio,
4023 /*retries*/da_retry_count,
4025 /*tag_action*/MSG_SIMPLE_Q_TAG,
4028 /*dxfer_len*/ ranges * 16 + 8,
4029 /*sense_len*/SSD_FULL_SIZE,
4030 da_default_timeout * 1000);
4031 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4032 ccb->ccb_h.flags |= CAM_UNLOCKED;
4033 softc->trim_count++;
4034 softc->trim_ranges += ranges;
4035 softc->trim_lbas += totalcount;
4036 cam_iosched_submit_trim(softc->cam_iosched);
4040 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4042 struct da_softc *softc = (struct da_softc *)periph->softc;
4044 uint8_t *buf = softc->unmap_buf;
4045 uint64_t lastlba = (uint64_t)-1;
4048 uint32_t lastcount = 0, c, requestcount;
4049 int ranges = 0, off, block_count;
4051 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
4054 if (bp1 != bp)//XXX imp XXX
4055 bioq_insert_tail(&softc->delete_run_queue, bp1);
4056 lba = bp1->bio_pblkno;
4057 count = bp1->bio_bcount / softc->params.secsize;
4058 requestcount = count;
4060 /* Try to extend the previous range. */
4061 if (lba == lastlba) {
4062 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
4064 off = (ranges - 1) * 8;
4065 buf[off + 6] = lastcount & 0xff;
4066 buf[off + 7] = (lastcount >> 8) & 0xff;
4072 c = omin(count, ATA_DSM_RANGE_MAX);
4075 buf[off + 0] = lba & 0xff;
4076 buf[off + 1] = (lba >> 8) & 0xff;
4077 buf[off + 2] = (lba >> 16) & 0xff;
4078 buf[off + 3] = (lba >> 24) & 0xff;
4079 buf[off + 4] = (lba >> 32) & 0xff;
4080 buf[off + 5] = (lba >> 40) & 0xff;
4081 buf[off + 6] = c & 0xff;
4082 buf[off + 7] = (c >> 8) & 0xff;
4087 if (count != 0 && ranges == softc->trim_max_ranges) {
4088 xpt_print(periph->path,
4089 "%s issuing short delete %ld > %ld\n",
4090 da_delete_method_desc[softc->delete_method],
4092 (softc->trim_max_ranges - ranges) *
4098 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4101 if (bp1->bio_bcount / softc->params.secsize >
4102 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
4103 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4108 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
4109 scsi_ata_trim(&ccb->csio,
4110 /*retries*/da_retry_count,
4112 /*tag_action*/MSG_SIMPLE_Q_TAG,
4115 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
4116 /*sense_len*/SSD_FULL_SIZE,
4117 da_default_timeout * 1000);
4118 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4119 ccb->ccb_h.flags |= CAM_UNLOCKED;
4120 cam_iosched_submit_trim(softc->cam_iosched);
4124 * We calculate ws_max_blks here based off d_delmaxsize instead
4125 * of using softc->ws_max_blks as it is absolute max for the
4126 * device not the protocol max which may well be lower.
4129 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4131 struct da_softc *softc;
4133 uint64_t ws_max_blks;
4135 uint64_t count; /* forward compat with WS32 */
4137 softc = (struct da_softc *)periph->softc;
4138 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
4139 lba = bp->bio_pblkno;
4143 if (bp1 != bp)//XXX imp XXX
4144 bioq_insert_tail(&softc->delete_run_queue, bp1);
4145 count += bp1->bio_bcount / softc->params.secsize;
4146 if (count > ws_max_blks) {
4147 xpt_print(periph->path,
4148 "%s issuing short delete %ld > %ld\n",
4149 da_delete_method_desc[softc->delete_method],
4150 count, ws_max_blks);
4151 count = omin(count, ws_max_blks);
4154 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4157 if (lba + count != bp1->bio_pblkno ||
4158 count + bp1->bio_bcount /
4159 softc->params.secsize > ws_max_blks) {
4160 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4165 scsi_write_same(&ccb->csio,
4166 /*retries*/da_retry_count,
4168 /*tag_action*/MSG_SIMPLE_Q_TAG,
4169 /*byte2*/softc->delete_method ==
4170 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
4171 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
4173 /*block_count*/count,
4174 /*data_ptr*/ __DECONST(void *, zero_region),
4175 /*dxfer_len*/ softc->params.secsize,
4176 /*sense_len*/SSD_FULL_SIZE,
4177 da_default_timeout * 1000);
4178 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4179 ccb->ccb_h.flags |= CAM_UNLOCKED;
4180 cam_iosched_submit_trim(softc->cam_iosched);
4184 cmd6workaround(union ccb *ccb)
4186 struct scsi_rw_6 cmd6;
4187 struct scsi_rw_10 *cmd10;
4188 struct da_softc *softc;
4193 cdb = ccb->csio.cdb_io.cdb_bytes;
4194 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
4196 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
4197 da_delete_methods old_method = softc->delete_method;
4200 * Typically there are two reasons for failure here
4201 * 1. Delete method was detected as supported but isn't
4202 * 2. Delete failed due to invalid params e.g. too big
4204 * While we will attempt to choose an alternative delete method
4205 * this may result in short deletes if the existing delete
4206 * requests from geom are big for the new method chosen.
4208 * This method assumes that the error which triggered this
4209 * will not retry the io otherwise a panic will occur
4211 dadeleteflag(softc, old_method, 0);
4212 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
4213 if (softc->delete_method == DA_DELETE_DISABLE)
4214 xpt_print(ccb->ccb_h.path,
4215 "%s failed, disabling BIO_DELETE\n",
4216 da_delete_method_desc[old_method]);
4218 xpt_print(ccb->ccb_h.path,
4219 "%s failed, switching to %s BIO_DELETE\n",
4220 da_delete_method_desc[old_method],
4221 da_delete_method_desc[softc->delete_method]);
4223 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
4224 cam_iosched_queue_work(softc->cam_iosched, bp);
4225 cam_iosched_queue_work(softc->cam_iosched,
4226 (struct bio *)ccb->ccb_h.ccb_bp);
4227 ccb->ccb_h.ccb_bp = NULL;
4231 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
4232 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4233 (*cdb == PREVENT_ALLOW) &&
4234 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
4236 xpt_print(ccb->ccb_h.path,
4237 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
4238 softc->quirks |= DA_Q_NO_PREVENT;
4242 /* Detect unsupported SYNCHRONIZE CACHE(10). */
4243 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4244 (*cdb == SYNCHRONIZE_CACHE) &&
4245 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
4247 xpt_print(ccb->ccb_h.path,
4248 "SYNCHRONIZE CACHE(10) not supported.\n");
4249 softc->quirks |= DA_Q_NO_SYNC_CACHE;
4250 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
4254 /* Translation only possible if CDB is an array and cmd is R/W6 */
4255 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
4256 (*cdb != READ_6 && *cdb != WRITE_6))
4259 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
4260 "increasing minimum_cmd_size to 10.\n");
4261 softc->minimum_cmd_size = 10;
4263 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
4264 cmd10 = (struct scsi_rw_10 *)cdb;
4265 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
4267 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
4268 cmd10->reserved = 0;
4269 scsi_ulto2b(cmd6.length, cmd10->length);
4270 cmd10->control = cmd6.control;
4271 ccb->csio.cdb_len = sizeof(*cmd10);
4273 /* Requeue request, unfreezing queue if necessary */
4274 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
4275 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4278 cam_release_devq(ccb->ccb_h.path,
4282 /*getcount_only*/0);
4288 dazonedone(struct cam_periph *periph, union ccb *ccb)
4290 struct da_softc *softc;
4293 softc = periph->softc;
4294 bp = (struct bio *)ccb->ccb_h.ccb_bp;
4296 switch (bp->bio_zone.zone_cmd) {
4297 case DISK_ZONE_OPEN:
4298 case DISK_ZONE_CLOSE:
4299 case DISK_ZONE_FINISH:
4302 case DISK_ZONE_REPORT_ZONES: {
4304 struct disk_zone_report *rep;
4305 struct scsi_report_zones_hdr *hdr;
4306 struct scsi_report_zones_desc *desc;
4307 struct disk_zone_rep_entry *entry;
4308 uint32_t hdr_len, num_avail;
4309 uint32_t num_to_fill, i;
4312 rep = &bp->bio_zone.zone_params.report;
4313 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
4315 * Note that bio_resid isn't normally used for zone
4316 * commands, but it is used by devstat_end_transaction_bio()
4317 * to determine how much data was transferred. Because
4318 * the size of the SCSI/ATA data structures is different
4319 * than the size of the BIO interface structures, the
4320 * amount of data actually transferred from the drive will
4321 * be different than the amount of data transferred to
4324 bp->bio_resid = ccb->csio.resid;
4325 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
4326 if (avail_len < sizeof(*hdr)) {
4328 * Is there a better error than EIO here? We asked
4329 * for at least the header, and we got less than
4332 bp->bio_error = EIO;
4333 bp->bio_flags |= BIO_ERROR;
4334 bp->bio_resid = bp->bio_bcount;
4338 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4343 hdr_len = ata ? le32dec(hdr->length) :
4344 scsi_4btoul(hdr->length);
4346 rep->entries_available = hdr_len / sizeof(*desc);
4348 rep->entries_available = 0;
4350 * NOTE: using the same values for the BIO version of the
4351 * same field as the SCSI/ATA values. This means we could
4352 * get some additional values that aren't defined in bio.h
4353 * if more values of the same field are defined later.
4355 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4356 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4357 scsi_8btou64(hdr->maximum_lba);
4359 * If the drive reports no entries that match the query,
4363 rep->entries_filled = 0;
4367 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4368 hdr_len / sizeof(*desc));
4370 * If the drive didn't return any data, then we're done.
4372 if (num_avail == 0) {
4373 rep->entries_filled = 0;
4377 num_to_fill = min(num_avail, rep->entries_allocated);
4379 * If the user didn't allocate any entries for us to fill,
4382 if (num_to_fill == 0) {
4383 rep->entries_filled = 0;
4387 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4388 i < num_to_fill; i++, desc++, entry++) {
4390 * NOTE: we're mapping the values here directly
4391 * from the SCSI/ATA bit definitions to the bio.h
4392 * definitons. There is also a warning in
4393 * disk_zone.h, but the impact is that if
4394 * additional values are added in the SCSI/ATA
4395 * specs these will be visible to consumers of
4398 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4399 entry->zone_condition =
4400 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4401 SRZ_ZONE_COND_SHIFT;
4402 entry->zone_flags |= desc->zone_flags &
4403 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4404 entry->zone_length =
4405 ata ? le64dec(desc->zone_length) :
4406 scsi_8btou64(desc->zone_length);
4407 entry->zone_start_lba =
4408 ata ? le64dec(desc->zone_start_lba) :
4409 scsi_8btou64(desc->zone_start_lba);
4410 entry->write_pointer_lba =
4411 ata ? le64dec(desc->write_pointer_lba) :
4412 scsi_8btou64(desc->write_pointer_lba);
4414 rep->entries_filled = num_to_fill;
4417 case DISK_ZONE_GET_PARAMS:
4420 * In theory we should not get a GET_PARAMS bio, since it
4421 * should be handled without queueing the command to the
4424 panic("%s: Invalid zone command %d", __func__,
4425 bp->bio_zone.zone_cmd);
4429 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4430 free(ccb->csio.data_ptr, M_SCSIDA);
4434 dadone(struct cam_periph *periph, union ccb *done_ccb)
4436 struct bio *bp, *bp1;
4437 struct da_softc *softc;
4438 struct ccb_scsiio *csio;
4442 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4444 softc = (struct da_softc *)periph->softc;
4445 priority = done_ccb->ccb_h.pinfo.priority;
4446 csio = &done_ccb->csio;
4448 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4449 if (csio->bio != NULL)
4450 biotrack(csio->bio, __func__);
4452 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4454 cam_periph_lock(periph);
4455 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4456 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4460 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4465 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4466 if (error == ERESTART) {
4467 /* A retry was scheduled, so just return. */
4468 cam_periph_unlock(periph);
4471 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4476 * return all queued I/O with EIO, so that
4477 * the client can retry these I/Os in the
4478 * proper order should it attempt to recover.
4483 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4485 * Catastrophic error. Mark our pack as
4488 * XXX See if this is really a media
4491 xpt_print(periph->path, "Invalidating pack\n");
4492 softc->flags |= DA_FLAG_PACK_INVALID;
4494 softc->invalidations++;
4496 queued_error = ENXIO;
4498 cam_iosched_flush(softc->cam_iosched, NULL,
4501 bp->bio_error = error;
4502 bp->bio_resid = bp->bio_bcount;
4503 bp->bio_flags |= BIO_ERROR;
4505 } else if (bp != NULL) {
4506 if (state == DA_CCB_DELETE)
4509 bp->bio_resid = csio->resid;
4511 if (bp->bio_resid != 0)
4512 bp->bio_flags |= BIO_ERROR;
4514 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4515 cam_release_devq(done_ccb->ccb_h.path,
4519 /*getcount_only*/0);
4520 } else if (bp != NULL) {
4521 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4522 panic("REQ_CMP with QFRZN");
4523 if (bp->bio_cmd == BIO_ZONE)
4524 dazonedone(periph, done_ccb);
4525 else if (state == DA_CCB_DELETE)
4528 bp->bio_resid = csio->resid;
4529 if ((csio->resid > 0) && (bp->bio_cmd != BIO_ZONE))
4530 bp->bio_flags |= BIO_ERROR;
4531 if (softc->error_inject != 0) {
4532 bp->bio_error = softc->error_inject;
4533 bp->bio_resid = bp->bio_bcount;
4534 bp->bio_flags |= BIO_ERROR;
4535 softc->error_inject = 0;
4540 biotrack(bp, __func__);
4541 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4542 if (LIST_EMPTY(&softc->pending_ccbs))
4543 softc->flags |= DA_FLAG_WAS_OTAG;
4546 * We need to call cam_iosched before we call biodone so that we don't
4547 * measure any activity that happens in the completion routine, which in
4548 * the case of sendfile can be quite extensive. Release the periph
4549 * refcount taken in dastart() for each CCB.
4551 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4552 xpt_release_ccb(done_ccb);
4553 KASSERT(softc->refcount >= 1, ("dadone softc %p refcount %d", softc, softc->refcount));
4555 if (state == DA_CCB_DELETE) {
4556 TAILQ_HEAD(, bio) queue;
4559 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4560 softc->delete_run_queue.insert_point = NULL;
4562 * Normally, the xpt_release_ccb() above would make sure
4563 * that when we have more work to do, that work would
4564 * get kicked off. However, we specifically keep
4565 * delete_running set to 0 before the call above to
4566 * allow other I/O to progress when many BIO_DELETE
4567 * requests are pushed down. We set delete_running to 0
4568 * and call daschedule again so that we don't stall if
4569 * there are no other I/Os pending apart from BIO_DELETEs.
4571 cam_iosched_trim_done(softc->cam_iosched);
4573 cam_periph_unlock(periph);
4574 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4575 TAILQ_REMOVE(&queue, bp1, bio_queue);
4576 bp1->bio_error = bp->bio_error;
4577 if (bp->bio_flags & BIO_ERROR) {
4578 bp1->bio_flags |= BIO_ERROR;
4579 bp1->bio_resid = bp1->bio_bcount;
4586 cam_periph_unlock(periph);
4594 dadone_probewp(struct cam_periph *periph, union ccb *done_ccb)
4596 struct scsi_mode_header_6 *mode_hdr6;
4597 struct scsi_mode_header_10 *mode_hdr10;
4598 struct da_softc *softc;
4599 struct ccb_scsiio *csio;
4603 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probewp\n"));
4605 softc = (struct da_softc *)periph->softc;
4606 priority = done_ccb->ccb_h.pinfo.priority;
4607 csio = &done_ccb->csio;
4609 cam_periph_assert(periph, MA_OWNED);
4611 if (softc->minimum_cmd_size > 6) {
4612 mode_hdr10 = (struct scsi_mode_header_10 *)csio->data_ptr;
4613 dev_spec = mode_hdr10->dev_spec;
4615 mode_hdr6 = (struct scsi_mode_header_6 *)csio->data_ptr;
4616 dev_spec = mode_hdr6->dev_spec;
4618 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
4619 if ((dev_spec & 0x80) != 0)
4620 softc->disk->d_flags |= DISKFLAG_WRITE_PROTECT;
4622 softc->disk->d_flags &= ~DISKFLAG_WRITE_PROTECT;
4626 error = daerror(done_ccb, CAM_RETRY_SELTO,
4627 SF_RETRY_UA|SF_NO_PRINT);
4628 if (error == ERESTART)
4630 else if (error != 0) {
4631 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4632 /* Don't wedge this device's queue */
4633 cam_release_devq(done_ccb->ccb_h.path,
4637 /*getcount_only*/0);
4642 free(csio->data_ptr, M_SCSIDA);
4643 xpt_release_ccb(done_ccb);
4644 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
4645 softc->state = DA_STATE_PROBE_RC16;
4647 softc->state = DA_STATE_PROBE_RC;
4648 xpt_schedule(periph, priority);
4653 dadone_proberc(struct cam_periph *periph, union ccb *done_ccb)
4655 struct scsi_read_capacity_data *rdcap;
4656 struct scsi_read_capacity_data_long *rcaplong;
4657 struct da_softc *softc;
4658 struct ccb_scsiio *csio;
4664 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_proberc\n"));
4666 softc = (struct da_softc *)periph->softc;
4667 priority = done_ccb->ccb_h.pinfo.priority;
4668 csio = &done_ccb->csio;
4669 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4674 /* XXX TODO: can this be a malloc? */
4675 announce_buf = softc->announce_temp;
4676 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4678 if (state == DA_CCB_PROBE_RC)
4679 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4681 rcaplong = (struct scsi_read_capacity_data_long *)
4684 cam_periph_assert(periph, MA_OWNED);
4686 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4687 struct disk_params *dp;
4688 uint32_t block_size;
4690 u_int lalba; /* Lowest aligned LBA. */
4692 if (state == DA_CCB_PROBE_RC) {
4693 block_size = scsi_4btoul(rdcap->length);
4694 maxsector = scsi_4btoul(rdcap->addr);
4698 * According to SBC-2, if the standard 10
4699 * byte READ CAPACITY command returns 2^32,
4700 * we should issue the 16 byte version of
4701 * the command, since the device in question
4702 * has more sectors than can be represented
4703 * with the short version of the command.
4705 if (maxsector == 0xffffffff) {
4706 free(rdcap, M_SCSIDA);
4707 xpt_release_ccb(done_ccb);
4708 softc->state = DA_STATE_PROBE_RC16;
4709 xpt_schedule(periph, priority);
4713 block_size = scsi_4btoul(rcaplong->length);
4714 maxsector = scsi_8btou64(rcaplong->addr);
4715 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4719 * Because GEOM code just will panic us if we
4720 * give them an 'illegal' value we'll avoid that
4723 if (block_size == 0) {
4728 if (block_size >= MAXPHYS) {
4729 xpt_print(periph->path,
4730 "unsupportable block size %ju\n",
4731 (uintmax_t) block_size);
4732 announce_buf = NULL;
4733 cam_periph_invalidate(periph);
4736 * We pass rcaplong into dasetgeom(),
4737 * because it will only use it if it is
4740 dasetgeom(periph, block_size, maxsector,
4741 rcaplong, sizeof(*rcaplong));
4742 lbp = (lalba & SRC16_LBPME_A);
4743 dp = &softc->params;
4744 n = snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4745 "%juMB (%ju %u byte sectors",
4746 ((uintmax_t)dp->secsize * dp->sectors) /
4748 (uintmax_t)dp->sectors, dp->secsize);
4749 if (softc->p_type != 0) {
4750 n += snprintf(announce_buf + n,
4751 DA_ANNOUNCETMP_SZ - n,
4752 ", DIF type %d", softc->p_type);
4754 snprintf(announce_buf + n, DA_ANNOUNCETMP_SZ - n, ")");
4760 * Retry any UNIT ATTENTION type errors. They
4761 * are expected at boot.
4763 error = daerror(done_ccb, CAM_RETRY_SELTO,
4764 SF_RETRY_UA|SF_NO_PRINT);
4765 if (error == ERESTART) {
4767 * A retry was scheuled, so
4771 } else if (error != 0) {
4773 int sense_key, error_code;
4776 struct ccb_getdev cgd;
4778 /* Don't wedge this device's queue */
4779 status = done_ccb->ccb_h.status;
4780 if ((status & CAM_DEV_QFRZN) != 0)
4781 cam_release_devq(done_ccb->ccb_h.path,
4785 /*getcount_only*/0);
4788 xpt_setup_ccb(&cgd.ccb_h, done_ccb->ccb_h.path,
4789 CAM_PRIORITY_NORMAL);
4790 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4791 xpt_action((union ccb *)&cgd);
4793 if (scsi_extract_sense_ccb(done_ccb,
4794 &error_code, &sense_key, &asc, &ascq))
4800 * If we tried READ CAPACITY(16) and failed,
4801 * fallback to READ CAPACITY(10).
4803 if ((state == DA_CCB_PROBE_RC16) &&
4804 (softc->flags & DA_FLAG_CAN_RC16) &&
4805 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4808 (error_code == SSD_CURRENT_ERROR ||
4809 error_code == SSD_DESC_CURRENT_ERROR) &&
4810 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4811 cam_periph_assert(periph, MA_OWNED);
4812 softc->flags &= ~DA_FLAG_CAN_RC16;
4813 free(rdcap, M_SCSIDA);
4814 xpt_release_ccb(done_ccb);
4815 softc->state = DA_STATE_PROBE_RC;
4816 xpt_schedule(periph, priority);
4821 * Attach to anything that claims to be a
4822 * direct access or optical disk device,
4823 * as long as it doesn't return a "Logical
4824 * unit not supported" (0x25) error.
4825 * "Internal Target Failure" (0x44) is also
4826 * special and typically means that the
4827 * device is a SATA drive behind a SATL
4828 * translation that's fallen into a
4829 * terminally fatal state.
4832 && (asc != 0x25) && (asc != 0x44)
4833 && (error_code == SSD_CURRENT_ERROR
4834 || error_code == SSD_DESC_CURRENT_ERROR)) {
4835 const char *sense_key_desc;
4836 const char *asc_desc;
4838 dasetgeom(periph, 512, -1, NULL, 0);
4839 scsi_sense_desc(sense_key, asc, ascq,
4840 &cgd.inq_data, &sense_key_desc,
4842 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4843 "Attempt to query device "
4844 "size failed: %s, %s",
4845 sense_key_desc, asc_desc);
4848 scsi_sense_print(&done_ccb->csio);
4850 xpt_print(periph->path,
4851 "got CAM status %#x\n",
4852 done_ccb->ccb_h.status);
4855 xpt_print(periph->path, "fatal error, "
4856 "failed to attach to device\n");
4858 announce_buf = NULL;
4861 * Free up resources.
4863 cam_periph_invalidate(periph);
4867 free(csio->data_ptr, M_SCSIDA);
4868 if (announce_buf != NULL &&
4869 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4872 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4874 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4875 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4881 * Create our sysctl variables, now that we know
4882 * we have successfully attached.
4884 /* increase the refcount */
4885 if (da_periph_acquire(periph, DA_REF_SYSCTL) == 0) {
4886 taskqueue_enqueue(taskqueue_thread,
4887 &softc->sysctl_task);
4889 /* XXX This message is useless! */
4890 xpt_print(periph->path, "fatal error, "
4891 "could not acquire reference count\n");
4895 /* We already probed the device. */
4896 if (softc->flags & DA_FLAG_PROBED) {
4897 daprobedone(periph, done_ccb);
4901 /* Ensure re-probe doesn't see old delete. */
4902 softc->delete_available = 0;
4903 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4904 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4906 * Based on older SBC-3 spec revisions
4907 * any of the UNMAP methods "may" be
4908 * available via LBP given this flag so
4909 * we flag all of them as available and
4910 * then remove those which further
4911 * probes confirm aren't available
4914 * We could also check readcap(16) p_type
4915 * flag to exclude one or more invalid
4916 * write same (X) types here
4918 dadeleteflag(softc, DA_DELETE_WS16, 1);
4919 dadeleteflag(softc, DA_DELETE_WS10, 1);
4920 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4922 xpt_release_ccb(done_ccb);
4923 softc->state = DA_STATE_PROBE_LBP;
4924 xpt_schedule(periph, priority);
4928 xpt_release_ccb(done_ccb);
4929 softc->state = DA_STATE_PROBE_BDC;
4930 xpt_schedule(periph, priority);
4935 dadone_probelbp(struct cam_periph *periph, union ccb *done_ccb)
4937 struct scsi_vpd_logical_block_prov *lbp;
4938 struct da_softc *softc;
4939 struct ccb_scsiio *csio;
4942 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probelbp\n"));
4944 softc = (struct da_softc *)periph->softc;
4945 priority = done_ccb->ccb_h.pinfo.priority;
4946 csio = &done_ccb->csio;
4947 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4949 cam_periph_assert(periph, MA_OWNED);
4951 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4953 * T10/1799-D Revision 31 states at least one of these
4954 * must be supported but we don't currently enforce this.
4956 dadeleteflag(softc, DA_DELETE_WS16,
4957 (lbp->flags & SVPD_LBP_WS16));
4958 dadeleteflag(softc, DA_DELETE_WS10,
4959 (lbp->flags & SVPD_LBP_WS10));
4960 dadeleteflag(softc, DA_DELETE_UNMAP,
4961 (lbp->flags & SVPD_LBP_UNMAP));
4964 error = daerror(done_ccb, CAM_RETRY_SELTO,
4965 SF_RETRY_UA|SF_NO_PRINT);
4966 if (error == ERESTART)
4968 else if (error != 0) {
4969 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4970 /* Don't wedge this device's queue */
4971 cam_release_devq(done_ccb->ccb_h.path,
4975 /*getcount_only*/0);
4979 * Failure indicates we don't support any SBC-3
4980 * delete methods with UNMAP
4985 free(lbp, M_SCSIDA);
4986 xpt_release_ccb(done_ccb);
4987 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4988 xpt_schedule(periph, priority);
4993 dadone_probeblklimits(struct cam_periph *periph, union ccb *done_ccb)
4995 struct scsi_vpd_block_limits *block_limits;
4996 struct da_softc *softc;
4997 struct ccb_scsiio *csio;
5000 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeblklimits\n"));
5002 softc = (struct da_softc *)periph->softc;
5003 priority = done_ccb->ccb_h.pinfo.priority;
5004 csio = &done_ccb->csio;
5005 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
5007 cam_periph_assert(periph, MA_OWNED);
5009 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5010 uint32_t max_txfer_len = scsi_4btoul(
5011 block_limits->max_txfer_len);
5012 uint32_t max_unmap_lba_cnt = scsi_4btoul(
5013 block_limits->max_unmap_lba_cnt);
5014 uint32_t max_unmap_blk_cnt = scsi_4btoul(
5015 block_limits->max_unmap_blk_cnt);
5016 uint32_t unmap_gran = scsi_4btoul(
5017 block_limits->opt_unmap_grain);
5018 uint32_t unmap_gran_align = scsi_4btoul(
5019 block_limits->unmap_grain_align);
5020 uint64_t ws_max_blks = scsi_8btou64(
5021 block_limits->max_write_same_length);
5023 if (max_txfer_len != 0) {
5024 softc->disk->d_maxsize = MIN(softc->maxio,
5025 (off_t)max_txfer_len * softc->params.secsize);
5029 * We should already support UNMAP but we check lba
5030 * and block count to be sure
5032 if (max_unmap_lba_cnt != 0x00L &&
5033 max_unmap_blk_cnt != 0x00L) {
5034 softc->unmap_max_lba = max_unmap_lba_cnt;
5035 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
5037 if (unmap_gran > 1) {
5038 softc->unmap_gran = unmap_gran;
5039 if (unmap_gran_align & 0x80000000) {
5040 softc->unmap_gran_align =
5041 unmap_gran_align & 0x7fffffff;
5046 * Unexpected UNMAP limits which means the
5047 * device doesn't actually support UNMAP
5049 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
5052 if (ws_max_blks != 0x00L)
5053 softc->ws_max_blks = ws_max_blks;
5056 error = daerror(done_ccb, CAM_RETRY_SELTO,
5057 SF_RETRY_UA|SF_NO_PRINT);
5058 if (error == ERESTART)
5060 else if (error != 0) {
5061 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5062 /* Don't wedge this device's queue */
5063 cam_release_devq(done_ccb->ccb_h.path,
5067 /*getcount_only*/0);
5071 * Failure here doesn't mean UNMAP is not
5072 * supported as this is an optional page.
5074 softc->unmap_max_lba = 1;
5075 softc->unmap_max_ranges = 1;
5079 free(block_limits, M_SCSIDA);
5080 xpt_release_ccb(done_ccb);
5081 softc->state = DA_STATE_PROBE_BDC;
5082 xpt_schedule(periph, priority);
5087 dadone_probebdc(struct cam_periph *periph, union ccb *done_ccb)
5089 struct scsi_vpd_block_device_characteristics *bdc;
5090 struct da_softc *softc;
5091 struct ccb_scsiio *csio;
5094 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probebdc\n"));
5096 softc = (struct da_softc *)periph->softc;
5097 priority = done_ccb->ccb_h.pinfo.priority;
5098 csio = &done_ccb->csio;
5099 bdc = (struct scsi_vpd_block_device_characteristics *)csio->data_ptr;
5101 cam_periph_assert(periph, MA_OWNED);
5103 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5107 * Disable queue sorting for non-rotational media
5110 u_int16_t old_rate = softc->disk->d_rotation_rate;
5112 valid_len = csio->dxfer_len - csio->resid;
5113 if (SBDC_IS_PRESENT(bdc, valid_len,
5114 medium_rotation_rate)) {
5115 softc->disk->d_rotation_rate =
5116 scsi_2btoul(bdc->medium_rotation_rate);
5117 if (softc->disk->d_rotation_rate ==
5118 SVPD_BDC_RATE_NON_ROTATING) {
5119 cam_iosched_set_sort_queue(
5120 softc->cam_iosched, 0);
5121 softc->rotating = 0;
5123 if (softc->disk->d_rotation_rate != old_rate) {
5124 disk_attr_changed(softc->disk,
5125 "GEOM::rotation_rate", M_NOWAIT);
5128 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
5129 && (softc->zone_mode == DA_ZONE_NONE)) {
5132 if (scsi_vpd_supported_page(periph,
5133 SVPD_ATA_INFORMATION))
5139 * The Zoned field will only be set for
5140 * Drive Managed and Host Aware drives. If
5141 * they are Host Managed, the device type
5142 * in the standard INQUIRY data should be
5143 * set to T_ZBC_HM (0x14).
5145 if ((bdc->flags & SVPD_ZBC_MASK) ==
5147 softc->zone_mode = DA_ZONE_HOST_AWARE;
5148 softc->zone_interface = (ata_proto) ?
5149 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5150 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
5152 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5153 softc->zone_interface = (ata_proto) ?
5154 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5155 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
5157 xpt_print(periph->path, "Unknown zoned "
5159 bdc->flags & SVPD_ZBC_MASK);
5164 error = daerror(done_ccb, CAM_RETRY_SELTO,
5165 SF_RETRY_UA|SF_NO_PRINT);
5166 if (error == ERESTART)
5168 else if (error != 0) {
5169 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5170 /* Don't wedge this device's queue */
5171 cam_release_devq(done_ccb->ccb_h.path,
5175 /*getcount_only*/0);
5180 free(bdc, M_SCSIDA);
5181 xpt_release_ccb(done_ccb);
5182 softc->state = DA_STATE_PROBE_ATA;
5183 xpt_schedule(periph, priority);
5188 dadone_probeata(struct cam_periph *periph, union ccb *done_ccb)
5190 struct ata_params *ata_params;
5191 struct ccb_scsiio *csio;
5192 struct da_softc *softc;
5198 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeata\n"));
5200 softc = (struct da_softc *)periph->softc;
5201 priority = done_ccb->ccb_h.pinfo.priority;
5202 csio = &done_ccb->csio;
5203 ata_params = (struct ata_params *)csio->data_ptr;
5204 ptr = (uint16_t *)ata_params;
5208 cam_periph_assert(periph, MA_OWNED);
5210 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5213 for (i = 0; i < sizeof(*ata_params) / 2; i++)
5214 ptr[i] = le16toh(ptr[i]);
5215 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
5216 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
5217 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
5218 if (ata_params->max_dsm_blocks != 0)
5219 softc->trim_max_ranges = min(
5220 softc->trim_max_ranges,
5221 ata_params->max_dsm_blocks *
5222 ATA_DSM_BLK_RANGES);
5225 * Disable queue sorting for non-rotational media
5228 old_rate = softc->disk->d_rotation_rate;
5229 softc->disk->d_rotation_rate = ata_params->media_rotation_rate;
5230 if (softc->disk->d_rotation_rate == ATA_RATE_NON_ROTATING) {
5231 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
5232 softc->rotating = 0;
5234 if (softc->disk->d_rotation_rate != old_rate) {
5235 disk_attr_changed(softc->disk,
5236 "GEOM::rotation_rate", M_NOWAIT);
5239 cam_periph_assert(periph, MA_OWNED);
5240 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
5241 softc->flags |= DA_FLAG_CAN_ATA_DMA;
5243 if (ata_params->support.extension & ATA_SUPPORT_GENLOG)
5244 softc->flags |= DA_FLAG_CAN_ATA_LOG;
5247 * At this point, if we have a SATA host aware drive,
5248 * we communicate via ATA passthrough unless the
5249 * SAT layer supports ZBC -> ZAC translation. In
5252 * XXX KDM figure out how to detect a host managed
5255 if (softc->zone_mode == DA_ZONE_NONE) {
5257 * Note that we don't override the zone
5258 * mode or interface if it has already been
5259 * set. This is because it has either been
5260 * set as a quirk, or when we probed the
5261 * SCSI Block Device Characteristics page,
5262 * the zoned field was set. The latter
5263 * means that the SAT layer supports ZBC to
5264 * ZAC translation, and we would prefer to
5265 * use that if it is available.
5267 if ((ata_params->support3 &
5268 ATA_SUPPORT_ZONE_MASK) ==
5269 ATA_SUPPORT_ZONE_HOST_AWARE) {
5270 softc->zone_mode = DA_ZONE_HOST_AWARE;
5271 softc->zone_interface =
5272 DA_ZONE_IF_ATA_PASS;
5273 } else if ((ata_params->support3 &
5274 ATA_SUPPORT_ZONE_MASK) ==
5275 ATA_SUPPORT_ZONE_DEV_MANAGED) {
5276 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5277 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
5282 error = daerror(done_ccb, CAM_RETRY_SELTO,
5283 SF_RETRY_UA|SF_NO_PRINT);
5284 if (error == ERESTART)
5286 else if (error != 0) {
5287 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5288 /* Don't wedge this device's queue */
5289 cam_release_devq(done_ccb->ccb_h.path,
5293 /*getcount_only*/0);
5298 free(ata_params, M_SCSIDA);
5299 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
5300 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
5302 * If the ATA IDENTIFY failed, we could be talking
5303 * to a SCSI drive, although that seems unlikely,
5304 * since the drive did report that it supported the
5305 * ATA Information VPD page. If the ATA IDENTIFY
5306 * succeeded, and the SAT layer doesn't support
5307 * ZBC -> ZAC translation, continue on to get the
5308 * directory of ATA logs, and complete the rest of
5309 * the ZAC probe. If the SAT layer does support
5310 * ZBC -> ZAC translation, we want to use that,
5311 * and we'll probe the SCSI Zoned Block Device
5312 * Characteristics VPD page next.
5315 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
5316 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
5317 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
5319 softc->state = DA_STATE_PROBE_ZONE;
5322 if (continue_probe != 0) {
5323 xpt_release_ccb(done_ccb);
5324 xpt_schedule(periph, priority);
5327 daprobedone(periph, done_ccb);
5332 dadone_probeatalogdir(struct cam_periph *periph, union ccb *done_ccb)
5334 struct da_softc *softc;
5335 struct ccb_scsiio *csio;
5339 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatalogdir\n"));
5341 softc = (struct da_softc *)periph->softc;
5342 priority = done_ccb->ccb_h.pinfo.priority;
5343 csio = &done_ccb->csio;
5345 cam_periph_assert(periph, MA_OWNED);
5346 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5348 softc->valid_logdir_len = 0;
5349 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
5350 softc->valid_logdir_len = csio->dxfer_len - csio->resid;
5351 if (softc->valid_logdir_len > 0)
5352 bcopy(csio->data_ptr, &softc->ata_logdir,
5353 min(softc->valid_logdir_len,
5354 sizeof(softc->ata_logdir)));
5356 * Figure out whether the Identify Device log is
5357 * supported. The General Purpose log directory
5358 * has a header, and lists the number of pages
5359 * available for each GP log identified by the
5360 * offset into the list.
5362 if ((softc->valid_logdir_len >=
5363 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
5364 && (le16dec(softc->ata_logdir.header) ==
5365 ATA_GP_LOG_DIR_VERSION)
5366 && (le16dec(&softc->ata_logdir.num_pages[
5367 (ATA_IDENTIFY_DATA_LOG *
5368 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
5369 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
5371 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5374 error = daerror(done_ccb, CAM_RETRY_SELTO,
5375 SF_RETRY_UA|SF_NO_PRINT);
5376 if (error == ERESTART)
5378 else if (error != 0) {
5380 * If we can't get the ATA log directory,
5381 * then ATA logs are effectively not
5382 * supported even if the bit is set in the
5385 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
5386 DA_FLAG_CAN_ATA_IDLOG);
5387 if ((done_ccb->ccb_h.status &
5388 CAM_DEV_QFRZN) != 0) {
5389 /* Don't wedge this device's queue */
5390 cam_release_devq(done_ccb->ccb_h.path,
5394 /*getcount_only*/0);
5399 free(csio->data_ptr, M_SCSIDA);
5402 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
5403 softc->state = DA_STATE_PROBE_ATA_IDDIR;
5404 xpt_release_ccb(done_ccb);
5405 xpt_schedule(periph, priority);
5408 daprobedone(periph, done_ccb);
5413 dadone_probeataiddir(struct cam_periph *periph, union ccb *done_ccb)
5415 struct da_softc *softc;
5416 struct ccb_scsiio *csio;
5420 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeataiddir\n"));
5422 softc = (struct da_softc *)periph->softc;
5423 priority = done_ccb->ccb_h.pinfo.priority;
5424 csio = &done_ccb->csio;
5426 cam_periph_assert(periph, MA_OWNED);
5428 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5429 off_t entries_offset, max_entries;
5432 softc->valid_iddir_len = 0;
5433 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
5434 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
5435 DA_FLAG_CAN_ATA_ZONE);
5436 softc->valid_iddir_len = csio->dxfer_len - csio->resid;
5437 if (softc->valid_iddir_len > 0)
5438 bcopy(csio->data_ptr, &softc->ata_iddir,
5439 min(softc->valid_iddir_len,
5440 sizeof(softc->ata_iddir)));
5443 __offsetof(struct ata_identify_log_pages,entries);
5444 max_entries = softc->valid_iddir_len - entries_offset;
5445 if ((softc->valid_iddir_len > (entries_offset + 1))
5446 && (le64dec(softc->ata_iddir.header) == ATA_IDLOG_REVISION)
5447 && (softc->ata_iddir.entry_count > 0)) {
5450 num_entries = softc->ata_iddir.entry_count;
5451 num_entries = min(num_entries,
5452 softc->valid_iddir_len - entries_offset);
5453 for (i = 0; i < num_entries && i < max_entries; i++) {
5454 if (softc->ata_iddir.entries[i] ==
5456 softc->flags |= DA_FLAG_CAN_ATA_SUPCAP;
5457 else if (softc->ata_iddir.entries[i] ==
5459 softc->flags |= DA_FLAG_CAN_ATA_ZONE;
5461 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP)
5462 && (softc->flags & DA_FLAG_CAN_ATA_ZONE))
5467 error = daerror(done_ccb, CAM_RETRY_SELTO,
5468 SF_RETRY_UA|SF_NO_PRINT);
5469 if (error == ERESTART)
5471 else if (error != 0) {
5473 * If we can't get the ATA Identify Data log
5474 * directory, then it effectively isn't
5475 * supported even if the ATA Log directory
5476 * a non-zero number of pages present for
5479 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5480 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5481 /* Don't wedge this device's queue */
5482 cam_release_devq(done_ccb->ccb_h.path,
5486 /*getcount_only*/0);
5491 free(csio->data_ptr, M_SCSIDA);
5493 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5494 softc->state = DA_STATE_PROBE_ATA_SUP;
5495 xpt_release_ccb(done_ccb);
5496 xpt_schedule(periph, priority);
5499 daprobedone(periph, done_ccb);
5504 dadone_probeatasup(struct cam_periph *periph, union ccb *done_ccb)
5506 struct da_softc *softc;
5507 struct ccb_scsiio *csio;
5511 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatasup\n"));
5513 softc = (struct da_softc *)periph->softc;
5514 priority = done_ccb->ccb_h.pinfo.priority;
5515 csio = &done_ccb->csio;
5517 cam_periph_assert(periph, MA_OWNED);
5519 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5522 struct ata_identify_log_sup_cap *sup_cap;
5525 sup_cap = (struct ata_identify_log_sup_cap *)csio->data_ptr;
5526 valid_len = csio->dxfer_len - csio->resid;
5527 needed_size = __offsetof(struct ata_identify_log_sup_cap,
5528 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5529 if (valid_len >= needed_size) {
5530 uint64_t zoned, zac_cap;
5532 zoned = le64dec(sup_cap->zoned_cap);
5533 if (zoned & ATA_ZONED_VALID) {
5535 * This should have already been
5536 * set, because this is also in the
5537 * ATA identify data.
5539 if ((zoned & ATA_ZONED_MASK) ==
5540 ATA_SUPPORT_ZONE_HOST_AWARE)
5541 softc->zone_mode = DA_ZONE_HOST_AWARE;
5542 else if ((zoned & ATA_ZONED_MASK) ==
5543 ATA_SUPPORT_ZONE_DEV_MANAGED)
5545 DA_ZONE_DRIVE_MANAGED;
5548 zac_cap = le64dec(sup_cap->sup_zac_cap);
5549 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5550 if (zac_cap & ATA_REPORT_ZONES_SUP)
5551 softc->zone_flags |=
5552 DA_ZONE_FLAG_RZ_SUP;
5553 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5554 softc->zone_flags |=
5555 DA_ZONE_FLAG_OPEN_SUP;
5556 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5557 softc->zone_flags |=
5558 DA_ZONE_FLAG_CLOSE_SUP;
5559 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5560 softc->zone_flags |=
5561 DA_ZONE_FLAG_FINISH_SUP;
5562 if (zac_cap & ATA_ND_RWP_SUP)
5563 softc->zone_flags |=
5564 DA_ZONE_FLAG_RWP_SUP;
5567 * This field was introduced in
5568 * ACS-4, r08 on April 28th, 2015.
5569 * If the drive firmware was written
5570 * to an earlier spec, it won't have
5571 * the field. So, assume all
5572 * commands are supported.
5574 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5578 error = daerror(done_ccb, CAM_RETRY_SELTO,
5579 SF_RETRY_UA|SF_NO_PRINT);
5580 if (error == ERESTART)
5582 else if (error != 0) {
5584 * If we can't get the ATA Identify Data
5585 * Supported Capabilities page, clear the
5588 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5590 * And clear zone capabilities.
5592 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5593 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5594 /* Don't wedge this device's queue */
5595 cam_release_devq(done_ccb->ccb_h.path,
5599 /*getcount_only*/0);
5604 free(csio->data_ptr, M_SCSIDA);
5606 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5607 softc->state = DA_STATE_PROBE_ATA_ZONE;
5608 xpt_release_ccb(done_ccb);
5609 xpt_schedule(periph, priority);
5612 daprobedone(periph, done_ccb);
5617 dadone_probeatazone(struct cam_periph *periph, union ccb *done_ccb)
5619 struct da_softc *softc;
5620 struct ccb_scsiio *csio;
5623 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatazone\n"));
5625 softc = (struct da_softc *)periph->softc;
5626 csio = &done_ccb->csio;
5628 cam_periph_assert(periph, MA_OWNED);
5630 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5631 struct ata_zoned_info_log *zi_log;
5635 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5637 valid_len = csio->dxfer_len - csio->resid;
5638 needed_size = __offsetof(struct ata_zoned_info_log,
5639 version_info) + 1 + sizeof(zi_log->version_info);
5640 if (valid_len >= needed_size) {
5643 tmpvar = le64dec(zi_log->zoned_cap);
5644 if (tmpvar & ATA_ZDI_CAP_VALID) {
5645 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5646 softc->zone_flags |=
5647 DA_ZONE_FLAG_URSWRZ;
5649 softc->zone_flags &=
5650 ~DA_ZONE_FLAG_URSWRZ;
5652 tmpvar = le64dec(zi_log->optimal_seq_zones);
5653 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5654 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5655 softc->optimal_seq_zones = (tmpvar &
5656 ATA_ZDI_OPT_SEQ_MASK);
5658 softc->zone_flags &= ~DA_ZONE_FLAG_OPT_SEQ_SET;
5659 softc->optimal_seq_zones = 0;
5662 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5663 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5664 softc->zone_flags |=
5665 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5666 softc->optimal_nonseq_zones =
5667 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5669 softc->zone_flags &=
5670 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5671 softc->optimal_nonseq_zones = 0;
5674 tmpvar = le64dec(zi_log->max_seq_req_zones);
5675 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5676 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5677 softc->max_seq_zones =
5678 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5680 softc->zone_flags &= ~DA_ZONE_FLAG_MAX_SEQ_SET;
5681 softc->max_seq_zones = 0;
5685 error = daerror(done_ccb, CAM_RETRY_SELTO,
5686 SF_RETRY_UA|SF_NO_PRINT);
5687 if (error == ERESTART)
5689 else if (error != 0) {
5690 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5691 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5693 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5694 /* Don't wedge this device's queue */
5695 cam_release_devq(done_ccb->ccb_h.path,
5699 /*getcount_only*/0);
5705 free(csio->data_ptr, M_SCSIDA);
5707 daprobedone(periph, done_ccb);
5712 dadone_probezone(struct cam_periph *periph, union ccb *done_ccb)
5714 struct da_softc *softc;
5715 struct ccb_scsiio *csio;
5718 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probezone\n"));
5720 softc = (struct da_softc *)periph->softc;
5721 csio = &done_ccb->csio;
5723 cam_periph_assert(periph, MA_OWNED);
5725 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5728 struct scsi_vpd_zoned_bdc *zoned_bdc;
5731 zoned_bdc = (struct scsi_vpd_zoned_bdc *)csio->data_ptr;
5732 valid_len = csio->dxfer_len - csio->resid;
5733 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5734 max_seq_req_zones) + 1 +
5735 sizeof(zoned_bdc->max_seq_req_zones);
5736 if ((valid_len >= needed_len)
5737 && (scsi_2btoul(zoned_bdc->page_length) >= SVPD_ZBDC_PL)) {
5738 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5739 softc->zone_flags |= DA_ZONE_FLAG_URSWRZ;
5741 softc->zone_flags &= ~DA_ZONE_FLAG_URSWRZ;
5742 softc->optimal_seq_zones =
5743 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5744 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5745 softc->optimal_nonseq_zones = scsi_4btoul(
5746 zoned_bdc->optimal_nonseq_zones);
5747 softc->zone_flags |= DA_ZONE_FLAG_OPT_NONSEQ_SET;
5748 softc->max_seq_zones =
5749 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5750 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5753 * All of the zone commands are mandatory for SCSI
5756 * XXX KDM this is valid as of September 2015.
5757 * Re-check this assumption once the SAT spec is
5758 * updated to support SCSI ZBC to ATA ZAC mapping.
5759 * Since ATA allows zone commands to be reported
5760 * as supported or not, this may not necessarily
5761 * be true for an ATA device behind a SAT (SCSI to
5762 * ATA Translation) layer.
5764 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5766 error = daerror(done_ccb, CAM_RETRY_SELTO,
5767 SF_RETRY_UA|SF_NO_PRINT);
5768 if (error == ERESTART)
5770 else if (error != 0) {
5771 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5772 /* Don't wedge this device's queue */
5773 cam_release_devq(done_ccb->ccb_h.path,
5777 /*getcount_only*/0);
5782 free(csio->data_ptr, M_SCSIDA);
5784 daprobedone(periph, done_ccb);
5789 dadone_tur(struct cam_periph *periph, union ccb *done_ccb)
5791 struct da_softc *softc;
5792 struct ccb_scsiio *csio;
5794 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_tur\n"));
5796 softc = (struct da_softc *)periph->softc;
5797 csio = &done_ccb->csio;
5799 cam_periph_assert(periph, MA_OWNED);
5801 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5803 if (daerror(done_ccb, CAM_RETRY_SELTO,
5804 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) == ERESTART)
5805 return; /* Will complete again, keep reference */
5806 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5807 cam_release_devq(done_ccb->ccb_h.path,
5811 /*getcount_only*/0);
5813 xpt_release_ccb(done_ccb);
5814 softc->flags &= ~DA_FLAG_TUR_PENDING;
5815 da_periph_release_locked(periph, DA_REF_TUR);
5820 dareprobe(struct cam_periph *periph)
5822 struct da_softc *softc;
5825 softc = (struct da_softc *)periph->softc;
5827 /* Probe in progress; don't interfere. */
5828 if (softc->state != DA_STATE_NORMAL)
5831 status = da_periph_acquire(periph, DA_REF_REPROBE);
5832 KASSERT(status == 0, ("dareprobe: cam_periph_acquire failed"));
5834 softc->state = DA_STATE_PROBE_WP;
5835 xpt_schedule(periph, CAM_PRIORITY_DEV);
5839 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5841 struct da_softc *softc;
5842 struct cam_periph *periph;
5843 int error, error_code, sense_key, asc, ascq;
5845 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5846 if (ccb->csio.bio != NULL)
5847 biotrack(ccb->csio.bio, __func__);
5850 periph = xpt_path_periph(ccb->ccb_h.path);
5851 softc = (struct da_softc *)periph->softc;
5853 cam_periph_assert(periph, MA_OWNED);
5856 * Automatically detect devices that do not support
5857 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5860 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5861 error = cmd6workaround(ccb);
5862 } else if (scsi_extract_sense_ccb(ccb,
5863 &error_code, &sense_key, &asc, &ascq)) {
5864 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5865 error = cmd6workaround(ccb);
5867 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5868 * query the capacity and notify upper layers.
5870 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5871 asc == 0x2A && ascq == 0x09) {
5872 xpt_print(periph->path, "Capacity data has changed\n");
5873 softc->flags &= ~DA_FLAG_PROBED;
5875 sense_flags |= SF_NO_PRINT;
5876 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5877 asc == 0x28 && ascq == 0x00) {
5878 softc->flags &= ~DA_FLAG_PROBED;
5879 disk_media_changed(softc->disk, M_NOWAIT);
5880 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5881 asc == 0x3F && ascq == 0x03) {
5882 xpt_print(periph->path, "INQUIRY data has changed\n");
5883 softc->flags &= ~DA_FLAG_PROBED;
5885 sense_flags |= SF_NO_PRINT;
5886 } else if (sense_key == SSD_KEY_NOT_READY &&
5887 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5888 softc->flags |= DA_FLAG_PACK_INVALID;
5889 disk_media_gone(softc->disk, M_NOWAIT);
5892 if (error == ERESTART)
5896 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5897 case CAM_CMD_TIMEOUT:
5900 case CAM_REQ_ABORTED:
5901 case CAM_REQ_CMP_ERR:
5902 case CAM_REQ_TERMIO:
5903 case CAM_UNREC_HBA_ERROR:
5904 case CAM_DATA_RUN_ERR:
5914 * Until we have a better way of doing pack validation,
5915 * don't treat UAs as errors.
5917 sense_flags |= SF_RETRY_UA;
5919 if (softc->quirks & DA_Q_RETRY_BUSY)
5920 sense_flags |= SF_RETRY_BUSY;
5921 return(cam_periph_error(ccb, cam_flags, sense_flags));
5925 damediapoll(void *arg)
5927 struct cam_periph *periph = arg;
5928 struct da_softc *softc = periph->softc;
5930 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5931 (softc->flags & DA_FLAG_TUR_PENDING) == 0 &&
5932 LIST_EMPTY(&softc->pending_ccbs)) {
5933 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
5934 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5938 /* Queue us up again */
5939 if (da_poll_period != 0)
5940 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5944 daprevent(struct cam_periph *periph, int action)
5946 struct da_softc *softc;
5950 cam_periph_assert(periph, MA_OWNED);
5951 softc = (struct da_softc *)periph->softc;
5953 if (((action == PR_ALLOW)
5954 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5955 || ((action == PR_PREVENT)
5956 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5960 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5962 scsi_prevent(&ccb->csio,
5970 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5971 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5974 if (action == PR_ALLOW)
5975 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5977 softc->flags |= DA_FLAG_PACK_LOCKED;
5980 xpt_release_ccb(ccb);
5984 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5985 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5987 struct ccb_calc_geometry ccg;
5988 struct da_softc *softc;
5989 struct disk_params *dp;
5990 u_int lbppbe, lalba;
5993 softc = (struct da_softc *)periph->softc;
5995 dp = &softc->params;
5996 dp->secsize = block_len;
5997 dp->sectors = maxsector + 1;
5998 if (rcaplong != NULL) {
5999 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
6000 lalba = scsi_2btoul(rcaplong->lalba_lbp);
6001 lalba &= SRC16_LALBA_A;
6002 if (rcaplong->prot & SRC16_PROT_EN)
6003 softc->p_type = ((rcaplong->prot & SRC16_P_TYPE) >>
6004 SRC16_P_TYPE_SHIFT) + 1;
6014 dp->stripesize = block_len << lbppbe;
6015 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
6017 } else if (softc->quirks & DA_Q_4K) {
6018 dp->stripesize = 4096;
6019 dp->stripeoffset = 0;
6020 } else if (softc->unmap_gran != 0) {
6021 dp->stripesize = block_len * softc->unmap_gran;
6022 dp->stripeoffset = (dp->stripesize - block_len *
6023 softc->unmap_gran_align) % dp->stripesize;
6026 dp->stripeoffset = 0;
6029 * Have the controller provide us with a geometry
6030 * for this disk. The only time the geometry
6031 * matters is when we boot and the controller
6032 * is the only one knowledgeable enough to come
6033 * up with something that will make this a bootable
6036 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6037 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
6038 ccg.block_size = dp->secsize;
6039 ccg.volume_size = dp->sectors;
6041 ccg.secs_per_track = 0;
6043 xpt_action((union ccb*)&ccg);
6044 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
6046 * We don't know what went wrong here- but just pick
6047 * a geometry so we don't have nasty things like divide
6051 dp->secs_per_track = 255;
6052 dp->cylinders = dp->sectors / (255 * 255);
6053 if (dp->cylinders == 0) {
6057 dp->heads = ccg.heads;
6058 dp->secs_per_track = ccg.secs_per_track;
6059 dp->cylinders = ccg.cylinders;
6063 * If the user supplied a read capacity buffer, and if it is
6064 * different than the previous buffer, update the data in the EDT.
6065 * If it's the same, we don't bother. This avoids sending an
6066 * update every time someone opens this device.
6068 if ((rcaplong != NULL)
6069 && (bcmp(rcaplong, &softc->rcaplong,
6070 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
6071 struct ccb_dev_advinfo cdai;
6073 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6074 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
6075 cdai.buftype = CDAI_TYPE_RCAPLONG;
6076 cdai.flags = CDAI_FLAG_STORE;
6077 cdai.bufsiz = rcap_len;
6078 cdai.buf = (uint8_t *)rcaplong;
6079 xpt_action((union ccb *)&cdai);
6080 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
6081 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
6082 if (cdai.ccb_h.status != CAM_REQ_CMP) {
6083 xpt_print(periph->path, "%s: failed to set read "
6084 "capacity advinfo\n", __func__);
6085 /* Use cam_error_print() to decode the status */
6086 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
6089 bcopy(rcaplong, &softc->rcaplong,
6090 min(sizeof(softc->rcaplong), rcap_len));
6094 softc->disk->d_sectorsize = softc->params.secsize;
6095 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
6096 softc->disk->d_stripesize = softc->params.stripesize;
6097 softc->disk->d_stripeoffset = softc->params.stripeoffset;
6098 /* XXX: these are not actually "firmware" values, so they may be wrong */
6099 softc->disk->d_fwsectors = softc->params.secs_per_track;
6100 softc->disk->d_fwheads = softc->params.heads;
6101 softc->disk->d_devstat->block_size = softc->params.secsize;
6102 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
6104 error = disk_resize(softc->disk, M_NOWAIT);
6106 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
6110 dasendorderedtag(void *arg)
6112 struct cam_periph *periph = arg;
6113 struct da_softc *softc = periph->softc;
6115 cam_periph_assert(periph, MA_OWNED);
6116 if (da_send_ordered) {
6117 if (!LIST_EMPTY(&softc->pending_ccbs)) {
6118 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
6119 softc->flags |= DA_FLAG_NEED_OTAG;
6120 softc->flags &= ~DA_FLAG_WAS_OTAG;
6124 /* Queue us up again */
6125 callout_reset(&softc->sendordered_c,
6126 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
6127 dasendorderedtag, periph);
6131 * Step through all DA peripheral drivers, and if the device is still open,
6132 * sync the disk cache to physical media.
6135 dashutdown(void * arg, int howto)
6137 struct cam_periph *periph;
6138 struct da_softc *softc;
6142 CAM_PERIPH_FOREACH(periph, &dadriver) {
6143 softc = (struct da_softc *)periph->softc;
6144 if (SCHEDULER_STOPPED()) {
6145 /* If we paniced with the lock held, do not recurse. */
6146 if (!cam_periph_owned(periph) &&
6147 (softc->flags & DA_FLAG_OPEN)) {
6148 dadump(softc->disk, NULL, 0, 0, 0);
6152 cam_periph_lock(periph);
6155 * We only sync the cache if the drive is still open, and
6156 * if the drive is capable of it..
6158 if (((softc->flags & DA_FLAG_OPEN) == 0)
6159 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
6160 cam_periph_unlock(periph);
6164 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
6165 scsi_synchronize_cache(&ccb->csio,
6169 /*begin_lba*/0, /* whole disk */
6174 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
6175 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
6176 softc->disk->d_devstat);
6178 xpt_print(periph->path, "Synchronize cache failed\n");
6179 xpt_release_ccb(ccb);
6180 cam_periph_unlock(periph);
6184 #else /* !_KERNEL */
6187 * XXX These are only left out of the kernel build to silence warnings. If,
6188 * for some reason these functions are used in the kernel, the ifdefs should
6189 * be moved so they are included both in the kernel and userland.
6192 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
6193 void (*cbfcnp)(struct cam_periph *, union ccb *),
6194 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
6195 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6198 struct scsi_format_unit *scsi_cmd;
6200 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
6201 scsi_cmd->opcode = FORMAT_UNIT;
6202 scsi_cmd->byte2 = byte2;
6203 scsi_ulto2b(ileave, scsi_cmd->interleave);
6208 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6218 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
6219 void (*cbfcnp)(struct cam_periph *, union ccb *),
6220 uint8_t tag_action, uint8_t list_format,
6221 uint32_t addr_desc_index, uint8_t *data_ptr,
6222 uint32_t dxfer_len, int minimum_cmd_size,
6223 uint8_t sense_len, uint32_t timeout)
6228 * These conditions allow using the 10 byte command. Otherwise we
6229 * need to use the 12 byte command.
6231 if ((minimum_cmd_size <= 10)
6232 && (addr_desc_index == 0)
6233 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
6234 struct scsi_read_defect_data_10 *cdb10;
6236 cdb10 = (struct scsi_read_defect_data_10 *)
6237 &csio->cdb_io.cdb_bytes;
6239 cdb_len = sizeof(*cdb10);
6240 bzero(cdb10, cdb_len);
6241 cdb10->opcode = READ_DEFECT_DATA_10;
6242 cdb10->format = list_format;
6243 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
6245 struct scsi_read_defect_data_12 *cdb12;
6247 cdb12 = (struct scsi_read_defect_data_12 *)
6248 &csio->cdb_io.cdb_bytes;
6250 cdb_len = sizeof(*cdb12);
6251 bzero(cdb12, cdb_len);
6252 cdb12->opcode = READ_DEFECT_DATA_12;
6253 cdb12->format = list_format;
6254 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
6255 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
6261 /*flags*/ CAM_DIR_IN,
6271 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
6272 void (*cbfcnp)(struct cam_periph *, union ccb *),
6273 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
6274 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6277 struct scsi_sanitize *scsi_cmd;
6279 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
6280 scsi_cmd->opcode = SANITIZE;
6281 scsi_cmd->byte2 = byte2;
6282 scsi_cmd->control = control;
6283 scsi_ulto2b(dxfer_len, scsi_cmd->length);
6288 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6297 #endif /* _KERNEL */
6300 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
6301 void (*cbfcnp)(struct cam_periph *, union ccb *),
6302 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
6303 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
6304 uint8_t sense_len, uint32_t timeout)
6306 struct scsi_zbc_out *scsi_cmd;
6308 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
6309 scsi_cmd->opcode = ZBC_OUT;
6310 scsi_cmd->service_action = service_action;
6311 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
6312 scsi_cmd->zone_flags = zone_flags;
6317 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6327 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
6328 void (*cbfcnp)(struct cam_periph *, union ccb *),
6329 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
6330 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
6331 uint8_t sense_len, uint32_t timeout)
6333 struct scsi_zbc_in *scsi_cmd;
6335 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
6336 scsi_cmd->opcode = ZBC_IN;
6337 scsi_cmd->service_action = service_action;
6338 scsi_ulto4b(dxfer_len, scsi_cmd->length);
6339 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
6340 scsi_cmd->zone_options = zone_options;
6345 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
6356 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
6357 void (*cbfcnp)(struct cam_periph *, union ccb *),
6358 uint8_t tag_action, int use_ncq,
6359 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6360 uint8_t *data_ptr, uint32_t dxfer_len,
6361 uint8_t *cdb_storage, size_t cdb_storage_len,
6362 uint8_t sense_len, uint32_t timeout)
6364 uint8_t command_out, protocol, ata_flags;
6365 uint16_t features_out;
6366 uint32_t sectors_out, auxiliary;
6372 command_out = ATA_ZAC_MANAGEMENT_OUT;
6373 features_out = (zm_action & 0xf) | (zone_flags << 8);
6374 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6375 if (dxfer_len == 0) {
6376 protocol = AP_PROTO_NON_DATA;
6377 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6380 protocol = AP_PROTO_DMA;
6381 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
6382 AP_FLAG_TDIR_TO_DEV;
6383 sectors_out = ((dxfer_len >> 9) & 0xffff);
6387 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6388 if (dxfer_len == 0) {
6389 command_out = ATA_NCQ_NON_DATA;
6390 features_out = ATA_NCQ_ZAC_MGMT_OUT;
6392 * We're assuming the SCSI to ATA translation layer
6393 * will set the NCQ tag number in the tag field.
6394 * That isn't clear from the SAT-4 spec (as of rev 05).
6397 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6399 command_out = ATA_SEND_FPDMA_QUEUED;
6401 * Note that we're defaulting to normal priority,
6402 * and assuming that the SCSI to ATA translation
6403 * layer will insert the NCQ tag number in the tag
6404 * field. That isn't clear in the SAT-4 spec (as
6407 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
6409 ata_flags |= AP_FLAG_TLEN_FEAT |
6410 AP_FLAG_TDIR_TO_DEV;
6413 * For SEND FPDMA QUEUED, the transfer length is
6414 * encoded in the FEATURE register, and 0 means
6415 * that 65536 512 byte blocks are to be tranferred.
6416 * In practice, it seems unlikely that we'll see
6417 * a transfer that large, and it may confuse the
6418 * the SAT layer, because generally that means that
6419 * 0 bytes should be transferred.
6421 if (dxfer_len == (65536 * 512)) {
6423 } else if (dxfer_len <= (65535 * 512)) {
6424 features_out = ((dxfer_len >> 9) & 0xffff);
6426 /* The transfer is too big. */
6433 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
6434 protocol = AP_PROTO_FPDMA;
6437 protocol |= AP_EXTEND;
6439 retval = scsi_ata_pass(csio,
6442 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6444 /*protocol*/ protocol,
6445 /*ata_flags*/ ata_flags,
6446 /*features*/ features_out,
6447 /*sector_count*/ sectors_out,
6449 /*command*/ command_out,
6452 /*auxiliary*/ auxiliary,
6454 /*data_ptr*/ data_ptr,
6455 /*dxfer_len*/ dxfer_len,
6456 /*cdb_storage*/ cdb_storage,
6457 /*cdb_storage_len*/ cdb_storage_len,
6458 /*minimum_cmd_size*/ 0,
6459 /*sense_len*/ SSD_FULL_SIZE,
6460 /*timeout*/ timeout);
6468 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
6469 void (*cbfcnp)(struct cam_periph *, union ccb *),
6470 uint8_t tag_action, int use_ncq,
6471 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6472 uint8_t *data_ptr, uint32_t dxfer_len,
6473 uint8_t *cdb_storage, size_t cdb_storage_len,
6474 uint8_t sense_len, uint32_t timeout)
6476 uint8_t command_out, protocol;
6477 uint16_t features_out, sectors_out;
6483 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
6486 command_out = ATA_ZAC_MANAGEMENT_IN;
6487 /* XXX KDM put a macro here */
6488 features_out = (zm_action & 0xf) | (zone_flags << 8);
6489 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
6490 protocol = AP_PROTO_DMA;
6491 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
6494 ata_flags |= AP_FLAG_TLEN_FEAT;
6496 command_out = ATA_RECV_FPDMA_QUEUED;
6497 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6500 * For RECEIVE FPDMA QUEUED, the transfer length is
6501 * encoded in the FEATURE register, and 0 means
6502 * that 65536 512 byte blocks are to be tranferred.
6503 * In practice, it seems unlikely that we'll see
6504 * a transfer that large, and it may confuse the
6505 * the SAT layer, because generally that means that
6506 * 0 bytes should be transferred.
6508 if (dxfer_len == (65536 * 512)) {
6510 } else if (dxfer_len <= (65535 * 512)) {
6511 features_out = ((dxfer_len >> 9) & 0xffff);
6513 /* The transfer is too big. */
6517 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6518 protocol = AP_PROTO_FPDMA;
6521 protocol |= AP_EXTEND;
6523 retval = scsi_ata_pass(csio,
6526 /*flags*/ CAM_DIR_IN,
6528 /*protocol*/ protocol,
6529 /*ata_flags*/ ata_flags,
6530 /*features*/ features_out,
6531 /*sector_count*/ sectors_out,
6533 /*command*/ command_out,
6536 /*auxiliary*/ auxiliary,
6538 /*data_ptr*/ data_ptr,
6539 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6540 /*cdb_storage*/ cdb_storage,
6541 /*cdb_storage_len*/ cdb_storage_len,
6542 /*minimum_cmd_size*/ 0,
6543 /*sense_len*/ SSD_FULL_SIZE,
6544 /*timeout*/ timeout);