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;
347 struct disk_params params;
350 struct task sysctl_task;
351 struct sysctl_ctx_list sysctl_ctx;
352 struct sysctl_oid *sysctl_tree;
353 struct callout sendordered_c;
355 uint8_t unmap_buf[UNMAP_BUF_SIZE];
356 struct scsi_read_capacity_data_long rcaplong;
357 struct callout mediapoll_c;
358 int ref_flags[DA_REF_MAX];
360 struct sysctl_ctx_list sysctl_stats_ctx;
361 struct sysctl_oid *sysctl_stats_tree;
366 #define DA_ANNOUNCETMP_SZ 160
367 char announce_temp[DA_ANNOUNCETMP_SZ];
368 #define DA_ANNOUNCE_SZ 400
369 char announcebuf[DA_ANNOUNCE_SZ];
372 #define dadeleteflag(softc, delete_method, enable) \
374 softc->delete_available |= (1 << delete_method); \
376 softc->delete_available &= ~(1 << delete_method); \
379 struct da_quirk_entry {
380 struct scsi_inquiry_pattern inq_pat;
384 static const char quantum[] = "QUANTUM";
385 static const char microp[] = "MICROP";
387 static struct da_quirk_entry da_quirk_table[] =
389 /* SPI, FC devices */
392 * Fujitsu M2513A MO drives.
393 * Tested devices: M2513A2 firmware versions 1200 & 1300.
394 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
395 * Reported by: W.Scholten <whs@xs4all.nl>
397 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
398 /*quirks*/ DA_Q_NO_SYNC_CACHE
402 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
403 /*quirks*/ DA_Q_NO_SYNC_CACHE
407 * This particular Fujitsu drive doesn't like the
408 * synchronize cache command.
409 * Reported by: Tom Jackson <toj@gorilla.net>
411 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
412 /*quirks*/ DA_Q_NO_SYNC_CACHE
416 * This drive doesn't like the synchronize cache command
417 * either. Reported by: Matthew Jacob <mjacob@feral.com>
418 * in NetBSD PR kern/6027, August 24, 1998.
420 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
421 /*quirks*/ DA_Q_NO_SYNC_CACHE
425 * This drive doesn't like the synchronize cache command
426 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
429 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
430 /*quirks*/ DA_Q_NO_SYNC_CACHE
434 * Doesn't like the synchronize cache command.
435 * Reported by: Blaz Zupan <blaz@gold.amis.net>
437 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
438 /*quirks*/ DA_Q_NO_SYNC_CACHE
442 * Doesn't like the synchronize cache command.
443 * Reported by: Blaz Zupan <blaz@gold.amis.net>
445 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
446 /*quirks*/ DA_Q_NO_SYNC_CACHE
450 * Doesn't like the synchronize cache command.
452 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
453 /*quirks*/ DA_Q_NO_SYNC_CACHE
457 * Doesn't like the synchronize cache command.
458 * Reported by: walter@pelissero.de
460 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
461 /*quirks*/ DA_Q_NO_SYNC_CACHE
465 * Doesn't work correctly with 6 byte reads/writes.
466 * Returns illegal request, and points to byte 9 of the
468 * Reported by: Adam McDougall <bsdx@spawnet.com>
470 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
471 /*quirks*/ DA_Q_NO_6_BYTE
475 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
476 /*quirks*/ DA_Q_NO_6_BYTE
480 * Doesn't like the synchronize cache command.
481 * Reported by: walter@pelissero.de
483 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
484 /*quirks*/ DA_Q_NO_SYNC_CACHE
488 * The CISS RAID controllers do not support SYNC_CACHE
490 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
491 /*quirks*/ DA_Q_NO_SYNC_CACHE
495 * The STEC SSDs sometimes hang on UNMAP.
497 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
498 /*quirks*/ DA_Q_NO_UNMAP
502 * VMware returns BUSY status when storage has transient
503 * connectivity problems, so better wait.
504 * Also VMware returns odd errors on misaligned UNMAPs.
506 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
507 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
509 /* USB mass storage devices supported by umass(4) */
512 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
515 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
516 /*quirks*/ DA_Q_NO_SYNC_CACHE
520 * Power Quotient Int. (PQI) USB flash key
523 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
524 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
528 * Creative Nomad MUVO mp3 player (USB)
531 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
532 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
536 * Jungsoft NEXDISK USB flash key
539 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
540 /*quirks*/ DA_Q_NO_SYNC_CACHE
544 * FreeDik USB Mini Data Drive
547 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
548 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
552 * Sigmatel USB Flash MP3 Player
555 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
556 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
560 * Neuros USB Digital Audio Computer
563 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
564 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
568 * SEAGRAND NP-900 MP3 Player
571 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
572 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
576 * iRiver iFP MP3 player (with UMS Firmware)
577 * PR: kern/54881, i386/63941, kern/66124
579 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
580 /*quirks*/ DA_Q_NO_SYNC_CACHE
584 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
587 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
588 /*quirks*/ DA_Q_NO_SYNC_CACHE
592 * ZICPlay USB MP3 Player with FM
595 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
596 /*quirks*/ DA_Q_NO_SYNC_CACHE
600 * TEAC USB floppy mechanisms
602 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
603 /*quirks*/ DA_Q_NO_SYNC_CACHE
607 * Kingston DataTraveler II+ USB Pen-Drive.
608 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
610 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
611 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
619 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
620 /*quirks*/ DA_Q_NO_SYNC_CACHE
624 * Motorola E398 Mobile Phone (TransFlash memory card).
625 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
628 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
629 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
633 * Qware BeatZkey! Pro
636 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
637 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
641 * Time DPA20B 1GB MP3 Player
644 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
645 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
649 * Samsung USB key 128Mb
652 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
653 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
657 * Kingston DataTraveler 2.0 USB Flash memory.
660 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
661 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
665 * Creative MUVO Slim mp3 player (USB)
668 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
669 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
673 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
676 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
677 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
681 * SanDisk Micro Cruzer 128MB
684 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
685 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
689 * TOSHIBA TransMemory USB sticks
692 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
693 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
697 * PNY USB 3.0 Flash Drives
699 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
700 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
705 * PR: usb/75578, usb/72344, usb/65436
707 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
708 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
714 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
715 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16
719 * Genesys 6-in-1 Card Reader
722 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
723 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
727 * Rekam Digital CAMERA
730 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
731 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
735 * iRiver H10 MP3 player
738 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
739 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
743 * iRiver U10 MP3 player
746 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
747 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
754 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
755 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
759 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
762 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
763 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
770 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
771 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
775 * Philips USB Key Audio KEY013
778 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
779 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
786 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
787 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
794 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
795 /*quirks*/ DA_Q_NO_SYNC_CACHE
799 * I/O Magic USB flash - Giga Bank
802 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
803 /*quirks*/ DA_Q_NO_SYNC_CACHE
807 * JoyFly 128mb USB Flash Drive
810 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
811 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
818 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
819 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
823 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
826 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
827 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
831 * Samsung YP-U3 mp3-player
834 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
835 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
838 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
839 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
843 * Sony Cyber-Shot DSC cameras
846 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
847 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
850 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
851 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
854 /* At least several Transcent USB sticks lie on RC16. */
855 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
856 "*"}, /*quirks*/ DA_Q_NO_RC16
860 * I-O Data USB Flash Disk
863 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
864 "*"}, /*quirks*/ DA_Q_NO_RC16
868 * 16GB SLC CHIPFANCIER
871 {T_DIRECT, SIP_MEDIA_REMOVABLE, "16G SLC", "CHIPFANCIER",
872 "1.00"}, /*quirks*/ DA_Q_NO_RC16
874 /* ATA/SATA devices over SAS/USB/... */
877 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SanDisk SD8SB8U1*", "*" },
881 /* Hitachi Advanced Format (4k) drives */
882 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
886 /* Micron Advanced Format (4k) drives */
887 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
891 /* Samsung Advanced Format (4k) drives */
892 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
896 /* Samsung Advanced Format (4k) drives */
897 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
901 /* Samsung Advanced Format (4k) drives */
902 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
906 /* Samsung Advanced Format (4k) drives */
907 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
911 /* Seagate Barracuda Green Advanced Format (4k) drives */
912 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
916 /* Seagate Barracuda Green Advanced Format (4k) drives */
917 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
921 /* Seagate Barracuda Green Advanced Format (4k) drives */
922 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
926 /* Seagate Barracuda Green Advanced Format (4k) drives */
927 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
931 /* Seagate Barracuda Green Advanced Format (4k) drives */
932 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
936 /* Seagate Barracuda Green Advanced Format (4k) drives */
937 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
941 /* Seagate Momentus Advanced Format (4k) drives */
942 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
946 /* Seagate Momentus Advanced Format (4k) drives */
947 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
951 /* Seagate Momentus Advanced Format (4k) drives */
952 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
956 /* Seagate Momentus Advanced Format (4k) drives */
957 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
961 /* Seagate Momentus Advanced Format (4k) drives */
962 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
966 /* Seagate Momentus Advanced Format (4k) drives */
967 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
971 /* Seagate Momentus Advanced Format (4k) drives */
972 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
976 /* Seagate Momentus Advanced Format (4k) drives */
977 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
981 /* Seagate Momentus Advanced Format (4k) drives */
982 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
986 /* Seagate Momentus Advanced Format (4k) drives */
987 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
991 /* Seagate Momentus Advanced Format (4k) drives */
992 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
996 /* Seagate Momentus Advanced Format (4k) drives */
997 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
1001 /* Seagate Momentus Advanced Format (4k) drives */
1002 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
1006 /* Seagate Momentus Advanced Format (4k) drives */
1007 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
1011 /* Seagate Momentus Thin Advanced Format (4k) drives */
1012 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
1016 /* Seagate Momentus Thin Advanced Format (4k) drives */
1017 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
1021 /* WDC Caviar Green Advanced Format (4k) drives */
1022 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
1026 /* WDC Caviar Green Advanced Format (4k) drives */
1027 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
1031 /* WDC Caviar Green Advanced Format (4k) drives */
1032 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
1036 /* WDC Caviar Green Advanced Format (4k) drives */
1037 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
1041 /* WDC Caviar Green Advanced Format (4k) drives */
1042 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1046 /* WDC Caviar Green Advanced Format (4k) drives */
1047 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1051 /* WDC Caviar Green Advanced Format (4k) drives */
1052 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1056 /* WDC Caviar Green Advanced Format (4k) drives */
1057 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1061 /* WDC Scorpio Black Advanced Format (4k) drives */
1062 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1066 /* WDC Scorpio Black Advanced Format (4k) drives */
1067 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1071 /* WDC Scorpio Black Advanced Format (4k) drives */
1072 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1076 /* WDC Scorpio Black Advanced Format (4k) drives */
1077 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1081 /* WDC Scorpio Blue Advanced Format (4k) drives */
1082 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1086 /* WDC Scorpio Blue Advanced Format (4k) drives */
1087 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1091 /* WDC Scorpio Blue Advanced Format (4k) drives */
1092 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1096 /* WDC Scorpio Blue Advanced Format (4k) drives */
1097 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1102 * Olympus digital cameras (C-3040ZOOM, C-2040ZOOM, C-1)
1105 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "C*", "*"},
1106 /*quirks*/ DA_Q_NO_6_BYTE | DA_Q_NO_SYNC_CACHE
1110 * Olympus digital cameras (D-370)
1113 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "D*", "*"},
1114 /*quirks*/ DA_Q_NO_6_BYTE
1118 * Olympus digital cameras (E-100RS, E-10).
1121 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "E*", "*"},
1122 /*quirks*/ DA_Q_NO_6_BYTE | DA_Q_NO_SYNC_CACHE
1126 * Olympus FE-210 camera
1128 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1129 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1133 * Pentax Digital Camera
1136 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PENTAX", "DIGITAL CAMERA",
1137 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1141 * LG UP3S MP3 player
1143 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1144 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1148 * Laser MP3-2GA13 MP3 player
1150 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1151 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1155 * LaCie external 250GB Hard drive des by Porsche
1156 * Submitted by: Ben Stuyts <ben@altesco.nl>
1159 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1160 /*quirks*/ DA_Q_NO_SYNC_CACHE
1165 * Corsair Force 2 SSDs
1166 * 4k optimised & trim only works in 4k requests + 4k aligned
1168 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1173 * Corsair Force 3 SSDs
1174 * 4k optimised & trim only works in 4k requests + 4k aligned
1176 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1181 * Corsair Neutron GTX SSDs
1182 * 4k optimised & trim only works in 4k requests + 4k aligned
1184 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1189 * Corsair Force GT & GS SSDs
1190 * 4k optimised & trim only works in 4k requests + 4k aligned
1192 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1198 * 4k optimised & trim only works in 4k requests + 4k aligned
1200 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1205 * Crucial RealSSD C300 SSDs
1208 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1209 "*" }, /*quirks*/DA_Q_4K
1213 * Intel 320 Series SSDs
1214 * 4k optimised & trim only works in 4k requests + 4k aligned
1216 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1221 * Intel 330 Series SSDs
1222 * 4k optimised & trim only works in 4k requests + 4k aligned
1224 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1229 * Intel 510 Series SSDs
1230 * 4k optimised & trim only works in 4k requests + 4k aligned
1232 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1237 * Intel 520 Series SSDs
1238 * 4k optimised & trim only works in 4k requests + 4k aligned
1240 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1245 * Intel S3610 Series SSDs
1246 * 4k optimised & trim only works in 4k requests + 4k aligned
1248 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1253 * Intel X25-M Series SSDs
1254 * 4k optimised & trim only works in 4k requests + 4k aligned
1256 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1261 * Kingston E100 Series SSDs
1262 * 4k optimised & trim only works in 4k requests + 4k aligned
1264 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1269 * Kingston HyperX 3k SSDs
1270 * 4k optimised & trim only works in 4k requests + 4k aligned
1272 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1277 * Marvell SSDs (entry taken from OpenSolaris)
1278 * 4k optimised & trim only works in 4k requests + 4k aligned
1280 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1285 * OCZ Agility 2 SSDs
1286 * 4k optimised & trim only works in 4k requests + 4k aligned
1288 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1293 * OCZ Agility 3 SSDs
1294 * 4k optimised & trim only works in 4k requests + 4k aligned
1296 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1301 * OCZ Deneva R Series SSDs
1302 * 4k optimised & trim only works in 4k requests + 4k aligned
1304 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1309 * OCZ Vertex 2 SSDs (inc pro series)
1310 * 4k optimised & trim only works in 4k requests + 4k aligned
1312 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1318 * 4k optimised & trim only works in 4k requests + 4k aligned
1320 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1326 * 4k optimised & trim only works in 4k requests + 4k aligned
1328 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1333 * Samsung 750 Series SSDs
1334 * 4k optimised & trim only works in 4k requests + 4k aligned
1336 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" },
1341 * Samsung 830 Series SSDs
1342 * 4k optimised & trim only works in 4k requests + 4k aligned
1344 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1350 * 4k optimised & trim only works in 4k requests + 4k aligned
1352 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1358 * 4k optimised & trim only works in 4k requests + 4k aligned
1360 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" },
1366 * 4k optimised & trim only works in 4k requests + 4k aligned
1368 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1373 * Samsung 843T Series SSDs (MZ7WD*)
1374 * Samsung PM851 Series SSDs (MZ7TE*)
1375 * Samsung PM853T Series SSDs (MZ7GE*)
1376 * Samsung SM863 Series SSDs (MZ7KM*)
1379 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1384 * Same as for SAMSUNG MZ7* but enable the quirks for SSD
1385 * starting with MZ7* too
1387 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MZ7*", "*" },
1392 * SuperTalent TeraDrive CT SSDs
1393 * 4k optimised & trim only works in 4k requests + 4k aligned
1395 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1400 * XceedIOPS SATA SSDs
1403 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1408 * Hama Innostor USB-Stick
1410 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1411 /*quirks*/DA_Q_NO_RC16
1415 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1416 * Drive Managed SATA hard drive. This drive doesn't report
1417 * in firmware that it is a drive managed SMR drive.
1419 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS000[23]*", "*" },
1420 /*quirks*/DA_Q_SMR_DM
1424 * MX-ES USB Drive by Mach Xtreme
1426 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1427 /*quirks*/DA_Q_NO_RC16
1431 static disk_strategy_t dastrategy;
1432 static dumper_t dadump;
1433 static periph_init_t dainit;
1434 static void daasync(void *callback_arg, u_int32_t code,
1435 struct cam_path *path, void *arg);
1436 static void dasysctlinit(void *context, int pending);
1437 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1438 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1439 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1440 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1441 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1442 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1443 static void dadeletemethodset(struct da_softc *softc,
1444 da_delete_methods delete_method);
1445 static off_t dadeletemaxsize(struct da_softc *softc,
1446 da_delete_methods delete_method);
1447 static void dadeletemethodchoose(struct da_softc *softc,
1448 da_delete_methods default_method);
1449 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1451 static periph_ctor_t daregister;
1452 static periph_dtor_t dacleanup;
1453 static periph_start_t dastart;
1454 static periph_oninv_t daoninvalidate;
1455 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1456 static void dadone(struct cam_periph *periph,
1457 union ccb *done_ccb);
1458 static void dadone_probewp(struct cam_periph *periph,
1459 union ccb *done_ccb);
1460 static void dadone_proberc(struct cam_periph *periph,
1461 union ccb *done_ccb);
1462 static void dadone_probelbp(struct cam_periph *periph,
1463 union ccb *done_ccb);
1464 static void dadone_probeblklimits(struct cam_periph *periph,
1465 union ccb *done_ccb);
1466 static void dadone_probebdc(struct cam_periph *periph,
1467 union ccb *done_ccb);
1468 static void dadone_probeata(struct cam_periph *periph,
1469 union ccb *done_ccb);
1470 static void dadone_probeatalogdir(struct cam_periph *periph,
1471 union ccb *done_ccb);
1472 static void dadone_probeataiddir(struct cam_periph *periph,
1473 union ccb *done_ccb);
1474 static void dadone_probeatasup(struct cam_periph *periph,
1475 union ccb *done_ccb);
1476 static void dadone_probeatazone(struct cam_periph *periph,
1477 union ccb *done_ccb);
1478 static void dadone_probezone(struct cam_periph *periph,
1479 union ccb *done_ccb);
1480 static void dadone_tur(struct cam_periph *periph,
1481 union ccb *done_ccb);
1482 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1483 u_int32_t sense_flags);
1484 static void daprevent(struct cam_periph *periph, int action);
1485 static void dareprobe(struct cam_periph *periph);
1486 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1488 struct scsi_read_capacity_data_long *rcaplong,
1490 static timeout_t dasendorderedtag;
1491 static void dashutdown(void *arg, int howto);
1492 static timeout_t damediapoll;
1494 #ifndef DA_DEFAULT_POLL_PERIOD
1495 #define DA_DEFAULT_POLL_PERIOD 3
1498 #ifndef DA_DEFAULT_TIMEOUT
1499 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1502 #ifndef DA_DEFAULT_SOFTTIMEOUT
1503 #define DA_DEFAULT_SOFTTIMEOUT 0
1506 #ifndef DA_DEFAULT_RETRY
1507 #define DA_DEFAULT_RETRY 4
1510 #ifndef DA_DEFAULT_SEND_ORDERED
1511 #define DA_DEFAULT_SEND_ORDERED 1
1514 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1515 static int da_retry_count = DA_DEFAULT_RETRY;
1516 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1517 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1518 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1519 static int da_disable_wp_detection = 0;
1521 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1522 "CAM Direct Access Disk driver");
1523 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1524 &da_poll_period, 0, "Media polling period in seconds");
1525 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1526 &da_retry_count, 0, "Normal I/O retry count");
1527 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1528 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1529 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1530 &da_send_ordered, 0, "Send Ordered Tags");
1531 SYSCTL_INT(_kern_cam_da, OID_AUTO, disable_wp_detection, CTLFLAG_RWTUN,
1532 &da_disable_wp_detection, 0,
1533 "Disable detection of write-protected disks");
1535 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1536 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1537 "Soft I/O timeout (ms)");
1538 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1541 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1542 * to the default timeout, we check to see whether an ordered
1543 * tagged transaction is appropriate to prevent simple tag
1544 * starvation. Since we'd like to ensure that there is at least
1545 * 1/2 of the timeout length left for a starved transaction to
1546 * complete after we've sent an ordered tag, we must poll at least
1547 * four times in every timeout period. This takes care of the worst
1548 * case where a starved transaction starts during an interval that
1549 * meets the requirement "don't send an ordered tag" test so it takes
1550 * us two intervals to determine that a tag must be sent.
1552 #ifndef DA_ORDEREDTAG_INTERVAL
1553 #define DA_ORDEREDTAG_INTERVAL 4
1556 static struct periph_driver dadriver =
1559 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1562 PERIPHDRIVER_DECLARE(da, dadriver);
1564 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1567 * This driver takes out references / holds in well defined pairs, never
1568 * recursively. These macros / inline functions enforce those rules. They
1569 * are only enabled with DA_TRACK_REFS or INVARIANTS. If DA_TRACK_REFS is
1570 * defined to be 2 or larger, the tracking also includes debug printfs.
1572 #if defined(DA_TRACK_REFS) || defined(INVARIANTS)
1574 #ifndef DA_TRACK_REFS
1575 #define DA_TRACK_REFS 1
1578 #if DA_TRACK_REFS > 1
1579 static const char *da_ref_text[] = {
1592 #define DA_PERIPH_PRINT(periph, msg, args...) \
1593 CAM_PERIPH_PRINT(periph, msg, ##args)
1595 #define DA_PERIPH_PRINT(periph, msg, args...)
1599 token_sanity(da_ref_token token)
1601 if ((unsigned)token >= DA_REF_MAX)
1602 panic("Bad token value passed in %d\n", token);
1606 da_periph_hold(struct cam_periph *periph, int priority, da_ref_token token)
1608 int err = cam_periph_hold(periph, priority);
1610 token_sanity(token);
1611 DA_PERIPH_PRINT(periph, "Holding device %s (%d): %d\n",
1612 da_ref_text[token], token, err);
1615 struct da_softc *softc = periph->softc;
1617 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1619 panic("Re-holding for reason %d, cnt = %d", token, cnt);
1625 da_periph_unhold(struct cam_periph *periph, da_ref_token token)
1628 struct da_softc *softc = periph->softc;
1630 token_sanity(token);
1631 DA_PERIPH_PRINT(periph, "Unholding device %s (%d)\n",
1632 da_ref_text[token], token);
1633 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1635 panic("Unholding %d with cnt = %d", token, cnt);
1636 cam_periph_unhold(periph);
1640 da_periph_acquire(struct cam_periph *periph, da_ref_token token)
1642 int err = cam_periph_acquire(periph);
1644 token_sanity(token);
1645 DA_PERIPH_PRINT(periph, "acquiring device %s (%d): %d\n",
1646 da_ref_text[token], token, err);
1649 struct da_softc *softc = periph->softc;
1651 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1653 panic("Re-refing for reason %d, cnt = %d", token, cnt);
1659 da_periph_release(struct cam_periph *periph, da_ref_token token)
1662 struct da_softc *softc = periph->softc;
1664 token_sanity(token);
1665 DA_PERIPH_PRINT(periph, "releasing device %s (%d)\n",
1666 da_ref_text[token], token);
1667 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1669 panic("Releasing %d with cnt = %d", token, cnt);
1670 cam_periph_release(periph);
1674 da_periph_release_locked(struct cam_periph *periph, da_ref_token token)
1677 struct da_softc *softc = periph->softc;
1679 token_sanity(token);
1680 DA_PERIPH_PRINT(periph, "releasing device (locked) %s (%d)\n",
1681 da_ref_text[token], token);
1682 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1684 panic("Unholding %d with cnt = %d", token, cnt);
1685 cam_periph_release_locked(periph);
1688 #define cam_periph_hold POISON
1689 #define cam_periph_unhold POISON
1690 #define cam_periph_acquire POISON
1691 #define cam_periph_release POISON
1692 #define cam_periph_release_locked POISON
1695 #define da_periph_hold(periph, prio, token) cam_periph_hold((periph), (prio))
1696 #define da_periph_unhold(periph, token) cam_periph_unhold((periph))
1697 #define da_periph_acquire(periph, token) cam_periph_acquire((periph))
1698 #define da_periph_release(periph, token) cam_periph_release((periph))
1699 #define da_periph_release_locked(periph, token) cam_periph_release_locked((periph))
1703 daopen(struct disk *dp)
1705 struct cam_periph *periph;
1706 struct da_softc *softc;
1709 periph = (struct cam_periph *)dp->d_drv1;
1710 if (da_periph_acquire(periph, DA_REF_OPEN) != 0) {
1714 cam_periph_lock(periph);
1715 if ((error = da_periph_hold(periph, PRIBIO|PCATCH, DA_REF_OPEN_HOLD)) != 0) {
1716 cam_periph_unlock(periph);
1717 da_periph_release(periph, DA_REF_OPEN);
1721 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1724 softc = (struct da_softc *)periph->softc;
1727 /* Wait for the disk size update. */
1728 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1731 xpt_print(periph->path, "unable to retrieve capacity data\n");
1733 if (periph->flags & CAM_PERIPH_INVALID)
1736 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1737 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1738 daprevent(periph, PR_PREVENT);
1741 softc->flags &= ~DA_FLAG_PACK_INVALID;
1742 softc->flags |= DA_FLAG_OPEN;
1745 da_periph_unhold(periph, DA_REF_OPEN_HOLD);
1746 cam_periph_unlock(periph);
1749 da_periph_release(periph, DA_REF_OPEN);
1755 daclose(struct disk *dp)
1757 struct cam_periph *periph;
1758 struct da_softc *softc;
1761 periph = (struct cam_periph *)dp->d_drv1;
1762 softc = (struct da_softc *)periph->softc;
1763 cam_periph_lock(periph);
1764 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1767 if (da_periph_hold(periph, PRIBIO, DA_REF_CLOSE_HOLD) == 0) {
1769 /* Flush disk cache. */
1770 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1771 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1772 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1773 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1774 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1775 /*cbfcnp*/NULL, MSG_SIMPLE_Q_TAG,
1776 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1778 cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1779 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1780 softc->disk->d_devstat);
1781 softc->flags &= ~DA_FLAG_DIRTY;
1782 xpt_release_ccb(ccb);
1785 /* Allow medium removal. */
1786 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1787 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1788 daprevent(periph, PR_ALLOW);
1790 da_periph_unhold(periph, DA_REF_CLOSE_HOLD);
1794 * If we've got removeable media, mark the blocksize as
1795 * unavailable, since it could change when new media is
1798 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1799 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1801 softc->flags &= ~DA_FLAG_OPEN;
1802 while (softc->refcount != 0)
1803 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1804 cam_periph_unlock(periph);
1805 da_periph_release(periph, DA_REF_OPEN);
1810 daschedule(struct cam_periph *periph)
1812 struct da_softc *softc = (struct da_softc *)periph->softc;
1814 if (softc->state != DA_STATE_NORMAL)
1817 cam_iosched_schedule(softc->cam_iosched, periph);
1821 * Actually translate the requested transfer into one the physical driver
1822 * can understand. The transfer is described by a buf and will include
1823 * only one physical transfer.
1826 dastrategy(struct bio *bp)
1828 struct cam_periph *periph;
1829 struct da_softc *softc;
1831 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1832 softc = (struct da_softc *)periph->softc;
1834 cam_periph_lock(periph);
1837 * If the device has been made invalid, error out
1839 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1840 cam_periph_unlock(periph);
1841 biofinish(bp, NULL, ENXIO);
1845 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1848 * Zone commands must be ordered, because they can depend on the
1849 * effects of previously issued commands, and they may affect
1850 * commands after them.
1852 if (bp->bio_cmd == BIO_ZONE)
1853 bp->bio_flags |= BIO_ORDERED;
1856 * Place it in the queue of disk activities for this disk
1858 cam_iosched_queue_work(softc->cam_iosched, bp);
1861 * Schedule ourselves for performing the work.
1864 cam_periph_unlock(periph);
1870 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1872 struct cam_periph *periph;
1873 struct da_softc *softc;
1875 struct ccb_scsiio csio;
1880 periph = dp->d_drv1;
1881 softc = (struct da_softc *)periph->softc;
1882 secsize = softc->params.secsize;
1884 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0)
1887 memset(&csio, 0, sizeof(csio));
1889 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1890 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1891 scsi_read_write(&csio,
1895 /*read*/SCSI_RW_WRITE,
1897 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1900 /*data_ptr*/(u_int8_t *) virtual,
1901 /*dxfer_len*/length,
1902 /*sense_len*/SSD_FULL_SIZE,
1903 da_default_timeout * 1000);
1904 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1905 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1907 printf("Aborting dump due to I/O error.\n");
1912 * Sync the disk cache contents to the physical media.
1914 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1916 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1917 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1918 scsi_synchronize_cache(&csio,
1922 /*begin_lba*/0,/* Cover the whole disk */
1926 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1927 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1929 xpt_print(periph->path, "Synchronize cache failed\n");
1935 dagetattr(struct bio *bp)
1938 struct cam_periph *periph;
1940 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1941 cam_periph_lock(periph);
1942 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1944 cam_periph_unlock(periph);
1946 bp->bio_completed = bp->bio_length;
1956 * Install a global async callback. This callback will
1957 * receive async callbacks like "new device found".
1959 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1961 if (status != CAM_REQ_CMP) {
1962 printf("da: Failed to attach master async callback "
1963 "due to status 0x%x!\n", status);
1964 } else if (da_send_ordered) {
1966 /* Register our shutdown event handler */
1967 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1968 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1969 printf("dainit: shutdown event registration failed!\n");
1974 * Callback from GEOM, called when it has finished cleaning up its
1978 dadiskgonecb(struct disk *dp)
1980 struct cam_periph *periph;
1982 periph = (struct cam_periph *)dp->d_drv1;
1983 da_periph_release(periph, DA_REF_GEOM);
1987 daoninvalidate(struct cam_periph *periph)
1989 struct da_softc *softc;
1991 cam_periph_assert(periph, MA_OWNED);
1992 softc = (struct da_softc *)periph->softc;
1995 * De-register any async callbacks.
1997 xpt_register_async(0, daasync, periph, periph->path);
1999 softc->flags |= DA_FLAG_PACK_INVALID;
2001 softc->invalidations++;
2005 * Return all queued I/O with ENXIO.
2006 * XXX Handle any transactions queued to the card
2007 * with XPT_ABORT_CCB.
2009 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
2012 * Tell GEOM that we've gone away, we'll get a callback when it is
2013 * done cleaning up its resources.
2015 disk_gone(softc->disk);
2019 dacleanup(struct cam_periph *periph)
2021 struct da_softc *softc;
2023 softc = (struct da_softc *)periph->softc;
2025 cam_periph_unlock(periph);
2027 cam_iosched_fini(softc->cam_iosched);
2030 * If we can't free the sysctl tree, oh well...
2032 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
2034 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
2035 xpt_print(periph->path,
2036 "can't remove sysctl stats context\n");
2038 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
2039 xpt_print(periph->path,
2040 "can't remove sysctl context\n");
2043 callout_drain(&softc->mediapoll_c);
2044 disk_destroy(softc->disk);
2045 callout_drain(&softc->sendordered_c);
2046 free(softc, M_DEVBUF);
2047 cam_periph_lock(periph);
2051 daasync(void *callback_arg, u_int32_t code,
2052 struct cam_path *path, void *arg)
2054 struct cam_periph *periph;
2055 struct da_softc *softc;
2057 periph = (struct cam_periph *)callback_arg;
2059 case AC_FOUND_DEVICE: /* callback to create periph, no locking yet */
2061 struct ccb_getdev *cgd;
2064 cgd = (struct ccb_getdev *)arg;
2068 if (cgd->protocol != PROTO_SCSI)
2070 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
2072 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
2073 && SID_TYPE(&cgd->inq_data) != T_RBC
2074 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
2075 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
2079 * Allocate a peripheral instance for
2080 * this device and start the probe
2083 status = cam_periph_alloc(daregister, daoninvalidate,
2085 "da", CAM_PERIPH_BIO,
2087 AC_FOUND_DEVICE, cgd);
2089 if (status != CAM_REQ_CMP
2090 && status != CAM_REQ_INPROG)
2091 printf("daasync: Unable to attach to new device "
2092 "due to status 0x%x\n", status);
2095 case AC_ADVINFO_CHANGED: /* Doesn't touch periph */
2099 buftype = (uintptr_t)arg;
2100 if (buftype == CDAI_TYPE_PHYS_PATH) {
2101 struct da_softc *softc;
2103 softc = periph->softc;
2104 disk_attr_changed(softc->disk, "GEOM::physpath",
2109 case AC_UNIT_ATTENTION:
2112 int error_code, sense_key, asc, ascq;
2114 softc = (struct da_softc *)periph->softc;
2115 ccb = (union ccb *)arg;
2118 * Handle all UNIT ATTENTIONs except our own, as they will be
2119 * handled by daerror(). Since this comes from a different periph,
2120 * that periph's lock is held, not ours, so we have to take it ours
2121 * out to touch softc flags.
2123 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
2124 scsi_extract_sense_ccb(ccb,
2125 &error_code, &sense_key, &asc, &ascq)) {
2126 if (asc == 0x2A && ascq == 0x09) {
2127 xpt_print(ccb->ccb_h.path,
2128 "Capacity data has changed\n");
2129 cam_periph_lock(periph);
2130 softc->flags &= ~DA_FLAG_PROBED;
2131 cam_periph_unlock(periph);
2133 } else if (asc == 0x28 && ascq == 0x00) {
2134 cam_periph_lock(periph);
2135 softc->flags &= ~DA_FLAG_PROBED;
2136 cam_periph_unlock(periph);
2137 disk_media_changed(softc->disk, M_NOWAIT);
2138 } else if (asc == 0x3F && ascq == 0x03) {
2139 xpt_print(ccb->ccb_h.path,
2140 "INQUIRY data has changed\n");
2141 cam_periph_lock(periph);
2142 softc->flags &= ~DA_FLAG_PROBED;
2143 cam_periph_unlock(periph);
2149 case AC_SCSI_AEN: /* Called for this path: periph locked */
2151 * Appears to be currently unused for SCSI devices, only ata SIMs
2154 cam_periph_assert(periph, MA_OWNED);
2155 softc = (struct da_softc *)periph->softc;
2156 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
2157 (softc->flags & DA_FLAG_TUR_PENDING) == 0) {
2158 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
2159 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
2164 case AC_SENT_BDR: /* Called for this path: periph locked */
2165 case AC_BUS_RESET: /* Called for this path: periph locked */
2167 struct ccb_hdr *ccbh;
2169 cam_periph_assert(periph, MA_OWNED);
2170 softc = (struct da_softc *)periph->softc;
2172 * Don't fail on the expected unit attention
2175 softc->flags |= DA_FLAG_RETRY_UA;
2176 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
2177 ccbh->ccb_state |= DA_CCB_RETRY_UA;
2180 case AC_INQ_CHANGED: /* Called for this path: periph locked */
2181 cam_periph_assert(periph, MA_OWNED);
2182 softc = (struct da_softc *)periph->softc;
2183 softc->flags &= ~DA_FLAG_PROBED;
2189 cam_periph_async(periph, code, path, arg);
2193 dasysctlinit(void *context, int pending)
2195 struct cam_periph *periph;
2196 struct da_softc *softc;
2197 char tmpstr[32], tmpstr2[16];
2198 struct ccb_trans_settings cts;
2200 periph = (struct cam_periph *)context;
2202 * periph was held for us when this task was enqueued
2204 if (periph->flags & CAM_PERIPH_INVALID) {
2205 da_periph_release(periph, DA_REF_SYSCTL);
2209 softc = (struct da_softc *)periph->softc;
2210 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
2211 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
2213 sysctl_ctx_init(&softc->sysctl_ctx);
2214 cam_periph_lock(periph);
2215 softc->flags |= DA_FLAG_SCTX_INIT;
2216 cam_periph_unlock(periph);
2217 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
2218 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
2219 CTLFLAG_RD, 0, tmpstr, "device_index");
2220 if (softc->sysctl_tree == NULL) {
2221 printf("dasysctlinit: unable to allocate sysctl tree\n");
2222 da_periph_release(periph, DA_REF_SYSCTL);
2227 * Now register the sysctl handler, so the user can change the value on
2230 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2231 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
2232 softc, 0, dadeletemethodsysctl, "A",
2233 "BIO_DELETE execution method");
2234 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2235 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
2236 softc, 0, dadeletemaxsysctl, "Q",
2237 "Maximum BIO_DELETE size");
2238 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2239 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
2240 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
2241 "Minimum CDB size");
2242 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2243 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2244 "trim_count", CTLFLAG_RD, &softc->trim_count,
2245 "Total number of unmap/dsm commands sent");
2246 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2247 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2248 "trim_ranges", CTLFLAG_RD, &softc->trim_ranges,
2249 "Total number of ranges in unmap/dsm commands");
2250 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2251 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2252 "trim_lbas", CTLFLAG_RD, &softc->trim_lbas,
2253 "Total lbas in the unmap/dsm commands sent");
2255 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2256 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
2257 softc, 0, dazonemodesysctl, "A",
2259 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2260 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
2261 softc, 0, dazonesupsysctl, "A",
2263 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2264 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2265 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2266 "Optimal Number of Open Sequential Write Preferred Zones");
2267 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2268 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2269 "optimal_nonseq_zones", CTLFLAG_RD,
2270 &softc->optimal_nonseq_zones,
2271 "Optimal Number of Non-Sequentially Written Sequential Write "
2273 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2274 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2275 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2276 "Maximum Number of Open Sequential Write Required Zones");
2278 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2279 SYSCTL_CHILDREN(softc->sysctl_tree),
2283 &softc->error_inject,
2285 "error_inject leaf");
2287 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2288 SYSCTL_CHILDREN(softc->sysctl_tree),
2294 "Unmapped I/O leaf");
2296 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2297 SYSCTL_CHILDREN(softc->sysctl_tree),
2305 #ifdef CAM_TEST_FAILURE
2306 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2307 OID_AUTO, "invalidate", CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE,
2308 periph, 0, cam_periph_invalidate_sysctl, "I",
2309 "Write 1 to invalidate the drive immediately");
2313 * Add some addressing info.
2315 memset(&cts, 0, sizeof (cts));
2316 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2317 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2318 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2319 cam_periph_lock(periph);
2320 xpt_action((union ccb *)&cts);
2321 cam_periph_unlock(periph);
2322 if (cts.ccb_h.status != CAM_REQ_CMP) {
2323 da_periph_release(periph, DA_REF_SYSCTL);
2326 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2327 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2328 if (fc->valid & CTS_FC_VALID_WWPN) {
2329 softc->wwpn = fc->wwpn;
2330 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2331 SYSCTL_CHILDREN(softc->sysctl_tree),
2332 OID_AUTO, "wwpn", CTLFLAG_RD,
2333 &softc->wwpn, "World Wide Port Name");
2339 * Now add some useful stats.
2340 * XXX These should live in cam_periph and be common to all periphs
2342 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2343 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2344 CTLFLAG_RD, 0, "Statistics");
2345 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2346 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2352 "Transport errors reported by the SIM");
2353 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2354 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2360 "Device timeouts reported by the SIM");
2361 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2362 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2364 "pack_invalidations",
2366 &softc->invalidations,
2368 "Device pack invalidations");
2371 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2372 softc->sysctl_tree);
2374 da_periph_release(periph, DA_REF_SYSCTL);
2378 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2382 struct da_softc *softc;
2384 softc = (struct da_softc *)arg1;
2386 value = softc->disk->d_delmaxsize;
2387 error = sysctl_handle_64(oidp, &value, 0, req);
2388 if ((error != 0) || (req->newptr == NULL))
2391 /* only accept values smaller than the calculated value */
2392 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2395 softc->disk->d_delmaxsize = value;
2401 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2405 value = *(int *)arg1;
2407 error = sysctl_handle_int(oidp, &value, 0, req);
2410 || (req->newptr == NULL))
2414 * Acceptable values here are 6, 10, 12 or 16.
2418 else if ((value > 6)
2421 else if ((value > 10)
2424 else if (value > 12)
2427 *(int *)arg1 = value;
2433 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2438 value = da_default_softtimeout / SBT_1MS;
2440 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2441 if ((error != 0) || (req->newptr == NULL))
2444 /* XXX Should clip this to a reasonable level */
2445 if (value > da_default_timeout * 1000)
2448 da_default_softtimeout = value * SBT_1MS;
2453 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2456 softc->delete_method = delete_method;
2457 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2458 softc->delete_func = da_delete_functions[delete_method];
2460 if (softc->delete_method > DA_DELETE_DISABLE)
2461 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2463 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2467 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2471 switch(delete_method) {
2472 case DA_DELETE_UNMAP:
2473 sectors = (off_t)softc->unmap_max_lba;
2475 case DA_DELETE_ATA_TRIM:
2476 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2478 case DA_DELETE_WS16:
2479 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2481 case DA_DELETE_ZERO:
2482 case DA_DELETE_WS10:
2483 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2489 return (off_t)softc->params.secsize *
2490 omin(sectors, softc->params.sectors);
2494 daprobedone(struct cam_periph *periph, union ccb *ccb)
2496 struct da_softc *softc;
2498 softc = (struct da_softc *)periph->softc;
2500 cam_periph_assert(periph, MA_OWNED);
2502 dadeletemethodchoose(softc, DA_DELETE_NONE);
2504 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2508 snprintf(buf, sizeof(buf), "Delete methods: <");
2510 for (i = 0; i <= DA_DELETE_MAX; i++) {
2511 if ((softc->delete_available & (1 << i)) == 0 &&
2512 i != softc->delete_method)
2515 strlcat(buf, ",", sizeof(buf));
2516 strlcat(buf, da_delete_method_names[i],
2518 if (i == softc->delete_method)
2519 strlcat(buf, "(*)", sizeof(buf));
2522 strlcat(buf, ">", sizeof(buf));
2523 printf("%s%d: %s\n", periph->periph_name,
2524 periph->unit_number, buf);
2526 if ((softc->disk->d_flags & DISKFLAG_WRITE_PROTECT) != 0 &&
2527 (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2528 printf("%s%d: Write Protected\n", periph->periph_name,
2529 periph->unit_number);
2533 * Since our peripheral may be invalidated by an error
2534 * above or an external event, we must release our CCB
2535 * before releasing the probe lock on the peripheral.
2536 * The peripheral will only go away once the last lock
2537 * is removed, and we need it around for the CCB release
2540 xpt_release_ccb(ccb);
2541 softc->state = DA_STATE_NORMAL;
2542 softc->flags |= DA_FLAG_PROBED;
2544 wakeup(&softc->disk->d_mediasize);
2545 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2546 softc->flags |= DA_FLAG_ANNOUNCED;
2547 da_periph_unhold(periph, DA_REF_PROBE_HOLD);
2549 da_periph_release_locked(periph, DA_REF_REPROBE);
2553 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2557 /* If available, prefer the method requested by user. */
2558 i = softc->delete_method_pref;
2559 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2560 if (methods & (1 << i)) {
2561 dadeletemethodset(softc, i);
2565 /* Use the pre-defined order to choose the best performing delete. */
2566 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2567 if (i == DA_DELETE_ZERO)
2569 if (softc->delete_available & (1 << i)) {
2570 dadeletemethodset(softc, i);
2575 /* Fallback to default. */
2576 dadeletemethodset(softc, default_method);
2580 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2584 struct da_softc *softc;
2585 int i, error, value;
2587 softc = (struct da_softc *)arg1;
2589 value = softc->delete_method;
2590 if (value < 0 || value > DA_DELETE_MAX)
2593 p = da_delete_method_names[value];
2594 strncpy(buf, p, sizeof(buf));
2595 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2596 if (error != 0 || req->newptr == NULL)
2598 for (i = 0; i <= DA_DELETE_MAX; i++) {
2599 if (strcmp(buf, da_delete_method_names[i]) == 0)
2602 if (i > DA_DELETE_MAX)
2604 softc->delete_method_pref = i;
2605 dadeletemethodchoose(softc, DA_DELETE_NONE);
2610 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2613 struct da_softc *softc;
2616 softc = (struct da_softc *)arg1;
2618 switch (softc->zone_mode) {
2619 case DA_ZONE_DRIVE_MANAGED:
2620 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2622 case DA_ZONE_HOST_AWARE:
2623 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2625 case DA_ZONE_HOST_MANAGED:
2626 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2630 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2634 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2640 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2643 struct da_softc *softc;
2648 softc = (struct da_softc *)arg1;
2652 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2654 for (i = 0; i < sizeof(da_zone_desc_table) /
2655 sizeof(da_zone_desc_table[0]); i++) {
2656 if (softc->zone_flags & da_zone_desc_table[i].value) {
2658 sbuf_printf(&sb, ", ");
2661 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2666 sbuf_printf(&sb, "None");
2670 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2676 daregister(struct cam_periph *periph, void *arg)
2678 struct da_softc *softc;
2679 struct ccb_pathinq cpi;
2680 struct ccb_getdev *cgd;
2684 cgd = (struct ccb_getdev *)arg;
2686 printf("daregister: no getdev CCB, can't register device\n");
2687 return(CAM_REQ_CMP_ERR);
2690 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2693 if (softc == NULL) {
2694 printf("daregister: Unable to probe new device. "
2695 "Unable to allocate softc\n");
2696 return(CAM_REQ_CMP_ERR);
2699 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2700 printf("daregister: Unable to probe new device. "
2701 "Unable to allocate iosched memory\n");
2702 free(softc, M_DEVBUF);
2703 return(CAM_REQ_CMP_ERR);
2706 LIST_INIT(&softc->pending_ccbs);
2707 softc->state = DA_STATE_PROBE_WP;
2708 bioq_init(&softc->delete_run_queue);
2709 if (SID_IS_REMOVABLE(&cgd->inq_data))
2710 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2711 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2712 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2713 softc->unmap_gran = 0;
2714 softc->unmap_gran_align = 0;
2715 softc->ws_max_blks = WS16_MAX_BLKS;
2716 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2717 softc->rotating = 1;
2719 periph->softc = softc;
2722 * See if this device has any quirks.
2724 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2725 (caddr_t)da_quirk_table,
2726 nitems(da_quirk_table),
2727 sizeof(*da_quirk_table), scsi_inquiry_match);
2730 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2732 softc->quirks = DA_Q_NONE;
2734 /* Check if the SIM does not want 6 byte commands */
2735 xpt_path_inq(&cpi, periph->path);
2736 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2737 softc->quirks |= DA_Q_NO_6_BYTE;
2739 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2740 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2741 else if (softc->quirks & DA_Q_SMR_DM)
2742 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2744 softc->zone_mode = DA_ZONE_NONE;
2746 if (softc->zone_mode != DA_ZONE_NONE) {
2747 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2748 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2749 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2751 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2753 softc->zone_interface = DA_ZONE_IF_SCSI;
2756 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2759 * Take an exclusive section lock qon the periph while dastart is called
2760 * to finish the probe. The lock will be dropped in dadone at the end
2761 * of probe. This locks out daopen and daclose from racing with the
2764 * XXX if cam_periph_hold returns an error, we don't hold a refcount.
2766 (void)da_periph_hold(periph, PRIBIO, DA_REF_PROBE_HOLD);
2769 * Schedule a periodic event to occasionally send an
2770 * ordered tag to a device.
2772 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2773 callout_reset(&softc->sendordered_c,
2774 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2775 dasendorderedtag, periph);
2777 cam_periph_unlock(periph);
2779 * RBC devices don't have to support READ(6), only READ(10).
2781 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2782 softc->minimum_cmd_size = 10;
2784 softc->minimum_cmd_size = 6;
2787 * Load the user's default, if any.
2789 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2790 periph->unit_number);
2791 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2794 * 6, 10, 12 and 16 are the currently permissible values.
2796 if (softc->minimum_cmd_size > 12)
2797 softc->minimum_cmd_size = 16;
2798 else if (softc->minimum_cmd_size > 10)
2799 softc->minimum_cmd_size = 12;
2800 else if (softc->minimum_cmd_size > 6)
2801 softc->minimum_cmd_size = 10;
2803 softc->minimum_cmd_size = 6;
2805 /* Predict whether device may support READ CAPACITY(16). */
2806 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2807 (softc->quirks & DA_Q_NO_RC16) == 0) {
2808 softc->flags |= DA_FLAG_CAN_RC16;
2812 * Register this media as a disk.
2814 softc->disk = disk_alloc();
2815 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2816 periph->unit_number, 0,
2817 DEVSTAT_BS_UNAVAILABLE,
2818 SID_TYPE(&cgd->inq_data) |
2819 XPORT_DEVSTAT_TYPE(cpi.transport),
2820 DEVSTAT_PRIORITY_DISK);
2821 softc->disk->d_open = daopen;
2822 softc->disk->d_close = daclose;
2823 softc->disk->d_strategy = dastrategy;
2824 softc->disk->d_dump = dadump;
2825 softc->disk->d_getattr = dagetattr;
2826 softc->disk->d_gone = dadiskgonecb;
2827 softc->disk->d_name = "da";
2828 softc->disk->d_drv1 = periph;
2830 softc->maxio = DFLTPHYS; /* traditional default */
2831 else if (cpi.maxio > MAXPHYS)
2832 softc->maxio = MAXPHYS; /* for safety */
2834 softc->maxio = cpi.maxio;
2835 if (softc->quirks & DA_Q_128KB)
2836 softc->maxio = min(softc->maxio, 128 * 1024);
2837 softc->disk->d_maxsize = softc->maxio;
2838 softc->disk->d_unit = periph->unit_number;
2839 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2840 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2841 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2842 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2843 softc->unmappedio = 1;
2844 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2846 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2847 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2848 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2849 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2850 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2851 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2852 softc->disk->d_hba_vendor = cpi.hba_vendor;
2853 softc->disk->d_hba_device = cpi.hba_device;
2854 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2855 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2858 * Acquire a reference to the periph before we register with GEOM.
2859 * We'll release this reference once GEOM calls us back (via
2860 * dadiskgonecb()) telling us that our provider has been freed.
2862 if (da_periph_acquire(periph, DA_REF_GEOM) != 0) {
2863 xpt_print(periph->path, "%s: lost periph during "
2864 "registration!\n", __func__);
2865 cam_periph_lock(periph);
2866 return (CAM_REQ_CMP_ERR);
2869 disk_create(softc->disk, DISK_VERSION);
2870 cam_periph_lock(periph);
2873 * Add async callbacks for events of interest.
2874 * I don't bother checking if this fails as,
2875 * in most cases, the system will function just
2876 * fine without them and the only alternative
2877 * would be to not attach the device on failure.
2879 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2880 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2881 AC_INQ_CHANGED, daasync, periph, periph->path);
2884 * Emit an attribute changed notification just in case
2885 * physical path information arrived before our async
2886 * event handler was registered, but after anyone attaching
2887 * to our disk device polled it.
2889 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2892 * Schedule a periodic media polling events.
2894 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2895 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2896 (cgd->inq_flags & SID_AEN) == 0 &&
2897 da_poll_period != 0)
2898 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2899 damediapoll, periph);
2901 xpt_schedule(periph, CAM_PRIORITY_DEV);
2903 return(CAM_REQ_CMP);
2907 da_zone_bio_to_scsi(int disk_zone_cmd)
2909 switch (disk_zone_cmd) {
2910 case DISK_ZONE_OPEN:
2911 return ZBC_OUT_SA_OPEN;
2912 case DISK_ZONE_CLOSE:
2913 return ZBC_OUT_SA_CLOSE;
2914 case DISK_ZONE_FINISH:
2915 return ZBC_OUT_SA_FINISH;
2917 return ZBC_OUT_SA_RWP;
2924 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2927 struct da_softc *softc;
2932 if (bp->bio_cmd != BIO_ZONE) {
2937 softc = periph->softc;
2939 switch (bp->bio_zone.zone_cmd) {
2940 case DISK_ZONE_OPEN:
2941 case DISK_ZONE_CLOSE:
2942 case DISK_ZONE_FINISH:
2943 case DISK_ZONE_RWP: {
2948 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2949 if (zone_sa == -1) {
2950 xpt_print(periph->path, "Cannot translate zone "
2951 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2957 lba = bp->bio_zone.zone_params.rwp.id;
2959 if (bp->bio_zone.zone_params.rwp.flags &
2960 DISK_ZONE_RWP_FLAG_ALL)
2961 zone_flags |= ZBC_OUT_ALL;
2963 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2964 scsi_zbc_out(&ccb->csio,
2965 /*retries*/ da_retry_count,
2967 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2968 /*service_action*/ zone_sa,
2970 /*zone_flags*/ zone_flags,
2973 /*sense_len*/ SSD_FULL_SIZE,
2974 /*timeout*/ da_default_timeout * 1000);
2977 * Note that in this case, even though we can
2978 * technically use NCQ, we don't bother for several
2980 * 1. It hasn't been tested on a SAT layer that
2981 * supports it. This is new as of SAT-4.
2982 * 2. Even when there is a SAT layer that supports
2983 * it, that SAT layer will also probably support
2984 * ZBC -> ZAC translation, since they are both
2985 * in the SAT-4 spec.
2986 * 3. Translation will likely be preferable to ATA
2987 * passthrough. LSI / Avago at least single
2988 * steps ATA passthrough commands in the HBA,
2989 * regardless of protocol, so unless that
2990 * changes, there is a performance penalty for
2991 * doing ATA passthrough no matter whether
2992 * you're using NCQ/FPDMA, DMA or PIO.
2993 * 4. It requires a 32-byte CDB, which at least at
2994 * this point in CAM requires a CDB pointer, which
2995 * would require us to allocate an additional bit
2996 * of storage separate from the CCB.
2998 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2999 /*retries*/ da_retry_count,
3001 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3003 /*zm_action*/ zone_sa,
3005 /*zone_flags*/ zone_flags,
3008 /*cdb_storage*/ NULL,
3009 /*cdb_storage_len*/ 0,
3010 /*sense_len*/ SSD_FULL_SIZE,
3011 /*timeout*/ da_default_timeout * 1000);
3014 xpt_print(periph->path,
3015 "scsi_ata_zac_mgmt_out() returned an "
3024 case DISK_ZONE_REPORT_ZONES: {
3026 uint32_t num_entries, alloc_size;
3027 struct disk_zone_report *rep;
3029 rep = &bp->bio_zone.zone_params.report;
3031 num_entries = rep->entries_allocated;
3032 if (num_entries == 0) {
3033 xpt_print(periph->path, "No entries allocated for "
3034 "Report Zones request\n");
3038 alloc_size = sizeof(struct scsi_report_zones_hdr) +
3039 (sizeof(struct scsi_report_zones_desc) * num_entries);
3040 alloc_size = min(alloc_size, softc->disk->d_maxsize);
3041 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
3042 if (rz_ptr == NULL) {
3043 xpt_print(periph->path, "Unable to allocate memory "
3044 "for Report Zones request\n");
3049 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
3050 scsi_zbc_in(&ccb->csio,
3051 /*retries*/ da_retry_count,
3053 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3054 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
3055 /*zone_start_lba*/ rep->starting_id,
3056 /*zone_options*/ rep->rep_options,
3057 /*data_ptr*/ rz_ptr,
3058 /*dxfer_len*/ alloc_size,
3059 /*sense_len*/ SSD_FULL_SIZE,
3060 /*timeout*/ da_default_timeout * 1000);
3063 * Note that in this case, even though we can
3064 * technically use NCQ, we don't bother for several
3066 * 1. It hasn't been tested on a SAT layer that
3067 * supports it. This is new as of SAT-4.
3068 * 2. Even when there is a SAT layer that supports
3069 * it, that SAT layer will also probably support
3070 * ZBC -> ZAC translation, since they are both
3071 * in the SAT-4 spec.
3072 * 3. Translation will likely be preferable to ATA
3073 * passthrough. LSI / Avago at least single
3074 * steps ATA passthrough commands in the HBA,
3075 * regardless of protocol, so unless that
3076 * changes, there is a performance penalty for
3077 * doing ATA passthrough no matter whether
3078 * you're using NCQ/FPDMA, DMA or PIO.
3079 * 4. It requires a 32-byte CDB, which at least at
3080 * this point in CAM requires a CDB pointer, which
3081 * would require us to allocate an additional bit
3082 * of storage separate from the CCB.
3084 error = scsi_ata_zac_mgmt_in(&ccb->csio,
3085 /*retries*/ da_retry_count,
3087 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3089 /*zm_action*/ ATA_ZM_REPORT_ZONES,
3090 /*zone_id*/ rep->starting_id,
3091 /*zone_flags*/ rep->rep_options,
3092 /*data_ptr*/ rz_ptr,
3093 /*dxfer_len*/ alloc_size,
3094 /*cdb_storage*/ NULL,
3095 /*cdb_storage_len*/ 0,
3096 /*sense_len*/ SSD_FULL_SIZE,
3097 /*timeout*/ da_default_timeout * 1000);
3100 xpt_print(periph->path,
3101 "scsi_ata_zac_mgmt_in() returned an "
3108 * For BIO_ZONE, this isn't normally needed. However, it
3109 * is used by devstat_end_transaction_bio() to determine
3110 * how much data was transferred.
3113 * XXX KDM we have a problem. But I'm not sure how to fix
3114 * it. devstat uses bio_bcount - bio_resid to calculate
3115 * the amount of data transferred. The GEOM disk code
3116 * uses bio_length - bio_resid to calculate the amount of
3117 * data in bio_completed. We have different structure
3118 * sizes above and below the ada(4) driver. So, if we
3119 * use the sizes above, the amount transferred won't be
3120 * quite accurate for devstat. If we use different sizes
3121 * for bio_bcount and bio_length (above and below
3122 * respectively), then the residual needs to match one or
3123 * the other. Everything is calculated after the bio
3124 * leaves the driver, so changing the values around isn't
3125 * really an option. For now, just set the count to the
3126 * passed in length. This means that the calculations
3127 * above (e.g. bio_completed) will be correct, but the
3128 * amount of data reported to devstat will be slightly
3129 * under or overstated.
3131 bp->bio_bcount = bp->bio_length;
3137 case DISK_ZONE_GET_PARAMS: {
3138 struct disk_zone_disk_params *params;
3140 params = &bp->bio_zone.zone_params.disk_params;
3141 bzero(params, sizeof(*params));
3143 switch (softc->zone_mode) {
3144 case DA_ZONE_DRIVE_MANAGED:
3145 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
3147 case DA_ZONE_HOST_AWARE:
3148 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
3150 case DA_ZONE_HOST_MANAGED:
3151 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
3155 params->zone_mode = DISK_ZONE_MODE_NONE;
3159 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
3160 params->flags |= DISK_ZONE_DISK_URSWRZ;
3162 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
3163 params->optimal_seq_zones = softc->optimal_seq_zones;
3164 params->flags |= DISK_ZONE_OPT_SEQ_SET;
3167 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
3168 params->optimal_nonseq_zones =
3169 softc->optimal_nonseq_zones;
3170 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
3173 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
3174 params->max_seq_zones = softc->max_seq_zones;
3175 params->flags |= DISK_ZONE_MAX_SEQ_SET;
3177 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
3178 params->flags |= DISK_ZONE_RZ_SUP;
3180 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
3181 params->flags |= DISK_ZONE_OPEN_SUP;
3183 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
3184 params->flags |= DISK_ZONE_CLOSE_SUP;
3186 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
3187 params->flags |= DISK_ZONE_FINISH_SUP;
3189 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
3190 params->flags |= DISK_ZONE_RWP_SUP;
3201 dastart(struct cam_periph *periph, union ccb *start_ccb)
3203 struct da_softc *softc;
3205 cam_periph_assert(periph, MA_OWNED);
3206 softc = (struct da_softc *)periph->softc;
3208 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
3211 switch (softc->state) {
3212 case DA_STATE_NORMAL:
3218 bp = cam_iosched_next_bio(softc->cam_iosched);
3220 if (cam_iosched_has_work_flags(softc->cam_iosched,
3222 softc->flags |= DA_FLAG_TUR_PENDING;
3223 cam_iosched_clr_work_flags(softc->cam_iosched,
3225 scsi_test_unit_ready(&start_ccb->csio,
3226 /*retries*/ da_retry_count,
3230 da_default_timeout * 1000);
3231 start_ccb->ccb_h.ccb_bp = NULL;
3232 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
3233 xpt_action(start_ccb);
3235 xpt_release_ccb(start_ccb);
3239 if (bp->bio_cmd == BIO_DELETE) {
3240 if (softc->delete_func != NULL) {
3241 softc->delete_func(periph, start_ccb, bp);
3245 * Not sure this is possible, but failsafe by
3246 * lying and saying "sure, done."
3248 biofinish(bp, NULL, 0);
3253 if (cam_iosched_has_work_flags(softc->cam_iosched,
3255 cam_iosched_clr_work_flags(softc->cam_iosched,
3257 da_periph_release_locked(periph, DA_REF_TUR);
3260 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
3261 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
3262 softc->flags &= ~DA_FLAG_NEED_OTAG;
3263 softc->flags |= DA_FLAG_WAS_OTAG;
3264 tag_code = MSG_ORDERED_Q_TAG;
3266 tag_code = MSG_SIMPLE_Q_TAG;
3269 switch (bp->bio_cmd) {
3276 biotrack(bp, __func__);
3278 if (bp->bio_cmd == BIO_WRITE) {
3279 softc->flags |= DA_FLAG_DIRTY;
3280 rw_op = SCSI_RW_WRITE;
3282 rw_op = SCSI_RW_READ;
3285 data_ptr = bp->bio_data;
3286 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
3287 rw_op |= SCSI_RW_BIO;
3291 scsi_read_write(&start_ccb->csio,
3292 /*retries*/da_retry_count,
3294 /*tag_action*/tag_code,
3297 softc->minimum_cmd_size,
3298 /*lba*/bp->bio_pblkno,
3299 /*block_count*/bp->bio_bcount /
3300 softc->params.secsize,
3302 /*dxfer_len*/ bp->bio_bcount,
3303 /*sense_len*/SSD_FULL_SIZE,
3304 da_default_timeout * 1000);
3305 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3306 start_ccb->csio.bio = bp;
3312 * If we don't support sync cache, or the disk
3313 * isn't dirty, FLUSH is a no-op. Use the
3314 * allocated CCB for the next bio if one is
3317 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) != 0 ||
3318 (softc->flags & DA_FLAG_DIRTY) == 0) {
3324 * BIO_FLUSH doesn't currently communicate
3325 * range data, so we synchronize the cache
3326 * over the whole disk.
3328 scsi_synchronize_cache(&start_ccb->csio,
3331 /*tag_action*/tag_code,
3335 da_default_timeout*1000);
3337 * Clear the dirty flag before sending the command.
3338 * Either this sync cache will be successful, or it
3339 * will fail after a retry. If it fails, it is
3340 * unlikely to be successful if retried later, so
3341 * we'll save ourselves time by just marking the
3344 softc->flags &= ~DA_FLAG_DIRTY;
3347 int error, queue_ccb;
3351 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3353 || (queue_ccb == 0)) {
3354 biofinish(bp, NULL, error);
3355 xpt_release_ccb(start_ccb);
3361 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3362 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3363 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3366 LIST_INSERT_HEAD(&softc->pending_ccbs,
3367 &start_ccb->ccb_h, periph_links.le);
3369 /* We expect a unit attention from this device */
3370 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3371 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3372 softc->flags &= ~DA_FLAG_RETRY_UA;
3375 start_ccb->ccb_h.ccb_bp = bp;
3377 cam_periph_unlock(periph);
3378 xpt_action(start_ccb);
3379 cam_periph_lock(periph);
3381 /* May have more work to do, so ensure we stay scheduled */
3385 case DA_STATE_PROBE_WP:
3390 if (da_disable_wp_detection) {
3391 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3392 softc->state = DA_STATE_PROBE_RC16;
3394 softc->state = DA_STATE_PROBE_RC;
3398 mode_buf = malloc(mode_buf_len, M_SCSIDA, M_NOWAIT);
3399 if (mode_buf == NULL) {
3400 xpt_print(periph->path, "Unable to send mode sense - "
3401 "malloc failure\n");
3402 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3403 softc->state = DA_STATE_PROBE_RC16;
3405 softc->state = DA_STATE_PROBE_RC;
3408 scsi_mode_sense_len(&start_ccb->csio,
3409 /*retries*/ da_retry_count,
3410 /*cbfcnp*/ dadone_probewp,
3411 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3413 /*pc*/ SMS_PAGE_CTRL_CURRENT,
3414 /*page*/ SMS_ALL_PAGES_PAGE,
3415 /*param_buf*/ mode_buf,
3416 /*param_len*/ mode_buf_len,
3417 /*minimum_cmd_size*/ softc->minimum_cmd_size,
3418 /*sense_len*/ SSD_FULL_SIZE,
3419 /*timeout*/ da_default_timeout * 1000);
3420 start_ccb->ccb_h.ccb_bp = NULL;
3421 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_WP;
3422 xpt_action(start_ccb);
3425 case DA_STATE_PROBE_RC:
3427 struct scsi_read_capacity_data *rcap;
3429 rcap = (struct scsi_read_capacity_data *)
3430 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3432 printf("dastart: Couldn't malloc read_capacity data\n");
3433 /* da_free_periph??? */
3436 scsi_read_capacity(&start_ccb->csio,
3437 /*retries*/da_retry_count,
3443 start_ccb->ccb_h.ccb_bp = NULL;
3444 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3445 xpt_action(start_ccb);
3448 case DA_STATE_PROBE_RC16:
3450 struct scsi_read_capacity_data_long *rcaplong;
3452 rcaplong = (struct scsi_read_capacity_data_long *)
3453 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3454 if (rcaplong == NULL) {
3455 printf("dastart: Couldn't malloc read_capacity data\n");
3456 /* da_free_periph??? */
3459 scsi_read_capacity_16(&start_ccb->csio,
3460 /*retries*/ da_retry_count,
3461 /*cbfcnp*/ dadone_proberc,
3462 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3466 /*rcap_buf*/ (uint8_t *)rcaplong,
3467 /*rcap_buf_len*/ sizeof(*rcaplong),
3468 /*sense_len*/ SSD_FULL_SIZE,
3469 /*timeout*/ da_default_timeout * 1000);
3470 start_ccb->ccb_h.ccb_bp = NULL;
3471 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3472 xpt_action(start_ccb);
3475 case DA_STATE_PROBE_LBP:
3477 struct scsi_vpd_logical_block_prov *lbp;
3479 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3481 * If we get here we don't support any SBC-3 delete
3482 * methods with UNMAP as the Logical Block Provisioning
3483 * VPD page support is required for devices which
3484 * support it according to T10/1799-D Revision 31
3485 * however older revisions of the spec don't mandate
3486 * this so we currently don't remove these methods
3487 * from the available set.
3489 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3493 lbp = (struct scsi_vpd_logical_block_prov *)
3494 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3497 printf("dastart: Couldn't malloc lbp data\n");
3498 /* da_free_periph??? */
3502 scsi_inquiry(&start_ccb->csio,
3503 /*retries*/da_retry_count,
3504 /*cbfcnp*/dadone_probelbp,
3505 /*tag_action*/MSG_SIMPLE_Q_TAG,
3506 /*inq_buf*/(u_int8_t *)lbp,
3507 /*inq_len*/sizeof(*lbp),
3509 /*page_code*/SVPD_LBP,
3510 /*sense_len*/SSD_MIN_SIZE,
3511 /*timeout*/da_default_timeout * 1000);
3512 start_ccb->ccb_h.ccb_bp = NULL;
3513 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3514 xpt_action(start_ccb);
3517 case DA_STATE_PROBE_BLK_LIMITS:
3519 struct scsi_vpd_block_limits *block_limits;
3521 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3522 /* Not supported skip to next probe */
3523 softc->state = DA_STATE_PROBE_BDC;
3527 block_limits = (struct scsi_vpd_block_limits *)
3528 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3530 if (block_limits == NULL) {
3531 printf("dastart: Couldn't malloc block_limits data\n");
3532 /* da_free_periph??? */
3536 scsi_inquiry(&start_ccb->csio,
3537 /*retries*/da_retry_count,
3538 /*cbfcnp*/dadone_probeblklimits,
3539 /*tag_action*/MSG_SIMPLE_Q_TAG,
3540 /*inq_buf*/(u_int8_t *)block_limits,
3541 /*inq_len*/sizeof(*block_limits),
3543 /*page_code*/SVPD_BLOCK_LIMITS,
3544 /*sense_len*/SSD_MIN_SIZE,
3545 /*timeout*/da_default_timeout * 1000);
3546 start_ccb->ccb_h.ccb_bp = NULL;
3547 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3548 xpt_action(start_ccb);
3551 case DA_STATE_PROBE_BDC:
3553 struct scsi_vpd_block_characteristics *bdc;
3555 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3556 softc->state = DA_STATE_PROBE_ATA;
3560 bdc = (struct scsi_vpd_block_characteristics *)
3561 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3564 printf("dastart: Couldn't malloc bdc data\n");
3565 /* da_free_periph??? */
3569 scsi_inquiry(&start_ccb->csio,
3570 /*retries*/da_retry_count,
3571 /*cbfcnp*/dadone_probebdc,
3572 /*tag_action*/MSG_SIMPLE_Q_TAG,
3573 /*inq_buf*/(u_int8_t *)bdc,
3574 /*inq_len*/sizeof(*bdc),
3576 /*page_code*/SVPD_BDC,
3577 /*sense_len*/SSD_MIN_SIZE,
3578 /*timeout*/da_default_timeout * 1000);
3579 start_ccb->ccb_h.ccb_bp = NULL;
3580 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3581 xpt_action(start_ccb);
3584 case DA_STATE_PROBE_ATA:
3586 struct ata_params *ata_params;
3588 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3589 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3590 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3592 * Note that if the ATA VPD page isn't
3593 * supported, we aren't talking to an ATA
3594 * device anyway. Support for that VPD
3595 * page is mandatory for SCSI to ATA (SAT)
3596 * translation layers.
3598 softc->state = DA_STATE_PROBE_ZONE;
3601 daprobedone(periph, start_ccb);
3605 ata_params = (struct ata_params*)
3606 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3608 if (ata_params == NULL) {
3609 xpt_print(periph->path, "Couldn't malloc ata_params "
3611 /* da_free_periph??? */
3615 scsi_ata_identify(&start_ccb->csio,
3616 /*retries*/da_retry_count,
3617 /*cbfcnp*/dadone_probeata,
3618 /*tag_action*/MSG_SIMPLE_Q_TAG,
3619 /*data_ptr*/(u_int8_t *)ata_params,
3620 /*dxfer_len*/sizeof(*ata_params),
3621 /*sense_len*/SSD_FULL_SIZE,
3622 /*timeout*/da_default_timeout * 1000);
3623 start_ccb->ccb_h.ccb_bp = NULL;
3624 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3625 xpt_action(start_ccb);
3628 case DA_STATE_PROBE_ATA_LOGDIR:
3630 struct ata_gp_log_dir *log_dir;
3635 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3637 * If we don't have log support, not much point in
3638 * trying to probe zone support.
3640 daprobedone(periph, start_ccb);
3645 * If we have an ATA device (the SCSI ATA Information VPD
3646 * page should be present and the ATA identify should have
3647 * succeeded) and it supports logs, ask for the log directory.
3650 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3651 if (log_dir == NULL) {
3652 xpt_print(periph->path, "Couldn't malloc log_dir "
3654 daprobedone(periph, start_ccb);
3658 retval = scsi_ata_read_log(&start_ccb->csio,
3659 /*retries*/ da_retry_count,
3660 /*cbfcnp*/ dadone_probeatalogdir,
3661 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3662 /*log_address*/ ATA_LOG_DIRECTORY,
3665 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3666 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3667 /*data_ptr*/ (uint8_t *)log_dir,
3668 /*dxfer_len*/ sizeof(*log_dir),
3669 /*sense_len*/ SSD_FULL_SIZE,
3670 /*timeout*/ da_default_timeout * 1000);
3673 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3674 free(log_dir, M_SCSIDA);
3675 daprobedone(periph, start_ccb);
3678 start_ccb->ccb_h.ccb_bp = NULL;
3679 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3680 xpt_action(start_ccb);
3683 case DA_STATE_PROBE_ATA_IDDIR:
3685 struct ata_identify_log_pages *id_dir;
3691 * Check here to see whether the Identify Device log is
3692 * supported in the directory of logs. If so, continue
3693 * with requesting the log of identify device pages.
3695 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3696 daprobedone(periph, start_ccb);
3700 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3701 if (id_dir == NULL) {
3702 xpt_print(periph->path, "Couldn't malloc id_dir "
3704 daprobedone(periph, start_ccb);
3708 retval = scsi_ata_read_log(&start_ccb->csio,
3709 /*retries*/ da_retry_count,
3710 /*cbfcnp*/ dadone_probeataiddir,
3711 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3712 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3713 /*page_number*/ ATA_IDL_PAGE_LIST,
3715 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3716 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3717 /*data_ptr*/ (uint8_t *)id_dir,
3718 /*dxfer_len*/ sizeof(*id_dir),
3719 /*sense_len*/ SSD_FULL_SIZE,
3720 /*timeout*/ da_default_timeout * 1000);
3723 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3724 free(id_dir, M_SCSIDA);
3725 daprobedone(periph, start_ccb);
3728 start_ccb->ccb_h.ccb_bp = NULL;
3729 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3730 xpt_action(start_ccb);
3733 case DA_STATE_PROBE_ATA_SUP:
3735 struct ata_identify_log_sup_cap *sup_cap;
3741 * Check here to see whether the Supported Capabilities log
3742 * is in the list of Identify Device logs.
3744 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3745 daprobedone(periph, start_ccb);
3749 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3750 if (sup_cap == NULL) {
3751 xpt_print(periph->path, "Couldn't malloc sup_cap "
3753 daprobedone(periph, start_ccb);
3757 retval = scsi_ata_read_log(&start_ccb->csio,
3758 /*retries*/ da_retry_count,
3759 /*cbfcnp*/ dadone_probeatasup,
3760 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3761 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3762 /*page_number*/ ATA_IDL_SUP_CAP,
3764 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3765 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3766 /*data_ptr*/ (uint8_t *)sup_cap,
3767 /*dxfer_len*/ sizeof(*sup_cap),
3768 /*sense_len*/ SSD_FULL_SIZE,
3769 /*timeout*/ da_default_timeout * 1000);
3772 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3773 free(sup_cap, M_SCSIDA);
3774 daprobedone(periph, start_ccb);
3779 start_ccb->ccb_h.ccb_bp = NULL;
3780 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3781 xpt_action(start_ccb);
3784 case DA_STATE_PROBE_ATA_ZONE:
3786 struct ata_zoned_info_log *ata_zone;
3792 * Check here to see whether the zoned device information
3793 * page is supported. If so, continue on to request it.
3794 * If not, skip to DA_STATE_PROBE_LOG or done.
3796 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3797 daprobedone(periph, start_ccb);
3800 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3802 if (ata_zone == NULL) {
3803 xpt_print(periph->path, "Couldn't malloc ata_zone "
3805 daprobedone(periph, start_ccb);
3809 retval = scsi_ata_read_log(&start_ccb->csio,
3810 /*retries*/ da_retry_count,
3811 /*cbfcnp*/ dadone_probeatazone,
3812 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3813 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3814 /*page_number*/ ATA_IDL_ZDI,
3816 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3817 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3818 /*data_ptr*/ (uint8_t *)ata_zone,
3819 /*dxfer_len*/ sizeof(*ata_zone),
3820 /*sense_len*/ SSD_FULL_SIZE,
3821 /*timeout*/ da_default_timeout * 1000);
3824 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3825 free(ata_zone, M_SCSIDA);
3826 daprobedone(periph, start_ccb);
3829 start_ccb->ccb_h.ccb_bp = NULL;
3830 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3831 xpt_action(start_ccb);
3835 case DA_STATE_PROBE_ZONE:
3837 struct scsi_vpd_zoned_bdc *bdc;
3840 * Note that this page will be supported for SCSI protocol
3841 * devices that support ZBC (SMR devices), as well as ATA
3842 * protocol devices that are behind a SAT (SCSI to ATA
3843 * Translation) layer that supports converting ZBC commands
3844 * to their ZAC equivalents.
3846 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3847 daprobedone(periph, start_ccb);
3850 bdc = (struct scsi_vpd_zoned_bdc *)
3851 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3854 xpt_release_ccb(start_ccb);
3855 xpt_print(periph->path, "Couldn't malloc zone VPD "
3859 scsi_inquiry(&start_ccb->csio,
3860 /*retries*/da_retry_count,
3861 /*cbfcnp*/dadone_probezone,
3862 /*tag_action*/MSG_SIMPLE_Q_TAG,
3863 /*inq_buf*/(u_int8_t *)bdc,
3864 /*inq_len*/sizeof(*bdc),
3866 /*page_code*/SVPD_ZONED_BDC,
3867 /*sense_len*/SSD_FULL_SIZE,
3868 /*timeout*/da_default_timeout * 1000);
3869 start_ccb->ccb_h.ccb_bp = NULL;
3870 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3871 xpt_action(start_ccb);
3878 * In each of the methods below, while its the caller's
3879 * responsibility to ensure the request will fit into a
3880 * single device request, we might have changed the delete
3881 * method due to the device incorrectly advertising either
3882 * its supported methods or limits.
3884 * To prevent this causing further issues we validate the
3885 * against the methods limits, and warn which would
3886 * otherwise be unnecessary.
3889 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3891 struct da_softc *softc = (struct da_softc *)periph->softc;;
3893 uint8_t *buf = softc->unmap_buf;
3894 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3895 uint64_t lba, lastlba = (uint64_t)-1;
3896 uint64_t totalcount = 0;
3898 uint32_t c, lastcount = 0, ranges = 0;
3901 * Currently this doesn't take the UNMAP
3902 * Granularity and Granularity Alignment
3903 * fields into account.
3905 * This could result in both unoptimal unmap
3906 * requests as as well as UNMAP calls unmapping
3907 * fewer LBA's than requested.
3910 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3914 * Note: ada and da are different in how they store the
3915 * pending bp's in a trim. ada stores all of them in the
3916 * trim_req.bps. da stores all but the first one in the
3917 * delete_run_queue. ada then completes all the bps in
3918 * its adadone() loop. da completes all the bps in the
3919 * delete_run_queue in dadone, and relies on the biodone
3920 * after to complete. This should be reconciled since there's
3921 * no real reason to do it differently. XXX
3924 bioq_insert_tail(&softc->delete_run_queue, bp1);
3925 lba = bp1->bio_pblkno;
3926 count = bp1->bio_bcount / softc->params.secsize;
3928 /* Try to extend the previous range. */
3929 if (lba == lastlba) {
3930 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3933 scsi_ulto4b(lastcount, d[ranges - 1].length);
3937 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3938 softc->unmap_gran != 0) {
3939 /* Align length of the previous range. */
3940 if ((c = lastcount % softc->unmap_gran) != 0) {
3941 if (lastcount <= c) {
3942 totalcount -= lastcount;
3943 lastlba = (uint64_t)-1;
3950 scsi_ulto4b(lastcount,
3951 d[ranges - 1].length);
3954 /* Align beginning of the new range. */
3955 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3957 c = softc->unmap_gran - c;
3968 c = omin(count, UNMAP_RANGE_MAX);
3969 if (totalcount + c > softc->unmap_max_lba ||
3970 ranges >= softc->unmap_max_ranges) {
3971 xpt_print(periph->path,
3972 "%s issuing short delete %ld > %ld"
3974 da_delete_method_desc[softc->delete_method],
3975 totalcount + c, softc->unmap_max_lba,
3976 ranges, softc->unmap_max_ranges);
3979 scsi_u64to8b(lba, d[ranges].lba);
3980 scsi_ulto4b(c, d[ranges].length);
3988 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3991 if (ranges >= softc->unmap_max_ranges ||
3992 totalcount + bp1->bio_bcount /
3993 softc->params.secsize > softc->unmap_max_lba) {
3994 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3999 /* Align length of the last range. */
4000 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
4001 (c = lastcount % softc->unmap_gran) != 0) {
4005 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
4008 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
4009 scsi_ulto2b(ranges * 16, &buf[2]);
4011 scsi_unmap(&ccb->csio,
4012 /*retries*/da_retry_count,
4014 /*tag_action*/MSG_SIMPLE_Q_TAG,
4017 /*dxfer_len*/ ranges * 16 + 8,
4018 /*sense_len*/SSD_FULL_SIZE,
4019 da_default_timeout * 1000);
4020 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4021 ccb->ccb_h.flags |= CAM_UNLOCKED;
4022 softc->trim_count++;
4023 softc->trim_ranges += ranges;
4024 softc->trim_lbas += totalcount;
4025 cam_iosched_submit_trim(softc->cam_iosched);
4029 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4031 struct da_softc *softc = (struct da_softc *)periph->softc;
4033 uint8_t *buf = softc->unmap_buf;
4034 uint64_t lastlba = (uint64_t)-1;
4037 uint32_t lastcount = 0, c, requestcount;
4038 int ranges = 0, off, block_count;
4040 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
4043 if (bp1 != bp)//XXX imp XXX
4044 bioq_insert_tail(&softc->delete_run_queue, bp1);
4045 lba = bp1->bio_pblkno;
4046 count = bp1->bio_bcount / softc->params.secsize;
4047 requestcount = count;
4049 /* Try to extend the previous range. */
4050 if (lba == lastlba) {
4051 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
4053 off = (ranges - 1) * 8;
4054 buf[off + 6] = lastcount & 0xff;
4055 buf[off + 7] = (lastcount >> 8) & 0xff;
4061 c = omin(count, ATA_DSM_RANGE_MAX);
4064 buf[off + 0] = lba & 0xff;
4065 buf[off + 1] = (lba >> 8) & 0xff;
4066 buf[off + 2] = (lba >> 16) & 0xff;
4067 buf[off + 3] = (lba >> 24) & 0xff;
4068 buf[off + 4] = (lba >> 32) & 0xff;
4069 buf[off + 5] = (lba >> 40) & 0xff;
4070 buf[off + 6] = c & 0xff;
4071 buf[off + 7] = (c >> 8) & 0xff;
4076 if (count != 0 && ranges == softc->trim_max_ranges) {
4077 xpt_print(periph->path,
4078 "%s issuing short delete %ld > %ld\n",
4079 da_delete_method_desc[softc->delete_method],
4081 (softc->trim_max_ranges - ranges) *
4087 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4090 if (bp1->bio_bcount / softc->params.secsize >
4091 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
4092 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4097 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
4098 scsi_ata_trim(&ccb->csio,
4099 /*retries*/da_retry_count,
4101 /*tag_action*/MSG_SIMPLE_Q_TAG,
4104 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
4105 /*sense_len*/SSD_FULL_SIZE,
4106 da_default_timeout * 1000);
4107 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4108 ccb->ccb_h.flags |= CAM_UNLOCKED;
4109 cam_iosched_submit_trim(softc->cam_iosched);
4113 * We calculate ws_max_blks here based off d_delmaxsize instead
4114 * of using softc->ws_max_blks as it is absolute max for the
4115 * device not the protocol max which may well be lower.
4118 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4120 struct da_softc *softc;
4122 uint64_t ws_max_blks;
4124 uint64_t count; /* forward compat with WS32 */
4126 softc = (struct da_softc *)periph->softc;
4127 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
4128 lba = bp->bio_pblkno;
4132 if (bp1 != bp)//XXX imp XXX
4133 bioq_insert_tail(&softc->delete_run_queue, bp1);
4134 count += bp1->bio_bcount / softc->params.secsize;
4135 if (count > ws_max_blks) {
4136 xpt_print(periph->path,
4137 "%s issuing short delete %ld > %ld\n",
4138 da_delete_method_desc[softc->delete_method],
4139 count, ws_max_blks);
4140 count = omin(count, ws_max_blks);
4143 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4146 if (lba + count != bp1->bio_pblkno ||
4147 count + bp1->bio_bcount /
4148 softc->params.secsize > ws_max_blks) {
4149 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4154 scsi_write_same(&ccb->csio,
4155 /*retries*/da_retry_count,
4157 /*tag_action*/MSG_SIMPLE_Q_TAG,
4158 /*byte2*/softc->delete_method ==
4159 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
4160 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
4162 /*block_count*/count,
4163 /*data_ptr*/ __DECONST(void *, zero_region),
4164 /*dxfer_len*/ softc->params.secsize,
4165 /*sense_len*/SSD_FULL_SIZE,
4166 da_default_timeout * 1000);
4167 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4168 ccb->ccb_h.flags |= CAM_UNLOCKED;
4169 cam_iosched_submit_trim(softc->cam_iosched);
4173 cmd6workaround(union ccb *ccb)
4175 struct scsi_rw_6 cmd6;
4176 struct scsi_rw_10 *cmd10;
4177 struct da_softc *softc;
4182 cdb = ccb->csio.cdb_io.cdb_bytes;
4183 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
4185 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
4186 da_delete_methods old_method = softc->delete_method;
4189 * Typically there are two reasons for failure here
4190 * 1. Delete method was detected as supported but isn't
4191 * 2. Delete failed due to invalid params e.g. too big
4193 * While we will attempt to choose an alternative delete method
4194 * this may result in short deletes if the existing delete
4195 * requests from geom are big for the new method chosen.
4197 * This method assumes that the error which triggered this
4198 * will not retry the io otherwise a panic will occur
4200 dadeleteflag(softc, old_method, 0);
4201 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
4202 if (softc->delete_method == DA_DELETE_DISABLE)
4203 xpt_print(ccb->ccb_h.path,
4204 "%s failed, disabling BIO_DELETE\n",
4205 da_delete_method_desc[old_method]);
4207 xpt_print(ccb->ccb_h.path,
4208 "%s failed, switching to %s BIO_DELETE\n",
4209 da_delete_method_desc[old_method],
4210 da_delete_method_desc[softc->delete_method]);
4212 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
4213 cam_iosched_queue_work(softc->cam_iosched, bp);
4214 cam_iosched_queue_work(softc->cam_iosched,
4215 (struct bio *)ccb->ccb_h.ccb_bp);
4216 ccb->ccb_h.ccb_bp = NULL;
4220 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
4221 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4222 (*cdb == PREVENT_ALLOW) &&
4223 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
4225 xpt_print(ccb->ccb_h.path,
4226 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
4227 softc->quirks |= DA_Q_NO_PREVENT;
4231 /* Detect unsupported SYNCHRONIZE CACHE(10). */
4232 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4233 (*cdb == SYNCHRONIZE_CACHE) &&
4234 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
4236 xpt_print(ccb->ccb_h.path,
4237 "SYNCHRONIZE CACHE(10) not supported.\n");
4238 softc->quirks |= DA_Q_NO_SYNC_CACHE;
4239 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
4243 /* Translation only possible if CDB is an array and cmd is R/W6 */
4244 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
4245 (*cdb != READ_6 && *cdb != WRITE_6))
4248 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
4249 "increasing minimum_cmd_size to 10.\n");
4250 softc->minimum_cmd_size = 10;
4252 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
4253 cmd10 = (struct scsi_rw_10 *)cdb;
4254 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
4256 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
4257 cmd10->reserved = 0;
4258 scsi_ulto2b(cmd6.length, cmd10->length);
4259 cmd10->control = cmd6.control;
4260 ccb->csio.cdb_len = sizeof(*cmd10);
4262 /* Requeue request, unfreezing queue if necessary */
4263 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
4264 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4267 cam_release_devq(ccb->ccb_h.path,
4271 /*getcount_only*/0);
4277 dazonedone(struct cam_periph *periph, union ccb *ccb)
4279 struct da_softc *softc;
4282 softc = periph->softc;
4283 bp = (struct bio *)ccb->ccb_h.ccb_bp;
4285 switch (bp->bio_zone.zone_cmd) {
4286 case DISK_ZONE_OPEN:
4287 case DISK_ZONE_CLOSE:
4288 case DISK_ZONE_FINISH:
4291 case DISK_ZONE_REPORT_ZONES: {
4293 struct disk_zone_report *rep;
4294 struct scsi_report_zones_hdr *hdr;
4295 struct scsi_report_zones_desc *desc;
4296 struct disk_zone_rep_entry *entry;
4297 uint32_t hdr_len, num_avail;
4298 uint32_t num_to_fill, i;
4301 rep = &bp->bio_zone.zone_params.report;
4302 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
4304 * Note that bio_resid isn't normally used for zone
4305 * commands, but it is used by devstat_end_transaction_bio()
4306 * to determine how much data was transferred. Because
4307 * the size of the SCSI/ATA data structures is different
4308 * than the size of the BIO interface structures, the
4309 * amount of data actually transferred from the drive will
4310 * be different than the amount of data transferred to
4313 bp->bio_resid = ccb->csio.resid;
4314 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
4315 if (avail_len < sizeof(*hdr)) {
4317 * Is there a better error than EIO here? We asked
4318 * for at least the header, and we got less than
4321 bp->bio_error = EIO;
4322 bp->bio_flags |= BIO_ERROR;
4323 bp->bio_resid = bp->bio_bcount;
4327 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4332 hdr_len = ata ? le32dec(hdr->length) :
4333 scsi_4btoul(hdr->length);
4335 rep->entries_available = hdr_len / sizeof(*desc);
4337 rep->entries_available = 0;
4339 * NOTE: using the same values for the BIO version of the
4340 * same field as the SCSI/ATA values. This means we could
4341 * get some additional values that aren't defined in bio.h
4342 * if more values of the same field are defined later.
4344 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4345 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4346 scsi_8btou64(hdr->maximum_lba);
4348 * If the drive reports no entries that match the query,
4352 rep->entries_filled = 0;
4356 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4357 hdr_len / sizeof(*desc));
4359 * If the drive didn't return any data, then we're done.
4361 if (num_avail == 0) {
4362 rep->entries_filled = 0;
4366 num_to_fill = min(num_avail, rep->entries_allocated);
4368 * If the user didn't allocate any entries for us to fill,
4371 if (num_to_fill == 0) {
4372 rep->entries_filled = 0;
4376 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4377 i < num_to_fill; i++, desc++, entry++) {
4379 * NOTE: we're mapping the values here directly
4380 * from the SCSI/ATA bit definitions to the bio.h
4381 * definitons. There is also a warning in
4382 * disk_zone.h, but the impact is that if
4383 * additional values are added in the SCSI/ATA
4384 * specs these will be visible to consumers of
4387 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4388 entry->zone_condition =
4389 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4390 SRZ_ZONE_COND_SHIFT;
4391 entry->zone_flags |= desc->zone_flags &
4392 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4393 entry->zone_length =
4394 ata ? le64dec(desc->zone_length) :
4395 scsi_8btou64(desc->zone_length);
4396 entry->zone_start_lba =
4397 ata ? le64dec(desc->zone_start_lba) :
4398 scsi_8btou64(desc->zone_start_lba);
4399 entry->write_pointer_lba =
4400 ata ? le64dec(desc->write_pointer_lba) :
4401 scsi_8btou64(desc->write_pointer_lba);
4403 rep->entries_filled = num_to_fill;
4406 case DISK_ZONE_GET_PARAMS:
4409 * In theory we should not get a GET_PARAMS bio, since it
4410 * should be handled without queueing the command to the
4413 panic("%s: Invalid zone command %d", __func__,
4414 bp->bio_zone.zone_cmd);
4418 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4419 free(ccb->csio.data_ptr, M_SCSIDA);
4423 dadone(struct cam_periph *periph, union ccb *done_ccb)
4425 struct bio *bp, *bp1;
4426 struct da_softc *softc;
4427 struct ccb_scsiio *csio;
4431 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4433 softc = (struct da_softc *)periph->softc;
4434 priority = done_ccb->ccb_h.pinfo.priority;
4435 csio = &done_ccb->csio;
4437 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4438 if (csio->bio != NULL)
4439 biotrack(csio->bio, __func__);
4441 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4443 cam_periph_lock(periph);
4444 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4445 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4449 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4454 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4455 if (error == ERESTART) {
4456 /* A retry was scheduled, so just return. */
4457 cam_periph_unlock(periph);
4460 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4465 * return all queued I/O with EIO, so that
4466 * the client can retry these I/Os in the
4467 * proper order should it attempt to recover.
4472 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4474 * Catastrophic error. Mark our pack as
4477 * XXX See if this is really a media
4480 xpt_print(periph->path, "Invalidating pack\n");
4481 softc->flags |= DA_FLAG_PACK_INVALID;
4483 softc->invalidations++;
4485 queued_error = ENXIO;
4487 cam_iosched_flush(softc->cam_iosched, NULL,
4490 bp->bio_error = error;
4491 bp->bio_resid = bp->bio_bcount;
4492 bp->bio_flags |= BIO_ERROR;
4494 } else if (bp != NULL) {
4495 if (state == DA_CCB_DELETE)
4498 bp->bio_resid = csio->resid;
4500 if (bp->bio_resid != 0)
4501 bp->bio_flags |= BIO_ERROR;
4503 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4504 cam_release_devq(done_ccb->ccb_h.path,
4508 /*getcount_only*/0);
4509 } else if (bp != NULL) {
4510 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4511 panic("REQ_CMP with QFRZN");
4512 if (bp->bio_cmd == BIO_ZONE)
4513 dazonedone(periph, done_ccb);
4514 else if (state == DA_CCB_DELETE)
4517 bp->bio_resid = csio->resid;
4518 if ((csio->resid > 0) && (bp->bio_cmd != BIO_ZONE))
4519 bp->bio_flags |= BIO_ERROR;
4520 if (softc->error_inject != 0) {
4521 bp->bio_error = softc->error_inject;
4522 bp->bio_resid = bp->bio_bcount;
4523 bp->bio_flags |= BIO_ERROR;
4524 softc->error_inject = 0;
4529 biotrack(bp, __func__);
4530 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4531 if (LIST_EMPTY(&softc->pending_ccbs))
4532 softc->flags |= DA_FLAG_WAS_OTAG;
4535 * We need to call cam_iosched before we call biodone so that we don't
4536 * measure any activity that happens in the completion routine, which in
4537 * the case of sendfile can be quite extensive. Release the periph
4538 * refcount taken in dastart() for each CCB.
4540 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4541 xpt_release_ccb(done_ccb);
4542 KASSERT(softc->refcount >= 1, ("dadone softc %p refcount %d", softc, softc->refcount));
4544 if (state == DA_CCB_DELETE) {
4545 TAILQ_HEAD(, bio) queue;
4548 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4549 softc->delete_run_queue.insert_point = NULL;
4551 * Normally, the xpt_release_ccb() above would make sure
4552 * that when we have more work to do, that work would
4553 * get kicked off. However, we specifically keep
4554 * delete_running set to 0 before the call above to
4555 * allow other I/O to progress when many BIO_DELETE
4556 * requests are pushed down. We set delete_running to 0
4557 * and call daschedule again so that we don't stall if
4558 * there are no other I/Os pending apart from BIO_DELETEs.
4560 cam_iosched_trim_done(softc->cam_iosched);
4562 cam_periph_unlock(periph);
4563 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4564 TAILQ_REMOVE(&queue, bp1, bio_queue);
4565 bp1->bio_error = bp->bio_error;
4566 if (bp->bio_flags & BIO_ERROR) {
4567 bp1->bio_flags |= BIO_ERROR;
4568 bp1->bio_resid = bp1->bio_bcount;
4575 cam_periph_unlock(periph);
4583 dadone_probewp(struct cam_periph *periph, union ccb *done_ccb)
4585 struct scsi_mode_header_6 *mode_hdr6;
4586 struct scsi_mode_header_10 *mode_hdr10;
4587 struct da_softc *softc;
4588 struct ccb_scsiio *csio;
4592 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probewp\n"));
4594 softc = (struct da_softc *)periph->softc;
4595 priority = done_ccb->ccb_h.pinfo.priority;
4596 csio = &done_ccb->csio;
4598 cam_periph_assert(periph, MA_OWNED);
4600 if (softc->minimum_cmd_size > 6) {
4601 mode_hdr10 = (struct scsi_mode_header_10 *)csio->data_ptr;
4602 dev_spec = mode_hdr10->dev_spec;
4604 mode_hdr6 = (struct scsi_mode_header_6 *)csio->data_ptr;
4605 dev_spec = mode_hdr6->dev_spec;
4607 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
4608 if ((dev_spec & 0x80) != 0)
4609 softc->disk->d_flags |= DISKFLAG_WRITE_PROTECT;
4611 softc->disk->d_flags &= ~DISKFLAG_WRITE_PROTECT;
4615 error = daerror(done_ccb, CAM_RETRY_SELTO,
4616 SF_RETRY_UA|SF_NO_PRINT);
4617 if (error == ERESTART)
4619 else if (error != 0) {
4620 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4621 /* Don't wedge this device's queue */
4622 cam_release_devq(done_ccb->ccb_h.path,
4626 /*getcount_only*/0);
4631 free(csio->data_ptr, M_SCSIDA);
4632 xpt_release_ccb(done_ccb);
4633 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
4634 softc->state = DA_STATE_PROBE_RC16;
4636 softc->state = DA_STATE_PROBE_RC;
4637 xpt_schedule(periph, priority);
4642 dadone_proberc(struct cam_periph *periph, union ccb *done_ccb)
4644 struct scsi_read_capacity_data *rdcap;
4645 struct scsi_read_capacity_data_long *rcaplong;
4646 struct da_softc *softc;
4647 struct ccb_scsiio *csio;
4653 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_proberc\n"));
4655 softc = (struct da_softc *)periph->softc;
4656 priority = done_ccb->ccb_h.pinfo.priority;
4657 csio = &done_ccb->csio;
4658 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4663 /* XXX TODO: can this be a malloc? */
4664 announce_buf = softc->announce_temp;
4665 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4667 if (state == DA_CCB_PROBE_RC)
4668 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4670 rcaplong = (struct scsi_read_capacity_data_long *)
4673 cam_periph_assert(periph, MA_OWNED);
4675 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4676 struct disk_params *dp;
4677 uint32_t block_size;
4679 u_int lalba; /* Lowest aligned LBA. */
4681 if (state == DA_CCB_PROBE_RC) {
4682 block_size = scsi_4btoul(rdcap->length);
4683 maxsector = scsi_4btoul(rdcap->addr);
4687 * According to SBC-2, if the standard 10
4688 * byte READ CAPACITY command returns 2^32,
4689 * we should issue the 16 byte version of
4690 * the command, since the device in question
4691 * has more sectors than can be represented
4692 * with the short version of the command.
4694 if (maxsector == 0xffffffff) {
4695 free(rdcap, M_SCSIDA);
4696 xpt_release_ccb(done_ccb);
4697 softc->state = DA_STATE_PROBE_RC16;
4698 xpt_schedule(periph, priority);
4702 block_size = scsi_4btoul(rcaplong->length);
4703 maxsector = scsi_8btou64(rcaplong->addr);
4704 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4708 * Because GEOM code just will panic us if we
4709 * give them an 'illegal' value we'll avoid that
4712 if (block_size == 0) {
4717 if (block_size >= MAXPHYS) {
4718 xpt_print(periph->path,
4719 "unsupportable block size %ju\n",
4720 (uintmax_t) block_size);
4721 announce_buf = NULL;
4722 cam_periph_invalidate(periph);
4725 * We pass rcaplong into dasetgeom(),
4726 * because it will only use it if it is
4729 dasetgeom(periph, block_size, maxsector,
4730 rcaplong, sizeof(*rcaplong));
4731 lbp = (lalba & SRC16_LBPME_A);
4732 dp = &softc->params;
4733 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4734 "%juMB (%ju %u byte sectors)",
4735 ((uintmax_t)dp->secsize * dp->sectors) /
4737 (uintmax_t)dp->sectors, dp->secsize);
4743 * Retry any UNIT ATTENTION type errors. They
4744 * are expected at boot.
4746 error = daerror(done_ccb, CAM_RETRY_SELTO,
4747 SF_RETRY_UA|SF_NO_PRINT);
4748 if (error == ERESTART) {
4750 * A retry was scheuled, so
4754 } else if (error != 0) {
4756 int sense_key, error_code;
4759 struct ccb_getdev cgd;
4761 /* Don't wedge this device's queue */
4762 status = done_ccb->ccb_h.status;
4763 if ((status & CAM_DEV_QFRZN) != 0)
4764 cam_release_devq(done_ccb->ccb_h.path,
4768 /*getcount_only*/0);
4771 xpt_setup_ccb(&cgd.ccb_h, done_ccb->ccb_h.path,
4772 CAM_PRIORITY_NORMAL);
4773 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4774 xpt_action((union ccb *)&cgd);
4776 if (scsi_extract_sense_ccb(done_ccb,
4777 &error_code, &sense_key, &asc, &ascq))
4783 * If we tried READ CAPACITY(16) and failed,
4784 * fallback to READ CAPACITY(10).
4786 if ((state == DA_CCB_PROBE_RC16) &&
4787 (softc->flags & DA_FLAG_CAN_RC16) &&
4788 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4791 (error_code == SSD_CURRENT_ERROR ||
4792 error_code == SSD_DESC_CURRENT_ERROR) &&
4793 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4794 cam_periph_assert(periph, MA_OWNED);
4795 softc->flags &= ~DA_FLAG_CAN_RC16;
4796 free(rdcap, M_SCSIDA);
4797 xpt_release_ccb(done_ccb);
4798 softc->state = DA_STATE_PROBE_RC;
4799 xpt_schedule(periph, priority);
4804 * Attach to anything that claims to be a
4805 * direct access or optical disk device,
4806 * as long as it doesn't return a "Logical
4807 * unit not supported" (0x25) error.
4808 * "Internal Target Failure" (0x44) is also
4809 * special and typically means that the
4810 * device is a SATA drive behind a SATL
4811 * translation that's fallen into a
4812 * terminally fatal state.
4815 && (asc != 0x25) && (asc != 0x44)
4816 && (error_code == SSD_CURRENT_ERROR
4817 || error_code == SSD_DESC_CURRENT_ERROR)) {
4818 const char *sense_key_desc;
4819 const char *asc_desc;
4821 dasetgeom(periph, 512, -1, NULL, 0);
4822 scsi_sense_desc(sense_key, asc, ascq,
4823 &cgd.inq_data, &sense_key_desc,
4825 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4826 "Attempt to query device "
4827 "size failed: %s, %s",
4828 sense_key_desc, asc_desc);
4831 scsi_sense_print(&done_ccb->csio);
4833 xpt_print(periph->path,
4834 "got CAM status %#x\n",
4835 done_ccb->ccb_h.status);
4838 xpt_print(periph->path, "fatal error, "
4839 "failed to attach to device\n");
4841 announce_buf = NULL;
4844 * Free up resources.
4846 cam_periph_invalidate(periph);
4850 free(csio->data_ptr, M_SCSIDA);
4851 if (announce_buf != NULL &&
4852 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4855 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4857 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4858 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4864 * Create our sysctl variables, now that we know
4865 * we have successfully attached.
4867 /* increase the refcount */
4868 if (da_periph_acquire(periph, DA_REF_SYSCTL) == 0) {
4869 taskqueue_enqueue(taskqueue_thread,
4870 &softc->sysctl_task);
4872 /* XXX This message is useless! */
4873 xpt_print(periph->path, "fatal error, "
4874 "could not acquire reference count\n");
4878 /* We already probed the device. */
4879 if (softc->flags & DA_FLAG_PROBED) {
4880 daprobedone(periph, done_ccb);
4884 /* Ensure re-probe doesn't see old delete. */
4885 softc->delete_available = 0;
4886 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4887 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4889 * Based on older SBC-3 spec revisions
4890 * any of the UNMAP methods "may" be
4891 * available via LBP given this flag so
4892 * we flag all of them as available and
4893 * then remove those which further
4894 * probes confirm aren't available
4897 * We could also check readcap(16) p_type
4898 * flag to exclude one or more invalid
4899 * write same (X) types here
4901 dadeleteflag(softc, DA_DELETE_WS16, 1);
4902 dadeleteflag(softc, DA_DELETE_WS10, 1);
4903 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4905 xpt_release_ccb(done_ccb);
4906 softc->state = DA_STATE_PROBE_LBP;
4907 xpt_schedule(periph, priority);
4911 xpt_release_ccb(done_ccb);
4912 softc->state = DA_STATE_PROBE_BDC;
4913 xpt_schedule(periph, priority);
4918 dadone_probelbp(struct cam_periph *periph, union ccb *done_ccb)
4920 struct scsi_vpd_logical_block_prov *lbp;
4921 struct da_softc *softc;
4922 struct ccb_scsiio *csio;
4925 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probelbp\n"));
4927 softc = (struct da_softc *)periph->softc;
4928 priority = done_ccb->ccb_h.pinfo.priority;
4929 csio = &done_ccb->csio;
4930 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4932 cam_periph_assert(periph, MA_OWNED);
4934 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4936 * T10/1799-D Revision 31 states at least one of these
4937 * must be supported but we don't currently enforce this.
4939 dadeleteflag(softc, DA_DELETE_WS16,
4940 (lbp->flags & SVPD_LBP_WS16));
4941 dadeleteflag(softc, DA_DELETE_WS10,
4942 (lbp->flags & SVPD_LBP_WS10));
4943 dadeleteflag(softc, DA_DELETE_UNMAP,
4944 (lbp->flags & SVPD_LBP_UNMAP));
4947 error = daerror(done_ccb, CAM_RETRY_SELTO,
4948 SF_RETRY_UA|SF_NO_PRINT);
4949 if (error == ERESTART)
4951 else if (error != 0) {
4952 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4953 /* Don't wedge this device's queue */
4954 cam_release_devq(done_ccb->ccb_h.path,
4958 /*getcount_only*/0);
4962 * Failure indicates we don't support any SBC-3
4963 * delete methods with UNMAP
4968 free(lbp, M_SCSIDA);
4969 xpt_release_ccb(done_ccb);
4970 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4971 xpt_schedule(periph, priority);
4976 dadone_probeblklimits(struct cam_periph *periph, union ccb *done_ccb)
4978 struct scsi_vpd_block_limits *block_limits;
4979 struct da_softc *softc;
4980 struct ccb_scsiio *csio;
4983 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeblklimits\n"));
4985 softc = (struct da_softc *)periph->softc;
4986 priority = done_ccb->ccb_h.pinfo.priority;
4987 csio = &done_ccb->csio;
4988 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4990 cam_periph_assert(periph, MA_OWNED);
4992 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4993 uint32_t max_txfer_len = scsi_4btoul(
4994 block_limits->max_txfer_len);
4995 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4996 block_limits->max_unmap_lba_cnt);
4997 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4998 block_limits->max_unmap_blk_cnt);
4999 uint32_t unmap_gran = scsi_4btoul(
5000 block_limits->opt_unmap_grain);
5001 uint32_t unmap_gran_align = scsi_4btoul(
5002 block_limits->unmap_grain_align);
5003 uint64_t ws_max_blks = scsi_8btou64(
5004 block_limits->max_write_same_length);
5006 if (max_txfer_len != 0) {
5007 softc->disk->d_maxsize = MIN(softc->maxio,
5008 (off_t)max_txfer_len * softc->params.secsize);
5012 * We should already support UNMAP but we check lba
5013 * and block count to be sure
5015 if (max_unmap_lba_cnt != 0x00L &&
5016 max_unmap_blk_cnt != 0x00L) {
5017 softc->unmap_max_lba = max_unmap_lba_cnt;
5018 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
5020 if (unmap_gran > 1) {
5021 softc->unmap_gran = unmap_gran;
5022 if (unmap_gran_align & 0x80000000) {
5023 softc->unmap_gran_align =
5024 unmap_gran_align & 0x7fffffff;
5029 * Unexpected UNMAP limits which means the
5030 * device doesn't actually support UNMAP
5032 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
5035 if (ws_max_blks != 0x00L)
5036 softc->ws_max_blks = ws_max_blks;
5039 error = daerror(done_ccb, CAM_RETRY_SELTO,
5040 SF_RETRY_UA|SF_NO_PRINT);
5041 if (error == ERESTART)
5043 else if (error != 0) {
5044 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5045 /* Don't wedge this device's queue */
5046 cam_release_devq(done_ccb->ccb_h.path,
5050 /*getcount_only*/0);
5054 * Failure here doesn't mean UNMAP is not
5055 * supported as this is an optional page.
5057 softc->unmap_max_lba = 1;
5058 softc->unmap_max_ranges = 1;
5062 free(block_limits, M_SCSIDA);
5063 xpt_release_ccb(done_ccb);
5064 softc->state = DA_STATE_PROBE_BDC;
5065 xpt_schedule(periph, priority);
5070 dadone_probebdc(struct cam_periph *periph, union ccb *done_ccb)
5072 struct scsi_vpd_block_device_characteristics *bdc;
5073 struct da_softc *softc;
5074 struct ccb_scsiio *csio;
5077 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probebdc\n"));
5079 softc = (struct da_softc *)periph->softc;
5080 priority = done_ccb->ccb_h.pinfo.priority;
5081 csio = &done_ccb->csio;
5082 bdc = (struct scsi_vpd_block_device_characteristics *)csio->data_ptr;
5084 cam_periph_assert(periph, MA_OWNED);
5086 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5090 * Disable queue sorting for non-rotational media
5093 u_int16_t old_rate = softc->disk->d_rotation_rate;
5095 valid_len = csio->dxfer_len - csio->resid;
5096 if (SBDC_IS_PRESENT(bdc, valid_len,
5097 medium_rotation_rate)) {
5098 softc->disk->d_rotation_rate =
5099 scsi_2btoul(bdc->medium_rotation_rate);
5100 if (softc->disk->d_rotation_rate ==
5101 SVPD_BDC_RATE_NON_ROTATING) {
5102 cam_iosched_set_sort_queue(
5103 softc->cam_iosched, 0);
5104 softc->rotating = 0;
5106 if (softc->disk->d_rotation_rate != old_rate) {
5107 disk_attr_changed(softc->disk,
5108 "GEOM::rotation_rate", M_NOWAIT);
5111 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
5112 && (softc->zone_mode == DA_ZONE_NONE)) {
5115 if (scsi_vpd_supported_page(periph,
5116 SVPD_ATA_INFORMATION))
5122 * The Zoned field will only be set for
5123 * Drive Managed and Host Aware drives. If
5124 * they are Host Managed, the device type
5125 * in the standard INQUIRY data should be
5126 * set to T_ZBC_HM (0x14).
5128 if ((bdc->flags & SVPD_ZBC_MASK) ==
5130 softc->zone_mode = DA_ZONE_HOST_AWARE;
5131 softc->zone_interface = (ata_proto) ?
5132 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5133 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
5135 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5136 softc->zone_interface = (ata_proto) ?
5137 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5138 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
5140 xpt_print(periph->path, "Unknown zoned "
5142 bdc->flags & SVPD_ZBC_MASK);
5147 error = daerror(done_ccb, CAM_RETRY_SELTO,
5148 SF_RETRY_UA|SF_NO_PRINT);
5149 if (error == ERESTART)
5151 else if (error != 0) {
5152 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5153 /* Don't wedge this device's queue */
5154 cam_release_devq(done_ccb->ccb_h.path,
5158 /*getcount_only*/0);
5163 free(bdc, M_SCSIDA);
5164 xpt_release_ccb(done_ccb);
5165 softc->state = DA_STATE_PROBE_ATA;
5166 xpt_schedule(periph, priority);
5171 dadone_probeata(struct cam_periph *periph, union ccb *done_ccb)
5173 struct ata_params *ata_params;
5174 struct ccb_scsiio *csio;
5175 struct da_softc *softc;
5181 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeata\n"));
5183 softc = (struct da_softc *)periph->softc;
5184 priority = done_ccb->ccb_h.pinfo.priority;
5185 csio = &done_ccb->csio;
5186 ata_params = (struct ata_params *)csio->data_ptr;
5187 ptr = (uint16_t *)ata_params;
5191 cam_periph_assert(periph, MA_OWNED);
5193 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5196 for (i = 0; i < sizeof(*ata_params) / 2; i++)
5197 ptr[i] = le16toh(ptr[i]);
5198 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
5199 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
5200 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
5201 if (ata_params->max_dsm_blocks != 0)
5202 softc->trim_max_ranges = min(
5203 softc->trim_max_ranges,
5204 ata_params->max_dsm_blocks *
5205 ATA_DSM_BLK_RANGES);
5208 * Disable queue sorting for non-rotational media
5211 old_rate = softc->disk->d_rotation_rate;
5212 softc->disk->d_rotation_rate = ata_params->media_rotation_rate;
5213 if (softc->disk->d_rotation_rate == ATA_RATE_NON_ROTATING) {
5214 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
5215 softc->rotating = 0;
5217 if (softc->disk->d_rotation_rate != old_rate) {
5218 disk_attr_changed(softc->disk,
5219 "GEOM::rotation_rate", M_NOWAIT);
5222 cam_periph_assert(periph, MA_OWNED);
5223 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
5224 softc->flags |= DA_FLAG_CAN_ATA_DMA;
5226 if (ata_params->support.extension & ATA_SUPPORT_GENLOG)
5227 softc->flags |= DA_FLAG_CAN_ATA_LOG;
5230 * At this point, if we have a SATA host aware drive,
5231 * we communicate via ATA passthrough unless the
5232 * SAT layer supports ZBC -> ZAC translation. In
5235 * XXX KDM figure out how to detect a host managed
5238 if (softc->zone_mode == DA_ZONE_NONE) {
5240 * Note that we don't override the zone
5241 * mode or interface if it has already been
5242 * set. This is because it has either been
5243 * set as a quirk, or when we probed the
5244 * SCSI Block Device Characteristics page,
5245 * the zoned field was set. The latter
5246 * means that the SAT layer supports ZBC to
5247 * ZAC translation, and we would prefer to
5248 * use that if it is available.
5250 if ((ata_params->support3 &
5251 ATA_SUPPORT_ZONE_MASK) ==
5252 ATA_SUPPORT_ZONE_HOST_AWARE) {
5253 softc->zone_mode = DA_ZONE_HOST_AWARE;
5254 softc->zone_interface =
5255 DA_ZONE_IF_ATA_PASS;
5256 } else if ((ata_params->support3 &
5257 ATA_SUPPORT_ZONE_MASK) ==
5258 ATA_SUPPORT_ZONE_DEV_MANAGED) {
5259 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5260 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
5265 error = daerror(done_ccb, CAM_RETRY_SELTO,
5266 SF_RETRY_UA|SF_NO_PRINT);
5267 if (error == ERESTART)
5269 else if (error != 0) {
5270 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5271 /* Don't wedge this device's queue */
5272 cam_release_devq(done_ccb->ccb_h.path,
5276 /*getcount_only*/0);
5281 free(ata_params, M_SCSIDA);
5282 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
5283 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
5285 * If the ATA IDENTIFY failed, we could be talking
5286 * to a SCSI drive, although that seems unlikely,
5287 * since the drive did report that it supported the
5288 * ATA Information VPD page. If the ATA IDENTIFY
5289 * succeeded, and the SAT layer doesn't support
5290 * ZBC -> ZAC translation, continue on to get the
5291 * directory of ATA logs, and complete the rest of
5292 * the ZAC probe. If the SAT layer does support
5293 * ZBC -> ZAC translation, we want to use that,
5294 * and we'll probe the SCSI Zoned Block Device
5295 * Characteristics VPD page next.
5298 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
5299 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
5300 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
5302 softc->state = DA_STATE_PROBE_ZONE;
5305 if (continue_probe != 0) {
5306 xpt_release_ccb(done_ccb);
5307 xpt_schedule(periph, priority);
5310 daprobedone(periph, done_ccb);
5315 dadone_probeatalogdir(struct cam_periph *periph, union ccb *done_ccb)
5317 struct da_softc *softc;
5318 struct ccb_scsiio *csio;
5322 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatalogdir\n"));
5324 softc = (struct da_softc *)periph->softc;
5325 priority = done_ccb->ccb_h.pinfo.priority;
5326 csio = &done_ccb->csio;
5328 cam_periph_assert(periph, MA_OWNED);
5329 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5331 softc->valid_logdir_len = 0;
5332 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
5333 softc->valid_logdir_len = csio->dxfer_len - csio->resid;
5334 if (softc->valid_logdir_len > 0)
5335 bcopy(csio->data_ptr, &softc->ata_logdir,
5336 min(softc->valid_logdir_len,
5337 sizeof(softc->ata_logdir)));
5339 * Figure out whether the Identify Device log is
5340 * supported. The General Purpose log directory
5341 * has a header, and lists the number of pages
5342 * available for each GP log identified by the
5343 * offset into the list.
5345 if ((softc->valid_logdir_len >=
5346 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
5347 && (le16dec(softc->ata_logdir.header) ==
5348 ATA_GP_LOG_DIR_VERSION)
5349 && (le16dec(&softc->ata_logdir.num_pages[
5350 (ATA_IDENTIFY_DATA_LOG *
5351 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
5352 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
5354 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5357 error = daerror(done_ccb, CAM_RETRY_SELTO,
5358 SF_RETRY_UA|SF_NO_PRINT);
5359 if (error == ERESTART)
5361 else if (error != 0) {
5363 * If we can't get the ATA log directory,
5364 * then ATA logs are effectively not
5365 * supported even if the bit is set in the
5368 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
5369 DA_FLAG_CAN_ATA_IDLOG);
5370 if ((done_ccb->ccb_h.status &
5371 CAM_DEV_QFRZN) != 0) {
5372 /* Don't wedge this device's queue */
5373 cam_release_devq(done_ccb->ccb_h.path,
5377 /*getcount_only*/0);
5382 free(csio->data_ptr, M_SCSIDA);
5385 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
5386 softc->state = DA_STATE_PROBE_ATA_IDDIR;
5387 xpt_release_ccb(done_ccb);
5388 xpt_schedule(periph, priority);
5391 daprobedone(periph, done_ccb);
5396 dadone_probeataiddir(struct cam_periph *periph, union ccb *done_ccb)
5398 struct da_softc *softc;
5399 struct ccb_scsiio *csio;
5403 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeataiddir\n"));
5405 softc = (struct da_softc *)periph->softc;
5406 priority = done_ccb->ccb_h.pinfo.priority;
5407 csio = &done_ccb->csio;
5409 cam_periph_assert(periph, MA_OWNED);
5411 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5412 off_t entries_offset, max_entries;
5415 softc->valid_iddir_len = 0;
5416 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
5417 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
5418 DA_FLAG_CAN_ATA_ZONE);
5419 softc->valid_iddir_len = csio->dxfer_len - csio->resid;
5420 if (softc->valid_iddir_len > 0)
5421 bcopy(csio->data_ptr, &softc->ata_iddir,
5422 min(softc->valid_iddir_len,
5423 sizeof(softc->ata_iddir)));
5426 __offsetof(struct ata_identify_log_pages,entries);
5427 max_entries = softc->valid_iddir_len - entries_offset;
5428 if ((softc->valid_iddir_len > (entries_offset + 1))
5429 && (le64dec(softc->ata_iddir.header) == ATA_IDLOG_REVISION)
5430 && (softc->ata_iddir.entry_count > 0)) {
5433 num_entries = softc->ata_iddir.entry_count;
5434 num_entries = min(num_entries,
5435 softc->valid_iddir_len - entries_offset);
5436 for (i = 0; i < num_entries && i < max_entries; i++) {
5437 if (softc->ata_iddir.entries[i] ==
5439 softc->flags |= DA_FLAG_CAN_ATA_SUPCAP;
5440 else if (softc->ata_iddir.entries[i] ==
5442 softc->flags |= DA_FLAG_CAN_ATA_ZONE;
5444 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP)
5445 && (softc->flags & DA_FLAG_CAN_ATA_ZONE))
5450 error = daerror(done_ccb, CAM_RETRY_SELTO,
5451 SF_RETRY_UA|SF_NO_PRINT);
5452 if (error == ERESTART)
5454 else if (error != 0) {
5456 * If we can't get the ATA Identify Data log
5457 * directory, then it effectively isn't
5458 * supported even if the ATA Log directory
5459 * a non-zero number of pages present for
5462 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5463 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5464 /* Don't wedge this device's queue */
5465 cam_release_devq(done_ccb->ccb_h.path,
5469 /*getcount_only*/0);
5474 free(csio->data_ptr, M_SCSIDA);
5476 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5477 softc->state = DA_STATE_PROBE_ATA_SUP;
5478 xpt_release_ccb(done_ccb);
5479 xpt_schedule(periph, priority);
5482 daprobedone(periph, done_ccb);
5487 dadone_probeatasup(struct cam_periph *periph, union ccb *done_ccb)
5489 struct da_softc *softc;
5490 struct ccb_scsiio *csio;
5494 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatasup\n"));
5496 softc = (struct da_softc *)periph->softc;
5497 priority = done_ccb->ccb_h.pinfo.priority;
5498 csio = &done_ccb->csio;
5500 cam_periph_assert(periph, MA_OWNED);
5502 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5505 struct ata_identify_log_sup_cap *sup_cap;
5508 sup_cap = (struct ata_identify_log_sup_cap *)csio->data_ptr;
5509 valid_len = csio->dxfer_len - csio->resid;
5510 needed_size = __offsetof(struct ata_identify_log_sup_cap,
5511 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5512 if (valid_len >= needed_size) {
5513 uint64_t zoned, zac_cap;
5515 zoned = le64dec(sup_cap->zoned_cap);
5516 if (zoned & ATA_ZONED_VALID) {
5518 * This should have already been
5519 * set, because this is also in the
5520 * ATA identify data.
5522 if ((zoned & ATA_ZONED_MASK) ==
5523 ATA_SUPPORT_ZONE_HOST_AWARE)
5524 softc->zone_mode = DA_ZONE_HOST_AWARE;
5525 else if ((zoned & ATA_ZONED_MASK) ==
5526 ATA_SUPPORT_ZONE_DEV_MANAGED)
5528 DA_ZONE_DRIVE_MANAGED;
5531 zac_cap = le64dec(sup_cap->sup_zac_cap);
5532 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5533 if (zac_cap & ATA_REPORT_ZONES_SUP)
5534 softc->zone_flags |=
5535 DA_ZONE_FLAG_RZ_SUP;
5536 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5537 softc->zone_flags |=
5538 DA_ZONE_FLAG_OPEN_SUP;
5539 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5540 softc->zone_flags |=
5541 DA_ZONE_FLAG_CLOSE_SUP;
5542 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5543 softc->zone_flags |=
5544 DA_ZONE_FLAG_FINISH_SUP;
5545 if (zac_cap & ATA_ND_RWP_SUP)
5546 softc->zone_flags |=
5547 DA_ZONE_FLAG_RWP_SUP;
5550 * This field was introduced in
5551 * ACS-4, r08 on April 28th, 2015.
5552 * If the drive firmware was written
5553 * to an earlier spec, it won't have
5554 * the field. So, assume all
5555 * commands are supported.
5557 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5561 error = daerror(done_ccb, CAM_RETRY_SELTO,
5562 SF_RETRY_UA|SF_NO_PRINT);
5563 if (error == ERESTART)
5565 else if (error != 0) {
5567 * If we can't get the ATA Identify Data
5568 * Supported Capabilities page, clear the
5571 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5573 * And clear zone capabilities.
5575 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5576 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5577 /* Don't wedge this device's queue */
5578 cam_release_devq(done_ccb->ccb_h.path,
5582 /*getcount_only*/0);
5587 free(csio->data_ptr, M_SCSIDA);
5589 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5590 softc->state = DA_STATE_PROBE_ATA_ZONE;
5591 xpt_release_ccb(done_ccb);
5592 xpt_schedule(periph, priority);
5595 daprobedone(periph, done_ccb);
5600 dadone_probeatazone(struct cam_periph *periph, union ccb *done_ccb)
5602 struct da_softc *softc;
5603 struct ccb_scsiio *csio;
5606 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatazone\n"));
5608 softc = (struct da_softc *)periph->softc;
5609 csio = &done_ccb->csio;
5611 cam_periph_assert(periph, MA_OWNED);
5613 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5614 struct ata_zoned_info_log *zi_log;
5618 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5620 valid_len = csio->dxfer_len - csio->resid;
5621 needed_size = __offsetof(struct ata_zoned_info_log,
5622 version_info) + 1 + sizeof(zi_log->version_info);
5623 if (valid_len >= needed_size) {
5626 tmpvar = le64dec(zi_log->zoned_cap);
5627 if (tmpvar & ATA_ZDI_CAP_VALID) {
5628 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5629 softc->zone_flags |=
5630 DA_ZONE_FLAG_URSWRZ;
5632 softc->zone_flags &=
5633 ~DA_ZONE_FLAG_URSWRZ;
5635 tmpvar = le64dec(zi_log->optimal_seq_zones);
5636 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5637 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5638 softc->optimal_seq_zones = (tmpvar &
5639 ATA_ZDI_OPT_SEQ_MASK);
5641 softc->zone_flags &= ~DA_ZONE_FLAG_OPT_SEQ_SET;
5642 softc->optimal_seq_zones = 0;
5645 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5646 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5647 softc->zone_flags |=
5648 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5649 softc->optimal_nonseq_zones =
5650 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5652 softc->zone_flags &=
5653 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5654 softc->optimal_nonseq_zones = 0;
5657 tmpvar = le64dec(zi_log->max_seq_req_zones);
5658 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5659 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5660 softc->max_seq_zones =
5661 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5663 softc->zone_flags &= ~DA_ZONE_FLAG_MAX_SEQ_SET;
5664 softc->max_seq_zones = 0;
5668 error = daerror(done_ccb, CAM_RETRY_SELTO,
5669 SF_RETRY_UA|SF_NO_PRINT);
5670 if (error == ERESTART)
5672 else if (error != 0) {
5673 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5674 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5676 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5677 /* Don't wedge this device's queue */
5678 cam_release_devq(done_ccb->ccb_h.path,
5682 /*getcount_only*/0);
5688 free(csio->data_ptr, M_SCSIDA);
5690 daprobedone(periph, done_ccb);
5695 dadone_probezone(struct cam_periph *periph, union ccb *done_ccb)
5697 struct da_softc *softc;
5698 struct ccb_scsiio *csio;
5701 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probezone\n"));
5703 softc = (struct da_softc *)periph->softc;
5704 csio = &done_ccb->csio;
5706 cam_periph_assert(periph, MA_OWNED);
5708 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5711 struct scsi_vpd_zoned_bdc *zoned_bdc;
5714 zoned_bdc = (struct scsi_vpd_zoned_bdc *)csio->data_ptr;
5715 valid_len = csio->dxfer_len - csio->resid;
5716 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5717 max_seq_req_zones) + 1 +
5718 sizeof(zoned_bdc->max_seq_req_zones);
5719 if ((valid_len >= needed_len)
5720 && (scsi_2btoul(zoned_bdc->page_length) >= SVPD_ZBDC_PL)) {
5721 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5722 softc->zone_flags |= DA_ZONE_FLAG_URSWRZ;
5724 softc->zone_flags &= ~DA_ZONE_FLAG_URSWRZ;
5725 softc->optimal_seq_zones =
5726 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5727 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5728 softc->optimal_nonseq_zones = scsi_4btoul(
5729 zoned_bdc->optimal_nonseq_zones);
5730 softc->zone_flags |= DA_ZONE_FLAG_OPT_NONSEQ_SET;
5731 softc->max_seq_zones =
5732 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5733 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5736 * All of the zone commands are mandatory for SCSI
5739 * XXX KDM this is valid as of September 2015.
5740 * Re-check this assumption once the SAT spec is
5741 * updated to support SCSI ZBC to ATA ZAC mapping.
5742 * Since ATA allows zone commands to be reported
5743 * as supported or not, this may not necessarily
5744 * be true for an ATA device behind a SAT (SCSI to
5745 * ATA Translation) layer.
5747 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5749 error = daerror(done_ccb, CAM_RETRY_SELTO,
5750 SF_RETRY_UA|SF_NO_PRINT);
5751 if (error == ERESTART)
5753 else if (error != 0) {
5754 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5755 /* Don't wedge this device's queue */
5756 cam_release_devq(done_ccb->ccb_h.path,
5760 /*getcount_only*/0);
5765 free(csio->data_ptr, M_SCSIDA);
5767 daprobedone(periph, done_ccb);
5772 dadone_tur(struct cam_periph *periph, union ccb *done_ccb)
5774 struct da_softc *softc;
5775 struct ccb_scsiio *csio;
5777 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_tur\n"));
5779 softc = (struct da_softc *)periph->softc;
5780 csio = &done_ccb->csio;
5782 cam_periph_assert(periph, MA_OWNED);
5784 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5786 if (daerror(done_ccb, CAM_RETRY_SELTO,
5787 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) == ERESTART)
5788 return; /* Will complete again, keep reference */
5789 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5790 cam_release_devq(done_ccb->ccb_h.path,
5794 /*getcount_only*/0);
5796 xpt_release_ccb(done_ccb);
5797 softc->flags &= ~DA_FLAG_TUR_PENDING;
5798 da_periph_release_locked(periph, DA_REF_TUR);
5803 dareprobe(struct cam_periph *periph)
5805 struct da_softc *softc;
5808 softc = (struct da_softc *)periph->softc;
5810 /* Probe in progress; don't interfere. */
5811 if (softc->state != DA_STATE_NORMAL)
5814 status = da_periph_acquire(periph, DA_REF_REPROBE);
5815 KASSERT(status == 0, ("dareprobe: cam_periph_acquire failed"));
5817 softc->state = DA_STATE_PROBE_WP;
5818 xpt_schedule(periph, CAM_PRIORITY_DEV);
5822 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5824 struct da_softc *softc;
5825 struct cam_periph *periph;
5826 int error, error_code, sense_key, asc, ascq;
5828 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5829 if (ccb->csio.bio != NULL)
5830 biotrack(ccb->csio.bio, __func__);
5833 periph = xpt_path_periph(ccb->ccb_h.path);
5834 softc = (struct da_softc *)periph->softc;
5836 cam_periph_assert(periph, MA_OWNED);
5839 * Automatically detect devices that do not support
5840 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5843 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5844 error = cmd6workaround(ccb);
5845 } else if (scsi_extract_sense_ccb(ccb,
5846 &error_code, &sense_key, &asc, &ascq)) {
5847 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5848 error = cmd6workaround(ccb);
5850 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5851 * query the capacity and notify upper layers.
5853 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5854 asc == 0x2A && ascq == 0x09) {
5855 xpt_print(periph->path, "Capacity data has changed\n");
5856 softc->flags &= ~DA_FLAG_PROBED;
5858 sense_flags |= SF_NO_PRINT;
5859 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5860 asc == 0x28 && ascq == 0x00) {
5861 softc->flags &= ~DA_FLAG_PROBED;
5862 disk_media_changed(softc->disk, M_NOWAIT);
5863 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5864 asc == 0x3F && ascq == 0x03) {
5865 xpt_print(periph->path, "INQUIRY data has changed\n");
5866 softc->flags &= ~DA_FLAG_PROBED;
5868 sense_flags |= SF_NO_PRINT;
5869 } else if (sense_key == SSD_KEY_NOT_READY &&
5870 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5871 softc->flags |= DA_FLAG_PACK_INVALID;
5872 disk_media_gone(softc->disk, M_NOWAIT);
5875 if (error == ERESTART)
5879 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5880 case CAM_CMD_TIMEOUT:
5883 case CAM_REQ_ABORTED:
5884 case CAM_REQ_CMP_ERR:
5885 case CAM_REQ_TERMIO:
5886 case CAM_UNREC_HBA_ERROR:
5887 case CAM_DATA_RUN_ERR:
5897 * Until we have a better way of doing pack validation,
5898 * don't treat UAs as errors.
5900 sense_flags |= SF_RETRY_UA;
5902 if (softc->quirks & DA_Q_RETRY_BUSY)
5903 sense_flags |= SF_RETRY_BUSY;
5904 return(cam_periph_error(ccb, cam_flags, sense_flags));
5908 damediapoll(void *arg)
5910 struct cam_periph *periph = arg;
5911 struct da_softc *softc = periph->softc;
5913 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5914 (softc->flags & DA_FLAG_TUR_PENDING) == 0 &&
5915 LIST_EMPTY(&softc->pending_ccbs)) {
5916 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
5917 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5921 /* Queue us up again */
5922 if (da_poll_period != 0)
5923 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5927 daprevent(struct cam_periph *periph, int action)
5929 struct da_softc *softc;
5933 cam_periph_assert(periph, MA_OWNED);
5934 softc = (struct da_softc *)periph->softc;
5936 if (((action == PR_ALLOW)
5937 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5938 || ((action == PR_PREVENT)
5939 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5943 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5945 scsi_prevent(&ccb->csio,
5953 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5954 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5957 if (action == PR_ALLOW)
5958 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5960 softc->flags |= DA_FLAG_PACK_LOCKED;
5963 xpt_release_ccb(ccb);
5967 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5968 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5970 struct ccb_calc_geometry ccg;
5971 struct da_softc *softc;
5972 struct disk_params *dp;
5973 u_int lbppbe, lalba;
5976 softc = (struct da_softc *)periph->softc;
5978 dp = &softc->params;
5979 dp->secsize = block_len;
5980 dp->sectors = maxsector + 1;
5981 if (rcaplong != NULL) {
5982 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5983 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5984 lalba &= SRC16_LALBA_A;
5991 dp->stripesize = block_len << lbppbe;
5992 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5994 } else if (softc->quirks & DA_Q_4K) {
5995 dp->stripesize = 4096;
5996 dp->stripeoffset = 0;
5997 } else if (softc->unmap_gran != 0) {
5998 dp->stripesize = block_len * softc->unmap_gran;
5999 dp->stripeoffset = (dp->stripesize - block_len *
6000 softc->unmap_gran_align) % dp->stripesize;
6003 dp->stripeoffset = 0;
6006 * Have the controller provide us with a geometry
6007 * for this disk. The only time the geometry
6008 * matters is when we boot and the controller
6009 * is the only one knowledgeable enough to come
6010 * up with something that will make this a bootable
6013 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6014 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
6015 ccg.block_size = dp->secsize;
6016 ccg.volume_size = dp->sectors;
6018 ccg.secs_per_track = 0;
6020 xpt_action((union ccb*)&ccg);
6021 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
6023 * We don't know what went wrong here- but just pick
6024 * a geometry so we don't have nasty things like divide
6028 dp->secs_per_track = 255;
6029 dp->cylinders = dp->sectors / (255 * 255);
6030 if (dp->cylinders == 0) {
6034 dp->heads = ccg.heads;
6035 dp->secs_per_track = ccg.secs_per_track;
6036 dp->cylinders = ccg.cylinders;
6040 * If the user supplied a read capacity buffer, and if it is
6041 * different than the previous buffer, update the data in the EDT.
6042 * If it's the same, we don't bother. This avoids sending an
6043 * update every time someone opens this device.
6045 if ((rcaplong != NULL)
6046 && (bcmp(rcaplong, &softc->rcaplong,
6047 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
6048 struct ccb_dev_advinfo cdai;
6050 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6051 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
6052 cdai.buftype = CDAI_TYPE_RCAPLONG;
6053 cdai.flags = CDAI_FLAG_STORE;
6054 cdai.bufsiz = rcap_len;
6055 cdai.buf = (uint8_t *)rcaplong;
6056 xpt_action((union ccb *)&cdai);
6057 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
6058 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
6059 if (cdai.ccb_h.status != CAM_REQ_CMP) {
6060 xpt_print(periph->path, "%s: failed to set read "
6061 "capacity advinfo\n", __func__);
6062 /* Use cam_error_print() to decode the status */
6063 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
6066 bcopy(rcaplong, &softc->rcaplong,
6067 min(sizeof(softc->rcaplong), rcap_len));
6071 softc->disk->d_sectorsize = softc->params.secsize;
6072 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
6073 softc->disk->d_stripesize = softc->params.stripesize;
6074 softc->disk->d_stripeoffset = softc->params.stripeoffset;
6075 /* XXX: these are not actually "firmware" values, so they may be wrong */
6076 softc->disk->d_fwsectors = softc->params.secs_per_track;
6077 softc->disk->d_fwheads = softc->params.heads;
6078 softc->disk->d_devstat->block_size = softc->params.secsize;
6079 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
6081 error = disk_resize(softc->disk, M_NOWAIT);
6083 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
6087 dasendorderedtag(void *arg)
6089 struct cam_periph *periph = arg;
6090 struct da_softc *softc = periph->softc;
6092 cam_periph_assert(periph, MA_OWNED);
6093 if (da_send_ordered) {
6094 if (!LIST_EMPTY(&softc->pending_ccbs)) {
6095 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
6096 softc->flags |= DA_FLAG_NEED_OTAG;
6097 softc->flags &= ~DA_FLAG_WAS_OTAG;
6101 /* Queue us up again */
6102 callout_reset(&softc->sendordered_c,
6103 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
6104 dasendorderedtag, periph);
6108 * Step through all DA peripheral drivers, and if the device is still open,
6109 * sync the disk cache to physical media.
6112 dashutdown(void * arg, int howto)
6114 struct cam_periph *periph;
6115 struct da_softc *softc;
6119 CAM_PERIPH_FOREACH(periph, &dadriver) {
6120 softc = (struct da_softc *)periph->softc;
6121 if (SCHEDULER_STOPPED()) {
6122 /* If we paniced with the lock held, do not recurse. */
6123 if (!cam_periph_owned(periph) &&
6124 (softc->flags & DA_FLAG_OPEN)) {
6125 dadump(softc->disk, NULL, 0, 0, 0);
6129 cam_periph_lock(periph);
6132 * We only sync the cache if the drive is still open, and
6133 * if the drive is capable of it..
6135 if (((softc->flags & DA_FLAG_OPEN) == 0)
6136 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
6137 cam_periph_unlock(periph);
6141 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
6142 scsi_synchronize_cache(&ccb->csio,
6146 /*begin_lba*/0, /* whole disk */
6151 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
6152 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
6153 softc->disk->d_devstat);
6155 xpt_print(periph->path, "Synchronize cache failed\n");
6156 xpt_release_ccb(ccb);
6157 cam_periph_unlock(periph);
6161 #else /* !_KERNEL */
6164 * XXX These are only left out of the kernel build to silence warnings. If,
6165 * for some reason these functions are used in the kernel, the ifdefs should
6166 * be moved so they are included both in the kernel and userland.
6169 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
6170 void (*cbfcnp)(struct cam_periph *, union ccb *),
6171 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
6172 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6175 struct scsi_format_unit *scsi_cmd;
6177 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
6178 scsi_cmd->opcode = FORMAT_UNIT;
6179 scsi_cmd->byte2 = byte2;
6180 scsi_ulto2b(ileave, scsi_cmd->interleave);
6185 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6195 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
6196 void (*cbfcnp)(struct cam_periph *, union ccb *),
6197 uint8_t tag_action, uint8_t list_format,
6198 uint32_t addr_desc_index, uint8_t *data_ptr,
6199 uint32_t dxfer_len, int minimum_cmd_size,
6200 uint8_t sense_len, uint32_t timeout)
6205 * These conditions allow using the 10 byte command. Otherwise we
6206 * need to use the 12 byte command.
6208 if ((minimum_cmd_size <= 10)
6209 && (addr_desc_index == 0)
6210 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
6211 struct scsi_read_defect_data_10 *cdb10;
6213 cdb10 = (struct scsi_read_defect_data_10 *)
6214 &csio->cdb_io.cdb_bytes;
6216 cdb_len = sizeof(*cdb10);
6217 bzero(cdb10, cdb_len);
6218 cdb10->opcode = READ_DEFECT_DATA_10;
6219 cdb10->format = list_format;
6220 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
6222 struct scsi_read_defect_data_12 *cdb12;
6224 cdb12 = (struct scsi_read_defect_data_12 *)
6225 &csio->cdb_io.cdb_bytes;
6227 cdb_len = sizeof(*cdb12);
6228 bzero(cdb12, cdb_len);
6229 cdb12->opcode = READ_DEFECT_DATA_12;
6230 cdb12->format = list_format;
6231 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
6232 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
6238 /*flags*/ CAM_DIR_IN,
6248 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
6249 void (*cbfcnp)(struct cam_periph *, union ccb *),
6250 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
6251 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
6254 struct scsi_sanitize *scsi_cmd;
6256 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
6257 scsi_cmd->opcode = SANITIZE;
6258 scsi_cmd->byte2 = byte2;
6259 scsi_cmd->control = control;
6260 scsi_ulto2b(dxfer_len, scsi_cmd->length);
6265 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6274 #endif /* _KERNEL */
6277 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
6278 void (*cbfcnp)(struct cam_periph *, union ccb *),
6279 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
6280 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
6281 uint8_t sense_len, uint32_t timeout)
6283 struct scsi_zbc_out *scsi_cmd;
6285 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
6286 scsi_cmd->opcode = ZBC_OUT;
6287 scsi_cmd->service_action = service_action;
6288 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
6289 scsi_cmd->zone_flags = zone_flags;
6294 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6304 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
6305 void (*cbfcnp)(struct cam_periph *, union ccb *),
6306 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
6307 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
6308 uint8_t sense_len, uint32_t timeout)
6310 struct scsi_zbc_in *scsi_cmd;
6312 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
6313 scsi_cmd->opcode = ZBC_IN;
6314 scsi_cmd->service_action = service_action;
6315 scsi_ulto4b(dxfer_len, scsi_cmd->length);
6316 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
6317 scsi_cmd->zone_options = zone_options;
6322 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
6333 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
6334 void (*cbfcnp)(struct cam_periph *, union ccb *),
6335 uint8_t tag_action, int use_ncq,
6336 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6337 uint8_t *data_ptr, uint32_t dxfer_len,
6338 uint8_t *cdb_storage, size_t cdb_storage_len,
6339 uint8_t sense_len, uint32_t timeout)
6341 uint8_t command_out, protocol, ata_flags;
6342 uint16_t features_out;
6343 uint32_t sectors_out, auxiliary;
6349 command_out = ATA_ZAC_MANAGEMENT_OUT;
6350 features_out = (zm_action & 0xf) | (zone_flags << 8);
6351 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6352 if (dxfer_len == 0) {
6353 protocol = AP_PROTO_NON_DATA;
6354 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6357 protocol = AP_PROTO_DMA;
6358 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
6359 AP_FLAG_TDIR_TO_DEV;
6360 sectors_out = ((dxfer_len >> 9) & 0xffff);
6364 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6365 if (dxfer_len == 0) {
6366 command_out = ATA_NCQ_NON_DATA;
6367 features_out = ATA_NCQ_ZAC_MGMT_OUT;
6369 * We're assuming the SCSI to ATA translation layer
6370 * will set the NCQ tag number in the tag field.
6371 * That isn't clear from the SAT-4 spec (as of rev 05).
6374 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6376 command_out = ATA_SEND_FPDMA_QUEUED;
6378 * Note that we're defaulting to normal priority,
6379 * and assuming that the SCSI to ATA translation
6380 * layer will insert the NCQ tag number in the tag
6381 * field. That isn't clear in the SAT-4 spec (as
6384 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
6386 ata_flags |= AP_FLAG_TLEN_FEAT |
6387 AP_FLAG_TDIR_TO_DEV;
6390 * For SEND FPDMA QUEUED, the transfer length is
6391 * encoded in the FEATURE register, and 0 means
6392 * that 65536 512 byte blocks are to be tranferred.
6393 * In practice, it seems unlikely that we'll see
6394 * a transfer that large, and it may confuse the
6395 * the SAT layer, because generally that means that
6396 * 0 bytes should be transferred.
6398 if (dxfer_len == (65536 * 512)) {
6400 } else if (dxfer_len <= (65535 * 512)) {
6401 features_out = ((dxfer_len >> 9) & 0xffff);
6403 /* The transfer is too big. */
6410 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
6411 protocol = AP_PROTO_FPDMA;
6414 protocol |= AP_EXTEND;
6416 retval = scsi_ata_pass(csio,
6419 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6421 /*protocol*/ protocol,
6422 /*ata_flags*/ ata_flags,
6423 /*features*/ features_out,
6424 /*sector_count*/ sectors_out,
6426 /*command*/ command_out,
6429 /*auxiliary*/ auxiliary,
6431 /*data_ptr*/ data_ptr,
6432 /*dxfer_len*/ dxfer_len,
6433 /*cdb_storage*/ cdb_storage,
6434 /*cdb_storage_len*/ cdb_storage_len,
6435 /*minimum_cmd_size*/ 0,
6436 /*sense_len*/ SSD_FULL_SIZE,
6437 /*timeout*/ timeout);
6445 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
6446 void (*cbfcnp)(struct cam_periph *, union ccb *),
6447 uint8_t tag_action, int use_ncq,
6448 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6449 uint8_t *data_ptr, uint32_t dxfer_len,
6450 uint8_t *cdb_storage, size_t cdb_storage_len,
6451 uint8_t sense_len, uint32_t timeout)
6453 uint8_t command_out, protocol;
6454 uint16_t features_out, sectors_out;
6460 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
6463 command_out = ATA_ZAC_MANAGEMENT_IN;
6464 /* XXX KDM put a macro here */
6465 features_out = (zm_action & 0xf) | (zone_flags << 8);
6466 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
6467 protocol = AP_PROTO_DMA;
6468 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
6471 ata_flags |= AP_FLAG_TLEN_FEAT;
6473 command_out = ATA_RECV_FPDMA_QUEUED;
6474 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6477 * For RECEIVE FPDMA QUEUED, the transfer length is
6478 * encoded in the FEATURE register, and 0 means
6479 * that 65536 512 byte blocks are to be tranferred.
6480 * In practice, it seems unlikely that we'll see
6481 * a transfer that large, and it may confuse the
6482 * the SAT layer, because generally that means that
6483 * 0 bytes should be transferred.
6485 if (dxfer_len == (65536 * 512)) {
6487 } else if (dxfer_len <= (65535 * 512)) {
6488 features_out = ((dxfer_len >> 9) & 0xffff);
6490 /* The transfer is too big. */
6494 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6495 protocol = AP_PROTO_FPDMA;
6498 protocol |= AP_EXTEND;
6500 retval = scsi_ata_pass(csio,
6503 /*flags*/ CAM_DIR_IN,
6505 /*protocol*/ protocol,
6506 /*ata_flags*/ ata_flags,
6507 /*features*/ features_out,
6508 /*sector_count*/ sectors_out,
6510 /*command*/ command_out,
6513 /*auxiliary*/ auxiliary,
6515 /*data_ptr*/ data_ptr,
6516 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6517 /*cdb_storage*/ cdb_storage,
6518 /*cdb_storage_len*/ cdb_storage_len,
6519 /*minimum_cmd_size*/ 0,
6520 /*sense_len*/ SSD_FULL_SIZE,
6521 /*timeout*/ timeout);