2 * Implementation of SCSI Direct Access Peripheral driver for CAM.
4 * Copyright (c) 1997 Justin T. Gibbs.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
38 #include <sys/sysctl.h>
39 #include <sys/taskqueue.h>
41 #include <sys/mutex.h>
43 #include <sys/devicestat.h>
44 #include <sys/eventhandler.h>
45 #include <sys/malloc.h>
47 #include <sys/endian.h>
50 #include <geom/geom.h>
51 #include <geom/geom_disk.h>
60 #include <cam/cam_ccb.h>
61 #include <cam/cam_periph.h>
62 #include <cam/cam_xpt_periph.h>
63 #include <cam/cam_sim.h>
64 #include <cam/cam_iosched.h>
66 #include <cam/scsi/scsi_message.h>
67 #include <cam/scsi/scsi_da.h>
71 * Note that there are probe ordering dependencies here. The order isn't
72 * controlled by this enumeration, but by explicit state transitions in
73 * dastart() and dadone(). Here are some of the dependencies:
75 * 1. RC should come first, before RC16, unless there is evidence that RC16
77 * 2. BDC needs to come before any of the ATA probes, or the ZONE probe.
78 * 3. The ATA probes should go in this order:
79 * ATA -> LOGDIR -> IDDIR -> SUP -> ATA_ZONE
85 DA_STATE_PROBE_BLK_LIMITS,
88 DA_STATE_PROBE_ATA_LOGDIR,
89 DA_STATE_PROBE_ATA_IDDIR,
90 DA_STATE_PROBE_ATA_SUP,
91 DA_STATE_PROBE_ATA_ZONE,
97 DA_FLAG_PACK_INVALID = 0x000001,
98 DA_FLAG_NEW_PACK = 0x000002,
99 DA_FLAG_PACK_LOCKED = 0x000004,
100 DA_FLAG_PACK_REMOVABLE = 0x000008,
101 DA_FLAG_NEED_OTAG = 0x000020,
102 DA_FLAG_WAS_OTAG = 0x000040,
103 DA_FLAG_RETRY_UA = 0x000080,
104 DA_FLAG_OPEN = 0x000100,
105 DA_FLAG_SCTX_INIT = 0x000200,
106 DA_FLAG_CAN_RC16 = 0x000400,
107 DA_FLAG_PROBED = 0x000800,
108 DA_FLAG_DIRTY = 0x001000,
109 DA_FLAG_ANNOUNCED = 0x002000,
110 DA_FLAG_CAN_ATA_DMA = 0x004000,
111 DA_FLAG_CAN_ATA_LOG = 0x008000,
112 DA_FLAG_CAN_ATA_IDLOG = 0x010000,
113 DA_FLAG_CAN_ATA_SUPCAP = 0x020000,
114 DA_FLAG_CAN_ATA_ZONE = 0x040000
119 DA_Q_NO_SYNC_CACHE = 0x01,
120 DA_Q_NO_6_BYTE = 0x02,
121 DA_Q_NO_PREVENT = 0x04,
124 DA_Q_NO_UNMAP = 0x20,
125 DA_Q_RETRY_BUSY = 0x40,
127 DA_Q_STRICT_UNMAP = 0x100
130 #define DA_Q_BIT_STRING \
132 "\001NO_SYNC_CACHE" \
143 DA_CCB_PROBE_RC = 0x01,
144 DA_CCB_PROBE_RC16 = 0x02,
145 DA_CCB_PROBE_LBP = 0x03,
146 DA_CCB_PROBE_BLK_LIMITS = 0x04,
147 DA_CCB_PROBE_BDC = 0x05,
148 DA_CCB_PROBE_ATA = 0x06,
149 DA_CCB_BUFFER_IO = 0x07,
151 DA_CCB_DELETE = 0x0B,
153 DA_CCB_PROBE_ZONE = 0x0D,
154 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
155 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
156 DA_CCB_PROBE_ATA_SUP = 0x10,
157 DA_CCB_PROBE_ATA_ZONE = 0x11,
158 DA_CCB_TYPE_MASK = 0x1F,
159 DA_CCB_RETRY_UA = 0x20
163 * Order here is important for method choice
165 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
166 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
167 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
168 * import taking 5mins.
179 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
180 DA_DELETE_MAX = DA_DELETE_ZERO
184 * For SCSI, host managed drives show up as a separate device type. For
185 * ATA, host managed drives also have a different device signature.
186 * XXX KDM figure out the ATA host managed signature.
190 DA_ZONE_DRIVE_MANAGED = 0x01,
191 DA_ZONE_HOST_AWARE = 0x02,
192 DA_ZONE_HOST_MANAGED = 0x03
196 * We distinguish between these interface cases in addition to the drive type:
197 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
198 * o ATA drive behind a SCSI translation layer that does not know about
199 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
200 * case, we would need to share the ATA code with the ada(4) driver.
210 DA_ZONE_FLAG_RZ_SUP = 0x0001,
211 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
212 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
213 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
214 DA_ZONE_FLAG_RWP_SUP = 0x0010,
215 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
216 DA_ZONE_FLAG_OPEN_SUP |
217 DA_ZONE_FLAG_CLOSE_SUP |
218 DA_ZONE_FLAG_FINISH_SUP |
219 DA_ZONE_FLAG_RWP_SUP),
220 DA_ZONE_FLAG_URSWRZ = 0x0020,
221 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
222 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
223 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
224 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
225 DA_ZONE_FLAG_OPT_NONSEQ_SET |
226 DA_ZONE_FLAG_MAX_SEQ_SET)
229 static struct da_zone_desc {
232 } da_zone_desc_table[] = {
233 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
234 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
235 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
236 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
237 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
240 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
242 static da_delete_func_t da_delete_trim;
243 static da_delete_func_t da_delete_unmap;
244 static da_delete_func_t da_delete_ws;
246 static const void * da_delete_functions[] = {
256 static const char *da_delete_method_names[] =
257 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
258 static const char *da_delete_method_desc[] =
259 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
260 "WRITE SAME(10) with UNMAP", "ZERO" };
262 /* Offsets into our private area for storing information */
263 #define ccb_state ppriv_field0
264 #define ccb_bp ppriv_ptr1
269 u_int8_t secs_per_track;
270 u_int32_t secsize; /* Number of bytes/sector */
271 u_int64_t sectors; /* total number sectors */
276 #define UNMAP_RANGE_MAX 0xffffffff
277 #define UNMAP_HEAD_SIZE 8
278 #define UNMAP_RANGE_SIZE 16
279 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
280 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
283 #define WS10_MAX_BLKS 0xffff
284 #define WS16_MAX_BLKS 0xffffffff
285 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
286 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
288 #define DA_WORK_TUR (1 << 16)
291 struct cam_iosched_softc *cam_iosched;
292 struct bio_queue_head delete_run_queue;
293 LIST_HEAD(, ccb_hdr) pending_ccbs;
294 int refcount; /* Active xpt_action() calls */
298 int minimum_cmd_size;
301 int delete_available; /* Delete methods possibly available */
302 da_zone_mode zone_mode;
303 da_zone_interface zone_interface;
304 da_zone_flags zone_flags;
305 struct ata_gp_log_dir ata_logdir;
306 int valid_logdir_len;
307 struct ata_identify_log_pages ata_iddir;
309 uint64_t optimal_seq_zones;
310 uint64_t optimal_nonseq_zones;
311 uint64_t max_seq_zones;
313 uint32_t unmap_max_ranges;
314 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
316 uint32_t unmap_gran_align;
317 uint64_t ws_max_blks;
318 da_delete_methods delete_method_pref;
319 da_delete_methods delete_method;
320 da_delete_func_t *delete_func;
323 struct disk_params params;
326 struct task sysctl_task;
327 struct sysctl_ctx_list sysctl_ctx;
328 struct sysctl_oid *sysctl_tree;
329 struct callout sendordered_c;
331 uint8_t unmap_buf[UNMAP_BUF_SIZE];
332 struct scsi_read_capacity_data_long rcaplong;
333 struct callout mediapoll_c;
335 struct sysctl_ctx_list sysctl_stats_ctx;
336 struct sysctl_oid *sysctl_stats_tree;
341 #define DA_ANNOUNCETMP_SZ 80
342 char announce_temp[DA_ANNOUNCETMP_SZ];
343 #define DA_ANNOUNCE_SZ 400
344 char announcebuf[DA_ANNOUNCE_SZ];
347 #define dadeleteflag(softc, delete_method, enable) \
349 softc->delete_available |= (1 << delete_method); \
351 softc->delete_available &= ~(1 << delete_method); \
354 struct da_quirk_entry {
355 struct scsi_inquiry_pattern inq_pat;
359 static const char quantum[] = "QUANTUM";
360 static const char microp[] = "MICROP";
362 static struct da_quirk_entry da_quirk_table[] =
364 /* SPI, FC devices */
367 * Fujitsu M2513A MO drives.
368 * Tested devices: M2513A2 firmware versions 1200 & 1300.
369 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
370 * Reported by: W.Scholten <whs@xs4all.nl>
372 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
373 /*quirks*/ DA_Q_NO_SYNC_CACHE
377 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
378 /*quirks*/ DA_Q_NO_SYNC_CACHE
382 * This particular Fujitsu drive doesn't like the
383 * synchronize cache command.
384 * Reported by: Tom Jackson <toj@gorilla.net>
386 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
387 /*quirks*/ DA_Q_NO_SYNC_CACHE
391 * This drive doesn't like the synchronize cache command
392 * either. Reported by: Matthew Jacob <mjacob@feral.com>
393 * in NetBSD PR kern/6027, August 24, 1998.
395 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
396 /*quirks*/ DA_Q_NO_SYNC_CACHE
400 * This drive doesn't like the synchronize cache command
401 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
404 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
405 /*quirks*/ DA_Q_NO_SYNC_CACHE
409 * Doesn't like the synchronize cache command.
410 * Reported by: Blaz Zupan <blaz@gold.amis.net>
412 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
413 /*quirks*/ DA_Q_NO_SYNC_CACHE
417 * Doesn't like the synchronize cache command.
418 * Reported by: Blaz Zupan <blaz@gold.amis.net>
420 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
421 /*quirks*/ DA_Q_NO_SYNC_CACHE
425 * Doesn't like the synchronize cache command.
427 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
428 /*quirks*/ DA_Q_NO_SYNC_CACHE
432 * Doesn't like the synchronize cache command.
433 * Reported by: walter@pelissero.de
435 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
436 /*quirks*/ DA_Q_NO_SYNC_CACHE
440 * Doesn't work correctly with 6 byte reads/writes.
441 * Returns illegal request, and points to byte 9 of the
443 * Reported by: Adam McDougall <bsdx@spawnet.com>
445 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
446 /*quirks*/ DA_Q_NO_6_BYTE
450 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
451 /*quirks*/ DA_Q_NO_6_BYTE
455 * Doesn't like the synchronize cache command.
456 * Reported by: walter@pelissero.de
458 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
459 /*quirks*/ DA_Q_NO_SYNC_CACHE
463 * The CISS RAID controllers do not support SYNC_CACHE
465 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
466 /*quirks*/ DA_Q_NO_SYNC_CACHE
470 * The STEC SSDs sometimes hang on UNMAP.
472 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
473 /*quirks*/ DA_Q_NO_UNMAP
477 * VMware returns BUSY status when storage has transient
478 * connectivity problems, so better wait.
479 * Also VMware returns odd errors on misaligned UNMAPs.
481 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
482 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP
484 /* USB mass storage devices supported by umass(4) */
487 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
490 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
491 /*quirks*/ DA_Q_NO_SYNC_CACHE
495 * Power Quotient Int. (PQI) USB flash key
498 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
499 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
503 * Creative Nomad MUVO mp3 player (USB)
506 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
507 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
511 * Jungsoft NEXDISK USB flash key
514 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
515 /*quirks*/ DA_Q_NO_SYNC_CACHE
519 * FreeDik USB Mini Data Drive
522 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
523 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
527 * Sigmatel USB Flash MP3 Player
530 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
531 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
535 * Neuros USB Digital Audio Computer
538 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
539 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
543 * SEAGRAND NP-900 MP3 Player
546 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
547 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
551 * iRiver iFP MP3 player (with UMS Firmware)
552 * PR: kern/54881, i386/63941, kern/66124
554 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
555 /*quirks*/ DA_Q_NO_SYNC_CACHE
559 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
562 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
563 /*quirks*/ DA_Q_NO_SYNC_CACHE
567 * ZICPlay USB MP3 Player with FM
570 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
571 /*quirks*/ DA_Q_NO_SYNC_CACHE
575 * TEAC USB floppy mechanisms
577 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
578 /*quirks*/ DA_Q_NO_SYNC_CACHE
582 * Kingston DataTraveler II+ USB Pen-Drive.
583 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
585 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
586 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
594 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
595 /*quirks*/ DA_Q_NO_SYNC_CACHE
599 * Motorola E398 Mobile Phone (TransFlash memory card).
600 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
603 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
604 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
608 * Qware BeatZkey! Pro
611 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
612 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
616 * Time DPA20B 1GB MP3 Player
619 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
620 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
624 * Samsung USB key 128Mb
627 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
628 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
632 * Kingston DataTraveler 2.0 USB Flash memory.
635 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
636 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
640 * Creative MUVO Slim mp3 player (USB)
643 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
644 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
648 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
651 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
652 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
656 * SanDisk Micro Cruzer 128MB
659 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
660 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
664 * TOSHIBA TransMemory USB sticks
667 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
668 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
672 * PNY USB 3.0 Flash Drives
674 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
675 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
680 * PR: usb/75578, usb/72344, usb/65436
682 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
683 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
689 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
690 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16
694 * Genesys 6-in-1 Card Reader
697 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
698 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
702 * Rekam Digital CAMERA
705 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
706 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
710 * iRiver H10 MP3 player
713 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
714 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
718 * iRiver U10 MP3 player
721 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
722 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
729 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
730 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
734 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
737 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
738 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
745 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
746 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
750 * Philips USB Key Audio KEY013
753 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
754 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
761 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
762 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
769 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
770 /*quirks*/ DA_Q_NO_SYNC_CACHE
774 * I/O Magic USB flash - Giga Bank
777 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
778 /*quirks*/ DA_Q_NO_SYNC_CACHE
782 * JoyFly 128mb USB Flash Drive
785 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
786 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
793 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
794 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
798 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
801 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
802 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
806 * Samsung YP-U3 mp3-player
809 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
810 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
813 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
814 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
818 * Sony Cyber-Shot DSC cameras
821 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
822 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
825 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
826 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
829 /* At least several Transcent USB sticks lie on RC16. */
830 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
831 "*"}, /*quirks*/ DA_Q_NO_RC16
835 * I-O Data USB Flash Disk
838 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
839 "*"}, /*quirks*/ DA_Q_NO_RC16
841 /* ATA/SATA devices over SAS/USB/... */
843 /* Hitachi Advanced Format (4k) drives */
844 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
848 /* Micron Advanced Format (4k) drives */
849 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
853 /* Samsung Advanced Format (4k) drives */
854 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
858 /* Samsung Advanced Format (4k) drives */
859 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
863 /* Samsung Advanced Format (4k) drives */
864 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
868 /* Samsung Advanced Format (4k) drives */
869 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
873 /* Seagate Barracuda Green Advanced Format (4k) drives */
874 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
878 /* Seagate Barracuda Green Advanced Format (4k) drives */
879 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
883 /* Seagate Barracuda Green Advanced Format (4k) drives */
884 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
888 /* Seagate Barracuda Green Advanced Format (4k) drives */
889 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
893 /* Seagate Barracuda Green Advanced Format (4k) drives */
894 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
898 /* Seagate Barracuda Green Advanced Format (4k) drives */
899 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
903 /* Seagate Momentus Advanced Format (4k) drives */
904 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
908 /* Seagate Momentus Advanced Format (4k) drives */
909 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
913 /* Seagate Momentus Advanced Format (4k) drives */
914 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
918 /* Seagate Momentus Advanced Format (4k) drives */
919 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
923 /* Seagate Momentus Advanced Format (4k) drives */
924 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
928 /* Seagate Momentus Advanced Format (4k) drives */
929 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
933 /* Seagate Momentus Advanced Format (4k) drives */
934 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
938 /* Seagate Momentus Advanced Format (4k) drives */
939 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
943 /* Seagate Momentus Advanced Format (4k) drives */
944 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
948 /* Seagate Momentus Advanced Format (4k) drives */
949 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
953 /* Seagate Momentus Advanced Format (4k) drives */
954 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
958 /* Seagate Momentus Advanced Format (4k) drives */
959 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
963 /* Seagate Momentus Advanced Format (4k) drives */
964 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
968 /* Seagate Momentus Advanced Format (4k) drives */
969 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
973 /* Seagate Momentus Thin Advanced Format (4k) drives */
974 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
978 /* Seagate Momentus Thin Advanced Format (4k) drives */
979 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
983 /* WDC Caviar Green Advanced Format (4k) drives */
984 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
988 /* WDC Caviar Green Advanced Format (4k) drives */
989 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
993 /* WDC Caviar Green Advanced Format (4k) drives */
994 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
998 /* WDC Caviar Green Advanced Format (4k) drives */
999 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
1003 /* WDC Caviar Green Advanced Format (4k) drives */
1004 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
1008 /* WDC Caviar Green Advanced Format (4k) drives */
1009 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
1013 /* WDC Caviar Green Advanced Format (4k) drives */
1014 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1018 /* WDC Caviar Green Advanced Format (4k) drives */
1019 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1023 /* WDC Scorpio Black Advanced Format (4k) drives */
1024 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1028 /* WDC Scorpio Black Advanced Format (4k) drives */
1029 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1033 /* WDC Scorpio Black Advanced Format (4k) drives */
1034 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1038 /* WDC Scorpio Black Advanced Format (4k) drives */
1039 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1043 /* WDC Scorpio Blue Advanced Format (4k) drives */
1044 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1048 /* WDC Scorpio Blue Advanced Format (4k) drives */
1049 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1053 /* WDC Scorpio Blue Advanced Format (4k) drives */
1054 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1058 /* WDC Scorpio Blue Advanced Format (4k) drives */
1059 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1064 * Olympus FE-210 camera
1066 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1067 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1071 * LG UP3S MP3 player
1073 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1074 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1078 * Laser MP3-2GA13 MP3 player
1080 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1081 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1085 * LaCie external 250GB Hard drive des by Porsche
1086 * Submitted by: Ben Stuyts <ben@altesco.nl>
1089 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1090 /*quirks*/ DA_Q_NO_SYNC_CACHE
1095 * Corsair Force 2 SSDs
1096 * 4k optimised & trim only works in 4k requests + 4k aligned
1098 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1103 * Corsair Force 3 SSDs
1104 * 4k optimised & trim only works in 4k requests + 4k aligned
1106 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1111 * Corsair Neutron GTX SSDs
1112 * 4k optimised & trim only works in 4k requests + 4k aligned
1114 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1119 * Corsair Force GT & GS SSDs
1120 * 4k optimised & trim only works in 4k requests + 4k aligned
1122 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1128 * 4k optimised & trim only works in 4k requests + 4k aligned
1130 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1135 * Crucial RealSSD C300 SSDs
1138 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1139 "*" }, /*quirks*/DA_Q_4K
1143 * Intel 320 Series SSDs
1144 * 4k optimised & trim only works in 4k requests + 4k aligned
1146 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1151 * Intel 330 Series SSDs
1152 * 4k optimised & trim only works in 4k requests + 4k aligned
1154 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1159 * Intel 510 Series SSDs
1160 * 4k optimised & trim only works in 4k requests + 4k aligned
1162 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1167 * Intel 520 Series SSDs
1168 * 4k optimised & trim only works in 4k requests + 4k aligned
1170 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1175 * Intel S3610 Series SSDs
1176 * 4k optimised & trim only works in 4k requests + 4k aligned
1178 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1183 * Intel X25-M Series SSDs
1184 * 4k optimised & trim only works in 4k requests + 4k aligned
1186 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1191 * Kingston E100 Series SSDs
1192 * 4k optimised & trim only works in 4k requests + 4k aligned
1194 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1199 * Kingston HyperX 3k SSDs
1200 * 4k optimised & trim only works in 4k requests + 4k aligned
1202 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1207 * Marvell SSDs (entry taken from OpenSolaris)
1208 * 4k optimised & trim only works in 4k requests + 4k aligned
1210 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1215 * OCZ Agility 2 SSDs
1216 * 4k optimised & trim only works in 4k requests + 4k aligned
1218 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1223 * OCZ Agility 3 SSDs
1224 * 4k optimised & trim only works in 4k requests + 4k aligned
1226 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1231 * OCZ Deneva R Series SSDs
1232 * 4k optimised & trim only works in 4k requests + 4k aligned
1234 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1239 * OCZ Vertex 2 SSDs (inc pro series)
1240 * 4k optimised & trim only works in 4k requests + 4k aligned
1242 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1248 * 4k optimised & trim only works in 4k requests + 4k aligned
1250 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1256 * 4k optimised & trim only works in 4k requests + 4k aligned
1258 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1263 * Samsung 750 Series SSDs
1264 * 4k optimised & trim only works in 4k requests + 4k aligned
1266 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" },
1271 * Samsung 830 Series SSDs
1272 * 4k optimised & trim only works in 4k requests + 4k aligned
1274 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1280 * 4k optimised & trim only works in 4k requests + 4k aligned
1282 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1288 * 4k optimised & trim only works in 4k requests + 4k aligned
1290 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" },
1296 * 4k optimised & trim only works in 4k requests + 4k aligned
1298 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1303 * Samsung 843T Series SSDs (MZ7WD*)
1304 * Samsung PM851 Series SSDs (MZ7TE*)
1305 * Samsung PM853T Series SSDs (MZ7GE*)
1306 * Samsung SM863 Series SSDs (MZ7KM*)
1309 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1314 * SuperTalent TeraDrive CT SSDs
1315 * 4k optimised & trim only works in 4k requests + 4k aligned
1317 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1322 * XceedIOPS SATA SSDs
1325 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1330 * Hama Innostor USB-Stick
1332 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1333 /*quirks*/DA_Q_NO_RC16
1337 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1338 * Drive Managed SATA hard drive. This drive doesn't report
1339 * in firmware that it is a drive managed SMR drive.
1341 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS0002*", "*" },
1342 /*quirks*/DA_Q_SMR_DM
1346 * MX-ES USB Drive by Mach Xtreme
1348 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1349 /*quirks*/DA_Q_NO_RC16
1353 static disk_strategy_t dastrategy;
1354 static dumper_t dadump;
1355 static periph_init_t dainit;
1356 static void daasync(void *callback_arg, u_int32_t code,
1357 struct cam_path *path, void *arg);
1358 static void dasysctlinit(void *context, int pending);
1359 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1360 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1361 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1362 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1363 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1364 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1365 static void dadeletemethodset(struct da_softc *softc,
1366 da_delete_methods delete_method);
1367 static off_t dadeletemaxsize(struct da_softc *softc,
1368 da_delete_methods delete_method);
1369 static void dadeletemethodchoose(struct da_softc *softc,
1370 da_delete_methods default_method);
1371 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1373 static periph_ctor_t daregister;
1374 static periph_dtor_t dacleanup;
1375 static periph_start_t dastart;
1376 static periph_oninv_t daoninvalidate;
1377 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1378 static void dadone(struct cam_periph *periph,
1379 union ccb *done_ccb);
1380 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1381 u_int32_t sense_flags);
1382 static void daprevent(struct cam_periph *periph, int action);
1383 static void dareprobe(struct cam_periph *periph);
1384 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1386 struct scsi_read_capacity_data_long *rcaplong,
1388 static timeout_t dasendorderedtag;
1389 static void dashutdown(void *arg, int howto);
1390 static timeout_t damediapoll;
1392 #ifndef DA_DEFAULT_POLL_PERIOD
1393 #define DA_DEFAULT_POLL_PERIOD 3
1396 #ifndef DA_DEFAULT_TIMEOUT
1397 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1400 #ifndef DA_DEFAULT_SOFTTIMEOUT
1401 #define DA_DEFAULT_SOFTTIMEOUT 0
1404 #ifndef DA_DEFAULT_RETRY
1405 #define DA_DEFAULT_RETRY 4
1408 #ifndef DA_DEFAULT_SEND_ORDERED
1409 #define DA_DEFAULT_SEND_ORDERED 1
1412 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1413 static int da_retry_count = DA_DEFAULT_RETRY;
1414 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1415 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1416 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1418 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1419 "CAM Direct Access Disk driver");
1420 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1421 &da_poll_period, 0, "Media polling period in seconds");
1422 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1423 &da_retry_count, 0, "Normal I/O retry count");
1424 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1425 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1426 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1427 &da_send_ordered, 0, "Send Ordered Tags");
1429 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1430 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1431 "Soft I/O timeout (ms)");
1432 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1435 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1436 * to the default timeout, we check to see whether an ordered
1437 * tagged transaction is appropriate to prevent simple tag
1438 * starvation. Since we'd like to ensure that there is at least
1439 * 1/2 of the timeout length left for a starved transaction to
1440 * complete after we've sent an ordered tag, we must poll at least
1441 * four times in every timeout period. This takes care of the worst
1442 * case where a starved transaction starts during an interval that
1443 * meets the requirement "don't send an ordered tag" test so it takes
1444 * us two intervals to determine that a tag must be sent.
1446 #ifndef DA_ORDEREDTAG_INTERVAL
1447 #define DA_ORDEREDTAG_INTERVAL 4
1450 static struct periph_driver dadriver =
1453 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1456 PERIPHDRIVER_DECLARE(da, dadriver);
1458 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1461 daopen(struct disk *dp)
1463 struct cam_periph *periph;
1464 struct da_softc *softc;
1467 periph = (struct cam_periph *)dp->d_drv1;
1468 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1472 cam_periph_lock(periph);
1473 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1474 cam_periph_unlock(periph);
1475 cam_periph_release(periph);
1479 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1482 softc = (struct da_softc *)periph->softc;
1485 /* Wait for the disk size update. */
1486 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1489 xpt_print(periph->path, "unable to retrieve capacity data\n");
1491 if (periph->flags & CAM_PERIPH_INVALID)
1494 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1495 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1496 daprevent(periph, PR_PREVENT);
1499 softc->flags &= ~DA_FLAG_PACK_INVALID;
1500 softc->flags |= DA_FLAG_OPEN;
1503 cam_periph_unhold(periph);
1504 cam_periph_unlock(periph);
1507 cam_periph_release(periph);
1513 daclose(struct disk *dp)
1515 struct cam_periph *periph;
1516 struct da_softc *softc;
1520 periph = (struct cam_periph *)dp->d_drv1;
1521 softc = (struct da_softc *)periph->softc;
1522 cam_periph_lock(periph);
1523 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1526 if (cam_periph_hold(periph, PRIBIO) == 0) {
1528 /* Flush disk cache. */
1529 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1530 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1531 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1532 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1533 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1534 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1535 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1537 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1538 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1539 softc->disk->d_devstat);
1540 softc->flags &= ~DA_FLAG_DIRTY;
1541 xpt_release_ccb(ccb);
1544 /* Allow medium removal. */
1545 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1546 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1547 daprevent(periph, PR_ALLOW);
1549 cam_periph_unhold(periph);
1553 * If we've got removeable media, mark the blocksize as
1554 * unavailable, since it could change when new media is
1557 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1558 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1560 softc->flags &= ~DA_FLAG_OPEN;
1561 while (softc->refcount != 0)
1562 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1563 cam_periph_unlock(periph);
1564 cam_periph_release(periph);
1569 daschedule(struct cam_periph *periph)
1571 struct da_softc *softc = (struct da_softc *)periph->softc;
1573 if (softc->state != DA_STATE_NORMAL)
1576 cam_iosched_schedule(softc->cam_iosched, periph);
1580 * Actually translate the requested transfer into one the physical driver
1581 * can understand. The transfer is described by a buf and will include
1582 * only one physical transfer.
1585 dastrategy(struct bio *bp)
1587 struct cam_periph *periph;
1588 struct da_softc *softc;
1590 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1591 softc = (struct da_softc *)periph->softc;
1593 cam_periph_lock(periph);
1596 * If the device has been made invalid, error out
1598 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1599 cam_periph_unlock(periph);
1600 biofinish(bp, NULL, ENXIO);
1604 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1607 * Zone commands must be ordered, because they can depend on the
1608 * effects of previously issued commands, and they may affect
1609 * commands after them.
1611 if (bp->bio_cmd == BIO_ZONE)
1612 bp->bio_flags |= BIO_ORDERED;
1615 * Place it in the queue of disk activities for this disk
1617 cam_iosched_queue_work(softc->cam_iosched, bp);
1620 * Schedule ourselves for performing the work.
1623 cam_periph_unlock(periph);
1629 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1631 struct cam_periph *periph;
1632 struct da_softc *softc;
1634 struct ccb_scsiio csio;
1639 periph = dp->d_drv1;
1640 softc = (struct da_softc *)periph->softc;
1641 cam_periph_lock(periph);
1642 secsize = softc->params.secsize;
1644 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1645 cam_periph_unlock(periph);
1650 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1651 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1652 scsi_read_write(&csio,
1656 /*read*/SCSI_RW_WRITE,
1658 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1661 /*data_ptr*/(u_int8_t *) virtual,
1662 /*dxfer_len*/length,
1663 /*sense_len*/SSD_FULL_SIZE,
1664 da_default_timeout * 1000);
1665 xpt_polled_action((union ccb *)&csio);
1667 error = cam_periph_error((union ccb *)&csio,
1668 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1669 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1670 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1671 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1673 printf("Aborting dump due to I/O error.\n");
1674 cam_periph_unlock(periph);
1679 * Sync the disk cache contents to the physical media.
1681 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1683 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1684 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1685 scsi_synchronize_cache(&csio,
1689 /*begin_lba*/0,/* Cover the whole disk */
1693 xpt_polled_action((union ccb *)&csio);
1695 error = cam_periph_error((union ccb *)&csio,
1696 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1697 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1698 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1699 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1701 xpt_print(periph->path, "Synchronize cache failed\n");
1703 cam_periph_unlock(periph);
1708 dagetattr(struct bio *bp)
1711 struct cam_periph *periph;
1713 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1714 cam_periph_lock(periph);
1715 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1717 cam_periph_unlock(periph);
1719 bp->bio_completed = bp->bio_length;
1729 * Install a global async callback. This callback will
1730 * receive async callbacks like "new device found".
1732 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1734 if (status != CAM_REQ_CMP) {
1735 printf("da: Failed to attach master async callback "
1736 "due to status 0x%x!\n", status);
1737 } else if (da_send_ordered) {
1739 /* Register our shutdown event handler */
1740 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1741 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1742 printf("dainit: shutdown event registration failed!\n");
1747 * Callback from GEOM, called when it has finished cleaning up its
1751 dadiskgonecb(struct disk *dp)
1753 struct cam_periph *periph;
1755 periph = (struct cam_periph *)dp->d_drv1;
1756 cam_periph_release(periph);
1760 daoninvalidate(struct cam_periph *periph)
1762 struct da_softc *softc;
1764 softc = (struct da_softc *)periph->softc;
1767 * De-register any async callbacks.
1769 xpt_register_async(0, daasync, periph, periph->path);
1771 softc->flags |= DA_FLAG_PACK_INVALID;
1773 softc->invalidations++;
1777 * Return all queued I/O with ENXIO.
1778 * XXX Handle any transactions queued to the card
1779 * with XPT_ABORT_CCB.
1781 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
1784 * Tell GEOM that we've gone away, we'll get a callback when it is
1785 * done cleaning up its resources.
1787 disk_gone(softc->disk);
1791 dacleanup(struct cam_periph *periph)
1793 struct da_softc *softc;
1795 softc = (struct da_softc *)periph->softc;
1797 cam_periph_unlock(periph);
1799 cam_iosched_fini(softc->cam_iosched);
1802 * If we can't free the sysctl tree, oh well...
1804 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
1806 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1807 xpt_print(periph->path,
1808 "can't remove sysctl stats context\n");
1810 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1811 xpt_print(periph->path,
1812 "can't remove sysctl context\n");
1815 callout_drain(&softc->mediapoll_c);
1816 disk_destroy(softc->disk);
1817 callout_drain(&softc->sendordered_c);
1818 free(softc, M_DEVBUF);
1819 cam_periph_lock(periph);
1823 daasync(void *callback_arg, u_int32_t code,
1824 struct cam_path *path, void *arg)
1826 struct cam_periph *periph;
1827 struct da_softc *softc;
1829 periph = (struct cam_periph *)callback_arg;
1831 case AC_FOUND_DEVICE:
1833 struct ccb_getdev *cgd;
1836 cgd = (struct ccb_getdev *)arg;
1840 if (cgd->protocol != PROTO_SCSI)
1842 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
1844 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1845 && SID_TYPE(&cgd->inq_data) != T_RBC
1846 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
1847 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
1851 * Allocate a peripheral instance for
1852 * this device and start the probe
1855 status = cam_periph_alloc(daregister, daoninvalidate,
1857 "da", CAM_PERIPH_BIO,
1859 AC_FOUND_DEVICE, cgd);
1861 if (status != CAM_REQ_CMP
1862 && status != CAM_REQ_INPROG)
1863 printf("daasync: Unable to attach to new device "
1864 "due to status 0x%x\n", status);
1867 case AC_ADVINFO_CHANGED:
1871 buftype = (uintptr_t)arg;
1872 if (buftype == CDAI_TYPE_PHYS_PATH) {
1873 struct da_softc *softc;
1875 softc = periph->softc;
1876 disk_attr_changed(softc->disk, "GEOM::physpath",
1881 case AC_UNIT_ATTENTION:
1884 int error_code, sense_key, asc, ascq;
1886 softc = (struct da_softc *)periph->softc;
1887 ccb = (union ccb *)arg;
1890 * Handle all UNIT ATTENTIONs except our own,
1891 * as they will be handled by daerror().
1893 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1894 scsi_extract_sense_ccb(ccb,
1895 &error_code, &sense_key, &asc, &ascq)) {
1896 if (asc == 0x2A && ascq == 0x09) {
1897 xpt_print(ccb->ccb_h.path,
1898 "Capacity data has changed\n");
1899 softc->flags &= ~DA_FLAG_PROBED;
1901 } else if (asc == 0x28 && ascq == 0x00) {
1902 softc->flags &= ~DA_FLAG_PROBED;
1903 disk_media_changed(softc->disk, M_NOWAIT);
1904 } else if (asc == 0x3F && ascq == 0x03) {
1905 xpt_print(ccb->ccb_h.path,
1906 "INQUIRY data has changed\n");
1907 softc->flags &= ~DA_FLAG_PROBED;
1911 cam_periph_async(periph, code, path, arg);
1915 softc = (struct da_softc *)periph->softc;
1916 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
1917 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1918 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
1926 struct ccb_hdr *ccbh;
1928 softc = (struct da_softc *)periph->softc;
1930 * Don't fail on the expected unit attention
1933 softc->flags |= DA_FLAG_RETRY_UA;
1934 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1935 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1938 case AC_INQ_CHANGED:
1939 softc = (struct da_softc *)periph->softc;
1940 softc->flags &= ~DA_FLAG_PROBED;
1946 cam_periph_async(periph, code, path, arg);
1950 dasysctlinit(void *context, int pending)
1952 struct cam_periph *periph;
1953 struct da_softc *softc;
1954 char tmpstr[80], tmpstr2[80];
1955 struct ccb_trans_settings cts;
1957 periph = (struct cam_periph *)context;
1959 * periph was held for us when this task was enqueued
1961 if (periph->flags & CAM_PERIPH_INVALID) {
1962 cam_periph_release(periph);
1966 softc = (struct da_softc *)periph->softc;
1967 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1968 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1970 sysctl_ctx_init(&softc->sysctl_ctx);
1971 softc->flags |= DA_FLAG_SCTX_INIT;
1972 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
1973 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1974 CTLFLAG_RD, 0, tmpstr, "device_index");
1975 if (softc->sysctl_tree == NULL) {
1976 printf("dasysctlinit: unable to allocate sysctl tree\n");
1977 cam_periph_release(periph);
1982 * Now register the sysctl handler, so the user can change the value on
1985 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1986 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
1987 softc, 0, dadeletemethodsysctl, "A",
1988 "BIO_DELETE execution method");
1989 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1990 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1991 softc, 0, dadeletemaxsysctl, "Q",
1992 "Maximum BIO_DELETE size");
1993 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1994 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1995 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1996 "Minimum CDB size");
1998 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1999 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
2000 softc, 0, dazonemodesysctl, "A",
2002 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
2003 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
2004 softc, 0, dazonesupsysctl, "A",
2006 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2007 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2008 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
2009 "Optimal Number of Open Sequential Write Preferred Zones");
2010 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2011 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2012 "optimal_nonseq_zones", CTLFLAG_RD,
2013 &softc->optimal_nonseq_zones,
2014 "Optimal Number of Non-Sequentially Written Sequential Write "
2016 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2017 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
2018 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
2019 "Maximum Number of Open Sequential Write Required Zones");
2021 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2022 SYSCTL_CHILDREN(softc->sysctl_tree),
2026 &softc->error_inject,
2028 "error_inject leaf");
2030 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2031 SYSCTL_CHILDREN(softc->sysctl_tree),
2037 "Unmapped I/O leaf");
2039 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2040 SYSCTL_CHILDREN(softc->sysctl_tree),
2049 * Add some addressing info.
2051 memset(&cts, 0, sizeof (cts));
2052 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2053 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2054 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2055 cam_periph_lock(periph);
2056 xpt_action((union ccb *)&cts);
2057 cam_periph_unlock(periph);
2058 if (cts.ccb_h.status != CAM_REQ_CMP) {
2059 cam_periph_release(periph);
2062 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2063 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2064 if (fc->valid & CTS_FC_VALID_WWPN) {
2065 softc->wwpn = fc->wwpn;
2066 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2067 SYSCTL_CHILDREN(softc->sysctl_tree),
2068 OID_AUTO, "wwpn", CTLFLAG_RD,
2069 &softc->wwpn, "World Wide Port Name");
2075 * Now add some useful stats.
2076 * XXX These should live in cam_periph and be common to all periphs
2078 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2079 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2080 CTLFLAG_RD, 0, "Statistics");
2081 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2082 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2088 "Transport errors reported by the SIM");
2089 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2090 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2096 "Device timeouts reported by the SIM");
2097 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2098 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2100 "pack_invalidations",
2102 &softc->invalidations,
2104 "Device pack invalidations");
2107 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2108 softc->sysctl_tree);
2110 cam_periph_release(periph);
2114 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2118 struct da_softc *softc;
2120 softc = (struct da_softc *)arg1;
2122 value = softc->disk->d_delmaxsize;
2123 error = sysctl_handle_64(oidp, &value, 0, req);
2124 if ((error != 0) || (req->newptr == NULL))
2127 /* only accept values smaller than the calculated value */
2128 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2131 softc->disk->d_delmaxsize = value;
2137 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2141 value = *(int *)arg1;
2143 error = sysctl_handle_int(oidp, &value, 0, req);
2146 || (req->newptr == NULL))
2150 * Acceptable values here are 6, 10, 12 or 16.
2154 else if ((value > 6)
2157 else if ((value > 10)
2160 else if (value > 12)
2163 *(int *)arg1 = value;
2169 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2174 value = da_default_softtimeout / SBT_1MS;
2176 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2177 if ((error != 0) || (req->newptr == NULL))
2180 /* XXX Should clip this to a reasonable level */
2181 if (value > da_default_timeout * 1000)
2184 da_default_softtimeout = value * SBT_1MS;
2189 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2192 softc->delete_method = delete_method;
2193 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2194 softc->delete_func = da_delete_functions[delete_method];
2196 if (softc->delete_method > DA_DELETE_DISABLE)
2197 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2199 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2203 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2207 switch(delete_method) {
2208 case DA_DELETE_UNMAP:
2209 sectors = (off_t)softc->unmap_max_lba;
2211 case DA_DELETE_ATA_TRIM:
2212 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2214 case DA_DELETE_WS16:
2215 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2217 case DA_DELETE_ZERO:
2218 case DA_DELETE_WS10:
2219 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2225 return (off_t)softc->params.secsize *
2226 omin(sectors, softc->params.sectors);
2230 daprobedone(struct cam_periph *periph, union ccb *ccb)
2232 struct da_softc *softc;
2234 softc = (struct da_softc *)periph->softc;
2236 dadeletemethodchoose(softc, DA_DELETE_NONE);
2238 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2242 snprintf(buf, sizeof(buf), "Delete methods: <");
2244 for (i = 0; i <= DA_DELETE_MAX; i++) {
2245 if ((softc->delete_available & (1 << i)) == 0 &&
2246 i != softc->delete_method)
2249 strlcat(buf, ",", sizeof(buf));
2250 strlcat(buf, da_delete_method_names[i],
2252 if (i == softc->delete_method)
2253 strlcat(buf, "(*)", sizeof(buf));
2256 strlcat(buf, ">", sizeof(buf));
2257 printf("%s%d: %s\n", periph->periph_name,
2258 periph->unit_number, buf);
2262 * Since our peripheral may be invalidated by an error
2263 * above or an external event, we must release our CCB
2264 * before releasing the probe lock on the peripheral.
2265 * The peripheral will only go away once the last lock
2266 * is removed, and we need it around for the CCB release
2269 xpt_release_ccb(ccb);
2270 softc->state = DA_STATE_NORMAL;
2271 softc->flags |= DA_FLAG_PROBED;
2273 wakeup(&softc->disk->d_mediasize);
2274 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2275 softc->flags |= DA_FLAG_ANNOUNCED;
2276 cam_periph_unhold(periph);
2278 cam_periph_release_locked(periph);
2282 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2286 /* If available, prefer the method requested by user. */
2287 i = softc->delete_method_pref;
2288 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2289 if (methods & (1 << i)) {
2290 dadeletemethodset(softc, i);
2294 /* Use the pre-defined order to choose the best performing delete. */
2295 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2296 if (i == DA_DELETE_ZERO)
2298 if (softc->delete_available & (1 << i)) {
2299 dadeletemethodset(softc, i);
2304 /* Fallback to default. */
2305 dadeletemethodset(softc, default_method);
2309 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2313 struct da_softc *softc;
2314 int i, error, methods, value;
2316 softc = (struct da_softc *)arg1;
2318 value = softc->delete_method;
2319 if (value < 0 || value > DA_DELETE_MAX)
2322 p = da_delete_method_names[value];
2323 strncpy(buf, p, sizeof(buf));
2324 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2325 if (error != 0 || req->newptr == NULL)
2327 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2328 for (i = 0; i <= DA_DELETE_MAX; i++) {
2329 if (strcmp(buf, da_delete_method_names[i]) == 0)
2332 if (i > DA_DELETE_MAX)
2334 softc->delete_method_pref = i;
2335 dadeletemethodchoose(softc, DA_DELETE_NONE);
2340 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2343 struct da_softc *softc;
2346 softc = (struct da_softc *)arg1;
2348 switch (softc->zone_mode) {
2349 case DA_ZONE_DRIVE_MANAGED:
2350 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2352 case DA_ZONE_HOST_AWARE:
2353 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2355 case DA_ZONE_HOST_MANAGED:
2356 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2360 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2364 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2370 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2373 struct da_softc *softc;
2378 softc = (struct da_softc *)arg1;
2382 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2384 for (i = 0; i < sizeof(da_zone_desc_table) /
2385 sizeof(da_zone_desc_table[0]); i++) {
2386 if (softc->zone_flags & da_zone_desc_table[i].value) {
2388 sbuf_printf(&sb, ", ");
2391 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2396 sbuf_printf(&sb, "None");
2400 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2406 daregister(struct cam_periph *periph, void *arg)
2408 struct da_softc *softc;
2409 struct ccb_pathinq cpi;
2410 struct ccb_getdev *cgd;
2414 cgd = (struct ccb_getdev *)arg;
2416 printf("daregister: no getdev CCB, can't register device\n");
2417 return(CAM_REQ_CMP_ERR);
2420 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2423 if (softc == NULL) {
2424 printf("daregister: Unable to probe new device. "
2425 "Unable to allocate softc\n");
2426 return(CAM_REQ_CMP_ERR);
2429 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2430 printf("daregister: Unable to probe new device. "
2431 "Unable to allocate iosched memory\n");
2432 free(softc, M_DEVBUF);
2433 return(CAM_REQ_CMP_ERR);
2436 LIST_INIT(&softc->pending_ccbs);
2437 softc->state = DA_STATE_PROBE_RC;
2438 bioq_init(&softc->delete_run_queue);
2439 if (SID_IS_REMOVABLE(&cgd->inq_data))
2440 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2441 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2442 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2443 softc->unmap_gran = 0;
2444 softc->unmap_gran_align = 0;
2445 softc->ws_max_blks = WS16_MAX_BLKS;
2446 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2447 softc->rotating = 1;
2449 periph->softc = softc;
2452 * See if this device has any quirks.
2454 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2455 (caddr_t)da_quirk_table,
2456 nitems(da_quirk_table),
2457 sizeof(*da_quirk_table), scsi_inquiry_match);
2460 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2462 softc->quirks = DA_Q_NONE;
2464 /* Check if the SIM does not want 6 byte commands */
2465 bzero(&cpi, sizeof(cpi));
2466 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2467 cpi.ccb_h.func_code = XPT_PATH_INQ;
2468 xpt_action((union ccb *)&cpi);
2469 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2470 softc->quirks |= DA_Q_NO_6_BYTE;
2472 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2473 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2474 else if (softc->quirks & DA_Q_SMR_DM)
2475 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2477 softc->zone_mode = DA_ZONE_NONE;
2479 if (softc->zone_mode != DA_ZONE_NONE) {
2480 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2481 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2482 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2484 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2486 softc->zone_interface = DA_ZONE_IF_SCSI;
2489 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2492 * Take an exclusive refcount on the periph while dastart is called
2493 * to finish the probe. The reference will be dropped in dadone at
2496 (void)cam_periph_hold(periph, PRIBIO);
2499 * Schedule a periodic event to occasionally send an
2500 * ordered tag to a device.
2502 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2503 callout_reset(&softc->sendordered_c,
2504 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2505 dasendorderedtag, softc);
2507 cam_periph_unlock(periph);
2509 * RBC devices don't have to support READ(6), only READ(10).
2511 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2512 softc->minimum_cmd_size = 10;
2514 softc->minimum_cmd_size = 6;
2517 * Load the user's default, if any.
2519 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2520 periph->unit_number);
2521 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2524 * 6, 10, 12 and 16 are the currently permissible values.
2526 if (softc->minimum_cmd_size > 12)
2527 softc->minimum_cmd_size = 16;
2528 else if (softc->minimum_cmd_size > 10)
2529 softc->minimum_cmd_size = 12;
2530 else if (softc->minimum_cmd_size > 6)
2531 softc->minimum_cmd_size = 10;
2533 softc->minimum_cmd_size = 6;
2535 /* Predict whether device may support READ CAPACITY(16). */
2536 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2537 (softc->quirks & DA_Q_NO_RC16) == 0) {
2538 softc->flags |= DA_FLAG_CAN_RC16;
2539 softc->state = DA_STATE_PROBE_RC16;
2543 * Register this media as a disk.
2545 softc->disk = disk_alloc();
2546 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2547 periph->unit_number, 0,
2548 DEVSTAT_BS_UNAVAILABLE,
2549 SID_TYPE(&cgd->inq_data) |
2550 XPORT_DEVSTAT_TYPE(cpi.transport),
2551 DEVSTAT_PRIORITY_DISK);
2552 softc->disk->d_open = daopen;
2553 softc->disk->d_close = daclose;
2554 softc->disk->d_strategy = dastrategy;
2555 softc->disk->d_dump = dadump;
2556 softc->disk->d_getattr = dagetattr;
2557 softc->disk->d_gone = dadiskgonecb;
2558 softc->disk->d_name = "da";
2559 softc->disk->d_drv1 = periph;
2561 softc->maxio = DFLTPHYS; /* traditional default */
2562 else if (cpi.maxio > MAXPHYS)
2563 softc->maxio = MAXPHYS; /* for safety */
2565 softc->maxio = cpi.maxio;
2566 softc->disk->d_maxsize = softc->maxio;
2567 softc->disk->d_unit = periph->unit_number;
2568 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2569 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2570 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2571 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2572 softc->unmappedio = 1;
2573 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2575 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2576 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2577 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2578 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2579 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2580 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2581 softc->disk->d_hba_vendor = cpi.hba_vendor;
2582 softc->disk->d_hba_device = cpi.hba_device;
2583 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2584 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2587 * Acquire a reference to the periph before we register with GEOM.
2588 * We'll release this reference once GEOM calls us back (via
2589 * dadiskgonecb()) telling us that our provider has been freed.
2591 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2592 xpt_print(periph->path, "%s: lost periph during "
2593 "registration!\n", __func__);
2594 cam_periph_lock(periph);
2595 return (CAM_REQ_CMP_ERR);
2598 disk_create(softc->disk, DISK_VERSION);
2599 cam_periph_lock(periph);
2602 * Add async callbacks for events of interest.
2603 * I don't bother checking if this fails as,
2604 * in most cases, the system will function just
2605 * fine without them and the only alternative
2606 * would be to not attach the device on failure.
2608 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2609 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2610 AC_INQ_CHANGED, daasync, periph, periph->path);
2613 * Emit an attribute changed notification just in case
2614 * physical path information arrived before our async
2615 * event handler was registered, but after anyone attaching
2616 * to our disk device polled it.
2618 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2621 * Schedule a periodic media polling events.
2623 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2624 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2625 (cgd->inq_flags & SID_AEN) == 0 &&
2626 da_poll_period != 0)
2627 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2628 damediapoll, periph);
2630 xpt_schedule(periph, CAM_PRIORITY_DEV);
2632 return(CAM_REQ_CMP);
2636 da_zone_bio_to_scsi(int disk_zone_cmd)
2638 switch (disk_zone_cmd) {
2639 case DISK_ZONE_OPEN:
2640 return ZBC_OUT_SA_OPEN;
2641 case DISK_ZONE_CLOSE:
2642 return ZBC_OUT_SA_CLOSE;
2643 case DISK_ZONE_FINISH:
2644 return ZBC_OUT_SA_FINISH;
2646 return ZBC_OUT_SA_RWP;
2653 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2656 struct da_softc *softc;
2661 if (bp->bio_cmd != BIO_ZONE) {
2666 softc = periph->softc;
2668 switch (bp->bio_zone.zone_cmd) {
2669 case DISK_ZONE_OPEN:
2670 case DISK_ZONE_CLOSE:
2671 case DISK_ZONE_FINISH:
2672 case DISK_ZONE_RWP: {
2677 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2678 if (zone_sa == -1) {
2679 xpt_print(periph->path, "Cannot translate zone "
2680 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2686 lba = bp->bio_zone.zone_params.rwp.id;
2688 if (bp->bio_zone.zone_params.rwp.flags &
2689 DISK_ZONE_RWP_FLAG_ALL)
2690 zone_flags |= ZBC_OUT_ALL;
2692 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2693 scsi_zbc_out(&ccb->csio,
2694 /*retries*/ da_retry_count,
2696 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2697 /*service_action*/ zone_sa,
2699 /*zone_flags*/ zone_flags,
2702 /*sense_len*/ SSD_FULL_SIZE,
2703 /*timeout*/ da_default_timeout * 1000);
2706 * Note that in this case, even though we can
2707 * technically use NCQ, we don't bother for several
2709 * 1. It hasn't been tested on a SAT layer that
2710 * supports it. This is new as of SAT-4.
2711 * 2. Even when there is a SAT layer that supports
2712 * it, that SAT layer will also probably support
2713 * ZBC -> ZAC translation, since they are both
2714 * in the SAT-4 spec.
2715 * 3. Translation will likely be preferable to ATA
2716 * passthrough. LSI / Avago at least single
2717 * steps ATA passthrough commands in the HBA,
2718 * regardless of protocol, so unless that
2719 * changes, there is a performance penalty for
2720 * doing ATA passthrough no matter whether
2721 * you're using NCQ/FPDMA, DMA or PIO.
2722 * 4. It requires a 32-byte CDB, which at least at
2723 * this point in CAM requires a CDB pointer, which
2724 * would require us to allocate an additional bit
2725 * of storage separate from the CCB.
2727 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2728 /*retries*/ da_retry_count,
2730 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2732 /*zm_action*/ zone_sa,
2734 /*zone_flags*/ zone_flags,
2737 /*cdb_storage*/ NULL,
2738 /*cdb_storage_len*/ 0,
2739 /*sense_len*/ SSD_FULL_SIZE,
2740 /*timeout*/ da_default_timeout * 1000);
2743 xpt_print(periph->path,
2744 "scsi_ata_zac_mgmt_out() returned an "
2753 case DISK_ZONE_REPORT_ZONES: {
2755 uint32_t num_entries, alloc_size;
2756 struct disk_zone_report *rep;
2758 rep = &bp->bio_zone.zone_params.report;
2760 num_entries = rep->entries_allocated;
2761 if (num_entries == 0) {
2762 xpt_print(periph->path, "No entries allocated for "
2763 "Report Zones request\n");
2767 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2768 (sizeof(struct scsi_report_zones_desc) * num_entries);
2769 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2770 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2771 if (rz_ptr == NULL) {
2772 xpt_print(periph->path, "Unable to allocate memory "
2773 "for Report Zones request\n");
2778 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2779 scsi_zbc_in(&ccb->csio,
2780 /*retries*/ da_retry_count,
2782 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2783 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2784 /*zone_start_lba*/ rep->starting_id,
2785 /*zone_options*/ rep->rep_options,
2786 /*data_ptr*/ rz_ptr,
2787 /*dxfer_len*/ alloc_size,
2788 /*sense_len*/ SSD_FULL_SIZE,
2789 /*timeout*/ da_default_timeout * 1000);
2792 * Note that in this case, even though we can
2793 * technically use NCQ, we don't bother for several
2795 * 1. It hasn't been tested on a SAT layer that
2796 * supports it. This is new as of SAT-4.
2797 * 2. Even when there is a SAT layer that supports
2798 * it, that SAT layer will also probably support
2799 * ZBC -> ZAC translation, since they are both
2800 * in the SAT-4 spec.
2801 * 3. Translation will likely be preferable to ATA
2802 * passthrough. LSI / Avago at least single
2803 * steps ATA passthrough commands in the HBA,
2804 * regardless of protocol, so unless that
2805 * changes, there is a performance penalty for
2806 * doing ATA passthrough no matter whether
2807 * you're using NCQ/FPDMA, DMA or PIO.
2808 * 4. It requires a 32-byte CDB, which at least at
2809 * this point in CAM requires a CDB pointer, which
2810 * would require us to allocate an additional bit
2811 * of storage separate from the CCB.
2813 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2814 /*retries*/ da_retry_count,
2816 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2818 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2819 /*zone_id*/ rep->starting_id,
2820 /*zone_flags*/ rep->rep_options,
2821 /*data_ptr*/ rz_ptr,
2822 /*dxfer_len*/ alloc_size,
2823 /*cdb_storage*/ NULL,
2824 /*cdb_storage_len*/ 0,
2825 /*sense_len*/ SSD_FULL_SIZE,
2826 /*timeout*/ da_default_timeout * 1000);
2829 xpt_print(periph->path,
2830 "scsi_ata_zac_mgmt_in() returned an "
2837 * For BIO_ZONE, this isn't normally needed. However, it
2838 * is used by devstat_end_transaction_bio() to determine
2839 * how much data was transferred.
2842 * XXX KDM we have a problem. But I'm not sure how to fix
2843 * it. devstat uses bio_bcount - bio_resid to calculate
2844 * the amount of data transferred. The GEOM disk code
2845 * uses bio_length - bio_resid to calculate the amount of
2846 * data in bio_completed. We have different structure
2847 * sizes above and below the ada(4) driver. So, if we
2848 * use the sizes above, the amount transferred won't be
2849 * quite accurate for devstat. If we use different sizes
2850 * for bio_bcount and bio_length (above and below
2851 * respectively), then the residual needs to match one or
2852 * the other. Everything is calculated after the bio
2853 * leaves the driver, so changing the values around isn't
2854 * really an option. For now, just set the count to the
2855 * passed in length. This means that the calculations
2856 * above (e.g. bio_completed) will be correct, but the
2857 * amount of data reported to devstat will be slightly
2858 * under or overstated.
2860 bp->bio_bcount = bp->bio_length;
2866 case DISK_ZONE_GET_PARAMS: {
2867 struct disk_zone_disk_params *params;
2869 params = &bp->bio_zone.zone_params.disk_params;
2870 bzero(params, sizeof(*params));
2872 switch (softc->zone_mode) {
2873 case DA_ZONE_DRIVE_MANAGED:
2874 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
2876 case DA_ZONE_HOST_AWARE:
2877 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
2879 case DA_ZONE_HOST_MANAGED:
2880 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
2884 params->zone_mode = DISK_ZONE_MODE_NONE;
2888 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
2889 params->flags |= DISK_ZONE_DISK_URSWRZ;
2891 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
2892 params->optimal_seq_zones = softc->optimal_seq_zones;
2893 params->flags |= DISK_ZONE_OPT_SEQ_SET;
2896 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
2897 params->optimal_nonseq_zones =
2898 softc->optimal_nonseq_zones;
2899 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
2902 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
2903 params->max_seq_zones = softc->max_seq_zones;
2904 params->flags |= DISK_ZONE_MAX_SEQ_SET;
2906 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
2907 params->flags |= DISK_ZONE_RZ_SUP;
2909 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
2910 params->flags |= DISK_ZONE_OPEN_SUP;
2912 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
2913 params->flags |= DISK_ZONE_CLOSE_SUP;
2915 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
2916 params->flags |= DISK_ZONE_FINISH_SUP;
2918 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
2919 params->flags |= DISK_ZONE_RWP_SUP;
2930 dastart(struct cam_periph *periph, union ccb *start_ccb)
2932 struct da_softc *softc;
2934 softc = (struct da_softc *)periph->softc;
2936 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2939 switch (softc->state) {
2940 case DA_STATE_NORMAL:
2946 bp = cam_iosched_next_bio(softc->cam_iosched);
2948 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2949 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2950 scsi_test_unit_ready(&start_ccb->csio,
2951 /*retries*/ da_retry_count,
2955 da_default_timeout * 1000);
2956 start_ccb->ccb_h.ccb_bp = NULL;
2957 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2958 xpt_action(start_ccb);
2960 xpt_release_ccb(start_ccb);
2964 if (bp->bio_cmd == BIO_DELETE) {
2965 if (softc->delete_func != NULL) {
2966 softc->delete_func(periph, start_ccb, bp);
2969 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
2970 biofinish(bp, NULL, 0);
2975 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2976 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2977 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */
2980 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2981 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2982 softc->flags &= ~DA_FLAG_NEED_OTAG;
2983 softc->flags |= DA_FLAG_WAS_OTAG;
2984 tag_code = MSG_ORDERED_Q_TAG;
2986 tag_code = MSG_SIMPLE_Q_TAG;
2989 switch (bp->bio_cmd) {
2996 biotrack(bp, __func__);
2998 if (bp->bio_cmd == BIO_WRITE) {
2999 softc->flags |= DA_FLAG_DIRTY;
3000 rw_op = SCSI_RW_WRITE;
3002 rw_op = SCSI_RW_READ;
3005 data_ptr = bp->bio_data;
3006 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
3007 rw_op |= SCSI_RW_BIO;
3011 scsi_read_write(&start_ccb->csio,
3012 /*retries*/da_retry_count,
3014 /*tag_action*/tag_code,
3017 softc->minimum_cmd_size,
3018 /*lba*/bp->bio_pblkno,
3019 /*block_count*/bp->bio_bcount /
3020 softc->params.secsize,
3022 /*dxfer_len*/ bp->bio_bcount,
3023 /*sense_len*/SSD_FULL_SIZE,
3024 da_default_timeout * 1000);
3025 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
3026 start_ccb->csio.bio = bp;
3032 * BIO_FLUSH doesn't currently communicate
3033 * range data, so we synchronize the cache
3034 * over the whole disk. We also force
3035 * ordered tag semantics the flush applies
3036 * to all previously queued I/O.
3038 scsi_synchronize_cache(&start_ccb->csio,
3045 da_default_timeout*1000);
3048 int error, queue_ccb;
3052 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3054 || (queue_ccb == 0)) {
3055 biofinish(bp, NULL, error);
3056 xpt_release_ccb(start_ccb);
3062 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3063 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3064 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3067 LIST_INSERT_HEAD(&softc->pending_ccbs,
3068 &start_ccb->ccb_h, periph_links.le);
3070 /* We expect a unit attention from this device */
3071 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3072 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3073 softc->flags &= ~DA_FLAG_RETRY_UA;
3076 start_ccb->ccb_h.ccb_bp = bp;
3078 cam_periph_unlock(periph);
3079 xpt_action(start_ccb);
3080 cam_periph_lock(periph);
3083 /* May have more work to do, so ensure we stay scheduled */
3087 case DA_STATE_PROBE_RC:
3089 struct scsi_read_capacity_data *rcap;
3091 rcap = (struct scsi_read_capacity_data *)
3092 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3094 printf("dastart: Couldn't malloc read_capacity data\n");
3095 /* da_free_periph??? */
3098 scsi_read_capacity(&start_ccb->csio,
3099 /*retries*/da_retry_count,
3105 start_ccb->ccb_h.ccb_bp = NULL;
3106 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3107 xpt_action(start_ccb);
3110 case DA_STATE_PROBE_RC16:
3112 struct scsi_read_capacity_data_long *rcaplong;
3114 rcaplong = (struct scsi_read_capacity_data_long *)
3115 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3116 if (rcaplong == NULL) {
3117 printf("dastart: Couldn't malloc read_capacity data\n");
3118 /* da_free_periph??? */
3121 scsi_read_capacity_16(&start_ccb->csio,
3122 /*retries*/ da_retry_count,
3124 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3128 /*rcap_buf*/ (uint8_t *)rcaplong,
3129 /*rcap_buf_len*/ sizeof(*rcaplong),
3130 /*sense_len*/ SSD_FULL_SIZE,
3131 /*timeout*/ da_default_timeout * 1000);
3132 start_ccb->ccb_h.ccb_bp = NULL;
3133 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3134 xpt_action(start_ccb);
3137 case DA_STATE_PROBE_LBP:
3139 struct scsi_vpd_logical_block_prov *lbp;
3141 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3143 * If we get here we don't support any SBC-3 delete
3144 * methods with UNMAP as the Logical Block Provisioning
3145 * VPD page support is required for devices which
3146 * support it according to T10/1799-D Revision 31
3147 * however older revisions of the spec don't mandate
3148 * this so we currently don't remove these methods
3149 * from the available set.
3151 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3155 lbp = (struct scsi_vpd_logical_block_prov *)
3156 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3159 printf("dastart: Couldn't malloc lbp data\n");
3160 /* da_free_periph??? */
3164 scsi_inquiry(&start_ccb->csio,
3165 /*retries*/da_retry_count,
3167 /*tag_action*/MSG_SIMPLE_Q_TAG,
3168 /*inq_buf*/(u_int8_t *)lbp,
3169 /*inq_len*/sizeof(*lbp),
3171 /*page_code*/SVPD_LBP,
3172 /*sense_len*/SSD_MIN_SIZE,
3173 /*timeout*/da_default_timeout * 1000);
3174 start_ccb->ccb_h.ccb_bp = NULL;
3175 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3176 xpt_action(start_ccb);
3179 case DA_STATE_PROBE_BLK_LIMITS:
3181 struct scsi_vpd_block_limits *block_limits;
3183 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3184 /* Not supported skip to next probe */
3185 softc->state = DA_STATE_PROBE_BDC;
3189 block_limits = (struct scsi_vpd_block_limits *)
3190 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3192 if (block_limits == NULL) {
3193 printf("dastart: Couldn't malloc block_limits data\n");
3194 /* da_free_periph??? */
3198 scsi_inquiry(&start_ccb->csio,
3199 /*retries*/da_retry_count,
3201 /*tag_action*/MSG_SIMPLE_Q_TAG,
3202 /*inq_buf*/(u_int8_t *)block_limits,
3203 /*inq_len*/sizeof(*block_limits),
3205 /*page_code*/SVPD_BLOCK_LIMITS,
3206 /*sense_len*/SSD_MIN_SIZE,
3207 /*timeout*/da_default_timeout * 1000);
3208 start_ccb->ccb_h.ccb_bp = NULL;
3209 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3210 xpt_action(start_ccb);
3213 case DA_STATE_PROBE_BDC:
3215 struct scsi_vpd_block_characteristics *bdc;
3217 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3218 softc->state = DA_STATE_PROBE_ATA;
3222 bdc = (struct scsi_vpd_block_characteristics *)
3223 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3226 printf("dastart: Couldn't malloc bdc data\n");
3227 /* da_free_periph??? */
3231 scsi_inquiry(&start_ccb->csio,
3232 /*retries*/da_retry_count,
3234 /*tag_action*/MSG_SIMPLE_Q_TAG,
3235 /*inq_buf*/(u_int8_t *)bdc,
3236 /*inq_len*/sizeof(*bdc),
3238 /*page_code*/SVPD_BDC,
3239 /*sense_len*/SSD_MIN_SIZE,
3240 /*timeout*/da_default_timeout * 1000);
3241 start_ccb->ccb_h.ccb_bp = NULL;
3242 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3243 xpt_action(start_ccb);
3246 case DA_STATE_PROBE_ATA:
3248 struct ata_params *ata_params;
3250 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3251 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3252 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3254 * Note that if the ATA VPD page isn't
3255 * supported, we aren't talking to an ATA
3256 * device anyway. Support for that VPD
3257 * page is mandatory for SCSI to ATA (SAT)
3258 * translation layers.
3260 softc->state = DA_STATE_PROBE_ZONE;
3263 daprobedone(periph, start_ccb);
3267 ata_params = (struct ata_params*)
3268 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3270 if (ata_params == NULL) {
3271 xpt_print(periph->path, "Couldn't malloc ata_params "
3273 /* da_free_periph??? */
3277 scsi_ata_identify(&start_ccb->csio,
3278 /*retries*/da_retry_count,
3280 /*tag_action*/MSG_SIMPLE_Q_TAG,
3281 /*data_ptr*/(u_int8_t *)ata_params,
3282 /*dxfer_len*/sizeof(*ata_params),
3283 /*sense_len*/SSD_FULL_SIZE,
3284 /*timeout*/da_default_timeout * 1000);
3285 start_ccb->ccb_h.ccb_bp = NULL;
3286 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3287 xpt_action(start_ccb);
3290 case DA_STATE_PROBE_ATA_LOGDIR:
3292 struct ata_gp_log_dir *log_dir;
3297 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3299 * If we don't have log support, not much point in
3300 * trying to probe zone support.
3302 daprobedone(periph, start_ccb);
3307 * If we have an ATA device (the SCSI ATA Information VPD
3308 * page should be present and the ATA identify should have
3309 * succeeded) and it supports logs, ask for the log directory.
3312 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3313 if (log_dir == NULL) {
3314 xpt_print(periph->path, "Couldn't malloc log_dir "
3316 daprobedone(periph, start_ccb);
3320 retval = scsi_ata_read_log(&start_ccb->csio,
3321 /*retries*/ da_retry_count,
3323 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3324 /*log_address*/ ATA_LOG_DIRECTORY,
3327 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3328 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3329 /*data_ptr*/ (uint8_t *)log_dir,
3330 /*dxfer_len*/ sizeof(*log_dir),
3331 /*sense_len*/ SSD_FULL_SIZE,
3332 /*timeout*/ da_default_timeout * 1000);
3335 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3336 free(log_dir, M_SCSIDA);
3337 daprobedone(periph, start_ccb);
3340 start_ccb->ccb_h.ccb_bp = NULL;
3341 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3342 xpt_action(start_ccb);
3345 case DA_STATE_PROBE_ATA_IDDIR:
3347 struct ata_identify_log_pages *id_dir;
3353 * Check here to see whether the Identify Device log is
3354 * supported in the directory of logs. If so, continue
3355 * with requesting the log of identify device pages.
3357 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3358 daprobedone(periph, start_ccb);
3362 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3363 if (id_dir == NULL) {
3364 xpt_print(periph->path, "Couldn't malloc id_dir "
3366 daprobedone(periph, start_ccb);
3370 retval = scsi_ata_read_log(&start_ccb->csio,
3371 /*retries*/ da_retry_count,
3373 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3374 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3375 /*page_number*/ ATA_IDL_PAGE_LIST,
3377 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3378 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3379 /*data_ptr*/ (uint8_t *)id_dir,
3380 /*dxfer_len*/ sizeof(*id_dir),
3381 /*sense_len*/ SSD_FULL_SIZE,
3382 /*timeout*/ da_default_timeout * 1000);
3385 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3386 free(id_dir, M_SCSIDA);
3387 daprobedone(periph, start_ccb);
3390 start_ccb->ccb_h.ccb_bp = NULL;
3391 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3392 xpt_action(start_ccb);
3395 case DA_STATE_PROBE_ATA_SUP:
3397 struct ata_identify_log_sup_cap *sup_cap;
3403 * Check here to see whether the Supported Capabilities log
3404 * is in the list of Identify Device logs.
3406 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3407 daprobedone(periph, start_ccb);
3411 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3412 if (sup_cap == NULL) {
3413 xpt_print(periph->path, "Couldn't malloc sup_cap "
3415 daprobedone(periph, start_ccb);
3419 retval = scsi_ata_read_log(&start_ccb->csio,
3420 /*retries*/ da_retry_count,
3422 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3423 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3424 /*page_number*/ ATA_IDL_SUP_CAP,
3426 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3427 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3428 /*data_ptr*/ (uint8_t *)sup_cap,
3429 /*dxfer_len*/ sizeof(*sup_cap),
3430 /*sense_len*/ SSD_FULL_SIZE,
3431 /*timeout*/ da_default_timeout * 1000);
3434 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3435 free(sup_cap, M_SCSIDA);
3436 daprobedone(periph, start_ccb);
3441 start_ccb->ccb_h.ccb_bp = NULL;
3442 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3443 xpt_action(start_ccb);
3446 case DA_STATE_PROBE_ATA_ZONE:
3448 struct ata_zoned_info_log *ata_zone;
3454 * Check here to see whether the zoned device information
3455 * page is supported. If so, continue on to request it.
3456 * If not, skip to DA_STATE_PROBE_LOG or done.
3458 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3459 daprobedone(periph, start_ccb);
3462 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3464 if (ata_zone == NULL) {
3465 xpt_print(periph->path, "Couldn't malloc ata_zone "
3467 daprobedone(periph, start_ccb);
3471 retval = scsi_ata_read_log(&start_ccb->csio,
3472 /*retries*/ da_retry_count,
3474 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3475 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3476 /*page_number*/ ATA_IDL_ZDI,
3478 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3479 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3480 /*data_ptr*/ (uint8_t *)ata_zone,
3481 /*dxfer_len*/ sizeof(*ata_zone),
3482 /*sense_len*/ SSD_FULL_SIZE,
3483 /*timeout*/ da_default_timeout * 1000);
3486 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3487 free(ata_zone, M_SCSIDA);
3488 daprobedone(periph, start_ccb);
3491 start_ccb->ccb_h.ccb_bp = NULL;
3492 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3493 xpt_action(start_ccb);
3497 case DA_STATE_PROBE_ZONE:
3499 struct scsi_vpd_zoned_bdc *bdc;
3502 * Note that this page will be supported for SCSI protocol
3503 * devices that support ZBC (SMR devices), as well as ATA
3504 * protocol devices that are behind a SAT (SCSI to ATA
3505 * Translation) layer that supports converting ZBC commands
3506 * to their ZAC equivalents.
3508 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3509 daprobedone(periph, start_ccb);
3512 bdc = (struct scsi_vpd_zoned_bdc *)
3513 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3516 xpt_release_ccb(start_ccb);
3517 xpt_print(periph->path, "Couldn't malloc zone VPD "
3521 scsi_inquiry(&start_ccb->csio,
3522 /*retries*/da_retry_count,
3524 /*tag_action*/MSG_SIMPLE_Q_TAG,
3525 /*inq_buf*/(u_int8_t *)bdc,
3526 /*inq_len*/sizeof(*bdc),
3528 /*page_code*/SVPD_ZONED_BDC,
3529 /*sense_len*/SSD_FULL_SIZE,
3530 /*timeout*/da_default_timeout * 1000);
3531 start_ccb->ccb_h.ccb_bp = NULL;
3532 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3533 xpt_action(start_ccb);
3540 * In each of the methods below, while its the caller's
3541 * responsibility to ensure the request will fit into a
3542 * single device request, we might have changed the delete
3543 * method due to the device incorrectly advertising either
3544 * its supported methods or limits.
3546 * To prevent this causing further issues we validate the
3547 * against the methods limits, and warn which would
3548 * otherwise be unnecessary.
3551 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3553 struct da_softc *softc = (struct da_softc *)periph->softc;;
3555 uint8_t *buf = softc->unmap_buf;
3556 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE];
3557 uint64_t lba, lastlba = (uint64_t)-1;
3558 uint64_t totalcount = 0;
3560 uint32_t c, lastcount = 0, ranges = 0;
3563 * Currently this doesn't take the UNMAP
3564 * Granularity and Granularity Alignment
3565 * fields into account.
3567 * This could result in both unoptimal unmap
3568 * requests as as well as UNMAP calls unmapping
3569 * fewer LBA's than requested.
3572 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3576 * Note: ada and da are different in how they store the
3577 * pending bp's in a trim. ada stores all of them in the
3578 * trim_req.bps. da stores all but the first one in the
3579 * delete_run_queue. ada then completes all the bps in
3580 * its adadone() loop. da completes all the bps in the
3581 * delete_run_queue in dadone, and relies on the biodone
3582 * after to complete. This should be reconciled since there's
3583 * no real reason to do it differently. XXX
3586 bioq_insert_tail(&softc->delete_run_queue, bp1);
3587 lba = bp1->bio_pblkno;
3588 count = bp1->bio_bcount / softc->params.secsize;
3590 /* Try to extend the previous range. */
3591 if (lba == lastlba) {
3592 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3595 scsi_ulto4b(lastcount, d[ranges - 1].length);
3599 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) &&
3600 softc->unmap_gran != 0) {
3601 /* Align length of the previous range. */
3602 if ((c = lastcount % softc->unmap_gran) != 0) {
3603 if (lastcount <= c) {
3604 totalcount -= lastcount;
3605 lastlba = (uint64_t)-1;
3612 scsi_ulto4b(lastcount, d[ranges - 1].length);
3615 /* Align beginning of the new range. */
3616 c = (lba - softc->unmap_gran_align) % softc->unmap_gran;
3618 c = softc->unmap_gran - c;
3629 c = omin(count, UNMAP_RANGE_MAX);
3630 if (totalcount + c > softc->unmap_max_lba ||
3631 ranges >= softc->unmap_max_ranges) {
3632 xpt_print(periph->path,
3633 "%s issuing short delete %ld > %ld"
3635 da_delete_method_desc[softc->delete_method],
3636 totalcount + c, softc->unmap_max_lba,
3637 ranges, softc->unmap_max_ranges);
3640 scsi_u64to8b(lba, d[ranges].lba);
3641 scsi_ulto4b(c, d[ranges].length);
3649 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3652 if (ranges >= softc->unmap_max_ranges ||
3653 totalcount + bp1->bio_bcount /
3654 softc->params.secsize > softc->unmap_max_lba) {
3655 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3660 /* Align length of the last range. */
3661 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 &&
3662 (c = lastcount % softc->unmap_gran) != 0) {
3666 scsi_ulto4b(lastcount - c, d[ranges - 1].length);
3669 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3670 scsi_ulto2b(ranges * 16, &buf[2]);
3672 scsi_unmap(&ccb->csio,
3673 /*retries*/da_retry_count,
3675 /*tag_action*/MSG_SIMPLE_Q_TAG,
3678 /*dxfer_len*/ ranges * 16 + 8,
3679 /*sense_len*/SSD_FULL_SIZE,
3680 da_default_timeout * 1000);
3681 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3682 ccb->ccb_h.flags |= CAM_UNLOCKED;
3683 cam_iosched_submit_trim(softc->cam_iosched);
3687 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3689 struct da_softc *softc = (struct da_softc *)periph->softc;
3691 uint8_t *buf = softc->unmap_buf;
3692 uint64_t lastlba = (uint64_t)-1;
3695 uint32_t lastcount = 0, c, requestcount;
3696 int ranges = 0, off, block_count;
3698 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3701 if (bp1 != bp)//XXX imp XXX
3702 bioq_insert_tail(&softc->delete_run_queue, bp1);
3703 lba = bp1->bio_pblkno;
3704 count = bp1->bio_bcount / softc->params.secsize;
3705 requestcount = count;
3707 /* Try to extend the previous range. */
3708 if (lba == lastlba) {
3709 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3711 off = (ranges - 1) * 8;
3712 buf[off + 6] = lastcount & 0xff;
3713 buf[off + 7] = (lastcount >> 8) & 0xff;
3719 c = omin(count, ATA_DSM_RANGE_MAX);
3722 buf[off + 0] = lba & 0xff;
3723 buf[off + 1] = (lba >> 8) & 0xff;
3724 buf[off + 2] = (lba >> 16) & 0xff;
3725 buf[off + 3] = (lba >> 24) & 0xff;
3726 buf[off + 4] = (lba >> 32) & 0xff;
3727 buf[off + 5] = (lba >> 40) & 0xff;
3728 buf[off + 6] = c & 0xff;
3729 buf[off + 7] = (c >> 8) & 0xff;
3734 if (count != 0 && ranges == softc->trim_max_ranges) {
3735 xpt_print(periph->path,
3736 "%s issuing short delete %ld > %ld\n",
3737 da_delete_method_desc[softc->delete_method],
3739 (softc->trim_max_ranges - ranges) *
3745 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3748 if (bp1->bio_bcount / softc->params.secsize >
3749 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3750 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3755 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3756 scsi_ata_trim(&ccb->csio,
3757 /*retries*/da_retry_count,
3759 /*tag_action*/MSG_SIMPLE_Q_TAG,
3762 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3763 /*sense_len*/SSD_FULL_SIZE,
3764 da_default_timeout * 1000);
3765 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3766 ccb->ccb_h.flags |= CAM_UNLOCKED;
3767 cam_iosched_submit_trim(softc->cam_iosched);
3771 * We calculate ws_max_blks here based off d_delmaxsize instead
3772 * of using softc->ws_max_blks as it is absolute max for the
3773 * device not the protocol max which may well be lower.
3776 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3778 struct da_softc *softc;
3780 uint64_t ws_max_blks;
3782 uint64_t count; /* forward compat with WS32 */
3784 softc = (struct da_softc *)periph->softc;
3785 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3786 lba = bp->bio_pblkno;
3790 if (bp1 != bp)//XXX imp XXX
3791 bioq_insert_tail(&softc->delete_run_queue, bp1);
3792 count += bp1->bio_bcount / softc->params.secsize;
3793 if (count > ws_max_blks) {
3794 xpt_print(periph->path,
3795 "%s issuing short delete %ld > %ld\n",
3796 da_delete_method_desc[softc->delete_method],
3797 count, ws_max_blks);
3798 count = omin(count, ws_max_blks);
3801 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3804 if (lba + count != bp1->bio_pblkno ||
3805 count + bp1->bio_bcount /
3806 softc->params.secsize > ws_max_blks) {
3807 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3812 scsi_write_same(&ccb->csio,
3813 /*retries*/da_retry_count,
3815 /*tag_action*/MSG_SIMPLE_Q_TAG,
3816 /*byte2*/softc->delete_method ==
3817 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3818 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3820 /*block_count*/count,
3821 /*data_ptr*/ __DECONST(void *, zero_region),
3822 /*dxfer_len*/ softc->params.secsize,
3823 /*sense_len*/SSD_FULL_SIZE,
3824 da_default_timeout * 1000);
3825 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3826 ccb->ccb_h.flags |= CAM_UNLOCKED;
3827 cam_iosched_submit_trim(softc->cam_iosched);
3831 cmd6workaround(union ccb *ccb)
3833 struct scsi_rw_6 cmd6;
3834 struct scsi_rw_10 *cmd10;
3835 struct da_softc *softc;
3840 cdb = ccb->csio.cdb_io.cdb_bytes;
3841 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3843 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3844 da_delete_methods old_method = softc->delete_method;
3847 * Typically there are two reasons for failure here
3848 * 1. Delete method was detected as supported but isn't
3849 * 2. Delete failed due to invalid params e.g. too big
3851 * While we will attempt to choose an alternative delete method
3852 * this may result in short deletes if the existing delete
3853 * requests from geom are big for the new method chosen.
3855 * This method assumes that the error which triggered this
3856 * will not retry the io otherwise a panic will occur
3858 dadeleteflag(softc, old_method, 0);
3859 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3860 if (softc->delete_method == DA_DELETE_DISABLE)
3861 xpt_print(ccb->ccb_h.path,
3862 "%s failed, disabling BIO_DELETE\n",
3863 da_delete_method_desc[old_method]);
3865 xpt_print(ccb->ccb_h.path,
3866 "%s failed, switching to %s BIO_DELETE\n",
3867 da_delete_method_desc[old_method],
3868 da_delete_method_desc[softc->delete_method]);
3870 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3871 cam_iosched_queue_work(softc->cam_iosched, bp);
3872 cam_iosched_queue_work(softc->cam_iosched,
3873 (struct bio *)ccb->ccb_h.ccb_bp);
3874 ccb->ccb_h.ccb_bp = NULL;
3878 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3879 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3880 (*cdb == PREVENT_ALLOW) &&
3881 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3883 xpt_print(ccb->ccb_h.path,
3884 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3885 softc->quirks |= DA_Q_NO_PREVENT;
3889 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3890 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3891 (*cdb == SYNCHRONIZE_CACHE) &&
3892 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3894 xpt_print(ccb->ccb_h.path,
3895 "SYNCHRONIZE CACHE(10) not supported.\n");
3896 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3897 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3901 /* Translation only possible if CDB is an array and cmd is R/W6 */
3902 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3903 (*cdb != READ_6 && *cdb != WRITE_6))
3906 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3907 "increasing minimum_cmd_size to 10.\n");
3908 softc->minimum_cmd_size = 10;
3910 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3911 cmd10 = (struct scsi_rw_10 *)cdb;
3912 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3914 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3915 cmd10->reserved = 0;
3916 scsi_ulto2b(cmd6.length, cmd10->length);
3917 cmd10->control = cmd6.control;
3918 ccb->csio.cdb_len = sizeof(*cmd10);
3920 /* Requeue request, unfreezing queue if necessary */
3921 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3922 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3925 cam_release_devq(ccb->ccb_h.path,
3929 /*getcount_only*/0);
3935 dazonedone(struct cam_periph *periph, union ccb *ccb)
3937 struct da_softc *softc;
3940 softc = periph->softc;
3941 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3943 switch (bp->bio_zone.zone_cmd) {
3944 case DISK_ZONE_OPEN:
3945 case DISK_ZONE_CLOSE:
3946 case DISK_ZONE_FINISH:
3949 case DISK_ZONE_REPORT_ZONES: {
3951 struct disk_zone_report *rep;
3952 struct scsi_report_zones_hdr *hdr;
3953 struct scsi_report_zones_desc *desc;
3954 struct disk_zone_rep_entry *entry;
3955 uint32_t num_alloced, hdr_len, num_avail;
3956 uint32_t num_to_fill, i;
3959 rep = &bp->bio_zone.zone_params.report;
3960 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
3962 * Note that bio_resid isn't normally used for zone
3963 * commands, but it is used by devstat_end_transaction_bio()
3964 * to determine how much data was transferred. Because
3965 * the size of the SCSI/ATA data structures is different
3966 * than the size of the BIO interface structures, the
3967 * amount of data actually transferred from the drive will
3968 * be different than the amount of data transferred to
3971 bp->bio_resid = ccb->csio.resid;
3972 num_alloced = rep->entries_allocated;
3973 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
3974 if (avail_len < sizeof(*hdr)) {
3976 * Is there a better error than EIO here? We asked
3977 * for at least the header, and we got less than
3980 bp->bio_error = EIO;
3981 bp->bio_flags |= BIO_ERROR;
3982 bp->bio_resid = bp->bio_bcount;
3986 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
3991 hdr_len = ata ? le32dec(hdr->length) :
3992 scsi_4btoul(hdr->length);
3994 rep->entries_available = hdr_len / sizeof(*desc);
3996 rep->entries_available = 0;
3998 * NOTE: using the same values for the BIO version of the
3999 * same field as the SCSI/ATA values. This means we could
4000 * get some additional values that aren't defined in bio.h
4001 * if more values of the same field are defined later.
4003 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
4004 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
4005 scsi_8btou64(hdr->maximum_lba);
4007 * If the drive reports no entries that match the query,
4011 rep->entries_filled = 0;
4015 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
4016 hdr_len / sizeof(*desc));
4018 * If the drive didn't return any data, then we're done.
4020 if (num_avail == 0) {
4021 rep->entries_filled = 0;
4025 num_to_fill = min(num_avail, rep->entries_allocated);
4027 * If the user didn't allocate any entries for us to fill,
4030 if (num_to_fill == 0) {
4031 rep->entries_filled = 0;
4035 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
4036 i < num_to_fill; i++, desc++, entry++) {
4038 * NOTE: we're mapping the values here directly
4039 * from the SCSI/ATA bit definitions to the bio.h
4040 * definitons. There is also a warning in
4041 * disk_zone.h, but the impact is that if
4042 * additional values are added in the SCSI/ATA
4043 * specs these will be visible to consumers of
4046 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
4047 entry->zone_condition =
4048 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
4049 SRZ_ZONE_COND_SHIFT;
4050 entry->zone_flags |= desc->zone_flags &
4051 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
4052 entry->zone_length =
4053 ata ? le64dec(desc->zone_length) :
4054 scsi_8btou64(desc->zone_length);
4055 entry->zone_start_lba =
4056 ata ? le64dec(desc->zone_start_lba) :
4057 scsi_8btou64(desc->zone_start_lba);
4058 entry->write_pointer_lba =
4059 ata ? le64dec(desc->write_pointer_lba) :
4060 scsi_8btou64(desc->write_pointer_lba);
4062 rep->entries_filled = num_to_fill;
4065 case DISK_ZONE_GET_PARAMS:
4068 * In theory we should not get a GET_PARAMS bio, since it
4069 * should be handled without queueing the command to the
4072 panic("%s: Invalid zone command %d", __func__,
4073 bp->bio_zone.zone_cmd);
4077 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4078 free(ccb->csio.data_ptr, M_SCSIDA);
4082 dadone(struct cam_periph *periph, union ccb *done_ccb)
4084 struct da_softc *softc;
4085 struct ccb_scsiio *csio;
4089 softc = (struct da_softc *)periph->softc;
4090 priority = done_ccb->ccb_h.pinfo.priority;
4092 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4094 csio = &done_ccb->csio;
4095 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4096 if (csio->bio != NULL)
4097 biotrack(csio->bio, __func__);
4099 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4101 case DA_CCB_BUFFER_IO:
4104 struct bio *bp, *bp1;
4106 cam_periph_lock(periph);
4107 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4108 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4112 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4117 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4118 if (error == ERESTART) {
4120 * A retry was scheduled, so
4123 cam_periph_unlock(periph);
4126 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4131 * return all queued I/O with EIO, so that
4132 * the client can retry these I/Os in the
4133 * proper order should it attempt to recover.
4138 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4140 * Catastrophic error. Mark our pack as
4144 * XXX See if this is really a media
4147 xpt_print(periph->path,
4148 "Invalidating pack\n");
4149 softc->flags |= DA_FLAG_PACK_INVALID;
4151 softc->invalidations++;
4153 queued_error = ENXIO;
4155 cam_iosched_flush(softc->cam_iosched, NULL,
4158 bp->bio_error = error;
4159 bp->bio_resid = bp->bio_bcount;
4160 bp->bio_flags |= BIO_ERROR;
4162 } else if (bp != NULL) {
4163 if (state == DA_CCB_DELETE)
4166 bp->bio_resid = csio->resid;
4168 if (bp->bio_resid != 0)
4169 bp->bio_flags |= BIO_ERROR;
4171 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4172 cam_release_devq(done_ccb->ccb_h.path,
4176 /*getcount_only*/0);
4177 } else if (bp != NULL) {
4178 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4179 panic("REQ_CMP with QFRZN");
4180 if (bp->bio_cmd == BIO_ZONE)
4181 dazonedone(periph, done_ccb);
4182 else if (state == DA_CCB_DELETE)
4185 bp->bio_resid = csio->resid;
4186 if ((csio->resid > 0)
4187 && (bp->bio_cmd != BIO_ZONE))
4188 bp->bio_flags |= BIO_ERROR;
4189 if (softc->error_inject != 0) {
4190 bp->bio_error = softc->error_inject;
4191 bp->bio_resid = bp->bio_bcount;
4192 bp->bio_flags |= BIO_ERROR;
4193 softc->error_inject = 0;
4198 biotrack(bp, __func__);
4199 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4200 if (LIST_EMPTY(&softc->pending_ccbs))
4201 softc->flags |= DA_FLAG_WAS_OTAG;
4204 * We need to call cam_iosched before we call biodone so that we
4205 * don't measure any activity that happens in the completion
4206 * routine, which in the case of sendfile can be quite
4209 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4210 xpt_release_ccb(done_ccb);
4211 if (state == DA_CCB_DELETE) {
4212 TAILQ_HEAD(, bio) queue;
4215 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4216 softc->delete_run_queue.insert_point = NULL;
4218 * Normally, the xpt_release_ccb() above would make sure
4219 * that when we have more work to do, that work would
4220 * get kicked off. However, we specifically keep
4221 * delete_running set to 0 before the call above to
4222 * allow other I/O to progress when many BIO_DELETE
4223 * requests are pushed down. We set delete_running to 0
4224 * and call daschedule again so that we don't stall if
4225 * there are no other I/Os pending apart from BIO_DELETEs.
4227 cam_iosched_trim_done(softc->cam_iosched);
4229 cam_periph_unlock(periph);
4230 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4231 TAILQ_REMOVE(&queue, bp1, bio_queue);
4232 bp1->bio_error = bp->bio_error;
4233 if (bp->bio_flags & BIO_ERROR) {
4234 bp1->bio_flags |= BIO_ERROR;
4235 bp1->bio_resid = bp1->bio_bcount;
4242 cam_periph_unlock(periph);
4248 case DA_CCB_PROBE_RC:
4249 case DA_CCB_PROBE_RC16:
4251 struct scsi_read_capacity_data *rdcap;
4252 struct scsi_read_capacity_data_long *rcaplong;
4259 /* XXX TODO: can this be a malloc? */
4260 announce_buf = softc->announce_temp;
4261 bzero(announce_buf, DA_ANNOUNCETMP_SZ);
4263 if (state == DA_CCB_PROBE_RC)
4264 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4266 rcaplong = (struct scsi_read_capacity_data_long *)
4269 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4270 struct disk_params *dp;
4271 uint32_t block_size;
4273 u_int lalba; /* Lowest aligned LBA. */
4275 if (state == DA_CCB_PROBE_RC) {
4276 block_size = scsi_4btoul(rdcap->length);
4277 maxsector = scsi_4btoul(rdcap->addr);
4281 * According to SBC-2, if the standard 10
4282 * byte READ CAPACITY command returns 2^32,
4283 * we should issue the 16 byte version of
4284 * the command, since the device in question
4285 * has more sectors than can be represented
4286 * with the short version of the command.
4288 if (maxsector == 0xffffffff) {
4289 free(rdcap, M_SCSIDA);
4290 xpt_release_ccb(done_ccb);
4291 softc->state = DA_STATE_PROBE_RC16;
4292 xpt_schedule(periph, priority);
4296 block_size = scsi_4btoul(rcaplong->length);
4297 maxsector = scsi_8btou64(rcaplong->addr);
4298 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4302 * Because GEOM code just will panic us if we
4303 * give them an 'illegal' value we'll avoid that
4306 if (block_size == 0) {
4311 if (block_size >= MAXPHYS) {
4312 xpt_print(periph->path,
4313 "unsupportable block size %ju\n",
4314 (uintmax_t) block_size);
4315 announce_buf = NULL;
4316 cam_periph_invalidate(periph);
4319 * We pass rcaplong into dasetgeom(),
4320 * because it will only use it if it is
4323 dasetgeom(periph, block_size, maxsector,
4324 rcaplong, sizeof(*rcaplong));
4325 lbp = (lalba & SRC16_LBPME_A);
4326 dp = &softc->params;
4327 snprintf(announce_buf, DA_ANNOUNCETMP_SZ,
4328 "%juMB (%ju %u byte sectors)",
4329 ((uintmax_t)dp->secsize * dp->sectors) /
4331 (uintmax_t)dp->sectors, dp->secsize);
4337 * Retry any UNIT ATTENTION type errors. They
4338 * are expected at boot.
4340 error = daerror(done_ccb, CAM_RETRY_SELTO,
4341 SF_RETRY_UA|SF_NO_PRINT);
4342 if (error == ERESTART) {
4344 * A retry was scheuled, so
4348 } else if (error != 0) {
4350 int sense_key, error_code;
4353 struct ccb_getdev cgd;
4355 /* Don't wedge this device's queue */
4356 status = done_ccb->ccb_h.status;
4357 if ((status & CAM_DEV_QFRZN) != 0)
4358 cam_release_devq(done_ccb->ccb_h.path,
4362 /*getcount_only*/0);
4365 xpt_setup_ccb(&cgd.ccb_h,
4366 done_ccb->ccb_h.path,
4367 CAM_PRIORITY_NORMAL);
4368 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4369 xpt_action((union ccb *)&cgd);
4371 if (scsi_extract_sense_ccb(done_ccb,
4372 &error_code, &sense_key, &asc, &ascq))
4378 * If we tried READ CAPACITY(16) and failed,
4379 * fallback to READ CAPACITY(10).
4381 if ((state == DA_CCB_PROBE_RC16) &&
4382 (softc->flags & DA_FLAG_CAN_RC16) &&
4383 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4386 (error_code == SSD_CURRENT_ERROR) &&
4387 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4388 softc->flags &= ~DA_FLAG_CAN_RC16;
4389 free(rdcap, M_SCSIDA);
4390 xpt_release_ccb(done_ccb);
4391 softc->state = DA_STATE_PROBE_RC;
4392 xpt_schedule(periph, priority);
4397 * Attach to anything that claims to be a
4398 * direct access or optical disk device,
4399 * as long as it doesn't return a "Logical
4400 * unit not supported" (0x25) error.
4401 * "Internal Target Failure" (0x44) is also
4402 * special and typically means that the
4403 * device is a SATA drive behind a SATL
4404 * translation that's fallen into a
4405 * terminally fatal state.
4408 && (asc != 0x25) && (asc != 0x44)
4409 && (error_code == SSD_CURRENT_ERROR)) {
4410 const char *sense_key_desc;
4411 const char *asc_desc;
4413 dasetgeom(periph, 512, -1, NULL, 0);
4414 scsi_sense_desc(sense_key, asc, ascq,
4418 snprintf(announce_buf,
4420 "Attempt to query device "
4421 "size failed: %s, %s",
4422 sense_key_desc, asc_desc);
4428 xpt_print(periph->path,
4429 "got CAM status %#x\n",
4430 done_ccb->ccb_h.status);
4433 xpt_print(periph->path, "fatal error, "
4434 "failed to attach to device\n");
4436 announce_buf = NULL;
4439 * Free up resources.
4441 cam_periph_invalidate(periph);
4445 free(csio->data_ptr, M_SCSIDA);
4446 if (announce_buf != NULL &&
4447 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4450 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ,
4452 xpt_announce_periph_sbuf(periph, &sb, announce_buf);
4453 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks,
4459 * Create our sysctl variables, now that we know
4460 * we have successfully attached.
4462 /* increase the refcount */
4463 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4465 taskqueue_enqueue(taskqueue_thread,
4466 &softc->sysctl_task);
4468 /* XXX This message is useless! */
4469 xpt_print(periph->path, "fatal error, "
4470 "could not acquire reference count\n");
4474 /* We already probed the device. */
4475 if (softc->flags & DA_FLAG_PROBED) {
4476 daprobedone(periph, done_ccb);
4480 /* Ensure re-probe doesn't see old delete. */
4481 softc->delete_available = 0;
4482 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4483 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4485 * Based on older SBC-3 spec revisions
4486 * any of the UNMAP methods "may" be
4487 * available via LBP given this flag so
4488 * we flag all of them as available and
4489 * then remove those which further
4490 * probes confirm aren't available
4493 * We could also check readcap(16) p_type
4494 * flag to exclude one or more invalid
4495 * write same (X) types here
4497 dadeleteflag(softc, DA_DELETE_WS16, 1);
4498 dadeleteflag(softc, DA_DELETE_WS10, 1);
4499 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4501 xpt_release_ccb(done_ccb);
4502 softc->state = DA_STATE_PROBE_LBP;
4503 xpt_schedule(periph, priority);
4507 xpt_release_ccb(done_ccb);
4508 softc->state = DA_STATE_PROBE_BDC;
4509 xpt_schedule(periph, priority);
4512 case DA_CCB_PROBE_LBP:
4514 struct scsi_vpd_logical_block_prov *lbp;
4516 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4518 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4520 * T10/1799-D Revision 31 states at least one of these
4521 * must be supported but we don't currently enforce this.
4523 dadeleteflag(softc, DA_DELETE_WS16,
4524 (lbp->flags & SVPD_LBP_WS16));
4525 dadeleteflag(softc, DA_DELETE_WS10,
4526 (lbp->flags & SVPD_LBP_WS10));
4527 dadeleteflag(softc, DA_DELETE_UNMAP,
4528 (lbp->flags & SVPD_LBP_UNMAP));
4531 error = daerror(done_ccb, CAM_RETRY_SELTO,
4532 SF_RETRY_UA|SF_NO_PRINT);
4533 if (error == ERESTART)
4535 else if (error != 0) {
4536 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4537 /* Don't wedge this device's queue */
4538 cam_release_devq(done_ccb->ccb_h.path,
4542 /*getcount_only*/0);
4546 * Failure indicates we don't support any SBC-3
4547 * delete methods with UNMAP
4552 free(lbp, M_SCSIDA);
4553 xpt_release_ccb(done_ccb);
4554 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4555 xpt_schedule(periph, priority);
4558 case DA_CCB_PROBE_BLK_LIMITS:
4560 struct scsi_vpd_block_limits *block_limits;
4562 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4564 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4565 uint32_t max_txfer_len = scsi_4btoul(
4566 block_limits->max_txfer_len);
4567 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4568 block_limits->max_unmap_lba_cnt);
4569 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4570 block_limits->max_unmap_blk_cnt);
4571 uint32_t unmap_gran = scsi_4btoul(
4572 block_limits->opt_unmap_grain);
4573 uint32_t unmap_gran_align = scsi_4btoul(
4574 block_limits->unmap_grain_align);
4575 uint64_t ws_max_blks = scsi_8btou64(
4576 block_limits->max_write_same_length);
4578 if (max_txfer_len != 0) {
4579 softc->disk->d_maxsize = MIN(softc->maxio,
4580 (off_t)max_txfer_len * softc->params.secsize);
4584 * We should already support UNMAP but we check lba
4585 * and block count to be sure
4587 if (max_unmap_lba_cnt != 0x00L &&
4588 max_unmap_blk_cnt != 0x00L) {
4589 softc->unmap_max_lba = max_unmap_lba_cnt;
4590 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4592 if (unmap_gran > 1) {
4593 softc->unmap_gran = unmap_gran;
4594 if (unmap_gran_align & 0x80000000) {
4595 softc->unmap_gran_align =
4602 * Unexpected UNMAP limits which means the
4603 * device doesn't actually support UNMAP
4605 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4608 if (ws_max_blks != 0x00L)
4609 softc->ws_max_blks = ws_max_blks;
4612 error = daerror(done_ccb, CAM_RETRY_SELTO,
4613 SF_RETRY_UA|SF_NO_PRINT);
4614 if (error == ERESTART)
4616 else if (error != 0) {
4617 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4618 /* Don't wedge this device's queue */
4619 cam_release_devq(done_ccb->ccb_h.path,
4623 /*getcount_only*/0);
4627 * Failure here doesn't mean UNMAP is not
4628 * supported as this is an optional page.
4630 softc->unmap_max_lba = 1;
4631 softc->unmap_max_ranges = 1;
4635 free(block_limits, M_SCSIDA);
4636 xpt_release_ccb(done_ccb);
4637 softc->state = DA_STATE_PROBE_BDC;
4638 xpt_schedule(periph, priority);
4641 case DA_CCB_PROBE_BDC:
4643 struct scsi_vpd_block_device_characteristics *bdc;
4645 bdc = (struct scsi_vpd_block_device_characteristics *)
4648 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4652 * Disable queue sorting for non-rotational media
4655 u_int16_t old_rate = softc->disk->d_rotation_rate;
4657 valid_len = csio->dxfer_len - csio->resid;
4658 if (SBDC_IS_PRESENT(bdc, valid_len,
4659 medium_rotation_rate)) {
4660 softc->disk->d_rotation_rate =
4661 scsi_2btoul(bdc->medium_rotation_rate);
4662 if (softc->disk->d_rotation_rate ==
4663 SVPD_BDC_RATE_NON_ROTATING) {
4664 cam_iosched_set_sort_queue(
4665 softc->cam_iosched, 0);
4666 softc->rotating = 0;
4668 if (softc->disk->d_rotation_rate != old_rate) {
4669 disk_attr_changed(softc->disk,
4670 "GEOM::rotation_rate", M_NOWAIT);
4673 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4674 && (softc->zone_mode == DA_ZONE_NONE)) {
4677 if (scsi_vpd_supported_page(periph,
4678 SVPD_ATA_INFORMATION))
4684 * The Zoned field will only be set for
4685 * Drive Managed and Host Aware drives. If
4686 * they are Host Managed, the device type
4687 * in the standard INQUIRY data should be
4688 * set to T_ZBC_HM (0x14).
4690 if ((bdc->flags & SVPD_ZBC_MASK) ==
4692 softc->zone_mode = DA_ZONE_HOST_AWARE;
4693 softc->zone_interface = (ata_proto) ?
4694 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4695 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4697 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4698 softc->zone_interface = (ata_proto) ?
4699 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4700 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4702 xpt_print(periph->path, "Unknown zoned "
4704 bdc->flags & SVPD_ZBC_MASK);
4709 error = daerror(done_ccb, CAM_RETRY_SELTO,
4710 SF_RETRY_UA|SF_NO_PRINT);
4711 if (error == ERESTART)
4713 else if (error != 0) {
4714 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4715 /* Don't wedge this device's queue */
4716 cam_release_devq(done_ccb->ccb_h.path,
4720 /*getcount_only*/0);
4725 free(bdc, M_SCSIDA);
4726 xpt_release_ccb(done_ccb);
4727 softc->state = DA_STATE_PROBE_ATA;
4728 xpt_schedule(periph, priority);
4731 case DA_CCB_PROBE_ATA:
4734 struct ata_params *ata_params;
4739 ata_params = (struct ata_params *)csio->data_ptr;
4740 ptr = (uint16_t *)ata_params;
4744 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4747 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4748 ptr[i] = le16toh(ptr[i]);
4749 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4750 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4751 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4752 if (ata_params->max_dsm_blocks != 0)
4753 softc->trim_max_ranges = min(
4754 softc->trim_max_ranges,
4755 ata_params->max_dsm_blocks *
4756 ATA_DSM_BLK_RANGES);
4759 * Disable queue sorting for non-rotational media
4762 old_rate = softc->disk->d_rotation_rate;
4763 softc->disk->d_rotation_rate =
4764 ata_params->media_rotation_rate;
4765 if (softc->disk->d_rotation_rate ==
4766 ATA_RATE_NON_ROTATING) {
4767 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4768 softc->rotating = 0;
4770 if (softc->disk->d_rotation_rate != old_rate) {
4771 disk_attr_changed(softc->disk,
4772 "GEOM::rotation_rate", M_NOWAIT);
4775 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4776 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4778 if (ata_params->support.extension &
4780 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4783 * At this point, if we have a SATA host aware drive,
4784 * we communicate via ATA passthrough unless the
4785 * SAT layer supports ZBC -> ZAC translation. In
4789 * XXX KDM figure out how to detect a host managed
4792 if (softc->zone_mode == DA_ZONE_NONE) {
4794 * Note that we don't override the zone
4795 * mode or interface if it has already been
4796 * set. This is because it has either been
4797 * set as a quirk, or when we probed the
4798 * SCSI Block Device Characteristics page,
4799 * the zoned field was set. The latter
4800 * means that the SAT layer supports ZBC to
4801 * ZAC translation, and we would prefer to
4802 * use that if it is available.
4804 if ((ata_params->support3 &
4805 ATA_SUPPORT_ZONE_MASK) ==
4806 ATA_SUPPORT_ZONE_HOST_AWARE) {
4807 softc->zone_mode = DA_ZONE_HOST_AWARE;
4808 softc->zone_interface =
4809 DA_ZONE_IF_ATA_PASS;
4810 } else if ((ata_params->support3 &
4811 ATA_SUPPORT_ZONE_MASK) ==
4812 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4813 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4814 softc->zone_interface =
4815 DA_ZONE_IF_ATA_PASS;
4820 error = daerror(done_ccb, CAM_RETRY_SELTO,
4821 SF_RETRY_UA|SF_NO_PRINT);
4822 if (error == ERESTART)
4824 else if (error != 0) {
4825 if ((done_ccb->ccb_h.status &
4826 CAM_DEV_QFRZN) != 0) {
4827 /* Don't wedge this device's queue */
4828 cam_release_devq(done_ccb->ccb_h.path,
4832 /*getcount_only*/0);
4837 free(ata_params, M_SCSIDA);
4838 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4839 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4841 * If the ATA IDENTIFY failed, we could be talking
4842 * to a SCSI drive, although that seems unlikely,
4843 * since the drive did report that it supported the
4844 * ATA Information VPD page. If the ATA IDENTIFY
4845 * succeeded, and the SAT layer doesn't support
4846 * ZBC -> ZAC translation, continue on to get the
4847 * directory of ATA logs, and complete the rest of
4848 * the ZAC probe. If the SAT layer does support
4849 * ZBC -> ZAC translation, we want to use that,
4850 * and we'll probe the SCSI Zoned Block Device
4851 * Characteristics VPD page next.
4854 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4855 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4856 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4858 softc->state = DA_STATE_PROBE_ZONE;
4861 if (continue_probe != 0) {
4862 xpt_release_ccb(done_ccb);
4863 xpt_schedule(periph, priority);
4866 daprobedone(periph, done_ccb);
4869 case DA_CCB_PROBE_ATA_LOGDIR:
4873 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4875 softc->valid_logdir_len = 0;
4876 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4877 softc->valid_logdir_len =
4878 csio->dxfer_len - csio->resid;
4879 if (softc->valid_logdir_len > 0)
4880 bcopy(csio->data_ptr, &softc->ata_logdir,
4881 min(softc->valid_logdir_len,
4882 sizeof(softc->ata_logdir)));
4884 * Figure out whether the Identify Device log is
4885 * supported. The General Purpose log directory
4886 * has a header, and lists the number of pages
4887 * available for each GP log identified by the
4888 * offset into the list.
4890 if ((softc->valid_logdir_len >=
4891 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4892 && (le16dec(softc->ata_logdir.header) ==
4893 ATA_GP_LOG_DIR_VERSION)
4894 && (le16dec(&softc->ata_logdir.num_pages[
4895 (ATA_IDENTIFY_DATA_LOG *
4896 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4897 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4899 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4902 error = daerror(done_ccb, CAM_RETRY_SELTO,
4903 SF_RETRY_UA|SF_NO_PRINT);
4904 if (error == ERESTART)
4906 else if (error != 0) {
4908 * If we can't get the ATA log directory,
4909 * then ATA logs are effectively not
4910 * supported even if the bit is set in the
4913 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
4914 DA_FLAG_CAN_ATA_IDLOG);
4915 if ((done_ccb->ccb_h.status &
4916 CAM_DEV_QFRZN) != 0) {
4917 /* Don't wedge this device's queue */
4918 cam_release_devq(done_ccb->ccb_h.path,
4922 /*getcount_only*/0);
4927 free(csio->data_ptr, M_SCSIDA);
4930 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
4931 softc->state = DA_STATE_PROBE_ATA_IDDIR;
4932 xpt_release_ccb(done_ccb);
4933 xpt_schedule(periph, priority);
4936 daprobedone(periph, done_ccb);
4939 case DA_CCB_PROBE_ATA_IDDIR:
4943 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4944 off_t entries_offset, max_entries;
4947 softc->valid_iddir_len = 0;
4948 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
4949 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
4950 DA_FLAG_CAN_ATA_ZONE);
4951 softc->valid_iddir_len =
4952 csio->dxfer_len - csio->resid;
4953 if (softc->valid_iddir_len > 0)
4954 bcopy(csio->data_ptr, &softc->ata_iddir,
4955 min(softc->valid_iddir_len,
4956 sizeof(softc->ata_iddir)));
4959 __offsetof(struct ata_identify_log_pages,entries);
4960 max_entries = softc->valid_iddir_len - entries_offset;
4961 if ((softc->valid_iddir_len > (entries_offset + 1))
4962 && (le64dec(softc->ata_iddir.header) ==
4964 && (softc->ata_iddir.entry_count > 0)) {
4967 num_entries = softc->ata_iddir.entry_count;
4968 num_entries = min(num_entries,
4969 softc->valid_iddir_len - entries_offset);
4970 for (i = 0; i < num_entries &&
4971 i < max_entries; i++) {
4972 if (softc->ata_iddir.entries[i] ==
4975 DA_FLAG_CAN_ATA_SUPCAP;
4976 else if (softc->ata_iddir.entries[i]==
4979 DA_FLAG_CAN_ATA_ZONE;
4982 DA_FLAG_CAN_ATA_SUPCAP)
4984 DA_FLAG_CAN_ATA_ZONE))
4989 error = daerror(done_ccb, CAM_RETRY_SELTO,
4990 SF_RETRY_UA|SF_NO_PRINT);
4991 if (error == ERESTART)
4993 else if (error != 0) {
4995 * If we can't get the ATA Identify Data log
4996 * directory, then it effectively isn't
4997 * supported even if the ATA Log directory
4998 * a non-zero number of pages present for
5001 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
5002 if ((done_ccb->ccb_h.status &
5003 CAM_DEV_QFRZN) != 0) {
5004 /* Don't wedge this device's queue */
5005 cam_release_devq(done_ccb->ccb_h.path,
5009 /*getcount_only*/0);
5014 free(csio->data_ptr, M_SCSIDA);
5017 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
5018 softc->state = DA_STATE_PROBE_ATA_SUP;
5019 xpt_release_ccb(done_ccb);
5020 xpt_schedule(periph, priority);
5023 daprobedone(periph, done_ccb);
5026 case DA_CCB_PROBE_ATA_SUP:
5030 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5033 struct ata_identify_log_sup_cap *sup_cap;
5036 sup_cap = (struct ata_identify_log_sup_cap *)
5038 valid_len = csio->dxfer_len - csio->resid;
5040 __offsetof(struct ata_identify_log_sup_cap,
5041 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
5042 if (valid_len >= needed_size) {
5043 uint64_t zoned, zac_cap;
5045 zoned = le64dec(sup_cap->zoned_cap);
5046 if (zoned & ATA_ZONED_VALID) {
5048 * This should have already been
5049 * set, because this is also in the
5050 * ATA identify data.
5052 if ((zoned & ATA_ZONED_MASK) ==
5053 ATA_SUPPORT_ZONE_HOST_AWARE)
5056 else if ((zoned & ATA_ZONED_MASK) ==
5057 ATA_SUPPORT_ZONE_DEV_MANAGED)
5059 DA_ZONE_DRIVE_MANAGED;
5062 zac_cap = le64dec(sup_cap->sup_zac_cap);
5063 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
5064 if (zac_cap & ATA_REPORT_ZONES_SUP)
5065 softc->zone_flags |=
5066 DA_ZONE_FLAG_RZ_SUP;
5067 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
5068 softc->zone_flags |=
5069 DA_ZONE_FLAG_OPEN_SUP;
5070 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
5071 softc->zone_flags |=
5072 DA_ZONE_FLAG_CLOSE_SUP;
5073 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
5074 softc->zone_flags |=
5075 DA_ZONE_FLAG_FINISH_SUP;
5076 if (zac_cap & ATA_ND_RWP_SUP)
5077 softc->zone_flags |=
5078 DA_ZONE_FLAG_RWP_SUP;
5081 * This field was introduced in
5082 * ACS-4, r08 on April 28th, 2015.
5083 * If the drive firmware was written
5084 * to an earlier spec, it won't have
5085 * the field. So, assume all
5086 * commands are supported.
5088 softc->zone_flags |=
5089 DA_ZONE_FLAG_SUP_MASK;
5094 error = daerror(done_ccb, CAM_RETRY_SELTO,
5095 SF_RETRY_UA|SF_NO_PRINT);
5096 if (error == ERESTART)
5098 else if (error != 0) {
5100 * If we can't get the ATA Identify Data
5101 * Supported Capabilities page, clear the
5104 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5106 * And clear zone capabilities.
5108 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5109 if ((done_ccb->ccb_h.status &
5110 CAM_DEV_QFRZN) != 0) {
5111 /* Don't wedge this device's queue */
5112 cam_release_devq(done_ccb->ccb_h.path,
5116 /*getcount_only*/0);
5121 free(csio->data_ptr, M_SCSIDA);
5124 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5125 softc->state = DA_STATE_PROBE_ATA_ZONE;
5126 xpt_release_ccb(done_ccb);
5127 xpt_schedule(periph, priority);
5130 daprobedone(periph, done_ccb);
5133 case DA_CCB_PROBE_ATA_ZONE:
5137 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5138 struct ata_zoned_info_log *zi_log;
5142 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5144 valid_len = csio->dxfer_len - csio->resid;
5145 needed_size = __offsetof(struct ata_zoned_info_log,
5146 version_info) + 1 + sizeof(zi_log->version_info);
5147 if (valid_len >= needed_size) {
5150 tmpvar = le64dec(zi_log->zoned_cap);
5151 if (tmpvar & ATA_ZDI_CAP_VALID) {
5152 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5153 softc->zone_flags |=
5154 DA_ZONE_FLAG_URSWRZ;
5156 softc->zone_flags &=
5157 ~DA_ZONE_FLAG_URSWRZ;
5159 tmpvar = le64dec(zi_log->optimal_seq_zones);
5160 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5161 softc->zone_flags |=
5162 DA_ZONE_FLAG_OPT_SEQ_SET;
5163 softc->optimal_seq_zones = (tmpvar &
5164 ATA_ZDI_OPT_SEQ_MASK);
5166 softc->zone_flags &=
5167 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5168 softc->optimal_seq_zones = 0;
5171 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5172 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5173 softc->zone_flags |=
5174 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5175 softc->optimal_nonseq_zones =
5176 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5178 softc->zone_flags &=
5179 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5180 softc->optimal_nonseq_zones = 0;
5183 tmpvar = le64dec(zi_log->max_seq_req_zones);
5184 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5185 softc->zone_flags |=
5186 DA_ZONE_FLAG_MAX_SEQ_SET;
5187 softc->max_seq_zones =
5188 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5190 softc->zone_flags &=
5191 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5192 softc->max_seq_zones = 0;
5196 error = daerror(done_ccb, CAM_RETRY_SELTO,
5197 SF_RETRY_UA|SF_NO_PRINT);
5198 if (error == ERESTART)
5200 else if (error != 0) {
5201 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5202 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5204 if ((done_ccb->ccb_h.status &
5205 CAM_DEV_QFRZN) != 0) {
5206 /* Don't wedge this device's queue */
5207 cam_release_devq(done_ccb->ccb_h.path,
5211 /*getcount_only*/0);
5216 free(csio->data_ptr, M_SCSIDA);
5218 daprobedone(periph, done_ccb);
5221 case DA_CCB_PROBE_ZONE:
5225 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5228 struct scsi_vpd_zoned_bdc *zoned_bdc;
5231 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5233 valid_len = csio->dxfer_len - csio->resid;
5234 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5235 max_seq_req_zones) + 1 +
5236 sizeof(zoned_bdc->max_seq_req_zones);
5237 if ((valid_len >= needed_len)
5238 && (scsi_2btoul(zoned_bdc->page_length) >=
5240 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5241 softc->zone_flags |=
5242 DA_ZONE_FLAG_URSWRZ;
5244 softc->zone_flags &=
5245 ~DA_ZONE_FLAG_URSWRZ;
5246 softc->optimal_seq_zones =
5247 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5248 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5249 softc->optimal_nonseq_zones = scsi_4btoul(
5250 zoned_bdc->optimal_nonseq_zones);
5251 softc->zone_flags |=
5252 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5253 softc->max_seq_zones =
5254 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5255 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5258 * All of the zone commands are mandatory for SCSI
5261 * XXX KDM this is valid as of September 2015.
5262 * Re-check this assumption once the SAT spec is
5263 * updated to support SCSI ZBC to ATA ZAC mapping.
5264 * Since ATA allows zone commands to be reported
5265 * as supported or not, this may not necessarily
5266 * be true for an ATA device behind a SAT (SCSI to
5267 * ATA Translation) layer.
5269 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5271 error = daerror(done_ccb, CAM_RETRY_SELTO,
5272 SF_RETRY_UA|SF_NO_PRINT);
5273 if (error == ERESTART)
5275 else if (error != 0) {
5276 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5277 /* Don't wedge this device's queue */
5278 cam_release_devq(done_ccb->ccb_h.path,
5282 /*getcount_only*/0);
5286 daprobedone(periph, done_ccb);
5290 /* No-op. We're polling */
5294 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5296 if (daerror(done_ccb, CAM_RETRY_SELTO,
5297 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5300 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5301 cam_release_devq(done_ccb->ccb_h.path,
5305 /*getcount_only*/0);
5307 xpt_release_ccb(done_ccb);
5308 cam_periph_release_locked(periph);
5314 xpt_release_ccb(done_ccb);
5318 dareprobe(struct cam_periph *periph)
5320 struct da_softc *softc;
5323 softc = (struct da_softc *)periph->softc;
5325 /* Probe in progress; don't interfere. */
5326 if (softc->state != DA_STATE_NORMAL)
5329 status = cam_periph_acquire(periph);
5330 KASSERT(status == CAM_REQ_CMP,
5331 ("dareprobe: cam_periph_acquire failed"));
5333 if (softc->flags & DA_FLAG_CAN_RC16)
5334 softc->state = DA_STATE_PROBE_RC16;
5336 softc->state = DA_STATE_PROBE_RC;
5338 xpt_schedule(periph, CAM_PRIORITY_DEV);
5342 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5344 struct da_softc *softc;
5345 struct cam_periph *periph;
5346 int error, error_code, sense_key, asc, ascq;
5348 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5349 if (ccb->csio.bio != NULL)
5350 biotrack(ccb->csio.bio, __func__);
5353 periph = xpt_path_periph(ccb->ccb_h.path);
5354 softc = (struct da_softc *)periph->softc;
5357 * Automatically detect devices that do not support
5358 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5361 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5362 error = cmd6workaround(ccb);
5363 } else if (scsi_extract_sense_ccb(ccb,
5364 &error_code, &sense_key, &asc, &ascq)) {
5365 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5366 error = cmd6workaround(ccb);
5368 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5369 * query the capacity and notify upper layers.
5371 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5372 asc == 0x2A && ascq == 0x09) {
5373 xpt_print(periph->path, "Capacity data has changed\n");
5374 softc->flags &= ~DA_FLAG_PROBED;
5376 sense_flags |= SF_NO_PRINT;
5377 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5378 asc == 0x28 && ascq == 0x00) {
5379 softc->flags &= ~DA_FLAG_PROBED;
5380 disk_media_changed(softc->disk, M_NOWAIT);
5381 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5382 asc == 0x3F && ascq == 0x03) {
5383 xpt_print(periph->path, "INQUIRY data has changed\n");
5384 softc->flags &= ~DA_FLAG_PROBED;
5386 sense_flags |= SF_NO_PRINT;
5387 } else if (sense_key == SSD_KEY_NOT_READY &&
5388 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5389 softc->flags |= DA_FLAG_PACK_INVALID;
5390 disk_media_gone(softc->disk, M_NOWAIT);
5393 if (error == ERESTART)
5397 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5398 case CAM_CMD_TIMEOUT:
5401 case CAM_REQ_ABORTED:
5402 case CAM_REQ_CMP_ERR:
5403 case CAM_REQ_TERMIO:
5404 case CAM_UNREC_HBA_ERROR:
5405 case CAM_DATA_RUN_ERR:
5415 * Until we have a better way of doing pack validation,
5416 * don't treat UAs as errors.
5418 sense_flags |= SF_RETRY_UA;
5420 if (softc->quirks & DA_Q_RETRY_BUSY)
5421 sense_flags |= SF_RETRY_BUSY;
5422 return(cam_periph_error(ccb, cam_flags, sense_flags,
5423 &softc->saved_ccb));
5427 damediapoll(void *arg)
5429 struct cam_periph *periph = arg;
5430 struct da_softc *softc = periph->softc;
5432 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5433 LIST_EMPTY(&softc->pending_ccbs)) {
5434 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5435 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5439 /* Queue us up again */
5440 if (da_poll_period != 0)
5441 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5445 daprevent(struct cam_periph *periph, int action)
5447 struct da_softc *softc;
5451 softc = (struct da_softc *)periph->softc;
5453 if (((action == PR_ALLOW)
5454 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5455 || ((action == PR_PREVENT)
5456 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5460 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5462 scsi_prevent(&ccb->csio,
5470 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5471 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5474 if (action == PR_ALLOW)
5475 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5477 softc->flags |= DA_FLAG_PACK_LOCKED;
5480 xpt_release_ccb(ccb);
5484 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5485 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5487 struct ccb_calc_geometry ccg;
5488 struct da_softc *softc;
5489 struct disk_params *dp;
5490 u_int lbppbe, lalba;
5493 softc = (struct da_softc *)periph->softc;
5495 dp = &softc->params;
5496 dp->secsize = block_len;
5497 dp->sectors = maxsector + 1;
5498 if (rcaplong != NULL) {
5499 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5500 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5501 lalba &= SRC16_LALBA_A;
5508 dp->stripesize = block_len << lbppbe;
5509 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5511 } else if (softc->quirks & DA_Q_4K) {
5512 dp->stripesize = 4096;
5513 dp->stripeoffset = 0;
5514 } else if (softc->unmap_gran != 0) {
5515 dp->stripesize = block_len * softc->unmap_gran;
5516 dp->stripeoffset = (dp->stripesize - block_len *
5517 softc->unmap_gran_align) % dp->stripesize;
5520 dp->stripeoffset = 0;
5523 * Have the controller provide us with a geometry
5524 * for this disk. The only time the geometry
5525 * matters is when we boot and the controller
5526 * is the only one knowledgeable enough to come
5527 * up with something that will make this a bootable
5530 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5531 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5532 ccg.block_size = dp->secsize;
5533 ccg.volume_size = dp->sectors;
5535 ccg.secs_per_track = 0;
5537 xpt_action((union ccb*)&ccg);
5538 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5540 * We don't know what went wrong here- but just pick
5541 * a geometry so we don't have nasty things like divide
5545 dp->secs_per_track = 255;
5546 dp->cylinders = dp->sectors / (255 * 255);
5547 if (dp->cylinders == 0) {
5551 dp->heads = ccg.heads;
5552 dp->secs_per_track = ccg.secs_per_track;
5553 dp->cylinders = ccg.cylinders;
5557 * If the user supplied a read capacity buffer, and if it is
5558 * different than the previous buffer, update the data in the EDT.
5559 * If it's the same, we don't bother. This avoids sending an
5560 * update every time someone opens this device.
5562 if ((rcaplong != NULL)
5563 && (bcmp(rcaplong, &softc->rcaplong,
5564 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5565 struct ccb_dev_advinfo cdai;
5567 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5568 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5569 cdai.buftype = CDAI_TYPE_RCAPLONG;
5570 cdai.flags = CDAI_FLAG_STORE;
5571 cdai.bufsiz = rcap_len;
5572 cdai.buf = (uint8_t *)rcaplong;
5573 xpt_action((union ccb *)&cdai);
5574 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5575 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5576 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5577 xpt_print(periph->path, "%s: failed to set read "
5578 "capacity advinfo\n", __func__);
5579 /* Use cam_error_print() to decode the status */
5580 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5583 bcopy(rcaplong, &softc->rcaplong,
5584 min(sizeof(softc->rcaplong), rcap_len));
5588 softc->disk->d_sectorsize = softc->params.secsize;
5589 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5590 softc->disk->d_stripesize = softc->params.stripesize;
5591 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5592 /* XXX: these are not actually "firmware" values, so they may be wrong */
5593 softc->disk->d_fwsectors = softc->params.secs_per_track;
5594 softc->disk->d_fwheads = softc->params.heads;
5595 softc->disk->d_devstat->block_size = softc->params.secsize;
5596 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5598 error = disk_resize(softc->disk, M_NOWAIT);
5600 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5604 dasendorderedtag(void *arg)
5606 struct da_softc *softc = arg;
5608 if (da_send_ordered) {
5609 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5610 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5611 softc->flags |= DA_FLAG_NEED_OTAG;
5612 softc->flags &= ~DA_FLAG_WAS_OTAG;
5615 /* Queue us up again */
5616 callout_reset(&softc->sendordered_c,
5617 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5618 dasendorderedtag, softc);
5622 * Step through all DA peripheral drivers, and if the device is still open,
5623 * sync the disk cache to physical media.
5626 dashutdown(void * arg, int howto)
5628 struct cam_periph *periph;
5629 struct da_softc *softc;
5633 CAM_PERIPH_FOREACH(periph, &dadriver) {
5634 softc = (struct da_softc *)periph->softc;
5635 if (SCHEDULER_STOPPED()) {
5636 /* If we paniced with the lock held, do not recurse. */
5637 if (!cam_periph_owned(periph) &&
5638 (softc->flags & DA_FLAG_OPEN)) {
5639 dadump(softc->disk, NULL, 0, 0, 0);
5643 cam_periph_lock(periph);
5646 * We only sync the cache if the drive is still open, and
5647 * if the drive is capable of it..
5649 if (((softc->flags & DA_FLAG_OPEN) == 0)
5650 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5651 cam_periph_unlock(periph);
5655 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5656 scsi_synchronize_cache(&ccb->csio,
5660 /*begin_lba*/0, /* whole disk */
5665 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5666 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5667 softc->disk->d_devstat);
5669 xpt_print(periph->path, "Synchronize cache failed\n");
5670 xpt_release_ccb(ccb);
5671 cam_periph_unlock(periph);
5675 #else /* !_KERNEL */
5678 * XXX These are only left out of the kernel build to silence warnings. If,
5679 * for some reason these functions are used in the kernel, the ifdefs should
5680 * be moved so they are included both in the kernel and userland.
5683 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5684 void (*cbfcnp)(struct cam_periph *, union ccb *),
5685 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5686 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5689 struct scsi_format_unit *scsi_cmd;
5691 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5692 scsi_cmd->opcode = FORMAT_UNIT;
5693 scsi_cmd->byte2 = byte2;
5694 scsi_ulto2b(ileave, scsi_cmd->interleave);
5699 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5709 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5710 void (*cbfcnp)(struct cam_periph *, union ccb *),
5711 uint8_t tag_action, uint8_t list_format,
5712 uint32_t addr_desc_index, uint8_t *data_ptr,
5713 uint32_t dxfer_len, int minimum_cmd_size,
5714 uint8_t sense_len, uint32_t timeout)
5719 * These conditions allow using the 10 byte command. Otherwise we
5720 * need to use the 12 byte command.
5722 if ((minimum_cmd_size <= 10)
5723 && (addr_desc_index == 0)
5724 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5725 struct scsi_read_defect_data_10 *cdb10;
5727 cdb10 = (struct scsi_read_defect_data_10 *)
5728 &csio->cdb_io.cdb_bytes;
5730 cdb_len = sizeof(*cdb10);
5731 bzero(cdb10, cdb_len);
5732 cdb10->opcode = READ_DEFECT_DATA_10;
5733 cdb10->format = list_format;
5734 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5736 struct scsi_read_defect_data_12 *cdb12;
5738 cdb12 = (struct scsi_read_defect_data_12 *)
5739 &csio->cdb_io.cdb_bytes;
5741 cdb_len = sizeof(*cdb12);
5742 bzero(cdb12, cdb_len);
5743 cdb12->opcode = READ_DEFECT_DATA_12;
5744 cdb12->format = list_format;
5745 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5746 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5752 /*flags*/ CAM_DIR_IN,
5762 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5763 void (*cbfcnp)(struct cam_periph *, union ccb *),
5764 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5765 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5768 struct scsi_sanitize *scsi_cmd;
5770 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5771 scsi_cmd->opcode = SANITIZE;
5772 scsi_cmd->byte2 = byte2;
5773 scsi_cmd->control = control;
5774 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5779 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5788 #endif /* _KERNEL */
5791 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5792 void (*cbfcnp)(struct cam_periph *, union ccb *),
5793 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5794 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5795 uint8_t sense_len, uint32_t timeout)
5797 struct scsi_zbc_out *scsi_cmd;
5799 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5800 scsi_cmd->opcode = ZBC_OUT;
5801 scsi_cmd->service_action = service_action;
5802 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5803 scsi_cmd->zone_flags = zone_flags;
5808 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5818 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5819 void (*cbfcnp)(struct cam_periph *, union ccb *),
5820 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5821 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5822 uint8_t sense_len, uint32_t timeout)
5824 struct scsi_zbc_in *scsi_cmd;
5826 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5827 scsi_cmd->opcode = ZBC_IN;
5828 scsi_cmd->service_action = service_action;
5829 scsi_ulto4b(dxfer_len, scsi_cmd->length);
5830 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5831 scsi_cmd->zone_options = zone_options;
5836 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5847 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5848 void (*cbfcnp)(struct cam_periph *, union ccb *),
5849 uint8_t tag_action, int use_ncq,
5850 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5851 uint8_t *data_ptr, uint32_t dxfer_len,
5852 uint8_t *cdb_storage, size_t cdb_storage_len,
5853 uint8_t sense_len, uint32_t timeout)
5855 uint8_t command_out, protocol, ata_flags;
5856 uint16_t features_out;
5857 uint32_t sectors_out, auxiliary;
5863 command_out = ATA_ZAC_MANAGEMENT_OUT;
5864 features_out = (zm_action & 0xf) | (zone_flags << 8);
5865 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5866 if (dxfer_len == 0) {
5867 protocol = AP_PROTO_NON_DATA;
5868 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5871 protocol = AP_PROTO_DMA;
5872 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5873 AP_FLAG_TDIR_TO_DEV;
5874 sectors_out = ((dxfer_len >> 9) & 0xffff);
5878 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5879 if (dxfer_len == 0) {
5880 command_out = ATA_NCQ_NON_DATA;
5881 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5883 * We're assuming the SCSI to ATA translation layer
5884 * will set the NCQ tag number in the tag field.
5885 * That isn't clear from the SAT-4 spec (as of rev 05).
5888 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5890 command_out = ATA_SEND_FPDMA_QUEUED;
5892 * Note that we're defaulting to normal priority,
5893 * and assuming that the SCSI to ATA translation
5894 * layer will insert the NCQ tag number in the tag
5895 * field. That isn't clear in the SAT-4 spec (as
5898 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5900 ata_flags |= AP_FLAG_TLEN_FEAT |
5901 AP_FLAG_TDIR_TO_DEV;
5904 * For SEND FPDMA QUEUED, the transfer length is
5905 * encoded in the FEATURE register, and 0 means
5906 * that 65536 512 byte blocks are to be tranferred.
5907 * In practice, it seems unlikely that we'll see
5908 * a transfer that large, and it may confuse the
5909 * the SAT layer, because generally that means that
5910 * 0 bytes should be transferred.
5912 if (dxfer_len == (65536 * 512)) {
5914 } else if (dxfer_len <= (65535 * 512)) {
5915 features_out = ((dxfer_len >> 9) & 0xffff);
5917 /* The transfer is too big. */
5924 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
5925 protocol = AP_PROTO_FPDMA;
5928 protocol |= AP_EXTEND;
5930 retval = scsi_ata_pass(csio,
5933 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5935 /*protocol*/ protocol,
5936 /*ata_flags*/ ata_flags,
5937 /*features*/ features_out,
5938 /*sector_count*/ sectors_out,
5940 /*command*/ command_out,
5943 /*auxiliary*/ auxiliary,
5945 /*data_ptr*/ data_ptr,
5946 /*dxfer_len*/ dxfer_len,
5947 /*cdb_storage*/ cdb_storage,
5948 /*cdb_storage_len*/ cdb_storage_len,
5949 /*minimum_cmd_size*/ 0,
5950 /*sense_len*/ SSD_FULL_SIZE,
5951 /*timeout*/ timeout);
5959 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
5960 void (*cbfcnp)(struct cam_periph *, union ccb *),
5961 uint8_t tag_action, int use_ncq,
5962 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5963 uint8_t *data_ptr, uint32_t dxfer_len,
5964 uint8_t *cdb_storage, size_t cdb_storage_len,
5965 uint8_t sense_len, uint32_t timeout)
5967 uint8_t command_out, protocol;
5968 uint16_t features_out, sectors_out;
5974 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
5977 command_out = ATA_ZAC_MANAGEMENT_IN;
5978 /* XXX KDM put a macro here */
5979 features_out = (zm_action & 0xf) | (zone_flags << 8);
5980 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
5981 protocol = AP_PROTO_DMA;
5982 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
5985 ata_flags |= AP_FLAG_TLEN_FEAT;
5987 command_out = ATA_RECV_FPDMA_QUEUED;
5988 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
5991 * For RECEIVE FPDMA QUEUED, the transfer length is
5992 * encoded in the FEATURE register, and 0 means
5993 * that 65536 512 byte blocks are to be tranferred.
5994 * In practice, it seems unlikely that we'll see
5995 * a transfer that large, and it may confuse the
5996 * the SAT layer, because generally that means that
5997 * 0 bytes should be transferred.
5999 if (dxfer_len == (65536 * 512)) {
6001 } else if (dxfer_len <= (65535 * 512)) {
6002 features_out = ((dxfer_len >> 9) & 0xffff);
6004 /* The transfer is too big. */
6008 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
6009 protocol = AP_PROTO_FPDMA;
6012 protocol |= AP_EXTEND;
6014 retval = scsi_ata_pass(csio,
6017 /*flags*/ CAM_DIR_IN,
6019 /*protocol*/ protocol,
6020 /*ata_flags*/ ata_flags,
6021 /*features*/ features_out,
6022 /*sector_count*/ sectors_out,
6024 /*command*/ command_out,
6027 /*auxiliary*/ auxiliary,
6029 /*data_ptr*/ data_ptr,
6030 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
6031 /*cdb_storage*/ cdb_storage,
6032 /*cdb_storage_len*/ cdb_storage_len,
6033 /*minimum_cmd_size*/ 0,
6034 /*sense_len*/ SSD_FULL_SIZE,
6035 /*timeout*/ timeout);