2 * Implementation of SCSI Direct Access Peripheral driver for CAM.
4 * SPDX-License-Identifier: BSD-2-Clause
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 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <sys/sysctl.h>
40 #include <sys/taskqueue.h>
42 #include <sys/mutex.h>
44 #include <sys/devicestat.h>
45 #include <sys/eventhandler.h>
46 #include <sys/malloc.h>
48 #include <sys/endian.h>
50 #include <sys/reboot.h>
52 #include <geom/geom.h>
53 #include <geom/geom_disk.h>
54 #include <machine/atomic.h>
63 #include <cam/cam_ccb.h>
64 #include <cam/cam_periph.h>
65 #include <cam/cam_xpt_periph.h>
67 #include <cam/cam_xpt_internal.h>
69 #include <cam/cam_sim.h>
70 #include <cam/cam_iosched.h>
72 #include <cam/scsi/scsi_message.h>
73 #include <cam/scsi/scsi_da.h>
77 * Note that there are probe ordering dependencies here. The order isn't
78 * controlled by this enumeration, but by explicit state transitions in
79 * dastart() and dadone(). Here are some of the dependencies:
81 * 1. RC should come first, before RC16, unless there is evidence that RC16
83 * 2. BDC needs to come before any of the ATA probes, or the ZONE probe.
84 * 3. The ATA probes should go in this order:
85 * ATA -> LOGDIR -> IDDIR -> SUP -> ATA_ZONE
92 DA_STATE_PROBE_BLK_LIMITS,
95 DA_STATE_PROBE_ATA_LOGDIR,
96 DA_STATE_PROBE_ATA_IDDIR,
97 DA_STATE_PROBE_ATA_SUP,
98 DA_STATE_PROBE_ATA_ZONE,
104 DA_FLAG_PACK_INVALID = 0x000001,
105 DA_FLAG_NEW_PACK = 0x000002,
106 DA_FLAG_PACK_LOCKED = 0x000004,
107 DA_FLAG_PACK_REMOVABLE = 0x000008,
108 DA_FLAG_ROTATING = 0x000010,
109 DA_FLAG_NEED_OTAG = 0x000020,
110 DA_FLAG_WAS_OTAG = 0x000040,
111 DA_FLAG_RETRY_UA = 0x000080,
112 DA_FLAG_OPEN = 0x000100,
113 DA_FLAG_SCTX_INIT = 0x000200,
114 DA_FLAG_CAN_RC16 = 0x000400,
115 DA_FLAG_PROBED = 0x000800,
116 DA_FLAG_DIRTY = 0x001000,
117 DA_FLAG_ANNOUNCED = 0x002000,
118 DA_FLAG_CAN_ATA_DMA = 0x004000,
119 DA_FLAG_CAN_ATA_LOG = 0x008000,
120 DA_FLAG_CAN_ATA_IDLOG = 0x010000,
121 DA_FLAG_CAN_ATA_SUPCAP = 0x020000,
122 DA_FLAG_CAN_ATA_ZONE = 0x040000,
123 DA_FLAG_TUR_PENDING = 0x080000,
124 DA_FLAG_UNMAPPEDIO = 0x100000
126 #define DA_FLAG_STRING \
131 "\004PACK_REMOVABLE" \
144 "\021CAN_ATA_IDLOG" \
145 "\022CAN_ATA_SUPACP" \
152 DA_Q_NO_SYNC_CACHE = 0x01,
153 DA_Q_NO_6_BYTE = 0x02,
154 DA_Q_NO_PREVENT = 0x04,
157 DA_Q_NO_UNMAP = 0x20,
158 DA_Q_RETRY_BUSY = 0x40,
160 DA_Q_STRICT_UNMAP = 0x100,
164 #define DA_Q_BIT_STRING \
166 "\001NO_SYNC_CACHE" \
178 DA_CCB_PROBE_RC = 0x01,
179 DA_CCB_PROBE_RC16 = 0x02,
180 DA_CCB_PROBE_LBP = 0x03,
181 DA_CCB_PROBE_BLK_LIMITS = 0x04,
182 DA_CCB_PROBE_BDC = 0x05,
183 DA_CCB_PROBE_ATA = 0x06,
184 DA_CCB_BUFFER_IO = 0x07,
186 DA_CCB_DELETE = 0x0B,
188 DA_CCB_PROBE_ZONE = 0x0D,
189 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
190 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
191 DA_CCB_PROBE_ATA_SUP = 0x10,
192 DA_CCB_PROBE_ATA_ZONE = 0x11,
193 DA_CCB_PROBE_WP = 0x12,
194 DA_CCB_TYPE_MASK = 0x1F,
195 DA_CCB_RETRY_UA = 0x20
199 * Order here is important for method choice
201 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
202 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
203 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
204 * import taking 5mins.
215 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
216 DA_DELETE_MAX = DA_DELETE_ZERO
220 * For SCSI, host managed drives show up as a separate device type. For
221 * ATA, host managed drives also have a different device signature.
222 * XXX KDM figure out the ATA host managed signature.
226 DA_ZONE_DRIVE_MANAGED = 0x01,
227 DA_ZONE_HOST_AWARE = 0x02,
228 DA_ZONE_HOST_MANAGED = 0x03
232 * We distinguish between these interface cases in addition to the drive type:
233 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
234 * o ATA drive behind a SCSI translation layer that does not know about
235 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
236 * case, we would need to share the ATA code with the ada(4) driver.
246 DA_ZONE_FLAG_RZ_SUP = 0x0001,
247 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
248 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
249 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
250 DA_ZONE_FLAG_RWP_SUP = 0x0010,
251 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
252 DA_ZONE_FLAG_OPEN_SUP |
253 DA_ZONE_FLAG_CLOSE_SUP |
254 DA_ZONE_FLAG_FINISH_SUP |
255 DA_ZONE_FLAG_RWP_SUP),
256 DA_ZONE_FLAG_URSWRZ = 0x0020,
257 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
258 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
259 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
260 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
261 DA_ZONE_FLAG_OPT_NONSEQ_SET |
262 DA_ZONE_FLAG_MAX_SEQ_SET)
265 static struct da_zone_desc {
268 } da_zone_desc_table[] = {
269 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
270 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
271 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
272 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
273 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
276 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
278 static da_delete_func_t da_delete_trim;
279 static da_delete_func_t da_delete_unmap;
280 static da_delete_func_t da_delete_ws;
282 static const void * da_delete_functions[] = {
292 static const char *da_delete_method_names[] =
293 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
294 static const char *da_delete_method_desc[] =
295 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
296 "WRITE SAME(10) with UNMAP", "ZERO" };
298 /* Offsets into our private area for storing information */
299 #define ccb_state ppriv_field0
300 #define ccb_bp ppriv_ptr1
305 uint8_t secs_per_track;
306 uint32_t secsize; /* Number of bytes/sector */
307 uint64_t sectors; /* total number sectors */
312 #define UNMAP_RANGE_MAX 0xffffffff
313 #define UNMAP_HEAD_SIZE 8
314 #define UNMAP_RANGE_SIZE 16
315 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
316 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
319 #define WS10_MAX_BLKS 0xffff
320 #define WS16_MAX_BLKS 0xffffffff
321 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
322 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
324 #define DA_WORK_TUR (1 << 16)
334 DA_REF_MAX /* KEEP LAST */
338 struct cam_iosched_softc *cam_iosched;
339 struct bio_queue_head delete_run_queue;
340 LIST_HEAD(, ccb_hdr) pending_ccbs;
341 int refcount; /* Active xpt_action() calls */
345 int minimum_cmd_size;
349 int delete_available; /* Delete methods possibly available */
350 da_zone_mode zone_mode;
351 da_zone_interface zone_interface;
352 da_zone_flags zone_flags;
353 struct ata_gp_log_dir ata_logdir;
354 int valid_logdir_len;
355 struct ata_identify_log_pages ata_iddir;
357 uint64_t optimal_seq_zones;
358 uint64_t optimal_nonseq_zones;
359 uint64_t max_seq_zones;
361 uint32_t unmap_max_ranges;
362 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
364 uint32_t unmap_gran_align;
365 uint64_t ws_max_blks;
367 uint64_t trim_ranges;
369 da_delete_methods delete_method_pref;
370 da_delete_methods delete_method;
371 da_delete_func_t *delete_func;
373 struct disk_params params;
375 struct task sysctl_task;
376 struct sysctl_ctx_list sysctl_ctx;
377 struct sysctl_oid *sysctl_tree;
378 struct callout sendordered_c;
380 uint8_t unmap_buf[UNMAP_BUF_SIZE];
381 struct scsi_read_capacity_data_long rcaplong;
382 struct callout mediapoll_c;
383 int ref_flags[DA_REF_MAX];
385 struct sysctl_ctx_list sysctl_stats_ctx;
386 struct sysctl_oid *sysctl_stats_tree;
391 #define DA_ANNOUNCETMP_SZ 160
392 char announce_temp[DA_ANNOUNCETMP_SZ];
393 #define DA_ANNOUNCE_SZ 400
394 char announcebuf[DA_ANNOUNCE_SZ];
397 #define dadeleteflag(softc, delete_method, enable) \
399 softc->delete_available |= (1 << delete_method); \
401 softc->delete_available &= ~(1 << delete_method); \
404 static uma_zone_t da_ccb_zone;
406 struct da_quirk_entry {
407 struct scsi_inquiry_pattern inq_pat;
411 static const char quantum[] = "QUANTUM";
412 static const char microp[] = "MICROP";
414 static struct da_quirk_entry da_quirk_table[] =
416 /* SPI, FC devices */
419 * Fujitsu M2513A MO drives.
420 * Tested devices: M2513A2 firmware versions 1200 & 1300.
421 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
422 * Reported by: W.Scholten <whs@xs4all.nl>
424 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
425 /*quirks*/ DA_Q_NO_SYNC_CACHE
429 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
430 /*quirks*/ DA_Q_NO_SYNC_CACHE
434 * This particular Fujitsu drive doesn't like the
435 * synchronize cache command.
436 * Reported by: Tom Jackson <toj@gorilla.net>
438 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
439 /*quirks*/ DA_Q_NO_SYNC_CACHE
443 * This drive doesn't like the synchronize cache command
444 * either. Reported by: Matthew Jacob <mjacob@feral.com>
445 * in NetBSD PR kern/6027, August 24, 1998.
447 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
448 /*quirks*/ DA_Q_NO_SYNC_CACHE
452 * This drive doesn't like the synchronize cache command
453 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
456 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
457 /*quirks*/ DA_Q_NO_SYNC_CACHE
461 * Doesn't like the synchronize cache command.
462 * Reported by: Blaz Zupan <blaz@gold.amis.net>
464 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
465 /*quirks*/ DA_Q_NO_SYNC_CACHE
469 * Doesn't like the synchronize cache command.
470 * Reported by: Blaz Zupan <blaz@gold.amis.net>
472 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
473 /*quirks*/ DA_Q_NO_SYNC_CACHE
477 * Doesn't like the synchronize cache command.
479 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
480 /*quirks*/ DA_Q_NO_SYNC_CACHE
484 * Doesn't like the synchronize cache command.
485 * Reported by: walter@pelissero.de
487 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
488 /*quirks*/ DA_Q_NO_SYNC_CACHE
492 * Doesn't work correctly with 6 byte reads/writes.
493 * Returns illegal request, and points to byte 9 of the
495 * Reported by: Adam McDougall <bsdx@spawnet.com>
497 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
498 /*quirks*/ DA_Q_NO_6_BYTE
502 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
503 /*quirks*/ DA_Q_NO_6_BYTE
507 * Doesn't like the synchronize cache command.
508 * Reported by: walter@pelissero.de
510 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
511 /*quirks*/ DA_Q_NO_SYNC_CACHE
515 * The CISS RAID controllers do not support SYNC_CACHE
517 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
518 /*quirks*/ DA_Q_NO_SYNC_CACHE
522 * The STEC SSDs sometimes hang on UNMAP.
524 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
525 /*quirks*/ DA_Q_NO_UNMAP
529 * VMware returns BUSY status when storage has transient
530 * connectivity problems, so better wait.
531 * Also VMware returns odd errors on misaligned UNMAPs.
533 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
534 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
536 /* USB mass storage devices supported by umass(4) */
539 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
542 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
543 /*quirks*/ DA_Q_NO_SYNC_CACHE
547 * Power Quotient Int. (PQI) USB flash key
550 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
551 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
555 * Creative Nomad MUVO mp3 player (USB)
558 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
559 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
563 * Jungsoft NEXDISK USB flash key
566 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
567 /*quirks*/ DA_Q_NO_SYNC_CACHE
571 * FreeDik USB Mini Data Drive
574 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
575 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
579 * Sigmatel USB Flash MP3 Player
582 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
583 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
587 * Neuros USB Digital Audio Computer
590 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
591 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
595 * SEAGRAND NP-900 MP3 Player
598 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
599 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
603 * iRiver iFP MP3 player (with UMS Firmware)
604 * PR: kern/54881, i386/63941, kern/66124
606 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
607 /*quirks*/ DA_Q_NO_SYNC_CACHE
611 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
614 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
615 /*quirks*/ DA_Q_NO_SYNC_CACHE
619 * ZICPlay USB MP3 Player with FM
622 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
623 /*quirks*/ DA_Q_NO_SYNC_CACHE
627 * TEAC USB floppy mechanisms
629 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
630 /*quirks*/ DA_Q_NO_SYNC_CACHE
634 * Kingston DataTraveler II+ USB Pen-Drive.
635 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
637 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
638 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
646 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
647 /*quirks*/ DA_Q_NO_SYNC_CACHE
651 * Motorola E398 Mobile Phone (TransFlash memory card).
652 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
655 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
656 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
660 * Qware BeatZkey! Pro
663 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
664 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
668 * Time DPA20B 1GB MP3 Player
671 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
672 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
676 * Samsung USB key 128Mb
679 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
680 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
684 * Kingston DataTraveler 2.0 USB Flash memory.
687 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
688 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
692 * Creative MUVO Slim mp3 player (USB)
695 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
696 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
700 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
703 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
704 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
708 * SanDisk Micro Cruzer 128MB
711 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
712 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
716 * TOSHIBA TransMemory USB sticks
719 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
720 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
724 * PNY USB 3.0 Flash Drives
726 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
727 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
732 * PR: usb/75578, usb/72344, usb/65436
734 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
735 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
741 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
742 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16
746 * Genesys 6-in-1 Card Reader
749 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
750 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
754 * Rekam Digital CAMERA
757 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
758 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
762 * iRiver H10 MP3 player
765 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
766 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
770 * iRiver U10 MP3 player
773 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
774 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
781 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
782 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
786 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
789 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
790 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
797 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
798 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
802 * Philips USB Key Audio KEY013
805 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
806 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
813 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
814 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
821 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
822 /*quirks*/ DA_Q_NO_SYNC_CACHE
826 * I/O Magic USB flash - Giga Bank
829 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
830 /*quirks*/ DA_Q_NO_SYNC_CACHE
834 * JoyFly 128mb USB Flash Drive
837 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
838 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
845 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
846 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
850 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
853 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
854 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
858 * Samsung YP-U3 mp3-player
861 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
862 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
865 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
866 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
870 * Sony Cyber-Shot DSC cameras
873 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
874 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
877 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
878 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
881 /* At least several Transcent USB sticks lie on RC16. */
882 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
883 "*"}, /*quirks*/ DA_Q_NO_RC16
887 * I-O Data USB Flash Disk
890 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
891 "*"}, /*quirks*/ DA_Q_NO_RC16
895 * SLC CHIPFANCIER USB drives
896 * PR: usb/234503 (RC10 right, RC16 wrong)
897 * 16GB, 32GB and 128GB confirmed to have same issue
899 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*SLC", "CHIPFANCIER",
900 "*"}, /*quirks*/ DA_Q_NO_RC16
902 /* ATA/SATA devices over SAS/USB/... */
905 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SanDisk SD8SB8U1*", "*" },
909 /* Hitachi Advanced Format (4k) drives */
910 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
914 /* Micron Advanced Format (4k) drives */
915 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
919 /* Samsung Advanced Format (4k) drives */
920 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
924 /* Samsung Advanced Format (4k) drives */
925 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
929 /* Samsung Advanced Format (4k) drives */
930 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
934 /* Samsung Advanced Format (4k) drives */
935 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
939 /* Seagate Barracuda Green Advanced Format (4k) drives */
940 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
944 /* Seagate Barracuda Green Advanced Format (4k) drives */
945 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
949 /* Seagate Barracuda Green Advanced Format (4k) drives */
950 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
954 /* Seagate Barracuda Green Advanced Format (4k) drives */
955 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
959 /* Seagate Barracuda Green Advanced Format (4k) drives */
960 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
964 /* Seagate Barracuda Green Advanced Format (4k) drives */
965 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
969 /* Seagate Momentus Advanced Format (4k) drives */
970 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
974 /* Seagate Momentus Advanced Format (4k) drives */
975 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
979 /* Seagate Momentus Advanced Format (4k) drives */
980 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
984 /* Seagate Momentus Advanced Format (4k) drives */
985 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
989 /* Seagate Momentus Advanced Format (4k) drives */
990 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
994 /* Seagate Momentus Advanced Format (4k) drives */
995 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
999 /* Seagate Momentus Advanced Format (4k) drives */
1000 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
1004 /* Seagate Momentus Advanced Format (4k) drives */
1005 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
1009 /* Seagate Momentus Advanced Format (4k) drives */
1010 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
1014 /* Seagate Momentus Advanced Format (4k) drives */
1015 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
1019 /* Seagate Momentus Advanced Format (4k) drives */
1020 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
1024 /* Seagate Momentus Advanced Format (4k) drives */
1025 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
1029 /* Seagate Momentus Advanced Format (4k) drives */
1030 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
1034 /* Seagate Momentus Advanced Format (4k) drives */
1035 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
1039 /* Seagate Momentus Thin Advanced Format (4k) drives */
1040 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
1044 /* Seagate Momentus Thin Advanced Format (4k) drives */
1045 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
1049 /* WDC Caviar Green Advanced Format (4k) drives */
1050 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
1054 /* WDC Caviar Green Advanced Format (4k) drives */
1055 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
1059 /* WDC Caviar Green Advanced Format (4k) drives */
1060 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
1064 /* WDC Caviar Green Advanced Format (4k) drives */
1065 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
1069 /* WDC Caviar Green Advanced Format (4k) drives */
1070 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1074 /* WDC Caviar Green Advanced Format (4k) drives */
1075 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1079 /* WDC Caviar Green Advanced Format (4k) drives */
1080 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1084 /* WDC Caviar Green Advanced Format (4k) drives */
1085 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1089 /* WDC Scorpio Black Advanced Format (4k) drives */
1090 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1094 /* WDC Scorpio Black Advanced Format (4k) drives */
1095 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1099 /* WDC Scorpio Black Advanced Format (4k) drives */
1100 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1104 /* WDC Scorpio Black Advanced Format (4k) drives */
1105 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1109 /* WDC Scorpio Blue Advanced Format (4k) drives */
1110 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1114 /* WDC Scorpio Blue Advanced Format (4k) drives */
1115 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1119 /* WDC Scorpio Blue Advanced Format (4k) drives */
1120 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1124 /* WDC Scorpio Blue Advanced Format (4k) drives */
1125 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1130 * Olympus digital cameras (C-3040ZOOM, C-2040ZOOM, C-1)
1133 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "C*", "*"},
1134 /*quirks*/ DA_Q_NO_6_BYTE | DA_Q_NO_SYNC_CACHE
1138 * Olympus digital cameras (D-370)
1141 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "D*", "*"},
1142 /*quirks*/ DA_Q_NO_6_BYTE
1146 * Olympus digital cameras (E-100RS, E-10).
1149 { T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "E*", "*"},
1150 /*quirks*/ DA_Q_NO_6_BYTE | DA_Q_NO_SYNC_CACHE
1154 * Olympus FE-210 camera
1156 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1157 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1161 * Pentax Digital Camera
1164 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PENTAX", "DIGITAL CAMERA",
1165 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1169 * LG UP3S MP3 player
1171 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1172 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1176 * Laser MP3-2GA13 MP3 player
1178 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1179 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1183 * LaCie external 250GB Hard drive des by Porsche
1184 * Submitted by: Ben Stuyts <ben@altesco.nl>
1187 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1188 /*quirks*/ DA_Q_NO_SYNC_CACHE
1193 * Corsair Force 2 SSDs
1194 * 4k optimised & trim only works in 4k requests + 4k aligned
1196 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1201 * Corsair Force 3 SSDs
1202 * 4k optimised & trim only works in 4k requests + 4k aligned
1204 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1209 * Corsair Neutron GTX SSDs
1210 * 4k optimised & trim only works in 4k requests + 4k aligned
1212 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1217 * Corsair Force GT & GS SSDs
1218 * 4k optimised & trim only works in 4k requests + 4k aligned
1220 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1226 * 4k optimised & trim only works in 4k requests + 4k aligned
1228 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1233 * Crucial RealSSD C300 SSDs
1236 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1237 "*" }, /*quirks*/DA_Q_4K
1241 * Intel 320 Series SSDs
1242 * 4k optimised & trim only works in 4k requests + 4k aligned
1244 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1249 * Intel 330 Series SSDs
1250 * 4k optimised & trim only works in 4k requests + 4k aligned
1252 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1257 * Intel 510 Series SSDs
1258 * 4k optimised & trim only works in 4k requests + 4k aligned
1260 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1265 * Intel 520 Series SSDs
1266 * 4k optimised & trim only works in 4k requests + 4k aligned
1268 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1273 * Intel S3610 Series SSDs
1274 * 4k optimised & trim only works in 4k requests + 4k aligned
1276 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1281 * Intel X25-M Series SSDs
1282 * 4k optimised & trim only works in 4k requests + 4k aligned
1284 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1289 * Kingston E100 Series SSDs
1290 * 4k optimised & trim only works in 4k requests + 4k aligned
1292 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1297 * Kingston HyperX 3k SSDs
1298 * 4k optimised & trim only works in 4k requests + 4k aligned
1300 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1305 * Marvell SSDs (entry taken from OpenSolaris)
1306 * 4k optimised & trim only works in 4k requests + 4k aligned
1308 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1313 * OCZ Agility 2 SSDs
1314 * 4k optimised & trim only works in 4k requests + 4k aligned
1316 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1321 * OCZ Agility 3 SSDs
1322 * 4k optimised & trim only works in 4k requests + 4k aligned
1324 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1329 * OCZ Deneva R Series SSDs
1330 * 4k optimised & trim only works in 4k requests + 4k aligned
1332 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1337 * OCZ Vertex 2 SSDs (inc pro series)
1338 * 4k optimised & trim only works in 4k requests + 4k aligned
1340 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1346 * 4k optimised & trim only works in 4k requests + 4k aligned
1348 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1354 * 4k optimised & trim only works in 4k requests + 4k aligned
1356 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1361 * Samsung 750 Series SSDs
1362 * 4k optimised & trim only works in 4k requests + 4k aligned
1364 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" },
1369 * Samsung 830 Series SSDs
1370 * 4k optimised & trim only works in 4k requests + 4k aligned
1372 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1378 * 4k optimised & trim only works in 4k requests + 4k aligned
1380 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1386 * 4k optimised & trim only works in 4k requests + 4k aligned
1388 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" },
1394 * 4k optimised & trim only works in 4k requests + 4k aligned
1396 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1401 * Samsung 843T Series SSDs (MZ7WD*)
1402 * Samsung PM851 Series SSDs (MZ7TE*)
1403 * Samsung PM853T Series SSDs (MZ7GE*)
1404 * Samsung SM863 Series SSDs (MZ7KM*)
1407 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1412 * Same as for SAMSUNG MZ7* but enable the quirks for SSD
1413 * starting with MZ7* too
1415 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MZ7*", "*" },
1420 * Same as above but enable the quirks for SSD SAMSUNG MZ7*
1421 * connected via SATA-to-SAS interposer and because of this
1422 * starting without "ATA"
1424 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MZ7*", "*" },
1429 * SuperTalent TeraDrive CT SSDs
1430 * 4k optimised & trim only works in 4k requests + 4k aligned
1432 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1437 * XceedIOPS SATA SSDs
1440 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1445 * Hama Innostor USB-Stick
1447 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1448 /*quirks*/DA_Q_NO_RC16
1452 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1453 * Drive Managed SATA hard drive. This drive doesn't report
1454 * in firmware that it is a drive managed SMR drive.
1456 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS000[23]*", "*" },
1457 /*quirks*/DA_Q_SMR_DM
1461 * MX-ES USB Drive by Mach Xtreme
1463 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1464 /*quirks*/DA_Q_NO_RC16
1468 static disk_strategy_t dastrategy;
1469 static dumper_t dadump;
1470 static periph_init_t dainit;
1471 static void daasync(void *callback_arg, uint32_t code,
1472 struct cam_path *path, void *arg);
1473 static void dasysctlinit(void *context, int pending);
1474 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1475 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1476 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1477 static int dabitsysctl(SYSCTL_HANDLER_ARGS);
1478 static int daflagssysctl(SYSCTL_HANDLER_ARGS);
1479 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1480 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1481 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1482 static void dadeletemethodset(struct da_softc *softc,
1483 da_delete_methods delete_method);
1484 static off_t dadeletemaxsize(struct da_softc *softc,
1485 da_delete_methods delete_method);
1486 static void dadeletemethodchoose(struct da_softc *softc,
1487 da_delete_methods default_method);
1488 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1490 static periph_ctor_t daregister;
1491 static periph_dtor_t dacleanup;
1492 static periph_start_t dastart;
1493 static periph_oninv_t daoninvalidate;
1494 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1495 static void dadone(struct cam_periph *periph,
1496 union ccb *done_ccb);
1497 static void dadone_probewp(struct cam_periph *periph,
1498 union ccb *done_ccb);
1499 static void dadone_proberc(struct cam_periph *periph,
1500 union ccb *done_ccb);
1501 static void dadone_probelbp(struct cam_periph *periph,
1502 union ccb *done_ccb);
1503 static void dadone_probeblklimits(struct cam_periph *periph,
1504 union ccb *done_ccb);
1505 static void dadone_probebdc(struct cam_periph *periph,
1506 union ccb *done_ccb);
1507 static void dadone_probeata(struct cam_periph *periph,
1508 union ccb *done_ccb);
1509 static void dadone_probeatalogdir(struct cam_periph *periph,
1510 union ccb *done_ccb);
1511 static void dadone_probeataiddir(struct cam_periph *periph,
1512 union ccb *done_ccb);
1513 static void dadone_probeatasup(struct cam_periph *periph,
1514 union ccb *done_ccb);
1515 static void dadone_probeatazone(struct cam_periph *periph,
1516 union ccb *done_ccb);
1517 static void dadone_probezone(struct cam_periph *periph,
1518 union ccb *done_ccb);
1519 static void dadone_tur(struct cam_periph *periph,
1520 union ccb *done_ccb);
1521 static int daerror(union ccb *ccb, uint32_t cam_flags,
1522 uint32_t sense_flags);
1523 static void daprevent(struct cam_periph *periph, int action);
1524 static void dareprobe(struct cam_periph *periph);
1525 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1527 struct scsi_read_capacity_data_long *rcaplong,
1529 static callout_func_t dasendorderedtag;
1530 static void dashutdown(void *arg, int howto);
1531 static callout_func_t damediapoll;
1533 #ifndef DA_DEFAULT_POLL_PERIOD
1534 #define DA_DEFAULT_POLL_PERIOD 3
1537 #ifndef DA_DEFAULT_TIMEOUT
1538 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1541 #ifndef DA_DEFAULT_SOFTTIMEOUT
1542 #define DA_DEFAULT_SOFTTIMEOUT 0
1545 #ifndef DA_DEFAULT_RETRY
1546 #define DA_DEFAULT_RETRY 4
1549 #ifndef DA_DEFAULT_SEND_ORDERED
1550 #define DA_DEFAULT_SEND_ORDERED 1
1553 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1554 static int da_retry_count = DA_DEFAULT_RETRY;
1555 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1556 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1557 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1558 static int da_disable_wp_detection = 0;
1559 static int da_enable_biospeedup = 1;
1560 static int da_enable_uma_ccbs = 1;
1562 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
1563 "CAM Direct Access Disk driver");
1564 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1565 &da_poll_period, 0, "Media polling period in seconds");
1566 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1567 &da_retry_count, 0, "Normal I/O retry count");
1568 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1569 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1570 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1571 &da_send_ordered, 0, "Send Ordered Tags");
1572 SYSCTL_INT(_kern_cam_da, OID_AUTO, disable_wp_detection, CTLFLAG_RWTUN,
1573 &da_disable_wp_detection, 0,
1574 "Disable detection of write-protected disks");
1575 SYSCTL_INT(_kern_cam_da, OID_AUTO, enable_biospeedup, CTLFLAG_RDTUN,
1576 &da_enable_biospeedup, 0, "Enable BIO_SPEEDUP processing");
1577 SYSCTL_INT(_kern_cam_da, OID_AUTO, enable_uma_ccbs, CTLFLAG_RWTUN,
1578 &da_enable_uma_ccbs, 0, "Use UMA for CCBs");
1580 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1581 CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, 0,
1582 dasysctlsofttimeout, "I",
1583 "Soft I/O timeout (ms)");
1584 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1587 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1588 * to the default timeout, we check to see whether an ordered
1589 * tagged transaction is appropriate to prevent simple tag
1590 * starvation. Since we'd like to ensure that there is at least
1591 * 1/2 of the timeout length left for a starved transaction to
1592 * complete after we've sent an ordered tag, we must poll at least
1593 * four times in every timeout period. This takes care of the worst
1594 * case where a starved transaction starts during an interval that
1595 * meets the requirement "don't send an ordered tag" test so it takes
1596 * us two intervals to determine that a tag must be sent.
1598 #ifndef DA_ORDEREDTAG_INTERVAL
1599 #define DA_ORDEREDTAG_INTERVAL 4
1602 static struct periph_driver dadriver =
1605 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1608 PERIPHDRIVER_DECLARE(da, dadriver);
1610 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1613 * This driver takes out references / holds in well defined pairs, never
1614 * recursively. These macros / inline functions enforce those rules. They
1615 * are only enabled with DA_TRACK_REFS or INVARIANTS. If DA_TRACK_REFS is
1616 * defined to be 2 or larger, the tracking also includes debug printfs.
1618 #if defined(DA_TRACK_REFS) || defined(INVARIANTS)
1620 #ifndef DA_TRACK_REFS
1621 #define DA_TRACK_REFS 1
1624 #if DA_TRACK_REFS > 1
1625 static const char *da_ref_text[] = {
1638 #define DA_PERIPH_PRINT(periph, msg, args...) \
1639 CAM_PERIPH_PRINT(periph, msg, ##args)
1641 #define DA_PERIPH_PRINT(periph, msg, args...)
1645 token_sanity(da_ref_token token)
1647 if ((unsigned)token >= DA_REF_MAX)
1648 panic("Bad token value passed in %d\n", token);
1652 da_periph_hold(struct cam_periph *periph, int priority, da_ref_token token)
1654 int err = cam_periph_hold(periph, priority);
1656 token_sanity(token);
1657 DA_PERIPH_PRINT(periph, "Holding device %s (%d): %d\n",
1658 da_ref_text[token], token, err);
1661 struct da_softc *softc = periph->softc;
1663 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1665 panic("Re-holding for reason %d, cnt = %d", token, cnt);
1671 da_periph_unhold(struct cam_periph *periph, da_ref_token token)
1674 struct da_softc *softc = periph->softc;
1676 token_sanity(token);
1677 DA_PERIPH_PRINT(periph, "Unholding device %s (%d)\n",
1678 da_ref_text[token], token);
1679 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1681 panic("Unholding %d with cnt = %d", token, cnt);
1682 cam_periph_unhold(periph);
1686 da_periph_acquire(struct cam_periph *periph, da_ref_token token)
1688 int err = cam_periph_acquire(periph);
1690 token_sanity(token);
1691 DA_PERIPH_PRINT(periph, "acquiring device %s (%d): %d\n",
1692 da_ref_text[token], token, err);
1695 struct da_softc *softc = periph->softc;
1697 cnt = atomic_fetchadd_int(&softc->ref_flags[token], 1);
1699 panic("Re-refing for reason %d, cnt = %d", token, cnt);
1705 da_periph_release(struct cam_periph *periph, da_ref_token token)
1708 struct da_softc *softc = periph->softc;
1710 token_sanity(token);
1711 DA_PERIPH_PRINT(periph, "releasing device %s (%d)\n",
1712 da_ref_text[token], token);
1713 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1715 panic("Releasing %d with cnt = %d", token, cnt);
1716 cam_periph_release(periph);
1720 da_periph_release_locked(struct cam_periph *periph, da_ref_token token)
1723 struct da_softc *softc = periph->softc;
1725 token_sanity(token);
1726 DA_PERIPH_PRINT(periph, "releasing device (locked) %s (%d)\n",
1727 da_ref_text[token], token);
1728 cnt = atomic_fetchadd_int(&softc->ref_flags[token], -1);
1730 panic("releasing (locked) %d with cnt = %d", token, cnt);
1731 cam_periph_release_locked(periph);
1734 #define cam_periph_hold POISON
1735 #define cam_periph_unhold POISON
1736 #define cam_periph_acquire POISON
1737 #define cam_periph_release POISON
1738 #define cam_periph_release_locked POISON
1741 #define da_periph_hold(periph, prio, token) cam_periph_hold((periph), (prio))
1742 #define da_periph_unhold(periph, token) cam_periph_unhold((periph))
1743 #define da_periph_acquire(periph, token) cam_periph_acquire((periph))
1744 #define da_periph_release(periph, token) cam_periph_release((periph))
1745 #define da_periph_release_locked(periph, token) cam_periph_release_locked((periph))
1749 daopen(struct disk *dp)
1751 struct cam_periph *periph;
1752 struct da_softc *softc;
1755 periph = (struct cam_periph *)dp->d_drv1;
1756 if (da_periph_acquire(periph, DA_REF_OPEN) != 0) {
1760 cam_periph_lock(periph);
1761 if ((error = da_periph_hold(periph, PRIBIO|PCATCH, DA_REF_OPEN_HOLD)) != 0) {
1762 cam_periph_unlock(periph);
1763 da_periph_release(periph, DA_REF_OPEN);
1767 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1770 softc = (struct da_softc *)periph->softc;
1773 /* Wait for the disk size update. */
1774 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1777 xpt_print(periph->path, "unable to retrieve capacity data\n");
1779 if (periph->flags & CAM_PERIPH_INVALID)
1782 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1783 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1784 daprevent(periph, PR_PREVENT);
1787 softc->flags &= ~DA_FLAG_PACK_INVALID;
1788 softc->flags |= DA_FLAG_OPEN;
1791 da_periph_unhold(periph, DA_REF_OPEN_HOLD);
1792 cam_periph_unlock(periph);
1795 da_periph_release(periph, DA_REF_OPEN);
1801 daclose(struct disk *dp)
1803 struct cam_periph *periph;
1804 struct da_softc *softc;
1807 periph = (struct cam_periph *)dp->d_drv1;
1808 softc = (struct da_softc *)periph->softc;
1809 cam_periph_lock(periph);
1810 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1813 if (da_periph_hold(periph, PRIBIO, DA_REF_CLOSE_HOLD) == 0) {
1814 /* Flush disk cache. */
1815 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1816 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1817 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1818 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1819 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1820 /*cbfcnp*/NULL, MSG_SIMPLE_Q_TAG,
1821 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1823 cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1824 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1825 softc->disk->d_devstat);
1826 softc->flags &= ~DA_FLAG_DIRTY;
1827 xpt_release_ccb(ccb);
1830 /* Allow medium removal. */
1831 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1832 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1833 daprevent(periph, PR_ALLOW);
1835 da_periph_unhold(periph, DA_REF_CLOSE_HOLD);
1839 * If we've got removable media, mark the blocksize as
1840 * unavailable, since it could change when new media is
1843 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1844 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1846 softc->flags &= ~DA_FLAG_OPEN;
1847 while (softc->refcount != 0)
1848 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1849 cam_periph_unlock(periph);
1850 da_periph_release(periph, DA_REF_OPEN);
1855 daschedule(struct cam_periph *periph)
1857 struct da_softc *softc = (struct da_softc *)periph->softc;
1859 if (softc->state != DA_STATE_NORMAL)
1862 cam_iosched_schedule(softc->cam_iosched, periph);
1866 * Actually translate the requested transfer into one the physical driver
1867 * can understand. The transfer is described by a buf and will include
1868 * only one physical transfer.
1871 dastrategy(struct bio *bp)
1873 struct cam_periph *periph;
1874 struct da_softc *softc;
1876 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1877 softc = (struct da_softc *)periph->softc;
1879 cam_periph_lock(periph);
1882 * If the device has been made invalid, error out
1884 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1885 cam_periph_unlock(periph);
1886 biofinish(bp, NULL, ENXIO);
1890 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1893 * Zone commands must be ordered, because they can depend on the
1894 * effects of previously issued commands, and they may affect
1895 * commands after them.
1897 if (bp->bio_cmd == BIO_ZONE)
1898 bp->bio_flags |= BIO_ORDERED;
1901 * Place it in the queue of disk activities for this disk
1903 cam_iosched_queue_work(softc->cam_iosched, bp);
1906 * Schedule ourselves for performing the work.
1909 cam_periph_unlock(periph);
1915 dadump(void *arg, void *virtual, off_t offset, size_t length)
1917 struct cam_periph *periph;
1918 struct da_softc *softc;
1920 struct ccb_scsiio csio;
1925 periph = dp->d_drv1;
1926 softc = (struct da_softc *)periph->softc;
1927 secsize = softc->params.secsize;
1929 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0)
1932 memset(&csio, 0, sizeof(csio));
1934 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1935 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1936 scsi_read_write(&csio,
1940 /*read*/SCSI_RW_WRITE,
1942 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1945 /*data_ptr*/(uint8_t *) virtual,
1946 /*dxfer_len*/length,
1947 /*sense_len*/SSD_FULL_SIZE,
1948 da_default_timeout * 1000);
1949 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1950 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1952 printf("Aborting dump due to I/O error.\n");
1957 * Sync the disk cache contents to the physical media.
1959 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1960 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1961 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1962 scsi_synchronize_cache(&csio,
1966 /*begin_lba*/0,/* Cover the whole disk */
1970 error = cam_periph_runccb((union ccb *)&csio, cam_periph_error,
1971 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1973 xpt_print(periph->path, "Synchronize cache failed\n");
1979 dagetattr(struct bio *bp)
1982 struct cam_periph *periph;
1984 if (g_handleattr_int(bp, "GEOM::canspeedup", da_enable_biospeedup))
1985 return (EJUSTRETURN);
1987 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1988 cam_periph_lock(periph);
1989 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1991 cam_periph_unlock(periph);
1993 bp->bio_completed = bp->bio_length;
2002 da_ccb_zone = uma_zcreate("da_ccb",
2003 sizeof(struct ccb_scsiio), NULL, NULL, NULL, NULL,
2007 * Install a global async callback. This callback will
2008 * receive async callbacks like "new device found".
2010 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
2012 if (status != CAM_REQ_CMP) {
2013 printf("da: Failed to attach master async callback "
2014 "due to status 0x%x!\n", status);
2015 } else if (da_send_ordered) {
2016 /* Register our shutdown event handler */
2017 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
2018 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
2019 printf("dainit: shutdown event registration failed!\n");
2024 * Callback from GEOM, called when it has finished cleaning up its
2028 dadiskgonecb(struct disk *dp)
2030 struct cam_periph *periph;
2032 periph = (struct cam_periph *)dp->d_drv1;
2033 da_periph_release(periph, DA_REF_GEOM);
2037 daoninvalidate(struct cam_periph *periph)
2039 struct da_softc *softc;
2041 cam_periph_assert(periph, MA_OWNED);
2042 softc = (struct da_softc *)periph->softc;
2045 * De-register any async callbacks.
2047 xpt_register_async(0, daasync, periph, periph->path);
2049 softc->flags |= DA_FLAG_PACK_INVALID;
2051 softc->invalidations++;
2055 * Return all queued I/O with ENXIO. Transactions may be queued up here
2056 * for retry (since we are called while there's other transactions
2057 * pending). Any requests in the hardware will drain before dacleanup
2060 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
2063 * Tell GEOM that we've gone away, we'll get a callback when it is
2064 * done cleaning up its resources.
2066 disk_gone(softc->disk);
2070 dacleanup(struct cam_periph *periph)
2072 struct da_softc *softc;
2074 softc = (struct da_softc *)periph->softc;
2076 cam_periph_unlock(periph);
2078 cam_iosched_fini(softc->cam_iosched);
2081 * If we can't free the sysctl tree, oh well...
2083 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
2085 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
2086 xpt_print(periph->path,
2087 "can't remove sysctl stats context\n");
2089 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
2090 xpt_print(periph->path,
2091 "can't remove sysctl context\n");
2094 callout_drain(&softc->mediapoll_c);
2095 disk_destroy(softc->disk);
2096 callout_drain(&softc->sendordered_c);
2097 free(softc, M_DEVBUF);
2098 cam_periph_lock(periph);
2102 daasync(void *callback_arg, uint32_t code,
2103 struct cam_path *path, void *arg)
2105 struct cam_periph *periph;
2106 struct da_softc *softc;
2108 periph = (struct cam_periph *)callback_arg;
2110 case AC_FOUND_DEVICE: /* callback to create periph, no locking yet */
2112 struct ccb_getdev *cgd;
2115 cgd = (struct ccb_getdev *)arg;
2119 if (cgd->protocol != PROTO_SCSI)
2121 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
2123 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
2124 && SID_TYPE(&cgd->inq_data) != T_RBC
2125 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
2126 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
2130 * Allocate a peripheral instance for
2131 * this device and start the probe
2134 status = cam_periph_alloc(daregister, daoninvalidate,
2136 "da", CAM_PERIPH_BIO,
2138 AC_FOUND_DEVICE, cgd);
2140 if (status != CAM_REQ_CMP
2141 && status != CAM_REQ_INPROG)
2142 printf("daasync: Unable to attach to new device "
2143 "due to status 0x%x\n", status);
2146 case AC_ADVINFO_CHANGED: /* Doesn't touch periph */
2150 buftype = (uintptr_t)arg;
2151 if (buftype == CDAI_TYPE_PHYS_PATH) {
2152 struct da_softc *softc;
2154 softc = periph->softc;
2155 disk_attr_changed(softc->disk, "GEOM::physpath",
2160 case AC_UNIT_ATTENTION: /* Called for this path: periph locked */
2163 int error_code, sense_key, asc, ascq;
2165 softc = (struct da_softc *)periph->softc;
2166 ccb = (union ccb *)arg;
2169 * Handle all UNIT ATTENTIONs except our own, as they will be
2170 * handled by daerror().
2172 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
2173 scsi_extract_sense_ccb(ccb,
2174 &error_code, &sense_key, &asc, &ascq)) {
2175 if (asc == 0x2A && ascq == 0x09) {
2176 xpt_print(ccb->ccb_h.path,
2177 "Capacity data has changed\n");
2178 cam_periph_assert(periph, MA_OWNED);
2179 softc->flags &= ~DA_FLAG_PROBED;
2181 } else if (asc == 0x28 && ascq == 0x00) {
2182 cam_periph_assert(periph, MA_OWNED);
2183 softc->flags &= ~DA_FLAG_PROBED;
2184 disk_media_changed(softc->disk, M_NOWAIT);
2185 } else if (asc == 0x3F && ascq == 0x03) {
2186 xpt_print(ccb->ccb_h.path,
2187 "INQUIRY data has changed\n");
2188 cam_periph_assert(periph, MA_OWNED);
2189 softc->flags &= ~DA_FLAG_PROBED;
2195 case AC_SCSI_AEN: /* Called for this path: periph locked */
2197 * Appears to be currently unused for SCSI devices, only ata SIMs
2200 cam_periph_assert(periph, MA_OWNED);
2201 softc = (struct da_softc *)periph->softc;
2202 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
2203 (softc->flags & DA_FLAG_TUR_PENDING) == 0) {
2204 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
2205 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
2210 case AC_SENT_BDR: /* Called for this path: periph locked */
2211 case AC_BUS_RESET: /* Called for this path: periph locked */
2213 struct ccb_hdr *ccbh;
2215 cam_periph_assert(periph, MA_OWNED);
2216 softc = (struct da_softc *)periph->softc;
2218 * Don't fail on the expected unit attention
2221 softc->flags |= DA_FLAG_RETRY_UA;
2222 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
2223 ccbh->ccb_state |= DA_CCB_RETRY_UA;
2226 case AC_INQ_CHANGED: /* Called for this path: periph locked */
2227 cam_periph_assert(periph, MA_OWNED);
2228 softc = (struct da_softc *)periph->softc;
2229 softc->flags &= ~DA_FLAG_PROBED;
2235 cam_periph_async(periph, code, path, arg);
2239 dasysctlinit(void *context, int pending)
2241 struct cam_periph *periph;
2242 struct da_softc *softc;
2243 char tmpstr[32], tmpstr2[16];
2244 struct ccb_trans_settings cts;
2246 periph = (struct cam_periph *)context;
2248 * periph was held for us when this task was enqueued
2250 if (periph->flags & CAM_PERIPH_INVALID) {
2251 da_periph_release(periph, DA_REF_SYSCTL);
2255 softc = (struct da_softc *)periph->softc;
2256 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
2257 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
2259 sysctl_ctx_init(&softc->sysctl_ctx);
2260 cam_periph_lock(periph);
2261 softc->flags |= DA_FLAG_SCTX_INIT;
2262 cam_periph_unlock(periph);
2263 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
2264 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
2265 CTLFLAG_RD | CTLFLAG_MPSAFE, 0, tmpstr, "device_index");
2266 if (softc->sysctl_tree == NULL) {
2267 printf("dasysctlinit: unable to allocate sysctl tree\n");
2268 da_periph_release(periph, DA_REF_SYSCTL);
2273 * Now register the sysctl handler, so the user can change the value on
2276 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2277 OID_AUTO, "delete_method",
2278 CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
2279 softc, 0, dadeletemethodsysctl, "A",
2280 "BIO_DELETE execution method");
2281 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2282 OID_AUTO, "delete_max",
2283 CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE,
2284 softc, 0, dadeletemaxsysctl, "Q",
2285 "Maximum BIO_DELETE size");
2286 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2287 OID_AUTO, "minimum_cmd_size",
2288 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
2289 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
2290 "Minimum CDB size");
2291 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2292 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2293 "trim_count", CTLFLAG_RD, &softc->trim_count,
2294 "Total number of unmap/dsm commands sent");
2295 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2296 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2297 "trim_ranges", CTLFLAG_RD, &softc->trim_ranges,
2298 "Total number of ranges in unmap/dsm commands");
2299 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2300 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2301 "trim_lbas", CTLFLAG_RD, &softc->trim_lbas,
2302 "Total lbas in the unmap/dsm commands sent");
2304 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2305 OID_AUTO, "zone_mode",
2306 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
2307 softc, 0, dazonemodesysctl, "A",
2309 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2310 OID_AUTO, "zone_support",
2311 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
2312 softc, 0, dazonesupsysctl, "A",
2314 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2315 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2316 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2317 "Optimal Number of Open Sequential Write Preferred Zones");
2318 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2319 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2320 "optimal_nonseq_zones", CTLFLAG_RD,
2321 &softc->optimal_nonseq_zones,
2322 "Optimal Number of Non-Sequentially Written Sequential Write "
2324 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2325 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2326 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2327 "Maximum Number of Open Sequential Write Required Zones");
2329 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2330 SYSCTL_CHILDREN(softc->sysctl_tree),
2334 &softc->error_inject,
2336 "error_inject leaf");
2338 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2339 SYSCTL_CHILDREN(softc->sysctl_tree),
2345 "DIF protection type");
2347 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2348 OID_AUTO, "flags", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
2349 softc, 0, daflagssysctl, "A",
2351 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2352 OID_AUTO, "rotating", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
2353 &softc->flags, (u_int)DA_FLAG_ROTATING, dabitsysctl, "I",
2354 "Rotating media *DEPRECATED* gone in FreeBSD 15");
2355 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2356 OID_AUTO, "unmapped_io", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
2357 &softc->flags, (u_int)DA_FLAG_UNMAPPEDIO, dabitsysctl, "I",
2358 "Unmapped I/O support *DEPRECATED* gone in FreeBSD 15");
2360 #ifdef CAM_TEST_FAILURE
2361 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2362 OID_AUTO, "invalidate", CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE,
2363 periph, 0, cam_periph_invalidate_sysctl, "I",
2364 "Write 1 to invalidate the drive immediately");
2368 * Add some addressing info.
2370 memset(&cts, 0, sizeof (cts));
2371 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2372 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2373 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2374 cam_periph_lock(periph);
2375 xpt_action((union ccb *)&cts);
2376 cam_periph_unlock(periph);
2377 if (cts.ccb_h.status != CAM_REQ_CMP) {
2378 da_periph_release(periph, DA_REF_SYSCTL);
2381 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2382 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2383 if (fc->valid & CTS_FC_VALID_WWPN) {
2384 softc->wwpn = fc->wwpn;
2385 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2386 SYSCTL_CHILDREN(softc->sysctl_tree),
2387 OID_AUTO, "wwpn", CTLFLAG_RD,
2388 &softc->wwpn, "World Wide Port Name");
2394 * Now add some useful stats.
2395 * XXX These should live in cam_periph and be common to all periphs
2397 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2398 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2399 CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Statistics");
2400 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2401 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2407 "Transport errors reported by the SIM");
2408 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2409 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2415 "Device timeouts reported by the SIM");
2416 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2417 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2419 "pack_invalidations",
2421 &softc->invalidations,
2423 "Device pack invalidations");
2426 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2427 softc->sysctl_tree);
2429 da_periph_release(periph, DA_REF_SYSCTL);
2433 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2437 struct da_softc *softc;
2439 softc = (struct da_softc *)arg1;
2441 value = softc->disk->d_delmaxsize;
2442 error = sysctl_handle_64(oidp, &value, 0, req);
2443 if ((error != 0) || (req->newptr == NULL))
2446 /* only accept values smaller than the calculated value */
2447 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2450 softc->disk->d_delmaxsize = value;
2456 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2460 value = *(int *)arg1;
2462 error = sysctl_handle_int(oidp, &value, 0, req);
2465 || (req->newptr == NULL))
2469 * Acceptable values here are 6, 10, 12 or 16.
2473 else if ((value > 6)
2476 else if ((value > 10)
2479 else if (value > 12)
2482 *(int *)arg1 = value;
2488 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2493 value = da_default_softtimeout / SBT_1MS;
2495 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2496 if ((error != 0) || (req->newptr == NULL))
2499 /* XXX Should clip this to a reasonable level */
2500 if (value > da_default_timeout * 1000)
2503 da_default_softtimeout = value * SBT_1MS;
2508 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2511 softc->delete_method = delete_method;
2512 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2513 softc->delete_func = da_delete_functions[delete_method];
2515 if (softc->delete_method > DA_DELETE_DISABLE)
2516 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2518 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2522 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2526 switch(delete_method) {
2527 case DA_DELETE_UNMAP:
2528 sectors = (off_t)softc->unmap_max_lba;
2530 case DA_DELETE_ATA_TRIM:
2531 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2533 case DA_DELETE_WS16:
2534 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2536 case DA_DELETE_ZERO:
2537 case DA_DELETE_WS10:
2538 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2544 return (off_t)softc->params.secsize *
2545 omin(sectors, softc->params.sectors);
2549 daprobedone(struct cam_periph *periph, union ccb *ccb)
2551 struct da_softc *softc;
2553 softc = (struct da_softc *)periph->softc;
2555 cam_periph_assert(periph, MA_OWNED);
2557 dadeletemethodchoose(softc, DA_DELETE_NONE);
2559 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2563 snprintf(buf, sizeof(buf), "Delete methods: <");
2565 for (i = 0; i <= DA_DELETE_MAX; i++) {
2566 if ((softc->delete_available & (1 << i)) == 0 &&
2567 i != softc->delete_method)
2570 strlcat(buf, ",", sizeof(buf));
2571 strlcat(buf, da_delete_method_names[i],
2573 if (i == softc->delete_method)
2574 strlcat(buf, "(*)", sizeof(buf));
2577 strlcat(buf, ">", sizeof(buf));
2578 printf("%s%d: %s\n", periph->periph_name,
2579 periph->unit_number, buf);
2581 if ((softc->disk->d_flags & DISKFLAG_WRITE_PROTECT) != 0 &&
2582 (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2583 printf("%s%d: Write Protected\n", periph->periph_name,
2584 periph->unit_number);
2588 * Since our peripheral may be invalidated by an error
2589 * above or an external event, we must release our CCB
2590 * before releasing the probe lock on the peripheral.
2591 * The peripheral will only go away once the last lock
2592 * is removed, and we need it around for the CCB release
2595 xpt_release_ccb(ccb);
2596 softc->state = DA_STATE_NORMAL;
2597 softc->flags |= DA_FLAG_PROBED;
2599 wakeup(&softc->disk->d_mediasize);
2600 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2601 softc->flags |= DA_FLAG_ANNOUNCED;
2604 * We'll release this reference once GEOM calls us back via
2605 * dadiskgonecb(), telling us that our provider has been freed.
2607 if (da_periph_acquire(periph, DA_REF_GEOM) == 0)
2608 disk_create(softc->disk, DISK_VERSION);
2610 cam_periph_release_boot(periph);
2612 da_periph_release_locked(periph, DA_REF_REPROBE);
2616 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2620 /* If available, prefer the method requested by user. */
2621 i = softc->delete_method_pref;
2622 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2623 if (methods & (1 << i)) {
2624 dadeletemethodset(softc, i);
2628 /* Use the pre-defined order to choose the best performing delete. */
2629 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2630 if (i == DA_DELETE_ZERO)
2632 if (softc->delete_available & (1 << i)) {
2633 dadeletemethodset(softc, i);
2638 /* Fallback to default. */
2639 dadeletemethodset(softc, default_method);
2643 dabitsysctl(SYSCTL_HANDLER_ARGS)
2645 u_int *flags = arg1;
2649 tmpout = !!(*flags & test);
2650 error = SYSCTL_OUT(req, &tmpout, sizeof(tmpout));
2651 if (error || !req->newptr)
2658 daflagssysctl(SYSCTL_HANDLER_ARGS)
2661 struct da_softc *softc = arg1;
2664 sbuf_new_for_sysctl(&sbuf, NULL, 0, req);
2665 if (softc->flags != 0)
2666 sbuf_printf(&sbuf, "0x%b", (unsigned)softc->flags, DA_FLAG_STRING);
2668 sbuf_printf(&sbuf, "0");
2669 error = sbuf_finish(&sbuf);
2676 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2680 struct da_softc *softc;
2681 int i, error, value;
2683 softc = (struct da_softc *)arg1;
2685 value = softc->delete_method;
2686 if (value < 0 || value > DA_DELETE_MAX)
2689 p = da_delete_method_names[value];
2690 strncpy(buf, p, sizeof(buf));
2691 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2692 if (error != 0 || req->newptr == NULL)
2694 for (i = 0; i <= DA_DELETE_MAX; i++) {
2695 if (strcmp(buf, da_delete_method_names[i]) == 0)
2698 if (i > DA_DELETE_MAX)
2700 softc->delete_method_pref = i;
2701 dadeletemethodchoose(softc, DA_DELETE_NONE);
2706 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2709 struct da_softc *softc;
2712 softc = (struct da_softc *)arg1;
2714 switch (softc->zone_mode) {
2715 case DA_ZONE_DRIVE_MANAGED:
2716 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2718 case DA_ZONE_HOST_AWARE:
2719 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2721 case DA_ZONE_HOST_MANAGED:
2722 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2726 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2730 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2736 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2739 struct da_softc *softc;
2744 softc = (struct da_softc *)arg1;
2748 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2750 for (i = 0; i < sizeof(da_zone_desc_table) /
2751 sizeof(da_zone_desc_table[0]); i++) {
2752 if (softc->zone_flags & da_zone_desc_table[i].value) {
2754 sbuf_printf(&sb, ", ");
2757 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2762 sbuf_printf(&sb, "None");
2766 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2772 daregister(struct cam_periph *periph, void *arg)
2774 struct da_softc *softc;
2775 struct ccb_pathinq cpi;
2776 struct ccb_getdev *cgd;
2781 cgd = (struct ccb_getdev *)arg;
2783 printf("daregister: no getdev CCB, can't register device\n");
2784 return(CAM_REQ_CMP_ERR);
2787 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2790 if (softc == NULL) {
2791 printf("daregister: Unable to probe new device. "
2792 "Unable to allocate softc\n");
2793 return(CAM_REQ_CMP_ERR);
2796 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2797 printf("daregister: Unable to probe new device. "
2798 "Unable to allocate iosched memory\n");
2799 free(softc, M_DEVBUF);
2800 return(CAM_REQ_CMP_ERR);
2803 LIST_INIT(&softc->pending_ccbs);
2804 softc->state = DA_STATE_PROBE_WP;
2805 bioq_init(&softc->delete_run_queue);
2806 if (SID_IS_REMOVABLE(&cgd->inq_data))
2807 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2808 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2809 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2810 softc->unmap_gran = 0;
2811 softc->unmap_gran_align = 0;
2812 softc->ws_max_blks = WS16_MAX_BLKS;
2813 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2814 softc->flags |= DA_FLAG_ROTATING;
2816 periph->softc = softc;
2819 * See if this device has any quirks.
2821 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2822 (caddr_t)da_quirk_table,
2823 nitems(da_quirk_table),
2824 sizeof(*da_quirk_table), scsi_inquiry_match);
2827 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2829 softc->quirks = DA_Q_NONE;
2831 /* Check if the SIM does not want 6 byte commands */
2832 xpt_path_inq(&cpi, periph->path);
2833 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2834 softc->quirks |= DA_Q_NO_6_BYTE;
2836 /* Override quirks if tunable is set */
2837 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.quirks",
2838 periph->unit_number);
2839 quirks = softc->quirks;
2840 TUNABLE_INT_FETCH(tmpstr, &quirks);
2841 softc->quirks = quirks;
2843 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2844 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2845 else if (softc->quirks & DA_Q_SMR_DM)
2846 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2848 softc->zone_mode = DA_ZONE_NONE;
2850 if (softc->zone_mode != DA_ZONE_NONE) {
2851 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2852 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2853 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2855 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2857 softc->zone_interface = DA_ZONE_IF_SCSI;
2860 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2863 * Let XPT know we can use UMA-allocated CCBs.
2865 if (da_enable_uma_ccbs) {
2866 KASSERT(da_ccb_zone != NULL,
2867 ("%s: NULL da_ccb_zone", __func__));
2868 periph->ccb_zone = da_ccb_zone;
2872 * Take a reference on the periph while dastart is called to finish the
2873 * probe. The reference will be dropped in dadone at the end of probe.
2875 (void)da_periph_acquire(periph, DA_REF_REPROBE);
2878 * Schedule a periodic event to occasionally send an
2879 * ordered tag to a device.
2881 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2882 callout_reset_sbt(&softc->sendordered_c,
2883 SBT_1S / DA_ORDEREDTAG_INTERVAL * da_default_timeout, 0,
2884 dasendorderedtag, periph, C_PREL(1));
2886 cam_periph_unlock(periph);
2888 * RBC devices don't have to support READ(6), only READ(10).
2890 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2891 softc->minimum_cmd_size = 10;
2893 softc->minimum_cmd_size = 6;
2896 * Load the user's default, if any.
2898 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2899 periph->unit_number);
2900 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2903 * 6, 10, 12 and 16 are the currently permissible values.
2905 if (softc->minimum_cmd_size > 12)
2906 softc->minimum_cmd_size = 16;
2907 else if (softc->minimum_cmd_size > 10)
2908 softc->minimum_cmd_size = 12;
2909 else if (softc->minimum_cmd_size > 6)
2910 softc->minimum_cmd_size = 10;
2912 softc->minimum_cmd_size = 6;
2914 /* On first PROBE_WP request all more pages, then adjust. */
2915 softc->mode_page = SMS_ALL_PAGES_PAGE;
2917 /* Predict whether device may support READ CAPACITY(16). */
2918 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2919 (softc->quirks & DA_Q_NO_RC16) == 0) {
2920 softc->flags |= DA_FLAG_CAN_RC16;
2924 * Register this media as a disk.
2926 softc->disk = disk_alloc();
2927 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2928 periph->unit_number, 0,
2929 DEVSTAT_BS_UNAVAILABLE,
2930 SID_TYPE(&cgd->inq_data) |
2931 XPORT_DEVSTAT_TYPE(cpi.transport),
2932 DEVSTAT_PRIORITY_DISK);
2933 softc->disk->d_open = daopen;
2934 softc->disk->d_close = daclose;
2935 softc->disk->d_strategy = dastrategy;
2936 if (cam_sim_pollable(periph->sim))
2937 softc->disk->d_dump = dadump;
2938 softc->disk->d_getattr = dagetattr;
2939 softc->disk->d_gone = dadiskgonecb;
2940 softc->disk->d_name = "da";
2941 softc->disk->d_drv1 = periph;
2943 softc->maxio = DFLTPHYS; /* traditional default */
2944 else if (cpi.maxio > maxphys)
2945 softc->maxio = maxphys; /* for safety */
2947 softc->maxio = cpi.maxio;
2948 if (softc->quirks & DA_Q_128KB)
2949 softc->maxio = min(softc->maxio, 128 * 1024);
2950 softc->disk->d_maxsize = softc->maxio;
2951 softc->disk->d_unit = periph->unit_number;
2952 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2953 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2954 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2955 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2956 softc->flags |= DA_FLAG_UNMAPPEDIO;
2957 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2959 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2960 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2961 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2962 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2963 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2964 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2965 softc->disk->d_hba_vendor = cpi.hba_vendor;
2966 softc->disk->d_hba_device = cpi.hba_device;
2967 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2968 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2969 snprintf(softc->disk->d_attachment, sizeof(softc->disk->d_attachment),
2970 "%s%d", cpi.dev_name, cpi.unit_number);
2971 cam_periph_lock(periph);
2974 * Add async callbacks for events of interest.
2975 * I don't bother checking if this fails as,
2976 * in most cases, the system will function just
2977 * fine without them and the only alternative
2978 * would be to not attach the device on failure.
2980 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2981 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2982 AC_INQ_CHANGED, daasync, periph, periph->path);
2985 * Schedule a periodic media polling events.
2987 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2988 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2989 (cgd->inq_flags & SID_AEN) == 0 &&
2990 da_poll_period != 0) {
2991 callout_reset_sbt(&softc->mediapoll_c, da_poll_period * SBT_1S,
2992 0, damediapoll, periph, C_PREL(1));
2995 /* Released after probe when disk_create() call pass it to GEOM. */
2996 cam_periph_hold_boot(periph);
2998 xpt_schedule(periph, CAM_PRIORITY_DEV);
2999 return(CAM_REQ_CMP);
3003 da_zone_bio_to_scsi(int disk_zone_cmd)
3005 switch (disk_zone_cmd) {
3006 case DISK_ZONE_OPEN:
3007 return ZBC_OUT_SA_OPEN;
3008 case DISK_ZONE_CLOSE:
3009 return ZBC_OUT_SA_CLOSE;
3010 case DISK_ZONE_FINISH:
3011 return ZBC_OUT_SA_FINISH;
3013 return ZBC_OUT_SA_RWP;
3020 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
3023 struct da_softc *softc;
3028 if (bp->bio_cmd != BIO_ZONE) {
3033 softc = periph->softc;
3035 switch (bp->bio_zone.zone_cmd) {
3036 case DISK_ZONE_OPEN:
3037 case DISK_ZONE_CLOSE:
3038 case DISK_ZONE_FINISH:
3039 case DISK_ZONE_RWP: {
3044 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
3045 if (zone_sa == -1) {
3046 xpt_print(periph->path, "Cannot translate zone "
3047 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
3053 lba = bp->bio_zone.zone_params.rwp.id;
3055 if (bp->bio_zone.zone_params.rwp.flags &
3056 DISK_ZONE_RWP_FLAG_ALL)
3057 zone_flags |= ZBC_OUT_ALL;
3059 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
3060 scsi_zbc_out(&ccb->csio,
3061 /*retries*/ da_retry_count,
3063 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3064 /*service_action*/ zone_sa,
3066 /*zone_flags*/ zone_flags,
3069 /*sense_len*/ SSD_FULL_SIZE,
3070 /*timeout*/ da_default_timeout * 1000);
3073 * Note that in this case, even though we can
3074 * technically use NCQ, we don't bother for several
3076 * 1. It hasn't been tested on a SAT layer that
3077 * supports it. This is new as of SAT-4.
3078 * 2. Even when there is a SAT layer that supports
3079 * it, that SAT layer will also probably support
3080 * ZBC -> ZAC translation, since they are both
3081 * in the SAT-4 spec.
3082 * 3. Translation will likely be preferable to ATA
3083 * passthrough. LSI / Avago at least single
3084 * steps ATA passthrough commands in the HBA,
3085 * regardless of protocol, so unless that
3086 * changes, there is a performance penalty for
3087 * doing ATA passthrough no matter whether
3088 * you're using NCQ/FPDMA, DMA or PIO.
3089 * 4. It requires a 32-byte CDB, which at least at
3090 * this point in CAM requires a CDB pointer, which
3091 * would require us to allocate an additional bit
3092 * of storage separate from the CCB.
3094 error = scsi_ata_zac_mgmt_out(&ccb->csio,
3095 /*retries*/ da_retry_count,
3097 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3099 /*zm_action*/ zone_sa,
3101 /*zone_flags*/ zone_flags,
3104 /*cdb_storage*/ NULL,
3105 /*cdb_storage_len*/ 0,
3106 /*sense_len*/ SSD_FULL_SIZE,
3107 /*timeout*/ da_default_timeout * 1000);
3110 xpt_print(periph->path,
3111 "scsi_ata_zac_mgmt_out() returned an "
3120 case DISK_ZONE_REPORT_ZONES: {
3122 uint32_t num_entries, alloc_size;
3123 struct disk_zone_report *rep;
3125 rep = &bp->bio_zone.zone_params.report;
3127 num_entries = rep->entries_allocated;
3128 if (num_entries == 0) {
3129 xpt_print(periph->path, "No entries allocated for "
3130 "Report Zones request\n");
3134 alloc_size = sizeof(struct scsi_report_zones_hdr) +
3135 (sizeof(struct scsi_report_zones_desc) * num_entries);
3136 alloc_size = min(alloc_size, softc->disk->d_maxsize);
3137 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
3138 if (rz_ptr == NULL) {
3139 xpt_print(periph->path, "Unable to allocate memory "
3140 "for Report Zones request\n");
3145 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
3146 scsi_zbc_in(&ccb->csio,
3147 /*retries*/ da_retry_count,
3149 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3150 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
3151 /*zone_start_lba*/ rep->starting_id,
3152 /*zone_options*/ rep->rep_options,
3153 /*data_ptr*/ rz_ptr,
3154 /*dxfer_len*/ alloc_size,
3155 /*sense_len*/ SSD_FULL_SIZE,
3156 /*timeout*/ da_default_timeout * 1000);
3159 * Note that in this case, even though we can
3160 * technically use NCQ, we don't bother for several
3162 * 1. It hasn't been tested on a SAT layer that
3163 * supports it. This is new as of SAT-4.
3164 * 2. Even when there is a SAT layer that supports
3165 * it, that SAT layer will also probably support
3166 * ZBC -> ZAC translation, since they are both
3167 * in the SAT-4 spec.
3168 * 3. Translation will likely be preferable to ATA
3169 * passthrough. LSI / Avago at least single
3170 * steps ATA passthrough commands in the HBA,
3171 * regardless of protocol, so unless that
3172 * changes, there is a performance penalty for
3173 * doing ATA passthrough no matter whether
3174 * you're using NCQ/FPDMA, DMA or PIO.
3175 * 4. It requires a 32-byte CDB, which at least at
3176 * this point in CAM requires a CDB pointer, which
3177 * would require us to allocate an additional bit
3178 * of storage separate from the CCB.
3180 error = scsi_ata_zac_mgmt_in(&ccb->csio,
3181 /*retries*/ da_retry_count,
3183 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3185 /*zm_action*/ ATA_ZM_REPORT_ZONES,
3186 /*zone_id*/ rep->starting_id,
3187 /*zone_flags*/ rep->rep_options,
3188 /*data_ptr*/ rz_ptr,
3189 /*dxfer_len*/ alloc_size,
3190 /*cdb_storage*/ NULL,
3191 /*cdb_storage_len*/ 0,
3192 /*sense_len*/ SSD_FULL_SIZE,
3193 /*timeout*/ da_default_timeout * 1000);
3196 xpt_print(periph->path,
3197 "scsi_ata_zac_mgmt_in() returned an "
3204 * For BIO_ZONE, this isn't normally needed. However, it
3205 * is used by devstat_end_transaction_bio() to determine
3206 * how much data was transferred.
3209 * XXX KDM we have a problem. But I'm not sure how to fix
3210 * it. devstat uses bio_bcount - bio_resid to calculate
3211 * the amount of data transferred. The GEOM disk code
3212 * uses bio_length - bio_resid to calculate the amount of
3213 * data in bio_completed. We have different structure
3214 * sizes above and below the ada(4) driver. So, if we
3215 * use the sizes above, the amount transferred won't be
3216 * quite accurate for devstat. If we use different sizes
3217 * for bio_bcount and bio_length (above and below
3218 * respectively), then the residual needs to match one or
3219 * the other. Everything is calculated after the bio
3220 * leaves the driver, so changing the values around isn't
3221 * really an option. For now, just set the count to the
3222 * passed in length. This means that the calculations
3223 * above (e.g. bio_completed) will be correct, but the
3224 * amount of data reported to devstat will be slightly
3225 * under or overstated.
3227 bp->bio_bcount = bp->bio_length;
3233 case DISK_ZONE_GET_PARAMS: {
3234 struct disk_zone_disk_params *params;
3236 params = &bp->bio_zone.zone_params.disk_params;
3237 bzero(params, sizeof(*params));
3239 switch (softc->zone_mode) {
3240 case DA_ZONE_DRIVE_MANAGED:
3241 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
3243 case DA_ZONE_HOST_AWARE:
3244 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
3246 case DA_ZONE_HOST_MANAGED:
3247 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
3251 params->zone_mode = DISK_ZONE_MODE_NONE;
3255 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
3256 params->flags |= DISK_ZONE_DISK_URSWRZ;
3258 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
3259 params->optimal_seq_zones = softc->optimal_seq_zones;
3260 params->flags |= DISK_ZONE_OPT_SEQ_SET;
3263 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
3264 params->optimal_nonseq_zones =
3265 softc->optimal_nonseq_zones;
3266 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
3269 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
3270 params->max_seq_zones = softc->max_seq_zones;
3271 params->flags |= DISK_ZONE_MAX_SEQ_SET;
3273 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
3274 params->flags |= DISK_ZONE_RZ_SUP;
3276 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
3277 params->flags |= DISK_ZONE_OPEN_SUP;
3279 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
3280 params->flags |= DISK_ZONE_CLOSE_SUP;
3282 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
3283 params->flags |= DISK_ZONE_FINISH_SUP;
3285 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
3286 params->flags |= DISK_ZONE_RWP_SUP;
3297 dastart(struct cam_periph *periph, union ccb *start_ccb)
3299 struct da_softc *softc;
3301 cam_periph_assert(periph, MA_OWNED);
3302 softc = (struct da_softc *)periph->softc;
3304 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
3307 switch (softc->state) {
3308 case DA_STATE_NORMAL:
3314 bp = cam_iosched_next_bio(softc->cam_iosched);
3316 if (cam_iosched_has_work_flags(softc->cam_iosched,
3318 softc->flags |= DA_FLAG_TUR_PENDING;
3319 cam_iosched_clr_work_flags(softc->cam_iosched,
3321 scsi_test_unit_ready(&start_ccb->csio,
3322 /*retries*/ da_retry_count,
3326 da_default_timeout * 1000);
3327 start_ccb->ccb_h.ccb_bp = NULL;
3328 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
3329 xpt_action(start_ccb);
3331 xpt_release_ccb(start_ccb);
3335 if (bp->bio_cmd == BIO_DELETE) {
3336 if (softc->delete_func != NULL) {
3337 softc->delete_func(periph, start_ccb, bp);
3341 * Not sure this is possible, but failsafe by
3342 * lying and saying "sure, done."
3344 biofinish(bp, NULL, 0);
3349 if (cam_iosched_has_work_flags(softc->cam_iosched,
3351 cam_iosched_clr_work_flags(softc->cam_iosched,
3353 da_periph_release_locked(periph, DA_REF_TUR);
3356 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
3357 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
3358 softc->flags &= ~DA_FLAG_NEED_OTAG;
3359 softc->flags |= DA_FLAG_WAS_OTAG;
3360 tag_code = MSG_ORDERED_Q_TAG;
3362 tag_code = MSG_SIMPLE_Q_TAG;
3365 switch (bp->bio_cmd) {
3372 biotrack(bp, __func__);
3374 if (bp->bio_cmd == BIO_WRITE) {
3375 softc->flags |= DA_FLAG_DIRTY;
3376 rw_op = SCSI_RW_WRITE;
3378 rw_op = SCSI_RW_READ;
3381 data_ptr = bp->bio_data;
3382 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
3383 rw_op |= SCSI_RW_BIO;
3387 scsi_read_write(&start_ccb->csio,
3388 /*retries*/da_retry_count,
3390 /*tag_action*/tag_code,
3393 softc->minimum_cmd_size,
3394 /*lba*/bp->bio_pblkno,
3395 /*block_count*/bp->bio_bcount /
3396 softc->params.secsize,
3398 /*dxfer_len*/ bp->bio_bcount,
3399 /*sense_len*/SSD_FULL_SIZE,
3400 da_default_timeout * 1000);
3401 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3402 start_ccb->csio.bio = bp;
3408 * If we don't support sync cache, or the disk
3409 * isn't dirty, FLUSH is a no-op. Use the
3410 * allocated CCB for the next bio if one is
3413 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) != 0 ||
3414 (softc->flags & DA_FLAG_DIRTY) == 0) {
3420 * BIO_FLUSH doesn't currently communicate
3421 * range data, so we synchronize the cache
3422 * over the whole disk.
3424 scsi_synchronize_cache(&start_ccb->csio,
3427 /*tag_action*/tag_code,
3431 da_default_timeout*1000);
3433 * Clear the dirty flag before sending the command.
3434 * Either this sync cache will be successful, or it
3435 * will fail after a retry. If it fails, it is
3436 * unlikely to be successful if retried later, so
3437 * we'll save ourselves time by just marking the
3440 softc->flags &= ~DA_FLAG_DIRTY;
3443 int error, queue_ccb;
3447 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3449 || (queue_ccb == 0)) {
3450 biofinish(bp, NULL, error);
3451 xpt_release_ccb(start_ccb);
3457 biofinish(bp, NULL, EOPNOTSUPP);
3458 xpt_release_ccb(start_ccb);
3461 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3462 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3463 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3466 LIST_INSERT_HEAD(&softc->pending_ccbs,
3467 &start_ccb->ccb_h, periph_links.le);
3469 /* We expect a unit attention from this device */
3470 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3471 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3472 softc->flags &= ~DA_FLAG_RETRY_UA;
3475 start_ccb->ccb_h.ccb_bp = bp;
3477 cam_periph_unlock(periph);
3478 xpt_action(start_ccb);
3479 cam_periph_lock(periph);
3481 /* May have more work to do, so ensure we stay scheduled */
3485 case DA_STATE_PROBE_WP:
3490 if (da_disable_wp_detection || softc->mode_page < 0) {
3491 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3492 softc->state = DA_STATE_PROBE_RC16;
3494 softc->state = DA_STATE_PROBE_RC;
3498 mode_buf = malloc(mode_buf_len, M_SCSIDA, M_NOWAIT);
3499 if (mode_buf == NULL) {
3500 xpt_print(periph->path, "Unable to send mode sense - "
3501 "malloc failure\n");
3502 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
3503 softc->state = DA_STATE_PROBE_RC16;
3505 softc->state = DA_STATE_PROBE_RC;
3508 scsi_mode_sense_len(&start_ccb->csio,
3509 /*retries*/ da_retry_count,
3510 /*cbfcnp*/ dadone_probewp,
3511 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3513 /*pc*/ SMS_PAGE_CTRL_CURRENT,
3514 /*page*/ softc->mode_page,
3515 /*param_buf*/ mode_buf,
3516 /*param_len*/ mode_buf_len,
3517 /*minimum_cmd_size*/ softc->minimum_cmd_size,
3518 /*sense_len*/ SSD_FULL_SIZE,
3519 /*timeout*/ da_default_timeout * 1000);
3520 start_ccb->ccb_h.ccb_bp = NULL;
3521 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_WP;
3522 xpt_action(start_ccb);
3525 case DA_STATE_PROBE_RC:
3527 struct scsi_read_capacity_data *rcap;
3529 rcap = (struct scsi_read_capacity_data *)
3530 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3532 printf("dastart: Couldn't malloc read_capacity data\n");
3533 /* da_free_periph??? */
3536 scsi_read_capacity(&start_ccb->csio,
3537 /*retries*/da_retry_count,
3543 start_ccb->ccb_h.ccb_bp = NULL;
3544 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3545 xpt_action(start_ccb);
3548 case DA_STATE_PROBE_RC16:
3550 struct scsi_read_capacity_data_long *rcaplong;
3552 rcaplong = (struct scsi_read_capacity_data_long *)
3553 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3554 if (rcaplong == NULL) {
3555 printf("dastart: Couldn't malloc read_capacity data\n");
3556 /* da_free_periph??? */
3559 scsi_read_capacity_16(&start_ccb->csio,
3560 /*retries*/ da_retry_count,
3561 /*cbfcnp*/ dadone_proberc,
3562 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3566 /*rcap_buf*/ (uint8_t *)rcaplong,
3567 /*rcap_buf_len*/ sizeof(*rcaplong),
3568 /*sense_len*/ SSD_FULL_SIZE,
3569 /*timeout*/ da_default_timeout * 1000);
3570 start_ccb->ccb_h.ccb_bp = NULL;
3571 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3572 xpt_action(start_ccb);
3575 case DA_STATE_PROBE_LBP:
3577 struct scsi_vpd_logical_block_prov *lbp;
3579 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3581 * If we get here we don't support any SBC-3 delete
3582 * methods with UNMAP as the Logical Block Provisioning
3583 * VPD page support is required for devices which
3584 * support it according to T10/1799-D Revision 31
3585 * however older revisions of the spec don't mandate
3586 * this so we currently don't remove these methods
3587 * from the available set.
3589 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3593 lbp = (struct scsi_vpd_logical_block_prov *)
3594 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3597 printf("dastart: Couldn't malloc lbp data\n");
3598 /* da_free_periph??? */
3602 scsi_inquiry(&start_ccb->csio,
3603 /*retries*/da_retry_count,
3604 /*cbfcnp*/dadone_probelbp,
3605 /*tag_action*/MSG_SIMPLE_Q_TAG,
3606 /*inq_buf*/(uint8_t *)lbp,
3607 /*inq_len*/sizeof(*lbp),
3609 /*page_code*/SVPD_LBP,
3610 /*sense_len*/SSD_MIN_SIZE,
3611 /*timeout*/da_default_timeout * 1000);
3612 start_ccb->ccb_h.ccb_bp = NULL;
3613 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3614 xpt_action(start_ccb);
3617 case DA_STATE_PROBE_BLK_LIMITS:
3619 struct scsi_vpd_block_limits *block_limits;
3621 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3622 /* Not supported skip to next probe */
3623 softc->state = DA_STATE_PROBE_BDC;
3627 block_limits = (struct scsi_vpd_block_limits *)
3628 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3630 if (block_limits == NULL) {
3631 printf("dastart: Couldn't malloc block_limits data\n");
3632 /* da_free_periph??? */
3636 scsi_inquiry(&start_ccb->csio,
3637 /*retries*/da_retry_count,
3638 /*cbfcnp*/dadone_probeblklimits,
3639 /*tag_action*/MSG_SIMPLE_Q_TAG,
3640 /*inq_buf*/(uint8_t *)block_limits,
3641 /*inq_len*/sizeof(*block_limits),
3643 /*page_code*/SVPD_BLOCK_LIMITS,
3644 /*sense_len*/SSD_MIN_SIZE,
3645 /*timeout*/da_default_timeout * 1000);
3646 start_ccb->ccb_h.ccb_bp = NULL;
3647 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3648 xpt_action(start_ccb);
3651 case DA_STATE_PROBE_BDC:
3653 struct scsi_vpd_block_device_characteristics *bdc;
3655 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3656 softc->state = DA_STATE_PROBE_ATA;
3660 bdc = (struct scsi_vpd_block_device_characteristics *)
3661 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3664 printf("dastart: Couldn't malloc bdc data\n");
3665 /* da_free_periph??? */
3669 scsi_inquiry(&start_ccb->csio,
3670 /*retries*/da_retry_count,
3671 /*cbfcnp*/dadone_probebdc,
3672 /*tag_action*/MSG_SIMPLE_Q_TAG,
3673 /*inq_buf*/(uint8_t *)bdc,
3674 /*inq_len*/sizeof(*bdc),
3676 /*page_code*/SVPD_BDC,
3677 /*sense_len*/SSD_MIN_SIZE,
3678 /*timeout*/da_default_timeout * 1000);
3679 start_ccb->ccb_h.ccb_bp = NULL;
3680 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3681 xpt_action(start_ccb);
3684 case DA_STATE_PROBE_ATA:
3686 struct ata_params *ata_params;
3688 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3689 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3690 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3692 * Note that if the ATA VPD page isn't
3693 * supported, we aren't talking to an ATA
3694 * device anyway. Support for that VPD
3695 * page is mandatory for SCSI to ATA (SAT)
3696 * translation layers.
3698 softc->state = DA_STATE_PROBE_ZONE;
3701 daprobedone(periph, start_ccb);
3705 ata_params = &periph->path->device->ident_data;
3707 scsi_ata_identify(&start_ccb->csio,
3708 /*retries*/da_retry_count,
3709 /*cbfcnp*/dadone_probeata,
3710 /*tag_action*/MSG_SIMPLE_Q_TAG,
3711 /*data_ptr*/(uint8_t *)ata_params,
3712 /*dxfer_len*/sizeof(*ata_params),
3713 /*sense_len*/SSD_FULL_SIZE,
3714 /*timeout*/da_default_timeout * 1000);
3715 start_ccb->ccb_h.ccb_bp = NULL;
3716 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3717 xpt_action(start_ccb);
3720 case DA_STATE_PROBE_ATA_LOGDIR:
3722 struct ata_gp_log_dir *log_dir;
3727 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3729 * If we don't have log support, not much point in
3730 * trying to probe zone support.
3732 daprobedone(periph, start_ccb);
3737 * If we have an ATA device (the SCSI ATA Information VPD
3738 * page should be present and the ATA identify should have
3739 * succeeded) and it supports logs, ask for the log directory.
3742 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3743 if (log_dir == NULL) {
3744 xpt_print(periph->path, "Couldn't malloc log_dir "
3746 daprobedone(periph, start_ccb);
3750 retval = scsi_ata_read_log(&start_ccb->csio,
3751 /*retries*/ da_retry_count,
3752 /*cbfcnp*/ dadone_probeatalogdir,
3753 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3754 /*log_address*/ ATA_LOG_DIRECTORY,
3757 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3758 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3759 /*data_ptr*/ (uint8_t *)log_dir,
3760 /*dxfer_len*/ sizeof(*log_dir),
3761 /*sense_len*/ SSD_FULL_SIZE,
3762 /*timeout*/ da_default_timeout * 1000);
3765 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3766 free(log_dir, M_SCSIDA);
3767 daprobedone(periph, start_ccb);
3770 start_ccb->ccb_h.ccb_bp = NULL;
3771 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3772 xpt_action(start_ccb);
3775 case DA_STATE_PROBE_ATA_IDDIR:
3777 struct ata_identify_log_pages *id_dir;
3783 * Check here to see whether the Identify Device log is
3784 * supported in the directory of logs. If so, continue
3785 * with requesting the log of identify device pages.
3787 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3788 daprobedone(periph, start_ccb);
3792 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3793 if (id_dir == NULL) {
3794 xpt_print(periph->path, "Couldn't malloc id_dir "
3796 daprobedone(periph, start_ccb);
3800 retval = scsi_ata_read_log(&start_ccb->csio,
3801 /*retries*/ da_retry_count,
3802 /*cbfcnp*/ dadone_probeataiddir,
3803 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3804 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3805 /*page_number*/ ATA_IDL_PAGE_LIST,
3807 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3808 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3809 /*data_ptr*/ (uint8_t *)id_dir,
3810 /*dxfer_len*/ sizeof(*id_dir),
3811 /*sense_len*/ SSD_FULL_SIZE,
3812 /*timeout*/ da_default_timeout * 1000);
3815 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3816 free(id_dir, M_SCSIDA);
3817 daprobedone(periph, start_ccb);
3820 start_ccb->ccb_h.ccb_bp = NULL;
3821 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3822 xpt_action(start_ccb);
3825 case DA_STATE_PROBE_ATA_SUP:
3827 struct ata_identify_log_sup_cap *sup_cap;
3833 * Check here to see whether the Supported Capabilities log
3834 * is in the list of Identify Device logs.
3836 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3837 daprobedone(periph, start_ccb);
3841 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3842 if (sup_cap == NULL) {
3843 xpt_print(periph->path, "Couldn't malloc sup_cap "
3845 daprobedone(periph, start_ccb);
3849 retval = scsi_ata_read_log(&start_ccb->csio,
3850 /*retries*/ da_retry_count,
3851 /*cbfcnp*/ dadone_probeatasup,
3852 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3853 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3854 /*page_number*/ ATA_IDL_SUP_CAP,
3856 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3857 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3858 /*data_ptr*/ (uint8_t *)sup_cap,
3859 /*dxfer_len*/ sizeof(*sup_cap),
3860 /*sense_len*/ SSD_FULL_SIZE,
3861 /*timeout*/ da_default_timeout * 1000);
3864 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3865 free(sup_cap, M_SCSIDA);
3866 daprobedone(periph, start_ccb);
3870 start_ccb->ccb_h.ccb_bp = NULL;
3871 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3872 xpt_action(start_ccb);
3875 case DA_STATE_PROBE_ATA_ZONE:
3877 struct ata_zoned_info_log *ata_zone;
3883 * Check here to see whether the zoned device information
3884 * page is supported. If so, continue on to request it.
3885 * If not, skip to DA_STATE_PROBE_LOG or done.
3887 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3888 daprobedone(periph, start_ccb);
3891 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3893 if (ata_zone == NULL) {
3894 xpt_print(periph->path, "Couldn't malloc ata_zone "
3896 daprobedone(periph, start_ccb);
3900 retval = scsi_ata_read_log(&start_ccb->csio,
3901 /*retries*/ da_retry_count,
3902 /*cbfcnp*/ dadone_probeatazone,
3903 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3904 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3905 /*page_number*/ ATA_IDL_ZDI,
3907 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3908 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3909 /*data_ptr*/ (uint8_t *)ata_zone,
3910 /*dxfer_len*/ sizeof(*ata_zone),
3911 /*sense_len*/ SSD_FULL_SIZE,
3912 /*timeout*/ da_default_timeout * 1000);
3915 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3916 free(ata_zone, M_SCSIDA);
3917 daprobedone(periph, start_ccb);
3920 start_ccb->ccb_h.ccb_bp = NULL;
3921 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3922 xpt_action(start_ccb);
3926 case DA_STATE_PROBE_ZONE:
3928 struct scsi_vpd_zoned_bdc *bdc;
3931 * Note that this page will be supported for SCSI protocol
3932 * devices that support ZBC (SMR devices), as well as ATA
3933 * protocol devices that are behind a SAT (SCSI to ATA
3934 * Translation) layer that supports converting ZBC commands
3935 * to their ZAC equivalents.
3937 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3938 daprobedone(periph, start_ccb);
3941 bdc = (struct scsi_vpd_zoned_bdc *)
3942 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3945 xpt_release_ccb(start_ccb);
3946 xpt_print(periph->path, "Couldn't malloc zone VPD "
3950 scsi_inquiry(&start_ccb->csio,
3951 /*retries*/da_retry_count,
3952 /*cbfcnp*/dadone_probezone,
3953 /*tag_action*/MSG_SIMPLE_Q_TAG,
3954 /*inq_buf*/(uint8_t *)bdc,
3955 /*inq_len*/sizeof(*bdc),
3957 /*page_code*/SVPD_ZONED_BDC,
3958 /*sense_len*/SSD_FULL_SIZE,
3959 /*timeout*/da_default_timeout * 1000);
3960 start_ccb->ccb_h.ccb_bp = NULL;
3961 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3962 xpt_action(start_ccb);
3969 * In each of the methods below, while its the caller's
3970 * responsibility to ensure the request will fit into a
3971 * single device request, we might have changed the delete
3972 * method due to the device incorrectly advertising either
3973 * its supported methods or limits.
3975 * To prevent this causing further issues we validate the
3976 * against the methods limits, and warn which would
3977 * otherwise be unnecessary.
3980 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3982 struct da_softc *softc = (struct da_softc *)periph->softc;
3984 uint8_t *buf = softc->unmap_buf;
3985 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3986 uint64_t lba, lastlba = (uint64_t)-1;
3987 uint64_t totalcount = 0;
3989 uint32_t c, lastcount = 0, ranges = 0;
3992 * Currently this doesn't take the UNMAP
3993 * Granularity and Granularity Alignment
3994 * fields into account.
3996 * This could result in both unoptimal unmap
3997 * requests as as well as UNMAP calls unmapping
3998 * fewer LBA's than requested.
4001 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
4005 * Note: ada and da are different in how they store the
4006 * pending bp's in a trim. ada stores all of them in the
4007 * trim_req.bps. da stores all but the first one in the
4008 * delete_run_queue. ada then completes all the bps in
4009 * its adadone() loop. da completes all the bps in the
4010 * delete_run_queue in dadone, and relies on the biodone
4011 * after to complete. This should be reconciled since there's
4012 * no real reason to do it differently. XXX
4015 bioq_insert_tail(&softc->delete_run_queue, bp1);
4016 lba = bp1->bio_pblkno;
4017 count = bp1->bio_bcount / softc->params.secsize;
4019 /* Try to extend the previous range. */
4020 if (lba == lastlba) {
4021 c = omin(count, UNMAP_RANGE_MAX - lastcount);
4024 scsi_ulto4b(lastcount, d[ranges - 1].length);
4028 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
4029 softc->unmap_gran != 0) {
4030 /* Align length of the previous range. */
4031 if ((c = lastcount % softc->unmap_gran) != 0) {
4032 if (lastcount <= c) {
4033 totalcount -= lastcount;
4034 lastlba = (uint64_t)-1;
4041 scsi_ulto4b(lastcount,
4042 d[ranges - 1].length);
4045 /* Align beginning of the new range. */
4046 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
4048 c = softc->unmap_gran - c;
4059 c = omin(count, UNMAP_RANGE_MAX);
4060 if (totalcount + c > softc->unmap_max_lba ||
4061 ranges >= softc->unmap_max_ranges) {
4062 xpt_print(periph->path,
4063 "%s issuing short delete %ld > %ld"
4065 da_delete_method_desc[softc->delete_method],
4066 totalcount + c, softc->unmap_max_lba,
4067 ranges, softc->unmap_max_ranges);
4070 scsi_u64to8b(lba, d[ranges].lba);
4071 scsi_ulto4b(c, d[ranges].length);
4079 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4082 if (ranges >= softc->unmap_max_ranges ||
4083 totalcount + bp1->bio_bcount /
4084 softc->params.secsize > softc->unmap_max_lba) {
4085 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4090 /* Align length of the last range. */
4091 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
4092 (c = lastcount % softc->unmap_gran) != 0) {
4096 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
4099 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
4100 scsi_ulto2b(ranges * 16, &buf[2]);
4102 scsi_unmap(&ccb->csio,
4103 /*retries*/da_retry_count,
4105 /*tag_action*/MSG_SIMPLE_Q_TAG,
4108 /*dxfer_len*/ ranges * 16 + 8,
4109 /*sense_len*/SSD_FULL_SIZE,
4110 da_default_timeout * 1000);
4111 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4112 ccb->ccb_h.flags |= CAM_UNLOCKED;
4113 softc->trim_count++;
4114 softc->trim_ranges += ranges;
4115 softc->trim_lbas += totalcount;
4116 cam_iosched_submit_trim(softc->cam_iosched);
4120 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4122 struct da_softc *softc = (struct da_softc *)periph->softc;
4124 uint8_t *buf = softc->unmap_buf;
4125 uint64_t lastlba = (uint64_t)-1;
4128 uint32_t lastcount = 0, c, requestcount;
4129 int ranges = 0, off, block_count;
4131 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
4134 if (bp1 != bp)//XXX imp XXX
4135 bioq_insert_tail(&softc->delete_run_queue, bp1);
4136 lba = bp1->bio_pblkno;
4137 count = bp1->bio_bcount / softc->params.secsize;
4138 requestcount = count;
4140 /* Try to extend the previous range. */
4141 if (lba == lastlba) {
4142 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
4144 off = (ranges - 1) * 8;
4145 buf[off + 6] = lastcount & 0xff;
4146 buf[off + 7] = (lastcount >> 8) & 0xff;
4152 c = omin(count, ATA_DSM_RANGE_MAX);
4155 buf[off + 0] = lba & 0xff;
4156 buf[off + 1] = (lba >> 8) & 0xff;
4157 buf[off + 2] = (lba >> 16) & 0xff;
4158 buf[off + 3] = (lba >> 24) & 0xff;
4159 buf[off + 4] = (lba >> 32) & 0xff;
4160 buf[off + 5] = (lba >> 40) & 0xff;
4161 buf[off + 6] = c & 0xff;
4162 buf[off + 7] = (c >> 8) & 0xff;
4167 if (count != 0 && ranges == softc->trim_max_ranges) {
4168 xpt_print(periph->path,
4169 "%s issuing short delete %ld > %ld\n",
4170 da_delete_method_desc[softc->delete_method],
4172 (softc->trim_max_ranges - ranges) *
4178 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4181 if (bp1->bio_bcount / softc->params.secsize >
4182 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
4183 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4188 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
4189 scsi_ata_trim(&ccb->csio,
4190 /*retries*/da_retry_count,
4192 /*tag_action*/MSG_SIMPLE_Q_TAG,
4195 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
4196 /*sense_len*/SSD_FULL_SIZE,
4197 da_default_timeout * 1000);
4198 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4199 ccb->ccb_h.flags |= CAM_UNLOCKED;
4200 cam_iosched_submit_trim(softc->cam_iosched);
4204 * We calculate ws_max_blks here based off d_delmaxsize instead
4205 * of using softc->ws_max_blks as it is absolute max for the
4206 * device not the protocol max which may well be lower.
4209 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
4211 struct da_softc *softc;
4213 uint64_t ws_max_blks;
4215 uint64_t count; /* forward compat with WS32 */
4217 softc = (struct da_softc *)periph->softc;
4218 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
4219 lba = bp->bio_pblkno;
4223 if (bp1 != bp)//XXX imp XXX
4224 bioq_insert_tail(&softc->delete_run_queue, bp1);
4225 count += bp1->bio_bcount / softc->params.secsize;
4226 if (count > ws_max_blks) {
4227 xpt_print(periph->path,
4228 "%s issuing short delete %ld > %ld\n",
4229 da_delete_method_desc[softc->delete_method],
4230 count, ws_max_blks);
4231 count = omin(count, ws_max_blks);
4234 bp1 = cam_iosched_next_trim(softc->cam_iosched);
4237 if (lba + count != bp1->bio_pblkno ||
4238 count + bp1->bio_bcount /
4239 softc->params.secsize > ws_max_blks) {
4240 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
4245 scsi_write_same(&ccb->csio,
4246 /*retries*/da_retry_count,
4248 /*tag_action*/MSG_SIMPLE_Q_TAG,
4249 /*byte2*/softc->delete_method ==
4250 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
4251 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
4253 /*block_count*/count,
4254 /*data_ptr*/ __DECONST(void *, zero_region),
4255 /*dxfer_len*/ softc->params.secsize,
4256 /*sense_len*/SSD_FULL_SIZE,
4257 da_default_timeout * 1000);
4258 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
4259 ccb->ccb_h.flags |= CAM_UNLOCKED;
4260 cam_iosched_submit_trim(softc->cam_iosched);
4264 cmd6workaround(union ccb *ccb)
4266 struct scsi_rw_6 cmd6;
4267 struct scsi_rw_10 *cmd10;
4268 struct da_softc *softc;
4273 cdb = ccb->csio.cdb_io.cdb_bytes;
4274 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
4276 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
4277 da_delete_methods old_method = softc->delete_method;
4280 * Typically there are two reasons for failure here
4281 * 1. Delete method was detected as supported but isn't
4282 * 2. Delete failed due to invalid params e.g. too big
4284 * While we will attempt to choose an alternative delete method
4285 * this may result in short deletes if the existing delete
4286 * requests from geom are big for the new method chosen.
4288 * This method assumes that the error which triggered this
4289 * will not retry the io otherwise a panic will occur
4291 dadeleteflag(softc, old_method, 0);
4292 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
4293 if (softc->delete_method == DA_DELETE_DISABLE)
4294 xpt_print(ccb->ccb_h.path,
4295 "%s failed, disabling BIO_DELETE\n",
4296 da_delete_method_desc[old_method]);
4298 xpt_print(ccb->ccb_h.path,
4299 "%s failed, switching to %s BIO_DELETE\n",
4300 da_delete_method_desc[old_method],
4301 da_delete_method_desc[softc->delete_method]);
4303 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
4304 cam_iosched_queue_work(softc->cam_iosched, bp);
4305 cam_iosched_queue_work(softc->cam_iosched,
4306 (struct bio *)ccb->ccb_h.ccb_bp);
4307 ccb->ccb_h.ccb_bp = NULL;
4311 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
4312 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4313 (*cdb == PREVENT_ALLOW) &&
4314 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
4316 xpt_print(ccb->ccb_h.path,
4317 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
4318 softc->quirks |= DA_Q_NO_PREVENT;
4322 /* Detect unsupported SYNCHRONIZE CACHE(10). */
4323 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
4324 (*cdb == SYNCHRONIZE_CACHE) &&
4325 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
4327 xpt_print(ccb->ccb_h.path,
4328 "SYNCHRONIZE CACHE(10) not supported.\n");
4329 softc->quirks |= DA_Q_NO_SYNC_CACHE;
4330 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
4334 /* Translation only possible if CDB is an array and cmd is R/W6 */
4335 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
4336 (*cdb != READ_6 && *cdb != WRITE_6))
4339 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
4340 "increasing minimum_cmd_size to 10.\n");
4341 softc->minimum_cmd_size = 10;
4343 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
4344 cmd10 = (struct scsi_rw_10 *)cdb;
4345 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
4347 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
4348 cmd10->reserved = 0;
4349 scsi_ulto2b(cmd6.length, cmd10->length);
4350 cmd10->control = cmd6.control;
4351 ccb->csio.cdb_len = sizeof(*cmd10);
4353 /* Requeue request, unfreezing queue if necessary */
4354 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
4355 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4358 cam_release_devq(ccb->ccb_h.path,
4362 /*getcount_only*/0);
4368 dazonedone(struct cam_periph *periph, union ccb *ccb)
4370 struct da_softc *softc;
4373 softc = periph->softc;
4374 bp = (struct bio *)ccb->ccb_h.ccb_bp;
4376 switch (bp->bio_zone.zone_cmd) {
4377 case DISK_ZONE_OPEN:
4378 case DISK_ZONE_CLOSE:
4379 case DISK_ZONE_FINISH:
4382 case DISK_ZONE_REPORT_ZONES: {
4384 struct disk_zone_report *rep;
4385 struct scsi_report_zones_hdr *hdr;
4386 struct scsi_report_zones_desc *desc;
4387 struct disk_zone_rep_entry *entry;
4388 uint32_t hdr_len, num_avail;
4389 uint32_t num_to_fill, i;
4392 rep = &bp->bio_zone.zone_params.report;
4393 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
4395 * Note that bio_resid isn't normally used for zone
4396 * commands, but it is used by devstat_end_transaction_bio()
4397 * to determine how much data was transferred. Because
4398 * the size of the SCSI/ATA data structures is different
4399 * than the size of the BIO interface structures, the
4400 * amount of data actually transferred from the drive will
4401 * be different than the amount of data transferred to
4404 bp->bio_resid = ccb->csio.resid;
4405 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
4406 if (avail_len < sizeof(*hdr)) {
4408 * Is there a better error than EIO here? We asked
4409 * for at least the header, and we got less than
4412 bp->bio_error = EIO;
4413 bp->bio_flags |= BIO_ERROR;
4414 bp->bio_resid = bp->bio_bcount;
4418 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
4423 hdr_len = ata ? le32dec(hdr->length) :
4424 scsi_4btoul(hdr->length);
4426 rep->entries_available = hdr_len / sizeof(*desc);
4428 rep->entries_available = 0;
4430 * NOTE: using the same values for the BIO version of the
4431 * same field as the SCSI/ATA values. This means we could
4432 * get some additional values that aren't defined in bio.h
4433 * if more values of the same field are defined later.
4435 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4436 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4437 scsi_8btou64(hdr->maximum_lba);
4439 * If the drive reports no entries that match the query,
4443 rep->entries_filled = 0;
4447 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4448 hdr_len / sizeof(*desc));
4450 * If the drive didn't return any data, then we're done.
4452 if (num_avail == 0) {
4453 rep->entries_filled = 0;
4457 num_to_fill = min(num_avail, rep->entries_allocated);
4459 * If the user didn't allocate any entries for us to fill,
4462 if (num_to_fill == 0) {
4463 rep->entries_filled = 0;
4467 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4468 i < num_to_fill; i++, desc++, entry++) {
4470 * NOTE: we're mapping the values here directly
4471 * from the SCSI/ATA bit definitions to the bio.h
4472 * definitions. There is also a warning in
4473 * disk_zone.h, but the impact is that if
4474 * additional values are added in the SCSI/ATA
4475 * specs these will be visible to consumers of
4478 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4479 entry->zone_condition =
4480 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4481 SRZ_ZONE_COND_SHIFT;
4482 entry->zone_flags |= desc->zone_flags &
4483 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4484 entry->zone_length =
4485 ata ? le64dec(desc->zone_length) :
4486 scsi_8btou64(desc->zone_length);
4487 entry->zone_start_lba =
4488 ata ? le64dec(desc->zone_start_lba) :
4489 scsi_8btou64(desc->zone_start_lba);
4490 entry->write_pointer_lba =
4491 ata ? le64dec(desc->write_pointer_lba) :
4492 scsi_8btou64(desc->write_pointer_lba);
4494 rep->entries_filled = num_to_fill;
4497 case DISK_ZONE_GET_PARAMS:
4500 * In theory we should not get a GET_PARAMS bio, since it
4501 * should be handled without queueing the command to the
4504 panic("%s: Invalid zone command %d", __func__,
4505 bp->bio_zone.zone_cmd);
4509 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4510 free(ccb->csio.data_ptr, M_SCSIDA);
4514 dadone(struct cam_periph *periph, union ccb *done_ccb)
4516 struct bio *bp, *bp1;
4517 struct da_softc *softc;
4518 struct ccb_scsiio *csio;
4521 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4523 softc = (struct da_softc *)periph->softc;
4524 csio = &done_ccb->csio;
4526 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4527 if (csio->bio != NULL)
4528 biotrack(csio->bio, __func__);
4530 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4532 cam_periph_lock(periph);
4533 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4534 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4538 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4543 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4544 if (error == ERESTART) {
4545 /* A retry was scheduled, so just return. */
4546 cam_periph_unlock(periph);
4549 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4554 * return all queued I/O with EIO, so that
4555 * the client can retry these I/Os in the
4556 * proper order should it attempt to recover.
4561 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4563 * Catastrophic error. Mark our pack as
4566 * XXX See if this is really a media
4569 xpt_print(periph->path, "Invalidating pack\n");
4570 softc->flags |= DA_FLAG_PACK_INVALID;
4572 softc->invalidations++;
4574 queued_error = ENXIO;
4576 cam_iosched_flush(softc->cam_iosched, NULL,
4579 bp->bio_error = error;
4580 bp->bio_resid = bp->bio_bcount;
4581 bp->bio_flags |= BIO_ERROR;
4583 } else if (bp != NULL) {
4584 if (state == DA_CCB_DELETE)
4587 bp->bio_resid = csio->resid;
4589 if (bp->bio_resid != 0)
4590 bp->bio_flags |= BIO_ERROR;
4592 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4593 cam_release_devq(done_ccb->ccb_h.path,
4597 /*getcount_only*/0);
4598 } else if (bp != NULL) {
4599 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4600 panic("REQ_CMP with QFRZN");
4601 if (bp->bio_cmd == BIO_ZONE)
4602 dazonedone(periph, done_ccb);
4603 else if (state == DA_CCB_DELETE)
4606 bp->bio_resid = csio->resid;
4607 if ((csio->resid > 0) && (bp->bio_cmd != BIO_ZONE))
4608 bp->bio_flags |= BIO_ERROR;
4609 if (softc->error_inject != 0) {
4610 bp->bio_error = softc->error_inject;
4611 bp->bio_resid = bp->bio_bcount;
4612 bp->bio_flags |= BIO_ERROR;
4613 softc->error_inject = 0;
4618 biotrack(bp, __func__);
4619 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4620 if (LIST_EMPTY(&softc->pending_ccbs))
4621 softc->flags |= DA_FLAG_WAS_OTAG;
4624 * We need to call cam_iosched before we call biodone so that we don't
4625 * measure any activity that happens in the completion routine, which in
4626 * the case of sendfile can be quite extensive. Release the periph
4627 * refcount taken in dastart() for each CCB.
4629 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4630 xpt_release_ccb(done_ccb);
4631 KASSERT(softc->refcount >= 1, ("dadone softc %p refcount %d", softc, softc->refcount));
4633 if (state == DA_CCB_DELETE) {
4634 TAILQ_HEAD(, bio) queue;
4637 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4638 softc->delete_run_queue.insert_point = NULL;
4640 * Normally, the xpt_release_ccb() above would make sure
4641 * that when we have more work to do, that work would
4642 * get kicked off. However, we specifically keep
4643 * delete_running set to 0 before the call above to
4644 * allow other I/O to progress when many BIO_DELETE
4645 * requests are pushed down. We set delete_running to 0
4646 * and call daschedule again so that we don't stall if
4647 * there are no other I/Os pending apart from BIO_DELETEs.
4649 cam_iosched_trim_done(softc->cam_iosched);
4651 cam_periph_unlock(periph);
4652 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4653 TAILQ_REMOVE(&queue, bp1, bio_queue);
4654 bp1->bio_error = bp->bio_error;
4655 if (bp->bio_flags & BIO_ERROR) {
4656 bp1->bio_flags |= BIO_ERROR;
4657 bp1->bio_resid = bp1->bio_bcount;
4664 cam_periph_unlock(periph);
4672 dadone_probewp(struct cam_periph *periph, union ccb *done_ccb)
4674 struct da_softc *softc;
4675 struct ccb_scsiio *csio;
4678 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probewp\n"));
4680 softc = (struct da_softc *)periph->softc;
4681 priority = done_ccb->ccb_h.pinfo.priority;
4682 csio = &done_ccb->csio;
4684 cam_periph_assert(periph, MA_OWNED);
4686 KASSERT(softc->state == DA_STATE_PROBE_WP,
4687 ("State (%d) not PROBE_WP in dadone_probewp, periph %p ccb %p",
4688 softc->state, periph, done_ccb));
4689 KASSERT((csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK) == DA_CCB_PROBE_WP,
4690 ("CCB State (%lu) not PROBE_WP in dadone_probewp, periph %p ccb %p",
4691 (unsigned long)csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK, periph,
4694 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
4698 if (csio->cdb_len > 6) {
4699 struct scsi_mode_header_10 *mh =
4700 (struct scsi_mode_header_10 *)csio->data_ptr;
4701 len = 2 + scsi_2btoul(mh->data_length);
4702 off = sizeof(*mh) + scsi_2btoul(mh->blk_desc_len);
4703 dev_spec = mh->dev_spec;
4705 struct scsi_mode_header_6 *mh =
4706 (struct scsi_mode_header_6 *)csio->data_ptr;
4707 len = 1 + mh->data_length;
4708 off = sizeof(*mh) + mh->blk_desc_len;
4709 dev_spec = mh->dev_spec;
4711 if ((dev_spec & 0x80) != 0)
4712 softc->disk->d_flags |= DISKFLAG_WRITE_PROTECT;
4714 softc->disk->d_flags &= ~DISKFLAG_WRITE_PROTECT;
4716 /* Next time request only the first of returned mode pages. */
4717 if (off < len && off < csio->dxfer_len - csio->resid)
4718 softc->mode_page = csio->data_ptr[off] & SMPH_PC_MASK;
4722 error = daerror(done_ccb, CAM_RETRY_SELTO,
4723 SF_RETRY_UA|SF_NO_PRINT);
4724 if (error == ERESTART)
4726 else if (error != 0) {
4727 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4728 /* Don't wedge this device's queue */
4729 cam_release_devq(done_ccb->ccb_h.path,
4733 /*getcount_only*/0);
4736 /* We don't depend on it, so don't try again. */
4737 softc->mode_page = -1;
4741 free(csio->data_ptr, M_SCSIDA);
4742 if ((softc->flags & DA_FLAG_CAN_RC16) != 0)
4743 softc->state = DA_STATE_PROBE_RC16;
4745 softc->state = DA_STATE_PROBE_RC;
4746 xpt_release_ccb(done_ccb);
4747 xpt_schedule(periph, priority);
4752 dadone_proberc(struct cam_periph *periph, union ccb *done_ccb)
4754 struct scsi_read_capacity_data *rdcap;
4755 struct scsi_read_capacity_data_long *rcaplong;
4756 struct da_softc *softc;
4757 struct ccb_scsiio *csio;
4763 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_proberc\n"));
4765 softc = (struct da_softc *)periph->softc;
4766 priority = done_ccb->ccb_h.pinfo.priority;
4767 csio = &done_ccb->csio;
4768 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4770 KASSERT(softc->state == DA_STATE_PROBE_RC || softc->state == DA_STATE_PROBE_RC16,
4771 ("State (%d) not PROBE_RC* in dadone_proberc, periph %p ccb %p",
4772 softc->state, periph, done_ccb));
4773 KASSERT(state == DA_CCB_PROBE_RC || state == DA_CCB_PROBE_RC16,
4774 ("CCB State (%lu) not PROBE_RC* in dadone_probewp, periph %p ccb %p",
4775 (unsigned long)state, periph, done_ccb));
4780 /* XXX TODO: can this be a malloc? */
4781 announce_buf = softc->announce_temp;
4782 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4784 if (state == DA_CCB_PROBE_RC)
4785 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4787 rcaplong = (struct scsi_read_capacity_data_long *)
4790 cam_periph_assert(periph, MA_OWNED);
4792 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4793 struct disk_params *dp;
4794 uint32_t block_size;
4796 u_int lalba; /* Lowest aligned LBA. */
4798 if (state == DA_CCB_PROBE_RC) {
4799 block_size = scsi_4btoul(rdcap->length);
4800 maxsector = scsi_4btoul(rdcap->addr);
4804 * According to SBC-2, if the standard 10
4805 * byte READ CAPACITY command returns 2^32,
4806 * we should issue the 16 byte version of
4807 * the command, since the device in question
4808 * has more sectors than can be represented
4809 * with the short version of the command.
4811 if (maxsector == 0xffffffff) {
4812 free(rdcap, M_SCSIDA);
4813 softc->state = DA_STATE_PROBE_RC16;
4814 xpt_release_ccb(done_ccb);
4815 xpt_schedule(periph, priority);
4819 block_size = scsi_4btoul(rcaplong->length);
4820 maxsector = scsi_8btou64(rcaplong->addr);
4821 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4825 * Because GEOM code just will panic us if we
4826 * give them an 'illegal' value we'll avoid that
4829 if (block_size == 0) {
4834 if (block_size >= maxphys) {
4835 xpt_print(periph->path,
4836 "unsupportable block size %ju\n",
4837 (uintmax_t) block_size);
4838 announce_buf = NULL;
4839 cam_periph_invalidate(periph);
4842 * We pass rcaplong into dasetgeom(),
4843 * because it will only use it if it is
4846 dasetgeom(periph, block_size, maxsector,
4847 rcaplong, sizeof(*rcaplong));
4848 lbp = (lalba & SRC16_LBPME_A);
4849 dp = &softc->params;
4850 n = snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4851 "%juMB (%ju %u byte sectors",
4852 ((uintmax_t)dp->secsize * dp->sectors) /
4854 (uintmax_t)dp->sectors, dp->secsize);
4855 if (softc->p_type != 0) {
4856 n += snprintf(announce_buf + n,
4857 DA_ANNOUNCETMP_SZ - n,
4858 ", DIF type %d", softc->p_type);
4860 snprintf(announce_buf + n, DA_ANNOUNCETMP_SZ - n, ")");
4866 * Retry any UNIT ATTENTION type errors. They
4867 * are expected at boot.
4869 error = daerror(done_ccb, CAM_RETRY_SELTO,
4870 SF_RETRY_UA|SF_NO_PRINT);
4871 if (error == ERESTART) {
4873 * A retry was scheuled, so
4877 } else if (error != 0) {
4879 int sense_key, error_code;
4882 struct ccb_getdev cgd;
4884 /* Don't wedge this device's queue */
4885 status = done_ccb->ccb_h.status;
4886 if ((status & CAM_DEV_QFRZN) != 0)
4887 cam_release_devq(done_ccb->ccb_h.path,
4891 /*getcount_only*/0);
4893 memset(&cgd, 0, sizeof(cgd));
4894 xpt_setup_ccb(&cgd.ccb_h, done_ccb->ccb_h.path,
4895 CAM_PRIORITY_NORMAL);
4896 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4897 xpt_action((union ccb *)&cgd);
4899 if (scsi_extract_sense_ccb(done_ccb,
4900 &error_code, &sense_key, &asc, &ascq))
4906 * If we tried READ CAPACITY(16) and failed,
4907 * fallback to READ CAPACITY(10).
4909 if ((state == DA_CCB_PROBE_RC16) &&
4910 (softc->flags & DA_FLAG_CAN_RC16) &&
4911 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4914 (error_code == SSD_CURRENT_ERROR ||
4915 error_code == SSD_DESC_CURRENT_ERROR) &&
4916 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4917 cam_periph_assert(periph, MA_OWNED);
4918 softc->flags &= ~DA_FLAG_CAN_RC16;
4919 free(rdcap, M_SCSIDA);
4920 softc->state = DA_STATE_PROBE_RC;
4921 xpt_release_ccb(done_ccb);
4922 xpt_schedule(periph, priority);
4927 * Attach to anything that claims to be a
4928 * direct access or optical disk device,
4929 * as long as it doesn't return a "Logical
4930 * unit not supported" (0x25) error.
4931 * "Internal Target Failure" (0x44) is also
4932 * special and typically means that the
4933 * device is a SATA drive behind a SATL
4934 * translation that's fallen into a
4935 * terminally fatal state.
4938 && (asc != 0x25) && (asc != 0x44)
4939 && (error_code == SSD_CURRENT_ERROR
4940 || error_code == SSD_DESC_CURRENT_ERROR)) {
4941 const char *sense_key_desc;
4942 const char *asc_desc;
4944 dasetgeom(periph, 512, -1, NULL, 0);
4945 scsi_sense_desc(sense_key, asc, ascq,
4946 &cgd.inq_data, &sense_key_desc,
4948 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4949 "Attempt to query device "
4950 "size failed: %s, %s",
4951 sense_key_desc, asc_desc);
4954 scsi_sense_print(&done_ccb->csio);
4956 xpt_print(periph->path,
4957 "got CAM status %#x\n",
4958 done_ccb->ccb_h.status);
4961 xpt_print(periph->path, "fatal error, "
4962 "failed to attach to device\n");
4964 announce_buf = NULL;
4967 * Free up resources.
4969 cam_periph_invalidate(periph);
4973 free(csio->data_ptr, M_SCSIDA);
4974 if (announce_buf != NULL &&
4975 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4978 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4980 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4981 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4987 * Create our sysctl variables, now that we know
4988 * we have successfully attached.
4990 /* increase the refcount */
4991 if (da_periph_acquire(periph, DA_REF_SYSCTL) == 0) {
4992 taskqueue_enqueue(taskqueue_thread,
4993 &softc->sysctl_task);
4995 /* XXX This message is useless! */
4996 xpt_print(periph->path, "fatal error, "
4997 "could not acquire reference count\n");
5001 /* We already probed the device. */
5002 if (softc->flags & DA_FLAG_PROBED) {
5003 daprobedone(periph, done_ccb);
5007 /* Ensure re-probe doesn't see old delete. */
5008 softc->delete_available = 0;
5009 dadeleteflag(softc, DA_DELETE_ZERO, 1);
5010 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
5012 * Based on older SBC-3 spec revisions
5013 * any of the UNMAP methods "may" be
5014 * available via LBP given this flag so
5015 * we flag all of them as available and
5016 * then remove those which further
5017 * probes confirm aren't available
5020 * We could also check readcap(16) p_type
5021 * flag to exclude one or more invalid
5022 * write same (X) types here
5024 dadeleteflag(softc, DA_DELETE_WS16, 1);
5025 dadeleteflag(softc, DA_DELETE_WS10, 1);
5026 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
5028 softc->state = DA_STATE_PROBE_LBP;
5029 xpt_release_ccb(done_ccb);
5030 xpt_schedule(periph, priority);
5034 softc->state = DA_STATE_PROBE_BDC;
5035 xpt_release_ccb(done_ccb);
5036 xpt_schedule(periph, priority);
5041 dadone_probelbp(struct cam_periph *periph, union ccb *done_ccb)
5043 struct scsi_vpd_logical_block_prov *lbp;
5044 struct da_softc *softc;
5045 struct ccb_scsiio *csio;
5048 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probelbp\n"));
5050 softc = (struct da_softc *)periph->softc;
5051 priority = done_ccb->ccb_h.pinfo.priority;
5052 csio = &done_ccb->csio;
5053 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
5055 cam_periph_assert(periph, MA_OWNED);
5057 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5059 * T10/1799-D Revision 31 states at least one of these
5060 * must be supported but we don't currently enforce this.
5062 dadeleteflag(softc, DA_DELETE_WS16,
5063 (lbp->flags & SVPD_LBP_WS16));
5064 dadeleteflag(softc, DA_DELETE_WS10,
5065 (lbp->flags & SVPD_LBP_WS10));
5066 dadeleteflag(softc, DA_DELETE_UNMAP,
5067 (lbp->flags & SVPD_LBP_UNMAP));
5070 error = daerror(done_ccb, CAM_RETRY_SELTO,
5071 SF_RETRY_UA|SF_NO_PRINT);
5072 if (error == ERESTART)
5074 else if (error != 0) {
5075 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5076 /* Don't wedge this device's queue */
5077 cam_release_devq(done_ccb->ccb_h.path,
5081 /*getcount_only*/0);
5085 * Failure indicates we don't support any SBC-3
5086 * delete methods with UNMAP
5091 free(lbp, M_SCSIDA);
5092 softc->state = DA_STATE_PROBE_BLK_LIMITS;
5093 xpt_release_ccb(done_ccb);
5094 xpt_schedule(periph, priority);
5099 dadone_probeblklimits(struct cam_periph *periph, union ccb *done_ccb)
5101 struct scsi_vpd_block_limits *block_limits;
5102 struct da_softc *softc;
5103 struct ccb_scsiio *csio;
5106 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeblklimits\n"));
5108 softc = (struct da_softc *)periph->softc;
5109 priority = done_ccb->ccb_h.pinfo.priority;
5110 csio = &done_ccb->csio;
5111 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
5113 cam_periph_assert(periph, MA_OWNED);
5115 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5116 uint32_t max_txfer_len = scsi_4btoul(
5117 block_limits->max_txfer_len);
5118 uint32_t max_unmap_lba_cnt = scsi_4btoul(
5119 block_limits->max_unmap_lba_cnt);
5120 uint32_t max_unmap_blk_cnt = scsi_4btoul(
5121 block_limits->max_unmap_blk_cnt);
5122 uint32_t unmap_gran = scsi_4btoul(
5123 block_limits->opt_unmap_grain);
5124 uint32_t unmap_gran_align = scsi_4btoul(
5125 block_limits->unmap_grain_align);
5126 uint64_t ws_max_blks = scsi_8btou64(
5127 block_limits->max_write_same_length);
5129 if (max_txfer_len != 0) {
5130 softc->disk->d_maxsize = MIN(softc->maxio,
5131 (off_t)max_txfer_len * softc->params.secsize);
5135 * We should already support UNMAP but we check lba
5136 * and block count to be sure
5138 if (max_unmap_lba_cnt != 0x00L &&
5139 max_unmap_blk_cnt != 0x00L) {
5140 softc->unmap_max_lba = max_unmap_lba_cnt;
5141 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
5143 if (unmap_gran > 1) {
5144 softc->unmap_gran = unmap_gran;
5145 if (unmap_gran_align & 0x80000000) {
5146 softc->unmap_gran_align =
5147 unmap_gran_align & 0x7fffffff;
5152 * Unexpected UNMAP limits which means the
5153 * device doesn't actually support UNMAP
5155 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
5158 if (ws_max_blks != 0x00L)
5159 softc->ws_max_blks = ws_max_blks;
5162 error = daerror(done_ccb, CAM_RETRY_SELTO,
5163 SF_RETRY_UA|SF_NO_PRINT);
5164 if (error == ERESTART)
5166 else if (error != 0) {
5167 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5168 /* Don't wedge this device's queue */
5169 cam_release_devq(done_ccb->ccb_h.path,
5173 /*getcount_only*/0);
5177 * Failure here doesn't mean UNMAP is not
5178 * supported as this is an optional page.
5180 softc->unmap_max_lba = 1;
5181 softc->unmap_max_ranges = 1;
5185 free(block_limits, M_SCSIDA);
5186 softc->state = DA_STATE_PROBE_BDC;
5187 xpt_release_ccb(done_ccb);
5188 xpt_schedule(periph, priority);
5193 dadone_probebdc(struct cam_periph *periph, union ccb *done_ccb)
5195 struct scsi_vpd_block_device_characteristics *bdc;
5196 struct da_softc *softc;
5197 struct ccb_scsiio *csio;
5200 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probebdc\n"));
5202 softc = (struct da_softc *)periph->softc;
5203 priority = done_ccb->ccb_h.pinfo.priority;
5204 csio = &done_ccb->csio;
5205 bdc = (struct scsi_vpd_block_device_characteristics *)csio->data_ptr;
5207 cam_periph_assert(periph, MA_OWNED);
5209 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5213 * Disable queue sorting for non-rotational media
5216 uint16_t old_rate = softc->disk->d_rotation_rate;
5218 valid_len = csio->dxfer_len - csio->resid;
5219 if (SBDC_IS_PRESENT(bdc, valid_len,
5220 medium_rotation_rate)) {
5221 softc->disk->d_rotation_rate =
5222 scsi_2btoul(bdc->medium_rotation_rate);
5223 if (softc->disk->d_rotation_rate == SVPD_NON_ROTATING) {
5224 cam_iosched_set_sort_queue(
5225 softc->cam_iosched, 0);
5226 softc->flags &= ~DA_FLAG_ROTATING;
5228 if (softc->disk->d_rotation_rate != old_rate) {
5229 disk_attr_changed(softc->disk,
5230 "GEOM::rotation_rate", M_NOWAIT);
5233 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
5234 && (softc->zone_mode == DA_ZONE_NONE)) {
5237 if (scsi_vpd_supported_page(periph,
5238 SVPD_ATA_INFORMATION))
5244 * The Zoned field will only be set for
5245 * Drive Managed and Host Aware drives. If
5246 * they are Host Managed, the device type
5247 * in the standard INQUIRY data should be
5248 * set to T_ZBC_HM (0x14).
5250 if ((bdc->flags & SVPD_ZBC_MASK) ==
5252 softc->zone_mode = DA_ZONE_HOST_AWARE;
5253 softc->zone_interface = (ata_proto) ?
5254 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5255 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
5257 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5258 softc->zone_interface = (ata_proto) ?
5259 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
5260 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
5262 xpt_print(periph->path, "Unknown zoned "
5264 bdc->flags & SVPD_ZBC_MASK);
5269 error = daerror(done_ccb, CAM_RETRY_SELTO,
5270 SF_RETRY_UA|SF_NO_PRINT);
5271 if (error == ERESTART)
5273 else if (error != 0) {
5274 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5275 /* Don't wedge this device's queue */
5276 cam_release_devq(done_ccb->ccb_h.path,
5280 /*getcount_only*/0);
5285 free(bdc, M_SCSIDA);
5286 softc->state = DA_STATE_PROBE_ATA;
5287 xpt_release_ccb(done_ccb);
5288 xpt_schedule(periph, priority);
5293 dadone_probeata(struct cam_periph *periph, union ccb *done_ccb)
5295 struct ata_params *ata_params;
5296 struct ccb_scsiio *csio;
5297 struct da_softc *softc;
5302 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeata\n"));
5304 softc = (struct da_softc *)periph->softc;
5305 priority = done_ccb->ccb_h.pinfo.priority;
5306 csio = &done_ccb->csio;
5307 ata_params = (struct ata_params *)csio->data_ptr;
5311 cam_periph_assert(periph, MA_OWNED);
5313 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5316 ata_param_fixup(ata_params);
5317 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
5318 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
5319 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
5320 if (ata_params->max_dsm_blocks != 0)
5321 softc->trim_max_ranges = min(
5322 softc->trim_max_ranges,
5323 ata_params->max_dsm_blocks *
5324 ATA_DSM_BLK_RANGES);
5327 * Disable queue sorting for non-rotational media
5330 old_rate = softc->disk->d_rotation_rate;
5331 softc->disk->d_rotation_rate = ata_params->media_rotation_rate;
5332 if (softc->disk->d_rotation_rate == ATA_RATE_NON_ROTATING) {
5333 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
5334 softc->flags &= ~DA_FLAG_ROTATING;
5336 if (softc->disk->d_rotation_rate != old_rate) {
5337 disk_attr_changed(softc->disk,
5338 "GEOM::rotation_rate", M_NOWAIT);
5341 cam_periph_assert(periph, MA_OWNED);
5342 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
5343 softc->flags |= DA_FLAG_CAN_ATA_DMA;
5345 if (ata_params->support.extension & ATA_SUPPORT_GENLOG)
5346 softc->flags |= DA_FLAG_CAN_ATA_LOG;
5349 * At this point, if we have a SATA host aware drive,
5350 * we communicate via ATA passthrough unless the
5351 * SAT layer supports ZBC -> ZAC translation. In
5354 * XXX KDM figure out how to detect a host managed
5357 if (softc->zone_mode == DA_ZONE_NONE) {
5359 * Note that we don't override the zone
5360 * mode or interface if it has already been
5361 * set. This is because it has either been
5362 * set as a quirk, or when we probed the
5363 * SCSI Block Device Characteristics page,
5364 * the zoned field was set. The latter
5365 * means that the SAT layer supports ZBC to
5366 * ZAC translation, and we would prefer to
5367 * use that if it is available.
5369 if ((ata_params->support3 &
5370 ATA_SUPPORT_ZONE_MASK) ==
5371 ATA_SUPPORT_ZONE_HOST_AWARE) {
5372 softc->zone_mode = DA_ZONE_HOST_AWARE;
5373 softc->zone_interface =
5374 DA_ZONE_IF_ATA_PASS;
5375 } else if ((ata_params->support3 &
5376 ATA_SUPPORT_ZONE_MASK) ==
5377 ATA_SUPPORT_ZONE_DEV_MANAGED) {
5378 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
5379 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
5384 error = daerror(done_ccb, CAM_RETRY_SELTO,
5385 SF_RETRY_UA|SF_NO_PRINT);
5386 if (error == ERESTART)
5388 else if (error != 0) {
5389 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5390 /* Don't wedge this device's queue */
5391 cam_release_devq(done_ccb->ccb_h.path,
5395 /*getcount_only*/0);
5400 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
5401 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
5403 * If the ATA IDENTIFY failed, we could be talking
5404 * to a SCSI drive, although that seems unlikely,
5405 * since the drive did report that it supported the
5406 * ATA Information VPD page. If the ATA IDENTIFY
5407 * succeeded, and the SAT layer doesn't support
5408 * ZBC -> ZAC translation, continue on to get the
5409 * directory of ATA logs, and complete the rest of
5410 * the ZAC probe. If the SAT layer does support
5411 * ZBC -> ZAC translation, we want to use that,
5412 * and we'll probe the SCSI Zoned Block Device
5413 * Characteristics VPD page next.
5416 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
5417 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
5418 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
5420 softc->state = DA_STATE_PROBE_ZONE;
5423 if (continue_probe != 0) {
5424 xpt_schedule(periph, priority);
5425 xpt_release_ccb(done_ccb);
5428 daprobedone(periph, done_ccb);
5433 dadone_probeatalogdir(struct cam_periph *periph, union ccb *done_ccb)
5435 struct da_softc *softc;
5436 struct ccb_scsiio *csio;
5440 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatalogdir\n"));
5442 softc = (struct da_softc *)periph->softc;
5443 priority = done_ccb->ccb_h.pinfo.priority;
5444 csio = &done_ccb->csio;
5446 cam_periph_assert(periph, MA_OWNED);
5447 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5449 softc->valid_logdir_len = 0;
5450 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
5451 softc->valid_logdir_len = csio->dxfer_len - csio->resid;
5452 if (softc->valid_logdir_len > 0)
5453 bcopy(csio->data_ptr, &softc->ata_logdir,
5454 min(softc->valid_logdir_len,
5455 sizeof(softc->ata_logdir)));
5457 * Figure out whether the Identify Device log is
5458 * supported. The General Purpose log directory
5459 * has a header, and lists the number of pages
5460 * available for each GP log identified by the
5461 * offset into the list.
5463 if ((softc->valid_logdir_len >=
5464 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
5465 && (le16dec(softc->ata_logdir.header) ==
5466 ATA_GP_LOG_DIR_VERSION)
5467 && (le16dec(&softc->ata_logdir.num_pages[
5468 (ATA_IDENTIFY_DATA_LOG *
5469 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
5470 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
5472 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5475 error = daerror(done_ccb, CAM_RETRY_SELTO,
5476 SF_RETRY_UA|SF_NO_PRINT);
5477 if (error == ERESTART)
5479 else if (error != 0) {
5481 * If we can't get the ATA log directory,
5482 * then ATA logs are effectively not
5483 * supported even if the bit is set in the
5486 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
5487 DA_FLAG_CAN_ATA_IDLOG);
5488 if ((done_ccb->ccb_h.status &
5489 CAM_DEV_QFRZN) != 0) {
5490 /* Don't wedge this device's queue */
5491 cam_release_devq(done_ccb->ccb_h.path,
5495 /*getcount_only*/0);
5500 free(csio->data_ptr, M_SCSIDA);
5503 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
5504 softc->state = DA_STATE_PROBE_ATA_IDDIR;
5505 xpt_release_ccb(done_ccb);
5506 xpt_schedule(periph, priority);
5509 daprobedone(periph, done_ccb);
5514 dadone_probeataiddir(struct cam_periph *periph, union ccb *done_ccb)
5516 struct da_softc *softc;
5517 struct ccb_scsiio *csio;
5521 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeataiddir\n"));
5523 softc = (struct da_softc *)periph->softc;
5524 priority = done_ccb->ccb_h.pinfo.priority;
5525 csio = &done_ccb->csio;
5527 cam_periph_assert(periph, MA_OWNED);
5529 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5530 off_t entries_offset, max_entries;
5533 softc->valid_iddir_len = 0;
5534 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
5535 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
5536 DA_FLAG_CAN_ATA_ZONE);
5537 softc->valid_iddir_len = csio->dxfer_len - csio->resid;
5538 if (softc->valid_iddir_len > 0)
5539 bcopy(csio->data_ptr, &softc->ata_iddir,
5540 min(softc->valid_iddir_len,
5541 sizeof(softc->ata_iddir)));
5544 __offsetof(struct ata_identify_log_pages,entries);
5545 max_entries = softc->valid_iddir_len - entries_offset;
5546 if ((softc->valid_iddir_len > (entries_offset + 1))
5547 && (le64dec(softc->ata_iddir.header) == ATA_IDLOG_REVISION)
5548 && (softc->ata_iddir.entry_count > 0)) {
5551 num_entries = softc->ata_iddir.entry_count;
5552 num_entries = min(num_entries,
5553 softc->valid_iddir_len - entries_offset);
5554 for (i = 0; i < num_entries && i < max_entries; i++) {
5555 if (softc->ata_iddir.entries[i] ==
5557 softc->flags |= DA_FLAG_CAN_ATA_SUPCAP;
5558 else if (softc->ata_iddir.entries[i] ==
5560 softc->flags |= DA_FLAG_CAN_ATA_ZONE;
5562 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP)
5563 && (softc->flags & DA_FLAG_CAN_ATA_ZONE))
5568 error = daerror(done_ccb, CAM_RETRY_SELTO,
5569 SF_RETRY_UA|SF_NO_PRINT);
5570 if (error == ERESTART)
5572 else if (error != 0) {
5574 * If we can't get the ATA Identify Data log
5575 * directory, then it effectively isn't
5576 * supported even if the ATA Log directory
5577 * a non-zero number of pages present for
5580 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5581 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5582 /* Don't wedge this device's queue */
5583 cam_release_devq(done_ccb->ccb_h.path,
5587 /*getcount_only*/0);
5592 free(csio->data_ptr, M_SCSIDA);
5594 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5595 softc->state = DA_STATE_PROBE_ATA_SUP;
5596 xpt_release_ccb(done_ccb);
5597 xpt_schedule(periph, priority);
5600 daprobedone(periph, done_ccb);
5605 dadone_probeatasup(struct cam_periph *periph, union ccb *done_ccb)
5607 struct da_softc *softc;
5608 struct ccb_scsiio *csio;
5612 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatasup\n"));
5614 softc = (struct da_softc *)periph->softc;
5615 priority = done_ccb->ccb_h.pinfo.priority;
5616 csio = &done_ccb->csio;
5618 cam_periph_assert(periph, MA_OWNED);
5620 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5623 struct ata_identify_log_sup_cap *sup_cap;
5626 sup_cap = (struct ata_identify_log_sup_cap *)csio->data_ptr;
5627 valid_len = csio->dxfer_len - csio->resid;
5628 needed_size = __offsetof(struct ata_identify_log_sup_cap,
5629 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5630 if (valid_len >= needed_size) {
5631 uint64_t zoned, zac_cap;
5633 zoned = le64dec(sup_cap->zoned_cap);
5634 if (zoned & ATA_ZONED_VALID) {
5636 * This should have already been
5637 * set, because this is also in the
5638 * ATA identify data.
5640 if ((zoned & ATA_ZONED_MASK) ==
5641 ATA_SUPPORT_ZONE_HOST_AWARE)
5642 softc->zone_mode = DA_ZONE_HOST_AWARE;
5643 else if ((zoned & ATA_ZONED_MASK) ==
5644 ATA_SUPPORT_ZONE_DEV_MANAGED)
5646 DA_ZONE_DRIVE_MANAGED;
5649 zac_cap = le64dec(sup_cap->sup_zac_cap);
5650 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5651 if (zac_cap & ATA_REPORT_ZONES_SUP)
5652 softc->zone_flags |=
5653 DA_ZONE_FLAG_RZ_SUP;
5654 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5655 softc->zone_flags |=
5656 DA_ZONE_FLAG_OPEN_SUP;
5657 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5658 softc->zone_flags |=
5659 DA_ZONE_FLAG_CLOSE_SUP;
5660 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5661 softc->zone_flags |=
5662 DA_ZONE_FLAG_FINISH_SUP;
5663 if (zac_cap & ATA_ND_RWP_SUP)
5664 softc->zone_flags |=
5665 DA_ZONE_FLAG_RWP_SUP;
5668 * This field was introduced in
5669 * ACS-4, r08 on April 28th, 2015.
5670 * If the drive firmware was written
5671 * to an earlier spec, it won't have
5672 * the field. So, assume all
5673 * commands are supported.
5675 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5679 error = daerror(done_ccb, CAM_RETRY_SELTO,
5680 SF_RETRY_UA|SF_NO_PRINT);
5681 if (error == ERESTART)
5683 else if (error != 0) {
5685 * If we can't get the ATA Identify Data
5686 * Supported Capabilities page, clear the
5689 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5691 * And clear zone capabilities.
5693 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5694 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5695 /* Don't wedge this device's queue */
5696 cam_release_devq(done_ccb->ccb_h.path,
5700 /*getcount_only*/0);
5705 free(csio->data_ptr, M_SCSIDA);
5707 if ((error == 0) && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5708 softc->state = DA_STATE_PROBE_ATA_ZONE;
5709 xpt_release_ccb(done_ccb);
5710 xpt_schedule(periph, priority);
5713 daprobedone(periph, done_ccb);
5718 dadone_probeatazone(struct cam_periph *periph, union ccb *done_ccb)
5720 struct da_softc *softc;
5721 struct ccb_scsiio *csio;
5724 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probeatazone\n"));
5726 softc = (struct da_softc *)periph->softc;
5727 csio = &done_ccb->csio;
5729 cam_periph_assert(periph, MA_OWNED);
5731 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5732 struct ata_zoned_info_log *zi_log;
5736 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5738 valid_len = csio->dxfer_len - csio->resid;
5739 needed_size = __offsetof(struct ata_zoned_info_log,
5740 version_info) + 1 + sizeof(zi_log->version_info);
5741 if (valid_len >= needed_size) {
5744 tmpvar = le64dec(zi_log->zoned_cap);
5745 if (tmpvar & ATA_ZDI_CAP_VALID) {
5746 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5747 softc->zone_flags |=
5748 DA_ZONE_FLAG_URSWRZ;
5750 softc->zone_flags &=
5751 ~DA_ZONE_FLAG_URSWRZ;
5753 tmpvar = le64dec(zi_log->optimal_seq_zones);
5754 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5755 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5756 softc->optimal_seq_zones = (tmpvar &
5757 ATA_ZDI_OPT_SEQ_MASK);
5759 softc->zone_flags &= ~DA_ZONE_FLAG_OPT_SEQ_SET;
5760 softc->optimal_seq_zones = 0;
5763 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5764 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5765 softc->zone_flags |=
5766 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5767 softc->optimal_nonseq_zones =
5768 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5770 softc->zone_flags &=
5771 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5772 softc->optimal_nonseq_zones = 0;
5775 tmpvar = le64dec(zi_log->max_seq_req_zones);
5776 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5777 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5778 softc->max_seq_zones =
5779 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5781 softc->zone_flags &= ~DA_ZONE_FLAG_MAX_SEQ_SET;
5782 softc->max_seq_zones = 0;
5786 error = daerror(done_ccb, CAM_RETRY_SELTO,
5787 SF_RETRY_UA|SF_NO_PRINT);
5788 if (error == ERESTART)
5790 else if (error != 0) {
5791 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5792 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5794 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5795 /* Don't wedge this device's queue */
5796 cam_release_devq(done_ccb->ccb_h.path,
5800 /*getcount_only*/0);
5805 free(csio->data_ptr, M_SCSIDA);
5807 daprobedone(periph, done_ccb);
5812 dadone_probezone(struct cam_periph *periph, union ccb *done_ccb)
5814 struct da_softc *softc;
5815 struct ccb_scsiio *csio;
5818 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probezone\n"));
5820 softc = (struct da_softc *)periph->softc;
5821 csio = &done_ccb->csio;
5823 cam_periph_assert(periph, MA_OWNED);
5825 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5828 struct scsi_vpd_zoned_bdc *zoned_bdc;
5831 zoned_bdc = (struct scsi_vpd_zoned_bdc *)csio->data_ptr;
5832 valid_len = csio->dxfer_len - csio->resid;
5833 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5834 max_seq_req_zones) + 1 +
5835 sizeof(zoned_bdc->max_seq_req_zones);
5836 if ((valid_len >= needed_len)
5837 && (scsi_2btoul(zoned_bdc->page_length) >= SVPD_ZBDC_PL)) {
5838 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5839 softc->zone_flags |= DA_ZONE_FLAG_URSWRZ;
5841 softc->zone_flags &= ~DA_ZONE_FLAG_URSWRZ;
5842 softc->optimal_seq_zones =
5843 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5844 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5845 softc->optimal_nonseq_zones = scsi_4btoul(
5846 zoned_bdc->optimal_nonseq_zones);
5847 softc->zone_flags |= DA_ZONE_FLAG_OPT_NONSEQ_SET;
5848 softc->max_seq_zones =
5849 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5850 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5853 * All of the zone commands are mandatory for SCSI
5856 * XXX KDM this is valid as of September 2015.
5857 * Re-check this assumption once the SAT spec is
5858 * updated to support SCSI ZBC to ATA ZAC mapping.
5859 * Since ATA allows zone commands to be reported
5860 * as supported or not, this may not necessarily
5861 * be true for an ATA device behind a SAT (SCSI to
5862 * ATA Translation) layer.
5864 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5866 error = daerror(done_ccb, CAM_RETRY_SELTO,
5867 SF_RETRY_UA|SF_NO_PRINT);
5868 if (error == ERESTART)
5870 else if (error != 0) {
5871 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5872 /* Don't wedge this device's queue */
5873 cam_release_devq(done_ccb->ccb_h.path,
5877 /*getcount_only*/0);
5882 free(csio->data_ptr, M_SCSIDA);
5884 daprobedone(periph, done_ccb);
5889 dadone_tur(struct cam_periph *periph, union ccb *done_ccb)
5891 struct da_softc *softc;
5893 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_tur\n"));
5895 softc = (struct da_softc *)periph->softc;
5897 cam_periph_assert(periph, MA_OWNED);
5899 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5900 if (daerror(done_ccb, CAM_RETRY_SELTO,
5901 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) == ERESTART)
5902 return; /* Will complete again, keep reference */
5903 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5904 cam_release_devq(done_ccb->ccb_h.path,
5908 /*getcount_only*/0);
5910 softc->flags &= ~DA_FLAG_TUR_PENDING;
5911 xpt_release_ccb(done_ccb);
5912 da_periph_release_locked(periph, DA_REF_TUR);
5917 dareprobe(struct cam_periph *periph)
5919 struct da_softc *softc;
5920 int status __diagused;
5922 softc = (struct da_softc *)periph->softc;
5924 cam_periph_assert(periph, MA_OWNED);
5926 /* Probe in progress; don't interfere. */
5927 if (softc->state != DA_STATE_NORMAL)
5930 status = da_periph_acquire(periph, DA_REF_REPROBE);
5931 KASSERT(status == 0, ("dareprobe: cam_periph_acquire failed"));
5933 softc->state = DA_STATE_PROBE_WP;
5934 xpt_schedule(periph, CAM_PRIORITY_DEV);
5938 daerror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags)
5940 struct da_softc *softc;
5941 struct cam_periph *periph;
5942 int error, error_code, sense_key, asc, ascq;
5944 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5945 if (ccb->csio.bio != NULL)
5946 biotrack(ccb->csio.bio, __func__);
5949 periph = xpt_path_periph(ccb->ccb_h.path);
5950 softc = (struct da_softc *)periph->softc;
5952 cam_periph_assert(periph, MA_OWNED);
5955 * Automatically detect devices that do not support
5956 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5959 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5960 error = cmd6workaround(ccb);
5961 } else if (scsi_extract_sense_ccb(ccb,
5962 &error_code, &sense_key, &asc, &ascq)) {
5963 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5964 error = cmd6workaround(ccb);
5966 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5967 * query the capacity and notify upper layers.
5969 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5970 asc == 0x2A && ascq == 0x09) {
5971 xpt_print(periph->path, "Capacity data has changed\n");
5972 softc->flags &= ~DA_FLAG_PROBED;
5974 sense_flags |= SF_NO_PRINT;
5975 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5976 asc == 0x28 && ascq == 0x00) {
5977 softc->flags &= ~DA_FLAG_PROBED;
5978 disk_media_changed(softc->disk, M_NOWAIT);
5979 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5980 asc == 0x3F && ascq == 0x03) {
5981 xpt_print(periph->path, "INQUIRY data has changed\n");
5982 softc->flags &= ~DA_FLAG_PROBED;
5984 sense_flags |= SF_NO_PRINT;
5985 } else if (sense_key == SSD_KEY_NOT_READY &&
5986 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5987 softc->flags |= DA_FLAG_PACK_INVALID;
5988 disk_media_gone(softc->disk, M_NOWAIT);
5991 if (error == ERESTART)
5995 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5996 case CAM_CMD_TIMEOUT:
5999 case CAM_REQ_ABORTED:
6000 case CAM_REQ_CMP_ERR:
6001 case CAM_REQ_TERMIO:
6002 case CAM_UNREC_HBA_ERROR:
6003 case CAM_DATA_RUN_ERR:
6004 case CAM_SCSI_STATUS_ERROR:
6005 case CAM_ATA_STATUS_ERROR:
6015 * Until we have a better way of doing pack validation,
6016 * don't treat UAs as errors.
6018 sense_flags |= SF_RETRY_UA;
6020 if (softc->quirks & DA_Q_RETRY_BUSY)
6021 sense_flags |= SF_RETRY_BUSY;
6022 return(cam_periph_error(ccb, cam_flags, sense_flags));
6026 damediapoll(void *arg)
6028 struct cam_periph *periph = arg;
6029 struct da_softc *softc = periph->softc;
6031 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
6032 (softc->flags & DA_FLAG_TUR_PENDING) == 0 &&
6033 softc->state == DA_STATE_NORMAL &&
6034 LIST_EMPTY(&softc->pending_ccbs)) {
6035 if (da_periph_acquire(periph, DA_REF_TUR) == 0) {
6036 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
6041 /* Queue us up again */
6042 if (da_poll_period != 0) {
6043 callout_schedule_sbt(&softc->mediapoll_c,
6044 da_poll_period * SBT_1S, 0, C_PREL(1));
6049 daprevent(struct cam_periph *periph, int action)
6051 struct da_softc *softc;
6055 cam_periph_assert(periph, MA_OWNED);
6056 softc = (struct da_softc *)periph->softc;
6058 if (((action == PR_ALLOW)
6059 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
6060 || ((action == PR_PREVENT)
6061 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
6065 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
6067 scsi_prevent(&ccb->csio,
6075 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
6076 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
6079 if (action == PR_ALLOW)
6080 softc->flags &= ~DA_FLAG_PACK_LOCKED;
6082 softc->flags |= DA_FLAG_PACK_LOCKED;
6085 xpt_release_ccb(ccb);
6089 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
6090 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
6092 struct ccb_calc_geometry ccg;
6093 struct da_softc *softc;
6094 struct disk_params *dp;
6095 u_int lbppbe, lalba;
6098 softc = (struct da_softc *)periph->softc;
6100 dp = &softc->params;
6101 dp->secsize = block_len;
6102 dp->sectors = maxsector + 1;
6103 if (rcaplong != NULL) {
6104 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
6105 lalba = scsi_2btoul(rcaplong->lalba_lbp);
6106 lalba &= SRC16_LALBA_A;
6107 if (rcaplong->prot & SRC16_PROT_EN)
6108 softc->p_type = ((rcaplong->prot & SRC16_P_TYPE) >>
6109 SRC16_P_TYPE_SHIFT) + 1;
6119 dp->stripesize = block_len << lbppbe;
6120 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
6122 } else if (softc->quirks & DA_Q_4K) {
6123 dp->stripesize = 4096;
6124 dp->stripeoffset = 0;
6125 } else if (softc->unmap_gran != 0) {
6126 dp->stripesize = block_len * softc->unmap_gran;
6127 dp->stripeoffset = (dp->stripesize - block_len *
6128 softc->unmap_gran_align) % dp->stripesize;
6131 dp->stripeoffset = 0;
6134 * Have the controller provide us with a geometry
6135 * for this disk. The only time the geometry
6136 * matters is when we boot and the controller
6137 * is the only one knowledgeable enough to come
6138 * up with something that will make this a bootable
6141 memset(&ccg, 0, sizeof(ccg));
6142 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6143 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
6144 ccg.block_size = dp->secsize;
6145 ccg.volume_size = dp->sectors;
6147 ccg.secs_per_track = 0;
6149 xpt_action((union ccb*)&ccg);
6150 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
6152 * We don't know what went wrong here- but just pick
6153 * a geometry so we don't have nasty things like divide
6157 dp->secs_per_track = 255;
6158 dp->cylinders = dp->sectors / (255 * 255);
6159 if (dp->cylinders == 0) {
6163 dp->heads = ccg.heads;
6164 dp->secs_per_track = ccg.secs_per_track;
6165 dp->cylinders = ccg.cylinders;
6169 * If the user supplied a read capacity buffer, and if it is
6170 * different than the previous buffer, update the data in the EDT.
6171 * If it's the same, we don't bother. This avoids sending an
6172 * update every time someone opens this device.
6174 if ((rcaplong != NULL)
6175 && (bcmp(rcaplong, &softc->rcaplong,
6176 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
6177 struct ccb_dev_advinfo cdai;
6179 memset(&cdai, 0, sizeof(cdai));
6180 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
6181 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
6182 cdai.buftype = CDAI_TYPE_RCAPLONG;
6183 cdai.flags = CDAI_FLAG_STORE;
6184 cdai.bufsiz = rcap_len;
6185 cdai.buf = (uint8_t *)rcaplong;
6186 xpt_action((union ccb *)&cdai);
6187 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
6188 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
6189 if (cdai.ccb_h.status != CAM_REQ_CMP) {
6190 xpt_print(periph->path, "%s: failed to set read "
6191 "capacity advinfo\n", __func__);
6192 /* Use cam_error_print() to decode the status */
6193 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
6196 bcopy(rcaplong, &softc->rcaplong,
6197 min(sizeof(softc->rcaplong), rcap_len));
6201 softc->disk->d_sectorsize = softc->params.secsize;
6202 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
6203 softc->disk->d_stripesize = softc->params.stripesize;
6204 softc->disk->d_stripeoffset = softc->params.stripeoffset;
6205 /* XXX: these are not actually "firmware" values, so they may be wrong */
6206 softc->disk->d_fwsectors = softc->params.secs_per_track;
6207 softc->disk->d_fwheads = softc->params.heads;
6208 softc->disk->d_devstat->block_size = softc->params.secsize;
6209 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
6211 error = disk_resize(softc->disk, M_NOWAIT);
6213 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
6217 dasendorderedtag(void *arg)
6219 struct cam_periph *periph = arg;
6220 struct da_softc *softc = periph->softc;
6222 cam_periph_assert(periph, MA_OWNED);
6223 if (da_send_ordered) {
6224 if (!LIST_EMPTY(&softc->pending_ccbs)) {
6225 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
6226 softc->flags |= DA_FLAG_NEED_OTAG;
6227 softc->flags &= ~DA_FLAG_WAS_OTAG;
6231 /* Queue us up again */
6232 callout_schedule_sbt(&softc->sendordered_c,
6233 SBT_1S / DA_ORDEREDTAG_INTERVAL * da_default_timeout, 0,
6238 * Step through all DA peripheral drivers, and if the device is still open,
6239 * sync the disk cache to physical media.
6242 dashutdown(void * arg, int howto)
6244 struct cam_periph *periph;
6245 struct da_softc *softc;
6249 if ((howto & RB_NOSYNC) != 0)
6252 CAM_PERIPH_FOREACH(periph, &dadriver) {
6253 softc = (struct da_softc *)periph->softc;
6254 if (SCHEDULER_STOPPED()) {
6255 /* If we paniced with the lock held, do not recurse. */
6256 if (!cam_periph_owned(periph) &&
6257 (softc->flags & DA_FLAG_OPEN)) {
6258 dadump(softc->disk, NULL, 0, 0);
6262 cam_periph_lock(periph);
6265 * We only sync the cache if the drive is still open, and
6266 * if the drive is capable of it..
6268 if (((softc->flags & DA_FLAG_OPEN) == 0)
6269 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
6270 cam_periph_unlock(periph);
6274 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
6275 scsi_synchronize_cache(&ccb->csio,
6279 /*begin_lba*/0, /* whole disk */
6284 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
6285 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
6286 softc->disk->d_devstat);
6288 xpt_print(periph->path, "Synchronize cache failed\n");
6289 xpt_release_ccb(ccb);
6290 cam_periph_unlock(periph);
6294 #else /* !_KERNEL */
6297 * XXX These are only left out of the kernel build to silence warnings. If,
6298 * for some reason these functions are used in the kernel, the ifdefs should
6299 * be moved so they are included both in the kernel and userland.
6302 scsi_format_unit(struct ccb_scsiio *csio, uint32_t retries,
6303 void (*cbfcnp)(struct cam_periph *, union ccb *),
6304 uint8_t tag_action, uint8_t byte2, uint16_t ileave,
6305 uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len,
6308 struct scsi_format_unit *scsi_cmd;
6310 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
6311 scsi_cmd->opcode = FORMAT_UNIT;
6312 scsi_cmd->byte2 = byte2;
6313 scsi_ulto2b(ileave, scsi_cmd->interleave);
6318 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6328 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
6329 void (*cbfcnp)(struct cam_periph *, union ccb *),
6330 uint8_t tag_action, uint8_t list_format,
6331 uint32_t addr_desc_index, uint8_t *data_ptr,
6332 uint32_t dxfer_len, int minimum_cmd_size,
6333 uint8_t sense_len, uint32_t timeout)
6338 * These conditions allow using the 10 byte command. Otherwise we
6339 * need to use the 12 byte command.
6341 if ((minimum_cmd_size <= 10)
6342 && (addr_desc_index == 0)
6343 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
6344 struct scsi_read_defect_data_10 *cdb10;
6346 cdb10 = (struct scsi_read_defect_data_10 *)
6347 &csio->cdb_io.cdb_bytes;
6349 cdb_len = sizeof(*cdb10);
6350 bzero(cdb10, cdb_len);
6351 cdb10->opcode = READ_DEFECT_DATA_10;
6352 cdb10->format = list_format;
6353 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
6355 struct scsi_read_defect_data_12 *cdb12;
6357 cdb12 = (struct scsi_read_defect_data_12 *)
6358 &csio->cdb_io.cdb_bytes;
6360 cdb_len = sizeof(*cdb12);
6361 bzero(cdb12, cdb_len);
6362 cdb12->opcode = READ_DEFECT_DATA_12;
6363 cdb12->format = list_format;
6364 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
6365 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
6371 /*flags*/ CAM_DIR_IN,
6381 scsi_sanitize(struct ccb_scsiio *csio, uint32_t retries,
6382 void (*cbfcnp)(struct cam_periph *, union ccb *),
6383 uint8_t tag_action, uint8_t byte2, uint16_t control,
6384 uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len,
6387 struct scsi_sanitize *scsi_cmd;
6389 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
6390 scsi_cmd->opcode = SANITIZE;
6391 scsi_cmd->byte2 = byte2;
6392 scsi_cmd->control = control;
6393 scsi_ulto2b(dxfer_len, scsi_cmd->length);
6398 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6407 #endif /* _KERNEL */
6410 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
6411 void (*cbfcnp)(struct cam_periph *, union ccb *),
6412 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
6413 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
6414 uint8_t sense_len, uint32_t timeout)
6416 struct scsi_zbc_out *scsi_cmd;
6418 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
6419 scsi_cmd->opcode = ZBC_OUT;
6420 scsi_cmd->service_action = service_action;
6421 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
6422 scsi_cmd->zone_flags = zone_flags;
6427 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6437 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
6438 void (*cbfcnp)(struct cam_periph *, union ccb *),
6439 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
6440 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
6441 uint8_t sense_len, uint32_t timeout)
6443 struct scsi_zbc_in *scsi_cmd;
6445 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
6446 scsi_cmd->opcode = ZBC_IN;
6447 scsi_cmd->service_action = service_action;
6448 scsi_ulto4b(dxfer_len, scsi_cmd->length);
6449 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
6450 scsi_cmd->zone_options = zone_options;
6455 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
6466 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
6467 void (*cbfcnp)(struct cam_periph *, union ccb *),
6468 uint8_t tag_action, int use_ncq,
6469 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6470 uint8_t *data_ptr, uint32_t dxfer_len,
6471 uint8_t *cdb_storage, size_t cdb_storage_len,
6472 uint8_t sense_len, uint32_t timeout)
6474 uint8_t command_out, protocol, ata_flags;
6475 uint16_t features_out;
6476 uint32_t sectors_out, auxiliary;
6482 command_out = ATA_ZAC_MANAGEMENT_OUT;
6483 features_out = (zm_action & 0xf) | (zone_flags << 8);
6484 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6485 if (dxfer_len == 0) {
6486 protocol = AP_PROTO_NON_DATA;
6487 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6490 protocol = AP_PROTO_DMA;
6491 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
6492 AP_FLAG_TDIR_TO_DEV;
6493 sectors_out = ((dxfer_len >> 9) & 0xffff);
6497 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
6498 if (dxfer_len == 0) {
6499 command_out = ATA_NCQ_NON_DATA;
6500 features_out = ATA_NCQ_ZAC_MGMT_OUT;
6502 * We're assuming the SCSI to ATA translation layer
6503 * will set the NCQ tag number in the tag field.
6504 * That isn't clear from the SAT-4 spec (as of rev 05).
6507 ata_flags |= AP_FLAG_TLEN_NO_DATA;
6509 command_out = ATA_SEND_FPDMA_QUEUED;
6511 * Note that we're defaulting to normal priority,
6512 * and assuming that the SCSI to ATA translation
6513 * layer will insert the NCQ tag number in the tag
6514 * field. That isn't clear in the SAT-4 spec (as
6517 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
6519 ata_flags |= AP_FLAG_TLEN_FEAT |
6520 AP_FLAG_TDIR_TO_DEV;
6523 * For SEND FPDMA QUEUED, the transfer length is
6524 * encoded in the FEATURE register, and 0 means
6525 * that 65536 512 byte blocks are to be tranferred.
6526 * In practice, it seems unlikely that we'll see
6527 * a transfer that large, and it may confuse the
6528 * the SAT layer, because generally that means that
6529 * 0 bytes should be transferred.
6531 if (dxfer_len == (65536 * 512)) {
6533 } else if (dxfer_len <= (65535 * 512)) {
6534 features_out = ((dxfer_len >> 9) & 0xffff);
6536 /* The transfer is too big. */
6542 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
6543 protocol = AP_PROTO_FPDMA;
6546 protocol |= AP_EXTEND;
6548 retval = scsi_ata_pass(csio,
6551 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
6553 /*protocol*/ protocol,
6554 /*ata_flags*/ ata_flags,
6555 /*features*/ features_out,
6556 /*sector_count*/ sectors_out,
6558 /*command*/ command_out,
6561 /*auxiliary*/ auxiliary,
6563 /*data_ptr*/ data_ptr,
6564 /*dxfer_len*/ dxfer_len,
6565 /*cdb_storage*/ cdb_storage,
6566 /*cdb_storage_len*/ cdb_storage_len,
6567 /*minimum_cmd_size*/ 0,
6568 /*sense_len*/ SSD_FULL_SIZE,
6569 /*timeout*/ timeout);
6577 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
6578 void (*cbfcnp)(struct cam_periph *, union ccb *),
6579 uint8_t tag_action, int use_ncq,
6580 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
6581 uint8_t *data_ptr, uint32_t dxfer_len,
6582 uint8_t *cdb_storage, size_t cdb_storage_len,
6583 uint8_t sense_len, uint32_t timeout)
6585 uint8_t command_out, protocol;
6586 uint16_t features_out, sectors_out;
6592 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
6595 command_out = ATA_ZAC_MANAGEMENT_IN;
6596 /* XXX KDM put a macro here */
6597 features_out = (zm_action & 0xf) | (zone_flags << 8);
6598 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
6599 protocol = AP_PROTO_DMA;
6600 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
6603 ata_flags |= AP_FLAG_TLEN_FEAT;
6605 command_out = ATA_RECV_FPDMA_QUEUED;
6606 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
6609 * For RECEIVE FPDMA QUEUED, the transfer length is
6610 * encoded in the FEATURE register, and 0 means
6611 * that 65536 512 byte blocks are to be tranferred.
6612 * In practice, it seems unlikely that we'll see
6613 * a transfer that large, and it may confuse the
6614 * the SAT layer, because generally that means that
6615 * 0 bytes should be transferred.
6617 if (dxfer_len == (65536 * 512)) {
6619 } else if (dxfer_len <= (65535 * 512)) {
6620 features_out = ((dxfer_len >> 9) & 0xffff);
6622 /* The transfer is too big. */
6626 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6627 protocol = AP_PROTO_FPDMA;
6630 protocol |= AP_EXTEND;
6632 retval = scsi_ata_pass(csio,
6635 /*flags*/ CAM_DIR_IN,
6637 /*protocol*/ protocol,
6638 /*ata_flags*/ ata_flags,
6639 /*features*/ features_out,
6640 /*sector_count*/ sectors_out,
6642 /*command*/ command_out,
6645 /*auxiliary*/ auxiliary,
6647 /*data_ptr*/ data_ptr,
6648 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6649 /*cdb_storage*/ cdb_storage,
6650 /*cdb_storage_len*/ cdb_storage_len,
6651 /*minimum_cmd_size*/ 0,
6652 /*sense_len*/ SSD_FULL_SIZE,
6653 /*timeout*/ timeout);